*** empty log message ***
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 8 Dec 2008 11:10:26 +0000 (11:10 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 8 Dec 2008 11:10:26 +0000 (11:10 +0000)
CHANGELOG.txt
purchasing/includes/db/grn_db.inc
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/po_db.inc
purchasing/includes/purchasing_db.inc
purchasing/includes/ui/invoice_ui.inc
reporting/rep209.php

index a5383b192405f32c07bdae815d8ddee57a878c6e..8e73e8cf4f7c1a7d3f4a00675ef3e5146f89e080 100644 (file)
@@ -19,6 +19,15 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+08-Dec-2008 Joe Hunt
+! Better support for purchasing data (automatic updating from PO receive)
+$ /purchasing/includes/db/grn_db.inc
+  /purchasing/includes/db/invoice_db.inc
+  /purchasing/includes/db/po_db.inc
+  /purchasing/includes/ui/invoice_ui.inc
+  /purchasing/includes/purchasing_db.inc
+  /reporting/rep209.php
+
 07-Dec-2008 Janusz Dobrowolski
 + Added list category grouping.
 $ /includes/ui/ui_lists.inc
index 1e080be792fc4bc2d654677e702981c985e9158a..f360a1ff18f3b2735c688ef747756055fe784ea6 100644 (file)
@@ -68,7 +68,9 @@ function add_grn(&$po, $date_, $reference, $location)
                                /*Need to get the standard cost as it is now so we can process GL jorunals later*/
                                $order_line->standard_cost = get_standard_cost($order_line->stock_id);
                        }
-
+                       // added 2008-12-08 Joe Hunt. Update the purchase data table
+                       add_or_update_purchase_data($po->supplier_id, $order_line->stock_id, $order_line->price, 
+                               $order_line->item_description); 
 
                        /*Need to insert a grn item */
 
index ec22b1cb2cdde221fff4f02df3c73ad3e5559fb3..ab76757cc925cdd0654023f742110e6991f452df 100644 (file)
@@ -209,6 +209,9 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
                                // only update the diff (last parameter, adj_only is set to true).
                                $mat_cost = update_average_material_cost($supp_trans->supplier_id, $entered_grn->item_code,
                                        $diff, $entered_grn->this_quantity_inv, $old_date, true);
+                               // added 2008-12-08 Joe Hunt. Update the purchase data table
+                               add_or_update_purchase_data($supp_trans->supplier_id, $entered_grn->item_code, $entered_grn->chg_price); 
+                                       
                                // function just above this
                                $deliveries = get_deliveries_between($entered_grn->item_code, $old_date, $date_);
                                if ($deliveries[0] != 0) // have deliveries been done during the period?
index cb2a1e49cfeca3cd93e2a8af32575a2f5023e415..a442c8b06c03a77dba545181d0f740a1d788382e 100644 (file)
@@ -174,6 +174,14 @@ 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 ($data['suppliers_uom'] != "")
+                               $myrow['units'] = $data['suppliers_uon'];
+               }               
             if (is_null($myrow["units"]))
             {
                        $units = "";
index a33c81b82fff13e404453b4e00888e608f651d2e..e98bd89a5d7b45884014f6b37d840b9a0b5e31ed 100644 (file)
@@ -55,5 +55,36 @@ function get_purchase_price($supplier_id, $stock_id)
 
 //----------------------------------------------------------------------------------------
 
+function get_purchase_data($supplier_id, $stock_id)
+{
+       $sql = "SELECT * FROM ".TB_PREF."purch_data 
+               WHERE supplier_id = '" . $supplier_id . "' 
+               AND stock_id = '". $stock_id . "'";
+       $result = db_query($sql, "The supplier pricing details for " . $stock_id . " could not be retrieved");    
+
+       return db_fetch($result);
+}
+
+function add_or_update_purchase_data($supplier_id, $stock_id, $price, $description="", $uom="")
+{
+       $data = get_purchase_data($supplier_id, $stock_id);
+       if ($data === false)
+       {
+               $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
+                       conversion_factor, supplier_description) VALUES ('$supplier_id', '$stock_id', 
+                       $price, '$uom', 1, '$description')";
+               db_query($sql,"The supplier purchasing details could not be added");
+               return;
+       }       
+       $price = round($price * $data['conversion_factor'], user_price_dec());  
+       $sql = "UPDATE ".TB_PREF."purch_data SET price=$price";
+       if ($uom != "")
+               $sql .= ",suppliers_uom='$uom'";
+       if ($description != "") 
+               $sql .= ",supplier_description='$description'";
+       $sql .= " WHERE stock_id='$stock_id' AND supplier_id='$supplier_id'";
+       db_query($sql,"The supplier purchasing details could not be updated");
+       return true;
+}
 
 ?>
\ No newline at end of file
index 1f6193b1fe6570c02f63c071cfd2b3695624cb5e..07f0d0e9bb78ba62a7a9df9b32be1844252a2b08 100644 (file)
@@ -392,10 +392,11 @@ function display_grn_items(&$supp_trans, $mode=0)
        {
                if ($heading2 != "")
                {
+                       //br();
                        display_note($heading2, 0, 0, "class='overduefg'");
-                       echo "</td>";
                }       
-               submit_cells('InvGRNAll', _("Add All Items"), "align=right",false,true);
+               echo "</td><td align='right'>";
+               submit('InvGRNAll', _("Add All Items"), true, false,true);
        }       
 
        end_outer_table(0, false);
index cc3d93bafc430b1d34572c3b1a34cbffe35a3f63..b59ca1ad8689f1f6a479a05e922c6397176af883 100644 (file)
@@ -103,6 +103,19 @@ function print_po()
                $SubTotal = 0;
                while ($myrow2=db_fetch($result))
                {
+                       $data = get_purchase_data($myrow['supplier_id'], $myrow2['item_code']);
+                       if ($data !== false)
+                       {
+                               if ($data['supplier_description'] != "")
+                                       $myrow2['description'] = $data['supplier_description'];
+                               if ($data['suppliers_uom'] != "")
+                                       $myrow2['units'] = $data['suppliers_uom'];
+                               if ($data['conversion_factor'] != 1)
+                               {
+                                       $myrow2['unit_price'] = round($myrow2['unit_price'] / $data['conversion_factor'], user_price_dec());
+                                       $myrow2['quantiry_ordered'] = round($myrow2['quantiry_ordered'] / $data['conversion_factor'], user_qty_dec());
+                               }
+                       }       
                        $Net = round(($myrow2["unit_price"] * $myrow2["quantity_ordered"]),
                          user_price_dec());
                        $SubTotal += $Net;