mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #8732 from turbo124/v5-develop
Fixes for report previews
This commit is contained in:
commit
8e5772e3c1
@ -839,7 +839,7 @@ class BaseExport
|
||||
foreach (array_merge($this->input['report_keys'], $this->forced_keys) as $value) {
|
||||
|
||||
$key = array_search($value, $this->entity_keys);
|
||||
|
||||
nlog("{$key} => {$value}");
|
||||
$prefix = '';
|
||||
|
||||
if(!$key) {
|
||||
@ -862,7 +862,6 @@ class BaseExport
|
||||
$key = array_search($value, $this->payment_report_keys);
|
||||
}
|
||||
|
||||
|
||||
if(!$key) {
|
||||
$prefix = ctrans('texts.quote')." ";
|
||||
$key = array_search($value, $this->quote_report_keys);
|
||||
@ -914,7 +913,7 @@ class BaseExport
|
||||
$key = str_replace('contact.', '', $key);
|
||||
$key = str_replace('payment.', '', $key);
|
||||
$key = str_replace('expense.', '', $key);
|
||||
|
||||
// nlog($key);
|
||||
if(in_array($key, ['quote1','quote2','quote3','quote4','credit1','credit2','credit3','credit4','purchase_order1','purchase_order2','purchase_order3','purchase_order4']))
|
||||
{
|
||||
$number = substr($key, -1);
|
||||
|
@ -34,11 +34,12 @@ class CreditExport extends BaseExport
|
||||
'amount' => 'amount',
|
||||
'balance' => 'balance',
|
||||
'client' => 'client_id',
|
||||
'country' => 'country_id',
|
||||
'custom_surcharge1' => 'custom_surcharge1',
|
||||
'custom_surcharge2' => 'custom_surcharge2',
|
||||
'custom_surcharge3' => 'custom_surcharge3',
|
||||
'custom_surcharge4' => 'custom_surcharge4',
|
||||
'country' => 'country_id',
|
||||
'currency' => 'currency',
|
||||
'custom_value1' => 'custom_value1',
|
||||
'custom_value2' => 'custom_value2',
|
||||
'custom_value3' => 'custom_value3',
|
||||
@ -65,7 +66,6 @@ class CreditExport extends BaseExport
|
||||
'tax_rate3' => 'tax_rate3',
|
||||
'terms' => 'terms',
|
||||
'total_taxes' => 'total_taxes',
|
||||
'currency' => 'currency',
|
||||
];
|
||||
|
||||
private array $decorate_keys = [
|
||||
@ -106,12 +106,14 @@ class CreditExport extends BaseExport
|
||||
$report_keys = explode(".", $value);
|
||||
|
||||
$column_key = str_replace("credit.", "", $value);
|
||||
$column_key = array_search($column_key, $this->entity_keys);
|
||||
|
||||
$clean_row[$key]['entity'] = $report_keys[0];
|
||||
$clean_row[$key]['id'] = $report_keys[1];
|
||||
$clean_row[$key]['id'] = $report_keys[1] ?? $report_keys[0];
|
||||
$clean_row[$key]['hashed_id'] = $report_keys[0] == 'credit' ? null : $credit->{$report_keys[0]}->hashed_id ?? null;
|
||||
$clean_row[$key]['value'] = $row[$column_key];
|
||||
|
||||
if(in_array($report_keys[1], ['amount', 'balance', 'partial', 'refunded', 'applied','unit_cost','cost','price']))
|
||||
if(in_array($clean_row[$key]['id'], ['amount', 'balance', 'partial', 'refunded', 'applied','unit_cost','cost','price']))
|
||||
$clean_row[$key]['display_value'] = Number::formatMoney($row[$column_key], $credit->client);
|
||||
else
|
||||
$clean_row[$key]['display_value'] = $row[$column_key];
|
||||
@ -131,10 +133,14 @@ class CreditExport extends BaseExport
|
||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||
|
||||
if (count($this->input['report_keys']) == 0) {
|
||||
$this->input['report_keys'] = array_values($this->entity_keys);
|
||||
// $this->input['report_keys'] = collect(array_values($this->entity_keys))->map(function ($value){
|
||||
|
||||
$this->input['report_keys'] = collect(array_values($this->entity_keys))->map(function ($value){
|
||||
return 'credit.'.$value;
|
||||
})->toArray();
|
||||
// // if(in_array($value,['client_id','country_id']))
|
||||
// // return $value;
|
||||
// // else
|
||||
// return 'credit.'.$value;
|
||||
// })->toArray();
|
||||
|
||||
}
|
||||
|
||||
@ -156,11 +162,11 @@ class CreditExport extends BaseExport
|
||||
|
||||
//insert the header
|
||||
$this->csv->insertOne($this->buildHeader());
|
||||
// nlog($this->input['report_keys']);
|
||||
// nlog($this->input['report_keys']);
|
||||
|
||||
$query->cursor()
|
||||
->each(function ($credit) {
|
||||
nlog($this->buildRow($credit));
|
||||
// nlog($this->buildRow($credit));
|
||||
$this->csv->insertOne($this->buildRow($credit));
|
||||
});
|
||||
|
||||
|
@ -40,7 +40,7 @@ class PreviewReport implements ShouldQueue
|
||||
$export = new $this->report_class($this->company, $this->request);
|
||||
$report = $export->returnJson();
|
||||
|
||||
nlog($report);
|
||||
// nlog($report);
|
||||
Cache::put($this->hash, $report, 60 * 60);
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,47 @@ class ReportCsvGenerationTest extends TestCase
|
||||
|
||||
public $cu;
|
||||
|
||||
private $all_client_report_keys = ["client.name","client.user","client.assigned_user","client.balance","client.paid_to_date","client.currency_id","client.website","client.private_notes","client.industry_id","client.size_id","client.address1","client.address2","client.city","client.state","client.postal_code","client.country_id","contact.custom_value4","client.shipping_address1","client.shipping_address2","client.shipping_city","client.shipping_state","client.shipping_postal_code","client.shipping_country_id","client.payment_terms","client.vat_number","client.id_number","client.public_notes","client.phone","contact.first_name","contact.last_name","contact.email","contact.phone"];
|
||||
private $all_client_report_keys = [
|
||||
"client.name",
|
||||
"client.user",
|
||||
"client.assigned_user",
|
||||
"client.balance",
|
||||
"client.address1",
|
||||
"client.address2",
|
||||
"client.city",
|
||||
"client.country_id",
|
||||
"client.currency_id",
|
||||
"client.custom_value1",
|
||||
"client.custom_value2",
|
||||
"client.custom_value3",
|
||||
"client.custom_value4",
|
||||
"client.industry_id",
|
||||
"client.id_number",
|
||||
"client.paid_to_date",
|
||||
"client.payment_terms",
|
||||
"client.phone",
|
||||
"client.postal_code",
|
||||
"client.private_notes",
|
||||
"client.public_notes",
|
||||
"client.size_id",
|
||||
"client.shipping_address1",
|
||||
"client.shipping_address2",
|
||||
"client.shipping_city",
|
||||
"client.shipping_state",
|
||||
"client.shipping_postal_code",
|
||||
"client.shipping_country_id",
|
||||
"client.state",
|
||||
"client.vat_number",
|
||||
"client.website",
|
||||
"contact.first_name",
|
||||
"contact.last_name",
|
||||
"contact.email",
|
||||
"contact.phone",
|
||||
"contact.custom_value1",
|
||||
"contact.custom_value2",
|
||||
"contact.custom_value3",
|
||||
"contact.custom_value4",
|
||||
];
|
||||
|
||||
private $all_payment_report_keys = [
|
||||
'payment.date',
|
||||
@ -1366,7 +1406,7 @@ class ReportCsvGenerationTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
|
||||
$csv = $response->streamedContent();
|
||||
|
||||
nlog($csv);
|
||||
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Amount'));
|
||||
$this->assertEquals('50', $this->getFirstValueByColumn($csv, 'Balance'));
|
||||
$this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Discount'));
|
||||
|
77
tests/Feature/Export/ReportPreviewTest.php
Normal file
77
tests/Feature/Export/ReportPreviewTest.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Export;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Tests\MockAccountData;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Export\CSV\CreditExport;
|
||||
use App\Jobs\Report\PreviewReport;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
class ReportPreviewTest extends TestCase
|
||||
{
|
||||
use MakesHash;
|
||||
use MockAccountData;
|
||||
|
||||
public $faker;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->faker = \Faker\Factory::create();
|
||||
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class
|
||||
);
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
}
|
||||
|
||||
public function testCreditExportPreview()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'send_email' => false,
|
||||
'date_range' => 'all',
|
||||
'report_keys' => [],
|
||||
];
|
||||
|
||||
$p = (new PreviewReport($this->company, $data, CreditExport::class, '123'))->handle();
|
||||
|
||||
$this->assertNull($p);
|
||||
|
||||
}
|
||||
|
||||
public function testCreditPreview()
|
||||
{
|
||||
$data = [
|
||||
'send_email' => false,
|
||||
'date_range' => 'all',
|
||||
'report_keys' => [],
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/reports/credits?output=json', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user