Fix 0 quantity not displayed
[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_costable_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id']);
64 // Needs to be done afterward  as it can modify the post variable
65 $stock_id = $_POST['stock_id'];
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 if(isset($_POST['Cancel'])) {
78         $Ajax->activate('item_schedule');
79         $params = new ScheduleParameters($_SESSION['schedule_parameters']);
80         $params->setMode('cancel');
81 }
82 else {
83         $params = in_ajax() && $stock_id == @$_POST['last_stock_id'] ? new ScheduleParameters($_POST) : null;
84         // save parameters form update
85         $_SESSION['schedule_parameters'] = $_POST;
86 }
87 $scheduler = new ItemScheduler($stock_id, OrderXtraConfig::$default_location, $params);
88 $scheduler->action();
89
90 print("<center><h2>$stock_id</h2></center>");
91
92 start_table(TABLESTYLE);
93 $th = $scheduler->tableHeader();
94
95 table_header($th);
96
97 $scheduler->generateTable();
98
99 end_table();
100
101
102 if($scheduler->needsUpdate()) {
103          submit_center_first('Update', _("Update"), '', 'default', false);
104         submit_center_last('Cancel', _("Cancel"), '', 'cancel', false);
105 }
106
107
108
109 end_form();
110 div_end();
111 end_page();
112 ?>
113 <style type='text/css'>
114 tr.partial {
115         color: darkred;
116 }
117
118 tr.partial  td:nth-child(5) {
119         background: pink;
120 }
121
122
123 tr.location {
124         font-weight: normal;
125                 background: #bbb;
126 }
127 tr.picked {
128         font-weight: normal;
129                 background: #8f8;
130 }
131 tr.on_time {
132 }
133
134 tr.late {
135                 background: #fc8;
136 }
137 tr.early {
138                 background: #def;
139                 color: blue;
140 }
141
142 tr.soldout {
143                 background: pink;
144 }
145
146 tr.expired td:nth-child(7) {
147         background: #444;
148         color: white;
149 }
150
151 tr.tDnD_whileDrag {
152         background: #ccc;
153         border: 2px solid black;
154 }
155 tr.tDnD_whileDrag :nth-child(4), tr.tDnD_whileDrag :nth-child(5) {
156         color: transparent;
157         background: transparent;
158 }
159
160 span.picked {
161         color: black;
162         font-weight: bold;
163 }
164
165 tr.partial span.pickable {
166         background: #cfc;
167 }
168 span.partial  {
169         background: transparent;
170 }
171 </style>
172 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
173 <script src="js/jquery.tablednd.0.8.min.js"></script>
174 <script text="text/javascript">
175         /**  add table DnD as behavior **/
176         function onDragStart (table, row) {
177         console.log(table)
178                 console.log(row)
179         }
180         function findRowPosition(table, row) {
181         }
182         function addInput(form, name, value) {
183                 $(form).append('<input type="hidden" name="'+name+'" value="'+value+'">')
184                         }
185         function addInputs(form, name, values) {
186                 for(index = 0; index < values.length; index++) {
187                                 addInput(form, name+'['+index+']', values[index])
188                                 }
189                         }
190         function onDrop(table, row) {
191                 var row_ids = $.map(table.tBodies[0].rows, function(r) { return r.id} )
192                 var row_id = row.id
193                 var form = $(table).closest('form')[0]
194                 
195                 addInput(form, 'row_id', row.id)
196                 addInputs(form, 'row_order', row_ids )
197                 
198                 JsHttpRequest.request(this, form);
199                 
200         }
201
202         function onPick(element) {
203                 /* horible hack but it works */
204                 /* in the way it call an Ajax request */
205                 var row = $(element).closest('tr')[0];
206                 var table = $(element).closest('table')[0];
207                 onDrop(table, row);
208                 
209         }
210
211         var inserts = {
212                 '#item_schedule table': function (e) { 
213                         $(e).tableDnD({onDragStart: onDragStart, onDrop: onDrop})
214                 }
215         }
216 Behaviour.register(inserts);
217 </script>