<?php
 namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Validation\Rule; use Session; use Validator; use Redirect; class Extra_income_type extends Setup { public function __construct() { parent::__construct(); } public function view(Request $request) { if(check_user_access('view_extra_income_type') === FALSE){ Redirect::to('/')->send(); } $branch_id = active_branch_id(); $extra_income_type = DB::table('extra_income_type')->where('branch',$branch_id); $extra_income_type = $extra_income_type->get(); $extra_income_type = json_decode(json_encode($extra_income_type),true); $this->data["pageData"] = $extra_income_type; $this->data["title"] = print_lang($this->data["app_lang"],'mod_extra_income_type_view_title'); $this->data["pageToLoad"] = "extra_income_type/view.php"; $this->data["activeLink"] = "extra_income_type"; $this->load_view($this->data); } public function add(Request $request) { if(check_user_access('add_extra_income_type') === FALSE){ Redirect::to('/')->send(); } $this->data["title"] = print_lang($this->data["app_lang"],'mod_extra_income_type_add_title'); $this->data["pageToLoad"] = "extra_income_type/add.php"; $this->data["activeLink"] = "extra_income_type"; $this->load_view($this->data); } public function save(Request $request) { $validator = Validator::make($request->request->all(), [ 'name' => 'required', ]); $validator->validate(); $uid = getUniqueId('EXTIT', 'extra_income_type', 'uid'); $db_array = array( 'uid' => $uid, 'branch' => active_branch_id(), 'name' => $request->name, ); insert_table('extra_income_type',$db_array); echo json_encode(array('status' => 'success', 'mood' => 'new', 'message_head' => print_lang($this->data["app_lang"],'mod_extra_income_type_added'), 'message_body' => print_lang($this->data["app_lang"],'mod_extra_income_type_save_successfully'))); } public function edit(Request $request, $uid) { if(check_user_access('edit_extra_income_type') === FALSE){ Redirect::to('/')->send(); } $this->data["editing_data"] = fetch_table_where('extra_income_type','uid',$uid,true); if(!is_array($this->data["editing_data"])){ Redirect::to('/extra-income-type')->send(); } $this->data["title"] = print_lang($this->data["app_lang"],'mod_extra_income_type_edit_title'); $this->data["pageToLoad"] = "extra_income_type/edit.php"; $this->data["activeLink"] = "extra_income_type"; $this->load_view($this->data); } public function update(Request $request, $uid) { $validator = Validator::make($request->request->all(), [ 'name' => 'required', ]); $validator->validate(); $db_array = array( 'name' => $request->name, ); update_table('extra_income_type','uid',$uid,$db_array); update_table('extra_income','type',$uid,['type_name' => $db_array['name']]); echo json_encode(array('status' => 'success', 'mood' => 'update', 'message_head' => print_lang($this->data["app_lang"],'mod_extra_income_type_update'), 'message_body' => print_lang($this->data["app_lang"],'mod_extra_income_type_update_successfully'))); } public function delete($uid) { if(check_user_access('delete_extra_income_type') === FALSE){ Redirect::to('/')->send(); } delete_table('extra_income_type','uid',$uid); echo json_encode(array('status' => 'success', 'mode' => 'deleted')); } }