Fixed include file issue in sales order entry.
[fa-stable.git] / sales / includes / cart_class.inc
index 37c16528cc1808f993770e9f5c035b4292bcfaa9..78f8309aaae42bb4debab6a444ec97d569c7e3f1 100644 (file)
@@ -73,13 +73,14 @@ class cart
        var $payment;
        var $payment_terms; // cached payment terms
        var $credit;
-       
        // prepayment mode:
        var $prepaid;           // true for documents issued in prepayment mode
        var $prep_amount;       // prepayment required for SO, invoiced amount for prepaiament invoice
        var $sum_paid;          // sum of all allocated prepayments both to order and related invoices
        var $alloc;             // sum of payments allocated to this document
        var $prepayments = array(); // allocation records for this document
+       var $ex_rate;
+
        //-------------------------------------------------------------------------
        //
        //  $trans_no==0 => open new/direct document
@@ -557,6 +558,40 @@ class cart
                return $total;
        }
 
+       /*
+               Checks cart quantities on document_date.
+               Returns array of stock_ids which stock quantities would go negative on some day.
+       */
+       function check_qoh($date=null, $location=null)
+       {
+               $low_stock = array();
+               // check only for customer delivery and direct sales invoice 
+               if (!($this->trans_type == ST_CUSTDELIVERY || ($this->trans_type == ST_SALESINVOICE && $this->trans_no==0)))
+                       return $low_stock;
+
+               // collect quantities by stock_id
+               $qtys = array();
+               foreach ($this->line_items as $line_no => $line_item)
+               {
+                       if (has_stock_holding($line_item->mb_flag))
+                       {
+                               if (!$this->trans_no) // new delivery
+                                       $qtys[$line_item->stock_id]['qty'] = $line_item->qty_dispatched + @$qtys[$line_item->stock_id]['qty'];
+                               else    // DN modification: check change in quantity
+                                       $qtys[$line_item->stock_id]['qty'] = ($line_item->qty_dispatched-$line_item->qty_old) + @$qtys[$line_item->stock_id]['qty'];
+                               $qtys[$line_item->stock_id]['line'] = $line_no;
+                       }
+               }
+
+               foreach($qtys as $stock_id => $sum)
+               {
+                       if (check_negative_stock($stock_id, -$sum['qty'], $location ? $location : $this->Location, $date ? $date : $this->document_date))
+                               $low_stock[] = $stock_id;
+               }
+
+               return $low_stock;
+       }
+
        /*
                Returns true for documents issued in prepayment cycle.
        */