Current credit display implemented.
[fa-stable.git] / purchasing / includes / db / invoice_db.inc
index d5c0214799ad8b7ab08219e3748b9aab1a9988f9..57934ae4f0952b909e7feaa506a46605b46de9ed 100644 (file)
@@ -131,11 +131,10 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
 
     $invoice_items_total = $supp_trans->get_total_charged($supp_trans->tax_group_id);
 
-       if ($supp_trans->is_invoice)
-               $trans_type = ST_SUPPINVOICE;
-       else
+       $trans_type = $supp_trans->trans_type;
+       
+       if ($trans_type == ST_SUPPCREDIT)
        {
-               $trans_type = ST_SUPPCREDIT;
                // let's negate everything because it's a credit note
                $invoice_items_total = -$invoice_items_total;
                $tax_total = -$tax_total;
@@ -175,7 +174,7 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
            /*GL Items are straight forward - just do the debit postings to the GL accounts specified -
            the credit is to creditors control act  done later for the total invoice value + tax*/
 
-               if (!$supp_trans->is_invoice)
+               if ($trans_type == ST_SUPPCREDIT)
                        $entered_gl_code->amount = -$entered_gl_code->amount;
 
                $memo_ = $entered_gl_code->memo_;
@@ -186,7 +185,7 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
                        $entered_gl_code->amount, $memo_);
 
                // store tax details if the gl account is a tax account
-               if (!$supp_trans->is_invoice)
+               if ($trans_type == ST_SUPPCREDIT)
                        $entered_gl_code->amount = -$entered_gl_code->amount;
                add_gl_tax_details($entered_gl_code->gl_code, 
                        $trans_type, $invoice_id, $entered_gl_code->amount,
@@ -195,7 +194,7 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
     foreach ($supp_trans->grn_items as $entered_grn)
     {
 
-       if (!$supp_trans->is_invoice)
+       if ($trans_type == ST_SUPPCREDIT)
        {
                        $entered_grn->this_quantity_inv = -$entered_grn->this_quantity_inv;
                        set_grn_item_credited($entered_grn, $supp_trans->supplier_id, $invoice_id, $date_);
@@ -208,7 +207,7 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
                        $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
                        $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);
        // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
-       if($supp_trans->is_invoice)
+       if ($trans_type == ST_SUPPINVOICE)
        {
                $old = update_supp_received_items_for_invoice($entered_grn->id, $entered_grn->po_detail_item,
                        $entered_grn->this_quantity_inv, $entered_grn->chg_price);
@@ -267,7 +266,7 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
        if ($taxitem['Net'] != 0)
        {
 
-               if (!$supp_trans->is_invoice)
+               if ($trans_type == ST_SUPPCREDIT)
                {
                        $taxitem['Net'] = -$taxitem['Net'];
                        $taxitem['Value'] = -$taxitem['Value'];
@@ -277,7 +276,7 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
                                $taxitem['tax_type_id'], $taxitem['rate'], 0, $taxitem['Value'],
                                $taxitem['Net'], $ex_rate, $date_, $supp_trans->supp_reference);
 
-               if (!$supp_trans->is_invoice)
+               if ($trans_type == ST_SUPPCREDIT)
                        $taxitem['Value'] = -$taxitem['Value'];
                $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_,
                        $taxitem['purchasing_gl_code'], 0, 0, $taxitem['Value'],
@@ -384,7 +383,7 @@ function read_supp_invoice($trans_no, $trans_type, &$supp_trans)
                {
                        $supp_trans->add_grn_to_trans($details_row["grn_item_id"], $details_row["po_detail_item_id"], $details_row["stock_id"],
                                        $details_row["description"], 0, 0, $details_row["quantity"], 0, $details_row["FullUnitPrice"],
-                                       false, 0, 0);
+                                       0, 0);
                }
                else
                {