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