mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for exports
This commit is contained in:
parent
45f2970579
commit
642fdc7139
@ -879,10 +879,7 @@ class BaseExport
|
||||
|
||||
$transformed_clients = $this->transformKeys($clients);
|
||||
|
||||
nlog($transformed_clients);
|
||||
|
||||
if(count($transformed_clients) > 0) {
|
||||
nlog("yus");
|
||||
$query->whereIn('client_id', $transformed_clients);
|
||||
}
|
||||
|
||||
|
@ -144,18 +144,6 @@ class InvoiceExport extends BaseExport
|
||||
private function decorateAdvancedFields(Invoice $invoice, array $entity): array
|
||||
{
|
||||
|
||||
// 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);
|
||||
// }
|
||||
|
@ -23,8 +23,13 @@ class ContactDecorator implements DecoratorInterface
|
||||
$contact = $entity;
|
||||
} elseif($entity->contacts) {
|
||||
$contact = $entity->contacts()->first();
|
||||
} elseif($entity->client) {
|
||||
$contact = $entity->client->primary_contact->first() ?? $entity->client->contacts()->whereNotNull('email')->first();
|
||||
} elseif($entity->vendor) {
|
||||
$contact = $entity->vendor->primary_contact->first() ?? $entity->vendor->contacts()->whereNotNull('email')->first();
|
||||
}
|
||||
|
||||
|
||||
if($contact && method_exists($this, $key)) {
|
||||
return $this->{$key}($contact);
|
||||
} elseif($contact && ($contact->{$key} ?? false)) {
|
||||
|
@ -266,6 +266,42 @@ class ReportCsvGenerationTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function testContactProps()
|
||||
{
|
||||
Invoice::factory()->count(5)->create(
|
||||
[
|
||||
'client_id'=> $this->client->id,
|
||||
'company_id' => $this->company->id,
|
||||
'user_id' => $this->user->id
|
||||
]
|
||||
);
|
||||
|
||||
$data = [
|
||||
'date_range' => 'all',
|
||||
'report_keys' => ['invoice.number','client.name', 'contact.email'],
|
||||
'send_email' => false,
|
||||
'client_id' => $this->client->hashed_id
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/reports/invoices', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$hash = $arr['message'];
|
||||
|
||||
$response = $this->poll($hash);
|
||||
|
||||
$csv = $response->body();
|
||||
|
||||
$this->assertEquals('john@doe.com', $this->getFirstValueByColumn($csv, 'Contact Email'));
|
||||
|
||||
}
|
||||
|
||||
public function testForcedInsertionOfMandatoryColumns()
|
||||
{
|
||||
$forced = ['client.name'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user