| 
									
										
										
										
											2021-12-20 17:47:02 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Brick\Money\Context\AutoContext; | 
					
						
							|  |  |  | use Brick\Money\Money; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | defined('BASEPATH') or exit('No direct script access allowed'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Agent extends CI_Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function __construct() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		parent::__construct(); | 
					
						
							|  |  |  | 		$this->load->model('wallet_model'); | 
					
						
							|  |  |  | 		$this->load->model('nano_credit_model'); | 
					
						
							|  |  |  | 		$this->load->model('Users_simple'); | 
					
						
							|  |  |  | 		$this->load->model('User_model'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function index() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if ($this->isLogged()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$data['active'] = "health_care_sheets"; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			$data['member_code'] = $this->session->userdata('member_code'); | 
					
						
							|  |  |  | 			$data['category'] = $this->session->userdata('category'); | 
					
						
							|  |  |  | 			$data['network'] = $this->session->userdata('network'); | 
					
						
							|  |  |  | 			$data['code_parrain'] = $this->session->userdata('parrain'); | 
					
						
							|  |  |  | 			$data['network_agent_id'] = $this->session->userdata('network_agent_id'); | 
					
						
							| 
									
										
										
										
											2021-12-28 15:51:25 +00:00
										 |  |  | 			$data['network_id'] = $data['id_network'] = $this->session->userdata('network_id'); | 
					
						
							|  |  |  | 			$data['hasWallet'] = $this->wallet_model->getConfigWallet($data['network_id']); | 
					
						
							| 
									
										
										
										
											2022-01-05 10:49:55 +00:00
										 |  |  | 			$data['show_health_care_sheet_buttons'] = true; | 
					
						
							| 
									
										
										
										
											2021-12-20 17:47:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-22 09:08:33 +00:00
										 |  |  | 			if ($this->input->get('history')) { | 
					
						
							| 
									
										
										
										
											2022-01-24 08:08:05 +00:00
										 |  |  | 				$history = $this->input->get('history'); | 
					
						
							| 
									
										
										
										
											2021-12-22 09:08:33 +00:00
										 |  |  | 				if($this->input->get('id') !== null){ | 
					
						
							|  |  |  | 					if($history == 'insurance-health_care_sheets'){ | 
					
						
							|  |  |  | 						$data['active'] = "health_care_sheets"; | 
					
						
							|  |  |  | 						$data['health_care_sheet_id'] = $this->input->get('id'); | 
					
						
							|  |  |  | 						$data['health_care_sheet'] = $this->nano_health_model->getInfosHealthCareSheetById($this->input->get('id')); | 
					
						
							|  |  |  | 						$data['performances'] = $this->nano_health_model->getHealthCareSheetPerformances($data['health_care_sheet']->id ?? null); | 
					
						
							|  |  |  | 						$data['exams'] = $this->nano_health_model->getHealthCareSheetExams($data['health_care_sheet']->id ?? null); | 
					
						
							|  |  |  | 						$data['prescriptions'] = $this->nano_health_model->getHealthCareSheetPrescriptions($data['health_care_sheet']->id ?? null); | 
					
						
							| 
									
										
										
										
											2021-12-20 17:47:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-31 11:24:35 +00:00
										 |  |  | 						// Calcul par assuré et assurance
 | 
					
						
							| 
									
										
										
										
											2022-02-17 14:15:10 +00:00
										 |  |  | //						$data['amounts'] = $this->nano_health_model->calculateSheetAmountsParts($data['health_care_sheet']->id ?? null, $data['health_care_sheet']->type ?? null);
 | 
					
						
							| 
									
										
										
										
											2022-01-31 11:24:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-22 09:08:33 +00:00
										 |  |  | 						$this->load->view('header_agent', $data); | 
					
						
							|  |  |  | 						$this->load->view('nano_health/hyper/infos_health_care_sheet'); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					$this->load->view('footer'); | 
					
						
							|  |  |  | 					return; | 
					
						
							|  |  |  | 				}else{ | 
					
						
							| 
									
										
										
										
											2022-01-24 08:08:05 +00:00
										 |  |  | 					$this->historique($this->input->get('d'), $this->input->get('f'), $this->input->get('history') , $data); | 
					
						
							| 
									
										
										
										
											2021-12-22 09:08:33 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}else if($this->input->get('action')) { | 
					
						
							| 
									
										
										
										
											2021-12-20 17:47:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 10:49:55 +00:00
										 |  |  | 				$action = $this->input->get('action'); | 
					
						
							| 
									
										
										
										
											2021-12-28 15:51:25 +00:00
										 |  |  | 				$nh_config = $this->nano_health_model->getConfig($data['network_id']); | 
					
						
							|  |  |  | 				$data['nh_config'] = $nh_config ? $nh_config->first_row() : null ; | 
					
						
							|  |  |  | 				$data['config_id'] = $data['nh_config'] ? $data['nh_config']->id : null ; | 
					
						
							|  |  |  | 				$data['acts'] = $this->nano_health_model->getConfigActs($data['config_id']); | 
					
						
							|  |  |  | 				$data['provider_classes'] = $this->nano_health_model->getProviderClasses($data['config_id']); | 
					
						
							|  |  |  | 				$data['drugs_and_devices'] =  $this->nano_health_model->getDrugAndDevices($data['network_id']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-22 09:08:33 +00:00
										 |  |  | 				$this->load->view('header_agent', $data); | 
					
						
							| 
									
										
										
										
											2022-01-05 10:49:55 +00:00
										 |  |  | 				if($action == 'new_consultation'){ | 
					
						
							|  |  |  | 					$this->load->view('nano_health/agent/health_care_sheet_consultation_form'); | 
					
						
							| 
									
										
										
										
											2022-01-13 15:48:45 +00:00
										 |  |  | 				} else if($action == 'update_consultation'){ | 
					
						
							|  |  |  | 					$this->load->view('nano_health/agent/health_care_sheet_update_consultation_form'); | 
					
						
							|  |  |  | 				} else if($action == 'update_execution'){ | 
					
						
							|  |  |  | 					$this->load->view('nano_health/agent/health_care_sheet_update_execution_form'); | 
					
						
							| 
									
										
										
										
											2022-01-05 10:49:55 +00:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					$this->load->view('nano_health/agent/health_care_sheet_execution_form'); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2021-12-22 09:08:33 +00:00
										 |  |  | 				$this->load->view('footer'); | 
					
						
							|  |  |  | 			}else{ | 
					
						
							| 
									
										
										
										
											2022-01-24 08:08:05 +00:00
										 |  |  | 				$this->historique($this->input->get('d'), $this->input->get('f'), 'insurance-health_care_sheets' , $data); | 
					
						
							| 
									
										
										
										
											2021-12-22 09:08:33 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-12-20 17:47:02 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Wallet
 | 
					
						
							|  |  |  | 	public function wallet() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (!$this->session->userdata('email')) { | 
					
						
							|  |  |  | 			$this->session->set_flashdata('error', 'log in first'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$data['alert'] = "ok"; | 
					
						
							|  |  |  | 			$data['message'] = "Login first!"; | 
					
						
							|  |  |  | 			$this->load->view('login', $data); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$id_network = $this->session->userdata('network_id'); | 
					
						
							|  |  |  | 			$data["commission"] = ""; | 
					
						
							|  |  |  | 			$data["principal"] = ""; | 
					
						
							|  |  |  | 			$data["transactions"] = ""; | 
					
						
							|  |  |  | 			$agent_id = $this->session->userdata('agent_id'); | 
					
						
							|  |  |  | 			$data['hasWallet'] = $this->wallet_model->getConfigWallet($this->session->userdata('network_id')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if ($this->input->get('history')) { | 
					
						
							|  |  |  | 				$this->historique($id_network, $this->input->get('d'), $this->input->get('f'), $this->session->userdata('member_code'), | 
					
						
							|  |  |  | 					$this->input->get('history')); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				$context = new AutoContext(); | 
					
						
							|  |  |  | 				//Create wallet if it not exist
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-24 08:08:05 +00:00
										 |  |  | 	private function historique($startDate, $endDate,$type , $data) | 
					
						
							| 
									
										
										
										
											2021-12-20 17:47:02 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2022-01-24 08:08:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-20 17:47:02 +00:00
										 |  |  | 		$format = $this->session->userdata('site_lang') === 'french' ? 'd-m-Y' : 'Y-m-d'; | 
					
						
							|  |  |  | 		$data['startDate'] = $startDate ? date($format, strtotime($startDate)) : null; | 
					
						
							|  |  |  | 		$data['endDate'] = $endDate ? date($format, strtotime($endDate)) : null; | 
					
						
							|  |  |  | 		$endDate = Date('Y-m-d', strtotime($endDate . "+1 day")); | 
					
						
							| 
									
										
										
										
											2022-01-24 08:08:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ($type == 'insurance-invoices') | 
					
						
							|  |  |  | 			$data['active'] = 'wallet_invoices'; | 
					
						
							|  |  |  | 		else if ($type == 'insurance-health_care_sheets') | 
					
						
							|  |  |  | 			$data['active'] = 'wallet_health_care_sheets'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->view('header_agent', $data); | 
					
						
							|  |  |  | 		if ($type == 'insurance-invoices') | 
					
						
							|  |  |  | 			$this->load->view('nano_health/hyper/insurances_invoices'); | 
					
						
							|  |  |  | 		else if ($type == 'insurance-health_care_sheets') | 
					
						
							|  |  |  | 			$this->load->view('nano_health/hyper/insurances_health_care_sheets'); | 
					
						
							| 
									
										
										
										
											2021-12-20 17:47:02 +00:00
										 |  |  | 		$this->load->view('footer'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private function isLogged() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (!$this->session->userdata('email')) { | 
					
						
							|  |  |  | 			$this->session->set_flashdata('error', 'log in first'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$data['alert'] = "ok"; | 
					
						
							|  |  |  | 			$data['message'] = "Login first!"; | 
					
						
							|  |  |  | 			$this->load->view('login', $data); | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |