diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 166dccc2..22cb5f00 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -654,7 +654,8 @@ $routes->group("employeeRest", ["filter" => ['appSignature' , 'authJWT']], funct $routes->post("ticketSave", "ThzController::ticketSave"); }); - + //API FAQ + $routes->match(['get','post','delete'], 'FAQ', 'AppContentManagementController::FAQ'); //claims $routes->post('initiateClaim',"EmployeeRestController::initiateClaim"); @@ -791,6 +792,9 @@ $routes->post('ticketAutoFetchDetails',"ThzController::ticketAutoFetchDetails"); $routes->match(['get','post','put'], 'ticketType', 'ThzController::ticketType'); $routes->get("ticketHistoryList", "ThzController::ticketHistoryList"); +// General FAQ +$routes->match(['get','post','delete'], 'FAQ', 'AppContentManagementController::FAQ'); + //for testing $routes->group('test', function($routes) { diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php index da65a7b1..a85d1bd6 100755 --- a/app/Controllers/AppContentManagementController.php +++ b/app/Controllers/AppContentManagementController.php @@ -11,6 +11,7 @@ use CodeIgniter\API\ResponseTrait; use App\Models\AddImgModel; use App\Models\FEContentModel; use App\Models\ClientModel; +use App\Models\FAQModel; class AppContentManagementController extends AdminController { @@ -19,6 +20,7 @@ class AppContentManagementController extends AdminController protected $addImgModel; protected $feContentModel; protected $clientModel; + protected $faqModel; public function __construct() @@ -27,6 +29,7 @@ class AppContentManagementController extends AdminController $this->addImgModel = new AddImgModel(); $this->feContentModel = new FEContentModel(); $this->clientModel = new ClientModel(); + $this->faqModel = new FAQModel(); } //listing public function add_image_index() @@ -156,4 +159,139 @@ class AppContentManagementController extends AdminController echo view('layout/footer'); } + + // + // public function FAQ() + // { + + // $data['tab_name'] = "FAQ's"; + // $data['page_name'] = "FAQ's"; + // return $this->loadLayout('faq_list', $data); + + // $returnType = strtolower($this->request->getGet('return_type') ?? 'api'); + + // $data = $this->request->getGet(); + + // $faq_list = $this->faqModel->select('*')->where('is_active', 1)->orderBy('id', 'desc')->findAll(); + + // if ($returnType === 'api') { + // if (empty($faq_list)) { + // $this->myLogger->logme('error', 'empty tickets in ticket list: ' . json_encode($faq)); + // return $this->response->setJSON([ 'status' => 'error','message' => 'No Details found'])->setStatusCode(404); + // } + // } else { + // $data['tab_name'] = "FAQ's"; + // $data['page_name'] = "FAQ's"; + // return $this->loadLayout('faq_list', $data); + // } + + // return $this->response->setJSON([ + // 'status' => 'success', + // 'data' => [], + // ])->setStatusCode(200); + // } + + + + public function FAQ() + { + $method = strtolower($this->request->getMethod()); + $returnType = strtolower($this->request->getGet('return_type') ?? 'api'); + $ref = ['timestamp' => date('Y-m-d H:i:s')]; + + try { + // --- 1. POST: CREATE OR UPDATE --- + if ($method === 'post') { + $id = $this->request->getPost('faq_id'); + $data = array_filter($this->request->getPost(), fn($v) => $v !== '' && $v !== null); + + if (empty($id)) { + $status = $this->faqModel->insert($data); + $msg = "Created"; + } else { + $status = $this->faqModel->update($id, $data); + $msg = "Updated"; + } + + // if ($returnType === 'web') { + // return redirect()->back()->with($status ? 'success' : 'error', "FAQ $msg " . ($status ? 'successfully' : 'failed')); + // } + + // return $this->response->setJSON([ + // ])->setStatusCode($result ? 200 : 400); + return $this->response->setJSON([ + 'status' => $status ? 'success' : 'error', + 'message' => "FAQ $msg " . ($status ? 'successfully' : 'failed'), + 'code' => $status ? 200 : 400, + 'data' => $data, + 'ref' => $ref + ])->setStatusCode($status ? 200 : 400); + } + + // --- 2. GET: FETCH LIST OR SINGLE --- + elseif ($method === 'get') { + + $id = $this->request->getGet('faq_id'); + + if (!empty($id)) { + // $row = $this->faqModel->where('is_active', 1)->find($id); + $row = $this->faqModel->find($id); + $data['faq_list'] = $row ? [$row] : []; + } else { + // $data['faq_list'] = $this->faqModel->where('is_active', 1)->orderBy('id', 'desc')->findAll(); + $data['faq_list'] = $this->faqModel->orderBy('id', 'desc')->findAll(); + } + + if ($returnType === 'web') { + $data['tab_name'] = "FAQ's"; + $data['page_name'] = "FAQ's"; + // print_r($data);die; + return $this->loadLayout('faq_list', $data); + } + + // API Response Logic + if (empty($data['faq_list'])) { + return $this->response->setJSON([ + 'status' => $returnType === 'web' ? false : 'error', + 'message' => 'No data found', + 'code' => 404, + 'data' => [], + 'ref' => $ref + ])->setStatusCode(200); // Using 200 with error status is common for mobile apps to prevent crashes + } + + return $this->response->setJSON([ + 'status' => $returnType === 'web' ? true : 'success', + 'message' => 'Data retrieved', + 'code' => 200, + 'data' => $data, + 'ref' => $ref + ])->setStatusCode(200); + } + + // --- 3. DELETE: SOFT DELETE --- + elseif ($method === 'delete') { + $id = $this->request->getGet('faq_id'); + $status = (!empty($id)) ? $this->faqModel->update($id, ['is_active' => 0]) : false; + + return $this->response->setJSON([ + 'status' => $status ? ($returnType === 'web' ? true : 'success') : ($returnType === 'web' ? false : 'error'), + 'message' => $status ? 'Data removed successfully' : 'Failed to remove or ID missing', + 'code' => $status ? 200 : 400, + 'data' => [], + 'ref' => $ref + ])->setStatusCode( 200 ); + } + + } catch (\Throwable $e) { + $msg = $e->getMessage(); + return $this->response->setJSON([ + 'status' => $returnType === 'web' ? false : 'error', + 'code' => 500, + 'message' => $msg, + 'ref' => ['file' => $e->getFile(), 'line' => $e->getLine()] + ])->setStatusCode(500); + } + } + } \ No newline at end of file diff --git a/app/Controllers/PayoutController.php b/app/Controllers/PayoutController.php index 29e8b555..90d501dc 100644 --- a/app/Controllers/PayoutController.php +++ b/app/Controllers/PayoutController.php @@ -51,12 +51,14 @@ class PayoutController extends BaseController $data = $this->request->getPost(); // print_r($data); die; - $agent_id = $data['agent_id'] ?? null; + // $agent_id = $data['agent_id'] ?? null; because dropdown hided + $pos_id = $data['pos_id'] ?? null; $status_id = $data['status_id'] ?? null; $start_date = $data['start_date'] ?? null; $end_date = $data['end_date'] ?? null; - $payout_data = $this->invoiceModel->invoiceList($agent_id, $status_id, $start_date, $end_date); + // $payout_data = $this->invoiceModel->invoiceList($agent_id, $status_id, $start_date, $end_date); // because dropdown hided + $payout_data = $this->invoiceModel->invoiceList($pos_id, $status_id, $start_date, $end_date); $payout_data['payout_list_data'] = $payout_data; $payout_data = view('payout_list', $payout_data); @@ -86,7 +88,8 @@ class PayoutController extends BaseController // for list $data['payout_status'] = $this->payout_status; - $data['agent_list'] = $this->invoiceModel->agentList(); + // $data['agent_list'] = $this->invoiceModel->agentList(); // because dropdown hided + $data['pos_list'] = $this->invoiceModel->posList(); $data['page_name'] = "Invoices"; $payout_data['payout_list_data'] = $this->invoiceModel->invoiceList(); $data['payout_list'] = view('payout_list', $payout_data); @@ -204,8 +207,9 @@ class PayoutController extends BaseController $title = $type === 'add' ? 'Add Payouts' : ($type === 'edit' ? 'Edit Payouts' + : ($type === 'view' ? 'View Payouts' : ($type === 'adjustment' ? 'Payouts Adjustment' - : 'Payouts')); + : 'Payouts'))); $data['tab_name'] = $title; $data['page_name'] = $title; @@ -215,10 +219,12 @@ class PayoutController extends BaseController if($type == 'add') { $data['agents'] = $this->invoiceModel->agentList(['is_active' => 1]); // common both add and edit + $data['pos_list'] = $this->invoiceModel->posList(['is_active' => 1]); // common both add and edit } else { $data['agents'] = $this->invoiceModel->agentList(); // common both add and edit + $data['pos_list'] = $this->invoiceModel->posList(); // common both add and edit } // $data['checked_policy_numbers'] = []; // $data['invoice'] = []; @@ -236,16 +242,21 @@ class PayoutController extends BaseController return $this->loadLayout('invoice_policy_mapping_add', $data); } - if (($type === 'edit' || $type === 'adjustment') && !empty($id)) { + if (($type === 'edit' || $type === 'view' || $type === 'adjustment') && !empty($id)) { $invoice = $this->invoiceModel->where('id', $id)->first(); + // print_r($invoice);die; $data['freeze_edit'] = $this->auditHistory->where('table_name', 'partner_invoice')->where('pk', $id)->countAllResults(); - + if($type === 'view'){ $data['freeze_edit'] = 1; } - $agentId = $invoice['agent_id'] ?? null; + // $agentId = $invoice['agent_id'] ?? null; + $posId = $invoice['pos_id'] ?? null; - $data['payouts'] = $this->invoiceModel->payoutList(2 ,$agentId,$id); - $data['extra_payouts'] = $agentId ? $this->invoiceModel->payoutList(3, $agentId) : []; + // $data['payouts'] = $this->invoiceModel->payoutList(2 ,$agentId,$id); + // $data['extra_payouts'] = $agentId ? $this->invoiceModel->payoutList(3, $agentId) : []; + $data['payouts'] = $this->invoiceModel->payoutList(2 ,$posId,$id); + // print_r($data['payouts']);die; + $data['extra_payouts'] = $posId ? $this->invoiceModel->payoutList(3, $posId) : []; $invoice_items = $this->invoiceItemModel->where('invoice_id', $id)->findAll(); @@ -518,6 +529,7 @@ class PayoutController extends BaseController // Get invoice data from database $invoiceData = $this->getInvoiceData($invoiceId); + // print_r($invoiceData);die; if (empty($invoiceData)) { return $this->respond([ @@ -591,6 +603,27 @@ class PayoutController extends BaseController } + // private function getInvoiceData($invoiceId) + // { + // $invoice_data = $this->invoiceModel + // ->select(' + // partner_invoice.*, + // pa.name as agent_name, + // pa.email as agent_email, + // pa.mobile as agent_mobile, + // pa.address as agent_address, + // pa.agent_code, + // pa.certificate_file_name, + // pa.commission_retain + // ') + // ->join('partner_agent pa', 'partner_invoice.agent_id = pa.id') + // ->where('partner_invoice.is_active', 1) + // ->where('partner_invoice.id', $invoiceId) + // ->first(); + + // return $invoice_data; + // } + private function getInvoiceData($invoiceId) { $invoice_data = $this->invoiceModel @@ -604,9 +637,20 @@ class PayoutController extends BaseController pa.address as agent_address, pa.agent_code, pa.certificate_file_name, - pa.commission_retain + pa.commission_retain, + pos.name as pos_name, + pos.email as pos_email, + pos.mobile as pos_mobile, + pos.address as pos_address, + pos.city as pos_city, + pos.pincode as pos_pincode, + pos.state as pos_state, + pos.pos_code, + pos.certificate_file_name as pos_certificate_file_name, + pos.bank_name,pos.account_holder_name,pos.account_number,pos.ifsc_code, ') - ->join('partner_agent pa', 'partner_invoice.agent_id = pa.id') + ->join('partner_agent pa', 'partner_invoice.agent_id = pa.id','left') + ->join('partner_pos pos', 'partner_invoice.pos_id = pos.id') ->where('partner_invoice.is_active', 1) ->where('partner_invoice.id', $invoiceId) ->first(); diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 48f3c7a3..22451e89 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -585,11 +585,11 @@ class UserController extends AdminController try{ // Listing if ($method === 'get') { - $types = $this->partnerStaffModel->findAll(); - if (empty($types)) { - return $this->response->setJSON(['status' => 'error','message' => 'No Staff found'])->setStatusCode(404); + $manager = $this->partnerStaffModel->where('role_id',1)->findAll(); + if (empty($manager)) { + return $this->response->setJSON(['status' => 'error','message' => 'No Manager found'])->setStatusCode(404); } - return $this->response->setJSON(['status' => 'success','data' => $types])->setStatusCode(200); + return $this->response->setJSON(['status' => 'success','data' => $manager])->setStatusCode(200); } // add/update diff --git a/app/Models/FAQModel.php b/app/Models/FAQModel.php new file mode 100644 index 00000000..aa7ca44f --- /dev/null +++ b/app/Models/FAQModel.php @@ -0,0 +1,56 @@ +select(" partner_invoice.*, @@ -105,14 +105,21 @@ class InvoiceModel extends Model WHEN payout_status = 2 THEN 'Completed' END AS status_text, - partner_agent.name as agent_name + partner_agent.name as agent_name, + partner_pos.name as pos_name + ") - ->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id') + ->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id','left') + ->join('partner_pos', 'partner_invoice.pos_id = partner_pos.id') ->where('partner_invoice.is_active', 1) ->where('partner_invoice.broker_id', 1); - if(!empty($agent_id)){ - $data->where('partner_invoice.agent_id', $agent_id); + // if(!empty($agent_id)){ + // $data->where('partner_invoice.agent_id', $agent_id); + // } // because dropdown hided + + if(!empty($pos_id)){ + $data->where('partner_invoice.pos_id', $pos_id); } if(!empty($status_id)){ @@ -128,7 +135,8 @@ class InvoiceModel extends Model ->where('partner_invoice.invoice_date <=', $endDate); } - if(!empty($agent_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ + // if(!empty($agent_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ + if(!empty($pos_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ $fromDate = date('Y-m-d', strtotime('-60 days')); $toDate = date('Y-m-d 23:59:59'); @@ -153,6 +161,21 @@ class InvoiceModel extends Model return $this->db->table('partner_agent')->get()->getResultArray(); } + public function posList(array $params = []) + { + $builder = $this->db->table('partner_pos') + ->select('partner_pos.*, partner_staff.name AS manager_name') + ->join('partner_staff', 'partner_staff.id = partner_pos.manager_id', 'left') + ->orderBy('partner_pos.id', 'DESC'); + + if (isset($params['is_active'])) { + $builder->where('partner_pos.is_active', $params['is_active']); + } + + return $builder->get()->getResultArray(); + } + + public function utrSummary($invoice_id) { $data = $this->select(" @@ -194,7 +217,7 @@ class InvoiceModel extends Model } - public function payoutList($flag, $agentId = null, $invoiceId = null) + public function payoutList($flag, $posId = null, $invoiceId = null) { $builder = $this->db->table('policy_transaction pt') ->select(' @@ -210,13 +233,15 @@ class InvoiceModel extends Model pii.commission_amount as paid_amount, pi.payout_status, pp.id as partner_policy_id, - pp.policy_transaction_id + pp.policy_transaction_id, + pt.pos_id as posId ') ->join('partner_invoice_items pii','pii.policy_no = pt.policy_no','left') ->join('partner_invoice pi','pi.id = pii.invoice_id','left') ->join('partner_policy pp','pt.policy_no = pp.policy_number AND pt.agent_id = pp.agent_id AND pt.id = pp.policy_transaction_id') ->where('pt.is_active',1) - ->where('pt.agent_id IS NOT NULL'); + ->where('pt.pos_id IS NOT NULL'); + // ->where('pt.agent_id IS NOT NULL'); if ($flag == 1) { // Add mode // EXCLUDE all policies that exist in partner_invoice_items @@ -230,16 +255,22 @@ class InvoiceModel extends Model if ($invoiceId) { $builder->where('pi.id', $invoiceId); // only policies of this invoice } - if ($agentId) { - $builder->where('pt.agent_id', $agentId); + // if ($agentId) { + // $builder->where('pt.agent_id', $agentId); + // } + if ($posId) { + $builder->where('pt.pos_id', $posId); } } if ($flag == 3) { // Extra policies // Policies not assigned to any invoice $builder->where('pii.id IS NULL', null, false); - if ($agentId) { - $builder->where('pt.agent_id', $agentId); + // if ($agentId) { + // $builder->where('pt.agent_id', $agentId); + // } + if ($posId) { + $builder->where('pt.pos_id', $posId); } } diff --git a/app/Models/PartnerStaffModel.php b/app/Models/PartnerStaffModel.php index f79f06ad..8c5ca862 100755 --- a/app/Models/PartnerStaffModel.php +++ b/app/Models/PartnerStaffModel.php @@ -16,7 +16,7 @@ class PartnerStaffModel extends Model protected $useSoftDeletes = false; // allowed fields for insert/update - protected $allowedFields = ['name','email','mobile','emp_id','role_id','email_otp','is_active','created_by','updated_by','manager_id','retention_rate']; + protected $allowedFields = ['name','email','mobile','emp_id','role_id','email_otp','is_active','created_by','updated_by','manager_id','retention_rate','nhance_branch_id']; // automatic timestamps protected $useTimestamps = true; diff --git a/app/Views/UserList.php b/app/Views/UserList.php index 1e3e2766..e1f0f127 100755 --- a/app/Views/UserList.php +++ b/app/Views/UserList.php @@ -489,9 +489,9 @@ table.dataTable tbody td {