コード例 #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;
 }
コード例 #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;
 }
コード例 #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;
 }
コード例 #4
0
ファイル: CostController.php プロジェクト: nq2916/savings
 /**
  * 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);
 }
コード例 #5
0
ファイル: Cost.php プロジェクト: nq2916/savings
 public static function exists($month, $year)
 {
     return Cost::where(DB::raw('MONTH(created_at)'), '=', $month)->where(DB::raw('YEAR(created_at)'), '=', $year)->first();
 }
コード例 #6
0
ファイル: Cost.php プロジェクト: nq2916/savings
 public function get($month, $year)
 {
     return \App\Models\Cost::where(DB::raw('MONTH(created_at)'), '=', $month)->where(DB::raw('YEAR(created_at)'), '=', $year)->first();
 }