mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
minor fixes
This commit is contained in:
commit
d6a18a74a4
@ -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,8 @@ class CompanySettings extends BaseSettings
|
||||
public $auto_archive_invoice_cancelled = false;
|
||||
|
||||
public static $casts = [
|
||||
'page_numbering_alignment' => 'string',
|
||||
'page_numbering' => 'bool',
|
||||
'auto_archive_invoice_cancelled' => 'bool',
|
||||
'email_from_name' => 'string',
|
||||
'show_all_tasks_client_portal' => 'string',
|
||||
|
@ -17,6 +17,7 @@ use App\Transformers\ActivityTransformer;
|
||||
use App\Utils\HostedPDF\NinjaPdf;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Utils\Traits\Pdf\PageNumbering;
|
||||
use App\Utils\Traits\Pdf\PdfMaker;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@ -27,7 +28,7 @@ use stdClass;
|
||||
|
||||
class ActivityController extends BaseController
|
||||
{
|
||||
use PdfMaker;
|
||||
use PdfMaker, PageNumbering;
|
||||
|
||||
protected $entity_type = Activity::class;
|
||||
|
||||
@ -164,12 +165,35 @@ class ActivityController extends BaseController
|
||||
|
||||
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
|
||||
$pdf = (new Phantom)->convertHtmlToPdf($html_backup);
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $activity->company);
|
||||
|
||||
if($numbered_pdf)
|
||||
$pdf = $numbered_pdf;
|
||||
|
||||
|
||||
}
|
||||
elseif(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){
|
||||
$pdf = (new NinjaPdf())->build($html_backup);
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $activity->company);
|
||||
|
||||
if($numbered_pdf)
|
||||
$pdf = $numbered_pdf;
|
||||
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
$pdf = $this->makePdf(null, null, $html_backup);
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $activity->company);
|
||||
|
||||
if($numbered_pdf)
|
||||
$pdf = $numbered_pdf;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (isset($activity->invoice_id)) {
|
||||
|
@ -191,7 +191,6 @@ class InvitationController extends Controller
|
||||
return response()->json(["message" => "no record found"], 400);
|
||||
|
||||
$file_name = $invitation->{$entity}->numberFormatter().'.pdf';
|
||||
nlog($file_name);
|
||||
|
||||
$file = CreateRawPdf::dispatchNow($invitation, $invitation->company->db);
|
||||
|
||||
|
@ -134,13 +134,21 @@ class SelfUpdateController extends BaseController
|
||||
|
||||
nlog("Extracting zip");
|
||||
|
||||
$zipFile = new \PhpZip\ZipFile();
|
||||
// $zipFile = new \PhpZip\ZipFile();
|
||||
|
||||
$zipFile->openFile($file);
|
||||
// $zipFile->openFile($file);
|
||||
|
||||
$zipFile->extractTo(base_path());
|
||||
// $zipFile->extractTo(base_path());
|
||||
|
||||
$zipFile->close();
|
||||
// $zipFile->close();
|
||||
|
||||
$zip = new \ZipArchive;
|
||||
|
||||
$res = $zip->open($file);
|
||||
if ($res === TRUE) {
|
||||
$zip->extractTo(base_path());
|
||||
$zip->close();
|
||||
}
|
||||
|
||||
nlog("Finished extracting files");
|
||||
|
||||
|
@ -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,23 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){
|
||||
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||
|
||||
if($numbered_pdf)
|
||||
$pdf = $numbered_pdf;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||
|
||||
if($numbered_pdf)
|
||||
$pdf = $numbered_pdf;
|
||||
|
||||
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@ -203,10 +221,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 +234,7 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $file_path;
|
||||
}
|
||||
|
||||
@ -225,4 +243,5 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Entity Ninja (https://entityninja.com).
|
||||
*
|
||||
@ -34,6 +33,7 @@ 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 Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -46,7 +46,7 @@ use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class CreateRawPdf implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash, PageNumbering;
|
||||
|
||||
public $entity;
|
||||
|
||||
@ -177,11 +177,22 @@ class CreateRawPdf implements ShouldQueue
|
||||
if($finfo->buffer($pdf) != 'application/pdf; charset=binary')
|
||||
{
|
||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||
|
||||
if($numbered_pdf)
|
||||
$pdf = $numbered_pdf;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||
|
||||
if($numbered_pdf)
|
||||
$pdf = $numbered_pdf;
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
@ -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,13 @@ class PreviewPdf implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
return $this->makePdf(null, null, $this->design_string);
|
||||
$pdf = $this->makePdf(null, null, $this->design_string);
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||
|
||||
if($numbered_pdf)
|
||||
$pdf = $numbered_pdf;
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,9 @@ class PaymentNotification implements ShouldQueue
|
||||
|
||||
$analytics_id = $company->google_analytics_key;
|
||||
|
||||
if(!strlen($analytics_id) > 2)
|
||||
return;
|
||||
|
||||
$client = $payment->client;
|
||||
$amount = $payment->amount;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ use App\Services\PdfMaker\PdfMaker as PdfMakerService;
|
||||
use App\Utils\CurlUtils;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\Pdf\PageNumbering;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@ -33,7 +34,7 @@ use Illuminate\Support\Str;
|
||||
|
||||
class Phantom
|
||||
{
|
||||
use MakesHash;
|
||||
use MakesHash, PageNumbering;
|
||||
|
||||
/**
|
||||
* Generate a PDF from the
|
||||
@ -99,6 +100,12 @@ class Phantom
|
||||
|
||||
$this->checkMime($pdf, $invitation, $entity);
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $invitation->company);
|
||||
|
||||
if($numbered_pdf)
|
||||
$pdf = $numbered_pdf;
|
||||
|
||||
|
||||
if(!Storage::disk(config('filesystems.default'))->exists($path))
|
||||
Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
|
||||
|
||||
|
40
app/Utils/Traits/Pdf/PDF.php
Normal file
40
app/Utils/Traits/Pdf/PDF.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?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;
|
||||
|
||||
use setasign\Fpdi\Fpdi;
|
||||
|
||||
class PDF extends FPDI
|
||||
{
|
||||
|
||||
public $text_alignment = 'L';
|
||||
|
||||
function Footer()
|
||||
{
|
||||
$this->SetXY(0, -5);
|
||||
$this->SetFont('Arial','I', 9);
|
||||
$this->SetTextColor(135,135,135);
|
||||
|
||||
$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)
|
||||
{
|
||||
if(in_array($alignment, ['C','L','R']))
|
||||
$this->text_alignment = $alignment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
54
app/Utils/Traits/Pdf/PageNumbering.php
Normal file
54
app/Utils/Traits/Pdf/PageNumbering.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?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;
|
||||
use App\Utils\Traits\Pdf\PDF;
|
||||
use setasign\Fpdi\PdfParser\StreamReader;
|
||||
|
||||
trait PageNumbering
|
||||
{
|
||||
private function pageNumbering($pdf_data_object, $company)
|
||||
{
|
||||
|
||||
if(!$company->settings->page_numbering)
|
||||
return $pdf_data_object;
|
||||
|
||||
try
|
||||
{
|
||||
$pdf = new PDF();
|
||||
|
||||
$pdf->setAlignment($company->getSetting('page_numbering_alignment'));
|
||||
|
||||
$pageCount = $pdf->setSourceFile(StreamReader::createByString($pdf_data_object));
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
return $pdf->Output('S');
|
||||
|
||||
}
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,8 @@
|
||||
"predis/predis": "^1.1",
|
||||
"razorpay/razorpay": "2.*",
|
||||
"sentry/sentry-laravel": "^2",
|
||||
"setasign/fpdf": "^1.8",
|
||||
"setasign/fpdi": "^2.3",
|
||||
"square/square": "13.0.0.20210721",
|
||||
"stripe/stripe-php": "^7.50",
|
||||
"symfony/http-client": "^5.2",
|
||||
@ -148,4 +150,4 @@
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
}
|
||||
|
15122
composer.lock
generated
15122
composer.lock
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user