App\services\BankAccountService::importExpenses PHP Method

importExpenses() public method

public importExpenses ( $bankId, $input )
    public function importExpenses($bankId = 0, $input)
    {
        $vendorMap = $this->createVendorMap();
        $countVendors = 0;
        $countExpenses = 0;
        foreach ($input as $transaction) {
            $vendorName = $transaction['vendor'];
            $key = strtolower($vendorName);
            $info = $transaction['info'];
            // find vendor otherwise create it
            if (isset($vendorMap[$key])) {
                $vendor = $vendorMap[$key];
            } else {
                $field = $this->determineInfoField($info);
                $vendor = $this->vendorRepo->save([$field => $info, 'name' => $vendorName, 'transaction_name' => $transaction['vendor_orig'], 'vendor_contact' => []]);
                $vendorMap[$key] = $vendor;
                $vendorMap[$transaction['vendor_orig']] = $vendor;
                $countVendors++;
            }
            // create the expense record
            $this->expenseRepo->save(['vendor_id' => $vendor->id, 'amount' => $transaction['amount'], 'public_notes' => $transaction['memo'], 'expense_date' => $transaction['date'], 'transaction_id' => $transaction['id'], 'bank_id' => $bankId, 'should_be_invoiced' => true]);
            $countExpenses++;
        }
        return trans('texts.imported_expenses', ['count_vendors' => $countVendors, 'count_expenses' => $countExpenses]);
    }