export segment customers

This commit is contained in:
edmondlang
2024-12-13 18:41:11 +08:00
parent 32bad3bf07
commit b5e5e88a6a
5 changed files with 139 additions and 4 deletions
@@ -10,6 +10,8 @@ use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Excel;
use Illuminate\Support\Facades\Storage;
use App\Classes\General\AWSS3Helper;
use App\Classes\Modules\Exports\Services\ExportsSegmentCustomers;
use App\Models\Segment;
class ExportCompanyModuleSummaryController
{
@@ -53,4 +55,26 @@ class ExportCompanyModuleSummaryController
return $response;
}
}
public function exportSegmentCustomers(Request $request)
{
$exportsSegmentCustomers = new ExportsSegmentCustomers($request);
$customer_marking = $request->route('companyMarking');
$segment = $request->route('segment');
$exportsSegmentCustomers->setParameters($customer_marking, $segment);
$segment_name = Segment::find($request->route('segment'))->name;
$segment_name = $segment_name ? strtolower(str_replace(' ', '_', $segment_name)): 'segment';
$exportFileName = $segment_name . '_customers.xls';
$filesystemDriver = Storage::getDefaultDriver();
if ($filesystemDriver === 's3') {
return response(['src' => AWSS3Helper::S3Exportable($exportFileName, $exportsSegmentCustomers)]);
} else {
$response = $exportsSegmentCustomers->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
ob_end_clean();
return $response;
}
}
}