Use next location only if no stock left
authorMaxime Bourget <bmx007@gmail.com>
Thu, 30 May 2013 17:03:32 +0000 (18:03 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Thu, 30 May 2013 17:03:32 +0000 (18:03 +0100)
haxe/ItemScheduler.hx

index 3480399079cc15f1087cc2da5c8547952adfd3ed..27dd7bf0c9e8c731c794ea738049f438279ff192 100644 (file)
@@ -54,7 +54,7 @@ class ItemScheduler {
        }
 
        function tableHeader() {
-               return ["Order", "Customer", "Quantity", "Before", "After", "Loc", "Required Date"];
+               return ["Order", "Customer", "Quantity", "Before", "After", "Loc", "From",  "Required Date"];
        }
 
 /*
@@ -95,7 +95,7 @@ class ItemScheduler {
                        var order = php.Lib.objectOfAssociativeArray(orderRow);
                        var quantity : Int = Std.parseInt(order.quantity);
 
-                       while(quantity > left && locationIter.hasNext()) {
+                       while(0 > left && locationIter.hasNext()) {
                                location = locationIter.next();
                                var quantityForLocation : Int = location.quantityOnHand(stock_id, null);
                                if(quantityForLocation == null || quantityForLocation == 0) continue;
@@ -104,14 +104,14 @@ class ItemScheduler {
                        }
                        left -= quantity;
 
-                       formatOrder(order, left);
+                       formatOrder(order, left, location.delivery);
                        
                }
                        
        }
 
        function printRow(tds : Array<Dynamic>, attributes : Array<String>) {
-               php.Lib.print('<tr "'+attributes.join(' ')+'">');
+               php.Lib.print('<tr '+attributes.join(' ')+'>');
                for(td in tds) {
                        php.Lib.print('<td>');
                        php.Lib.print(td);
@@ -120,17 +120,41 @@ class ItemScheduler {
                php.Lib.print('</tr>');
        }
 
-       function formatOrder(order : Dynamic, left : Int) {
+       function formatOrder(order : Dynamic, left : Int, date : Date) {
                        var attributes = [];
+                       var classes = [];
+                       var before : Int = left + order.quantity;
+                       /* We have basically 3 different cases;
+                        * - the order can be fullfilled
+                        * - the order can be partially 
+                  * - not at all
+                        */
+                       if (before < 0 ) {
+                                       classes.push('soldout');
+                       }
+                       else if(left < 0) {
+                                       classes.push('partial');
+                       }
+                       else {
+                                       classes.push('full');
+                       }
+
+                       /* The order can also be late if we need
+                        * to wait for a delivery to get it
+                        */
                        var cells : Array <Dynamic> = [
                                order.order_id
                                ,order.deliver_to
                                ,order.quantity
+                               ,before
                                ,left
-                               ,left+order.quantity
                                ,order.from_stk_loc
                                ,order.delivery_date
+                               ,order.required_date 
+                               ,order.comment
                        ];
+
+                       attributes.push('class="'+classes.join(' ')+'"');
                        printRow(cells, attributes);
 
        }
@@ -196,9 +220,11 @@ class ItemScheduler {
        function orders() {
                var tb : String =  untyped __php__('TB_PREF');
                var sql : String = "SELECT *  
-                                               FROM "+tb+"denorm_order_details_queue 
-                                               JOIN  "+tb+"sales_orders ON (order_no = order_id)
+                                               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)
                                                WHERE stock_id = '"+this.stock_id+"'
+                                               AND od.trans_type = 30
                                                ORDER by quantity_before";
        
                return FA.query(sql);