Merge branch 'vapor/production' of https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal into vapor/staging

This commit is contained in:
Edmond Lang
2025-07-01 12:37:43 +08:00
2 changed files with 51 additions and 36 deletions
@@ -2,19 +2,27 @@
namespace App\Classes\Modules\Exports\Services;
use App\Models\Company;
use App\Models\CompanyConnection;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use App\Classes\General\Eloquent\ApplyFiltersToQuery;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class ExportsAllCustomersInfoForLarkSystem implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize
{
use Exportable;
public function __construct() {}
protected $deduplicateMarking;
protected $request;
public function __construct(Request $request, $deduplicateMarking = true)
{
$this->deduplicateMarking = $deduplicateMarking;
$this->request = $request;
}
public function headings(): array
{
@@ -33,48 +41,44 @@ class ExportsAllCustomersInfoForLarkSystem implements FromQuery, WithMapping, Wi
public function query()
{
return (new ApplyFiltersToQuery())->execute(
Company::query()->with([
'companyModules.employees',
'companyModules.connections.segments',
'contacts'
]),
['has_business_module_type' => 1]
);
$baseQuery = CompanyConnection::has('invitee.company');
if ($this->deduplicateMarking) {
$baseQuery->whereIn('id', function ($sub) {
$sub->selectRaw('min(id)')
->from('company_connections')
->groupBy('invitee_reference');
});
}
return $baseQuery->with([
'invitee.company.contacts',
'invitee.company.companyModules.employees',
'segments'
]);
}
public function map($company): array
public function map($connection): array
{
$companyModule = $company->companyModules->first();
$marking = $companyModule ? $companyModule->getMarking() : '';
$creditTermCustomer = '';
if ($companyModule && $companyModule->connections->first()) {
$creditTermCustomer = $companyModule->connections->first()->is_credit_term ? 'YES' : 'NO';
}
$company = optional(optional($connection)->invitee)->company;
$companyModule = optional($company)->companyModules->first();
$employee = optional($companyModule)->employees->first();
$contact = optional($company)->contacts->first();
$employeeEmail = '';
if ($companyModule && $companyModule->employees->first()) {
$employeeEmail = $companyModule->employees->first()->email;
}
$contactPhone = '';
if ($company->contacts->first()) {
$contactPhone = $company->contacts->first()->phone;
}
$segments = '';
if ($companyModule && $companyModule->connections->first()) {
$segments = $companyModule->connections->first()->segments->pluck('name')->implode(', ');
}
$marking = $connection->invitee_reference;
$creditTermCustomer = $connection->is_credit_term ? 'YES' : 'NO';
$employeeEmail = optional($employee)->email ?? '';
$contactPhone = optional($contact)->phone ?? '';
$segments = optional($connection->segments)->pluck('name')->implode(', ') ?: '';
return [
$marking,
$company->name,
optional($company)->name ?? '',
$contactPhone,
$employeeEmail,
$company->created_at ? $company->created_at->toDateString() : '',
$company->updated_at ? $company->updated_at->toDateString() : '',
$company->debtor,
optional($company)->created_at ? $company->created_at->toDateString() : '',
optional($company)->updated_at ? $company->updated_at->toDateString() : '',
optional($company)->debtor ?? '',
$creditTermCustomer,
$segments,
];
File diff suppressed because one or more lines are too long