diff --git a/app/Http/Controllers/Supply.php b/app/Http/Controllers/Supply.php index 50b63aa..2fdec1f 100644 --- a/app/Http/Controllers/Supply.php +++ b/app/Http/Controllers/Supply.php @@ -61,6 +61,7 @@ class Supply extends Controller } } + //Fulfills an order with only the primary supplier of it's service public static function fulfill($order) { if (gettype($order) == 'integer') { $order = Order::find($order); @@ -69,16 +70,39 @@ class Supply extends Controller return Supply::orderPrimary($order); } - public static function fulfillAny($order) { + //Fulfills an order with the first available supplier it finds. It returns + //false if none could be found and the refreshed order model otherwise. + public static function fulfillWithAny($order) { if (gettype($order) == 'integer') { $order = Order::find($order); } if (Supply::orderPrimary($order)) { - + return $order->refresh(); }; + + $suppliers = $order->service->suppliers; + + foreach ($suppliers as $s) { + switch ($s->supplier) { + case 'smmkings': + if (Supply::orderSmmkings($order, $s)){ + return $order->refresh(); + } + break; + case 'smmworld': + if (Supply::orderSmmkings($order, $s)){ + return $order->refresh(); + } + break; + } + + } + + return false; } + //Fulfills an order with only the primary supplier of it's service public static function orderPrimary($order) { if (gettype($order) == 'integer') { $order = Order::find($order);