2021-10-03 12:51:42 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2022-04-27 05:20:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-10-03 12:51:42 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs\Cron;
|
|
|
|
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2022-08-07 08:47:37 +02:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2021-10-03 12:51:42 +02:00
|
|
|
|
2022-08-07 08:47:37 +02:00
|
|
|
class AutoBill implements ShouldQueue
|
2021-10-03 12:51:42 +02:00
|
|
|
{
|
2022-08-07 08:47:37 +02:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
2021-10-03 12:51:42 +02:00
|
|
|
|
|
|
|
public $tries = 1;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-10-03 12:51:42 +02:00
|
|
|
public Invoice $invoice;
|
|
|
|
|
|
|
|
public string $db;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(Invoice $invoice, ?string $db)
|
|
|
|
{
|
|
|
|
$this->invoice = $invoice;
|
|
|
|
$this->db = $db;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle() : void
|
|
|
|
{
|
|
|
|
set_time_limit(0);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($this->db) {
|
2021-10-03 12:51:42 +02:00
|
|
|
MultiDB::setDb($this->db);
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-10-03 12:51:42 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
try {
|
2021-10-04 23:17:41 +02:00
|
|
|
nlog("autobill {$this->invoice->id}");
|
2021-10-03 12:51:42 +02:00
|
|
|
|
2021-12-03 07:19:24 +01:00
|
|
|
$this->invoice->service()->autoBill();
|
2022-06-21 11:57:17 +02:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
nlog("Failed to capture payment for {$this->invoice->company_id} - {$this->invoice->number} ->".$e->getMessage());
|
2021-10-03 12:51:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|