mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
cs-fixer
This commit is contained in:
parent
7f2f9d6faa
commit
137231c95e
@ -332,16 +332,16 @@ class CheckData extends Command
|
||||
$total_amount = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.amount');
|
||||
$total_refund = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.refunded');
|
||||
|
||||
$total_invoice_payments += ($total_amount - $total_refund);
|
||||
$total_invoice_payments += ($total_amount - $total_refund);
|
||||
}
|
||||
|
||||
foreach($client->payments as $payment)
|
||||
{
|
||||
$credit_total_applied += $payment->paymentables->where('paymentable_type', App\Models\Credit::class)->sum(DB::raw('amount'));
|
||||
foreach ($client->payments as $payment) {
|
||||
$credit_total_applied += $payment->paymentables->where('paymentable_type', App\Models\Credit::class)->sum(DB::raw('amount'));
|
||||
}
|
||||
|
||||
if($credit_total_applied < 0)
|
||||
$total_invoice_payments += $credit_total_applied; //todo this is contentious
|
||||
if ($credit_total_applied < 0) {
|
||||
$total_invoice_payments += $credit_total_applied;
|
||||
} //todo this is contentious
|
||||
|
||||
info("total invoice payments = {$total_invoice_payments} with client paid to date of of {$client->paid_to_date}");
|
||||
|
||||
|
@ -100,7 +100,6 @@ class CreateSingleAccount extends Command
|
||||
$this->warmCache();
|
||||
|
||||
$this->createSmallAccount();
|
||||
|
||||
}
|
||||
|
||||
private function createSmallAccount()
|
||||
@ -205,7 +204,6 @@ class CreateSingleAccount extends Command
|
||||
|
||||
$this->info('creating credit for client #'.$client->id);
|
||||
$this->createCredit($client);
|
||||
|
||||
}
|
||||
|
||||
$this->createGateways($company, $user);
|
||||
@ -299,7 +297,6 @@ class CreateSingleAccount extends Command
|
||||
|
||||
private function createInvoice($client)
|
||||
{
|
||||
|
||||
$faker = Factory::create();
|
||||
|
||||
$invoice = InvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id
|
||||
@ -369,7 +366,6 @@ class CreateSingleAccount extends Command
|
||||
|
||||
private function createQuote($client)
|
||||
{
|
||||
|
||||
$faker = Factory::create();
|
||||
|
||||
$quote = Quote::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
|
||||
@ -414,21 +410,21 @@ class CreateSingleAccount extends Command
|
||||
{
|
||||
$line_items = [];
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->quantity = 1;
|
||||
$item->cost = 1000;
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->quantity = 1;
|
||||
$item->cost = 1000;
|
||||
|
||||
$product = Product::all()->random();
|
||||
$product = Product::all()->random();
|
||||
|
||||
$item->cost = (float) $product->cost;
|
||||
$item->product_key = $product->product_key;
|
||||
$item->notes = $product->notes;
|
||||
$item->custom_value1 = $product->custom_value1;
|
||||
$item->custom_value2 = $product->custom_value2;
|
||||
$item->custom_value3 = $product->custom_value3;
|
||||
$item->custom_value4 = $product->custom_value4;
|
||||
$item->cost = (float) $product->cost;
|
||||
$item->product_key = $product->product_key;
|
||||
$item->notes = $product->notes;
|
||||
$item->custom_value1 = $product->custom_value1;
|
||||
$item->custom_value2 = $product->custom_value2;
|
||||
$item->custom_value3 = $product->custom_value3;
|
||||
$item->custom_value4 = $product->custom_value4;
|
||||
|
||||
$line_items[] = $item;
|
||||
$line_items[] = $item;
|
||||
|
||||
|
||||
return $line_items;
|
||||
@ -505,7 +501,6 @@ class CreateSingleAccount extends Command
|
||||
|
||||
private function createGateways($company, $user)
|
||||
{
|
||||
|
||||
if (config('ninja.testvars.stripe') && ($this->gateway == 'all' || $this->gateway == 'stripe')) {
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $company->id;
|
||||
|
@ -471,7 +471,6 @@ class CreateTestData extends Command
|
||||
|
||||
private function createInvoice($client)
|
||||
{
|
||||
|
||||
$faker = Factory::create();
|
||||
|
||||
$invoice = InvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id
|
||||
@ -522,7 +521,6 @@ class CreateTestData extends Command
|
||||
|
||||
private function createCredit($client)
|
||||
{
|
||||
|
||||
$faker = Factory::create();
|
||||
|
||||
$credit = Credit::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
|
||||
@ -562,7 +560,6 @@ class CreateTestData extends Command
|
||||
|
||||
private function createQuote($client)
|
||||
{
|
||||
|
||||
$faker = Factory::create();
|
||||
|
||||
//$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id
|
||||
|
@ -303,7 +303,7 @@ class DemoMode extends Command
|
||||
'is_primary' => 1,
|
||||
]);
|
||||
|
||||
ClientContact::factory()->count(rand(1,5))->create([
|
||||
ClientContact::factory()->count(rand(1, 5))->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id,
|
||||
'company_id' => $company->id,
|
||||
@ -325,7 +325,7 @@ class DemoMode extends Command
|
||||
|
||||
private function createExpense($client)
|
||||
{
|
||||
Expense::factory()->count(rand(1,5))->create([
|
||||
Expense::factory()->count(rand(1, 5))->create([
|
||||
'user_id' => $client->user_id,
|
||||
'client_id' => $client->id,
|
||||
'company_id' => $client->company_id,
|
||||
@ -346,7 +346,7 @@ class DemoMode extends Command
|
||||
'is_primary' => 1,
|
||||
]);
|
||||
|
||||
VendorContact::factory()->count(rand(1,5))->create([
|
||||
VendorContact::factory()->count(rand(1, 5))->create([
|
||||
'user_id' => $client->user->id,
|
||||
'vendor_id' => $vendor->id,
|
||||
'company_id' => $client->company_id,
|
||||
@ -376,7 +376,6 @@ class DemoMode extends Command
|
||||
|
||||
private function createInvoice($client, $assigned_user_id = null)
|
||||
{
|
||||
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$invoice = InvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id
|
||||
@ -441,7 +440,6 @@ class DemoMode extends Command
|
||||
|
||||
private function createCredit($client, $assigned_user_id = null)
|
||||
{
|
||||
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$credit = Credit::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
|
||||
|
@ -46,7 +46,6 @@ class PostUpdate extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
info('running post update');
|
||||
@ -73,6 +72,5 @@ class PostUpdate extends Command
|
||||
$application->run($input);
|
||||
|
||||
echo "Done.";
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -65,10 +65,9 @@ class SendRemindersCron extends Command
|
||||
->whereDate('due_date', now()->subDays(1)->startOfDay())
|
||||
->cursor();
|
||||
|
||||
$invoices->each(function ($invoice){
|
||||
$invoices->each(function ($invoice) {
|
||||
WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private function webHookExpiredQuotes()
|
||||
@ -78,7 +77,7 @@ class SendRemindersCron extends Command
|
||||
->whereDate('due_date', now()->subDays(1)->startOfDay())
|
||||
->cursor();
|
||||
|
||||
$quotes->each(function ($quote){
|
||||
$quotes->each(function ($quote) {
|
||||
WebHookHandler::dispatch(Webhook::EVENT_EXPIRED_QUOTE, $quote, $quote->company);
|
||||
});
|
||||
}
|
||||
|
@ -82,7 +82,6 @@ class SendTestEmails extends Command
|
||||
$user = User::whereEmail('user@example.com')->first();
|
||||
|
||||
if (! $user) {
|
||||
|
||||
$account = Account::factory()->create();
|
||||
|
||||
$user = User::factory()->create([
|
||||
|
@ -175,13 +175,13 @@ class CompanySettings extends BaseSettings
|
||||
public $email_template_reminder3 = ''; //@implemented
|
||||
public $email_template_reminder_endless = ''; //@implemented
|
||||
public $email_signature = ''; //@implemented
|
||||
public $enable_email_markup = true; //@TODO -
|
||||
public $enable_email_markup = true; //@TODO -
|
||||
|
||||
public $email_subject_custom1 = ''; //@TODO
|
||||
public $email_subject_custom2 = ''; //@TODO
|
||||
public $email_subject_custom3 = ''; //@TODO
|
||||
|
||||
public $email_template_custom1 = ''; //@TODO
|
||||
public $email_template_custom1 = ''; //@TODO
|
||||
public $email_template_custom2 = ''; //@TODO
|
||||
public $email_template_custom3 = ''; //@TODO
|
||||
|
||||
@ -195,7 +195,7 @@ class CompanySettings extends BaseSettings
|
||||
public $num_days_reminder3 = 0;//@implmemented
|
||||
|
||||
public $schedule_reminder1 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented
|
||||
public $schedule_reminder2 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented
|
||||
public $schedule_reminder2 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented
|
||||
public $schedule_reminder3 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented
|
||||
|
||||
public $reminder_send_time = 32400; //number of seconds from UTC +0 to send reminders @TODO
|
||||
@ -511,7 +511,7 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
/**
|
||||
* Provides class defaults on init.
|
||||
*
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
public static function defaults(): stdClass
|
||||
@ -544,7 +544,7 @@ class CompanySettings extends BaseSettings
|
||||
* set new properties to the object prior to being returned.
|
||||
*
|
||||
* @param $settings
|
||||
*
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
public static function setProperties($settings): stdClass
|
||||
@ -562,7 +562,7 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
/**
|
||||
* Stubs the notification defaults
|
||||
*
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
public static function notificationDefaults() :stdClass
|
||||
@ -575,7 +575,7 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
/**
|
||||
* Defines entity variables for PDF generation
|
||||
*
|
||||
*
|
||||
* @return stdClass The stdClass of PDF variables
|
||||
*/
|
||||
private static function getEntityVariableDefaults() :stdClass
|
||||
|
@ -148,11 +148,9 @@ class EmailTemplateDefaults
|
||||
|
||||
public static function emailPaymentTemplate()
|
||||
{
|
||||
|
||||
$payment_message = '<p>'.self::transformText('payment_message').'</p><br><br><p>$view_link</p>';
|
||||
|
||||
return $payment_message;
|
||||
|
||||
}
|
||||
|
||||
public static function emailCreditTemplate()
|
||||
@ -164,11 +162,9 @@ class EmailTemplateDefaults
|
||||
|
||||
public static function emailPaymentPartialTemplate()
|
||||
{
|
||||
|
||||
$payment_message = '<p>'.self::transformText('payment_message').'</p><br><br><p>$view_link</p>';
|
||||
|
||||
return $payment_message;
|
||||
|
||||
}
|
||||
|
||||
public static function emailPaymentPartialSubject()
|
||||
|
@ -24,9 +24,9 @@ class TaskFactory
|
||||
$task->company_id = $company_id;
|
||||
$task->user_id = $user_id;
|
||||
$task->time_log = '[]';
|
||||
$task->is_running = false;
|
||||
$task->is_deleted = false;
|
||||
$task->duration = 0;
|
||||
$task->is_running = false;
|
||||
$task->is_deleted = false;
|
||||
$task->duration = 0;
|
||||
|
||||
return $task;
|
||||
}
|
||||
|
@ -51,13 +51,11 @@ class SystemLogFilters extends QueryFilters
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
{
|
||||
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,7 +231,7 @@ class InvoiceItemSum
|
||||
}
|
||||
|
||||
//$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
|
||||
$amount = ( $this->sub_total > 0 ) ? $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)) : 0;
|
||||
$amount = ($this->sub_total > 0) ? $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)) : 0;
|
||||
|
||||
|
||||
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
|
||||
@ -264,7 +264,7 @@ class InvoiceItemSum
|
||||
|
||||
/**
|
||||
* Sets default casts for the values in the line_items.
|
||||
*
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
private function cleanLineItem()
|
||||
|
@ -160,17 +160,21 @@ class InvoiceSum
|
||||
{
|
||||
$this->total += $this->total_taxes;
|
||||
|
||||
if(is_numeric($this->invoice->custom_value1) && $this->invoice->custom_value1 > 0)
|
||||
if (is_numeric($this->invoice->custom_value1) && $this->invoice->custom_value1 > 0) {
|
||||
$this->total += $this->invoice->custom_value1;
|
||||
}
|
||||
|
||||
if(is_numeric($this->invoice->custom_value2) && $this->invoice->custom_value2 > 0)
|
||||
if (is_numeric($this->invoice->custom_value2) && $this->invoice->custom_value2 > 0) {
|
||||
$this->total += $this->invoice->custom_value2;
|
||||
}
|
||||
|
||||
if(is_numeric($this->invoice->custom_value3) && $this->invoice->custom_value3 > 0)
|
||||
if (is_numeric($this->invoice->custom_value3) && $this->invoice->custom_value3 > 0) {
|
||||
$this->total += $this->invoice->custom_value3;
|
||||
}
|
||||
|
||||
if(is_numeric($this->invoice->custom_value4) && $this->invoice->custom_value4 > 0)
|
||||
if (is_numeric($this->invoice->custom_value4) && $this->invoice->custom_value4 > 0) {
|
||||
$this->total += $this->invoice->custom_value4;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -202,7 +206,6 @@ class InvoiceSum
|
||||
|
||||
public function getRecurringInvoice()
|
||||
{
|
||||
|
||||
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
$this->invoice->total_taxes = $this->getTotalTaxes();
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
@ -220,8 +223,7 @@ class InvoiceSum
|
||||
{
|
||||
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
|
||||
|
||||
if($this->invoice->status_id != Invoice::STATUS_DRAFT)
|
||||
{
|
||||
if ($this->invoice->status_id != Invoice::STATUS_DRAFT) {
|
||||
if ($this->invoice->amount != $this->invoice->balance) {
|
||||
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
|
||||
|
||||
@ -318,7 +320,6 @@ class InvoiceSum
|
||||
|
||||
public function purgeTaxes()
|
||||
{
|
||||
|
||||
$this->tax_rate1 = 0;
|
||||
$this->tax_name1 = '';
|
||||
|
||||
@ -332,7 +333,7 @@ class InvoiceSum
|
||||
|
||||
$line_items = collect($this->invoice->line_items);
|
||||
|
||||
$items = $line_items->map(function ($item){
|
||||
$items = $line_items->map(function ($item) {
|
||||
$item->tax_rate1 = 0;
|
||||
$item->tax_rate2 = 0;
|
||||
$item->tax_rate3 = 0;
|
||||
@ -350,5 +351,4 @@ class InvoiceSum
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class InvoiceSumInclusive
|
||||
->calculateCustomValues()
|
||||
->calculateInvoiceTaxes()
|
||||
->setTaxMap()
|
||||
->calculateTotals() //just don't add the taxes!!
|
||||
->calculateTotals() //just don't add the taxes!!
|
||||
->calculateBalance()
|
||||
->calculatePartial();
|
||||
|
||||
@ -172,24 +172,27 @@ class InvoiceSumInclusive
|
||||
{
|
||||
//$this->total += $this->total_taxes;
|
||||
|
||||
if(is_numeric($this->invoice->custom_value1) && $this->invoice->custom_value1 > 0)
|
||||
if (is_numeric($this->invoice->custom_value1) && $this->invoice->custom_value1 > 0) {
|
||||
$this->total += $this->invoice->custom_value1;
|
||||
}
|
||||
|
||||
if(is_numeric($this->invoice->custom_value2) && $this->invoice->custom_value2 > 0)
|
||||
if (is_numeric($this->invoice->custom_value2) && $this->invoice->custom_value2 > 0) {
|
||||
$this->total += $this->invoice->custom_value2;
|
||||
}
|
||||
|
||||
if(is_numeric($this->invoice->custom_value3) && $this->invoice->custom_value3 > 0)
|
||||
if (is_numeric($this->invoice->custom_value3) && $this->invoice->custom_value3 > 0) {
|
||||
$this->total += $this->invoice->custom_value3;
|
||||
}
|
||||
|
||||
if(is_numeric($this->invoice->custom_value4) && $this->invoice->custom_value4 > 0)
|
||||
$this->total += $this->invoice->custom_value4;
|
||||
if (is_numeric($this->invoice->custom_value4) && $this->invoice->custom_value4 > 0) {
|
||||
$this->total += $this->invoice->custom_value4;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRecurringInvoice()
|
||||
{
|
||||
|
||||
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
$this->invoice->total_taxes = $this->getTotalTaxes();
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
@ -329,7 +332,6 @@ class InvoiceSumInclusive
|
||||
|
||||
public function purgeTaxes()
|
||||
{
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -80,5 +80,4 @@ class ContactLoginController extends Controller
|
||||
|
||||
return redirect('/client/login');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -173,8 +173,7 @@ class LoginController extends BaseController
|
||||
$cu = CompanyUser::query()
|
||||
->where('user_id', auth()->user()->id);
|
||||
|
||||
return $this->listResponse($cu);
|
||||
|
||||
return $this->listResponse($cu);
|
||||
} else {
|
||||
LightLogs::create(new LoginFailure())
|
||||
->increment()
|
||||
|
@ -207,12 +207,12 @@ class BaseController extends Controller
|
||||
$updated_at = date('Y-m-d H:i:s', $updated_at);
|
||||
|
||||
$query->with(
|
||||
[
|
||||
[
|
||||
'company' => function ($query) use ($updated_at) {
|
||||
$query->whereNotNull('updated_at')->with('documents');
|
||||
},
|
||||
'company.clients' => function ($query) use ($updated_at) {
|
||||
$query->where('clients.updated_at', '>=', $updated_at)->with('contacts.company', 'gateway_tokens','documents');
|
||||
$query->where('clients.updated_at', '>=', $updated_at)->with('contacts.company', 'gateway_tokens', 'documents');
|
||||
},
|
||||
'company.company_gateways' => function ($query) {
|
||||
$query->whereNotNull('updated_at');
|
||||
@ -236,7 +236,7 @@ class BaseController extends Controller
|
||||
$query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents');
|
||||
},
|
||||
'company.payments'=> function ($query) use ($updated_at) {
|
||||
$query->where('updated_at', '>=', $updated_at)->with('paymentables','documents');
|
||||
$query->where('updated_at', '>=', $updated_at)->with('paymentables', 'documents');
|
||||
},
|
||||
'company.payment_terms'=> function ($query) use ($updated_at) {
|
||||
$query->where('updated_at', '>=', $updated_at);
|
||||
@ -245,7 +245,7 @@ class BaseController extends Controller
|
||||
$query->where('updated_at', '>=', $updated_at)->with('documents');
|
||||
},
|
||||
'company.projects'=> function ($query) use ($updated_at) {
|
||||
$query->where('updated_at', '>=', $updated_at)->with('documents' );
|
||||
$query->where('updated_at', '>=', $updated_at)->with('documents');
|
||||
},
|
||||
'company.quotes'=> function ($query) use ($updated_at) {
|
||||
$query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents');
|
||||
@ -254,13 +254,13 @@ class BaseController extends Controller
|
||||
$query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents');
|
||||
},
|
||||
'company.tasks'=> function ($query) use ($updated_at) {
|
||||
$query->where('updated_at', '>=', $updated_at)->with('documents' );
|
||||
$query->where('updated_at', '>=', $updated_at)->with('documents');
|
||||
},
|
||||
'company.tax_rates' => function ($query) use ($updated_at) {
|
||||
$query->where('updated_at', '>=', $updated_at);
|
||||
},
|
||||
'company.vendors'=> function ($query) use ($updated_at) {
|
||||
$query->where('updated_at', '>=', $updated_at)->with('contacts','documents');
|
||||
$query->where('updated_at', '>=', $updated_at)->with('contacts', 'documents');
|
||||
},
|
||||
'company.expense_categories'=> function ($query) use ($updated_at) {
|
||||
$query->where('updated_at', '>=', $updated_at);
|
||||
@ -297,14 +297,17 @@ class BaseController extends Controller
|
||||
|
||||
$query->with($includes);
|
||||
|
||||
if (auth()->user() && ! auth()->user()->hasPermission('view_'.lcfirst(class_basename($this->entity_type))))
|
||||
if (auth()->user() && ! auth()->user()->hasPermission('view_'.lcfirst(class_basename($this->entity_type)))) {
|
||||
$query->where('user_id', '=', auth()->user()->id);
|
||||
}
|
||||
|
||||
if (request()->has('updated_at') && request()->input('updated_at') > 0)
|
||||
if (request()->has('updated_at') && request()->input('updated_at') > 0) {
|
||||
$query->where('updated_at', '>=', date('Y-m-d H:i:s', intval(request()->input('updated_at'))));
|
||||
}
|
||||
|
||||
if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON)
|
||||
if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON) {
|
||||
$this->entity_type = null;
|
||||
}
|
||||
|
||||
if ($query instanceof Builder) {
|
||||
$limit = request()->input('per_page', 20);
|
||||
@ -317,7 +320,6 @@ class BaseController extends Controller
|
||||
}
|
||||
|
||||
return $this->response($this->manager->createData($resource)->toArray());
|
||||
|
||||
}
|
||||
|
||||
protected function response($response)
|
||||
@ -357,13 +359,15 @@ class BaseController extends Controller
|
||||
|
||||
$transformer = new $this->entity_transformer(request()->input('serializer'));
|
||||
|
||||
if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON)
|
||||
if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON) {
|
||||
$this->entity_type = null;
|
||||
}
|
||||
|
||||
$resource = new Item($item, $transformer, $this->entity_type);
|
||||
|
||||
if (auth()->user() && request()->include_static)
|
||||
if (auth()->user() && request()->include_static) {
|
||||
$data['static'] = Statics::company(auth()->user()->getCompany()->getLocale());
|
||||
}
|
||||
|
||||
return $this->response($this->manager->createData($resource)->toArray());
|
||||
}
|
||||
@ -407,7 +411,6 @@ class BaseController extends Controller
|
||||
|
||||
public function flutterRoute()
|
||||
{
|
||||
|
||||
if ((bool) $this->checkAppSetup() !== false && $account = Account::first()) {
|
||||
if (config('ninja.require_https') && ! request()->isSecure()) {
|
||||
return redirect()->secure(request()->getRequestUri());
|
||||
|
@ -25,11 +25,6 @@ class ContactHashLoginController extends Controller
|
||||
*/
|
||||
public function login(string $contact_key)
|
||||
{
|
||||
|
||||
return redirect('/client/login');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,7 +37,6 @@ class InvitationController extends Controller
|
||||
|
||||
public function router(string $entity, string $invitation_key)
|
||||
{
|
||||
|
||||
$key = $entity.'_id';
|
||||
|
||||
$entity_obj = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation';
|
||||
@ -48,18 +47,15 @@ class InvitationController extends Controller
|
||||
|
||||
/* Return early if we have the correct client_hash embedded */
|
||||
|
||||
if(request()->has('client_hash') && request()->input('client_hash') == $invitation->contact->client->client_hash) {
|
||||
if (request()->has('client_hash') && request()->input('client_hash') == $invitation->contact->client->client_hash) {
|
||||
auth()->guard('contact')->login($invitation->contact, true);
|
||||
}
|
||||
else if ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
|
||||
} elseif ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
|
||||
$this->middleware('auth:contact');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
auth()->guard('contact')->login($invitation->contact, true);
|
||||
}
|
||||
|
||||
if (auth()->guard('contact') && ! request()->has('silent') && ! $invitation->viewed_date) {
|
||||
|
||||
$invitation->markViewed();
|
||||
|
||||
event(new InvitationWasViewed($invitation->{$entity}, $invitation, $invitation->{$entity}->company, Ninja::eventVars()));
|
||||
@ -68,8 +64,6 @@ class InvitationController extends Controller
|
||||
}
|
||||
|
||||
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function fireEntityViewedEvent($invitation, $entity_string)
|
||||
|
@ -77,8 +77,9 @@ class PaymentController extends Controller
|
||||
$is_credit_payment = false;
|
||||
$token = false;
|
||||
|
||||
if($request->input('company_gateway_id') == CompanyGateway::GATEWAY_CREDIT)
|
||||
if ($request->input('company_gateway_id') == CompanyGateway::GATEWAY_CREDIT) {
|
||||
$is_credit_payment = true;
|
||||
}
|
||||
|
||||
$gateway = CompanyGateway::find($request->input('company_gateway_id'));
|
||||
|
||||
@ -94,10 +95,8 @@ class PaymentController extends Controller
|
||||
$invoices = Invoice::whereIn('id', $this->transformKeys($payable_invoices->pluck('invoice_id')->toArray()))->get();
|
||||
|
||||
/* pop non payable invoice from the $payable_invoices array */
|
||||
$payable_invoices = $payable_invoices->filter(function ($payable_invoice) use ($invoices){
|
||||
|
||||
$payable_invoices = $payable_invoices->filter(function ($payable_invoice) use ($invoices) {
|
||||
return $invoices->where('hashed_id', $payable_invoice['invoice_id'])->first()->isPayable();
|
||||
|
||||
});
|
||||
|
||||
/*return early if no invoices*/
|
||||
@ -110,8 +109,7 @@ class PaymentController extends Controller
|
||||
$settings = auth()->user()->client->getMergedSettings();
|
||||
|
||||
/*iterate through invoices and add gateway fees and other payment metadata*/
|
||||
$payable_invoices = $payable_invoices->map(function($payable_invoice) use($invoices, $settings){
|
||||
|
||||
$payable_invoices = $payable_invoices->map(function ($payable_invoice) use ($invoices, $settings) {
|
||||
$payable_invoice['amount'] = Number::parseFloat($payable_invoice['amount']);
|
||||
|
||||
$invoice = $invoices->first(function ($inv) use ($payable_invoice) {
|
||||
@ -167,7 +165,6 @@ class PaymentController extends Controller
|
||||
$payable_invoice['additional_info'] = $additional_info;
|
||||
|
||||
return $payable_invoice;
|
||||
|
||||
});
|
||||
|
||||
if (request()->has('signature') && !is_null(request()->signature) && !empty(request()->signature)) {
|
||||
@ -182,8 +179,9 @@ class PaymentController extends Controller
|
||||
$credit_totals = $first_invoice->client->getSetting('use_credits_payment') == 'off' ? 0 : $first_invoice->client->service()->getCreditBalance();
|
||||
$starting_invoice_amount = $first_invoice->amount;
|
||||
|
||||
if($gateway)
|
||||
if ($gateway) {
|
||||
$first_invoice->service()->addGatewayFee($gateway, $payment_method_id, $invoice_totals)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gateway fee is calculated
|
||||
@ -192,8 +190,9 @@ class PaymentController extends Controller
|
||||
*/
|
||||
$fee_totals = $first_invoice->amount - $starting_invoice_amount;
|
||||
|
||||
if($gateway)
|
||||
if ($gateway) {
|
||||
$token = auth()->user()->client->gateway_token($gateway->id, $payment_method_id);
|
||||
}
|
||||
|
||||
$payment_hash = new PaymentHash;
|
||||
$payment_hash->hash = Str::random(128);
|
||||
@ -218,7 +217,7 @@ class PaymentController extends Controller
|
||||
'amount_with_fee' => $invoice_totals + $fee_totals,
|
||||
];
|
||||
|
||||
if($is_credit_payment) {
|
||||
if ($is_credit_payment) {
|
||||
return $this->processCreditPayment($request, $data);
|
||||
}
|
||||
|
||||
@ -252,9 +251,9 @@ class PaymentController extends Controller
|
||||
$payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->first();
|
||||
|
||||
/* Hydrate the $payment */
|
||||
if($payment_hash->payment()->exists())
|
||||
if ($payment_hash->payment()->exists()) {
|
||||
$payment = $payment_hash->payment;
|
||||
else {
|
||||
} else {
|
||||
$payment = PaymentFactory::create($payment_hash->fee_invoice->company_id, $payment_hash->fee_invoice->user_id);
|
||||
$payment->client_id = $payment_hash->fee_invoice->client_id;
|
||||
$payment->save();
|
||||
@ -264,8 +263,7 @@ class PaymentController extends Controller
|
||||
}
|
||||
|
||||
/* Iterate through the invoices and apply credits to them */
|
||||
collect($payment_hash->invoices())->each(function ($payable_invoice) use ($payment, $payment_hash){
|
||||
|
||||
collect($payment_hash->invoices())->each(function ($payable_invoice) use ($payment, $payment_hash) {
|
||||
$invoice = Invoice::find($this->decodePrimaryKey($payable_invoice->invoice_id));
|
||||
$amount = $payable_invoice->amount;
|
||||
|
||||
@ -274,35 +272,31 @@ class PaymentController extends Controller
|
||||
->service()
|
||||
->getCredits();
|
||||
|
||||
foreach($credits as $credit)
|
||||
{
|
||||
//starting invoice balance
|
||||
$invoice_balance = $invoice->balance;
|
||||
foreach ($credits as $credit) {
|
||||
//starting invoice balance
|
||||
$invoice_balance = $invoice->balance;
|
||||
|
||||
//credit payment applied
|
||||
$credit->service()->applyPayment($invoice, $amount, $payment);
|
||||
//credit payment applied
|
||||
$credit->service()->applyPayment($invoice, $amount, $payment);
|
||||
|
||||
//amount paid from invoice calculated
|
||||
$remaining_balance = ($invoice_balance - $invoice->fresh()->balance);
|
||||
//amount paid from invoice calculated
|
||||
$remaining_balance = ($invoice_balance - $invoice->fresh()->balance);
|
||||
|
||||
//reduce the amount to be paid on the invoice from the NEXT credit
|
||||
$amount -= $remaining_balance;
|
||||
//reduce the amount to be paid on the invoice from the NEXT credit
|
||||
$amount -= $remaining_balance;
|
||||
|
||||
//break if the invoice is no longer PAYABLE OR there is no more amount to be applied
|
||||
if(!$invoice->isPayable() || (int)$amount == 0)
|
||||
break;
|
||||
//break if the invoice is no longer PAYABLE OR there is no more amount to be applied
|
||||
if (!$invoice->isPayable() || (int)$amount == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]);
|
||||
|
||||
}
|
||||
|
||||
public function processCreditPayment(Request $request, array $data)
|
||||
{
|
||||
|
||||
return render('gateways.credit.index', $data);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -408,9 +408,9 @@ class CompanyController extends BaseController
|
||||
*/
|
||||
public function update(UpdateCompanyRequest $request, Company $company)
|
||||
{
|
||||
|
||||
if($request->hasFile('company_logo') || (is_array($request->input('settings')) && !array_key_exists('company_logo', $request->input('settings'))))
|
||||
if ($request->hasFile('company_logo') || (is_array($request->input('settings')) && !array_key_exists('company_logo', $request->input('settings')))) {
|
||||
$this->removeLogo($company);
|
||||
}
|
||||
|
||||
$company = $this->company_repo->save($request->all(), $company);
|
||||
|
||||
@ -490,7 +490,6 @@ class CompanyController extends BaseController
|
||||
LightLogs::create(new AccountDeleted())
|
||||
->increment()
|
||||
->batch();
|
||||
|
||||
} else {
|
||||
$company_id = $company->id;
|
||||
$company->delete();
|
||||
|
@ -187,7 +187,7 @@ class CreditController extends BaseController
|
||||
|
||||
$credit = $this->credit_repository->save($request->all(), CreditFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
$credit = $credit->service()
|
||||
$credit = $credit->service()
|
||||
->fillDefaults()
|
||||
->save();
|
||||
|
||||
|
@ -120,18 +120,14 @@ class EmailController extends BaseController
|
||||
$template = str_replace("email_template_", "", $template);
|
||||
|
||||
$entity_obj->invitations->each(function ($invitation) use ($subject, $body, $entity_string, $entity_obj, $template) {
|
||||
|
||||
if ($invitation->contact->send_email && $invitation->contact->email) {
|
||||
|
||||
$data = [
|
||||
'subject' => $subject,
|
||||
'body' => $body
|
||||
];
|
||||
|
||||
EmailEntity::dispatchNow($invitation, $invitation->company, $template, $data);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$entity_obj->last_sent_date = now();
|
||||
|
@ -396,7 +396,7 @@ class InvoiceController extends BaseController
|
||||
|
||||
$invoice = $this->invoice_repo->save($request->all(), $invoice);
|
||||
|
||||
UnlinkFile::dispatchNow(config('filesystems.default'),$invoice->client->invoice_filepath().$invoice->number.'.pdf');
|
||||
UnlinkFile::dispatchNow(config('filesystems.default'), $invoice->client->invoice_filepath().$invoice->number.'.pdf');
|
||||
|
||||
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars()));
|
||||
|
||||
@ -731,7 +731,6 @@ class InvoiceController extends BaseController
|
||||
$invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($invoice) {
|
||||
info("firing email");
|
||||
EmailEntity::dispatch($invitation, $invoice->company, $this->reminder_template);
|
||||
|
||||
});
|
||||
|
||||
if (! $bulk) {
|
||||
|
@ -219,7 +219,6 @@ class MigrationController extends BaseController
|
||||
*/
|
||||
public function startMigration(Request $request)
|
||||
{
|
||||
|
||||
$companies = json_decode($request->companies);
|
||||
|
||||
if (app()->environment() === 'local') {
|
||||
@ -227,7 +226,6 @@ class MigrationController extends BaseController
|
||||
}
|
||||
|
||||
foreach ($companies as $company) {
|
||||
|
||||
$is_valid = $request->file($company->company_index)->isValid();
|
||||
|
||||
if (!$is_valid) {
|
||||
|
@ -27,4 +27,4 @@
|
||||
* @OA\Property(property="updated_at", type="number", format="integer", example="1434342123", description="Timestamp"),
|
||||
* @OA\Property(property="archived_at", type="number", format="integer", example="1434342123", description="Timestamp"),
|
||||
* )
|
||||
*/
|
||||
*/
|
||||
|
@ -45,7 +45,9 @@ class PingController extends BaseController
|
||||
return response()->json(
|
||||
['company_name' => auth()->user()->getCompany()->present()->name(),
|
||||
'user_name' => auth()->user()->present()->name(),
|
||||
], 200);
|
||||
],
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -363,7 +363,7 @@ class ProjectController extends BaseController
|
||||
$project->fill($request->all());
|
||||
$project->save();
|
||||
|
||||
if(empty($project->number)){
|
||||
if (empty($project->number)) {
|
||||
$project->number = $this->getNextProjectNumber($project);
|
||||
$project->save();
|
||||
}
|
||||
|
@ -670,22 +670,25 @@ class QuoteController extends BaseController
|
||||
case 'restore':
|
||||
$this->quote_repo->restore($quote);
|
||||
|
||||
if (!$bulk)
|
||||
if (!$bulk) {
|
||||
return $this->listResponse($quote);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'archive':
|
||||
$this->quote_repo->archive($quote);
|
||||
|
||||
if (!$bulk)
|
||||
if (!$bulk) {
|
||||
return $this->listResponse($quote);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'delete':
|
||||
$this->quote_repo->delete($quote);
|
||||
|
||||
if (!$bulk)
|
||||
if (!$bulk) {
|
||||
return $this->listResponse($quote);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'email':
|
||||
@ -700,7 +703,6 @@ class QuoteController extends BaseController
|
||||
return $this->itemResponse($quote);
|
||||
}
|
||||
break;
|
||||
// no break
|
||||
default:
|
||||
return response()->json(['message' => "The requested action `{$action}` is not available."], 400);
|
||||
break;
|
||||
|
@ -628,6 +628,5 @@ class RecurringInvoiceController extends BaseController
|
||||
// code...
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,6 @@ class SelfUpdateController extends BaseController
|
||||
try {
|
||||
$res = $repo->pull();
|
||||
} catch (GitException $e) {
|
||||
|
||||
info($e->getMessage());
|
||||
return response()->json(['message'=>$e->getMessage()], 500);
|
||||
}
|
||||
|
@ -63,8 +63,9 @@ class SystemLogController extends BaseController
|
||||
{
|
||||
$system_logs = SystemLog::filter($filters);
|
||||
|
||||
if(auth()->user()->isAdmin())
|
||||
if (auth()->user()->isAdmin()) {
|
||||
return $this->listResponse($system_logs);
|
||||
}
|
||||
|
||||
return $this->errorResponse('Insufficient permissions', 403);
|
||||
}
|
||||
|
@ -65,9 +65,9 @@ class General extends Component
|
||||
|
||||
$data = $this->validate($this->rules);
|
||||
|
||||
if (!empty($this->password)) {
|
||||
$this->profile->password = Hash::make($this->password);
|
||||
}
|
||||
if (!empty($this->password)) {
|
||||
$this->profile->password = Hash::make($this->password);
|
||||
}
|
||||
|
||||
$this->profile
|
||||
->fill($data)
|
||||
|
@ -27,9 +27,9 @@ class ApiSecretCheck
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
if(! config('ninja.api_secret'))
|
||||
if (! config('ninja.api_secret')) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($request->header('X-API-SECRET') && ($request->header('X-API-SECRET') == config('ninja.api_secret'))) {
|
||||
return $next($request);
|
||||
|
@ -34,47 +34,32 @@ class ContactKeyLogin
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
if(Auth::guard('contact')->check())
|
||||
if (Auth::guard('contact')->check()) {
|
||||
Auth::guard('contact')->logout();
|
||||
}
|
||||
|
||||
if ($request->segment(3) && config('ninja.db.multi_db_enabled')) {
|
||||
|
||||
if (MultiDB::findAndSetDbByContactKey($request->segment(3))) {
|
||||
|
||||
$client_contact = ClientContact::where('contact_key', $request->segment(3))->first();
|
||||
Auth::guard('contact')->login($client_contact, true);
|
||||
return redirect()->to('client/dashboard');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if ($request->has('contact_key')) {
|
||||
|
||||
if($client_contact = ClientContact::where('contact_key', $request->segment(3))->first()){
|
||||
} elseif ($request->has('contact_key')) {
|
||||
if ($client_contact = ClientContact::where('contact_key', $request->segment(3))->first()) {
|
||||
Auth::guard('contact')->login($client_contact, true);
|
||||
return redirect()->to('client/dashboard');
|
||||
}
|
||||
|
||||
}
|
||||
else if($request->has('client_hash') && config('ninja.db.multi_db_enabled')){
|
||||
|
||||
} elseif ($request->has('client_hash') && config('ninja.db.multi_db_enabled')) {
|
||||
if (MultiDB::findAndSetDbByClientHash($request->input('client_hash'))) {
|
||||
|
||||
$client = Client::where('client_hash', $request->input('client_hash'))->first();
|
||||
Auth::guard('contact')->login($client->primary_contact()->first(), true);
|
||||
return redirect()->to('client/dashboard');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if($request->has('client_hash')){
|
||||
|
||||
if($client = Client::where('client_hash', $request->input('client_hash'))->first()){
|
||||
} elseif ($request->has('client_hash')) {
|
||||
if ($client = Client::where('client_hash', $request->input('client_hash'))->first()) {
|
||||
Auth::guard('contact')->login($client->primary_contact()->first(), true);
|
||||
return redirect()->to('client/dashboard');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@ -55,7 +55,7 @@ class ContactTokenAuth
|
||||
//stateless, don't remember the contact.
|
||||
auth()->guard('contact')->login($client_contact, false);
|
||||
|
||||
event(new ContactLoggedIn($client_contact, $client_contact->company, Ninja::eventVars()));
|
||||
event(new ContactLoggedIn($client_contact, $client_contact->company, Ninja::eventVars()));
|
||||
} else {
|
||||
$error = [
|
||||
'message' => 'Invalid token',
|
||||
|
@ -31,7 +31,6 @@ class QueryLogging
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
|
||||
$timeStart = microtime(true);
|
||||
|
||||
// Enable query logging for development
|
||||
@ -54,7 +53,6 @@ class QueryLogging
|
||||
|
||||
// if($count > 50)
|
||||
// Log::info($queries);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class SetEmailDb
|
||||
if (! MultiDB::userFindAndSetDb($request->input('email'))) {
|
||||
return response()->json($error, 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// return response()->json($error, 403);
|
||||
// }
|
||||
|
@ -69,8 +69,9 @@ class StartupCheck
|
||||
|
||||
|
||||
/*Build template cache*/
|
||||
if ($request->has('clear_cache') || ! Cache::has('templates'))
|
||||
if ($request->has('clear_cache') || ! Cache::has('templates')) {
|
||||
$this->buildTemplates();
|
||||
}
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
|
@ -36,12 +36,12 @@ class TrustProxies extends Middleware
|
||||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
*/
|
||||
public function __construct(Repository $config) {
|
||||
|
||||
parent::__construct($config);
|
||||
|
||||
if (config('ninja.trusted_proxies'))
|
||||
$this->proxies = config('ninja.trusted_proxies');
|
||||
public function __construct(Repository $config)
|
||||
{
|
||||
parent::__construct($config);
|
||||
|
||||
if (config('ninja.trusted_proxies')) {
|
||||
$this->proxies = config('ninja.trusted_proxies');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,9 @@ class UpdateExpenseRequest extends Request
|
||||
//$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id;
|
||||
$rules['contacts.*.email'] = 'nullable|distinct';
|
||||
|
||||
if(isset($this->number))
|
||||
if (isset($this->number)) {
|
||||
$rules['number'] = Rule::unique('expenses')->where('company_id', auth()->user()->company()->id)->ignore($this->expense->id);
|
||||
}
|
||||
|
||||
return $this->globalRules($rules);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace App\Http\Requests\ExpenseCategory;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Utils\Traits\ChecksEntityStatus;
|
||||
|
||||
class UpdateExpenseCategoryRequest extends Request
|
||||
{
|
||||
use ChecksEntityStatus;
|
||||
@ -29,13 +30,12 @@ class UpdateExpenseCategoryRequest extends Request
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
$rules = [];
|
||||
|
||||
if ($this->input('name'))
|
||||
if ($this->input('name')) {
|
||||
$rules['name'] = 'unique:expense_categories,name,'.$this->id.',id,company_id,'.$this->expense_category->company_id;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ class StoreGroupSettingRequest extends Request
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
$rules['name'] = 'required|unique:group_settings,name,null,null,company_id,'.auth()->user()->companyId();
|
||||
|
||||
$rules['settings'] = new ValidClientGroupSettingsRule();
|
||||
|
@ -39,7 +39,7 @@ class StorePaymentRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
// info(print_r($input,1));
|
||||
// info(print_r($input,1));
|
||||
|
||||
$invoices_total = 0;
|
||||
$credits_total = 0;
|
||||
@ -77,7 +77,7 @@ class StorePaymentRequest extends Request
|
||||
}
|
||||
|
||||
if (! isset($input['amount']) || $input['amount'] == 0) {
|
||||
$input['amount'] = $invoices_total - $credits_total;
|
||||
$input['amount'] = $invoices_total - $credits_total;
|
||||
}
|
||||
|
||||
$input['is_manual'] = true;
|
||||
|
@ -35,8 +35,7 @@ class UpdatePaymentRequest extends Request
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
$rules = [
|
||||
$rules = [
|
||||
'number' => 'nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->payment->company_id,
|
||||
'invoices' => ['array', new PaymentAppliedValidAmount, new ValidCreditsPresentRule],
|
||||
'invoices.*.invoice_id' => 'distinct',
|
||||
|
@ -34,16 +34,16 @@ class StoreProjectRequest extends Request
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
$rules['name'] = 'required';
|
||||
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
|
||||
$rules['number'] = 'unique:projects,number,'.$this->id.',id,company_id,'.auth()->user()->company()->id;
|
||||
$rules['name'] = 'required';
|
||||
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
|
||||
$rules['number'] = 'unique:projects,number,'.$this->id.',id,company_id,'.auth()->user()->company()->id;
|
||||
|
||||
return $this->globalRules($rules);
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
@ -33,18 +33,20 @@ class UpdateProjectRequest extends Request
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
if(isset($this->number))
|
||||
if (isset($this->number)) {
|
||||
$rules['number'] = Rule::unique('projects')->where('company_id', auth()->user()->company()->id)->ignore($this->project->id);
|
||||
}
|
||||
|
||||
return $this->globalRules($rules);
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
|
||||
if(isset($input['client_id']))
|
||||
if (isset($input['client_id'])) {
|
||||
unset($input['client_id']);
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
@ -100,29 +100,30 @@ class StoreRecurringInvoiceRequest extends Request
|
||||
|
||||
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
|
||||
|
||||
if(isset($input['auto_bill']))
|
||||
if (isset($input['auto_bill'])) {
|
||||
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
|
||||
else{
|
||||
|
||||
if($client = Client::find($input['client_id']))
|
||||
} else {
|
||||
if ($client = Client::find($input['client_id'])) {
|
||||
$input['auto_bill'] = $client->getSetting('auto_bill');
|
||||
}
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
private function setAutoBillFlag($auto_bill)
|
||||
{
|
||||
if($auto_bill == 'always')
|
||||
if ($auto_bill == 'always') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if($auto_bill == 'off')
|
||||
if ($auto_bill == 'off') {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public function messages()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ class UpdateRecurringInvoiceRequest extends Request
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
$rules = [];
|
||||
|
||||
if ($this->input('documents') && is_array($this->input('documents'))) {
|
||||
@ -90,33 +89,32 @@ class UpdateRecurringInvoiceRequest extends Request
|
||||
|
||||
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
|
||||
|
||||
if(isset($input['auto_bill']))
|
||||
if (isset($input['auto_bill'])) {
|
||||
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* if($auto_bill == '')
|
||||
* off / optin / optout will reset the status of this field to off to allow
|
||||
* off / optin / optout will reset the status of this field to off to allow
|
||||
* the client to choose whether to auto_bill or not.
|
||||
*
|
||||
*
|
||||
* @param enum $auto_bill off/always/optin/optout
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function setAutoBillFlag($auto_bill) :bool
|
||||
{
|
||||
|
||||
if($auto_bill == 'always')
|
||||
if ($auto_bill == 'always') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if($auto_bill == '')
|
||||
// off / optin / optout will reset the status of this field to off to allow
|
||||
// off / optin / optout will reset the status of this field to off to allow
|
||||
// the client to choose whether to auto_bill or not.
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class Request extends FormRequest
|
||||
{
|
||||
use MakesHash;
|
||||
use MakesHash;
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
@ -31,22 +31,22 @@ class Request extends FormRequest
|
||||
|
||||
public function globalRules($rules)
|
||||
{
|
||||
$merge_rules = [];
|
||||
$merge_rules = [];
|
||||
|
||||
foreach($this->all() as $key => $value)
|
||||
{
|
||||
if(method_exists($this, $key))
|
||||
$merge_rules = $this->{$key}($rules);
|
||||
}
|
||||
foreach ($this->all() as $key => $value) {
|
||||
if (method_exists($this, $key)) {
|
||||
$merge_rules = $this->{$key}($rules);
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($merge_rules, $rules);
|
||||
return array_merge($merge_rules, $rules);
|
||||
}
|
||||
|
||||
private function assigned_user_id($rules)
|
||||
{
|
||||
$rules['assigned_user_id'] = [
|
||||
'bail' ,
|
||||
'sometimes',
|
||||
{
|
||||
$rules['assigned_user_id'] = [
|
||||
'bail' ,
|
||||
'sometimes',
|
||||
'nullable',
|
||||
new RelatedUserRule($this->all())
|
||||
];
|
||||
@ -70,7 +70,6 @@ class Request extends FormRequest
|
||||
|
||||
public function decodePrimaryKeys($input)
|
||||
{
|
||||
|
||||
if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) {
|
||||
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
|
||||
}
|
||||
@ -81,15 +80,15 @@ class Request extends FormRequest
|
||||
|
||||
if (array_key_exists('vendor_id', $input) && is_string($input['vendor_id'])) {
|
||||
$input['vendor_id'] = $this->decodePrimaryKey($input['vendor_id']);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('client_id', $input) && is_string($input['client_id'])) {
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('invoice_id', $input) && is_string($input['invoice_id'])) {
|
||||
$input['invoice_id'] = $this->decodePrimaryKey($input['invoice_id']);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
@ -146,6 +145,6 @@ class Request extends FormRequest
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
return $input;
|
||||
}
|
||||
}
|
||||
|
@ -38,17 +38,18 @@ class StoreTaskRequest extends Request
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
if(isset($this->number))
|
||||
if (isset($this->number)) {
|
||||
$rules['number'] = Rule::unique('tasks')->where('company_id', auth()->user()->company()->id);
|
||||
}
|
||||
|
||||
return $this->globalRules($rules);
|
||||
return $this->globalRules($rules);
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
|
||||
if (array_key_exists('status_id', $input) && is_string($input['status_id'])) {
|
||||
$input['status_id'] = $this->decodePrimaryKey($input['status_id']);
|
||||
@ -56,5 +57,4 @@ class StoreTaskRequest extends Request
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,15 +38,16 @@ class UpdateTaskRequest extends Request
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
if(isset($this->number))
|
||||
if (isset($this->number)) {
|
||||
$rules['number'] = Rule::unique('tasks')->where('company_id', auth()->user()->company()->id)->ignore($this->task->id);
|
||||
}
|
||||
|
||||
return $this->globalRules($rules);
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
$input = $this->decodePrimaryKeys($this->all());
|
||||
|
||||
if (array_key_exists('status_id', $input) && is_string($input['status_id'])) {
|
||||
$input['status_id'] = $this->decodePrimaryKey($input['status_id']);
|
||||
|
@ -33,10 +33,10 @@ class UpdateTaskStatusRequest extends Request
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
if ($this->input('name'))
|
||||
$rules['name'] = 'unique:task_statuses,name,'.$this->id.',id,company_id,'.$this->task_status->company_id;
|
||||
if ($this->input('name')) {
|
||||
$rules['name'] = 'unique:task_statuses,name,'.$this->id.',id,company_id,'.$this->task_status->company_id;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
return $rules;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,12 +41,11 @@ class CreditsSumRule implements Rule
|
||||
|
||||
private function checkCreditTotals()
|
||||
{
|
||||
|
||||
if( array_sum(array_column($this->input['credits'],'amount')) > array_sum(array_column($this->input['invoices'], 'amount')))
|
||||
if (array_sum(array_column($this->input['credits'], 'amount')) > array_sum(array_column($this->input['invoices'], 'amount'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,8 +51,9 @@ class UniqueExpenseNumberRule implements Rule
|
||||
*/
|
||||
private function checkIfExpenseNumberUnique() : bool
|
||||
{
|
||||
if(empty($this->input['number']))
|
||||
if (empty($this->input['number'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$expense = Expense::query()
|
||||
->where('number', $this->input['number'])
|
||||
|
@ -51,8 +51,9 @@ class UniqueInvoiceNumberRule implements Rule
|
||||
*/
|
||||
private function checkIfInvoiceNumberUnique() : bool
|
||||
{
|
||||
if(empty($this->input['number']))
|
||||
if (empty($this->input['number'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$invoice = Invoice::where('client_id', $this->input['client_id'])
|
||||
->where('number', $this->input['number'])
|
||||
|
@ -73,8 +73,8 @@ class PaymentAmountsBalanceRule implements Rule
|
||||
return true;
|
||||
} // if no invoices are present, then this is an unapplied payment, let this pass validation!
|
||||
|
||||
// info("payment amounts = {$payment_amounts}");
|
||||
// info("invoice amounts = {$invoice_amounts}");
|
||||
// info("payment amounts = {$payment_amounts}");
|
||||
// info("invoice amounts = {$invoice_amounts}");
|
||||
|
||||
return $payment_amounts >= $invoice_amounts;
|
||||
}
|
||||
|
@ -35,11 +35,13 @@ class ValidProjectForClient implements Rule
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
if(empty($this->input['project_id']))
|
||||
if (empty($this->input['project_id'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(is_string($this->input['project_id']))
|
||||
if (is_string($this->input['project_id'])) {
|
||||
$this->input['project_id'] = $this->decodePrimaryKey($this->input['project_id']);
|
||||
}
|
||||
|
||||
$project = Project::findOrFail($this->input['project_id']);
|
||||
|
||||
@ -53,6 +55,4 @@ class ValidProjectForClient implements Rule
|
||||
{
|
||||
return "Project client does not match entity client";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -52,8 +52,9 @@ class UniqueRecurringInvoiceNumberRule implements Rule
|
||||
*/
|
||||
private function checkIfInvoiceNumberUnique() : bool
|
||||
{
|
||||
if(empty($this->input['number']))
|
||||
if (empty($this->input['number'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$invoice = RecurringInvoice::where('client_id', $this->input['client_id'])
|
||||
->where('number', $this->input['number'])
|
||||
|
@ -50,9 +50,9 @@ class RelatedUserRule implements Rule
|
||||
*/
|
||||
private function checkUserIsRelated($user_id) : bool
|
||||
{
|
||||
|
||||
if(empty($user_id))
|
||||
if (empty($user_id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return User::query()
|
||||
->where('id', $user_id)
|
||||
|
@ -60,7 +60,6 @@ class ValidCreditsPresentRule implements Rule
|
||||
|
||||
|
||||
if (request()->input('credits') && is_array(request()->input('credits'))) {
|
||||
|
||||
$credit_collection = Credit::whereIn('id', $this->transformKeys(array_column(request()->input('credits'), 'credit_id')))
|
||||
->where('balance', '>', 0)
|
||||
->get();
|
||||
|
@ -32,8 +32,9 @@ class PortalComposer
|
||||
{
|
||||
$view->with($this->portalData());
|
||||
|
||||
if(auth()->user())
|
||||
if (auth()->user()) {
|
||||
Lang::replace(Ninja::transformTranslations(auth()->user()->client->getMergedSettings()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,7 +74,7 @@ class PortalComposer
|
||||
$data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download'];
|
||||
|
||||
if (auth()->user('contact')->client->getSetting('enable_client_portal_tasks')) {
|
||||
$data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.dashboard', 'icon' => 'clock'];
|
||||
$data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.dashboard', 'icon' => 'clock'];
|
||||
|
||||
// TODO: Update when 'tasks' module is available in client portal.
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class RecurringInvoicesCron
|
||||
{
|
||||
use Dispatchable;
|
||||
use Dispatchable;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
@ -44,27 +44,23 @@ class RecurringInvoicesCron
|
||||
info("Sending recurring invoices ".Carbon::now()->format('Y-m-d h:i:s'));
|
||||
|
||||
if (! config('ninja.db.multi_db_enabled')) {
|
||||
|
||||
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '=', now())
|
||||
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '=', now())
|
||||
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||
->with('company')
|
||||
->cursor();
|
||||
|
||||
Log::info(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count());
|
||||
|
||||
$recurring_invoices->each(function ($recurring_invoice, $key) {
|
||||
Log::info(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count());
|
||||
|
||||
$recurring_invoices->each(function ($recurring_invoice, $key) {
|
||||
info("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date);
|
||||
|
||||
if(!$recurring_invoice->company->is_disabled)
|
||||
if (!$recurring_invoice->company->is_disabled) {
|
||||
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
//multiDB environment, need to
|
||||
foreach (MultiDB::$dbs as $db) {
|
||||
|
||||
MultiDB::setDB($db);
|
||||
|
||||
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '=', now())
|
||||
@ -75,12 +71,11 @@ class RecurringInvoicesCron
|
||||
Log::info(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count().' On Database # '.$db);
|
||||
|
||||
$recurring_invoices->each(function ($recurring_invoice, $key) {
|
||||
|
||||
info("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date);
|
||||
|
||||
if(!$recurring_invoice->company->is_disabled)
|
||||
if (!$recurring_invoice->company->is_disabled) {
|
||||
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -72,19 +72,16 @@ class CreateEntityPdf implements ShouldQueue
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
|
||||
if($invitation instanceof InvoiceInvitation){
|
||||
if ($invitation instanceof InvoiceInvitation) {
|
||||
$this->entity = $invitation->invoice;
|
||||
$this->entity_string = 'invoice';
|
||||
}
|
||||
elseif($invitation instanceof QuoteInvitation){
|
||||
} elseif ($invitation instanceof QuoteInvitation) {
|
||||
$this->entity = $invitation->quote;
|
||||
$this->entity_string = 'quote';
|
||||
}
|
||||
elseif($invitation instanceof CreditInvitation){
|
||||
} elseif ($invitation instanceof CreditInvitation) {
|
||||
$this->entity = $invitation->credit;
|
||||
$this->entity_string = 'credit';
|
||||
}
|
||||
elseif($invitation instanceof RecurringInvoiceInvitation){
|
||||
} elseif ($invitation instanceof RecurringInvoiceInvitation) {
|
||||
$this->entity = $invitation->recurring_invoice;
|
||||
$this->entity_string = 'recurring_invoice';
|
||||
}
|
||||
@ -98,7 +95,6 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
if (config('ninja.phantomjs_key')) {
|
||||
return (new Phantom)->generate($this->invitation);
|
||||
}
|
||||
@ -108,15 +104,13 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
$entity_design_id = '';
|
||||
|
||||
if($this->entity instanceof Invoice){
|
||||
if ($this->entity instanceof Invoice) {
|
||||
$path = $this->entity->client->invoice_filepath();
|
||||
$entity_design_id = 'invoice_design_id';
|
||||
}
|
||||
elseif($this->entity instanceof Quote){
|
||||
} elseif ($this->entity instanceof Quote) {
|
||||
$path = $this->entity->client->quote_filepath();
|
||||
$entity_design_id = 'quote_design_id';
|
||||
}
|
||||
elseif($this->entity instanceof Credit){
|
||||
} elseif ($this->entity instanceof Credit) {
|
||||
$path = $this->entity->client->credit_filepath();
|
||||
$entity_design_id = 'credit_design_id';
|
||||
}
|
||||
@ -131,12 +125,12 @@ class CreateEntityPdf implements ShouldQueue
|
||||
$html = new HtmlEngine($this->invitation);
|
||||
|
||||
if ($design->is_custom) {
|
||||
$options = [
|
||||
$options = [
|
||||
'custom_partials' => json_decode(json_encode($design->design), true)
|
||||
];
|
||||
$template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options);
|
||||
$template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options);
|
||||
} else {
|
||||
$template = new PdfMakerDesign(strtolower($design->name));
|
||||
$template = new PdfMakerDesign(strtolower($design->name));
|
||||
}
|
||||
|
||||
$state = [
|
||||
@ -165,15 +159,14 @@ class CreateEntityPdf implements ShouldQueue
|
||||
$pdf = null;
|
||||
|
||||
try {
|
||||
|
||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
info(print_r($e->getMessage(),1));
|
||||
} catch (\Exception $e) {
|
||||
info(print_r($e->getMessage(), 1));
|
||||
}
|
||||
|
||||
if($pdf)
|
||||
if ($pdf) {
|
||||
$instance = Storage::disk($this->disk)->put($file_path, $pdf);
|
||||
}
|
||||
|
||||
return $file_path;
|
||||
}
|
||||
|
@ -88,7 +88,6 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
$this->template_data = $template_data;
|
||||
|
||||
$this->email_entity_builder = $this->resolveEmailBuilder();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,8 +98,9 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if($this->company->is_disabled)
|
||||
if ($this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
MultiDB::setDB($this->company->db);
|
||||
|
||||
@ -132,14 +132,15 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
|
||||
private function resolveEntityString() :string
|
||||
{
|
||||
if($this->invitation instanceof InvoiceInvitation)
|
||||
if ($this->invitation instanceof InvoiceInvitation) {
|
||||
return 'invoice';
|
||||
elseif($this->invitation instanceof QuoteInvitation)
|
||||
} elseif ($this->invitation instanceof QuoteInvitation) {
|
||||
return 'quote';
|
||||
elseif($this->invitation instanceof CreditInvitation)
|
||||
} elseif ($this->invitation instanceof CreditInvitation) {
|
||||
return 'credit';
|
||||
elseif($this->invitation instanceof RecurringInvoiceInvitation)
|
||||
} elseif ($this->invitation instanceof RecurringInvoiceInvitation) {
|
||||
return 'recurring_invoice';
|
||||
}
|
||||
}
|
||||
|
||||
private function entityEmailFailed($message)
|
||||
@ -153,7 +154,6 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function entityEmailSucceeded()
|
||||
|
@ -97,10 +97,8 @@ class ZipInvoices extends BaseMailerJob implements ShouldQueue
|
||||
try {
|
||||
Mail::to($this->email)
|
||||
->send(new DownloadInvoices(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company));
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->failed($e);
|
||||
|
||||
}
|
||||
|
||||
UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1));
|
||||
|
@ -104,6 +104,5 @@ class BaseMailerJob implements ShouldQueue
|
||||
|
||||
LightLogs::create($job_failure)
|
||||
->batch();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -72,8 +72,9 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
/*If we are migrating data we don't want to fire these notification*/
|
||||
if ($this->company->is_disabled)
|
||||
if ($this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
@ -82,18 +83,15 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue
|
||||
$this->setMailDriver();
|
||||
|
||||
try {
|
||||
|
||||
$mail_obj = (new EntityPaidObject($this->payment))->build();
|
||||
$mail_obj->from = [$this->user->email, $this->user->present()->name()];
|
||||
|
||||
//send email
|
||||
Mail::to($this->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->payment->client);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -76,8 +76,9 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
/*If we are migrating data we don't want to fire these notification*/
|
||||
if ($this->company->is_disabled)
|
||||
if ($this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
@ -91,12 +92,9 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue
|
||||
try {
|
||||
Mail::to($this->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
}catch(\Exception $e) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->entity->client);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -76,8 +76,9 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
/*If we are migrating data we don't want to fire these notification*/
|
||||
if ($this->company->is_disabled)
|
||||
if ($this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
@ -89,15 +90,12 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
|
||||
$mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()];
|
||||
|
||||
//send email
|
||||
try{
|
||||
try {
|
||||
Mail::to($this->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->entity->client);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,8 +67,9 @@ class MailRouter extends BaseMailerJob implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
/*If we are migrating data we don't want to fire these notification*/
|
||||
if ($this->company->is_disabled)
|
||||
if ($this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
@ -79,13 +80,9 @@ class MailRouter extends BaseMailerJob implements ShouldQueue
|
||||
try {
|
||||
Mail::to($this->to_user->email)
|
||||
->send($this->mailable);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->to_user);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -77,8 +77,9 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
/*If we are migrating data we don't want to fire these notification*/
|
||||
if ($this->company->is_disabled)
|
||||
if ($this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
@ -103,14 +104,10 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
||||
try {
|
||||
Mail::to($company_user->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->client);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -41,16 +41,19 @@ class RefundCancelledAccount implements ShouldQueue
|
||||
|
||||
$plan_details = $this->account->getPlanDetails();
|
||||
|
||||
if(!$plan_details)
|
||||
if (!$plan_details) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Trial user cancelling early.... */
|
||||
if ($plan_details['trial_plan'])
|
||||
if ($plan_details['trial_plan']) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Is the plan Active? */
|
||||
if (! $plan_details['active'])
|
||||
if (! $plan_details['active']) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Refundable client! */
|
||||
|
@ -47,26 +47,18 @@ class SendReminders implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
info("Sending reminders ".Carbon::now()->format('Y-m-d h:i:s'));
|
||||
|
||||
if (! config('ninja.db.multi_db_enabled')) {
|
||||
|
||||
$this->sendReminderEmails();
|
||||
|
||||
|
||||
} else {
|
||||
//multiDB environment, need to
|
||||
foreach (MultiDB::$dbs as $db)
|
||||
{
|
||||
|
||||
foreach (MultiDB::$dbs as $db) {
|
||||
MultiDB::setDB($db);
|
||||
|
||||
$this->sendReminderEmails();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -80,21 +72,17 @@ class SendReminders implements ShouldQueue
|
||||
->cursor();
|
||||
|
||||
//we only need invoices that are payable
|
||||
$invoices->filter(function ($invoice){
|
||||
|
||||
$invoices->filter(function ($invoice) {
|
||||
return $invoice->isPayable();
|
||||
})->each(function ($invoice) {
|
||||
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||
|
||||
})->each(function ($invoice){
|
||||
|
||||
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||
|
||||
info("hitting a reminder for {$invoice->number} with template {$reminder_template}");
|
||||
info("hitting a reminder for {$invoice->number} with template {$reminder_template}");
|
||||
|
||||
if(in_array($reminder_template, ['reminder1', 'reminder2', 'reminder3', 'endless_reminder']))
|
||||
$this->sendReminder($invoice, $reminder_template);
|
||||
|
||||
if (in_array($reminder_template, ['reminder1', 'reminder2', 'reminder3', 'endless_reminder'])) {
|
||||
$this->sendReminder($invoice, $reminder_template);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private function checkSendSetting($invoice, $template)
|
||||
@ -111,7 +99,7 @@ class SendReminders implements ShouldQueue
|
||||
break;
|
||||
case 'endless_reminder':
|
||||
return $invoice->client->getSetting('enable_reminder_endless');
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
@ -121,9 +109,9 @@ class SendReminders implements ShouldQueue
|
||||
/**
|
||||
* Create a collection of all possible reminder dates
|
||||
* and pass back the first one in chronology
|
||||
*
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @return Carbon $date
|
||||
* @return Carbon $date
|
||||
*/
|
||||
private function calculateNextSendDate($invoice)
|
||||
{
|
||||
@ -135,41 +123,41 @@ class SendReminders implements ShouldQueue
|
||||
$set_reminder2 = false;
|
||||
$set_reminder3 = false;
|
||||
|
||||
if((int)$settings->schedule_reminder1 > 0){
|
||||
|
||||
if ((int)$settings->schedule_reminder1 > 0) {
|
||||
$next_reminder_date = $this->calculateScheduledDate($invoice, (int)$settings->schedule_reminder1, (int)$settings->num_days_reminder1);
|
||||
|
||||
if($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date)));
|
||||
$dates->push($next_reminder_date);
|
||||
if ($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date)));
|
||||
$dates->push($next_reminder_date);
|
||||
|
||||
if(!$invoice->reminder1_sent)
|
||||
if (!$invoice->reminder1_sent) {
|
||||
$set_reminder1 = true;
|
||||
}
|
||||
}
|
||||
|
||||
if((int)$settings->num_days_reminder2 > 0){
|
||||
|
||||
if ((int)$settings->num_days_reminder2 > 0) {
|
||||
$next_reminder_date = $this->calculateScheduledDate($invoice, (int)$settings->schedule_reminder2, (int)$settings->num_days_reminder2);
|
||||
|
||||
if($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date)));
|
||||
$dates->push($next_reminder_date);
|
||||
if ($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date)));
|
||||
$dates->push($next_reminder_date);
|
||||
|
||||
if(!$invoice->reminder2_sent)
|
||||
if (!$invoice->reminder2_sent) {
|
||||
$set_reminder3 = true;
|
||||
}
|
||||
}
|
||||
|
||||
if((int)$settings->num_days_reminder3 > 0){
|
||||
|
||||
if ((int)$settings->num_days_reminder3 > 0) {
|
||||
$next_reminder_date = $this->calculateScheduledDate($invoice, (int)$settings->schedule_reminder3, (int)$settings->num_days_reminder3);
|
||||
|
||||
if($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date)));
|
||||
$dates->push($next_reminder_date);
|
||||
if ($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date)));
|
||||
$dates->push($next_reminder_date);
|
||||
|
||||
if(!$invoice->reminder3_sent)
|
||||
if (!$invoice->reminder3_sent) {
|
||||
$set_reminder3 = true;
|
||||
}
|
||||
}
|
||||
|
||||
//If all the available reminders have fired, we then start to fire the endless reminders
|
||||
if((int)$settings->endless_reminder_frequency_id > 0 && !$set_reminder1 && !$set_reminder2 && !$set_reminder3) {
|
||||
if ((int)$settings->endless_reminder_frequency_id > 0 && !$set_reminder1 && !$set_reminder2 && !$set_reminder3) {
|
||||
$dates->push($this->addTimeInterval($invoice->last_sent_date, (int)$settings->endless_reminder_frequency_id));
|
||||
}
|
||||
|
||||
@ -179,10 +167,10 @@ class SendReminders implements ShouldQueue
|
||||
|
||||
/**
|
||||
* Helper method which switches values based on the $schedule_reminder
|
||||
* @param Invoice $invoice
|
||||
* @param string $schedule_reminder
|
||||
* @param int $num_days_reminder
|
||||
* @return Carbon $date
|
||||
* @param Invoice $invoice
|
||||
* @param string $schedule_reminder
|
||||
* @param int $num_days_reminder
|
||||
* @return Carbon $date
|
||||
*/
|
||||
private function calculateScheduledDate($invoice, $schedule_reminder, $num_days_reminder) :?Carbon
|
||||
{
|
||||
@ -204,48 +192,46 @@ class SendReminders implements ShouldQueue
|
||||
|
||||
/**
|
||||
* Sends the reminder and/or late fee for the invoice.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @param string $template
|
||||
* @return void
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @param string $template
|
||||
* @return void
|
||||
*/
|
||||
private function sendReminder($invoice, $template) :void
|
||||
{
|
||||
$invoice = $this->calcLateFee($invoice, $template);
|
||||
|
||||
$invoice->invitations->each(function ($invitation) use($template, $invoice){
|
||||
$invoice->invitations->each(function ($invitation) use ($template, $invoice) {
|
||||
|
||||
//only send if enable_reminder setting is toggled to yes
|
||||
if($this->checkSendSetting($invoice, $template)) {
|
||||
|
||||
if ($this->checkSendSetting($invoice, $template)) {
|
||||
info("firing email");
|
||||
|
||||
EmailEntity::dispatchNow($invitation, $invitation->company, $template);
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
if($this->checkSendSetting($invoice, $template))
|
||||
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars()));
|
||||
if ($this->checkSendSetting($invoice, $template)) {
|
||||
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars()));
|
||||
}
|
||||
|
||||
$invoice->last_sent_date = now();
|
||||
$invoice->next_send_date = $this->calculateNextSendDate($invoice);
|
||||
$invoice->last_sent_date = now();
|
||||
$invoice->next_send_date = $this->calculateNextSendDate($invoice);
|
||||
|
||||
if(in_array($template, ['reminder1', 'reminder2', 'reminder3']))
|
||||
$invoice->{$template."_sent"} = now();
|
||||
if (in_array($template, ['reminder1', 'reminder2', 'reminder3'])) {
|
||||
$invoice->{$template."_sent"} = now();
|
||||
}
|
||||
|
||||
$invoice->save();
|
||||
$invoice->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the late if - if any - and rebuilds the invoice
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @param string $template
|
||||
* @return Invoice
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @param string $template
|
||||
* @return Invoice
|
||||
*/
|
||||
private function calcLateFee($invoice, $template) :Invoice
|
||||
{
|
||||
@ -268,7 +254,7 @@ class SendReminders implements ShouldQueue
|
||||
case 'endless_reminder':
|
||||
$late_fee_amount = $invoice->client->getSetting('late_fee_endless_amount');
|
||||
$late_fee_percent = $invoice->client->getSetting('late_fee_endless_percent');
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
$late_fee_amount = 0;
|
||||
$late_fee_percent = 0;
|
||||
@ -276,31 +262,32 @@ class SendReminders implements ShouldQueue
|
||||
}
|
||||
|
||||
return $this->setLateFee($invoice, $late_fee_amount, $late_fee_percent);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the late fee to the invoice line items
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @param float $amount The fee amount
|
||||
* @param float $percent The fee percentage amount
|
||||
*
|
||||
* @return Invoice
|
||||
*
|
||||
* @return Invoice
|
||||
*/
|
||||
private function setLateFee($invoice, $amount, $percent) :Invoice
|
||||
{
|
||||
$temp_invoice_balance = $invoice->balance;
|
||||
|
||||
if ($amount <= 0 && $percent <= 0)
|
||||
if ($amount <= 0 && $percent <= 0) {
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
$fee = $amount;
|
||||
|
||||
if ($invoice->partial > 0)
|
||||
if ($invoice->partial > 0) {
|
||||
$fee += round($invoice->partial * $percent / 100, 2);
|
||||
else
|
||||
} else {
|
||||
$fee += round($invoice->balance * $percent / 100, 2);
|
||||
}
|
||||
|
||||
$invoice_item = new InvoiceItem;
|
||||
$invoice_item->type_id = '5';
|
||||
@ -321,7 +308,5 @@ class SendReminders implements ShouldQueue
|
||||
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance - $temp_invoice_balance);
|
||||
|
||||
return $invoice;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -73,37 +73,29 @@ class EmailPayment extends BaseMailerJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
if($this->company->is_disabled)
|
||||
if ($this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->contact->email) {
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
//if we need to set an email driver do it now
|
||||
$this->setMailDriver();
|
||||
|
||||
$email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build();
|
||||
|
||||
try{
|
||||
|
||||
try {
|
||||
$mail = Mail::to($this->contact->email, $this->contact->present()->name());
|
||||
$mail->send(new TemplateEmail($email_builder, $this->contact->user, $this->contact->client));
|
||||
|
||||
}catch(\Exception $e) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
info("mailing failed with message " . $e->getMessage());
|
||||
event(new PaymentWasEmailedAndFailed($this->payment, $this->company, Mail::failures(), Ninja::eventVars()));
|
||||
$this->failed($e);
|
||||
return $this->logMailError($e->getMessage(), $this->payment->client);
|
||||
|
||||
}
|
||||
|
||||
event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -60,9 +60,7 @@ class UpdateOrCreateProduct implements ShouldQueue
|
||||
|
||||
//only update / create products - not tasks or gateway fees
|
||||
$updateable_products = collect($this->products)->filter(function ($item) {
|
||||
|
||||
return $item->type_id == 1;
|
||||
|
||||
});
|
||||
|
||||
foreach ($updateable_products as $item) {
|
||||
@ -98,6 +96,6 @@ class UpdateOrCreateProduct implements ShouldQueue
|
||||
public function failed($exception = null)
|
||||
{
|
||||
info("update create failed with = ");
|
||||
info(print_r($exception->getMessage(),1));
|
||||
info(print_r($exception->getMessage(), 1));
|
||||
}
|
||||
}
|
||||
|
@ -67,19 +67,18 @@ class SendRecurring implements ShouldQueue
|
||||
->createInvitations()
|
||||
->save();
|
||||
|
||||
info("Invoice {$invoice->number} created");
|
||||
info("Invoice {$invoice->number} created");
|
||||
|
||||
$invoice->invitations->each(function ($invitation) use ($invoice) {
|
||||
|
||||
if($invitation->contact && strlen($invitation->contact->email) >=1){
|
||||
if ($invitation->contact && strlen($invitation->contact->email) >=1) {
|
||||
EmailEntity::dispatch($invitation, $invoice->company);
|
||||
info("Firing email for invoice {$invoice->number}");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $this->recurring_invoice->auto_bill_enabled)
|
||||
if ($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $this->recurring_invoice->auto_bill_enabled) {
|
||||
$invoice->service()->autoBill()->save();
|
||||
}
|
||||
|
||||
info("updating recurring invoice dates");
|
||||
/* Set next date here to prevent a recurring loop forming */
|
||||
@ -88,8 +87,9 @@ class SendRecurring implements ShouldQueue
|
||||
$this->recurring_invoice->last_sent_date = date('Y-m-d');
|
||||
|
||||
/* Set completed if we don't have any more cycles remaining*/
|
||||
if ($this->recurring_invoice->remaining_cycles == 0)
|
||||
if ($this->recurring_invoice->remaining_cycles == 0) {
|
||||
$this->recurring_invoice->setCompleted();
|
||||
}
|
||||
|
||||
info("next send date = " . $this->recurring_invoice->next_send_date);
|
||||
info("remaining cycles = " . $this->recurring_invoice->remaining_cycles);
|
||||
@ -100,7 +100,6 @@ class SendRecurring implements ShouldQueue
|
||||
//this is duplicated!!
|
||||
// if ($invoice->invitations->count() > 0)
|
||||
// event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars()));
|
||||
|
||||
}
|
||||
|
||||
public function failed($exception = null)
|
||||
@ -116,5 +115,4 @@ class SendRecurring implements ShouldQueue
|
||||
|
||||
info(print_r($exception->getMessage(), 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,8 +54,9 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if($this->company->is_disabled)
|
||||
if ($this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
@ -74,19 +75,15 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue
|
||||
//Send email via a Mailable class
|
||||
//
|
||||
try {
|
||||
Mail::to($this->old_email)
|
||||
Mail::to($this->old_email)
|
||||
->send(new UserNotificationMailer($mail_obj));
|
||||
|
||||
Mail::to($this->new_email)
|
||||
Mail::to($this->new_email)
|
||||
->send(new UserNotificationMailer($mail_obj));
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->company->owner());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function getData()
|
||||
|
@ -156,7 +156,7 @@ class Import implements ShouldQueue
|
||||
|
||||
// public $backoff = 86430;
|
||||
|
||||
// public $maxExceptions = 2;
|
||||
// public $maxExceptions = 2;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -178,16 +178,15 @@ class Import implements ShouldQueue
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function handle()
|
||||
public function handle()
|
||||
{
|
||||
set_time_limit(0);
|
||||
|
||||
// $jsonStream = \JsonMachine\JsonMachine::fromFile($this->file_path, "/data");
|
||||
// $jsonStream = \JsonMachine\JsonMachine::fromFile($this->file_path, "/data");
|
||||
$array = json_decode(file_get_contents($this->file_path), 1);
|
||||
$data = $array['data'];
|
||||
|
||||
foreach ($this->available_imports as $import) {
|
||||
|
||||
if (! array_key_exists($import, $data)) {
|
||||
//throw new ResourceNotAvailableForMigration("Resource {$key} is not available for migration.");
|
||||
info("Resource {$import} is not available for migration.");
|
||||
@ -210,7 +209,6 @@ class Import implements ShouldQueue
|
||||
CompanySizeCheck::dispatch();
|
||||
|
||||
info('Completed🚀🚀🚀🚀🚀 at '.now());
|
||||
|
||||
}
|
||||
|
||||
private function setInitialCompanyLedgerBalances()
|
||||
@ -268,15 +266,12 @@ class Import implements ShouldQueue
|
||||
$company_repository = new CompanyRepository();
|
||||
$company_repository->save($data, $this->company);
|
||||
|
||||
if(isset($data['settings']->company_logo) && strlen($data['settings']->company_logo) > 0) {
|
||||
|
||||
if (isset($data['settings']->company_logo) && strlen($data['settings']->company_logo) > 0) {
|
||||
try {
|
||||
$tempImage = tempnam(sys_get_temp_dir(), basename($data['settings']->company_logo));
|
||||
copy($data['settings']->company_logo, $tempImage);
|
||||
$this->uploadLogo($tempImage, $this->company, $this->company);
|
||||
}
|
||||
catch(\Exception $e){
|
||||
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -596,7 +591,6 @@ class Import implements ShouldQueue
|
||||
$invoice_repository = new InvoiceMigrationRepository();
|
||||
|
||||
foreach ($data as $key => $resource) {
|
||||
|
||||
$modified = $resource;
|
||||
|
||||
if (array_key_exists('client_id', $resource) && ! array_key_exists('clients', $this->ids)) {
|
||||
@ -621,7 +615,6 @@ class Import implements ShouldQueue
|
||||
'old' => $resource['id'],
|
||||
'new' => $invoice->id,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
RecurringInvoice::reguard();
|
||||
@ -629,7 +622,6 @@ class Import implements ShouldQueue
|
||||
/*Improve memory handling by setting everything to null when we have finished*/
|
||||
$data = null;
|
||||
$invoice_repository = null;
|
||||
|
||||
}
|
||||
|
||||
private function processInvoices(array $data): void
|
||||
@ -785,7 +777,6 @@ class Import implements ShouldQueue
|
||||
|
||||
private function processPayments(array $data): void
|
||||
{
|
||||
|
||||
Payment::reguard();
|
||||
|
||||
$rules = [
|
||||
@ -818,14 +809,12 @@ class Import implements ShouldQueue
|
||||
|
||||
if (isset($modified['invoices'])) {
|
||||
foreach ($modified['invoices'] as $key => $invoice) {
|
||||
|
||||
if($this->tryTransformingId('invoices', $invoice['invoice_id']))
|
||||
if ($this->tryTransformingId('invoices', $invoice['invoice_id'])) {
|
||||
$modified['invoices'][$key]['invoice_id'] = $this->transformId('invoices', $invoice['invoice_id']);
|
||||
else{
|
||||
} else {
|
||||
$modified['credits'][$key]['credit_id'] = $this->transformId('credits', $invoice['invoice_id']);
|
||||
$modified['credits'][$key]['amount'] = $modified['invoices'][$key]['amount'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -886,12 +875,12 @@ class Import implements ShouldQueue
|
||||
$payment->status_id = Payment::STATUS_PARTIALLY_REFUNDED;
|
||||
$payment->save();
|
||||
return $payment;
|
||||
break;
|
||||
break;
|
||||
case 6:
|
||||
$payment->status_id = Payment::STATUS_REFUNDED;
|
||||
$payment->save();
|
||||
return $payment;
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
return $payment;
|
||||
@ -901,11 +890,10 @@ class Import implements ShouldQueue
|
||||
|
||||
private function processDocuments(array $data): void
|
||||
{
|
||||
// Document::unguard();
|
||||
// Document::unguard();
|
||||
/* No validators since data provided by database is already valid. */
|
||||
|
||||
foreach($data as $resource)
|
||||
{
|
||||
foreach ($data as $resource) {
|
||||
$modified = $resource;
|
||||
|
||||
if (array_key_exists('invoice_id', $resource) && $resource['invoice_id'] && ! array_key_exists('invoices', $this->ids)) {
|
||||
@ -927,7 +915,6 @@ class Import implements ShouldQueue
|
||||
}
|
||||
|
||||
$this->saveDocument(file_get_contents($resource['url']), $entity, $is_public = true);
|
||||
|
||||
}
|
||||
|
||||
// foreach ($data as $resource) {
|
||||
@ -1079,7 +1066,8 @@ class Import implements ShouldQueue
|
||||
}
|
||||
|
||||
private function processTaskStatuses(array $data) :void
|
||||
{info('in task statuses');
|
||||
{
|
||||
info('in task statuses');
|
||||
TaskStatus::unguard();
|
||||
|
||||
foreach ($data as $resource) {
|
||||
@ -1149,17 +1137,21 @@ class Import implements ShouldQueue
|
||||
$modified['company_id'] = $this->company->id;
|
||||
$modified['user_id'] = $this->processUserId($resource);
|
||||
|
||||
if(isset($modified['client_id']))
|
||||
if (isset($modified['client_id'])) {
|
||||
$modified['client_id'] = $this->transformId('clients', $resource['client_id']);
|
||||
}
|
||||
|
||||
if(isset($modified['invoice_id']))
|
||||
if (isset($modified['invoice_id'])) {
|
||||
$modified['invoice_id'] = $this->transformId('invoices', $resource['invoice_id']);
|
||||
}
|
||||
|
||||
if(isset($modified['project_id']))
|
||||
if (isset($modified['project_id'])) {
|
||||
$modified['project_id'] = $this->transformId('projects', $resource['project_id']);
|
||||
}
|
||||
|
||||
if(isset($modified['status_id']))
|
||||
if (isset($modified['status_id'])) {
|
||||
$modified['status_id'] = $this->transformId('task_statuses', $resource['status_id']);
|
||||
}
|
||||
|
||||
$task = Task::Create($modified);
|
||||
|
||||
@ -1190,8 +1182,9 @@ class Import implements ShouldQueue
|
||||
$modified['company_id'] = $this->company->id;
|
||||
$modified['user_id'] = $this->processUserId($resource);
|
||||
|
||||
if(isset($modified['client_id']))
|
||||
if (isset($modified['client_id'])) {
|
||||
$modified['client_id'] = $this->transformId('clients', $resource['client_id']);
|
||||
}
|
||||
|
||||
$project = Project::Create($modified);
|
||||
|
||||
@ -1201,7 +1194,6 @@ class Import implements ShouldQueue
|
||||
'old' => $resource['id'],
|
||||
'new' => $project->id,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
Project::reguard();
|
||||
@ -1211,7 +1203,6 @@ class Import implements ShouldQueue
|
||||
|
||||
private function processExpenses(array $data) :void
|
||||
{
|
||||
|
||||
Expense::unguard();
|
||||
|
||||
foreach ($data as $resource) {
|
||||
@ -1222,20 +1213,25 @@ class Import implements ShouldQueue
|
||||
$modified['company_id'] = $this->company->id;
|
||||
$modified['user_id'] = $this->processUserId($resource);
|
||||
|
||||
if(isset($resource['client_id']))
|
||||
if (isset($resource['client_id'])) {
|
||||
$modified['client_id'] = $this->transformId('clients', $resource['client_id']);
|
||||
}
|
||||
|
||||
if(isset($resource['category_id']))
|
||||
if (isset($resource['category_id'])) {
|
||||
$modified['category_id'] = $this->transformId('expense_categories', $resource['category_id']);
|
||||
}
|
||||
|
||||
if(isset($resource['invoice_id']))
|
||||
if (isset($resource['invoice_id'])) {
|
||||
$modified['invoice_id'] = $this->transformId('invoices', $resource['invoice_id']);
|
||||
}
|
||||
|
||||
if(isset($resource['project_id']))
|
||||
if (isset($resource['project_id'])) {
|
||||
$modified['project_id'] = $this->transformId('projects', $resource['project_id']);
|
||||
}
|
||||
|
||||
if(isset($resource['vendor_id']))
|
||||
if (isset($resource['vendor_id'])) {
|
||||
$modified['vendor_id'] = $this->transformId('vendors', $resource['vendor_id']);
|
||||
}
|
||||
|
||||
$expense = Expense::Create($modified);
|
||||
|
||||
@ -1252,7 +1248,6 @@ class Import implements ShouldQueue
|
||||
Expense::reguard();
|
||||
|
||||
$data = null;
|
||||
|
||||
}
|
||||
/**
|
||||
* |--------------------------------------------------------------------------
|
||||
@ -1289,7 +1284,7 @@ class Import implements ShouldQueue
|
||||
public function transformId($resource, string $old): int
|
||||
{
|
||||
if (! array_key_exists($resource, $this->ids)) {
|
||||
info(print_r($resource,1));
|
||||
info(print_r($resource, 1));
|
||||
throw new Exception("Resource {$resource} not available.");
|
||||
}
|
||||
|
||||
@ -1345,7 +1340,5 @@ class Import implements ShouldQueue
|
||||
->batch();
|
||||
|
||||
info(print_r($exception->getMessage(), 1));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,37 +55,27 @@ class ReminderJob implements ShouldQueue
|
||||
$this->processReminders($db);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function processReminders($db = null)
|
||||
{
|
||||
|
||||
Invoice::where('next_send_date', Carbon::today()->format('Y-m-d'))->with('invitations')->cursor()->each(function ($invoice) {
|
||||
|
||||
if ($invoice->isPayable()) {
|
||||
|
||||
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||
$invoice->service()->touchReminder($this->reminder_template)->save();
|
||||
|
||||
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
|
||||
|
||||
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
|
||||
info("Firing email for invoice {$invoice->number}");
|
||||
});
|
||||
|
||||
if ($invoice->invitations->count() > 0)
|
||||
if ($invoice->invitations->count() > 0) {
|
||||
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars()));
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
$invoice->next_send_date = null;
|
||||
$invoice->save();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ class SendFailedEmails implements ShouldQueue
|
||||
|
||||
private function processEmails()
|
||||
{
|
||||
|
||||
$email_jobs = SystemLog::where('event_id', SystemLog::EVENT_MAIL_RETRY_QUEUE)->get();
|
||||
|
||||
$email_jobs->each(function ($job) {
|
||||
@ -64,7 +63,6 @@ class SendFailedEmails implements ShouldQueue
|
||||
$invitation = $job_meta_array['entity_name']::where('key', $job_meta_array['invitation_key'])->with('contact')->first();
|
||||
|
||||
if ($invitation->invoice) {
|
||||
|
||||
if ($invitation->contact->send_email && $invitation->contact->email) {
|
||||
EmailEntity::dispatch($invitation, $invitation->company, $job_meta_array['reminder_template']);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class StartMigration implements ShouldQueue
|
||||
|
||||
public $timeout = 0;
|
||||
|
||||
// public $maxExceptions = 2;
|
||||
// public $maxExceptions = 2;
|
||||
|
||||
//public $backoff = 86430;
|
||||
|
||||
@ -111,7 +111,6 @@ class StartMigration implements ShouldQueue
|
||||
//Import::dispatchNow($data['data'], $this->company, $this->user);
|
||||
Import::dispatchNow($file, $this->company, $this->user);
|
||||
} catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) {
|
||||
|
||||
Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage()));
|
||||
|
||||
if (app()->environment() !== 'production') {
|
||||
@ -126,6 +125,6 @@ class StartMigration implements ShouldQueue
|
||||
|
||||
public function failed($exception = null)
|
||||
{
|
||||
info(print_r($exception->getMessage(),1));
|
||||
info(print_r($exception->getMessage(), 1));
|
||||
}
|
||||
}
|
||||
|
@ -63,21 +63,22 @@ class WebhookHandler implements ShouldQueue
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
if (! $this->company || $this->company->is_disabled)
|
||||
if (! $this->company || $this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
$subscriptions = Webhook::where('company_id', $this->company->id)
|
||||
->where('event_id', $this->event_id)
|
||||
->get();
|
||||
|
||||
if (! $subscriptions || $subscriptions->count() == 0)
|
||||
if (! $subscriptions || $subscriptions->count() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$subscriptions->each(function ($subscription) {
|
||||
$this->process($subscription);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private function process($subscription)
|
||||
|
@ -62,7 +62,6 @@ class InvoiceEmailedNotification implements ShouldQueue
|
||||
|
||||
EntitySentMailer::dispatch($event->invitation, 'invoice', $user, $event->invitation->company);
|
||||
$first_notification_sent = false;
|
||||
|
||||
}
|
||||
|
||||
$notification->method = $methods;
|
||||
|
@ -57,9 +57,8 @@ class InvoicePaidActivity implements ShouldQueue
|
||||
|
||||
try {
|
||||
$event->invoice->service()->touchPdf();
|
||||
}
|
||||
catch(\Exception $e){
|
||||
info(print_r($e->getMessage(),1));
|
||||
} catch (\Exception $e) {
|
||||
info(print_r($e->getMessage(), 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,8 +50,6 @@ class PaymentEmailFailureActivity implements ShouldQueue
|
||||
$payment = $event->payment;
|
||||
|
||||
info("i failed emailing {$payment->number}");
|
||||
// info(print_r($event->errors,1));
|
||||
|
||||
// info(print_r($event->errors,1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,4 +52,3 @@ class PaymentEmailedActivity implements ShouldQueue
|
||||
info("i succeeded in emailing payment {$payment->number}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,6 @@ class PaymentNotification implements ShouldQueue
|
||||
|
||||
/*User notifications*/
|
||||
foreach ($payment->company->company_users as $company_user) {
|
||||
|
||||
$user = $company_user->user;
|
||||
|
||||
$methods = $this->findUserEntityNotificationType($payment, $company_user, ['all_notifications']);
|
||||
@ -64,7 +63,6 @@ class PaymentNotification implements ShouldQueue
|
||||
unset($methods[$key]);
|
||||
|
||||
EntityPaidMailer::dispatch($payment, $payment->company, $user);
|
||||
|
||||
}
|
||||
|
||||
$notification = new NewPaymentNotification($payment, $payment->company);
|
||||
|
@ -51,11 +51,8 @@ class SendVerificationNotification implements ShouldQueue
|
||||
$event->user->notify(new VerifyUser($event->user, $event->company));
|
||||
|
||||
Ninja::registerNinjaUser($event->user);
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
info("I couldn't send the email " . $e->getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,5 @@ class DownloadInvoices extends Mailable
|
||||
'logo' => $this->company->present()->logo,
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,129 +13,132 @@ namespace App\Mail\Engine;
|
||||
|
||||
class BaseEmailEngine implements EngineInterface
|
||||
{
|
||||
public $footer;
|
||||
public $footer;
|
||||
|
||||
public $variables;
|
||||
public $variables;
|
||||
|
||||
public $contact;
|
||||
public $contact;
|
||||
|
||||
public $subject;
|
||||
public $subject;
|
||||
|
||||
public $body;
|
||||
public $body;
|
||||
|
||||
public $template_style;
|
||||
public $template_style;
|
||||
|
||||
public $attachments;
|
||||
public $attachments;
|
||||
|
||||
public $link;
|
||||
public $link;
|
||||
|
||||
public $text;
|
||||
public $text;
|
||||
|
||||
public function setFooter($footer)
|
||||
{
|
||||
$this->footer = $footer;
|
||||
$this->footer = $footer;
|
||||
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setVariables($variables)
|
||||
{
|
||||
$this->variables = $variables;
|
||||
$this->variables = $variables;
|
||||
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setContact($contact)
|
||||
{
|
||||
$this->contact = $contact;
|
||||
$this->contact = $contact;
|
||||
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSubject($subject)
|
||||
{
|
||||
if (! empty($this->variables))
|
||||
if (! empty($this->variables)) {
|
||||
$subject = str_replace(array_keys($this->variables), array_values($this->variables), $subject);
|
||||
}
|
||||
|
||||
$this->subject = $subject;
|
||||
$this->subject = $subject;
|
||||
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setBody($body)
|
||||
{
|
||||
if (! empty($this->variables))
|
||||
if (! empty($this->variables)) {
|
||||
$body = str_replace(array_keys($this->variables), array_values($this->variables), $body);
|
||||
}
|
||||
|
||||
$this->body = $body;
|
||||
$this->body = $body;
|
||||
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTemplate($template_style)
|
||||
{
|
||||
$this->template_style = $template_style;
|
||||
$this->template_style = $template_style;
|
||||
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAttachments($attachments)
|
||||
{
|
||||
$this->attachments = $attachments;
|
||||
$this->attachments = $attachments;
|
||||
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setViewLink($link)
|
||||
{
|
||||
$this->link = $link;
|
||||
$this->link = $link;
|
||||
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setViewText($text)
|
||||
{
|
||||
$this->text = $text;
|
||||
$this->text = $text;
|
||||
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->subject;
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function getAttachments()
|
||||
{
|
||||
return $this->attachments;
|
||||
return $this->attachments;
|
||||
}
|
||||
|
||||
public function getFooter()
|
||||
{
|
||||
return $this->footer;
|
||||
return $this->footer;
|
||||
}
|
||||
|
||||
public function getTemplate()
|
||||
{
|
||||
return $this->template_style;
|
||||
return $this->template_style;
|
||||
}
|
||||
|
||||
public function getViewLink()
|
||||
{
|
||||
return $this->link;
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
|
||||
public function getViewText()
|
||||
{
|
||||
return $this->text;
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function build(){}
|
||||
|
||||
}
|
||||
public function build()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,15 @@ namespace App\Mail\Engine;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\Number;
|
||||
|
||||
class CreditEmailEngine extends BaseEmailEngine
|
||||
class CreditEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
public $invitation;
|
||||
public $invitation;
|
||||
|
||||
public $client;
|
||||
public $client;
|
||||
|
||||
public $credit;
|
||||
public $credit;
|
||||
|
||||
public $contact;
|
||||
public $contact;
|
||||
|
||||
public $reminder_template;
|
||||
|
||||
@ -30,7 +30,7 @@ class CreditEmailEngine extends BaseEmailEngine
|
||||
|
||||
public function __construct($invitation, $reminder_template, $template_data)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->invitation = $invitation;
|
||||
$this->reminder_template = $reminder_template;
|
||||
$this->client = $invitation->contact->client;
|
||||
$this->credit = $invitation->credit;
|
||||
@ -40,11 +40,11 @@ class CreditEmailEngine extends BaseEmailEngine
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
if(is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0)
|
||||
if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) {
|
||||
$body_template = $this->template_data['body'];
|
||||
else
|
||||
} else {
|
||||
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||
}
|
||||
|
||||
/* Use default translations if a custom message has not been set*/
|
||||
if (iconv_strlen($body_template) == 0) {
|
||||
@ -60,13 +60,13 @@ class CreditEmailEngine extends BaseEmailEngine
|
||||
);
|
||||
}
|
||||
|
||||
if(is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0)
|
||||
if (is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0) {
|
||||
$subject_template = $this->template_data['subject'];
|
||||
else
|
||||
} else {
|
||||
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
}
|
||||
|
||||
if (iconv_strlen($subject_template) == 0) {
|
||||
|
||||
$subject_template = trans(
|
||||
'texts.credit_subject',
|
||||
[
|
||||
@ -76,7 +76,6 @@ class CreditEmailEngine extends BaseEmailEngine
|
||||
null,
|
||||
$this->client->locale()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->setTemplate($this->client->getSetting('email_style'))
|
||||
@ -93,8 +92,5 @@ class CreditEmailEngine extends BaseEmailEngine
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ namespace App\Mail\Engine;
|
||||
|
||||
interface EngineInterface
|
||||
{
|
||||
|
||||
public function setFooter($footer);
|
||||
|
||||
public function setVariables($variables);
|
||||
@ -47,5 +46,4 @@ interface EngineInterface
|
||||
public function getViewText();
|
||||
|
||||
public function build();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,15 +15,15 @@ use App\DataMapper\EmailTemplateDefaults;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\Number;
|
||||
|
||||
class InvoiceEmailEngine extends BaseEmailEngine
|
||||
class InvoiceEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
public $invitation;
|
||||
public $invitation;
|
||||
|
||||
public $client;
|
||||
public $client;
|
||||
|
||||
public $invoice;
|
||||
public $invoice;
|
||||
|
||||
public $contact;
|
||||
public $contact;
|
||||
|
||||
public $reminder_template;
|
||||
|
||||
@ -31,7 +31,7 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
|
||||
public function __construct($invitation, $reminder_template, $template_data)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->invitation = $invitation;
|
||||
$this->reminder_template = $reminder_template;
|
||||
$this->client = $invitation->contact->client;
|
||||
$this->invoice = $invitation->invoice;
|
||||
@ -41,12 +41,11 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
if(is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0)
|
||||
if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) {
|
||||
$body_template = $this->template_data['body'];
|
||||
elseif(strlen($this->client->getSetting('email_template_'.$this->reminder_template)) > 0)
|
||||
} elseif (strlen($this->client->getSetting('email_template_'.$this->reminder_template)) > 0) {
|
||||
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||
else{
|
||||
} else {
|
||||
$body_template = EmailTemplateDefaults::getDefaultTemplate('email_template_'.$this->reminder_template, $this->client->locale());
|
||||
}
|
||||
|
||||
@ -64,22 +63,19 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
);
|
||||
}
|
||||
|
||||
if(is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0){
|
||||
if (is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0) {
|
||||
$subject_template = $this->template_data['subject'];
|
||||
info("subject = template data");
|
||||
}
|
||||
elseif(strlen($this->client->getSetting('email_subject_'.$this->reminder_template)) > 0){
|
||||
} elseif (strlen($this->client->getSetting('email_subject_'.$this->reminder_template)) > 0) {
|
||||
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
info("subject = settings var");
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
info("subject = default template " . 'email_subject_'.$this->reminder_template);
|
||||
$subject_template = EmailTemplateDefaults::getDefaultTemplate('email_subject_'.$this->reminder_template, $this->client->locale());
|
||||
// $subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
// $subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
}
|
||||
|
||||
if (iconv_strlen($subject_template) == 0) {
|
||||
|
||||
$subject_template = trans(
|
||||
'texts.invoice_subject',
|
||||
[
|
||||
@ -89,7 +85,6 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
null,
|
||||
$this->client->locale()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->setTemplate($this->client->getSetting('email_style'))
|
||||
@ -106,8 +101,5 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,13 +16,13 @@ use App\Utils\HtmlEngine;
|
||||
use App\Utils\Number;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
|
||||
class PaymentEmailEngine extends BaseEmailEngine
|
||||
class PaymentEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
use MakesDates;
|
||||
|
||||
public $client;
|
||||
public $client;
|
||||
|
||||
public $payment;
|
||||
public $payment;
|
||||
|
||||
public $template_data;
|
||||
|
||||
@ -44,12 +44,11 @@ class PaymentEmailEngine extends BaseEmailEngine
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
if(is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0)
|
||||
if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) {
|
||||
$body_template = $this->template_data['body'];
|
||||
elseif(strlen($this->client->getSetting('email_template_payment')) > 0)
|
||||
} elseif (strlen($this->client->getSetting('email_template_payment')) > 0) {
|
||||
$body_template = $this->client->getSetting('email_template_payment');
|
||||
else{
|
||||
} else {
|
||||
$body_template = EmailTemplateDefaults::getDefaultTemplate('email_template_payment', $this->client->locale());
|
||||
}
|
||||
|
||||
@ -63,13 +62,11 @@ class PaymentEmailEngine extends BaseEmailEngine
|
||||
);
|
||||
}
|
||||
|
||||
if(is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0){
|
||||
if (is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0) {
|
||||
$subject_template = $this->template_data['subject'];
|
||||
}
|
||||
elseif(strlen($this->client->getSetting('email_subject_payment')) > 0){
|
||||
} elseif (strlen($this->client->getSetting('email_subject_payment')) > 0) {
|
||||
$subject_template = $this->client->getSetting('email_subject_payment');
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$subject_template = EmailTemplateDefaults::getDefaultTemplate('email_subject_payment', $this->client->locale());
|
||||
}
|
||||
|
||||
@ -92,7 +89,6 @@ class PaymentEmailEngine extends BaseEmailEngine
|
||||
->setViewText('');
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -115,7 +111,7 @@ class PaymentEmailEngine extends BaseEmailEngine
|
||||
$data['$payment2'] = ['value' => $this->formatCustomFieldValue('payment2', $this->payment->custom_value2) ?: ' ', 'label' => $this->makeCustomField('payment2')];
|
||||
$data['$payment3'] = ['value' => $this->formatCustomFieldValue('payment3', $this->payment->custom_value3) ?: ' ', 'label' => $this->makeCustomField('payment3')];
|
||||
$data['$payment4'] = ['value' => $this->formatCustomFieldValue('payment4', $this->payment->custom_value4) ?: ' ', 'label' => $this->makeCustomField('payment4')];
|
||||
// $data['$type'] = ['value' => $this->payment->type->name ?: '', 'label' => ctrans('texts.payment_type')];
|
||||
// $data['$type'] = ['value' => $this->payment->type->name ?: '', 'label' => ctrans('texts.payment_type')];
|
||||
|
||||
$data['$client1'] = ['value' => $this->formatCustomFieldValue('client1', $this->client->custom_value1) ?: ' ', 'label' => $this->makeCustomField('client1')];
|
||||
$data['$client2'] = ['value' => $this->formatCustomFieldValue('client2', $this->client->custom_value2) ?: ' ', 'label' => $this->makeCustomField('client2')];
|
||||
@ -200,8 +196,7 @@ class PaymentEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
$invoice_list = '';
|
||||
|
||||
foreach($this->payment->invoices as $invoice)
|
||||
{
|
||||
foreach ($this->payment->invoices as $invoice) {
|
||||
$invoice_list .= ctrans('texts.invoice_number_short') . " {$invoice->number} - " . Number::formatMoney($invoice->pivot->amount, $this->client) . "<br>";
|
||||
}
|
||||
|
||||
@ -232,8 +227,9 @@ class PaymentEmailEngine extends BaseEmailEngine
|
||||
$custom_field = $custom_fields->{$field};
|
||||
$custom_field_parts = explode('|', $custom_field);
|
||||
|
||||
if(count($custom_field_parts) >= 2)
|
||||
if (count($custom_field_parts) >= 2) {
|
||||
$custom_field = $custom_field_parts[1];
|
||||
}
|
||||
}
|
||||
|
||||
switch ($custom_field) {
|
||||
@ -260,4 +256,3 @@ class PaymentEmailEngine extends BaseEmailEngine
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,23 +14,23 @@ namespace App\Mail\Engine;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\Number;
|
||||
|
||||
class QuoteEmailEngine extends BaseEmailEngine
|
||||
class QuoteEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
public $invitation;
|
||||
public $invitation;
|
||||
|
||||
public $client;
|
||||
public $client;
|
||||
|
||||
public $quote;
|
||||
public $quote;
|
||||
|
||||
public $contact;
|
||||
public $contact;
|
||||
|
||||
public $reminder_template;
|
||||
|
||||
public $template_data;
|
||||
public $template_data;
|
||||
|
||||
public function __construct($invitation, $reminder_template, $template_data)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->invitation = $invitation;
|
||||
$this->reminder_template = $reminder_template;
|
||||
$this->client = $invitation->contact->client;
|
||||
$this->quote = $invitation->quote;
|
||||
@ -40,11 +40,11 @@ class QuoteEmailEngine extends BaseEmailEngine
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
if(is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0)
|
||||
if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) {
|
||||
$body_template = $this->template_data['body'];
|
||||
else
|
||||
} else {
|
||||
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||
}
|
||||
|
||||
/* Use default translations if a custom message has not been set*/
|
||||
if (iconv_strlen($body_template) == 0) {
|
||||
@ -60,13 +60,13 @@ class QuoteEmailEngine extends BaseEmailEngine
|
||||
);
|
||||
}
|
||||
|
||||
if(is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0)
|
||||
if (is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0) {
|
||||
$subject_template = $this->template_data['subject'];
|
||||
else
|
||||
} else {
|
||||
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
}
|
||||
|
||||
if (iconv_strlen($subject_template) == 0) {
|
||||
|
||||
$subject_template = trans(
|
||||
'texts.quote_subject',
|
||||
[
|
||||
@ -76,7 +76,6 @@ class QuoteEmailEngine extends BaseEmailEngine
|
||||
null,
|
||||
$this->client->locale()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->setTemplate($this->client->getSetting('email_style'))
|
||||
@ -93,8 +92,5 @@ class QuoteEmailEngine extends BaseEmailEngine
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,6 @@ class TemplateEmail extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
|
||||
$template_name = 'email.template.'.$this->build_email->getTemplate();
|
||||
|
||||
$settings = $this->client->getMergedSettings();
|
||||
@ -56,13 +55,15 @@ class TemplateEmail extends Mailable
|
||||
|
||||
$this->from($this->user->email, $this->user->present()->name());
|
||||
|
||||
if(strlen($settings->reply_to_email) > 1)
|
||||
if (strlen($settings->reply_to_email) > 1) {
|
||||
$this->replyTo($settings->reply_to_email, $settings->reply_to_email);
|
||||
}
|
||||
|
||||
if(strlen($settings->bcc_email) > 1)
|
||||
if (strlen($settings->bcc_email) > 1) {
|
||||
$this->bcc($settings->bcc_email, $settings->bcc_email);
|
||||
}
|
||||
|
||||
$this->subject($this->build_email->getSubject())
|
||||
$this->subject($this->build_email->getSubject())
|
||||
->text('email.template.plain', [
|
||||
'body' => $this->build_email->getBody(),
|
||||
'footer' => $this->build_email->getFooter(),
|
||||
|
@ -157,7 +157,7 @@ class Activity extends StaticModel
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function resolveRouteBinding($value, $field = NULL)
|
||||
public function resolveRouteBinding($value, $field = null)
|
||||
{
|
||||
if (is_numeric($value)) {
|
||||
throw new ModelNotFoundException("Record with value {$value} not found");
|
||||
|
@ -166,7 +166,7 @@ class BaseModel extends Model
|
||||
* @param null $field
|
||||
* @return Model|null
|
||||
*/
|
||||
public function resolveRouteBinding($value, $field = NULL)
|
||||
public function resolveRouteBinding($value, $field = null)
|
||||
{
|
||||
if (is_numeric($value)) {
|
||||
throw new ModelNotFoundException("Record with value {$value} not found");
|
||||
|
@ -243,7 +243,6 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
return $date_formats->filter(function ($item) {
|
||||
return $item->id == $this->getSetting('date_format_id');
|
||||
})->first()->format;
|
||||
|
||||
}
|
||||
|
||||
public function currency()
|
||||
@ -384,7 +383,7 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
return array_search($model->id, $transformed_ids);
|
||||
});
|
||||
} else {
|
||||
$gateways = $this->company->company_gateways;
|
||||
$gateways = $this->company->company_gateways;
|
||||
}
|
||||
|
||||
foreach ($gateways as $gateway) {
|
||||
@ -472,7 +471,6 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
|
||||
//we need to check for "0" here as we disable a payment gateway for a client with the number "0"
|
||||
if ($company_gateways || $company_gateways == '0') {
|
||||
|
||||
$transformed_ids = $this->transformKeys(explode(',', $company_gateways));
|
||||
$gateways = $this->company
|
||||
->company_gateways
|
||||
@ -488,21 +486,13 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
|
||||
foreach ($gateways as $gateway) {
|
||||
foreach ($gateway->driver($this)->gatewayTypes() as $type) {
|
||||
|
||||
if(isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type))
|
||||
{
|
||||
|
||||
if($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $amount))
|
||||
if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) {
|
||||
if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $amount)) {
|
||||
$payment_methods[] = [$gateway->id => $type];
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
} else {
|
||||
$payment_methods[] = [$gateway->id => $type];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -527,8 +517,8 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
}
|
||||
}
|
||||
|
||||
if(($this->getSetting('use_credits_payment') == 'option' || $this->getSetting('use_credits_payment') == 'always') && $this->service()->getCreditBalance() > 0) {
|
||||
$payment_urls[] = [
|
||||
if (($this->getSetting('use_credits_payment') == 'option' || $this->getSetting('use_credits_payment') == 'always') && $this->service()->getCreditBalance() > 0) {
|
||||
$payment_urls[] = [
|
||||
'label' => ctrans('texts.apply_credit'),
|
||||
'company_gateway_id' => CompanyGateway::GATEWAY_CREDIT,
|
||||
'gateway_type_id' => GatewayType::CREDIT,
|
||||
@ -540,21 +530,21 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
|
||||
public function validGatewayForAmount($fees_and_limits_for_payment_type, $amount) :bool
|
||||
{
|
||||
if (isset($fees_and_limits_for_payment_type)) {
|
||||
$fees_and_limits = $fees_and_limits_for_payment_type;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $fees_and_limits->min_limit != -1 && $amount < $fees_and_limits->min_limit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $fees_and_limits->max_limit != -1 && $amount > $fees_and_limits->max_limit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($fees_and_limits_for_payment_type)) {
|
||||
$fees_and_limits = $fees_and_limits_for_payment_type;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $fees_and_limits->min_limit != -1 && $amount < $fees_and_limits->min_limit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $fees_and_limits->max_limit != -1 && $amount > $fees_and_limits->max_limit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preferredLocale()
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user