Bug 5695: Purchase Order Item Description should be saved on the PO line description...
authorJoe <joe.hunt.consulting@gmail.com>
Thu, 27 Apr 2023 15:32:38 +0000 (17:32 +0200)
committerJoe <joe.hunt.consulting@gmail.com>
Thu, 27 Apr 2023 15:32:38 +0000 (17:32 +0200)
purchasing/includes/db/po_db.inc
purchasing/includes/po_class.inc
purchasing/includes/purchasing_db.inc
purchasing/view/view_po.php
reporting/rep209.php

index 23f19a09f582b81b56c8b63ca2df6244ac19a60c..06ce31ffcf59d4d463f79cc33d0c90df16fa0734 100644 (file)
@@ -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 = "";
             }
index c24119d2b9d26bd226e7c149a83a468cfbfb4db5..51f40a8c775b8bb73792b14b50b9a10f0de626f7 100644 (file)
@@ -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;
index 69df53b4a6e4052d4dadbcebcf559d7e76994bdf..28f9c720fa4fbbfd79f225df0582813085ec28be 100644 (file)
@@ -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;
index 38064894344c4230b2e2201f3631189ba9a17ac8..c83d12b3e452d972b436c44bbdc309b492ba98e7 100644 (file)
@@ -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)
 {
 
index 5a08217168009fb8a0c8c933aef3be4daa16bdf5..ce15c150d07595f432bac261ea8d2dd6a975aa00 100644 (file)
@@ -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'];