where('school_year', $school_year)->where('period', $period)->where('is_manual', 0)->where('payment',0.00)->get(); if (count($currentledgers) > 0) { foreach ($currentledgers as $currentledger) { $currentledger->delete(); } } $deleteledgerduedates = \App\LedgerDueDate::where('idno', $idno)->where('school_year', $school_year)->where('period', $period)->get(); if (count($deleteledgerduedates) > 0) { foreach ($deleteledgerduedates as $deleteledgerduedate) { $deleteledgerduedate->delete(); } } $type_of_account = Input::get("type_of_account"); $program_code = Input::get("program_code"); $academic_type = Input::get("academic_type"); $discount_code = Input::get('discount'); $changestatus = \App\Status::where('idno', $idno)->first(); $changestatus->status = 2; $changestatus->type_of_account = $type_of_account; $changestatus->type_of_discount = $discount_code; $changestatus->save(); if (!is_null($discount_code)) { $discounttype = \App\CtrDiscount::where('discount_code', $discount_code)->first()->discount_type; if ($discounttype == 0) { $discounttf = $this->getdiscountrate('tf', $discount_code); $discountof = $this->getdiscountrate('of', $discount_code); } else if ($discounttype == 1) { $discounttf = $this->getdiscount('tf', $discount_code); } } if ($academic_type == "College") { $tfr = \App\CtrCollegeTuition::where('program_code', $program_code)->where('level', $level)->first(); $tuitionrate = $tfr->per_unit; $otherfee = $this->getOtherFee($idno, $school_year, $period, $level, $program_code, $tuitionrate, $discounttf, $discountof, $discount_code, $discounttype, $type_of_account); $tuitionfee = $this->getCollegeTuition($idno, $school_year, $period, $level, $program_code, $tuitionrate, $discounttf, $discountof, $discount_code, $discounttype, $type_of_account); return view('registrar.assessment.ajax.collegedisplayassessment', compact('reservation', 'deposit', 'idno', 'school_year', 'level', 'period')); } // $tfr = \App\CtrCollegeTuition::where('program_code', $program_code)->where('level', $level)->first(); // $tuitionrate = $tfr->per_unit; // $otherfee = $this->getOtherFee($idno, $school_year, $period, $level, $program_code, $tuitionrate, $discounttf, $discountof, $discount_code, $discounttype, $type_of_account); // $tuitionfee = $this->getCollegeTuition($idno, $school_year, $period, $level, $program_code, $tuitionrate, $discounttf, $discountof, $discount_code, $discounttype, $type_of_account); // return view('registrar.assessment.ajax.collegedisplayassessment', compact('reservation', 'deposit', 'idno', 'school_year', 'level', 'period')); } } function getCollegeTuition($idno, $school_year, $period, $level, $program_code, $tuitionrate, $discounttf, $discountof, $discount_code, $discounttype, $type_of_account) { $grades = \App\GradeCollege::where('idno', $idno)->where('school_year', $school_year)->where('period', $period)->get(); $chartofaccount = \App\ChartOfAccount::where('accounting_name', "Tuition Fee")->first(); if (count($grades) > 0) { $lab = 0; foreach ($grades as $grade) { $lab = $this->getLabCount($lab,$grade->lab,$grade->course_code); if($grade->is_petitioned == 0){ if ($discounttype == 0) { $tobediscount = (($grade->lec * $tuitionrate * $grade->percent_tuition / 100) + (($grade->lab * $tuitionrate * $grade->percent_tuition / 100) * 3)) * ($discounttf / 100); } else if ($discounttype == 1) { $tobediscount = $discounttf / count($grades); } if ($type_of_account != "regular") { if ($grade->is_overload == 0) { $discounttf = $this->getSpecialDiscount($idno, $school_year, $period, $level, $program_code, $tuitionrate, $discounttf, $discountof, $discount_code, $discounttype, $type_of_account); $tobediscount = (($grade->lec * $tuitionrate * $grade->percent_tuition / 100) + (($grade->lab * $tuitionrate * $grade->percent_tuition / 100) * 3)) * ($discounttf / 100); $discount_code = $type_of_account; } else { $tobediscount = 0; $discount_code = ""; } } if ($grade->course_code == "NSTP101" or $grade->course_code == "NSTP102") { $receipt_type = "AR"; } else { $receipt_type = "OR"; } $addledger = new \App\ledger; $addledger->idno = $idno; $addledger->program_code = $program_code; $addledger->level = $level; $addledger->school_year = $school_year; $addledger->period = $period; $addledger->category = "Tuition Fee"; $addledger->description = $grade->course_code; $addledger->receipt_details = "Tuition Fee"; $addledger->receipt_type = $receipt_type; $addledger->accounting_code = $chartofaccount->accounting_code; $addledger->category_switch = "3"; $addledger->amount = (($grade->lec * $tuitionrate * $grade->percent_tuition / 100) + (($grade->lab * $tuitionrate * $grade->percent_tuition / 100) * 3)); $addledger->discount = $tobediscount; $addledger->discount_code = $discount_code; $addledger->save(); $this->getSpecialFee($grade->course_code, $level, $program_code, $school_year, $period, $idno); } } if ($lab > 0) { $this->getLabFee($idno, $school_year, $period, $level, $program_code, $tuitionrate, $discounttf, $discountof, $discount_code, $discounttype, $type_of_account); } } } function getOtherFee($idno, $school_year, $period, $level, $program_code, $tuitionrate, $discounttf, $discountof, $discount_code, $discounttype, $type_of_account) { $otherfees = \App\CtrCollegeOtherFee::where('program_code', $program_code)->where('level', $level)->where('period', $period)->get(); $discountrate = 0; if (count($otherfees) > 0) { foreach ($otherfees as $otherfee) { $addledger = new \App\ledger; $addledger->idno = $idno; $addledger->program_code = $program_code; $addledger->level = $level; $addledger->school_year = $school_year; $addledger->period = $period; $addledger->category = $otherfee->category; $addledger->description = $otherfee->description; $addledger->receipt_details = $otherfee->receipt_details; $addledger->receipt_type = $otherfee->receipt_type; $addledger->accounting_code = $otherfee->accounting_code; $addledger->category_switch = $otherfee->category_switch; $addledger->amount = $otherfee->amount; $addledger->discount = $otherfee->amount * ($discountof / 100); $addledger->discount_code = $discount_code; $addledger->save(); } } } function getSpecialFee($course_code, $level, $program_code, $school_year, $period, $idno) { $fees = \App\CtrSpecialFee::where('course_code', $course_code)->get(); if (count($fees) > 0) { foreach ($fees as $fee) { $addledger = new \App\ledger; $addledger->idno = $idno; $addledger->program_code = $program_code; $addledger->level = $level; $addledger->school_year = $school_year; $addledger->period = $period; $addledger->category = $fee->category; $addledger->description = $fee->description . "/" . $fee->course_code; $addledger->receipt_details = $fee->receipt_details; $addledger->receipt_type = "OR"; $addledger->accounting_code = $fee->accounting_code; $addledger->category_switch = $fee->category_switch; $addledger->amount = $fee->amount; $addledger->save(); } } } function getLabCount($count,$lab,$code){ $data = 0; $check = \App\CtrSpecialFee::where('course_code',$code)->first(); //if special fee no lab fee if(count($check) == 0){ $data = $count + $lab; } else{ $data = $count; } return $data; } function getdiscountrate($type, $discount_code) { if ($type == 'tf') { return \App\CtrDiscount::where('discount_code', $discount_code)->first()->tuition_fee; } elseif ($type == 'of') { return \App\CtrDiscount::where('discount_code', $discount_code)->first()->other_fee; } } function getdiscount($type, $discount_code) { if ($type == 'tf') { return \App\CtrDiscount::where('discount_code', $discount_code)->first()->amount; } } function getLabFee($idno, $school_year, $period, $level, $program_code, $tuitionrate, $discounttf, $discountof, $discount_code, $discounttype, $type_of_account) { // if($level != '5th' && $program_code != 'BSPT'){ $labfee = \App\CtrLabFee::where('program_code', $program_code)->where('level', $level) ->where('period', $period)->first(); if(count($labfee) > 0){ $addledger = new \App\ledger; $addledger->idno = $idno; $addledger->program_code = $program_code; $addledger->level = $level; $addledger->school_year = $school_year; $addledger->period = $period; $addledger->category = $labfee->category; $addledger->description = $labfee->description; $addledger->receipt_details = $labfee->receipt_details; $addledger->receipt_type = $labfee->receipt_type; $addledger->accounting_code = $labfee->accounting_code; $addledger->category_switch = $labfee->category_switch; $addledger->amount = $labfee->amount; $addledger->discount = $labfee->amount * $discountof / 100; $addledger->discount_code = $discount_code; $addledger->save(); } } function getSpecialDiscount($idno, $school_year, $period, $level, $program_code, $tuitionrate, $discounttf, $discountof, $discount_code, $discounttype, $type_of_account) { if ($level == '1st') { $otherfees = \App\CtrCollegeOtherFee::where('program_code', $program_code)->where('level', $level)->where('period', $period)->get(); } else { $otherfees = \App\CtrCollegeOtherFee::where('program_code', $program_code)->where('level', $level)->where('period', $period)->where('category_switch', 1)->get(); } $otherf = \App\CtrCollegeOtherFee::where('program_code', $program_code)->where('level', $level)->where('period', $period)->where('category_switch', 2)->get(); $grades = \App\GradeCollege::where('idno', $idno)->where('school_year', $school_year)->where('period', $period)->get(); $specialfee = \App\CtrSpecialDiscount::where('discount_code', $type_of_account)->where('program_code', $program_code)->where('level', $level)->first()->amount; $totalotherfees = 0; $totaltuition = 0; $totallab = 0; $totalother = 0; $totalunits = 0; $lab = 0; $anuu = ""; foreach ($otherf as $ofee) { //$totalother = $totalother + $ofee->amount; } foreach ($otherfees as $of) { $totalotherfees = $totalotherfees + $of->amount; } foreach ($grades as $grade) { $lab = $lab + $grade->lab; if($grade->is_overload == 0 && $grade->is_petitioned == 0){ $totaltuition += (($grade->lec * $tuitionrate * $grade->percent_tuition / 100) + (($grade->lab * $tuitionrate * $grade->percent_tuition / 100) * 3)); $totalunits += $grade->lab + $grade->lec; } } //OVERLOAD UNITS // $reg_units = \App\CtrRegularUnits::where('course_code', $program_code)->where('level', $level) // ->where('period', $period)->first(); // $overload = $totalunits - $reg_units->reg_units; // $totaloverload = $overload * $tuitionrate; // //OTHER FEE NG LAB if ($lab > 0) { $labfee = \App\CtrLabFee::where('program_code', $program_code)->where('level', $level) ->where('period', $period)->first(); $totallab = $labfee->amount; } $amountobe = $specialfee - ($totalotherfees + $totallab + $totalother); $discounttf = (($totaltuition - $amountobe) / $totaltuition) * 100; //dd($discounttf,($grandtotal - $specialfee),$grandtotal); return $discounttf; } }