diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 857f4c69..0a174d34 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -421,6 +421,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->match(['get', 'post', 'delete'], 'nhanceBranchMaster', 'MasterController::nhanceBranchMaster'); $routes->match(['get', 'post', 'delete'], 'vehicleTypeMaster', 'MasterController::vehicleTypeMaster'); $routes->match(['get', 'post', 'delete'], 'rtoMaster', 'MasterController::rtoMaster'); + $routes->match(['get', 'post', 'delete'], 'partnerPOS', 'MasterController::partnerPOS'); $routes->get('checkDuplicateCdAccount', 'MasterController::checkDuplicateCdAccount'); $routes->get('proceedExcelFileDataValidation', 'EmployeeController::proceedExcelFileDataValidation'); $routes->get('checkTpaApiEnable', 'EmployeeRestController::checkTpaApiEnable'); diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index fec5dc4e..8d8a161d 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -38,6 +38,7 @@ use App\Models\SettingsModel; use App\Models\VehicleModel; use App\Models\VehicleTypeModel; use App\Models\RTOModel; +use App\Models\PartnerPosModel; use CodeIgniter\CLI\CLI; @@ -2320,4 +2321,141 @@ class MasterController extends AdminController } } -} \ No newline at end of file + public function partnerPOS() + { + $posModel = new PartnerPosModel(); + $method = $this->request->getMethod(); + + if ($this->request->getMethod() === 'post') { + + $id = $this->request->getPost('pk'); + $data = $this->request->getPost(); + + unset($data['pk']); + + try { + // Certificate + $certificate = $this->uploadPOSFile('certificate_file_name', 'pos_certificate_files'); + if ($certificate !== null) { $data['certificate_file_name'] = $certificate; } else { unset($data['certificate_file_name']); } + + // PAN file + $panFile = $this->uploadPOSFile('pan_file_name', 'pos_certificate_files'); + if ($panFile !== null) { $data['pan_file_name'] = $panFile; } else { unset($data['pan_file_name']);} + + // Aadhaar file + $aadharFile = $this->uploadPOSFile('aadhar_file_name', 'pos_certificate_files'); + if ($aadharFile !== null) { $data['aadhar_file_name'] = $aadharFile; } else { unset($data['aadhar_file_name']);} + + } catch (\RuntimeException $e) { + return $this->respond([ 'status' => false, 'code' => 400, 'message' => $e->getMessage(), 'data' => $data ], 400); + } + + // INSERT / UPDATE + if (empty($id)) { + $status = $posModel->insert($data); + } else { + $status = $posModel->update($id, $data); + } + + if ($status) { + return $this->respond([ 'status' => true, 'code' => 200, 'message' => 'POS updated successfully', 'data' => $data ], 200); + } + + return $this->respond([ 'status' => false, 'code' => 400, 'message' => 'Failed to update', 'data' => $data ], 400); + } + elseif ($method === 'get') { + + $id = $this->request->getGet('pk') ?? null; + + $db = db_connect(); + + $builder = $db->table('partner_staff'); + + $data['manager_list'] = $builder->select('partner_staff.id, partner_staff.name') + ->where('partner_staff.is_active', 1) + ->where('partner_staff.role_id', 1) + ->get() + ->getResultArray(); + + + if (!empty($id)) { + + $data['pos_list'] = $posModel + ->select('partner_pos.*, partner_staff.name AS manager_name') + ->join('partner_staff', 'partner_staff.id = partner_pos.manager_id', 'left') + ->where('partner_pos.id', $id) + ->orderBy('partner_pos.id', 'DESC') + ->findAll(); + + if (!empty($data)) { + return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200); + } else { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200); + } + } + + $data['pos_list'] = $posModel + ->select('partner_pos.*, ps.name AS manager_name') + ->join('partner_staff ps', 'ps.id = partner_pos.manager_id', 'left') + ->orderBy('partner_pos.id', 'DESC') + ->findAll(); + + + return $this->loadLayout('pos_list', ['data' => $data,'tab_name' => 'POS details','page_name' => 'POS details']); + + } elseif ($method === 'delete') { + + // $input = $this->request->getRawInput(); + $id = $this->request->getGet('pk'); // ✅ THIS + $id = $id ?? null; + + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => 'No ID provided for deletion' + ], 200); + } + + $update_status = $posModel->where('id', $id)->set(['is_active' => 0])->update(); + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'Data removed successfully', + 'pk' => $id + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to remove data', + 'pk' => $id + ], 200); + } + } + } + + private function uploadPOSFile(string $fieldName, string $uploadDir) + { + $file = $this->request->getFile($fieldName); + + if (!$file || !$file->isValid()) { return null; } + + $allowedMime = [ 'image/jpg', 'image/jpeg', 'image/png', 'image/webp', 'application/pdf']; + + if (!in_array($file->getMimeType(), $allowedMime)) { throw new \RuntimeException('Invalid file format'); } + + $path = ROOTPATH . 'public/uploads/' . $uploadDir . '/'; + + if (!is_dir($path)) { mkdir($path, 0755, true); } + + $newName = $file->getRandomName(); + $file->move($path, $newName); + + return $newName; + } + + + } \ No newline at end of file diff --git a/app/Models/PartnerPosModel.php b/app/Models/PartnerPosModel.php new file mode 100644 index 00000000..6e897e35 --- /dev/null +++ b/app/Models/PartnerPosModel.php @@ -0,0 +1,132 @@ + 'required|min_length[3]', + // 'email' => 'permit_empty|valid_email|is_unique[partner_pos.email,id,{id}]', + // 'mobile' => 'permit_empty|numeric|max_length[20]|is_unique[partner_pos.mobile,id,{id}]', + // 'manager_id' => 'required|integer', + // ]; + + // protected $validationMessages = [ + // 'email' => [ + // 'is_unique' => 'Sorry, that email address is already registered.', + // ], + // ]; + + /** + * @var bool Whether to skip validation during inserts and updates. + */ + protected $skipValidation = false; + + /** + * @var bool Whether to clean data for SQL Injection. + */ + protected $cleanValidationRules = true; + + protected $beforeInsert = ["checkAndADDCreatedByValue"]; + protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; + + protected function checkAndADDCreatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['created_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['created_by'] = get_session_userid(); + } + + return $data; + } + + protected function checkAndUpdateUpdatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['updated_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['updated_by'] = get_session_userid(); + } + + return $data; + } + +} \ No newline at end of file diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index eb8bfea0..96061707 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -1808,6 +1808,9 @@
| S.No. | +POS Name | +POS Code | +Mobile | +Manager | +Status | +Action | +|
|---|---|---|---|---|---|---|---|
| = $slno++; ?> | += $row['name']; ?> | += $row['pos_code']; ?> | += $row['email']; ?> | += $row['mobile']; ?> | += $row['manager_name']; ?> | ++ + + + | ++ + | +
| No data available | +|||||||