mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 20:44:19 +00:00
242 lines
7.8 KiB
PHP
242 lines
7.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Classes\General\Interfaces\Documentable;
|
|
use App\Classes\General\Interfaces\Remarkable;
|
|
use App\Classes\General\Interfaces\Transactionable;
|
|
use App\Classes\General\Traits\LogData;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use Carbon\Carbon;
|
|
use Eloquent;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\Activitylog\Models\Activity;
|
|
|
|
/**
|
|
* App\Models\Transaction
|
|
*
|
|
* @property int $id
|
|
* @property string $owner_type
|
|
* @property int $owner_id
|
|
* @property string $type
|
|
* @property int $issuer
|
|
* @property int $receiver
|
|
* @property int $recipient_bank_account_id
|
|
* @property string|null $payment_method
|
|
* @property string|null $payment_reference
|
|
* @property string $bill_no
|
|
* @property string $amount
|
|
* @property string $original_amount
|
|
* @property int $currency_id
|
|
* @property int $original_currency_id
|
|
* @property string $currency_rate
|
|
* @property string $tax
|
|
* @property string $service_charge
|
|
* @property string|null $expires_on
|
|
* @property int $status
|
|
* @property \Illuminate\Support\Carbon|null $deleted_at
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read Collection|Activity[] $activities
|
|
* @property-read int|null $activities_count
|
|
* @property-read Model|Eloquent $causer
|
|
* @property-read Currency $currency
|
|
* @property-read Collection|Document[] $documents
|
|
* @property-read int|null $documents_count
|
|
* @property-read Collection|Order[] $order
|
|
* @property-read int|null $order_count
|
|
* @property-read Currency $original_currency
|
|
* @property-read Model|Eloquent $owner
|
|
* @property-read Collection|Remark[] $remarks
|
|
* @property-read int|null $remarks_count
|
|
* @property-read Model|Eloquent $subject
|
|
* @property-read Model|Eloquent $target
|
|
* @property-read Collection|TransactionDetail[] $transactionDetails
|
|
* @property-read int|null $transaction_details_count
|
|
* @property-read Collection|Transaction[] $transactions
|
|
* @property-read int|null $transactions_count
|
|
* @method static Builder|Transaction complete()
|
|
* @method static Builder|Transaction inComplete()
|
|
* @method static Builder|Transaction newModelQuery()
|
|
* @method static Builder|Transaction newQuery()
|
|
* @method static \Illuminate\Database\Query\Builder|Transaction onlyTrashed()
|
|
* @method static Builder|Transaction payments()
|
|
* @method static Builder|Transaction query()
|
|
* @method static Builder|Transaction transferred()
|
|
* @method static Builder|Transaction whereAmount($value)
|
|
* @method static Builder|Transaction whereBillNo($value)
|
|
* @method static Builder|Transaction whereCreatedAt($value)
|
|
* @method static Builder|Transaction whereCurrencyId($value)
|
|
* @method static Builder|Transaction whereCurrencyRate($value)
|
|
* @method static Builder|Transaction whereDeletedAt($value)
|
|
* @method static Builder|Transaction whereExpiresOn($value)
|
|
* @method static Builder|Transaction whereId($value)
|
|
* @method static Builder|Transaction whereIssuer($value)
|
|
* @method static Builder|Transaction whereOriginalAmount($value)
|
|
* @method static Builder|Transaction whereOriginalCurrencyId($value)
|
|
* @method static Builder|Transaction whereOwnerId($value)
|
|
* @method static Builder|Transaction whereOwnerType($value)
|
|
* @method static Builder|Transaction wherePaymentMethod($value)
|
|
* @method static Builder|Transaction wherePaymentReference($value)
|
|
* @method static Builder|Transaction whereReceiver($value)
|
|
* @method static Builder|Transaction whereRecipientBankAccountId($value)
|
|
* @method static Builder|Transaction whereServiceCharge($value)
|
|
* @method static Builder|Transaction whereStatus($value)
|
|
* @method static Builder|Transaction whereTax($value)
|
|
* @method static Builder|Transaction whereType($value)
|
|
* @method static Builder|Transaction whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Query\Builder|Transaction withTrashed()
|
|
* @method static \Illuminate\Database\Query\Builder|Transaction withoutTrashed()
|
|
* @mixin Eloquent
|
|
*/
|
|
class Transaction extends AbstractModel implements Documentable, Transactionable, Remarkable
|
|
{
|
|
use SoftDeletes;
|
|
use LogData;
|
|
|
|
protected $casts = [
|
|
'type' => 'int'
|
|
];
|
|
|
|
protected $table = 'transactions';
|
|
|
|
public function owner(): morphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function order(): morphMany
|
|
{
|
|
return $this->morphMany(Order::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function transactions(): MorphMany
|
|
{
|
|
return $this->MorphMany(Transaction::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function documents(): morphMany
|
|
{
|
|
return $this->morphMany(Document::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo
|
|
*/
|
|
public function currency(): BelongsTo
|
|
{
|
|
return $this->BelongsTo(Currency::class, 'currency_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo
|
|
*/
|
|
public function original_currency(): BelongsTo
|
|
{
|
|
return $this->BelongsTo(Currency::class, 'original_currency_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany
|
|
*/
|
|
public function transactionDetails(): HasMany
|
|
{
|
|
return $this->HasMany(TransactionDetail::class, 'transaction_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsToMany
|
|
*/
|
|
public function groups(): BelongsToMany
|
|
{
|
|
return $this->BelongsToMany(Group::class, GroupTransaction::class, 'transaction_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsToMany
|
|
*/
|
|
public function groupsWithTrashed(): BelongsToMany
|
|
{
|
|
return $this->BelongsToMany(Group::class, GroupTransaction::class, 'transaction_id')->withTrashed();;
|
|
}
|
|
|
|
public function convert_original_amount()
|
|
{
|
|
if($this->booking()->first()->fix_currency_id !== 1) {
|
|
$currency_rate = $this->currency()->first()->rates()->where('payment_method_type', $this->payment_method)->first();
|
|
|
|
return number_format($this->original_amount / $currency_rate->selling, 2);
|
|
}
|
|
return $this->original_amount;
|
|
}
|
|
|
|
/**
|
|
* @param Builder $query
|
|
* @return Builder
|
|
*/
|
|
public function scopePayments(Builder $query)
|
|
{
|
|
return $query->whereIn('type', [TransactionType::PAYMENT, TransactionType::TOP_UP]);
|
|
}
|
|
|
|
/**
|
|
* @param Builder $query
|
|
* @return Builder
|
|
*/
|
|
public function scopeInComplete(Builder $query)
|
|
{
|
|
return $query->where(function(Builder $query){
|
|
$query->where(function(Builder $query){
|
|
$query->where('status', ApprovalStatus::PENDING_SUBMISSION)
|
|
->whereDate('expires_on', '>=', Carbon::now());
|
|
})->orWhere(function(Builder $query){
|
|
$query->where('status', ApprovalStatus::PENDING_VERIFICATION);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param Builder $query
|
|
* @return Builder
|
|
*/
|
|
public function scopeComplete(Builder $query)
|
|
{
|
|
return $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
|
}
|
|
|
|
/**
|
|
* @param Builder $query
|
|
* @return Builder
|
|
*/
|
|
public function scopeTransferred(Builder $query)
|
|
{
|
|
return $query->whereIn('status', [ApprovalStatus::COMPLETED]);
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function remarks(): morphMany
|
|
{
|
|
return $this->morphMany(Remark::class, 'owner');
|
|
}
|
|
}
|