Some smaller and compatibility fixes - see CHANGELOG.txt
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 10 Mar 2008 13:09:18 +0000 (13:09 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 10 Mar 2008 13:09:18 +0000 (13:09 +0000)
12 files changed:
sales/credit_note_entry.php
sales/customer_credit_invoice.php
sales/customer_delivery.php
sales/customer_invoice.php
sales/includes/cart_class.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/sales_db.inc
sales/includes/ui/sales_credit_ui.inc
sales/includes/ui/sales_order_ui.inc

index 5b43a17352f7b6d443c08d2d296064fb001b7093..9258863992f46e5a8612a8876f8817743f24aaef 100644 (file)
@@ -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;
 }
index 31306707c7597736e1fa05bb833bcdc009b81468..0a1e103c136310233b23e5a3b003e2e032014562 100644 (file)
@@ -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']);
 
index a1672775c74685780b4bc4ed9ed558d1e6135b2a..6575598ad4fc69081313c921149b666a4a15cbab 100644 (file)
@@ -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();
 
index 51c38d2fad729cebed7a8d8d4addececdfecc8cc..fb726cd01734441a6a3bfc0b4b612ddd2491589b 100644 (file)
@@ -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();
index c2f7f4ab6d436ca7bf0bbadd33980700594b631c..463b762256a517cca8b7c7e8a9b1e2b48235df01 100644 (file)
@@ -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_no<count($this->line_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_no<count($this->line_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;
index f5d66505b42ee6c403c2cd468da2725bb8b08fd9..4cf0aa567ab717acc78189315c17a25e4b95af07 100644 (file)
@@ -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)
 {
 
index b50d418aef579b5880b2637bb226d26062c97e99..71d5ca8856c5f68b04c2dc613b57ecafead0726a 100644 (file)
@@ -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) {
index 0a1683abbe8c1f07a63ea3461b3e3655d9ed015b..3627eb19354ae0daf4de38a9891d17795ed345bb 100644 (file)
@@ -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) {
index 72f54eebdc0d9039cd39ecddff0b7a3e6023c204..1b0273dfd7ff953fa81946102c4d3b551739b16f 100644 (file)
@@ -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"]);
index e3b3e5a34752fa304d8bef0e191487b6ded1b598..55d6138516dfee8b84464be2176db5d81f8453f1 100644 (file)
@@ -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");
 
index 751d7bd30cb8ba7debccd5a31f573705375a86fb..811167d603aa9103d82f1401c88eb3ee79d71a1c 100644 (file)
@@ -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 "<table height='5'>";
 
     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 "</table>";
@@ -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;
        }
index ead41ed92fc165ad06f654e89e8d9d5e332f5f43..5494ae00f83a6b7e27d5af9f41f93487f4505fee 100644 (file)
@@ -160,6 +160,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
        echo "<table>";
 
        $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 "</td><td>"; // 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 "<table height='5'>";
-       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 "</table>";
 
@@ -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;
        }