| Server IP : 103.161.17.216 / Your IP : 216.73.216.1 Web Server : nginx/1.18.0 System : Linux tipsysaigoncharming 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/app.ansachsongkhoe.net/app/ |
Upload File : |
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Events\TransactionPaymentDeleted;
use App\Events\TransactionPaymentUpdated;
class TransactionPayment extends Model
{
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = ['id'];
/**
* Get the phone record associated with the user.
*/
public function payment_account()
{
return $this->belongsTo(\App\Account::class, 'account_id');
}
/**
* Get the transaction related to this payment.
*/
public function transaction()
{
return $this->belongsTo(\App\Transaction::class, 'transaction_id');
}
/**
* Get the user.
*/
public function created_user()
{
return $this->belongsTo(\App\User::class, 'created_by');
}
/**
* Get child payments
*/
public function child_payments()
{
return $this->hasMany(\App\TransactionPayment::class, 'parent_id');
}
/**
* Retrieves documents path if exists
*/
public function getDocumentPathAttribute()
{
$path = !empty($this->document) ? asset('/uploads/documents/' . $this->document) : null;
return $path;
}
/**
* Removes timestamp from document name
*/
public function getDocumentNameAttribute()
{
$document_name = !empty(explode("_", $this->document, 2)[1]) ? explode("_", $this->document, 2)[1] : $this->document ;
return $document_name;
}
public static function deletePayment($payment)
{
//Update parent payment if exists
if (!empty($payment->parent_id)) {
$parent_payment = TransactionPayment::find($payment->parent_id);
$parent_payment->amount -= $payment->amount;
if ($parent_payment->amount <= 0) {
$parent_payment->delete();
event(new TransactionPaymentDeleted($parent_payment));
} else {
$parent_payment->save();
//Add event to update parent payment account transaction
event(new TransactionPaymentUpdated($parent_payment, null));
}
}
$payment->delete();
$transactionUtil = new \App\Utils\TransactionUtil();
if(!empty($payment->transaction_id)) {
//update payment status
$transaction = $payment->load('transaction')->transaction;
$transaction_before = $transaction->replicate();
$payment_status = $transactionUtil->updatePaymentStatus($payment->transaction_id);
$transaction->payment_status = $payment_status;
$transactionUtil->activityLog($transaction, 'payment_edited', $transaction_before);
}
$log_properities = [
'id' => $payment->id,
'ref_no' => $payment->payment_ref_no
];
$transactionUtil->activityLog($payment, 'payment_deleted', null, $log_properities);
//Add event to delete account transaction
event(new TransactionPaymentDeleted($payment));
}
}