$taxitem['tax_type_id'], $taxitem['rate'], $supp_trans->tax_included, $taxitem['Value'],
$taxitem['Net'], $ex_rate, $date_, $supp_trans->supp_reference);
- 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'],
- $supp_trans->supplier_id,
- "A general ledger transaction for the tax amount could not be added");
+ if (isset($taxitem['purchasing_gl_code']))
+ {
+ 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'],
+ $supp_trans->supplier_id,
+ "A general ledger transaction for the tax amount could not be added");
+ }
}
}
if ($trans_type == ST_SUPPCREDIT)
$supp_trans->supplier_id,
"The general ledger transaction for the control total could not be added");
+ $to_allocate = ($invoice_items_total + $item_added_tax + $supp_trans->ov_discount);
+
foreach ($supp_trans->gl_codes as $entered_gl_code)
{
/*GL Items are straight forward - just do the debit postings to the GL accounts specified -
$currency = get_supplier_currency($supp_trans->supplier_id);
$total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act,
- $dim1, $dim2, $entered_grn->this_quantity_inv * $old_price, $supp_trans->supplier_id, "", $ex_rate);
- $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_price,
- $line_taxfree);
+ $dim, $dim2, $entered_grn->this_quantity_inv * $old_price, $supp_trans->supplier_id, "", $ex_rate);
+ $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_value,
+ $taxfree_line);
$mat_cost = update_average_material_cost(null, $entered_grn->item_code,
$diff/$entered_grn->this_quantity_inv, $entered_grn->this_quantity_inv, null, true);
if ($invoice_alloc_balance > 0)
{ //the invoice is not already fully allocated
- $trans = get_supp_trans($supp_trans->src_docs, ST_SUPPINVOICE);
- $total = $trans['Total'];
+ $trans = get_supp_trans($invoice_id, ST_SUPPCREDIT);
+ $total = -$trans['Total'];
$allocate_amount = ($invoice_alloc_balance > $total) ? $total : $invoice_alloc_balance;
+
/*Now insert the allocation record if > 0 */
if ($allocate_amount != 0)
{
- update_supp_trans_allocation(ST_SUPPINVOICE, $supp_trans->src_docs);
- update_supp_trans_allocation(ST_SUPPCREDIT, $invoice_id);
- add_supp_allocation($allocate_amount, ST_SUPPCREDIT, $invoice_id, ST_SUPPINVOICE, $supp_trans->src_docs,
+ add_supp_allocation($allocate_amount, ST_SUPPCREDIT, $invoice_id, ST_SUPPINVOICE, $invoice_no,
$date_);
+ update_supp_trans_allocation(ST_SUPPINVOICE, $invoice_no);
+ update_supp_trans_allocation(ST_SUPPCREDIT, $invoice_id);
exchange_variation(ST_SUPPCREDIT, $invoice_id, ST_SUPPINVOICE, $supp_trans->src_docs, $date_,
$allocate_amount, PT_SUPPLIER);
//_vd(get_payments_for($sales_order, ST_PURCHORDER));
//_vd(get_payments_for($invoice_id, ST_SUPPINVOICE));
//exit;
+ $supp_trans->trans_no = $invoice_id;
hook_db_postwrite($supp_trans, $supp_trans->trans_type);
commit_transaction();
add_audit_trail(ST_JOURNAL, $id, $old_date);
add_comments(ST_JOURNAL, $id, $old_date, $memo);
- $Refs->save(ST_JOURNAL, $id, $ref);
- }
- }
- /*$deliveries = get_deliveries_between($details_row["stock_id"], $old_date, $date_);
- if ($deliveries[0] != 0) // have deliveries been done during the period?
- {
- update_stock_move_pid(ST_CUSTDELIVERY, $details_row["stock_id"], $old_date, $date_, 0, $mat_cost);
+ $Refs->save(ST_JOURNAL, $id, $ref);
+ }
}
- update_stock_move_pid(ST_SUPPRECEIVE, $details_row["stock_id"], $old_date, $old_date, $grn['supplier_id'], $mat_cost);
- */
}
}
}