Пример #1
0
 /**
  * get storeItemsDetails.
  *
  * @return Response
  */
 public function storeItemsDetails()
 {
     $store = Store::where('recipient_id', Auth::user()->recipient_id)->get();
     $arr = array();
     foreach ($store as $stock) {
         $arr[$stock->id] = StoreStock::where('store_id', $stock->id)->get()->load('packaging');
     }
     return json_encode($arr);
 }
Пример #2
0
 public function cancelDispatch($id, Request $request)
 {
     $dispatch = RecipientPackage::find($id);
     $recipient = Recipient::find(Auth::user()->recipient_id);
     foreach ($dispatch->items as $items) {
         $volume = $items->amount * PackagingInformation::find($items->packaging_id)->cm_per_dose * 0.001;
         $stock = Stock::where('recipient_id', $recipient->id)->where('vaccine_id', $items->vaccine_id)->where('lot_number', $items->batch_number)->first();
         $storeStock = StoreStock::where('store_id', $items->store_id)->where('vaccine_id', $items->vaccine_id)->where('lot_number', $items->batch_number)->first();
         $stock->amount = $stock->amount + $items->amount;
         $storeStock->amount = $storeStock->amount + $items->amount;
         $stock->save();
         $storeStock->save();
         //reduce volume in store
         $store = Store::find($items->store_id);
         $store->used_volume = $store->used_volume + $volume;
         $store->save();
         //update line item status
         $items->status = 'canceled';
         $items->save();
         //delete stock item if amount has turned to zero
         if ($stock->amount == 0) {
             $stock->delete();
         }
         if ($storeStock->amount == 0) {
             $storeStock->delete();
         }
     }
     //update arrival status
     $dispatch->receiving_status = 'canceled';
     $dispatch->comments = $request->has('notes') ? $request->input('notes') : "";
     $dispatch->save();
     Log::create(array("user_id" => Auth::user()->id, "action" => "Cancel Dispatch with reference Number " . $dispatch->voucher_number));
     return $dispatch->voucher_number;
 }