2022-11-11 05:28:49 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2022-11-11 05:28:49 +01:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Services\Bank;
|
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
use App\Factory\ExpenseCategoryFactory;
|
|
|
|
use App\Factory\ExpenseFactory;
|
2022-11-11 05:28:49 +01:00
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use App\Models\BankTransaction;
|
|
|
|
use App\Models\Company;
|
2022-11-20 03:12:33 +01:00
|
|
|
use App\Models\ExpenseCategory;
|
2022-11-11 05:28:49 +01:00
|
|
|
use App\Models\Invoice;
|
2022-11-20 03:55:19 +01:00
|
|
|
use App\Services\Bank\BankService;
|
2022-11-20 03:12:33 +01:00
|
|
|
use App\Utils\Traits\GeneratesCounter;
|
2022-11-11 05:28:49 +01:00
|
|
|
use Illuminate\Bus\Queueable;
|
2022-12-19 06:31:23 +01:00
|
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
2022-11-11 05:28:49 +01:00
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
2022-11-20 03:12:33 +01:00
|
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
2022-11-11 05:28:49 +01:00
|
|
|
use Illuminate\Queue\SerializesModels;
|
2022-11-20 03:12:33 +01:00
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-11-11 05:28:49 +01:00
|
|
|
|
2023-01-16 01:59:24 +01:00
|
|
|
class BankMatchingService implements ShouldQueue
|
2022-11-11 05:28:49 +01:00
|
|
|
{
|
2022-11-27 09:03:28 +01:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
2022-11-11 05:28:49 +01:00
|
|
|
|
2023-01-15 21:54:49 +01:00
|
|
|
public function __construct(public $company_id, public $db){}
|
2022-11-11 05:28:49 +01:00
|
|
|
|
2022-11-27 09:03:28 +01:00
|
|
|
public function handle() :void
|
2022-11-11 05:28:49 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
MultiDB::setDb($this->db);
|
|
|
|
|
2022-11-27 09:03:28 +01:00
|
|
|
BankTransaction::where('company_id', $this->company_id)
|
2022-11-20 03:12:33 +01:00
|
|
|
->where('status_id', BankTransaction::STATUS_UNMATCHED)
|
|
|
|
->cursor()
|
|
|
|
->each(function ($bt){
|
|
|
|
|
2022-11-20 03:55:19 +01:00
|
|
|
(new BankService($bt))->processRules();
|
2022-11-20 03:12:33 +01:00
|
|
|
|
|
|
|
});
|
2022-11-27 09:03:28 +01:00
|
|
|
|
2022-11-11 05:28:49 +01:00
|
|
|
}
|
|
|
|
|
2022-12-19 06:31:23 +01:00
|
|
|
/**
|
|
|
|
* The unique ID of the job.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function uniqueId()
|
2022-11-27 09:12:00 +01:00
|
|
|
{
|
2022-12-19 06:31:23 +01:00
|
|
|
return (string)$this->company_id;
|
2022-11-27 09:12:00 +01:00
|
|
|
}
|
2022-12-19 06:31:23 +01:00
|
|
|
|
2022-11-11 05:28:49 +01:00
|
|
|
}
|