diff --git a/app/Jobs/Document/CopyDocs.php b/app/Jobs/Document/CopyDocs.php new file mode 100644 index 000000000000..98e5003a8d21 --- /dev/null +++ b/app/Jobs/Document/CopyDocs.php @@ -0,0 +1,85 @@ +db); + + Document::whereIn('id', $this->document_ids) + ->where('company_id', $this->entity->company_id) + ->each(function ($document){ + + $file = $document->getFile(); + + $extension = pathinfo($document->name, PATHINFO_EXTENSION); + + $new_hash = \Illuminate\Support\Str::random(32) . "." . $extension; + + Storage::disk($document->disk)->put( + "{$this->entity->company->company_key}/documents/{$new_hash}", + $file, + ); + + $instance = Storage::disk($document->disk)->path("{$this->entity->company->company_key}/documents/{$new_hash}"); + + $new_doc = new Document(); + $new_doc->user_id = $this->entity->user_id; + $new_doc->company_id = $this->entity->company_id; + $new_doc->url = $instance; + $new_doc->name = $document->name; + $new_doc->type = $extension; + $new_doc->disk = $document->disk; + $new_doc->hash = $new_hash; + $new_doc->size = $document->size; + $new_doc->width = $document->width; + $new_doc->height = $document->height; + $new_doc->is_public = $document->is_public; + + $this->entity->documents()->save($new_doc); + + }); + } + +} diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index 2118386d664f..8c4bea787849 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -103,13 +103,6 @@ class Statement ], \App\Services\PdfMaker\Design::STATEMENT), 'variables' => $variables, 'options' => [ - // 'client' => $this->client, - // 'entity' => $this->entity, - // 'variables' => $variables, - // 'invoices' => $this->getInvoices()->cursor(), - // 'payments' => $this->getPayments()->cursor(), - // 'credits' => $this->getCredits()->cursor(), - // 'aging' => $this->getAging(), ], 'process_markdown' => $this->entity->client->company->markdown_enabled, ]; diff --git a/app/Services/Quote/ConvertQuote.php b/app/Services/Quote/ConvertQuote.php index c0ce4abe1562..97c1e18e8641 100644 --- a/app/Services/Quote/ConvertQuote.php +++ b/app/Services/Quote/ConvertQuote.php @@ -12,13 +12,15 @@ namespace App\Services\Quote; -use App\Factory\CloneQuoteToInvoiceFactory; -use App\Factory\InvoiceInvitationFactory; -use App\Models\Invoice; use App\Models\Quote; -use App\Repositories\InvoiceRepository; -use App\Utils\Traits\GeneratesConvertedQuoteCounter; +use App\Models\Invoice; +use App\Jobs\Util\UploadFile; use App\Utils\Traits\MakesHash; +use App\Repositories\InvoiceRepository; +use App\Factory\InvoiceInvitationFactory; +use App\Factory\CloneQuoteToInvoiceFactory; +use App\Jobs\Document\CopyDocs; +use App\Utils\Traits\GeneratesConvertedQuoteCounter; class ConvertQuote { @@ -73,7 +75,9 @@ class ConvertQuote $quote->status_id = Quote::STATUS_CONVERTED; $quote->save(); - // maybe should return invoice here + if($quote->documents()->count() > 0) + CopyDocs::dispatch($quote->documents()->pluck('id'), $invoice, $invoice->company->db); + return $invoice; }