From 9c09b1e01d694fcfe47c880629a230a42bb48751 Mon Sep 17 00:00:00 2001 From: Edmond Lang Date: Fri, 27 Jun 2025 16:21:28 +0800 Subject: [PATCH 1/4] update /export/all-customers-info-for-lark-system, fix duplications on customer connections - use the first one --- .../ExportsAllCustomersInfoForLarkSystem.php | 75 ++++++++++--------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php b/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php index 40294a21..8c07723f 100644 --- a/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php +++ b/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php @@ -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\DB; 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,43 @@ 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::query(); + + if ($this->deduplicateMarking) { + // Only keep one row per invitee_reference (marking), keeping the latest ID + $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($connection->invitee)->company; + $companyModule = optional($company)->companyModules->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($companyModule?->employees->first())->email; + $contactPhone = optional($company?->contacts->first())->phone; + $segments = $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?->toDateString(), + optional($company)->updated_at?->toDateString(), + optional($company)->debtor, $creditTermCustomer, $segments, ]; From 17d8c82cffeb52cc6f620e74154ffdd7ef407f34 Mon Sep 17 00:00:00 2001 From: Edmond Lang Date: Fri, 27 Jun 2025 16:53:28 +0800 Subject: [PATCH 2/4] update /export/all-customers-info-for-lark-system, fix duplications on customer connections - use the first one --- .../ExportsAllCustomersInfoForLarkSystem.php | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php b/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php index 8c07723f..821ea70c 100644 --- a/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php +++ b/app/Classes/Modules/Exports/Services/ExportsAllCustomersInfoForLarkSystem.php @@ -9,7 +9,7 @@ use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class ExportsAllCustomersInfoForLarkSystem implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize { @@ -41,10 +41,9 @@ class ExportsAllCustomersInfoForLarkSystem implements FromQuery, WithMapping, Wi public function query() { - $baseQuery = CompanyConnection::query(); + $baseQuery = CompanyConnection::has('invitee.company'); if ($this->deduplicateMarking) { - // Only keep one row per invitee_reference (marking), keeping the latest ID $baseQuery->whereIn('id', function ($sub) { $sub->selectRaw('min(id)') ->from('company_connections') @@ -61,23 +60,25 @@ class ExportsAllCustomersInfoForLarkSystem implements FromQuery, WithMapping, Wi public function map($connection): array { - $company = optional($connection->invitee)->company; + $company = optional(optional($connection)->invitee)->company; $companyModule = optional($company)->companyModules->first(); + $employee = optional($companyModule)->employees->first(); + $contact = optional($company)->contacts->first(); $marking = $connection->invitee_reference; $creditTermCustomer = $connection->is_credit_term ? 'YES' : 'NO'; - $employeeEmail = optional($companyModule?->employees->first())->email; - $contactPhone = optional($company?->contacts->first())->phone; - $segments = $connection->segments->pluck('name')->implode(', '); + $employeeEmail = optional($employee)->email ?? ''; + $contactPhone = optional($contact)->phone ?? ''; + $segments = optional($connection->segments)->pluck('name')->implode(', ') ?: ''; return [ $marking, - optional($company)->name, + optional($company)->name ?? '', $contactPhone, $employeeEmail, - optional($company)->created_at?->toDateString(), - optional($company)->updated_at?->toDateString(), - optional($company)->debtor, + optional($company)->created_at ? $company->created_at->toDateString() : '', + optional($company)->updated_at ? $company->updated_at->toDateString() : '', + optional($company)->debtor ?? '', $creditTermCustomer, $segments, ]; From 5767ab1853530fab7b39cdeba70167ca0bfb3bf0 Mon Sep 17 00:00:00 2001 From: Edmond Lang Date: Sat, 28 Jun 2025 23:41:03 +0800 Subject: [PATCH 3/4] add new menu "E-Invoice Guideline" - open in new tab --- resources/views/partials/menu.blade.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resources/views/partials/menu.blade.php b/resources/views/partials/menu.blade.php index 1e502ae6..3a9769d5 100644 --- a/resources/views/partials/menu.blade.php +++ b/resources/views/partials/menu.blade.php @@ -163,6 +163,14 @@
Payment And Billing
+
+
+ +
+ +
Date: Tue, 1 Jul 2025 12:37:09 +0800 Subject: [PATCH 4/4] update menu icon --- resources/views/partials/menu.blade.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resources/views/partials/menu.blade.php b/resources/views/partials/menu.blade.php index 3a9769d5..cd189817 100644 --- a/resources/views/partials/menu.blade.php +++ b/resources/views/partials/menu.blade.php @@ -165,7 +165,10 @@