display_error( _("The Terms description must be entered."));
set_focus('terms');
}
-
- if ($_POST['DayNumber'] == '')
- $_POST['DayNumber'] = 0;
+ $early_days = input_num('early_days', 0);
+ if ($early_days) {
+ if ($early_days >= $_POST['DayNumber']) {
+ $input_error = 1;
+ display_error(_("Early payment days option should be shorter that payment term days."));
+ set_focus('early_days');
+ } else if (!check_num('early_discount', 0, 100) or input_num('early_discount') == 0)
+ {
+ $input_error = 1;
+ display_error(_("The payment discount must be numeric and is expected to be less than 100% and greater than or equal to 0."));
+ set_focus('early_discount');
+ }
+ } else {
+ if (input_num('early_discount', 0)) {
+ $input_error = 1;
+ display_error(_("Early payment days option should be positive and less than payment term days."));
+ set_focus('early_days');
+ }
+ }
if ($input_error != 1)
{
-
if ($selected_id != -1)
{
- update_payment_terms($selected_id, get_post('terms'), get_post('type'), input_num('DayNumber', 0));
+ update_payment_terms($selected_id, get_post('terms'), get_post('type'), input_num('DayNumber', 0), input_num('early_discount')/100, $early_days);
$note = _('Selected payment terms have been updated');
}
else
{
- add_payment_terms(get_post('terms'), get_post('type'), input_num('DayNumber', 0));
+ add_payment_terms(get_post('terms'), get_post('type'), input_num('DayNumber', 0), input_num('early_discount')/100, $early_days);
$note = _('New payment terms have been added');
}
//run the sql from either of the above possibilites
start_form();
start_table(TABLESTYLE);
-$th = array(_("Description"), _("Type"), _("Due After/Days"), "", "");
+$th = array(_("Description"), _("Type"), _("Due After/Days"), _("Early payment discount"),"", "");
inactive_control_column($th);
table_header($th);
while ($myrow = db_fetch($result))
{
$days = $myrow['days'];
+ $percent = $myrow['early_discount'];
+
alt_table_row_color($k);
label_cell($myrow["terms"]);
label_cell($pterm_types[$myrow['type']]);
label_cell($myrow['type'] == PTT_DAYS ? "$days "._("days") : ($myrow['type'] == PTT_FOLLOWING ? $days : _("N/A")));
+ label_cell(in_array($myrow['type'], array(PTT_FOLLOWING, PTT_DAYS)) ? ($percent==0 ? _("None") : ($percent*100).'/'.$myrow['early_days']) : _("N/A"));
inactive_control_cell($myrow["id"], $myrow["inactive"], 'payment_terms', "id");
edit_button_cell("Edit".$myrow["id"], _("Edit"));
delete_button_cell("Delete".$myrow["id"], _("Delete"));
$_POST['terms'] = $myrow["terms"];
$_POST['type'] = $myrow['type'];
$_POST['DayNumber'] = $myrow['days'];
+ $_POST['early_discount'] = $myrow['early_discount']*100;
+ $_POST['early_days'] = $myrow['early_days'];
}
hidden('selected_id', $selected_id);
}
payment_type_list_row(_("Payment type:"), 'type', null, true);
-if ( in_array(get_post('type'), array(PTT_FOLLOWING, PTT_DAYS)))
+if ( in_array(get_post('type'), array(PTT_FOLLOWING, PTT_DAYS))) {
text_row_ex(_("Days (Or Day In Following Month):"), 'DayNumber', 3);
-else
+ small_amount_row(_("Days of early payment discount option:"), 'early_days', null, null, _('days'), 0);
+ small_amount_row(_("Early payment discount percent:"), 'early_discount', null, null, _('%'), 1);
+} else
hidden('DayNumber', 0);
end_table(1);
end_form();
end_page();
-
}
function add_item($type, $type_no, $date_, $due_date, $amount, $amount_allocated,
- $current_allocated, $ref)
+ $current_allocated, $ref, $early_discount=0, $early_days=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);
+ $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days);
return true;
}
else
}
function update_item($index, $type, $type_no, $date_, $due_date,
- $amount, $amount_allocated, $current_allocated, $ref)
+ $amount, $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0)
{
if (floatcmp($amount, 0))
{
$this->allocs[$index] = new allocation_item($type, $type_no,
- $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref);
+ $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days);
return true;
}
else
}
function add_or_update_item($type, $type_no, $date_, $due_date,
- $amount, $amount_allocated, $current_allocated, $ref)
+ $amount, $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0)
{
for ($i = 0; $i < count($this->allocs); $i++)
{
if (($item->type == $type) && ($item->type_no == $type_no))
{
return $this->update_item($i, $type, $type_no, $date_, $due_date,
- $amount, $amount_allocated, $current_allocated, $ref);
+ $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days);
}
}
return $this->add_item($type, $type_no, $date_, $due_date,
- $amount, $amount_allocated, $current_allocated, $ref);
+ $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days);
}
//
sql2date($myrow["due_date"]),
$myrow["Total"], // trans total
$myrow["alloc"], // trans total allocated
- 0,
- $myrow["reference"]); // this allocation
+ 0, // this allocation
+ $myrow["reference"], $myrow["early_discount"], $myrow["early_days"]);
}
}
if ($this->trans_no == 0) return; // this is new payment
sql2date($myrow["tran_date"]),
sql2date($myrow["due_date"]),
$myrow["Total"],
- $myrow["alloc"] - $myrow["amt"], $myrow["amt"], $myrow["reference"]);
+ $myrow["alloc"] - $myrow["amt"], $myrow["amt"], $myrow["reference"], $myrow["early_discount"], $myrow["early_days"]);
}
}
//
} else {
add_cust_allocation($amount,
$this->type, $this->trans_no,
- $alloc_item->type, $alloc_item->type_no, $this->person_id, $this->date_);
+ $alloc_item->type, $alloc_item->type_no, $this->person_id, $this->date_);
update_debtor_trans_allocation($alloc_item->type, $alloc_item->type_no, $this->person_id);
}
+
// Exchange Variations Joe Hunt 2008-09-20 ////////////////////
if ($alloc_item->type != ST_SALESORDER && !@$no_exchange_variations
&& $alloc_item->type != ST_PURCHORDER && $alloc_item->type != ST_JOURNAL && $this->type != ST_JOURNAL)
var $ref;
var $current_allocated;
+ var $early_discount; // nominal early payment discount according to payment terms
+ var $early_days; // days for early payment
function __construct($type, $type_no, $date_, $due_date, $amount,
- $amount_allocated, $current_allocated, $ref)
+ $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0)
{
$this->type = $type;
$this->amount = $amount;
$this->amount_allocated = $amount_allocated;
$this->current_allocated = $current_allocated;
+ $this->early_discount = $early_discount;
+ $this->early_days = $early_days;
}
}
//--------------------------------------------------------------------------------
-function show_allocatable($show_totals) {
+function show_allocatable($reallocation) {
global $systypes_array;
- $k = $total_allocated = 0;
+ $k = $total_allocated = $total_discount = 0;
$cart = $_SESSION['alloc'];
$supp_ref = in_array($cart->type, array(ST_SUPPCREDIT, ST_SUPPAYMENT, ST_BANKPAYMENT));
display_heading(sprintf(_("Allocated amounts in %s:"), $cart->person_curr));
start_table(TABLESTYLE, "width='60%'");
$th = array(_("Transaction Type"), _("#"), $supp_ref ? _("Supplier Ref"): _("Ref"), _("Date"), _("Due Date"), _("Amount"),
- _("Other Allocations"), _("Left to Allocate"), _("This Allocation"),'','');
+ _("Other Allocations"), _("Left to Allocate"), _("Early Payment Discount"), _("This Allocation"),'','');
table_header($th);
-
+ $doc_ids = array();
foreach ($cart->allocs as $id => $alloc_item)
{
- if (floatcmp(abs($alloc_item->amount), $alloc_item->amount_allocated))
- {
+ $doc_ids[] = $id;
+ $early_discount = $alloc_item->early_discount != 0 && !date1_greater_date2($cart->date_, add_days($alloc_item->date_, $alloc_item->early_days));
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), "nowrap align='right'");
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));
+ if ($early_discount) {
+ $discount = price_format($alloc_item->early_discount*abs($alloc_item->amount));
+
+ if ($reallocation)
+ label_cell($discount, 'align=center');
+ else
+ check_cells(null, 'early_disc'.$id, $discount, false, false, 'align=center');
+ $total_discount += $discount;
+ } else {
+ label_cell(_("N/A"), 'align=center'); hidden('early_disc'.$id, 0);
+ }
+ amount_cells(null, "amount" . $id);
+ if (0) {
+ label_cells('', '', '', 'colspan=2');
+ } else {
+ 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) {
+ add_js_source('var docs=['.implode(',', $doc_ids).']');
+ if ($reallocation) {
label_row(_("Total Allocated"), price_format($total_allocated),
- "colspan=8 align=right", "align=right id='total_allocated'", 3);
+ "colspan=9 align=right", "align=right id='total_allocated'", 3);
+
+ label_row(_("Total Discount"), price_format($total_discount),
+ "colspan=9 align=right", "align=right id='total_discount'", 3);
$amount = abs($cart->amount);
$font1 = $font2 = "";
$left_to_allocate = price_format($amount - $total_allocated);
label_row(_("Left to Allocate"), $font1 . $left_to_allocate . $font2,
- "colspan=8 align=right", "nowrap align=right id='left_to_allocate'",
+ "colspan=9 align=right", "nowrap align=right id='left_to_allocate'",
3);
}
end_table(1);
}
return $allocs;
}
+
if ($value === null)
$value = get_post($name,0);
- $str .= "<input"
- .($value == 1 ? ' checked':'')
- ." type='checkbox' name='$name' value='1'"
+ $str .= "<input class=check"
+ .($value != 0 ? ' checked':'')
+ ." type='checkbox' name='$name' value='".$value."'"
.($submit_on_change ? " onclick='$submit_on_change'" : '')
.($title ? " title='$title'" : '')
." >\n";
price_format('total_allocated', total, user.pdec, 1, 1);
}
+function update_totals() {
+ var amount = 0;
+ var discount = 0;
+
+ for (var i=0; i<docs.length; i++) {
+ amount += get_amount('amount'+docs[i])
+ if (document.getElementsByName('early_disc'+docs[i])[0].checked
+ && (get_amount('un_allocated'+docs[i]) == get_amount('amount'+docs[i])))
+ discount += get_amount('early_disc'+docs[i]);
+ }
+ price_format('amount', amount-discount, user.pdec);
+ price_format('discount', discount, user.pdec);
+
+}
+
function allocate_all(doc) {
var amount = get_amount('amount'+doc);
var unallocated = get_amount('un_allocated'+doc);
e.onfocus = function() {
focus_alloc(this);
};
+ },
+ '.check':function(e) {
+ e.onclick = function() {
+ update_totals();
+ }
}
}
}
}
-function allocate_all(doc) {
- var amount = get_amount('amount'+doc);
- var unallocated = get_amount('un_allocated'+doc);
- var total = get_amount('amount');
- var left = 0;
- total -= (amount-unallocated);
- left -= (amount-unallocated);
- amount = unallocated;
- if(left<0) {
- total += left;
- amount += left;
- left = 0;
+function update_totals() {
+ var amount = 0;
+ var discount = 0;
+
+ for (var i=0; i<docs.length; i++) {
+ amount += get_amount('amount'+docs[i])
+ if (document.getElementsByName('early_disc'+docs[i])[0].checked
+ && (get_amount('un_allocated'+docs[i]) == get_amount('amount'+docs[i])))
+ discount += get_amount('early_disc'+docs[i]);
}
- price_format('amount'+doc, amount, user.pdec);
- price_format('amount', total, user.pdec);
+ price_format('amount', amount-discount, user.pdec);
+ price_format('discount', discount, user.pdec);
+
+}
+
+function allocate_all(doc) {
+ var unallocated = get_amount('maxval'+doc, 1);
+ price_format('amount'+doc, unallocated, user.pdec);
+ update_totals();
}
function allocate_none(doc) {
- amount = get_amount('amount'+doc);
- total = get_amount('amount');
price_format('amount'+doc, 0, user.pdec);
- price_format('amount', total-amount, user.pdec);
+ update_totals();
}
+
var allocations = {
'.amount': function(e) {
if(e.name == 'allocated_amount' || e.name == 'bank_amount')
focus_alloc(this);
};
}
+ },
+ '.check':function(e) {
+ e.onclick = function() {
+ update_totals();
+ }
}
}
due_dates.date as due_date,
supplier.address,
amt,
- supp_reference as supp_ref
+ supp_reference as supp_ref,
+ 0, 0
FROM ".TB_PREF."purch_orders as porder
LEFT JOIN ".TB_PREF."suppliers as supplier ON porder.supplier_id = supplier.supplier_id
LEFT JOIN ".TB_PREF."supp_allocations as alloc
trans.due_date,
trans.supplier_id,
amt,
- supp_reference
+ supp_reference,
+ pmt.early_days,
+ pmt.early_discount
FROM ".TB_PREF."supp_trans as trans
+ LEFT JOIN ".TB_PREF."suppliers supplier ON trans.supplier_id=supplier.supplier_id
+ LEFT JOIN ".TB_PREF."payment_terms as pmt ON supplier.payment_terms=pmt.id
LEFT JOIN ".TB_PREF."supp_allocations as alloc
- ON trans.trans_no = alloc.trans_no_to AND trans.type = alloc.trans_type_to AND alloc.person_id=trans.supplier_id,"
- .TB_PREF."suppliers as supplier
- WHERE
- trans.supplier_id=supplier.supplier_id";
- if ($supplier_id)
- $sql .= " AND supplier.supplier_id=".db_escape($supplier_id);
+ ON trans.trans_no = alloc.trans_no_to AND trans.type = alloc.trans_type_to AND alloc.person_id=trans.supplier_id";
if ($trans_no != null and $type != null)
{
- $sql .= " AND alloc.trans_no_from=".db_escape($trans_no)."
+ $sql .= " WHERE alloc.trans_no_from=".db_escape($trans_no)."
AND alloc.trans_type_from=".db_escape($type);
}
else
{
- $sql .= " AND round(ov_amount+ov_gst+ov_discount-alloc,6) > 0
+ $sql .= " WHERE round(ov_amount+ov_gst+ov_discount-alloc,6) > 0
AND trans.type NOT IN (".implode(',',array(ST_SUPPAYMENT, ST_BANKPAYMENT)).")";
- $sql .= " GROUP BY type, trans_no";
}
+ if ($supplier_id)
+ $sql .= " AND supplier.supplier_id=".db_escape($supplier_id);
+
+
$orders = get_allocatable_purch_orders($supplier_id, $trans_no, $type);
$sql = "($sql ORDER BY trans_no) \nUNION \n($orders)";
$Ajax->activate('due_date');
}
- date_row(_("Due Date") . ":", 'due_date');
-
label_row(_("Terms:"), $supp_trans->terms['description']);
+ date_row(_("Due Date") . ":", 'due_date');
+
if (get_company_pref('use_dimension'))
dimensions_list_row(_('Dimension').':', 'dimension', null, true, _('Default'), false, 1);
table_section(2);
+ label_row(_("Terms:"), $order->terms['description']);
+
if ($order->trans_type==ST_SUPPINVOICE)
date_row(_("Due Date:"), 'due_date', '', false, 0, 0, 0, null, true);
dimensions_list_row(_('Dimension').':', 'dimension', null, true, _('Default'), false, 1);
if (get_company_pref('use_dimension') == 2)
dimensions_list_row(_('Dimension 2').':', 'dimension2', null, true, _('Default'), false, 2);
- locations_list_row(_("Receive Into:"), 'StkLocation', null, false, true, $order->fixed_asset);
table_section(3);
-
+ locations_list_row(_("Receive Into:"), 'StkLocation', null, false, true, $order->fixed_asset);
if (!isset($_POST['StkLocation']) || $_POST['StkLocation'] == "" ||
isset($_POST['_StkLocation_update']) || !isset($_POST['delivery_address']) ||
$_POST['delivery_address'] == "")
echo "<center>" . _("Select a customer: ") . " ";
echo customer_list('customer_id', $_POST['customer_id'], true, true);
echo "<br>";
+
check(_("Show Settled Items:"), 'ShowSettled', null, true);
echo "</center><br><br>";
function alloc_link($row)
{
- return pager_link(_("Allocate"),
+ global $all_settled;
+
+ return ($row['settled']&&!get_post('ShowSettled')) || (!$row['settled'] && $all_settled) ? '' : pager_link(_("Allocate"),
"/sales/allocations/customer_allocate.php?trans_no="
.$row["trans_no"] . "&trans_type=" . $row["type"]. "&debtor_no=" . $row["debtor_no"], ICON_ALLOC);
}
return $row['settled'] == 1;
}
+$all_settled = !db_num_rows(get_allocatable_to_cust_transactions($customer_id));
+if ($all_settled)
+ display_note('<b>'._("There is no unsettled transactions for this customer.").'</b>');
$sql = get_allocatable_from_cust_sql($customer_id, $settled);
$_POST['bank_account'] = $dflt_act['id'];
}
if (!isset($_POST['DateBanked'])) {
- $_POST['DateBanked'] = new_doc_date();
+ $_SESSION['alloc']->date_ =$_POST['DateBanked'] = new_doc_date();
if (!is_date_in_fiscalyear($_POST['DateBanked'])) {
$_POST['DateBanked'] = end_fiscalyear();
}
}
+if (get_post('_DateBanked_changed')) {
+ if (!is_date($_POST['DateBanked'])) {
+ display_error(_("The entered date is invalid. Please enter a valid date for the payment."));
+ set_focus('DateBanked');
+ } else {
+ $_SESSION['alloc']->date_ = get_post('DateBanked');
+ $Ajax->activate('_page_body');
+ }
+}
if (isset($_GET['AddedID'])) {
$payment_no = $_GET['AddedID'];
$new_pmt = !$_SESSION['alloc']->trans_no;
$payment_no = save_cust_payment($_SESSION['alloc'], get_post('customer_id'), get_post('BranchID'), get_post('bank_account'),
- get_post('DateBanked'), get_post('ref'), input_num('amount'), input_num('discount'), get_post('memo_'),
- input_num('charge'), input_num('bank_amount', input_num('amount')));
+ get_post('DateBanked'), get_post('ref'), input_num('amount'), input_num('discount'), get_post('memo_'),
+ input_num('charge'), input_num('bank_amount', input_num('amount')));
unset($_SESSION['alloc']);
meta_forward($_SERVER['PHP_SELF'], $new_pmt ? "AddedID=$payment_no" : "UpdatedID=$payment_no");
$myrow = get_customer_habit($_POST['customer_id']);
$_POST['HoldAccount'] = $myrow["dissallow_invoices"];
- $_POST['pymt_discount'] = $myrow["pymt_discount"];
// To support Edit feature
// If page is called first time and New entry fetch the nex reference number
if (!$_SESSION['alloc']->trans_no && !isset($_POST['charge']))
set_global_customer($_POST['customer_id']);
if (isset($_POST['HoldAccount']) && $_POST['HoldAccount'] != 0)
display_warning(_("This customer account is on hold."));
-$display_discount_percent = percent_format($_POST['pymt_discount']*100) . "%";
table_section(2);
start_table(TABLESTYLE, "width='60%'");
-label_row(_("Customer prompt payment discount :"), $display_discount_percent);
-
amount_row(_("Amount of Discount:"), 'discount', null, '', $cust_currency);
amount_row(_("Amount:"), 'amount', null, '', $cust_currency);
var $pos; // user assigned POS
var $cash_account;
var $account_name;
- var $cash_discount; // not used as of FA 2.1
var $dimension_id;
var $dimension2_id;
var $payment;
return $ret;
}
- function set_customer($customer_id, $customer_name, $currency, $discount, $payment, $cdiscount=0)
+ function set_customer($customer_id, $customer_name, $currency, $discount, $payment)
{
$this->customer_name = $customer_name;
$this->customer_id = $customer_id;
$this->customer_currency = $currency;
$this->payment = $payment;
$this->payment_terms = get_payment_terms($payment);
- $this->cash_discount = $cdiscount;
if ($this->payment_terms['type'] == PTT_CASH) {
$this->Location = $this->pos['pos_location'];
.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))
+ AND (((type=".ST_CUSTPAYMENT." OR type=".ST_BANKDEPOSIT.") AND (trans.ov_amount+ov_discount > 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)";
+ $sql .= " AND (round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-alloc,6) > 0)";
if ($customer_id != null)
$sql .= " AND trans.debtor_no = ".db_escape($customer_id);
sorder.version,
amt,
sorder.debtor_no,
- sorder.branch_code
+ sorder.branch_code,
+ pmt.early_days,
+ pmt.early_discount
FROM ".TB_PREF."sales_orders as sorder
LEFT JOIN ".TB_PREF."debtors_master as debtor ON sorder.debtor_no = debtor.debtor_no
+ LEFT JOIN ".TB_PREF."payment_terms as pmt ON sorder.payment_terms=pmt.id
LEFT JOIN ".TB_PREF."cust_allocations as alloc
ON sorder.order_no = alloc.trans_no_to AND sorder.trans_type = alloc.trans_type_to AND alloc.person_id=sorder.debtor_no
LEFT JOIN (SELECT order_, sum(prep_amount) amount FROM ".TB_PREF."debtor_trans dt
trans.version,
amt,
trans.debtor_no,
- trans.branch_code
+ trans.branch_code,
+ pmt.early_days,
+ pmt.early_discount
FROM ".TB_PREF."debtor_trans as trans
LEFT JOIN ".TB_PREF."cust_allocations as alloc
- ON trans.trans_no = alloc.trans_no_to AND trans.type = alloc.trans_type_to AND alloc.person_id=trans.debtor_no,"
+ ON trans.trans_no = alloc.trans_no_to AND trans.type = alloc.trans_type_to AND alloc.person_id=trans.debtor_no
+ LEFT JOIN ".TB_PREF."payment_terms as pmt ON trans.payment_terms=pmt.id,"
.TB_PREF."debtors_master as debtor
WHERE
trans.debtor_no=debtor.debtor_no";
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>alloc
OR
trans.type = '". ST_BANKPAYMENT."'
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>alloc
)";
$sql .= " GROUP BY type, trans_no";
}
***********************************************************************/
function add_customer($CustName, $cust_ref, $address, $tax_id, $curr_code,
- $dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount, $pymt_discount,
+ $dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount,
$credit_limit, $sales_type, $notes)
{
$sql = "INSERT INTO ".TB_PREF."debtors_master (name, debtor_ref, address, tax_id,
dimension_id, dimension2_id, curr_code, credit_status, payment_terms, discount,
- pymt_discount,credit_limit, sales_type, notes) VALUES ("
+ credit_limit, sales_type, notes) VALUES ("
.db_escape($CustName) .", " .db_escape($cust_ref) .", "
.db_escape($address) . ", " . db_escape($tax_id) . ","
.db_escape($dimension_id) . ", "
.db_escape($dimension2_id) . ", ".db_escape($curr_code) . ",
- " . db_escape($credit_status) . ", ".db_escape($payment_terms) . ", " . $discount . ",
- " . $pymt_discount . ", " . $credit_limit
+ " . db_escape($credit_status) .", " . db_escape($payment_terms) .", " . $discount . "," . $credit_limit
.", ".db_escape($sales_type).", ".db_escape($notes) . ")";
db_query($sql,"The customer could not be added");
}
function update_customer($customer_id, $CustName, $cust_ref, $address, $tax_id, $curr_code,
- $dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount, $pymt_discount,
+ $dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount,
$credit_limit, $sales_type, $notes)
{
$sql = "UPDATE ".TB_PREF."debtors_master SET name=" . db_escape($CustName) . ",
credit_status=".db_escape($credit_status) . ",
payment_terms=".db_escape($payment_terms) . ",
discount=" . $discount . ",
- pymt_discount=" . $pymt_discount . ",
credit_limit=" . $credit_limit . ",
sales_type = ".db_escape($sales_type) . ",
notes=".db_escape($notes) ."
function get_customer_habit($customer_id)
{
- $sql = "SELECT debtor.pymt_discount, credit_status.dissallow_invoices
+ $sql = "SELECT credit_status.dissallow_invoices
FROM ".TB_PREF."debtors_master debtor,"
.TB_PREF."credit_status credit_status
WHERE debtor.credit_status = credit_status.id
$amount = $items_total + $items_added_tax + $invoice->freight_cost
+ $freight_added_tax;
- // to use debtors.pmt_discount on cash sale:
- // extend invoice entry page with final amount after discount
- // and change line below.
- $discount = 0; // $invoice->cash_discount*$amount;
+ $discount = 0;
$pmtno = write_customer_payment(0, $invoice->customer_id,
$invoice->Branch, $invoice->pos['pos_account'], $date_,
$Refs->get_next(ST_CUSTPAYMENT, null, array('customer' => $invoice->customer_id,
cust.curr_code,
cust.discount,
cust.payment_terms,
- cust.pymt_discount,
cust.credit_limit - Sum(IFNULL(IF(trans.type IN(".implode(',', array(ST_CUSTCREDIT, ST_CUSTPAYMENT, ST_BANKDEPOSIT))."),
-1, 1) * (ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount),0)) as cur_credit
FROM ".TB_PREF."debtors_master cust
}
function write_customer($customer_id, $name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status,
- $payment_terms, $discount, $pymt_discount, $credit_limit, $sales_type, $notes, $inactive, $salesman, $area,
+ $payment_terms, $discount, $credit_limit, $sales_type, $notes, $inactive, $salesman, $area,
$tax_group, $location, $address, $ship_via, $notes, $bank_account, $address, $phone, $phone2, $fax, $email)
{
global $SysPrefs;
if ($customer_id) {
update_customer($customer_id, $name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status,
- $payment_terms, $discount/100, $pymt_discount/100, $credit_limit, $sales_type, $notes, $inactive);
+ $payment_terms, $discount/100, $credit_limit, $sales_type, $notes, $inactive);
update_record_status($customer_id, $inactive, 'debtors_master', 'debtor_no');
} else {
add_customer($name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status, $payment_terms,
- $discount / 100, $pymt_discount / 100, $credit_limit, $sales_type, $notes);
+ $discount / 100, $credit_limit, $sales_type, $notes);
$customer_id = db_insert_id();
$deliver = $myrow['address']; // in case no branch address use company address
$order->set_customer($customer_id, $name, $myrow['curr_code'],
- $myrow['discount'], $myrow['payment_terms'], $myrow['pymt_discount']);
+ $myrow['discount'], $myrow['payment_terms']);
// the sales type determines the price list to be used by default
$order->set_sales_type($myrow['salestype'], $myrow['sales_type'], $myrow['tax_included'],
return false;
}
- if (!check_num('pymt_discount', 0, 100))
- {
- display_error(_("The payment discount must be numeric and is expected to be less than 100% and greater than or equal to 0."));
- set_focus('pymt_discount');
- return false;
- }
-
if (!check_num('discount', 0, 100))
{
display_error(_("The discount percentage must be numeric and is expected to be less than 100% and greater than or equal to 0."));
$_POST['customer_id'] = write_customer($_POST['customer_id'], $_POST['CustName'], $_POST['cust_ref'], $_POST['address'],
$_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'],
- $_POST['credit_status'], $_POST['payment_terms'], input_num('discount'), input_num('pymt_discount'),
+ $_POST['credit_status'], $_POST['payment_terms'], input_num('discount'),
input_num('credit_limit'), $_POST['sales_type'], $_POST['notes'], @$_POST['inactive'], get_post('salesman'),
get_post('area'), get_post('tax_group_id'), get_post('location'), get_post('address'), get_post('ship_via'),
get_post('notes'), get_post('bank_account'), get_post('address'), get_post('phone'), get_post('phone2'), get_post('fax'), get_post('email'));
$_POST['credit_status'] = -1;
$_POST['payment_terms'] = $_POST['notes'] = '';
- $_POST['discount'] = $_POST['pymt_discount'] = percent_format(0);
+ $_POST['discount'] = percent_format(0);
$_POST['credit_limit'] = price_format($SysPrefs->default_credit_limit());
}
}
$_POST['credit_status'] = $myrow["credit_status"];
$_POST['payment_terms'] = $myrow["payment_terms"];
$_POST['discount'] = percent_format($myrow["discount"] * 100);
- $_POST['pymt_discount'] = percent_format($myrow["pymt_discount"] * 100);
$_POST['credit_limit'] = price_format($myrow["credit_limit"]);
$_POST['notes'] = $myrow["notes"];
$_POST['inactive'] = $myrow["inactive"];
table_section_title(_("Sales"));
percent_row(_("Discount Percent:"), 'discount', $_POST['discount']);
- percent_row(_("Prompt Payment Discount Percent:"), 'pymt_discount', $_POST['pymt_discount']);
amount_row(_("Credit Limit:"), 'credit_limit', $_POST['credit_limit']);
payment_terms_list_row(_("Payment Terms:"), 'payment_terms', $_POST['payment_terms']);
`credit_status` int(11) NOT NULL DEFAULT '0',
`payment_terms` int(11) DEFAULT NULL,
`discount` double NOT NULL DEFAULT '0',
- `pymt_discount` double NOT NULL DEFAULT '0',
`credit_limit` float NOT NULL DEFAULT '1000',
`notes` tinytext NOT NULL,
`inactive` tinyint(1) NOT NULL DEFAULT '0',
-- Data of table `0_debtors_master` --
INSERT INTO `0_debtors_master` VALUES
-('1', 'Donald Easter LLC', 'Donald Easter', 'N/A', '123456789', 'USD', '1', '0', '0', '1', '4', '0', '0', '1000', '', '0'),
-('2', 'MoneyMaker Ltd.', 'MoneyMaker', 'N/A', '54354333', 'EUR', '1', '1', '0', '1', '1', '0', '0', '1000', '', '0');
+('1', 'Donald Easter LLC', 'Donald Easter', 'N/A', '123456789', 'USD', '1', '0', '0', '1', '4', '0', '1000', '', '0'),
+('2', 'MoneyMaker Ltd.', 'MoneyMaker', 'N/A', '54354333', 'EUR', '1', '1', '0', '1', '1', '0', '1000', '', '0');
-- Structure of table `0_dimensions` --
`credit_status` int(11) NOT NULL DEFAULT '0',
`payment_terms` int(11) DEFAULT NULL,
`discount` double NOT NULL DEFAULT '0',
- `pymt_discount` double NOT NULL DEFAULT '0',
`credit_limit` float NOT NULL DEFAULT '1000',
`notes` tinytext NOT NULL,
`inactive` tinyint(1) NOT NULL DEFAULT '0',