Dimension wise balance sheet items (A/C Payable and Receivables) implemented.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 11 Aug 2020 22:12:04 +0000 (00:12 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 11 Aug 2020 22:12:04 +0000 (00:12 +0200)
gl/includes/db/gl_db_banking.inc
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/supp_payment_db.inc
purchasing/includes/purchasing_db.inc
purchasing/supplier_payment.php
sales/customer_payments.php
sales/includes/db/payment_db.inc
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_invoice_db.inc

index a7ad5576093a7f8501f923cf71f59e015d5029d0..ac29552b647f7aaac96536dd79beaaacf1f048c4 100644 (file)
@@ -507,7 +507,7 @@ function write_bank_transaction($trans_type, $trans_no, $from_account, $items, $
        }
 
        // do the source account postings
-    add_gl_trans($trans_type, $trans_no, $date_, $bank_gl_account, 0, 0, $memo_,
+    add_gl_trans($trans_type, $trans_no, $date_, $bank_gl_account, $gl_item->dimension_id, $gl_item->dimension2_id, $memo_,
        -$total, null, $person_type_id, $person_id);
 
     if ($do_exchange_variance)
index 0a7f360b647af2638404c59b4d0347aded6f0de5..06d5c8779a207b0f3ce0ca551e3a3d0b6b5be56b 100644 (file)
@@ -131,6 +131,10 @@ function add_supp_invoice(&$supp_trans)
        $trans_no = $supp_trans->trans_no;
        $trans_type = $supp_trans->trans_type;
        $supplier = get_supplier($supp_trans->supplier_id);
+    $dim = !empty($supp_trans->dimension) ? $supp_trans->dimension :
+        ($supplier['dimension_id'] ? $supplier['dimension_id'] : 0);
+    $dim2 = !empty($supp_trans->dimension2) ? $supp_trans->dimension2 :
+        ($supplier['dimension2_id'] ? $supplier['dimension2_id'] : 0);
 
        begin_transaction();
        hook_db_prewrite($supp_trans, $trans_type);
@@ -209,7 +213,7 @@ function add_supp_invoice(&$supp_trans)
                                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'],
+                                       $taxitem['purchasing_gl_code'], $dim, $dim2, $taxitem['Value'],
                                        $supp_trans->supplier_id,
                                        "A general ledger transaction for the tax amount could not be added");
                        }
@@ -219,7 +223,7 @@ function add_supp_invoice(&$supp_trans)
                $net_diff = -$net_diff;
 
     /* Now the AP account */
-    $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $supplier["payable_account"], 0, 0,
+    $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $supplier["payable_account"], $dim, $dim2,
                -($invoice_items_total +  $item_added_tax + $supp_trans->ov_discount),
                $supp_trans->supplier_id,
                "The general ledger transaction for the control total could not be added");
index 8cbc4413dc41573a19f3a780b6f429055feea6dd..70119577135d6db66ef09b03500e1d0af96dec58 100644 (file)
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
 function write_supp_payment($trans_no, $supplier_id, $bank_account,
-       $date_, $ref, $supp_amount, $supp_discount, $memo_, $bank_charge=0, $bank_amount=0)
+       $date_, $ref, $supp_amount, $supp_discount, $memo_, $bank_charge=0, $bank_amount=0, $dimension=0, $dimension2=0)
 {
        global $Refs;
 
        begin_transaction();
-       $args = func_get_args(); while (count($args) < 10) $args[] = 0;
+       $args = func_get_args(); while (count($args) < 12) $args[] = 0;
        $args = (object)array_combine(array('trans_no', 'supplier_id', 'bank_account', 'date_',
-                'ref', 'bank_amount', 'supp_amount', 'supp_discount', 'memo_', 'bank_charge'), $args);
+                'ref', 'supp_amount', 'supp_discount', 'memo_', 'bank_charge', 'bank_amount', 'dimension', 'dimension2'), $args);
        $args->trans_no = 0;
        hook_db_prewrite( $args, ST_SUPPAYMENT);
 
@@ -50,31 +50,31 @@ function write_supp_payment($trans_no, $supplier_id, $bank_account,
 
        $total = 0;
     $supplier_accounts = get_supplier_accounts($supplier_id);
-       $total += add_gl_trans_supplier(ST_SUPPAYMENT, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0,
+       $total += add_gl_trans_supplier(ST_SUPPAYMENT, $payment_id, $date_, $supplier_accounts["payable_account"], $dimension, $dimension2,
                $supp_amount + $supp_discount, $supplier_id, "", $rate);
 
        // Now credit discount received account with discounts
        if ($supp_discount != 0)
        {
-               $total += add_gl_trans_supplier(ST_SUPPAYMENT, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
+               $total += add_gl_trans_supplier(ST_SUPPAYMENT, $payment_id, $date_, $supplier_accounts["payment_discount_account"], $dimension, $dimension2,
                        -$supp_discount, $supplier_id, "", $rate);
        }
 
        if ($bank_charge != 0)
        {
                $charge_act = get_company_pref('bank_charge_act');
-               $total += add_gl_trans(ST_SUPPAYMENT, $payment_id, $date_, $charge_act, 0, 0, '',
+               $total += add_gl_trans(ST_SUPPAYMENT, $payment_id, $date_, $charge_act, $dimension, $dimension2, '',
                        $bank_charge, $bank['bank_curr_code']);
        }
 
-       $total += add_gl_trans(ST_SUPPAYMENT, $payment_id, $date_, $bank['account_code'], 0, 0, '',
+       $total += add_gl_trans(ST_SUPPAYMENT, $payment_id, $date_, $bank['account_code'], $dimension, $dimension2, '',
                -($bank_amount + $bank_charge), $bank['bank_curr_code'], PT_SUPPLIER, $supplier_id);
 
        /*Post a balance post if $total != 0 due to variance in AP and bank posted values*/
        if ($total != 0)
        {
                $variance_act = get_company_pref('exchange_diff_act');
-               add_gl_trans(ST_SUPPAYMENT, $payment_id, $date_, $variance_act, 0, 0, '',
+               add_gl_trans(ST_SUPPAYMENT, $payment_id, $date_, $variance_act, $dimension, $dimension2, '',
                        -$total, null, PT_SUPPLIER,  $supplier_id);
        }
 
index 89c4d94b4d5097803047f44bd5bef820f9344985..fe174800d495ebfbf19e2c0ee5dc07df44c7973f 100644 (file)
@@ -213,7 +213,7 @@ function add_direct_supp_trans($cart)
 
        if ($cart->cash_account) {
                $pmt_no = write_supp_payment(0, $inv->supplier_id, $cart->cash_account, $inv->tran_date, $Refs->get_next(ST_SUPPAYMENT, null, $inv->tran_date), 
-                       $total, 0, _('Payment for:').$inv->supp_reference .' ('.$type_shortcuts[ST_SUPPINVOICE].$inv_no.')');
+                       $total, 0, _('Payment for:').$inv->supp_reference .' ('.$type_shortcuts[ST_SUPPINVOICE].$inv_no.')' . ' ' . $cart->Comments, $cart->dimension, $cart->dimension2);
                add_supp_allocation($total, ST_SUPPAYMENT, $pmt_no, ST_SUPPINVOICE, $inv_no, $inv->supplier_id, $inv->tran_date);
                update_supp_trans_allocation(ST_SUPPINVOICE, $inv_no, $inv->supplier_id);
                update_supp_trans_allocation(ST_SUPPAYMENT, $pmt_no, $inv->supplier_id);
index c7bedf4dcd16502bd153c201a98e839283b28335..45fb163e618ed0a681bae2f6921ba5b8dda269ff 100644 (file)
@@ -234,7 +234,7 @@ function handle_add_payment()
 {
        $payment_id = write_supp_payment(0, $_POST['supplier_id'], $_POST['bank_account'],
                $_POST['DatePaid'], $_POST['ref'], input_num('amount'), input_num('discount'), $_POST['memo_'], 
-               input_num('charge'), input_num('bank_amount', input_num('amount')));
+               input_num('charge'), input_num('bank_amount', input_num('amount')), $_POST['dimension_id'], $_POST['dimension2_id']);
        new_doc_date($_POST['DatePaid']);
 
        $_SESSION['alloc']->trans_no = $payment_id;
@@ -318,6 +318,20 @@ start_form();
 
        amount_row(_("Bank Charge:"), 'charge', null, '', $bank_currency);
 
+       $row = get_supplier($_POST['supplier_id']);
+       $_POST['dimension_id'] = $row['dimension_id'];
+       $_POST['dimension2_id'] = $row['dimension2_id'];
+       $dim = get_company_pref('use_dimension');
+       if ($dim > 0)
+               dimensions_list_row(_("Dimension").":", 'dimension_id',
+                       null, true, ' ', false, 1, false);
+       else
+               hidden('dimension_id', 0);
+       if ($dim > 1)
+               dimensions_list_row(_("Dimension")." 2:", 'dimension2_id',
+                       null, true, ' ', false, 2, false);
+       else
+               hidden('dimension2_id', 0);
 
        end_outer_table(1);
 
index 907f789eca8499fd7dd1e9014fe0be406779c6b4..25f3b3f8090ce1aa6ec73c5ad71ba8ca8b5b6311 100644 (file)
@@ -241,7 +241,7 @@ if (get_post('AddPaymentItem') && can_process()) {
        //Chaitanya : 13-OCT-2011 - To support Edit feature
        $payment_no = write_customer_payment($_SESSION['alloc']->trans_no, $_POST['customer_id'], $_POST['BranchID'],
                $_POST['bank_account'], $_POST['DateBanked'], $_POST['ref'],
-               input_num('amount'), input_num('discount'), $_POST['memo_'], 0, input_num('charge'), input_num('bank_amount', input_num('amount')));
+                input_num('amount'), input_num('discount'), $_POST['memo_'], 0, input_num('charge'), input_num('bank_amount', input_num('amount')), $_POST['dimension_id'], $_POST['dimension2_id']);
 
        $_SESSION['alloc']->trans_no = $payment_no;
        $_SESSION['alloc']->date_ = $_POST['DateBanked'];
@@ -365,6 +365,21 @@ if ($cust_currency != $bank_currency)
 
 amount_row(_("Bank Charge:"), 'charge', null, '', $bank_currency);
 
+$row = get_customer($_POST['customer_id']);
+$_POST['dimension_id'] = $row['dimension_id'];
+$_POST['dimension2_id'] = $row['dimension2_id'];
+$dim = get_company_pref('use_dimension');
+if ($dim > 0)
+    dimensions_list_row(_("Dimension").":", 'dimension_id',
+        null, true, ' ', false, 1, false);
+else
+    hidden('dimension_id', 0);
+if ($dim > 1)
+    dimensions_list_row(_("Dimension")." 2:", 'dimension2_id',
+        null, true, ' ', false, 2, false);
+else
+    hidden('dimension2_id', 0);
+
 end_outer_table(1);
 
 div_start('alloc_tbl');
index 766648533351281e718ebcde127902624c4722e8..e15318666d254c2beeda87d99f546af63b22e691 100644 (file)
        $charge - in bank currency
 */
 function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_account,
-       $date_, $ref, $amount, $discount, $memo_, $rate=0, $charge=0, $bank_amount=0)
+       $date_, $ref, $amount, $discount, $memo_, $rate=0, $charge=0, $bank_amount=0, $dim1=0, $dim2=0)
 {
        global $Refs;
 
        begin_transaction();
-       $args = func_get_args(); while (count($args) < 12) $args[] = 0;
+       $args = func_get_args(); while (count($args) < 14) $args[] = 0;
        $args = (object)array_combine(array('trans_no', 'customer_id', 'branch_id', 'bank_account', 
-               'date_', 'ref', 'amount', 'discount', 'memo_','rate','charge', 'bank_amount'), $args);
+               'date_', 'ref', 'amount', 'discount', 'memo_','rate','charge', 'bank_amount', 'dim1', 'dim2'), $args);
        hook_db_prewrite($args, ST_CUSTPAYMENT);
 
        $company_record = get_company_prefs();
@@ -61,7 +61,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
 
        /* Bank account entry first */
        $total += add_gl_trans(ST_CUSTPAYMENT, $payment_no, $date_,
-               $bank_gl_account, 0, 0, '', ($bank_amount - $charge),  $bank['bank_curr_code'], PT_CUSTOMER, $customer_id);
+               $bank_gl_account, $dim1, $dim2, '', ($bank_amount - $charge),  $bank['bank_curr_code'], PT_CUSTOMER, $customer_id);
 
        if ($branch_id != ANY_NUMERIC) {
 
@@ -78,20 +78,20 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
        if (($discount + $amount) != 0) {
        /* Now Credit Debtors account with receipts + discounts */
        $total += add_gl_trans_customer(ST_CUSTPAYMENT, $payment_no, $date_,
-               $debtors_account, 0, 0, -($discount + $amount), $customer_id,
+               $debtors_account, $dim1, $dim2, -($discount + $amount), $customer_id,
                "Cannot insert a GL transaction for the debtors account credit");
        }
        if ($discount != 0)     {
                /* Now Debit discount account with discounts allowed*/
                $total += add_gl_trans_customer(ST_CUSTPAYMENT, $payment_no, $date_,
-                       $discount_account, 0, 0, $discount, $customer_id,
+                       $discount_account, $dim1, $dim2, $discount, $customer_id,
                        "Cannot insert a GL transaction for the payment discount debit");
        }
 
        if ($charge != 0)       {
                /* Now Debit bank charge account with charges */
                $charge_act = get_bank_charge_account($bank_account);
-               $total += add_gl_trans(ST_CUSTPAYMENT, $payment_no, $date_,     $charge_act, 0, 0, '', 
+               $total += add_gl_trans(ST_CUSTPAYMENT, $payment_no, $date_,     $charge_act, $dim1, $dim2, '', 
                        $charge, $bank['bank_curr_code'], PT_CUSTOMER,  $customer_id);
        }
 
@@ -100,7 +100,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
        if ($total != 0)
        {
                $variance_act = get_company_pref('exchange_diff_act');
-               add_gl_trans(ST_CUSTPAYMENT, $payment_no, $date_,       $variance_act, 0, 0, '',
+               add_gl_trans(ST_CUSTPAYMENT, $payment_no, $date_,       $variance_act, $dim1, $dim2, '',
                        -$total, null, PT_CUSTOMER,  $customer_id);
        }
 
index 171c0a7e86a78711039b5c73443d8237966a8998..0bdbf7072f2239c0bb5175c3f6d9a6265be5d24f 100644 (file)
@@ -134,14 +134,14 @@ function write_credit_note(&$credit_note, $write_off_acc)
 
        if (($credit_note_total + $credit_note->freight_cost) != 0) {
 
-               $total += add_gl_trans_customer(ST_CUSTCREDIT, $credit_no, $credit_date, $branch_data["receivables_account"], 0, 0,
+               $total += add_gl_trans_customer(ST_CUSTCREDIT, $credit_no, $credit_date, $branch_data["receivables_account"], $credit_note->dimension_id, $credit_note->dimension2_id,
                        -($credit_note_total + $credit_note->freight_cost + $items_added_tax + $freight_added_tax),
                        $credit_note->customer_id,
                        "The total debtor GL posting for the credit note could not be inserted");
        }
 
        if ($credit_note->freight_cost != 0) {
-               $total += add_gl_trans_customer(ST_CUSTCREDIT, $credit_no, $credit_date, $company_data["freight_act"], 0, 0,
+               $total += add_gl_trans_customer(ST_CUSTCREDIT, $credit_no, $credit_date, $company_data["freight_act"], $credit_note->dimension_id, $credit_note->dimension2_id,
                        $credit_note->get_tax_free_shipping(), $credit_note->customer_id,
                        "The freight GL posting for this credit note could not be inserted");
        }
@@ -154,8 +154,9 @@ function write_credit_note(&$credit_note, $write_off_acc)
                                $taxitem['rate'], $credit_note->tax_included, $taxitem['Value'],
                                $taxitem['Net'], $ex_rate,
                                $credit_note->document_date, $credit_note->reference, TR_OUTPUT);
-
-                       $total += add_gl_trans_customer(ST_CUSTCREDIT, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0,
+            // sales_gl_code is not set for taxexempt
+            if (isset($taxitem['sales_gl_code']))
+                               $total += add_gl_trans_customer(ST_CUSTCREDIT, $credit_no, $credit_date, $taxitem['sales_gl_code'], $credit_note->dimension_id, $credit_note->dimension2_id,
                                $taxitem['Value'], $credit_note->customer_id,
                                "A tax GL posting for this credit note could not be inserted");
                }
index b858652e98cefd07c3582ca84c015c40215ab986..c17e9214e361e936664bbdf93a68c736765d4edc 100644 (file)
@@ -158,14 +158,14 @@ function write_sales_invoice(&$invoice)
        } /*end of delivery_line loop */
 
        if (($items_total + $charge_shipping) != 0) {
-               $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0,
+               $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $branch_data["receivables_account"], $invoice->dimension_id, $invoice->dimension2_id,
                        ($items_total + $charge_shipping + $items_added_tax + $freight_added_tax)*$prepaid_factor,
                        $invoice->customer_id, "The total debtor GL posting could not be inserted");
        }
        $to_allocate = ($items_total + $charge_shipping + $items_added_tax + $freight_added_tax);
 
        if ($charge_shipping != 0) {
-               $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $company_data["freight_act"], 0, 0,
+               $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $company_data["freight_act"], $invoice->dimension_id, $invoice->dimension2_id,
                        -$invoice->get_tax_free_shipping()*$prepaid_factor, $invoice->customer_id,
                        "The freight GL posting could not be inserted");
        }
@@ -177,7 +177,7 @@ function write_sales_invoice(&$invoice)
                                $taxitem['rate'], $invoice->tax_included, $prepaid_factor*$taxitem['Value'],
                                 $taxitem['Net'], $ex_rate, $date_, $invoice->reference, TR_OUTPUT);
                        if (isset($taxitem['sales_gl_code']) && !empty($taxitem['sales_gl_code']) && $taxitem['Value'] != 0)
-                               $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
+                               $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $taxitem['sales_gl_code'], $invoice->dimension_id, $invoice->dimension2_id,
                                        (-$taxitem['Value'])*$prepaid_factor, $invoice->customer_id,
                                        "A tax GL posting could not be inserted");
                }
@@ -198,12 +198,15 @@ function write_sales_invoice(&$invoice)
                                // extend invoice entry page with final amount after discount 
                                // and change line below.
                                $discount = 0; // $invoice->cash_discount*$amount;
+                               $payment_info = $invoice->pos['pos_name'].' #'.$invoice_no;
+                               if (!empty($invoice->payment_info))
+                                       $payment_info .= ' ' . $invoice->payment_info;
                                $pmtno = write_customer_payment(0, $invoice->customer_id, 
                                        $invoice->Branch, $invoice->pos['pos_account'], $date_,
                                        $Refs->get_next(ST_CUSTPAYMENT, null, array('customer' => $invoice->customer_id,
                                                'branch' => $invoice->Branch, 'date' => $date_)),
-                                       $amount-$discount, $discount,
-                                       $invoice->pos['pos_name'].' #'.$invoice_no);
+                                       $amount-$discount, $discount, $payment_info,
+                                       0,0,0,$invoice->dimension_id, $invoice->dimension2_id);
                                add_cust_allocation($amount, ST_CUSTPAYMENT, $pmtno, ST_SALESINVOICE, $invoice_no, $invoice->customer_id, $date_);
 
                                update_debtor_trans_allocation(ST_SALESINVOICE, $invoice_no, $invoice->customer_id);