Add extract cell functions.
[order_line_extra.git] / includes / order_lines.inc
index 0238b343fb71813b067077a36e52803849b88e17..54b2a7faec8eb4f309827d4492f7b8afe39f0f35 100644 (file)
@@ -1,5 +1,36 @@
 <?php
 include_once($path_to_root."/includes/ui/ui_input.inc");
+/* This utility function remove beginning <td> and </td> from a string
+ * generated by the above *_cell function.
+ * This is usefull to use the result of the function within a pager
+ * which already include the <td>...</td>
+ * However, for function which doesn't return a string
+ * but echo, we need to capture the output of the echo first.
+ */
+function start_extract_cell() {
+       // We need 
+       ob_start();
+}
+
+function end_extract_cell() {
+       $content = ob_get_contents();
+       ob_end_clean();
+       return extract_cell($content);
+}
+
+function extract_cell($td) {
+       if(preg_match('/\s*<td>(.*)<\/td>\s*/s', $td, $matches)) {
+               return $matches[1];
+       }
+       else {
+print_r('cacou');
+               return $td;
+       }
+}
+
+?>
+
+
 
 function update_extra_order_details() {
        if(!isset($_POST['Update']) || $_POST['Update'] != 'Update')  return;
@@ -57,6 +88,22 @@ function customer_link($row) {
        
 }
 
+function aggregate_comment($row) {
+       $comment =  $row['order_comment'].$row['detail_comment'];
+       if($comment) {
+               $comments = array_map('trim', explode(';', $comment));
+               $comments = array_filter($comments);
+               $first = array_shift($comments);
+               if(count($comments) == 0)
+                       return $first;
+               else {
+                       $tooltip = implode('<br>', $comments);
+                       return "$first <span class='before-tooltip'>more</span><span class='tooltip'>&nbsp$tooltip</span>";
+               }
+       }
+       return '';
+}
+
 function input_date_details($row, $date) {
 $row_id = $row['id'];
        $name = compute_input_name($row, 'required_date');
@@ -86,7 +133,7 @@ function get_order_details_extra($customer_id) {
        , stk_code
        , quantity - qty_sent
        , required_date
-       , comment
+       ,comment
        FROM ".TB_PREF."sales_order_details sod
        JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
                AND so.trans_type = sod.trans_type
@@ -105,7 +152,8 @@ function get_order_summary() {
        , sum(quantity - qty_sent) as quantity
        , sum((quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount
        , min(required_date)
-       , min(comment)
+       , group_concat(distinct comments separator ';') as order_comment
+       , group_concat(distinct comment separator ';') as detail_comment
        FROM ".TB_PREF."sales_order_details sod
        JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
                AND so.trans_type = sod.trans_type