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)) {
32 function update_extra_order_details() {
33 if(!isset($_POST['Update']) || $_POST['Update'] != 'Update') return;
36 // update in database all field
37 foreach($_POST['detail'] as $detail_id => $values) {
39 if($comment = $values['comment']) array_push($set, " comment='$comment' ");
40 if(isset($values['required_date'])) {
41 $required_date = trim($values['required_date']);
42 if($required_date == "") {
43 array_push($set," required_date = NULL");
45 $date = date2sql($required_date);
46 array_push($set," required_date='$date' ");
51 $sql = "UPDATE ".TB_PREF."sales_order_details SET ".implode($set,', ')." WHERE id = $detail_id ";
54 display_error('Problem while updating order details. Try again');
62 display_notification('Order details updated');
66 function compute_input_name($row, $field) {
68 return "detail[$row_id][$field]";
71 function view_link($dummy, $order_no)
73 return get_customer_trans_view_str(ST_SALESORDER, $order_no);
76 function item_link($dummy, $stock_id)
78 return pager_link( _($stock_id),
79 "/modules/order_line_extra/item_schedule.php?stock_id=" .$stock_id);
82 function order_link($row)
84 return pager_link( _("Sales Order"),
85 "/sales/sales_order_entry.php?NewQuoteToSalesOrder=" .$row['order_no'], ICON_DOC);
88 function customer_link($row) {
89 return customer_link2($row['debtor_ref'], $row['debtor_no']);
92 function customer_link2($name, $id) {
93 return pager_link(_($name), "/modules/order_line_extra/order_lines_view.php?customer_id=${id}");
97 function aggregate_comment($row) {
98 $comment = $row['order_comment'].";".$row['detail_comment'];
100 $comments = array_map('trim', explode(';', $comment));
101 $comments = array_filter($comments);
102 $first = array_shift($comments);
103 if(count($comments) == 0)
106 $tooltip = implode('<br> - ', $comments);
107 return "$first <span class='before-tooltip'>more<span class='tooltip'> $tooltip</span><span>";
113 function available_quantity($row, $available) {
114 $quantity = $row['quantity'];
116 if($available== 0) $class = 'limited';
117 else if($quantity > $available) $class = 'partial';
119 return "<span class='$class'>$available<span>";
122 function input_date_details($row, $date) {
123 $row_id = $row['id'];
124 $name = compute_input_name($row, 'required_date');
126 $_POST[$name] = sql2date($date);
128 start_extract_cell();
129 date_cells (null, $name, 'title', null, 0,0,1001);
130 return end_extract_cell();
134 <input type='text' value='$date' name='$name'>
138 function input_comment_details($row, $comment) {
139 $row_id = $row['id'];
141 <input type='text' value='$comment' name='detail[$row_id][comment]'>
145 function get_order_details_extra($customer_id, $location) {
146 $sql = "SELECT sod.id
149 , sod.quantity - qty_sent quantity
150 , GREATEST(0, LEAST(qoh.quantity - quantity_before, sod.quantity - qty_sent))
154 FROM ".TB_PREF."sales_order_details sod
155 JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
156 AND so.trans_type = sod.trans_type
157 AND so.trans_type = ".ST_SALESORDER."
158 AND so.debtor_no = $customer_id
160 JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location')
161 LEFT JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id)
162 WHERE sod.quantity > qty_sent
168 function get_order_summary($location) {
170 $sub = "SELECT debtor_no, debtor_ref, branch_ref, stk_code
172 , sum(sod.quantity - qty_sent) as quantity
173 , sum((sod.quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount
175 , group_concat(distinct comments separator ';') as order_comment
176 , group_concat(distinct comment separator ';') as detail_comment
177 , max(quantity_before) as quantity_before
178 FROM ".TB_PREF."sales_order_details sod
179 JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
180 AND so.trans_type = sod.trans_type
181 AND so.trans_type = ".ST_SALESORDER."
183 NATURAL JOIN ".TB_PREF."debtors_master
184 NATURAL JOIN ".TB_PREF."cust_branch
185 JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id)
186 WHERE sod.quantity > qty_sent AND ".ST_SALESORDER."
187 GROUP BY debtor_no, branch_code, stk_code
191 $sub = TB_PREF."order_summary_view";
193 $sql = "SELECT debtor_no, debtor_ref, branch_ref
194 , `min(delivery_date)`
195 , sum(sub.quantity) as quantity
196 , sum(sub.amount) as amount
197 , sum(greatest(least(sub.quantity, qoh.quantity - quantity_before), 0))
198 , sum(sub.amount*greatest(least(sub.quantity, qoh.quantity - quantity_before), 0)/sub.quantity)
199 , min(`min(required_date)`)
200 , group_concat(distinct order_comment separator ';') as order_comment
201 , group_concat(distinct detail_comment separator ';') as detail_comment
203 LEFT JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location')
204 GROUP BY debtor_no, debtor_ref