diff --git a/app/Export/CSV/ClientExport.php b/app/Export/CSV/ClientExport.php index bcf93bf5897f..7d645c78b410 100644 --- a/app/Export/CSV/ClientExport.php +++ b/app/Export/CSV/ClientExport.php @@ -172,8 +172,8 @@ class ClientExport extends BaseExport $entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : ''; } - if (in_array('client.currency', $this->input['report_keys'])) { - $entity['currency'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code; + if (in_array('client.currency_id', $this->input['report_keys'])) { + $entity['client.currency_id'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code; } if (in_array('client.industry_id', $this->input['report_keys'])) { diff --git a/tests/Feature/Export/ReportCsvGenerationTest.php b/tests/Feature/Export/ReportCsvGenerationTest.php index e980d459179a..3f074cf922f1 100644 --- a/tests/Feature/Export/ReportCsvGenerationTest.php +++ b/tests/Feature/Export/ReportCsvGenerationTest.php @@ -143,10 +143,13 @@ class ReportCsvGenerationTest extends TestCase $this->client = Client::factory()->create([ 'user_id' => $this->user->id, + // 'assigned_user_id', $this->user->id, 'company_id' => $this->company->id, 'is_deleted' => 0, 'name' => 'bob', - 'address1' => '1234' + 'address1' => '1234', + 'balance' => 100, + 'paid_to_date' => 50, ]); ClientContact::factory()->create([ @@ -307,6 +310,35 @@ class ReportCsvGenerationTest extends TestCase } + public function testClientCustomColumnsCsvGeneration() + { + + $data = [ + 'date_range' => 'all', + 'report_keys' => ["client.name","client.user","client.assigned_user","client.balance","client.paid_to_date","client.currency_id"], + 'send_email' => false, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/reports/clients', $data); + + $csv = $response->streamedContent(); + + $this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Name')); + $this->assertEquals(100, $this->getFirstValueByColumn($csv, 'Balance')); + $this->assertEquals(50, $this->getFirstValueByColumn($csv, 'Paid to Date')); + $this->assertEquals($this->user->present()->name(), $this->getFirstValueByColumn($csv, 'Client User')); + $this->assertEquals('', $this->getFirstValueByColumn($csv, 'Client Assigned User')); + $this->assertEquals('USD', $this->getFirstValueByColumn($csv, 'Client Currency')); + + } + + + + + public function testClientContactCsvGeneration() {