1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Ninja/Repositories/BankAccountRepository.php

54 lines
1.6 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Ninja\Repositories;
2016-01-20 00:07:31 +01:00
use App\Models\BankAccount;
2016-01-26 21:22:33 +01:00
use App\Models\BankSubaccount;
2017-01-30 20:40:43 +01:00
use Crypt;
use DB;
2016-01-20 00:07:31 +01:00
class BankAccountRepository extends BaseRepository
{
public function getClassName()
{
return 'App\Models\BankAccount';
}
public function find($accountId)
{
return DB::table('bank_accounts')
->join('banks', 'banks.id', '=', 'bank_accounts.bank_id')
->where('bank_accounts.deleted_at', '=', null)
->where('bank_accounts.account_id', '=', $accountId)
2016-01-26 21:22:33 +01:00
->select(
'bank_accounts.public_id',
'banks.name as bank_name',
'bank_accounts.deleted_at',
'banks.bank_library_id'
);
}
public function save($input)
{
$bankAccount = BankAccount::createNew();
$bankAccount->bank_id = $input['bank_id'];
$bankAccount->username = Crypt::encrypt(trim($input['bank_username']));
$account = \Auth::user()->account;
$account->bank_accounts()->save($bankAccount);
foreach ($input['bank_accounts'] as $data) {
2017-01-30 17:05:31 +01:00
if (! isset($data['include']) || ! filter_var($data['include'], FILTER_VALIDATE_BOOLEAN)) {
2016-01-26 21:22:33 +01:00
continue;
}
$subaccount = BankSubaccount::createNew();
$subaccount->account_name = trim($data['account_name']);
$subaccount->account_number = trim($data['hashed_account_number']);
$bankAccount->bank_subaccounts()->save($subaccount);
}
return $bankAccount;
2016-01-20 00:07:31 +01:00
}
}