<?php

namespace App\Jobs;

use App\TransactionOnlineLog;
use Carbon\Carbon                                                                           ;

class CleanTransactionOnlineLogJob extends Job
{
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
      $numberOfMonthDeletedBack = 3;
       
      $logger = app('job_log');
      $logger->info('Cleaning Transaction Online Log');
      
      try {
      TransactionOnlineLog::where('created_at', '<', Carbon::now()->subMonths($numberOfMonthDeletedBack))->get()->each(function ($log) use($logger) {
            $logger->info('Deleting Transaction Online Log : ' . $log->id);
            $log->delete();
        });
      } catch (\Exception $e) {
        $logger->error($e);
        throw $e;
      }
    }
}
