コード例 #1
0
 public static function triggerAlerts($alertsId, $additional)
 {
     $message = '';
     switch ($alertsId) {
         case 1:
             if (isset($additional['productId'])) {
                 $product = Product::find($additional['productId']);
                 if (!is_null($product)) {
                     if ($product->stock > 0 and $product->stock < $product->minimum_stock) {
                         $message = 'El producto ' . $product->name . ' ha bajado del stock mínimo.';
                     }
                 }
             }
             break;
         case 2:
             if (isset($additional['productId'])) {
                 $product = Product::find($additional['productId']);
                 if (!is_null($product)) {
                     if ($product->stock == 0) {
                         $message = 'El producto ' . $product->name . ' no tiene stock.';
                     }
                 }
             }
             break;
         case 3:
             if (isset($additional['userId'])) {
                 $user = User::find($additional['userId']);
                 if (!is_null($user)) {
                     $message = 'El usuario ' . $user->display_name . ' necesita aprobación.';
                 }
             }
             break;
         case 4:
             if (isset($additional['productId'])) {
                 $product = Product::find($additional['productId']);
                 if (!is_null($product)) {
                     $message = 'El producto ' . $product->name . ' ha sido creado.';
                 }
             }
             break;
         case 5:
             if (isset($additional['supplierOrderId'])) {
                 $supplierOrder = SupplierOrder::find($additional['supplierOrderId']);
                 if (!is_null($supplierOrder)) {
                     $message = 'Se ha creado un nuevo pedido al proveedor ' . $supplierOrder->supplier->name . '.';
                 }
             }
             break;
         case 6:
             if (isset($additional['supplierOrderId'])) {
                 $supplierOrder = SupplierOrder::find($additional['supplierOrderId']);
                 if (!is_null($supplierOrder)) {
                     $message = 'Se ha recibido un pedido del proveedor ' . $supplierOrder->supplier->name . '.';
                 }
             }
             break;
         default:
             break;
     }
     if ($message != '') {
         static::__sendAlert($alertsId, $message);
     }
 }
コード例 #2
0
 /**
  * Checks if the parameter is a valid supplier id
  * @param $id int
  * @return SupplierOrder object if $id is found, otherwise false
  */
 private function __checkExistence($id)
 {
     if (!is_null($id) && $id != '') {
         $supplier = SupplierOrder::find($id);
         if (is_null($supplier)) {
             return false;
         }
         return $supplier;
     }
     return false;
 }