Fixes in sales reports to use debtor_trans.tax_included field instead of trans_tax_de...
[fa-stable.git] / purchasing / includes / supp_trans_class.inc
index 0647b96fd4e6eeec682da5f3791f9719845efe38..8178d30d1094affee1bf159c88b1058ebdbe7f8f 100644 (file)
@@ -21,7 +21,6 @@ class supp_trans
        var $gl_codes; /*array of objects of class gl_codes using a counter as the pointer */
        var $supplier_id;
        var $supplier_name;
-       var $terms_description;
        var $terms;
        
        var $tax_description;
@@ -29,10 +28,12 @@ class supp_trans
        var $tax_included;
        
        var $trans_type;        // invoice or credit
+       var $trans_no;
 
        var $Comments;
        var $tran_date;
        var $due_date;
+       var $src_docs = array();                // source invoice for this credit note (if any)
 
        var $supp_reference;
        var $reference;
@@ -40,13 +41,32 @@ class supp_trans
        var $ov_discount;
        var $ov_gst;
        var $gl_codes_counter=0;
+       var $credit = 0;
+       var $tax_algorithm;
+       var $stored_algorithm;
+       var $currency;
 
-       function supp_trans($trans_type)
+       function supp_trans($trans_type, $trans_no=0)
        {
                $this->trans_type = $trans_type;
                /*Constructor function initialises a new Supplier Transaction object */
-               $this->grn_items = array();
-               $this->gl_codes = array();
+               $this->read($trans_type, $trans_no);
+       }
+
+       function read($trans_type, $trans_no)
+       {
+               $this->trans_type = $trans_type;
+               $this->trans_no = $trans_no;
+               $this->grn_items = array();
+               $this->gl_codes = array();
+               if ($trans_no) {
+                       read_supp_invoice($trans_no, $trans_type, $this);
+                       if ($trans_type == ST_SUPPCREDIT)
+                       {
+                               $this->src_docs = find_src_invoices($trans_no);
+                       }
+                       read_supplier_details_to_trans($this, $this->supplier_id);
+               }
        }
 
        function add_grn_to_trans($grn_item_id, $po_detail_item, $item_code, $item_description, 
@@ -56,6 +76,7 @@ class supp_trans
                $this->grn_items[$grn_item_id] = new grn_item($grn_item_id, $po_detail_item, 
                        $item_code, $item_description, $qty_recd, $prev_quantity_inv, $this_quantity_inv, 
                        $order_price, $chg_price, $std_cost_unit, $gl_code, $this->tax_included);
+               $this->src_docs = find_src_invoices($this);
                return 1;
        }
 
@@ -114,7 +135,7 @@ class supp_trans
         if ($tax_group_id == null)
                $tax_group_id = $this->tax_group_id;
         $taxes = get_tax_for_items($items, $prices, $shipping_cost, $tax_group_id, 
-               $this->tax_included);
+               $this->tax_included, null, $this->tax_algorithm);
 
 ///////////////// Joe Hunt 2009.08.18
 
@@ -156,7 +177,9 @@ class supp_trans
                }       
                return $total;
     }
-
+       //
+       //      Returns transaction total 
+       //
        function get_items_total()
        {
                $total = 0;
@@ -166,7 +189,7 @@ class supp_trans
 
                foreach ($this->gl_codes as $gl_line)
                {   //////// 2010-10-10 Joe Hunt
-                       if (!is_tax_account($gl_line->gl_code))
+                       if (!is_tax_account($gl_line->gl_code) || $this->tax_included)
                                $total += $gl_line->amount;
                }
                return $total;