/**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $item = AdjustmentReason::find($id);
     $item->status = 'deleted';
     $item->save();
     Log::create(array("user_id" => Auth::user()->id, "action" => "Delete Adjustment Reason named " . $item->name));
 }
Example #2
0
 public function adjustDuringArrival($stock_id, $doses, $item_id, $lot_number, $original_amount)
 {
     $stock = Stock::find($stock_id);
     $amount = $stock->amount + ($original_amount - $doses);
     $storeStock = StoreStock::where('store_id', $stock->store_id)->where('vaccine_id', $item_id)->where('lot_number', $lot_number)->first();
     //        $stock->amount = $doses;
     //        $storeStock->amount = $doses;
     $volume = ($original_amount - $doses) * PackagingInformation::find($stock->packaging_id)->cm_per_dose * 0.001;
     //        $current_occupied_volume = $amount * PackagingInformation::find($stock->packaging_id)->cm_per_dose * 0.001;
     //        $volume_to_use = $current_occupied_volume - $volume;
     //        $stock->save();
     //        $storeStock->save();
     //        if($stock->amount == 0){
     //            $stock->delete();
     //        }
     //        if($storeStock->amount == 0){
     //            $storeStock->delete();
     //        }
     //updating volumes
     //        $store = Store::find($stock->store_id);
     //        $store->used_volume = $store->used_volume - $volume_to_use ;
     //        $store->save();
     $reason = AdjustmentReason::where('code', 'AR')->first();
     if ($reason) {
         $adjustment_reason = $reason->id;
     } else {
         $adjustment_reason = 1;
     }
     $adjustment = new Adjustment();
     $nextNumber = $this->getNextAdjustmentNumber();
     $str = "";
     for ($sj = 6; $sj > strlen($nextNumber); $sj--) {
         $str .= "0";
     }
     $adjustment->reference = date('Y') . "3" . $str + "" . $nextNumber;
     $adjustment->adjustment_reason = $adjustment_reason;
     $adjustment->adjustment_type = 'stock';
     $adjustment->resource_id = $stock->id;
     $adjustment->year = date('Y');
     $adjustment->order_no = $nextNumber;
     $adjustment->vaccine_id = $stock->vaccine_id;
     $adjustment->store_id = $stock->store_id;
     $adjustment->lot_number = $stock->lot_number;
     $adjustment->packaging_id = $stock->packaging_id;
     $adjustment->expiry_date = $stock->expiry_date;
     $adjustment->source_id = $stock->source_id;
     $adjustment->activity_id = $stock->activity_id;
     $adjustment->recipient_id = $stock->recipient_id;
     $adjustment->previous_amount = $amount;
     $adjustment->current_amount = $stock->amount;
     $adjustment->adjusted_volume = abs($volume);
     $adjustment->save();
     Log::create(array("user_id" => Auth::user()->id, "action" => "Stock Adjustment with reference Number " . $adjustment->reference));
     return $adjustment->reference;
 }