mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 05:34:34 -04:00
Fixes for payment exports
This commit is contained in:
parent
c4c5547281
commit
9d55ff2d49
@ -28,39 +28,39 @@ class PaymentExport extends BaseExport
|
|||||||
|
|
||||||
public Writer $csv;
|
public Writer $csv;
|
||||||
|
|
||||||
public array $entity_keys = [
|
// public array $entity_keys = [
|
||||||
'amount' => 'amount',
|
// 'amount' => 'amount',
|
||||||
'applied' => 'applied',
|
// 'applied' => 'applied',
|
||||||
'client' => 'client_id',
|
// 'client' => 'client_id',
|
||||||
'currency' => 'currency_id',
|
// 'currency' => 'currency_id',
|
||||||
'custom_value1' => 'custom_value1',
|
// 'custom_value1' => 'custom_value1',
|
||||||
'custom_value2' => 'custom_value2',
|
// 'custom_value2' => 'custom_value2',
|
||||||
'custom_value3' => 'custom_value3',
|
// 'custom_value3' => 'custom_value3',
|
||||||
'custom_value4' => 'custom_value4',
|
// 'custom_value4' => 'custom_value4',
|
||||||
'date' => 'date',
|
// 'date' => 'date',
|
||||||
'exchange_currency' => 'exchange_currency_id',
|
// 'exchange_currency' => 'exchange_currency_id',
|
||||||
'gateway' => 'gateway_type_id',
|
// 'gateway' => 'gateway_type_id',
|
||||||
'number' => 'number',
|
// 'number' => 'number',
|
||||||
'private_notes' => 'private_notes',
|
// 'private_notes' => 'private_notes',
|
||||||
'project' => 'project_id',
|
// 'project' => 'project_id',
|
||||||
'refunded' => 'refunded',
|
// 'refunded' => 'refunded',
|
||||||
'status' => 'status_id',
|
// 'status' => 'status_id',
|
||||||
'transaction_reference' => 'transaction_reference',
|
// 'transaction_reference' => 'transaction_reference',
|
||||||
'type' => 'type_id',
|
// 'type' => 'type_id',
|
||||||
'vendor' => 'vendor_id',
|
// 'vendor' => 'vendor_id',
|
||||||
'invoices' => 'invoices',
|
// 'invoices' => 'invoices',
|
||||||
];
|
// ];
|
||||||
|
|
||||||
private array $decorate_keys = [
|
// private array $decorate_keys = [
|
||||||
'vendor',
|
// 'vendor',
|
||||||
'status',
|
// 'status',
|
||||||
'project',
|
// 'project',
|
||||||
'client',
|
// 'client',
|
||||||
'currency',
|
// 'currency',
|
||||||
'exchange_currency',
|
// 'exchange_currency',
|
||||||
'type',
|
// 'type',
|
||||||
'invoices',
|
// 'invoices',
|
||||||
];
|
// ];
|
||||||
|
|
||||||
public function __construct(Company $company, array $input)
|
public function __construct(Company $company, array $input)
|
||||||
{
|
{
|
||||||
@ -137,26 +137,17 @@ class PaymentExport extends BaseExport
|
|||||||
$entity = [];
|
$entity = [];
|
||||||
|
|
||||||
foreach (array_values($this->input['report_keys']) as $key) {
|
foreach (array_values($this->input['report_keys']) as $key) {
|
||||||
// $keyval = array_search($key, $this->entity_keys);
|
|
||||||
|
|
||||||
$parts = explode('.', $key);
|
$parts = explode('.', $key);
|
||||||
|
|
||||||
// if(!$keyval) {
|
if (is_array($parts) && $parts[0] == 'payment' && array_key_exists($parts[1], $transformed_entity)) {
|
||||||
// $keyval = array_search(str_replace("payment.", "", $key), $this->entity_keys) ?? $key;
|
$entity[$key] = $transformed_entity[$parts[1]];
|
||||||
// }
|
} elseif (array_key_exists($key, $transformed_entity)) {
|
||||||
|
$entity[$key] = $transformed_entity[$key];
|
||||||
// if(!$keyval) {
|
} else {
|
||||||
// $keyval = $key;
|
$entity[$key] = $this->resolveKey($key, $payment, $this->entity_transformer);
|
||||||
// }
|
|
||||||
|
|
||||||
if (array_key_exists($key, $transformed_entity)) {
|
|
||||||
$entity[$keyval] = $transformed_entity[$key];
|
|
||||||
} elseif (array_key_exists($keyval, $transformed_entity)) {
|
|
||||||
$entity[$keyval] = $transformed_entity[$keyval];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$entity[$keyval] = $this->resolveKey($keyval, $payment, $this->entity_transformer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->decorateAdvancedFields($payment, $entity);
|
return $this->decorateAdvancedFields($payment, $entity);
|
||||||
|
@ -11,13 +11,14 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Reports;
|
namespace App\Http\Controllers\Reports;
|
||||||
|
|
||||||
|
use App\Models\Client;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Jobs\Report\SendToAdmin;
|
||||||
use App\Export\CSV\ExpenseExport;
|
use App\Export\CSV\ExpenseExport;
|
||||||
|
use App\Jobs\Report\PreviewReport;
|
||||||
use App\Http\Controllers\BaseController;
|
use App\Http\Controllers\BaseController;
|
||||||
use App\Http\Requests\Report\GenericReportRequest;
|
use App\Http\Requests\Report\GenericReportRequest;
|
||||||
use App\Jobs\Report\SendToAdmin;
|
|
||||||
use App\Models\Client;
|
|
||||||
use App\Utils\Traits\MakesHash;
|
|
||||||
use Illuminate\Http\Response;
|
|
||||||
|
|
||||||
class ExpenseReportController extends BaseController
|
class ExpenseReportController extends BaseController
|
||||||
{
|
{
|
||||||
@ -63,14 +64,27 @@ class ExpenseReportController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function __invoke(GenericReportRequest $request)
|
public function __invoke(GenericReportRequest $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
if ($request->has('send_email') && $request->get('send_email')) {
|
if ($request->has('send_email') && $request->get('send_email')) {
|
||||||
SendToAdmin::dispatch(auth()->user()->company(), $request->all(), ExpenseExport::class, $this->filename);
|
SendToAdmin::dispatch($user->company(), $request->all(), ExpenseExport::class, $this->filename);
|
||||||
|
|
||||||
return response()->json(['message' => 'working...'], 200);
|
return response()->json(['message' => 'working...'], 200);
|
||||||
}
|
}
|
||||||
// expect a list of visible fields, or use the default
|
// expect a list of visible fields, or use the default
|
||||||
|
|
||||||
$export = new ExpenseExport(auth()->user()->company(), $request->all());
|
if($request->has('output') && $request->input('output') == 'json') {
|
||||||
|
|
||||||
|
$hash = \Illuminate\Support\Str::uuid();
|
||||||
|
|
||||||
|
PreviewReport::dispatch($user->company(), $request->all(), ExpenseExport::class, $hash);
|
||||||
|
|
||||||
|
return response()->json(['message' => $hash], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$export = new ExpenseExport($user->company(), $request->all());
|
||||||
|
|
||||||
$csv = $export->run();
|
$csv = $export->run();
|
||||||
|
|
||||||
|
@ -11,13 +11,14 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Reports;
|
namespace App\Http\Controllers\Reports;
|
||||||
|
|
||||||
|
use App\Models\Client;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Jobs\Report\SendToAdmin;
|
||||||
use App\Export\CSV\PaymentExport;
|
use App\Export\CSV\PaymentExport;
|
||||||
|
use App\Jobs\Report\PreviewReport;
|
||||||
use App\Http\Controllers\BaseController;
|
use App\Http\Controllers\BaseController;
|
||||||
use App\Http\Requests\Report\GenericReportRequest;
|
use App\Http\Requests\Report\GenericReportRequest;
|
||||||
use App\Jobs\Report\SendToAdmin;
|
|
||||||
use App\Models\Client;
|
|
||||||
use App\Utils\Traits\MakesHash;
|
|
||||||
use Illuminate\Http\Response;
|
|
||||||
|
|
||||||
class PaymentReportController extends BaseController
|
class PaymentReportController extends BaseController
|
||||||
{
|
{
|
||||||
@ -63,14 +64,26 @@ class PaymentReportController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function __invoke(GenericReportRequest $request)
|
public function __invoke(GenericReportRequest $request)
|
||||||
{
|
{
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
if ($request->has('send_email') && $request->get('send_email')) {
|
if ($request->has('send_email') && $request->get('send_email')) {
|
||||||
SendToAdmin::dispatch(auth()->user()->company(), $request->all(), PaymentExport::class, $this->filename);
|
SendToAdmin::dispatch($user->company(), $request->all(), PaymentExport::class, $this->filename);
|
||||||
|
|
||||||
return response()->json(['message' => 'working...'], 200);
|
return response()->json(['message' => 'working...'], 200);
|
||||||
}
|
}
|
||||||
// expect a list of visible fields, or use the default
|
// expect a list of visible fields, or use the default
|
||||||
|
|
||||||
$export = new PaymentExport(auth()->user()->company(), $request->all());
|
if($request->has('output') && $request->input('output') == 'json') {
|
||||||
|
|
||||||
|
$hash = \Illuminate\Support\Str::uuid();
|
||||||
|
|
||||||
|
PreviewReport::dispatch($user->company(), $request->all(), PaymentExport::class, $hash);
|
||||||
|
|
||||||
|
return response()->json(['message' => $hash], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$export = new PaymentExport($user->company(), $request->all());
|
||||||
|
|
||||||
$csv = $export->run();
|
$csv = $export->run();
|
||||||
|
|
||||||
|
@ -59,8 +59,6 @@ class ReportApiTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function testUserSalesReportApiRoute()
|
public function testUserSalesReportApiRoute()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
@ -649,11 +649,11 @@ class ReportCsvGenerationTest extends TestCase
|
|||||||
|
|
||||||
$csv = $response->streamedContent();
|
$csv = $response->streamedContent();
|
||||||
|
|
||||||
$this->assertEquals(500, $this->getFirstValueByColumn($csv, 'Amount'));
|
$this->assertEquals(500, $this->getFirstValueByColumn($csv, 'Payment Amount'));
|
||||||
$this->assertEquals(0, $this->getFirstValueByColumn($csv, 'Applied'));
|
$this->assertEquals(0, $this->getFirstValueByColumn($csv, 'Payment Applied'));
|
||||||
$this->assertEquals(0, $this->getFirstValueByColumn($csv, 'Refunded'));
|
$this->assertEquals(0, $this->getFirstValueByColumn($csv, 'Payment Refunded'));
|
||||||
$this->assertEquals('2020-01-01', $this->getFirstValueByColumn($csv, 'Date'));
|
$this->assertEquals('2020-01-01', $this->getFirstValueByColumn($csv, 'Payment Date'));
|
||||||
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Transaction Reference'));
|
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Payment Transaction Reference'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1491,7 +1491,6 @@ nlog($csv);
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$csv = $response->streamedContent();
|
$csv = $response->streamedContent();
|
||||||
nlog($csv);
|
|
||||||
|
|
||||||
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Invoice Amount'));
|
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Invoice Amount'));
|
||||||
$this->assertEquals('50', $this->getFirstValueByColumn($csv, 'Invoice Balance'));
|
$this->assertEquals('50', $this->getFirstValueByColumn($csv, 'Invoice Balance'));
|
||||||
|
@ -21,9 +21,10 @@ use App\Export\CSV\ClientExport;
|
|||||||
use App\Export\CSV\CreditExport;
|
use App\Export\CSV\CreditExport;
|
||||||
use App\Export\CSV\ContactExport;
|
use App\Export\CSV\ContactExport;
|
||||||
use App\Export\CSV\ExpenseExport;
|
use App\Export\CSV\ExpenseExport;
|
||||||
|
use App\Export\CSV\InvoiceExport;
|
||||||
|
use App\Export\CSV\PaymentExport;
|
||||||
use App\Export\CSV\ActivityExport;
|
use App\Export\CSV\ActivityExport;
|
||||||
use App\Export\CSV\DocumentExport;
|
use App\Export\CSV\DocumentExport;
|
||||||
use App\Export\CSV\InvoiceExport;
|
|
||||||
use App\Jobs\Report\PreviewReport;
|
use App\Jobs\Report\PreviewReport;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
@ -54,6 +55,37 @@ class ReportPreviewTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testPaymentJsonExport()
|
||||||
|
{
|
||||||
|
\App\Models\Payment::factory()->count(5)->create([
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $this->client->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$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/payments?output=json', $data)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
$p = (new PreviewReport($this->company, $data, PaymentExport::class, '123'))->handle();
|
||||||
|
|
||||||
|
$this->assertNull($p);
|
||||||
|
|
||||||
|
$r = Cache::pull('123');
|
||||||
|
|
||||||
|
$this->assertNotNull($r);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testInvoiceItemJsonExport()
|
public function testInvoiceItemJsonExport()
|
||||||
{
|
{
|
||||||
\App\Models\Invoice::factory()->count(5)->create([
|
\App\Models\Invoice::factory()->count(5)->create([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user