5 include($path_to_root . "/includes/db_pager.inc");
6 include($path_to_root . "/includes/session.inc");
8 include($path_to_root . "/sales/includes/sales_ui.inc");
9 include_once($path_to_root . "/reporting/includes/reporting.inc");
12 if ($use_popup_windows)
13 $js .= get_js_open_window(900, 600);
15 $js .= get_js_date_picker();
17 if (isset($_GET['OutstandingOnly']) && ($_GET['OutstandingOnly'] == true))
19 $_POST['OutstandingOnly'] = true;
20 page(_("Search Not Invoiced Deliveries"), false, false, "", $js);
24 $_POST['OutstandingOnly'] = false;
25 page(_("Search All Deliveries"), false, false, "", $js);
28 if (isset($_GET['selected_customer']))
30 $selected_customer = $_GET['selected_customer'];
32 elseif (isset($_POST['selected_customer']))
34 $selected_customer = $_POST['selected_customer'];
37 $selected_customer = -1;
39 if (isset($_POST['BatchInvoice']))
41 // checking batch integrity
43 foreach($_POST['Sel_'] as $delivery => $branch) {
44 $checkbox = 'Sel_'.$delivery;
45 if (check_value($checkbox)) {
47 $del_branch = $branch;
50 if ($del_branch != $branch) {
55 $selected[] = $delivery;
61 display_error(_('For batch invoicing you should
62 select at least one delivery. All items must be dispatched to
63 the same customer branch.'));
65 $_SESSION['DeliveryBatch'] = $selected;
66 meta_forward($path_to_root . '/sales/customer_invoice.php','BatchInvoice=Yes');
70 //-----------------------------------------------------------------------------------
71 if (get_post('_DeliveryNumber_changed'))
73 $disable = get_post('DeliveryNumber') !== '';
75 $Ajax->addDisable(true, 'DeliveryAfterDate', $disable);
76 $Ajax->addDisable(true, 'DeliveryToDate', $disable);
77 $Ajax->addDisable(true, 'StockLocation', $disable);
78 $Ajax->addDisable(true, '_SelectStockFromList_edit', $disable);
79 $Ajax->addDisable(true, 'SelectStockFromList', $disable);
80 // if search is not empty rewrite table
82 $Ajax->addFocus(true, 'DeliveryNumber');
84 $Ajax->addFocus(true, 'DeliveryAfterDate');
85 $Ajax->activate('deliveries_tbl');
88 //-----------------------------------------------------------------------------------
90 start_form(false, false, $_SERVER['PHP_SELF'] ."?OutstandingOnly=" . $_POST['OutstandingOnly'] .SID);
92 start_table("class='tablestyle_noborder'");
94 ref_cells(_("#:"), 'DeliveryNumber', '',null, '', true);
95 date_cells(_("from:"), 'DeliveryAfterDate', '', null, -30);
96 date_cells(_("to:"), 'DeliveryToDate', '', null, 1);
98 locations_list_cells(_("Location:"), 'StockLocation', null, true);
100 stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true);
102 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), true);
104 hidden('OutstandingOnly', $_POST['OutstandingOnly']);
110 //---------------------------------------------------------------------------------------------
112 if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
113 ($_POST['SelectStockFromList'] != reserved_words::get_all()))
115 $selected_stock_item = $_POST['SelectStockFromList'];
119 unset($selected_stock_item);
122 //---------------------------------------------------------------------------------------------
123 function trans_view($trans, $trans_no)
125 return get_customer_trans_view_str(13, $trans['trans_no']);
128 function batch_checkbox($row)
130 $name = "Sel_" .$row['trans_no'];
131 return $row['Done'] ? '' :
132 "<center><input type='checkbox' name='$name' value='1' ></center>"
133 // add also trans_no => branch code for checking after 'Batch' submit
134 ."<input name='Sel_[".$row['trans_no']."]' type='hidden' value='"
135 .$row['branch_code']."'>\n";
138 function edit_link($row)
140 return $row["Outstanding"]==0 ? '' :
141 pager_link(_('Edit'), "/sales/customer_delivery.php?ModifyDelivery="
145 function prt_link($row)
147 return print_document_link($row['trans_no'], _("Print"), true, 13);
150 function invoice_link($row)
152 return $row["Outstanding"]==0 ? '' :
153 pager_link(_('Invoice'), "/sales/customer_invoice.php?DeliveryNumber="
157 function check_overdue($row)
159 return date1_greater_date2(Today(), sql2date($row["due_date"])) &&
160 $row["Outstanding"]!=0;
162 //------------------------------------------------------------------------------------------------
163 $sql = "SELECT trans.trans_no,
172 (ov_amount+ov_gst+ov_freight+ov_freight_tax) AS DeliveryValue,
174 Sum(line.quantity-line.qty_done) AS Outstanding,
175 Sum(line.qty_done) AS Done
177 .TB_PREF."sales_orders as sorder, "
178 .TB_PREF."debtor_trans as trans, "
179 .TB_PREF."debtor_trans_details as line, "
180 .TB_PREF."debtors_master as debtor, "
181 .TB_PREF."cust_branch as branch
183 sorder.order_no = trans.order_ AND
184 trans.debtor_no = debtor.debtor_no
186 AND line.debtor_trans_no = trans.trans_no
187 AND line.debtor_trans_type = trans.type
188 AND trans.branch_code = branch.branch_code
189 AND trans.debtor_no = branch.debtor_no ";
191 if ($_POST['OutstandingOnly'] == true) {
192 $sql .= " AND line.qty_done < line.quantity ";
195 //figure out the sql required from the inputs available
196 if (isset($_POST['DeliveryNumber']) && $_POST['DeliveryNumber'] != "")
198 $sql .= " AND trans.trans_no LIKE '%". $_POST['DeliveryNumber'] ."'";
199 $sql .= " GROUP BY trans.trans_no";
203 $sql .= " AND trans.tran_date >= '".date2sql($_POST['DeliveryAfterDate'])."'";
204 $sql .= " AND trans.tran_date <= '".date2sql($_POST['DeliveryToDate'])."'";
206 if ($selected_customer != -1)
207 $sql .= " AND trans.debtor_no='" . $selected_customer . "' ";
209 if (isset($selected_stock_item))
210 $sql .= " AND line.stock_id='". $selected_stock_item ."' ";
212 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != reserved_words::get_all())
213 $sql .= " AND sorder.from_stk_loc = '". $_POST['StockLocation'] . "' ";
215 $sql .= " GROUP BY trans.trans_no ";
217 } //end no delivery number selected
220 _("Delivery #") => array('type'=>'spec', 'fun'=>'trans_view'),
222 'branch_code' => 'skip',
223 _("Branch") => array('ord'=>''),
227 _("Delivery Date") => array('type'=>'date', 'ord'=>''),
228 _("Due By") => 'date',
229 _("Delivery Total") => array('type'=>'amount', 'ord'=>''),
231 submit('BatchInvoice','Batch Inv', false)
232 => array('type'=>'insert', 'fun'=>'batch_checkbox'),
233 array('type'=>'insert', 'fun'=>'edit_link'),
234 array('type'=>'insert', 'fun'=>'invoice_link'),
235 array('type'=>'insert', 'fun'=>'prt_link')
238 //-----------------------------------------------------------------------------------
239 if (isset($_SESSION['Batch']))
241 foreach($_SESSION['Batch'] as $trans=>$del)
242 unset($_SESSION['Batch'][$trans]);
243 unset($_SESSION['Batch']);
248 $_SESSION['Batch'][] = array('trans'=>$myrow["trans_no"],
249 'cust'=>$myrow["name"],'branch'=>$myrow["br_name"] );
252 $table =& new_db_pager('deliveries_tbl', $sql, $cols);
253 $table->set_marker('check_overdue', _("Marked items are overdue."));
256 if(get_post('SearchOrders'))
258 $table->set_sql($sql);
259 $Ajax->activate('doc_tbl');
263 display_db_pager($table);