diff --git a/app/DataMapper/InvoiceItem.php b/app/DataMapper/InvoiceItem.php index 1621c8f54a33..48eb8aaa326a 100644 --- a/app/DataMapper/InvoiceItem.php +++ b/app/DataMapper/InvoiceItem.php @@ -19,6 +19,8 @@ class InvoiceItem public $product_key = ''; + public $product_cost = 0; + public $notes = ''; public $discount = 0; @@ -57,6 +59,7 @@ class InvoiceItem 'type_id' => 'string', 'quantity' => 'float', 'cost' => 'float', + 'product_cost' => 'float', 'product_key' => 'string', 'notes' => 'string', 'discount' => 'float', diff --git a/app/Http/Controllers/ClientPortal/QuoteController.php b/app/Http/Controllers/ClientPortal/QuoteController.php index 253631fc5b3f..6add1d63bc61 100644 --- a/app/Http/Controllers/ClientPortal/QuoteController.php +++ b/app/Http/Controllers/ClientPortal/QuoteController.php @@ -27,6 +27,7 @@ use Illuminate\View\View; use Symfony\Component\HttpFoundation\BinaryFileResponse; use ZipStream\Option\Archive; use ZipStream\ZipStream; +use Illuminate\Support\Facades\Storage; class QuoteController extends Controller { @@ -89,8 +90,11 @@ class QuoteController extends Controller if ($quotes->count() == 1) { - $file = $quotes->first()->pdf_file_path(); - return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + $file = $quotes->first()->service()->getQuotePdf(); + // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + return response()->streamDownload(function () use($file) { + echo Storage::get($file); + }, basename($file)); } // enable output of HTTP headers diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index dbfffc2df29a..c8fb445a4293 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -37,6 +37,7 @@ use App\Utils\TempFile; use App\Utils\Traits\MakesHash; use App\Utils\Traits\SavesDocuments; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Storage; /** * Class CreditController. @@ -536,8 +537,14 @@ class CreditController extends BaseController } break; case 'download': - $file = $credit->pdf_file_path(); - return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + // $file = $credit->pdf_file_path(); + $file = $credit->service()->getCreditPdf($credit->invitations->first()); + + // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + + return response()->streamDownload(function () use($file) { + echo Storage::get($file); + }, basename($file)); break; case 'archive': $this->credit_repository->archive($credit); @@ -585,9 +592,12 @@ class CreditController extends BaseController // $contact = $invitation->contact; $credit = $invitation->credit; - $file_path = $credit->service()->getCreditPdf($invitation); - - return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + $file = $credit->service()->getCreditPdf($invitation); + + return response()->streamDownload(function () use($file) { + echo Storage::get($file); + }, basename($file)); + // return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); } /** diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 80c00fe4e906..4917e5e55e36 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -672,8 +672,17 @@ class InvoiceController extends BaseController break; case 'download': - $file = $invoice->pdf_file_path(); - return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + // $file = $invoice->pdf_file_path(); + // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + + $file = $invoice->service()->getInvoicePdf(); + + // return response()->download(Storage::get($file), basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + + return response()->streamDownload(function () use($file) { + echo Storage::get($file); + }, basename($file)); + break; case 'restore': @@ -722,7 +731,8 @@ class InvoiceController extends BaseController } //touch reminder1,2,3_sent + last_sent here if the email is a reminder. - $invoice->service()->touchReminder($this->reminder_template)->deletePdf()->save(); + //$invoice->service()->touchReminder($this->reminder_template)->deletePdf()->save(); + $invoice->service()->touchReminder($this->reminder_template)->markSent()->save(); $invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($invoice) { EmailEntity::dispatch($invitation, $invoice->company, $this->reminder_template)->delay(now()->addSeconds(30)); @@ -795,8 +805,11 @@ class InvoiceController extends BaseController $file = $invoice->service()->getInvoicePdf($contact); - return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + // return response()->download(Storage::get($file), basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + return response()->streamDownload(function () use($file) { + echo Storage::get($file); + }, basename($file)); } /** @@ -848,7 +861,10 @@ class InvoiceController extends BaseController $file = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact); - return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + return response()->streamDownload(function () use($file) { + echo Storage::get($file); + }, basename($file)); } diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index 2619a1262e86..a867a7697168 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -39,6 +39,7 @@ use App\Utils\Traits\MakesHash; use App\Utils\Traits\SavesDocuments; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Storage; /** * Class QuoteController. @@ -676,8 +677,14 @@ class QuoteController extends BaseController break; case 'download': - $file = $quote->pdf_file_path(); - return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + //$file = $quote->pdf_file_path(); + $file = $quote->service()->getQuotePdf(); + + return response()->streamDownload(function () use($file) { + echo Storage::get($file); + }, basename($file)); + + //return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); break; case 'restore': @@ -728,9 +735,14 @@ class QuoteController extends BaseController $contact = $invitation->contact; $quote = $invitation->quote; - $file_path = $quote->service()->getQuotePdf($contact); + $file = $quote->service()->getQuotePdf($contact); +nlog($file); - return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); + return response()->streamDownload(function () use($file) { + echo Storage::get($file); + }, basename($file)); + + // return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); } /** diff --git a/app/Http/Requests/Company/UpdateCompanyRequest.php b/app/Http/Requests/Company/UpdateCompanyRequest.php index c98814bf43a1..609876cbe5ee 100644 --- a/app/Http/Requests/Company/UpdateCompanyRequest.php +++ b/app/Http/Requests/Company/UpdateCompanyRequest.php @@ -67,7 +67,7 @@ class UpdateCompanyRequest extends Request { $input = $this->all(); - if(array_key_exists('portal_domain', $input) && strlen($input['portal_domain']) > 1) + if(Ninja::isHosted() && array_key_exists('portal_domain', $input) && strlen($input['portal_domain']) > 1) $input['portal_domain'] = $this->addScheme($input['portal_domain']); if (array_key_exists('settings', $input)) { diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index 4e2fc4967077..c4a946d98720 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -86,9 +86,8 @@ class CreateEntityPdf implements ShouldQueue $this->contact = $invitation->contact; - //$this->disk = Ninja::isHosted() ? config('filesystems.default') : $disk; - $this->disk = $disk; - // $this->disk = $disk ?? config('filesystems.default'); + $this->disk = Ninja::isHosted() ? config('filesystems.default') : $disk; + } public function handle() diff --git a/app/Mail/Engine/CreditEmailEngine.php b/app/Mail/Engine/CreditEmailEngine.php index af3cf5eb2e5a..68bd72ebbc22 100644 --- a/app/Mail/Engine/CreditEmailEngine.php +++ b/app/Mail/Engine/CreditEmailEngine.php @@ -11,6 +11,7 @@ namespace App\Mail\Engine; +use App\Models\Account; use App\Utils\HtmlEngine; use App\Utils\Ninja; use App\Utils\Number; diff --git a/app/Services/Credit/GetCreditPdf.php b/app/Services/Credit/GetCreditPdf.php index f5edd2418451..10517aaa7267 100644 --- a/app/Services/Credit/GetCreditPdf.php +++ b/app/Services/Credit/GetCreditPdf.php @@ -41,10 +41,13 @@ class GetCreditPdf extends AbstractService $file_path = $path.$this->credit->numberFormatter().'.pdf'; - $disk = 'public'; + // $disk = 'public'; + $disk = config('filesystems.default'); $file_path = CreateEntityPdf::dispatchNow($this->invitation); - return Storage::disk($disk)->path($file_path); +nlog($file_path); + return $file_path; + // return Storage::disk($disk)->path($file_path); } } diff --git a/app/Services/Invoice/GenerateDeliveryNote.php b/app/Services/Invoice/GenerateDeliveryNote.php index 6a638f9676bb..b0e47753ac02 100644 --- a/app/Services/Invoice/GenerateDeliveryNote.php +++ b/app/Services/Invoice/GenerateDeliveryNote.php @@ -49,9 +49,9 @@ class GenerateDeliveryNote $this->contact = $contact; - $this->disk = 'public'; + // $this->disk = 'public'; - // $this->disk = $disk ?? config('filesystems.default'); + $this->disk = $disk ?? config('filesystems.default'); } public function run() @@ -111,7 +111,8 @@ class GenerateDeliveryNote Storage::disk($this->disk)->put($file_path, $pdf); - return Storage::disk($this->disk)->path($file_path); + //return Storage::disk($this->disk)->path($file_path); + return $file_path; } } diff --git a/app/Services/Invoice/GetInvoicePdf.php b/app/Services/Invoice/GetInvoicePdf.php index 6438bdfff2c5..9f519cab7fbe 100644 --- a/app/Services/Invoice/GetInvoicePdf.php +++ b/app/Services/Invoice/GetInvoicePdf.php @@ -39,7 +39,8 @@ class GetInvoicePdf extends AbstractService $file_path = $path.$this->invoice->numberFormatter().'.pdf'; - $disk = 'public'; + // $disk = 'public'; + $disk = config('filesystems.default'); $file = Storage::disk($disk)->exists($file_path); @@ -47,6 +48,8 @@ class GetInvoicePdf extends AbstractService $file_path = CreateEntityPdf::dispatchNow($invitation); } - return Storage::disk($disk)->path($file_path); + // return Storage::disk($disk)->path($file_path); + // + return $file_path; } } diff --git a/app/Services/Quote/GetQuotePdf.php b/app/Services/Quote/GetQuotePdf.php index 7b27c6d43e18..d904ea7029f4 100644 --- a/app/Services/Quote/GetQuotePdf.php +++ b/app/Services/Quote/GetQuotePdf.php @@ -39,10 +39,12 @@ class GetQuotePdf extends AbstractService $file_path = $path.$this->quote->numberFormatter().'.pdf'; - $disk = 'public'; - + // $disk = 'public'; + $disk = config('filesystems.default'); + $file_path = CreateEntityPdf::dispatchNow($invitation); - return Storage::disk($disk)->path($file_path); + return $file_path; + //return Storage::disk($disk)->path($file_path); } }