/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     // dd($request->all());
     $rules = ['code' => 'required', 'name' => 'required', 'description' => 'required'];
     $this->validate($request, $rules);
     $fee_element = FeeElement::create($request->all());
     // dd($fee_element->id);
     //get the last radix number
     $last_radix_no = ChartOfAccount::where(['id_parent' => 52])->max('radix_no');
     $this_radix_no = $last_radix_no + 1;
     ChartOfAccount::create(['item_title' => $request->name, 'account_code' => $fee_element->id, 'radix_no' => $this_radix_no, 'parent_radix_id' => 52, 'item_level' => 2, 'id_parent' => 52]);
     session()->flash('flash_message', 'Element created');
     return redirect('billing/fee_elements');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('fee_elements')->truncate();
     $tuition = FeeElement::create(array('code' => 'TUI', 'name' => 'Tuition', 'description' => 'Payment for Tuition', 'status_id' => 1));
     //get the last radix number
     $last_radix_no = ChartOfAccount::where(['id_parent' => 52])->max('radix_no');
     $this_radix_no = $last_radix_no + 1;
     ChartOfAccount::create(['item_title' => 'Tuition', 'account_code' => $tuition->id, 'radix_no' => $this_radix_no, 'parent_radix_id' => 52, 'item_level' => 2, 'id_parent' => 52]);
     $medical = FeeElement::create(array('code' => 'MED', 'name' => 'Medical', 'description' => 'Payment for medical expenses', 'status_id' => 1));
     //get the last radix number
     $last_radix_no = ChartOfAccount::where(['id_parent' => 52])->max('radix_no');
     $this_radix_no = $last_radix_no + 1;
     ChartOfAccount::create(['item_title' => 'Medical', 'account_code' => $medical->id, 'radix_no' => $this_radix_no, 'parent_radix_id' => 52, 'item_level' => 2, 'id_parent' => 52]);
     $food = FeeElement::create(array('code' => 'Food', 'name' => 'Food', 'description' => 'Payment for all meals in school', 'status_id' => 1));
     //get the last radix number
     $last_radix_no = ChartOfAccount::where(['id_parent' => 52])->max('radix_no');
     $this_radix_no = $last_radix_no + 1;
     ChartOfAccount::create(['item_title' => 'Food', 'account_code' => $food->id, 'radix_no' => $this_radix_no, 'parent_radix_id' => 52, 'item_level' => 2, 'id_parent' => 52]);
     $devLev = FeeElement::create(array('code' => 'DevLEV', 'name' => 'Development Levy', 'description' => 'Payment for all school development projects', 'status_id' => 1));
     //get the last radix number
     $last_radix_no = ChartOfAccount::where(['id_parent' => 52])->max('radix_no');
     $this_radix_no = $last_radix_no + 1;
     ChartOfAccount::create(['item_title' => 'Development Levy', 'account_code' => $devLev->id, 'radix_no' => $this_radix_no, 'parent_radix_id' => 52, 'item_level' => 2, 'id_parent' => 52]);
     $sch_bus = FeeElement::create(array('code' => 'SchBUS', 'name' => 'School Bus', 'description' => 'Payment for us of the School Bus', 'status_id' => 1));
     //get the last radix number
     $last_radix_no = ChartOfAccount::where(['id_parent' => 52])->max('radix_no');
     $this_radix_no = $last_radix_no + 1;
     ChartOfAccount::create(['item_title' => 'School Bus', 'account_code' => $sch_bus->id, 'radix_no' => $this_radix_no, 'parent_radix_id' => 52, 'item_level' => 2, 'id_parent' => 52]);
     $comp_ict = FeeElement::create(array('code' => 'CompICT', 'name' => 'Computer & ICT', 'description' => 'Payment for use of all Computers and ICT infrastructure', 'status_id' => 1));
     //get the last radix number
     $last_radix_no = ChartOfAccount::where(['id_parent' => 52])->max('radix_no');
     $this_radix_no = $last_radix_no + 1;
     ChartOfAccount::create(['item_title' => 'Computer & ICT', 'account_code' => $comp_ict->id, 'radix_no' => $this_radix_no, 'parent_radix_id' => 52, 'item_level' => 2, 'id_parent' => 52]);
     $pta = FeeElement::create(array('code' => 'PTA', 'name' => 'PTA', 'description' => 'Payment for PTA', 'status_id' => 1));
     //get the last radix number
     $last_radix_no = ChartOfAccount::where(['id_parent' => 52])->max('radix_no');
     $this_radix_no = $last_radix_no + 1;
     ChartOfAccount::create(['item_title' => 'PTA', 'account_code' => $pta->id, 'radix_no' => $this_radix_no, 'parent_radix_id' => 52, 'item_level' => 2, 'id_parent' => 52]);
     $excursion = FeeElement::create(array('code' => 'ECURSION', 'name' => 'Excursion', 'description' => 'Payment for Excursion', 'status_id' => 1));
     //get the last radix number
     $last_radix_no = ChartOfAccount::where(['id_parent' => 52])->max('radix_no');
     $this_radix_no = $last_radix_no + 1;
     ChartOfAccount::create(['item_title' => 'Excursion', 'account_code' => $excursion->id, 'radix_no' => $this_radix_no, 'parent_radix_id' => 52, 'item_level' => 2, 'id_parent' => 52]);
 }
 public function reports_search(Request $request)
 {
     // dd($request);
     $fee_element_id = $request->fee_element_id;
     $search_by = $request->search_by;
     $data['title'] = 'Reports';
     $data['accounts_menu'] = 1;
     $data['coa_elements'] = ChartOfAccount::where(['id_parent' => 52])->lists('item_title', 'account_code');
     $data['search_dates'] = ['0' => 'Select Search Date', '1' => 'Last Week', '2' => 'Last Month', '3' => '3 Months Ago', '4' => '6 Months Ago', '5' => '1 Year Ago'];
     $data['result'] = 1;
     $data['total'] = Helper::reports_total_on_item($fee_element_id, $search_by);
     $data['search_item'] = FeeElement::find($fee_element_id)->first()->name;
     return view('accounts.reports.index', $data);
 }