From: Janusz Dobrowolski Date: Mon, 10 Mar 2008 13:09:18 +0000 (+0000) Subject: Some smaller and compatibility fixes - see CHANGELOG.txt X-Git-Tag: v2.4.2~19^2~2203 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=e871e7b7f097ec86efa815e2005786710afb79e4;p=fa-stable.git Some smaller and compatibility fixes - see CHANGELOG.txt --- diff --git a/sales/credit_note_entry.php b/sales/credit_note_entry.php index 5b43a173..92588639 100644 --- a/sales/credit_note_entry.php +++ b/sales/credit_note_entry.php @@ -63,7 +63,7 @@ function copy_to_cn() $_SESSION['Items']->document_date = $_POST['OrderDate']; $_SESSION['Items']->freight_cost = $_POST['ChargeFreightCost']; $_SESSION['Items']->Location = $_POST["Location"]; - $_SESSION['Items']->default_sales_type = $_POST['sales_type_id']; + $_SESSION['Items']->sales_type = $_POST['sales_type_id']; $_SESSION['Items']->reference = $_POST['ref']; $_SESSION['Items']->ship_via = $_POST['ShipperID']; } @@ -76,7 +76,7 @@ function copy_from_cn() $_POST['OrderDate'] = $_SESSION['Items']->document_date; $_POST['ChargeFreightCost'] = $_SESSION['Items']->freight_cost; $_POST['Location'] = $_SESSION['Items']->Location; - $_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type; + $_POST['sales_type_id'] = $_SESSION['Items']->sales_type; $_POST['ref'] = $_SESSION['Items']->reference; $_POST['ShipperID'] = $_SESSION['Items']->ship_via; } diff --git a/sales/customer_credit_invoice.php b/sales/customer_credit_invoice.php index 31306707..0a1e103c 100644 --- a/sales/customer_credit_invoice.php +++ b/sales/customer_credit_invoice.php @@ -236,7 +236,7 @@ function display_credit_items() label_cell(_("Shipping Company"), "class='tableheader2'"); shippers_list_cells(null, 'ShipperID', $_POST['ShipperID']); // if (!isset($_POST['sales_type_id'])) -// $_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type; +// $_POST['sales_type_id'] = $_SESSION['Items']->sales_type; // label_cell(_("Sales Type"), "class='tableheader2'"); // sales_types_list_cells(null, 'sales_type_id', $_POST['sales_type_id']); diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index a1672775..6575598a 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -181,7 +181,7 @@ function copy_to_cart() $cart->due_date = $_POST['due_date']; $cart->Location = $_POST['Location']; $cart->Comments = $_POST['Comments']; - $cart->default_sales_type = $_POST['sales_type_id']; + $cart->sales_type = $_POST['sales_type_id']; } //------------------------------------------------------------------------------ @@ -194,7 +194,7 @@ function copy_from_cart() $_POST['due_date'] = $cart->due_date; $_POST['Location']= $cart->Location; $_POST['Comments']= $cart->Comments; - $_POST['sales_type_id'] = $cart->default_sales_type; + $_POST['sales_type_id'] = $cart->sales_type; } //------------------------------------------------------------------------------ @@ -298,12 +298,7 @@ if ($_SESSION['Items']->trans_no==0) { label_cells(_("For Sales Order"), get_customer_trans_view_str(systypes::sales_order(), $_SESSION['Items']->order_no), "class='tableheader2'"); -if (!isset($_POST['sales_type_id'])) { - $_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type; -} -label_cell(_("Sales Type"), "class='tableheader2'"); -sales_types_list_cells(null, 'sales_type_id', $_POST['sales_type_id']); - +label_cells(_("Sales Type"), $_SESSION['Items']->sales_type_name, "class='tableheader2'"); end_row(); start_row(); diff --git a/sales/customer_invoice.php b/sales/customer_invoice.php index 51c38d2f..fb726cd0 100644 --- a/sales/customer_invoice.php +++ b/sales/customer_invoice.php @@ -277,12 +277,7 @@ if ($_SESSION['Items']->trans_no == 0) { label_cells(_("Delivery Notes:"), get_customer_trans_view_str(systypes::cust_dispatch(), array_keys($_SESSION['Items']->src_docs)), "class='tableheader2'"); -if (!isset($_POST['sales_type_id'])) { - $_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type; -} - -label_cell(_("Sales Type"), "class='tableheader2'"); -sales_types_list_cells(null, 'sales_type_id', $_POST['sales_type_id']); +label_cells(_("Sales Type"), $_SESSION['Items']->sales_type_name, "class='tableheader2'"); end_row(); start_row(); diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index c2f7f4ab..463b7622 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -25,7 +25,7 @@ class cart var $document_date; var $due_date; - var $default_sales_type; // set to the customer's sales type + var $sales_type; // set to the customer's sales type var $sales_type_name; // set to customer's sales type name var $tax_included; @@ -64,94 +64,93 @@ class cart function Cart($type, $trans_no=0, $view=false ) { /*Constructor function initialises a new shopping cart */ $this->line_items = array(); - $this->default_sales_type = ""; + $this->sales_type = ""; $this->trans_type = 30; $this->read($type, $trans_no, $view ); } + //------------------------------------------------------------------------- + // Reading document into cart + // + function read($type, $trans_no = 0, $view=false ) { - function read($type, $trans_no=0, $view=false ) { - - if (!is_array($trans_no)) $trans_no = array($trans_no); + if (!is_array($trans_no)) $trans_no = array($trans_no); - if ($trans_no[0]) { - if ($type==30) { // sales order - read_sales_order($trans_no[0], $this); - if ($view) { // prepare for DN/IV entry - for($line_no=0; $line_noline_items); $line_no++) { - $line= &$this->line_items[$line_no]; - $line->qty_dispatched = $line->quantity-$line->qty_done; - } - } - } else { // derivative transaction - read_sales_trans($type, $trans_no, $this); - if ($this->order_no) { // free hand credit notes have no order_no - $sodata = get_sales_order_header($this->order_no); - $this->cust_ref = $sodata["customer_ref"]; -//set_customer($customer_name, $customer_id, $currency, $discount) -//* $this->customer_name = $sodata["name"]; -//* $this->customer_currency = $sodata["curr_code"]; -//* $this->Comments = $sodata["comments"]; - $this->delivery_address = $sodata["delivery_address"]; -// $this->location_name = $sodata["location_name"]; -// $this->document_date = sql2date($myrow["ord_date"]); - } - if (!$view && ($type!=11 || $this->trans_link!=0)) { - $src_type = get_parent_type($type); - $src_details = 0; - if ($src_type==30) { // get src data from sales_orders - $this->src_docs = array( $sodata['order_no']=>$sodata['version']); - $srcdetails = get_sales_order_details($this->order_no); - } else { // get src_data from debtor_trans - $this->src_docs = get_customer_trans_version($src_type, get_parent_trans($type,$trans_no[0])); - $srcdetails = get_customer_trans_details($src_type,array_keys($this->src_docs)); - } - // calculate & save: qtys on other docs and free qtys on src doc - $line_no = 0; - for($line_no=0; $srcline = db_fetch($srcdetails); $line_no++) { - $sign = 1; // $type==13 ? 1 : -1; // this is strange debtor_trans atavism + if ($trans_no[0]) { + if ($type == 30) { // sales order + read_sales_order($trans_no[0], $this); + if ($view) { // prepare for DN/IV entry + for($line_no = 0; $line_no < count($this->line_items); $line_no++) { $line = &$this->line_items[$line_no]; - - $line->qty_old = $line->qty_dispatched = $line->quantity; - $line->quantity += $sign*($srcline['quantity']-$srcline['qty_done']); // add free qty on src doc + $line->qty_dispatched = $line->quantity - $line->qty_done; + } + } + } else { // derivative transaction + read_sales_trans($type, $trans_no, $this); + if ($this->order_no) { // free hand credit notes have no order_no + $sodata = get_sales_order_header($this->order_no); + $this->cust_ref = $sodata["customer_ref"]; + // currently currency is hard linked to debtor account + // $this->customer_currency = $sodata["curr_code"]; + $this->delivery_to = $sodata["deliver_to"]; + $this->delivery_address = $sodata["delivery_address"]; } - } else { - for($line_no=0; $line_noline_items); $line_no++) { - $line= &$this->line_items[$line_no]; - $line->qty_dispatched = $line->quantity; + if (!$view && ($type!=11 || $this->trans_link!=0)) { + $src_type = get_parent_type($type); + $src_details = 0; + if ($src_type == 30) { // get src data from sales_orders + $this->src_docs = array( $sodata['order_no']=>$sodata['version']); + $srcdetails = get_sales_order_details($this->order_no); + } else { // get src_data from debtor_trans + $this->src_docs = get_customer_trans_version($src_type, get_parent_trans($type,$trans_no[0])); + $srcdetails = get_customer_trans_details($src_type,array_keys($this->src_docs)); + } + // calculate & save: qtys on other docs and free qtys on src doc + $line_no = 0; + for($line_no = 0; $srcline = db_fetch($srcdetails); $line_no++) { + $sign = 1; // $type==13 ? 1 : -1; // this is strange debtor_trans atavism + $line = &$this->line_items[$line_no]; + + $line->qty_old = $line->qty_dispatched = $line->quantity; + $line->quantity += $sign * ($srcline['quantity'] - $srcline['qty_done']); // add free qty on src doc + } + } else { + for($line_no = 0; $line_no < count($this->line_items); $line_no++) { + $line = &$this->line_items[$line_no]; + $line->qty_dispatched = $line->quantity; + } } } + } else { + $this->trans_type = $type; + $this->trans_no = 0; + // set new sales document defaults here + $this->customer_id = ''; + $this->document_date = Today(); + if (!is_date_in_fiscalyear($this->document_date)) + $this->document_date = end_fiscalyear(); + $this->reference = references::get_next($this->trans_type); } - } else { - $this->trans_type = $type; - $this->trans_no = 0; - // set new sales document defaults here - $this->customer_id=''; - $this->document_date = Today(); - if (!is_date_in_fiscalyear($this->document_date)) - $this->document_date = end_fiscalyear(); - $this->reference = references::get_next($this->trans_type); - } } //------------------------------------------------------------------------- // Writing new/modified sales document to database. // Makes parent documents for direct delivery/invoice by recurent call. - + // $policy - 0 or 1: writeoff/return for IV, back order/cancel for DN function write($policy=0) { if (count($this->src_docs) == 0 && ($this->trans_type == 10 || $this->trans_type == 13)) { - // direct document -> first add parent - $src = do_clone($this); + // this is direct document - first add parent + $src = (PHP_VERSION<5) ? $this : clone( $this ); // make local copy of this cart $src->trans_type = get_parent_type($src->trans_type); $src->reference = 'auto'; $src->write(1); + $type = $this->trans_type; $ref = $this->reference; // re-read document $this->read($src->trans_type, key($src->trans_no), true); - $this->reference = $ref; $this->trans_type = $type; $this->src_docs= $this->trans_no; @@ -192,9 +191,10 @@ class cart function set_sales_type($sales_type, $sales_name, $tax_included=0) { - $this->default_sales_type = $sales_type; - $this->sales_type_name = $sales_name; - $this->tax_included = $tax_included; + $old_tax_inc = $this->tax_included; + $this->sales_type = $sales_type; + $this->sales_type_name = $sales_name; + $this->tax_included = $tax_included; } function set_location($id, $name) @@ -248,7 +248,7 @@ class cart { unset($this->line_items); $this->line_items = array(); - $this->default_sales_type = ""; + $this->sales_type = ""; $this->trans_no = 0; $this->customer_id = $this->order_no = 0; } @@ -337,7 +337,8 @@ class cart } - function get_tax_free_shipping() { + function get_tax_free_shipping() + { if ($this->tax_included==0) return $this->freight_cost; @@ -345,7 +346,8 @@ class cart return ($this->freight_cost - $this->get_shipping_tax()); } - function get_shipping_tax() { + function get_shipping_tax() + { $tax_items = get_shipping_tax_as_array(); $tax_rate = 0; diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index f5d66505..4cf0aa56 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -51,7 +51,7 @@ function write_credit_note($credit_note, $write_off_acc) $credit_note->Branch, $credit_date, $credit_note->reference, $credit_note_total, 0, $items_added_tax, $credit_note->freight_cost, $freight_added_tax, - $credit_note->default_sales_type, + $credit_note->sales_type, $credit_note->order_no, $credit_invoice, $credit_note->ship_via //, $credit_note->due_date ); @@ -102,7 +102,7 @@ function write_credit_note($credit_note, $write_off_acc) $credit_line->line_price(), $line_tax, $credit_line->discount_percent, $credit_line->standard_cost, $trans_no==0 ? 0: $credit_line->id); - add_credit_movements_item(&$credit_note, &$credit_line, $credit_date, + add_credit_movements_item(&$credit_note, &$credit_line, $credit_type, $line_taxfree_price+$line_tax, $credit_invoice); add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no, @@ -132,7 +132,7 @@ function write_credit_note($credit_note, $write_off_acc) add_customer_trans_tax_detail_item(11, $credit_no, $taxitem['tax_type_id'], $taxitem['rate'], $credit_note->tax_included, $taxitem['Value']); - add_gl_trans_customer(11, $credit_no, $date_, $taxitem['sales_gl_code'], 0, 0, + add_gl_trans_customer(11, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0, $taxitem['Value'], $credit_note->customer_id, "A tax GL posting for this credit note could not be inserted"); } @@ -153,7 +153,7 @@ function write_credit_note($credit_note, $write_off_acc) // Insert a stock movement coming back in to show the credit note and // a reversing stock movement to show the write off // -function add_credit_movements_item(&$credit_note, &$credit_line, $date_, +function add_credit_movements_item(&$credit_note, &$credit_line, $credit_type, $price, $credited_invoice=0) { diff --git a/sales/includes/db/sales_delivery_db.inc b/sales/includes/db/sales_delivery_db.inc index b50d418a..71d5ca88 100644 --- a/sales/includes/db/sales_delivery_db.inc +++ b/sales/includes/db/sales_delivery_db.inc @@ -29,7 +29,7 @@ function write_sales_delivery(&$delivery,$bo_policy) $delivery->tax_included ? 0 : $tax_total-$freight_tax, $delivery->freight_cost, $delivery->tax_included ? 0 : $freight_tax, - $delivery->default_sales_type, $delivery->order_no, 0, + $delivery->sales_type, $delivery->order_no, 0, $delivery->ship_via, $delivery->due_date); if ($trans_no == 0) { diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 0a1683ab..3627eb19 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -52,7 +52,7 @@ function write_sales_invoice(&$invoice) $invoice_no = write_customer_trans(10, $trans_no, $invoice->customer_id, $invoice->Branch, $date_, $invoice->reference, $items_total, 0, $items_added_tax, $invoice->freight_cost, $freight_added_tax, - $invoice->default_sales_type, $sales_order, $delivery_no, + $invoice->sales_type, $sales_order, $delivery_no, $invoice->ship_via, $invoice->due_date); if ($trans_no == 0) { diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index 72f54eeb..1b0273df 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -57,7 +57,7 @@ function add_sales_order(&$order) VALUES ('" . $order_type . "', '" . $order->customer_id . "', '" . $order->Branch . "', '". $order->cust_ref ."','". db_escape($order->Comments) ."','" . date2sql($order->document_date) . "', '" . - $order->default_sales_type . "', " . + $order->sales_type . "', " . $_POST['ship_via'] .",'" . $order->deliver_to . "', '" . $order->delivery_address . "', '" . $order->phone . "', '" . $order->email . "', " . @@ -182,7 +182,7 @@ function update_sales_order($order) customer_ref = '". $order->cust_ref ."', comments = '". db_escape($order->Comments) ."', ord_date = '" . $ord_date . "', - order_type = '" . $order->default_sales_type . "', + order_type = '" . $order->sales_type . "', ship_via = " . $order->ship_via .", deliver_to = '" . $order->deliver_to . "', delivery_address = '" . $order->delivery_address . "', @@ -365,7 +365,7 @@ function read_sales_order($order_no, &$order) $myrow["delivery_address"], $myrow["freight_cost"]); $order->cust_ref = $myrow["customer_ref"]; - $order->default_sales_type =$myrow["order_type"]; + $order->sales_type =$myrow["order_type"]; $order->Comments = $myrow["comments"]; $order->due_date = sql2date($myrow["delivery_date"]); $order->document_date = sql2date($myrow["ord_date"]); diff --git a/sales/includes/sales_db.inc b/sales/includes/sales_db.inc index e3b3e5a3..55d61385 100644 --- a/sales/includes/sales_db.inc +++ b/sales/includes/sales_db.inc @@ -46,14 +46,13 @@ function add_gl_trans_customer($type, $type_no, $date_, $account, $dimension, $d //---------------------------------------------------------------------------------------- -function get_price ($stock_id, $debtor_no) +function get_price ($stock_id, $currency, $sales_type_id) { $sql = "SELECT ".TB_PREF."prices.price - FROM ".TB_PREF."prices, ".TB_PREF."debtors_master - WHERE ".TB_PREF."debtors_master.sales_type=".TB_PREF."prices.sales_type_id - AND ".TB_PREF."debtors_master.debtor_no='" . $debtor_no . "' - AND ".TB_PREF."prices.stock_id = '" . $stock_id . "' - AND ".TB_PREF."prices.curr_abrev = ".TB_PREF."debtors_master.curr_code"; + FROM ".TB_PREF."prices + WHERE ".TB_PREF."prices.stock_id = '" . $stock_id . "' + AND ".TB_PREF."prices.sales_type_id = " . $sales_type_id . " + AND ".TB_PREF."prices.curr_abrev = '$currency'"; $result = db_query($sql, "There was a problem retrieving the pricing information for the part $stock_id for customer"); diff --git a/sales/includes/ui/sales_credit_ui.inc b/sales/includes/ui/sales_credit_ui.inc index 751d7bd3..811167d6 100644 --- a/sales/includes/ui/sales_credit_ui.inc +++ b/sales/includes/ui/sales_credit_ui.inc @@ -18,7 +18,7 @@ function display_credit_header(&$order) customer_list_row(_("Customer:"), 'customer_id', null, false, true); - if ($order->customer_id != $_POST['customer_id']) + if ($order->customer_id != $_POST['customer_id'] || $order->sales_type != $_POST['sales_type_id']) { // customer has changed @@ -68,8 +68,8 @@ function display_credit_header(&$order) echo ""; if (!isset($_POST['sales_type_id'])) - $_POST['sales_type_id'] = $order->default_sales_type; - sales_types_list_row(_("Sales Type"), 'sales_type_id', $_POST['sales_type_id']); + $_POST['sales_type_id'] = $order->sales_type; + sales_types_list_row(_("Sales Type"), 'sales_type_id', $_POST['sales_type_id'], true); label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%"); echo "
"; @@ -215,7 +215,8 @@ function credit_edit_item_controls(&$order, $line_no=-1) $_POST['units'] = $item_info["units"]; $_POST['qty'] = 0; - $_POST['price'] = get_price($_POST['stock_id'], $order->customer_id); + $_POST['price'] = get_price($_POST['stock_id'], + $order->customer_currency, $order->sales_type); // default to the customer's discount % $_POST['Disc'] = $order->default_discount * 100; } diff --git a/sales/includes/ui/sales_order_ui.inc b/sales/includes/ui/sales_order_ui.inc index ead41ed9..5494ae00 100644 --- a/sales/includes/ui/sales_order_ui.inc +++ b/sales/includes/ui/sales_order_ui.inc @@ -160,6 +160,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group echo ""; $customer_error = ""; + $change_prices = 0; if (isset($order) && !$editable) { @@ -205,36 +206,31 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group $customer_error = _("The selected customer does not have any branches. Please create at least one branch."); unset($_POST['branch_id']); $order->Branch = 0; - } else - + } else { - //set_global_customer($_POST['customer_id']); if (($order->customer_id != $_POST['customer_id']) || ($order->Branch != $_POST['branch_id'])) { - $old_order = $order; + + $old_order = (PHP_VERSION<5) ? $order : clone( $order ); $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']); $_POST['Location'] = $order->Location; $_POST['deliver_to'] = $order->deliver_to; $_POST['delivery_address'] = $order->delivery_address; $_POST['phone'] = $order->phone; + $_POST['sales_type'] = $order->sales_type; // change prices if necessary // what about discount in template case? if ( $old_order->customer_currency!=$order->customer_currency - || $old_order->default_sales_type!=$order->default_sales_type + || $old_order->sales_type!=$order->sales_type // || $old_order->default_discount!=$order->default_discount ) { - - foreach ($order->line_items as $line_no=>$item) { - $line = &$order->line_items[$line_no]; - $line->price = get_price($line->stock_id, $order->customer_id); - // $line->discount_percent = $order->default_discount; + $change_prices = 1; } - } } - } + } // changed branch set_global_customer($_POST['customer_id']); } @@ -256,8 +252,28 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group echo "
"; // outer table } + if( $order->sales_type != $_POST['sales_type']) { + $myrow = get_sales_type($_POST['sales_type']); + $order->set_sales_type($myrow['id'], $myrow['sales_type'], + $myrow['tax_included']); + $change_prices = 1; + } + + if($change_prices!=0) + { + foreach ($order->line_items as $line_no=>$item) { + $line = &$order->line_items[$line_no]; + $line->price = get_price($line->stock_id, $order->customer_currency, + $order->sales_type); + // $line->discount_percent = $order->default_discount; + } + } + echo ""; - label_row(_("Sales Type:"), $order->sales_type_name); + if($editable) + sales_types_list_row(_("Price List"), 'sales_type', $_POST['sales_type'], true); + else + label_row(_("Price List:"), $order->sales_type_name); label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%"); echo "
"; @@ -340,7 +356,8 @@ function sales_order_item_controls(&$order, $line_no=-1) $_POST['units'] = $item_info["units"]; $_POST['qty'] = 1; - $_POST['price'] = get_price ($_POST['stock_id'], $order->customer_id); + $_POST['price'] = get_price ($_POST['stock_id'], + $order->customer_currency, $order->sales_type); // default to the customer's discount % $_POST['Disc'] = $order->default_discount * 100; }