Rewritten sales shipping cost taxation, improved shipping cost handling in sales...
[fa-stable.git] / sales / includes / ui / sales_order_ui.inc
index 7b91967b97ab7bb734e393d297781c7496f53c17..d5e5600eaf023884f7cde538460d20cf91fb343b 100644 (file)
@@ -215,9 +215,15 @@ function display_order_summary($title, &$order, $editable_items=false)
        if ($order->trans_no!=0)
                ++$colspan;
        start_row();
-       label_cell(_("Shipping Charge"), "colspan=$colspan align=right");
-       small_amount_cells(null, 'freight_cost', price_format(get_post('freight_cost',0)));
-       label_cell('', 'colspan=2');
+
+       label_cell(_("Shipping method:") . shipping_methods_list('ship_via', null, _("None"), true), "colspan=$colspan align=right");
+
+       if (get_post('ship_via') !== ALL_TEXT) 
+       {
+               small_amount_cells(null, 'freight_cost', price_format(get_post('freight_cost',0)));
+               label_cell('', 'colspan=2');
+       } else
+               label_cell('', 'colspan=3');
        end_row();
        $display_sub_total = price_format($total + input_num('freight_cost'));
        label_row(_("Sub-total"), $display_sub_total, "colspan=$colspan align=right","align=right", 2);
@@ -457,12 +463,22 @@ function display_order_header(&$order, $editable, $date_text)
 
        end_outer_table(1); // outer table
 
+       if (list_updated('ship_via')) {
+               $_SESSION['Items']->ship_via = get_post('ship_via');
+               $_POST['freight_cost'] = price_format(get_price(get_post('ship_via'), $_SESSION['Items']->customer_currency, get_post('sales_type')));
+               $Ajax->activate('items_table');
+       }
+
+
        if ($change_prices != 0) {
                foreach ($order->line_items as $line_no=>$item) {
                        $line = &$order->line_items[$line_no];
                        $line->price = get_kit_price($line->stock_id, $order->customer_currency,
                                $order->sales_type, $order->price_factor, get_post('OrderDate'));
                }
+       }
+       if ($change_prices != 0 || list_updated('ship_via')) {
+               $_POST['freight_cost'] = price_format(get_price(get_post('ship_via'), $_SESSION['Items']->customer_currency, get_post('sales_type')));
            $Ajax->activate('items_table');
        }
 
@@ -490,7 +506,7 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1)
                hidden('stock_id', $_POST['stock_id']);
                label_cell($_POST['stock_id']);
                if ($order->line_items[$id]->descr_editable)
-                       text_cells(null,'item_description', null, 45, 150);
+                       text_cells(null,'item_description', null, 45, 50);
                else {
                        hidden('item_description', $_POST['item_description']);
                        label_cell($_POST['item_description']);
@@ -499,13 +515,20 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1)
        }
        else    // prepare new line
        {
-               sales_items_list_cells(null,'stock_id', null, false, true, true);
-               if (list_updated('stock_id')) {
-                           $Ajax->activate('price');
-                           $Ajax->activate('units');
-                           $Ajax->activate('qty');
-                           $Ajax->activate('line_total');
-               }
+               if ($order->fixed_asset)
+            stock_disposable_fa_list_cells(null,'stock_id', null, _('[Select item]'), true, $order->line_items);
+        else {
+            if (!isset($_POST['stock_id'])) {   // Check if stock_id dosesn't exist
+                               $_POST['stock_id'] = last_sales_order_detail($order, 'stk_code');  //get the llast sales stock id.
+                       }
+            sales_items_list_cells(null,'stock_id', $_POST['stock_id'], false, true, true);
+        }
+        if (list_updated('stock_id')) {            
+            $Ajax->activate('price');
+            $Ajax->activate('units');
+            $Ajax->activate('qty');
+            $Ajax->activate('line_total');
+        }              
 
                $item_info = get_item_edit_info($_POST['stock_id']);
                $units = $item_info["units"];
@@ -519,7 +542,11 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1)
                $_POST['Disc'] = percent_format($order->default_discount * 100);
        }
 
-       qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
+       if ($order->fixed_asset) {
+               label_cell(1, '', 'qty');
+               hidden('qty', 1);
+       } else 
+               qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
 
        if ($order->trans_no!=0) {
                qty_cell($line_no==-1 ? 0 :$order->line_items[$line_no]->qty_done, false, $dec);
@@ -599,8 +626,8 @@ function display_delivery_details(&$order)
                start_outer_table(TABLESTYLE2, "width='90%'");
                table_section(1);
 
-               locations_list_row(_("Deliver from Location:"), 'Location', null, false, true);
-               if ($order->payment_terms['days_before_due'] < 0)
+               locations_list_row(_("Deliver from Location:"), 'Location', null, false, true, $order->fixed_asset);
+               if ($order->payment_terms['days_before_due'] == -1)
                {
                        $Ajax->addUpdate('items_table', 'prep_amount', price_format($order->get_trans_total())); // bind to items_table update
                        if (!$order->is_started())
@@ -629,8 +656,6 @@ function display_delivery_details(&$order)
                  _('Customer reference number for this order (if any)'));
                textarea_row(_("Comments:"), "Comments", $order->Comments, 31, 5);
 
-               shippers_list_row(_("Shipping Company:"), 'ship_via', $order->ship_via);
-
                end_outer_table(1);
        }
        div_end();