diff --git a/app/DataMapper/Schedule/ClientStatement.php b/app/DataMapper/Schedule/EmailStatement.php similarity index 92% rename from app/DataMapper/Schedule/ClientStatement.php rename to app/DataMapper/Schedule/EmailStatement.php index fb08df943..07b171306 100644 --- a/app/DataMapper/Schedule/ClientStatement.php +++ b/app/DataMapper/Schedule/EmailStatement.php @@ -11,10 +11,14 @@ namespace App\DataMapper\Schedule; +<<<<<<< HEAD:app/DataMapper/Schedule/ClientStatement.php use App\Models\Client; use stdClass; class ClientStatement +======= +class EmailStatement +>>>>>>> 63a7a1185 (Minor fixes for types):app/DataMapper/Schedule/EmailStatement.php { /** diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index ecaf942e9..7d9bde717 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -225,7 +225,7 @@ class NinjaMailerJob implements ShouldQueue switch ($class) { case Invoice::class: - event(new InvoiceWasEmailedAndFailed($this->nmo->invitation, $this->nmo->company, $message, $this->nmo->reminder_template, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + event(new InvoiceWasEmailedAndFailed($this->nmo->invitation, $this->nmo->company, $message, $this->nmo->template, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); break; case Payment::class: event(new PaymentWasEmailedAndFailed($this->nmo->entity, $this->nmo->company, $message, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); @@ -578,7 +578,7 @@ class NinjaMailerJob implements ShouldQueue * Logs any errors to the SystemLog * * @param string $errors - * @param App\Models\User | App\Models\Client $recipient_object + * @param App\Models\User | App\Models\Client | null $recipient_object * @return void */ private function logMailError($errors, $recipient_object) :void diff --git a/app/Services/Email/EmailObject.php b/app/Services/Email/EmailObject.php index 30edec78c..f1a250924 100644 --- a/app/Services/Email/EmailObject.php +++ b/app/Services/Email/EmailObject.php @@ -11,11 +11,17 @@ namespace App\Services\Email; +<<<<<<< HEAD use App\Models\Client; use App\Models\ClientContact; use App\Models\Company; +======= +>>>>>>> 63a7a1185 (Minor fixes for types) use App\Models\User; +use App\Models\Client; use App\Models\Vendor; +use App\Models\Company; +use App\Models\ClientContact; use App\Models\VendorContact; use Illuminate\Mail\Mailables\Address; @@ -77,8 +83,15 @@ class EmailObject public ?int $entity_id = null; +<<<<<<< HEAD public ?string $entity_class = null; public array $variables = []; -} \ No newline at end of file +} +======= + public array $variables = []; + + public ?Company $company = null; +} +>>>>>>> 63a7a1185 (Minor fixes for types) diff --git a/app/Services/Scheduler/SchedulerService.php b/app/Services/Scheduler/SchedulerService.php index 1fc62c3b5..87701909f 100644 --- a/app/Services/Scheduler/SchedulerService.php +++ b/app/Services/Scheduler/SchedulerService.php @@ -15,8 +15,12 @@ use App\Models\Client; use App\Models\RecurringInvoice; use App\Models\Scheduler; use App\Utils\Traits\MakesDates; +<<<<<<< HEAD use App\Utils\Traits\MakesHash; use Carbon\Carbon; +======= +use App\DataMapper\Schedule\EmailStatement; +>>>>>>> 63a7a1185 (Minor fixes for types) class SchedulerService { @@ -93,6 +97,7 @@ class SchedulerService private function calculateStartAndEndDates(): array { return match ($this->scheduler->parameters['date_range']) { +<<<<<<< HEAD 'this_month' => [now()->startOfDay()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->lastOfMonth()->format('Y-m-d')], 'this_quarter' => [now()->startOfDay()->firstOfQuarter()->format('Y-m-d'), now()->startOfDay()->lastOfQuarter()->format('Y-m-d')], 'this_year' => [now()->startOfDay()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->lastOfYear()->format('Y-m-d')], @@ -101,6 +106,19 @@ class SchedulerService 'previous_year' => [now()->startOfDay()->subYearNoOverflow()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->subYearNoOverflow()->lastOfYear()->format('Y-m-d')], 'custom_range' => [$this->scheduler->parameters['start_date'], $this->scheduler->parameters['end_date']], default => [now()->startOfDay()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->lastOfMonth()->format('Y-m-d')], +======= + EmailStatement::LAST7 => [now()->startOfDay()->subDays(7)->format('Y-m-d'), now()->startOfDay()->format('Y-m-d')], + EmailStatement::LAST30 => [now()->startOfDay()->subDays(30)->format('Y-m-d'), now()->startOfDay()->format('Y-m-d')], + EmailStatement::LAST365 => [now()->startOfDay()->subDays(365)->format('Y-m-d'), now()->startOfDay()->format('Y-m-d')], + EmailStatement::THIS_MONTH => [now()->startOfDay()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->lastOfMonth()->format('Y-m-d')], + EmailStatement::LAST_MONTH => [now()->startOfDay()->subMonthNoOverflow()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->subMonthNoOverflow()->lastOfMonth()->format('Y-m-d')], + EmailStatement::THIS_QUARTER => [now()->startOfDay()->firstOfQuarter()->format('Y-m-d'), now()->startOfDay()->lastOfQuarter()->format('Y-m-d')], + EmailStatement::LAST_QUARTER => [now()->startOfDay()->subQuarterNoOverflow()->firstOfQuarter()->format('Y-m-d'), now()->startOfDay()->subQuarterNoOverflow()->lastOfQuarter()->format('Y-m-d')], + EmailStatement::THIS_YEAR => [now()->startOfDay()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->lastOfYear()->format('Y-m-d')], + EmailStatement::LAST_YEAR => [now()->startOfDay()->subYearNoOverflow()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->subYearNoOverflow()->lastOfYear()->format('Y-m-d')], + EmailStatement::CUSTOM_RANGE => [$this->scheduler->parameters['start_date'], $this->scheduler->parameters['end_date']], + default => [now()->startOfDay()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->lastOfMonth()->format('Y-m-d')], +>>>>>>> 63a7a1185 (Minor fixes for types) }; } diff --git a/tests/Feature/Scheduler/SchedulerTest.php b/tests/Feature/Scheduler/SchedulerTest.php index ebaebbe7a..450b4a972 100644 --- a/tests/Feature/Scheduler/SchedulerTest.php +++ b/tests/Feature/Scheduler/SchedulerTest.php @@ -19,6 +19,10 @@ use App\Services\Scheduler\SchedulerService; use App\Utils\Traits\MakesHash; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Session; +use App\DataMapper\Schedule\EmailStatement; +use App\Services\Scheduler\SchedulerService; +use Illuminate\Validation\ValidationException; use Illuminate\Foundation\Testing\WithoutEvents; use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Support\Facades\Session; @@ -77,7 +81,7 @@ class SchedulerTest extends TestCase 'next_run' => now()->format('Y-m-d'), 'template' => 'client_statement', 'parameters' => [ - 'date_range' => 'previous_month', + 'date_range' => EmailStatement::LAST_MONTH, 'show_payments_table' => true, 'show_aging_table' => true, 'status' => 'paid', @@ -143,7 +147,7 @@ class SchedulerTest extends TestCase 'next_run' => now()->format('Y-m-d'), 'template' => 'client_statement', 'parameters' => [ - 'date_range' => 'previous_month', + 'date_range' => EmailStatement::LAST_MONTH, 'show_payments_table' => true, 'show_aging_table' => true, 'status' => 'paid', @@ -176,7 +180,7 @@ class SchedulerTest extends TestCase 'next_run' => now()->addDay()->format('Y-m-d'), 'template' => 'client_statement', 'parameters' => [ - 'date_range' => 'previous_month', + 'date_range' => EmailStatement::LAST_MONTH, 'show_payments_table' => true, 'show_aging_table' => true, 'status' => 'paid', @@ -200,7 +204,7 @@ class SchedulerTest extends TestCase 'next_run' => now()->format('Y-m-d'), 'template' => 'client_statement', 'parameters' => [ - 'date_range' => 'previous_month', + 'date_range' => EmailStatement::LAST_MONTH, 'show_payments_table' => true, 'show_aging_table' => true, 'status' => 'paid', @@ -232,7 +236,7 @@ class SchedulerTest extends TestCase 'next_run' => now()->format('Y-m-d'), 'template' => 'client_statement', 'parameters' => [ - 'date_range' => 'previous_month', + 'date_range' => EmailStatement::LAST_MONTH, 'show_payments_table' => true, 'show_aging_table' => true, 'status' => 'paid', @@ -268,7 +272,7 @@ class SchedulerTest extends TestCase 'next_run' => "2023-01-01", 'template' => 'client_statement', 'parameters' => [ - 'date_range' => 'previous_month', + 'date_range' => EmailStatement::LAST_MONTH, 'show_payments_table' => true, 'show_aging_table' => true, 'status' => 'paid', @@ -287,7 +291,7 @@ class SchedulerTest extends TestCase $this->assertIsArray($method); - $this->assertEquals('previous_month', $scheduler->parameters['date_range']); + $this->assertEquals(EmailStatement::LAST_MONTH, $scheduler->parameters['date_range']); $this->assertEqualsCanonicalizing(['2022-12-01','2022-12-31'], $method); @@ -304,7 +308,7 @@ class SchedulerTest extends TestCase 'next_run' => now()->format('Y-m-d'), 'template' => 'client_statement', 'parameters' => [ - 'date_range' => 'previous_month', + 'date_range' => EmailStatement::LAST_MONTH, 'show_payments_table' => true, 'show_aging_table' => true, 'status' => 'paid', @@ -337,13 +341,13 @@ class SchedulerTest extends TestCase $this->travelTo(Carbon::parse('2023-01-14')); - $this->assertEqualsCanonicalizing(['2023-01-01','2023-01-31'], $this->getDateRange('this_month')); - $this->assertEqualsCanonicalizing(['2023-01-01','2023-03-31'], $this->getDateRange('this_quarter')); - $this->assertEqualsCanonicalizing(['2023-01-01','2023-12-31'], $this->getDateRange('this_year')); + $this->assertEqualsCanonicalizing(['2023-01-01','2023-01-31'], $this->getDateRange(EmailStatement::THIS_MONTH)); + $this->assertEqualsCanonicalizing(['2023-01-01','2023-03-31'], $this->getDateRange(EmailStatement::THIS_QUARTER)); + $this->assertEqualsCanonicalizing(['2023-01-01','2023-12-31'], $this->getDateRange(EmailStatement::THIS_YEAR)); - $this->assertEqualsCanonicalizing(['2022-12-01','2022-12-31'], $this->getDateRange('previous_month')); - $this->assertEqualsCanonicalizing(['2022-10-01','2022-12-31'], $this->getDateRange('previous_quarter')); - $this->assertEqualsCanonicalizing(['2022-01-01','2022-12-31'], $this->getDateRange('previous_year')); + $this->assertEqualsCanonicalizing(['2022-12-01','2022-12-31'], $this->getDateRange(EmailStatement::LAST_MONTH)); + $this->assertEqualsCanonicalizing(['2022-10-01','2022-12-31'], $this->getDateRange(EmailStatement::LAST_QUARTER)); + $this->assertEqualsCanonicalizing(['2022-01-01','2022-12-31'], $this->getDateRange(EmailStatement::LAST_YEAR)); $this->travelBack(); @@ -352,13 +356,17 @@ class SchedulerTest extends TestCase private function getDateRange($range) { return match ($range) { - 'this_month' => [now()->firstOfMonth()->format('Y-m-d'), now()->lastOfMonth()->format('Y-m-d')], - 'this_quarter' => [now()->firstOfQuarter()->format('Y-m-d'), now()->lastOfQuarter()->format('Y-m-d')], - 'this_year' => [now()->firstOfYear()->format('Y-m-d'), now()->lastOfYear()->format('Y-m-d')], - 'previous_month' => [now()->subMonth()->firstOfMonth()->format('Y-m-d'), now()->subMonth()->lastOfMonth()->format('Y-m-d')], - 'previous_quarter' => [now()->subQuarter()->firstOfQuarter()->format('Y-m-d'), now()->subQuarter()->lastOfQuarter()->format('Y-m-d')], - 'previous_year' => [now()->subYear()->firstOfYear()->format('Y-m-d'), now()->subYear()->lastOfYear()->format('Y-m-d')], - 'custom_range' => [$this->scheduler->parameters['start_date'], $this->scheduler->parameters['end_date']] + EmailStatement::LAST7 => [now()->startOfDay()->subDays(7)->format('Y-m-d'), now()->startOfDay()->format('Y-m-d')], + EmailStatement::LAST30 => [now()->startOfDay()->subDays(30)->format('Y-m-d'), now()->startOfDay()->format('Y-m-d')], + EmailStatement::LAST365 => [now()->startOfDay()->subDays(365)->format('Y-m-d'), now()->startOfDay()->format('Y-m-d')], + EmailStatement::THIS_MONTH => [now()->startOfDay()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->lastOfMonth()->format('Y-m-d')], + EmailStatement::LAST_MONTH => [now()->startOfDay()->subMonthNoOverflow()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->subMonthNoOverflow()->lastOfMonth()->format('Y-m-d')], + EmailStatement::THIS_QUARTER => [now()->startOfDay()->firstOfQuarter()->format('Y-m-d'), now()->startOfDay()->lastOfQuarter()->format('Y-m-d')], + EmailStatement::LAST_QUARTER => [now()->startOfDay()->subQuarterNoOverflow()->firstOfQuarter()->format('Y-m-d'), now()->startOfDay()->subQuarterNoOverflow()->lastOfQuarter()->format('Y-m-d')], + EmailStatement::THIS_YEAR => [now()->startOfDay()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->lastOfYear()->format('Y-m-d')], + EmailStatement::LAST_YEAR => [now()->startOfDay()->subYearNoOverflow()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->subYearNoOverflow()->lastOfYear()->format('Y-m-d')], + EmailStatement::CUSTOM_RANGE => [$this->scheduler->parameters['start_date'], $this->scheduler->parameters['end_date']], + default => [now()->startOfDay()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->lastOfMonth()->format('Y-m-d')], }; } @@ -370,7 +378,7 @@ class SchedulerTest extends TestCase 'next_run' => now()->format('Y-m-d'), 'template' => 'client_statement', 'parameters' => [ - 'date_range' => 'previous_month', + 'date_range' => EmailStatement::LAST_MONTH, 'show_payments_table' => true, 'show_aging_table' => true, 'status' => 'paid',