+ function purcharseOrders() {
+ var TB = FA.tb();
+ var sql = 'SELECT SUM(quantity_ordered - quantity_received) as quantity
+ into_stock_location AS location
+ FROM '+TB+'purch_order_details
+ NATURAL JOIN '+TB+'purch_orders
+ WHERE item_code = "'+this.stock_id+'"
+ AND quantity_ordered > quantity_received
+ GROUP by item_code,delivery_date, into_stock_location
+ ORDER by delivery_date' ;
+
+ return FA.query(sql);
+ }
+
+ 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();
+ }
+ }