<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Modules\Hr\TimeLog;
use Carbon\Carbon;
class fixlunchtimes extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'lunchtimes:fix';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'addeds one second to lunch clockin';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $all = TimeLog::where('type','in')->where('lunch',true)->get();
        foreach ($all as $log) {
            //Load new instance of the object
	    $obj = TimeLog::find($log->id);
        $this->info($log->id);
        $this->info($log->time);
        $oldTime = new Carbon($log->time);
        $obj->time = $oldTime->addSeconds(1);
        $this->info($obj->time);
	    $obj->save();
        }
    }
}
