X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Forder_lines.inc;h=00c1193b67220be696c5f020cf83b80bc1512526;hb=ee3469d3ffd74d2a6be87d3dd0a9541a14bcdfde;hp=e8d161224d3e21a135abf973441c58df0a79a35d;hpb=b1db75caf17ed70df2de54711fe98c4e5f989bfe;p=order_line_extra.git diff --git a/includes/order_lines.inc b/includes/order_lines.inc index e8d1612..00c1193 100644 --- a/includes/order_lines.inc +++ b/includes/order_lines.inc @@ -23,21 +23,45 @@ function extract_cell($td) { return $matches[1]; } else { -print_r('cacou'); return $td; } } +/* remove unchecked data so each + * funcion doesn't to check what's been checked or not. + */ +function filter_data(&$data) { + if(!isset($data['detail'])) return; + $new_details = array(); + foreach(@$data['detail'] as $detail_id => $values) { + if(@$values['check'] === 'on') $new_details[$detail_id]=$values; + } + $data['detail'] = $new_details; +} + +function post_to_detail_ids() { + if(!isset($_POST['detail'])) return; + $detail_ids = array(); + foreach($_POST['detail'] as $detail_id => $values) { + array_push($detail_ids, $detail_id); + } + + return $detail_ids; +} function update_extra_order_details() { if(!isset($_POST['Update']) || $_POST['Update'] != 'Update') return; + $cart = post_to_detail_ids(); + if($cart === null) return; begin_transaction(); + hook_db_prewrite($cart, 'order_xtra'); // update in database all field $date_fields = array('hold_until_date', 'required_date', 'expiry_date', 'priority'); foreach($_POST['detail'] as $detail_id => $values) { $set = array(); - if($comment = $values['comment']) array_push($set, " comment='$comment' "); + $comment=$values['comment']; + array_push($set, " comment='$comment' "); // erase comment if needed. foreach($date_fields as $date_field) { if(isset($values[$date_field])) { $input_date = trim($values[$date_field]); @@ -60,14 +84,39 @@ begin_transaction(); return; } } -commit_transaction(); - } + hook_db_postwrite($cart, 'order_xtra'); + commit_transaction(); + display_notification('Order details updated'); } +function split_order_details() { + if(!isset($_POST['Split']) || $_POST['Split'] != 'Split') return; + $splitter = new Splitter($_POST); + begin_transaction(); + $cart = post_to_detail_ids(); + if($cart === null) return; + hook_db_prewrite($cart, 'order_xtra'); + if($splitter->splitAll()) display_warning("Items have been split."); + hook_db_postwrite($cart, 'order_xtra'); + commit_transaction(); +} + +function bulk_update_order_details() { + if(!isset($_POST['Bulk']) || $_POST['Bulk'] != 'Bulk') return; + $bulk_updater = new BulkUpdater($_POST); + begin_transaction(); + $cart = post_to_detail_ids(); + if($cart === null) return; + hook_db_prewrite($cart, 'order_xtra'); + $bulk_updater->update(); + hook_db_postwrite($cart, 'order_xtra'); + commit_transaction(); +} + function compute_input_name($row, $field) { $row_id = $row['id']; return "detail[$row_id][$field]"; @@ -163,7 +212,13 @@ $row_id = $row['id']; "; } -function get_order_details_extra($customer_id, $location) { +function input_check_details($row, $dummy) { + $row_id = $row['id']; + return " + "; +} + +function get_order_details_extra($customer_id, $location, $item_like) { $sql = "SELECT sod.id , so.order_no , stk_code @@ -186,6 +241,15 @@ function get_order_details_extra($customer_id, $location) { WHERE sod.quantity > qty_sent "; + if($item_like) { + if($item_like[0]=='/') { + $regexp = substr($item_like, 1); + $sql .= " AND stk_code RLIKE '$regexp'"; + } + else + $sql .= " AND stk_code LIKE '$item_like'"; + } + return $sql; }