From f170b9aa3c81b04ac06a6929818643f19f083bbc Mon Sep 17 00:00:00 2001 From: Maxime Bourget Date: Fri, 7 Jun 2013 09:59:53 +0100 Subject: [PATCH] Date saves properly. --- includes/order_lines.inc | 48 ++++++++++++++++++++++++++++------------ order_lines_view.php | 8 +++---- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/includes/order_lines.inc b/includes/order_lines.inc index d170222..d94c4de 100644 --- a/includes/order_lines.inc +++ b/includes/order_lines.inc @@ -34,29 +34,33 @@ function update_extra_order_details() { begin_transaction(); // 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 == "") { + 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; } } - +commit_transaction(); + } display_notification('Order details updated'); @@ -75,13 +79,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 +95,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 +123,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 +139,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 " diff --git a/order_lines_view.php b/order_lines_view.php index 227a15c..c96c3e6 100644 --- a/order_lines_view.php +++ b/order_lines_view.php @@ -76,10 +76,10 @@ if($customer_id) { ,_("Quantity") => array('type' => 'qty', 'dec' => 0) ,_("Available") => array('fun' => 'available_quantity', 'dec' => 0, 'ord' => '') ,_("Before") => 'skip' - ,_("Priority") => array('fun' => 'input_date_details', 'ord' => '') - ,_("Hold Until") => array('fun' => 'input_date_details', 'ord' => '') - ,_("Require By") => array('fun' => 'input_date_details', 'ord' => '') - ,_("Expiry Date") => array('fun' => 'input_date_details', 'ord' => '') + ,_("Priority") => array('fun' => 'input_priority_date_details', 'ord' => '') + ,_("Hold Until") => array('fun' => 'input_hold_until_date_details', 'ord' => '') + ,_("Require By") => array('fun' => 'input_required_date_details', 'ord' => '') + ,_("Expiry Date") => array('fun' => 'input_expiry_date_details', 'ord' => '') ,_("Comment") => array('fun' => 'input_comment_details', 'ord' => '') ); } -- 2.30.2