/** * Run the database seeds. * * @return void */ public function run() { DB::table('discount_policies')->truncate(); DiscountPolicy::create(['discount_name' => 'Parent']); DiscountPolicy::create(['discount_name' => 'Staff']); DiscountPolicy::create(['discount_name' => 'Scholarship']); }
/** * @param int * @param string * @return double */ public static function calculateStaffDiscount($student_id, $fee_schedule_code) { //initialise discount to zero $discount = 0; //get stuednt info $student = Student::find($student_id); //get the staff discount value for this fee schedule $staff_discount = self::getStaffDiscountAmount($fee_schedule_code); //get details of staff discount policy $discount_policy = DiscountPolicy::where('discount_name', 'Parent')->first(); //get all wards with same staff $same_staff = Student::select('id')->where('staff_id', $student->staff_id)->get(); //divide staff discount accross all wards that have thesame staff if ($discount_policy->all_wards == 1) { $discount += $staff_discount / count($same_staff); return $discount; } //dont divide staff discount accross all wards that have thesame staff if ($discount_policy->dont_divide == 1) { $discount += $staff_discount; return $discount; } if ($discount_policy->all_wards == 0) { $student_ids = []; foreach ($same_staff as $stud) { $student_ids[] = $stud->id; } sort($student_ids); foreach ($student_ids as $key => $student_id) { if ($key == $discount_policy->ward_to_deduct - 1) { $ward_to_deduct = $student_id; } } if ($ward_to_deduct == $student->id) { $discount += $staff_discount; } return $discount; } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function bill_class($fee_schedule_code) { // dd($fee_schedule_code); $table = 'fee_sch_' . session()->get('current_session') . '_' . session()->get('current_term'); $fee_schedule = DB::table($table)->where('fee_schedule_code', $fee_schedule_code)->first(); $amount = DB::table($table)->where('fee_schedule_code', $fee_schedule_code)->sum('amount'); $students = Student::where('class_id', $fee_schedule->class_id)->get(); $school = School::find(1); //get all studenta ids who are eligible for the parent discount if ($school->parent_discount == 1) { $children_number = DiscountPolicy::find(1)->children_number; if ($children_number == null) { session()->flash('flash_message', 'Please, set the parent discount values. Go to Billing-> Discount Policies.'); return redirect()->back(); } $parent_discount_eligible = Helper::getParentDiscountEligibles(); sort($parent_discount_eligible); } // dd($parent_discount_eligible); foreach ($students as $student) { $discount = 0; //get parent discount if ($school->parent_discount == 1) { if (in_array($student->id, $parent_discount_eligible)) { $discount = Helper::calculateParentDiscount($student->id, $fee_schedule_code); // dd($discount); } } //calculate total amount due to be paid $total = $amount - $discount; try { \DB::table('invoices_' . \Session::get('current_session') . '_' . \Session::get('current_term'))->insert(['student_id' => $student->id, 'fee_schedule_code' => $fee_schedule_code, 'invoice_number' => str_replace('-', '', $fee_schedule_code) . str_pad($student->id, 3, '0', STR_PAD_LEFT), 'amount' => $amount, 'discount' => $discount, 'balance' => Helper::getStudentCurrentBalance($student->id), 'total' => $total]); } catch (\Illuminate\Database\QueryException $e) { $errorCode = $e->errorInfo[1]; if ($errorCode == 1062) { session()->flash('flash_message', 'Hey, these guys have been invoiced'); return \Redirect::back(); } } } //change the status of the fee schedule after billing class DB::table($table)->where('fee_schedule_code', $fee_schedule_code)->update(['status_id' => 8]); return redirect()->to('billing/invoices'); }
public function update_staff_policy(Request $request) { // dd($request); $discountPolicy = DiscountPolicy::find(2); $discountPolicy->children_number = $request->children_number; $discountPolicy->all_wards = $request->all_wards; $discountPolicy->dont_divide = $request->dont_divide; $discountPolicy->type = $request->type; $discountPolicy->discount_duration = $request->discount_duration; $discountPolicy->ward_to_deduct = $request->ward_to_deduct; $discountPolicy->percentage_value = $request->percentage_value; $discountPolicy->affected_elements = json_encode($request->affected_elements); $discountPolicy->sum_value = $request->sum_value; $discountPolicy->save(); return redirect()->back(); }