From: Maxime Bourget Date: Sun, 2 Jun 2013 22:57:45 +0000 (+0100) Subject: Update works. X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=7a4c7c9512eb74d2f91ef7939cd435cb98b8114c;p=order_line_extra.git Update works. --- diff --git a/haxe/ItemScheduler.hx b/haxe/ItemScheduler.hx index bb851e5..d01c960 100644 --- a/haxe/ItemScheduler.hx +++ b/haxe/ItemScheduler.hx @@ -9,7 +9,7 @@ typedef Detail = { typedef Order = { id:String ,quantity:String - ,priority:Int + ,priority:Date ,delivery_date:String } @@ -72,10 +72,10 @@ class ScheduleParameters { } - public function priority(order : {id: String, priority: Int}) : Int { + public function priority(order : {id: String, priority: Date}) : Int { var orderId = ItemScheduler.orderId(order); var orderPosition = position(orderId); - return orderPosition != null ? orderPosition : order.priority; + return orderPosition != null ? orderPosition : cast(order.priority.getTime(), Int); } } @@ -232,7 +232,7 @@ return cast(locations(), Array); private function loadOrders() { var tb : String = untyped __php__('TB_PREF'); - var sql : String = "SELECT * + var sql : String = "SELECT * , d.priority AS pp FROM "+tb+"denorm_order_details_queue d JOIN "+tb+"sales_order_details od ON (od.id = d.id) JOIN "+tb+"sales_orders so ON (so.order_no = d.order_id) @@ -247,7 +247,11 @@ function orders():Array { var rows = loadOrders(); var orderList = []; for(row in rows) { - var order:Order = php.Lib.objectOfAssociativeArray(row); + // for some reason, priority is null + // so we use the pp field + var a:Dynamic = php.Lib.objectOfAssociativeArray(row); + var order:Order = a; + order.priority = Date.fromString(a.pp); orderList.push(order); }; @@ -281,13 +285,43 @@ function locations() { } -function purcharseOrders() { -} + function purcharseOrders() { + } public function needsUpdate():Bool { return parameters != null && parameters.mode == ScheduleMode.Move; } + + function update() { + var orders = this.orders(); + var priorities = Lambda.array(Lambda.map(orders, function(o) { return o.priority;})); + priorities.sort(function(a,b) { + var as = a.toString(); + var bs = b.toString(); + if (as < bs) return -1; + if( as > bs) return 1; + return 0; + }); + + var iter = priorities.iterator(); + var p = iter.next(); + var position:Int = 0-priorities.length; + for(order in orders) { + var new_priority = DateTools.delta(p, 1000*position); + untyped __call__ ('update_order_detail_priority', order.id, new_priority.toString()); + + position +=1; + p = iter.next(); + } + untyped __call__ ('update_queue_quantity_for_item', stock_id); + + } + public function action() { + if(parameters != null && parameters.mode == ScheduleMode.Update) { + update(); + } + } } diff --git a/includes/db_order_lines.inc b/includes/db_order_lines.inc index 6947df1..6d3b235 100644 --- a/includes/db_order_lines.inc +++ b/includes/db_order_lines.inc @@ -63,6 +63,7 @@ function insert_item_into_queue($stock_id) { * This function update the denormalisation table for * a given stock id. */ + function update_queue_quantity_for_item($stock_id) { begin_transaction(); clear_queue_quantity_for_item($stock_id); @@ -79,5 +80,10 @@ function update_queue_quantities() { } } +function update_order_detail_priority($detail_id, $priority) { + $sql = "UPDATE ".TB_PREF."sales_order_details SET priority='".$priority."' WHERE id = $detail_id "; + print($sql); + db_query($sql, "can't set priorti to order details $detail_id"); +} ?> diff --git a/item_schedule.php b/item_schedule.php index eaa9c2e..acbf4be 100644 --- a/item_schedule.php +++ b/item_schedule.php @@ -19,6 +19,7 @@ include_once($path_to_root . "/reporting/includes/reporting.inc"); //include_once("includes/item_scheduler.inc"); include_once("hincludes/lib/php/Boot.class.php"); +include_once("includes/db_order_lines.inc"); $page_security = 'SA_ORDERLINEX_EDIT'; add_access_extensions(); @@ -73,18 +74,16 @@ if(isset($_POST['Update'])) { $Ajax->activate('item_schedule'); echo 'youpiii'; // Restore the parameters - /* - $params = $_SESSION['schedule_parameters']; + $params = new ScheduleParameters($_SESSION['schedule_parameters']); $params->setMode('update'); - */ - $params = null; } else { $params = in_ajax() && $stock_id == @$_POST['last_stock_id'] ? new ScheduleParameters($_POST) : null; // save parameters form update - $_SESSION['schedule_parameters'] = $params; + $_SESSION['schedule_parameters'] = $_POST; } $scheduler = new ItemScheduler($stock_id, 'DEF', $params); +$scheduler->action(); start_table(TABLESTYLE); $th = $scheduler->tableHeader();