Invoice upload by robot
This commit is contained in:
8
app/Tasks/CronTask.php
Normal file
8
app/Tasks/CronTask.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tasks;
|
||||
|
||||
interface CronTask
|
||||
{
|
||||
public function handle(): void;
|
||||
}
|
||||
31
app/Tasks/UploadInvoices.php
Normal file
31
app/Tasks/UploadInvoices.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tasks;
|
||||
|
||||
use App\Domains\Invoice\Actions\UploadInvoice\UploadInvoiceCommand;
|
||||
use App\Domains\Invoice\Actions\UploadInvoice\UploadInvoiceRequest;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class UploadInvoices implements CronTask {
|
||||
public function handle(): void
|
||||
{
|
||||
if (!app('tenant')->upload_exports) {
|
||||
return;
|
||||
}
|
||||
|
||||
$invoiceRepository = new InvoiceRepository();
|
||||
foreach ($invoiceRepository->getUnexportedInvoices() as $invoice) {
|
||||
app('taskLogger')->info("Uploading invoice {$invoice->invoice_number}");
|
||||
$request = new UploadInvoiceRequest($invoice);
|
||||
$command = new UploadInvoiceCommand($request);
|
||||
if ($command->execute()->success) {
|
||||
app('taskLogger')->info('Upload successful');
|
||||
} else {
|
||||
app('taskLogger')->error('Upload failed');
|
||||
}
|
||||
|
||||
app('taskLogger')->info('------------------------------------');
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user