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')
29 $trans_type = $_POST['type'];
30 elseif (isset($_GET['type']) && $_GET['type'] == ST_SALESQUOTE)
31 $trans_type = ST_SALESQUOTE;
33 $trans_type = ST_SALESORDER;
35 if ($trans_type == ST_SALESORDER)
37 if (isset($_GET['OutstandingOnly']) && ($_GET['OutstandingOnly'] == true))
39 $_POST['order_view_mode'] = 'OutstandingOnly';
40 $_SESSION['page_title'] = _($help_context = "Search Outstanding Sales Orders");
42 elseif (isset($_GET['InvoiceTemplates']) && ($_GET['InvoiceTemplates'] == true))
44 $_POST['order_view_mode'] = 'InvoiceTemplates';
45 $_SESSION['page_title'] = _($help_context = "Search Template for Invoicing");
47 elseif (isset($_GET['DeliveryTemplates']) && ($_GET['DeliveryTemplates'] == true))
49 $_POST['order_view_mode'] = 'DeliveryTemplates';
50 $_SESSION['page_title'] = _($help_context = "Select Template for Delivery");
52 elseif (!isset($_POST['order_view_mode']))
54 $_POST['order_view_mode'] = false;
55 $_SESSION['page_title'] = _($help_context = "Search All Sales Orders");
60 $_POST['order_view_mode'] = "Quotations";
61 $_SESSION['page_title'] = _($help_context = "Search All Sales Quotations");
65 if ($use_popup_windows)
66 $js .= get_js_open_window(900, 600);
68 $js .= get_js_date_picker();
69 page($_SESSION['page_title'], false, false, "", $js);
71 if (isset($_GET['selected_customer']))
73 $selected_customer = $_GET['selected_customer'];
75 elseif (isset($_POST['selected_customer']))
77 $selected_customer = $_POST['selected_customer'];
80 $selected_customer = -1;
82 //---------------------------------------------------------------------------------------------
84 if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
85 ($_POST['SelectStockFromList'] != ALL_TEXT))
87 $selected_stock_item = $_POST['SelectStockFromList'];
91 unset($selected_stock_item);
93 //---------------------------------------------------------------------------------------------
94 // Query format functions
96 function check_overdue($row)
99 if ($trans_type == ST_SALESQUOTE)
100 return (date1_greater_date2(Today(), sql2date($row['delivery_date'])));
102 return ($row['type'] == 0
103 && date1_greater_date2(Today(), sql2date($row['ord_date']))
104 && ($row['TotDelivered'] < $row['TotQuantity']));
107 function view_link($dummy, $order_no)
110 return get_customer_trans_view_str($trans_type, $order_no);
113 function prt_link($row)
116 return print_document_link($row['order_no'], _("Print"), true, $trans_type, ICON_PRINT);
119 function edit_link($row)
126 $modify = ($trans_type == ST_SALESORDER ? "ModifyOrderNumber" : "ModifyQuotationNumber");
127 return pager_link( _("Edit"),
128 "/sales/sales_order_entry.php?$modify=" . $row['order_no'], ICON_EDIT);
131 function dispatch_link($row)
134 if ($trans_type == ST_SALESORDER)
135 return pager_link( _("Dispatch"),
136 "/sales/customer_delivery.php?OrderNumber=" .$row['order_no'], ICON_DOC);
138 return pager_link( _("Sales Order"),
139 "/sales/sales_order_entry.php?OrderNumber=" .$row['order_no'], ICON_DOC);
142 function invoice_link($row)
145 if ($trans_type == ST_SALESORDER)
146 return pager_link( _("Invoice"),
147 "/sales/sales_order_entry.php?NewInvoice=" .$row["order_no"], ICON_DOC);
152 function delivery_link($row)
154 return pager_link( _("Delivery"),
155 "/sales/sales_order_entry.php?NewDelivery=" .$row['order_no'], ICON_DOC);
158 function order_link($row)
160 return pager_link( _("Sales Order"),
161 "/sales/sales_order_entry.php?NewQuoteToSalesOrder=" .$row['order_no'], ICON_DOC);
164 function tmpl_checkbox($row)
166 global $trans_type, $page_nested;
167 if ($trans_type == ST_SALESQUOTE)
172 $name = "chgtpl" .$row['order_no'];
173 $value = $row['type'] ? 1:0;
175 // save also in hidden field for testing during 'Update'
177 return checkbox(null, $name, $value, true,
178 _('Set this order as a template for direct deliveries/invoices'))
179 . hidden('last['.$row['order_no'].']', $value, false);
181 //---------------------------------------------------------------------------------------------
182 // Update db record if respective checkbox value has changed.
184 function change_tpl_flag($id)
188 $sql = "UPDATE ".TB_PREF."sales_orders SET type = !type WHERE order_no=$id";
190 db_query($sql, "Can't change sales order type");
191 $Ajax->activate('orders_tbl');
194 $id = find_submit('_chgtpl');
196 change_tpl_flag($id);
198 if (isset($_POST['Update']) && isset($_POST['last'])) {
199 foreach($_POST['last'] as $id => $value)
200 if ($value != check_value('chgtpl'.$id))
201 change_tpl_flag($id);
204 $show_dates = !in_array($_POST['order_view_mode'], array('OutstandingOnly', 'InvoiceTemplates', 'DeliveryTemplates'));
205 //---------------------------------------------------------------------------------------------
208 if (get_post('_OrderNumber_changed') || get_post('_OrderReference_changed')) // enable/disable selection controls
210 $disable = get_post('OrderNumber') !== '' || get_post('OrderReference') !== '';
213 $Ajax->addDisable(true, 'OrdersAfterDate', $disable);
214 $Ajax->addDisable(true, 'OrdersToDate', $disable);
217 $Ajax->activate('orders_tbl');
222 start_table(TABLESTYLE_NOBORDER);
224 ref_cells(_("#:"), 'OrderNumber', '',null, '', true);
225 ref_cells(_("Ref"), 'OrderReference', '',null, '', true);
228 date_cells(_("from:"), 'OrdersAfterDate', '', null, -$_SESSION["wa_current_user"]->prefs->transaction_days());
229 date_cells(_("to:"), 'OrdersToDate', '', null, 1);
231 locations_list_cells(_("Location:"), 'StockLocation', null, true);
237 start_table(TABLESTYLE_NOBORDER);
240 stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true);
241 if (!@$_GET['popup'])
242 customer_list_cells(_("Select a customer: "), 'customer_id', null, true);
243 if ($trans_type == ST_SALESQUOTE)
244 check_cells(_("Show All:"), 'show_all');
246 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
247 hidden('order_view_mode', $_POST['order_view_mode']);
248 hidden('type', $trans_type);
253 //---------------------------------------------------------------------------------------------
254 // Orders inquiry table
256 $sql = get_sql_for_sales_orders_view($selected_customer, $trans_type, $_POST['OrderNumber'], $_POST['order_view_mode'],
257 @$selected_stock_item, @$_POST['OrdersAfterDate'], @$_POST['OrdersToDate'], @$_POST['OrderReference'], $_POST['StockLocation'], $_POST['customer_id']);
259 if ($trans_type == ST_SALESORDER)
261 _("Order #") => array('fun'=>'view_link'),
266 _("Order Date") => 'date',
267 _("Required By") =>array('type'=>'date', 'ord'=>''),
269 _("Order Total") => array('type'=>'amount', 'ord'=>''),
271 _("Currency") => array('align'=>'center')
275 _("Quote #") => array('fun'=>'view_link'),
280 _("Quote Date") => 'date',
281 _("Valid until") =>array('type'=>'date', 'ord'=>''),
283 _("Quote Total") => array('type'=>'amount', 'ord'=>''),
285 _("Currency") => array('align'=>'center')
287 if ($_POST['order_view_mode'] == 'OutstandingOnly') {
288 //array_substitute($cols, 3, 1, _("Cust Order Ref"));
289 array_append($cols, array(
290 array('insert'=>true, 'fun'=>'dispatch_link'),
291 array('insert'=>true, 'fun'=>'edit_link')));
293 } elseif ($_POST['order_view_mode'] == 'InvoiceTemplates') {
294 array_substitute($cols, 3, 1, _("Description"));
295 array_append($cols, array( array('insert'=>true, 'fun'=>'invoice_link')));
297 } else if ($_POST['order_view_mode'] == 'DeliveryTemplates') {
298 array_substitute($cols, 3, 1, _("Description"));
299 array_append($cols, array(
300 array('insert'=>true, 'fun'=>'delivery_link'))
303 } elseif ($trans_type == ST_SALESQUOTE) {
304 array_append($cols,array(
305 array('insert'=>true, 'fun'=>'edit_link'),
306 array('insert'=>true, 'fun'=>'order_link'),
307 array('insert'=>true, 'fun'=>'prt_link')));
308 } elseif ($trans_type == ST_SALESORDER) {
309 array_append($cols,array(
310 _("Tmpl") => array('insert'=>true, 'fun'=>'tmpl_checkbox'),
311 array('insert'=>true, 'fun'=>'edit_link'),
312 array('insert'=>true, 'fun'=>'prt_link')));
316 $table =& new_db_pager('orders_tbl', $sql, $cols);
317 $table->set_marker('check_overdue', _("Marked items are overdue."));
319 $table->width = "80%";
321 display_db_pager($table);
322 submit_center('Update', _("Update"), true, '', null);