global $systypes_array;
$cart = $_SESSION['alloc'];
-
+
+ if ($cart->type == ST_JOURNAL && $cart->bank_amount < 0)
+ {
+ $cart->bank_amount = -$cart->bank_amount;
+ $cart->amount = -$cart->amount;
+ }
display_heading(sprintf(_("Allocation of %s # %d"), $systypes_array[$cart->type], $cart->trans_no));
display_heading($cart->person_name);
.$row["trans_no"] . "&trans_type=" . $row["type"]. "&debtor_no=" . $row["debtor_no"], ICON_ALLOC);
}
+function amount_total($row)
+{
+ return price_format($row['type'] == ST_JOURNAL && $row["Total"] < 0 ? -$row["Total"] : $row["Total"]);
+}
+
function amount_left($row)
{
- return price_format($row["Total"]-$row["alloc"]);
+ return price_format(($row['type'] == ST_JOURNAL && $row["Total"] < 0 ? -$row["Total"] : $row["Total"])-$row["alloc"]);
}
function check_settled($row)
_("Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>'asc'),
_("Customer") => array('ord'=>''),
_("Currency") => array('align'=>'center'),
- _("Total") => 'amount',
+ _("Total") => array('align'=>'right','fun'=>'amount_total'),
_("Left to Allocate") => array('align'=>'right','insert'=>true, 'fun'=>'amount_left'),
array('insert'=>true, 'fun'=>'alloc_link')
);
.TB_PREF."debtor_trans as trans, "
.TB_PREF."debtors_master as debtor"
." WHERE trans.debtor_no=debtor.debtor_no
- AND (((type=".ST_CUSTPAYMENT." OR type=".ST_BANKDEPOSIT.") AND (trans.ov_amount > 0))"
- ." OR ( (type=".ST_CUSTCREDIT. " OR type=".ST_JOURNAL. ") AND (ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)>0))";
+ AND (((type=".ST_CUSTPAYMENT." OR type=".ST_BANKDEPOSIT.") AND (trans.ov_amount > 0))
+ OR (type=".ST_CUSTCREDIT. " AND (ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)>0)
+ OR (type=".ST_JOURNAL. " AND (trans.ov_amount < 0)))";
if (!$settled)
$sql .= " AND (round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax-ov_discount-alloc),6) > 0)";
AND round(-IF(prep_amount, prep_amount, ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-alloc,6) > 0
OR
trans.type = '". ST_JOURNAL."'
- AND ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount<0
+ AND ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount>0
OR
trans.type = '". ST_BANKPAYMENT."'
AND ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount>0
function fmt_balance($row)
{
- return $row["TotalAmount"] - $row["Allocated"];
+ return ($row["type"] == ST_JOURNAL && $row["TotalAmount"] < 0 ? -$row["TotalAmount"] : $row["TotalAmount"]) - $row["Allocated"];
}
function alloc_link($row)
function fmt_amount($row)
{
$value =
- $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT || $row['type']==ST_JOURNAL ?
+ $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT ?
-$row["TotalAmount"] : $row["TotalAmount"];
return price_format($value);
}