+*/
+
+ function generateTable(): Void {
+ var startDate = Date.fromTime(0);
+ for(order in orders()) {
+ var obj = php.Lib.objectOfAssociativeArray(order);
+
+ }
+
+ // Sort location by datae
+ var locations = this.locations();
+ locations.sort(function(a, b) {
+ return cast(a.delivery.getTime() - b.delivery.getTime(), Int );
+ });
+
+ // Get the start location, it should be the first one
+ var locationIter = locations.iterator();
+ var location = locationIter.next();
+ var qoh : Int = location.quantityOnHand(stock_id, null);
+ var left = qoh;
+ formatLocation(location, "Initial", left);
+
+ // We display the order ordered by priority
+ // But insert the location when needed (meaning
+ // when we run out of item available
+ for(orderRow in orders()) {
+ var order = php.Lib.objectOfAssociativeArray(orderRow);
+ var quantity : Int = Std.parseInt(order.quantity);
+
+ while(0 > left && locationIter.hasNext()) {
+ location = locationIter.next();
+ var quantityForLocation : Int = location.quantityOnHand(stock_id, null);
+ if(quantityForLocation == null || quantityForLocation == 0) continue;
+ left += quantityForLocation;
+ formatLocation(location, "Delivery", left);
+ }
+ left -= quantity;
+
+ formatOrder(order, left, location.delivery);
+
+ }
+
+ }
+
+ function printRow(tds : Array<Dynamic>, attributes : Array<String>) {
+ php.Lib.print('<tr '+attributes.join(' ')+'>');
+ var position : Int = 1;
+ for(td in tds) {
+ php.Lib.print('<td class="cell_'+position+'">');
+ if(td) php.Lib.print(td);
+ php.Lib.print('</td>');
+ position++;
+ }
+ php.Lib.print('</tr>');
+ }
+
+ function formatOrder(order : Dynamic, left : Int, date : Date) {
+ var row_id = 'order_'+order.id;
+ var attributes = ['id = "'+row_id+'"'];
+ 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 required_by : Date = FA.sql2date(order.required_date);
+ if(required_by == null) required_by = FA.sql2date(order.delivery_date);
+ if(required_by.getTime() < date.getTime()) {
+ classes.push('late');
+ }
+ else {
+ classes.push('on_time');
+ }
+ var cells : Array <Dynamic> = [
+ order.order_id
+ , '<a href="/modules/order_line_extra/order_lines_view.php?customer_id='+Std.string(order.debtor_no)+'">'+order.deliver_to+'</a>'
+ ,'<input type="text" name="'+row_id+'[quantity]" value="'+order.quantity+'">'
+ ,before
+ ,left
+ ,order.from_stk_loc
+ ,order.delivery_date
+ ,order.required_date
+ ,order.comment
+ ];
+
+ attributes.push('class="'+classes.join(' ')+'"');
+ printRow(cells, attributes);
+
+ }