Server IP : 103.191.208.50 / Your IP : 216.73.216.53 Web Server : LiteSpeed System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64 User : celkcksm ( 1031) PHP Version : 7.4.33 Disable Function : show_source, system, shell_exec, passthru, popen, exec MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/celkcksm/cms.ncriptech.com/app/Traits/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php namespace App\Traits; use Illuminate\Http\Request; use Illuminate\Support\Str; use App\Models\Transaction; use App\Models\Fee; use Carbon\Carbon; use Auth; use DB; trait FeesStudent { /** * @param Request $request */ public function netAmount($fee_id) { // $fee = Fee::find($fee_id); // Discount Calculation $discount_amount = 0; $today = date('Y-m-d'); if(isset($fee->category)){ foreach($fee->category->discounts->where('status', '1') as $discount){ $availability = \App\Models\FeesDiscount::availability($discount->id, $fee->studentEnroll->student_id); if(isset($availability)){ if($discount->start_date <= $today && $discount->end_date >= $today){ if($discount->type == '1'){ $discount_amount = $discount_amount + $discount->amount; } else{ $discount_amount = $discount_amount + ( ($fee->fee_amount / 100) * $discount->amount); } }} }} // Fine Calculation $fine_amount = 0; if(empty($fee->pay_date) || $fee->due_date < $fee->pay_date){ $due_date = strtotime($fee->due_date); $today = strtotime(date('Y-m-d')); $days = (int)(($today - $due_date)/86400); if($fee->due_date < date("Y-m-d")){ if(isset($fee->category)){ foreach($fee->category->fines->where('status', '1') as $fine){ if($fine->start_day <= $days && $fine->end_day >= $days){ if($fine->type == '1'){ $fine_amount = $fine_amount + $fine->amount; } else{ $fine_amount = $fine_amount + ( ($fee->fee_amount / 100) * $fine->amount); } } }} } } // Net Amount Calculation $net_amount = ($fee->fee_amount - $discount_amount) + $fine_amount; return $net_amount; } /** * @param Request $request */ public function payStudentFee($fee_id, $method) { // $fee = Fee::find($fee_id); // Discount Calculation $discount_amount = 0; $today = date('Y-m-d'); if(isset($fee->category)){ foreach($fee->category->discounts->where('status', '1') as $discount){ $availability = \App\Models\FeesDiscount::availability($discount->id, $fee->studentEnroll->student_id); if(isset($availability)){ if($discount->start_date <= $today && $discount->end_date >= $today){ if($discount->type == '1'){ $discount_amount = $discount_amount + $discount->amount; } else{ $discount_amount = $discount_amount + ( ($fee->fee_amount / 100) * $discount->amount); } }} }} // Fine Calculation $fine_amount = 0; if(empty($fee->pay_date) || $fee->due_date < $fee->pay_date){ $due_date = strtotime($fee->due_date); $today = strtotime(date('Y-m-d')); $days = (int)(($today - $due_date)/86400); if($fee->due_date < date("Y-m-d")){ if(isset($fee->category)){ foreach($fee->category->fines->where('status', '1') as $fine){ if($fine->start_day <= $days && $fine->end_day >= $days){ if($fine->type == '1'){ $fine_amount = $fine_amount + $fine->amount; } else{ $fine_amount = $fine_amount + ( ($fee->fee_amount / 100) * $fine->amount); } } }} } } // Net Amount Calculation $net_amount = ($fee->fee_amount - $discount_amount) + $fine_amount; DB::beginTransaction(); // Update Data $fee->discount_amount = $discount_amount; $fee->fine_amount = $fine_amount; $fee->paid_amount = $net_amount; $fee->pay_date = Carbon::today(); $fee->payment_method = $method; $fee->status = '1'; $fee->updated_by = Auth::guard('web')->user()->id; $fee->save(); // Transaction $transaction = new Transaction; $transaction->transaction_id = Str::random(16); $transaction->amount = $net_amount; $transaction->type = '1'; $transaction->created_by = Auth::guard('web')->user()->id; $fee->studentEnroll->student->transactions()->save($transaction); DB::commit(); return $success = true; } }