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