Ejemplo n.º 1
0
 /**
  * Handle the command.
  *
  * @param  CreateCostCommand  $command
  * @return void
  */
 public function handle(CreateCostCommand $command)
 {
     $cost = Cost::create(['salary' => $command->salary, 'save' => $command->save, 'spend' => $command->spend]);
     if (!empty($cost)) {
         return $cost;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Handle the command.
  *
  * @param  UpdateTotalCommand  $command
  * @return void
  */
 public function handle(UpdateTotalCommand $command)
 {
     $cost = Cost::where(DB::raw('MONTH(created_at)'), '=', $command->month)->where(DB::raw('YEAR(created_at)'), '=', $command->year)->first();
     if (!empty($cost)) {
         $cost->spend = $command->spend;
         $cost->income = $command->income;
         if ($cost->save()) {
             return $cost;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Handle the command.
  *
  * @param  UpdateCostCommand  $command
  * @return void
  */
 public function handle(UpdateCostCommand $command)
 {
     $cost = Cost::whereId($command->id)->first();
     if ($cost) {
         $cost->salary = $command->salary;
         $cost->save = $command->save;
         if ($cost->save()) {
             return $cost;
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store()
 {
     //Check if exists
     $cost = Cost::exists($this->month, $this->year);
     if (!empty($cost)) {
         return $this->saveResponse(false);
     }
     $setting = Setting::first();
     $spend = Item::total($this->month, $this->year);
     $cost = Bus::dispatch(new CreateCostCommand($setting->salary, $setting->save, $spend));
     return $this->saveResponse($cost);
 }
Ejemplo n.º 5
0
 public static function exists($month, $year)
 {
     return Cost::where(DB::raw('MONTH(created_at)'), '=', $month)->where(DB::raw('YEAR(created_at)'), '=', $year)->first();
 }
Ejemplo n.º 6
0
 public function get($month, $year)
 {
     return \App\Models\Cost::where(DB::raw('MONTH(created_at)'), '=', $month)->where(DB::raw('YEAR(created_at)'), '=', $year)->first();
 }