$supp_accs = get_supplier_accounts($trans['supplier_id']);
$ar_ap_act = $supp_accs['payable_account'];
$person_id = $trans['supplier_id'];
- $curr = $trans['SupplierCurrCode'];
+ $curr = $trans['curr_code'];
$date = sql2date($trans['tran_date']);
}
if (is_company_currency($curr))
var $type;
var $person_id = '';
var $person_name = '';
- var $person_type; // true - supplier, otherwise customer
+ var $person_type; // PT_SUPPLIER/PT_CUSTOMER
+ var $person_curr;
var $date_;
var $amount = 0; /*Total amount of the transaction in FX */
-
- var $allocs; /*array of transactions allocated to */
+ var $currency;
+
+ var $allocs; /*array of transactions allocated to */
- function allocation($type, $trans_no)
+ function allocation($type, $trans_no, $person_id = null, $person_type_id=null)
{
$this->allocs = array();
$this->trans_no = $trans_no;
$this->type = $type;
- $this->read(); // read payment or credit
+ if ($person_id)
+ $this->set_person($person_id, $person_type_id);
+
+ $this->read($type, $trans_no, $person_id, $person_type_id); // read payment or credit
+ }
+
+ function set_person($person_id, $person_type)
+ {
+ $this->person_id = $person_id;
+ $this->person_type = $person_type;
+ $this->person_curr = $person_type == PT_SUPPLIER ?
+ get_supplier_currency($person_id) : get_customer_currency($person_id);
+ return $this->person_curr;
}
function add_item($type, $type_no, $date_, $due_date, $amount, $amount_allocated,
$current_allocated, $ref)
{
- if ($amount > 0)
+ if (floatcmp($amount, 0))
{
$this->allocs[count($this->allocs)] = new allocation_item($type, $type_no,
$date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref);
function update_item($index, $type, $type_no, $date_, $due_date,
$amount, $amount_allocated, $current_allocated, $ref)
{
- if ($amount > 0)
+ if (floatcmp($amount, 0))
{
$this->allocs[$index] = new allocation_item($type, $type_no,
$date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref);
{
return false;
}
- }
+ }
function add_or_update_item($type, $type_no, $date_, $due_date,
$amount, $amount_allocated, $current_allocated, $ref)
{
return $this->update_item($i, $type, $type_no, $date_, $due_date,
$amount, $amount_allocated, $current_allocated, $ref);
- }
+ }
}
return $this->add_item($type, $type_no, $date_, $due_date,
$amount, $amount_allocated, $current_allocated, $ref);
//
// FIXME - read all transactions below twice seems to be suboptimal
//
- function read($type = null, $trans_no = 0)
+ function read($type = null, $trans_no = 0, $person_id=null, $person_type_id=null)
{
- if ($type == null) { // re-read
+ if ($type !== null) { // otherwise re-read
$type = $this->type;
$trans_no = $this->trans_no;
- }
- if ($type == ST_BANKPAYMENT || $type == ST_BANKDEPOSIT) {
- $bank_trans = db_fetch(get_bank_trans($type, $trans_no));
- $this->person_type = $bank_trans['person_type_id'] == PT_SUPPLIER;
- } else
- $this->person_type = $type == ST_SUPPCREDIT || $type == ST_SUPPAYMENT;
- $this->allocs = array();
- if ($trans_no) {
- $trans = $this->person_type ? get_supp_trans($trans_no, $type)
- : get_customer_trans($trans_no, $type);
+ if (isset($person_type_id))
+ {
+ $this->person_type = $person_type_id;
+ $this->person_id = $person_id;
+ } else { // guess person_type_id
+ if (in_array($type, array(ST_BANKPAYMENT, ST_BANKDEPOSIT)))
+ {
+ $bank_trans = db_fetch(get_bank_trans($type, $trans_no));
+ $this->person_type = $bank_trans['person_type_id'];
+ } else
+ $this->person_type = in_array($type, array(ST_SUPPCREDIT, ST_SUPPAYMENT)) ? PT_SUPPLIER : PT_CUSTOMER;
+ }
- $this->person_id = $trans[$this->person_type ? 'supplier_id':'debtor_no'];
- $this->person_name = $trans[$this->person_type ? "supplier_name":"DebtorName"];
- $this->amount = $trans["Total"];
- $this->date_ = sql2date($trans["tran_date"]);
- }
- else {
- $this->person_id = get_post($this->person_type ? 'supplier_id':'customer_id');
- $this->date_ = get_post($this->person_type ? 'DatePaid':'DateBanked', Today());
+ if ($trans_no) {
+ $trans = $this->person_type == PT_SUPPLIER ? get_supp_trans($trans_no, $type, $person_id)
+ : get_customer_trans($trans_no, $type, $person_id);
+
+ $this->person_id = $trans[$this->person_type == PT_SUPPLIER ? 'supplier_id':'debtor_no'];
+ $this->person_name = $trans[$this->person_type == PT_SUPPLIER ? "supplier_name":"DebtorName"];
+ $this->date_ = sql2date($trans["tran_date"]);
+ $this->person_curr = $trans['curr_code'];
+ $this->currency = isset($trans['bank_curr_code']) ? $trans['bank_curr_code'] : $trans['curr_code'];
+ $this->bank_amount = @$trans["bank_amount"];
+ $this->amount = $trans["Total"];
+ }
}
-
/* Now populate the array of possible (and previous actual) allocations
for this customer/supplier. First get the transactions that have
outstanding balances ie Total-alloc >0 */
- if ($this->person_type)
- $trans_items = get_allocatable_to_supp_transactions($this->person_id);
- else
- $trans_items = get_allocatable_to_cust_transactions($this->person_id);
-
- while ($myrow = db_fetch($trans_items))
+ $this->allocs = array();
+ if ($this->person_id)
{
- $this->add_item($myrow["type"], $myrow["trans_no"],
- sql2date($myrow["tran_date"]),
- sql2date($myrow["due_date"]),
- $myrow["Total"], // trans total
- $myrow["alloc"], // trans total allocated
- 0,
- $myrow["reference"]); // this allocation
+ if ($this->person_type==PT_SUPPLIER)
+ $trans_items = get_allocatable_to_supp_transactions($this->person_id);
+ else
+ $trans_items = get_allocatable_to_cust_transactions($this->person_id);
+ while ($myrow = db_fetch($trans_items))
+ {
+ $this->add_item($myrow["type"], $myrow["trans_no"],
+ sql2date($myrow["tran_date"]),
+ sql2date($myrow["due_date"]),
+ $myrow["Total"], // trans total
+ $myrow["alloc"], // trans total allocated
+ 0,
+ $myrow["reference"]); // this allocation
+ }
}
- if ($trans_no == 0) return; // this is new payment
+ if ($this->trans_no == 0) return; // this is new payment
/* Now get trans that might have previously been allocated to by this trans
NB existing entries where still some of the trans outstanding entered from
above logic will be overwritten with the prev alloc detail below */
- if ($this->person_type)
+ if ($this->person_type==PT_SUPPLIER)
$trans_items = get_allocatable_to_supp_transactions($this->person_id,
- $trans_no, $type);
+ $this->trans_no, $this->type);
else
$trans_items = get_allocatable_to_cust_transactions($this->person_id,
- $trans_no, $type);
+ $this->trans_no, $this->type);
while ($myrow = db_fetch($trans_items))
{
{
begin_transaction();
- if ($this->person_type)
+ if ($this->person_type == PT_SUPPLIER)
clear_supp_alloctions($this->type, $this->trans_no, $this->date_);
else
clear_cust_alloctions($this->type, $this->trans_no, $this->date_);
// now add the new allocations
$total_allocated = 0;
+ $dec = user_price_dec();
foreach ($this->allocs as $alloc_item)
{
if ($alloc_item->current_allocated > 0)
{
- if ($this->person_type) {
- add_supp_allocation($alloc_item->current_allocated,
+ $amount = round($alloc_item->current_allocated, $dec);
+
+ if ($this->person_type == PT_SUPPLIER) {
+ add_supp_allocation($amount,
$this->type, $this->trans_no,
$alloc_item->type, $alloc_item->type_no, $this->date_);
- update_supp_trans_allocation($alloc_item->type,
- $alloc_item->type_no, $alloc_item->current_allocated);
+ update_supp_trans_allocation($alloc_item->type, $alloc_item->type_no);
} else {
- add_cust_allocation($alloc_item->current_allocated,
+ add_cust_allocation($amount,
$this->type, $this->trans_no,
$alloc_item->type, $alloc_item->type_no, $this->date_);
-
- update_debtor_trans_allocation($alloc_item->type,
- $alloc_item->type_no, $alloc_item->current_allocated);
+
+ update_debtor_trans_allocation($alloc_item->type, $alloc_item->type_no);
}
// Exchange Variations Joe Hunt 2008-09-20 ////////////////////
exchange_variation($this->type, $this->trans_no,
$alloc_item->type, $alloc_item->type_no, $this->date_,
- $alloc_item->current_allocated,
- $this->person_type ? PT_SUPPLIER : PT_CUSTOMER);
-
+ $amount, $this->person_type);
//////////////////////////////////////////////////////////////
$total_allocated += $alloc_item->current_allocated;
}
} /*end of the loop through the array of allocations made */
- if ($this->person_type)
- update_supp_trans_allocation($this->type, $this->trans_no,
- $total_allocated);
+ if ($this->person_type == PT_SUPPLIER)
+ update_supp_trans_allocation($this->type, $this->trans_no);
else
- update_debtor_trans_allocation($this->type, $this->trans_no,
- $total_allocated);
+ update_debtor_trans_allocation($this->type, $this->trans_no);
commit_transaction();
$k = $counter = $total_allocated = 0;
- if (count($_SESSION['alloc']->allocs))
+ $cart = $_SESSION['alloc'];
+ $supp_ref = in_array($cart->type, array(ST_SUPPCREDIT, ST_SUPPAYMENT, ST_BANKPAYMENT));
+
+ if (count($cart->allocs))
{
+ if ($cart->currency != $cart->person_curr)
+ display_heading(sprintf(_("Allocated amounts in %s:"), $cart->person_curr));
start_table(TABLESTYLE, "width=60%");
- $th = array(_("Transaction Type"), _("#"), _("Ref"), _("Date"), _("Due Date"), _("Amount"),
- _("Other Allocations"), _("This Allocation"), _("Left to Allocate"),'','');
+ $th = array(_("Transaction Type"), _("#"), $supp_ref ? _("Supplier Ref"): _("Ref"), _("Date"), _("Due Date"), _("Amount"),
+ _("Other Allocations"), _("Left to Allocate"), _("This Allocation"),'','');
+
table_header($th);
- foreach ($_SESSION['alloc']->allocs as $alloc_item)
- {
- alt_table_row_color($k);
- label_cell($systypes_array[$alloc_item->type]);
- label_cell(get_trans_view_str($alloc_item->type, $alloc_item->type_no));
- label_cell($alloc_item->ref);
- label_cell($alloc_item->date_, "align=right");
- label_cell($alloc_item->due_date, "align=right");
- amount_cell($alloc_item->amount);
- amount_cell($alloc_item->amount_allocated);
-
- $_POST['amount' . $counter] = price_format($alloc_item->current_allocated);
- amount_cells(null, "amount" . $counter, price_format('amount' . $counter));
-
- $un_allocated = round($alloc_item->amount - $alloc_item->amount_allocated, 6);
- amount_cell($un_allocated, false,'', 'maxval'.$counter);
- label_cell("<a href='#' name=Alloc$counter onclick='allocate_all(this.name.substr(5));return true;'>"
- . _("All") . "</a>");
- label_cell("<a href='#' name=DeAll$counter onclick='allocate_none(this.name.substr(5));return true;'>"
- . _("None") . "</a>".hidden("un_allocated" . $counter,
- price_format($un_allocated), false));
- end_row();
-
- $total_allocated += input_num('amount' . $counter);
- $counter++;
- }
+ foreach ($cart->allocs as $id => $alloc_item)
+ {
+ if (floatcmp(abs($alloc_item->amount), $alloc_item->amount_allocated))
+ {
+ alt_table_row_color($k);
+ label_cell($systypes_array[$alloc_item->type]);
+ label_cell(get_trans_view_str($alloc_item->type, $alloc_item->type_no));
+ label_cell($alloc_item->ref);
+ label_cell($alloc_item->date_, "align=right");
+ label_cell($alloc_item->due_date, "align=right");
+ amount_cell(abs($alloc_item->amount));
+ amount_cell($alloc_item->amount_allocated);
+
+ $_POST['amount' . $id] = price_format($alloc_item->current_allocated);
+
+ $un_allocated = round((abs($alloc_item->amount) - $alloc_item->amount_allocated), 6);
+ amount_cell($un_allocated, false,'', 'maxval'.$id);
+ amount_cells(null, "amount" . $id);//, input_num('amount' . $id));
+ label_cell("<a href='#' name=Alloc$id onclick='allocate_all(this.name.substr(5));return true;'>"
+ . _("All") . "</a>");
+ label_cell("<a href='#' name=DeAll$id onclick='allocate_none(this.name.substr(5));return true;'>"
+ . _("None") . "</a>".hidden("un_allocated" . $id,
+ price_format($un_allocated), false));
+ end_row();
+
+ $total_allocated += input_num('amount' . $id);
+ }
+ }
if ($show_totals) {
label_row(_("Total Allocated"), price_format($total_allocated),
- "colspan=6 align=right", "align=right id='total_allocated'", 3);
+ "colspan=8 align=right", "align=right id='total_allocated'", 3);
+/*
$amount = $_SESSION['alloc']->amount;
if ($_SESSION['alloc']->type == ST_SUPPCREDIT
|| $_SESSION['alloc']->type == ST_SUPPAYMENT
|| $_SESSION['alloc']->type == ST_BANKPAYMENT)
$amount = -$amount;
-
- if ($amount - $total_allocated < 0)
+*/
+ $amount = abs($cart->amount);
+
+ if (floatcmp($amount, $total_allocated) < 0)
{
$font1 = "<font color=red>";
$font2 = "</font>";
$font1 = $font2 = "";
$left_to_allocate = price_format($amount - $total_allocated);
label_row(_("Left to Allocate"), $font1 . $left_to_allocate . $font2,
- "colspan=6 align=right", "nowrap align=right id='left_to_allocate'",
+ "colspan=8 align=right", "nowrap align=right id='left_to_allocate'",
3);
}
end_table(1);
}
- hidden('TotalNumberOfAllocs', $counter);
+ hidden('TotalNumberOfAllocs', count($cart->allocs));
}
//--------------------------------------------------------------------------------
$total_allocated = 0;
- for ($counter = 0; $counter < $_POST["TotalNumberOfAllocs"]; $counter++)
+ for ($counter = 0; $counter < get_post("TotalNumberOfAllocs"); $counter++)
{
+ if (!isset($_POST['amount'.$counter])) continue;
if (!check_num('amount' . $counter, 0))
{
display_error(_("The entry for one or more amounts is invalid or negative."));
return false;
}
- /*Now check to see that the AllocAmt is no greater than the
- amount left to be allocated against the transaction under review */
- if (input_num('amount' . $counter) > input_num('un_allocated' . $counter))
+ /* Now check to see that the AllocAmt is no greater than the
+ amount left to be allocated against the transaction under review;
+ skip check if no allocation is set to avoid deadlock on mistakenly overallocated transactions*/
+ $allocated = input_num('amount' . $counter);
+ if ($allocated && ($allocated > input_num('un_allocated' . $counter)))
{
display_error(_("At least one transaction is overallocated."));
set_focus('amount'.$counter);
$total_allocated += input_num('amount' . $counter);
}
-
+/*
$amount = $_SESSION['alloc']->amount;
-
if (in_array($_SESSION['alloc']->type, array(ST_BANKPAYMENT, ST_SUPPCREDIT, ST_SUPPAYMENT)))
$amount = -$amount;
+*/
+ $amount = abs($_SESSION['alloc']->amount);
if ($total_allocated - ($amount + input_num('discount')) > $SysPrefs->allocation_settled_allowance())
{
return true;
}
-
-?>
unset($_SESSION['alloc']->allocs);
unset($_SESSION['alloc']);
}
+ //session_register("alloc");
}
//--------------------------------------------------------------------------------
start_form();
- display_heading(_("Allocation of") . " " . $systypes_array[$_SESSION['alloc']->type] . " # " . $_SESSION['alloc']->trans_no);
+ $cart = $_SESSION['alloc'];
- display_heading($_SESSION['alloc']->person_name);
+ display_heading(_("Allocation of") . " " . $systypes_array[$cart->type] . " # " . $cart->trans_no);
- display_heading2(_("Date:") . " <b>" . $_SESSION['alloc']->date_ . "</b>");
- display_heading2(_("Total:") . " <b>" . price_format(-$_SESSION['alloc']->amount) . "</b>");
+ display_heading($cart->person_name);
+ display_heading2(_("Date:") . " <b>" . $cart->date_ . "</b>");
+
+ display_heading2(_("Total:"). " <b>" . price_format(-$cart->bank_amount).' '.$cart->currency."</b>");
+
+ if ($cart->currency != $cart->person_curr)
+ {
+ $total = _("Total in clearing currency:") . " <b>" . price_format(-$cart->amount)."</b>"
+ . sprintf(" %s (%s %s/%s)", $cart->person_curr, exrate_format($cart->bank_amount/$cart->amount), $cart->currency, $cart->person_curr);
+ display_heading2($total);
+ }
echo "<br>";
div_start('alloc_tbl');
- if (count($_SESSION['alloc']->allocs) > 0)
+ if (count($cart->allocs) > 0)
{
show_allocatable(true);
if (isset($_GET['trans_no']) && isset($_GET['trans_type']))
{
- $_SESSION['alloc'] = new allocation($_GET['trans_type'], $_GET['trans_no']);
+ $_SESSION['alloc'] = new allocation($_GET['trans_type'], $_GET['trans_no'], @$_GET['supplier_id'], PT_SUPPLIER);
}
if (get_post('UpdateDisplay'))
function get_supp_trans($trans_no, $trans_type=-1)
{
$sql = "SELECT ".TB_PREF."supp_trans.*, (".TB_PREF."supp_trans.ov_amount+".TB_PREF."supp_trans.ov_gst+".TB_PREF."supp_trans.ov_discount) AS Total,
- ".TB_PREF."suppliers.supp_name AS supplier_name, ".TB_PREF."suppliers.curr_code AS SupplierCurrCode ";
+ ".TB_PREF."suppliers.supp_name AS supplier_name, ".TB_PREF."suppliers.curr_code AS curr_code ";
if ($trans_type == ST_SUPPAYMENT)
{
// it's a payment so also get the bank account
$sql .= ", ".TB_PREF."bank_accounts.bank_name, ".TB_PREF."bank_accounts.bank_account_name, ".TB_PREF."bank_accounts.bank_curr_code,
- ".TB_PREF."bank_accounts.account_type AS BankTransType, ".TB_PREF."bank_trans.amount AS BankAmount,
+ ".TB_PREF."bank_accounts.account_type AS BankTransType, ".TB_PREF."bank_trans.amount AS bank_amount,
".TB_PREF."bank_trans.ref ";
}
}
//----------------------------------------------------------------------------------------
-
-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="")
{
$trans = get_supp_trans($_POST['invoice_no'], ST_SUPPINVOICE);
$_POST['supplier_id'] = $trans['supplier_id'];
- $supp = $trans['supplier_name'] . " - " . $trans['SupplierCurrCode'];
+ $supp = $trans['supplier_name'] . " - " . $trans['curr_code'];
label_row(_("Supplier:"), $supp.hidden('supplier_id', $_POST['supplier_id'], false));
}
else
function alloc_link($row)
{
if (($row["type"] == ST_BANKPAYMENT || $row["type"] == ST_SUPPCREDIT || $row["type"] == ST_SUPPAYMENT)
- && (-$row["TotalAmount"] - $row["Allocated"]) > 0)
+ && (-$row["TotalAmount"] - $row["Allocated"]) >= 0)
return pager_link(_("Allocations"), "/purchasing/allocations/supplier_allocate.php?trans_no=" .
- $row["trans_no"]. "&trans_type=" . $row["type"], ICON_MONEY );
+ $row["trans_no"]. "&trans_type=" . $row["type"]. "&supplier_id=" . $row["supplier_id"], ICON_MONEY );
elseif ($row["type"] == ST_SUPPINVOICE && ($row["TotalAmount"] - $row["Allocated"]) > 0)
return pager_link(_("Pay"), "/purchasing/supplier_payment.php?supplier_id=".$row["supplier_id"]
."&PInvoice=".$row["trans_no"], ICON_MONEY );
$Ajax->activate('_ex_rate');
}
+if (list_updated('supplier_id')) {
+ $_POST['amount'] = price_format(0);
+ $_SESSION['alloc']->person_id = get_post('supplier_id');
+ $Ajax->activate('amount');
+} elseif (list_updated('bank_account'))
+ $Ajax->activate('alloc_tbl');
+
//----------------------------------------------------------------------------------------
if (!isset($_POST['bank_account'])) { // first page call
- $_SESSION['alloc'] = new allocation(ST_SUPPAYMENT, 0);
+ $_SESSION['alloc'] = new allocation(ST_SUPPAYMENT, 0, get_post('supplier_id'));
if (isset($_GET['PInvoice'])) {
// get date and supplier
if($inv) {
$_POST['supplier_id'] = $inv['supplier_id'];
$_POST['DatePaid'] = sql2date($inv['tran_date']);
-// $_POST['discount'] = price_format(0);
-// $_POST['bank_account'], $_POST['ref']
$_POST['memo_'] = $inv['supp_reference'];
foreach($_SESSION['alloc']->allocs as $line => $trans) {
if ($trans->type == ST_SUPPINVOICE && $trans->type_no == $_GET['PInvoice']) {
- $_POST['amount'] =
- $_SESSION['alloc']->amount = price_format($_SESSION['alloc']->allocs[$line]->amount);
- $_SESSION['alloc']->allocs[$line]->current_allocated =
- $_SESSION['alloc']->allocs[$line]->amount;
+ $un_allocated = abs($trans->amount) - $trans->amount_allocated;
+ $_POST['amount'] = $_SESSION['alloc']->amount =
+ $_SESSION['alloc']->allocs[$line]->current_allocated = price_format($un_allocated);
break;
}
}
submenu_print(_("&Print This Remittance"), ST_SUPPAYMENT, $payment_id."-".ST_SUPPAYMENT, 'prtopt');
submenu_print(_("&Email This Remittance"), ST_SUPPAYMENT, $payment_id."-".ST_SUPPAYMENT, null, 1);
- display_note(get_gl_view_str(ST_SUPPAYMENT, $payment_id, _("View the GL &Journal Entries for this Payment")));
-
- hyperlink_no_params($path_to_root . "/purchasing/inquiry/supplier_allocation_inquiry.php?supplier_id=", _("Select Another &Supplier Transaction for Payment"));
-// hyperlink_params($path_to_root . "/purchasing/allocations/supplier_allocate.php", _("&Allocate this Payment"), "trans_no=$payment_id&trans_type=22");
+ submenu_view(_("View this Payment"), ST_SUPPAYMENT, $payment_id);
+ display_note(get_gl_view_str(ST_SUPPAYMENT, $payment_id, _("View the GL &Journal Entries for this Payment")), 0, 1);
- hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Supplier &Payment"), "supplier_id=" . $_POST['supplier_id']);
+ submenu_option(_("Enter another supplier &payment"), "/purchasing/supplier_payment.php?supplier_id=".$_POST['supplier_id']);
+ submenu_option(_("Enter Other &Payment"), "/gl/gl_bank.php?NewPayment=Yes");
+ submenu_option(_("Enter &Customer Payment"), "/sales/customer_payments.php");
+ submenu_option(_("Enter Other &Deposit"), "/gl/gl_bank.php?NewDeposit=Yes");
+ submenu_option(_("Bank Account &Transfer"), "/gl/bank_transfer.php");
display_footer_exit();
}
return false;
}
- if ($_POST['amount'] == "")
+ if (@$_POST['amount'] == "")
{
$_POST['amount'] = price_format(0);
}
}
}
- if ($_POST['discount'] == "")
+ if (@$_POST['discount'] == "")
{
$_POST['discount'] = 0;
}
return false;
}
+ //if (input_num('amount') - input_num('discount') <= 0)
if (input_num('amount') <= 0)
{
display_error(_("The total of the amount and the discount is zero or negative. Please enter positive values."));
}
elseif (!is_date_in_fiscalyear($_POST['DatePaid']))
{
- display_error(_("The entered date is not in fiscal year."));
+ display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
set_focus('DatePaid');
return false;
}
$limit = get_bank_account_limit($_POST['bank_account'], $_POST['DatePaid']);
- if ($limit !== null && floatcmp($limit, input_num('amount') < 0))
+ if (($limit !== null) && (floatcmp($limit, input_num('amount')) < 0))
{
display_error(sprintf(_("The total bank amount exceeds allowed limit (%s)."), price_format($limit)));
set_focus('amount');
if (!db_has_currency_rates(get_supplier_currency($_POST['supplier_id']), $_POST['DatePaid'], true))
return false;
+
$_SESSION['alloc']->amount = -input_num('amount');
if (isset($_POST["TotalNumberOfAllocs"]))
set_global_supplier($_POST['supplier_id']);
+ if (!list_updated('bank_account') && !get_post('__ex_rate_changed'))
+ $_POST['bank_account'] = get_default_supplier_bank_account($_POST['supplier_id']);
+ else
+ $_POST['amount'] = price_format(0);
+
bank_accounts_list_row(_("From Bank Account:"), 'bank_account', null, true);
bank_balance_row($_POST['bank_account']);
table_section(2);
- ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_SUPPAYMENT));
-
date_row(_("Date Paid") . ":", 'DatePaid', '', true, 0, 0, 0, null, true);
+ ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_SUPPAYMENT));
+
table_section(3);
- $supplier_currency = get_supplier_currency($_POST['supplier_id']);
- $bank_currency = get_bank_account_currency($_POST['bank_account']);
+ $comp_currency = get_company_currency();
+ $supplier_currency = $_SESSION['alloc']->set_person($_POST['supplier_id'], PT_SUPPLIER);
+ if (!$supplier_currency)
+ $supplier_currency = $comp_currency;
+ $_SESSION['alloc']->currency = $bank_currency = get_bank_account_currency($_POST['bank_account']);
+
if ($bank_currency != $supplier_currency)
{
amount_row("Bank Amount:", 'bank_amount', null, '', $bank_currency, 2);
end_outer_table(1);
div_start('alloc_tbl');
- display_heading(sprintf(_("Accounts Payable settled in %s:"), $supplier_currency));
show_allocatable(false);
div_end();
$show_currencies = false;
$show_both_amounts = false;
-if (($receipt['bank_curr_code'] != $company_currency) || ($receipt['SupplierCurrCode'] != $company_currency))
+if (($receipt['bank_curr_code'] != $company_currency) || ($receipt['curr_code'] != $company_currency))
$show_currencies = true;
-if ($receipt['bank_curr_code'] != $receipt['SupplierCurrCode'])
+if ($receipt['bank_curr_code'] != $receipt['curr_code'])
{
$show_currencies = true;
$show_both_amounts = true;
start_row();
if ($show_currencies)
label_cells(_("Payment Currency"), $receipt['bank_curr_code'], "class='tableheader2'");
-label_cells(_("Amount"), number_format2(-$receipt['BankAmount'], user_price_dec()), "class='tableheader2'");
+label_cells(_("Amount"), number_format2(-$receipt['bank_amount'], user_price_dec()), "class='tableheader2'");
if ($receipt['ov_discount'] != 0)
label_cells(_("Discount"), number_format2(-$receipt['ov_discount']*$receipt['rate'], user_price_dec()), "class='tableheader2'");
else
start_row();
if ($show_currencies)
{
- label_cells(_("Supplier's Currency"), $receipt['SupplierCurrCode'], "class='tableheader2'");
+ label_cells(_("Supplier's Currency"), $receipt['curr_code'], "class='tableheader2'");
}
if ($show_both_amounts)
label_cells(_("Amount"), number_format2(-$receipt['Total'], user_price_dec()), "class='tableheader2'");
unset($_SESSION['alloc']->allocs);
unset($_SESSION['alloc']);
}
+ //session_register('alloc');
}
//--------------------------------------------------------------------------------
{
global $systypes_array;
- display_heading(sprintf(_("Allocation of %s # %d"), $systypes_array[$_SESSION['alloc']->type],
- $_SESSION['alloc']->trans_no));
+ $cart = $_SESSION['alloc'];
- display_heading($_SESSION['alloc']->person_name);
+ display_heading(sprintf(_("Allocation of %s # %d"), $systypes_array[$cart->type], $cart->trans_no));
- display_heading2(_("Date:") . " <b>" . $_SESSION['alloc']->date_ . "</b>");
- display_heading2(_("Total:") . " <b>" . price_format($_SESSION['alloc']->amount) . "</b>");
+ display_heading($cart->person_name);
+
+ display_heading2(_("Date:") . " <b>" . $cart->date_ . "</b>");
+ display_heading2(_("Total:"). " <b>" . price_format($cart->bank_amount).' '.$cart->currency."</b>");
+
+ if ($cart->currency != $cart->person_curr)
+ {
+ $total = _("Total in clearing currency:") . " <b>" . price_format($cart->amount)."</b>"
+ . sprintf(" %s (%s %s/%s)", $cart->person_curr, exrate_format($cart->bank_amount/$cart->amount), $cart->currency, $cart->person_curr);
+ display_heading2($total);
+ }
echo "<br>";
start_form();
div_start('alloc_tbl');
- if (count($_SESSION['alloc']->allocs) > 0)
+ if (count($cart->allocs) > 0)
{
show_allocatable(true);
submit_center_first('UpdateDisplay', _("Refresh"), _('Start again allocation of selected amount'), true);
if (isset($_GET['trans_no']) && isset($_GET['trans_type']))
{
clear_allocations();
- $_SESSION['alloc'] = new allocation($_GET['trans_type'], $_GET['trans_no']);
+ $_SESSION['alloc'] = new allocation($_GET['trans_type'], $_GET['trans_no'], @$_GET['debtor_no'], PT_CUSTOMER);
}
if(get_post('UpdateDisplay'))
{
return pager_link(_("Allocate"),
"/sales/allocations/customer_allocate.php?trans_no="
- .$row["trans_no"] . "&trans_type=" . $row["type"], ICON_MONEY);
+ .$row["trans_no"] . "&trans_type=" . $row["type"]. "&debtor_no=" . $row["debtor_no"], ICON_MONEY);
}
function amount_left($row)
include_once($path_to_root . "/includes/banking.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
-//include_once($path_to_root . "/sales/includes/ui/cust_alloc_ui.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
$js = "";
$_POST['customer_id'] = $_GET['customer_id'];
}
-if (!isset($_POST['bank_account']))
-{ // first page call
- $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT,0);
+if (!isset($_POST['bank_account'])) { // first page call
+ $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT, 0, get_post('customer_id'));
if (isset($_GET['SInvoice'])) {
// get date and supplier
$_POST['DateBanked'] = sql2date($inv['tran_date']);
foreach($_SESSION['alloc']->allocs as $line => $trans) {
if ($trans->type == ST_SALESINVOICE && $trans->type_no == $_GET['SInvoice']) {
- $_POST['amount'] =
- $_SESSION['alloc']->amount = price_format($_SESSION['alloc']->allocs[$line]->amount);
+ $un_allocated = $trans->amount - $trans->amount_allocated;
+ if($un_allocated){
+ $_POST['amount'] = $_SESSION['alloc']->amount =
+// price_format($trans->amount);
$_SESSION['alloc']->allocs[$line]->current_allocated =
- $_SESSION['alloc']->allocs[$line]->amount;
+// $trans->amount;
+ price_format($un_allocated);}
break;
}
}
// when branch is selected via external editor also customer can change
$br = get_branch(get_post('BranchID'));
$_POST['customer_id'] = $br['debtor_no'];
+ $_SESSION['alloc']->person_id = $br['debtor_no'];
$Ajax->activate('customer_id');
}
submenu_print(_("&Print This Receipt"), ST_CUSTPAYMENT, $payment_no."-".ST_CUSTPAYMENT, 'prtopt');
- display_note(get_gl_view_str(ST_CUSTPAYMENT, $payment_no, _("&View the GL Journal Entries for this Customer Payment")));
-
-// hyperlink_params($path_to_root . "/sales/allocations/customer_allocate.php", _("&Allocate this Customer Payment"), "trans_no=$payment_no&trans_type=12");
+ submenu_view(_("&View this Customer Payment"), ST_CUSTPAYMENT, $payment_no);
- hyperlink_no_params($path_to_root . "/sales/inquiry/customer_allocation_inquiry.php?customer_id=", _("Select Another &Customer Transaction for Payment"));
+ submenu_option(_("Enter Another &Customer Payment"), "/sales/customer_payments.php");
+ submenu_option(_("Enter Other &Deposit"), "/gl/gl_bank.php?NewDeposit=Yes");
+ submenu_option(_("Enter Payment to &Supplier"), "/purchasing/supplier_payment.php");
+ submenu_option(_("Enter Other &Payment"), "/gl/gl_bank.php?NewPayment=Yes");
+ submenu_option(_("Bank Account &Transfer"), "/gl/bank_transfer.php");
- hyperlink_no_params($path_to_root . "/sales/customer_payments.php", _("Enter Another &Customer Payment"));
+ display_note(get_gl_view_str(ST_CUSTPAYMENT, $payment_no, _("&View the GL Journal Entries for this Customer Payment")));
display_footer_exit();
}
return false;
}
- if (!get_post('BranchID'))
+ if (!get_post('BranchID'))
{
display_error(_("This customer has no branch defined."));
set_focus('BranchID');
// return false;
// }
- if ($_POST['discount'] == "")
+ if (@$_POST['discount'] == "")
{
$_POST['discount'] = 0;
}
}
if (list_updated('customer_id') || ($new && list_updated('bank_account'))) {
+ $_SESSION['alloc']->set_person($_POST['customer_id'], PT_CUSTOMER);
$_SESSION['alloc']->read();
$_POST['memo_'] = $_POST['amount'] = $_POST['discount'] = '';
$Ajax->activate('alloc_tbl');
date_row(_("Date of Deposit:"), 'DateBanked', '', true, 0, 0, 0, null, true);
- text_row(_("Reference:"), 'ref', null, 20, 40);
+ ref_row(_("Reference:"), 'ref','' , null, '', ST_CUSTPAYMENT);
table_section(3);
$comp_currency = get_company_currency();
- $cust_currency = get_customer_currency($_POST['customer_id']);
- $bank_currency = get_bank_account_currency($_POST['bank_account']);
-
-// if ($cust_currency != $bank_currency) {
-// exchange_rate_display($bank_currency, $cust_currency, $_POST['DateBanked'], ($bank_currency == $comp_currency));
-// }
+ $cust_currency = $_SESSION['alloc']->set_person($_POST['customer_id'], PT_CUSTOMER);
+ if (!$cust_currency)
+ $cust_currency = $comp_currency;
+ $_SESSION['alloc']->currency = $bank_currency = get_bank_account_currency($_POST['bank_account']);
if ($cust_currency != $bank_currency)
{
amount_row(_("Payment Amount:"), 'bank_amount', null, '', $bank_currency);
- // aproximate value in customer currency:
-// label_row(_("Current value:"), price_format(input_num('bank_amount')*$rate).' '.$cust_currency);
}
amount_row(_("Bank Charge:"), 'charge', null, '', $bank_currency);
end_outer_table(1);
- display_heading(sprintf(_("Accounts Receivable settled in %s:"), $cust_currency));
div_start('alloc_tbl');
show_allocatable(false);
div_end();
function get_customer_trans($trans_id, $trans_type)
{
+ global $go_debug;
+
$sql = "SELECT trans.*,"
."ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,"
."cust.name AS DebtorName, cust.address, "
.TB_PREF."tax_groups.id AS tax_group_id ";
}
- $sql .= " FROM ".TB_PREF."debtor_trans trans LEFT JOIN ".TB_PREF."comments com ON trans.type=com.type AND trans.trans_no=com.id
+ $sql .= " FROM ".TB_PREF."debtor_trans trans
+ LEFT JOIN ".TB_PREF."comments com ON trans.type=com.type AND trans.trans_no=com.id
LEFT JOIN ".TB_PREF."shippers ON ".TB_PREF."shippers.shipper_id=trans.ship_via,
".TB_PREF."debtors_master cust";
if (db_num_rows($result) == 0) {
// can't return nothing
+ if($go_debug)
+ display_backtrace();
display_db_error("no debtor trans found for given params", $sql, true);
exit;
}
-
if (db_num_rows($result) > 1) {
// can't return multiple
+ if($go_debug)
+ display_backtrace();
display_db_error("duplicate debtor transactions found for given params", $sql, true);
exit;
}
}
//----------------------------------------------------------------------------------------
-
-function update_debtor_trans_allocation($trans_type, $trans_no, $alloc)
+// Update debtor trans alloc field according to current status of cust_allocations
+//
+function update_debtor_trans_allocation($trans_type, $trans_no)
{
- $sql = "UPDATE ".TB_PREF."debtor_trans SET alloc = alloc + $alloc
- WHERE type=".db_escape($trans_type)." AND trans_no = ".db_escape($trans_no);
+ $sql = "UPDATE `".TB_PREF."debtor_trans` trans,
+ (SELECT sum(amt) amt from ".TB_PREF."cust_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=".db_escape($trans_type)." AND trans_no=".db_escape($trans_no);
+
db_query($sql, "The debtor transaction record could not be modified for the allocation against it");
}
trans.alloc,
trans.due_date,
debtor.address,
- trans.version ";
+ trans.version,
+ trans.debtor_no ";
if ($extra_fields)
$sql .= ", $extra_fields ";
return db_query($sql." ORDER BY trans_no", "Cannot retreive alloc to transactions");
}
-function get_sql_for_customer_allocation_inquiry()
+function get_sql_for_customer_allocation_inquiry($from, $to, $customer, $filterType, $settled)
{
- $data_after = date2sql($_POST['TransAfterDate']);
- $date_to = date2sql($_POST['TransToDate']);
+ $data_after = date2sql($from);
+ $date_to = date2sql($to);
$sql = "SELECT
trans.type,
AND trans.tran_date >= '$data_after'
AND trans.tran_date <= '$date_to'";
- if ($_POST['customer_id'] != ALL_TEXT)
- $sql .= " AND trans.debtor_no = ".db_escape($_POST['customer_id']);
+ if ($customer != ALL_TEXT)
+ $sql .= " AND trans.debtor_no = ".db_escape($customer);
- if (isset($_POST['filterType']) && $_POST['filterType'] != ALL_TEXT)
+ if (isset($filterType) && $filterType != ALL_TEXT)
{
- if ($_POST['filterType'] == '1' || $_POST['filterType'] == '2')
+ if ($filterType == '1' || $filterType == '2')
{
$sql .= " AND trans.type = ".ST_SALESINVOICE." ";
}
- elseif ($_POST['filterType'] == '3')
+ elseif ($filterType == '3')
{
$sql .= " AND trans.type = " . ST_CUSTPAYMENT;
}
- elseif ($_POST['filterType'] == '4')
+ elseif ($filterType == '4')
{
$sql .= " AND trans.type = ".ST_CUSTCREDIT." ";
}
- if ($_POST['filterType'] == '2')
+ if ($filterType == '2')
{
$today = date2sql(Today());
$sql .= " AND trans.due_date < '$today'
}
- if (!check_value('showSettled'))
+ if (!$settled)
{
$sql .= " AND (round(abs(trans.ov_amount + trans.ov_gst + "
."trans.ov_freight + trans.ov_freight_tax + "
."trans.ov_discount) - trans.alloc,6) != 0) ";
}
+
return $sql;
}
$link =
pager_link(_("Allocation"),
"/sales/allocations/customer_allocate.php?trans_no=" . $row["trans_no"]
- ."&trans_type=" . $row["type"], ICON_MONEY);
+ ."&trans_type=" . $row["type"]."&debtor_no=" . $row["debtor_no"], ICON_MONEY);
if ($row["type"] == ST_CUSTCREDIT && $row['TotalAmount'] > 0)
{
return $link;
}
elseif (($row["type"] == ST_CUSTPAYMENT || $row["type"] == ST_BANKDEPOSIT) &&
- ($row['TotalAmount'] - $row['Allocated']) > 0)
+ (floatcmp($row['TotalAmount'], $row['Allocated']) >= 0))
{
/*its a receipt which could have an allocation*/
return $link;
}
- elseif ($row["type"] == ST_CUSTPAYMENT && $row['TotalAmount'] < 0)
+ elseif ($row["type"] == ST_CUSTPAYMENT && $row['TotalAmount'] <= 0)
{
/*its a negative receipt */
return '';
}
//------------------------------------------------------------------------------------------------
-$sql = get_sql_for_customer_allocation_inquiry();
+$sql = get_sql_for_customer_allocation_inquiry(get_post('TransAfterDate'), get_post('TransToDate'),
+ get_post('customer_id'), get_post('filterType'), check_value('showSettled'));
//------------------------------------------------------------------------------------------------
$cols = array(