Fixes for subscription cron query

This commit is contained in:
David Bomba 2024-06-17 10:14:04 +10:00
parent 38114d0c48
commit 742b49c75a
30 changed files with 202 additions and 214 deletions

View File

@ -31,11 +31,11 @@ class QuoteExport extends BaseExport
private Decorator $decorator; private Decorator $decorator;
private array $decorate_keys = [ // private array $decorate_keys = [
'client', // 'client',
'currency', // 'currency',
'invoice', // 'invoice',
]; // ];
public function __construct(Company $company, array $input) public function __construct(Company $company, array $input)
{ {

View File

@ -31,7 +31,7 @@ class TaskExport extends BaseExport
public string $date_key = 'created_at'; public string $date_key = 'created_at';
private string $date_format = 'YYYY-MM-DD'; private string $date_format = 'Y-m-d';
public Writer $csv; public Writer $csv;
@ -180,13 +180,7 @@ class TaskExport extends BaseExport
$logs = json_decode($task->time_log, 1); $logs = json_decode($task->time_log, 1);
$date_format_default = 'Y-m-d'; $date_format_default = $this->date_format;
$date_format = DateFormat::find($task->company->settings->date_format_id);
if ($date_format) {
$date_format_default = $date_format->format;
}
foreach ($logs as $key => $item) { foreach ($logs as $key => $item) {
if (in_array('task.start_date', $this->input['report_keys']) || in_array('start_date', $this->input['report_keys'])) { if (in_array('task.start_date', $this->input['report_keys']) || in_array('start_date', $this->input['report_keys'])) {
@ -236,7 +230,7 @@ class TaskExport extends BaseExport
*/ */
protected function addTaskStatusFilter(Builder $query, string $status): Builder protected function addTaskStatusFilter(Builder $query, string $status): Builder
{ {
/** @var array $status_parameters */
$status_parameters = explode(',', $status); $status_parameters = explode(',', $status);
if (in_array('all', $status_parameters) || count($status_parameters) == 0) { if (in_array('all', $status_parameters) || count($status_parameters) == 0) {

View File

@ -171,16 +171,16 @@ class VendorExport extends BaseExport
return $entity; return $entity;
} }
private function calculateStatus($vendor) // private function calculateStatus($vendor)
{ // {
if ($vendor->is_deleted) { // if ($vendor->is_deleted) {
return ctrans('texts.deleted'); // return ctrans('texts.deleted');
} // }
if ($vendor->deleted_at) { // if ($vendor->deleted_at) {
return ctrans('texts.archived'); // return ctrans('texts.archived');
} // }
return ctrans('texts.active'); // return ctrans('texts.active');
} // }
} }

View File

@ -144,7 +144,7 @@ class RecurringExpenseToExpenseFactory
continue; continue;
} }
if (Str::contains($match, '|')) { // if (Str::contains($match, '|')) {
$parts = explode('|', $match); // [ '[MONTH', 'MONTH+2]' ] $parts = explode('|', $match); // [ '[MONTH', 'MONTH+2]' ]
$left = substr($parts[0], 1); // 'MONTH' $left = substr($parts[0], 1); // 'MONTH'
@ -182,7 +182,7 @@ class RecurringExpenseToExpenseFactory
$value, $value,
1 1
); );
} // }
} }
// Second case with more common calculations. // Second case with more common calculations.

View File

@ -271,6 +271,7 @@ class InvoiceFilters extends QueryFilters
if (count($parts) != 2) { if (count($parts) != 2) {
return $this->builder; return $this->builder;
} }
try { try {
$start_date = Carbon::parse($parts[0]); $start_date = Carbon::parse($parts[0]);
@ -281,7 +282,6 @@ class InvoiceFilters extends QueryFilters
return $this->builder; return $this->builder;
} }
return $this->builder;
} }
/** /**
@ -307,7 +307,6 @@ class InvoiceFilters extends QueryFilters
return $this->builder; return $this->builder;
} }
return $this->builder;
} }

View File

@ -204,7 +204,6 @@ class PaymentFilters extends QueryFilters
return $this->builder; return $this->builder;
} }
return $this->builder;
} }
/** /**

View File

@ -162,9 +162,10 @@ class RecurringInvoiceFilters extends QueryFilters
return $this->builder; return $this->builder;
} }
/** @var array $key_parameters */
$key_parameters = explode(',', $value); $key_parameters = explode(',', $value);
if (count($key_parameters)) { if (count($key_parameters) > 0) {
return $this->builder->where(function ($query) use ($key_parameters) { return $this->builder->where(function ($query) use ($key_parameters) {
foreach ($key_parameters as $key) { foreach ($key_parameters as $key) {
$query->orWhereJsonContains('line_items', ['product_key' => $key]); $query->orWhereJsonContains('line_items', ['product_key' => $key]);
@ -183,6 +184,7 @@ class RecurringInvoiceFilters extends QueryFilters
*/ */
public function next_send_between(string $range = ''): Builder public function next_send_between(string $range = ''): Builder
{ {
/** @var array $parts */
$parts = explode('|', $range); $parts = explode('|', $range);
if (!isset($parts[0]) || !isset($parts[1])) { if (!isset($parts[0]) || !isset($parts[1])) {

View File

@ -175,6 +175,7 @@ class TaskFilters extends QueryFilters
return $this->builder; return $this->builder;
} }
/** @var array $status_parameters */
$status_parameters = explode(',', $value); $status_parameters = explode(',', $value);
if(count($status_parameters) >= 1) { if(count($status_parameters) >= 1) {

View File

@ -26,15 +26,15 @@ use BaconQrCode\Writer;
*/ */
class EpcQrGenerator class EpcQrGenerator
{ {
private array $sepa = [ // private array $sepa = [
'serviceTag' => 'BCD', // 'serviceTag' => 'BCD',
'version' => 2, // 'version' => 2,
'characterSet' => 1, // 'characterSet' => 1,
'identification' => 'SCT', // 'identification' => 'SCT',
'bic' => '', // 'bic' => '',
'purpose' => '', // 'purpose' => '',
]; // ];
public function __construct(protected Company $company, protected Invoice|RecurringInvoice $invoice, protected float $amount) public function __construct(protected Company $company, protected Invoice|RecurringInvoice $invoice, protected float $amount)
{ {
@ -61,13 +61,7 @@ class EpcQrGenerator
} catch(\Throwable $e) { } catch(\Throwable $e) {
nlog("EPC QR failure => ".$e->getMessage()); nlog("EPC QR failure => ".$e->getMessage());
return ''; return '';
} catch(\Exception $e) { }
nlog("EPC QR failure => ".$e->getMessage());
return '';
} catch(InvalidArgumentException $e) {
nlog("EPC QR failure => ".$e->getMessage());
return '';
}
} }

View File

@ -399,7 +399,7 @@ class InvoiceItemSumInclusive
private function shouldCalculateTax(): self private function shouldCalculateTax(): self
{ {
if (!$this->invoice->company?->calculate_taxes || $this->invoice->company->account->isFreeHostedClient()) { if (!$this->invoice->company->calculate_taxes || $this->invoice->company->account->isFreeHostedClient()) {
$this->calc_tax = false; $this->calc_tax = false;
return $this; return $this;
} }

View File

@ -58,12 +58,12 @@ class ProRata
* Prepares the line items of an invoice * Prepares the line items of an invoice
* to be pro rata refunded. * to be pro rata refunded.
* *
* @param Invoice $invoice * @param ?Invoice $invoice
* @param bool $is_credit * @param bool $is_credit
* @return array * @return array
* @throws Exception * @throws Exception
*/ */
public function refundItems(Invoice $invoice, $is_credit = false): array public function refundItems(?Invoice $invoice, $is_credit = false): array
{ {
if (! $invoice) { if (! $invoice) {
return []; return [];

View File

@ -118,7 +118,7 @@ class ContactForgotPasswordController extends Controller
})->first(); })->first();
} }
$response = false; // $response = false;
if ($contact) { if ($contact) {
/* Update all instances of the client */ /* Update all instances of the client */
@ -131,16 +131,16 @@ class ContactForgotPasswordController extends Controller
} }
if ($request->ajax()) { if ($request->ajax()) {
if ($response == Password::RESET_THROTTLED) { if ($response == Password::RESET_THROTTLED) { // @phpstan-ignore-line
return response()->json(['message' => ctrans('passwords.throttled'), 'status' => false], 429); return response()->json(['message' => ctrans('passwords.throttled'), 'status' => false], 429);
} }
return $response == Password::RESET_LINK_SENT return $response == Password::RESET_LINK_SENT // @phpstan-ignore-line
? response()->json(['message' => 'Reset link sent to your email.', 'status' => true], 201) ? response()->json(['message' => 'Reset link sent to your email.', 'status' => true], 201)
: response()->json(['message' => 'Email not found', 'status' => false], 401); : response()->json(['message' => 'Email not found', 'status' => false], 401);
} }
return $response == Password::RESET_LINK_SENT return $response == Password::RESET_LINK_SENT // @phpstan-ignore-line
? $this->sendResetLinkResponse($request, $response) ? $this->sendResetLinkResponse($request, $response)
: $this->sendResetLinkFailedResponse($request, $response); : $this->sendResetLinkFailedResponse($request, $response);
} }

View File

@ -55,7 +55,7 @@ class ContactLoginController extends Controller
$company = Company::where('company_key', $company_key)->first(); $company = Company::where('company_key', $company_key)->first();
} }
/** @var \App\Models\Company $company **/ /** @var ?\App\Models\Company $company **/
if ($company) { if ($company) {
$account = $company->account; $account = $company->account;
} elseif (! $company && strpos($request->getHost(), config('ninja.app_domain')) !== false) { } elseif (! $company && strpos($request->getHost(), config('ninja.app_domain')) !== false) {

View File

@ -137,8 +137,8 @@ class ResetPasswordController extends Controller
return redirect('/#/login'); return redirect('/#/login');
} }
return redirect($this->redirectPath()) // return redirect($this->redirectPath())
->with('status', trans($response)); // ->with('status', trans($response));
} }
} }

View File

@ -1035,7 +1035,7 @@ class BaseController extends Controller
$resource = new Item($item, $transformer, $this->entity_type); $resource = new Item($item, $transformer, $this->entity_type);
/** @var \App\Models\User $user */ /** @var ?\App\Models\User $user */
$user = auth()->user(); $user = auth()->user();
if ($user && request()->include_static) { if ($user && request()->include_static) {

View File

@ -19,7 +19,6 @@ use Illuminate\Http\Request;
*/ */
class BrevoController extends BaseController class BrevoController extends BaseController
{ {
private $invitation;
public function __construct() public function __construct()
{ {

View File

@ -141,7 +141,7 @@ class ClientController extends BaseController
return $request->disallowUpdate(); return $request->disallowUpdate();
} }
/** @var \App\Models\User $user */ /** @var ?\App\Models\User $user */
$user = auth()->user(); $user = auth()->user();
$client = $this->client_repo->save($request->all(), $client); $client = $this->client_repo->save($request->all(), $client);
@ -426,7 +426,7 @@ class ClientController extends BaseController
try { try {
/** @var \Postmark\Models\DynamicResponseModel $response */ /** @var ?\Postmark\Models\DynamicResponseModel $response */
$response = $postmark->activateBounce((int)$bounce_id); $response = $postmark->activateBounce((int)$bounce_id);
if($response && $response?->Message == 'OK' && !$response->Bounce->Inactive && $response->Bounce->Email) { if($response && $response?->Message == 'OK' && !$response->Bounce->Inactive && $response->Bounce->Email) {

View File

@ -97,12 +97,12 @@ class InvoiceController extends Controller
$invitation = false; $invitation = false;
match($data['entity_type'] ?? false) { match($data['entity_type'] ?? 'invoice') {
'invoice' => $invitation = InvoiceInvitation::withTrashed()->find($data['invitation_id']), 'invoice' => $invitation = InvoiceInvitation::withTrashed()->find($data['invitation_id']),
'quote' => $invitation = QuoteInvitation::withTrashed()->find($data['invitation_id']), 'quote' => $invitation = QuoteInvitation::withTrashed()->find($data['invitation_id']),
'credit' => $invitation = CreditInvitation::withTrashed()->find($data['invitation_id']), 'credit' => $invitation = CreditInvitation::withTrashed()->find($data['invitation_id']),
'recurring_invoice' => $invitation = RecurringInvoiceInvitation::withTrashed()->find($data['invitation_id']), 'recurring_invoice' => $invitation = RecurringInvoiceInvitation::withTrashed()->find($data['invitation_id']),
false => $invitation = false, default => $invitation = false,
}; };
if (! $invitation) { if (! $invitation) {

View File

@ -77,6 +77,7 @@ class PaymentController extends Controller
'EUR' => $data = $bt->formatDataforEur($payment_intent), 'EUR' => $data = $bt->formatDataforEur($payment_intent),
'JPY' => $data = $bt->formatDataforJp($payment_intent), 'JPY' => $data = $bt->formatDataforJp($payment_intent),
'GBP' => $data = $bt->formatDataforUk($payment_intent), 'GBP' => $data = $bt->formatDataforUk($payment_intent),
default => $data = $bt->formatDataforUk($payment_intent),
}; };
$gateway = $stripe; $gateway = $stripe;

View File

@ -61,7 +61,7 @@ class PasswordProtection
return $next($request); return $next($request);
} elseif(strlen(auth()->user()->oauth_provider_id) > 2 && !auth()->user()->company()->oauth_password_required) { } elseif(strlen(auth()->user()->oauth_provider_id) > 2 && !auth()->user()->company()->oauth_password_required) {
return $next($request); return $next($request);
} elseif ($request->header('X-API-OAUTH-PASSWORD') && strlen($request->header('X-API-OAUTH-PASSWORD')) >= 1) { } elseif ($request->header('X-API-OAUTH-PASSWORD') && strlen($request->header('X-API-OAUTH-PASSWORD')) > 1) {
//user is attempting to reauth with OAuth - check the token value //user is attempting to reauth with OAuth - check the token value
//todo expand this to include all OAuth providers //todo expand this to include all OAuth providers
if (auth()->user()->oauth_provider_id == 'google') { if (auth()->user()->oauth_provider_id == 'google') {

View File

@ -65,9 +65,9 @@ class SubscriptionCron
//Requires the crons to be updated and set to hourly @ 00:01 //Requires the crons to be updated and set to hourly @ 00:01
private function timezoneAware() private function timezoneAware()
{ {
$grouped_company_ids =
Invoice::query()
Invoice::select('company_id') ->with('company')
->where('is_deleted', 0) ->where('is_deleted', 0)
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('balance', '>', 0) ->where('balance', '>', 0)
@ -77,10 +77,11 @@ class SubscriptionCron
->whereNotNull('subscription_id') ->whereNotNull('subscription_id')
->groupBy('company_id') ->groupBy('company_id')
->cursor() ->cursor()
->each(function ($company_id) { ->each(function ($invoice) {
/** @var \App\Models\Company $company */ /** @var \App\Models\Company $company */
$company = Company::find($company_id); // $company = Company::find($invoice->company_id);
$company = $invoice->company;
$timezone_now = now()->setTimezone($company->timezone()->name ?? 'Pacific/Midway'); $timezone_now = now()->setTimezone($company->timezone()->name ?? 'Pacific/Midway');

View File

@ -63,7 +63,7 @@ class TaskScheduler implements ShouldQueue
//@var \App\Models\Schedule $scheduler //@var \App\Models\Schedule $scheduler
$scheduler->service()->runTask(); $scheduler->service()->runTask();
} catch(\Exception $e) { } catch(\Exception $e) {
nlog($e->getMessage()); nlog("Exception:: TaskScheduler:: Doing job {$scheduler->name}" . $e->getMessage());
} }
}); });

View File

@ -130,7 +130,6 @@ use Laracasts\Presenter\PresentableTrait;
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\InvoiceInvitation> $invitations * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\InvoiceInvitation> $invitations
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Task> $tasks * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Task> $tasks
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel company()
* @property object|null $tax_data * @property object|null $tax_data
* @mixin \Eloquent * @mixin \Eloquent
*/ */

View File

@ -58,7 +58,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property int|null $exchange_currency_id * @property int|null $exchange_currency_id
* @property \App\Models\Paymentable $paymentable * @property \App\Models\Paymentable $paymentable
* @property object|null $meta * @property object|null $meta
* @property object|null $refund_meta * @property array|null $refund_meta
* @property string|null $custom_value1 * @property string|null $custom_value1
* @property string|null $custom_value2 * @property string|null $custom_value2
* @property string|null $custom_value3 * @property string|null $custom_value3

View File

@ -46,9 +46,9 @@ class EmailReport
use MakesHash; use MakesHash;
use MakesDates; use MakesDates;
private Client $client; // private Client $client;
private bool $multiple_clients = false; // private bool $multiple_clients = false;
private string $file_name = 'file.csv'; private string $file_name = 'file.csv';
@ -66,6 +66,7 @@ class EmailReport
$data['end_date'] = $start_end_dates[1]; $data['end_date'] = $start_end_dates[1];
$data['date_range'] = $data['date_range'] ?? 'all'; $data['date_range'] = $data['date_range'] ?? 'all';
$data['report_keys'] = $data['report_keys'] ?? []; $data['report_keys'] = $data['report_keys'] ?? [];
$data['include_deleted'] = $data['include_deleted'] ?? false;
$export = false; $export = false;

View File

@ -124,7 +124,7 @@ class TemplateService
$this->twig->addFilter($filter); $this->twig->addFilter($filter);
$allowedTags = ['if', 'for', 'set', 'filter']; $allowedTags = ['if', 'for', 'set', 'filter'];
$allowedFilters = ['escape', 'e', 'upper', 'lower', 'capitalize', 'filter', 'length', 'merge','format_currency','map', 'join', 'first', 'date','sum']; $allowedFilters = ['escape', 'e', 'upper', 'lower', 'capitalize', 'filter', 'length', 'merge','format_currency', 'format_number','format_percent_number','map', 'join', 'first', 'date','sum'];
$allowedFunctions = ['range', 'cycle', 'constant', 'date',]; $allowedFunctions = ['range', 'cycle', 'constant', 'date',];
$allowedProperties = ['type_id']; $allowedProperties = ['type_id'];
$allowedMethods = ['img','t']; $allowedMethods = ['img','t'];
@ -620,8 +620,6 @@ class TemplateService
private function transformPayment(Payment $payment): array private function transformPayment(Payment $payment): array
{ {
$data = [];
$this->payment = $payment; $this->payment = $payment;
$credits = $payment->credits->map(function ($credit) use ($payment) { $credits = $payment->credits->map(function ($credit) use ($payment) {
@ -694,8 +692,6 @@ class TemplateService
'refund_activity' => $this->getPaymentRefundActivity($payment), 'refund_activity' => $this->getPaymentRefundActivity($payment),
]; ];
return $data;
} }
/** /**
@ -1196,6 +1192,7 @@ class TemplateService
'company-details' => $this->companyDetails($stack['labels'] == 'true'), 'company-details' => $this->companyDetails($stack['labels'] == 'true'),
'company-address' => $this->companyAddress($stack['labels'] == 'true'), 'company-address' => $this->companyAddress($stack['labels'] == 'true'),
'shipping-details' => $this->shippingDetails($stack['labels'] == 'true'), 'shipping-details' => $this->shippingDetails($stack['labels'] == 'true'),
default => $this->entityDetails(),
}; };
$this->save(); $this->save();

View File

@ -97,15 +97,15 @@ class Helpers
switch ($custom_field) { switch ($custom_field) {
case 'date': case 'date':
return is_null($entity) ? $value : $this->translateDate($value, $entity->date_format(), $entity->locale()); return is_null($entity) ? $value : $this->translateDate($value, $entity->date_format(), $entity->locale());
break;
case 'switch': case 'switch':
return trim($value ?? '') == 'yes' ? ctrans('texts.yes') : ctrans('texts.no'); return trim($value ?? '') == 'yes' ? ctrans('texts.yes') : ctrans('texts.no');
break;
default: default:
return is_null($value) ? '' : $this->processReservedKeywords($value, $entity); return is_null($value) ? '' : $this->processReservedKeywords($value, $entity);
break;
} }
} }
@ -252,7 +252,7 @@ class Helpers
continue; continue;
} }
if (Str::contains($match, '|')) { // if (Str::contains($match, '|')) {
$parts = explode('|', $match); // [ '[MONTH', 'MONTH+2]' ] $parts = explode('|', $match); // [ '[MONTH', 'MONTH+2]' ]
$left = substr($parts[0], 1); // 'MONTH' $left = substr($parts[0], 1); // 'MONTH'
@ -290,7 +290,7 @@ class Helpers
$value, $value,
1 1
); );
} // }
} }
// Second case with more common calculations. // Second case with more common calculations.

View File

@ -45,7 +45,7 @@ class HtmlEngine
/** @var \App\Models\Client $client */ /** @var \App\Models\Client $client */
public $client; public $client;
/** @var \App\Models\ClientContact $contact */ /** @var ?\App\Models\ClientContact $contact */
public $contact; public $contact;
/** @var \App\Models\Company $company */ /** @var \App\Models\Company $company */
@ -120,7 +120,7 @@ class HtmlEngine
{ {
if (! $this->client->currency()) { if (! $this->client->currency()) {
throw new Exception(debug_backtrace()[1]['function'], 1); throw new Exception(debug_backtrace()[1]['function'], 1);
exit; // exit;
} }
App::forgetInstance('translator'); App::forgetInstance('translator');
@ -132,10 +132,10 @@ class HtmlEngine
$data['$global_margin'] = ['value' => '6.35mm', 'label' => '']; $data['$global_margin'] = ['value' => '6.35mm', 'label' => ''];
$data['$company_logo_size'] = ['value' => $this->resolveCompanyLogoSize(), 'label' => '']; $data['$company_logo_size'] = ['value' => $this->resolveCompanyLogoSize(), 'label' => ''];
$data['$show_shipping_address'] = ['value' => $this->settings?->show_shipping_address ? 'flex' : 'none', 'label' => '']; $data['$show_shipping_address'] = ['value' => $this->settings->show_shipping_address ? 'flex' : 'none', 'label' => ''];
$data['$show_shipping_address_block'] = ['value' => $this->settings?->show_shipping_address ? 'block' : 'none', 'label' => '']; $data['$show_shipping_address_block'] = ['value' => $this->settings->show_shipping_address ? 'block' : 'none', 'label' => ''];
// $data['$show_shipping_address_visibility'] = ['value' => $this->settings?->show_shipping_address ? 'visible' : 'hidden', 'label' => '']; // $data['$show_shipping_address_visibility'] = ['value' => $this->settings?->show_shipping_address ? 'visible' : 'hidden', 'label' => ''];
$data['$show_shipping_address_visibility'] = ['value' => $this->settings?->show_shipping_address ? 1 : 0, 'label' => '']; $data['$show_shipping_address_visibility'] = ['value' => $this->settings->show_shipping_address ? 1 : 0, 'label' => ''];
$data['$order_number'] = ['value' => '', 'label' => ctrans('texts.order_number')]; $data['$order_number'] = ['value' => '', 'label' => ctrans('texts.order_number')];
$data['$tax'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$tax'] = ['value' => '', 'label' => ctrans('texts.tax')];
@ -226,7 +226,7 @@ class HtmlEngine
$data['$status_logo'] = ['value' => '<div class="stamp is-paid"> ' . ctrans('texts.paid') .'</div>', 'label' => '']; $data['$status_logo'] = ['value' => '<div class="stamp is-paid"> ' . ctrans('texts.paid') .'</div>', 'label' => ''];
$data['$show_paid_stamp'] = ['value' => $this->entity->status_id == 4 && $this->settings?->show_paid_stamp ? 'flex' : 'none', 'label' => '']; $data['$show_paid_stamp'] = ['value' => $this->entity->status_id == 4 && $this->settings->show_paid_stamp ? 'flex' : 'none', 'label' => ''];
if ($this->entity->vendor) { if ($this->entity->vendor) {
$data['$invoice.vendor'] = ['value' => $this->entity->vendor->present()->name(), 'label' => ctrans('texts.vendor_name')]; $data['$invoice.vendor'] = ['value' => $this->entity->vendor->present()->name(), 'label' => ctrans('texts.vendor_name')];
@ -775,8 +775,7 @@ class HtmlEngine
return ''; return '';
} }
return return collect($payment->refund_meta)
collect($payment->refund_meta)
->map(function ($refund) use ($payment) { ->map(function ($refund) use ($payment) {
$date = \Carbon\Carbon::parse($refund['date'] ?? $payment->date)->addSeconds($payment->client->timezone_offset()); $date = \Carbon\Carbon::parse($refund['date'] ?? $payment->date)->addSeconds($payment->client->timezone_offset());
@ -962,20 +961,20 @@ class HtmlEngine
* @return string a collection of <tr> rows with line item * @return string a collection of <tr> rows with line item
* aggregate data * aggregate data
*/ */
private function makeLineTaxes(): string // private function makeLineTaxes(): string
{ // {
$tax_map = $this->entity_calc->getTaxMap(); // $tax_map = $this->entity_calc->getTaxMap();
$data = ''; // $data = '';
foreach ($tax_map as $tax) { // foreach ($tax_map as $tax) {
$data .= '<tr class="line_taxes">'; // $data .= '<tr class="line_taxes">';
$data .= '<td>'.$tax['name'].'</td>'; // $data .= '<td>'.$tax['name'].'</td>';
$data .= '<td>'.Number::formatMoney($tax['total'], $this->client).'</td></tr>'; // $data .= '<td>'.Number::formatMoney($tax['total'], $this->client).'</td></tr>';
} // }
return $data; // return $data;
} // }
private function lineTaxValues(): string private function lineTaxValues(): string
{ {
@ -990,30 +989,30 @@ class HtmlEngine
return $data; return $data;
} }
private function makeTotalTaxes(): string // private function makeTotalTaxes(): string
{ // {
$data = ''; // $data = '';
if (! $this->entity_calc->getTotalTaxMap()) { // if (! $this->entity_calc->getTotalTaxMap()) {
return $data; // return $data;
} // }
foreach ($this->entity_calc->getTotalTaxMap() as $tax) { // foreach ($this->entity_calc->getTotalTaxMap() as $tax) {
$data .= '<tr>'; // $data .= '<tr>';
$data .= '<td colspan="{ count($this->entity->company->settings->pdf_variables->total_columns) - 2 }"></td>'; // $data .= '<td colspan="{ count($this->entity->company->settings->pdf_variables->total_columns) - 2 }"></td>';
$data .= '<td>'.$tax['name'].'</td>'; // $data .= '<td>'.$tax['name'].'</td>';
$data .= '<td>'.Number::formatMoney($tax['total'], $this->client).'</td></tr>'; // $data .= '<td>'.Number::formatMoney($tax['total'], $this->client).'</td></tr>';
} // }
return $data; // return $data;
} // }
private function parseLabelsAndValues($labels, $values, $section): string // private function parseLabelsAndValues($labels, $values, $section): string
{ // {
$section = strtr($section, $labels); // $section = strtr($section, $labels);
return strtr($section, $values); // return strtr($section, $values);
} // }
/* /*
| Ensures the URL doesn't have duplicated trailing slash | Ensures the URL doesn't have duplicated trailing slash
@ -1029,98 +1028,98 @@ class HtmlEngine
* of Repeating headers and footers on the PDF. * of Repeating headers and footers on the PDF.
* @return string The css string * @return string The css string
*/ */
private function generateCustomCSS(): string // private function generateCustomCSS(): string
{ // {
$header_and_footer = ' // $header_and_footer = '
.header, .header-space { // .header, .header-space {
height: 160px; // height: 160px;
} // }
.footer, .footer-space { // .footer, .footer-space {
height: 160px; // height: 160px;
} // }
.footer { // .footer {
position: fixed; // position: fixed;
bottom: 0; // bottom: 0;
width: 100%; // width: 100%;
} // }
.header { // .header {
position: fixed; // position: fixed;
top: 0mm; // top: 0mm;
width: 100%; // width: 100%;
} // }
@media print { // @media print {
thead {display: table-header-group;} // thead {display: table-header-group;}
tfoot {display: table-footer-group;} // tfoot {display: table-footer-group;}
button {display: none;} // button {display: none;}
body {margin: 0;} // body {margin: 0;}
}'; // }';
$header = ' // $header = '
.header, .header-space { // .header, .header-space {
height: 160px; // height: 160px;
} // }
.header { // .header {
position: fixed; // position: fixed;
top: 0mm; // top: 0mm;
width: 100%; // width: 100%;
} // }
@media print { // @media print {
thead {display: table-header-group;} // thead {display: table-header-group;}
button {display: none;} // button {display: none;}
body {margin: 0;} // body {margin: 0;}
}'; // }';
$footer = ' // $footer = '
.footer, .footer-space { // .footer, .footer-space {
height: 160px; // height: 160px;
} // }
.footer { // .footer {
position: fixed; // position: fixed;
bottom: 0; // bottom: 0;
width: 100%; // width: 100%;
} // }
@media print { // @media print {
tfoot {display: table-footer-group;} // tfoot {display: table-footer-group;}
button {display: none;} // button {display: none;}
body {margin: 0;} // body {margin: 0;}
}'; // }';
$css = ''; // $css = '';
if ($this->settings->all_pages_header && $this->settings->all_pages_footer) { // if ($this->settings->all_pages_header && $this->settings->all_pages_footer) {
$css .= $header_and_footer; // $css .= $header_and_footer;
} elseif ($this->settings->all_pages_header && ! $this->settings->all_pages_footer) { // } elseif ($this->settings->all_pages_header && ! $this->settings->all_pages_footer) {
$css .= $header; // $css .= $header;
} elseif (! $this->settings->all_pages_header && $this->settings->all_pages_footer) { // } elseif (! $this->settings->all_pages_header && $this->settings->all_pages_footer) {
$css .= $footer; // $css .= $footer;
} // }
$css .= ' // $css .= '
.page { // .page {
page-break-after: always; // page-break-after: always;
} // }
@page { // @page {
margin: 0mm // margin: 0mm
} // }
html { // html {
'; // ';
$css .= 'font-size:'.$this->settings->font_size.'px;'; // $css .= 'font-size:'.$this->settings->font_size.'px;';
$css .= '}'; // $css .= '}';
return $css; // return $css;
} // }
/** /**
* Generate markup for HTML images on entity. * Generate markup for HTML images on entity.
@ -1200,14 +1199,14 @@ html {
'; ';
return ' // return '
<table border="0" cellspacing="0" cellpadding="0" align="center"> // <table border="0" cellspacing="0" cellpadding="0" align="center">
<tr style="border: 0 !important; "> // <tr style="border: 0 !important; ">
<td class="new_button" style="padding: 12px 18px 12px 18px; border-radius:5px;" align="center"> // <td class="new_button" style="padding: 12px 18px 12px 18px; border-radius:5px;" align="center">
<a href="'. $link .'" target="_blank" style="border: 0 !important;font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; display: inline-block;">'. $text .'</a> // <a href="'. $link .'" target="_blank" style="border: 0 !important;font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; display: inline-block;">'. $text .'</a>
</td> // </td>
</tr> // </tr>
</table> // </table>
'; // ';
} }
} }

View File

@ -355,14 +355,14 @@ class PaymentHtmlEngine
'; ';
return ' // return '
<table border="0" cellspacing="0" cellpadding="0" align="center"> // <table border="0" cellspacing="0" cellpadding="0" align="center">
<tr style="border: 0 !important; "> // <tr style="border: 0 !important; ">
<td class="new_button" style="padding: 12px 18px 12px 18px; border-radius:5px;" align="center"> // <td class="new_button" style="padding: 12px 18px 12px 18px; border-radius:5px;" align="center">
<a href="'. $link .'" target="_blank" style="border: 0 !important;font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; display: inline-block;">'. $text .'</a> // <a href="'. $link .'" target="_blank" style="border: 0 !important;font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; display: inline-block;">'. $text .'</a>
</td> // </td>
</tr> // </tr>
</table> // </table>
'; // ';
} }
} }

View File

@ -240,8 +240,10 @@ class TemplateEngine
} else { } else {
$data['signature'] = $this->settings->email_signature; $data['signature'] = $this->settings->email_signature;
$data['settings'] = $this->settings; $data['settings'] = $this->settings;
$data['whitelabel'] = $this->entity_obj ? $this->entity_obj->company->account->isPaid() : true; // $data['whitelabel'] = $this->entity_obj ? $this->entity_obj->company->account->isPaid() : true;
$data['company'] = $this->entity_obj ? $this->entity_obj->company : ''; // $data['company'] = $this->entity_obj ? $this->entity_obj->company : '';
$data['whitelabel'] = $this->entity_obj->company->account->isPaid();
$data['company'] = $this->entity_obj->company;
$data['settings'] = $this->settings; $data['settings'] = $this->settings;
} }