diff --git a/app/Http/Controllers/Reports/ARDetailReportController.php b/app/Http/Controllers/Reports/ARDetailReportController.php index 1d37848222..1d3183a41d 100644 --- a/app/Http/Controllers/Reports/ARDetailReportController.php +++ b/app/Http/Controllers/Reports/ARDetailReportController.php @@ -11,11 +11,12 @@ 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\Requests\Report\GenericReportRequest; -use App\Jobs\Report\SendToAdmin; -use App\Services\Report\ARDetailReport; -use App\Utils\Traits\MakesHash; class ARDetailReportController extends BaseController { @@ -61,24 +62,21 @@ class ARDetailReportController extends BaseController */ public function __invoke(GenericReportRequest $request) { + + /** @var \App\Models\User $user */ + $user = auth()->user(); + 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); } - // 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 = [ - 'Content-Disposition' => 'attachment', - 'Content-Type' => 'text/csv', - ]; + return response()->json(['message' => $hash], 200); - return response()->streamDownload(function () use ($csv) { - echo $csv; - }, $this->filename, $headers); } } diff --git a/app/Http/Controllers/Reports/ARSummaryReportController.php b/app/Http/Controllers/Reports/ARSummaryReportController.php index cde4779451..0898c9e408 100644 --- a/app/Http/Controllers/Reports/ARSummaryReportController.php +++ b/app/Http/Controllers/Reports/ARSummaryReportController.php @@ -11,11 +11,12 @@ 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\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 { @@ -71,17 +72,11 @@ class ARSummaryReportController extends BaseController } // 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 = [ - 'Content-Disposition' => 'attachment', - 'Content-Type' => 'text/csv', - ]; + return response()->json(['message' => $hash], 200); - return response()->streamDownload(function () use ($csv) { - echo $csv; - }, $this->filename, $headers); } } diff --git a/app/Http/Controllers/Reports/ClientBalanceReportController.php b/app/Http/Controllers/Reports/ClientBalanceReportController.php index c29b0a213a..d3b1859dd0 100644 --- a/app/Http/Controllers/Reports/ClientBalanceReportController.php +++ b/app/Http/Controllers/Reports/ClientBalanceReportController.php @@ -11,11 +11,12 @@ 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\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 { @@ -61,24 +62,20 @@ class ClientBalanceReportController extends BaseController */ public function __invoke(GenericReportRequest $request) { + /** @var \App\Models\User $user */ + $user = auth()->user(); + 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); } - // 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 = [ - 'Content-Disposition' => 'attachment', - 'Content-Type' => 'text/csv', - ]; + return response()->json(['message' => $hash], 200); - return response()->streamDownload(function () use ($csv) { - echo $csv; - }, $this->filename, $headers); } } diff --git a/app/Http/Controllers/Reports/ClientSalesReportController.php b/app/Http/Controllers/Reports/ClientSalesReportController.php index 63c0ac69fe..612986f421 100644 --- a/app/Http/Controllers/Reports/ClientSalesReportController.php +++ b/app/Http/Controllers/Reports/ClientSalesReportController.php @@ -11,11 +11,12 @@ 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\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 { @@ -61,24 +62,20 @@ class ClientSalesReportController extends BaseController */ public function __invoke(GenericReportRequest $request) { + /** @var \App\Models\User $user */ + $user = auth()->user(); + 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); } - // 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 = [ - 'Content-Disposition' => 'attachment', - 'Content-Type' => 'text/csv', - ]; + return response()->json(['message' => $hash], 200); - return response()->streamDownload(function () use ($csv) { - echo $csv; - }, $this->filename, $headers); } } diff --git a/app/Http/Controllers/Reports/ProductSalesReportController.php b/app/Http/Controllers/Reports/ProductSalesReportController.php index f27de4b193..a2b8902db8 100644 --- a/app/Http/Controllers/Reports/ProductSalesReportController.php +++ b/app/Http/Controllers/Reports/ProductSalesReportController.php @@ -11,13 +11,14 @@ 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\Http\Controllers\BaseController; 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 { @@ -63,24 +64,20 @@ class ProductSalesReportController extends BaseController */ public function __invoke(ProductSalesReportRequest $request) { + /** @var \App\Models\User $user */ + $user = auth()->user(); + 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); } - // 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 = [ - 'Content-Disposition' => 'attachment', - 'Content-Type' => 'text/csv', - ]; + return response()->json(['message' => $hash], 200); - return response()->streamDownload(function () use ($csv) { - echo $csv; - }, $this->filename, $headers); } } diff --git a/app/Http/Controllers/Reports/ProfitAndLossController.php b/app/Http/Controllers/Reports/ProfitAndLossController.php index 26e860f16b..18e575dd8d 100644 --- a/app/Http/Controllers/Reports/ProfitAndLossController.php +++ b/app/Http/Controllers/Reports/ProfitAndLossController.php @@ -11,13 +11,14 @@ 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\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 { @@ -71,18 +72,13 @@ class ProfitAndLossController extends BaseController return response()->json(['message' => 'working...'], 200); } - // expect a list of visible fields, or use the default - $pnl = new ProfitLoss($user->company(), $request->all()); - $csv = $pnl->run(); + $hash = \Illuminate\Support\Str::uuid(); + + 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); } } diff --git a/app/Http/Controllers/Reports/TaxSummaryReportController.php b/app/Http/Controllers/Reports/TaxSummaryReportController.php index b199eadcc1..08b978a003 100644 --- a/app/Http/Controllers/Reports/TaxSummaryReportController.php +++ b/app/Http/Controllers/Reports/TaxSummaryReportController.php @@ -11,11 +11,12 @@ 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\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 { @@ -61,24 +62,21 @@ class TaxSummaryReportController extends BaseController */ public function __invoke(GenericReportRequest $request) { + + /** @var \App\Models\User $user */ + $user = auth()->user(); + 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); } - // 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 = [ - 'Content-Disposition' => 'attachment', - 'Content-Type' => 'text/csv', - ]; + return response()->json(['message' => $hash], 200); - return response()->streamDownload(function () use ($csv) { - echo $csv; - }, $this->filename, $headers); } } diff --git a/app/Http/Controllers/Reports/UserSalesReportController.php b/app/Http/Controllers/Reports/UserSalesReportController.php index 2d80995791..c26e7dd35d 100644 --- a/app/Http/Controllers/Reports/UserSalesReportController.php +++ b/app/Http/Controllers/Reports/UserSalesReportController.php @@ -11,11 +11,12 @@ 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\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 { @@ -61,24 +62,20 @@ class UserSalesReportController extends BaseController */ public function __invoke(GenericReportRequest $request) { + /** @var \App\Models\User $user */ + $user = auth()->user(); + 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); } - // 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 = [ - 'Content-Disposition' => 'attachment', - 'Content-Type' => 'text/csv', - ]; + return response()->json(['message' => $hash], 200); - return response()->streamDownload(function () use ($csv) { - echo $csv; - }, $this->filename, $headers); } } diff --git a/app/Http/Middleware/Locale.php b/app/Http/Middleware/Locale.php index cea5b9b8f7..5f7f2006f3 100644 --- a/app/Http/Middleware/Locale.php +++ b/app/Http/Middleware/Locale.php @@ -27,8 +27,8 @@ class Locale public function handle($request, Closure $next) { /*LOCALE SET */ - if ($request->has('lang')) { - $locale = $request->input('lang'); + if ($request->has('lang') && is_string($request->input('lang'))) { + $locale = $request->string('lang','en'); App::setLocale($locale); } elseif (auth()->guard('contact')->user()) { App::setLocale(auth()->guard('contact')->user()->client()->setEagerLoads([])->first()->locale()); diff --git a/app/Http/Middleware/SetEmailDb.php b/app/Http/Middleware/SetEmailDb.php index d2dd3190c2..fa02b2c759 100644 --- a/app/Http/Middleware/SetEmailDb.php +++ b/app/Http/Middleware/SetEmailDb.php @@ -32,7 +32,7 @@ class SetEmailDb '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'))) { return response()->json($error, 400); } diff --git a/app/Http/Middleware/VendorLocale.php b/app/Http/Middleware/VendorLocale.php index abca08b9e3..17ae99c62e 100644 --- a/app/Http/Middleware/VendorLocale.php +++ b/app/Http/Middleware/VendorLocale.php @@ -32,7 +32,7 @@ class VendorLocale } /*LOCALE SET */ - if ($request->has('lang')) { + if ($request->has('lang') && is_string($request->input('lang'))) { $locale = $request->input('lang'); App::setLocale($locale); } elseif (auth()->guard('vendor')->user()) { diff --git a/app/Services/Report/TaxSummaryReport.php b/app/Services/Report/TaxSummaryReport.php index aaf313eaf2..3f1b67512e 100644 --- a/app/Services/Report/TaxSummaryReport.php +++ b/app/Services/Report/TaxSummaryReport.php @@ -113,12 +113,15 @@ class TaxSummaryReport extends BaseExport if(in_array($invoice->status_id, [Invoice::STATUS_PARTIAL,Invoice::STATUS_PAID])) { - if($invoice->status_id == Invoice::STATUS_PAID) { - $cash_map[$key]['tax_amount'] += $tax['total']; - } else { - $cash_map[$key]['tax_amount'] += (($invoice->amount - $invoice->balance) / $invoice->balance) * $tax['total'] ?? 0; + try { + if($invoice->status_id == Invoice::STATUS_PAID) { + $cash_map[$key]['tax_amount'] += $tax['total']; + } else { + $cash_map[$key]['tax_amount'] += (($invoice->amount - $invoice->balance) / $invoice->balance) * $tax['total'] ?? 0; + } + } catch(\DivisionByZeroError $e) { + $cash_map[$key]['tax_amount'] += 0; } - } }