|
|
|
|
@ -4,18 +4,52 @@ use tracing::info;
|
|
|
|
|
use axum::body::Bytes;
|
|
|
|
|
use crate::db::adjustment::add_adjustment_new_stock;
|
|
|
|
|
use crate::db::inventory_item::add_inventory_item;
|
|
|
|
|
use crate::db::vetcove::item_history::add_vetcove_item_history_entry;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, serde::Deserialize)]
|
|
|
|
|
struct ItemHistoryRecord {
|
|
|
|
|
name: String,
|
|
|
|
|
#[serde(alias = "qty")]
|
|
|
|
|
#[serde(alias = "Vetcove ID")]
|
|
|
|
|
vetcove_entry_id: i64,
|
|
|
|
|
#[serde(alias = "Date")]
|
|
|
|
|
order_date: chrono::NaiveDate,
|
|
|
|
|
#[serde(alias = "Hospital")]
|
|
|
|
|
hospital: String,
|
|
|
|
|
#[serde(alias = "Name")]
|
|
|
|
|
item_name: String,
|
|
|
|
|
#[serde(alias = "Order #")]
|
|
|
|
|
order_id: String,
|
|
|
|
|
#[serde(alias = "PO Number")]
|
|
|
|
|
po_number: String,
|
|
|
|
|
#[serde(alias = "Supplier")]
|
|
|
|
|
supplier: String,
|
|
|
|
|
#[serde(alias = "Manufacturer")]
|
|
|
|
|
manufacturer: String,
|
|
|
|
|
#[serde(alias = "Manufacturer Number")]
|
|
|
|
|
manufacturer_number: String,
|
|
|
|
|
#[serde(alias = "Primary Category")]
|
|
|
|
|
primary_category: String,
|
|
|
|
|
#[serde(alias = "Secondary Category")]
|
|
|
|
|
secondary_category: String,
|
|
|
|
|
#[serde(alias = "Vetcove Item ID")]
|
|
|
|
|
vetcove_item_id: i64,
|
|
|
|
|
#[serde(alias = "Cost per Dose")]
|
|
|
|
|
cost_per_dose: String,
|
|
|
|
|
#[serde(alias = "Units")]
|
|
|
|
|
units: f64,
|
|
|
|
|
#[serde(alias = "Unit Price")]
|
|
|
|
|
unit_price: String,
|
|
|
|
|
#[serde(alias = "Unit Measurement")]
|
|
|
|
|
unit_measurement: String,
|
|
|
|
|
#[serde(alias = "List Price")]
|
|
|
|
|
list_price: String,
|
|
|
|
|
#[serde(alias = "Quantity")]
|
|
|
|
|
quantity: f64,
|
|
|
|
|
unit: String,
|
|
|
|
|
fractional: bool,
|
|
|
|
|
#[serde(alias = "reorder")]
|
|
|
|
|
reorder_point: f64,
|
|
|
|
|
#[serde(alias = "price")]
|
|
|
|
|
unit_price: i64,
|
|
|
|
|
#[serde(alias = "Total Price")]
|
|
|
|
|
total_price: String,
|
|
|
|
|
#[serde(alias = "Item Status")]
|
|
|
|
|
item_status: String,
|
|
|
|
|
#[serde(alias = "Supplier's SKU")]
|
|
|
|
|
supplier_sku: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn ingest_item_history_bytes(bytes: Bytes, db: SqlitePool, user_id: i64) -> anyhow::Result<()> {
|
|
|
|
|
@ -31,17 +65,35 @@ pub async fn ingest_item_history<T: std::io::Read>(mut reader: csv::Reader<T>, d
|
|
|
|
|
for result in reader.deserialize() {
|
|
|
|
|
let record: ItemHistoryRecord = result?;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
let new_entry_id = add_inventory_item(&db,
|
|
|
|
|
&record.name,
|
|
|
|
|
record.reorder_point,
|
|
|
|
|
record.fractional,
|
|
|
|
|
&record.unit,
|
|
|
|
|
&None,
|
|
|
|
|
&None,
|
|
|
|
|
let query_res = add_vetcove_item_history_entry(
|
|
|
|
|
&db,
|
|
|
|
|
record.vetcove_entry_id,
|
|
|
|
|
record.vetcove_item_id,
|
|
|
|
|
record.order_date,
|
|
|
|
|
record.item_name,
|
|
|
|
|
record.order_id,
|
|
|
|
|
record.units,
|
|
|
|
|
record.quantity,
|
|
|
|
|
record.total_price,
|
|
|
|
|
Some(record.unit_price),
|
|
|
|
|
Some(record.list_price),
|
|
|
|
|
Some(record.cost_per_dose),
|
|
|
|
|
Some(record.hospital),
|
|
|
|
|
Some(record.po_number),
|
|
|
|
|
Some(record.supplier),
|
|
|
|
|
Some(record.manufacturer),
|
|
|
|
|
Some(record.manufacturer_number),
|
|
|
|
|
Some(record.primary_category),
|
|
|
|
|
Some(record.secondary_category),
|
|
|
|
|
Some(record.unit_measurement),
|
|
|
|
|
Some(record.item_status),
|
|
|
|
|
Some(record.supplier_sku),
|
|
|
|
|
).await?;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
match query_res {
|
|
|
|
|
Some(new_db_id) => info!("Added new history item: {} => {}", record.vetcove_entry_id, new_db_id),
|
|
|
|
|
None => info!("History item exists, skipping {}", record.vetcove_entry_id),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|