<?php
-
+/**********************************************************************
+ Copyright (C) FrontAccounting, LLC.
+ Released under the terms of the GNU Affero General Public License,
+ AGPL, as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
+***********************************************************************/
//-----------------------------------------------------------------------------
// Add or update Sales Invoice
//
$invoice->Branch, $date_, $invoice->reference, $items_total, 0,
$items_added_tax, $invoice->freight_cost, $freight_added_tax,
$invoice->sales_type, $sales_order, $delivery_no,
- $invoice->ship_via, $invoice->due_date, $alloc); // 2008-06-14 extra $alloc
+ $invoice->ship_via, $invoice->due_date, $alloc, 0, $invoice->dimension_id, $invoice->dimension2_id);
+ // 2008-06-14 extra $alloc, 2008-11-12 added dimension_id Joe Hunt
if ($trans_no == 0) {
$invoice->trans_no = array($invoice_no=>0);
void_cust_allocations(10, $invoice_no); // ?
void_customer_trans_tax_details(10, $invoice_no);
}
-
+ $total = 0;
foreach ($invoice->line_items as $invoice_line) {
$line_taxfree_price = get_tax_free_price_for_item($invoice_line->stock_id,
$sales_account = ($branch_data['sales_account'] != "" ? $branch_data['sales_account'] : $stock_gl_code['sales_account']);
// 2008-08-01. If there is a Customer Dimension, then override with this,
// else take the Item Dimension (if any)
- $dim = ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]);
- $dim2 = ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]);
- add_gl_trans_customer(10, $invoice_no, $date_, $sales_account, $dim, $dim2,
+ $dim = ($invoice->dimension_id != $customer['dimension_id'] ? $invoice->dimension_id :
+ ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]));
+ $dim2 = ($invoice->dimension2_id != $customer['dimension2_id'] ? $invoice->dimension2_id :
+ ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]));
+ $total += add_gl_trans_customer(10, $invoice_no, $date_, $sales_account, $dim, $dim2,
(-$line_taxfree_price * $invoice_line->qty_dispatched),
$invoice->customer_id, "The sales price GL posting could not be inserted");
if ($invoice_line->discount_percent != 0) {
- add_gl_trans_customer(10, $invoice_no, $date_,
+ $total += add_gl_trans_customer(10, $invoice_no, $date_,
$branch_data["sales_discount_account"], $dim, $dim2,
($line_taxfree_price * $invoice_line->qty_dispatched * $invoice_line->discount_percent),
$invoice->customer_id, "The sales discount GL posting could not be inserted");
} /*quantity dispatched is more than 0 */
} /*end of delivery_line loop */
- /*Post debtors transaction to GL debit debtors, credit freight re-charged and credit sales */
if (($items_total + $charge_shipping) != 0) {
- add_gl_trans_customer(10, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0,
+ $total += add_gl_trans_customer(10, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0,
($items_total + $charge_shipping + $items_added_tax + $freight_added_tax),
$invoice->customer_id, "The total debtor GL posting could not be inserted");
}
+
if ($charge_shipping != 0) {
- add_gl_trans_customer(10, $invoice_no, $date_, $company_data["freight_act"], 0, 0,
+ $total += add_gl_trans_customer(10, $invoice_no, $date_, $company_data["freight_act"], 0, 0,
-$invoice->get_tax_free_shipping(), $invoice->customer_id,
"The freight GL posting could not be inserted");
}
add_customer_trans_tax_detail_item(10, $invoice_no, $taxitem['tax_type_id'],
$taxitem['rate'], $invoice->tax_included, $taxitem['Value']);
- add_gl_trans_customer(10, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
+ $total += add_gl_trans_customer(10, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
(-$taxitem['Value']), $invoice->customer_id,
"A tax GL posting could not be inserted");
}
}
+ /*Post a balance post if $total != 0 */
+ add_gl_balance(10, $invoice_no, $date_, -$total, payment_person_types::customer(), $invoice->customer_id);
+
add_comments(10, $invoice_no, $date_, $invoice->Comments);
if ($trans_no == 0) {
references::get_next(12), $amount-$discount, $discount,
_('Cash invoice').' '.$invoice->trans_no);
add_cust_allocation($amount, 12, $pmtno, 10, $invoice_no);
+
+ update_debtor_trans_allocation(10, $invoice_no, $amount);
+ update_debtor_trans_allocation(12, $pmtno, $amount);
}
}
commit_transaction();