PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/app/Http/Controllers/NhifMobController.php

https://bitbucket.org/milleagallo/afyapepe_millie
PHP | 272 lines | 237 code | 34 blank | 1 comment | 6 complexity | 7cf860cd3a5bee22e4d645e6b2a5c17a MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Http\Models\Facility;
  5. use App\Http\Models\Branch;
  6. use App\Http\Models\SubCategory;
  7. use App\Http\Models\Category;
  8. use App\Http\Models\NhifEmployer;
  9. use App\Http\Models\NhifUser;
  10. use App\Http\Models\NhifEmployee;
  11. use App\Http\Models\NhifDependent;
  12. use DB;
  13. class NhifMobController extends Controller {
  14. public function getPredetails() {
  15. $counties = Branch::select('county as name')->groupby('county')->get();
  16. $nearestNhifBranches = Branch::get();
  17. $categories = Category::all();
  18. $subCategories = SubCategory::all();
  19. return json_encode(array(
  20. 'counties' => $counties,
  21. 'branches' => $nearestNhifBranches,
  22. 'categories' => $categories,
  23. 'sub_categories' => $subCategories
  24. ));
  25. }
  26. public function getNhifEmployee(Request $request) {
  27. $id = $request->input('user');
  28. $user = NhifUser::join('nhif_employees', 'nhif_employees.user_id', '=', 'nhif_users.id')->where('nhif_users.afyapepe_user', $id)->first();
  29. return json_encode($user);
  30. }
  31. public function getNhifEmployer(Request $request) {
  32. $id = $request->input('user');
  33. $user = NhifUser::join('nhif_employers', 'nhif_employers.user_id', '=', 'nhif_users.id')->where('nhif_users.afyapepe_user', $id)->first();
  34. return json_encode($user);
  35. }
  36. public function registerUser(Request $request) {
  37. $userJson = $request->input('details');
  38. $user = json_decode($userJson);
  39. $docFile = $request->file('file');
  40. $passport = $request->file('file1');
  41. $type = $request->input('type');
  42. $docPath = uniqid() . '.' . $docFile->getClientOriginalExtension();
  43. $docFile->move(public_path() . '/nhif_documents/', $docPath);
  44. $nhifUser = new NhifUser();
  45. $nhifUser['afyapepe_user'] = $user->afyapepe_user;
  46. $nhifUser['po_box'] = $user->po_box;
  47. $nhifUser['postal_code'] = $user->postal_code;
  48. $nhifUser['postal_address'] = $user->postal_address;
  49. $nhifUser['telephone_number'] = $user->telephone_number;
  50. $nhifUser['email'] = $user->email;
  51. $nhifUser['type'] = $type;
  52. $nhifUser['town'] = $user->town;
  53. $nhifUser['nearest_nhif'] = $user->nearest_nhif;
  54. $nhifUser['id_document'] = $docPath;
  55. $nhifUser->save();
  56. switch($type) {
  57. case 3:
  58. $passportPath = uniqid() . '.' . $docFile->getClientOriginalExtension();
  59. $passport->move(storage_path() . '/nhif_passports/', $passportPath);
  60. NhifEmployee::create([
  61. 'user_id' => $nhifUser->id,
  62. 'employer_code' => $user->employer_code,
  63. 'employer_name' => $user->employer_name,
  64. 'employer_pin' => $user->employer_pin,
  65. 'id_type' => $user->id_type,
  66. 'id_number' => $user->id_number,
  67. 'id_serial_number' => $user->id_serial_number,
  68. 'first_name' => $user->first_name,
  69. 'other_name' => $user->other_name,
  70. 'dob' => $user->afyapepe_user,
  71. 'gender' => $user->gender,
  72. 'marital_status' => $user->marital_status,
  73. 'passport' => $passportPath
  74. ]);
  75. break;
  76. case 2:
  77. $passportPath = uniqid() . '.' . $docFile->getClientOriginalExtension();
  78. $passport->move(storage_path() . '/nhif_passports/', $passportPath);
  79. NhifEmployee::create([
  80. 'user_id' => $nhifUser->id,
  81. 'id_type' => $user->id_type,
  82. 'id_number' => $user->id_number,
  83. 'id_serial_number' => $user->id_serial_number,
  84. 'first_name' => $user->first_name,
  85. 'other_name' => $user->other_name,
  86. 'dob' => $user->afyapepe_user,
  87. 'gender' => $user->gender,
  88. 'marital_status' => $user->marital_status,
  89. 'passport' => $passportPath
  90. ]);
  91. break;
  92. case 1:
  93. $pinPath = uniqid() . '.' . $passport->getClientOriginalExtension();
  94. $passport->move(storage_path() . '/nhif_pins/', $pinPath);
  95. NhifEmployer::create([
  96. 'user_id' => $nhifUser->id,
  97. 'registration_cert_number' => $user->registration_cert_number,
  98. 'organisation_name' => $user->organisation_name,
  99. 'kra_pin' => $user->kra_pin,
  100. 'road' => $user->road,
  101. 'building' => $user->building,
  102. 'no_of_emp' => $user->no_of_emp,
  103. 'business_type' => $user->business_type,
  104. 'sector' => $user->sector,
  105. 'category' => $user->category,
  106. 'sub_category' => $user->sub_category,
  107. 'pin_document' => $pinPath
  108. ]);
  109. break;
  110. }
  111. }
  112. public function limits() {
  113. $data = array(
  114. 'o_nhif_limit' => 200,
  115. 'o_nhif_used' => 100,
  116. 'o_nhif_available' => 100,
  117. 'i_nhif_limit' => 200,
  118. 'i_nhif_used' => 100,
  119. 'i_nhif_available' => 100
  120. );
  121. return json_encode($data);
  122. }
  123. public function statements() {
  124. $data = array(
  125. array(
  126. 'date' => '12 Feb 2017',
  127. 'amount' => 500,
  128. 'status' => 'On Time'
  129. ),
  130. array(
  131. 'date' => '12 Feb 2017',
  132. 'amount' => 500,
  133. 'status' => 'On Time'
  134. ),
  135. array(
  136. 'date' => '12 Feb 2017',
  137. 'amount' => 500,
  138. 'status' => 'On Time'
  139. ),
  140. array(
  141. 'date' => '12 Feb 2017',
  142. 'amount' => 500,
  143. 'status' => 'On Time'
  144. ),
  145. );
  146. return json_encode($data);
  147. }
  148. public function addDependent(Request $request) {
  149. $docFile = $request->file('file');
  150. $passport = $request->file('file1');
  151. $userJson = $request->input('details');
  152. $dependent = json_decode($userJson);
  153. $docPath = "";
  154. $passportPath = "";
  155. if($docFile != null) {
  156. $docPath = uniqid() . '.' . $docFile->getClientOriginalExtension();
  157. $docFile->move(public_path() . '/nhif_documents/', $docPath);
  158. }
  159. if($passport != null) {
  160. $passportPath = uniqid() . '.' . $docFile->getClientOriginalExtension();
  161. $passport->move(storage_path() . '/nhif_passports/', $passportPath);
  162. }
  163. NhifDependent::create([
  164. 'principal' => $dependent->principal,
  165. 'dob' => $dependent->dob,
  166. 'surname' => $dependent->surname,
  167. 'phone' => $dependent->phone,
  168. 'othername' => $dependent->othername,
  169. 'type' => $dependent->code,
  170. 'identification' => $dependent->identification,
  171. 'gender' => $dependent->gender,
  172. 'facility' => $dependent->facility,
  173. 'id_document' => $docPath,
  174. 'passport' => $passportPath
  175. ]);
  176. }
  177. public function getDependents(Request $request) {
  178. $user = $request->input('user');
  179. $data = array();
  180. $dependents = NhifDependent::where('principal', $user)->orderby('type', 'asc')->get();
  181. return json_encode($dependents);
  182. }
  183. public function getDependent(Request $request) {
  184. $user = $request->input('dependent');
  185. $data = array();
  186. $dependent = NhifDependent::where('id', $user)->first();
  187. $data['id'] = $dependent['id'];
  188. $data['principal'] = $dependent['principal'];
  189. $data['dob'] = $dependent['dob'];
  190. $data['type'] = $dependent['type'];
  191. $data['surname'] = $dependent['surname'];
  192. $data['phone'] = $dependent['phone'];
  193. $data['othername'] = $dependent['othername'];
  194. $data['code'] = $dependent['code'];
  195. $data['identification'] = $dependent['identification'];
  196. $data['gender'] = $dependent['gender'];
  197. $data['facility'] = $dependent['facility'];
  198. $data['id_document'] = $dependent['id_document'];
  199. $data['passport'] = $dependent['passport'];
  200. $data['hospital'] = Facility::where('id', '=', $dependent['facility'])->first()['hospital'];
  201. return json_encode($data);
  202. }
  203. public function chooseFacility(Request $request) {
  204. $passport = $request->file('file1');
  205. $passportPath = "";
  206. $userJson = $request->input('details');
  207. $user = json_decode($userJson);
  208. if($passport != null) {
  209. $passportPath = uniqid() . '.' . $passport->getClientOriginalExtension();
  210. $passport->move(storage_path() . '/nhif_passports/', $passportPath);
  211. }
  212. NhifDependent::where('id', $user->name)->update([
  213. 'facility' => $user->id,
  214. 'passport' => $passportPath
  215. ]);
  216. echo $user->id;
  217. }
  218. public function changeFacility(Request $request) {
  219. $userJson = $request->input('details');
  220. $details = json_decode($userJson);
  221. // dd($details);
  222. $from = NhifDependent::where('id', $details->id)->first()['facility'];
  223. $to = $details->facility;
  224. DB::table("nhif.nhif_facility_changes")->insert([
  225. 'from' => $from,
  226. 'to' => $to,
  227. 'user' => $details->id,
  228. 'reasons' => json_encode($details->reasons)
  229. ]);
  230. NhifDependent::where('id', $details->id)->update([
  231. 'facility' => $details->facility,
  232. ]);
  233. }
  234. public function getFacilities() {
  235. $facilities = Facility::orderby('hospital', 'asc')->select('hospital as name', 'id')->get();
  236. return json_encode($facilities);
  237. }
  238. }