+// if (is_fa_item($item->item_code)) {
+// add_actual_cost($item->order_price, $item->item_code);
+// }
+
+ if ($trans_type == ST_SUPPCREDIT)
+ set_grn_item_credited($item, $supp_trans->supplier_id, $invoice_id, $date_);
+ else {
+ add_or_update_purchase_data($supp_trans->supplier_id, $item->item_code, $item->chg_price);
+
+ update_supp_received_items_for_invoice($item->id, $item->po_detail_item,
+ $item->this_quantity_inv, $item->chg_price);
+ }
+
+ $qty = ($trans_type==ST_SUPPCREDIT ? 1 : -1)*$item->this_quantity_inv;
+ add_supp_invoice_item($trans_type, $invoice_id, $item->item_code,
+ $item->item_description, 0, $item->chg_price, $line_tax/$qty, $qty, $item->id, $item->po_detail_item);
+ } // grn_items
+
+
+ /*GL Items are straight forward - just do the debit postings to the GL accounts specified -
+ the credit is to creditors control act */
+ foreach ($supp_trans->gl_codes as $entered_gl_code)
+ {
+ $memo_ = $entered_gl_code->memo_;
+
+ $index = is_tax_account($entered_gl_code->gl_code);
+ if ($index !== false)
+ {
+ $gl_cart->add_gl_item($entered_gl_code->gl_code, $entered_gl_code->gl_dim, $entered_gl_code->gl_dim2, $entered_gl_code->amount);
+ // store tax details if the gl account is a tax account
+ add_gl_tax_details($entered_gl_code->gl_code,
+ $trans_type, $invoice_id, $entered_gl_code->amount,
+ $supp_trans->ex_rate, $date_, $supp_trans->supp_reference, $supp_trans->tax_included, null, $supp_trans->tax_group_id);
+
+ $tax_total += $entered_gl_code->amount;
+ } else {
+ $gl_cart->add_gl_item($entered_gl_code->gl_code, $entered_gl_code->gl_dim, $entered_gl_code->gl_dim2, $entered_gl_code->amount);
+ $net_total += $entered_gl_code->amount;
+ }
+ $gl_cart->add_gl_item($supplier["payable_account"], 0, 0, -$entered_gl_code->amount, '', '', $supp_trans->supplier_id);
+
+ add_supp_invoice_gl_item($trans_type, $invoice_id, $entered_gl_code->gl_code, $entered_gl_code->amount, $memo_,
+ $entered_gl_code->gl_dim, $entered_gl_code->gl_dim2);
+ }
+
+ if ($trans_type == ST_SUPPCREDIT) { // reverse postings if this is credit note
+ foreach($gl_cart->gl_items as &$line)
+ $line->amount = -$line->amount;
+ $net_total = -$net_total;
+ $tax_total = -$tax_total;
+ }
+ $gl_cart->reduce_gl(); // minimize GL lines
+
+ $gl_cart->write_gl(false); // don't check balances here: we are working on two (maybe unbalanced) carts
+
+ update_supp_trans_sums($trans_type, $invoice_id, round($net_total,2), round($tax_total,2));