Browse Source

Place orders by traversing suppliers

master
Immanuel Onyeka 3 years ago
parent
commit
6648c72d53
1 changed files with 26 additions and 2 deletions
  1. +26
    -2
      app/Http/Controllers/Supply.php

+ 26
- 2
app/Http/Controllers/Supply.php View File

@@ -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);


Loading…
Cancel
Save