diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6d405c6..ce29445 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -45,6 +45,10 @@ use CodeIgniter\Router\RouteCollection; $routes->match(['get','post'],'/template_edit','MasterController::template_edit'); $routes->match(['get','post'],'/template_preview','MasterController::template_preview'); $routes->match(['get','post'],'/shared_docs_list','MasterController::shared_docs_list'); + $routes->match(['get','post'],'/get_templates','MasterController::get_templates'); + $routes->match(['get','post'],'/create_docs','MasterController::create_docs'); + $routes->match(['get','post'],'/client_docs_preview','MasterController::client_docs_preview'); + $routes->match(['get','post'],'/change_doc_status','MasterController::change_doc_status'); $routes->match(['get','post'],'/test','MasterController::test'); diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index d07734b..84b27fb 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -200,37 +200,86 @@ class MasterController extends BaseController { if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); } - if($this->request->getmethod() == 'POST') - { - $templateData = $this->request->getVar(); - - if($this->request->getVar('template_id') != 'null'){ - $id = $this->request->getVar('template_id'); - unset($templateData['template_id']); - $this->TemplateModel->where('template_id', $id )->set($templateData)->update(); - return $this->response->setJSON(['success' => true , 'service_id' =>$this->request->getVar('service_id')]); - }else{ - unset($templateData['template_id']); - $this->TemplateModel->insert($templateData); - return $this->response->setJSON(['success' => true , 'service_id' =>$this->request->getVar('service_id')]); - } - - - - }else{ - + $client_id = $this->request->getVar('client_id'); - $data['doc_list'] = $this->ClientDocsModel->getTemplate($client_id); - + $data['doc_list'] = $this->ClientDocsModel->getDocs($client_id); $data['clientdata'] = $this->ClientModel->where('client_id', $client_id)->get()->getRow(); + $data['serviceData'] = $this->ServiceModel->findAll(); $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); echo view('layout/header', ['Data'=>$staffdata]); echo view('docs_shared_with_client',$data); echo view('layout/footer'); - } + } + public function get_templates() + { + + $result = $this->TemplateModel->where('service_id',$this->request->getVar('service_id'))->findAll(); + + return $this->response->setJSON(['count'=>count($result) , 'data'=>$result ]); + + } + + public function create_docs() + { + $docData = $this->request->getVar(); + $docData['created_by'] = $this->session->has('is_staff_logged_in'); + $insert = $this->ClientDocsModel->insert($docData); + + if( $insert) + echo true; + else + echo false; + + } + + public function client_docs_preview() + { + + $doc_id = $this->request->getVar('doc_id'); + $data['docData'] = $this->ClientDocsModel->docPreview($doc_id); + + $clientData = $this->ClientModel->where('client_id',$data['docData']->client_id)->get()->getRow(); + $data['body_html'] = $data['docData']->body_html; + foreach ($clientData as $key => $value) { + $placeHolder = '%'.$key.'%'; + $data['body_html'] = str_replace($placeHolder,$value,$data['body_html']); + + } + + + $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); + echo view('layout/header', ['Data'=>$staffdata]); + echo view('client_docs_preview',$data); + echo view('layout/footer'); + + } + + public function change_doc_status() + { + try { + $doc_id = $this->request->getPost('doc_id'); + $is_active = $this->request->getPost('is_active'); + $data = [ + 'is_active' => $is_active + ]; + + $updated = $this->ClientDocsModel->update($doc_id, $data); + + if ($updated) { + return $this->response->setJSON(['status' => 'success','code' => 200,'data' => true],200); + } else { + $result = "No Match's"; + return $this->response->setJSON(['status' => 'failed','code' => 404,'data' => $result],404); + } + } catch (\Exception $exception) { + return $this->response->setJSON(['status' => 'failed','code' => 500,'data' => $exception],500); + } + } + + // str_replace("%name%","Gowtham",$data['templateData']->body_html); diff --git a/app/Models/ClientDocsModel.php b/app/Models/ClientDocsModel.php index c597563..af5b99a 100644 --- a/app/Models/ClientDocsModel.php +++ b/app/Models/ClientDocsModel.php @@ -14,12 +14,35 @@ class ClientDocsModel extends Model public function getTemplate($client_id){ - $this->select('template.*,client_docs.is_approved'); + $this->select('template.template_name , template.template_id ,client_docs.is_approved ,client_docs.id as doc_id , services.service_name'); $this->join('template', 'template.template_id = client_docs.template_id'); + $this->join('services', 'services.service_id = template.service_id'); $this->where('client_docs.is_active', 1); $this->where('client_docs.client_id', $client_id); return $this->findAll(); } + + public function getDocs($client_id){ + + + $this->select('template.template_name , template.template_id ,client_docs.is_approved ,client_docs.id as doc_id ,client_docs.is_active, services.service_name'); + $this->join('template', 'template.template_id = client_docs.template_id'); + $this->join('services', 'services.service_id = template.service_id'); + $this->where('client_docs.client_id', $client_id); + return $this->findAll(); + + } + + public function docPreview($doc_id){ + + + $this->select('client_docs.is_approved ,client_docs.id as doc_id,client_docs.client_id ,template.template_name,template.body_html , services.service_name'); + $this->join('template', 'template.template_id = client_docs.template_id'); + $this->join('services', 'services.service_id = template.service_id'); + $this->where('client_docs.id', $doc_id); + return $this->get()->getRow(); + + } } \ No newline at end of file diff --git a/app/Views/client_docs_preview.php b/app/Views/client_docs_preview.php new file mode 100644 index 0000000..dfdbf9d --- /dev/null +++ b/app/Views/client_docs_preview.php @@ -0,0 +1,66 @@ + + + + + +
+ +
+ + +
+
+
+
+

service_name; ?>

+ +
+
+
+
+ + + +
+
+
+
+
+ +
+
+ +
+ + + +
+ +
+
+
+
+
+ + + +
+ +
+ + + + + + + + + + + + + diff --git a/app/Views/docs_shared_with_client.php b/app/Views/docs_shared_with_client.php index 79fbef2..6779437 100644 --- a/app/Views/docs_shared_with_client.php +++ b/app/Views/docs_shared_with_client.php @@ -1,24 +1,39 @@ - +
- -
- - -
-
-
-

Docs Shared With name; ?>

+ +
+ + +
+
+
+

Docs Shared With name; ?>

+ +
+ + Share Docs
-
- - -
-
- +
+
+ + + +
@@ -30,8 +45,8 @@ - - + + @@ -42,18 +57,40 @@ $value) { ?> - + + - + + @@ -73,6 +110,57 @@ + + + @@ -80,20 +168,112 @@ - - + + \ No newline at end of file
TemplateStatusServiceDoc Status Action
- - Approved - - Pending Approval - - Rejected - + + + + Approved + + Pending Approval + + Rejected + + + Not Shared + Preview + + +