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