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;
35 // update in database all field
36 $date_fields = array('hold_until_date', 'required_date', 'expiry_date', 'priority');
37 foreach($_POST['detail'] as $detail_id => $values) {
39 if($comment = $values['comment']) array_push($set, " comment='$comment' ");
40 foreach($date_fields as $date_field) {
41 if(isset($values[$date_field])) {
42 $input_date = trim($values[$date_field]);
43 if($input_date == "") {
44 // Only the priority field can be set to null.
45 if($date_field == 'priority') array_push($set," $date_field = NULL");
47 $date = date2sql($input_date);
48 array_push($set," $date_field='$date' ");
54 $sql = "UPDATE ".TB_PREF."sales_order_details SET ".implode($set,', ')." WHERE id = $detail_id ";
57 display_error('Problem while updating order details. Try again');
66 display_notification('Order details updated');
70 function split_order_details() {
71 if(!isset($_POST['Split']) || $_POST['Split'] != 'Split') return;
72 $splitter = new Splitter($_POST);
75 hook_db_prewrite($cart, 'order_xtra');
76 if($splitter->splitAll()) display_warning("Items have been split.");
77 hook_db_postwrite($cart, 'order_xtra');
81 function compute_input_name($row, $field) {
83 return "detail[$row_id][$field]";
86 function view_link($dummy, $order_no)
88 return get_customer_trans_view_str(ST_SALESORDER, $order_no);
91 function item_link($dummy, $stock_id)
93 return pager_link( _($stock_id),
94 "/modules/order_line_extra/item_schedule.php?stock_id=" .$stock_id);
97 function order_link($row)
99 return pager_link( _("Sales Order"),
100 "/sales/sales_order_entry.php?NewQuoteToSalesOrder=" .$row['order_no'], ICON_DOC);
103 function customer_link($row) {
104 return customer_link2($row['debtor_ref'], $row['debtor_no']);
107 function customer_link2($name, $id) {
108 return pager_link(_($name), "/modules/order_line_extra/order_lines_view.php?customer_id=${id}");
112 function aggregate_comment($row) {
113 $comment = $row['order_comment'].";".$row['detail_comment'];
115 $comments = array_map('trim', explode(';', $comment));
116 $comments = array_filter($comments);
117 $first = array_shift($comments);
118 if(count($comments) == 0)
121 $tooltip = implode('<br> - ', $comments);
122 return "$first <span class='before-tooltip'>more<span class='tooltip'> $tooltip</span><span>";
128 function available_quantity($row, $available) {
129 $quantity = $row['quantity'];
131 if($available== 0) $class = 'limited';
132 else if($quantity > $available) $class = 'partial';
134 return "<span class='$class'>$available<span>";
137 function input_date_details($row, $field_name, $date) {
138 $row_id = $row['id'];
139 $name = compute_input_name($row, $field_name);
141 $_POST[$name] = sql2date($date);
143 start_extract_cell();
144 date_cells (null, $name, 'title', null, 0,0,1001);
145 return end_extract_cell();
149 <input type='text' value='$date' name='$name'>
153 function input_priority_date_details($row, $date) {
154 return input_date_details($row, 'priority', $date);
157 function input_hold_until_date_details($row, $date) {
158 return input_date_details($row, 'hold_until_date', $date);
161 function input_required_date_details($row, $date) {
162 return input_date_details($row, 'required_date', $date);
165 function input_expiry_date_details($row, $date) {
166 return input_date_details($row, 'expiry_date', $date);
169 function input_comment_details($row, $comment) {
170 $row_id = $row['id'];
172 <input type='text' value='$comment' name='detail[$row_id][comment]'>
176 function get_order_details_extra($customer_id, $location) {
177 $sql = "SELECT sod.id
180 , sod.quantity - qty_sent quantity
181 , GREATEST(0, LEAST(qoh.quantity - quantity_before, sod.quantity - qty_sent))
188 FROM ".TB_PREF."sales_order_details sod
189 JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
190 AND so.trans_type = sod.trans_type
191 AND so.trans_type = ".ST_SALESORDER."
192 AND so.debtor_no = $customer_id
194 JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location')
195 LEFT JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id)
196 WHERE sod.quantity > qty_sent
202 function get_order_summary($location) {
204 $sub = "SELECT debtor_no, debtor_ref, branch_ref, stk_code
206 , sum(sod.quantity - qty_sent) as quantity
207 , sum((sod.quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount
209 , group_concat(distinct comments separator ';') as order_comment
210 , group_concat(distinct comment separator ';') as detail_comment
211 , max(quantity_before) as quantity_before
212 FROM ".TB_PREF."sales_order_details sod
213 JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
214 AND so.trans_type = sod.trans_type
215 AND so.trans_type = ".ST_SALESORDER."
217 NATURAL JOIN ".TB_PREF."debtors_master
218 NATURAL JOIN ".TB_PREF."cust_branch
219 JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id)
220 WHERE sod.quantity > qty_sent AND ".ST_SALESORDER."
221 GROUP BY debtor_no, branch_code, stk_code
225 $sub = TB_PREF."order_summary_view";
227 $sql = "SELECT debtor_no, debtor_ref, branch_ref
228 , `min(delivery_date)`
229 , sum(sub.quantity) as quantity
230 , sum(sub.amount) as amount
231 , sum(greatest(least(sub.quantity, qoh.quantity - quantity_before), 0))
232 , sum(sub.amount*greatest(least(sub.quantity, qoh.quantity - quantity_before), 0)/sub.quantity)
233 , min(`min(required_date)`)
234 , group_concat(distinct order_comment separator ';') as order_comment
235 , group_concat(distinct detail_comment separator ';') as detail_comment
237 LEFT JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location')
238 GROUP BY debtor_no, debtor_ref