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

Merge branch 'v5-develop' into Cirkovic/INA-2!

This commit is contained in:
Nikola Cirkovic 2022-05-17 01:46:30 +02:00 committed by GitHub
commit adc6e7b32a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 328 additions and 53 deletions

View File

@ -607,7 +607,7 @@ class CheckData extends Command
invoices ON
clients.id=invoices.client_id
WHERE invoices.is_deleted = false
AND invoices.status_id IN (2,3,4)
AND invoices.status_id IN (2,3)
GROUP BY clients.id
HAVING invoice_balance != clients.balance
ORDER BY clients.id;
@ -663,7 +663,7 @@ class CheckData extends Command
ON invoices.client_id = clients.id
WHERE invoices.is_deleted = 0
AND clients.is_deleted = 0
AND invoices.status_id IN (2,3,4)
AND invoices.status_id IN (2,3)
GROUP BY clients.id
HAVING(invoices_balance != clients.balance)
ORDER BY clients.id;
@ -683,7 +683,7 @@ class CheckData extends Command
{
$client = Client::withTrashed()->find($_client->id);
$invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2,3,4])->sum('balance');
$invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2,3])->sum('balance');
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();
@ -724,7 +724,7 @@ class CheckData extends Command
$this->wrong_paid_to_dates = 0;
foreach (Client::where('is_deleted', 0)->where('clients.updated_at', '>', now()->subDays(2))->cursor() as $client) {
$invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2,3,4])->sum('balance');
$invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2,3])->sum('balance');
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();
if ($ledger && number_format($ledger->balance, 4) != number_format($client->balance, 4)) {

View File

@ -18,6 +18,7 @@ use App\Jobs\Cron\SubscriptionCron;
use App\Jobs\Ledger\LedgerBalanceUpdate;
use App\Jobs\Ninja\AdjustEmailQuota;
use App\Jobs\Ninja\CompanySizeCheck;
use App\Jobs\Ninja\QueueSize;
use App\Jobs\Util\DiskCleanup;
use App\Jobs\Util\ReminderJob;
use App\Jobs\Util\SchedulerCheck;
@ -55,7 +56,8 @@ class Kernel extends ConsoleKernel
$schedule->job(new ReminderJob)->hourly()->withoutOverlapping();
$schedule->job(new LedgerBalanceUpdate)->everyFiveMinutes()->withoutOverlapping();
// $schedule->job(new LedgerBalanceUpdate)->everyFiveMinutes()->withoutOverlapping();
$schedule->job(new QueueSize)->everyFiveMinutes()->withoutOverlapping();
$schedule->job(new CompanySizeCheck)->daily()->withoutOverlapping();
@ -87,9 +89,9 @@ class Kernel extends ConsoleKernel
$schedule->job(new SendFailedEmails)->daily()->withoutOverlapping();
$schedule->command('ninja:check-data --database=db-ninja-01')->daily('01:00')->withoutOverlapping();
$schedule->command('ninja:check-data --database=db-ninja-01')->daily('02:00')->withoutOverlapping();
$schedule->command('ninja:check-data --database=db-ninja-02')->dailyAt('01:05')->withoutOverlapping();
$schedule->command('ninja:check-data --database=db-ninja-02')->dailyAt('02:05')->withoutOverlapping();
$schedule->command('ninja:s3-cleanup')->dailyAt('23:15')->withoutOverlapping();

View File

@ -0,0 +1,79 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\DataMapper\Analytics;
use Turbo124\Beacon\ExampleMetric\GenericMixedMetric;
class QueueSize extends GenericMixedMetric
{
/**
* The type of Sample.
*
* Monotonically incrementing counter
*
* - counter
*
* @var string
*/
public $type = 'mixed_metric';
/**
* The name of the counter.
* @var string
*/
public $name = 'ninja.queue_size';
/**
* The datetime of the counter measurement.
*
* date("Y-m-d H:i:s")
*
* @var DateTime
*/
public $datetime;
/**
* The Class failure name
* set to 0.
*
* @var string
*/
public $string_metric5 = 'stub';
/**
* The exception string
* set to 0.
*
* @var string
*/
public $string_metric6 = 'stub';
/**
* The counter
* set to 1.
*
* @var string
*/
public $int_metric1 = 1;
/**
* Company Key
* @var string
*/
public $string_metric7 = '';
public function __construct($int_metric1) {
$this->int_metric1 = $int_metric1;
}
}

View File

@ -104,7 +104,7 @@ class StorePaymentRequest extends Request
'credits.*.credit_id' => new ValidCreditsRules($this->all()),
'credits.*.amount' => ['required', new CreditsSumRule($this->all())],
'invoices' => new ValidPayableInvoicesRule(),
'number' => ['nullable', Rule::unique('payments')->where('company_id', auth()->user()->company()->id)],
'number' => ['nullable', 'bail', Rule::unique('payments')->where('company_id', auth()->user()->company()->id)],
];

View File

@ -38,6 +38,8 @@ class SubscriptionCron
public function handle() : void
{
nlog("Subscription Cron");
if (! config('ninja.db.multi_db_enabled')) {
$this->loopSubscriptions();

View File

@ -0,0 +1,85 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Ledger;
use App\Libraries\MultiDB;
use App\Models\Client;
use App\Models\Company;
use App\Models\CompanyLedger;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ClientLedgerBalanceUpdate implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 1;
public $company;
public $client;
public function __construct(Company $company, Client $client)
{
$this->company = $company;
$this->client = $client;
}
/**
* Execute the job.
*
*
* @return void
*/
public function handle() :void
{
nlog("Updating company ledgers");
MultiDB::setDb($this->company->db);
CompanyLedger::where('balance', 0)->where('client_id', $this->client->id)->cursor()->each(function ($company_ledger){
if($company_ledger->balance > 0)
return;
$last_record = CompanyLedger::where('client_id', $company_ledger->client_id)
->where('company_id', $company_ledger->company_id)
->where('balance', '!=', 0)
->orderBy('id', 'DESC')
->first();
if(!$last_record)
return;
nlog("Updating Balance NOW");
$company_ledger->balance = $last_record->balance + $company_ledger->adjustment;
$company_ledger->save();
});
nlog("Finished checking company ledgers");
}
public function checkLedger()
{
}
}

View File

@ -24,6 +24,8 @@ class LedgerBalanceUpdate implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 1;
public function __construct()
{
}
@ -34,26 +36,31 @@ class LedgerBalanceUpdate implements ShouldQueue
*
* @return void
*/
public function handle()
public function handle() :void
{
nlog("Updating company ledgers");
if (! config('ninja.db.multi_db_enabled')) {
$this->check();
$this->checkLedger();
} else {
//multiDB environment, need to
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
$this->check();
$this->checkLedger();
}
}
nlog("Finished checking company ledgers");
}
public function check()
public function checkLedger()
{
CompanyLedger::where('balance', 0)->cursor()->each(function ($company_ledger){
nlog("Checking ledgers....");
CompanyLedger::where('balance', 0)->where('adjustment', '!=', 0)->cursor()->each(function ($company_ledger){
if($company_ledger->balance > 0)
return;
@ -67,6 +74,8 @@ class LedgerBalanceUpdate implements ShouldQueue
if(!$last_record)
return;
nlog("Updating Balance NOW");
$company_ledger->balance = $last_record->balance + $company_ledger->adjustment;
$company_ledger->save();

View File

@ -0,0 +1,48 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Ninja;
use App\DataMapper\Analytics\QueueSize as QueueSizeAnalytic;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Queue;
use Turbo124\Beacon\Facades\LightLogs;
use Turbo124\Beacon\Jobs\Database\MySQL\DbStatus;
class QueueSize implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
LightLogs::create(new QueueSizeAnalytic(Queue::size()))
->queue();
}
}

View File

@ -36,7 +36,7 @@ class DiskCleanup implements ShouldQueue
*/
public function handle()
{
nlog("Cleaning Storage");
// Get all files in a directory
$files = Storage::allFiles(config('filesystems.default'), 'backups/');

View File

@ -153,10 +153,12 @@ class InvoiceEmailEngine extends BaseEmailEngine
$line_items = $this->invoice->line_items;
$expense_ids = [];
foreach($line_items as $item)
{
$expense_ids = [];
if(property_exists($item, 'expense_id'))
{
$expense_ids[] = $item->expense_id;
@ -177,6 +179,8 @@ class InvoiceEmailEngine extends BaseEmailEngine
});
}
$task_ids = [];
if(property_exists($item, 'task_id'))
{
$task_ids[] = $item->task_id;

View File

@ -48,4 +48,9 @@ class CompanyLedger extends Model
{
return $this->morphTo();
}
public function client()
{
return $this->belongsTo(Client::class);
}
}

View File

@ -30,7 +30,7 @@ class ClientObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client, $client->company);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client, $client->company)->delay(now()->addSeconds(2));
}
}
@ -47,7 +47,7 @@ class ClientObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CLIENT, $client, $client->company);
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CLIENT, $client, $client->company)->delay(now()->addSeconds(2));
}
}
@ -64,7 +64,7 @@ class ClientObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_CLIENT, $client, $client->company);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_CLIENT, $client, $client->company)->delay(now()->addSeconds(2));
}
}

View File

@ -30,7 +30,7 @@ class ExpenseObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense, $expense->company);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(2));
}
}
@ -47,7 +47,7 @@ class ExpenseObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_EXPENSE, $expense, $expense->company);
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(2));
}
}
@ -64,7 +64,7 @@ class ExpenseObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_EXPENSE, $expense, $expense->company);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(2));
}
}

View File

@ -36,7 +36,7 @@ class InvoiceObserver
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company, 'client');
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(2));
}
}
@ -55,7 +55,7 @@ class InvoiceObserver
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company, 'client');
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(2));
}
@ -75,7 +75,7 @@ class InvoiceObserver
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company, 'client');
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(2));
}
}

View File

@ -30,7 +30,7 @@ class PaymentObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company, 'invoices,client')->delay(5);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company, 'invoices,client')->delay(now()->addSeconds(20));
}
}
@ -57,7 +57,7 @@ class PaymentObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company, 'invoices,client')->delay(5);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company, 'invoices,client')->delay(now()->addSeconds(20));
}
}

View File

@ -32,7 +32,7 @@ class ProjectObserver
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_CREATE, $project, $project->company, 'client');
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_CREATE, $project, $project->company, 'client')->delay(now()->addSeconds(2));
}
}
@ -50,7 +50,7 @@ class ProjectObserver
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_UPDATE, $project, $project->company, 'client');
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_UPDATE, $project, $project->company, 'client')->delay(now()->addSeconds(2));
}
}

View File

@ -33,7 +33,7 @@ class QuoteObserver
if ($subscriptions) {
$quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote, $quote->company, 'client');
WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(2));
}
}
@ -53,7 +53,7 @@ class QuoteObserver
if ($subscriptions) {
$quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company, 'client');
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(2));
}
}
@ -72,7 +72,7 @@ class QuoteObserver
if ($subscriptions) {
$quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote, $quote->company, 'client');
WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(2));
}
}

View File

@ -30,7 +30,7 @@ class TaskObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task, $task->company);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task, $task->company)->delay(now()->addSeconds(2));
}
}
@ -47,7 +47,7 @@ class TaskObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_TASK, $task, $task->company);
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_TASK, $task, $task->company)->delay(now()->addSeconds(2));
}
}
@ -64,7 +64,7 @@ class TaskObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_TASK, $task, $task->company);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_TASK, $task, $task->company)->delay(now()->addSeconds(2));
}
}

View File

@ -568,7 +568,7 @@ class StripePaymentDriver extends BaseDriver
//payment_intent.succeeded - this will confirm or cancel the payment
if($request->type === 'payment_intent.succeeded'){
PaymentIntentWebhook::dispatch($request->data, $request->company_key, $this->company_gateway->id)->delay(10);
PaymentIntentWebhook::dispatch($request->data, $request->company_key, $this->company_gateway->id)->delay(now()->addSeconds(10));
return response()->json([], 200);
}

View File

@ -45,8 +45,8 @@ class SendEmail
$this->credit->invitations->each(function ($invitation) {
if (!$invitation->contact->trashed() && $invitation->contact->email) {
$email_builder = (new CreditEmail())->build($invitation, $this->reminder_template);
// $email_builder = (new CreditEmail())->build($invitation, $this->reminder_template);
// EmailCredit::dispatchNow($email_builder, $invitation, $invitation->company);
EmailEntity::dispatchNow($invitation, $invitation->company, $this->reminder_template);
}

View File

@ -114,7 +114,7 @@ class AutoBillInvoice extends AbstractService
]);
nlog("Payment hash created => {$payment_hash->id}");
$payment = false;
$number_of_retries = $this->invoice->auto_bill_tries;

View File

@ -35,7 +35,7 @@ class UpdateReminder extends AbstractService
$this->settings = $this->invoice->client->getMergedSettings();
}
if (! $this->invoice->isPayable()) {
if (! $this->invoice->isPayable() || $this->invoice->status_id == Invoice::STATUS_DRAFT) {
$this->invoice->next_send_date = null;
$this->invoice->saveQuietly();
@ -51,7 +51,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder1_sent) &&
$this->settings->schedule_reminder1 == 'after_invoice_date' &&
$this->settings->enable_reminder1) {
$this->settings->enable_reminder1 &&
$this->settings->num_days_reminder1 != 0) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -60,7 +61,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder1_sent) &&
$this->settings->schedule_reminder1 == 'before_due_date' &&
$this->settings->enable_reminder1) {
$this->settings->enable_reminder1 &&
$this->settings->num_days_reminder1 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -69,7 +71,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder1_sent) &&
$this->settings->schedule_reminder1 == 'after_due_date' &&
$this->settings->enable_reminder1) {
$this->settings->enable_reminder1 &&
$this->settings->num_days_reminder1 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -78,7 +81,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder2_sent) &&
$this->settings->schedule_reminder2 == 'after_invoice_date' &&
$this->settings->enable_reminder2) {
$this->settings->enable_reminder2 &&
$this->settings->num_days_reminder2 != 0) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -87,7 +91,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder2_sent) &&
$this->settings->schedule_reminder2 == 'before_due_date' &&
$this->settings->enable_reminder2) {
$this->settings->enable_reminder2 &&
$this->settings->num_days_reminder2 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -96,7 +101,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder2_sent) &&
$this->settings->schedule_reminder2 == 'after_due_date' &&
$this->settings->enable_reminder2) {
$this->settings->enable_reminder2 &&
$this->settings->num_days_reminder2 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -105,7 +111,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder3_sent) &&
$this->settings->schedule_reminder3 == 'after_invoice_date' &&
$this->settings->enable_reminder3) {
$this->settings->enable_reminder3 &&
$this->settings->num_days_reminder3 != 0) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -114,7 +121,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder3_sent) &&
$this->settings->schedule_reminder3 == 'before_due_date' &&
$this->settings->enable_reminder3) {
$this->settings->enable_reminder3 &&
$this->settings->num_days_reminder3 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -123,7 +131,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder3_sent) &&
$this->settings->schedule_reminder3 == 'after_due_date' &&
$this->settings->enable_reminder3) {
$this->settings->enable_reminder3 &&
$this->settings->num_days_reminder3 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))

View File

@ -12,6 +12,7 @@
namespace App\Services\Ledger;
use App\Factory\CompanyLedgerFactory;
use App\Jobs\Ledger\ClientLedgerBalanceUpdate;
use App\Models\Activity;
use App\Models\CompanyLedger;
@ -36,6 +37,7 @@ class LedgerService
$this->entity->company_ledger()->save($company_ledger);
ClientLedgerBalanceUpdate::dispatch($this->entity->company, $this->entity->client)->delay(now()->addSeconds(300));
return $this;
}
@ -52,6 +54,8 @@ class LedgerService
$this->entity->company_ledger()->save($company_ledger);
ClientLedgerBalanceUpdate::dispatch($this->entity->company, $this->entity->client)->delay(now()->addSeconds(300));
return $this;
}
@ -67,6 +71,8 @@ class LedgerService
$this->entity->company_ledger()->save($company_ledger);
ClientLedgerBalanceUpdate::dispatch($this->entity->company, $this->entity->client)->delay(now()->addSeconds(300));
return $this;
}

View File

@ -226,7 +226,7 @@ class Design extends BaseDesign
{
if ($this->type === 'statement') {
$s_date = $this->translateDate(now()->format($this->client->company->date_format()), $this->client->date_format(), $this->client->locale());
$s_date = $this->translateDate(now(), $this->client->date_format(), $this->client->locale());
return [
['element' => 'tr', 'properties' => ['data-ref' => 'statement-label'], 'elements' => [
@ -391,10 +391,10 @@ class Design extends BaseDesign
$element = ['element' => 'tr', 'elements' => []];
$element['elements'][] = ['element' => 'td', 'content' => $invoice->number];
$element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($invoice->date, $this->client->date_format(), $this->client->locale()) ?: '&nbsp;'];
$element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($invoice->due_date, $this->client->date_format(), $this->client->locale()) ?: '&nbsp;'];
$element['elements'][] = ['element' => 'td', 'content' => Number::formatMoney($invoice->amount, $this->client) ?: '&nbsp;'];
$element['elements'][] = ['element' => 'td', 'content' => Number::formatMoney($invoice->balance, $this->client) ?: '&nbsp;'];
$element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($invoice->date, $this->client->date_format(), $this->client->locale()) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($invoice->due_date, $this->client->date_format(), $this->client->locale()) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => Number::formatMoney($invoice->amount, $this->client) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => Number::formatMoney($invoice->balance, $this->client) ?: ' '];
$tbody[] = $element;
}

View File

@ -169,4 +169,30 @@ class ReminderTest extends TestCase
}
public function testReminderIsSet()
{
$this->invoice->next_send_date = null;
$this->invoice->date = now()->format('Y-m-d');
$this->invoice->due_date = Carbon::now()->addDays(30)->format('Y-m-d');
$this->invoice->save();
$settings = $this->company->settings;
$settings->enable_reminder1 = true;
$settings->schedule_reminder1 = 'after_invoice_date';
$settings->num_days_reminder1 = 7;
$settings->enable_reminder2 = true;
$settings->schedule_reminder2 = 'before_due_date';
$settings->num_days_reminder2 = 1;
$settings->enable_reminder3 = true;
$settings->schedule_reminder3 = 'after_due_date';
$settings->num_days_reminder3 = 1;
$this->company->settings = $settings;
$this->invoice = $this->invoice->service()->markSent()->save();
$this->invoice->service()->setReminder($settings)->save();
$this->assertNotNull($this->invoice->next_send_date);
}
}