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)) {
35 function update_extra_order_details() {
36 if(!isset($_POST['Update']) || $_POST['Update'] != 'Update') return;
39 // update in database all field
40 foreach($_POST['detail'] as $detail_id => $values) {
42 if($comment = $values['comment']) array_push($set, " comment='$comment' ");
43 if(isset($values['required_date'])) {
44 $required_date = trim($values['required_date']);
45 if($required_date == "") {
46 array_push($set," required_date = NULL");
48 $date = date2sql($required_date);
49 array_push($set," required_date='$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');
65 display_notification('Order details updated');
69 function compute_input_name($row, $field) {
71 return "detail[$row_id][$field]";
74 function view_link($dummy, $order_no)
76 return get_customer_trans_view_str(ST_SALESORDER, $order_no);
80 function order_link($row)
82 return pager_link( _("Sales Order"),
83 "/sales/sales_order_entry.php?NewQuoteToSalesOrder=" .$row['order_no'], ICON_DOC);
86 function customer_link($row) {
87 return pager_link(_($row['debtor_ref']), "/modules/order_line_extra/order_lines_view.php?customer_id=${row['debtor_no']}");
91 function aggregate_comment($row) {
92 $comment = $row['order_comment'].$row['detail_comment'];
94 $comments = array_map('trim', explode(';', $comment));
95 $comments = array_filter($comments);
96 $first = array_shift($comments);
97 if(count($comments) == 0)
100 $tooltip = implode('<br>', $comments);
101 return "$first <span class='before-tooltip'>more</span><span class='tooltip'> $tooltip</span>";
107 function input_date_details($row, $date) {
108 $row_id = $row['id'];
109 $name = compute_input_name($row, 'required_date');
111 $_POST[$name] = sql2date($date);
113 start_extract_cell();
114 date_cells (null, $name, 'title', null, 0,0,1001);
115 return end_extract_cell();
119 <input type='text' value='$date' name='$name'>
123 function input_comment_details($row, $comment) {
124 $row_id = $row['id'];
126 <input type='text' value='$comment' name='detail[$row_id][comment]'>
130 function get_order_details_extra($customer_id) {
131 $sql = "SELECT sod.id
134 , quantity - qty_sent
137 FROM ".TB_PREF."sales_order_details sod
138 JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
139 AND so.trans_type = sod.trans_type
140 AND so.trans_type = ".ST_SALESORDER."
141 AND so.debtor_no = $customer_id
143 WHERE quantity > qty_sent
149 function get_order_summary() {
150 $sql = "SELECT debtor_no, debtor_ref, branch_ref
152 , sum(quantity - qty_sent) as quantity
153 , sum((quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount
155 , group_concat(distinct comments separator ';') as order_comment
156 , group_concat(distinct comment separator ';') as detail_comment
157 FROM ".TB_PREF."sales_order_details sod
158 JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
159 AND so.trans_type = sod.trans_type
160 AND so.trans_type = ".ST_SALESORDER."
162 NATURAL JOIN ".TB_PREF."debtors_master
163 NATURAL JOIN ".TB_PREF."cust_branch
164 WHERE quantity > qty_sent AND ".ST_SALESORDER."
165 GROUP BY debtor_no, branch_code