fixes
This commit is contained in:
@@ -11,7 +11,9 @@ import type {
|
||||
OrderItemOption,
|
||||
PartRow,
|
||||
PurchaseOrderListRow,
|
||||
PurchaseOrderLineDetailRow,
|
||||
SalesOrderListRow,
|
||||
SalesOrderLineDetailRow,
|
||||
VendorBillRow
|
||||
} from "@/lib/types";
|
||||
|
||||
@@ -190,6 +192,54 @@ export function getPurchaseOrders(): PurchaseOrderListRow[] {
|
||||
.all() as PurchaseOrderListRow[];
|
||||
}
|
||||
|
||||
export function getSalesOrderLineDetails(): SalesOrderLineDetailRow[] {
|
||||
return db()
|
||||
.prepare(
|
||||
`
|
||||
SELECT
|
||||
sol.id AS lineId,
|
||||
sol.sales_order_id AS salesOrderId,
|
||||
sol.part_id AS partId,
|
||||
p.sku,
|
||||
p.name AS partName,
|
||||
sol.quantity,
|
||||
sol.shipped_quantity AS fulfilledQuantity,
|
||||
sol.quantity - sol.shipped_quantity AS remainingQuantity,
|
||||
sol.unit_price AS unitPrice,
|
||||
COALESCE(ib.quantity_on_hand, 0) AS quantityOnHand,
|
||||
p.unit_of_measure AS unitOfMeasure
|
||||
FROM sales_order_lines sol
|
||||
INNER JOIN parts p ON p.id = sol.part_id
|
||||
LEFT JOIN inventory_balances ib ON ib.part_id = p.id
|
||||
ORDER BY sol.sales_order_id DESC, sol.id ASC
|
||||
`
|
||||
)
|
||||
.all() as SalesOrderLineDetailRow[];
|
||||
}
|
||||
|
||||
export function getPurchaseOrderLineDetails(): PurchaseOrderLineDetailRow[] {
|
||||
return db()
|
||||
.prepare(
|
||||
`
|
||||
SELECT
|
||||
pol.id AS lineId,
|
||||
pol.purchase_order_id AS purchaseOrderId,
|
||||
pol.part_id AS partId,
|
||||
p.sku,
|
||||
p.name AS partName,
|
||||
pol.quantity,
|
||||
pol.received_quantity AS fulfilledQuantity,
|
||||
pol.quantity - pol.received_quantity AS remainingQuantity,
|
||||
pol.unit_cost AS unitCost,
|
||||
p.unit_of_measure AS unitOfMeasure
|
||||
FROM purchase_order_lines pol
|
||||
INNER JOIN parts p ON p.id = pol.part_id
|
||||
ORDER BY pol.purchase_order_id DESC, pol.id ASC
|
||||
`
|
||||
)
|
||||
.all() as PurchaseOrderLineDetailRow[];
|
||||
}
|
||||
|
||||
export function getJournalEntries(): JournalEntryRow[] {
|
||||
const entries = db()
|
||||
.prepare(
|
||||
|
||||
Reference in New Issue
Block a user