- FEAT_CLIENTMODULE FEAT_DEPOSITSUMMARY_CONTD

This commit is contained in:
heama 2024-03-02 13:56:29 +05:30
parent d8fc4ab42c
commit f1f79af9bd
13 changed files with 852 additions and 162 deletions

View File

@ -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 = '<label>{label}</label><input type="text" name="{name}" value=""/>'
# honeypot.container = '<div style="display:none">{template}</div>'
#--------------------------------------------------------------------
# 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"

View File

@ -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.

View File

@ -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,

View File

@ -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");

View File

@ -1,7 +1,7 @@
<?php
namespace App\Controllers;
use App\Helpers\DepositHelper;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
@ -12,6 +12,7 @@ use App\Models\UserModel;
use App\Models\ClientModel;
use App\Models\ClientBranchModel;
use App\Models\ClientKYCDocsModel;
use App\Models\ClientDepositModel;
use App\Models\ClientPolicyModel;
use App\Models\ClientRMModel;
use App\Models\InsurerBranchModel;
@ -51,6 +52,8 @@ class ClientController extends AdminController
protected $policyGridModel;
protected $policyPremium1Model;
protected $policyPremium2Model;
protected $clientDepositModel;
public function __construct()
@ -62,6 +65,7 @@ class ClientController extends AdminController
$this->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)
{

View File

@ -0,0 +1,99 @@
<?php
// File: App\Helpers\DepositHelper.php
namespace App\Helpers;
use App\Models\ClientDepositModel;
class DepositHelper
{
/**
* Calculate the new balance based on the transaction type.
*
* @param float $lastBalance The last known balance.
* @param float $amount The transaction amount.
* @param string $transactionType The transaction type.
*
* @return float The new balance.
*/
public static function calculateBalance(float $lastBalance, float $amount, string $transactionType): float
{
return ($transactionType === 'Credit') ? $lastBalance + $amount : $lastBalance - $amount;
}
/**
* Save a deposit transaction.
*
* @param array $data The transaction data.
* @param float $newBalance The new balance.
*
* @return array The response array.
*/
public static function saveDeposit(array $data, int $loggedInUserID): array
{
// Retrieve the last known balance
$lastBalance = self::calculateLastBalance($data['client_id'], $data['insurer_id']);
// Calculate the new balance based on the transaction type
$newBalance = self::calculateBalance(
$lastBalance,
(float)$data['amount'],
$data['transaction_type'] ?: 'Credit'
);
// Insert data into cash_deposit table
$model = new ClientDepositModel();
// Insert data into the cash_deposit table
$insertData = [
'amount' => $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;
}
}
?>

View File

@ -0,0 +1,29 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class ClientDepositModel extends Model
{
protected $table = 'cash_deposit';
protected $primaryKey = 'id';
protected $allowedFields = [
'id',
'client_id',
'insurer_id',
'transaction_type',
'amount',
'sub_type',
'is_active',
"created_by",
"updated_by",
"created_at",
"updated_at",
"description",
"balance",
];
}

View File

@ -96,4 +96,123 @@ class ClientPolicyModel extends Model
->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();
}
}

View File

@ -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();
// }
}

View File

@ -0,0 +1,67 @@
<div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal Content is Responsive</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body p-4">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="field-1" class="control-label">Name</label>
<input type="text" class="form-control" id="field-1" placeholder="John">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="field-2" class="control-label">Surname</label>
<input type="text" class="form-control" id="field-2" placeholder="Doe">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="field-3" class="control-label">Address</label>
<input type="text" class="form-control" id="field-3" placeholder="Address">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="field-4" class="control-label">City</label>
<input type="text" class="form-control" id="field-4" placeholder="Boston">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="field-5" class="control-label">Country</label>
<input type="text" class="form-control" id="field-5" placeholder="United States">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="field-6" class="control-label">Zip</label>
<input type="text" class="form-control" id="field-6" placeholder="123456">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group no-margin">
<label for="field-7" class="control-label">Personal Info</label>
<textarea class="form-control" id="field-7" placeholder="Write something about yourself"></textarea>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-info waves-effect waves-light">Save changes</button>
</div>
</div>
</div>
</div><!-- /.modal -->

View File

@ -0,0 +1,97 @@
<div class="row" id="client_list">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row" style="margin-bottom:1rem;">
<div class="col-6" style="align-self: center;">
<h4 class="header-title" style="position: relative;">Client Deposit-</h4>
</div>
<div class="col-6" style="text-align: right; position: relative;top: 53px;">
<a href="<?= base_url("client/client_deposit"); ?>" type="button" id="btnAdd" class="btn btn-primary waves-effect waves-light" data-toggle="" data-placement="top" title="Add" data-trigger="hover">ADD</a>
</div>
</div>
<table class="table table-sm table-hover m-0 table-centered dt-responsive nowrap w-100" cellspacing="0"
id="tickets-table">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">Insurer Name</th>
<th class="font-weight-medium">Current Balance</th>
<th class="font-weight-medium">Action</th>
</tr>
</thead>
<tbody>
<tr>
<?php foreach ($clientData as $value): ?>
<td>
<?php echo $value->insurer_name;?>
</td>
<td>
<?php
$insurerId = $value->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
}
?>
</td>
<td>
<a class="dropdown-item" href="<?= base_url("client/view_deposit/{$value->insurer_id}?client_id={$value->client_id}"); ?>">
<i class="mdi mdi-eye mr-2 text-muted font-18 vertical-middle"></i>View Deposit
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div><!-- end col -->
</div>
<!-- end row -->
<script>
$(document).ready(function(){
$('#tickets-table').DataTable({
dom: "<'row'<'col-sm-0'f><'col-sm-9 text-right'B>>" ,
buttons: [
{
extend: 'csv',
text: 'CSV',
title: 'ClientList',
className: 'my_class',
exportOptions: {
columns: ':not(:last-child)'
},
}
],
language: {
search: "_INPUT_",
searchPlaceholder: "Search..."
},
});
})
</script>

View File

@ -38,6 +38,11 @@
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown"aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="<?= base_url("client/list/"); ?><?= $row->id;?>"><i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a class="dropdown-item" href="<?= base_url("client/deposit/{$row->id}"); ?>">
<i class="mdi mdi-cash mr-2 text-muted font-18 vertical-middle"></i>Deposit
</a>
<a class="dropdown-item" href="#"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete</a>
</div>
</div>

304
app/Views/view_deposit.php Normal file
View File

@ -0,0 +1,304 @@
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="text-center">
<div class="row">
<div class="col-md-6 col-xl-5">
<div class="py-1">
<i class="font-24"></i>
<h4 >Deposit Summary Of <?php echo $clientData->short_name?></h4>
</div>
</div>
<div class="col-md-8 col-xl-7">
<div class="py-1">
<i class=" font-24"></i>
<h4><?php echo $insurerName->name; ?></h4>
</div>
</div>
</div>
<div class="row mt-3 text-center">
<div class="col-3">
<p class="text-muted font-15 mb-1 text-truncate">Deposits</p>
<h4 style="font-size: 26px;"><i class="fe-arrow-up text-success mr-1"></i><?php echo $deposiamount->total_credit?></h4>
</div>
<div class="col-3">
<p class="text-muted font-15 mb-1 text-truncate">Consumed</p>
<h4 style="font-size: 26px;"><i class="fe-arrow-down text-danger mr-1"></i><?php echo $deposiamount->total_withdraw?></h4>
</div>
<div class="col-3">
<p class="text-muted font-15 mb-1 text-truncate">Refund</p>
<h4 style="font-size: 26px;"><i class="fe-arrow-up text-success mr-1"></i><?php echo $deposiamount->total_refund?></h4>
</div>
<div class="col-3">
<p class="text-muted font-15 mb-1 text-truncate">Current Balance</p>
<h4 style="font-size: 26px;"><i class="fe-credit-card text-sucess mr-1"></i><?php echo $deposiamount->balance?></h4>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title"></h4>
<div class="page-title-right">
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row" id="List-page">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row" style="margin-bottom:1rem;">
<div class="col-6" style="align-self: center;">
<h4 class="header-title" style="position: relative;">Transaction Details</h4>
</div>
<div class="col-6" style="text-align: right; position: relative;top: 51px;
right: 31px;">
<button type="button" id="btnAdd" class="btn btn-primary waves-effect waves-light" data-toggle="modal" data-target="#addTransactionModal">New</button>
</div>
</div>
<table class="table table-sm table-hover m-0 table-centered dt-responsive nowrap w-100" cellspacing="0" id="tickets-table">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">Date</th>
<th class="font-weight-medium">User</th>
<th class="font-weight-medium">Description</th>
<th class="font-weight-medium">Sub Type</th>
<th class="font-weight-medium">Credit</th>
<th class="font-weight-medium">Debit</th>
<th class="font-weight-medium">Balnce</th>
</tr>
</thead>
<tbody>
<?php foreach($depositdata as $row) { ?>
<tr id="<?php echo $row->id;?>">
<td class=""><?php echo date('d-m-y h:i A', strtotime($row->created_at)); ?></td>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->description; ?></td>
<td><?php echo isset($subTypeOptions[$row->sub_type]) ? $subTypeOptions[$row->sub_type] : ''; ?></td>
<td><?php echo ($row->transaction_type == 'Credit') ? $row->amount : ''; ?></td>
<td><?php echo ($row->transaction_type == 'Debit') ? $row->amount : ''; ?></td>
<td><?php echo $row->balance; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- end col -->
</div>
</div>
<!-- Add this modal markup at the end of your HTML body -->
<!-- Button to trigger modal -->
<!-- Add this modal markup at the end of your HTML body -->
<div class="modal fade" id="addTransactionModal" tabindex="-1" role="dialog" aria-labelledby="addTransactionModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addTransactionModalLabel">Add Transaction</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="transactionMode" class="control-label">Transaction Mode</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="transactionMode" id="addMode" value="add" checked>
<label class="form-check-label" for="addMode">Deposit</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="transactionMode" id="adjustmentMode" value="adjustment">
<label class="form-check-label" for="adjustmentMode">Adjustment</label>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="field-1" class="control-label">Amount</label>
<input type="number" class="form-control" id="amount" placeholder="Amount">
</div>
</div>
</div>
<div class="row" id="transactionTypeRow" style="display:none;">
<div class="col-md-6">
<div class="form-group">
<label for="transactionType" class="control-label">Transaction Type</label>
<select class="form-control" id="transactionType">
<option value="Credit">Add</option>
<option value="Debit">Reduce</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group no-margin">
<label for="description" class="control-label">Description</label>
<textarea class="form-control" id="description" placeholder="Write something about the transaction"></textarea>
</div>
</div>
</div>
<div class="form-group">
<label for="subType" class="control-label"style="display: none;">Transaction Sub Type</label>
<select class="form-control" id="subType" name="sub_type"style="display: none;">
<option value="Deposit"hidden>Deposit</option>
<option value="Adjustment"hidden>Adjustment</option>
<!-- Add more options as needed -->
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="saveTransactionBtn">Save Transaction</button>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function () {
$('input[name="transactionMode"]').change(function () {
if ($(this).val() === 'adjustment') {
$('#transactionTypeRow').show();
} else {
$('#transactionTypeRow').hide();
}
});
});
</script>
<script>
$(document).ready(function () {
$('#tickets-table').DataTable({
dom: "<'row'<'col-sm-0'f><'col-sm-9 text-right'B>>" ,
buttons: [
{
extend: 'csv',
text: 'CSV',
title: 'TransactionDetails',
exportOptions: {
columns: ''
}
}
],
language: {
search: "_INPUT_",
searchPlaceholder: "Search..."
},
});
});
</script>
<!-- Include jQuery library (if not already included) -->
<script>
$(document).ready(function () {
// Event listener for radio buttons
$('input[name="transactionMode"]').change(function () {
if ($(this).val() === 'add') {
// Set the hidden input value to 'Deposit' when 'Deposit' radio button is selected
$('#subType').val('Deposit');
} else if ($(this).val() === 'adjustment') {
// Set the hidden input value to 'Adjustment' when 'Adjustment' radio button is selected
$('#subType').val('Adjustment');
}
});
$('#saveTransactionBtn').on('click', function () {
// Collect data from modal fields
var amount = $('#amount').val();
var description = $('#description').val();
var clientId = '<?php echo $clientData->id; ?>';
var insurerId = '<?php echo $insurerName->id; ?>';
var transactionType;
if ($('#addMode').is(':checked')) {
transactionType = 'Credit'; // Assuming 'Credit' is the default when the 'Deposit' radio button is selected
} else if ($('#adjustmentMode').is(':checked') && $('#transactionTypeRow').is(':visible')) {
transactionType = $('#transactionType').val();
} else {
transactionType = ''; // You might want to handle this case based on your requirements
}
// Fetch sub_type_id based on the selected sub_type
var subTypeOptions = {
'Deposit': 1,
'Adjustment': 2,
'Deletion': 3,
// Add more options as needed
};
var subType = $('#subType').val();
var subTypeId = subTypeOptions[subType] || null;
if (subTypeId === null) {
// Handle the case where sub_type is not found in the options
alert('Invalid sub_type selected.');
return;
}
// Send data to the server using Ajax
$.ajax({
type: 'POST',
url: '<?= base_url()."client/save_deposit" ?>',
data: {
amount: amount,
description: description,
transaction_type: transactionType,
sub_type: subType,
sub_type_id: subTypeId, // Include sub_type_id
client_id: clientId,
insurer_id: insurerId
},
success: function (response) {
// Handle success response
console.log("Transaction saved successfully");
// Reload the page or perform other actions as needed
location.reload();
},
error: function (error) {
// Handle error response
console.error(error);
}
});
});
});
</script>