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

Merge pull request #6800 from turbo124/v5-develop

Fixes for deleted invoices showing in portal
This commit is contained in:
David Bomba 2021-10-08 21:24:21 +11:00 committed by GitHub
commit b85e35dd62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 85 additions and 46 deletions

View File

@ -23,6 +23,7 @@ use App\Jobs\Util\SchedulerCheck;
use App\Jobs\Util\SendFailedEmails;
use App\Jobs\Util\UpdateExchangeRates;
use App\Jobs\Util\VersionCheck;
use App\Models\Account;
use App\Utils\Ninja;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@ -69,6 +70,10 @@ class Kernel extends ConsoleKernel
$schedule->job(new SchedulerCheck)->daily()->withoutOverlapping();
$schedule->call(function () {
Account::whereNotNull('id')->update(['is_scheduler_running' => true]);
})->everyFiveMinutes()->withoutOverlapping();
/* Run hosted specific jobs */
if (Ninja::isHosted()) {

View File

@ -75,7 +75,10 @@ class InvitationController extends Controller
$entity_obj = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation';
$invitation = $entity_obj::whereRaw('BINARY `key`= ?', [$invitation_key])
$invitation = $entity_obj::where('key', $invitation_key)
->whereHas($entity, function ($query) {
$query->where('is_deleted',0);
})
->with('contact.client')
->firstOrFail();

View File

@ -216,7 +216,7 @@ class PreviewController extends BaseController
if(!$request->has('entity_id'))
$entity_obj->service()->fillDefaults()->save();
$entity_obj->load('client');
$entity_obj->load('client.contacts','company');
App::forgetInstance('translator');
$t = app('translator');
@ -345,7 +345,7 @@ class PreviewController extends BaseController
$invoice->setRelation('invitations', $invitation);
$invoice->setRelation('client', $client);
$invoice->setRelation('company', auth()->user()->company());
$invoice->load('client');
$invoice->load('client.company');
// nlog(print_r($invoice->toArray(),1));

View File

@ -52,7 +52,7 @@ class QueryLogging
$timeEnd = microtime(true);
$time = $timeEnd - $timeStart;
// nlog("Query count = {$count}");
// info("Query count = {$count}");
if($count > 175){
nlog("Query count = {$count}");

View File

@ -59,6 +59,8 @@ class CreateEntityPdf implements ShouldQueue
public $entity_string = '';
public $client;
/**
* Create a new job instance.
*
@ -69,15 +71,19 @@ class CreateEntityPdf implements ShouldQueue
$this->invitation = $invitation;
if ($invitation instanceof InvoiceInvitation) {
// $invitation->load('contact.client.company','invoice.client','invoice.user.account');
$this->entity = $invitation->invoice;
$this->entity_string = 'invoice';
} elseif ($invitation instanceof QuoteInvitation) {
// $invitation->load('contact.client.company','quote.client','quote.user.account');
$this->entity = $invitation->quote;
$this->entity_string = 'quote';
} elseif ($invitation instanceof CreditInvitation) {
// $invitation->load('contact.client.company','credit.client','credit.user.account');
$this->entity = $invitation->credit;
$this->entity_string = 'credit';
} elseif ($invitation instanceof RecurringInvoiceInvitation) {
// $invitation->load('contact.client.company','recurring_invoice');
$this->entity = $invitation->recurring_invoice;
$this->entity_string = 'recurring_invoice';
}
@ -86,6 +92,8 @@ class CreateEntityPdf implements ShouldQueue
$this->contact = $invitation->contact;
$this->client = $invitation->contact->client;
$this->disk = Ninja::isHosted() ? config('filesystems.default') : $disk;
}
@ -102,7 +110,7 @@ class CreateEntityPdf implements ShouldQueue
App::setLocale($this->contact->preferredLocale());
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->entity->client->getMergedSettings()));
$t->replace(Ninja::transformTranslations($this->client->getMergedSettings()));
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
return (new Phantom)->generate($this->invitation);
@ -111,22 +119,22 @@ class CreateEntityPdf implements ShouldQueue
$entity_design_id = '';
if ($this->entity instanceof Invoice) {
$path = $this->entity->client->invoice_filepath($this->invitation);
$path = $this->client->invoice_filepath($this->invitation);
$entity_design_id = 'invoice_design_id';
} elseif ($this->entity instanceof Quote) {
$path = $this->entity->client->quote_filepath($this->invitation);
$path = $this->client->quote_filepath($this->invitation);
$entity_design_id = 'quote_design_id';
} elseif ($this->entity instanceof Credit) {
$path = $this->entity->client->credit_filepath($this->invitation);
$path = $this->client->credit_filepath($this->invitation);
$entity_design_id = 'credit_design_id';
} elseif ($this->entity instanceof RecurringInvoice) {
$path = $this->entity->client->recurring_invoice_filepath($this->invitation);
$path = $this->client->recurring_invoice_filepath($this->invitation);
$entity_design_id = 'invoice_design_id';
}
$file_path = $path.$this->entity->numberFormatter().'.pdf';
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->client->getSetting($entity_design_id));
// if(!$this->company->account->hasFeature(Account::FEATURE_DIFFERENT_DESIGNS))
// $entity_design_id = 2;
@ -152,18 +160,18 @@ class CreateEntityPdf implements ShouldQueue
$state = [
'template' => $template->elements([
'client' => $this->entity->client,
'client' => $this->client,
'entity' => $this->entity,
'pdf_variables' => (array) $this->entity->company->settings->pdf_variables,
'pdf_variables' => (array) $this->company->settings->pdf_variables,
'$product' => $design->design->product,
'variables' => $variables,
]),
'variables' => $variables,
'options' => [
'all_pages_header' => $this->entity->client->getSetting('all_pages_header'),
'all_pages_footer' => $this->entity->client->getSetting('all_pages_footer'),
'all_pages_header' => $this->client->getSetting('all_pages_header'),
'all_pages_footer' => $this->client->getSetting('all_pages_footer'),
],
'process_markdown' => $this->entity->client->company->markdown_enabled,
'process_markdown' => $this->client->company->markdown_enabled,
];
$maker = new PdfMakerService($state);

View File

@ -74,12 +74,15 @@ class EmailPayment implements ShouldQueue
MultiDB::setDb($this->company->db);
$this->payment->load('invoices');
$this->contact->load('client');
$email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build();
$invitation = null;
if($this->payment->invoices()->exists())
$invitation = $this->payment->invoices()->first()->invitations()->first();
if($this->payment->invoices && $this->payment->invoices->count() >=1)
$invitation = $this->payment->invoices->first()->invitations()->first();
$nmo = new NinjaMailerObject;
$nmo->mailable = new TemplateEmail($email_builder, $this->contact, $invitation);

View File

@ -237,9 +237,12 @@ class Import implements ShouldQueue
//company size check
if ($this->company->invoices()->count() > 500 || $this->company->products()->count() > 500 || $this->company->clients()->count() > 500) {
$this->company->is_large = true;
$this->company->save();
}
$this->company->client_registration_fields = \App\DataMapper\ClientRegistrationFields::generate();
$this->company->save();
$this->setInitialCompanyLedgerBalances();
// $this->fixClientBalances();

View File

@ -38,8 +38,6 @@ class SchedulerCheck implements ShouldQueue
{
set_time_limit(0);
Account::whereNotNull('id')->update(['is_scheduler_running' => true]);
if(config('ninja.app_version') != base_path('VERSION.txt'))
{

View File

@ -47,6 +47,7 @@ class PaymentEmailEngine extends BaseEmailEngine
$this->company = $payment->company;
$this->client = $payment->client;
$this->contact = $contact ?: $this->client->primary_contact()->first();
$this->contact->load('client.company');
$this->settings = $this->client->getMergedSettings();
$this->template_data = $template_data;
$this->helpers = new Helpers();

View File

@ -119,6 +119,10 @@ class Activity extends StaticModel
'hashed_id',
];
protected $with = [
'backup',
];
public function getHashedIdAttribute()
{
return $this->encodePrimaryKey($this->id);

View File

@ -84,12 +84,12 @@ class Client extends BaseModel implements HasLocalePreference
];
protected $with = [
'gateway_tokens',
'documents',
'contacts.company',
// 'gateway_tokens',
// 'documents',
// 'contacts.company',
// 'currency',
// 'primary_contact',
'country',
// 'country',
// 'contacts',
// 'shipping_country',
// 'company',

View File

@ -64,6 +64,10 @@ class Subscription extends BaseModel
'deleted_at' => 'timestamp',
];
protected $with = [
'company',
];
public function service(): SubscriptionService
{
return new SubscriptionService($this);

View File

@ -30,9 +30,9 @@ class QuoteObserver
->where('event_id', Webhook::EVENT_CREATE_QUOTE)
->exists();
$quote->load('client');
if ($subscriptions) {
$quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote, $quote->company);
}
}
@ -49,10 +49,10 @@ class QuoteObserver
->where('event_id', Webhook::EVENT_UPDATE_QUOTE)
->exists();
$quote->load('client');
if ($subscriptions) {
$quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company);
}
@ -71,6 +71,7 @@ class QuoteObserver
->exists();
if ($subscriptions) {
$quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote, $quote->company);
}
}

View File

@ -70,13 +70,9 @@ class ActivityRepository extends BaseRepository
*/
public function createBackup($entity, $activity)
{
if($entity instanceof User){
}
else if ($entity->company->is_disabled) {
if ($entity instanceof User || $entity->company->is_disabled)
return;
}
$backup = new Backup();
@ -85,6 +81,7 @@ class ActivityRepository extends BaseRepository
|| get_class($entity) == Credit::class
|| get_class($entity) == RecurringInvoice::class
) {
$entity->load('company', 'client');
$contact = $entity->client->primary_contact()->first();
$backup->html_backup = $this->generateHtml($entity);
$backup->amount = $entity->amount;
@ -92,7 +89,6 @@ class ActivityRepository extends BaseRepository
$backup->activity_id = $activity->id;
$backup->json_backup = '';
//$backup->json_backup = $entity->toJson();
$backup->save();
}
@ -121,6 +117,8 @@ class ActivityRepository extends BaseRepository
$entity_design_id = 'credit_design_id';
}
$entity->load('client','client.company');
$entity_design_id = $entity->design_id ? $entity->design_id : $this->decodePrimaryKey($entity->client->getSetting($entity_design_id));
$design = Design::find($entity_design_id);

View File

@ -322,6 +322,8 @@ class InvoiceService
public function deletePdf()
{
$this->invoice->load('invitations');
$this->invoice->invitations->each(function ($invitation){
Storage::disk(config('filesystems.default'))->delete($this->invoice->client->invoice_filepath($invitation) . $this->invoice->numberFormatter().'.pdf');

View File

@ -32,6 +32,8 @@ class SendEmail
*/
public function run()
{
$this->payment->load('company', 'client.contacts');
$this->payment->client->contacts->each(function ($contact) {
if ($contact->email) {
EmailPayment::dispatchNow($this->payment, $this->payment->company, $contact);

View File

@ -165,6 +165,7 @@ class CompanyTransformer extends EntityTransformer
'markdown_enabled' => (bool) $company->markdown_enabled,
'use_comma_as_decimal_place' => (bool) $company->use_comma_as_decimal_place,
'report_include_drafts' => (bool) $company->report_include_drafts,
'client_registration_fields' => (array) $company->client_registration_fields,
];
}

View File

@ -49,6 +49,7 @@ class HtmlEngine
public function __construct($invitation)
{
$this->invitation = $invitation;
// $invitation->load('contact.client.company', 'company');
$this->entity_string = $this->resolveEntityString();
@ -58,7 +59,9 @@ class HtmlEngine
$this->contact = $invitation->contact;
$this->client = $this->entity->client;
$this->client = $invitation->contact->client;
$this->client->load('country','company');
$this->entity->load('client');
$this->settings = $this->client->getMergedSettings();
@ -113,19 +116,19 @@ class HtmlEngine
$data['$total_tax_values'] = ['value' => $this->totalTaxValues(), 'label' => ctrans('texts.taxes')];
$data['$line_tax_labels'] = ['value' => $this->lineTaxLabels(), 'label' => ctrans('texts.taxes')];
$data['$line_tax_values'] = ['value' => $this->lineTaxValues(), 'label' => ctrans('texts.taxes')];
$data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->entity->client->date_format(), $this->entity->client->locale()) ?: ' ', 'label' => ctrans('texts.date')];
$data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->client->date_format(), $this->client->locale()) ?: ' ', 'label' => ctrans('texts.date')];
$data['$invoice.date'] = &$data['$date'];
$data['$invoiceDate'] = &$data['$date'];
$data['$due_date'] = ['value' => $this->translateDate($this->entity->due_date, $this->entity->client->date_format(), $this->entity->client->locale()) ?: ' ', 'label' => ctrans('texts.'.$this->entity_string.'_due_date')];
$data['$due_date'] = ['value' => $this->translateDate($this->entity->due_date, $this->client->date_format(), $this->client->locale()) ?: ' ', 'label' => ctrans('texts.'.$this->entity_string.'_due_date')];
$data['$dueDate'] = &$data['$due_date'];
$data['$payment_due'] = ['value' => $this->translateDate($this->entity->due_date, $this->entity->client->date_format(), $this->entity->client->locale()) ?: ' ', 'label' => ctrans('texts.payment_due')];
$data['$payment_due'] = ['value' => $this->translateDate($this->entity->due_date, $this->client->date_format(), $this->client->locale()) ?: ' ', 'label' => ctrans('texts.payment_due')];
$data['$invoice.due_date'] = &$data['$due_date'];
$data['$invoice.number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.invoice_number')];
$data['$invoice.po_number'] = ['value' => $this->entity->po_number ?: ' ', 'label' => ctrans('texts.po_number')];
$data['$poNumber'] = &$data['$invoice.po_number'];
$data['$entity.datetime'] = ['value' => $this->formatDatetime($this->entity->created_at, $this->entity->client->date_format(), $this->entity->client->locale()), 'label' => ctrans('texts.date')];
$data['$entity.datetime'] = ['value' => $this->formatDatetime($this->entity->created_at, $this->client->date_format(), $this->client->locale()), 'label' => ctrans('texts.date')];
$data['$invoice.datetime'] = &$data['$entity.datetime'];
$data['$quote.datetime'] = &$data['$entity.datetime'];
$data['$credit.datetime'] = &$data['$entity.datetime'];
@ -145,9 +148,9 @@ class HtmlEngine
$data['$view_button'] = &$data['$view_link'];
$data['$paymentButton'] = &$data['$payment_button'];
$data['$view_url'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_invoice')];
$data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->entity->client->date_format(), $this->entity->client->locale()) ?: ' ', 'label' => ctrans('texts.invoice_date')];
$data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->client->date_format(), $this->client->locale()) ?: ' ', 'label' => ctrans('texts.invoice_date')];
if($this->entity->project()->exists()) {
if($this->entity->project) {
$data['$project.name'] = ['value' => $this->entity->project->name, 'label' => ctrans('texts.project_name')];
}
}
@ -164,7 +167,7 @@ class HtmlEngine
$data['$view_button'] = &$data['$view_link'];
$data['$approveButton'] = ['value' => '<a class="button" href="'.$this->invitation->getLink().'">'.ctrans('texts.view_quote').'</a>', 'label' => ctrans('texts.approve')];
$data['$view_url'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_quote')];
$data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->entity->client->date_format(), $this->entity->client->locale()) ?: '&nbsp;', 'label' => ctrans('texts.quote_date')];
$data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->client->date_format(), $this->client->locale()) ?: '&nbsp;', 'label' => ctrans('texts.quote_date')];
}
if ($this->entity_string == 'credit') {
@ -179,7 +182,7 @@ class HtmlEngine
$data['$viewLink'] = &$data['$view_link'];
$data['$view_url'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_credit')];
// $data['$view_link'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_credit')];
$data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->entity->client->date_format(), $this->entity->client->locale()) ?: '&nbsp;', 'label' => ctrans('texts.credit_date')];
$data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->client->date_format(), $this->client->locale()) ?: '&nbsp;', 'label' => ctrans('texts.credit_date')];
}
$data['$portal_url'] = ['value' => $this->invitation->getPortalLink(), 'label' =>''];
@ -200,7 +203,7 @@ class HtmlEngine
if ($this->entity->partial > 0) {
$data['$balance_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: '&nbsp;', 'label' => ctrans('texts.partial_due')];
$data['$balance_due_raw'] = ['value' => $this->entity->partial, 'label' => ctrans('texts.partial_due')];
$data['$due_date'] = ['value' => $this->translateDate($this->entity->partial_due_date, $this->entity->client->date_format(), $this->entity->client->locale()) ?: '&nbsp;', 'label' => ctrans('texts.'.$this->entity_string.'_due_date')];
$data['$due_date'] = ['value' => $this->translateDate($this->entity->partial_due_date, $this->client->date_format(), $this->client->locale()) ?: '&nbsp;', 'label' => ctrans('texts.'.$this->entity_string.'_due_date')];
} else {
@ -233,7 +236,7 @@ class HtmlEngine
$data['$credit.number'] = ['value' => $this->entity->number ?: '&nbsp;', 'label' => ctrans('texts.credit_number')];
$data['$credit.total'] = &$data['$credit.total'];
$data['$credit.po_number'] = &$data['$invoice.po_number'];
$data['$credit.date'] = ['value' => $this->translateDate($this->entity->date, $this->entity->client->date_format(), $this->entity->client->locale()), 'label' => ctrans('texts.credit_date')];
$data['$credit.date'] = ['value' => $this->translateDate($this->entity->date, $this->client->date_format(), $this->client->locale()), 'label' => ctrans('texts.credit_date')];
$data['$balance'] = ['value' => Number::formatMoney($this->entity_calc->getBalance(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.balance')];
$data['$credit.balance'] = &$data['$balance'];
@ -260,13 +263,13 @@ class HtmlEngine
$data['$entity_issued_to'] = ['value' => '', 'label' => ctrans("texts.{$this->entity_string}_issued_to")];
$data['$your_entity'] = ['value' => '', 'label' => ctrans("texts.your_{$this->entity_string}")];
$data['$quote.date'] = ['value' => $this->translateDate($this->entity->date, $this->entity->client->date_format(), $this->entity->client->locale()) ?: '&nbsp;', 'label' => ctrans('texts.quote_date')];
$data['$quote.date'] = ['value' => $this->translateDate($this->entity->date, $this->client->date_format(), $this->client->locale()) ?: '&nbsp;', 'label' => ctrans('texts.quote_date')];
$data['$quote.number'] = ['value' => $this->entity->number ?: '&nbsp;', 'label' => ctrans('texts.quote_number')];
$data['$quote.po_number'] = &$data['$invoice.po_number'];
$data['$quote.quote_number'] = &$data['$quote.number'];
$data['$quote_no'] = &$data['$quote.number'];
$data['$quote.quote_no'] = &$data['$quote.number'];
$data['$quote.valid_until'] = ['value' => $this->translateDate($this->entity->due_date, $this->client->date_format(), $this->entity->client->locale()), 'label' => ctrans('texts.valid_until')];
$data['$quote.valid_until'] = ['value' => $this->translateDate($this->entity->due_date, $this->client->date_format(), $this->client->locale()), 'label' => ctrans('texts.valid_until')];
$data['$valid_until'] = &$data['$quote.valid_until'];
$data['$credit_amount'] = ['value' => Number::formatMoney($this->entity_calc->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.credit_amount')];
$data['$credit_balance'] = ['value' => Number::formatMoney($this->entity->balance, $this->client) ?: '&nbsp;', 'label' => ctrans('texts.credit_balance')];
@ -461,6 +464,7 @@ class HtmlEngine
/*Payment Aliases*/
$data['$paymentLink'] = &$data['$payment_link'];
$data['$payment_url'] = &$data['$payment_link'];
$data['$portalButton'] = &$data['$paymentLink'];
$data['$dir'] = ['value' => optional($this->client->language())->locale === 'ar' ? 'rtl' : 'ltr', 'label' => ''];

View File

@ -14,6 +14,7 @@
@csrf
<div class="grid grid-cols-12 gap-4 mt-10">
@if($company->client_registration_fields)
@foreach($company->client_registration_fields as $field)
@if($field['required'])
<div class="col-span-12 md:col-span-6">
@ -96,6 +97,7 @@
@endif
@endif
@endforeach
@endif
</div>
<div class="flex justify-between items-center mt-8">