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 $page_security = 'SA_SALESINVOICE';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/db_pager.inc");
15 include($path_to_root . "/includes/session.inc");
17 include($path_to_root . "/sales/includes/sales_ui.inc");
18 include_once($path_to_root . "/reporting/includes/reporting.inc");
21 if ($use_popup_windows)
22 $js .= get_js_open_window(900, 600);
24 $js .= get_js_date_picker();
26 if (isset($_GET['OutstandingOnly']) && ($_GET['OutstandingOnly'] == true))
28 $_POST['OutstandingOnly'] = true;
29 page(_($help_context = "Search Not Invoiced Deliveries"), false, false, "", $js);
33 $_POST['OutstandingOnly'] = false;
34 page(_($help_context = "Search All Deliveries"), false, false, "", $js);
37 if (isset($_GET['selected_customer']))
39 $selected_customer = $_GET['selected_customer'];
41 elseif (isset($_POST['selected_customer']))
43 $selected_customer = $_POST['selected_customer'];
46 $selected_customer = -1;
48 if (isset($_POST['BatchInvoice']))
50 // checking batch integrity
52 foreach($_POST['Sel_'] as $delivery => $branch) {
53 $checkbox = 'Sel_'.$delivery;
54 if (check_value($checkbox)) {
56 $del_branch = $branch;
59 if ($del_branch != $branch) {
64 $selected[] = $delivery;
70 display_error(_('For batch invoicing you should
71 select at least one delivery. All items must be dispatched to
72 the same customer branch.'));
74 $_SESSION['DeliveryBatch'] = $selected;
75 meta_forward($path_to_root . '/sales/customer_invoice.php','BatchInvoice=Yes');
79 //-----------------------------------------------------------------------------------
80 if (get_post('_DeliveryNumber_changed'))
82 $disable = get_post('DeliveryNumber') !== '';
84 $Ajax->addDisable(true, 'DeliveryAfterDate', $disable);
85 $Ajax->addDisable(true, 'DeliveryToDate', $disable);
86 $Ajax->addDisable(true, 'StockLocation', $disable);
87 $Ajax->addDisable(true, '_SelectStockFromList_edit', $disable);
88 $Ajax->addDisable(true, 'SelectStockFromList', $disable);
89 // if search is not empty rewrite table
91 $Ajax->addFocus(true, 'DeliveryNumber');
93 $Ajax->addFocus(true, 'DeliveryAfterDate');
94 $Ajax->activate('deliveries_tbl');
97 //-----------------------------------------------------------------------------------
99 start_form(false, false, $_SERVER['PHP_SELF'] ."?OutstandingOnly=".$_POST['OutstandingOnly']);
101 start_table(TABLESTYLE_NOBORDER);
103 ref_cells(_("#:"), 'DeliveryNumber', '',null, '', true);
104 date_cells(_("from:"), 'DeliveryAfterDate', '', null, -30);
105 date_cells(_("to:"), 'DeliveryToDate', '', null, 1);
107 locations_list_cells(_("Location:"), 'StockLocation', null, true);
111 start_table(TABLESTYLE_NOBORDER);
114 stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true);
116 customer_list_cells(_("Select a customer: "), 'customer_id', null, true, true);
118 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
120 hidden('OutstandingOnly', $_POST['OutstandingOnly']);
125 //---------------------------------------------------------------------------------------------
127 if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
128 ($_POST['SelectStockFromList'] != ALL_TEXT))
130 $selected_stock_item = $_POST['SelectStockFromList'];
134 $selected_stock_item = null;
137 //---------------------------------------------------------------------------------------------
138 function trans_view($trans, $trans_no)
140 return get_customer_trans_view_str(ST_CUSTDELIVERY, $trans['trans_no']);
143 function batch_checkbox($row)
145 $name = "Sel_" .$row['trans_no'];
146 return $row['Done'] ? '' :
147 "<input type='checkbox' name='$name' value='1' >"
148 // add also trans_no => branch code for checking after 'Batch' submit
149 ."<input name='Sel_[".$row['trans_no']."]' type='hidden' value='"
150 .$row['branch_code']."'>\n";
153 function edit_link($row)
155 return $row["Outstanding"]==0 ? '' :
156 pager_link(_('Edit'), "/sales/customer_delivery.php?ModifyDelivery="
157 .$row['trans_no'], ICON_EDIT);
160 function prt_link($row)
162 return print_document_link($row['trans_no'], _("Print"), true, ST_CUSTDELIVERY, ICON_PRINT);
165 function invoice_link($row)
167 return $row["Outstanding"]==0 ? '' :
168 pager_link(_('Invoice'), "/sales/customer_invoice.php?DeliveryNumber="
169 .$row['trans_no'], ICON_DOC);
172 function check_overdue($row)
174 return date1_greater_date2(Today(), sql2date($row["due_date"])) &&
175 $row["Outstanding"]!=0;
177 //------------------------------------------------------------------------------------------------
178 $sql = get_sql_for_sales_deliveries_view($selected_customer, $selected_stock_item, $_POST['customer_id']);
181 _("Delivery #") => array('fun'=>'trans_view'),
183 'branch_code' => 'skip',
184 _("Branch") => array('ord'=>''),
188 _("Delivery Date") => array('type'=>'date', 'ord'=>''),
189 _("Due By") => 'date',
190 _("Delivery Total") => array('type'=>'amount', 'ord'=>''),
191 _("Currency") => array('align'=>'center'),
192 submit('BatchInvoice',_("Batch"), false, _("Batch Invoicing"))
193 => array('insert'=>true, 'fun'=>'batch_checkbox', 'align'=>'center'),
194 array('insert'=>true, 'fun'=>'edit_link'),
195 array('insert'=>true, 'fun'=>'invoice_link'),
196 array('insert'=>true, 'fun'=>'prt_link')
199 //-----------------------------------------------------------------------------------
200 if (isset($_SESSION['Batch']))
202 foreach($_SESSION['Batch'] as $trans=>$del)
203 unset($_SESSION['Batch'][$trans]);
204 unset($_SESSION['Batch']);
207 $table =& new_db_pager('deliveries_tbl', $sql, $cols);
208 $table->set_marker('check_overdue', _("Marked items are overdue."));
210 //$table->width = "92%";
212 display_db_pager($table);