is_invoice => trans_type
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 13 Jun 2010 18:40:59 +0000 (18:40 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 13 Jun 2010 18:40:59 +0000 (18:40 +0000)
purchasing/includes/db/invoice_db.inc
purchasing/includes/supp_trans_class.inc
purchasing/includes/ui/invoice_ui.inc
purchasing/view/view_supp_credit.php
purchasing/view/view_supp_invoice.php

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
                {
index d5f7508410f8222b35f6186ed76207ed1f7a623b..0870f07487eb39496a43c05608772dd16821acce 100644 (file)
@@ -27,7 +27,7 @@ class supp_trans
        var $tax_description;
        var $tax_group_id;
        
-       var $is_invoice;
+       var $trans_type;        // invoice or credit
 
        var $Comments;
        var $tran_date;
@@ -40,8 +40,9 @@ class supp_trans
        var $ov_gst;
        var $gl_codes_counter=0;
 
-       function supp_trans()
+       function supp_trans($trans_type)
        {
+               $this->trans_type = $trans_type;
                /*Constructor function initialises a new Supplier Transaction object */
                $this->grn_items = array();
                $this->gl_codes = array();
@@ -49,11 +50,11 @@ class supp_trans
 
        function add_grn_to_trans($grn_item_id, $po_detail_item, $item_code, $item_description, 
                $qty_recd, $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price, 
-               $Complete, $std_cost_unit, $gl_code)
+               $std_cost_unit, $gl_code)
        {
                $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, $Complete, $std_cost_unit, $gl_code);
+                       $order_price, $chg_price, $std_cost_unit, $gl_code);
                return 1;
        }
 
@@ -169,12 +170,11 @@ all the info to do the necessary entries without looking up ie additional querie
        var $this_quantity_inv;
        var $order_price;
        var $chg_price;
-       var $Complete;
        var $std_cost_unit;
        var $gl_code;
 
        function grn_item ($id, $po_detail_item, $item_code, $item_description, $qty_recd, 
-               $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price, $Complete, 
+               $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price,
                $std_cost_unit, $gl_code)
        {
 
@@ -187,7 +187,6 @@ all the info to do the necessary entries without looking up ie additional querie
                $this->this_quantity_inv = $this_quantity_inv;
                $this->order_price =$order_price;
                $this->chg_price = $chg_price;
-               $this->Complete = $Complete;
                $this->std_cost_unit = $std_cost_unit;
                $this->gl_code = $gl_code;
        }
index b3957fd8cf66bf3f46e6ee780b9ddecdee41d1bb..0694cdaed82828180523bfb153d982fc5a12362a 100644 (file)
@@ -89,10 +89,7 @@ function invoice_header(&$supp_trans)
                copy_from_trans($supp_trans);
        }
 
-       if ($supp_trans->is_invoice)
-       ref_row(_("Reference:"), 'reference', '', $Refs->get_next(ST_SUPPINVOICE));
-    else
-       ref_row(_("Reference:"), 'reference', '', $Refs->get_next(ST_SUPPCREDIT));
+       ref_row(_("Reference:"), 'reference', '', $Refs->get_next($supp_trans->trans_type));
 
        if (isset($_POST['invoice_no']))
        {
@@ -151,8 +148,9 @@ function invoice_totals(&$supp_trans)
 
     $display_total = price_format($supp_trans->ov_amount + $tax_total);
 
-       if ($supp_trans->is_invoice)
-       label_row(_("Invoice Total:"), $display_total, "colspan=$colspan align=right style='font-weight:bold;'", "align=right style='font-weight:bold;'");
+       if ($supp_trans->trans_type == ST_SUPPINVOICE)
+       label_row(_("Invoice Total:"), 
+               $display_total, "colspan=$colspan align=right style='font-weight:bold;'", "align=right style='font-weight:bold;'");
     else
                label_row(_("Credit Note Total"),
                        $display_total, "colspan=$colspan align=right style='font-weight:bold;color:red;'", "nowrap align=right style='font-weight:bold;color:red;'");
@@ -203,7 +201,7 @@ function display_gl_items(&$supp_trans, $mode=0)
     if (($mode == 2 || $mode == 3) && count($supp_trans->gl_codes) == 0)
        return 0;
 
-       if ($supp_trans->is_invoice)
+       if ($supp_trans->trans_type == ST_SUPPINVOICE)
                $heading = _("GL Items for this Invoice");
        else
                $heading = _("GL Items for this Credit Note");
@@ -316,7 +314,7 @@ function display_gl_items(&$supp_trans, $mode=0)
 
 function display_grn_items_for_selection(&$supp_trans, $k)
 {
-       if ($supp_trans->is_invoice)
+       if ($supp_trans->trans_type == ST_SUPPINVOICE)
                $result = get_grn_items(0, $supp_trans->supplier_id, true);
        else
        {
@@ -367,7 +365,7 @@ function display_grn_items_for_selection(&$supp_trans, $k)
             $dec = get_qty_dec($myrow["item_code"]);
             qty_cell($myrow["qty_recd"], false, $dec);
             qty_cell($myrow["quantity_inv"], false, $dec);
-            if ($supp_trans->is_invoice)
+            if ($supp_trans->trans_type == ST_SUPPINVOICE)
                qty_cells(null, 'this_quantity_inv'.$n, number_format2($myrow["qty_recd"] - $myrow["quantity_inv"], $dec), 
                        null, null, $dec);
             else               
@@ -375,15 +373,15 @@ function display_grn_items_for_selection(&$supp_trans, $k)
                        null, null, $dec);
             $dec2 = 0;                 
             amount_cells(null, 'ChgPrice'.$n, price_decimal_format($myrow["unit_price"], $dec2), null, null, $dec2);
-            if ($supp_trans->is_invoice)
+            if ($supp_trans->trans_type == ST_SUPPINVOICE)
                amount_cell(round2($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]), user_price_dec()));
             else       
                amount_cell(round2($myrow["unit_price"] * max($myrow['quantity_inv'], 0), user_price_dec()));
-            if ($supp_trans->is_invoice)       
+            if ($supp_trans->trans_type == ST_SUPPINVOICE)
                        submit_cells('grn_item_id'.$n, _("Add"), '', _("Add to Invoice"), true);
                else    
                        submit_cells('grn_item_id'.$n, _("Add"), '', _("Add to Credit Note"), true);
-               if ($supp_trans->is_invoice && $_SESSION["wa_current_user"]->can_access('SA_GRNDELETE')) {      // Added 2008-10-18 by Joe Hunt. Special access rights needed.
+               if (($supp_trans->trans_type == ST_SUPPINVOICE) && $_SESSION["wa_current_user"]->can_access('SA_GRNDELETE')) {  // Added 2008-10-18 by Joe Hunt. Special access rights needed.
                        submit_cells('void_item_id'.$n, _("Remove"), '', _("WARNING! Be careful with removal. The operation is executed immediately and cannot be undone !!!"), true);
                                submit_js_confirm('void_item_id'.$n,
                                        sprintf(_('You are about to remove all yet non-invoiced items from delivery line #%d. This operation also irreversibly changes related order line. Do you want to continue ?'), $n));
@@ -415,7 +413,7 @@ function display_grn_items(&$supp_trans, $mode=0)
        $heading2 = "";
        if ($mode == 1)
        {
-               if ($supp_trans->is_invoice)
+               if ($supp_trans->trans_type == ST_SUPPINVOICE)
                {
                        $heading = _("Items Received Yet to be Invoiced");
                if ($_SESSION["wa_current_user"]->can_access('SA_GRNDELETE'))   // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
@@ -426,7 +424,7 @@ function display_grn_items(&$supp_trans, $mode=0)
        }
        else
        {
-               if ($supp_trans->is_invoice)
+               if ($supp_trans->trans_type == ST_SUPPINVOICE)
                        $heading = _("Received Items Charged on this Invoice");
                else
                        $heading = _("Received Items Credited on this Note");
@@ -436,7 +434,7 @@ function display_grn_items(&$supp_trans, $mode=0)
 
        if ($mode == 1)
        {
-               if (!$supp_trans->is_invoice && !isset($_POST['invoice_no']))
+               if ($supp_trans->trans_type == ST_SUPPCREDIT && !isset($_POST['invoice_no']))
                {
                        echo "</td>";
                        date_cells(_("Received between"), 'receive_begin', "", null, -30, 0, 0, "valign=middle");
@@ -462,9 +460,9 @@ function display_grn_items(&$supp_trans, $mode=0)
        $th = array(_("Delivery"), _("Sequence #"), _("P.O."), _("Item"), _("Description"),
                _("Received On"), _("Quantity Received"), _("Quantity Invoiced"),
                _("Qty Yet To Invoice"), _("Order Price"), _("Total"), "");
-       if ($supp_trans->is_invoice && $_SESSION["wa_current_user"]->can_access('SA_GRNDELETE'))        // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
+       if (($supp_trans->trans_type == ST_SUPPINVOICE) && $_SESSION["wa_current_user"]->can_access('SA_GRNDELETE'))    // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
                $th[] = "";
-               if (!$supp_trans->is_invoice)
+               if ($supp_trans->trans_type == ST_SUPPCREDIT)
                {
                        $th[8] = _("Qty Yet To Credit");
                }
@@ -508,7 +506,7 @@ function display_grn_items(&$supp_trans, $mode=0)
                        if ($mode == 1)
                        {
                                delete_button_cell("Delete" . $entered_grn->id, _("Edit"), _('Edit document line'));
-                               if ($supp_trans->is_invoice && $_SESSION["wa_current_user"]->can_access('SA_GRNDELETE'))          
+                               if (($supp_trans->trans_type == ST_SUPPINVOICE) && $_SESSION["wa_current_user"]->can_access('SA_GRNDELETE'))      
                                        label_cell("");
                        }       
                        end_row();
@@ -537,7 +535,7 @@ function display_grn_items(&$supp_trans, $mode=0)
        {
                start_row();
                echo "<td colspan=".($colspan + 1).">";
-               if ($supp_trans->is_invoice)
+               if ($supp_trans->trans_type == ST_SUPPINVOICE)
                        display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 0);
                else
                {
index 5c8ec92fc9cf057ea5c5810536b0ce8dd8d4bfb2..ec5cb40b20fd92ba764c3b5dd4dc98a7ad3da198 100644 (file)
@@ -31,8 +31,7 @@ elseif (isset($_POST["trans_no"]))
        $trans_no = $_POST["trans_no"];
 }
 
-$supp_trans = new supp_trans();
-$supp_trans->is_invoice = false;
+$supp_trans = new supp_trans(ST_SUPPCREDIT);
 
 read_supp_invoice($trans_no, ST_SUPPCREDIT, $supp_trans);
 
index 0aa672fe9e88bd05c5215c6baf33fc3a66b7fbe0..b13ef4160dca923e95bb2d263f7dbf47a8a8f9f5 100644 (file)
@@ -31,8 +31,7 @@ elseif (isset($_POST["trans_no"]))
        $trans_no = $_POST["trans_no"];
 }
 
-$supp_trans = new supp_trans();
-$supp_trans->is_invoice = true;
+$supp_trans = new supp_trans(ST_SUPPINVOICE);
 
 read_supp_invoice($trans_no, ST_SUPPINVOICE, $supp_trans);