mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 10:34:30 -04:00
Fixes for report exports
This commit is contained in:
parent
d62bdbedcb
commit
1163c42fd8
@ -231,7 +231,7 @@ class BaseExport
|
|||||||
'po_number' => 'purchase_order.po_number',
|
'po_number' => 'purchase_order.po_number',
|
||||||
'private_notes' => 'purchase_order.private_notes',
|
'private_notes' => 'purchase_order.private_notes',
|
||||||
'public_notes' => 'purchase_order.public_notes',
|
'public_notes' => 'purchase_order.public_notes',
|
||||||
'status' => 'purchase_order.status_id',
|
'status' => 'purchase_order.status',
|
||||||
'tax_name1' => 'purchase_order.tax_name1',
|
'tax_name1' => 'purchase_order.tax_name1',
|
||||||
'tax_name2' => 'purchase_order.tax_name2',
|
'tax_name2' => 'purchase_order.tax_name2',
|
||||||
'tax_name3' => 'purchase_order.tax_name3',
|
'tax_name3' => 'purchase_order.tax_name3',
|
||||||
@ -430,6 +430,14 @@ class BaseExport
|
|||||||
'project' => 'task.project_id',
|
'project' => 'task.project_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected array $forced_client_fields = [
|
||||||
|
"name" => "client.name",
|
||||||
|
];
|
||||||
|
|
||||||
|
protected array $forced_vendor_fields = [
|
||||||
|
"name" => "vendor.name",
|
||||||
|
];
|
||||||
|
|
||||||
protected function filterByClients($query)
|
protected function filterByClients($query)
|
||||||
{
|
{
|
||||||
if (isset($this->input['client_id']) && $this->input['client_id'] != 'all') {
|
if (isset($this->input['client_id']) && $this->input['client_id'] != 'all') {
|
||||||
|
@ -93,6 +93,8 @@ class CreditExport extends BaseExport
|
|||||||
$this->input['report_keys'] = array_values($this->credit_report_keys);
|
$this->input['report_keys'] = array_values($this->credit_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], array_diff($this->forced_client_fields, $this->input['report_keys']));
|
||||||
|
|
||||||
$query = Credit::query()
|
$query = Credit::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('client')
|
->with('client')
|
||||||
|
@ -50,6 +50,8 @@ class InvoiceExport extends BaseExport
|
|||||||
$this->input['report_keys'] = array_values($this->invoice_report_keys);
|
$this->input['report_keys'] = array_values($this->invoice_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], array_diff($this->forced_client_fields, $this->input['report_keys']));
|
||||||
|
|
||||||
$query = Invoice::query()
|
$query = Invoice::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('client')
|
->with('client')
|
||||||
|
@ -62,6 +62,8 @@ class InvoiceItemExport extends BaseExport
|
|||||||
$this->input['report_keys'] = array_values($this->mergeItemsKeys('invoice_report_keys'));
|
$this->input['report_keys'] = array_values($this->mergeItemsKeys('invoice_report_keys'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], array_diff($this->forced_client_fields, $this->input['report_keys']));
|
||||||
|
|
||||||
$query = Invoice::query()
|
$query = Invoice::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('client')
|
->with('client')
|
||||||
@ -200,6 +202,27 @@ class InvoiceItemExport extends BaseExport
|
|||||||
$entity['tax_category'] = $invoice->taxTypeString($entity['tax_category']);
|
$entity['tax_category'] = $invoice->taxTypeString($entity['tax_category']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in_array('invoice.country_id', $this->input['report_keys'])) {
|
||||||
|
$entity['invoice.country_id'] = $invoice->client->country ? ctrans("texts.country_{$invoice->client->country->name}") : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array('invoice.currency_id', $this->input['report_keys'])) {
|
||||||
|
$entity['invoice.currency_id'] = $invoice->client->currency() ? $invoice->client->currency()->code : $invoice->company->currency()->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array('invoice.client_id', $this->input['report_keys'])) {
|
||||||
|
$entity['invoice.client_id'] = $invoice->client->present()->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array('invoice.status', $this->input['report_keys'])) {
|
||||||
|
$entity['invoice.status'] = $invoice->stringStatus($invoice->status_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array('invoice.recurring_id', $this->input['report_keys'])) {
|
||||||
|
$entity['invoice.recurring_id'] = $invoice->recurring_invoice->number ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@ class PaymentExport extends BaseExport
|
|||||||
$this->input['report_keys'] = array_values($this->payment_report_keys);
|
$this->input['report_keys'] = array_values($this->payment_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], array_diff($this->forced_client_fields, $this->input['report_keys']));
|
||||||
|
|
||||||
$query = Payment::query()
|
$query = Payment::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
|
@ -54,7 +54,7 @@ class PurchaseOrderExport extends BaseExport
|
|||||||
'po_number' => 'purchase_order.po_number',
|
'po_number' => 'purchase_order.po_number',
|
||||||
'private_notes' => 'purchase_order.private_notes',
|
'private_notes' => 'purchase_order.private_notes',
|
||||||
'public_notes' => 'purchase_order.public_notes',
|
'public_notes' => 'purchase_order.public_notes',
|
||||||
'status' => 'purchase_order.status_id',
|
'status' => 'purchase_order.status',
|
||||||
'tax_name1' => 'purchase_order.tax_name1',
|
'tax_name1' => 'purchase_order.tax_name1',
|
||||||
'tax_name2' => 'purchase_order.tax_name2',
|
'tax_name2' => 'purchase_order.tax_name2',
|
||||||
'tax_name3' => 'purchase_order.tax_name3',
|
'tax_name3' => 'purchase_order.tax_name3',
|
||||||
@ -95,6 +95,9 @@ class PurchaseOrderExport extends BaseExport
|
|||||||
if (count($this->input['report_keys']) == 0) {
|
if (count($this->input['report_keys']) == 0) {
|
||||||
$this->input['report_keys'] = array_values($this->purchase_order_report_keys);
|
$this->input['report_keys'] = array_values($this->purchase_order_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], array_diff($this->forced_vendor_fields, $this->input['report_keys']));
|
||||||
|
|
||||||
$query = PurchaseOrder::query()
|
$query = PurchaseOrder::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('vendor')
|
->with('vendor')
|
||||||
@ -181,8 +184,8 @@ class PurchaseOrderExport extends BaseExport
|
|||||||
$entity['vendor'] = $purchase_order->vendor->present()->name();
|
$entity['vendor'] = $purchase_order->vendor->present()->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array('status_id', $this->input['report_keys'])) {
|
if (in_array('purchase_order.status', $this->input['report_keys'])) {
|
||||||
$entity['status'] = $purchase_order->stringStatus($purchase_order->status_id);
|
$entity['purchase_order.status'] = $purchase_order->stringStatus($purchase_order->status_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
|
@ -55,6 +55,8 @@ class PurchaseOrderItemExport extends BaseExport
|
|||||||
$this->input['report_keys'] = array_values($this->mergeItemsKeys('purchase_order_report_keys'));
|
$this->input['report_keys'] = array_values($this->mergeItemsKeys('purchase_order_report_keys'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], array_diff($this->forced_vendor_fields, $this->input['report_keys']));
|
||||||
|
|
||||||
$query = PurchaseOrder::query()
|
$query = PurchaseOrder::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('vendor')->where('company_id', $this->company->id)
|
->with('vendor')->where('company_id', $this->company->id)
|
||||||
|
@ -56,6 +56,8 @@ class QuoteExport extends BaseExport
|
|||||||
$this->input['report_keys'] = array_values($this->quote_report_keys);
|
$this->input['report_keys'] = array_values($this->quote_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], array_diff($this->forced_client_fields, $this->input['report_keys']));
|
||||||
|
|
||||||
$query = Quote::query()
|
$query = Quote::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('client')
|
->with('client')
|
||||||
|
@ -57,6 +57,8 @@ class QuoteItemExport extends BaseExport
|
|||||||
$this->input['report_keys'] = array_values($this->mergeItemsKeys('quote_report_keys'));
|
$this->input['report_keys'] = array_values($this->mergeItemsKeys('quote_report_keys'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], array_diff($this->forced_client_fields, $this->input['report_keys']));
|
||||||
|
|
||||||
$query = Quote::query()
|
$query = Quote::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('client')->where('company_id', $this->company->id)
|
->with('client')->where('company_id', $this->company->id)
|
||||||
|
@ -48,6 +48,8 @@ class RecurringInvoiceExport extends BaseExport
|
|||||||
$this->input['report_keys'] = array_values($this->recurring_invoice_report_keys);
|
$this->input['report_keys'] = array_values($this->recurring_invoice_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], array_diff($this->forced_client_fields, $this->input['report_keys']));
|
||||||
|
|
||||||
$query = RecurringInvoice::query()
|
$query = RecurringInvoice::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->with('client')
|
->with('client')
|
||||||
@ -135,8 +137,8 @@ class RecurringInvoiceExport extends BaseExport
|
|||||||
$entity['client'] = $invoice->client->present()->name();
|
$entity['client'] = $invoice->client->present()->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array('status_id', $this->input['report_keys'])) {
|
if (in_array('recurring_invoice.status', $this->input['report_keys'])) {
|
||||||
$entity['status'] = $invoice->stringStatus($invoice->status_id);
|
$entity['recurring_invoice.status'] = $invoice->stringStatus($invoice->status_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array('project_id', $this->input['report_keys'])) {
|
if (in_array('project_id', $this->input['report_keys'])) {
|
||||||
|
@ -60,6 +60,8 @@ class TaskExport extends BaseExport
|
|||||||
$this->input['report_keys'] = array_values($this->task_report_keys);
|
$this->input['report_keys'] = array_values($this->task_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], array_diff($this->forced_client_fields, $this->input['report_keys']));
|
||||||
|
|
||||||
$query = Task::query()
|
$query = Task::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
|
@ -20,7 +20,6 @@ use App\Models\Account;
|
|||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use Tests\MockAccountData;
|
|
||||||
use App\Models\CompanyToken;
|
use App\Models\CompanyToken;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
use App\Export\CSV\TaskExport;
|
use App\Export\CSV\TaskExport;
|
||||||
@ -30,8 +29,6 @@ use App\Export\CSV\ProductExport;
|
|||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\Export\CSV\PaymentExport;
|
use App\Export\CSV\PaymentExport;
|
||||||
use App\Factory\CompanyUserFactory;
|
use App\Factory\CompanyUserFactory;
|
||||||
use App\Factory\InvoiceItemFactory;
|
|
||||||
use App\Services\Report\ARDetailReport;
|
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,6 +259,21 @@ class ReportCsvGenerationTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testForcedInsertionOfMandatoryColumns()
|
||||||
|
{
|
||||||
|
$forced = ['client.name'];
|
||||||
|
|
||||||
|
$report_keys = ['invoice.number','client.name', 'invoice.amount'];
|
||||||
|
$array = array_merge($report_keys, array_diff($forced, $report_keys));
|
||||||
|
|
||||||
|
$this->assertEquals('client.name', $array[1]);
|
||||||
|
|
||||||
|
$report_keys = ['invoice.number','invoice.amount'];
|
||||||
|
$array = array_merge($report_keys, array_diff($forced, $report_keys));
|
||||||
|
|
||||||
|
$this->assertEquals('client.name', $array[2]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testVendorCsvGeneration()
|
public function testVendorCsvGeneration()
|
||||||
{
|
{
|
||||||
@ -322,7 +334,7 @@ class ReportCsvGenerationTest extends TestCase
|
|||||||
$data = $export->returnJson();
|
$data = $export->returnJson();
|
||||||
|
|
||||||
$this->assertNotNull($data);
|
$this->assertNotNull($data);
|
||||||
// nlog($data);
|
// nlog($data);
|
||||||
// $this->assertEquals(0, $this->traverseJson($data, 'columns.0.identifier'));
|
// $this->assertEquals(0, $this->traverseJson($data, 'columns.0.identifier'));
|
||||||
$this->assertEquals('Vendor Name', $this->traverseJson($data, 'columns.9.display_value'));
|
$this->assertEquals('Vendor Name', $this->traverseJson($data, 'columns.9.display_value'));
|
||||||
$this->assertEquals('vendor', $this->traverseJson($data, '0.0.entity'));
|
$this->assertEquals('vendor', $this->traverseJson($data, '0.0.entity'));
|
||||||
@ -1021,6 +1033,44 @@ class ReportCsvGenerationTest extends TestCase
|
|||||||
'X-API-TOKEN' => $this->token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/reports/recurring_invoices', $data)->assertStatus(200);
|
])->post('/api/v1/reports/recurring_invoices', $data)->assertStatus(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testRecurringInvoiceColumnsCsvGeneration()
|
||||||
|
{
|
||||||
|
|
||||||
|
\App\Models\RecurringInvoice::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'client_id' => $this->client->id,
|
||||||
|
'amount' => 100,
|
||||||
|
'balance' => 50,
|
||||||
|
'number' => '1234',
|
||||||
|
'status_id' => 2,
|
||||||
|
'discount' => 10,
|
||||||
|
'po_number' => '1234',
|
||||||
|
'public_notes' => 'Public',
|
||||||
|
'private_notes' => 'Private',
|
||||||
|
'terms' => 'Terms',
|
||||||
|
'frequency_id' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'date_range' => 'all',
|
||||||
|
'report_keys' => [],
|
||||||
|
'send_email' => false,
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/reports/recurring_invoices', $data);
|
||||||
|
|
||||||
|
$csv = $response->streamedContent();
|
||||||
|
|
||||||
|
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Recurring Invoice Invoice Number'));
|
||||||
|
$this->assertEquals('Daily', $this->getFirstValueByColumn($csv, 'Recurring Invoice How Often'));
|
||||||
|
$this->assertEquals('Active', $this->getFirstValueByColumn($csv, 'Recurring Invoice Status'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user