X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Forder_lines.inc;h=87a83f01f6b58e73a029467d42612be7750e426c;hb=4c611accdad255c87aa52739fb3e6540ad1b43a5;hp=92391f6034458ef3efb3c9447e1562e7dca6a111;hpb=7099417ed904d1b154cdd96e20cf70f6659bab01;p=order_line_extra.git diff --git a/includes/order_lines.inc b/includes/order_lines.inc index 92391f6..87a83f0 100644 --- a/includes/order_lines.inc +++ b/includes/order_lines.inc @@ -28,41 +28,68 @@ print_r('cacou'); } } +function post_to_detail_ids() { + $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(); 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' "); - if(isset($values['required_date'])) { - $required_date = trim($values['required_date']); - if($required_date == "") { - array_push($set," required_date = NULL"); - } else { - $date = date2sql($required_date); - array_push($set," required_date='$date' "); + foreach($date_fields as $date_field) { + if(isset($values[$date_field])) { + $input_date = trim($values[$date_field]); + if($input_date == "") { + // Only the priority field can be set to null. + if($date_field == 'priority') array_push($set," $date_field = NULL"); + } else { + $date = date2sql($input_date); + array_push($set," $date_field='$date' "); + } } } if(!empty($set)) { $sql = "UPDATE ".TB_PREF."sales_order_details SET ".implode($set,', ')." WHERE id = $detail_id "; - + if(!db_query($sql)) { display_error('Problem while updating order details. Try again'); cancel_transaction(); return; } } - } + 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(); + hook_db_prewrite($cart, 'order_xtra'); + if($splitter->splitAll()) display_warning("Items have been split."); + hook_db_postwrite($cart, 'order_xtra'); + commit_transaction(); +} + function compute_input_name($row, $field) { $row_id = $row['id']; return "detail[$row_id][$field]"; @@ -75,13 +102,13 @@ function view_link($dummy, $order_no) function item_link($dummy, $stock_id) { - return pager_link( _($stock_id), + return pager_link( _($stock_id), "/modules/order_line_extra/item_schedule.php?stock_id=" .$stock_id); } function order_link($row) { - return pager_link( _("Sales Order"), + return pager_link( _("Sales Order"), "/sales/sales_order_entry.php?NewQuoteToSalesOrder=" .$row['order_no'], ICON_DOC); } @@ -91,7 +118,7 @@ function customer_link($row) { function customer_link2($name, $id) { return pager_link(_($name), "/modules/order_line_extra/order_lines_view.php?customer_id=${id}"); - + } function aggregate_comment($row) { @@ -119,9 +146,9 @@ function available_quantity($row, $available) { return "$available"; } -function input_date_details($row, $date) { +function input_date_details($row, $field_name, $date) { $row_id = $row['id']; - $name = compute_input_name($row, 'required_date'); + $name = compute_input_name($row, $field_name); $_POST[$name] = sql2date($date); @@ -135,6 +162,22 @@ $_POST[$name] = sql2date($date); "; } +function input_priority_date_details($row, $date) { + return input_date_details($row, 'priority', $date); +} + +function input_hold_until_date_details($row, $date) { + return input_date_details($row, 'hold_until_date', $date); +} + +function input_required_date_details($row, $date) { + return input_date_details($row, 'required_date', $date); +} + +function input_expiry_date_details($row, $date) { + return input_date_details($row, 'expiry_date', $date); +} + function input_comment_details($row, $comment) { $row_id = $row['id']; return " @@ -149,7 +192,10 @@ function get_order_details_extra($customer_id, $location) { , sod.quantity - qty_sent quantity , GREATEST(0, LEAST(qoh.quantity - quantity_before, sod.quantity - qty_sent)) , quantity_before + , sod.`priority` + , hold_until_date , required_date + , expiry_date ,comment FROM ".TB_PREF."sales_order_details sod JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no @@ -158,21 +204,23 @@ function get_order_details_extra($customer_id, $location) { AND so.debtor_no = $customer_id ) JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location') - JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id) + LEFT JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id) WHERE sod.quantity > qty_sent "; return $sql; } -function get_order_summary() { - $sql = "SELECT debtor_no, debtor_ref, branch_ref +function get_order_summary($location) { +/* + $sub = "SELECT debtor_no, debtor_ref, branch_ref, stk_code , min(delivery_date) - , sum(quantity - qty_sent) as quantity - , sum((quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount + , sum(sod.quantity - qty_sent) as quantity + , sum((sod.quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount , min(required_date) , group_concat(distinct comments separator ';') as order_comment , group_concat(distinct comment separator ';') as detail_comment + , max(quantity_before) as quantity_before 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 @@ -180,8 +228,26 @@ function get_order_summary() { ) NATURAL JOIN ".TB_PREF."debtors_master NATURAL JOIN ".TB_PREF."cust_branch - WHERE quantity > qty_sent AND ".ST_SALESORDER." - GROUP BY debtor_no, branch_code + JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id) + WHERE sod.quantity > qty_sent AND ".ST_SALESORDER." + GROUP BY debtor_no, branch_code, stk_code + "; +*/ + + $sub = TB_PREF."order_summary_view"; + + $sql = "SELECT debtor_no, debtor_ref, branch_ref + , `min(delivery_date)` + , sum(sub.quantity) as quantity + , sum(sub.amount) as amount + , sum(greatest(least(sub.quantity, qoh.quantity - quantity_before), 0)) + , sum(sub.amount*greatest(least(sub.quantity, qoh.quantity - quantity_before), 0)/sub.quantity) + , min(`min(required_date)`) + , group_concat(distinct order_comment separator ';') as order_comment + , group_concat(distinct detail_comment separator ';') as detail_comment + FROM $sub sub + LEFT JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location') + GROUP BY debtor_no, debtor_ref "; return $sql;