IMMREX7
<?php
namespace App\Http\Controllers\School;
use Illuminate\Http\Request;
use Auth;
use DB;
use Session;
class NorthDiscountController extends SchoolController {
public function index(Request $request) {
if (!request()->ajax()) {
return view('schools.north.studentlist', compact('students'));
}
$columns = array(
// 0 =>'sNo',
0 => 'photo',
1 => 'ecNo',
2 => 'name',
3 => 'father_name',
4 => 'className',
5 => 'sectionName',
6 => 'mobile',
7 => 'action',
);
$totalData = \App\AdmEntry::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->where('isActive', '=', 'Y')->count();
$totalFiltered = $totalData;
$limit = $request->input('length');
$start = $request->input('start');
$order = $columns[$request->input('order.0.column')];
$dir = $request->input('order.0.dir');
// Get Data according to search value
if (empty($request->input('search.value'))) {
if ($limit == '-1') {
$students = DB::table('students')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->orderBy($order, $dir)
->where('isActive', '=', 'Y')
->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
->get();
} else {
$students = DB::table('students')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->offset($start)
->limit($limit)
->orderBy($order, $dir)
->where('isActive', '=', 'Y')
->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
->get();
}
} else {
$search = $request->input('search.value');
if ($limit == '-1') {
$students = DB::table('students')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->orderBy($order, $dir)
->where('isActive', '=', 'Y')
->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
->where(function ($query) use ($search) {
$query->where(DB::raw('CONCAT(firstName, " ",middleName, " ",lastName)'), 'LIKE', "%{$search}%")
->orWhere('ecNo', 'LIKE', "%{$search}%")
->orWhere('className', 'LIKE', "%{$search}%")
->orWhere('sectionName', 'LIKE', "%{$search}%")
->orWhere('father_fname', 'LIKE', "%{$search}%")
->orWhere('studentDob', 'LIKE', "%{$search}%")
->orWhere('father_mobile', 'LIKE', "%{$search}%");
})
->get();
} else {
$students = DB::table('students')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->offset($start)
->limit($limit)
->orderBy($order, $dir)
->where('isActive', '=', 'Y')
->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
->where(function ($query) use ($search) {
$query->where(DB::raw('CONCAT(firstName, " ",middleName, " ",lastName)'), 'LIKE', "%{$search}%")
->orWhere('ecNo', 'LIKE', "%{$search}%")
->orWhere('className', 'LIKE', "%{$search}%")
->orWhere('sectionName', 'LIKE', "%{$search}%")
->orWhere('father_fname', 'LIKE', "%{$search}%")
->orWhere('studentDob', 'LIKE', "%{$search}%")
->orWhere('father_mobile', 'LIKE', "%{$search}%");
})
->get();
}
$totalFiltered = DB::table('students')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->where('isActive', '=', 'Y')
->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
->where(function ($query) use ($search) {
$query->where(DB::raw('CONCAT(firstName, " ",middleName, " ",lastName)'), 'LIKE', "%{$search}%")
->orWhere('ecNo', 'LIKE', "%{$search}%")
->orWhere('className', 'LIKE', "%{$search}%")
->orWhere('sectionName', 'LIKE', "%{$search}%")
->orWhere('father_fname', 'LIKE', "%{$search}%")
->orWhere('studentDob', 'LIKE', "%{$search}%")
->orWhere('father_mobile', 'LIKE', "%{$search}%");
})
->get()->count();
}
$data = array();
if (!empty($students)) {
$count = 1;
foreach ($students as $var) {
// $nestedData['sNo'] = $count;
$nestedData['photo'] = '<img src="https://online-login.online/storage/schools/' . $var->idSchool . '/students/' . $var->photo . '" height="60">';
$nestedData['ecNo'] = $var->ecNo;
$nestedData['name'] = $var->firstName . " " . $var->middleName . " " . $var->lastName;
$nestedData['father_name'] = $var->father_fname . " " . $var->father_lname;
$nestedData['className'] = $var->className;
$nestedData['sectionName'] = $var->sectionName;
$nestedData['father_mobile'] = $var->father_mobile;
$nestedData['action'] = '<a class="btn btn-warning btn-sm" href="https://online-login.online/school/north/discount/' . $var->idStudent . '/details" target="_blank">Select</a>';
$data[] = $nestedData;
// $count++;
}
}
$json_data = array(
"draw" => intval($request->input('draw')),
"recordsTotal" => intval($totalData),
"recordsFiltered" => intval($totalFiltered),
"data" => $data
);
$students = json_encode($json_data);
return $students;
// $students = \App\AdmEntry::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
// ->get();
// return view('schools.transaction.studentlist', compact('students'));
}
public function getDiscountDetails($id){
$student = \App\AdmEntry::where('idStudent', '=', $id)->first();
$demand = ['' => '--Select--'] + \App\NorthFeeHead::where('idSchool', '=',$student->idSchool)
->where('idFinancialYear', '=', $student->idFinancialYear)
->where('idStudent', '=', $student->idStudent)
->where('isParent', '=', 0)
->where('isActive','=','Y')
->orderBy('idFeehead', 'desc')
->get()->pluck('demandName', 'idFeehead')->toArray();
return view('schools.north.discounts_form', compact( 'student','demand'));
}
public function getFeeDetails($id){
$feeheads= DB::table('northfeeheads')
->join('headers','northfeeheads.idHeader','=','headers.idHeader')
->where('northfeeheads.idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('northfeeheads.idFinancialYear', '=', Session::get('idFinancialYear'))
->where('isParent', '=', $id)
->select('idFeehead','amount','headerName','discount',DB::raw('COALESCE(description, "") as description'))
->orderBy('idFeehead', 'desc')->get();
return json_encode($feeheads);
}
public function addFeeDiscount(Request $request) {
if ($request->ajax()) {
foreach($request->discount as $var){
\App\NorthFeeHead::where('idFeehead', $var['id'])
->update(['discount' => $var['amount_discount'],'description'=>$var['remarks']]);
}
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}else
return response()->json(['success' => "FAILED"], 404, ['app-status' => 'failed']);
}
}
Copyright © 2021 -