Fix 0 quantity not displayed
[order_line_extra.git] / order_lines_view.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/db_pager.inc");
15 include_once($path_to_root . "/includes/session.inc");
16 include_once($path_to_root . "/sales/includes/sales_ui.inc");
17 include_once($path_to_root . "/reporting/includes/reporting.inc");
18
19 include_once("config.php");
20 include_once("includes/order_lines.inc");
21 include_once("includes/splitter.inc");
22 include_once("includes/bulk_updater.inc");
23 include_once("includes/picking.inc");
24
25 $page_security = 'SA_ORDERLINEX_EDIT';
26 add_access_extensions();
27
28 $_SESSION['page_title'] = _($help_context = "Edit lines extra parameters");
29
30 function get_parameter($param) {
31         $value = null;
32         if(!isset($_POST[$param])) {
33                 if(isset($_GET[$param])) {
34                         $value = $_GET[$param];
35                         $_POST[$param] = $value;
36                 }
37         }
38         else $value = $_POST[$param];
39         return $value;
40 }
41
42 // Process POST
43 filter_data($_POST);
44 update_extra_order_details();
45 split_order_details();
46 bulk_update_order_details();
47 pick_order_details();
48 unpick_order_details();
49
50 process_picking_flag();
51
52
53 $js = "";
54 if ($use_popup_windows)
55         $js .= get_js_open_window(900, 600);
56 if ($use_date_picker)
57         $js .= get_js_date_picker();
58 page($_SESSION['page_title'], false, false, "", $js);
59
60 //---------------------------------------------------------------------------------------------
61
62 div_start('order_line_view');
63 start_form();
64
65 start_table(TABLESTYLE_NOBORDER);
66 start_row();
67
68 $order_id = get_parameter('order_id');
69 text_cells_ex(_('Order #'), 'order_id', 10, null, $order_id,
70                 null, null, null, true );
71
72 if(!isset($_POST['customer_id'])) {
73         if(isset($_GET['customer_id'])) {
74                 $customer_id = $_GET['customer_id'];
75                 $_POST['customer_id'] = $customer_id;
76         }
77 else {
78         $customer_id = null;
79
80 }
81
82 }
83 else {
84         $customer_id = $_POST['customer_id'];
85 }
86         if($order_id) {
87                 // find the customer owing the order
88                 $result = db_query("SELECT debtor_no FROM ".TB_PREF."sales_orders WHERE order_no = $order_id AND trans_type =".ST_SALESORDER );
89                 if($result && $row=db_fetch($result)) $customer_id= $row['debtor_no'];
90         }
91 customer_list_cells(_("Select a customer: "), 'customer_id', $customer_id, true, true);
92
93 if($customer_id != null) {
94         if(!isset($_POST['item_like'])) {
95                 if(isset($_GET['item_like'])) {
96                         $item_like = $_GET['item_like'];
97                         $_POST['item_like'] = $item_like;
98                 }
99                 else $item_like = null;
100         }
101         else $item_like = $_POST['item_like'];
102         text_cells_ex('Filter Item', 'item_like', 50, null, $item_like,
103                         null, null, null, true );
104
105 }
106
107
108
109
110
111 //submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
112
113 end_row();
114
115 end_table(1);
116
117 //---------------------------------------------------------------------------------------------
118 //      Orders inquiry table
119 //
120 if($customer_id) {
121         // Display all item for one customer
122         $sql = get_order_details_extra($customer_id, 'DEF', $item_like, $order_id);
123         $cols = array(
124                 'detail_id' => 'skip'
125                 ,       _("Order #") => array('fun'=>'edit_link', 'ord' => '')
126                 ,_("Item Code") => array('ord' => '', 'fun' => 'item_link')
127                 ,_("Quantity") => array('ord' => '', 'type' => 'qty', 'dec' => 0)
128                 ,_("Available") => array('fun' => 'available_quantity', 'dec' => 0, 'ord' => '')
129                 ,_("Before") => 'skip'
130                 ,_("QOH") => 'skip'
131                 ,_("To Pick") => array('type' => 'qty', 'ord' => '', 'dec' => 0)
132                 ,_("Priority") => array('type' => 'time', 'ord' => '')
133                 ,_("Hold Until") => array('fun' => 'input_hold_until_date_details', 'ord' => '')
134                 ,_("Require By") => array('fun' => 'input_required_date_details', 'ord' => '')
135                 ,_("Expiry Date") => array('fun' => 'input_expiry_date_details', 'ord' => '')
136                 ,_("Comment") => array('fun' => 'input_comment_details', 'ord' => '')
137                 ,_("Reference") => array( 'ord' => '')
138                 ,'<input id="checkAll" type="checkbox">' => array('fun' => 'input_check_details')
139         );
140 }
141 else {
142         // Display all customers
143         $sql = get_order_summary('DEF');
144         $cols = array(
145         'customer id' => 'skip',
146         'branch code ' => 'skip',
147 _("Customer") => array('ord' => '', 'fun' => 'customer_link'),
148 _("Branch") => array('ord' => ''),
149 _("Delivery Date") => array('ord' => '', 'type' => 'date'),
150 _("Quantity") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
151 _("Amount") => array('ord' => '', 'type' => 'amount'),
152 _("Avail. Q") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
153 _("Avail. A") => array('ord' => '', 'type' => 'amount', 'dec' => 0),
154 _("Held. Q") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
155 _("required date") => array('ord' => '', 'type' => 'date'),
156 _("Comments") => array('ord' => '', 'fun' => 'aggregate_comment'),
157 _("comment 2 ") =>  'skip',
158 _("Q to Pick") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
159 _("A to Pick") => array('ord' => '', 'type' => 'amount'),
160 _("Pick")=> array('insert'=>true, 'fun'=>'pick_checkbox'),
161         );
162 }
163
164
165 $table =& new_db_pager('orders_tbl', $sql, $cols);
166
167 $table->width = "80%";
168
169 display_db_pager($table);
170
171 function display_split_area() {
172 qty_cells('Before', 'start_offset', -5);
173 date_cells('Start', 'start_date', null, null, 0, 0, 1001);
174 date_cells('End', 'end_date', null, null, 0, 0, 1001);
175 qty_cells('After', 'end_offset', 2);
176 qty_cells('Max', 'max_quantity', 6);
177 submit_cells('Split', 'Split');
178
179 }
180
181 function display_bulk_area()  {
182 date_cells('Priority', 'bulk[priority_date]', null, null, 0, 0, 1001);
183 qty_cells(null, 'bulk[priority_time]', '12:00:00');
184 date_cells('Hold', 'bulk[hold_until_date]', null, null, 0, 0, 1001);
185 date_cells('Required', 'bulk[required_date]', null, null, 0, 0, 1001);
186 date_cells('Expiry', 'bulk[expiry_date]', null, null, 0, 0, 1001);
187 text_cells('Comment', 'bulk[comment]');
188 submit_cells('Bulk', 'Bulk');
189 }
190
191 function display_pick_area() {
192 submit_cells('Pick', 'Pick');
193 submit_cells('Unpick', 'Unpick');
194 }
195
196
197 if($customer_id !== null) {
198 start_table(TABLESTYLE_NOBORDER);
199 display_split_area();
200 end_table();
201 start_table(TABLESTYLE_NOBORDER);
202 display_bulk_area();
203 end_table();
204 start_table(TABLESTYLE_NOBORDER);
205 display_pick_area();
206 end_table();
207 }
208
209
210 br(1);
211 submit_center_first('Update', _("Update"), '', 'default', false);
212 submit_center_last('Cancel', _("Cancel"), '', 'cancel', false);
213
214 end_form();
215 div_end();
216 end_page();
217 ?>
218 <style>
219 span.tooltip{ display:none;}
220 span.tooltip {
221       position: absolute;
222                         right: -0px;
223                         top: 20px;
224       width: 200px;
225       color: rgb(113, 157, 171);
226       background: rgb(255, 255, 255);
227       border: 1px solid rgb(113, 157, 171);
228 }
229
230 :hover > span.tooltip, span.tooltip:hover {
231         display: inline;
232 }
233 span.before-tooltip {
234         color: #800;
235         font-style: italic;
236         position: relative;
237 }
238
239 input:disabled + a {
240         display: none;
241         
242 }
243
244 </style>
245 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
246 <script text="text/javascript">
247
248 var inserts = {
249         '#checkAll': function (e) {
250                 e.onchange = function()  {
251                         $('.check_detail').prop('checked', e.checked)
252                         $('.check_detail').trigger('change');
253                 }
254         }
255         ,'tr': function(e) {
256                         // find if there is a check detail box on link all input to it
257                         var tr = $(e);
258                         var check = tr.find('.check_detail');
259                         if(check.length != 1) return;
260                         check = check[0];
261                         var jcheck = $(check);
262                         var inputs = tr.find('input');
263                         inputs.each(function(index, input) {
264                                 if(input === check) return;
265                                 $(input).prop('disabled', true)
266                         })
267
268                         check.onchange = function() {
269                                 inputs.each(function(index, input) {
270                                         var on = jcheck.prop('checked')
271                                         if(input == check) return;
272                                         $(input).prop('disabled', !on);
273                                 })
274                         };
275                 }
276         }
277 Behaviour.register(inserts);
278 </script>