chartOfAccountFacade = app(ChartOfAccountFacade::class); $this->expenseRepository = app(ExpenseRepositoryInterface::class); $this->supplierFacade = app(SupplierFacade::class); $this->customerFacade = app(CustomerFacade::class); } /** * @param Collection $collection */ public function collection(Collection $collection) { foreach ($collection as $i => $row) { if ($i != 0) { $expenseDate = $row[0]; $expenseAccountName = $row[1]; $expenseAccountType = keyChartOfAccountType($row[2]); $expenseAccount = $this->chartOfAccountFacade->findByNameOrCreate( (new ChartOfAccountAttr) ->setName($expenseAccountName) ->settype($expenseAccountType) ); $amount = $row[3]; $taxRate = $row[4]; $paymentAccountName = $row[5]; $paymentAccountType = keyChartOfAccountType($row[6]); $paymentAccount = $this->chartOfAccountFacade->findByNameOrCreate( (new ChartOfAccountAttr) ->setName($paymentAccountName) ->settype($paymentAccountType) ); if ($row[7]) { $customer = $this->customerFacade->findByNameOrCreate( (new CustomerAttr) ->setName($row[7]) ); } if ($row[8]) { $supplier = $this->supplierFacade->findByNameOrCreate( (new SupplierAttr) ->setName($row[8]) ); } $notes = $row[9]; $this->expenseRepository->create( (new ExpenseAttr) ->setExpenseDate($expenseDate) ->setExpenseAccountId($expenseAccount->id) ->setAmount($amount) ->setTaxRate($taxRate) ->setPaymentAccountId($paymentAccount->id) ->setCustomerId($customer->id ?? null) ->setSupplierId($supplier->id ?? null) ->setNotes($notes) ); } } } }