diff --git a/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php b/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php new file mode 100644 index 00000000..06988abb --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php @@ -0,0 +1,71 @@ +execute( + Company::query()->with([ + 'employees', + 'segments', + 'contacts' + ]), + ['business_type' => 2] + ); + } + + public function map($company): array + { + $employeeEmail = ''; + if ($company->employees->first()) { + $employeeEmail = $company->employees->first()->email; + } + + $contactPhone = ''; + if ($company->contacts->first()) { + $contactPhone = $company->contacts->first()->phone; + } + + $segments = ''; + if ($company->segments->first()) { + $segments = $company->segments->pluck('name')->implode(', '); + } + + return [ + $company->reference, + $company->name, + $contactPhone, + $employeeEmail, + $company->created_at ? $company->created_at->toDateString() : '', + $company->updated_at ? $company->updated_at->toDateString() : '', + $segments, + ]; + } +} diff --git a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php index b693f326..8452dd6b 100644 --- a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php @@ -24,6 +24,7 @@ use App\Classes\Modules\Exports\Services\ExportsImportedReceiptMappeds; use App\Classes\Modules\Exports\Services\ExportsWhiteFormTransactions; use Illuminate\Support\Facades\Storage; use App\Classes\General\AWSS3Helper; +use App\Classes\Modules\Exports\Services\ExportsAllCustomersInfoForLarkSystem; use Illuminate\Support\Carbon; class ExportCustomersToExcelController @@ -241,5 +242,25 @@ class ExportCustomersToExcelController return $response; } } + + public function exportAllCustomersInfoForLarkSystem(Request $request) + { + $password = $request->input('password'); + if ($password !== 'all_customers_data') { + return response()->json(['error' => 'Invalid password'], 403); + } + + $exportsAllCustomersInfoForLarkSystem = new ExportsAllCustomersInfoForLarkSystem($request); + $exportFileName = 'all_customers_info_for_lark_system.xls'; + + $filesystemDriver = Storage::getDefaultDriver(); + if ($filesystemDriver === 's3') { + return response(['src' => AWSS3Helper::S3Exportable($exportFileName, $exportsAllCustomersInfoForLarkSystem)]); + } else { + $response = $exportsAllCustomersInfoForLarkSystem->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); + ob_end_clean(); + return $response; + } + } } diff --git a/resources/assets/vue/components/general/elements/PasswordProtectedDownloadComponent.vue b/resources/assets/vue/components/general/elements/PasswordProtectedDownloadComponent.vue new file mode 100644 index 00000000..22b68ce6 --- /dev/null +++ b/resources/assets/vue/components/general/elements/PasswordProtectedDownloadComponent.vue @@ -0,0 +1,156 @@ + + + + + \ No newline at end of file diff --git a/resources/views/pages/downloads/index.blade.php b/resources/views/pages/downloads/index.blade.php index bb03689d..85cb7c6d 100644 --- a/resources/views/pages/downloads/index.blade.php +++ b/resources/views/pages/downloads/index.blade.php @@ -69,6 +69,20 @@ +
+
+
+
+ all_customers_info_for_lark_system.xls + + Download + +
+
+
+
+ + diff --git a/routes/web.php b/routes/web.php index 1014aea6..b2e5df0e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -326,6 +326,7 @@ Route::get('/export/analytic/booking', 'Exports\ExportAnalyticToExcelController@ Route::get('/export/analytic/bills', 'Exports\ExportAnalyticToExcelController@billingData')->name('billingData.export');; Route::get('/export/customers/leads', 'Exports\ExportCustomersToExcelController@leadsData')->name('leads.export'); route::get('/export/excel/{id}', 'Exports\ExportCustomersToExcelController@exportCurrencyVendorOrder')->name('group.excel'); +Route::get('/export/all-customers-info-for-lark-system', 'Exports\ExportCustomersToExcelController@exportAllCustomersInfoForLarkSystem')->name('exportAllCustomersInfoForLarkSystem.export'); Route::get('/products', function (\App\Classes\Modules\Exports\Services\ExportsProducts $exportsProducts) { $bookings = Booking::where(function($query){