From: Janusz Dobrowolski Date: Mon, 11 Oct 2010 06:41:28 +0000 (+0000) Subject: Fixed point of sale handling and terms selection X-Git-Tag: v2.4.2~19^2~576 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=4d3a86a9286de3f4d5552ad2aa237a91df6aa689;p=fa-stable.git Fixed point of sale handling and terms selection --- diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index 7a3b765b..286cc3fd 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -65,7 +65,6 @@ class cart var $price_factor; // ditto for price calculations var $pos; // user assigned POS - 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 @@ -91,6 +90,7 @@ class cart $this->trans_type = ST_SALESORDER; $this->dimension_id = 0; $this->dimension2_id = 0; + $this->pos = get_sales_point(user_pos()); $this->read($type, $trans_no, $no_edit); $this->cart_id = uniqid(''); } @@ -238,8 +238,7 @@ class cart } else $this->due_date = add_days($this->document_date, $SysPrefs->default_delivery_required_by()); - $this->pos = user_pos(); - } + } $this->credit = get_current_cust_credit($this->customer_id); } @@ -302,17 +301,13 @@ class cart $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; - $pos = get_sales_point($this->pos); - if (!$pos['cash_sale'] || !$pos['credit_sale']) - $this->pos = -1; // mark not editable payment type - 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']; + if ($this->payment_terms['cash_sale']) { + $this->Location = $this->pos['pos_location']; + $this->location_name = $this->pos['location_name']; + $this->cash_account = $this->pos['pos_account']; + $this->account_name = $this->pos['bank_account_name']; } $this->credit = get_current_cust_credit($customer_id); } diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 3b540d55..7928a12d 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -164,7 +164,7 @@ function write_sales_invoice(&$invoice) if ($trans_no == 0) { $Refs->save(ST_SALESINVOICE, $invoice_no, $invoice->reference); - if ($invoice->cash) { + if ($invoice->payment_terms['cash_sale']) { $amount = $items_total + $items_added_tax + $invoice->freight_cost + $freight_added_tax; diff --git a/sales/includes/ui/sales_order_ui.inc b/sales/includes/ui/sales_order_ui.inc index 688f1689..b44cd305 100644 --- a/sales/includes/ui/sales_order_ui.inc +++ b/sales/includes/ui/sales_order_ui.inc @@ -117,16 +117,11 @@ 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) { + if ($order->trans_type == ST_SALESINVOICE || $order->trans_type == ST_SALESORDER) { $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) { - $pos = get_sales_point($order->pos); - $order->set_location($pos["pos_location"], $pos["location_name"]); - } + if($order->payment_terms['cash_sale']) { + $order->set_location($order->pos["pos_location"], $order->pos["location_name"]); } else $order->set_location($myrow["default_location"], $myrow["location_name"]); @@ -316,7 +311,20 @@ 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('payment') !== $order->payment) { + $_POST['delivery_date'] = $order->due_date; + + 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']))) { + // 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. + display_warning( + sprintf(_("Customer's payment terms '%s' cannot be selected on this POS"), + $order->payment_terms['terms'])); + $order->payment = ''; + } elseif (get_post('payment') !== $order->payment) { $_POST['payment'] = $order->payment; $Ajax->activate('delivery'); $Ajax->activate('payment'); @@ -379,26 +387,31 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%"); table_section(3); - - if (($order->trans_type != ST_CUSTDELIVERY) && ($order->pos != -1)) { // editable payment type + if ($order->pos['cash_sale'] || $order->pos['credit_sale']) { + // 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']; - $_POST['Location'] = $order->Location = $paym['pos_location']; - $order->location_name = $paym['location_name']; + $order->due_date = get_invoice_duedate($order->payment, $order->document_date); + if ($order->payment_terms['cash_sale']) { + $order->cash_account = $order->pos['pos_account']; + $order->account_name = $order->pos['bank_account_name']; + $_POST['Location'] = $order->Location = $order->pos['pos_location']; + $order->location_name = $order->pos['location_name']; } $Ajax->activate('items_table'); $Ajax->activate('delivery'); } - sale_payment_list_cells(_('Payment:'), 'payment', null); + $paymcat = !$order->pos['cash_sale'] ? PM_CREDIT : + (!$order->pos['credit_sale'] ? PM_CASH : PM_ANY); + // all terms are available for SO + sale_payment_list_cells(_('Payment:'), 'payment', + (in_array($order->trans_type, array(ST_SALESQUOTE, ST_SALESORDER)) + ? PM_ANY : $paymcat), null); } else { label_cells(_('Payment:'), $order->payment_terms['terms']); } + if($editable) { $str = sales_types_list_row(_("Price List"), 'sales_type', null, true); } else { @@ -572,13 +585,13 @@ function display_delivery_details(&$order) div_start('delivery'); - if ($order->cash) { // Direct payment sale + + if ($order->payment_terms['cash_sale']) { // Direct payment sale $Ajax->activate('items_table'); display_heading(_('Cash payment')); start_table(TABLESTYLE2, "width=60%"); - label_row(_("Deliver from Location:"), $order->location_name); - hidden('Location', $order->Location); + locations_list_row(_("Deliver from Location:"), 'Location', null, false, true); label_row(_("Cash account:"), $order->account_name); textarea_row(_("Comments:"), "Comments", $order->Comments, 31, 5); end_table(); @@ -607,8 +620,7 @@ function display_delivery_details(&$order) start_outer_table(TABLESTYLE2, "width=90%"); table_section(1); - locations_list_row(_("Deliver from Location:"), 'Location', null, - false, true); + locations_list_row(_("Deliver from Location:"), 'Location', null, false, true); if (list_updated('Location')) $Ajax->activate('items_table'); diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index 82e3fbd4..8c6ab770 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -239,9 +239,8 @@ function copy_to_cart() 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) { + if ($cart->payment_terms['cash_sale']) { $cart->due_date = $cart->document_date; $cart->phone = $cart->cust_ref = $cart->delivery_address = ''; $cart->freight_cost = input_num('freight_cost'); @@ -295,8 +294,7 @@ function copy_from_cart() $_POST['branch_id'] = $cart->Branch; $_POST['sales_type'] = $cart->sales_type; // POS - if ($cart->pos != -1) - $_POST['payment'] = $cart->payment; + $_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; @@ -346,7 +344,7 @@ function can_process() { set_focus('AddItem'); return false; } - if ($_SESSION['Items']->cash == 0) { + if ($_SESSION['Items']->payment_terms['cash_sale'] == 0) { if (strlen($_POST['deliver_to']) <= 1) { display_error(_("You must enter the person or company to whom delivery should be made to.")); set_focus('deliver_to'); @@ -598,13 +596,7 @@ function create_cart($type, $trans_no) $doc->document_date = new_doc_date(); if ($type == ST_SALESINVOICE) { $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->pos = -1; // mark not editable payment type -// else -// $doc->cash = date_diff2($doc->due_date, Today(), 'd')<2; + $doc->pos = get_sales_point(user_pos()); } else $doc->due_date = $doc->document_date; $doc->reference = $Refs->get_next($doc->trans_type);