· 5 years ago · Aug 17, 2020, 09:16 AM
1<?php
2
3namespace App\Http\Controllers\Admin;
4
5use App\AdblCbsResponse;
6use App\AdblCountry;
7use App\AdblDistrict;
8use App\AdblGender;
9use App\AdblLocalGovt;
10use App\AdblLocLegIssAut;
11use App\AdblMaritalStatus;
12use App\AdblState;
13use App\ConfigAccountStatus;
14use App\ConfigAccountType;
15use App\ConfigBankBranch;
16use App\ConfigSetting;
17use App\CustomerAccountStatus;
18use App\CustomerDocument;
19use App\CustomerFamilyInfo;
20use App\CustomerInfo;
21use App\CustomerAccountCompletedStep;
22use App\Customerkycdetail;
23use App\FixedDepositCustomer;
24use App\Mail\GeneralMail;
25use App\Zone;
26use App\District;
27use App\Http\Controllers\Controller;
28use App\User;
29use Illuminate\Support\Facades\Mail;
30use Validator, Request as Input, DB, DateTime, Auth, Session, Form, PDF, Excel, File;
31use App\Exports\ApplicantExport;
32use App\Exports\KycExport;
33
34
35class ApplicantController extends Controller
36{
37
38 public function getList()
39 {
40
41 $customers = CustomerInfo::listApplicants(Input::get('status_id'), Input::get('account_type_id'), Input::get('reference_code'), Input::get('startdate'), Input::get('enddate'), '', Input::get('bank_branch_id'));
42 // $customers->setPath('list');
43 // dd(Auth::User());
44 $statuses = ConfigAccountStatus::all()->pluck('name', 'id')->prepend('All Statuses');
45 $account_types = ConfigAccountType::all()->pluck('name', 'id')->prepend('All Account Types');
46 $branch = ConfigBankBranch::all()->pluck('location', 'id')->prepend('All Bank');
47 if (Input::get('excel') && Input::get('excel') == 1) {
48
49
50 $customers = CustomerInfo::listApplicants(Input::get('status_id'), Input::get('account_type_id'), Input::get('reference_code'), Input::get('startdate'), Input::get('enddate'), 'excel', Input::get('bank_branch_id'));
51
52// return view('admin.applicant.exportexcel', ['customers' => $customers]);
53 return Excel::download(new ApplicantExport($customers), 'applicant_' . date("Y-m-d h:i:sa") . '.xlsx');
54 // echo 'excel export';die;
55 } else {
56 return view('admin.applicant.list')->with(array('applicants' => $customers, 'status_select' => $statuses, 'account_type_select' => $account_types, 'branch_select' => $branch));
57 }
58 }
59
60 public function getFixedList()
61 {
62 ini_set('memory_limit', '-1');
63 ini_set('max_execution_time', '30000');
64 $query = FixedDepositCustomer::with('scheme');
65
66 if(request()->has('status_id') && request('status_id') != ''){
67 if(request('status_id') == 0)
68 $query->where('is_active', 0);
69 elseif(request('status_id') == 1)
70 $query->where('is_active', 1);
71 else
72 $query->where('is_rejected', 1);
73 }
74
75 if(request('bank_branch_id') && request('bank_branch_id') != ''){
76 $query->where('config_bank_branch_id', request('bank_branch_id'));
77 }
78
79 if(request('scheme_id') && request('scheme_id') != ''){
80 $query->where('fixed_deposit_scheme_id', request('scheme_id'));
81 }
82
83 if(request('amount_condition') && request('amount_condition') != ''){
84 if(request('amount_condition') == 1) {
85 $query->where('fd_amount', '<', request('amount'));
86 }
87 if(request('amount_condition') == 2) {
88 $query->where('fd_amount', request('amount'));
89 }
90 if(request('amount_condition') == 3) {
91 $query->where('fd_amount', '>', request('amount'));
92 }
93 }
94
95
96 $userdata = User::find(auth()->user()->id);
97 $branch = ConfigBankBranch::find($userdata->branch_id);
98 if (empty($branch)) {
99
100 if($userdata->province_id != NULL || $userdata->province_id != ''){
101
102 $provinces = \Helper::getProvinces();
103
104 $branch_ids = ConfigBankBranch::where('name', $provinces[$userdata->province_id])->pluck('id')->toArray();
105
106 $query->whereIn('bank_branch_id', $branch_ids);
107 }else {
108 echo 'You are not assigned to any branch';
109 die;
110 }
111 } else {
112 if ($branch->id == 1) {
113 } else {
114 $query->where('bank_branch_id', $branch->id);
115 }
116 // dd($branch);
117 }
118
119 $data['applicants'] = $query->whereNull('deleted_at')->get();
120 $data['scheme_select'] = ConfigAccountType::where('type', '3')->pluck('name', 'id')->toArray();
121 $data['branch_select'] = ConfigBankBranch::pluck('location', 'id')->toArray();
122
123
124 if (Input::get('excel') && Input::get('excel') == 1) {
125 $customers = $query->whereNull('deleted_at')->get();
126
127// return view('admin.applicant.export_fixed', ['customers' => $customers]);
128 return Excel::download(new ApplicantExport($customers), 'applicant_' . date("Y-m-d h:i:sa") . '.xlsx');
129 // echo 'excel export';die;
130 } else {
131 return view('admin.applicant.fixed', $data);
132 }
133 }
134
135 public function getKyclist()
136 {
137 $query = Customerkycdetail::where('status', '0');
138 if (Input::get('mobile_no') != null) {
139 $query->where('mobile_no', 'like', '%' . Input::get('mobile_no') . '%');
140 }
141 if (Input::get('orgkey') != null) {
142 $query->where('orgkey', 'like', '%' . Input::get('orgkey') . '%');
143 }
144 if (Input::get('email') != null) {
145 $query->where('email', 'like', '%' . Input::get('email') . '%');
146 }
147
148 if (Input::get('excel') && Input::get('excel') == 1) {
149 $customerkycdetail = $query->get();
150 // dd($customerkycdetail);
151
152 foreach ($customerkycdetail as $key => $value) {
153 $value->status = 1;
154 $value->save();
155 }
156 // $customers = CustomerInfo::listApplicants(Input::get('status_id'), Input::get('account_type_id'), Input::get('reference_code'), Input::get('startdate'), Input::get('enddate'),'excel');
157
158 // return view('admin.applicant.exportexcel', ['customers' => $customers]);
159 return Excel::download(new KycExport($customerkycdetail), 'Kycexport_' . date("Y-m-d h:i:sa") . '.xlsx');
160 // echo 'excel export';die;
161 } else {
162 $customerkycdetail = $query->paginate();
163 return view('admin.applicant.kyclist')->with(array('customerkycdetails' => $customerkycdetail));
164 }
165 // dd($customerkycdetail);
166
167 }
168
169 public function getKycexportedlist()
170 {
171 $query = Customerkycdetail::where('status', '1');
172 if (Input::get('mobile_no') != null) {
173 $query->where('mobile_no', 'like', '%' . Input::get('mobile_no') . '%');
174 }
175 if (Input::get('orgkey') != null) {
176 $query->where('orgkey', 'like', '%' . Input::get('orgkey') . '%');
177 }
178 if (Input::get('email') != null) {
179 $query->where('email', 'like', '%' . Input::get('email') . '%');
180 }
181
182 if (Input::get('excel') && Input::get('excel') == 1) {
183 $customerkycdetail = $query->get();
184 // dd($customerkycdetail);
185
186 foreach ($customerkycdetail as $key => $value) {
187 $value->status = 1;
188 $value->save();
189 }
190 // $customers = CustomerInfo::listApplicants(Input::get('status_id'), Input::get('account_type_id'), Input::get('reference_code'), Input::get('startdate'), Input::get('enddate'),'excel');
191
192 // return view('admin.applicant.exportexcel', ['customers' => $customers]);
193 return Excel::download(new KycExport($customerkycdetail), 'Kycexport_' . date("Y-m-d h:i:sa") . '.xlsx');
194 // echo 'excel export';die;
195 } else {
196 $customerkycdetail = $query->paginate();
197 return view('admin.applicant.kycexportedlist')->with(array('customerkycdetails' => $customerkycdetail));
198 }
199 // dd($customerkycdetail);
200
201 }
202
203 /*
204 * Change status
205 * @param : int $customer_info_id
206 * @param : inte $status_id
207 */
208 public function changeStatus($customer_info_id)
209 {
210
211 // if(Auth::User()->user_type_id=="2") {
212 // die("No Access");
213 // }
214 // $old_status = CustomerAccountStatus::findByCustomerInfoId($customer_info_id);
215
216 // $old_status->deleted = \Settings::getCurrentDateTime();
217 // $old_status->save();
218
219 // $customer_status = new CustomerAccountStatus();
220 // $customer_status->customer_info_id = $customer_info_id;
221 // $customer_status->config_account_status_id = $status_id;
222 // $customer_status->save();
223 $customer = CustomerInfo::find($customer_info_id);
224 $statuses = ConfigAccountStatus::changeableStatus()->pluck('name', 'id');
225
226
227 if ($customer->currentStatus->config_account_status_id != 3) {
228 unset($statuses['6']);
229 } else {
230 unset($statuses['3']);
231 }
232
233 // print_r($statuses); die();
234 // $statuses = $statuses->lists('name', 'id');
235 $statuses->prepend('Status', '');
236
237 return view('admin.applicant.changestatus')->with(array('status_select' => $statuses, 'customer_info' => $customer));
238
239
240 // return redirect()->route('adbladmin.applicant.list');
241 }
242
243 /*
244 * post status
245 * @param : int $customer_info_id
246 */
247 public function postChangeStatus($customer_info_id)
248 {
249
250 try {
251 $validation = Validator::make(Input::all(), array(
252
253 'status' => 'required',
254// 'account_no' => 'required_if:status,3|unique:customer_infos,account_no',
255// 'client_code' => 'required_if:status,3|unique:customer_infos,client_code',
256
257 'adbl_industry_id' => 'required_if:status,3',
258 'adbl_sector_id' => 'required_if:status,3',
259 'adbl_dept_acct_officer_id' => 'required_if:status,3',
260 'adbl_target_id' => 'required_if:status,3',
261 'adbl_customer_status_id' => 'required_if:status,3',
262 'adbl_cal_risk_class_id' => 'required_if:status,3',
263 'adbl_manual_risk_class_id' => 'required_if:status,3|same:adbl_cal_risk_class_id',
264 'adbl_loc_kyc_form_id' => 'required_if:status,3',
265
266 ), array(
267 'status.required' => 'Status required',
268// 'account_no.required_if' => 'Account no required for approved status',
269// 'client_code.required_if' => 'Client code required for approved status',
270 'adbl_industry_id.required_if' => 'Industry required for approved status',
271 'adbl_sector_id.required_if' => 'Sector required for approved status',
272 'adbl_dept_acct_officer_id.required_if' => 'Account Officer required for approved status',
273 'adbl_target_id.required_if' => 'Target required for approved status',
274 'adbl_customer_status_id.required_if' => 'Customer Status required for approved status',
275 'adbl_cal_risk_class_id.required_if' => 'Cal Risk required for approved status',
276 'adbl_manual_risk_class_id.required_if' => 'Manual Risk required for approved status',
277 'adbl_loc_kyc_form_id.required_if' => 'Kyc Form required for approved status',
278
279 ));
280
281 $customer_info = CustomerInfo::find($customer_info_id);
282
283 if ($validation->passes()) {
284
285 $input = array_filter(Input::except('relation'), 'strlen');
286 // echo $input['status'];die;
287
288 if ($input['status'] == '3') {
289 self::wholeApprovedProcess($customer_info_id);
290 } else {
291
292 $old_status = CustomerAccountStatus::findByCustomerInfoId($customer_info_id);
293 if ($old_status) {
294 $old_status->delete();
295 }
296
297 $customer_status = new CustomerAccountStatus();
298 $customer_status->customer_info_id = $customer_info_id;
299 $customer_status->config_account_status_id = $input['status'];
300 (isset($input['remarks'])) ? $customer_status->remarks = $input['remarks'] : "";
301 $customer_status->save();
302
303
304 Session::flash('class', 'alert alert-success');
305 Session::flash('message', 'Status successfully updated');
306 return redirect()->route('adbladmin.applicant.list');
307
308 }
309
310 }
311
312 return redirect()->back()->withInput()->withErrors($validation);
313 } catch (\Exception $e) {
314 Session::flash('class', 'alert alert-danger');
315 Session::flash('message', 'Sorry there was some technical issue during the customer approve process.');
316 return redirect()->back();
317 }
318 }
319
320
321 public function wholeApprovedProcess($customer_info_id)
322 {
323
324 $cus_fields = request()->only(['adbl_industry_id', 'adbl_sector_id', 'adbl_dept_acct_officer_id',
325 'adbl_target_id', 'adbl_customer_status_id', 'adbl_cal_risk_class_id', 'adbl_manual_risk_class_id',
326 'adbl_loc_kyc_form_id', 'old_customer_id']);
327
328
329 CustomerInfo::where('id', $customer_info_id)->update($cus_fields);
330
331 $customer_info = CustomerInfo::find($customer_info_id);
332
333 $cus_family_fields = (request()->only('relation'))['relation'];
334
335 CustomerFamilyInfo::where('customer_info_id', $customer_info->id)->update($cus_family_fields);
336
337
338 if ($customer_info->cbs_failure == '2') {
339 $cus_check_string = self::getCustomerCheckFields($customer_info);
340
341 $cus_check_request = ['customer_info_id' => $customer_info->id,
342 'first_api_request' => $cus_check_string];
343
344 $cusCheckRecord = AdblCbsResponse::insertGetId($cus_check_request);
345 $cus_check_response = self::callCusAPI($customer_info->unique_string);
346
347 echo $cus_check_string;
348
349 echo "<br>";
350
351 echo $cus_check_response['output'];
352
353 if (!preg_match('/No records were found/', $cus_check_response['output']) && !preg_match('/OFSERROR_TIMEOUT/', $cus_check_response['output'])) {
354
355
356 AdblCbsResponse::where('id', $cusCheckRecord)->update(['first_api_response' => $cus_check_response['output'], 'first_api_status' => 1]);
357 CustomerInfo::where('id', $customer_info->id)->update(['cbs_success' => 1, 'cbs_failure' => '0']);
358 Session::flash('class', 'alert alert-success');
359 Session::flash('message', 'CBS entry is successful. Please press CREATE KYC ENTRY for succesful account creation.');
360 return true;
361 }
362 }
363
364
365 $cbs_fields_string = self::getCBSFields($customer_info);
366
367 $cbs_request = ['customer_info_id' => $customer_info->id,
368 'first_api_request' => $cbs_fields_string];
369
370 $cbsRecord = AdblCbsResponse::insertGetId($cbs_request);
371 $cbs_response = self::callCBSAPI($customer_info->unique_string);
372
373 AdblCbsResponse::where('id', $cbsRecord)->update(['first_api_response' => $cbs_response['output'], 'first_api_status' => $cbs_response['status']]);
374
375
376 if ($cbs_response['status'] === '1') {
377
378 CustomerInfo::where('id', $customer_info->id)->update(['cbs_success' => '1', 'cbs_failure' => '0']);
379 Session::flash('class', 'alert alert-success');
380 Session::flash('message', 'CBS entry is successful. Please press CREATE KYC ENTRY for succesful account creation.');
381
382 } else if ($cbs_response['status'] === '-1') {
383
384 CustomerInfo::where('id', $customer_info->id)->update(['cbs_failure' => '-1']);
385 $error = explode(',', $cbs_response['output']);
386 if ($error) {
387 unset($error[0]);
388 $custom_error = implode(',', $error);
389 }
390 Session::flash('class', 'alert alert-danger');
391 Session::flash('message', 'Sorry CBS entry was failure. Detail : ' . $custom_error);
392
393 } else if ($cbs_response['status'] === 'd') {
394
395 $customer_info->cbs_failure = '2';
396 $customer_info->save();
397
398 $cus_check_string = self::getCustomerCheckFields($customer_info);
399
400 $cus_check_request = ['customer_info_id' => $customer_info->id,
401 'first_api_request' => $cus_check_string];
402
403 $cusCheckRecord = AdblCbsResponse::insertGetId($cus_check_request);
404 $cus_check_response = self::callCusAPI($customer_info->unique_string);
405
406
407 if (!preg_match('/No records were found/', $cus_check_response['output']) && !preg_match('/OFSERROR_TIMEOUT/', $cus_check_response['output'])) {
408 AdblCbsResponse::where('id', $cusCheckRecord)->update(['first_api_response' => $cus_check_response['output'], 'first_api_status' => 1]);
409 CustomerInfo::where('id', $customer_info->id)->update(['cbs_success' => 1, 'cbs_failure' => '0']);
410 Session::flash('class', 'alert alert-success');
411 Session::flash('message', 'CBS entry is successful. Please press CREATE KYC ENTRY for succesful account creation.');
412 } else {
413 AdblCbsResponse::where('id', $cusCheckRecord)->update(['first_api_response' => $cus_check_response['output'], 'first_api_status' => 0]);
414 Session::flash('class', 'alert alert-danger');
415 Session::flash('message', 'Sorry CBS entry was failure. Please try again');
416 }
417
418
419 } else {
420 $customer_info->cbs_failure = '2';
421 $customer_info->save();
422 AdblCbsResponse::where('id', $cusCheckRecord)->update(['first_api_response' => $cus_check_response['output'], 'first_api_status' => 0]);
423 Session::flash('class', 'alert alert-danger');
424 Session::flash('message', 'Sorry CBS entry was failure. Please try again');
425 }
426
427
428 }
429
430 public function confirmkyc($customer_info_id)
431 {
432 $customer_info = CustomerInfo::find($customer_info_id);
433 $kyc_fields_string = self::getKYCFields($customer_info);
434
435 $cbsRecord = AdblCbsResponse::where('customer_info_id', $customer_info_id)->orderBy('id', 'desc')->value('id');
436 AdblCbsResponse::where('id', $cbsRecord)->update(['second_api_request' => $kyc_fields_string]);
437
438 $kyc_response = self::callKYCAPI($customer_info->unique_string);
439
440 AdblCbsResponse::where('id', $cbsRecord)->update(['second_api_response' => $kyc_response['output'], 'second_api_status' => $kyc_response['status']]);
441 if ($kyc_response['status'] == 1 || preg_match('/FIELD ALREADY STORED IN CONCATFILE/', $kyc_response['output']) || preg_match('/ALREADY STORED IN/', $kyc_response['output'])) {
442
443 /*
444 * Fetching Customer Info Again 3rd Api Begin
445 *
446 */
447
448 if (preg_match('/FIELD ALREADY STORED IN CONCATFILE/', $kyc_response['output']) || preg_match('/ALREADY STORED IN/', $kyc_response['output'])) {
449 $acc_fetch_string = self::getAccFetchString($customer_info);
450
451 $cbsRecord = AdblCbsResponse::where('customer_info_id', $customer_info_id)->orderBy('id', 'desc')->value('id');
452 AdblCbsResponse::where('id', $cbsRecord)->update(['second_api_request' => $acc_fetch_string]);
453
454 $acc_fetch_response = self::callKYCAPI($customer_info->unique_string);
455
456 AdblCbsResponse::where('id', $cbsRecord)->update(['second_api_response' => $acc_fetch_response['output'], 'second_api_status' => $acc_fetch_response['status']]);
457
458 if (!preg_match('/No records were found that matched the selection criteria/', $acc_fetch_response['output'])) {
459
460
461 $exploded_response = explode(',', $acc_fetch_response['output']);
462
463 if (isset($exploded_response[2])) {
464 $exp_response = explode('"', $exploded_response[2]);
465
466 $final_result = [];
467
468 for ($i = 0; $i < count($exp_response); $i++) {
469 $replaced_item = str_replace(' ', '', $exp_response[$i]);
470 $replaced_item = trim(preg_replace('/\t+/', '', $exp_response[$i]));
471 $replaced_item = trim(preg_replace('/\n+/', '', $exp_response[$i]));
472 if ($replaced_item != '')
473 $final_result[] = $replaced_item;
474 };
475
476 if (isset($final_result[1])) {
477 $customer_info->kyc_success = 1;
478 $customer_info->account_no = $final_result[1];
479 $customer_info->save();
480 self::callAfterKycSuccess($customer_info_id);
481
482 Session::flash('class', 'alert alert-success');
483 Session::flash('message', 'Status successfully updated');
484
485 return redirect()->route('adbladmin.applicant.changestatus', $customer_info_id);
486 } else {
487 $customer_info->kyc_failure = 1;
488 $customer_info->save();
489 Session::flash('class', 'alert alert-danger');
490 Session::flash('message', 'Sorry there was some technical issue. Please try submitting the button again.');
491 return redirect()->route('adbladmin.applicant.changestatus', $customer_info_id);
492 }
493 } else {
494 $customer_info->kyc_failure = 1;
495 $customer_info->save();
496 Session::flash('class', 'alert alert-danger');
497 Session::flash('message', 'Sorry there was some technical issue. Please try submitting the button again.');
498 return redirect()->route('adbladmin.applicant.changestatus', $customer_info_id);
499 }
500
501
502 } else {
503 $customer_info->kyc_failure = 1;
504 $customer_info->save();
505 Session::flash('class', 'alert alert-danger');
506 Session::flash('message', 'Sorry there was some technical issue. Please try submitting the button again.');
507 return redirect()->route('adbladmin.applicant.changestatus', $customer_info_id);
508 }
509
510 } else {
511
512 $customer_info->kyc_success = 1;
513 $customer_info->account_no = $kyc_response['account_no'];
514 $customer_info->save();
515 self::callAfterKycSuccess($customer_info_id);
516
517 Session::flash('class', 'alert alert-success');
518 Session::flash('message', 'Status successfully updated');
519
520 return redirect()->route('adbladmin.applicant.changestatus', $customer_info_id);
521 }
522
523 } else {
524 $customer_info->kyc_failure = 1;
525 $customer_info->save();
526 Session::flash('class', 'alert alert-danger');
527 Session::flash('message', 'Sorry there was some technical issue. Please try submitting the button again.');
528 return redirect()->route('adbladmin.applicant.changestatus', $customer_info_id);
529 }
530 }
531
532 public function getAccFetchString($customer_info)
533 {
534 $request_string = 'ENQUIRY.SELECT,,' . env('ADBL_CBS_USER') . '/' . env('ADBL_CBS_PASS') . '/' . ($customer_info->bankBranch->code ?? '') . ',ADBL.ONLINEAC.ACC,MNEMONIC:=' . $customer_info->mnemonic;
535 return $request_string;
536 }
537
538
539 public function getCustomerCheckFields($customer_info)
540 {
541 $request_string = 'ENQUIRY.SELECT,,' . env('ADBL_CBS_USER') . '/' . env('ADBL_CBS_PASS') . '/,ADBL.ONLINEAC.CUST,@ID:=' . $customer_info->cbs_id;
542 return $request_string;
543 }
544
545
546 public function callAfterKycSuccess($customer_info_id)
547 {
548 /*
549 *
550 *
551 * Old Coldes go here
552 */
553
554 $customer_info = CustomerInfo::find($customer_info_id);
555
556 $input = array_filter(Input::except('relation'), 'strlen');
557 $input['status'] = 3;
558 // echo $input['status'];die;
559
560 $old_status = CustomerAccountStatus::findByCustomerInfoId($customer_info_id);
561 if ($old_status) {
562 $old_status->delete();
563 }
564 $customer_status = new CustomerAccountStatus();
565 $customer_status->customer_info_id = $customer_info_id;
566 $customer_status->config_account_status_id = $input['status'];
567 (isset($input['remarks'])) ? $customer_status->remarks = $input['remarks'] : "";
568 $customer_status->save();
569
570
571 //send email starts
572
573 $senderEmailInfo = ConfigSetting::findByCode('sender_email');
574 $senderNameInfo = ConfigSetting::findByCode('sender_name');
575
576 if ($senderEmailInfo)
577 $senderEmail = $senderEmailInfo->value;
578 else
579 $senderEmail = "eaccount@adbl.gov.np";
580
581 if ($senderNameInfo)
582 $senderName = $senderNameInfo->value;
583 else
584 $senderName = "ADBL";
585
586 $subject = "Thank you for registering";
587 $siteName = env('APP_NAME');
588 // echo $siteName;die;
589 // dd($customer_info->accountType->name);
590 if ($input['status'] == '3') {
591 $content = "<table width='100%''>
592 <tr>
593 <td>Dear <strong>{$customer_info->salutation}. {$customer_info->first_name} {$customer_info->middle_name} {$customer_info->last_name}</strong>,<br /><br />
594 Congratulation!! Your online account has been opened.
595 Your account number is {$customer_info->account_no} ( {$customer_info->accountType->name} ) at our {$customer_info->bankBranch->location} branch.
596 Please drop all your original documents to the branch and collect cheqeue book.
597 You will be able to make deposits, however, withdrawals from the account will not be allowed until you present all your original documents for verification. Please Call toll free number 16600111110 for necessary support. Thank you for connecting with us.
598 </td>
599 </tr>
600 <tr>
601 <td>
602 बधाई छ ! शाखा कार्यालय {$customer_info->bankBranch->location} मा {$customer_info->accountType->name} खाता नं {$customer_info->account_no} प्रदान गरिएको छ । खाता खोल्दा पेश गरेका कागजात लिई नजिकको शाखामा स्वयं उपस्थित भई ग्राहक पहिचान विवरण अद्यावधिक गरी नियमित कारोवार गर्नुहुन आग्रह गर्दछौं । ग्राहक पहिचान विवरण अद्यावधिक नभएसम्म तपाईले विद्युतीय माध्यमबाट खाताको मौज्दात हेर्न सक्नुहुनेछ । थप जानकारी आवश्यक भएमा बैंकको टोल फ्रि नं.१६६००१११११० मा फोन गर्नु हुन अनुरोध गर्दछौं ।
603 </td>
604 </tr>
605 <tr>
606 <td>Thank you.<br>
607 ADBL Bank
608 </td>
609 </tr>
610 </table>";
611 } else if ($input['status'] == '6') {
612 $content = "<table width='100%''>
613 <tr>
614 <td>Dear <strong>{$customer_info->salutation}. {$customer_info->first_name} {$customer_info->middle_name} {$customer_info->last_name}</strong>,<br /><br />
615 We are pleased to inform you that we have opened account number {$customer_info->account_no} ( {$customer_info->accountType->name} ) for you at our {$customer_info->bankBranch->location} branch has been activated. Now, you are able to make deposit and withdrawal from this account.
616
617 </td>
618 </tr>
619
620 <tr>
621 <td>Thank you.<br>
622 ADBL Bank
623 </td>
624 </tr>
625 </table>";
626 } else if ($input['status'] == '4' || $input['status'] == '5') {
627
628 // dd($customer_info->bankBranch->name);
629 // echo $customer_info->statuses->remarks;die;
630 $content = "<table width='100%''>
631 <tr>
632 <td>Dear <strong>{$customer_info->salutation}. {$customer_info->first_name} {$customer_info->middle_name} {$customer_info->last_name}</strong>,<br /><br />
633 We are sorry to advise you that, we were unable to process your request for online account opening due to following reasons:<br>
634 {$customer_info->statuses[0]->remarks}
635 <br>
636 Your request has been put on hold pending completion of these issues. For tracking the status of your request, please click on the link below.
637 </td>
638 </tr>
639 <tr>
640 <td>Go to application tracker " . route('tracker') . "</td>
641 </tr>
642 <tr>
643 <td>Thank you.<br>
644 ADBL Bank
645 </td>
646 </tr>
647 </table>";
648 }
649
650 // dd($content);
651 $receiverEmail = $customer_info->email;
652 $data = array(
653 'logopath' => url('images/logo.png'),
654 'content' => $content,
655 'footer' => ' Copyright ' . date('Y') . ' ',
656 'sitename' => $siteName,
657 'subject' => 'Account Information'
658 );
659
660 try {
661 Mail::to($receiverEmail)->send(new \App\Mail\GeneralMail($data));
662 } catch (Exception $y) {
663 return view('admin.error')->with('custom_error', "Problem Sending Email.");
664 }
665 //send email ends
666
667
668 //send email starts
669
670 $senderEmailInfo = ConfigSetting::findByCode('sender_email');
671 $senderNameInfo = ConfigSetting::findByCode('sender_name');
672
673 if ($senderEmailInfo)
674 $senderEmail = $senderEmailInfo->value;
675 else
676 $senderEmail = "eaccount@adbl.gov.np";
677
678 if ($senderNameInfo)
679 $senderName = $senderNameInfo->value;
680 else
681 $senderName = "ADBL";
682
683 $subject = "Thank you for registering";
684 $siteName = env('APP_NAME');
685 // echo $siteName;die;
686 // dd($customer_info->accountType->name);
687
688 $content = "<table width='100%''>
689 <tr>
690 <td>Dear Sir/Madam,<br>
691 <strong>{$customer_info->salutation}. {$customer_info->first_name} {$customer_info->middle_name} {$customer_info->last_name}</strong>,<br /><br />
692 has applied to open {$customer_info->accountType->name} account.Please download the form and manage his/her/their personal records. If customer makes delays to come to office, please mail/telephone/SMS to submit all documents and request to deposit as much he/she can.
693 </td>
694 </tr>
695 <tr>
696 <td>Thank you.<br>
697 Online Account Section<br>
698 Marketing and Branch Management Division.
699
700
701 </td>
702 </tr>
703 </table>";
704
705 // dd($content);
706 $receiverEmail = $customer_info->bankBranch->email;
707 $data = array(
708 'logopath' => url('images/logo.png'),
709 'content' => $content,
710 'footer' => ' Copyright ' . date('Y') . ' ',
711 'sitename' => $siteName,
712 'subject' => 'Account Information'
713 );
714
715 try {
716 Mail::to($receiverEmail)->send(new \App\Mail\GeneralMail($data));
717 } catch (Exception $y) {
718 return view('admin.error')->with('custom_error', "Problem Sending Email.");
719 }
720 //send email ends
721
722
723 return true;
724
725 /*
726 *
727 *
728 *
729 */
730
731 }
732
733 public function getCBSFields($customer_info)
734 {
735 $string = 'CUSTOMER,ONLINE.KYC/I/PROCESS,' . env('ADBL_CBS_USER') . '/' . env('ADBL_CBS_PASS') . '/NP0010001,3000001,MNEMONIC=ABCD1757,SHORT.NAME=ABCD XYZ,NAME.1=ABCD XYZ,NAME.2=ABCD XYZ,STREET=KATHMANDU 6? KATHMANDU,ADDRESS=KATHMANDU 6? KATHMANDU,TOWN.COUNTRY=KATHMANDU,COUNTRY=NP,SECTOR=1002,ACCOUNT.OFFICER=1,INDUSTRY=1000,TARGET=1,NATIONALITY=NP,CUSTOMER.STATUS=1,RESIDENCE=NP,LANGUAGE=2,TITLE=MR,GIVEN.NAMES=ABCD KMR,FAMILY.NAME=XYZ,GENDER=MALE,PHONE.1=01425869,SMS.1=9841123454,EMAIL.1=abcd.xyz@gmail.com,CALC.RISK.CLASS=HIGH,MANUAL.RISK.CLASS=HIGH,MARITAL.STATUS=MARRIED,NO.OF.DEPENDENTS=,TEXT=,LOC.PAN.NO=1033158987,LOC.CONT.DATE=20630807,LOC.LEG.ID=1245,LOC.LEG.DOC=CITIZENSHIP.NO,LOC.LEG.HOLDER=ABCD,LOC.LEG.ISS.AUT=46,LOC.LEG.ISS.DT=20700430,LOC.DOB=20450415,LOC.KYC.FORM=01.INDIVIDUAL,LOC.SMS.ALERT=Y,LOC.ESTIM.TXN=900000,LOC.OLD.CUST=1254,LOCPANISSDT=20700101,LOCPROVINCE=3,LOCDISTRICT=301,LOCLOCALGOVT=30101,LOCWARDNO=1,LOC.FAMILY.REL:1:1=SPOUSE,LOC.FAMILY.NM:1:1=SPOUSE XYZ,LOC.FAMILY.ID:1:1=12354,LOC.FAMILY.CTZ:1:1=1589,LOC.FAMILY.REL:2:1=FATHER,LOC.FAMILY.NM:2:1=FATHER XYZ,LOC.FAMILY.ID:2:1=45546,LOC.FAMILY.CTZ:2:1=26,LOC.FAMILY.REL:3:1=MOTHER,LOC.FAMILY.NM:3:1=MOTHER XYZ,LOC.FAMILY.ID:3:1=,LOC.FAMILY.CTZ:3:1=138,LOC.FAMILY.REL:4:1=SON,LOC.FAMILY.NM:4:1=SON XYZ,LOC.FAMILY.ID:4:1=,LOC.FAMILY.CTZ:4:1=,LOC.FAMILY.REL:5:1=DAUGHTER,LOC.FAMILY.NM:5:1=DAUGHTER XYZ,LOC.FAMILY.ID:5:1=,LOC.FAMILY.CTZ:5:1=,LOC.FAMILY.REL:6:1=GRANDFATHER,LOC.FAMILY.NM:6:1=GRANDFATHER XYZ,LOC.FAMILY.ID:6:1=,LOC.FAMILY.CTZ:6:1=,LOC.FAMILY.REL:7:1=GRANDMOTHER,LOC.FAMILY.NM:7:1=GRANDMOTHER XYZ,LOC.FAMILY.ID:7:1=,LOC.FAMILY.CTZ:7:1=';
736
737 $nepaliDateApi = new \NepaliDateApi();
738
739 $request_string = 'CUSTOMER,ONLINE.KYC/I/PROCESS,' . env('ADBL_CBS_USER') . '/' . env('ADBL_CBS_PASS') . '/';
740 $request_string .= $customer_info->bankBranch->code . ',';
741
742
743 $request_string .= $customer_info->cbs_id . ',';
744
745
746 $request_string .= 'MNEMONIC=' . $customer_info->mnemonic . ',';
747
748 $request_array = [];
749 $request_array['SHORT.NAME'] = $customer_info->first_name . " " . $customer_info->middle_name . " " . $customer_info->last_name;
750 $request_array['NAME.1'] = $customer_info->first_name . " " . $customer_info->middle_name . " " . $customer_info->last_name;
751 $request_array['NAME.1'] = $customer_info->first_name . " " . $customer_info->middle_name . " " . $customer_info->last_name;
752
753 $per_address = $customer_info->permanentAddress->first();
754
755// $countries = \App\AdblCountry::pluck('adbl_id', 'short_name')->toArray();
756 $local_govt = AdblLocalGovt::pluck('local_govt_name', 'adbl_id')->toArray();
757 $dis_names = AdblDistrict::pluck('adbl_id', 'district_name')->toArray();
758 $auth_names = AdblLocLegIssAut::pluck('adbl_id', 'district_name')->toArray();
759
760 $request_array['STREET'] = $per_address->street;
761 $request_array['ADDRESS'] = substr($per_address->ward_no . "? " . $local_govt[$per_address->vdc_mc], 0, 35);
762 $request_array['TOWN.COUNTRY'] = $per_address->district ?? '';
763 $request_array['COUNTRY'] = $per_address->country;
764 $request_array['SECTOR'] = $customer_info->adbl_sector_id;
765 $request_array['ACCOUNT.OFFICER'] = $customer_info->adbl_dept_acct_officer_id;
766 $request_array['INDUSTRY'] = $customer_info->adbl_industry_id;
767 $request_array['TARGET'] = $customer_info->adbl_target_id;
768 $request_array['NATIONALITY'] = $per_address->country;
769 $request_array['CUSTOMER.STATUS'] = $customer_info->adbl_customer_status_id;
770 $request_array['RESIDENCE'] = $per_address->country;
771
772 $request_array['LANGUAGE'] = 1;
773
774 $titles = \App\AdblTitle::pluck('name', 'adbl_id')->toArray();
775 $request_array['TITLE'] = $titles[$customer_info->salutation];
776 $request_array['GIVEN.NAMES'] = $customer_info->first_name . " " . $customer_info->middle_name . " " . $customer_info->last_name;
777 $request_array['FAMILY.NAME'] = $customer_info->last_name;
778
779 $request_array['GENDER'] = strtoupper(($customer_info->gender == 'M') ? 'Male' : 'Female');
780
781 $request_array['PHONE'] = $customer_info->contact_no;
782 $request_array['SMS.1'] = $customer_info->mobile_no;
783 $request_array['EMAIL.1'] = str_replace("_", "'_'",strtolower($customer_info->email));
784 $request_array['CALC.RISK.CLASS'] = $customer_info->adbl_cal_risk_class_id;
785 $request_array['MANUAL.RISK.CLASS'] = $customer_info->adbl_manual_risk_class_id;
786
787 $marital = AdblMaritalStatus::pluck('adbl_id', 'name')->toArray();
788 $request_array['MARITAL.STATUS'] = $marital[$customer_info->marital_status];
789 $request_array['NO.OF.DEPENDENTS'] = '';
790 $request_array['TEXT'] = "";
791 $request_array['LOC.PAN.NO'] = $customer_info->otherInfo->pan_no;
792
793 $today = explode('-', date('Y-m-d'));
794 $todayDate = $nepaliDateApi->englishToNepali($today[0], $today[1], $today[2]);
795
796
797 $request_array['LOC.CONT.DATE'] = str_replace('-', '', $todayDate) ?? "";
798
799
800 $doc = "";
801
802 $id = $customer_info->customerIdentificationInfo;
803
804 if ($id) {
805 switch ($id->identification_type) {
806 case(1):
807 $doc = 'CITIZENSHIP.NO';
808 break;
809 case(2):
810 $doc = 'PASSPORT';
811 break;
812 case(3):
813 $doc = 'VOTER.CARD';
814 break;
815 case(4):
816 $doc = 'DRIVING.LICENSE';
817 break;
818 case(5):
819 $doc = 'BIRTH.CERTIFICATE';
820 break;
821 case(6):
822 $doc = 'SOCIAL.SECURITY.NO';
823 break;
824
825
826 }
827 }
828
829 $request_array['LOC.LEG.ID'] = $id->id_no ?? "";
830 $request_array['LOC.LEG.DOC'] = $doc ?? "";
831 $request_array['LOC.LEG.HOLDER'] = $doc ?? "";
832 $request_array['LOC.LEG.ISS.AUT'] = $auth_names[$id->id_office ?? ""];
833 $request_array['LOC.LEG.ISS.DT'] = str_replace('-', '', $id->id_issue_date_np) ?? "";
834
835 $dob = explode('-', $customer_info->dob);
836
837 $convertDate = $nepaliDateApi->englishToNepali($dob[0], $dob[1], $dob[2]);
838
839 $request_array['LOC.DOB'] = str_replace('-', '', $convertDate) ?? "";
840 $request_array['LOC.KYC.FORM'] = $customer_info->adbl_loc_kyc_form_id;
841
842 $service_array = explode(",", $customer_info->otherInfo->services);
843
844 $request_array['LOC.SMS.ALERT'] = (in_array('SMSAL', $service_array)) ? 'Y' : 'N';
845
846 $transaction_volume = "";
847 $otherInfo = $customer_info->otherInfo;
848 switch ($otherInfo->estimated_transaction_volume) {
849 case(4):
850 $transaction_volume = "100000";
851 break;
852 case(5):
853 $transaction_volume = "500000";
854 break;
855 case(0):
856 $transaction_volume = "1000000";
857 break;
858 case(1):
859 $transaction_volume = "2500000";
860 break;
861 case(2):
862 $transaction_volume = "5000000";
863 break;
864 case(3):
865 $transaction_volume = "5000000";
866 break;
867
868 }
869
870 $request_array['LOC.ESTIM.TXN'] = $transaction_volume ?? "";
871 $request_array['LOC.OLD.CUST'] = $customer_info->old_customer_id;
872 $request_array['LOCPANISSDT'] = str_replace('-', '', $customer_info->otherInfo->pan_issue_date) ?? "";;
873 $province = AdblState::pluck('adbl_id', 'state_name')->toArray();
874 $request_array['LOCPROVINCE'] = $province[$per_address->province_no];
875 $district = AdblDistrict::pluck('adbl_id', 'district_name')->toArray();
876 $request_array['LOCDISTRICT'] = $district[$per_address->district];
877 $request_array['LOCLOCALGOVT'] = $per_address->vdc_mc;
878 $request_array['LOCWARDNO'] = $per_address->ward_no;
879
880 $family_relations = [['Spouse', 'spouse_name', 'spouse_citizenship', 'spouse_cbs_id'], ['Father', 'father_name', 'father_citizenship', 'father_cbs_id'],
881 ['Mother', 'mother_name', 'mother_citizenship', 'mother_cbs_id'], ['Grandfather', 'grand_father_name', 'grand_father_citizenship', 'grand_father_cbs_id'],
882 ['Son', 'son_name', 'son_citizenship', 'son_cbs_id'], ['Daughter', 'daughter_name', 'daughter_citizenship', 'daughter_cbs_id'],
883 ['Son', 'son2_name', 'son2_citizenship', 'son2_cbs_id'], ['Daughter', 'daughter2_name', 'daughter2_citizenship', 'daughter2_cbs_id'],
884 ['DAUGHTERINLAW', 'daughter_in_law_name', 'daughter_in_law_citizenship', 'daughter_in_law_cbs_id'],
885 ['FATHERINLAW', 'father_in_law_name', 'father_in_law_citizenship', 'father_in_law_cbs_id'],
886 ['MOTHERINLAW', 'mother_in_law_name', 'mother_in_law_citizenship', 'mother_in_law_cbs_id']];
887
888
889 $relation_count = 1;
890 if (isset($customer_info) && $customer_info->familyInfo) {
891 $fr_array = collect($customer_info->familyInfo)->toArray();
892 foreach ($family_relations as $relations) {
893 if ($fr_array[$relations[1]] != "") {
894 $request_array['LOC.FAMILY.REL:' . $relation_count . ':1'] = strtoupper($relations[0]);
895 $request_array['LOC.FAMILY.NM:' . $relation_count . ':1'] = sub_str($fr_array[$relations[1]], 0, 35);
896 $request_array['LOC.FAMILY.ID:' . $relation_count . ':1'] = $fr_array[$relations[3]];
897 $request_array['LOC.FAMILY.CTZ:' . $relation_count . ':1'] = $fr_array[$relations[2]];
898
899 $relation_count++;
900 }
901 }
902
903 }
904
905//dd($request_array);
906
907 foreach ($request_array as $key => $value) {
908
909 if($key == 'EMAIL.1') {
910 $alpha_numeric_value = preg_replace("/[^a-zA-Z\-'_@.0-9 ]+/", "", $value);
911 }elseif($key == 'ADDRESS'){
912 $str_value = strtoupper(str_replace(',', '?', $value));
913 $alpha_numeric_value = preg_replace("/[^a-zA-Z?0-9 ]+/", "", $str_value);
914 }elseif(in_array($key, ['LOC.LEG.ID', 'LOC.LEG.DOC', 'LOC.LEG.HOLDER', 'LOC.KYC.FORM', 'INDUSTRY', 'SECTOR', 'TARGET', 'ACCOUNT.OFFICER', 'CUSTOMER.STATUS', 'CALC.RISK.CLASS', 'MANUAL.RISK.CLASS'])){
915 $alpha_numeric_value = strtoupper($value);
916 }else {
917 $alpha_numeric_value = strtoupper(preg_replace("/[^a-zA-Z0-9 ]+/", "", $value));
918 }
919
920 $space_trim_value = trim(preg_replace('/\s+/', ' ', $alpha_numeric_value));
921 $request_string .= $key . "=". $space_trim_value. ",";
922 }
923
924 return $request_string;
925 }
926
927
928 public function callCBSAPI($customer_unique_string)
929 {
930 $page = public_path('node_scripts/cbs-new.js');
931 exec("node $page $customer_unique_string", $output, $return_var);
932 $data['output'] = $output[1];
933 $exploded_output = explode(',', $output[1]);
934 $final_char = substr($exploded_output[0], -1);
935 $data['status'] = $final_char;
936 return $data;
937 }
938
939 public function callCusAPI($customer_unique_string)
940 {
941 $page = public_path('node_scripts/cbs-cus-check.js');
942 exec("node $page $customer_unique_string", $output, $return_var);
943 $data['output'] = $output[1];
944 $exploded_output = explode(',', $output[1]);
945 $final_char = substr($exploded_output[0], -1);
946 $data['status'] = $final_char;
947 return $data;
948 }
949
950 public function getKYCFields($customer_info)
951 {
952 $request_string = 'ACCOUNT,ONLINE.INDIVIDUAL/I/PROCESS,' . env('ADBL_CBS_USER') . '/' . env('ADBL_CBS_PASS') . '/';
953 $request_string .= $customer_info->bankBranch->code . ',';
954
955 $request_string .= $customer_info->cbs_id . ',';
956 $request_string .= 'MNEMONIC=' . $customer_info->mnemonic . ',';
957 $request_string .= 'CATEGORY=' . $customer_info->accountType->adbl_category_id . ',';
958
959 $nominee = $customer_info->otherInfo;
960
961 $request_array = [];
962 $request_array['ACCOUNT.OFFICER'] = $customer_info->adbl_dept_acct_officer_id;
963
964 $ids = ['1' => 'Citzenship', '2' => 'Passport', '3' => 'Voter Card', '4' => 'Driving Liscense', '5' => 'Birth Certificate', '6' => 'Social Security No'];
965 $relation_ids = ['1' => 'Father', '2' => 'Mother', '3' => 'Husband', '4' => 'Wife', '5' => 'Son', '6' => 'Daughter', '7' => 'Other'];
966
967
968 if ($nominee->nominee_name != '') {
969 $request_array['NOMINEE'] = $nominee->nominee_name ?? '';
970 $request_array['NOMRELATION'] = $relation_ids[$nominee->nominee_relation] ?? '';
971 $request_array['NOMIDTYPE'] = $ids[$nominee->nominee_id_type] ?? '';
972 $request_array['NOMIDNO'] = $nominee->nominee_citizenship ?? '';
973 } elseif ($nominee->minor_name != '') {
974 $request_array['NOMINEE'] = $nominee->minor_name ?? '';
975 $request_array['NOMRELATION'] = $relation_ids[$nominee->minor_relation_with_me] ?? '';
976 $request_array['NOMIDTYPE'] = $ids[$nominee->minor_id_type] ?? '';
977 $request_array['NOMIDNO'] = $nominee->minor_citizenship ?? '';
978 } else {
979 $request_array['NOMINEE'] = '';
980 $request_array['NOMRELATION'] = '';
981 $request_array['NOMIDTYPE'] = '';
982 $request_array['NOMIDNO'] = '';
983 }
984
985 foreach ($request_array as $key => $value) {
986 if ($key == 'NOMIDTYPE')
987 $request_string .= $key . "=" . (str_replace(',', '?', $value)) . ",";
988 else
989 $request_string .= strtoupper($key . "=" . (str_replace(',', '?', $value)) . ",");
990 }
991
992
993 return $request_string;
994 }
995
996 public function callKYCAPI($customer_unique_string)
997 {
998 $page = public_path('node_scripts/kyc-new.js');
999 exec("node $page $customer_unique_string", $output, $return_var);
1000
1001// $data['output'] = "0100103000001011/KYC201140236115501.31/1,CUSTOMER=3000001:1:1,CATEGORY=6001:1:1,ACCOUNT.TITLE.1=ABCD XYZ:1:1,SHORT.TITLE=ABCD XYZ:1:1,POSITION.TYPE=TR:1:1,CURRENCY=NPR:1:1,CURRENCY.MARKET=1:1:1,ACCOUNT.OFFICER=1:1:1,NOMINEE=NOMINEE NAME:1:1,NOMRELATION=WIFE:1:1,NOMIDTYPE=Driving Liscense:1:1,NOMIDNO=1886:1:1,CONDITION.GROUP=2:1:1,CAP.DATE.CHARGE=20200331:1:1,PASSBOOK=NO:1:1,OPENING.DATE=20200423:1:1,OPEN.CATEGORY=6001:1:1,CHARGE.CCY=NPR:1:1,CHARGE.MKT=1:1:1,INTEREST.CCY=NPR:1:1,INTEREST.MKT=1:1:1,ALT.ACCT.TYPE=LEGACY:1:1,ALLOW.NETTING=NO:1:1,HVT.FLAG=NO:1:1,CURR.NO=1:1:1,INPUTTER=2361_KYC.USER__WS_10.10.10.43__OFS_KYC:1:1,DATE.TIME=2004231358:1:1,AUTHORISER=2361_KYC.USER_WS_10.10.10.43___OFS_KYC:1:1,CO.CODE=NP0010001:1:1,DEPT.CODE=1:1:1";
1002
1003 $data['output'] = $output[1];
1004 $exploded_output = explode(',', $output[1]);
1005
1006 $data['account_no'] = substr($exploded_output[0], 0, 16);
1007 if ($output[1] != 'exec error: Error: response not received') {
1008 $data['status'] = substr($exploded_output[0], -1);
1009 } else {
1010 $data['status'] = '-1';
1011 }
1012 return $data;
1013 }
1014
1015 /*
1016 * Delete applicant
1017 */
1018 public function delete($id)
1019 {
1020
1021 if (!$id) throw new Exception('Id cannot be null');
1022
1023 $customer_info = CustomerInfo::find($id);
1024 // dd(Auth::User());
1025 if (Auth::User()->user_type_id == "2" && Auth::User()->branch_id != $customer_info->bank_branch_id) {
1026 die("No Access");
1027 }
1028
1029 if (!$customer_info)
1030 throw new Exception('Invalid id');
1031
1032 $customer_info->deleted_at = \Settings::getCurrentDateTime();
1033 $customer_info->save();
1034 // echo $id;die;
1035
1036 CustomerAccountStatus::where('customer_info_id', $id)->update(['deleted_at' => \Settings::getCurrentDateTime()]);
1037
1038 Session::flash('class', 'alert alert-danger');
1039 Session::flash('message', 'Applicant successfully deleted');
1040
1041 return redirect()->route('adbladmin.applicant.list');
1042 }
1043
1044 public function fixedDelete($id)
1045 {
1046
1047 if (!$id) throw new Exception('Id cannot be null');
1048
1049 $customer_info = FixedDepositCustomer::find($id);
1050
1051 if (!$customer_info)
1052 throw new Exception('Invalid id');
1053
1054 $customer_info->deleted_at = \Settings::getCurrentDateTime();
1055 $customer_info->save();
1056 Session::flash('class', 'alert alert-danger');
1057 Session::flash('message', 'Applicant successfully deleted');
1058
1059 return redirect()->back();
1060 }
1061
1062
1063 public function confirmdocument($customer_info)
1064 {
1065 DB::beginTransaction();
1066
1067 $max_cbs_id = CustomerInfo::max('cbs_id');
1068
1069 if ($max_cbs_id == "") {
1070 $cbs_id = "02000001";
1071 } else {
1072 $cbs_id = "0" . ($max_cbs_id + 1);
1073 }
1074
1075 $mnemonic = 'M' . $cbs_id . 'N';
1076 if (CustomerInfo::where('id', $customer_info)->update(['final_document_confirm' => 1, 'cbs_id' => $cbs_id, 'mnemonic' => $mnemonic])) {
1077 DB::commit();
1078 Session::flash('class', 'alert alert-success');
1079 Session::flash('message', 'Document verification complete. Now You can begin process to approve the user.');
1080 } else {
1081 Session::flash('class', 'alert alert-danger');
1082 Session::flash('message', 'Sorry, something went wrong.');
1083 }
1084
1085 return redirect()->back();
1086 }
1087
1088
1089 /*
1090 * Test pdf
1091 */
1092 public function viewPDF($id)
1093 {
1094
1095 // echo $id;die;
1096 if (!$id) throw new Exception('Id cannot be null');
1097
1098 $customer_info = CustomerInfo::find($id);
1099 $engdate = explode('-', $customer_info->dob);
1100 $nepaliDateApi = new \NepaliDateApi();
1101 $convertDate = $nepaliDateApi->englishToNepali($engdate[0], $engdate[1], $engdate[2]);
1102 $customer_info->nepalidate = $convertDate;
1103
1104 $per_address = "";
1105 if ($customer_info->addresses && $customer_info->addresses()->ofType('1')->first())
1106 $per_address = $customer_info->addresses()->ofType('1')->first();
1107
1108 $curr_address = "";
1109 if ($customer_info->addresses && $customer_info->addresses()->ofType('2')->first())
1110 $curr_address = $customer_info->addresses()->ofType('2')->first();
1111
1112 if (!$customer_info)
1113 throw new Exception('Invalid id');
1114
1115 $customer_submission = CustomerAccountStatus::findDateByType($customer_info->id, '2');
1116 $zone = Zone::find($per_address->zone);
1117 $zone1 = Zone::find($curr_address->zone);
1118 $district = District::find($per_address->district);
1119 $district1 = District::find($curr_address->district);
1120 if (isset($zone)) {
1121 $per_address->zone = $zone->name;
1122 } else {
1123 $per_address->zone = '';
1124 }
1125
1126 if (isset($zone1)) {
1127 $curr_address->zone = $zone1->name;
1128 } else {
1129 $curr_address->zone = '';
1130 }
1131
1132
1133 // return view('admin.applicant.pdf', array('customer_info'=>$customer_info,'per_address'=>$per_address,'curr_address'=>$curr_address, 'submission_info' => $customer_submission));
1134
1135 // return view('admin.applicant.pdf', array('customer_info' => $customer_info, 'per_address' => $per_address, 'curr_address' => $curr_address, 'submission_info' => $customer_submission));
1136//
1137 return PDF::loadView('admin.applicant.pdf', array('customer_info' => $customer_info, 'per_address' => $per_address, 'curr_address' => $curr_address, 'submission_info' => $customer_submission))->setPaper('a4')->stream();
1138
1139 // return PDF::loadView('admin.applicant.pdf', array('customer_info'=>$customer_info, 'submission_info' => $customer_submission))->setPaper('a4')->download();
1140 // return view('customer.account.pdf', array('customer_info'=>$customer_info, 'submission_info' => $customer_submission));
1141 }
1142
1143 public function viewMinifiedPdf($id)
1144 {
1145
1146 // echo $id;die;
1147 if (!$id) throw new Exception('Id cannot be null');
1148
1149 $customer_info = CustomerInfo::find($id);
1150 $engdate = explode('-', $customer_info->dob);
1151 $nepaliDateApi = new \NepaliDateApi();
1152 $convertDate = $nepaliDateApi->englishToNepali($engdate[0], $engdate[1], $engdate[2]);
1153 $customer_info->nepalidate = $convertDate;
1154
1155 $per_address = "";
1156 if ($customer_info->addresses && $customer_info->addresses()->ofType('1')->first())
1157 $per_address = $customer_info->addresses()->ofType('1')->first();
1158
1159 $curr_address = "";
1160 if ($customer_info->addresses && $customer_info->addresses()->ofType('2')->first())
1161 $curr_address = $customer_info->addresses()->ofType('2')->first();
1162
1163 if (!$customer_info)
1164 throw new Exception('Invalid id');
1165
1166 $customer_submission = CustomerAccountStatus::findDateByType($customer_info->id, '2');
1167 $zone = Zone::find($per_address->zone);
1168 $zone1 = Zone::find($curr_address->zone);
1169 $district = District::find($per_address->district);
1170 $district1 = District::find($curr_address->district);
1171 if (isset($zone)) {
1172 $per_address->zone = $zone->name;
1173 } else {
1174 $per_address->zone = '';
1175 }
1176
1177 if (isset($zone1)) {
1178 $curr_address->zone = $zone1->name;
1179 } else {
1180 $curr_address->zone = '';
1181 }
1182
1183 return PDF::loadView('admin.applicant.minifiedpdf', array('customer_info' => $customer_info, 'per_address' => $per_address, 'curr_address' => $curr_address, 'submission_info' => $customer_submission))->setPaper('a4')->stream();
1184 }
1185
1186 public function viewFixedPdf($id)
1187 {
1188
1189 if (!$id) throw new Exception('Id cannot be null');
1190
1191 $customer_info = FixedDepositCustomer::find($id);
1192
1193 if (!$customer_info)
1194 throw new Exception('Invalid id');
1195
1196 $data['org_customer_info'] = $customer_info;
1197 $data['customer_info'] = $customer_info->toArray();
1198
1199 // return view('admin.applicant.fixed_pdf', $data);
1200
1201 //return view('admin.applicant.fixed_pdf', $data);
1202
1203 return PDF::loadView('admin.applicant.fixed_pdf', $data)->setPaper('a4')->stream();
1204
1205 }
1206
1207
1208 /*
1209 * View File
1210 */
1211 public
1212 function viewFile($id)
1213 {
1214 $last_completed_step = CustomerAccountCompletedStep::getMaxStepId($id);
1215 $files = CustomerDocument::findByCustomerId($id);
1216 $customer_submission = CustomerAccountStatus::findDateByType($id, '2');
1217 $customer_info = CustomerInfo::where('id', $id)->with('bankbranch')->first();
1218 $per_address = "";
1219 if ($customer_info->addresses && $customer_info->addresses()->ofType('1')->first())
1220 $per_address = $customer_info->addresses()->ofType('1')->first();
1221 return view('admin.applicant.files')->with(array("files" => $files,
1222 'customer_info' => $customer_info, 'submission_info' => $customer_submission, 'last_step' => $last_completed_step, 'per_address' => $per_address));
1223
1224 }
1225
1226 public
1227 function viewFixedFiles($id)
1228 {
1229 $data['customer_info'] = FixedDepositCustomer::where('id', $id)->with('bankbranch')->first();
1230 return view('admin.applicant.fixed_files', $data);
1231
1232 }
1233
1234 public
1235 function sendMessage($id)
1236 {
1237 $customer = CustomerInfo::find($id);
1238 return view('admin.applicant.sendmessage')->with(['customerInfo' => $customer]);
1239 }
1240
1241 public
1242 function postMessage($id)
1243 {
1244 $subject = Input::get('subject');
1245 $content = Input::get('message');
1246
1247 $customer = CustomerInfo::find($id);
1248
1249 $senderEmailInfo = ConfigSetting::findByCode('sender_email');
1250 $senderNameInfo = ConfigSetting::findByCode('sender_name');
1251
1252 if ($senderEmailInfo)
1253 $senderEmail = $senderEmailInfo->value;
1254 else
1255 $senderEmail = "eaccount@ADBLbank.com.np";
1256
1257 if ($senderNameInfo)
1258 $senderName = $senderNameInfo->value;
1259 else
1260 $senderName = env('APP_NAME');
1261
1262 $siteName = env('APP_NAME');
1263
1264
1265 $receiverEmail = $customer->email;
1266 $data_admin = array(
1267 'logopath' => url('images/logo.png'),
1268 'content' => $content,
1269 'footer' => ' Copyright ' . date('Y') . ' ',
1270 'sitename' => $siteName,
1271 'subject' => $subject,
1272 );
1273
1274 try {
1275 Mail::to($receiverEmail)->send(new \App\Mail\GeneralMail($data_admin));
1276 } catch (Exception $y) {
1277 return view('admin.error')->with('custom_error', "Problem Sending Email.");
1278 }
1279
1280 Session::flash('class', 'alert alert-success');
1281 Session::flash('message', 'Message successfully sent');
1282 return redirect()->back();
1283 }
1284
1285 public
1286 function exportExcel()
1287 {
1288 dd($_GET);
1289 // dd($data);/
1290 }
1291
1292 public
1293 function changeImage()
1294 {
1295
1296 $customer_info = CustomerInfo::where('id', $_POST['id'])->with('document')->first();
1297 // dd($customer_info->document->photo);
1298 $allowedtype = array('jpg', 'jpeg', 'png', 'pdf');
1299 $file = $_FILES;
1300 $photoFile = new ApplicantController();
1301 $photoFile->name = $file[$_POST['type']]['name'];
1302 $photoFile->size = $file[$_POST['type']]['size'];
1303 $photoFile->tmp_name = $file[$_POST['type']]['tmp_name'];
1304 $photoFile->type = $file[$_POST['type']]['type'];
1305 $photoFile->error = $file[$_POST['type']]['error'];
1306 $extension = \File::extension($file[$_POST['type']]['name']);
1307 $maximum_filesize = 1 * 1024 * 1024;
1308 if (in_array($extension, $allowedtype)) {
1309 if ($maximum_filesize > $file[$_POST['type']]['size']) {
1310 if ($_POST['type'] == 'photo') {
1311
1312 if ($customer_info->document && file_exists("uploads/documents/{$customer_info->id}/" . $customer_info->document->photo) && $customer_info->document->photo != '') {
1313 unlink("uploads/documents/{$customer_info->id}/" . $customer_info->document->photo);
1314 }
1315 $path = public_path() . '/uploads/documents';
1316 $destinationPath = $path . "/{$customer_info->id}";
1317
1318 $new_image_name = "photo" . "_" . time();
1319 $attachment = request()->photo->move($destinationPath, $new_image_name . $extension);
1320 $customer_info->document->photo = $new_image_name . $extension;
1321 $customer_info->document->save();
1322 } else if ($_POST['type'] == 'citizen_passport_file') {
1323 if ($customer_info->document && file_exists("uploads/documents/{$customer_info->id}/" . $customer_info->document->citizen_passport_file) && $customer_info->document->citizen_passport_file != '') {
1324 unlink("uploads/documents/{$customer_info->id}/" . $customer_info->document->citizen_passport_file);
1325 }
1326 $path = public_path() . '/uploads/documents';
1327 $destinationPath = $path . "/{$customer_info->id}";
1328
1329 $new_image_name = "citizen_passport_file" . "_" . time();
1330 $attachment = request()->citizen_passport_file->move($destinationPath, $new_image_name . $extension);
1331 $customer_info->document->citizen_passport_file = $new_image_name . $extension;
1332 $customer_info->document->save();
1333 } else if ($_POST['type'] == 'other') {
1334 if ($customer_info->document && file_exists("uploads/documents/{$customer_info->id}/" . $customer_info->document->other) && $customer_info->document->other != '') {
1335 unlink("uploads/documents/{$customer_info->id}/" . $customer_info->document->other);
1336 }
1337 $path = public_path() . '/uploads/documents';
1338 $destinationPath = $path . "/{$customer_info->id}";
1339
1340 $new_image_name = "other" . "_" . time();
1341 $attachment = request()->other->move($destinationPath, $new_image_name . $extension);
1342 $customer_info->document->other = $new_image_name . $extension;
1343 $customer_info->document->save();
1344 } else if ($_POST['type'] == 'other_1') {
1345 if ($customer_info->document && file_exists("uploads/documents/{$customer_info->id}/" . $customer_info->document->other_1) && $customer_info->document->other_1 != '') {
1346 unlink("uploads/documents/{$customer_info->id}/" . $customer_info->document->other_1);
1347 }
1348 $path = public_path() . '/uploads/documents';
1349 $destinationPath = $path . "/{$customer_info->id}";
1350
1351 $new_image_name = "other_1" . "_" . time();
1352 $attachment = request()->other_1->move($destinationPath, $new_image_name . $extension);
1353 $customer_info->document->other_1 = $new_image_name . $extension;
1354 $customer_info->document->save();
1355 } else if ($_POST['type'] == 'other_2') {
1356 if ($customer_info->document && file_exists("uploads/documents/{$customer_info->id}/" . $customer_info->document->other_2) && $customer_info->document->other_2 != '') {
1357 unlink("uploads/documents/{$customer_info->id}/" . $customer_info->document->other_2);
1358 }
1359 $path = public_path() . '/uploads/documents';
1360 $destinationPath = $path . "/{$customer_info->id}";
1361
1362 $new_image_name = "other_2" . "_" . time();
1363 $attachment = request()->other_2->move($destinationPath, $new_image_name . $extension);
1364 $customer_info->document->other_2 = $new_image_name . $extension;
1365 $customer_info->document->save();
1366 } else if ($_POST['type'] == 'id_front') {
1367
1368 if ($customer_info->document && file_exists("uploads/documents/{$customer_info->id}/" . $customer_info->document->id_front) && $customer_info->document->id_front != '') {
1369 unlink("uploads/documents/{$customer_info->id}/" . $customer_info->document->id_front);
1370 }
1371 $path = public_path() . '/uploads/documents';
1372 $destinationPath = $path . "/{$customer_info->id}";
1373
1374 $new_image_name = "id_front" . "_" . time();
1375 $attachment = request()->id_front->move($destinationPath, $new_image_name . $extension);
1376 $customer_info->document->id_front = $new_image_name . $extension;
1377 $customer_info->document->save();
1378 } else if ($_POST['type'] == 'id_back') {
1379
1380 if ($customer_info->document && file_exists("uploads/documents/{$customer_info->id}/" . $customer_info->document->id_back) && $customer_info->document->id_back != '') {
1381 unlink("uploads/documents/{$customer_info->id}/" . $customer_info->document->id_back);
1382 }
1383 $path = public_path() . '/uploads/documents';
1384 $destinationPath = $path . "/{$customer_info->id}";
1385
1386 $new_image_name = "id_back" . "_" . time();
1387 $attachment = request()->id_back->move($destinationPath, $new_image_name . $extension);
1388 $customer_info->document->id_back = $new_image_name . $extension;
1389 $customer_info->document->save();
1390 } else if ($_POST['type'] == 'nominee_first') {
1391 if ($customer_info->document && file_exists("uploads/documents/{$customer_info->id}/" . $customer_info->document->nominee_first) && $customer_info->document->nominee_first != '') {
1392 unlink("uploads/documents/{$customer_info->id}/" . $customer_info->document->nominee_first);
1393 }
1394 $path = public_path() . '/uploads/documents';
1395 $destinationPath = $path . "/{$customer_info->id}";
1396
1397 $new_image_name = "nominee_first" . "_" . time();
1398 $attachment = request()->nominee_first->move($destinationPath, $new_image_name . $extension);
1399 $customer_info->document->nominee_first = $new_image_name . $extension;
1400 $customer_info->document->save();
1401 } else if ($_POST['type'] == 'nominee_second') {
1402 if ($customer_info->document && file_exists("uploads/documents/{$customer_info->id}/" . $customer_info->document->nominee_second) && $customer_info->document->nominee_second != '') {
1403 unlink("uploads/documents/{$customer_info->id}/" . $customer_info->document->nominee_second);
1404 }
1405 $path = public_path() . '/uploads/documents';
1406 $destinationPath = $path . "/{$customer_info->id}";
1407
1408 $new_image_name = "nominee_second" . "_" . time();
1409 $attachment = request()->nominee_second->move($destinationPath, $new_image_name . $extension);
1410 $customer_info->document->nominee_second = $new_image_name . $extension;
1411 $customer_info->document->save();
1412 } else if ($_POST['type'] == 'additional_file') {
1413 if ($customer_info->document && file_exists("uploads/documents/{$customer_info->id}/" . $customer_info->document->additional_file) && $customer_info->document->additional_file != '') {
1414 unlink("uploads/documents/{$customer_info->id}/" . $customer_info->document->additional_file);
1415 }
1416 $path = public_path() . '/uploads/documents';
1417 $destinationPath = $path . "/{$customer_info->id}";
1418
1419 $new_image_name = "additional_file" . "_" . time();
1420 $attachment = request()->additional_file->move($destinationPath, $new_image_name . $extension);
1421 $customer_info->document->additional_file = $new_image_name . $extension;
1422 $customer_info->document->save();
1423 }
1424 $data['status'] = 'success';
1425 $data['message'] = 'File Uploaded';
1426 echo json_encode($data);
1427 } else {
1428 $data['status'] = 'error';
1429 $data['message'] = 'Size exceeded';
1430 echo json_encode($data);
1431 }
1432 } else {
1433 $data['status'] = 'error';
1434 $data['message'] = 'File Type Not Allowed';
1435 echo json_encode($data);
1436 }
1437 }
1438
1439 public function run()
1440 {
1441 $approved_users = CustomerAccountStatus::where('config_account_status_id', 3)->pluck('customer_info_id')->toArray();
1442 CustomerInfo::whereNotIn('id', $approved_users)->update(['cbs_success' => '0']);
1443 }
1444
1445
1446 public function fixedChangeStatus($id){
1447 $customer = FixedDepositCustomer::find($id);
1448 if($customer->is_active == 0) {
1449 $customer->is_active = 1;
1450 $customer->fd_no = request('fd_no');
1451 }else {
1452 $customer->is_active = 0;
1453 $customer->fd_no = NULL;
1454 }
1455 if($customer->save()){
1456 Session::flash('class', 'alert alert-success');
1457 Session::flash('message', 'Status successfully updated');
1458 }else{
1459 Session::flash('class', 'alert alert-danger');
1460 Session::flash('message', 'Sorry, something went wrong.');
1461 }
1462
1463 return redirect()->back();
1464 }
1465
1466 public function fixedChangeRejected($id){
1467 $customer = FixedDepositCustomer::find($id);
1468 if($customer->is_rejected == 0)
1469 $customer->is_rejected = 1;
1470 else
1471 $customer->is_rejected = 0;
1472 if($customer->save()){
1473 Session::flash('class', 'alert alert-success');
1474 Session::flash('message', 'Reject status successfully updated');
1475 }else{
1476 Session::flash('class', 'alert alert-danger');
1477 Session::flash('message', 'Sorry, something went wrong.');
1478 }
1479
1480 return redirect()->back();
1481 }
1482
1483 public
1484 function sendFixedMessage($id)
1485 {
1486 $customer = CustomerInfo::find($id);
1487 return view('admin.applicant.sendfixedmessage')->with(['customerInfo' => $customer]);
1488 }
1489
1490 public
1491 function postFixedMessage($id)
1492 {
1493 $subject = Input::get('subject');
1494 $content = Input::get('message');
1495
1496 $customer = FixedDepositCustomer::find($id);
1497
1498 $senderEmailInfo = ConfigSetting::findByCode('sender_email');
1499 $senderNameInfo = ConfigSetting::findByCode('sender_name');
1500
1501 if ($senderEmailInfo)
1502 $senderEmail = $senderEmailInfo->value;
1503 else
1504 $senderEmail = "eaccount@ADBLbank.com.np";
1505
1506 if ($senderNameInfo)
1507 $senderName = $senderNameInfo->value;
1508 else
1509 $senderName = env('APP_NAME');
1510
1511 $siteName = env('APP_NAME');
1512
1513
1514 $receiverEmail = $customer->email;
1515 $data_admin = array(
1516 'logopath' => url('images/logo.png'),
1517 'content' => $content,
1518 'footer' => ' Copyright ' . date('Y') . ' ',
1519 'sitename' => $siteName,
1520 'subject' => $subject,
1521 );
1522
1523 try {
1524 Mail::to($receiverEmail)->send(new \App\Mail\GeneralMail($data_admin));
1525 } catch (Exception $y) {
1526 return view('admin.error')->with('custom_error', "Problem Sending Email.");
1527 }
1528
1529 Session::flash('class', 'alert alert-success');
1530 Session::flash('message', 'Message successfully sent');
1531 return redirect()->back();
1532 }
1533
1534}
1535