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 'DeliveryTemplates' => 'SA_SALESDELIVERY',
25 'PrepaidOrders' => 'SA_SALESINVOICE'),
26 array( 'OutstandingOnly' => 'SA_SALESDELIVERY',
27 'InvoiceTemplates' => 'SA_SALESINVOICE',
28 'DeliveryTemplates' => 'SA_SALESDELIVERY',
29 'PrepaidOrders' => 'SA_SALESINVOICE')
33 $trans_type = $_POST['type'];
34 elseif (isset($_GET['type']) && $_GET['type'] == ST_SALESQUOTE)
35 $trans_type = ST_SALESQUOTE;
37 $trans_type = ST_SALESORDER;
39 if ($trans_type == ST_SALESORDER)
41 if (isset($_GET['OutstandingOnly']) && ($_GET['OutstandingOnly'] == true))
43 $_POST['order_view_mode'] = 'OutstandingOnly';
44 $_SESSION['page_title'] = _($help_context = "Search Outstanding Sales Orders");
46 elseif (isset($_GET['InvoiceTemplates']) && ($_GET['InvoiceTemplates'] == true))
48 $_POST['order_view_mode'] = 'InvoiceTemplates';
49 $_SESSION['page_title'] = _($help_context = "Search Template for Invoicing");
51 elseif (isset($_GET['DeliveryTemplates']) && ($_GET['DeliveryTemplates'] == true))
53 $_POST['order_view_mode'] = 'DeliveryTemplates';
54 $_SESSION['page_title'] = _($help_context = "Select Template for Delivery");
56 elseif (isset($_GET['PrepaidOrders']) && ($_GET['PrepaidOrders'] == true))
58 $_POST['order_view_mode'] = 'PrepaidOrders';
59 $_SESSION['page_title'] = _($help_context = "Invoicing Prepayment Orders");
61 elseif (!isset($_POST['order_view_mode']))
63 $_POST['order_view_mode'] = false;
64 $_SESSION['page_title'] = _($help_context = "Search All Sales Orders");
69 $_POST['order_view_mode'] = "Quotations";
70 $_SESSION['page_title'] = _($help_context = "Search All Sales Quotations");
74 if ($SysPrefs->use_popup_windows)
75 $js .= get_js_open_window(900, 600);
76 if (user_use_date_picker())
77 $js .= get_js_date_picker();
78 page($_SESSION['page_title'], false, false, "", $js);
79 //---------------------------------------------------------------------------------------------
80 // Query format functions
82 function check_overdue($row)
85 if ($trans_type == ST_SALESQUOTE)
86 return (date1_greater_date2(Today(), sql2date($row['delivery_date'])));
88 return ($row['type'] == 0
89 && date1_greater_date2(Today(), sql2date($row['delivery_date']))
90 && ($row['TotDelivered'] < $row['TotQuantity']));
93 function view_link($dummy, $order_no)
96 return get_customer_trans_view_str($trans_type, $order_no);
99 function prt_link($row)
102 return print_document_link($row['order_no'], _("Print"), true, $trans_type, ICON_PRINT);
105 function edit_link($row)
109 if (is_prepaid_order_open($row['order_no']))
112 return $page_nested ? '' : trans_editor_link($row['trans_type'], $row['order_no']);
115 function dispatch_link($row)
119 if ($row['ord_payments'] + $row['inv_payments'] < $row['prep_amount'])
122 if ($trans_type == ST_SALESORDER)
123 return pager_link( _("Dispatch"),
124 "/sales/customer_delivery.php?OrderNumber=" .$row['order_no'], ICON_DOC);
126 return pager_link( _("Sales Order"),
127 "/sales/sales_order_entry.php?OrderNumber=" .$row['order_no'], ICON_DOC);
130 function invoice_link($row)
133 if ($trans_type == ST_SALESORDER)
134 return pager_link( _("Invoice"),
135 "/sales/sales_order_entry.php?NewInvoice=" .$row["order_no"], ICON_DOC);
140 function delivery_link($row)
142 return pager_link( _("Delivery"),
143 "/sales/sales_order_entry.php?NewDelivery=" .$row['order_no'], ICON_DOC);
146 function order_link($row)
148 return pager_link( _("Sales Order"),
149 "/sales/sales_order_entry.php?NewQuoteToSalesOrder=" .$row['order_no'], ICON_DOC);
152 function tmpl_checkbox($row)
154 global $trans_type, $page_nested;
156 if ($trans_type == ST_SALESQUOTE || !check_sales_order_type($row['order_no']))
161 $name = "chgtpl" .$row['order_no'];
162 $value = $row['type'] ? 1:0;
164 // save also in hidden field for testing during 'Update'
166 return checkbox(null, $name, $value, true,
167 _('Set this order as a template for direct deliveries/invoices'))
168 . hidden('last['.$row['order_no'].']', $value, false);
171 function invoice_prep_link($row)
173 // invoicing should be available only for partially allocated orders
175 $row['inv_payments'] < $row['total'] ?
176 pager_link($row['ord_payments'] ? _("Prepayment Invoice") : _("Final Invoice"),
177 "/sales/customer_invoice.php?InvoicePrepayments=" .$row['order_no'], ICON_DOC) : '';
180 $id = find_submit('_chgtpl');
183 sales_order_set_template($id, check_value('chgtpl'.$id));
184 $Ajax->activate('orders_tbl');
187 if (isset($_POST['Update']) && isset($_POST['last'])) {
188 foreach($_POST['last'] as $id => $value)
189 if ($value != check_value('chgtpl'.$id))
190 sales_order_set_template($id, !check_value('chgtpl'.$id));
193 $show_dates = !in_array($_POST['order_view_mode'], array('OutstandingOnly', 'InvoiceTemplates', 'DeliveryTemplates'));
194 //---------------------------------------------------------------------------------------------
197 if (get_post('_OrderNumber_changed') || get_post('_OrderReference_changed')) // enable/disable selection controls
199 $disable = get_post('OrderNumber') !== '' || get_post('OrderReference') !== '';
202 $Ajax->addDisable(true, 'OrdersAfterDate', $disable);
203 $Ajax->addDisable(true, 'OrdersToDate', $disable);
206 $Ajax->activate('orders_tbl');
211 start_table(TABLESTYLE_NOBORDER);
213 ref_cells(_("#:"), 'OrderNumber', '',null, '', true);
214 ref_cells(_("Ref"), 'OrderReference', '',null, '', true);
217 date_cells(_("from:"), 'OrdersAfterDate', '', null, -user_transaction_days());
218 date_cells(_("to:"), 'OrdersToDate', '', null, 1);
220 locations_list_cells(_("Location:"), 'StockLocation', null, true, true);
226 start_table(TABLESTYLE_NOBORDER);
229 stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true, true);
232 customer_list_cells(_("Select a customer: "), 'customer_id', null, true, true);
233 if ($trans_type == ST_SALESQUOTE)
234 check_cells(_("Show All:"), 'show_all');
236 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
237 hidden('order_view_mode', $_POST['order_view_mode']);
238 hidden('type', $trans_type);
243 //---------------------------------------------------------------------------------------------
244 // Orders inquiry table
246 $sql = get_sql_for_sales_orders_view($trans_type, get_post('OrderNumber'), get_post('order_view_mode'),
247 get_post('SelectStockFromList'), get_post('OrdersAfterDate'), get_post('OrdersToDate'), get_post('OrderReference'), get_post('StockLocation'),
248 get_post('customer_id'));
250 if ($trans_type == ST_SALESORDER)
252 _("Order #") => array('fun'=>'view_link', 'align'=>'right'),
253 _("Ref") => array('type' => 'sorder.reference', 'ord' => '') ,
254 _("Customer") => array('type' => 'debtor.name' , 'ord' => '') ,
257 _("Order Date") => array('type' => 'date', 'ord' => ''),
258 _("Required By") =>array('type'=>'date', 'ord'=>''),
260 _("Order Total") => array('type'=>'amount', 'ord'=>''),
262 _("Currency") => array('align'=>'center')
266 _("Quote #") => array('fun'=>'view_link', 'align'=>'right'),
271 _("Quote Date") => 'date',
272 _("Valid until") =>array('type'=>'date', 'ord'=>''),
274 _("Quote Total") => array('type'=>'amount', 'ord'=>''),
276 _("Currency") => array('align'=>'center')
278 if ($_POST['order_view_mode'] == 'OutstandingOnly') {
279 array_append($cols, array(
280 array('insert'=>true, 'fun'=>'dispatch_link'),
281 array('insert'=>true, 'fun'=>'edit_link')));
283 } elseif ($_POST['order_view_mode'] == 'InvoiceTemplates') {
284 array_substitute($cols, 4, 1, _("Description"));
285 array_append($cols, array( array('insert'=>true, 'fun'=>'invoice_link')));
287 } else if ($_POST['order_view_mode'] == 'DeliveryTemplates') {
288 array_substitute($cols, 4, 1, _("Description"));
289 array_append($cols, array(
290 array('insert'=>true, 'fun'=>'delivery_link'))
292 } else if ($_POST['order_view_mode'] == 'PrepaidOrders') {
293 array_append($cols, array(
294 array('insert'=>true, 'fun'=>'invoice_prep_link'))
297 } elseif ($trans_type == ST_SALESQUOTE) {
298 array_append($cols,array(
299 array('insert'=>true, 'fun'=>'edit_link'),
300 array('insert'=>true, 'fun'=>'order_link'),
301 array('insert'=>true, 'fun'=>'prt_link')));
302 } elseif ($trans_type == ST_SALESORDER) {
303 array_append($cols,array(
304 _("Tmpl") => array('insert'=>true, 'fun'=>'tmpl_checkbox'),
305 array('insert'=>true, 'fun'=>'edit_link'),
306 array('insert'=>true, 'fun'=>'prt_link')));
310 $table =& new_db_pager('orders_tbl', $sql, $cols);
311 $table->set_marker('check_overdue', _("Marked items are overdue."));
313 $table->width = "80%";
315 display_db_pager($table);
316 submit_center('Update', _("Update"), true, '', null);