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 = "../..";
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");
19 $page_security = 'SA_SALESTRANSVIEW';
21 set_page_security( @$_POST['order_view_mode'],
22 array( 'OutstandingOnly' => 'SA_SALESDELIVERY',
23 'InvoiceTemplates' => 'SA_SALESINVOICE'),
24 array( 'OutstandingOnly' => 'SA_SALESDELIVERY',
25 'InvoiceTemplates' => 'SA_SALESINVOICE')
27 if (!@$_GET['popup'])
\r
30 if ($use_popup_windows)
31 $js .= get_js_open_window(900, 600);
33 $js .= get_js_date_picker();
34 page($_SESSION['page_title'], false, false, "", $js);
\r
37 $trans_type = $_POST['type'];
38 elseif (isset($_GET['type']) && $_GET['type'] == ST_SALESQUOTE)
39 $trans_type = ST_SALESQUOTE;
41 $trans_type = ST_SALESORDER;
43 if ($trans_type == ST_SALESORDER)
45 if (isset($_GET['OutstandingOnly']) && ($_GET['OutstandingOnly'] == true))
47 $_POST['order_view_mode'] = 'OutstandingOnly';
48 $_SESSION['page_title'] = _($help_context = "Search Outstanding Sales Orders");
50 elseif (isset($_GET['InvoiceTemplates']) && ($_GET['InvoiceTemplates'] == true))
52 $_POST['order_view_mode'] = 'InvoiceTemplates';
53 $_SESSION['page_title'] = _($help_context = "Search Template for Invoicing");
55 elseif (isset($_GET['DeliveryTemplates']) && ($_GET['DeliveryTemplates'] == true))
57 $_POST['order_view_mode'] = 'DeliveryTemplates';
58 $_SESSION['page_title'] = _($help_context = "Select Template for Delivery");
60 elseif (!isset($_POST['order_view_mode']))
62 $_POST['order_view_mode'] = false;
63 $_SESSION['page_title'] = _($help_context = "Search All Sales Orders");
68 $_POST['order_view_mode'] = "Quotations";
69 $_SESSION['page_title'] = _($help_context = "Search All Sales Quotations");
72 if (isset($_GET['selected_customer']))
74 $selected_customer = $_GET['selected_customer'];
76 elseif (isset($_POST['selected_customer']))
78 $selected_customer = $_POST['selected_customer'];
81 $selected_customer = -1;
83 //---------------------------------------------------------------------------------------------
85 if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
86 ($_POST['SelectStockFromList'] != ALL_TEXT))
88 $selected_stock_item = $_POST['SelectStockFromList'];
92 unset($selected_stock_item);
94 //---------------------------------------------------------------------------------------------
95 // Query format functions
97 function check_overdue($row)
100 if ($trans_type == ST_SALESQUOTE)
101 return (date1_greater_date2(Today(), sql2date($row['delivery_date'])));
103 return ($row['type'] == 0
104 && date1_greater_date2(Today(), sql2date($row['ord_date']))
105 && ($row['TotDelivered'] < $row['TotQuantity']));
108 function view_link($dummy, $order_no)
111 return get_customer_trans_view_str($trans_type, $order_no);
114 function prt_link($row)
117 return print_document_link($row['order_no'], _("Print"), true, $trans_type, ICON_PRINT);
120 function edit_link($row)
122 if (@$_GET['popup'])
\r
125 $modify = ($trans_type == ST_SALESORDER ? "ModifyOrderNumber" : "ModifyQuotationNumber");
126 return pager_link( _("Edit"),
127 "/sales/sales_order_entry.php?$modify=" . $row['order_no'], ICON_EDIT);
130 function dispatch_link($row)
133 if ($trans_type == ST_SALESORDER)
134 return pager_link( _("Dispatch"),
135 "/sales/customer_delivery.php?OrderNumber=" .$row['order_no'], ICON_DOC);
137 return pager_link( _("Sales Order"),
138 "/sales/sales_order_entry.php?OrderNumber=" .$row['order_no'], ICON_DOC);
141 function invoice_link($row)
144 if ($trans_type == ST_SALESORDER)
145 return pager_link( _("Invoice"),
146 "/sales/sales_order_entry.php?NewInvoice=" .$row["order_no"], ICON_DOC);
151 function delivery_link($row)
153 return pager_link( _("Delivery"),
154 "/sales/sales_order_entry.php?NewDelivery=" .$row['order_no'], ICON_DOC);
157 function order_link($row)
159 return pager_link( _("Sales Order"),
160 "/sales/sales_order_entry.php?NewQuoteToSalesOrder=" .$row['order_no'], ICON_DOC);
163 function tmpl_checkbox($row)
166 if ($trans_type == ST_SALESQUOTE)
168 if (@$_GET['popup'])
\r
170 $name = "chgtpl" .$row['order_no'];
171 $value = $row['type'] ? 1:0;
173 // save also in hidden field for testing during 'Update'
175 return checkbox(null, $name, $value, true,
176 _('Set this order as a template for direct deliveries/invoices'))
177 . hidden('last['.$row['order_no'].']', $value, false);
179 //---------------------------------------------------------------------------------------------
180 // Update db record if respective checkbox value has changed.
182 function change_tpl_flag($id)
186 $sql = "UPDATE ".TB_PREF."sales_orders SET type = !type WHERE order_no=$id";
188 db_query($sql, "Can't change sales order type");
189 $Ajax->activate('orders_tbl');
192 $id = find_submit('_chgtpl');
194 change_tpl_flag($id);
196 if (isset($_POST['Update']) && isset($_POST['last'])) {
197 foreach($_POST['last'] as $id => $value)
198 if ($value != check_value('chgtpl'.$id))
199 change_tpl_flag($id);
202 $show_dates = !in_array($_POST['order_view_mode'], array('OutstandingOnly', 'InvoiceTemplates', 'DeliveryTemplates'));
203 //---------------------------------------------------------------------------------------------
206 if (get_post('_OrderNumber_changed') || get_post('_OrderReference_changed')) // enable/disable selection controls
208 $disable = get_post('OrderNumber') !== '' || get_post('OrderReference') !== '';
211 $Ajax->addDisable(true, 'OrdersAfterDate', $disable);
212 $Ajax->addDisable(true, 'OrdersToDate', $disable);
215 $Ajax->activate('orders_tbl');
218 if (!@$_GET['popup'])
\r
221 start_table(TABLESTYLE_NOBORDER);
223 ref_cells(_("#:"), 'OrderNumber', '',null, '', true);
224 ref_cells(_("Ref"), 'OrderReference', '',null, '', true);
227 date_cells(_("from:"), 'OrdersAfterDate', '', null, -30);
228 date_cells(_("to:"), 'OrdersToDate', '', null, 1);
230 locations_list_cells(_("Location:"), 'StockLocation', null, true);
236 start_table(TABLESTYLE_NOBORDER);
239 stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true);
240 if (!@$_GET['popup'])
\r
241 customer_list_cells(_("Select a customer: "), 'customer_id', null, true);
\r
242 if ($trans_type == ST_SALESQUOTE)
243 check_cells(_("Show All:"), 'show_all');
245 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
246 hidden('order_view_mode', $_POST['order_view_mode']);
247 hidden('type', $trans_type);
252 //---------------------------------------------------------------------------------------------
253 // Orders inquiry table
255 $sql = get_sql_for_sales_orders_view($selected_customer, $trans_type, $_POST['OrderNumber'], $_POST['order_view_mode'],
256 @$selected_stock_item, @$_POST['OrdersAfterDate'], @$_POST['OrdersToDate'], @$_POST['OrderReference'], $_POST['StockLocation'], $_POST['customer_id']);
\r
258 if ($trans_type == ST_SALESORDER)
260 _("Order #") => array('fun'=>'view_link'),
265 _("Order Date") => 'date',
266 _("Required By") =>array('type'=>'date', 'ord'=>''),
268 _("Order Total") => array('type'=>'amount', 'ord'=>''),
270 _("Currency") => array('align'=>'center')
274 _("Quote #") => array('fun'=>'view_link'),
279 _("Quote Date") => 'date',
280 _("Valid until") =>array('type'=>'date', 'ord'=>''),
282 _("Quote Total") => array('type'=>'amount', 'ord'=>''),
284 _("Currency") => array('align'=>'center')
286 if ($_POST['order_view_mode'] == 'OutstandingOnly') {
\r
287 //array_substitute($cols, 3, 1, _("Cust Order Ref"));
\r
288 array_append($cols, array(
\r
289 array('insert'=>true, 'fun'=>'dispatch_link'),
\r
290 array('insert'=>true, 'fun'=>'edit_link')));
\r
292 } elseif ($_POST['order_view_mode'] == 'InvoiceTemplates') {
293 array_substitute($cols, 3, 1, _("Description"));
294 array_append($cols, array( array('insert'=>true, 'fun'=>'invoice_link')));
296 } else if ($_POST['order_view_mode'] == 'DeliveryTemplates') {
297 array_substitute($cols, 3, 1, _("Description"));
298 array_append($cols, array(
299 array('insert'=>true, 'fun'=>'delivery_link'))
302 } elseif ($trans_type == ST_SALESQUOTE) {
303 array_append($cols,array(
304 array('insert'=>true, 'fun'=>'edit_link'),
305 array('insert'=>true, 'fun'=>'order_link'),
306 array('insert'=>true, 'fun'=>'prt_link')));
307 } elseif ($trans_type == ST_SALESORDER) {
308 array_append($cols,array(
309 _("Tmpl") => array('insert'=>true, 'fun'=>'tmpl_checkbox'),
310 array('insert'=>true, 'fun'=>'edit_link'),
311 array('insert'=>true, 'fun'=>'prt_link')));
315 $table =& new_db_pager('orders_tbl', $sql, $cols);
316 $table->set_marker('check_overdue', _("Marked items are overdue."));
318 $table->width = "80%";
320 display_db_pager($table);
321 submit_center('Update', _("Update"), true, '', null);
323 if (!@$_GET['popup'])
\r