Picked = Green + fix null quantity => 0.
[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("includes/picking.inc");
24 include_once("config.php");
25
26 $page_security = 'SA_ORDERLINEX_SCHEDULE';
27 add_access_extensions();
28
29 $_SESSION['page_title'] = _($help_context = "Item schedule");
30
31
32 $js = "";
33 page($_SESSION['page_title'], false, false, "", $js);
34
35 //---------------------------------------------------------------------------------------------
36
37 div_start('item_schedule');
38 start_form();
39
40
41 start_table(TABLESTYLE_NOBORDER);
42 start_row();
43
44 if (!isset($_POST['stock_id'])) {
45 if (isset($_GET['stock_id']))
46 {
47         $_POST['stock_id'] = $_GET['stock_id'];
48 }
49 else {
50         $_POST['stock_id'] = get_global_stock_item();
51         }
52 }
53
54 if (list_updated('stock_id') || in_ajax()) $Ajax->activate('item_schedule') ;
55 //else update_queue_quantities() && update_qoh_for_item();
56
57
58 //if (!@$_GET['popup'])
59 //      start_form();
60
61
62
63 $stock_id = $_POST['stock_id'];
64         stock_costable_items_list_cells(_("Item:"), 'stock_id', $stock_id);
65
66
67 end_row();
68 end_table(1);
69 if(isset($stock_id)) echo '<input type="hidden" name="last_stock_id" value="'.$stock_id.'">';
70
71 if(isset($_POST['Update'])) {
72         $Ajax->activate('item_schedule');
73         // Restore the parameters
74         $params = new ScheduleParameters($_SESSION['schedule_parameters']);
75         $params->setMode('update');
76 }
77 else {
78         $params = in_ajax() && $stock_id == @$_POST['last_stock_id'] ? new ScheduleParameters($_POST) : null;
79         // save parameters form update
80         $_SESSION['schedule_parameters'] = $_POST;
81 }
82 $scheduler = new ItemScheduler($stock_id, OrderXtraConfig::$default_location, $params);
83 $scheduler->action();
84
85 start_table(TABLESTYLE);
86 $th = $scheduler->tableHeader();
87
88 table_header($th);
89
90 $scheduler->generateTable();
91
92 end_table();
93
94
95 if($scheduler->needsUpdate()) {
96          submit_center_first('Update', _("Update"), '', 'default', false);
97         submit_center_last('Cancel', _("Cancel"), '', 'cancel', false);
98 }
99
100
101
102 end_form();
103 div_end();
104 end_page();
105 ?>
106 <style type='text/css'>
107 tr.partial {
108         color: darkred;
109 }
110
111 tr.partial  td:nth-child(5) {
112         background: pink;
113 }
114
115
116 tr.location {
117         font-weight: normal;
118                 background: #bbb;
119 }
120 tr.picked {
121         font-weight: normal;
122                 background: #8f8;
123 }
124 tr.on_time {
125 }
126
127 tr.late {
128                 background: #fc8;
129 }
130 tr.early {
131                 background: #def;
132                 color: blue;
133 }
134
135 tr.soldout {
136                 background: pink;
137 }
138
139 tr.expired td:nth-child(7) {
140         background: #444;
141         color: white;
142 }
143
144 tr.tDnD_whileDrag {
145         background: #ccc;
146         border: 2px solid black;
147 }
148 tr.tDnD_whileDrag :nth-child(4), tr.tDnD_whileDrag :nth-child(5) {
149         color: transparent;
150         background: transparent;
151 }
152
153 span.picked {
154         color: black;
155         font-weight: bold;
156 }
157
158 tr.partial span.pickable {
159         background: #cfc;
160 }
161 span.partial  {
162         background: transparent;
163 }
164 </style>
165 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
166 <script src="js/jquery.tablednd.0.8.min.js"></script>
167 <script text="text/javascript">
168         /**  add table DnD as behavior **/
169         function onDragStart (table, row) {
170         console.log(table)
171                 console.log(row)
172         }
173         function findRowPosition(table, row) {
174         }
175         function addInput(form, name, value) {
176                 $(form).append('<input type="hidden" name="'+name+'" value="'+value+'">')
177                         }
178         function addInputs(form, name, values) {
179                 for(index = 0; index < values.length; index++) {
180                                 addInput(form, name+'['+index+']', values[index])
181                                 }
182                         }
183         function onDrop(table, row) {
184                 var row_ids = $.map(table.tBodies[0].rows, function(r) { return r.id} )
185                 var row_id = row.id
186                 var form = $(table).closest('form')[0]
187                 
188                 addInput(form, 'row_id', row.id)
189                 addInputs(form, 'row_order', row_ids )
190                 
191                 JsHttpRequest.request(this, form);
192                 
193         }
194
195         function onPick(element) {
196                 /* horible hack but it works */
197                 /* in the way it call an Ajax request */
198                 var row = $(element).closest('tr')[0];
199                 var table = $(element).closest('table')[0];
200                 onDrop(table, row);
201                 
202         }
203
204         var inserts = {
205                 '#item_schedule table': function (e) { 
206                         $(e).tableDnD({onDragStart: onDragStart, onDrop: onDrop})
207                 }
208         }
209 Behaviour.register(inserts);
210 </script>