Fixes for reset of counters

This commit is contained in:
David Bomba 2021-05-05 10:58:18 +10:00
parent 2655ba679b
commit e7526cb4dc
3 changed files with 17 additions and 14 deletions

View File

@ -47,6 +47,7 @@ class InvoiceEmailActivity implements ShouldQueue
$fields->user_id = $event->invitation->invoice->user_id; $fields->user_id = $event->invitation->invoice->user_id;
$fields->company_id = $event->invitation->invoice->company_id; $fields->company_id = $event->invitation->invoice->company_id;
$fields->client_contact_id = $event->invitation->invoice->client_contact_id; $fields->client_contact_id = $event->invitation->invoice->client_contact_id;
$fields->client_id = $event->invitation->invoice->client_id;
$fields->activity_type_id = Activity::EMAIL_INVOICE; $fields->activity_type_id = Activity::EMAIL_INVOICE;
$this->activity_repo->save($fields, $event->invitation->invoice, $event->event_vars); $this->activity_repo->save($fields, $event->invitation->invoice, $event->event_vars);

View File

@ -48,6 +48,7 @@ class QuoteEmailActivity implements ShouldQueue
$fields->user_id = $event->invitation->quote->user_id; $fields->user_id = $event->invitation->quote->user_id;
$fields->company_id = $event->invitation->quote->company_id; $fields->company_id = $event->invitation->quote->company_id;
$fields->client_contact_id = $event->invitation->quote->client_contact_id; $fields->client_contact_id = $event->invitation->quote->client_contact_id;
$fields->client_id = $event->invitation->quote->client_id;
$fields->activity_type_id = Activity::EMAIL_QUOTE; $fields->activity_type_id = Activity::EMAIL_QUOTE;
$this->activity_repo->save($fields, $event->invitation->quote, $event->event_vars); $this->activity_repo->save($fields, $event->invitation->quote, $event->event_vars);

View File

@ -431,54 +431,55 @@ trait GeneratesCounter
$reset_date = Carbon::parse($client->getSetting('reset_counter_date'), $timezone->name); $reset_date = Carbon::parse($client->getSetting('reset_counter_date'), $timezone->name);
if (! $reset_date->isToday() || ! $client->getSetting('reset_counter_date')) { if (! $reset_date->lte(now()) || ! $client->getSetting('reset_counter_date')) {
return false; return false;
} }
switch ($reset_counter_frequency) { switch ($reset_counter_frequency) {
case RecurringInvoice::FREQUENCY_DAILY: case RecurringInvoice::FREQUENCY_DAILY:
$reset_date->addDay(); now()->addDay();
break; break;
case RecurringInvoice::FREQUENCY_WEEKLY: case RecurringInvoice::FREQUENCY_WEEKLY:
$reset_date->addWeek(); now()->addWeek();
break; break;
case RecurringInvoice::FREQUENCY_TWO_WEEKS: case RecurringInvoice::FREQUENCY_TWO_WEEKS:
$reset_date->addWeeks(2); now()->addWeeks(2);
break; break;
case RecurringInvoice::FREQUENCY_FOUR_WEEKS: case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
$reset_date->addWeeks(4); now()->addWeeks(4);
break; break;
case RecurringInvoice::FREQUENCY_MONTHLY: case RecurringInvoice::FREQUENCY_MONTHLY:
$reset_date->addMonth(); now()->addMonth();
break; break;
case RecurringInvoice::FREQUENCY_TWO_MONTHS: case RecurringInvoice::FREQUENCY_TWO_MONTHS:
$reset_date->addMonths(2); now()->addMonths(2);
break; break;
case RecurringInvoice::FREQUENCY_THREE_MONTHS: case RecurringInvoice::FREQUENCY_THREE_MONTHS:
$reset_date->addMonths(3); now()->addMonths(3);
break; break;
case RecurringInvoice::FREQUENCY_FOUR_MONTHS: case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
$reset_date->addMonths(4); now()->addMonths(4);
break; break;
case RecurringInvoice::FREQUENCY_SIX_MONTHS: case RecurringInvoice::FREQUENCY_SIX_MONTHS:
$reset_date->addMonths(6); now()->addMonths(6);
break; break;
case RecurringInvoice::FREQUENCY_ANNUALLY: case RecurringInvoice::FREQUENCY_ANNUALLY:
$reset_date->addYear(); now()->addYear();
break; break;
case RecurringInvoice::FREQUENCY_TWO_YEARS: case RecurringInvoice::FREQUENCY_TWO_YEARS:
$reset_date->addYears(2); now()->addYears(2);
break; break;
} }
$settings = $client->company->settings; $settings = $client->company->settings;
$settings->reset_counter_date = $reset_date->format($client->date_format()); $settings->reset_counter_date = $reset_date->format('Y-m-d');
$settings->invoice_number_counter = 1; $settings->invoice_number_counter = 1;
$settings->quote_number_counter = 1; $settings->quote_number_counter = 1;
$settings->credit_number_counter = 1; $settings->credit_number_counter = 1;
$client->company->settings = $settings; $client->company->settings = $settings;
$client->company->save(); $client->company->save();
} }
private function resetCompanyCounters($company) private function resetCompanyCounters($company)
@ -487,7 +488,7 @@ trait GeneratesCounter
$reset_date = Carbon::parse($company->settings->reset_counter_date, $timezone->name); $reset_date = Carbon::parse($company->settings->reset_counter_date, $timezone->name);
if (! $reset_date->isToday() || ! $company->settings->reset_counter_date) { if (! $reset_date->lte(now()) || ! $company->settings->reset_counter_date) {
return false; return false;
} }