mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Tests for calculating date ranges
This commit is contained in:
parent
ada6210e34
commit
cf9ffb05d5
@ -59,7 +59,6 @@ class ClientStatement
|
||||
*/
|
||||
public string $start_date = '';
|
||||
|
||||
|
||||
/**
|
||||
* If a custom range is select for the date range then
|
||||
* the end_date should be supplied in Y-m-d format
|
||||
@ -93,4 +92,5 @@ class ClientStatement
|
||||
*/
|
||||
public string $status = 'paid'; // paid | unpaid
|
||||
|
||||
|
||||
}
|
@ -43,50 +43,47 @@ class SchedulerService
|
||||
if(count($this->scheduler->parameters['clients']) >= 1)
|
||||
$query->where('id', $this->transformKeys($this->scheduler->parameters['clients']));
|
||||
|
||||
$statement_properties = $this->calculateStatementProperties();
|
||||
|
||||
$query->cursor()
|
||||
->each(function ($client){
|
||||
->each(function ($client) use($statement_properties){
|
||||
|
||||
//work out the date range
|
||||
$pdf = $client->service()->statement($statement_properties);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// public function scheduleStatement()
|
||||
// {
|
||||
|
||||
// //Is it for one client
|
||||
// //Is it for all clients
|
||||
// //Is it for all clients excluding these clients
|
||||
|
||||
// //Frequency
|
||||
|
||||
// //show aging
|
||||
// //show payments
|
||||
// //paid/unpaid
|
||||
|
||||
// //When to send? 1st of month
|
||||
// //End of month
|
||||
// //This date
|
||||
|
||||
// }
|
||||
|
||||
// public function scheduleReport()
|
||||
// {
|
||||
// //Report type
|
||||
// //same schema as ScheduleStatement
|
||||
// }
|
||||
|
||||
// public function scheduleEntitySend()
|
||||
// {
|
||||
// //Entity
|
||||
// //Entity Id
|
||||
// //When
|
||||
// }
|
||||
|
||||
// public function projectStatus()
|
||||
// {
|
||||
// //Project ID
|
||||
// //Tasks - task statuses
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private function calculateStatementProperties()
|
||||
{
|
||||
$start_end = $this->calculateStartAndEndDates();
|
||||
|
||||
return [
|
||||
'start_date' =>$start_end[0],
|
||||
'end_date' =>$start_end[1],
|
||||
'show_payments_table' => $this->scheduler->parameters['show_payments_table'],
|
||||
'show_aging_table' => $this->scheduler->parameters['show_aging_table'],
|
||||
'status' => $this->scheduler->status
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
private function calculateStartAndEndDates()
|
||||
{
|
||||
return match ($this->scheduler->parameters['date_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()->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()->format('Y-m-d')],
|
||||
'custom_range' => [$this->scheduler->parameters['start_date'], $this->scheduler->parameters['end_date']]
|
||||
};
|
||||
}
|
||||
|
||||
private function thisMonth()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -31,7 +31,6 @@ class SchedulerTest extends TestCase
|
||||
use MakesHash;
|
||||
use MockAccountData;
|
||||
use WithoutEvents;
|
||||
// use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
@ -52,6 +51,37 @@ class SchedulerTest extends TestCase
|
||||
$this->withoutExceptionHandling();
|
||||
}
|
||||
|
||||
|
||||
public function testGetThisMonthRange()
|
||||
{
|
||||
|
||||
$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(['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->travelBack();
|
||||
|
||||
}
|
||||
|
||||
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']]
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 'name' => ['bail', 'required', Rule::unique('schedulers')->where('company_id', auth()->user()->company()->id)],
|
||||
'is_paused' => 'bail|sometimes|boolean',
|
||||
@ -66,7 +96,7 @@ class SchedulerTest extends TestCase
|
||||
$data = [
|
||||
'name' => 'A test statement scheduler',
|
||||
'frequency_id' => RecurringInvoice::FREQUENCY_MONTHLY,
|
||||
'next_run' => '2023-01-31',
|
||||
'next_run' => '2023-01-14',
|
||||
'template' => 'client_statement',
|
||||
'clients' => [],
|
||||
'parameters' => [
|
||||
|
@ -42,4 +42,5 @@ class RecurringDateTest extends TestCase
|
||||
|
||||
$this->assertequals($trial_ends->format('Y-m-d'), '2021-12-03');
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user