diff --git a/app/Filament/Imports/CustomerPoMasterImporter.php b/app/Filament/Imports/CustomerPoMasterImporter.php index 430f81b..bf089bf 100644 --- a/app/Filament/Imports/CustomerPoMasterImporter.php +++ b/app/Filament/Imports/CustomerPoMasterImporter.php @@ -17,6 +17,8 @@ class CustomerPoMasterImporter extends Importer { protected static ?string $model = CustomerPoMaster::class; + protected array $importedPos = []; + public static function getColumns(): array { return [ @@ -67,6 +69,8 @@ class CustomerPoMasterImporter extends Importer $plantCod = $this->data['plant']; $plant = null; $item = null; + $customerPo = trim($this->data['customer_po']); + $customerName = trim($this->data['customer_name']); if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) { $warnMsg[] = 'Invalid plant code found'; @@ -90,6 +94,23 @@ class CustomerPoMasterImporter extends Importer $warnMsg[] = 'Customer PO cannot be empty.'; } + if (isset($this->importedPos[$customerPo])) { + + if (strtolower(trim($this->importedPos[$customerPo])) != strtolower($customerName)){ + $warnMsg[] = "Customer PO '{$customerPo}' has multiple customer names in the import file."; + } + } + else { + $this->importedPos[$customerPo] = $customerName; + } + + $existingPo = CustomerPoMaster::where('plant_id', $plant->id)->where('customer_po', $this->data['customer_po'])->first(); + + if ($existingPo && trim(strtolower($existingPo->customer_name)) != trim(strtolower($this->data['customer_name']))) + { + $warnMsg[] = "Customer PO '{$this->data['customer_po']}' is already mapped to customer '{$existingPo->customer_name}'."; + } + // $user = User::where('name', $this->data['created_by'])->first(); // if (! $user) { // $warnMsg[] = 'User not found';