mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for Product Sales Reports
This commit is contained in:
parent
ee837b7cdd
commit
c90d930f89
@ -39,10 +39,10 @@ class BaseExport
|
|||||||
return $query->where('client_id', $this->input['client_id']);
|
return $query->where('client_id', $this->input['client_id']);
|
||||||
}
|
}
|
||||||
elseif(isset($this->input['clients']) && count($this->input['clients']) > 0) {
|
elseif(isset($this->input['clients']) && count($this->input['clients']) > 0) {
|
||||||
|
|
||||||
$this->client_description = 'Multiple Clients';
|
$this->client_description = 'Multiple Clients';
|
||||||
return $query->whereIn('client_id', $this->input['clients']);
|
return $query->whereIn('client_id', $this->input['clients']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,8 +97,6 @@ class ProductSalesExport extends BaseExport
|
|||||||
}
|
}
|
||||||
|
|
||||||
//insert the header
|
//insert the header
|
||||||
$this->csv->insertOne($this->buildHeader());
|
|
||||||
|
|
||||||
$query = Invoice::query()
|
$query = Invoice::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
@ -109,6 +107,8 @@ class ProductSalesExport extends BaseExport
|
|||||||
|
|
||||||
$query = $this->filterByClients($query);
|
$query = $this->filterByClients($query);
|
||||||
|
|
||||||
|
$this->csv->insertOne($this->buildHeader());
|
||||||
|
|
||||||
$query->cursor()
|
$query->cursor()
|
||||||
->each(function ($invoice) {
|
->each(function ($invoice) {
|
||||||
foreach ($invoice->line_items as $item) {
|
foreach ($invoice->line_items as $item) {
|
||||||
|
@ -28,7 +28,8 @@ class BlackListRule implements Rule
|
|||||||
'dataservices.space',
|
'dataservices.space',
|
||||||
'karenkey.com',
|
'karenkey.com',
|
||||||
'sharklasers.com',
|
'sharklasers.com',
|
||||||
'100072641.help'
|
'100072641.help',
|
||||||
|
'yandex.com',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,10 +42,6 @@ class EmailProductSalesReport
|
|||||||
$start_end_dates = $this->calculateStartAndEndDates();
|
$start_end_dates = $this->calculateStartAndEndDates();
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
if (count($this->scheduler->parameters['clients']) >= 1) {
|
|
||||||
$data['clients'] = $this->transformKeys($this->scheduler->parameters['clients']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'start_date' => $start_end_dates[0],
|
'start_date' => $start_end_dates[0],
|
||||||
'end_date' => $start_end_dates[1],
|
'end_date' => $start_end_dates[1],
|
||||||
@ -54,6 +50,10 @@ class EmailProductSalesReport
|
|||||||
'report_keys' => []
|
'report_keys' => []
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (count($this->scheduler->parameters['clients']) >= 1) {
|
||||||
|
$data['clients'] = $this->transformKeys($this->scheduler->parameters['clients']);
|
||||||
|
}
|
||||||
|
|
||||||
$export = (new ProductSalesExport($this->scheduler->company, $data));
|
$export = (new ProductSalesExport($this->scheduler->company, $data));
|
||||||
$csv = $export->run();
|
$csv = $export->run();
|
||||||
|
|
||||||
|
@ -22,11 +22,11 @@ use App\Factory\SchedulerFactory;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use App\DataMapper\Schedule\EmailStatement;
|
use App\DataMapper\Schedule\EmailStatement;
|
||||||
use App\Services\Scheduler\SchedulerService;
|
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||||
use App\Services\Scheduler\EmailStatementService;
|
use App\Services\Scheduler\EmailStatementService;
|
||||||
use App\Services\Scheduler\EmailProductSalesReport;
|
use App\Services\Scheduler\EmailProductSalesReport;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,6 +38,7 @@ class SchedulerTest extends TestCase
|
|||||||
use MakesHash;
|
use MakesHash;
|
||||||
use MockAccountData;
|
use MockAccountData;
|
||||||
use WithoutEvents;
|
use WithoutEvents;
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
@ -58,6 +59,97 @@ class SchedulerTest extends TestCase
|
|||||||
// $this->withoutExceptionHandling();
|
// $this->withoutExceptionHandling();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProductSalesReportGenerationOneClientSeparateParam()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'name' => 'A test product sales scheduler',
|
||||||
|
'frequency_id' => RecurringInvoice::FREQUENCY_MONTHLY,
|
||||||
|
'next_run' => now()->format('Y-m-d'),
|
||||||
|
'template' => 'email_product_sales_report',
|
||||||
|
'parameters' => [
|
||||||
|
'date_range' => EmailStatement::LAST_MONTH,
|
||||||
|
'clients' => [],
|
||||||
|
'report_keys' => [],
|
||||||
|
'client_id' => $this->client->hashed_id,
|
||||||
|
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/task_schedulers', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
catch(\Exception $e){
|
||||||
|
nlog($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$id = $this->decodePrimaryKey($arr['data']['id']);
|
||||||
|
$scheduler = Scheduler::find($id);
|
||||||
|
$user = $scheduler->user;
|
||||||
|
$user->email = "{rand(5,555555}@gmail.com";
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$this->assertNotNull($scheduler);
|
||||||
|
|
||||||
|
$export = (new EmailProductSalesReport($scheduler))->run();
|
||||||
|
|
||||||
|
$this->assertEquals(now()->addMonth()->format('Y-m-d'), $scheduler->next_run->format('Y-m-d'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProductSalesReportGenerationOneClient()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'name' => 'A test product sales scheduler',
|
||||||
|
'frequency_id' => RecurringInvoice::FREQUENCY_MONTHLY,
|
||||||
|
'next_run' => now()->format('Y-m-d'),
|
||||||
|
'template' => 'email_product_sales_report',
|
||||||
|
'parameters' => [
|
||||||
|
'date_range' => EmailStatement::LAST_MONTH,
|
||||||
|
'clients' => [$this->client->hashed_id],
|
||||||
|
'report_keys' => [],
|
||||||
|
'client_id' => null,
|
||||||
|
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/task_schedulers', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
catch(\Exception $e){
|
||||||
|
nlog($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$id = $this->decodePrimaryKey($arr['data']['id']);
|
||||||
|
$scheduler = Scheduler::find($id);
|
||||||
|
$user = $scheduler->user;
|
||||||
|
$user->email = "{rand(5,555555}@gmail.com";
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$this->assertNotNull($scheduler);
|
||||||
|
|
||||||
|
$export = (new EmailProductSalesReport($scheduler))->run();
|
||||||
|
|
||||||
|
$this->assertEquals(now()->addMonth()->format('Y-m-d'), $scheduler->next_run->format('Y-m-d'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testProductSalesReportGeneration()
|
public function testProductSalesReportGeneration()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user