<?php

namespace App\Console\Commands;

use Illuminate\Support\Facades\Log;
use Illuminate\Console\Command;
use App\Models\JournalizingDetails;
use App\Models\GeneralDaily;
use App\Models\Assets;
use DB ;
use DateTime;
use App\Events\AssetsMonthlyEvent;


class LifSpanAsset extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'Life:Asset';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Lif Span Asset';

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {

          try {

    DB::beginTransaction();
             // Assets Monthly Event

      AssetsMonthlyEvent::dispatch();


  DB::commit();

             }catch(\Exception $ex){

     $MODEL=Assets::class;
              DB::rollBack();
Log::channel('custom')->error(' Model => '.$MODEL.' Message => '. $ex->getMessage() ." Line => ".$ex->getLine() . "\n");

           session()->flash('error',trans('admin.There_is_Something_Wrong_Happen'));
            return back();

         }catch(\Error $ex){


             $MODEL=Assets::class;
              DB::rollBack();
Log::channel('custom')->error(' Model => '.$MODEL.' Message => '. $ex->getMessage() ." Line => ".$ex->getLine() . "\n");

        session()->flash('error',trans('admin.There_is_Something_Wrong_Happen'));
            return back();

         }


    }
}
