+ foreach ($invoice->line_items as $invoice_line) {
+
+ $line_taxfree_price = get_tax_free_price_for_item($invoice_line->stock_id,
+ $invoice_line->price, 0, $invoice->tax_included,
+ $invoice->tax_group_array);
+
+ $line_tax = get_full_price_for_item($invoice_line->stock_id,
+ $invoice_line->price, 0, $invoice->tax_included,
+ $invoice->tax_group_array) - $line_taxfree_price;
+
+ write_customer_trans_detail_item(10, $invoice_no, $invoice_line->stock_id,
+ $invoice_line->item_description, $invoice_line->qty_dispatched,
+ $invoice_line->line_price(), $line_tax, $invoice_line->discount_percent,
+ $invoice_line->standard_cost,
+ $trans_no ? $invoice_line->id : 0);
+
+ // Update delivery items for the quantity invoiced
+ if ($invoice_line->qty_old != $invoice_line->qty_dispatched)
+ update_parent_line(10, $invoice_line->id, ($invoice_line->qty_dispatched-$invoice_line->qty_old));
+
+ if ($invoice_line->qty_dispatched != 0) {
+ $stock_gl_code = get_stock_gl_code($invoice_line->stock_id);
+ // 2008-06-14. If there is a Branch Sales Account, then override with this,
+ // else take the Item Sales Account
+ if ($branch_data['sales_account'] != "")
+ $sales_account = $branch_data['sales_account'];
+ else
+ $sales_account = $stock_gl_code['sales_account'];
+
+ if ($invoice_line->line_price() != 0) {
+ //Post sales transaction to GL credit sales
+
+ add_gl_trans_customer(10, $invoice_no, $date_, $sales_account,
+ $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"],
+ (-$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_,
+ $branch_data["sales_discount_account"], $stock_gl_code["dimension_id"],
+ $stock_gl_code["dimension2_id"],
+ ($line_taxfree_price * $invoice_line->qty_dispatched * $invoice_line->discount_percent),
+ $invoice->customer_id, "The sales discount GL posting could not be inserted");
+ } /*end of if discount !=0 */
+ }
+ } /*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,
+ ($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,
+ -$invoice->get_tax_free_shipping(), $invoice->customer_id,
+ "The freight GL posting could not be inserted");