Fixed edit line total, price update after date change
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 21 Sep 2008 14:48:52 +0000 (14:48 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 21 Sep 2008 14:48:52 +0000 (14:48 +0000)
sales/includes/ui/sales_credit_ui.inc
sales/includes/ui/sales_order_ui.inc

index 16e8fd488ef45fbf7aa93b3c8ec6530d4532e39d..be4adbf3060af84870e41abb06245b1d856f8830 100644 (file)
@@ -77,12 +77,14 @@ function display_credit_header(&$order)
 
        if (!is_company_currency($order->customer_currency))
        {
+           div_start('currency');
                echo "<table height='5'>";
                label_row(_("Customer Currency:"), $order->customer_currency);
                exchange_rate_display($order->customer_currency, get_company_currency(),
-                       $_POST['OrderDate'], true);
+                       $_POST['OrderDate']);
                echo "</table>";
                echo "</td><td>"; // outer table
+           div_end();
        }
 
        echo "<table height='5'>";
@@ -99,16 +101,6 @@ function display_credit_header(&$order)
                $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, $order->price_factor, $order->document_date);
-               //              $line->discount_percent = $order->default_discount;
-               }
-           $Ajax->activate('items_table');
-       }
-
        label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
        echo "</table>";
 
@@ -119,8 +111,11 @@ function display_credit_header(&$order)
        if (!isset($_POST['OrderDate']) || $_POST['OrderDate'] == "")
                $_POST['OrderDate'] = $order->document_date;
 
-       date_row(_("Date:"), 'OrderDate');
-
+       date_row(_("Date:"), 'OrderDate', '', null, 0, 0, 0, null, true);
+       if (isset($_POST['_OrderDate_changed'])) {
+               $change_prices = 1;
+               $Ajax->activate('currency');
+       }
     shippers_list_row(_("Shipping Company:"), 'ShipperID', $order->ship_via);
 
        echo "</table>";
@@ -129,6 +124,17 @@ function display_credit_header(&$order)
 
        end_table(1); // outer table
 
+       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, $order->price_factor, get_post('OrderDate'));
+               //              $line->discount_percent = $order->default_discount;
+               }
+           $Ajax->activate('items_table');
+       }
+
+
        return $customer_error;
 }
 
@@ -256,7 +262,7 @@ function credit_edit_item_controls(&$order, $rowcounter, $line_no=-1)
        amount_cells(null, 'price',  null);
        small_amount_cells(null, 'Disc', percent_format(0), null, null, user_percent_dec());
 
-       amount_cell($_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc']/100));
+       amount_cell(input_num('qty') * input_num('price') * (1 - input_num('Disc')/100));
 
        if ($id!=-1)
        {
index ec188302813bd85e08c52e41448c2cfe24cd5128..e2c004abb09d44221551079a7a8d06d6ac4b960b 100644 (file)
@@ -243,7 +243,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
                echo "<table height='5'>";
                label_row(_("Customer Currency:"), $order->customer_currency);
                exchange_rate_display($order->customer_currency, get_company_currency(),
-                       ($editable ? $_POST['OrderDate'] : $order->document_date), $editable);
+                       ($editable ? $_POST['OrderDate'] : $order->document_date));
                echo "</table>";
            div_end();
                echo "</td><td>"; // outer table
@@ -259,20 +259,11 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
        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'], $myrow['factor']);
+                       $myrow['tax_included'], $myrow['factor']);
                $Ajax->activate('sales_type');
                $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, $order->price_factor, $order->document_date);
-               //              $line->discount_percent = $order->default_discount;
-               }
-           $Ajax->activate('items_table');
-       }
        label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
        echo "</table>";
 
@@ -286,7 +277,16 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
                        $_POST['OrderDate'] = $order->document_date;
 
                date_row($date_text, 'OrderDate',
-                 _('Date of order receive'));
+                 _('Date of order receive'), null, 0, 0, 0, null, true);
+               if (isset($_POST['_OrderDate_changed'])) {
+                       $change_prices = 1;
+                       $Ajax->activate('currency');
+                       if ($order->trans_type == 10) {
+                               $_POST['delivery_date'] = get_invoice_duedate(get_post('customer_id'), get_post('OrderDate'));
+                       } else 
+                               $_POST['delivery_date'] = add_days(get_post('OrderDate'), sys_prefs::default_delivery_required_by());
+                       $Ajax->activate('delivery_date');
+               }
        }
        else
        {
@@ -305,6 +305,16 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
 
        end_table(1); // outer table
 
+       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, $order->price_factor, get_post('OrderDate'));
+               //              $line->discount_percent = $order->default_discount;
+               }
+           $Ajax->activate('items_table');
+       }
+
        return $customer_error;
 }
 
@@ -347,7 +357,7 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1)
 
                $_POST['price'] = price_format(get_price ($_POST['stock_id'],
                        $order->customer_currency, $order->sales_type,
-                       $order->price_factor, $order->document_date));
+                       $order->price_factor, get_post('OrderDate')));
                // default to the customer's discount %
                $_POST['Disc'] = percent_format($order->default_discount * 100);
 
@@ -365,7 +375,7 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1)
 
        small_amount_cells(null, 'Disc', percent_format($_POST['Disc']), null, null, user_percent_dec());
 
-       $line_total = $_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc'] / 100);
+       $line_total = input_num('qty') * input_num('price') * (1 - input_num('Disc') / 100);
 
        amount_cell($line_total, false, '','line_total');