Fix displayed required date
[order_line_extra.git] / item_schedule.php
index fff2d21feca5fadc869133a919aa07e6d862b9ce..1937108e1a2b834d893d3ade96c8a01ca312e940 100644 (file)
@@ -19,6 +19,7 @@ include_once($path_to_root . "/reporting/includes/reporting.inc");
 
 //include_once("includes/item_scheduler.inc");
 include_once("hincludes/lib/php/Boot.class.php");
+include_once("includes/db_order_lines.inc");
 
 $page_security = 'SA_ORDERLINEX_EDIT';
 add_access_extensions();
@@ -31,31 +32,54 @@ page($_SESSION['page_title'], false, false, "", $js);
 
 //---------------------------------------------------------------------------------------------
 
+div_start('item_schedule');
 start_form();
 
+
 start_table(TABLESTYLE_NOBORDER);
 start_row();
 
+if (!isset($_POST['stock_id'])) {
 if (isset($_GET['stock_id']))
 {
        $_POST['stock_id'] = $_GET['stock_id'];
 }
+else {
+       $_POST['stock_id'] = get_global_stock_item();
+       }
+}
+
+if (list_updated('stock_id') || in_ajax()) $Ajax->activate('item_schedule') ;
+else update_queue_quantities() && update_qoh_for_item();
+
 
 //if (!@$_GET['popup'])
-       start_form();
+//     start_form();
+
 
-if (!isset($_POST['stock_id']))
-       $_POST['stock_id'] = get_global_stock_item();
 
 $stock_id = $_POST['stock_id'];
        stock_costable_items_list_cells(_("Item:"), 'stock_id', $stock_id);
 
+
 end_row();
 end_table(1);
+if(isset($stock_id)) echo '<input type="hidden" name="last_stock_id" value="'.$stock_id.'">';
 
-$scheduler = new ItemScheduler($stock_id, 'DEF');
+if(isset($_POST['Update'])) {
+       $Ajax->activate('item_schedule');
+       // Restore the parameters
+       $params = new ScheduleParameters($_SESSION['schedule_parameters']);
+       $params->setMode('update');
+}
+else {
+       $params = in_ajax() && $stock_id == @$_POST['last_stock_id'] ? new ScheduleParameters($_POST) : null;
+       // save parameters form update
+       $_SESSION['schedule_parameters'] = $_POST;
+}
+$scheduler = new ItemScheduler($stock_id, 'DEF', $params);
+$scheduler->action();
 
-div_start('item_schedule');
 start_table(TABLESTYLE);
 $th = $scheduler->tableHeader();
 
@@ -64,15 +88,17 @@ table_header($th);
 $scheduler->generateTable();
 
 end_table();
-div_end();
 
 
-submit_center_first('Update', _("Update"), '', 'default', false);
-submit_center_last('Cancel', _("Cancel"), '', 'cancel', false);
+if($scheduler->needsUpdate()) {
+        submit_center_first('Update', _("Update"), '', 'default', false);
+       submit_center_last('Cancel', _("Cancel"), '', 'cancel', false);
+}
 
 
 
 end_form();
+div_end();
 end_page();
 ?>
 <style type='text/css'>
@@ -112,9 +138,37 @@ tr.tDnD_whileDrag :nth-child(4), tr.tDnD_whileDrag :nth-child(5) {
 <script src="js/jquery.tablednd.0.8.min.js"></script>
 <script text="text/javascript">
        console.log('hello')
-       $(document).ready(function() {
-               console.log('ready')
-               $('#item_schedule table').tableDnD()
+       /**  add table DnD as behavior **/
+       function onDragStart (table, row) {
+       console.log(table)
+               console.log(row)
+       }
+       function findRowPosition(table, row) {
+       }
+       function addInput(form, name, value) {
+               $(form).append('<input type="hidden" name="'+name+'" value="'+value+'">')
+                       }
+       function addInputs(form, name, values) {
+               for(index = 0; index < values.length; index++) {
+                               addInput(form, name+'['+index+']', values[index])
+                               }
+                       }
+       function onDrop(table, row) {
+               var row_ids = $.map(table.tBodies[0].rows, function(r) { return r.id} )
+               var row_id = row.id
+               var form = $(table).closest('form')[0]
+               
+               addInput(form, 'row_id', row.id)
+               addInputs(form, 'row_order', row_ids )
+               
+               JsHttpRequest.request(this, form);
+               
+       }
+
+       var inserts = {
+               '#item_schedule table': function (e) { 
+                       $(e).tableDnD({onDragStart: onDragStart, onDrop: onDrop})
+               }
        }
-       )
+Behaviour.register(inserts);
 </script>