1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Ninja/Repositories/BankAccountRepository.php
2016-07-14 22:37:04 +02:00

70 lines
1.8 KiB
PHP

<?php
namespace App\Ninja\Repositories;
use DB;
use Crypt;
use App\Models\BankAccount;
use App\Models\BankSubaccount;
/**
* Class BankAccountRepository
*/
class BankAccountRepository extends BaseRepository
{
/**
* @return string
*/
public function getClassName()
{
return 'App\Models\BankAccount';
}
/**
* @param $accountId
*
* @return $this
*/
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)
->select(
'bank_accounts.public_id',
'banks.name as bank_name',
'bank_accounts.deleted_at',
'banks.bank_library_id'
);
}
/**
* @param $input
*
* @return mixed
*/
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) {
if ( ! isset($data['include']) || ! filter_var($data['include'], FILTER_VALIDATE_BOOLEAN)) {
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;
}
}