php-cs-fixer

This commit is contained in:
David Bomba 2023-02-22 17:37:16 +11:00
parent 9972bce7d7
commit cfdaa1517c
12 changed files with 109 additions and 118 deletions

View File

@ -50,9 +50,9 @@ class ContactHashLoginController extends Controller
public function errorPage()
{
return render('generic.error', [
'title' => session()->get('title'),
'notification' => session()->get('notification'),
'account' => auth()->guard('contact')?->user()?->user?->account,
'title' => session()->get('title'),
'notification' => session()->get('notification'),
'account' => auth()->guard('contact')?->user()?->user?->account,
'company' => auth()->guard('contact')?->user()?->user?->company
]);
}

View File

@ -195,12 +195,11 @@ class PreviewController extends BaseController
$response->header('Content-Type', 'application/pdf');
return $response;
}
public function oldDesign(DesignPreviewRequest $request)
{
if(Ninja::isHosted() && !in_array($request->getHost(), ['preview.invoicing.co','staging.invoicing.co'])){
if (Ninja::isHosted() && !in_array($request->getHost(), ['preview.invoicing.co','staging.invoicing.co'])) {
return response()->json(['message' => 'This server cannot handle this request.'], 400);
}
@ -238,13 +237,12 @@ class PreviewController extends BaseController
->first();
}
if($request->has('client_id') && strlen($request->client_id) > 4) {
if ($request->has('client_id') && strlen($request->client_id) > 4) {
$client = Client::withTrashed()->find($this->decodePrimaryKey($request->client_id));
if($request->settings_type == 'client' && $client ){
$client->settings = $request->settings;
$client->save();
}
if ($request->settings_type == 'client' && $client) {
$client->settings = $request->settings;
$client->save();
}
}
if ($request->has('group_id')) {
@ -340,13 +338,13 @@ class PreviewController extends BaseController
$headers = ['Content-Type' => 'application/pdf'];
if(request()->input('inline') == 'true')
if (request()->input('inline') == 'true') {
$headers = array_merge($headers, ['Content-Disposition' => 'inline']);
}
return response()->streamDownload(function () use($pdf) {
echo $pdf;
}, "preview.pdf", $headers);
return response()->streamDownload(function () use ($pdf) {
echo $pdf;
}, "preview.pdf", $headers);
}
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
@ -354,13 +352,13 @@ class PreviewController extends BaseController
$headers = ['Content-Type' => 'application/pdf'];
if(request()->input('inline') == 'true')
if (request()->input('inline') == 'true') {
$headers = array_merge($headers, ['Content-Disposition' => 'inline']);
}
return response()->streamDownload(function () use($pdf) {
echo $pdf;
}, "preview.pdf", $headers);
return response()->streamDownload(function () use ($pdf) {
echo $pdf;
}, "preview.pdf", $headers);
}
$file_path = (new PreviewPdf($maker->getCompiledHTML(true), $company))->handle();
@ -372,8 +370,9 @@ class PreviewController extends BaseController
public function live(PreviewInvoiceRequest $request)
{
if(Ninja::isHosted() && !in_array($request->getHost(), ['preview.invoicing.co','staging.invoicing.co']))
if (Ninja::isHosted() && !in_array($request->getHost(), ['preview.invoicing.co','staging.invoicing.co'])) {
return response()->json(['message' => 'This server cannot handle this request.'], 400);
}
$company = auth()->user()->company();

View File

@ -208,9 +208,7 @@ class SetupController extends Controller
public function checkPdf(Request $request)
{
try {
return response(['url' => ''], 200);
} catch (Exception $e) {
nlog($e->getMessage());

View File

@ -11,8 +11,8 @@
namespace App\Http\Requests\TaskScheduler;
use App\Http\Requests\Request;
use Illuminate\Validation\Rule;
use App\Http\ValidationRules\Scheduler\ValidClientIds;
use Illuminate\Validation\Rule;
class UpdateSchedulerRequest extends Request
{

View File

@ -26,8 +26,9 @@ class ValidCompanyQuantity implements Rule
*/
public function passes($attribute, $value)
{
if(config('ninja.testvars.travis'))
if (config('ninja.testvars.travis')) {
return true;
}
if (Ninja::isSelfHost()) {
return auth()->user()->company()->account->companies->count() < 10;

View File

@ -611,8 +611,9 @@ class NinjaMailerJob implements ShouldQueue
public function failed($exception = null)
{
if($exception)
if ($exception) {
nlog($exception->getMessage());
}
config(['queue.failed.driver' => null]);
}

View File

@ -22,7 +22,9 @@ class UnlinkFile implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(protected string $disk = '', protected ?string $file_path = ''){}
public function __construct(protected string $disk = '', protected ?string $file_path = '')
{
}
/**
* Execute the job.
@ -32,12 +34,14 @@ class UnlinkFile implements ShouldQueue
public function handle()
{
/* Do not delete files if we are on the sync queue*/
if (config('queue.default') == 'sync')
if (config('queue.default') == 'sync') {
return;
}
if(!$this->file_path)
if (!$this->file_path) {
return;
}
Storage::disk($this->disk)->delete($this->file_path);
}

View File

@ -11,16 +11,16 @@
namespace App\Models;
use Illuminate\Support\Str;
use Illuminate\Support\Carbon;
use App\Utils\Traits\MakesHash;
use App\DataMapper\ClientSettings;
use App\Jobs\Util\WebhookHandler;
use App\Models\Traits\Excludable;
use App\DataMapper\ClientSettings;
use Illuminate\Database\Eloquent\Model;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\UserSessionAttributes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
/**
* Class BaseModel

View File

@ -11,8 +11,8 @@
namespace App\Models;
use App\Utils\Traits\MakesHash;
use App\Models\Traits\Excludable;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;

View File

@ -486,15 +486,15 @@ class User extends Authenticatable implements MustVerifyEmail
/**
* Used when we need to filter permissions carefully.
*
*
* For instance, users that have view_client permissions should not
* see the client balance, however if they also have
* see the client balance, however if they also have
* view_invoice or view_all etc, then they should be able to see the balance.
*
*
* First we pass over the excluded permissions and return false if we find a match.
*
*
* If those permissions are not hit, then we can iterate through the matched_permissions and search for a hit.
*
*
* Note, returning FALSE here means the user does NOT have the permission we want to exclude
*
* @param array $matched_permission
@ -513,7 +513,7 @@ class User extends Authenticatable implements MustVerifyEmail
}
}
foreach($matched_permission as $permission) {
foreach ($matched_permission as $permission) {
if ($this->hasExactPermission($permission)) {
return true;
}

View File

@ -245,28 +245,28 @@ class Design extends BaseDesign
{
$elements = [];
if(!$this->client)
if (!$this->client) {
return $elements;
}
$elements = [
['element' => 'p', 'content' => ctrans('texts.shipping_address'), 'properties' => ['data-ref' => 'shipping_address-label', 'style' => 'font-weight: bold; text-transform: uppercase']],
['element' => 'p', 'content' => $this->client->name, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.name']],
['element' => 'p', 'content' => $this->client->shipping_address1, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.shipping_address1']],
['element' => 'p', 'content' => $this->client->shipping_address2, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.shipping_address2']],
['element' => 'p', 'show_empty' => false, 'elements' => [
['element' => 'span', 'content' => "{$this->client->shipping_city} ", 'properties' => ['ref' => 'shipping_address-client.shipping_city']],
['element' => 'span', 'content' => "{$this->client->shipping_state} ", 'properties' => ['ref' => 'shipping_address-client.shipping_state']],
['element' => 'span', 'content' => "{$this->client->shipping_postal_code} ", 'properties' => ['ref' => 'shipping_address-client.shipping_postal_code']],
]],
['element' => 'p', 'content' => optional($this->client->shipping_country)->name, 'show_empty' => false],
];
$elements = [
['element' => 'p', 'content' => ctrans('texts.shipping_address'), 'properties' => ['data-ref' => 'shipping_address-label', 'style' => 'font-weight: bold; text-transform: uppercase']],
['element' => 'p', 'content' => $this->client->name, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.name']],
['element' => 'p', 'content' => $this->client->shipping_address1, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.shipping_address1']],
['element' => 'p', 'content' => $this->client->shipping_address2, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.shipping_address2']],
['element' => 'p', 'show_empty' => false, 'elements' => [
['element' => 'span', 'content' => "{$this->client->shipping_city} ", 'properties' => ['ref' => 'shipping_address-client.shipping_city']],
['element' => 'span', 'content' => "{$this->client->shipping_state} ", 'properties' => ['ref' => 'shipping_address-client.shipping_state']],
['element' => 'span', 'content' => "{$this->client->shipping_postal_code} ", 'properties' => ['ref' => 'shipping_address-client.shipping_postal_code']],
]],
['element' => 'p', 'content' => optional($this->client->shipping_country)->name, 'show_empty' => false],
];
// if (!is_null($this->context['contact'])) {
// if (!is_null($this->context['contact'])) {
// $elements[] = ['element' => 'p', 'content' => $this->context['contact']->email, 'show_empty' => false, 'properties' => ['data-ref' => 'delivery_note-contact.email']];
// }
// }
return $elements;
return $elements;
}
public function clientDetails(): array
@ -309,22 +309,18 @@ class Design extends BaseDesign
public function entityDetailsx(): array
{
if ($this->type === 'statement') {
$s_date = $this->translateDate($this->options['start_date'], $this->client->date_format(), $this->client->locale()) . " - " . $this->translateDate($this->options['end_date'], $this->client->date_format(), $this->client->locale());
return [
return [
['element' => 'p', 'content' => "<h2>".ctrans('texts.statement')."</h2>", 'properties' => ['data-ref' => 'statement-label']],
['element' => 'p', 'content' => ctrans('texts.statement_date'), 'properties' => ['data-ref' => 'statement-label'],'elements' =>
['element' => 'p', 'content' => ctrans('texts.statement_date'), 'properties' => ['data-ref' => 'statement-label'],'elements' =>
['element' => 'span', 'content' => "{$s_date} "]
],
['element' => 'p', 'content' => '$balance_due_label', 'properties' => ['data-ref' => 'statement-label'],'elements' =>
['element' => 'p', 'content' => '$balance_due_label', 'properties' => ['data-ref' => 'statement-label'],'elements' =>
['element' => 'span', 'content' => Number::formatMoney($this->invoices->sum('balance'), $this->client)]
],
],
];
}
$variables = $this->context['pdf_variables']['invoice_details'];
@ -341,10 +337,8 @@ class Design extends BaseDesign
$variables = $this->context['pdf_variables']['credit_details'];
}
if($this->vendor){
if ($this->vendor) {
$variables = $this->context['pdf_variables']['purchase_order_details'];
}
$elements = [];
@ -376,8 +370,7 @@ class Design extends BaseDesign
}
}
return $elements;
return $elements;
}
public function entityDetails(): array

View File

@ -11,27 +11,26 @@
namespace App\Services\Preview;
use App\Models\User;
use App\Models\Client;
use App\Models\Vendor;
use App\Models\Company;
use App\Models\Invoice;
use App\Utils\HtmlEngine;
use Illuminate\Support\Str;
use App\Jobs\Util\PreviewPdf;
use App\Models\ClientContact;
use App\Models\VendorContact;
use App\Utils\PhantomJS\Phantom;
use App\Models\InvoiceInvitation;
use App\Services\PdfMaker\Design;
use App\Utils\HostedPDF\NinjaPdf;
use Illuminate\Support\Facades\DB;
use App\Services\PdfMaker\PdfMaker;
use App\Factory\GroupSettingFactory;
use App\Jobs\Util\PreviewPdf;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
use App\Models\Design as DesignModel;
use App\Models\Invoice;
use App\Models\InvoiceInvitation;
use App\Models\User;
use App\Models\Vendor;
use App\Models\VendorContact;
use App\Services\PdfMaker\Design as PdfMakerDesign;
use App\Services\PdfMaker\PdfMaker;
use App\Utils\HostedPDF\NinjaPdf;
use App\Utils\HtmlEngine;
use App\Utils\PhantomJS\Phantom;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\Pdf\PageNumbering;
use App\Services\PdfMaker\Design as PdfMakerDesign;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class StubBuilder
{
@ -56,7 +55,9 @@ class StubBuilder
public array $settings;
public function __construct(public Company $company, public User $user){}
public function __construct(public Company $company, public User $user)
{
}
public function setEntityType($entity_type)
{
@ -67,26 +68,26 @@ class StubBuilder
public function build(): self
{
try{
DB::connection($this->company->db)->beginTransaction();
$this
->createRecipient()
try {
DB::connection(config('database.default'))->transaction(function () {
$this->createRecipient()
->initializeSettings()
->createEntity()
->createEntity()
->linkRelations()
->buildHtml();
DB::connection($this->company->db)->rollBack();
}
catch(\Exception $e)
{
->buildHtml();
});
} catch (\Throwable $throwable) {
nlog("DB ERROR " . $throwable->getMessage());
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
} catch(\Exception $e) {
nlog($e->getMessage());
// return $e->getMessage();
DB::connection($this->company->db)->rollBack();
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
}
return $this;
@ -94,7 +95,6 @@ class StubBuilder
public function getPdf(): mixed
{
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
return (new Phantom)->convertHtmlToPdf($this->html);
}
@ -112,15 +112,13 @@ class StubBuilder
}
return (new PreviewPdf($this->html, $this->company))->handle();
}
private function initializeSettings(): self
{
$this->dynamic_settings_type = 'company';
match($this->dynamic_settings_type) {
match ($this->dynamic_settings_type) {
'company' => $this->setCompanySettings(),
'client' => $this->setClientSettings(),
'group' => $this->setGroupSettings(),
@ -175,7 +173,6 @@ class StubBuilder
private function buildHtml(): self
{
$html = new HtmlEngine($this->invitation);
$design_string = "{$this->entity_type}_design_id";
@ -216,8 +213,7 @@ class StubBuilder
private function createRecipient(): self
{
match($this->entity_type) {
match ($this->entity_type) {
'invoice' => $this->createClient(),
'quote' => $this->createClient(),
'credit' => $this->createClient(),
@ -225,7 +221,6 @@ class StubBuilder
};
return $this;
}
private function createClient(): self
@ -267,7 +262,7 @@ class StubBuilder
private function createEntity(): self
{
match($this->entity_type) {
match ($this->entity_type) {
'invoice' => $this->createInvoice(),
'quote' => $this->createQuote(),
'credit' => $this->createCredit(),
@ -299,15 +294,15 @@ class StubBuilder
private function createQuote()
{
$this->entity->save();
}
}
private function createCredit()
{
$this->entity->save();
}
}
private function createPurchaseOrder()
{
$this->entity->save();
}
}
}