1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00

Updates for all report endpoints

This commit is contained in:
David Bomba 2023-10-28 09:20:37 +11:00
parent e078b9637b
commit da62f3da4b
12 changed files with 104 additions and 126 deletions

View File

@ -11,11 +11,12 @@
namespace App\Http\Controllers\Reports; namespace App\Http\Controllers\Reports;
use App\Utils\Traits\MakesHash;
use App\Jobs\Report\SendToAdmin;
use App\Jobs\Report\PreviewReport;
use App\Services\Report\ARDetailReport;
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\Services\Report\ARDetailReport;
use App\Utils\Traits\MakesHash;
class ARDetailReportController extends BaseController class ARDetailReportController extends BaseController
{ {
@ -61,24 +62,21 @@ class ARDetailReportController 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(), ARDetailReport::class, $this->filename); SendToAdmin::dispatch($user->company(), $request->all(), ARDetailReport::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
$export = new ARDetailReport(auth()->user()->company(), $request->all()); $hash = \Illuminate\Support\Str::uuid();
$csv = $export->run(); PreviewReport::dispatch($user->company(), $request->all(), ARDetailReport::class, $hash);
$headers = [ return response()->json(['message' => $hash], 200);
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
} }
} }

View File

@ -11,11 +11,12 @@
namespace App\Http\Controllers\Reports; namespace App\Http\Controllers\Reports;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Services\Report\ARSummaryReport;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Jobs\Report\SendToAdmin;
use App\Jobs\Report\PreviewReport;
use App\Http\Controllers\BaseController;
use App\Services\Report\ARSummaryReport;
use App\Http\Requests\Report\GenericReportRequest;
class ARSummaryReportController extends BaseController class ARSummaryReportController extends BaseController
{ {
@ -71,17 +72,11 @@ class ARSummaryReportController extends BaseController
} }
// expect a list of visible fields, or use the default // expect a list of visible fields, or use the default
$export = new ARSummaryReport($user->company(), $request->all()); $hash = \Illuminate\Support\Str::uuid();
$csv = $export->run(); PreviewReport::dispatch($user->company(), $request->all(), ARSummaryReport::class, $hash);
$headers = [ return response()->json(['message' => $hash], 200);
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
} }
} }

View File

@ -11,11 +11,12 @@
namespace App\Http\Controllers\Reports; namespace App\Http\Controllers\Reports;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Services\Report\ClientBalanceReport;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Jobs\Report\SendToAdmin;
use App\Jobs\Report\PreviewReport;
use App\Http\Controllers\BaseController;
use App\Services\Report\ClientBalanceReport;
use App\Http\Requests\Report\GenericReportRequest;
class ClientBalanceReportController extends BaseController class ClientBalanceReportController extends BaseController
{ {
@ -61,24 +62,20 @@ class ClientBalanceReportController 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(), ClientBalanceReport::class, $this->filename); SendToAdmin::dispatch($user->company(), $request->all(), ClientBalanceReport::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
$export = new ClientBalanceReport(auth()->user()->company(), $request->all()); $hash = \Illuminate\Support\Str::uuid();
$csv = $export->run(); PreviewReport::dispatch($user->company(), $request->all(), ClientBalanceReport::class, $hash);
$headers = [ return response()->json(['message' => $hash], 200);
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
} }
} }

View File

@ -11,11 +11,12 @@
namespace App\Http\Controllers\Reports; namespace App\Http\Controllers\Reports;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Services\Report\ClientSalesReport;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Jobs\Report\SendToAdmin;
use App\Jobs\Report\PreviewReport;
use App\Http\Controllers\BaseController;
use App\Services\Report\ClientSalesReport;
use App\Http\Requests\Report\GenericReportRequest;
class ClientSalesReportController extends BaseController class ClientSalesReportController extends BaseController
{ {
@ -61,24 +62,20 @@ class ClientSalesReportController 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(), ClientSalesReport::class, $this->filename); SendToAdmin::dispatch($user->company(), $request->all(), ClientSalesReport::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
$export = new ClientSalesReport(auth()->user()->company(), $request->all()); $hash = \Illuminate\Support\Str::uuid();
$csv = $export->run(); PreviewReport::dispatch($user->company(), $request->all(), ClientSalesReport::class, $hash);
$headers = [ return response()->json(['message' => $hash], 200);
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
} }
} }

View File

@ -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\Jobs\Report\PreviewReport;
use App\Export\CSV\ProductSalesExport; use App\Export\CSV\ProductSalesExport;
use App\Http\Controllers\BaseController; use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\ProductSalesReportRequest; use App\Http\Requests\Report\ProductSalesReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Models\Client;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
class ProductSalesReportController extends BaseController class ProductSalesReportController extends BaseController
{ {
@ -63,24 +64,20 @@ class ProductSalesReportController extends BaseController
*/ */
public function __invoke(ProductSalesReportRequest $request) public function __invoke(ProductSalesReportRequest $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(), ProductSalesExport::class, $this->filename); SendToAdmin::dispatch($user->company(), $request->all(), ProductSalesExport::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
$export = new ProductSalesExport(auth()->user()->company(), $request->all()); $hash = \Illuminate\Support\Str::uuid();
$csv = $export->run(); PreviewReport::dispatch($user->company(), $request->all(), ProductSalesExport::class, $hash);
$headers = [ return response()->json(['message' => $hash], 200);
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
} }
} }

View File

@ -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\Jobs\Report\PreviewReport;
use App\Services\Report\ProfitLoss;
use App\Http\Controllers\BaseController; use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\ProfitLossRequest; use App\Http\Requests\Report\ProfitLossRequest;
use App\Jobs\Report\SendToAdmin;
use App\Models\Client;
use App\Services\Report\ProfitLoss;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
class ProfitAndLossController extends BaseController class ProfitAndLossController extends BaseController
{ {
@ -71,18 +72,13 @@ class ProfitAndLossController extends BaseController
return response()->json(['message' => 'working...'], 200); return response()->json(['message' => 'working...'], 200);
} }
// expect a list of visible fields, or use the default
$pnl = new ProfitLoss($user->company(), $request->all()); $hash = \Illuminate\Support\Str::uuid();
$csv = $pnl->run();
PreviewReport::dispatch($user->company(), $request->all(), ProfitLoss::class, $hash);
return response()->json(['message' => $hash], 200);
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
} }
} }

View File

@ -11,11 +11,12 @@
namespace App\Http\Controllers\Reports; namespace App\Http\Controllers\Reports;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Services\Report\TaxSummaryReport;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Jobs\Report\SendToAdmin;
use App\Jobs\Report\PreviewReport;
use App\Http\Controllers\BaseController;
use App\Services\Report\TaxSummaryReport;
use App\Http\Requests\Report\GenericReportRequest;
class TaxSummaryReportController extends BaseController class TaxSummaryReportController extends BaseController
{ {
@ -61,24 +62,21 @@ class TaxSummaryReportController 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(), TaxSummaryReport::class, $this->filename); SendToAdmin::dispatch($user->company(), $request->all(), TaxSummaryReport::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
$export = new TaxSummaryReport(auth()->user()->company(), $request->all()); $hash = \Illuminate\Support\Str::uuid();
$csv = $export->run(); PreviewReport::dispatch($user->company(), $request->all(), TaxSummaryReport::class, $hash);
$headers = [ return response()->json(['message' => $hash], 200);
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
} }
} }

View File

@ -11,11 +11,12 @@
namespace App\Http\Controllers\Reports; namespace App\Http\Controllers\Reports;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Report\GenericReportRequest;
use App\Jobs\Report\SendToAdmin;
use App\Services\Report\UserSalesReport;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Jobs\Report\SendToAdmin;
use App\Jobs\Report\PreviewReport;
use App\Http\Controllers\BaseController;
use App\Services\Report\UserSalesReport;
use App\Http\Requests\Report\GenericReportRequest;
class UserSalesReportController extends BaseController class UserSalesReportController extends BaseController
{ {
@ -61,24 +62,20 @@ class UserSalesReportController 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(), UserSalesReport::class, $this->filename); SendToAdmin::dispatch($user->company(), $request->all(), UserSalesReport::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
$export = new UserSalesReport(auth()->user()->company(), $request->all()); $hash = \Illuminate\Support\Str::uuid();
$csv = $export->run(); PreviewReport::dispatch($user->company(), $request->all(), UserSalesReport::class, $hash);
$headers = [ return response()->json(['message' => $hash], 200);
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
} }
} }

View File

@ -27,8 +27,8 @@ class Locale
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
/*LOCALE SET */ /*LOCALE SET */
if ($request->has('lang')) { if ($request->has('lang') && is_string($request->input('lang'))) {
$locale = $request->input('lang'); $locale = $request->string('lang','en');
App::setLocale($locale); App::setLocale($locale);
} elseif (auth()->guard('contact')->user()) { } elseif (auth()->guard('contact')->user()) {
App::setLocale(auth()->guard('contact')->user()->client()->setEagerLoads([])->first()->locale()); App::setLocale(auth()->guard('contact')->user()->client()->setEagerLoads([])->first()->locale());

View File

@ -32,7 +32,7 @@ class SetEmailDb
'errors' => new stdClass, 'errors' => new stdClass,
]; ];
if ($request->input('email') && config('ninja.db.multi_db_enabled')) { if ($request->input('email') && is_string($request->input('email')) && config('ninja.db.multi_db_enabled')) {
if (! MultiDB::userFindAndSetDb($request->input('email'))) { if (! MultiDB::userFindAndSetDb($request->input('email'))) {
return response()->json($error, 400); return response()->json($error, 400);
} }

View File

@ -32,7 +32,7 @@ class VendorLocale
} }
/*LOCALE SET */ /*LOCALE SET */
if ($request->has('lang')) { if ($request->has('lang') && is_string($request->input('lang'))) {
$locale = $request->input('lang'); $locale = $request->input('lang');
App::setLocale($locale); App::setLocale($locale);
} elseif (auth()->guard('vendor')->user()) { } elseif (auth()->guard('vendor')->user()) {

View File

@ -113,12 +113,15 @@ class TaxSummaryReport extends BaseExport
if(in_array($invoice->status_id, [Invoice::STATUS_PARTIAL,Invoice::STATUS_PAID])) { if(in_array($invoice->status_id, [Invoice::STATUS_PARTIAL,Invoice::STATUS_PAID])) {
if($invoice->status_id == Invoice::STATUS_PAID) { try {
$cash_map[$key]['tax_amount'] += $tax['total']; if($invoice->status_id == Invoice::STATUS_PAID) {
} else { $cash_map[$key]['tax_amount'] += $tax['total'];
$cash_map[$key]['tax_amount'] += (($invoice->amount - $invoice->balance) / $invoice->balance) * $tax['total'] ?? 0; } else {
$cash_map[$key]['tax_amount'] += (($invoice->amount - $invoice->balance) / $invoice->balance) * $tax['total'] ?? 0;
}
} catch(\DivisionByZeroError $e) {
$cash_map[$key]['tax_amount'] += 0;
} }
} }
} }