return $installed_extensions;
}
-function add_payment_terms($daysOrFoll, $terms, $dayNumber)
+function add_payment_terms($terms, $type, $days=0, $early_discount=0, $early_days=0)
{
begin_transaction(__FUNCTION__, func_get_args());
- if ($daysOrFoll)
- {
- $sql = "INSERT INTO ".TB_PREF."payment_terms (terms,
- days_before_due, day_in_following_month)
- VALUES (" .
- db_escape($terms) . ", " . db_escape($dayNumber) . ", 0)";
- }
- else
- {
- $sql = "INSERT INTO ".TB_PREF."payment_terms (terms,
- days_before_due, day_in_following_month)
- VALUES (" . db_escape($terms) . ",
- 0, " . db_escape($dayNumber) . ")";
- }
+ $sql = "INSERT INTO ".TB_PREF."payment_terms (terms, type, days, early_discount, early_days)
+ VALUES (" .db_escape($terms) . "," . db_escape($type) . ", ".db_escape($days). ", ".db_escape($early_discount). ", ".db_escape($early_days).")";
+
db_query($sql,"The payment term could not be added");
commit_transaction();
}
-function update_payment_terms($selected_id, $daysOrFoll, $terms, $dayNumber)
+function update_payment_terms($selected_id, $terms, $type, $days=0, $early_discount=0, $early_days=0)
{
begin_transaction(__FUNCTION__, func_get_args());
- if ($daysOrFoll)
- {
- $sql = "UPDATE ".TB_PREF."payment_terms SET terms=" . db_escape($terms) . ",
- day_in_following_month=0,
- days_before_due=" . db_escape($dayNumber) . "
- WHERE terms_indicator = " .db_escape($selected_id);
- }
- else
- {
- $sql = "UPDATE ".TB_PREF."payment_terms SET terms=" . db_escape($terms) . ",
- day_in_following_month=" . db_escape($dayNumber) . ",
- days_before_due=0
- WHERE terms_indicator = " .db_escape($selected_id);
- }
+ $sql = "UPDATE ".TB_PREF."payment_terms SET terms=" . db_escape($terms) . ",
+ type=".db_escape($type).",
+ days=" . db_escape($days).",
+ early_discount=".db_escape($early_discount).",
+ early_days=".db_escape($early_days).
+ " WHERE id = " .db_escape($selected_id);
+
db_query($sql,"The payment term could not be updated");
commit_transaction();
{
begin_transaction(__FUNCTION__, func_get_args());
- $sql="DELETE FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($selected_id);
+ $sql="DELETE FROM ".TB_PREF."payment_terms WHERE id=".db_escape($selected_id);
db_query($sql,"could not delete a payment terms");
commit_transaction();
function get_payment_terms($selected_id)
{
- $sql = "SELECT *, (t.days_before_due=0) AND (t.day_in_following_month=0) as cash_sale
- FROM ".TB_PREF."payment_terms t WHERE terms_indicator=".db_escape($selected_id);
+ $sql = "SELECT * FROM ".TB_PREF."payment_terms t WHERE id=".db_escape($selected_id);
$result = db_query($sql,"could not get payment term");
simple_page_mode(true);
-//------------------------------
-// Helper to translate record content to more intuitive form
-//
-function term_days($myrow)
-{
- return $myrow["day_in_following_month"] != 0 ? $myrow["day_in_following_month"] :
- $myrow["days_before_due"];
-}
-
-function term_type($myrow)
-{
- if ($myrow["day_in_following_month"] != 0)
- return PTT_FOLLOWING;
-
- $days = $myrow["days_before_due"];
-
- return $days < 0 ? PTT_PRE : ($days ? PTT_DAYS : PTT_CASH);
-}
-
//-------------------------------------------------------------------------------------------
if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
if ($input_error != 1)
{
- $type = get_post('type');
- $days = input_num('DayNumber');
- $from_now = ($type != PTT_FOLLOWING);
- if ($type == PTT_CASH)
- $days = 0;
- if ($type == PTT_PRE)
- $days = -1;
if ($selected_id != -1)
{
- update_payment_terms($selected_id, $from_now, $_POST['terms'], $days);
+ update_payment_terms($selected_id, get_post('terms'), get_post('type'), input_num('DayNumber', 0));
$note = _('Selected payment terms have been updated');
}
else
{
- add_payment_terms($from_now, $_POST['terms'], $days);
+ add_payment_terms(get_post('terms'), get_post('type'), input_num('DayNumber', 0));
$note = _('New payment terms have been added');
}
//run the sql from either of the above possibilites
$k = 0; //row colour counter
while ($myrow = db_fetch($result))
{
-
+ $days = $myrow['days'];
alt_table_row_color($k);
- $type = term_type($myrow);
- $days = term_days($myrow);
label_cell($myrow["terms"]);
- label_cell($pterm_types[$type]);
- label_cell($type == PTT_DAYS ? "$days "._("days") : ($type == PTT_FOLLOWING ? $days : _("N/A")));
- inactive_control_cell($myrow["terms_indicator"], $myrow["inactive"], 'payment_terms', "terms_indicator");
- edit_button_cell("Edit".$myrow["terms_indicator"], _("Edit"));
- delete_button_cell("Delete".$myrow["terms_indicator"], _("Delete"));
+ label_cell($pterm_types[$myrow['type']]);
+ label_cell($myrow['type'] == PTT_DAYS ? "$days "._("days") : ($myrow['type'] == PTT_FOLLOWING ? $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"));
end_row();
}
start_table(TABLESTYLE2);
-$day_in_following_month = $days_before_due = 0;
if ($selected_id != -1)
{
if ($Mode == 'Edit') {
$myrow = get_payment_terms($selected_id);
$_POST['terms'] = $myrow["terms"];
- $_POST['DayNumber'] = term_days($myrow);
- $_POST['type'] = term_type($myrow);
+ $_POST['type'] = $myrow['type'];
+ $_POST['DayNumber'] = $myrow['days'];
}
hidden('selected_id', $selected_id);
}
//----------------------------------------------------------------------------------
$pterm_types = array(
- PTT_PRE => _("Prepayment"),
+ PTT_PREPAY => _("Prepayment"),
PTT_CASH => _("Cash"),
PTT_DAYS => _("After No. of Days"),
PTT_FOLLOWING => _("Day In Following Month")
//----------------------------------------------------------------------------------
// Payment term types
-define('PTT_PRE', 1);
+define('PTT_PREPAY', 1);
define('PTT_CASH', 2);
define('PTT_DAYS', 3);
define('PTT_FOLLOWING', 4);
function payment_terms_list($name, $selected_id=null)
{
- $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
- return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
+ $sql = "SELECT id, terms, inactive FROM ".TB_PREF."payment_terms";
+ return combo_input($name, $selected_id, $sql, 'id', 'terms', array());
}
function payment_terms_list_cells($label, $name, $selected_id=null)
//
function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
{
- $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
+ $sql = "SELECT id, terms, inactive FROM ".TB_PREF."payment_terms";
if ($category == PM_CASH) // only cash
- $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
+ $sql .= " WHERE type=".PTT_CASH;
elseif ($category == PM_CREDIT) // only delayed payments
- $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
+ $sql .= " WHERE type IN(".PTT_FOLLOWING.",".PTT_DAYS.")";
elseif (!$prepayments)
- $sql .= " WHERE days_before_due>=0";
+ $sql .= " WHERE type<>".PTT_PREPAY;
- return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
+ return combo_input($name, $selected_id, $sql, 'id', 'terms',
array(
'select_submit'=> $submit_on_change,
'async' => true
function read_supplier_details_to_trans(&$supp_trans, $supplier_id)
{
- $sql = "SELECT supp.supp_name, terms.terms, terms.days_before_due, supp.dimension_id, supp.dimension2_id,
- terms.day_in_following_month, supp.tax_included,
+ $sql = "SELECT supp.supp_name, supp.dimension_id, supp.dimension2_id, supp.tax_included,
supp.tax_group_id, tax_group.name AS tax_group_name,
- supp.credit_limit - Sum((ov_amount + ov_gst + ov_discount)) as cur_credit, curr_code
- FROM ".TB_PREF."suppliers supp LEFT JOIN "
- .TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id, "
- .TB_PREF."payment_terms terms, "
- .TB_PREF."tax_groups tax_group
- WHERE supp.tax_group_id = tax_group.id
- AND supp.payment_terms=terms.terms_indicator
- AND supp.supplier_id = ".db_escape($supplier_id)." GROUP BY supp.supp_name";
+ supp.credit_limit - Sum((ov_amount + ov_gst + ov_discount)) as cur_credit,
+ supp.curr_code,
+ terms.*
+ FROM ".TB_PREF."suppliers supp
+ LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id
+ LEFT JOIN ".TB_PREF."payment_terms terms ON supp.payment_terms=terms.id
+ LEFT JOIN ".TB_PREF."tax_groups tax_group ON supp.tax_group_id = tax_group.id
+ WHERE supp.supplier_id = ".db_escape($supplier_id);
$result = db_query($sql, "The supplier record selected: " . $supplier_id . " cannot be retrieved");
$supp_trans->supplier_name = $myrow['supp_name'];
$supp_trans->terms = array(
'description' => $myrow['terms'],
- 'days_before_due' => $myrow['days_before_due'],
- 'day_in_following_month' => $myrow['day_in_following_month'] );
-
+ 'type' => $myrow['type'],
+ 'days' => $myrow['days'],
+ 'early_discount' => $myrow['early_discount'],
+ 'early_days' => $myrow['early_days'],
+ );
$supp_trans->credit = $myrow['cur_credit'];
$supp_trans->tax_description = $myrow['tax_group_name'];
{
$sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, dimension_id, dimension2_id,
supp.credit_limit - Sum((ov_amount + ov_gst + ov_discount)) as cur_credit,
- terms.terms, terms.days_before_due, terms.day_in_following_month, tg.tax_area
+ terms.*, tg.tax_area
FROM ".TB_PREF."suppliers supp
LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id
- LEFT JOIN ".TB_PREF."payment_terms terms ON supp.payment_terms=terms.terms_indicator
+ LEFT JOIN ".TB_PREF."payment_terms terms ON supp.payment_terms=terms.id
LEFT JOIN ".TB_PREF."tax_groups tg ON supp.tax_group_id=tg.id
- WHERE supp.supplier_id = ".db_escape($supplier_id)."
- GROUP BY
- supp.supp_name";
+ WHERE supp.supplier_id = ".db_escape($supplier_id);
$result = db_query($sql, "The supplier details could not be retreived");
$myrow = db_fetch($result);
$order->credit = $myrow["cur_credit"];
$order->terms = array(
'description' => $myrow['terms'],
- 'days_before_due' => $myrow['days_before_due'],
- 'day_in_following_month' => $myrow['day_in_following_month'] );
+ 'type' => $myrow['type'],
+ 'days' => $myrow['days'],
+ 'early_discount' => $myrow['early_discount'],
+ 'early_days' => $myrow['early_days'],
+ );
$_POST['supplier_id'] = $supplier_id;
$_POST['supplier_name'] = $myrow["supp_name"];
supp.tax_group_id
FROM ".TB_PREF."suppliers supp
- LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id AND trans.tran_date <= '$todate',
- ".TB_PREF."payment_terms
-
+ LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id AND trans.tran_date <= '$todate'
+ LEFT JOIN ".TB_PREF."payment_terms ON supp.payment_terms = ".TB_PREF."payment_terms.id
WHERE
- supp.payment_terms = ".TB_PREF."payment_terms.terms_indicator
- AND supp.supplier_id = $supplier_id ";
+ supp.supplier_id = $supplier_id ";
if (!$all)
- $sql .= "AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount) - trans.alloc > ".FLOAT_COMP_DELTA." ";
- $sql .= "GROUP BY
- supp.supp_name,
- ".TB_PREF."payment_terms.terms,
- ".TB_PREF."payment_terms.days_before_due,
- ".TB_PREF."payment_terms.day_in_following_month";
+ $sql .= "AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount) - trans.alloc > ".FLOAT_COMP_DELTA." ";
+
$result = db_query($sql,"The customer details could not be retrieved");
$supp = db_fetch($result);
{
$date = Today();
}
- if ($trans->terms['day_in_following_month'])
+ if ($trans->terms['type'] == PTT_FOLLOWING)
{ /*Its a day in the following month when due */
$trans->due_date =
- add_days(end_month($date), $trans->terms["day_in_following_month"]);
+ add_days(end_month($date), $trans->terms["days"]);
}
else
{ /*Use the Days Before Due to add to the invoice date */
- $trans->due_date = add_days($date, $trans->terms["days_before_due"]);
+ $trans->due_date = add_days($date, $trans->terms["days"]);
}
}
$row = get_payment_terms($this->formData['payment_terms']);
$Payment_Terms = _("Payment Terms") . ': ' . $row["terms"];
if ($this->formData['doctype'] == ST_SALESINVOICE && $this->formData['prepaid'])
- $this->formData['prepaid'] = ($row['days_before_due'] >= 0) ? 'final' : 'partial';
+ $this->formData['prepaid'] = ($row['type'] != PTT_PREPAY) ? 'final' : 'partial';
}
WHERE ";
if ($fromsupp != ALL_TEXT)
$sql .= "supplier_id=".db_escape($fromsupp)." AND ";
- $sql .= "".TB_PREF."suppliers.payment_terms = ".TB_PREF."payment_terms.terms_indicator
+ $sql .= "".TB_PREF."suppliers.payment_terms = ".TB_PREF."payment_terms.id
ORDER BY supp_name";
$result = db_query($sql, "The customers could not be retrieved");
return false;
}
} else {
- if (($_SESSION['Items']->payment_terms['days_before_due'] == -1) && !count($_SESSION['Items']->prepayments)) {
+ if (($_SESSION['Items']->payment_terms['type'] == PTT_PREPAY) && !count($_SESSION['Items']->prepayments)) {
display_error(_("There is no non-invoiced payments for this order. If you want to issue final invoice, select delayed or cash payment terms."));
return false;
}
$_POST['Comments'] = '';
$Ajax->activate('due_date');
$Ajax->activate('options');
- if ($order->payment_terms['cash_sale']) {
+ if ($order->payment_terms['type'] == PTT_CASH) {
$_POST['Location'] = $order->Location = $order->pos['pos_location'];
$order->location_name = $order->pos['location_name'];
}
$this->payment_terms = get_payment_terms($payment);
$this->cash_discount = $cdiscount;
- if ($this->payment_terms['cash_sale']) {
+ if ($this->payment_terms['type'] == PTT_CASH) {
$this->Location = $this->pos['pos_location'];
$this->location_name = $this->pos['location_name'];
}
$remainder = prepaid_invoice_remainder($this->order_no);
// recalculate prepaid part from payments
- if ($this->payment_terms['days_before_due'] == -1)
+ if ($this->payment_terms['type'] == PTT_PREPAY)
{ // this is partial invoice for selected prepayments made.
$paid = 0;
foreach($this->prepayments as $payment)
$past1 = get_company_pref('past_due_days');
$past2 = 2 * $past1;
// removed - debtor_trans.alloc from all summations
- $sign = "IF(`type` IN(".implode(',', array(ST_CUSTCREDIT,ST_CUSTPAYMENT,ST_BANKDEPOSIT))."), -1, 1)";
+ $sign = "IF(trans.`type` IN(".implode(',', array(ST_CUSTCREDIT,ST_CUSTPAYMENT,ST_BANKDEPOSIT))."), -1, 1)";
if ($all)
$value = "IFNULL($sign*(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount),0)";
else
Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) > $past1,$value,0)) AS Overdue1,
Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) > $past2,$value,0)) AS Overdue2
FROM ".TB_PREF."debtors_master debtor
- LEFT JOIN ".TB_PREF."debtor_trans trans ON trans.tran_date <= '$todate' AND debtor.debtor_no = trans.debtor_no AND trans.type <> ".ST_CUSTDELIVERY.","
- .TB_PREF."payment_terms terms,"
+ LEFT JOIN ".TB_PREF."debtor_trans trans ON trans.tran_date <= '$todate' AND debtor.debtor_no = trans.debtor_no AND trans.type <> ".ST_CUSTDELIVERY."
+ LEFT JOIN ".TB_PREF."payment_terms terms ON debtor.payment_terms = terms.id,"
.TB_PREF."credit_status credit_status
WHERE
- debtor.payment_terms = terms.terms_indicator
- AND debtor.credit_status = credit_status.id";
+ debtor.credit_status = credit_status.id";
if ($customer_id)
$sql .= " AND debtor.debtor_no = ".db_escape($customer_id);
$sql .= " AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount - trans.alloc) > ".FLOAT_COMP_DELTA;
$sql .= " GROUP BY
debtor.name,
- terms.terms,
- terms.days_before_due,
- terms.day_in_following_month,
debtor.credit_limit,
credit_status.dissallow_invoices,
credit_status.reason_description";
{
$myrow = get_sales_order_header($order_no, ST_SALESORDER);
- return !$myrow['prepaid'];
+ return !$myrow['prepaid'] && ! $myrow['cash_sale'];
}
function create_template_invoice($customer_id, $branch_id, $order_no, $tmpl_no, $date, $from, $to, $memo)
$cart = $doc;
$cart->trans_type = ST_SALESINVOICE;
$cart->reference = $Refs->get_next($cart->trans_type);
- $cart->payment_terms['cash_sale'] = false; // no way to register cash payment with recurrent invoice at once
$invno = $cart->write(1);
if ($trans_no == 0) {
$Refs->save(ST_SALESINVOICE, $invoice_no, $invoice->reference, null, $invoice->fixed_asset);
- if ($invoice->payment_terms['cash_sale'] && $invoice->pos['pos_account']) {
+ if ($invoice->payment_terms['type'] == PTT_CASH && $invoice->pos['pos_account']) {
$amount = $items_total + $items_added_tax + $invoice->freight_cost
+ $freight_added_tax;
." AND so.trans_type=".ST_SALESORDER
." AND inv.type=".ST_SALESINVOICE
." AND inv.order_=so.order_no"
- ." AND so.payment_terms=pt.terms_indicator"
- ." AND inv.payment_terms=pt.terms_indicator"
- ." AND pt.days_before_due = -1";
+ ." AND so.payment_terms=pt.id"
+ ." AND inv.payment_terms=pt.id"
+ ." AND pt.type = ".PTT_PREPAY;
$result = db_fetch(db_query($sql, "cannot find final invoice value"));
return $result[0] ? $result[0] : 0;
cust.tax_id,
sorder.alloc,
IFNULL(allocs.ord_allocs, 0)+IFNULL(inv.inv_allocs ,0) AS sum_paid,
- sorder.prep_amount>0 as prepaid
+ sorder.prep_amount>0 as prepaid,
+ terms.type=".PTT_CASH." as cash_sale
FROM ".TB_PREF."sales_orders sorder
LEFT JOIN (SELECT trans_no_to, sum(amt) ord_allocs FROM ".TB_PREF."cust_allocations
- WHERE trans_type_to=".ST_SALESORDER." AND trans_no_to=".db_escape($order_no)." GROUP BY trans_no_to)
- allocs ON sorder.trans_type=".ST_SALESORDER." AND allocs.trans_no_to=sorder.order_no
+ WHERE trans_type_to=".ST_SALESORDER." AND trans_no_to=".db_escape($order_no)." GROUP BY trans_no_to) allocs
+ ON sorder.trans_type=".ST_SALESORDER." AND allocs.trans_no_to=sorder.order_no
LEFT JOIN (SELECT order_, sum(alloc) inv_allocs FROM ".TB_PREF."debtor_trans
WHERE type=".ST_SALESINVOICE." AND order_=".db_escape($order_no)." GROUP BY order_)
inv ON sorder.trans_type=".ST_SALESORDER." AND inv.order_=sorder.order_no
- LEFT JOIN ".TB_PREF."stock_master ship ON ship.stock_id = sorder.ship_via,"
+ LEFT JOIN ".TB_PREF."stock_master ship ON ship.stock_id = sorder.ship_via
+ LEFT JOIN ".TB_PREF."payment_terms terms ON sorder.payment_terms=terms.id,"
.TB_PREF."debtors_master cust,"
.TB_PREF."sales_types stype, "
.TB_PREF."tax_groups tax_group, "
if (!$myrow)
return $invdate;
- if ($myrow['day_in_following_month'] > 0)
- $duedate = add_days(end_month($invdate), $myrow['day_in_following_month']);
- elseif ($myrow['days_before_due'] > 0)
- $duedate = add_days($invdate, $myrow['days_before_due']);
+ if ($myrow['type'] == PTT_FOLLOWING)
+ $duedate = add_days(end_month($invdate), $myrow['days']);
+ elseif ($myrow['type'] == PTT_DAYS)
+ $duedate = add_days($invdate, $myrow['days']);
else
$duedate = $invdate;
return $duedate;
elseif ($order->trans_type == ST_SALESQUOTE)
$order->due_date = add_days($order->document_date, $SysPrefs->default_quote_valid_days());
- if($order->payment_terms['cash_sale']) {
+ if($order->payment_terms['type'] == PTT_CASH) {
$order->set_location($order->pos["pos_location"], $order->pos["location_name"]);
} else
$order->set_location($myrow["default_location"], $myrow["location_name"]);
if (!in_array($order->trans_type, array(ST_SALESQUOTE, ST_SALESORDER))
&& ($order->pos['cash_sale'] != $order->pos['credit_sale'])
- && (($order->payment_terms['cash_sale'] && !$order->pos['cash_sale']) ||
- (!$order->payment_terms['cash_sale'] && !$order->pos['credit_sale']))) {
+ && (($order->payment_terms['type'] == PTT_CASH && !$order->pos['cash_sale']) ||
+ (!$order->payment_terms['type'] != PTT_CASH && !$order->pos['credit_sale']))) {
// force payment terms refresh if terms are editable
// and pos have no permitions for terms selected in customer record.
// Terms are set to first terms in allowed category below.
$order->payment = get_post('payment');
$order->payment_terms = get_payment_terms($order->payment);
$order->due_date = get_invoice_duedate($order->payment, $order->document_date);
- if ($order->payment_terms['cash_sale']) {
+ if ($order->payment_terms['type'] == PTT_CASH) {
$_POST['Location'] = $order->Location = $order->pos['pos_location'];
$order->location_name = $order->pos['location_name'];
}
div_start('delivery');
- if ($order->payment_terms['cash_sale']) { // Direct payment sale
+ if ($order->payment_terms['type'] == PTT_CASH) { // Direct payment sale
$Ajax->activate('items_table');
display_heading(_('Cash payment'));
start_table(TABLESTYLE2, "width='60%'");
table_section(1);
locations_list_row(_("Deliver from Location:"), 'Location', null, false, true, $order->fixed_asset);
- if ($order->payment_terms['days_before_due'] == -1)
+ if ($order->payment_terms['type'] == PTT_PREPAY)
{
$Ajax->addUpdate('items_table', 'prep_amount', price_format($order->get_trans_total())); // bind to items_table update
if (!$order->is_started())
$cart->payment_terms = get_payment_terms($_POST['payment']);
$newpayment = true;
}
- if ($cart->payment_terms['cash_sale']) {
+ if ($cart->payment_terms['type'] == PTT_CASH) {
if ($newpayment)
{
$cart->due_date = $cart->document_date;
display_error(_("This document cannot be processed because there is insufficient quantity for items marked."));
return false;
}
- if ($_SESSION['Items']->payment_terms['cash_sale'] == 0) {
- if (!$_SESSION['Items']->is_started() && ($_SESSION['Items']->payment_terms['days_before_due'] == -1) && ((input_num('prep_amount')<=0) ||
+ if ($_SESSION['Items']->payment_terms['type'] != PTT_CASH) {
+ if (!$_SESSION['Items']->is_started() && ($_SESSION['Items']->payment_terms['type'] == PTT_PREPAY) && ((input_num('prep_amount')<=0) ||
input_num('prep_amount')>$_SESSION['Items']->get_trans_total())) {
display_error(_("Pre-payment required have to be positive and less than total amount."));
set_focus('prep_amount');
return false;
}
- if ($_SESSION['Items']->payment_terms['cash_sale'] &&
+ if ($_SESSION['Items']->payment_terms['type'] == PTT_CASH &&
($_SESSION['Items']->trans_type == ST_CUSTDELIVERY || $_SESSION['Items']->trans_type == ST_SALESINVOICE))
$_SESSION['Items']->due_date = $_SESSION['Items']->document_date;
return true;
$sales_order = get_sales_order_header($myrow["order_"], ST_SALESORDER);
display_heading(sprintf($myrow['prep_amount'] > 0 ? (
- $paym['days_before_due']>=0 ? _("FINAL INVOICE #%d") : _("PREPAYMENT INVOICE #%d")) : _("SALES INVOICE #%d"),$trans_id));
+ $paym['type'] == PTT_PREPAY ? _("FINAL INVOICE #%d") : _("PREPAYMENT INVOICE #%d")) : _("SALES INVOICE #%d"),$trans_id));
echo "<br>";
start_table(TABLESTYLE2, "width='95%'");
end_row();
-if ($_SESSION['View']->payment_terms['days_before_due']<0)
+if ($_SESSION['View']->payment_terms['type'] == PTT_PREPAY)
{
start_row();
label_cells(_("Payment Terms"), $_SESSION['View']->payment_terms['terms'], "class='tableheader2'");
`data` text DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
+
+# payment terms normalization, early payment support
+ALTER TABLE `0_payment_terms` CHANGE COLUMN `terms_indicator` `id` tinyint(1) NOT NULL DEFAULT '0';
+ALTER TABLE `0_payment_terms` ADD COLUMN `type` tinyint(1) NOT NULL DEFAULT '0' AFTER `terms`;
+UPDATE `0_payment_terms` SET `type`=IF(days_before_due < 0, 1, IF(day_in_following_month>0, 4, IF(days_before_due=0, 2, 3)));
+UPDATE `0_payment_terms` SET days_before_due=day_in_following_month WHERE days_before_due<=0;
+ALTER TABLE `0_payment_terms` CHANGE COLUMN `days_before_due` `days` int(11) NOT NULL DEFAULT '0';
+ALTER TABLE `0_payment_terms` DROP COLUMN `day_in_following_month`;
+ALTER TABLE `0_payment_terms` ADD COLUMN `early_discount` double NOT NULL DEFAULT '0' AFTER `days`;
+ALTER TABLE `0_payment_terms` ADD COLUMN `early_days` int(11) NOT NULL DEFAULT '0' AFTER `early_discount`;
DROP TABLE IF EXISTS `0_payment_terms`;
CREATE TABLE `0_payment_terms` (
- `terms_indicator` int(11) NOT NULL AUTO_INCREMENT,
+ `id` int(11) NOT NULL AUTO_INCREMENT,
`terms` char(80) NOT NULL DEFAULT '',
- `days_before_due` smallint(6) NOT NULL DEFAULT '0',
- `day_in_following_month` smallint(6) NOT NULL DEFAULT '0',
+ `type` tinyint(1) NOT NULL DEFAULT '1'
+ `days` int(11) NOT NULL DEFAULT '0'
+ `early_discount` double NOT NULL DEFAULT '0'
+ `early_days` double NOT NULL DEFAULT '0',
`inactive` tinyint(1) NOT NULL DEFAULT '0',
- PRIMARY KEY (`terms_indicator`),
+ PRIMARY KEY (`id`),
UNIQUE KEY `terms` (`terms`)
) ENGINE=InnoDB AUTO_INCREMENT=6 ;
-- Data of table `0_payment_terms` --
INSERT INTO `0_payment_terms` VALUES
-('1', 'Due 15th Of the Following Month', '0', '17', '0'),
-('2', 'Due By End Of The Following Month', '0', '30', '0'),
-('3', 'Payment due within 10 days', '10', '0', '0'),
-('4', 'Cash Only', '0', '0', '0'),
-('5', 'Prepaid', '-1', '0', '0');
+('1', 'Due 15th Of the Following Month', '4', '17', '0', '0', '0'),
+('2', 'Due By End Of The Following Month', '4', '30', '0', '0', '0'),
+('3', 'Payment due within 10 days', '10', '3', '0', '0', '0', '0'),
+('4', 'Cash Only', '2', '0', '0', '0', '0'),
+('5', 'Prepaid', '1', '0', '0', '0', '0');
-- Structure of table `0_prices` --
DROP TABLE IF EXISTS `0_payment_terms`;
CREATE TABLE `0_payment_terms` (
- `terms_indicator` int(11) NOT NULL AUTO_INCREMENT,
+ `id` int(11) NOT NULL AUTO_INCREMENT,
`terms` char(80) NOT NULL DEFAULT '',
- `days_before_due` smallint(6) NOT NULL DEFAULT '0',
- `day_in_following_month` smallint(6) NOT NULL DEFAULT '0',
+ `type` tinyint(1) NOT NULL DEFAULT '1'
+ `days` int(11) NOT NULL DEFAULT '0'
+ `early_discount` double NOT NULL DEFAULT '0'
+ `early_days` double NOT NULL DEFAULT '0',
`inactive` tinyint(1) NOT NULL DEFAULT '0',
- PRIMARY KEY (`terms_indicator`),
+ PRIMARY KEY (`id`),
UNIQUE KEY `terms` (`terms`)
) ENGINE=InnoDB AUTO_INCREMENT=6 ;
-- Data of table `0_payment_terms` --
INSERT INTO `0_payment_terms` VALUES
-('1', 'Due 15th Of the Following Month', '0', '17', '0'),
-('2', 'Due By End Of The Following Month', '0', '30', '0'),
-('3', 'Payment due within 10 days', '10', '0', '0'),
-('4', 'Cash Only', '0', '0', '0'),
-('5', 'Prepaid', '-1', '0', '0');
+('1', 'Due 15th Of the Following Month', '4', '17', '0', '0', '0'),
+('2', 'Due By End Of The Following Month', '4', '30', '0', '0', '0'),
+('3', 'Payment due within 10 days', '3', '10', '0', '0', '0'),
+('4', 'Cash Only', '2', '0', '0', '0', '0'),
+('5', 'Prepaid', '1', '0', '0', '0', '0');
-- Structure of table `0_prices` --