From 7f245375371ab9eb2234b704049f61e7b021c25f Mon Sep 17 00:00:00 2001 From: Maxime Bourget Date: Tue, 11 Jun 2013 13:49:50 +0100 Subject: [PATCH] Fix install hooks. --- hooks.php | 4 +++- includes/db_order_lines.inc | 25 ++++++++++++++++++------- sql/clean_sales_order_details.sql | 9 ++++++--- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/hooks.php b/hooks.php index b472aef..9bb260b 100644 --- a/hooks.php +++ b/hooks.php @@ -54,7 +54,9 @@ class hooks_order_line_extra extends hooks { return $this->update_databases($company, $updates, $check_only) && update_queue_quantities() - && update_qoh_for_item();; + && update_qoh_for_item() + && update_order_detail_defaults(true) + ; } function deactivate_extension($company, $check_only=true) diff --git a/includes/db_order_lines.inc b/includes/db_order_lines.inc index a7dea9c..266b343 100644 --- a/includes/db_order_lines.inc +++ b/includes/db_order_lines.inc @@ -116,18 +116,27 @@ function clear_qoh_for_item($stock_id=null) { return db_query($sql, 'Error when trying to clean ".TB_PREF."denorm_qoh'); } -function update_order_detail_defaults() { +function update_order_detail_defaults($use_order_date=false) { + + $ok = true; // Set priority to current time. - $sql = "UPDATE ".TB_PREF."sales_order_details - SET priority = now() - WHERE priority is null"; - db_query($sql); + $sql = "UPDATE ".TB_PREF."sales_order_details"; + if($use_order_date) { + $sql .= " NATURAL JOIN 0_sales_orders + SET priority = ord_date"; + } + else { + $sql .= " SET priority = now()"; + } + $sql .= " WHERE priority is null"; + $ok &= db_query($sql); + // Set hold_until_date to delivery_date $sql = "UPDATE ".TB_PREF."sales_order_details NATURAL JOIN 0_sales_orders SET hold_until_date = delivery_date WHERE hold_until_date is null"; - db_query($sql); + $ok &= db_query($sql); // Set expiry date to 6 weeks + delivery date // or 2 weeks + required date. Stuff with an @@ -137,7 +146,9 @@ function update_order_detail_defaults() { SET expiry_date = if(required_date is null, hold_until_date + INTERVAL 6 WEEK, required_date + INTERVAL 2 WEEK) WHERE expiry_date is null"; - db_query($sql); + $ok &= db_query($sql, $sql); + + return $ok; } ?> diff --git a/sql/clean_sales_order_details.sql b/sql/clean_sales_order_details.sql index 2b70ddf..5216efc 100644 --- a/sql/clean_sales_order_details.sql +++ b/sql/clean_sales_order_details.sql @@ -1,7 +1,10 @@ ALTER TABlE 0_sales_order_details -# DROP COLUMN required_date , -# DROP COLUMN comment , -# DROP COLUMN priority; + DROP COLUMN required_date , + DROP COLUMN ref , + DROP COLUMN comment , + DROP COLUMN priority; + DROP COLUMN expiry_date + DROP COLUMN hold_until_date; DROP TABLE IF EXISTS 0_denorm_order_details_queue; DROP TABLE IF EXISTS 0_denorm_qoh; -- 2.30.2