From: Joe Hunt Date: Tue, 11 Aug 2020 22:12:04 +0000 (+0200) Subject: Dimension wise balance sheet items (A/C Payable and Receivables) implemented. X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=b2a9c105e368f6e4fdb35477665edeff13fb574b Dimension wise balance sheet items (A/C Payable and Receivables) implemented. --- diff --git a/gl/includes/db/gl_db_banking.inc b/gl/includes/db/gl_db_banking.inc index a7ad5576..ac29552b 100644 --- a/gl/includes/db/gl_db_banking.inc +++ b/gl/includes/db/gl_db_banking.inc @@ -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) diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 0a7f360b..06d5c877 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -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"); diff --git a/purchasing/includes/db/supp_payment_db.inc b/purchasing/includes/db/supp_payment_db.inc index 8cbc4413..70119577 100644 --- a/purchasing/includes/db/supp_payment_db.inc +++ b/purchasing/includes/db/supp_payment_db.inc @@ -10,14 +10,14 @@ See the License here . ***********************************************************************/ 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); } diff --git a/purchasing/includes/purchasing_db.inc b/purchasing/includes/purchasing_db.inc index 89c4d94b..fe174800 100644 --- a/purchasing/includes/purchasing_db.inc +++ b/purchasing/includes/purchasing_db.inc @@ -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); diff --git a/purchasing/supplier_payment.php b/purchasing/supplier_payment.php index c7bedf4d..45fb163e 100644 --- a/purchasing/supplier_payment.php +++ b/purchasing/supplier_payment.php @@ -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); diff --git a/sales/customer_payments.php b/sales/customer_payments.php index 907f789e..25f3b3f8 100644 --- a/sales/customer_payments.php +++ b/sales/customer_payments.php @@ -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'); diff --git a/sales/includes/db/payment_db.inc b/sales/includes/db/payment_db.inc index 76664853..e1531866 100644 --- a/sales/includes/db/payment_db.inc +++ b/sales/includes/db/payment_db.inc @@ -21,14 +21,14 @@ $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); } diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index 171c0a7e..0bdbf707 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -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"); } diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index b858652e..c17e9214 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -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);