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 $date_fields = array('hold_until_date', 'required_date', 'expiry_date', 'priority');
38 foreach($_POST['detail'] as $detail_id => $values) {
40 if($comment = $values['comment']) array_push($set, " comment='$comment' ");
41 foreach($date_fields as $date_field) {
42 if(isset($values[$date_field])) {
43 $input_date = trim($values[$date_field]);
44 if($input_date == "") {
45 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 compute_input_name($row, $field) {
72 return "detail[$row_id][$field]";
75 function view_link($dummy, $order_no)
77 return get_customer_trans_view_str(ST_SALESORDER, $order_no);
80 function item_link($dummy, $stock_id)
82 return pager_link( _($stock_id),
83 "/modules/order_line_extra/item_schedule.php?stock_id=" .$stock_id);
86 function order_link($row)
88 return pager_link( _("Sales Order"),
89 "/sales/sales_order_entry.php?NewQuoteToSalesOrder=" .$row['order_no'], ICON_DOC);
92 function customer_link($row) {
93 return customer_link2($row['debtor_ref'], $row['debtor_no']);
96 function customer_link2($name, $id) {
97 return pager_link(_($name), "/modules/order_line_extra/order_lines_view.php?customer_id=${id}");
101 function aggregate_comment($row) {
102 $comment = $row['order_comment'].";".$row['detail_comment'];
104 $comments = array_map('trim', explode(';', $comment));
105 $comments = array_filter($comments);
106 $first = array_shift($comments);
107 if(count($comments) == 0)
110 $tooltip = implode('<br> - ', $comments);
111 return "$first <span class='before-tooltip'>more<span class='tooltip'> $tooltip</span><span>";
117 function available_quantity($row, $available) {
118 $quantity = $row['quantity'];
120 if($available== 0) $class = 'limited';
121 else if($quantity > $available) $class = 'partial';
123 return "<span class='$class'>$available<span>";
126 function input_date_details($row, $field_name, $date) {
127 $row_id = $row['id'];
128 $name = compute_input_name($row, $field_name);
130 $_POST[$name] = sql2date($date);
132 start_extract_cell();
133 date_cells (null, $name, 'title', null, 0,0,1001);
134 return end_extract_cell();
138 <input type='text' value='$date' name='$name'>
142 function input_priority_date_details($row, $date) {
143 return input_date_details($row, 'priority', $date);
146 function input_hold_until_date_details($row, $date) {
147 return input_date_details($row, 'hold_until_date', $date);
150 function input_required_date_details($row, $date) {
151 return input_date_details($row, 'required_date', $date);
154 function input_expiry_date_details($row, $date) {
155 return input_date_details($row, 'expiry_date', $date);
158 function input_comment_details($row, $comment) {
159 $row_id = $row['id'];
161 <input type='text' value='$comment' name='detail[$row_id][comment]'>
165 function get_order_details_extra($customer_id, $location) {
166 $sql = "SELECT sod.id
169 , sod.quantity - qty_sent quantity
170 , GREATEST(0, LEAST(qoh.quantity - quantity_before, sod.quantity - qty_sent))
177 FROM ".TB_PREF."sales_order_details sod
178 JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
179 AND so.trans_type = sod.trans_type
180 AND so.trans_type = ".ST_SALESORDER."
181 AND so.debtor_no = $customer_id
183 JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location')
184 LEFT JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id)
185 WHERE sod.quantity > qty_sent
191 function get_order_summary($location) {
193 $sub = "SELECT debtor_no, debtor_ref, branch_ref, stk_code
195 , sum(sod.quantity - qty_sent) as quantity
196 , sum((sod.quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount
198 , group_concat(distinct comments separator ';') as order_comment
199 , group_concat(distinct comment separator ';') as detail_comment
200 , max(quantity_before) as quantity_before
201 FROM ".TB_PREF."sales_order_details sod
202 JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
203 AND so.trans_type = sod.trans_type
204 AND so.trans_type = ".ST_SALESORDER."
206 NATURAL JOIN ".TB_PREF."debtors_master
207 NATURAL JOIN ".TB_PREF."cust_branch
208 JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id)
209 WHERE sod.quantity > qty_sent AND ".ST_SALESORDER."
210 GROUP BY debtor_no, branch_code, stk_code
214 $sub = TB_PREF."order_summary_view";
216 $sql = "SELECT debtor_no, debtor_ref, branch_ref
217 , `min(delivery_date)`
218 , sum(sub.quantity) as quantity
219 , sum(sub.amount) as amount
220 , sum(greatest(least(sub.quantity, qoh.quantity - quantity_before), 0))
221 , sum(sub.amount*greatest(least(sub.quantity, qoh.quantity - quantity_before), 0)/sub.quantity)
222 , min(`min(required_date)`)
223 , group_concat(distinct order_comment separator ';') as order_comment
224 , group_concat(distinct detail_comment separator ';') as detail_comment
226 LEFT JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location')
227 GROUP BY debtor_no, debtor_ref