Added Direct GRN and Direct invice in Purchases module.
[fa-stable.git] / purchasing / includes / db / grn_db.inc
index b055c1f94eb8b14a955b9f8afa302d9eaf04303a..54134532d0c134afb54455d79ff4174321e7a09c 100644 (file)
@@ -21,7 +21,7 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date,
        $price = price_decimal_format($price, $dec);
        if ($currency != null)
        {
-               $ex_rate = get_exchange_rate_to_home_currency($currency, $date_);
+               $ex_rate = get_exchange_rate_to_home_currency($currency, $date);
                $price_in_home_currency = $price / $ex_rate;
                //$price_in_home_currency = to_home_currency($price, $currency, $date);
        }       
@@ -63,15 +63,17 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date,
 
 //-------------------------------------------------------------------------------------------------------------
 
-function add_grn(&$po, $date_, $reference, $location)
+function add_grn(&$po)
 {
        global $Refs;
 
+       $date_ = $po->orig_order_date;
+
        begin_transaction();
 
-       $grn = add_grn_batch($po->order_no, $po->supplier_id, $reference, $location, $date_);
+       $grn = add_grn_batch($po->order_no, $po->supplier_id, $po->reference, $po->Location, $date_);
 
-       foreach ($po->line_items as $order_line)
+       foreach ($po->line_items as $line_no => $order_line)
        {
 
                if ($order_line->receive_qty != 0 && $order_line->receive_qty != "" && isset($order_line->receive_qty))
@@ -98,15 +100,16 @@ function add_grn(&$po, $date_, $reference, $location)
                                $order_line->stock_id, $order_line->item_description,
                                $order_line->standard_cost,     $order_line->receive_qty, $order_line->price);
 
+                       $po->line_items[$line_no]->grn_item_id = $grn_item;
                        /* Update location stock records - NB  a po cannot be entered for a service/kit parts */
-            add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $location, $date_, "",
+            add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $po->Location, $date_, "",
                $order_line->receive_qty, $order_line->standard_cost,
                $po->supplier_id, 1, $order_line->price);
 
                } /*quantity received is != 0 */
        } /*end of order_line loop */
 
-       $Refs->save(ST_SUPPRECEIVE, $grn, $reference);
+       $Refs->save(ST_SUPPRECEIVE, $grn, $po->reference);
 
        add_audit_trail(ST_SUPPRECEIVE, $grn, $date_);