<?php

namespace App\Jobs;

use App\RejectedBill;
use App\Services\LogService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class RejectedBillCreateInstantBill implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $rejected;
    /**
     * Create a new job instance.
     *
     * @return void
     *
     * @param RejectedBill $rejectedBill
     */
    public function __construct(RejectedBill $rejectedBill)
    {
        $this->rejected = $rejectedBill;
    }

    /**
     * Execute the job.
     *
     * @return void
     * @throws
     */
    public function handle()
    {
        try{
            app("RejectedBillService")->buildInstantBill($this->rejected);
        }catch(\Exception $exception){
            LogService::log(__CLASS__,"退货单建立即时账单",$exception->getMessage()." | ".json_encode($this->rejected));
            throw new \Exception($e->getMessage());
        }
    }
}
