示例#1
0
 /**
  * get received_items.
  *
  * @return Response
  */
 public function receivItems()
 {
     $dispatch = ArrivalItem::where('recipient_destination_id', Auth::user()->recipient_id)->select('vaccine_id', DB::raw('sum(number_received) as total'))->groupBy('vaccine_id')->get();
     //        $dispatch =  RecipientPackageItem::where('recipient_id',Auth::user()->recipient_id)->select('vaccine_id', DB::raw('sum(amount) as total'),DB::raw('month(created_at) as month'))
     //                ->groupBy('month')
     //                ->get();
     return $dispatch;
 }
示例#2
0
 /**
  * Function to receive item in national level & lower levels
  *
  * @param  Request  $request
  * @return Response
  */
 public function pre_receive(Request $request)
 {
     $recipient = Recipient::find(Auth::user()->recipient_id);
     $arrival = new Arrival();
     $nextNumber = $this->getNextArrivalNumber();
     $str = "";
     for ($sj = 6; $sj > strlen($nextNumber); $sj--) {
         $str .= "0";
     }
     $arrival->reference = date('Y') . "1" . $str + "" . $nextNumber;
     $arrival->recipient_source_id = $recipient->parent_id;
     $arrival->recipient_destination_id = $recipient->id;
     $arrival->source_id = $request->has('source_id') ? $request->input('source_id') : '';
     $arrival->arrival_report_number = $request->has('arrival_report_no') ? $request->input('arrival_report_no') : '';
     $arrival->package_volume = $request->has('packed_volume') ? $request->input('packed_volume') : '';
     $arrival->total_weight = $request->has('total_weight') ? $request->input('total_weight') : '';
     $arrival->arrival_date = $request->input('arrival_date');
     $arrival->freight_cost = $request->has('freight_cost') ? $request->input('freight_cost') : '';
     $arrival->receiving_user = Auth::user()->id;
     $arrival->order_no = $nextNumber;
     $arrival->year = date('Y');
     $arrival->notes = $request->has('notes') ? $request->input('notes') : '';
     $arrival->main_currency = $request->has('main_currency') ? $request->input('main_currency') : '';
     $arrival->used_currency = $request->has('currency_of_bill') ? $request->input('currency_of_bill') : '';
     $arrival->exchange_rate = $request->has('exchange_rate') ? $request->input('exchange_rate') : '';
     $arrival->save();
     foreach ($request->input('items') as $item) {
         if (isset($item['number_received'])) {
             if (isset($item['damaged_amount'])) {
                 $amount = $item['number_received'] - $item['damaged_amount'];
                 $amount = $amount <= 0 ? 0 : $amount;
             } else {
                 $amount = $item['number_received'];
             }
         } else {
             if (isset($item['damaged_amount'])) {
                 $amount = $item['doses'] - $item['damaged_amount'];
                 $amount = $amount <= 0 ? 0 : $amount;
             } else {
                 $amount = $item['doses'];
             }
         }
         $ArrivalItem = new ArrivalItem();
         $ArrivalItem->recipient_source_id = $recipient->parent_id;
         $ArrivalItem->recipient_destination_id = $recipient->id;
         $ArrivalItem->vaccine_id = isset($item['item_id']) ? $item['item_id'] : "";
         $ArrivalItem->packaging_id = isset($item['packaging_id']) ? $item['packaging_id'] : "";
         $ArrivalItem->activity_id = isset($item['activity']) ? $item['activity'] : "";
         $ArrivalItem->store_id = isset($item['store_id']) ? $item['store_id'] : "";
         $ArrivalItem->vvm_status = isset($item['vvm_stage']) ? $item['u_price'] : '';
         $ArrivalItem->arrival_id = $arrival->id;
         $ArrivalItem->package_number = $request->has('arrival_report_no') ? $request->input('arrival_report_no') : '';
         $ArrivalItem->lot_number = isset($item['lot_number']) ? $item['lot_number'] : "";
         $ArrivalItem->number_expected = isset($item['doses']) ? $item['doses'] : "";
         $ArrivalItem->number_received = $amount;
         $ArrivalItem->physical_damage = isset($item['physical_damage']) ? $item['physical_damage'] : "";
         $ArrivalItem->number_as_expected = isset($item['number_as_expected']) ? $item['number_as_expected'] : "";
         $ArrivalItem->damaged_amount = isset($item['damaged_amount']) ? $item['damaged_amount'] : 0;
         $ArrivalItem->receiving_user = Auth::user()->id;
         $ArrivalItem->unit_price = isset($item['u_price']) ? $item['u_price'] : '';
         $ArrivalItem->total_price = isset($item['t_price']) ? $item['t_price'] : '';
         $ArrivalItem->volume = isset($item['total_volume']) ? $item['total_volume'] : '';
         $ArrivalItem->manufacture_id = isset($item['manufacture_id']) ? $item['manufacture_id'] : 0;
         $ArrivalItem->prduction_date = isset($item['prod_date']) ? $item['prod_date'] : '';
         $ArrivalItem->expiry_date = isset($item['expired_date']) ? $item['expired_date'] : '';
         $ArrivalItem->voucher_number = $arrival->reference;
         $ArrivalItem->arrival_date = $request->input('arrival_date');
         $ArrivalItem->save();
         $store = Store::find($item['store_id']);
         $store->used_volume = $store->used_volume + $amount * $item['cm_per_dose'] * 0.001;
         $store->save();
         //adding the item to stock
         if (count(Stock::where('recipient_id', $recipient->id)->where('vaccine_id', $item['item_id'])->where('lot_number', $item['lot_number'])->get()) != 0) {
             $stock = Stock::where('recipient_id', $recipient->id)->where('vaccine_id', $item['item_id'])->where('lot_number', $item['lot_number'])->first();
             $stock->vaccine_id = isset($item['item_id']) ? $item['item_id'] : "";
             $stock->recipient_id = $recipient->id;
             $stock->source_id = $request->has('source_id') ? $request->input('source_id') : '';
             $stock->amount = $amount + $stock->amount;
             $stock->lot_number = isset($item['lot_number']) ? $item['lot_number'] : "";
             $stock->packaging_id = isset($item['packaging_id']) ? $item['packaging_id'] : "";
             $stock->expiry_date = isset($item['expired_date']) ? $item['expired_date'] : "";
             $stock->store_id = isset($item['store_id']) ? $item['store_id'] : "";
             $stock->unit_price = isset($item['u_price']) ? $item['u_price'] : "";
             $stock->activity_id = isset($item['activity']) ? $item['activity'] : "";
             $stock->save();
         } else {
             $stock = new Stock();
             $stock->vaccine_id = isset($item['item_id']) ? $item['item_id'] : "";
             $stock->recipient_id = $recipient->id;
             $stock->amount = $amount;
             $stock->source_id = $request->has('source_id') ? $request->input('source_id') : '';
             $stock->lot_number = isset($item['lot_number']) ? $item['lot_number'] : "";
             $stock->packaging_id = isset($item['packaging_id']) ? $item['packaging_id'] : "";
             $stock->expiry_date = isset($item['expired_date']) ? $item['expired_date'] : "";
             $stock->store_id = isset($item['store_id']) ? $item['store_id'] : "";
             $stock->unit_price = isset($item['u_price']) ? $item['u_price'] : "";
             $stock->activity_id = isset($item['activity']) ? $item['activity'] : "";
             $stock->save();
         }
         //adding the item to store
         if (count(StoreStock::where('store_id', $item['store_id'])->where('vaccine_id', $item['item_id'])->where('lot_number', $item['lot_number'])->get()) != 0) {
             $storeStock = StoreStock::where('store_id', $item['store_id'])->where('vaccine_id', $item['item_id'])->where('lot_number', $item['lot_number'])->first();
             $storeStock->vaccine_id = isset($item['item_id']) ? $item['item_id'] : "";
             $storeStock->store_id = isset($item['store_id']) ? $item['store_id'] : "";
             $storeStock->amount = $amount + $storeStock->amount;
             $storeStock->lot_number = isset($item['lot_number']) ? $item['lot_number'] : "";
             $storeStock->packaging_id = isset($item['packaging_id']) ? $item['packaging_id'] : "";
             $storeStock->expiry_date = isset($item['expired_date']) ? $item['expired_date'] : "";
             $storeStock->unit_price = isset($item['u_price']) ? $item['u_price'] : "";
             $storeStock->source_id = $request->has('source_id') ? $request->input('source_id') : '';
             $storeStock->activity_id = isset($item['activity']) ? $item['activity'] : "";
             $storeStock->save();
         } else {
             $storeStock = new StoreStock();
             $storeStock->vaccine_id = isset($item['item_id']) ? $item['item_id'] : "";
             $storeStock->store_id = isset($item['store_id']) ? $item['store_id'] : "";
             $storeStock->amount = $amount;
             $storeStock->lot_number = isset($item['lot_number']) ? $item['lot_number'] : "";
             $storeStock->packaging_id = isset($item['packaging_id']) ? $item['packaging_id'] : "";
             $storeStock->expiry_date = isset($item['expired_date']) ? $item['expired_date'] : "";
             $storeStock->unit_price = isset($item['u_price']) ? $item['u_price'] : "";
             $storeStock->source_id = $request->has('source_id') ? $request->input('source_id') : '';
             $storeStock->activity_id = isset($item['activity']) ? $item['activity'] : "";
             $storeStock->save();
         }
         if ($request->input('from_type') == 'pre_advice') {
             foreach (PreShipment::where('package_id', $request->input('arrival_report_no'))->get() as $pre_shipment) {
                 $pre_shipment->status = 'received';
                 $pre_shipment->save();
             }
         }
         if (isset($item['number_received'])) {
             if (isset($item['damaged_amount'])) {
                 $amountss = $item['number_received'] - $item['damaged_amount'];
                 $amountss = $amountss <= 0 ? 0 : $amountss;
                 $this->adjustDuringArrival($stock->id, $amountss, $item['item_id'], $item['lot_number'], $item['doses']);
             } else {
                 $amountss = $item['number_received'];
                 $this->adjustDuringArrival($stock->id, $amountss, $item['item_id'], $item['lot_number'], $item['doses']);
             }
         } else {
             if (isset($item['damaged_amount'])) {
                 $amountss = $item['doses'] - $item['damaged_amount'];
                 $amountss = $amountss <= 0 ? 0 : $amountss;
                 $this->adjustDuringArrival($stock->id, $amountss, $item['item_id'], $item['lot_number'], $item['doses']);
             } else {
                 $amountss = $item['doses'];
             }
         }
     }
     if ($request->input('from_type') == 'other') {
         foreach (RecipientPackage::where('voucher_number', $request->input('arrival_report_no'))->get() as $pre_shipment) {
             $pre_shipment->receiving_user = Auth::user()->id;
             $pre_shipment->receiving_status = 'received';
             $pre_shipment->save();
         }
     }
     Log::create(array("user_id" => Auth::user()->id, "action" => "Receive Products, Reference Number " . $arrival->reference));
     return $arrival->reference;
 }