BulkUpdater work.
[order_line_extra.git] / item_schedule.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $path_to_root = "../..";
13
14 include_once($path_to_root . "/includes/session.inc");
15 include_once($path_to_root . "/includes/ui/ui_lists.inc");
16 include_once($path_to_root . "/includes/ui/ui_globals.inc");
17 include_once($path_to_root . "/includes/ui/ui_input.inc");
18 include_once($path_to_root . "/reporting/includes/reporting.inc");
19
20 //include_once("includes/item_scheduler.inc");
21 include_once("hincludes/lib/php/Boot.class.php");
22 include_once("includes/db_order_lines.inc");
23 include_once("config.php");
24
25 $page_security = 'SA_ORDERLINEX_EDIT';
26 add_access_extensions();
27
28 $_SESSION['page_title'] = _($help_context = "Item schedule");
29
30
31 $js = "";
32 page($_SESSION['page_title'], false, false, "", $js);
33
34 //---------------------------------------------------------------------------------------------
35
36 div_start('item_schedule');
37 start_form();
38
39
40 start_table(TABLESTYLE_NOBORDER);
41 start_row();
42
43 if (!isset($_POST['stock_id'])) {
44 if (isset($_GET['stock_id']))
45 {
46         $_POST['stock_id'] = $_GET['stock_id'];
47 }
48 else {
49         $_POST['stock_id'] = get_global_stock_item();
50         }
51 }
52
53 if (list_updated('stock_id') || in_ajax()) $Ajax->activate('item_schedule') ;
54 //else update_queue_quantities() && update_qoh_for_item();
55
56
57 //if (!@$_GET['popup'])
58 //      start_form();
59
60
61
62 $stock_id = $_POST['stock_id'];
63         stock_costable_items_list_cells(_("Item:"), 'stock_id', $stock_id);
64
65
66 end_row();
67 end_table(1);
68 if(isset($stock_id)) echo '<input type="hidden" name="last_stock_id" value="'.$stock_id.'">';
69
70 if(isset($_POST['Update'])) {
71         $Ajax->activate('item_schedule');
72         // Restore the parameters
73         $params = new ScheduleParameters($_SESSION['schedule_parameters']);
74         $params->setMode('update');
75 }
76 else {
77         $params = in_ajax() && $stock_id == @$_POST['last_stock_id'] ? new ScheduleParameters($_POST) : null;
78         // save parameters form update
79         $_SESSION['schedule_parameters'] = $_POST;
80 }
81 $scheduler = new ItemScheduler($stock_id, OrderXtraConfig::$default_location, $params);
82 $scheduler->action();
83
84 start_table(TABLESTYLE);
85 $th = $scheduler->tableHeader();
86
87 table_header($th);
88
89 $scheduler->generateTable();
90
91 end_table();
92
93
94 if($scheduler->needsUpdate()) {
95          submit_center_first('Update', _("Update"), '', 'default', false);
96         submit_center_last('Cancel', _("Cancel"), '', 'cancel', false);
97 }
98
99
100
101 end_form();
102 div_end();
103 end_page();
104 ?>
105 <style type='text/css'>
106 tr.partial {
107         color: darkred;
108 }
109
110 tr.partial  td:nth-child(5) {
111         background: pink;
112 }
113
114 tr.location {
115         font-weight: normal;
116                 background: #8f8;
117 }
118 tr.on_time {
119 }
120
121 tr.late {
122                 background: #fc8;
123 }
124 tr.early {
125                 background: #def;
126                 color: blue;
127 }
128
129 tr.soldout {
130                 background: pink;
131 }
132
133 tr.tDnD_whileDrag {
134         background: #ccc;
135         border: 2px solid black;
136 }
137 tr.tDnD_whileDrag :nth-child(4), tr.tDnD_whileDrag :nth-child(5) {
138         color: transparent;
139         background: transparent;
140 }
141 </style>
142 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
143 <script src="js/jquery.tablednd.0.8.min.js"></script>
144 <script text="text/javascript">
145         /**  add table DnD as behavior **/
146         function onDragStart (table, row) {
147         console.log(table)
148                 console.log(row)
149         }
150         function findRowPosition(table, row) {
151         }
152         function addInput(form, name, value) {
153                 $(form).append('<input type="hidden" name="'+name+'" value="'+value+'">')
154                         }
155         function addInputs(form, name, values) {
156                 for(index = 0; index < values.length; index++) {
157                                 addInput(form, name+'['+index+']', values[index])
158                                 }
159                         }
160         function onDrop(table, row) {
161                 var row_ids = $.map(table.tBodies[0].rows, function(r) { return r.id} )
162                 var row_id = row.id
163                 var form = $(table).closest('form')[0]
164                 
165                 addInput(form, 'row_id', row.id)
166                 addInputs(form, 'row_order', row_ids )
167                 
168                 JsHttpRequest.request(this, form);
169                 
170         }
171
172         var inserts = {
173                 '#item_schedule table': function (e) { 
174                         $(e).tableDnD({onDragStart: onDragStart, onDrop: onDrop})
175                 }
176         }
177 Behaviour.register(inserts);
178 </script>