2 include_once($path_to_root."/includes/ui/ui_input.inc");
3 /* This utility function remove beginning <td> and </td> from a string
4 * generated by the above *_cell function.
5 * This is usefull to use the result of the function within a pager
6 * which already include the <td>...</td>
7 * However, for function which doesn't return a string
8 * but echo, we need to capture the output of the echo first.
10 function start_extract_cell() {
15 function end_extract_cell() {
16 $content = ob_get_contents();
18 return extract_cell($content);
21 function extract_cell($td) {
22 if(preg_match('/\s*<td>(.*)<\/td>\s*/s', $td, $matches)) {
31 function update_extra_order_details() {
32 if(!isset($_POST['Update']) || $_POST['Update'] != 'Update') return;
36 hook_db_prewrite($cart, 'order_xtra');
37 // update in database all field
38 $date_fields = array('hold_until_date', 'required_date', 'expiry_date', 'priority');
39 foreach($_POST['detail'] as $detail_id => $values) {
41 if($comment = $values['comment']) array_push($set, " comment='$comment' ");
42 foreach($date_fields as $date_field) {
43 if(isset($values[$date_field])) {
44 $input_date = trim($values[$date_field]);
45 if($input_date == "") {
46 // Only the priority field can be set to null.
47 if($date_field == 'priority') array_push($set," $date_field = NULL");
49 $date = date2sql($input_date);
50 array_push($set," $date_field='$date' ");
56 $sql = "UPDATE ".TB_PREF."sales_order_details SET ".implode($set,', ')." WHERE id = $detail_id ";
59 display_error('Problem while updating order details. Try again');
64 hook_db_postwrite($cart, 'order_xtra');
69 display_notification('Order details updated');
73 function split_order_details() {
74 if(!isset($_POST['Split']) || $_POST['Split'] != 'Split') return;
75 $splitter = new Splitter($_POST);
78 hook_db_prewrite($cart, 'order_xtra');
79 if($splitter->splitAll()) display_warning("Items have been split.");
80 hook_db_postwrite($cart, 'order_xtra');
84 function compute_input_name($row, $field) {
86 return "detail[$row_id][$field]";
89 function view_link($dummy, $order_no)
91 return get_customer_trans_view_str(ST_SALESORDER, $order_no);
94 function item_link($dummy, $stock_id)
96 return pager_link( _($stock_id),
97 "/modules/order_line_extra/item_schedule.php?stock_id=" .$stock_id);
100 function order_link($row)
102 return pager_link( _("Sales Order"),
103 "/sales/sales_order_entry.php?NewQuoteToSalesOrder=" .$row['order_no'], ICON_DOC);
106 function customer_link($row) {
107 return customer_link2($row['debtor_ref'], $row['debtor_no']);
110 function customer_link2($name, $id) {
111 return pager_link(_($name), "/modules/order_line_extra/order_lines_view.php?customer_id=${id}");
115 function aggregate_comment($row) {
116 $comment = $row['order_comment'].";".$row['detail_comment'];
118 $comments = array_map('trim', explode(';', $comment));
119 $comments = array_filter($comments);
120 $first = array_shift($comments);
121 if(count($comments) == 0)
124 $tooltip = implode('<br> - ', $comments);
125 return "$first <span class='before-tooltip'>more<span class='tooltip'> $tooltip</span><span>";
131 function available_quantity($row, $available) {
132 $quantity = $row['quantity'];
134 if($available== 0) $class = 'limited';
135 else if($quantity > $available) $class = 'partial';
137 return "<span class='$class'>$available<span>";
140 function input_date_details($row, $field_name, $date) {
141 $row_id = $row['id'];
142 $name = compute_input_name($row, $field_name);
144 $_POST[$name] = sql2date($date);
146 start_extract_cell();
147 date_cells (null, $name, 'title', null, 0,0,1001);
148 return end_extract_cell();
152 <input type='text' value='$date' name='$name'>
156 function input_priority_date_details($row, $date) {
157 return input_date_details($row, 'priority', $date);
160 function input_hold_until_date_details($row, $date) {
161 return input_date_details($row, 'hold_until_date', $date);
164 function input_required_date_details($row, $date) {
165 return input_date_details($row, 'required_date', $date);
168 function input_expiry_date_details($row, $date) {
169 return input_date_details($row, 'expiry_date', $date);
172 function input_comment_details($row, $comment) {
173 $row_id = $row['id'];
175 <input type='text' value='$comment' name='detail[$row_id][comment]'>
179 function get_order_details_extra($customer_id, $location) {
180 $sql = "SELECT sod.id
183 , sod.quantity - qty_sent quantity
184 , GREATEST(0, LEAST(qoh.quantity - quantity_before, sod.quantity - qty_sent))
191 FROM ".TB_PREF."sales_order_details sod
192 JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
193 AND so.trans_type = sod.trans_type
194 AND so.trans_type = ".ST_SALESORDER."
195 AND so.debtor_no = $customer_id
197 JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location')
198 LEFT JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id)
199 WHERE sod.quantity > qty_sent
205 function get_order_summary($location) {
207 $sub = "SELECT debtor_no, debtor_ref, branch_ref, stk_code
209 , sum(sod.quantity - qty_sent) as quantity
210 , sum((sod.quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount
212 , group_concat(distinct comments separator ';') as order_comment
213 , group_concat(distinct comment separator ';') as detail_comment
214 , max(quantity_before) as quantity_before
215 FROM ".TB_PREF."sales_order_details sod
216 JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
217 AND so.trans_type = sod.trans_type
218 AND so.trans_type = ".ST_SALESORDER."
220 NATURAL JOIN ".TB_PREF."debtors_master
221 NATURAL JOIN ".TB_PREF."cust_branch
222 JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id)
223 WHERE sod.quantity > qty_sent AND ".ST_SALESORDER."
224 GROUP BY debtor_no, branch_code, stk_code
228 $sub = TB_PREF."order_summary_view";
230 $sql = "SELECT debtor_no, debtor_ref, branch_ref
231 , `min(delivery_date)`
232 , sum(sub.quantity) as quantity
233 , sum(sub.amount) as amount
234 , sum(greatest(least(sub.quantity, qoh.quantity - quantity_before), 0))
235 , sum(sub.amount*greatest(least(sub.quantity, qoh.quantity - quantity_before), 0)/sub.quantity)
236 , min(`min(required_date)`)
237 , group_concat(distinct order_comment separator ';') as order_comment
238 , group_concat(distinct detail_comment separator ';') as detail_comment
240 LEFT JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location')
241 GROUP BY debtor_no, debtor_ref