return array($ret, $date, $unit_price);
}
-function get_deliveries_between($stock_id, $from, $to)
-{
- $from = date2sql($from);
- $to = date2sql($to);
- $sql = "SELECT SUM(-qty), SUM(-qty*standard_cost) FROM ".TB_PREF."stock_moves
- WHERE type=".ST_CUSTDELIVERY." AND stock_id=".db_escape($stock_id)." AND
- tran_date>='$from' AND tran_date<='$to' GROUP BY stock_id";
-
- $result = db_query($sql, "The deliveries could not be updated");
- return db_fetch_row($result);
-}
-
function get_diff_in_home_currency($supplier, $old_date, $date, $amount1, $amount2)
{
$dec = user_price_dec();
$currency = get_supplier_currency($supplier);
$ex_rate = get_exchange_rate_to_home_currency($currency, $old_date);
$amount1 = $amount1 / $ex_rate;
- $ex_rate = get_exchange_rate_to_home_currency($currency, $date_);
+ $ex_rate = get_exchange_rate_to_home_currency($currency, $date);
$amount2 = $amount2 / $ex_rate;
$diff = $amount2 - $amount1;
return round2($diff, $dec);
$invoice_items_total = $supp_trans->get_total_charged($supp_trans->tax_group_id);
- if ($supp_trans->is_invoice)
- $trans_type = ST_SUPPINVOICE;
- else
+ $trans_type = $supp_trans->trans_type;
+
+ if ($trans_type == ST_SUPPCREDIT)
{
- $trans_type = ST_SUPPCREDIT;
// let's negate everything because it's a credit note
$invoice_items_total = -$invoice_items_total;
$tax_total = -$tax_total;
/*GL Items are straight forward - just do the debit postings to the GL accounts specified -
the credit is to creditors control act done later for the total invoice value + tax*/
- if (!$supp_trans->is_invoice)
+ if ($trans_type == ST_SUPPCREDIT)
$entered_gl_code->amount = -$entered_gl_code->amount;
$memo_ = $entered_gl_code->memo_;
$entered_gl_code->amount, $memo_);
// store tax details if the gl account is a tax account
- if (!$supp_trans->is_invoice)
+ if ($trans_type == ST_SUPPCREDIT)
$entered_gl_code->amount = -$entered_gl_code->amount;
add_gl_tax_details($entered_gl_code->gl_code,
$trans_type, $invoice_id, $entered_gl_code->amount,
foreach ($supp_trans->grn_items as $entered_grn)
{
- if (!$supp_trans->is_invoice)
+ if ($trans_type == ST_SUPPCREDIT)
{
$entered_grn->this_quantity_inv = -$entered_grn->this_quantity_inv;
set_grn_item_credited($entered_grn, $supp_trans->supplier_id, $invoice_id, $date_);
$stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
$entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);
// -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
- if($supp_trans->is_invoice)
+ if ($trans_type == ST_SUPPINVOICE)
{
$old = update_supp_received_items_for_invoice($entered_grn->id, $entered_grn->po_detail_item,
$entered_grn->this_quantity_inv, $entered_grn->chg_price);
$amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
if ($amt != 0.0)
{
+ $_s = $entered_grn->item_code;
+ $_d = $deliveries[0];
+ $_od = $old_date;
+ $_cd = $mat_cost - $deliveries[1];
+ $memo = _("Cost difference adjustment for $_s. $_d items delivered since $_od. The cost difference is $_cd");
add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"],
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], _("Cost diff."),
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
$amt, null, null, null,
"The general ledger transaction could not be added for the price variance of the inventory item");
add_gl_trans($trans_type, $invoice_id, $date_, $iv_act,
- 0, 0, _("Cost diff."), -$amt, null, null, null,
+ 0, 0, $memo, -$amt, null, null, null,
"The general ledger transaction could not be added for the price variance of the inventory item");
}
update_stock_move_pid(ST_CUSTDELIVERY, $entered_grn->item_code, $old_date, $date_, 0, $mat_cost);
if ($taxitem['Net'] != 0)
{
- if (!$supp_trans->is_invoice)
+ if ($trans_type == ST_SUPPCREDIT)
{
$taxitem['Net'] = -$taxitem['Net'];
$taxitem['Value'] = -$taxitem['Value'];
$taxitem['tax_type_id'], $taxitem['rate'], 0, $taxitem['Value'],
$taxitem['Net'], $ex_rate, $date_, $supp_trans->supp_reference);
- if (!$supp_trans->is_invoice)
+ 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->tran_date = sql2date($trans_row["tran_date"]);
$supp_trans->due_date = sql2date($trans_row["due_date"]);
//$supp_trans->Comments = $trans_row["TransText"];
- $supp_trans->Comments = "";
+ $supp_trans->Comments = get_comments_string($trans_type, $trans_no);
$supp_trans->reference = $trans_row["reference"];
$supp_trans->supp_reference = $trans_row["supp_reference"];
$supp_trans->ov_amount = $trans_row["ov_amount"];
{
$supp_trans->add_grn_to_trans($details_row["grn_item_id"], $details_row["po_detail_item_id"], $details_row["stock_id"],
$details_row["description"], 0, 0, $details_row["quantity"], 0, $details_row["FullUnitPrice"],
- false, 0, 0);
+ 0, 0);
}
else
{