Invoice upload by robot
This commit is contained in:
@@ -40,7 +40,7 @@ class ChangeStatusCommand {
|
||||
$this->request->invoice->status = InvoiceStatus::INVOICE_STATUS_DELETED;
|
||||
break;
|
||||
case InvoiceStatus::INVOICE_STATUS_EXPORTED:
|
||||
//$this->request->invoice->status = InvoiceStatus::INVOICE_STATUS_EXPORTED;
|
||||
$this->request->invoice->status = InvoiceStatus::INVOICE_STATUS_EXPORTED;
|
||||
$this->request->invoice->upload_required = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Invoice\Actions\UploadInvoice;
|
||||
|
||||
use App\Domains\Invoice\Actions\CreateInvoiceReceipt\CreateInvoiceReceiptCommand;
|
||||
use App\Domains\Invoice\Actions\CreateInvoiceReceipt\CreateInvoiceReceiptRequest;
|
||||
use App\Providers\WebDavProvider;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UploadInvoiceCommand {
|
||||
private UploadInvoiceRequest $request;
|
||||
public function __construct(UploadInvoiceRequest $request) {
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function execute() : UploadInvoiceResponse {
|
||||
$uploadResponse = new UploadInvoiceResponse();
|
||||
|
||||
$uploadDir = sprintf(
|
||||
'%1$s%2$s/%3$s',
|
||||
WebDavProvider::INVOICE_PREFIX,
|
||||
app('tenant')->url,
|
||||
$this->request->invoice->costUnit()->first()->name
|
||||
);
|
||||
|
||||
$webDavProvider = new WebDavProvider($uploadDir);
|
||||
|
||||
$createInvoiceReceiptRequest = new CreateInvoiceReceiptRequest($this->request->invoice);
|
||||
$createInvoiceReceiptCommand = new CreateInvoiceReceiptCommand($createInvoiceReceiptRequest);
|
||||
$response = $createInvoiceReceiptCommand->execute();
|
||||
if ('' === $response->fileName) {
|
||||
app('taskLogger')->error('PDF oder ZIP zur Abrechnung konnte nicht erstellt werden.');
|
||||
return $uploadResponse;
|
||||
}
|
||||
|
||||
if ($webDavProvider->uploadFile($response->fileName)) {
|
||||
$this->request->invoice->upload_required = false;
|
||||
$this->request->invoice->save();
|
||||
$uploadResponse->success = true;
|
||||
} else {
|
||||
app('taskLogger')->error('PDF oder ZIP zur Abrechnung konnte nicht hochgeladen werden.');
|
||||
}
|
||||
|
||||
if (Storage::exists($response->fileName)) {
|
||||
Storage::delete($response->fileName);
|
||||
}
|
||||
|
||||
return $uploadResponse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Invoice\Actions\UploadInvoice;
|
||||
|
||||
use App\Models\Invoice;
|
||||
|
||||
class UploadInvoiceRequest {
|
||||
public Invoice $invoice;
|
||||
|
||||
public function __construct(Invoice $invoice) {
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Invoice\Actions\UploadInvoice;
|
||||
|
||||
class UploadInvoiceResponse {
|
||||
public bool $success;
|
||||
|
||||
public function __construct() {
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user