Refactor for reports

This commit is contained in:
David Bomba 2023-10-26 14:54:32 +11:00
parent 269fe7b38c
commit 9089d548b5
16 changed files with 48 additions and 253 deletions

View File

@ -41,28 +41,12 @@ class ActivityReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), ActivityExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), ActivityExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new ActivityExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -72,30 +72,11 @@ class ClientContactReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
$hash = \Illuminate\Support\Str::uuid();
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
PreviewReport::dispatch($user->company(), $request->all(), ContactExport::class, $hash);
$hash = \Illuminate\Support\Str::uuid();
return response()->json(['message' => $hash], 200);
PreviewReport::dispatch($user->company(), $request->all(), ContactExport::class, $hash);
return response()->json(['message' => $hash], 200);
}
// expect a list of visible fields, or use the default
$export = new ContactExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -73,27 +73,11 @@ class ClientReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), ClientExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), ClientExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new ClientExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -72,27 +72,11 @@ class InvoiceReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), InvoiceExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), InvoiceExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
// expect a list of visible fields, or use the default
$export = new InvoiceExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -72,29 +72,13 @@ class PaymentReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), PaymentExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), PaymentExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new PaymentExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -73,28 +73,12 @@ class ProductReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), ProductExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), ProductExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new ProductExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -39,28 +39,12 @@ class PurchaseOrderItemReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), PurchaseOrderItemExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), PurchaseOrderItemExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new PurchaseOrderItemExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -41,29 +41,12 @@ class PurchaseOrderReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), PurchaseOrderExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), PurchaseOrderExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new PurchaseOrderExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -71,28 +71,12 @@ class QuoteItemReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), QuoteItemExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), QuoteItemExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new QuoteItemExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -71,28 +71,12 @@ class QuoteReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), QuoteExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), QuoteExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new QuoteExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -39,28 +39,12 @@ class RecurringInvoiceReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), RecurringInvoiceExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), RecurringInvoiceExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new RecurringInvoiceExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -71,28 +71,12 @@ class TaskReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), TaskExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), TaskExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new TaskExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -39,28 +39,12 @@ class VendorReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), VendorExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), VendorExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new VendorExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -38,7 +38,11 @@ class PreviewReport implements ShouldQueue
/** @var \App\Export\CSV\CreditExport $export */
$export = new $this->report_class($this->company, $this->request);
$report = $export->returnJson();
if($this->request['output'] == 'json' ?? false)
$report = $export->returnJson();
else
$report = $export->run();
Cache::put($this->hash, $report, 60 * 60);
}

View File

@ -25,6 +25,7 @@ use App\Models\PurchaseOrder;
use App\Models\PurchaseOrderInvitation;
use App\Models\Quote;
use App\Models\QuoteInvitation;
use App\Models\RecurringInvoice;
use App\Models\RecurringInvoiceInvitation;
use App\Models\Vendor;
use App\Models\VendorContact;
@ -51,7 +52,7 @@ class PdfConfiguration
public Design $design;
public Invoice | Credit | Quote | PurchaseOrder $entity;
public Invoice | Credit | Quote | PurchaseOrder | RecurringInvoice $entity;
public string $entity_design_id;

View File

@ -322,6 +322,8 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale']
Route::post('reports/tax_summary_report', TaxSummaryReportController::class);
Route::post('reports/user_sales_report', UserSalesReportController::class);
Route::post('reports/preview/{hash}', ReportPreviewController::class);
Route::post('exports/preview/{hash}', ReportPreviewController::class);
Route::post('templates/preview/{hash}', TemplatePreviewController::class);
Route::post('search', SearchController::class);