<?php


            if ($resultCd == '000') {

                \Log::debug('Get Imported From Etims Fetched Successfully', [$responseArray]);
                //  \Log::debug('eTims Pulled Imported Goods and  Response.', $responseArray);

                $importedIitemList = $responseArray['data']['itemList'];

                if (isset($responseArray['data']['itemList']) && is_array($responseArray['data']['itemList'])) {
                    $itemlistcount = count($responseArray['data']['itemList']);
                } else {
                    // Handle the case where the data is not an array or doesn't exist
                    $itemlistcount = 0; // You can set a default count or handle the error in another way.
                }

                //\Log::debug('eTims Imported Items fetch count  and  Response.', ['count' => $itemlistcount]);
                foreach ($importedIitemList as $detail) {

                    $exists = ImportedItem::where('declaration_no', $detail['dclNo'])
                        ->where('company_id', $companyId)->exists();
                    if (!$exists) {

                        $supplier = Supplier::where('name', $detail['spplrNm'])->
                        where('company_id', $companyId)->first();
                        \Log::debug('Check if supplier Exist.');

                        if ($supplier) {
                            $supplier_id = $supplier->id;
                        } else {
                            $supplierC = Supplier::create([
                                'name' => $detail['spplrNm'],

                            ]);
                            $supplier_id = $supplierC->id;
                        }
						
						
                        $purchaseprice = ($detail['invcFcurAmt'] / $detail['qty']) * $detail['invcFcurExcrt'];
                        $importedItem = ImportedItem::create([
                            'company_id' => $companyId,
                            'store_id' => $storeId,
                            'supplier_id' => $supplier_id,
                            'name' => $detail['itemNm'],
                            'refNo' => $detail['dclNo'],
                            'task_code' => $detail['taskCd'],
                            'declaration_date' => $detail['dclDe'],
                            'item_sequence' => $detail['itemSeq'],
                            'declaration_no' => $detail['dclNo'],
                            'hs_code' => $detail['hsCd'],
                            'item_name' => $detail['itemNm'],
                            'impitem_status_code' => $detail['imptItemsttsCd'],
                            'origin_place_code' => $detail['orgnNatCd'],
                            'export_nation_code' => $detail['exptNatCd'],
                            'packaging' => $detail['pkg'],
                            'pkg_unit_code' => $detail['pkgUnitCd'],
                            'quantity' => $detail['qty'],
                            'qty_unit_code' => $detail['qtyUnitCd'],
                            'gross_weight' => $detail['totWt'],
                            'net_weight' => $detail['netWt'],
                            'agent_name' => $detail['agntNm'],
                            'invc_forecurrency_amount' => $detail['invcFcurAmt'],
                            'invc_forecurrency' => $detail['invcFcurCd'],
                            'invc_forecur_exportcur_amount' => $detail['invcFcurExcrt'],
                            'purchase_price' => round($purchaseprice, 2),
                            'last_req_date' => $resultDt,
                        ]);

                    }
                }















?>