|
|
|
@ -10,6 +10,11 @@ pub struct DbInventoryItem {
|
|
|
|
pub reorder_point: f64,
|
|
|
|
pub reorder_point: f64,
|
|
|
|
pub allow_fractional_units: bool,
|
|
|
|
pub allow_fractional_units: bool,
|
|
|
|
pub display_unit: i64,
|
|
|
|
pub display_unit: i64,
|
|
|
|
|
|
|
|
pub active: bool,
|
|
|
|
|
|
|
|
pub pims_id: Option<String>,
|
|
|
|
|
|
|
|
pub vetcove_id: Option<String>,
|
|
|
|
|
|
|
|
pub manufacturer_name: Option<String>,
|
|
|
|
|
|
|
|
pub manufacturer_id: Option<String>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -23,7 +28,12 @@ pub async fn inventory_item_get_all(db: &SqlitePool, page_size: i64, page_num: i
|
|
|
|
name,
|
|
|
|
name,
|
|
|
|
reorder_point,
|
|
|
|
reorder_point,
|
|
|
|
allow_fractional_units,
|
|
|
|
allow_fractional_units,
|
|
|
|
display_unit
|
|
|
|
display_unit,
|
|
|
|
|
|
|
|
active,
|
|
|
|
|
|
|
|
pims_id,
|
|
|
|
|
|
|
|
vetcove_id,
|
|
|
|
|
|
|
|
manufacturer_name,
|
|
|
|
|
|
|
|
manufacturer_id
|
|
|
|
FROM
|
|
|
|
FROM
|
|
|
|
InventoryItem
|
|
|
|
InventoryItem
|
|
|
|
LIMIT ? OFFSET ?
|
|
|
|
LIMIT ? OFFSET ?
|
|
|
|
@ -49,7 +59,12 @@ pub async fn inventory_item_get_search(db: &SqlitePool,
|
|
|
|
name,
|
|
|
|
name,
|
|
|
|
reorder_point,
|
|
|
|
reorder_point,
|
|
|
|
allow_fractional_units,
|
|
|
|
allow_fractional_units,
|
|
|
|
display_unit
|
|
|
|
display_unit,
|
|
|
|
|
|
|
|
active,
|
|
|
|
|
|
|
|
pims_id,
|
|
|
|
|
|
|
|
vetcove_id,
|
|
|
|
|
|
|
|
manufacturer_name,
|
|
|
|
|
|
|
|
manufacturer_id
|
|
|
|
FROM
|
|
|
|
FROM
|
|
|
|
InventoryItem
|
|
|
|
InventoryItem
|
|
|
|
WHERE InventoryItem.name LIKE ?
|
|
|
|
WHERE InventoryItem.name LIKE ?
|
|
|
|
@ -71,7 +86,12 @@ pub async fn inventory_item_get_by_id(db: &SqlitePool, id: i64) -> Result<DbInve
|
|
|
|
name,
|
|
|
|
name,
|
|
|
|
reorder_point,
|
|
|
|
reorder_point,
|
|
|
|
allow_fractional_units,
|
|
|
|
allow_fractional_units,
|
|
|
|
display_unit
|
|
|
|
display_unit,
|
|
|
|
|
|
|
|
active,
|
|
|
|
|
|
|
|
pims_id,
|
|
|
|
|
|
|
|
vetcove_id,
|
|
|
|
|
|
|
|
manufacturer_name,
|
|
|
|
|
|
|
|
manufacturer_id
|
|
|
|
FROM
|
|
|
|
FROM
|
|
|
|
InventoryItem
|
|
|
|
InventoryItem
|
|
|
|
WHERE InventoryItem.id = ?
|
|
|
|
WHERE InventoryItem.id = ?
|
|
|
|
@ -87,10 +107,10 @@ pub async fn add_inventory_item(db: &SqlitePool, name: &str, reorder_point: f64,
|
|
|
|
) -> Result<i64> {
|
|
|
|
) -> Result<i64> {
|
|
|
|
let res = sqlx::query!(
|
|
|
|
let res = sqlx::query!(
|
|
|
|
r#"
|
|
|
|
r#"
|
|
|
|
INSERT INTO InventoryItem (name, reorder_point, allow_fractional_units, display_unit)
|
|
|
|
INSERT INTO InventoryItem (name, reorder_point, allow_fractional_units, display_unit, active)
|
|
|
|
VALUES (?, ?, ?, (SELECT id from DisplayUnit WHERE abbreviation = ? ))
|
|
|
|
VALUES (?, ?, ?, (SELECT id from DisplayUnit WHERE abbreviation = ? ), ?)
|
|
|
|
"#,
|
|
|
|
"#,
|
|
|
|
name, reorder_point, allow_fractional_units, display_unit_abbreviation
|
|
|
|
name, reorder_point, allow_fractional_units, display_unit_abbreviation, true
|
|
|
|
).execute(db).await?;
|
|
|
|
).execute(db).await?;
|
|
|
|
|
|
|
|
|
|
|
|
let new_id = res.last_insert_rowid();
|
|
|
|
let new_id = res.last_insert_rowid();
|
|
|
|
@ -109,6 +129,7 @@ pub struct DbInventoryItemWithCount {
|
|
|
|
pub display_unit_str: String,
|
|
|
|
pub display_unit_str: String,
|
|
|
|
pub display_unit_abbreviation: String,
|
|
|
|
pub display_unit_abbreviation: String,
|
|
|
|
pub amount: Option<f64>,
|
|
|
|
pub amount: Option<f64>,
|
|
|
|
|
|
|
|
pub active: bool,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn inventory_item_get_by_id_with_unit(db: &SqlitePool, id: i64) -> Result<DbInventoryItemWithCount> {
|
|
|
|
pub async fn inventory_item_get_by_id_with_unit(db: &SqlitePool, id: i64) -> Result<DbInventoryItemWithCount> {
|
|
|
|
@ -123,7 +144,8 @@ pub async fn inventory_item_get_by_id_with_unit(db: &SqlitePool, id: i64) -> Res
|
|
|
|
item.display_unit as display_unit,
|
|
|
|
item.display_unit as display_unit,
|
|
|
|
display_unit.unit as display_unit_str,
|
|
|
|
display_unit.unit as display_unit_str,
|
|
|
|
display_unit.abbreviation as display_unit_abbreviation,
|
|
|
|
display_unit.abbreviation as display_unit_abbreviation,
|
|
|
|
(SELECT TOTAL(amount) as amt FROM Adjustment WHERE item = ?) as amount
|
|
|
|
(SELECT TOTAL(amount) as amt FROM Adjustment WHERE item = ?) as amount,
|
|
|
|
|
|
|
|
item.active as active
|
|
|
|
FROM
|
|
|
|
FROM
|
|
|
|
InventoryItem as item
|
|
|
|
InventoryItem as item
|
|
|
|
JOIN DisplayUnit as display_unit ON item.display_unit = display_unit.id
|
|
|
|
JOIN DisplayUnit as display_unit ON item.display_unit = display_unit.id
|
|
|
|
@ -150,3 +172,20 @@ pub async fn does_inventory_item_allow_fractional_units(db: &SqlitePool, id: i64
|
|
|
|
|
|
|
|
|
|
|
|
Ok(res.allow_fractional_units)
|
|
|
|
Ok(res.allow_fractional_units)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn inventory_item_get_unit_abbreviation(db: &SqlitePool, id: i64) -> Result<String> {
|
|
|
|
|
|
|
|
let res = sqlx::query!(
|
|
|
|
|
|
|
|
r#"
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
|
|
unit.abbreviation
|
|
|
|
|
|
|
|
FROM InventoryItem as item
|
|
|
|
|
|
|
|
JOIN DisplayUnit as unit
|
|
|
|
|
|
|
|
ON item.display_unit = unit.id
|
|
|
|
|
|
|
|
WHERE item.id = ?
|
|
|
|
|
|
|
|
"#,
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.fetch_one(db).await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(res.abbreviation)
|
|
|
|
|
|
|
|
}
|
|
|
|
|