mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Merge support for purchase order PDF generation
This commit is contained in:
parent
6458406128
commit
e8100ac1c3
@ -24,6 +24,7 @@ use App\Http\Requests\PurchaseOrder\ShowPurchaseOrderRequest;
|
||||
use App\Http\Requests\PurchaseOrder\StorePurchaseOrderRequest;
|
||||
use App\Http\Requests\PurchaseOrder\UpdatePurchaseOrderRequest;
|
||||
use App\Http\Requests\PurchaseOrder\UploadPurchaseOrderRequest;
|
||||
use App\Jobs\Entity\CreateRawPdf;
|
||||
use App\Jobs\PurchaseOrder\PurchaseOrderEmail;
|
||||
use App\Jobs\PurchaseOrder\ZipPurchaseOrders;
|
||||
use App\Models\Account;
|
||||
@ -513,7 +514,8 @@ class PurchaseOrderController extends BaseController
|
||||
|
||||
if ($action == 'bulk_print' && $user->can('view', $purchase_orders->first())) {
|
||||
$paths = $purchase_orders->map(function ($purchase_order) {
|
||||
return (new \App\Jobs\Vendor\CreatePurchaseOrderPdf($purchase_order->invitations->first()))->rawPdf();
|
||||
return (new CreateRawPdf($purchase_order->invitations->first()))->handle();
|
||||
// return (new \App\Jobs\Vendor\CreatePurchaseOrderPdf($purchase_order->invitations->first()))->rawPdf();
|
||||
});
|
||||
|
||||
$merge = (new PdfMerge($paths->toArray()))->run();
|
||||
@ -622,8 +624,8 @@ class PurchaseOrderController extends BaseController
|
||||
$file = $purchase_order->service()->getPurchaseOrderPdf();
|
||||
|
||||
return response()->streamDownload(function () use ($file) {
|
||||
echo Storage::get($file);
|
||||
}, basename($file), ['Content-Type' => 'application/pdf']);
|
||||
echo $file;
|
||||
}, $purchase_order->numberFormatter().".pdf", ['Content-Type' => 'application/pdf']);
|
||||
|
||||
break;
|
||||
case 'restore':
|
||||
@ -827,7 +829,7 @@ class PurchaseOrderController extends BaseController
|
||||
}
|
||||
|
||||
return response()->streamDownload(function () use ($file) {
|
||||
echo Storage::get($file);
|
||||
}, basename($file), $headers);
|
||||
echo $file;
|
||||
}, $purchase_order->numberFormatter().".pdf", $headers);
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class CreateRawPdf
|
||||
/**
|
||||
* @param $invitation
|
||||
*/
|
||||
public function __construct($invitation)
|
||||
public function __construct($invitation, private ?string $type = null)
|
||||
{
|
||||
|
||||
$this->invitation = $invitation;
|
||||
@ -83,16 +83,36 @@ class CreateRawPdf
|
||||
$this->contact = $invitation->contact;
|
||||
}
|
||||
|
||||
private function resolveType(): string
|
||||
{
|
||||
if($this->type)
|
||||
return $this->type;
|
||||
|
||||
$type = 'product';
|
||||
|
||||
match($this->entity_string) {
|
||||
'purchase_order' => $type = 'purchase_order',
|
||||
'invoice' => $type = 'product',
|
||||
'quote' => $type = 'product',
|
||||
'credit' => $type = 'product',
|
||||
'recurring_invoice' => $type = 'product',
|
||||
};
|
||||
|
||||
return $type;
|
||||
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
/** Testing this override to improve PDF generation performance */
|
||||
$ps = new PdfService($this->invitation, 'product', [
|
||||
$ps = new PdfService($this->invitation, $this->resolveType(), [
|
||||
'client' => $this->entity->client ?? false,
|
||||
'vendor' => $this->entity->vendor ?? false,
|
||||
"{$this->entity_string}s" => [$this->entity],
|
||||
]);
|
||||
|
||||
$pdf = $ps->boot()->getPdf();
|
||||
return $pdf;
|
||||
nlog("pdf timer = ". $ps->execution_time);
|
||||
|
||||
/* Forget the singleton*/
|
||||
|
49
app/Jobs/Vendor/CreatePurchaseOrderPdf.php
vendored
49
app/Jobs/Vendor/CreatePurchaseOrderPdf.php
vendored
@ -11,28 +11,29 @@
|
||||
|
||||
namespace App\Jobs\Vendor;
|
||||
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Utils\Ninja;
|
||||
use App\Models\Design;
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\VendorHtmlEngine;
|
||||
use App\Services\Pdf\PdfService;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Utils\HostedPDF\NinjaPdf;
|
||||
use App\Utils\Traits\Pdf\PdfMaker;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use App\Utils\Traits\NumberFormatter;
|
||||
use App\Utils\Traits\MakesInvoiceHtml;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Utils\Traits\Pdf\PageNumbering;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\Services\PdfMaker\Design as PdfDesignModel;
|
||||
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
||||
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
|
||||
use App\Utils\HostedPDF\NinjaPdf;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\MakesInvoiceHtml;
|
||||
use App\Utils\Traits\NumberFormatter;
|
||||
use App\Utils\Traits\Pdf\PageNumbering;
|
||||
use App\Utils\Traits\Pdf\PdfMaker;
|
||||
use App\Utils\VendorHtmlEngine;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class CreatePurchaseOrderPdf implements ShouldQueue
|
||||
{
|
||||
@ -79,6 +80,18 @@ class CreatePurchaseOrderPdf implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
/** Testing this override to improve PDF generation performance */
|
||||
$ps = new PdfService($this->invitation, 'product', [
|
||||
'client' => $this->entity->client ?? false,
|
||||
'vendor' => $this->entity->vendor ?? false,
|
||||
"{$this->entity_string}s" => [$this->entity],
|
||||
]);
|
||||
|
||||
nlog("returning purchase order");
|
||||
|
||||
return $ps->boot()->getPdf();
|
||||
|
||||
|
||||
$pdf = $this->rawPdf();
|
||||
|
||||
if ($pdf) {
|
||||
|
@ -35,19 +35,21 @@ class GetPurchaseOrderPdf extends AbstractService
|
||||
$invitation = $this->purchase_order->invitations()->first();
|
||||
}
|
||||
|
||||
$path = $this->purchase_order->vendor->purchase_order_filepath($invitation);
|
||||
return (new CreatePurchaseOrderPdf($invitation))->handle();
|
||||
|
||||
$file_path = $path.$this->purchase_order->numberFormatter().'.pdf';
|
||||
// $path = $this->purchase_order->vendor->purchase_order_filepath($invitation);
|
||||
|
||||
// $disk = 'public';
|
||||
$disk = config('filesystems.default');
|
||||
// $file_path = $path.$this->purchase_order->numberFormatter().'.pdf';
|
||||
|
||||
$file = Storage::disk($disk)->exists($file_path);
|
||||
// // $disk = 'public';
|
||||
// $disk = config('filesystems.default');
|
||||
|
||||
if (! $file) {
|
||||
$file_path = (new CreatePurchaseOrderPdf($invitation))->handle();
|
||||
}
|
||||
// $file = Storage::disk($disk)->exists($file_path);
|
||||
|
||||
return $file_path;
|
||||
// if (! $file) {
|
||||
// $file_path = (new CreatePurchaseOrderPdf($invitation))->handle();
|
||||
// }
|
||||
|
||||
// return $file_path;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user