Exemplo n.º 1
0
         $stock_id = $p->id . '-' . $aid;
         //CURRENT STOCK TARGET
         $target_stock = $p->getDIOHstockTarget($aid);
         //CURRENT STOCK (ALREADY RETRIEVED ABOVE)
         $current_stock = intval($products_stock[$stock_id]);
         //CURRENT OPEN ORDERS
         $already_ordered = $class_do->refillOpenOrdersQuantity($segment_id, $p->id, $aid);
         //Check if we have missing qty
         $missing_quantity = $target_stock - ($current_stock + $already_ordered);
         if ($missing_quantity > 0) {
             $products_with_missing_qty[] = $p->id;
             $articles_with_missing_qty[] = $stock_id;
             $total_qty += $missing_quantity;
             $log_message = "Product {$stock_id} - Missing:{$missing_quantity}";
             //Create depot orders of the needed qty
             $class_do->newOrderAutoRefill($segment_id, $p->id, $aid, $a['products_ean'], $missing_quantity, depot_orders::AUTO_REFILL_ID_DAILYCRON);
             $log_message .= " - Refill created";
             //If needed qty is too big, send an email notification
             $tolerance_limit = ceil($tolerance_email_notification * $target_stock);
             //check only if target stock > 11
             if ($target_stock > $stock_target_tolerance && $missing_quantity > $tolerance_limit) {
                 $log_message .= " (Missing Qty too big)";
             }
             $logger->write($log_message);
         }
     }
 }
 $products_with_missing_qty = array_unique($products_with_missing_qty);
 $total_products_with_missing_qty = count($products_with_missing_qty);
 $total_articles_with_missing_qty = count($articles_with_missing_qty);
 if ($total_products_with_missing_qty == 0) {