Add new functions to Quote and PO-Service

This commit is contained in:
Lars Kusch 2024-03-10 15:23:52 +01:00
parent 99d6ac5a70
commit 8c06698980
4 changed files with 58 additions and 3 deletions

View File

@ -754,7 +754,7 @@ class Client extends BaseModel implements HasLocalePreference
return $this->company->company_key.'/'.$this->client_hash.'/'.$contact_key.'/invoices/';
}
public function e_invoice_filepath($invitation): string
public function e_document_filepath($invitation): string
{
$contact_key = $invitation->contact->contact_key;

View File

@ -409,12 +409,12 @@ class InvoiceService
$this->invoice->invitations->each(function ($invitation) {
try {
// if (Storage::disk(config('filesystems.default'))->exists($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"))) {
Storage::disk(config('filesystems.default'))->delete($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"));
Storage::disk(config('filesystems.default'))->delete($this->invoice->client->e_document_filepath($invitation).$this->invoice->getFileName("xml"));
// }
// if (Ninja::isHosted() && Storage::disk('public')->exists($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"))) {
if (Ninja::isHosted()) {
Storage::disk('public')->delete($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"));
Storage::disk('public')->delete($this->invoice->client->e_document_filepath($invitation).$this->invoice->getFileName("xml"));
}
} catch (\Exception $e) {
nlog($e->getMessage());

View File

@ -11,7 +11,9 @@
namespace App\Services\PurchaseOrder;
use App\Jobs\EDocument\CreateEDocument;
use App\Models\PurchaseOrder;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
class PurchaseOrderService
@ -75,6 +77,32 @@ class PurchaseOrderService
return (new GetPurchaseOrderPdf($this->purchase_order, $contact))->run();
}
public function getEPurchaseOrder($contact = null)
{
return (new CreateEDocument($this->purchase_order))->handle();
}
public function deleteEPurchaseOrder()
{
$this->purchase_order->load('invitations');
$this->purchase_order->invitations->each(function ($invitation) {
try {
// if (Storage::disk(config('filesystems.default'))->exists($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"))) {
Storage::disk(config('filesystems.default'))->delete($this->purchase_order->client->e_document_filepath($invitation).$this->purchase_order->getFileName("xml"));
// }
// if (Ninja::isHosted() && Storage::disk('public')->exists($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"))) {
if (Ninja::isHosted()) {
Storage::disk('public')->delete($this->purchase_order->client->e_document_filepath($invitation).$this->purchase_order->getFileName("xml"));
}
} catch (\Exception $e) {
nlog($e->getMessage());
}
});
return $this;
}
public function setStatus($status)
{
$this->purchase_order->status_id = $status;

View File

@ -13,6 +13,7 @@ namespace App\Services\Quote;
use App\Events\Quote\QuoteWasApproved;
use App\Exceptions\QuoteConversion;
use App\Jobs\EDocument\CreateEDocument;
use App\Models\Project;
use App\Models\Quote;
use App\Repositories\QuoteRepository;
@ -72,6 +73,11 @@ class QuoteService
return (new GetQuotePdf($this->quote, $contact))->run();
}
public function getEQuote($contact = null)
{
return (new CreateEDocument($this->quote))->handle();
}
public function sendEmail($contact = null): self
{
$send_email = new SendEmail($this->quote, null, $contact);
@ -226,6 +232,27 @@ class QuoteService
return $this;
}
public function deleteEQuote()
{
$this->quote->load('invitations');
$this->quote->invitations->each(function ($invitation) {
try {
// if (Storage::disk(config('filesystems.default'))->exists($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"))) {
Storage::disk(config('filesystems.default'))->delete($this->quote->client->e_document_filepath($invitation).$this->quote->getFileName("xml"));
// }
// if (Ninja::isHosted() && Storage::disk('public')->exists($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"))) {
if (Ninja::isHosted()) {
Storage::disk('public')->delete($this->quote->client->e_document_filepath($invitation).$this->quote->getFileName("xml"));
}
} catch (\Exception $e) {
nlog($e->getMessage());
}
});
return $this;
}
/**
* Saves the quote.