Пример #1
0
 public function determineWorkOrders(Request $request)
 {
     if ($request->input('productsToFulfill') && is_array($request->input('productsToFulfill'))) {
         try {
             \DB::beginTransaction();
             // Determine work orders (if any for these PO products
             $workOrdersToCreate = $this->workOrderSchedulerService->determineWorkOrdersForPo($request->input('productsToFulfill'));
             if ($request->input('purchaseOrderId')) {
                 // This is on the detail page, instead of just previewing
                 // the PO products and the workorders actually create them now.
                 $po = PurchaseOrder::where('id', $request->input('purchaseOrderId'))->first();
                 foreach ($request->input('productsToFulfill') as $p) {
                     PurchaseOrderProduct::create(['purchase_order_id' => $po->id, 'product_id' => $p['product_id'], 'quantity' => $p['quantity']]);
                     // Deduct the quantity ordered from the current stock for the product
                     $this->workOrderSchedulerService->deductStockFromProducts([$p]);
                 }
                 if ($workOrdersToCreate['workOrdersToCreate'] > 0) {
                     if (isset($po)) {
                         // Create any work orders for the PO product
                         $this->workOrderSchedulerService->generateWorkOrdersForPo($po, $workOrdersToCreate['workOrders']);
                     }
                 }
             }
             \DB::commit();
             return response()->json($workOrdersToCreate);
         } catch (\Exception $ex) {
             \DB::rollBack();
             throw $ex;
         }
     }
 }
 public function deletePurchaseOrderProduct($purchaseOrderId, $productId)
 {
     PurchaseOrderProduct::where('purchase_order_id', $purchaseOrderId)->where('product_id', $productId)->delete();
 }