diff --git a/.env.sample b/.env.sample deleted file mode 100644 index 6af188a4..00000000 --- a/.env.sample +++ /dev/null @@ -1,155 +0,0 @@ -#-------------------------------------------------------------------- -# Example Environment Configuration file -# -# This file can be used as a starting point for your own -# custom .env files, and contains most of the possible settings -# available in a default install. -# -# By default, all of the settings are commented out. If you want -# to override the setting, you must un-comment it by removing the '#' -# at the beginning of the line. -#-------------------------------------------------------------------- - -#-------------------------------------------------------------------- -# ENVIRONMENT -#-------------------------------------------------------------------- - -CI_ENVIRONMENT = development - -#-------------------------------------------------------------------- -# APP -#-------------------------------------------------------------------- - -app.baseURL = 'http://localhost/nhance/' -# If you have trouble with `.`, you could also use `_`. -# app_baseURL = '' -# app.forceGlobalSecureRequests = false -# app.CSPEnabled = false - -#-------------------------------------------------------------------- -# DATABASE -#-------------------------------------------------------------------- - - - -database.default.hostname = 119.18.54.85 -database.default.database = venbaehn_nhance -database.default.username = venbaehn_nhance_user1 -database.default.password = 'iM~X7(cR+}A-' -# database.default.DBDriver = MySQLi -# database.default.DBPrefix = -# database.default.port = 3306 - -database.default.hostname = 119.18.54.85 -database.default.database = venbaehn_nhance -database.default.username = venbaehn_nhance_user1 -database.default.password = 'iM~X7(cR+}A-' -# database.tests.DBDriver = MySQLi -# database.tests.DBPrefix = -# database.tests.port = 3306 - -#-------------------------------------------------------------------- -# CONTENT SECURITY POLICY -#-------------------------------------------------------------------- - -# contentsecuritypolicy.reportOnly = false -# contentsecuritypolicy.defaultSrc = 'none' -# contentsecuritypolicy.scriptSrc = 'self' -# contentsecuritypolicy.styleSrc = 'self' -# contentsecuritypolicy.imageSrc = 'self' -# contentsecuritypolicy.baseURI = null -# contentsecuritypolicy.childSrc = null -# contentsecuritypolicy.connectSrc = 'self' -# contentsecuritypolicy.fontSrc = null -# contentsecuritypolicy.formAction = null -# contentsecuritypolicy.frameAncestors = null -# contentsecuritypolicy.frameSrc = null -# contentsecuritypolicy.mediaSrc = null -# contentsecuritypolicy.objectSrc = null -# contentsecuritypolicy.pluginTypes = null -# contentsecuritypolicy.reportURI = null -# contentsecuritypolicy.sandbox = false -# contentsecuritypolicy.upgradeInsecureRequests = false -# contentsecuritypolicy.styleNonceTag = '{csp-style-nonce}' -# contentsecuritypolicy.scriptNonceTag = '{csp-script-nonce}' -# contentsecuritypolicy.autoNonce = true - -#-------------------------------------------------------------------- -# COOKIE -#-------------------------------------------------------------------- - -# cookie.prefix = '' -# cookie.expires = 0 -# cookie.path = '/' -# cookie.domain = '' -# cookie.secure = false -# cookie.httponly = false -# cookie.samesite = 'Lax' -# cookie.raw = false - -#-------------------------------------------------------------------- -# ENCRYPTION -#-------------------------------------------------------------------- - -# encryption.key = -# encryption.driver = OpenSSL -# encryption.blockSize = 16 -# encryption.digest = SHA512 - -#-------------------------------------------------------------------- -# HONEYPOT -#-------------------------------------------------------------------- - -# honeypot.hidden = 'true' -# honeypot.label = 'Fill This Field' -# honeypot.name = 'honeypot' -# honeypot.template = '' -# honeypot.container = '
{template}
' - -#-------------------------------------------------------------------- -# SECURITY -#-------------------------------------------------------------------- - -# security.csrfProtection = 'cookie' -# security.tokenRandomize = false -# security.tokenName = 'csrf_token_name' -# security.headerName = 'X-CSRF-TOKEN' -# security.cookieName = 'csrf_cookie_name' -# security.expires = 7200 -# security.regenerate = true -# security.redirect = false -# security.samesite = 'Lax' - -#-------------------------------------------------------------------- -# SESSION -#-------------------------------------------------------------------- - -# session.driver = 'CodeIgniter\Session\Handlers\FileHandler' -# session.cookieName = 'ci_session' -# session.expiration = 7200 -# session.savePath = null -# session.matchIP = false -# session.timeToUpdate = 300 -# session.regenerateDestroy = false - -#-------------------------------------------------------------------- -# LOGGER -#-------------------------------------------------------------------- - -# logger.threshold = 4 - -#-------------------------------------------------------------------- -# CURLRequest -#-------------------------------------------------------------------- - -# curlrequest.shareOptions = true - -#-------------------------------------------------------------------- -# Google-OAUTH-Credentials -#-------------------------------------------------------------------- - -GOOGLE_OAUTH_APP_NAME = 'OAuth' -GOOGLE_OAUTH_CLIENT_ID = '696241936560-m2mr272ge7vr2n4q36c22l3d2gdgi90l.apps.googleusercontent.com' -GOOGLE_OAUTH_CLIENT_SECRET = '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' -GOOGLE_OAUTH_REDIRECT_URI = 'http://localhost/nhance/oauth2callback' -GOOGLE_OAUTH_SCOPES = "https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile" diff --git a/app/Config/App.php b/app/Config/App.php index ec06b887..884c19f1 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -16,7 +16,7 @@ class App extends BaseConfig * * http://example.com/ */ - public string $baseURL = ''; + public string $baseURL = 'http://localhost/nhance/'; /** * Allowed Hostnames in the Site URL other than the hostname in the baseURL. diff --git a/app/Config/Database.php b/app/Config/Database.php index e2450ec1..388b1b03 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -51,10 +51,10 @@ class Database extends Config */ public array $tests = [ 'DSN' => '', - 'hostname' => '127.0.0.1', - 'username' => '', - 'password' => '', - 'database' => ':memory:', + 'hostname' => '119.18.54.85', + 'username' => 'venbaehn_nhance_user1', + 'password' => 'iM~X7(cR+}A-', + 'database' => 'venbaehn_nhance', 'DBDriver' => 'SQLite3', 'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS 'pConnect' => false, diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 33f81ae8..1d535aea 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -33,7 +33,26 @@ $routes->group("/client", ["filter" => "authMVC"], function($routes){ $routes->get("list", "ClientController::index"); $routes->get("create", "ClientController::clientOnboarding"); + $routes->get('deposit/(:num)', 'ClientController::deposit/$1'); + // application/config/routes.php + +// Add a route for the view_Deposit method +$routes->get('view_deposit/(:num)', 'ClientController::view_Deposit/$1'); +$routes->get('createtransaction', 'ClientController::createtransaction'); + +$routes->post('save_deposit', 'ClientController::saveDeposit'); + + + + + + + // $routes->get('view_Deposit/(:num)/(:num)','ClientController/view_Deposit/$1/$2'); + + + $routes->get("list/(:any)", "ClientController::editClientOnboarding/$1"); + $routes->group("general", ["filter" => "authMVC"], function($routes){ $routes->post("create", "ClientController::createClientGeneralInfo"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 554c8a2f..bc4506e1 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1,7 +1,7 @@ userModel = new UserModel(); $this->clientBranchModel = new ClientBranchModel(); $this->clientKYCDocsModel = new ClientKYCDocsModel(); + $this->clientDepositModel = new ClientDepositModel(); $this->clientPolicyModel = new ClientPolicyModel(); $this->clientRMModel = new ClientRMModel(); $this->insurerBranchModel = new InsurerBranchModel(); @@ -116,6 +120,79 @@ class ClientController extends AdminController echo view('layout/footer'); } + // In your controller + public function deposit($id = null) + { + $headerData['page_name'] = 'Client Deposit'; + + $data['clientData'] = $this->clientPolicyModel->getinsurerswithclientid($id); + $data['depositsummary'] = $this->clientPolicyModel->getDepositlistsummary($id); + + // Fetch associated insurer names and balances + $balances = $this->clientPolicyModel->getBalances($id); + $data['balances'] = $balances; + + echo view('layout/header', $headerData); + echo view('client_deposit_list', $data); + echo view('layout/footer'); + } + + + +public function view_Deposit($insurerId) { + // Load your model to fetch data based on $clientId and $insurerId + $subTypeOptions = [ + 1 => 'Deposit', + 2 => 'Adjustment', + 3 => 'Deletion', + // Add more options as needed + ]; + $data['subTypeOptions'] = $subTypeOptions; + $headerData['page_name'] = 'Client Deposit'; + $data['insurerName']= $this->insurerModel->getInsurerName($insurerId); + $loggedInUserID = get_session_userid(); + // $data['clientData']= $this->clientPolicyModel->getinsurerswithinsurenceid($insurerId); + $clientId = $this->request->getGet('client_id'); + $data['depositdata']= $this->clientPolicyModel->getdepositData($clientId,$insurerId); + $data['clientData'] = $this->clientPolicyModel->getClientById($clientId); + $data['deposiamount'] = $this->clientPolicyModel->getDepositSummary($clientId, $insurerId); + + +// print_r($data['depositdata'] );die; + // Load the view for the new list page + echo view('layout/header', $headerData); + echo view('view_deposit',$data); + echo view('layout/footer'); +} + + + + +public function saveDeposit() +{ + // Retrieve form data from POST request + $loggedInUserID = get_session_userid(); + + // Prepare the array with data + $data = [ + 'amount' => $this->request->getPost('amount'), + 'sub_type_id' => $this->request->getPost('sub_type_id'), + 'client_id' => $this->request->getPost('client_id'), + 'insurer_id' => $this->request->getPost('insurer_id'), + 'description' => $this->request->getPost('description'), + 'transaction_type' => $this->request->getPost('transaction_type') ?: 'Credit', + 'updated_by' => 1, // You need to set the correct value for updated_by + ]; + + // Call the saveDeposit function from DepositHelper + $response = DepositHelper::saveDeposit($data, $loggedInUserID); + + // Return a boolean value based on success + return $this->response->setJSON(['success' => $response['success']]); +} + + + public function editClientOnboarding($id = null) { diff --git a/app/Helpers/DepositHelper.php b/app/Helpers/DepositHelper.php new file mode 100644 index 00000000..a25aff9e --- /dev/null +++ b/app/Helpers/DepositHelper.php @@ -0,0 +1,99 @@ + $data['amount'], + 'sub_type' => $data['sub_type_id'], + 'client_id' => $data['client_id'], + 'insurer_id' => $data['insurer_id'], + 'description' => $data['description'], + 'transaction_type' => $data['transaction_type'], + 'is_active' => 1, + 'created_by' => $loggedInUserID, + 'updated_by' => $data['updated_by'], + 'balance' => $newBalance, // Include the new balance in the data array + ]; + + // Insert data and get the insert ID + $insertId = $model->insert($insertData); + + // Return the response + if ($insertId) { + return [ + 'success' => true, + 'message' => 'Transaction saved successfully', + 'insert_id' => $insertId, + ]; + } else { + return [ + 'success' => false, + 'message' => 'Failed to save transaction', + ]; + } + } + /** + * Calculate the last balance based on client and insurer ID. + * + * @param int $clientId The client ID. + * @param int $insurerId The insurer ID. + * + * @return float The last known balance. + */ + public static function calculateLastBalance(int $clientId, int $insurerId): float + { + $model = new ClientDepositModel(); + + $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE client_id = ? AND insurer_id = ? ORDER BY created_at DESC LIMIT 1"; + $getLastBalanceParams = [$clientId, $insurerId]; + + $lastBalance = $model->query($getLastBalanceQuery, $getLastBalanceParams)->getRow()->balance ?? 0; + + return $lastBalance; + } +} + +?> diff --git a/app/Models/ClientDepositModel.php b/app/Models/ClientDepositModel.php new file mode 100644 index 00000000..0f2573b5 --- /dev/null +++ b/app/Models/ClientDepositModel.php @@ -0,0 +1,29 @@ +get() ->getResult(); } + public function getinsurerswithclientid($id){ + + return $this->db->table('client_policy') + ->select('client_policy.*') + ->select('insurers.name as insurer_name, insurers.short_name as insurer_short') + ->select('clients.client_name as client_name') + ->join('clients','clients.id=client_policy.client_id') + ->join('insurers', 'insurers.id = client_policy.insurer_id') + ->where('client_policy.client_id', $id) + ->groupBy('client_policy.insurer_id') + ->groupBy('client_policy.client_id', $id) // Group by insurer_id + ->get() + ->getResult(); + } + + public function getinsurerswithinsurenceid($insurerId){ + + return $this->db->table('client_policy') + ->select('client_policy.*') + ->select('insurers.name as insurer_name, insurers.short_name as insurer_short') + ->select('clients.client_name as clientname, clients.short_name as clientshort') + ->join('insurers', 'insurers.id = client_policy.insurer_id') + ->join('clients', 'clients.id = client_policy.client_id') + ->where('client_policy.insurer_id', $insurerId) + ->groupBy('client_policy.client_id') // Group by insurer_id + ->get() + ->getResult(); + } + public function getClientById($id) { + $query = $this->db->table('clients')->getWhere(['id' => $id]); + // Debug statement + return $query->getRow(); + } + public function getDepositData($clientId, $insurerId) + { + // Fetch the deposit data based on client and insurer IDs + return $this->db->table('cash_deposit') + ->select('cash_deposit.*') + ->select('insurers.name as insurer_name, insurers.short_name as insurer_short') + ->select('clients.client_name as clientname, clients.short_name as clientshort') + ->select('user_profiles.first_name as username') + ->join('user_profiles','user_profiles.id=cash_deposit.created_by') + ->join('insurers', 'insurers.id = cash_deposit.insurer_id') + ->join('clients', 'clients.id = cash_deposit.client_id') + + ->where('cash_deposit.client_id', $clientId) + ->where('cash_deposit.insurer_id', $insurerId) // Add this line to filter by insurer_id + ->get() + ->getResult(); + } + public function getDepositSummary($clientId, $insurerId) +{ + // Fetch the sum of credit and debit transactions and calculate the balance + return $this->db->table('cash_deposit') + ->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE 0 END) AS total_credit') + ->select('SUM(CASE WHEN transaction_type = "Debit" THEN amount ELSE 0 END) AS total_withdraw') + ->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance') + ->select('SUM(CASE WHEN sub_type = 3 THEN amount ELSE 0 END) AS total_refund') + ->where('client_id', $clientId) + ->where('insurer_id', $insurerId) + ->get() + ->getRow(); +} +// Inside your clientPolicyModel +// Inside your clientPolicyModel +// public function getDepositDataWithBalance($clientId, $insurerId) +// { +// // Fetch deposit data with balance information +// $builder = $this->db->table('cash_deposit'); +// $builder->select('id, created_at, description, sub_type, amount, transaction_type'); + +// $builder->where('client_id', $clientId); +// $builder->where('insurer_id', $insurerId); +// $builder->orderBy('created_at', 'asc'); + +// $depositData = $builder->get()->getResult(); + +// $currentBalance = 0; + +// foreach ($depositData as $transaction) { +// if ($transaction->transaction_type == 'Credit') { +// $currentBalance += $transaction->amount; +// } elseif ($transaction->transaction_type == 'Debit') { +// $currentBalance -= $transaction->amount; +// } + +// $transaction->balance = $currentBalance; +// } + +// return $depositData; +// } + + + + +public function getBalances($clientId) +{ + $depositsummary = $this->getDepositlistsummary($clientId); + $balances = []; + + foreach ($depositsummary as $summary) { + $insurerId = $summary->insurer_id; + $balances[$insurerId] = $summary; + } + + return $balances; +} + +public function getDepositlistsummary($id) +{ + return $this->db->table('cash_deposit') + ->select('insurer_id') + ->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance') + ->where('client_id', $id) + ->groupBy('insurer_id') + ->get() + ->getResult(); +} + } diff --git a/app/Models/InsurerModel.php b/app/Models/InsurerModel.php index 6e6b7a1f..77ad5d49 100644 --- a/app/Models/InsurerModel.php +++ b/app/Models/InsurerModel.php @@ -30,4 +30,33 @@ class InsurerModel extends Model ->getResult(); } -} + public function getInsurerName($insurerId) + { + // Fetch the insurer name based on the insurer ID + $query = $this->select('id,name') + ->where('id', $insurerId) + ->get(); + + if ($query->resultID->num_rows > 0) { + $result = $query->getRow(); + return $result; + } + + return null; // or handle accordingly if the insurer is not found + } + // public function getdepositData($id) + // { + // // Fetch the insurer name based on the insurer ID + // $query = $this->db->table('cash_deposit') + + + // ->get() + + + // ->getResult(); + + // } + + } + + \ No newline at end of file diff --git a/app/Views/add_transaction.php b/app/Views/add_transaction.php new file mode 100644 index 00000000..c8c64190 --- /dev/null +++ b/app/Views/add_transaction.php @@ -0,0 +1,67 @@ + + \ No newline at end of file diff --git a/app/Views/client_deposit_list.php b/app/Views/client_deposit_list.php new file mode 100644 index 00000000..2d48ccc6 --- /dev/null +++ b/app/Views/client_deposit_list.php @@ -0,0 +1,97 @@ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Insurer NameCurrent BalanceAction
+ + + insurer_name;?> + + ₹ + insurer_id; + + // Check if the balance information exists for the insurer + if (isset($balances[$insurerId])) { + $balance = $balances[$insurerId]->balance; + echo $balance; + } else { + echo "N/A"; // Display "Not Available" if balance information is not present + } + ?> + + + insurer_id}?client_id={$value->client_id}"); ?>"> + View Deposit + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/app/Views/client_list.php b/app/Views/client_list.php index fb454c59..09a34662 100644 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -38,6 +38,11 @@ diff --git a/app/Views/view_deposit.php b/app/Views/view_deposit.php new file mode 100644 index 00000000..2e75f579 --- /dev/null +++ b/app/Views/view_deposit.php @@ -0,0 +1,304 @@ + + +
+
+
+
+
+
+
+
+ +

Deposit Summary Of short_name?>

+ +
+
+ +
+
+ + + +

name; ?>

+
+
+ +
+
+
+

Deposits

+

total_credit?>

+
+ +
+

Consumed

+

total_withdraw?>

+
+
+

Refund

+

total_refund?>

+
+
+

Current Balance

+

balance?>

+
+
+
+
+
+
+
+ +
+
+
+

+
+
+
+
+
+ +
+
+
+
+
+
+

Transaction Details

+
+
+ + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DateUserDescriptionSub TypeCreditDebitBalnce
created_at)); ?>username; ?>description; ?>sub_type]) ? $subTypeOptions[$row->sub_type] : ''; ?>transaction_type == 'Credit') ? $row->amount : ''; ?>transaction_type == 'Debit') ? $row->amount : ''; ?>balance; ?>
+
+
+
+ +
+ + + + + + + + + + + + +