Vendor custom columns

This commit is contained in:
David Bomba 2023-07-18 18:30:13 +10:00
parent a2b0a13c1f
commit 3b9c82d456
2 changed files with 93 additions and 2 deletions

View File

@ -114,7 +114,7 @@ class VendorExport extends BaseExport
private function buildRow(Vendor $vendor) :array private function buildRow(Vendor $vendor) :array
{ {
$transformed_contact = false; $transformed_contact = [];
$transformed_vendor = $this->vendor_transformer->transform($vendor); $transformed_vendor = $this->vendor_transformer->transform($vendor);

View File

@ -165,9 +165,100 @@ class ReportCsvGenerationTest extends TestCase
} }
public function testTaskCustomColumnsCsvGeneration() public function testVendorCsvGeneration()
{ {
$vendor =
\App\Models\Vendor::factory()->create(
[
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'name' => 'Vendor 1',
'city' => 'city',
'address1' => 'address1',
'address2' => 'address2',
'postal_code' => 'postal_code',
'phone' => 'work_phone',
'private_notes' => 'private_notes',
'public_notes' => 'public_notes',
'website' => 'website',
'number' => '1234',
]
);
$data = [
'date_range' => 'all',
'report_keys' => [],
// 'report_keys' => ["vendor.name","purchase_order.number","purchase_order.amount", "item.quantity", "item.cost", "item.line_total", "item.discount", "item.notes", "item.product_key", "item.custom_value1", "item.tax_name1", "item.tax_rate1",],
'send_email' => false,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/vendors', $data);
$csv = $response->streamedContent();
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Number'));
$this->assertEquals('city', $this->getFirstValueByColumn($csv, 'City'));
$this->assertEquals('address1', $this->getFirstValueByColumn($csv, 'Street'));
$this->assertEquals('address2', $this->getFirstValueByColumn($csv, 'Apt/Suite'));
$this->assertEquals('postal_code', $this->getFirstValueByColumn($csv, 'Postal Code'));
$this->assertEquals('work_phone', $this->getFirstValueByColumn($csv, 'Phone'));
$this->assertEquals('private_notes', $this->getFirstValueByColumn($csv, 'Private Notes'));
$this->assertEquals('public_notes', $this->getFirstValueByColumn($csv, 'Public Notes'));
$this->assertEquals('website', $this->getFirstValueByColumn($csv, 'Website'));
}
public function testVendorCustomColumnCsvGeneration()
{
\App\Models\Vendor::query()->cursor()->each(function ($t) {
$t->forceDelete();
});
$vendor =
\App\Models\Vendor::factory()->create(
[
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'name' => 'Vendor 1',
'city' => 'city',
'address1' => 'address1',
'address2' => 'address2',
'postal_code' => 'postal_code',
'phone' => 'work_phone',
'private_notes' => 'private_notes',
'public_notes' => 'public_notes',
'website' => 'website',
'number' => '1234',
]
);
$data = [
'date_range' => 'all',
'report_keys' => ["vendor.name", "vendor.city", "vendor.number"],
'send_email' => false,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/vendors', $data);
$csv = $response->streamedContent();
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Number'));
$this->assertEquals('city', $this->getFirstValueByColumn($csv, 'City'));
}
public function testTaskCustomColumnsCsvGeneration()
{
$invoice = \App\Models\Invoice::factory()->create([ $invoice = \App\Models\Invoice::factory()->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,