//----------------------------------------------------------------------------------------
function add_supp_allocation($amount, $trans_type_from, $trans_no_from,
- $trans_type_to, $trans_no_to, $date_)
+ $trans_type_to, $trans_no_to, $date_=null)
{
+ if (!$date_)
+ $date = Today();
+
$date = date2sql($date_);
$sql = "INSERT INTO ".TB_PREF."supp_allocations (
amt, date_alloc,
}
//----------------------------------------------------------------------------------------
-
-function update_supp_trans_allocation($trans_type, $trans_no, $alloc)
+// Update supplier trans alloc field according to current status of supp_allocations
+//
+function update_supp_trans_allocation($trans_type, $trans_no)
{
- $sql = "UPDATE ".TB_PREF."supp_trans SET alloc = alloc + ".db_escape($alloc)."
- WHERE type=".db_escape($trans_type)." AND trans_no = ".db_escape($trans_no);
+ $sql = "UPDATE `".TB_PREF.($trans_type==ST_PURCHORDER ? 'purch_orders' : 'supp_trans')."` trans,
+ (SELECT sum(amt) amt from ".TB_PREF."supp_allocations
+ WHERE (trans_type_to=".db_escape($trans_type)." AND trans_no_to=".db_escape($trans_no).")
+ OR (trans_type_from=".db_escape($trans_type)." AND trans_no_from=".db_escape($trans_no).")) allocated
+ SET
+ trans.alloc=IFNULL(allocated.amt, 0)
+ WHERE " . ($trans_type==ST_PURCHORDER ?
+ "trans.order_no=".db_escape($trans_no)
+ : "trans.type=".db_escape($trans_type)." AND trans.trans_no=".db_escape($trans_no));
+
db_query($sql, "The supp transaction record could not be modified for the allocation against it");
}
+
//-------------------------------------------------------------------------------------------------------------
function void_supp_allocations($type, $type_no, $date="")
$sql = "UPDATE ".TB_PREF."supp_trans SET alloc=alloc - " . $row['amt'] . "
WHERE (type= " . $row['trans_type_from'] . " AND trans_no=" . $row['trans_no_from'] . ")
OR (type=" . $row['trans_type_to'] . " AND trans_no=" . $row['trans_no_to'] . ")";
- //$sql = "UPDATE ".TB_PREF."supp_trans SET alloc=alloc - " . $row['amt'] . "
- // WHERE type=" . $row['trans_type_to'] . " AND trans_no=" . $row['trans_no_to'];
db_query($sql, "could not clear allocation");
+
// 2008-09-20 Joe Hunt
if ($date != "")
exchange_variation($type, $type_no, $row['trans_type_to'], $row['trans_no_to'], $date,
$row['amt'], PT_SUPPLIER, true);
+ // 2014-01-16 Joe Hunt. Fix for voiding allocated currency supp_invoices.
+ elseif ($type == ST_SUPPINVOICE && $row['trans_type_to'] == $type && $row['trans_no_to'] == $type_no)
+ exchange_variation($row['trans_type_from'], $row['trans_no_from'], $row['trans_type_to'], $row['trans_no_to'],
+ sql2date($row['date_alloc']), $row['amt'], PT_SUPPLIER, true);
//////////////////////
}
return $sql;
}
+
//-------------------------------------------------------------------------------------------------------------
function get_allocatable_to_supp_transactions($supplier_id, $trans_no=null, $type=null)
else
{
$sql = get_alloc_supp_sql(null, "round(ABS(ov_amount+ov_gst+ov_discount)-alloc,6) > 0
- AND trans.type != ".ST_SUPPAYMENT."
+ AND trans.type NOT IN (".implode(',',array(ST_SUPPAYMENT, ST_BANKPAYMENT, ST_SUPPCREDIT)).")
AND trans.supplier_id=".db_escape($supplier_id));
}