1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Updates for displaying delivery notes

This commit is contained in:
David Bomba 2023-10-04 15:29:31 +11:00
parent 09fafb46dd
commit 7055be44ba
8 changed files with 109 additions and 30 deletions

View File

@ -481,13 +481,21 @@ class CompanySettings extends BaseSettings
public $enable_e_invoice = false;
public $statement_design_id = 'VolejRejNm';
public $delivery_note_design_id = '';
public $statement_design_id = '';
public $payment_receipt_design_id = '';
public $delivery_note_design_id = 'VolejRejNm';
public $payment_refund_design_id = '';
public $classification = ''; // individual, business, partnership, trust, charity, government, other
public static $casts = [
'statement_design_id' => 'string',
'delivery_note_design_id' => 'string',
'payment_receipt_design_id' => 'string',
'payment_refund_design_id' => 'string',
'classification' => 'string',
'enable_e_invoice' => 'bool',
'default_expense_payment_type_id' => 'string',
@ -718,8 +726,6 @@ class CompanySettings extends BaseSettings
'portal_custom_js' => 'string',
'client_portal_enable_uploads' => 'bool',
'purchase_order_number_counter' => 'integer',
'statement_design_id' => 'string',
'delivery_note_design_id' => 'string',
];
public static $free_plan_casts = [

View File

@ -911,8 +911,12 @@ class InvoiceController extends BaseController
$file = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact);
return response()->streamDownload(function () use ($file) {
echo Storage::get($file);
echo $file;
}, basename($file), ['Content-Type' => 'application/pdf']);
// return response()->streamDownload(function () use ($file) {
// echo Storage::get($file);
// }, basename($file), ['Content-Type' => 'application/pdf']);
}
/**

View File

@ -16,6 +16,11 @@ use App\Models\Account;
class StoreDesignRequest extends Request
{
private array $valid_entities = [
'invoice',
];
/**
* Determine if the user is authorized to make this request.
*
@ -78,6 +83,20 @@ class StoreDesignRequest extends Request
$input['design']['body'] = '';
}
if(array_key_exists('entities', $input)) {
$user_entities = explode(",", $input['entities']);
$e = [];
foreach ($user_entities as $entity) {
if (in_array($entity, $this->valid_entities)) {
$e[] = $entity;
}
}
$input['entities'] = implode(",", $e);
}
$this->replace($input);
}
}

View File

@ -18,6 +18,10 @@ class UpdateDesignRequest extends Request
{
use ChecksEntityStatus;
private array $valid_entities = [
'invoice',
];
/**
* Determine if the user is authorized to make this request.
*
@ -67,6 +71,21 @@ class UpdateDesignRequest extends Request
$input['design']['body'] = '';
}
if(array_key_exists('entities', $input)) {
$user_entities = explode(",", $input['entities']);
$e = [];
foreach ($user_entities as $entity) {
if (in_array($entity, $this->valid_entities)) {
$e[] = $entity;
}
}
$input['entities'] = implode(",", $e);
}
$this->replace($input);
}
}

View File

@ -70,6 +70,7 @@ class Design extends BaseModel
'design',
'is_active',
'is_template',
'entities',
];
public function company()

View File

@ -17,6 +17,7 @@ use App\Models\Design;
use App\Models\Invoice;
use App\Services\PdfMaker\Design as PdfMakerDesign;
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
use App\Services\Template\TemplateService;
use App\Utils\HostedPDF\NinjaPdf;
use App\Utils\HtmlEngine;
use App\Utils\PhantomJS\Phantom;
@ -40,6 +41,22 @@ class GenerateDeliveryNote
public function run()
{
$delivery_note_design_id = $this->invoice->client->getSetting('delivery_note_design_id');
// if($design = Design::find($this->decodePrimaryKey($delivery_note_design_id)))
if($design = Design::find(15))
{
$ts = new TemplateService($design);
$pdf = $ts->build([
'invoices' => collect([$this->invoice]),
])->getPdf();
return $pdf;
}
$design_id = $this->invoice->design_id
? $this->invoice->design_id
: $this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id'));
@ -84,8 +101,6 @@ class GenerateDeliveryNote
->design($template)
->build();
// Storage::makeDirectory($this->invoice->client->invoice_filepath(), 0775);
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
} else {
@ -96,11 +111,12 @@ class GenerateDeliveryNote
info($maker->getCompiledHTML());
}
Storage::disk($this->disk)->put($file_path, $pdf);
return $pdf;
// Storage::disk($this->disk)->put($file_path, $pdf);
$maker = null;
$state = null;
return $file_path;
// return $file_path;
}
}

View File

@ -11,8 +11,6 @@
namespace App\Services\Template;
use App\Models\Task;
use App\Models\Quote;
use App\Utils\Number;
use App\Models\Client;
use App\Models\Credit;
@ -22,27 +20,25 @@ use App\Models\Payment;
use App\Models\Project;
use App\Utils\HtmlEngine;
use League\Fractal\Manager;
use App\Models\ClientContact;
use App\Models\PurchaseOrder;
use App\Utils\VendorHtmlEngine;
use App\Utils\PaymentHtmlEngine;
use App\Utils\Traits\MakesDates;
use App\Utils\HostedPDF\NinjaPdf;
use Twig\Extra\Intl\IntlExtension;
use App\Transformers\TaskTransformer;
use App\Transformers\QuoteTransformer;
use App\Services\Template\TemplateMock;
use App\Transformers\CreditTransformer;
use App\Transformers\InvoiceTransformer;
use App\Transformers\PaymentTransformer;
use App\Transformers\ProjectTransformer;
use App\Services\Template\LogoTokenParser;
use App\Transformers\PurchaseOrderTransformer;
use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Serializer\JsonApiSerializer;
use App\Utils\Traits\Pdf\PdfMaker;
class TemplateService
{
use MakesDates;
use MakesDates, PdfMaker;
private \DomDocument $document;
@ -131,6 +127,19 @@ class TemplateService
return $this->compiled_html;
}
public function getPdf(): mixed
{
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
$pdf = (new NinjaPdf())->build($this->compiled_html);
} else {
$pdf = $this->makePdf(null, null, $this->compiled_html);
}
return $pdf;
}
private function processData($data): self
{
@ -318,10 +327,14 @@ class TemplateService
$invoices = collect($invoices)
->map(function ($invoice){
$payments = $invoice->payments->map(function ($payment) {
// nlog(microtime(true));
return $this->transformPayment($payment);
})->toArray();
$payments = [];
nlog($invoice);
if($invoice->payments) {
$payments = $invoice->payments->map(function ($payment) {
// nlog(microtime(true));
return $this->transformPayment($payment);
})->toArray();
}
return [
'amount' => Number::formatMoney($invoice->amount, $invoice->client),
@ -391,12 +404,12 @@ class TemplateService
{
return collect($items)->map(function ($item) use ($client){
$item->cost_raw = $item->cost;
$item->discount_raw = $item->discount;
$item->line_total_raw = $item->line_total;
$item->gross_line_total_raw = $item->gross_line_total;
$item->tax_amount_raw = $item->tax_amount;
$item->product_cost_raw = $item->product_cost;
$item->cost_raw = $item->cost ?? 0;
$item->discount_raw = $item->discount ?? 0;
$item->line_total_raw = $item->line_total ?? 0;
$item->gross_line_total_raw = $item->gross_line_total ?? 0;
$item->tax_amount_raw = $item->tax_amount ?? 0;
$item->product_cost_raw = $item->product_cost ?? 0;
$item->cost = Number::formatMoney($item->cost_raw, $client);

View File

@ -324,7 +324,7 @@ class TemplateTest extends TestCase
nlog("query count = {$count}");
$x = $invoices->toArray();
nlog(json_encode($x));
// nlog(json_encode($x));
// nlog(json_encode(htmlspecialchars(json_encode($x), ENT_QUOTES, 'UTF-8')));
// nlog($invoices->toJson());
@ -337,8 +337,8 @@ class TemplateTest extends TestCase
private function transformPayment(Payment $payment): array
{
$data = [];
$data = [];
$credits = $payment->credits->map(function ($credit) use ($payment) {
return [
'credit' => $credit->number,
@ -401,11 +401,12 @@ class TemplateTest extends TestCase
],
'paymentables' => $pivot,
];
return $data;
}
public function testVariableResolutionViaTransformersForPaymentsInStatements()