mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Page numbering for PDFs
This commit is contained in:
parent
bdb08bf93a
commit
51455cacef
@ -74,7 +74,7 @@ class CheckData extends Command
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'ninja:check-data {--database=} {--fix=} {--client_id=} {--vendor_id=} {--paid_to_date=} {--client_balance=} {--ledger_balance=}';
|
||||
protected $signature = 'ninja:check-data {--database=} {--fix=} {--client_id=} {--vendor_id=} {--paid_to_date=} {--client_balance=} {--ledger_balance=} {--balance_status=}';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@ -89,6 +89,9 @@ class CheckData extends Command
|
||||
|
||||
protected $wrong_balances = 0;
|
||||
|
||||
protected $wrong_paid_status = 0;
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$time_start = microtime(true);
|
||||
@ -109,6 +112,7 @@ class CheckData extends Command
|
||||
$this->checkVendorContacts();
|
||||
$this->checkEntityInvitations();
|
||||
$this->checkCompanyData();
|
||||
$this->checkBalanceVsPaidStatus();
|
||||
|
||||
if(Ninja::isHosted())
|
||||
$this->checkAccountStatuses();
|
||||
@ -856,4 +860,44 @@ class CheckData extends Command
|
||||
});
|
||||
}
|
||||
|
||||
public function checkBalanceVsPaidStatus()
|
||||
{
|
||||
$this->wrong_paid_status = 0;
|
||||
|
||||
foreach(Invoice::with(['payments'])->whereHas('payments')->where('status_id', 4)->where('balance', '>', 0)->where('is_deleted',0)->cursor() as $invoice)
|
||||
{
|
||||
|
||||
$this->logMessage("# {$invoice->id} " . ' - '.$invoice->number." - Marked as paid, but balance = {$invoice->balance}");
|
||||
|
||||
if($this->option('balance_status')){
|
||||
|
||||
$val = $invoice->balance;
|
||||
|
||||
$invoice->balance = 0;
|
||||
$invoice->paid_to_date=$val;
|
||||
$invoice->save();
|
||||
|
||||
$p = $invoice->payments->first();
|
||||
|
||||
if($p && (int)$p->amount == 0)
|
||||
{
|
||||
$p->amount = $val;
|
||||
$p->applied = $val;
|
||||
$p->save();
|
||||
|
||||
$pivot = $p->paymentables->first();
|
||||
$pivot->amount = $val;
|
||||
$pivot->save();
|
||||
}
|
||||
|
||||
|
||||
$this->logMessage("Fixing {$invoice->id} settings payment to {$val}");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->logMessage($this->wrong_paid_status." wrong invoices with bad balance state");
|
||||
|
||||
}
|
||||
}
|
@ -249,6 +249,9 @@ class CompanySettings extends BaseSettings
|
||||
public $primary_color = '#298AAB';
|
||||
public $secondary_color = '#7081e0';
|
||||
|
||||
public $page_numbering = false;
|
||||
public $page_numbering_alignment = 'C'; //C,R,L
|
||||
|
||||
public $hide_paid_to_date = false; //@TODO where?
|
||||
public $embed_documents = false; //@TODO where?
|
||||
public $all_pages_header = false; //@deprecated 31-05-2021
|
||||
@ -274,6 +277,7 @@ class CompanySettings extends BaseSettings
|
||||
public $auto_archive_invoice_cancelled = false;
|
||||
|
||||
public static $casts = [
|
||||
'page_numbering' => 'bool',
|
||||
'auto_archive_invoice_cancelled' => 'bool',
|
||||
'email_from_name' => 'string',
|
||||
'show_all_tasks_client_portal' => 'string',
|
||||
|
@ -34,6 +34,8 @@ 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\PDF;
|
||||
use App\Utils\Traits\Pdf\PdfMaker;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -43,10 +45,11 @@ use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use setasign\Fpdi\PdfParser\StreamReader;
|
||||
|
||||
class CreateEntityPdf implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash, PageNumbering;
|
||||
|
||||
public $entity;
|
||||
|
||||
@ -102,6 +105,7 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
/* Forget the singleton*/
|
||||
@ -186,9 +190,15 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){
|
||||
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
|
||||
$pdf = $this->pageNumbering($pdf, $this->company);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||
|
||||
$pdf = $this->pageNumbering($pdf, $this->company);
|
||||
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@ -203,10 +213,10 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
try{
|
||||
|
||||
if(!Storage::disk($this->disk)->exists($path))
|
||||
|
||||
if(!Storage::disk($this->disk)->exists($path))
|
||||
Storage::disk($this->disk)->makeDirectory($path, 0775);
|
||||
Storage::disk($this->disk)->put($file_path, $pdf, 'public');
|
||||
|
||||
Storage::disk($this->disk)->put($file_path, $pdf, 'public');
|
||||
|
||||
}
|
||||
catch(\Exception $e)
|
||||
@ -216,7 +226,7 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $file_path;
|
||||
}
|
||||
|
||||
@ -225,4 +235,5 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace App\Jobs\Util;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Utils\Traits\Pdf\PageNumbering;
|
||||
use App\Utils\Traits\Pdf\PdfMaker;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -21,7 +22,7 @@ use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class PreviewPdf implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PdfMaker;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PdfMaker, PageNumbering;
|
||||
|
||||
public $company;
|
||||
|
||||
@ -46,6 +47,10 @@ class PreviewPdf implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
return $this->makePdf(null, null, $this->design_string);
|
||||
$pdf = $this->makePdf(null, null, $this->design_string);
|
||||
|
||||
$pdf = $this->pageNumbering($pdf, $this->company);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Models\Language;
|
||||
use App\Models\Presenters\CompanyPresenter;
|
||||
use App\Models\User;
|
||||
@ -402,6 +403,12 @@ class Company extends BaseModel
|
||||
return $this->settings->{$setting};
|
||||
}
|
||||
|
||||
$cs = CompanySettings::defaults();
|
||||
|
||||
if (property_exists($cs, $setting) != false) {
|
||||
return $cs->{$setting};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Utils\Traits\Pdf;
|
||||
|
||||
@ -7,17 +16,26 @@ use setasign\Fpdi\Fpdi;
|
||||
class PDF extends FPDI
|
||||
{
|
||||
|
||||
public $text_alignment = 'L';
|
||||
|
||||
function Footer()
|
||||
{
|
||||
// Position at 1.5 cm from bottom
|
||||
// $this->SetY(-7);
|
||||
// $this->SetX(-50);
|
||||
|
||||
$this->SetXY(0, -5);
|
||||
|
||||
// Arial italic 8
|
||||
$this->SetFont('Arial','I',8);
|
||||
// Page number
|
||||
$this->Cell(0,5, ctrans('texts.page').' '.$this->PageNo().'/{nb}',0,0,'C');
|
||||
$this->SetFont('Arial','I',9);
|
||||
|
||||
$trans = ctrans('texts.pdf_page_info', ['current' => $this->PageNo(), 'total' => '{nb}']);
|
||||
|
||||
$this->Cell(0,5, $trans ,0,0, $this->text_alignment);
|
||||
|
||||
}
|
||||
|
||||
public function setAlignment($alignment)
|
||||
{
|
||||
$this->text_alignment = $alignment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
@ -11,37 +10,43 @@
|
||||
*/
|
||||
|
||||
namespace App\Utils\Traits\Pdf;
|
||||
|
||||
use App\Utils\Traits\Pdf\PDF;
|
||||
use setasign\Fpdi\PdfParser\StreamReader;
|
||||
|
||||
trait PageNumbering
|
||||
{
|
||||
|
||||
public function pageNumbers($pdf_data_object)
|
||||
{
|
||||
|
||||
// initiate PDF
|
||||
$pdf = new PDF();
|
||||
private function pageNumbering($pdf_data_object, $company)
|
||||
{
|
||||
|
||||
// set the source file
|
||||
$pageCount = $pdf->setSourceFile(StreamReader::createByString($pdf_data_object));
|
||||
try
|
||||
{
|
||||
$pdf = new PDF();
|
||||
|
||||
$pdf->AliasNbPages();
|
||||
for ($i=1; $i <= $pageCount; $i++) {
|
||||
//import a page then get the id and will be used in the template
|
||||
$tplId = $pdf->importPage($i);
|
||||
$pdf->setAlignment($company->getSetting('page_numbering_alignment'));
|
||||
|
||||
//create a page
|
||||
$templateSize = $pdf->getTemplateSize($tplId);
|
||||
$pdf->AddPage('', [$templateSize['width'], $templateSize['height']]);
|
||||
$pageCount = $pdf->setSourceFile(StreamReader::createByString($pdf_data_object));
|
||||
|
||||
$pdf->useTemplate($tplId);
|
||||
}
|
||||
|
||||
|
||||
return $pdf->Output();
|
||||
$pdf->AliasNbPages();
|
||||
|
||||
}
|
||||
for ($i=1; $i <= $pageCount; $i++) {
|
||||
//import a page then get the id and will be used in the template
|
||||
$tplId = $pdf->importPage($i);
|
||||
|
||||
}
|
||||
//create a page
|
||||
$templateSize = $pdf->getTemplateSize($tplId);
|
||||
|
||||
$pdf->AddPage($templateSize['orientation'], [$templateSize['width'], $templateSize['height']]);
|
||||
|
||||
$pdf->useTemplate($tplId);
|
||||
}
|
||||
|
||||
ob_end_flush();
|
||||
return $pdf->Output();
|
||||
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
nlog($e->getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ trait PdfMaker
|
||||
if($generated)
|
||||
return $generated;
|
||||
|
||||
|
||||
throw new InternalPDFFailure('There was an issue generating the PDF locally');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user