Ultronprime commited on
Commit
60d4775
·
verified ·
1 Parent(s): 2313378

Update purchaseOrderService.js

Browse files
Files changed (1) hide show
  1. purchaseOrderService.js +16 -15
purchaseOrderService.js CHANGED
@@ -1,12 +1,13 @@
1
  // purchaseOrderService.js - Generates Purchase Order PDFs
2
 
3
  /**
4
- * Generates a single consolidated Purchase Order PDF for multiple materials.
5
- * @param {Array<Object>} materialsToOrder - An array of material objects that need to be reordered.
 
6
  */
7
- export function generatePurchaseOrder(materialsToOrder) {
8
- if (!materialsToOrder || materialsToOrder.length === 0) {
9
- console.error("No materials provided for PO generation.");
10
  return;
11
  }
12
 
@@ -39,26 +40,25 @@ export function generatePurchaseOrder(materialsToOrder) {
39
  doc.setFont("helvetica", "normal");
40
  doc.text(today, 160, 46);
41
 
42
- // Supplier Info (Placeholder)
43
  doc.setFont("helvetica", "bold");
44
  doc.text("TO:", 20, 70);
45
  doc.setFont("helvetica", "normal");
46
- doc.text("________________________ (Supplier Name)", 20, 76);
47
  doc.text("________________________ (Supplier Address)", 20, 82);
48
 
49
 
50
  // Items Table
51
- const tableColumn = ["Item Description", "Current Stock", "Reorder Point", "Recommended Order Qty", "Unit"];
52
  const tableRows = [];
53
 
54
- materialsToOrder.forEach(material => {
55
- // Order enough to reach 2x the reorder point. Ensure at least 1 is ordered.
56
- const quantityToOrder = Math.max(1, (material.reorderPoint * 2) - material.currentStock);
57
  const materialRow = [
58
  material.name,
59
  material.currentStock,
60
  material.reorderPoint,
61
- quantityToOrder,
62
  material.unit
63
  ];
64
  tableRows.push(materialRow);
@@ -69,16 +69,17 @@ export function generatePurchaseOrder(materialsToOrder) {
69
  body: tableRows,
70
  startY: 95,
71
  theme: 'grid',
72
- headStyles: { fillColor: [45, 55, 72] } // Dark blue header
73
  });
74
 
75
  // Footer
76
- const finalY = doc.lastAutoTable.finalY || 150; // Get Y position after table
77
  doc.setFontSize(10);
78
  doc.setTextColor(150);
79
  doc.text("Please deliver items to the address above. Contact us with any questions regarding this order.", 105, Math.max(finalY + 20, 280), { align: 'center'});
80
 
81
 
82
  // Save the PDF
83
- doc.save(`Consolidated_PO_${poNumber}.pdf`);
 
84
  }
 
1
  // purchaseOrderService.js - Generates Purchase Order PDFs
2
 
3
  /**
4
+ * Generates a single consolidated and customized Purchase Order PDF.
5
+ * @param {Array<Object>} itemsToOrder - An array of objects, each with { material, quantity }.
6
+ * @param {string} supplierName - The name of the supplier for the PO.
7
  */
8
+ export function generatePurchaseOrder(itemsToOrder, supplierName) {
9
+ if (!itemsToOrder || itemsToOrder.length === 0) {
10
+ console.error("No items provided for PO generation.");
11
  return;
12
  }
13
 
 
40
  doc.setFont("helvetica", "normal");
41
  doc.text(today, 160, 46);
42
 
43
+ // Supplier Info
44
  doc.setFont("helvetica", "bold");
45
  doc.text("TO:", 20, 70);
46
  doc.setFont("helvetica", "normal");
47
+ doc.text(supplierName || "________________________ (Supplier Name)", 20, 76);
48
  doc.text("________________________ (Supplier Address)", 20, 82);
49
 
50
 
51
  // Items Table
52
+ const tableColumn = ["Item Description", "Current Stock", "Reorder Point", "Order Quantity", "Unit"];
53
  const tableRows = [];
54
 
55
+ itemsToOrder.forEach(item => {
56
+ const { material, quantity } = item;
 
57
  const materialRow = [
58
  material.name,
59
  material.currentStock,
60
  material.reorderPoint,
61
+ quantity,
62
  material.unit
63
  ];
64
  tableRows.push(materialRow);
 
69
  body: tableRows,
70
  startY: 95,
71
  theme: 'grid',
72
+ headStyles: { fillColor: [45, 55, 72] }
73
  });
74
 
75
  // Footer
76
+ const finalY = doc.lastAutoTable.finalY || 150;
77
  doc.setFontSize(10);
78
  doc.setTextColor(150);
79
  doc.text("Please deliver items to the address above. Contact us with any questions regarding this order.", 105, Math.max(finalY + 20, 280), { align: 'center'});
80
 
81
 
82
  // Save the PDF
83
+ const safeSupplierName = supplierName.replace(/[\s/]/g, '_') || 'General';
84
+ doc.save(`PO_${safeSupplierName}_${poNumber}.pdf`);
85
  }