Skip to content

Commit

Permalink
feat: allow open account balance
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusantguerrero committed Feb 2, 2023
1 parent 8b50c5d commit bd6819c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/Models/Core/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;

Expand Down Expand Up @@ -213,4 +214,29 @@ public static function setNumber($account)
$account->number = $number + 1;
}
}

public function openBalance($amount, $type = 1, $counterAccountId = null) {
$formData = [
'account_id' => $this->id,
'team_id' => $this->team_id,
'user_id' => $this->user_id,
'date' => Carbon::now()->format('Y-m-d H:i:s'),
'payee_id' => 'new',
'payee_label' => $this->user->name,
'currency_code' => $this->currency_code ?? "DOP",
'counter_account_id' => $counterAccountId ?? Account::guessAccount($this, ['opening_balance_capital', 'business_owner_contribution']),
'description' => 'Starting Balance',
'direction' => $type == 1 ? Transaction::DIRECTION_DEBIT : Transaction::DIRECTION_CREDIT,
'total' => $amount,
'items' => [],
'status' => Transaction::STATUS_VERIFIED,
'metaData' => json_encode([
"resource_id" => "SYSTEM:$this->id",
"resource_origin" => 'SYSTEM',
"resource_type" => 'transaction',
])
];

Transaction::createTransaction($formData);
}
}
3 changes: 2 additions & 1 deletion src/Models/Core/Payee.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ public static function createContactAccount($payee)
$clientTrustType = AccountDetailType::where([
'name' => 'client_trust_account',
])->first();

$account = Account::create([
"team_id" => $payee->team_id,
"user_id" => $payee->user_id,
"display_id" => Str::slug($accountName),
"name" => $accountName,
"account_detail_type_id" => $clientTrustType->id,
"account_detail_type_id" => $clientTrustType?->id ?? 1,
"currency_code" => "DOP"
]);
return $account->id;
Expand Down

0 comments on commit bd6819c

Please sign in to comment.