! -> Note
$ -> Affected files
+26-Jan-2010 Janusz Dobrowolski
++ Editable sales terms in sales orders and invoices, default terms from customer record.
+$ /admin/db/company_db.inc
+ /includes/ui/ui_lists.inc
+ /reporting/rep102.php
+ /reporting/rep108.php
+ /sales/create_recurrent_invoices.php
+ /sales/customer_delivery.php
+ /sales/customer_invoice.php
+ /sales/sales_order_entry.php
+ /sales/includes/cart_class.inc
+ /sales/includes/sales_db.inc
+ /sales/includes/db/cust_trans_db.inc
+ /sales/includes/db/sales_credit_db.inc
+ /sales/includes/db/sales_delivery_db.inc
+ /sales/includes/db/sales_invoice_db.inc
+ /sales/includes/db/sales_order_db.inc
+ /sales/includes/ui/sales_order_ui.inc
+ /sales/manage/sales_points.php
+ /sql/alter2.3.php
+ /sql/alter2.3.sql
+ /sql/en_US-demo.sql
+ /sql/en_US-new.sql
26-Jan-2010 Janusz Dobrowolski
+ Full support for items with editable descriptions in sales documents
$doc->trans_no = 0;
$doc->document_date = Today(); // 2006-06-15. Added so Invoices and Deliveries get current day
- $doc->due_date = get_invoice_duedate($doc->customer_id, $doc->document_date);
+ $doc->due_date = get_invoice_duedate($doc->payment, $doc->document_date);
$doc->reference = $Refs->get_next($doc->trans_type);
//$doc->Comments='';
start_table("$table_style width=90%");
if (!isset($_POST['due_date']) || !is_date($_POST['due_date'])) {
- $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->customer_id, $_POST['DispatchDate']);
+ $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->payment, $_POST['DispatchDate']);
}
date_row(_("Invoice Dead-line"), 'due_date', '', null, 0, 0, 0, "class='tableheader2'");
end_table();
text_cells(null, 'Line'.$line.'Desc', $ln_itm->item_description, 30, 50);
else
label_cell($ln_itm->item_description);
-
- label_cell($ln_itm->units);
+
$dec = get_qty_dec($ln_itm->stock_id);
qty_cell($ln_itm->quantity, false, $dec);
label_cell($ln_itm->units);
$dn->src_docs = $dn->trans_no;
$dn->trans_no = 0;
$dn->reference = $Refs->get_next(ST_SALESINVOICE);
- $dn->due_date = get_invoice_duedate($dn->customer_id, $dn->document_date);
+ $dn->due_date = get_invoice_duedate($dn->payment, $dn->document_date);
$_SESSION['Items'] = $dn;
copy_from_cart();
$Ajax->activate('Items');
}
if (isset($_POST['_InvoiceDate_changed'])) {
- $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->customer_id,
+ $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->payment,
+ $_POST['InvoiceDate']);
+ $Ajax->activate('due_date');
+}
+if (list_updated('payment')) {
+ $_SESSION['Items']->payment = get_post('payment');
+ $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->payment,
$_POST['InvoiceDate']);
$Ajax->activate('due_date');
}
$cart->freight_cost = input_num('ChargeFreightCost');
$cart->document_date = $_POST['InvoiceDate'];
$cart->due_date = $_POST['due_date'];
+ $cart->payment = $_POST['payment'];
$cart->Comments = $_POST['Comments'];
if ($_SESSION['Items']->trans_no == 0)
$cart->reference = $_POST['ref'];
+
}
//-----------------------------------------------------------------------------
$newinvoice= $_SESSION['Items']->trans_no == 0;
copy_to_cart();
if ($newinvoice) new_doc_date($_SESSION['Items']->document_date);
- $invoice_no = $_SESSION['Items']->write();
+ $invoice_no = $_SESSION['Items']->write();
processing_end();
+
if ($newinvoice) {
meta_forward($_SERVER['PHP_SELF'], "AddedID=$invoice_no");
} else {
label_cells(_("Reference"), $_SESSION['Items']->reference, "class='tableheader2'");
}
-label_cells(_("Delivery Notes:"),
-get_customer_trans_view_str(ST_CUSTDELIVERY, array_keys($_SESSION['Items']->src_docs)), "class='tableheader2'");
+//label_cells(_("Delivery Notes:"),
+//get_customer_trans_view_str(ST_CUSTDELIVERY, array_keys($_SESSION['Items']->src_docs)), "class='tableheader2'");
label_cells(_("Sales Type"), $_SESSION['Items']->sales_type_name, "class='tableheader2'");
+if ($_SESSION['Items']->pos != -1) // editable payment type
+ label_cells(_("Payment terms:"), sale_payment_list('payment'), "class='tableheader2'");
+else
+ label_cells(_('Payment:'), $_SESSION['Items']->payment_terms['terms'], "class='tableheader2'");
+
end_row();
start_row();
0, 0, 0, "class='tableheader2'", true);
if (!isset($_POST['due_date']) || !is_date($_POST['due_date'])) {
- $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->customer_id, $_POST['InvoiceDate']);
+ $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->payment, $_POST['InvoiceDate']);
}
date_cells(_("Due Date"), 'due_date', '', null, 0, 0, 0, "class='tableheader2'");
var $price_factor; // ditto for price calculations
var $pos; // user assigned POS
- var $cash; // cash transaction
+ var $cash; // cash transaction - helper variable not stored in db
var $cash_account;
var $account_name;
var $cash_discount; // not used as of FA 2.1
var $dimension_id;
var $dimension2_id;
+ var $payment;
+ var $payment_terms; // cached payment terms
//-------------------------------------------------------------------------
//
// $trans_no==0 => open new/direct document
}
}
if ($type == ST_SALESINVOICE) {
- $this->due_date =
- get_invoice_duedate($this->customer_id, $this->document_date);
- $this->pos = user_pos();
- $pos = get_sales_point($this->pos);
- $this->cash = !$pos['credit_sale'];
- if (!$pos['cash_sale'] || !$pos['credit_sale'])
- $this->pos = -1; // mark not editable payment type
- else
- $this->cash = date_diff2($this->due_date, Today(), 'd')<2;
- if ($this->cash) {
- $this->Location = $pos['pos_location'];
- $this->location_name = $pos['location_name'];
- $this->cash_account = $pos['pos_account'];
- $this->account_name = $pos['bank_account_name'];
- }
+ $this->due_date =
+ get_invoice_duedate($this->payment, $this->document_date);
+ $this->cash = $this->payment_terms['cash_sale'];
+ if ($this->cash) {
+ $this->Location = $pos['pos_location'];
+ $this->location_name = $pos['location_name'];
+ $this->cash_account = $pos['pos_account'];
+ $this->account_name = $pos['bank_account_name'];
+ }
} else
- $this->due_date =
- add_days($this->document_date, $SysPrefs->default_delivery_required_by());
+ $this->due_date =
+ add_days($this->document_date, $SysPrefs->default_delivery_required_by());
}
+ $this->pos = user_pos();
+ $pos = get_sales_point($this->pos);
+ if (!$pos['cash_sale'] && !$pos['credit_sale'])
+ $this->pos = -1; // mark not editable payment type
}
//-------------------------------------------------------------------------
}
}
- function set_customer($customer_id, $customer_name, $currency, $discount, $cdiscount=0)
+ function set_customer($customer_id, $customer_name, $currency, $discount, $payment, $cdiscount=0)
{
$this->customer_name = $customer_name;
$this->customer_id = $customer_id;
$this->default_discount = $discount;
- $this->cash_discount = $cdiscount;
$this->customer_currency = $currency;
+ $this->payment = $payment;
+ $this->payment_terms = get_payment_terms($payment);
+ $this->cash = $this->payment_terms['cash_sale'];
+ $this->cash_discount = $cdiscount;
}
function set_branch($branch_id, $tax_group_id, $tax_group_name, $phone='', $email='')
function write_customer_trans($trans_type, $trans_no, $debtor_no, $BranchNo,
$date_, $reference, $Total, $discount=0, $Tax=0, $Freight=0, $FreightTax=0,
$sales_type=0, $order_no=0, $trans_link=0, $ship_via=0, $due_date="",
- $AllocAmt=0, $rate=0, $dimension_id=0, $dimension2_id=0)
+ $AllocAmt=0, $rate=0, $dimension_id=0, $dimension2_id=0, $payment_terms=null)
{
$new = $trans_no==0;
$curr = get_customer_currency($debtor_no);
order_, ov_amount, ov_discount,
ov_gst, ov_freight, ov_freight_tax,
rate, ship_via, alloc, trans_link,
- dimension_id, dimension2_id
+ dimension_id, dimension2_id, payment_terms
) VALUES ($trans_no, ".db_escape($trans_type).",
".db_escape($debtor_no).", ".db_escape($BranchNo).",
'$SQLDate', '$SQLDueDate', ".db_escape($reference).",
".db_escape($sales_type).", ".db_escape($order_no).", $Total, ".db_escape($discount).", $Tax,
".db_escape($Freight).",
$FreightTax, $rate, ".db_escape($ship_via).", $AllocAmt, ".db_escape($trans_link).",
- ".db_escape($dimension_id).", ".db_escape($dimension2_id).")";
+ ".db_escape($dimension_id).", ".db_escape($dimension2_id).", "
+ .db_escape($payment_terms).")";
} else { // may be optional argument should stay unchanged ?
$sql = "UPDATE ".TB_PREF."debtor_trans SET
debtor_no=".db_escape($debtor_no)." , branch_code=".db_escape($BranchNo).",
ov_amount=$Total, ov_discount=".db_escape($discount).", ov_gst=$Tax,
ov_freight=".db_escape($Freight).", ov_freight_tax=$FreightTax, rate=$rate,
ship_via=".db_escape($ship_via).", alloc=$AllocAmt, trans_link=$trans_link,
- dimension_id=".db_escape($dimension_id).", dimension2_id=".db_escape($dimension2_id)."
+ dimension_id=".db_escape($dimension_id).", dimension2_id=".db_escape($dimension2_id).",
+ payment_terms=".db_escape($payment_terms)."
WHERE trans_no=$trans_no AND type=".db_escape($trans_type);
}
db_query($sql, "The debtor transaction record could not be inserted");
$sql = "SELECT ".TB_PREF."debtor_trans.*,
ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,
".TB_PREF."debtors_master.name AS DebtorName, ".TB_PREF."debtors_master.address, ".TB_PREF."debtors_master.email AS email2,
- ".TB_PREF."debtors_master.curr_code, ".TB_PREF."debtors_master.tax_id, ".TB_PREF."debtors_master.payment_terms ";
+ ".TB_PREF."debtors_master.curr_code, ".TB_PREF."debtors_master.tax_id ";
if ($trans_type == ST_CUSTPAYMENT) {
// it's a payment so also get the bank account
$credit_note->freight_cost, $freight_added_tax,
$credit_note->sales_type,
$credit_note->order_no, $credit_invoice, $credit_note->ship_via,
- null, $alloc, 0, $credit_note->dimension_id, $credit_note->dimension2_id);
+ null, $alloc, 0, $credit_note->dimension_id, $credit_note->dimension2_id,
+ $credit_note->payment);
// 2008-06-14 extra $alloc, 2008-11-12 dimension_id Joe Hunt
if ($trans_no==0) {
$delivery->freight_cost,
$delivery->tax_included ? 0 : $freight_tax,
$delivery->sales_type, $delivery->order_no, 0,
- $delivery->ship_via, $delivery->due_date, 0, 0, $delivery->dimension_id, $delivery->dimension2_id);
+ $delivery->ship_via, $delivery->due_date, 0, 0, $delivery->dimension_id,
+ $delivery->dimension2_id, $delivery->payment);
if ($trans_no == 0) {
$delivery->trans_no = array($delivery_no=>0);
$invoice->Branch, $date_, $invoice->reference, $items_total, 0,
$items_added_tax, $invoice->freight_cost, $freight_added_tax,
$invoice->sales_type, $sales_order, $delivery_no,
- $invoice->ship_via, $invoice->due_date, $alloc, 0, $invoice->dimension_id, $invoice->dimension2_id);
+ $invoice->ship_via, $invoice->due_date, $alloc, 0, $invoice->dimension_id,
+ $invoice->dimension2_id, $invoice->payment);
// 2008-06-14 extra $alloc, 2008-11-12 added dimension_id Joe Hunt
if ($trans_no == 0) {
$order_type = 0; // this is default on new order
$sql = "INSERT INTO ".TB_PREF."sales_orders (order_no, type, debtor_no, trans_type, branch_code, customer_ref, reference, comments, ord_date,
order_type, ship_via, deliver_to, delivery_address, contact_phone,
- contact_email, freight_cost, from_stk_loc, delivery_date)
+ contact_email, freight_cost, from_stk_loc, delivery_date, payment_terms)
VALUES (" .db_escape($order_no) . "," .db_escape($order_type) . "," . db_escape($order->customer_id) .
", " .db_escape($order->trans_type) . "," .db_escape($order->Branch) . ", ".
db_escape($order->cust_ref) .",".
db_escape($order->email) . ", " .
db_escape($order->freight_cost) .", " .
db_escape($order->Location) .", " .
- db_escape($del_date) . ")";
+ db_escape($del_date) . "," .
+ db_escape($order->payment) . ")";
db_query($sql, "order Cannot be Added");
freight_cost = " .db_escape($order->freight_cost) .",
from_stk_loc = " .db_escape($order->Location) .",
delivery_date = " .db_escape($del_date). ",
- version = ".($version+1)."
+ version = ".($version+1).",
+ payment_terms = " .db_escape($order->payment). "
WHERE order_no=" . $order_no ."
AND trans_type=".$order->trans_type." AND version=".$version;
db_query($sql, "order Cannot be Updated, this can be concurrent edition conflict");
.TB_PREF."debtors_master.curr_code, "
.TB_PREF."debtors_master.email AS master_email, "
.TB_PREF."locations.location_name, "
- .TB_PREF."debtors_master.payment_terms, "
.TB_PREF."debtors_master.discount, "
.TB_PREF."sales_types.sales_type, "
.TB_PREF."sales_types.id AS sales_type_id, "
$order->trans_no = array($order_no=> $myrow["version"]);
$order->set_customer($myrow["debtor_no"], $myrow["name"],
- $myrow["curr_code"], $myrow["discount"]);
+ $myrow["curr_code"], $myrow["discount"], $myrow["payment_terms"]);
$order->set_branch($myrow["branch_code"], $myrow["tax_group_id"],
$myrow["tax_group_name"], $myrow["contact_phone"], $myrow["contact_email"]);
//---------------------------------------------------------------------------------------------------------------
-function get_invoice_duedate($debtorno, $invdate)
+function get_invoice_duedate($terms, $invdate)
{
if (!is_date($invdate))
{
return new_doc_date();
}
- $sql = "SELECT ".TB_PREF."debtors_master.debtor_no, ".TB_PREF."debtors_master.payment_terms, ".TB_PREF."payment_terms.* FROM ".TB_PREF."debtors_master,
- ".TB_PREF."payment_terms WHERE ".TB_PREF."debtors_master.payment_terms = ".TB_PREF."payment_terms.terms_indicator AND
- ".TB_PREF."debtors_master.debtor_no = ".db_escape($debtorno);
-
- $result = db_query($sql,"The customer details could not be retrieved");
- $myrow = db_fetch($result);
-
- if (db_num_rows($result) == 0)
+
+ $myrow = get_payment_terms($terms);
+
+ if (!$myrow)
return $invdate;
+
if ($myrow['day_in_following_month'] > 0)
$duedate = add_days(end_month($invdate), $myrow['day_in_following_month']);
else
.TB_PREF."sales_types.factor, "
.TB_PREF."debtors_master.curr_code, "
.TB_PREF."debtors_master.discount,"
+ .TB_PREF."debtors_master.payment_terms,"
.TB_PREF."debtors_master.pymt_discount
FROM ".TB_PREF."debtors_master, "
.TB_PREF."credit_status, "
$cart->set_sales_type($myrow["tpe"], $myrow["sales_type"], $myrow["tax_included"],0);
$cart->set_customer($myrow["debtor_no"], $myrow["DebtorName"],
- $myrow["curr_code"], $myrow["discount"]);
+ $myrow["curr_code"], $myrow["discount"], $myrow["payment_terms"]);
$cart->set_branch($myrow["branch_code"], $myrow["tax_group_id"],
$myrow["tax_group_name"], $myrow["phone"], $myrow["email"]);
$deliver = $myrow['address']; // in case no branch address use company address
$order->set_customer($customer_id, $name, $myrow['curr_code'],
- $myrow['discount'], $myrow['pymt_discount']);
+ $myrow['discount'], $myrow['payment_terms'], $myrow['pymt_discount']);
// the sales type determines the price list to be used by default
$order->set_sales_type($myrow['salestype'], $myrow['sales_type'], $myrow['tax_included'],
$order->set_delivery($myrow["default_ship_via"], $myrow["br_name"],
$address);
if ($order->trans_type == ST_SALESINVOICE) {
- $order->due_date = get_invoice_duedate($customer_id, $order->document_date);
- if ($order->pos != -1)
- $order->cash = date_diff2($order->due_date, Today(), 'd')<2;
+ $order->due_date = get_invoice_duedate($order->payment, $order->document_date);
+// if ($order->pos != -1)
+// $order->cash = date_diff2($order->due_date, Today(), 'd')<2;
}
if($order->cash ) {
if($order->pos != -1) {
- $paym = get_sales_point($order->pos);
- $order->set_location($paym["pos_location"], $paym["location_name"]);
+ $pos = get_sales_point($order->pos);
+ $order->set_location($pos["pos_location"], $pos["location_name"]);
}
} else
$order->set_location($myrow["default_location"], $myrow["location_name"]);
if( ($order->customer_id != get_post('customer_id', -1)) ||
($order->Branch != get_post('branch_id', -1)) ||
- list_updated('customer_id'))
+ list_updated('customer_id'))
{
if (!isset($_POST['branch_id']) || $_POST['branch_id'] == "")
$_POST['deliver_to'] = $order->deliver_to;
$_POST['delivery_address'] = $order->delivery_address;
$_POST['phone'] = $order->phone;
- if (get_post('cash') !== $order->cash) {
- $_POST['cash'] = $order->cash;
+ if (get_post('payment') !== $order->payment) {
+ $_POST['payment'] = $order->payment;
$Ajax->activate('delivery');
- $Ajax->activate('cash');
+ $Ajax->activate('payment');
} else {
if ($order->trans_type == ST_SALESINVOICE)
{
}
table_section(3);
- if ($order->trans_type == ST_SALESINVOICE && $order->pos != -1) {
- sale_payment_list_cells(_('Payment:'), 'cash', null, true);
- $cash_payment = get_post('cash', 0);
- // current user can issue both credit and cash invoices
- if ($order->cash != $cash_payment) {
- $order->cash = $cash_payment;
- if ($cash_payment) {
+ if (($order->trans_type != ST_CUSTDELIVERY) && ($order->pos != -1)) { // editable payment type
+ if (get_post('payment') !== $order->payment) {
+ $order->payment = get_post('payment');
+ $order->payment_terms = get_payment_terms($order->payment);
+ $order->cash = $order->payment_terms['cash_sale'];
+ if ($order->cash) {
$paym = get_sales_point(user_pos());
$order->cash_account = $paym['pos_account'];
$order->account_name = $paym['bank_account_name'];
$Ajax->activate('delivery');
set_focus($order->pos == -1 ? 'delivery_date' : 'account');
}
- } else
- hidden('cash', $order->cash);
-
+ sale_payment_list_cells(_('Payment:'), 'payment', null);
+ } else {
+ label_cells(_('Payment:'), $order->payment_terms['terms']);
+ }
if($editable) {
$str = sales_types_list_row(_("Price List"), 'sales_type', null, true);
} else {
date_row($date_text, 'OrderDate', _('Date of order receive'),
$order->trans_no==0, 0, 0, 0, null, true);
- if (isset($_POST['_OrderDate_changed'])) {
+ if (isset($_POST['_OrderDate_changed']) || list_updated('payment')) {
if (!is_company_currency($order->customer_currency)
&& (get_base_sales_type()>0)) {
$change_prices = 1;
}
$Ajax->activate('_ex_rate');
if ($order->trans_type == ST_SALESINVOICE) {
- $_POST['delivery_date'] = get_invoice_duedate(get_post('customer_id'), get_post('OrderDate'));
+ $_POST['delivery_date'] = get_invoice_duedate(get_post('payment'), get_post('OrderDate'));
} else
$_POST['delivery_date'] = add_days(get_post('OrderDate'), $SysPrefs->default_delivery_required_by());
$Ajax->activate('items_table');
div_start('delivery');
- if (get_post('cash', 0)) { // Direct payment sale
+ if ($order->cash) { // Direct payment sale
$Ajax->activate('items_table');
display_heading(_('Cash payment'));
start_table("$table_style2 width=60%");
textarea_row(_("Comments:"), "Comments", $order->Comments, 31, 5);
end_table();
} else {
-
if ($order->trans_type==ST_SALESINVOICE)
{
$title = _("Delivery Details");
date_row($delname, 'delivery_date',
- $order->trans_type==ST_SALESORDER ? _('Enter requested day of delivery') : $order->trans_type==ST_SALESQUOTE ? _('Enter Valid until Date') : '');
+ $order->trans_type==ST_SALESORDER ? _('Enter requested day of delivery')
+ : $order->trans_type==ST_SALESQUOTE ? _('Enter Valid until Date') : '');
text_row(_("Deliver To:"), 'deliver_to', $order->deliver_to, 40, 40,
_('Additional identifier for delivery e.g. name of receiving person'));
set_focus('pos_name');
return false;
}
- if (!check_value('cash') && !check_value('credit'))
- {
- display_error(_("You must allow cash or credit sale."));
- set_focus('credit');
- return false;
- }
-
return true;
}
text_row_ex(_("Point of Sale Name").':', 'name', 20, 30);
if($cash) {
- check_row(_('Allowed credit sale'), 'credit', check_value('credit_sale'));
- check_row(_('Allowed cash sale'), 'cash', check_value('cash_sale'));
+ check_row(_('Allowed credit sale terms selection:'), 'credit', check_value('credit_sale'));
+ check_row(_('Allowed cash sale terms selection:'), 'cash', check_value('cash_sale'));
cash_accounts_list_row(_("Default cash account").':', 'account');
} else {
hidden('credit', 1);
$cart->Comments = $_POST['Comments'];
$cart->document_date = $_POST['OrderDate'];
- if ($cart->trans_type == ST_SALESINVOICE)
- $cart->cash = $_POST['cash'];
+// if ($cart->trans_type == ST_SALESINVOICE) {
+ if (isset($_POST['payment']) && ($cart->payment != $_POST['payment'])) {
+ $cart->payment = $_POST['payment'];
+ $cart->payment_terms = get_payment_terms($_POST['payment']);
+ $cart->cash = $cart->payment_terms['cash_sale'];
+ }
if ($cart->cash) {
$cart->due_date = $cart->document_date;
$cart->phone = $cart->cust_ref = $cart->delivery_address = '';
$_POST['branch_id'] = $cart->Branch;
$_POST['sales_type'] = $cart->sales_type;
// POS
- if ($cart->trans_type == ST_SALESINVOICE)
- $_POST['cash'] = $cart->cash;
+ if ($cart->pos != -1)
+ $_POST['payment'] = $cart->payment;
if ($cart->trans_type!=ST_SALESORDER && $cart->trans_type!=ST_SALESQUOTE) { // 2008-11-12 Joe Hunt
$_POST['dimension_id'] = $cart->dimension_id;
$_POST['dimension2_id'] = $cart->dimension2_id;
global $Refs;
processing_start();
- $doc_type = $type;
if (isset($_GET['NewQuoteToSalesOrder']))
{
$_SESSION['Items'] = $doc;
}
elseif($type != ST_SALESORDER && $type != ST_SALESQUOTE && $trans_no != 0) { // this is template
- $doc_type = ST_SALESORDER;
$doc = new Cart(ST_SALESORDER, array($trans_no));
$doc->trans_type = $type;
$doc->trans_no = 0;
$doc->document_date = new_doc_date();
if ($type == ST_SALESINVOICE) {
- $doc->due_date = get_invoice_duedate($doc->customer_id, $doc->document_date);
+ $doc->due_date = get_invoice_duedate($doc->payment, $doc->document_date);
$doc->pos = user_pos();
$pos = get_sales_point($doc->pos);
- $doc->cash = $pos['cash_sale'];
- if (!$pos['cash_sale'] || !$pos['credit_sale'])
+// $doc->cash = $pos['cash_sale'];
+ if (!$pos['cash_sale'] && !$pos['credit_sale'])
$doc->pos = -1; // mark not editable payment type
- else
- $doc->cash = date_diff2($doc->due_date, Today(), 'd')<2;
+// else
+// $doc->cash = date_diff2($doc->due_date, Today(), 'd')<2;
} else
$doc->due_date = $doc->document_date;
$doc->reference = $Refs->get_next($doc->trans_type);
}
$_SESSION['Items'] = $doc;
} else
- $_SESSION['Items'] = new Cart($type,array($trans_no));
+ $_SESSION['Items'] = new Cart($type, array($trans_no));
copy_from_cart();
}
//
function install($pref, $force)
{
- // remove old prefereces table after upgrade script has been executed
+ $sql = "SELECT debtor_no, payment_terms FROM {$pref}debtors_master";
+
+ $result = db_query($sql);
+ if (!$result) {
+ display_error("Cannot read customers"
+ .':<br>'. db_error_msg($db));
+ return false;
+ }
+ // update all sales orders and transactions with customer std payment terms
+ while($cust = db_fetch($result)) {
+ $sql = "UPDATE {$pref}debtor_trans SET "
+ ."payment_terms = '" .$cust['payment_terms']
+ ."' WHERE debtor_no='".$cust['debtor_no']."'";
+ if (db_query($sql)==false) {
+ display_error("Cannot update cust trans payment"
+ .':<br>'. db_error_msg($db));
+ return false;
+ }
+ $sql = "UPDATE {$pref}sales_orders SET "
+ ."payment_terms = '" .$cust['payment_terms']
+ ."' WHERE debtor_no='".$cust['debtor_no']."'";
+ if (db_query($sql)==false) {
+ display_error("Cannot update sales order payment"
+ .':<br>'. db_error_msg($db));
+ return false;
+ }
+ }
+ // remove old preferences table after upgrade script has been executed
$sql = "DROP TABLE IF EXISTS `".$pref."company`";
return db_query($sql) && update_company_prefs(array('version_id'=>'2.3'));
// Test if patch was applied before.
//
function installed($pref) {
- $n = 2; // number of patches to be installed
+ $n = 3; // number of patches to be installed
$patchcnt = 0;
if (!check_table($pref, 'comments', 'type', array('Key'=>'MUL'))) $patchcnt++;
if (!check_table($pref, 'sys_prefs')) $patchcnt++;
+ if (!check_table($pref, 'sales_orders', 'payment_terms')) $patchcnt++;
$n -= $patchcnt;
return $n == 0 ? true : $patchcnt;
}
-};
-
+
$install = new fa2_3;
?>
\ No newline at end of file
INSERT INTO `0_sys_prefs` SELECT 'version_id', 'system', 'varchar', '11', c.version_id FROM `0_company` c;
ALTER TABLE `0_stock_master` ADD COLUMN `editable` TINYINT(1) NOT NULL default '0';
+ALTER TABLE `0_debtor_trans` ADD COLUMN `payment_terms` int(11) default NULL;
+ALTER TABLE `0_sales_orders` ADD COLUMN `payment_terms` int(11) default NULL;
`trans_link` int(11) NOT NULL default '0',
`dimension_id` int(11) NOT NULL default '0',
`dimension2_id` int(11) NOT NULL default '0',
+ `payment_terms` int(11) default NULL,
PRIMARY KEY (`type`, `trans_no`),
KEY `debtor_no` (`debtor_no`,`branch_code`),
KEY (`tran_date`)
### Data of table `0_debtor_trans` ###
-INSERT INTO `0_debtor_trans` VALUES ('2', '13', '0', '1', '1', '2009-06-21', '2009-06-22', '1', '2', '1', '60.8', '0', '10', '0', '0', '0', '1.6445729799917', '1', '0', '0', '0');
-INSERT INTO `0_debtor_trans` VALUES ('3', '11', '0', '3', '3', '2009-06-21', '0000-00-00', '1', '2', '3', '35.89', '1.79', '0', '0', '0', '37.68', '1.3932', '1', '18', '2', '0');
-INSERT INTO `0_debtor_trans` VALUES ('3', '13', '1', '2', '2', '2009-06-21', '2009-06-22', 'auto', '1', '2', '50', '2.5', '0', '0', '0', '0', '1', '1', '17', '0', '0');
-INSERT INTO `0_debtor_trans` VALUES ('4', '13', '1', '3', '3', '2009-06-21', '2009-07-01', 'auto', '2', '3', '35.89', '1.79', '0', '0', '0', '0', '1.3932', '1', '18', '2', '0');
-INSERT INTO `0_debtor_trans` VALUES ('5', '13', '1', '2', '2', '2009-06-21', '2009-06-22', 'auto', '1', '5', '50', '0', '5', '0', '0', '0', '1', '1', '19', '0', '0');
-INSERT INTO `0_debtor_trans` VALUES ('17', '10', '0', '2', '2', '2009-06-21', '2009-06-22', '1', '1', '2', '50', '2.5', '0', '0', '0', '0', '1', '1', '3', '0', '0');
-INSERT INTO `0_debtor_trans` VALUES ('18', '10', '1', '3', '3', '2009-06-21', '2009-07-01', '2', '2', '3', '35.89', '1.79', '0', '0', '0', '37.68', '1.3932', '1', '4', '2', '0');
-INSERT INTO `0_debtor_trans` VALUES ('19', '10', '0', '2', '2', '2009-06-21', '2009-06-22', '3', '1', '5', '50', '0', '5', '0', '0', '0', '1', '1', '5', '0', '0');
+INSERT INTO `0_debtor_trans` VALUES ('2', '13', '0', '1', '1', '2009-06-21', '2009-06-22', '1', '2', '1', '60.8', '0', '10', '0', '0', '0', '1.6445729799917', '1', '0', '0', '0','3');
+INSERT INTO `0_debtor_trans` VALUES ('3', '11', '0', '3', '3', '2009-06-21', '0000-00-00', '1', '2', '3', '35.89', '1.79', '0', '0', '0', '37.68', '1.3932', '1', '18', '2', '0','3');
+INSERT INTO `0_debtor_trans` VALUES ('3', '13', '1', '2', '2', '2009-06-21', '2009-06-22', 'auto', '1', '2', '50', '2.5', '0', '0', '0', '0', '1', '1', '17', '0', '0','');
+INSERT INTO `0_debtor_trans` VALUES ('4', '13', '1', '3', '3', '2009-06-21', '2009-07-01', 'auto', '2', '3', '35.89', '1.79', '0', '0', '0', '0', '1.3932', '1', '18', '2', '0','3');
+INSERT INTO `0_debtor_trans` VALUES ('5', '13', '1', '2', '2', '2009-06-21', '2009-06-22', 'auto', '1', '5', '50', '0', '5', '0', '0', '0', '1', '1', '19', '0', '0','4');
+INSERT INTO `0_debtor_trans` VALUES ('17', '10', '0', '2', '2', '2009-06-21', '2009-06-22', '1', '1', '2', '50', '2.5', '0', '0', '0', '0', '1', '1', '3', '0', '0','4');
+INSERT INTO `0_debtor_trans` VALUES ('18', '10', '1', '3', '3', '2009-06-21', '2009-07-01', '2', '2', '3', '35.89', '1.79', '0', '0', '0', '37.68', '1.3932', '1', '4', '2', '0','3');
+INSERT INTO `0_debtor_trans` VALUES ('19', '10', '0', '2', '2', '2009-06-21', '2009-06-22', '3', '1', '5', '50', '0', '5', '0', '0', '0', '1', '1', '5', '0', '0','4');
### Structure of table `0_debtor_trans_details` ###
`freight_cost` double NOT NULL default '0',
`from_stk_loc` varchar(5) NOT NULL default '',
`delivery_date` date NOT NULL default '0000-00-00',
+ `payment_terms` int(11) default NULL,
PRIMARY KEY (`trans_type`, `order_no`)
) TYPE=InnoDB;
### Data of table `0_sales_orders` ###
-INSERT INTO `0_sales_orders` VALUES ('1', '30', '1', '0', '1', '1', '1', '', '', '2009-06-21', '2', '1', 'Address 1\r\nAddress 2\r\nAddress 3', '', '', 'Beefeater Ltd.', '10', 'DEF', '2009-06-22');
-INSERT INTO `0_sales_orders` VALUES ('2', '30', '1', '0', '2', '2', '2', '', '', '2009-06-21', '1', '1', 'Address 1\r\nAddress 2\r\nAddress 3', '', '', 'Ghostbusters Corp.', '0', 'DEF', '2009-06-22');
-INSERT INTO `0_sales_orders` VALUES ('3', '30', '1', '0', '3', '3', '3', '', '', '2009-06-21', '2', '1', 'Address 1\r\nAddress 2\r\nAddress 3', '', '', 'Brezan', '0', 'DEF', '2009-07-01');
-INSERT INTO `0_sales_orders` VALUES ('4', '30', '0', '0', '1', '1', '4', '', '', '2009-06-21', '2', '1', 'Address 1\r\nAddress 2\r\nAddress 3', '', '', 'Beefeater Ltd.', '0', 'DEF', '2009-06-22');
-INSERT INTO `0_sales_orders` VALUES ('5', '30', '1', '0', '2', '2', '5', '', '', '2009-06-21', '1', '1', 'Address 1\r\nAddress 2\r\nAddress 3', '', '', 'Ghostbusters Corp.', '5', 'DEF', '2009-06-22');
+INSERT INTO `0_sales_orders` VALUES ('1', '30', '1', '0', '1', '1', '1', '', '', '2009-06-21', '2', '1', 'Address 1\r\nAddress 2\r\nAddress 3', '', '', 'Beefeater Ltd.', '10', 'DEF', '2009-06-22','3');
+INSERT INTO `0_sales_orders` VALUES ('2', '30', '1', '0', '2', '2', '2', '', '', '2009-06-21', '1', '1', 'Address 1\r\nAddress 2\r\nAddress 3', '', '', 'Ghostbusters Corp.', '0', 'DEF', '2009-06-22','4');
+INSERT INTO `0_sales_orders` VALUES ('3', '30', '1', '0', '3', '3', '3', '', '', '2009-06-21', '2', '1', 'Address 1\r\nAddress 2\r\nAddress 3', '', '', 'Brezan', '0', 'DEF', '2009-07-01','3');
+INSERT INTO `0_sales_orders` VALUES ('4', '30', '0', '0', '1', '1', '4', '', '', '2009-06-21', '2', '1', 'Address 1\r\nAddress 2\r\nAddress 3', '', '', 'Beefeater Ltd.', '0', 'DEF', '2009-06-22','3');
+INSERT INTO `0_sales_orders` VALUES ('5', '30', '1', '0', '2', '2', '5', '', '', '2009-06-21', '1', '1', 'Address 1\r\nAddress 2\r\nAddress 3', '', '', 'Ghostbusters Corp.', '5', 'DEF', '2009-06-22','4');
### Structure of table `0_sales_pos` ###
`trans_link` int(11) NOT NULL default '0',
`dimension_id` int(11) NOT NULL default '0',
`dimension2_id` int(11) NOT NULL default '0',
+ `payment_terms` int(11) default NULL,
PRIMARY KEY (`type`, `trans_no`),
KEY `debtor_no` (`debtor_no`,`branch_code`),
KEY (`tran_date`)
`freight_cost` double NOT NULL default '0',
`from_stk_loc` varchar(5) NOT NULL default '',
`delivery_date` date NOT NULL default '0000-00-00',
+ `payment_terms` int(11) default NULL,
PRIMARY KEY (`trans_type`, `order_no`)
) TYPE=InnoDB;