BulkUpdater work.
[order_line_extra.git] / order_lines_view.php
index f85e3b56a10ab39ad342019cba5541c6b25269bd..077e3767793f54ef3761888fc94485b2b083b271 100644 (file)
@@ -17,13 +17,19 @@ include_once($path_to_root . "/sales/includes/sales_ui.inc");
 include_once($path_to_root . "/reporting/includes/reporting.inc");
 
 include_once("includes/order_lines.inc");
+include_once("includes/splitter.inc");
+include_once("includes/bulk_updater.inc");
 
 $page_security = 'SA_ORDERLINEX_EDIT';
 add_access_extensions();
 
 $_SESSION['page_title'] = _($help_context = "Edit lines extra parameters");
 
+// Process POST
+filter_data($_POST);
 update_extra_order_details();
+split_order_details();
+bulk_update_order_details();
 
 
 $js = "";
@@ -54,6 +60,19 @@ else {
 }
 customer_list_cells(_("Select a customer: "), 'customer_id', $customer_id, true, true);
 
+if($customer_id != null) {
+       if(!isset($_POST['item_like'])) {
+               if(isset($_GET['item_like'])) {
+                       $item_like = $_GET['item_like'];
+                       $_POST['item_like'] = $item_like;
+               }
+               else $item_like = null;
+       }
+       else $item_like = $_POST['item_like'];
+       text_cells_ex('Filter Item', 'item_like', 50, null, $item_like,
+                       null, null, null, true );
+}
+
 
 
 
@@ -68,18 +87,24 @@ end_table(1);
 //     Orders inquiry table
 //
 if($customer_id) {
-       $sql = get_order_details_extra($customer_id);
+       $sql = get_order_details_extra($customer_id, 'DEF', $item_like);
        $cols = array(
                'detail_id' => 'skip'
                ,       _("Order #") => array('fun'=>'view_link', 'ord' => '')
-               ,_("Item Code") => array('ord' => '')
+               ,_("Item Code") => array('ord' => '', 'fun' => 'item_link')
                ,_("Quantity") => array('type' => 'qty', 'dec' => 0)
-       ,_("Required Date") => array('fun' => 'input_date_details', 'ord' => '')
-       ,_("Comment") => array('fun' => 'input_comment_details', 'ord' => '')
+               ,_("Available") => array('fun' => 'available_quantity', 'dec' => 0, 'ord' => '')
+               ,_("Before") => 'skip'
+               ,_("Priority") => array('type' => 'time', 'ord' => '')
+               ,_("Hold Until") => array('fun' => 'input_hold_until_date_details', 'ord' => '')
+               ,_("Require By") => array('fun' => 'input_required_date_details', 'ord' => '')
+               ,_("Expiry Date") => array('fun' => 'input_expiry_date_details', 'ord' => '')
+               ,_("Comment") => array('fun' => 'input_comment_details', 'ord' => '')
+               ,'<input id="checkAll" type="checkbox">' => array('fun' => 'input_check_details')
        );
 }
 else {
-       $sql = get_order_summary();
+       $sql = get_order_summary('DEF');
        $cols = array(
        'customer id' => 'skip',
 _("Customer") => array('ord' => '', 'fun' => 'customer_link'),
@@ -87,6 +112,8 @@ _("Branch") => array('ord' => ''),
 _("Delivery Date") => array('ord' => '', 'type' => 'date'),
 _("Quantity") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
 _("Amount") => array('ord' => '', 'type' => 'amount'),
+_("Avail. Q") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
+_("Avail. A") => array('ord' => '', 'type' => 'amount', 'dec' => 0),
 _("required date") => array('ord' => '', 'type' => 'date'),
 _("Comments") => array('ord' => '', 'fun' => 'aggregate_comment'),
 _("comment 2 ") =>  'skip'
@@ -100,9 +127,42 @@ $table->width = "80%";
 
 display_db_pager($table);
 
+function display_split_area() {
+qty_cells('Before', 'start_offset', -5);
+date_cells('Start', 'start_date', null, null, 0, 0, 1001);
+date_cells('End', 'end_date', null, null, 0, 0, 1001);
+qty_cells('After', 'end_offset', 2);
+qty_cells('Max', 'max_quantity', 6);
+submit_cells('Split', 'Split');
+
+}
+
+function display_bulk_area()  {
+date_cells('Priority', 'bulk[priority_date]', null, null, 0, 0, 1001);
+qty_cells(null, 'bulk[priority_time]', '12:00:00');
+date_cells('Hold', 'bulk[hold_until_date]', null, null, 0, 0, 1001);
+date_cells('Required', 'bulk[required_date]', null, null, 0, 0, 1001);
+date_cells('Expiry', 'bulk[expiry_date]', null, null, 0, 0, 1001);
+text_cells('Comment', 'bulk[comment]');
+submit_cells('Bulk', 'Bulk');
+}
+
+
+if($customer_id !== null) {
+start_table(TABLESTYLE);
+start_table(TABLESTYLE_NOBORDER);
+display_split_area();
+end_table();
+start_table(TABLESTYLE_NOBORDER);
+display_bulk_area();
+end_table();
+end_table();
+}
+
+
 br(1);
-submit_center_first('Update', _("Update"), true, '', 'default', true);
-submit_center_last('Cancel', _("Cancel"), true, '', 'cancel', true);
+submit_center_first('Update', _("Update"), '', 'default', false);
+submit_center_last('Cancel', _("Cancel"), '', 'cancel', false);
 
        end_form();
        end_page();
@@ -129,3 +189,37 @@ span.before-tooltip {
 }
 
 </style>
+<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
+<script text="text/javascript">
+
+var inserts = {
+       '#checkAll': function (e) {
+               e.onchange = function()  {
+                       $('.check_detail').prop('checked', e.checked)
+                       $('.check_detail').trigger('change');
+               }
+       }
+       ,'tr': function(e) {
+                       // find if there is a check detail box on link all input to it
+                       var tr = $(e);
+                       var check = tr.find('.check_detail');
+                       if(check.length != 1) return;
+                       check = check[0];
+                       var jcheck = $(check);
+                       var inputs = tr.find('input');
+                       inputs.each(function(index, input) {
+                               if(input === check) return;
+                               $(input).prop('disabled', true)
+                       })
+
+                       check.onchange = function() {
+                               inputs.each(function(index, input) {
+                                       var on = jcheck.prop('checked')
+                                       if(input == check) return;
+                                       $(input).prop('disabled', !on);
+                               })
+                       };
+               }
+       }
+Behaviour.register(inserts);
+</script>