From: Janusz Dobrowolski Date: Sun, 31 Jan 2010 22:14:48 +0000 (+0000) Subject: Editable sales terms in sales orders and invoices. X-Git-Tag: v2.4.2~19^2~971 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=8127089373814523c323e3e60cd48ea547c1c0f5;p=fa-stable.git Editable sales terms in sales orders and invoices. --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b8983ae5..1894dd5b 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,29 @@ Legend: ! -> 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 diff --git a/sales/create_recurrent_invoices.php b/sales/create_recurrent_invoices.php index 04c4bda5..f1bbe4b5 100644 --- a/sales/create_recurrent_invoices.php +++ b/sales/create_recurrent_invoices.php @@ -35,7 +35,7 @@ function create_recurrent_invoices($customer_id, $branch_id, $order_no, $tmpl_no $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=''; diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index 15f851fb..82ae32a0 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -375,7 +375,7 @@ echo "";// outer table 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(); @@ -432,8 +432,7 @@ foreach ($_SESSION['Items']->line_items as $line=>$ln_itm) { 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); diff --git a/sales/customer_invoice.php b/sales/customer_invoice.php index 10e9d7d7..66e3c6b9 100644 --- a/sales/customer_invoice.php +++ b/sales/customer_invoice.php @@ -121,7 +121,7 @@ if ( (isset($_GET['DeliveryNumber']) && ($_GET['DeliveryNumber'] > 0) ) $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(); @@ -157,7 +157,13 @@ if (isset($_POST['Update'])) { $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'); } @@ -220,9 +226,11 @@ function copy_to_cart() $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']; + } //----------------------------------------------------------------------------- @@ -305,9 +313,10 @@ if (isset($_POST['process_invoice']) && check_data()) { $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 { @@ -359,11 +368,16 @@ if ($_SESSION['Items']->trans_no == 0) { 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(); @@ -384,7 +398,7 @@ date_cells(_("Date"), 'InvoiceDate', '', $_SESSION['Items']->trans_no == 0, 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'"); diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index b43c945f..68166e98 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -66,12 +66,14 @@ class cart 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 @@ -183,25 +185,23 @@ class cart } } 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 } //------------------------------------------------------------------------- @@ -250,13 +250,16 @@ class cart } } - 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='') diff --git a/sales/includes/db/cust_trans_db.inc b/sales/includes/db/cust_trans_db.inc index d8cc5d97..0d5d5ff9 100644 --- a/sales/includes/db/cust_trans_db.inc +++ b/sales/includes/db/cust_trans_db.inc @@ -88,7 +88,7 @@ function get_customer_trans_version($type, $trans_no) { 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); @@ -115,14 +115,15 @@ function write_customer_trans($trans_type, $trans_no, $debtor_no, $BranchNo, 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).", @@ -131,7 +132,8 @@ function write_customer_trans($trans_type, $trans_no, $debtor_no, $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"); @@ -148,7 +150,7 @@ function get_customer_trans($trans_id, $trans_type) $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 diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index a71d686a..995a0609 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -73,7 +73,8 @@ function write_credit_note($credit_note, $write_off_acc) $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) { diff --git a/sales/includes/db/sales_delivery_db.inc b/sales/includes/db/sales_delivery_db.inc index 8bd2d785..c4721527 100644 --- a/sales/includes/db/sales_delivery_db.inc +++ b/sales/includes/db/sales_delivery_db.inc @@ -43,7 +43,8 @@ function write_sales_delivery(&$delivery,$bo_policy) $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); diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index c4e97e4c..23bd798a 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -72,7 +72,8 @@ function write_sales_invoice(&$invoice) $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) { diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index 299240c9..de50c6aa 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -21,7 +21,7 @@ function add_sales_order(&$order) $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) .",". @@ -36,7 +36,8 @@ function add_sales_order(&$order) 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"); @@ -172,7 +173,8 @@ function update_sales_order($order) 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"); @@ -269,7 +271,6 @@ function get_sales_order_header($order_no, $trans_type) .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, " @@ -339,7 +340,7 @@ function read_sales_order($order_no, &$order, $trans_type) $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"]); @@ -404,21 +405,18 @@ function close_sales_order($order_no) //--------------------------------------------------------------------------------------------------------------- -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 @@ -440,6 +438,7 @@ function get_customer_to_order($customer_id) { .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, " diff --git a/sales/includes/sales_db.inc b/sales/includes/sales_db.inc index 88727e80..c350642a 100644 --- a/sales/includes/sales_db.inc +++ b/sales/includes/sales_db.inc @@ -292,7 +292,7 @@ function read_sales_trans($doc_type, $trans_no, &$cart) $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"]); diff --git a/sales/includes/ui/sales_order_ui.inc b/sales/includes/ui/sales_order_ui.inc index bb20dce6..b58436ab 100644 --- a/sales/includes/ui/sales_order_ui.inc +++ b/sales/includes/ui/sales_order_ui.inc @@ -84,7 +84,7 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id) $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'], @@ -113,14 +113,14 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id) $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"]); @@ -290,7 +290,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group 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'] == "") @@ -313,10 +313,10 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group $_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) { @@ -372,13 +372,12 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group } 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']; @@ -389,9 +388,10 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group $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 { @@ -416,14 +416,14 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group 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'); @@ -567,7 +567,7 @@ function display_delivery_details(&$order) 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%"); @@ -578,7 +578,6 @@ function display_delivery_details(&$order) textarea_row(_("Comments:"), "Comments", $order->Comments, 31, 5); end_table(); } else { - if ($order->trans_type==ST_SALESINVOICE) { $title = _("Delivery Details"); @@ -610,7 +609,8 @@ function display_delivery_details(&$order) 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')); diff --git a/sales/manage/sales_points.php b/sales/manage/sales_points.php index 4ac75900..3455c85c 100644 --- a/sales/manage/sales_points.php +++ b/sales/manage/sales_points.php @@ -29,13 +29,6 @@ function can_process() 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; } @@ -135,8 +128,8 @@ if ($selected_id != -1) 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); diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index 6c349361..b2483063 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -228,8 +228,12 @@ function copy_to_cart() $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 = ''; @@ -284,8 +288,8 @@ function copy_from_cart() $_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; @@ -536,7 +540,6 @@ function create_cart($type, $trans_no) global $Refs; processing_start(); - $doc_type = $type; if (isset($_GET['NewQuoteToSalesOrder'])) { @@ -550,21 +553,20 @@ function create_cart($type, $trans_no) $_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); @@ -574,7 +576,7 @@ function create_cart($type, $trans_no) } $_SESSION['Items'] = $doc; } else - $_SESSION['Items'] = new Cart($type,array($trans_no)); + $_SESSION['Items'] = new Cart($type, array($trans_no)); copy_from_cart(); } diff --git a/sql/alter2.3.php b/sql/alter2.3.php index 33872924..bafd38d7 100644 --- a/sql/alter2.3.php +++ b/sql/alter2.3.php @@ -26,7 +26,34 @@ class fa2_3 { // 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" + .':
'. 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" + .':
'. 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" + .':
'. 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')); @@ -42,16 +69,16 @@ class fa2_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 diff --git a/sql/alter2.3.sql b/sql/alter2.3.sql index ff1e9c99..94ae34e6 100644 --- a/sql/alter2.3.sql +++ b/sql/alter2.3.sql @@ -113,3 +113,5 @@ INSERT INTO `0_sys_prefs` SELECT 'default_workorder_required','glsetup.manuf', ' 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; diff --git a/sql/en_US-demo.sql b/sql/en_US-demo.sql index 95eed1ae..c1597a2a 100644 --- a/sql/en_US-demo.sql +++ b/sql/en_US-demo.sql @@ -560,6 +560,7 @@ CREATE TABLE `0_debtor_trans` ( `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`) @@ -568,14 +569,14 @@ CREATE TABLE `0_debtor_trans` ( ### 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` ### @@ -1355,16 +1356,17 @@ CREATE TABLE `0_sales_orders` ( `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` ### diff --git a/sql/en_US-new.sql b/sql/en_US-new.sql index 1a2d43cc..0abbc967 100644 --- a/sql/en_US-new.sql +++ b/sql/en_US-new.sql @@ -538,6 +538,7 @@ CREATE TABLE `0_debtor_trans` ( `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`) @@ -1190,6 +1191,7 @@ CREATE TABLE `0_sales_orders` ( `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;