From 91d3ebdef0c693e44d4e313e44e662c54f2d734d Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 27 Apr 2023 17:32:38 +0200 Subject: [PATCH] Bug 5695: Purchase Order Item Description should be saved on the PO line description directly. Fixed. --- purchasing/includes/db/po_db.inc | 26 ++++++++++++++++++-------- purchasing/includes/po_class.inc | 3 ++- purchasing/includes/purchasing_db.inc | 8 ++++---- purchasing/view/view_po.php | 1 - reporting/rep209.php | 5 +++-- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/purchasing/includes/db/po_db.inc b/purchasing/includes/db/po_db.inc index 23f19a09..06ce31ff 100644 --- a/purchasing/includes/db/po_db.inc +++ b/purchasing/includes/db/po_db.inc @@ -91,6 +91,12 @@ function add_po(&$po_obj) /*Insert the purchase order detail records */ foreach ($po_obj->line_items as $line_no => $po_line) { + if (!$po_line->descr_editable) + { + $data = get_purchase_data($po_obj->supplier_id, $po_line->stock_id); + if ($data !== false && $data['supplier_description'] != "") + $po_line->item_description = $data['supplier_description']; + } $sql = "INSERT INTO ".TB_PREF."purch_order_details (order_no, item_code, description, delivery_date, unit_price, quantity_ordered) VALUES ("; $sql .= $po_obj->order_no . ", " . db_escape($po_line->stock_id). "," . db_escape($po_line->item_description). ",'" . @@ -136,6 +142,12 @@ function update_po(&$po_obj) /*Now Update the purchase order detail records */ foreach ($po_obj->line_items as $po_line) { + if (!$po_line->descr_editable) + { + $data = get_purchase_data($po_obj->supplier_id, $po_line->stock_id); + if ($data !== false && $data['supplier_description'] != "") + $po_line->item_description = $data['supplier_description']; + } $sql = "INSERT INTO ".TB_PREF."purch_order_details (po_detail_item, order_no, item_code, description, delivery_date, unit_price, quantity_ordered, quantity_received) VALUES (" .db_escape($po_line->po_detail_rec ? $po_line->po_detail_rec : 0). "," @@ -217,7 +229,7 @@ function read_po_items($order_no, &$order, $open_items_only=false) { /*now populate the line po array with the purchase order details records */ - $sql = "SELECT poline.*, units + $sql = "SELECT poline.*, units, editable FROM ".TB_PREF."purch_order_details poline LEFT JOIN ".TB_PREF."stock_master item ON poline.item_code=item.stock_id WHERE order_no =".db_escape($order_no); @@ -233,13 +245,11 @@ function read_po_items($order_no, &$order, $open_items_only=false) { while ($myrow = db_fetch($result)) { - $data = get_purchase_data($order->supplier_id, $myrow['item_code']); - if ($data !== false) - { - if ($data['supplier_description'] != "") - $myrow['description'] = $data['supplier_description']; - } - if (is_null($myrow["units"])) + $data = get_purchase_data($order->supplier_id, $myrow['item_code']); + if ($data !== false && !$myrow['editable'] && $data['supplier_description'] != "" && + $myrow['description'] != $data['supplier_description']) // backward compatibility + $myrow['description'] = $data['supplier_description']; + if (is_null($myrow["units"])) { $units = ""; } diff --git a/purchasing/includes/po_class.inc b/purchasing/includes/po_class.inc index c24119d2..51f40a8c 100644 --- a/purchasing/includes/po_class.inc +++ b/purchasing/includes/po_class.inc @@ -228,7 +228,8 @@ class po_line_details return; $this->descr_editable = $item_row["editable"]; - if ($item_descr == null || !$this->descr_editable) + //if ($item_descr == null || !$this->descr_editable) this was overriding the prchase description!! + if ($item_descr == null) $this->item_description = $item_row["description"]; else $this->item_description = $item_descr; diff --git a/purchasing/includes/purchasing_db.inc b/purchasing/includes/purchasing_db.inc index 69df53b4..28f9c720 100644 --- a/purchasing/includes/purchasing_db.inc +++ b/purchasing/includes/purchasing_db.inc @@ -102,16 +102,16 @@ function add_or_update_purchase_data($supplier_id, $stock_id, $price, $descripti $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom, conversion_factor, supplier_description) VALUES (".db_escape($supplier_id) .", ".db_escape($stock_id).", ".db_escape($price).", " - .db_escape($uom).", 1, ".db_escape($description).")"; // the description should only be updated here. + .db_escape($uom).", 1, ".db_escape($description).")"; db_query($sql,"The supplier purchasing details could not be added"); return; } - $price = round($price * $data['conversion_factor'], user_price_dec()); + //$price = round($price * $data['conversion_factor'], user_price_dec()); $sql = "UPDATE ".TB_PREF."purch_data SET price=".db_escape($price); if ($uom != "") $sql .= ",suppliers_uom=".db_escape($uom); - //if ($description != "") should only be updateded if $data === false (see above) - // $sql .= ",supplier_description=".db_escape($description); + if ($description != "") + $sql .= ",supplier_description=".db_escape($description); $sql .= " WHERE stock_id=".db_escape($stock_id)." AND supplier_id=".db_escape($supplier_id); db_query($sql,"The supplier purchasing details could not be updated"); return true; diff --git a/purchasing/view/view_po.php b/purchasing/view/view_po.php index 38064894..c83d12b3 100644 --- a/purchasing/view/view_po.php +++ b/purchasing/view/view_po.php @@ -50,7 +50,6 @@ $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"), _(" table_header($th); $total = $k = 0; $overdue_items = false; - foreach ($purchase_order->line_items as $stock_item) { diff --git a/reporting/rep209.php b/reporting/rep209.php index 5a082171..ce15c150 100644 --- a/reporting/rep209.php +++ b/reporting/rep209.php @@ -49,7 +49,7 @@ function get_supp_po($order_no) function get_po_details($order_no) { - $sql = "SELECT poline.*, units + $sql = "SELECT poline.*, units, editable FROM ".TB_PREF."purch_order_details poline LEFT JOIN ".TB_PREF."stock_master item ON poline.item_code=item.stock_id WHERE order_no =".db_escape($order_no)." "; @@ -121,7 +121,8 @@ function print_po() $data = get_purchase_data($myrow['supplier_id'], $myrow2['item_code']); if ($data !== false) { - if ($data['supplier_description'] != "") + if (!$myrow2['editable'] && $data['supplier_description'] != "" && + $myrow2['description'] != $data['supplier_description']) // backward compatibility $myrow2['description'] = $data['supplier_description']; if ($data['suppliers_uom'] != "") $myrow2['units'] = $data['suppliers_uom']; -- 2.30.2