Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
VENKATESHWARAN 2024-09-27 17:10:29 +05:30
commit 48fc2eab5f
7 changed files with 268 additions and 119 deletions

View File

@ -1028,6 +1028,7 @@ class EmployeeRestController extends AdminController
$self['data']['basic_cover_si'] = $employee_policy->basic_cover_si;
$array->mapped_family_floaters = $self;
$array->type = 'GPA';
@ -1155,7 +1156,7 @@ class EmployeeRestController extends AdminController
}
$array->mapped_family_floaters = $data;
$array->type = "Group Medical Coverage";
$array->type = "GMC";
$checkGmcParentsPolicyExist = $this->clientPolicyModel->select('client_policy.id as ClientPolicyId , client_policy.client_id as ClientId, client_policy.policy_type_id as policy_type_id, policy_type.long_name as Policy_Name , client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type , client_policy.policy_terms as Policy_Terms')
->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left')
@ -1344,7 +1345,7 @@ class EmployeeRestController extends AdminController
}
$array->mapped_family_floaters = $data;
$array->type = "Group Medical Coverage - Parents";
$array->type = "GMC - Parents";
return $array;
@ -1791,7 +1792,7 @@ class EmployeeRestController extends AdminController
$responce['family_floaters_of_only_si_value'] = $only_si_value;
$responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value;
$responce['family_floaters_of_only_si_gst_value'] = $only_si_gst_value;
$responce['type'] = "Group Medical Coverage - Top Up";
if($this->request->getGet('policy') == 'GMC-SI-TOPUP'){
return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_topup'=>$responce]], 200);
@ -1840,7 +1841,7 @@ class EmployeeRestController extends AdminController
$responce['family_floaters_of_only_si_value'] = $only_si_value;
$responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value;
$responce['family_floaters_of_only_si_gst_value'] = $only_si_gst_value;
$responce['type'] = "Group Medical Coverage - Parents Top Up";
if($this->request->getGet('policy') == 'GMC-SI-PARENT-TOPUP'){
return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_parent_topup'=>$responce]], 200);

View File

@ -56,6 +56,7 @@ class MasterController extends AdminController
protected $clientModel;
protected $clientDepositModel;
protected $insurerTemplateModel;
protected $cli_colors;
@ -84,6 +85,13 @@ class MasterController extends AdminController
$this->clientModel = new ClientModel();
$this->clientDepositModel = new ClientDepositModel();
$this->insurerTemplateModel = new InsurerExcelExportTemplateModel();
$this->cli_colors = [
'red' => "\033[31m",
'green' => "\033[32m",
'yellow' => "\033[33m",
'blue' => "\033[34m",
'reset' => "\033[0m"
];
}
@ -1546,6 +1554,7 @@ class MasterController extends AdminController
$this->checkAndCreateDirectories();
$this->checkGoogleOAuthCredentialsinDB();
$this->getCronJobsList();
$this->checkGdriveRootFolderID();
}
@ -1594,7 +1603,7 @@ class MasterController extends AdminController
$token = $settingsModel->where('id', 1)->first();
echo "################ CHECKING GMAIL OAUTH FOR EMAIL ###################\n";
if (is_array($token) && !is_null($token['gmail_api_oauth_credentials'])) {
if (is_array($token) && is_null($token['gmail_api_oauth_credentials'])) {
echo "Email OAuth credentials not found in database.\n";
echo "Check the following..!\n";
@ -1632,4 +1641,20 @@ class MasterController extends AdminController
echo "################################################################\n\n";
}
//check gdrive root folder id in env file
function checkGdriveRootFolderID()
{
echo "#################### CHECKING GDRIVE FOLDER ID IN ENV FILE ############################\n";
$id = getenv('GDRIVE_ROOT_FOLDER_ID');
if($id)
{
echo $this->cli_colors['green'] . "ID is :". $id . $this->cli_colors['reset']. "\n";
}
else
{
echo $this->cli_colors['red'] ."Gdrive Folder id not set in env file. set it under 'GDRIVE_ROOT_FOLDER_ID' in env file.". $this->cli_colors['reset'] ."\n";
}
echo "################################################################\n\n";
}
}

View File

@ -1268,8 +1268,11 @@ class PolicyTransactionController extends BaseController
//insurer statement list page
public function statementList()
{
// dd($this->updateInsurerStatement(['file_id' => 13]));
// dd($this->validateInsurerStatement(['file_id' => 30]));
// $data['insurers'] = $this->insurerModel->where('is_active',1)->findAll();
$today = date('Y-m-d');
$fromday = $from_date = date('Y-m-d', strtotime('-60 days', strtotime($today)));
// echo $fromday;die();
$data['invoice_status_array'] = $this->invoiceStatus;
$data['insurers'] = $this->insurerBranchModel ->getInsurerBranchesWithInsurerNames();
@ -1285,7 +1288,7 @@ class PolicyTransactionController extends BaseController
WHERE pt_co_share_details.is_active = 1
AND pt_co_share_details.statement_id = insurer_statements.id
) AS exp_inv_amt,
(SELECT SUM(inv_payment_details.inv_amt)
(SELECT SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds)
FROM inv_payment_details
WHERE inv_payment_details.is_active = 1
AND inv_payment_details.statement_id = insurer_statements.id
@ -1295,10 +1298,12 @@ class PolicyTransactionController extends BaseController
->join('insurer_branch', 'insurer_statements.branch_id = insurer_branch.id')
->join('user_profiles', 'insurer_statements.created_by = user_profiles.id')
->where('insurer_statements.is_active', 1)
->where('date(insurer_statements.created_at) >= ', $from_date)
->where('date(insurer_statements.created_at) <= ', $today)
->orderBy('insurer_statements.id', 'DESC')
->findAll();
// dd( $data['insurer_statement_list']);
// dd( $this->insurerStatements->getLastQuery());
$this->loadLayout('insurer_statement_list', $data);
}
@ -1314,7 +1319,7 @@ class PolicyTransactionController extends BaseController
'max_size[statement,16384]',
],
]);
$this->createStatementFolder();
// $this->createStatementFolder();
if ($validated)
{
$avatar = $this->request->getFile('statement');
@ -1351,6 +1356,8 @@ class PolicyTransactionController extends BaseController
// print_r($branch_id);
// die();
$month = $this->request->getPost('statement_month');
$month = $month.'-01';
// print_r($month);die;
$month = change_date_format($month,'Y-M-d','Y-m-d');
// print_r($month);die;
@ -1439,27 +1446,28 @@ class PolicyTransactionController extends BaseController
// dd($highestRowAndColumn);
$excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
unset($excel_data[0]);
// dd($excel_data);
// Kint::dump($excel_data);
//get no of line items and update in DB
$line_items = count($excel_data);
// get uploaded month transactions data
$source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(month:$month,year:$year,insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']);
// var_dump($source_data);die();
// Kint::dump($excel_data);
// Kint::dump($source_data);//die();
// check policy no,insurer and etc in DB for this month
// if all good return true, otherwise return false with messssage
foreach ($excel_data as $excel_key => $excel_row)
{
$is_source_found = 0;
$excel_row[4] = trim($excel_row[4]);
$excel_row[5] = trim($excel_row[5]);
// Kint::dump(change_date_format($excel_row[4],'d-m-Y','Y-m-d'));
// echo $excel_row[1].'#'.$excel_row[2] .'#'.$excel_row[3].'#'.change_date_format($excel_row[4],'d-m-Y','Y-m-d').'#'.change_date_format($excel_row[5],'d-m-Y','Y-m-d').'<br>';
$policy_start_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[4]);//policy_start_date from excel
$policy_end_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[5]);//policy_end_date from excel
$policy_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[1]);//policy_end_date from excel
$client_name = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[3]);//clientname from excel
$endorsement_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[2]);//policy_end_date from excel
foreach ($source_data as $source_key => $source_row)
{
// Kint::dump(change_date_format($excel_row[3],'d-m-Y','Y-m-d'));
if( (trim($excel_row[1]) == $source_row['policy_no']) && trim($excel_row[2]) == $source_row['endorsement_no'] && trim($excel_row[3]) == $source_row['client_name'] && change_date_format($excel_row[4],'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($excel_row[5],'d-m-Y','Y-m-d') == $source_row['policy_end_date'])
if( ($policy_no == $source_row['policy_no']) && $endorsement_no == $source_row['endorsement_no'] && change_date_format($policy_start_date,'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date,'d-m-Y','Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name'])
{
$is_source_found = 1;
unset($source_data[$source_key]);
@ -1475,7 +1483,6 @@ class PolicyTransactionController extends BaseController
$error_data['error_data'] = array_merge($error_data['error_data'],[$excel_row[0]]);//match not found
}
}
if($error_data['error_code'])
{
$status = 'failed';
@ -1543,13 +1550,16 @@ class PolicyTransactionController extends BaseController
foreach ($excel_data as $excel_key => $excel_row)
{
$is_source_found = 0;
$excel_row[4] = trim($excel_row[4]);
$excel_row[5] = trim($excel_row[5]);
$policy_start_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[4]);//policy_start_date from excel
$policy_end_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[5]);//policy_end_date from excel
$policy_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[1]);//policy_end_date from excel
$client_name = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[3]);//clientname from excel
$endorsement_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[2]);//policy_end_date from excel
foreach ($source_data as $source_key => $source_row)
{
// Kint::dump(change_date_format($excel_row[3],'d-m-Y','Y-m-d'));
if( (trim($excel_row[1]) == $source_row['policy_no']) && trim($excel_row[2]) == $source_row['endorsement_no'] && trim($excel_row[3]) == $source_row['client_name'] && change_date_format($excel_row[4],'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($excel_row[5],'d-m-Y','Y-m-d') == $source_row['policy_end_date'])
if( ($policy_no == $source_row['policy_no']) && $endorsement_no == $source_row['endorsement_no'] && change_date_format($policy_start_date,'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date,'d-m-Y','Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name'])
{
$is_source_found = 1;
@ -1646,10 +1656,11 @@ class PolicyTransactionController extends BaseController
->where('is_active',1)
->get()
->getResultArray();
// print_r($inv_details);
// ~dd($inv_details);
$data = [ 'invoice_status' => $inv_details['invoice_status'],
'invoice_no' => $inv_details['invoice_no'],
'invoice_date' => $inv_details['invoice_date'] ];
'invoice_amount' => $inv_details['invoice_amount'],
'invoice_date' => isset($inv_details['invoice_date']) ? change_date_format($inv_details['invoice_date'],'Y-m-d','d-m-Y') : null ];
$data['payments'] = $inv_payment_details;
return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $data], 200);
@ -1666,13 +1677,15 @@ class PolicyTransactionController extends BaseController
$invoiceStatus = $jsonData['invoice_status'];
$hiddenStatementId = $jsonData['hidden_statement_id'];
$invoiceNo = $jsonData['invoice_no'];
$invoiceDate = $jsonData['invoice_date'];
$invoiceDate = change_date_format($jsonData['invoice_date'],'d-m-Y','Y-m-d');
$invoice_amount = $jsonData['invoice_amount'];
//Update statement table
$parentData = [
'invoice_status' => $invoiceStatus,
'invoice_no' => $invoiceNo,
'invoice_date' => $invoiceDate,
'invoice_amount' => $invoice_amount,
'updated_by' => get_session_userid()
];
@ -1681,21 +1694,24 @@ class PolicyTransactionController extends BaseController
$this->insurerStatements->update($hiddenStatementId, $parentData);
// Process child data
$invoiceAmounts = $jsonData['invoice_amount'];
$receivedAmounts = $jsonData['received_amount'];
$utrNos = $jsonData['utr_no'];
$tdsTotal = $jsonData['tds'];
$paymentDates = $jsonData['payment_date'];
$pks = $jsonData['pk'];
foreach ($invoiceAmounts as $index => $invoiceAmount) {
foreach ($receivedAmounts as $index => $receivedAmount) {
$pk = $pks[$index]; // Get the pk for the current record
$utrNo = $utrNos[$index];
$tds = $tdsTotal[$index];
$paymentDate = $paymentDates[$index];
// Prepare data for insert/update
$childData = [
'inv_amt' => $invoiceAmount,
'inv_amt' => $receivedAmount,
'utr_no' => $utrNo,
'received_date' => $paymentDate,
'tds' => $tds,
'received_date' => change_date_format($paymentDate,'d-m-Y','Y-m-d'),
'statement_id' => $hiddenStatementId
];
if($pk){

View File

@ -21,6 +21,7 @@ class InsurerStatements extends Model
"reason",
"invoice_status",
"invoice_no",
"invoice_amount",
"invoice_date",
"updated_by"

View File

@ -15,6 +15,7 @@ class InvPaymentDetailsModel extends Model
'statement_id',
'inv_amt',
'utr_no',
'tds',
'received_date',
'created_by',
'is_active',

View File

@ -87,16 +87,18 @@ class PTCOShareDetailsModel extends Model
pt_co.bp_amt,
pt_co.tp_amt,
pt_co.tep_amt,
pt_co.exp_amt
pt_co.exp_amt,
pt_co.statement_id
')
->join('policy_transaction pt', 'pt_co.pt_id = pt.id')
->join('clients c', 'pt.client_id = c.id')
->where('pt_co.is_active', 1)
->where('MONTH(pt.created_at)', $month)
->where('YEAR(pt.created_at)', $year)
->where('MONTH(pt.month)', $month)
->where('YEAR(pt.month)', $year)
->where('pt_co.insurer_id', $insurer_id)
->where('pt_co.insurer_branch_id', $insurer_branch_id)
->where('pt_co.statement_id is null')
->where('pt.status','completed')
// ->where('pt_co.exp_amt', 0.00)
// ->orWhere('pt_co.exp_amt is null')
->get()

View File

@ -113,13 +113,10 @@ table.dataTable tbody td {
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Insurer Statement List</h4>
</div>
<!-- <div class="col-2" id="add_div" style="text-align: right; position: relative;top: 56px; left: 314px;"> -->
<!-- <button type="button" id="change_status" class="btn btn-primary waves-effect waves-light">Invoice Status</button> -->
<!-- </div> -->
<!-- <div class="col-1" id="status_change" style="text-align: right; position: relative;top: 56px; left: 291px;"> -->
<div class="col-6" style="text-align: right;">
<button type="button" id="btnAdd" onclick="showFileUploadModal()" class="btn btn-primary waves-effect waves-light">Upload</button>
<!-- </div> -->
</div>
</div>
<div>
<table class="table table-striped mb-0 nowrap" cellspacing="0" id="tickets-table">
@ -155,18 +152,20 @@ table.dataTable tbody td {
<td><?php echo (isset($invoice_status_array[ $row['invoice_status'] ]) ? $invoice_status_array[ $row['invoice_status'] ] : ' - ') ?>
<span class="col-xl-3 col-lg-4 col-sm-6">
<?php if($row['file_status'] == 'success' ) { ?>
<i class="fe-alert-circle"
data-toggle="tooltip"
data-placement="right"
title="<?php echo 'Exp Invoice Amt: ' . (isset($row['exp_inv_amt']) ? $row['exp_inv_amt'] : '0.00' ) . ' Received Invoice Amt: ' . (isset($row['received_inv_amt']) ? $row['received_inv_amt'] : '0.00') ; ?>"
title="<?php echo 'Invoice Amt: ' . (isset($row['invoice_amount']) ? $row['invoice_amount'] : '0.00' ) . ' Received Amt: ' . (isset($row['received_inv_amt']) ? $row['received_inv_amt'] : '0.00') ; ?>"
data-original-title="Tooltip on right">
</i>
<?php } ?>
</span>
</td>
<td><?php echo change_date_format($row['created_at'],'Y-m-d H:i:s','d M Y h:i a').' by <br>'.$row['first_name'] ?></td>
<td>
<?php if($row['file_status'] != 'failed'){?>
<div class="btn-group dropdown">
<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">
@ -175,6 +174,7 @@ table.dataTable tbody td {
</a>
</div>
</div>
<?php } ?>
</td>
</tr>
@ -203,7 +203,7 @@ table.dataTable tbody td {
<div class="form-group">
<div class="form-group col-md-12">
<div class="form-group col-md-10">
<label for="insurer"> Insurer <spanclass="text-danger">*</spanclass=></label>
<select class="form-control" id="insurer" name="insurer" required>
<option value="" selected>Select Insurer</option>
@ -216,11 +216,11 @@ table.dataTable tbody td {
?>
</select>
</div>
<div class="form-group col-md-12">
<div class="form-group col-md-10">
<label for="statement_month">Statement month</label>
<input type="date" class="form-control" id="statement_month" name="statement_month" placeholder="Enter Invoice Number" required>
<input type="text" class="form-control" id="statement_month" name="statement_month" placeholder="" required readonly>
</div>
<div class="form-group col-md-12" >
<div class="form-group col-md-10" >
<label for="statment">Statement </label> <span><a href="downloadSampleInsurerStatement" id="download_sample_file" style="font-size: small;">Download sample file</a></span>
<input type="file" class="form-control" name="statement" required accept=" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet">
</div>
@ -254,7 +254,7 @@ table.dataTable tbody td {
</div><!-- /.modal -->
<!-- Invoice status content modal-->
<div class="modal fade" id="invoice_modal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal fade" id="invoice_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
@ -282,25 +282,29 @@ table.dataTable tbody td {
</select>
<input type="hidden" id="hidden_statement_id" name="hidden_statement_id">
</div>
<div class="form-group col-md-4">
<!-- <div class="form-group col-md-4">
<label for="addon_policy">Exp Amount</label>
<input type="text" class="form-control" id="modal_exp_amt" placeholder="Enter Invoice Number" disabled>
</div>
<div class="form-group col-md-4">
<label for="addon_policy">Received Amount</label>
<input type="text" class="form-control" id="modal_received_amt" placeholder="Enter Invoice Number" disabled>
<input type="text" class="form-control" id="modal_exp_amt" placeholder="" disabled>
</div> -->
<div class="form-group col-md-4" id="modal_received_amt_div">
<label for="addon_policy">Total Received Amount</label>
<input type="text" class="form-control" id="modal_received_amt" placeholder="" disabled>
</div>
</div>
<!-- Invoice Number and Invoice Date in same row -->
<div class="row" id="invoice_no_div_modal" style="display: none;">
<div class="form-group col-md-6">
<div class="form-group col-md-4">
<label for="invoice_no">Invoice Number<span id="base_danger" class="text-danger"></span></label>
<input type="text" class="form-control" id="invoice_no_modal" name="invoice_no" placeholder="Enter Invoice Number" required>
</div>
<div class="form-group col-md-6">
<div class="form-group col-md-4">
<label for="invoice_no">Invoice Amount<span id="base_danger" class="text-danger"></span></label>
<input type="number" class="form-control" id="invoice_amount_no_modal" name="invoice_amount" placeholder="Enter Invoice Amt" required>
</div>
<div class="form-group col-md-4">
<label for="invoice_date">Invoice Date</label>
<input type="date" class="form-control" id="invoice_date_modal" name="invoice_date" value="<?php echo date('Y-m-d'); ?>" required>
<input type="text" class="form-control" id="invoice_date_modal" name="invoice_date" value="<?php echo date('Y-m-d'); ?>" readonly required>
</div>
</div>
@ -315,7 +319,8 @@ table.dataTable tbody td {
<thead>
<tr>
<th style="display: none;">pk</th>
<th>Invoice Amount</th>
<th>Received Amount</th>
<th>TDS</th>
<th>UTR Number</th>
<th>Date</th>
<th>Action</th>
@ -324,9 +329,10 @@ table.dataTable tbody td {
<tbody>
<tr>
<td style="display: none;"><input type="hidden" class="form-control" name="pk[]" placeholder="Enter Amount"></td>
<td><input type="number" class="form-control" name="invoice_amount[]" placeholder="Enter Amount" required onchange="checkInvAmont(event)"></td>
<td><input type="number" class="form-control" name="received_amount[]" placeholder="Enter Amount" required onchange="checkInvAmont(event)"></td>
<td><input type="number" class="form-control" name="tds[]" placeholder="Enter TDS" onchange="checkInvAmont(event)" required></td>
<td><input type="text" class="form-control" name="utr_no[]" placeholder="Enter UTR No" required></td>
<td><input type="date" class="form-control" name="payment_date[]" value="<?php echo date('Y-m-d'); ?>" required></td>
<td><input type="text" class="form-control payment_date" name="payment_date[]" value="<?php echo date('d-m-Y'); ?>" placeholder="dd-mm-yyyy" required readonly></td>
<td><i class="fa fa-trash mr-2 font-18 vertical-middle text-danger remove-row" style="text-align: center;"></i></td>
</tr>
</tbody>
@ -354,19 +360,24 @@ table.dataTable tbody td {
const invoiceNoDiv = document.getElementById('invoice_no_div_modal');
// const invoiceDateDiv = document.getElementById('invoice_date_div_modal');
const paymentTableDiv = document.getElementById('payment_table_div_modal');
const totalReceivedAmtDiv = document.getElementById('modal_received_amt_div');
// Hide everything initially
invoiceNoDiv.style.display = 'none';
// invoiceDateDiv.style.display = 'none';
paymentTableDiv.style.display = 'none';
totalReceivedAmtDiv.style.display = 'none';
// Show fields based on selected status
if (invoiceStatus === 'generated' || invoiceStatus === 'sent') {
invoiceNoDiv.style.display = 'flex';
totalReceivedAmtDiv.style.display = 'none';
switchRequired('invoice_no_modal',true);
switchRequired('invoice_date_modal',true);
switchRequired('invoice_amount_no_modal',true);
switchRequired('invoice_amount',false,'name');
switchRequired('received_amount',false,'name');
switchRequired('tds',false,'name');
switchRequired('utr_no',false,'name');
switchRequired('payment_date',false,'name');
switchRequired('pk',false,'name');
@ -374,24 +385,32 @@ table.dataTable tbody td {
} else if (invoiceStatus === 'payment_received') {
invoiceNoDiv.style.display = 'flex';
paymentTableDiv.style.display = 'block';
totalReceivedAmtDiv.style.display = 'block';
switchRequired('invoice_no_modal',true);
switchRequired('invoice_date_modal',true);
switchRequired('invoice_amount',true,'name');
switchRequired('invoice_amount_no_modal',true);
switchRequired('received_amount',true,'name');
switchRequired('utr_no',true,'name');
switchRequired('tds',true,'name');
switchRequired('payment_date',true,'name');
switchRequired('pk',true,'name');
}else if(invoiceStatus === 'pending')
{
invoiceNoDiv.style.display = 'none';
paymentTableDiv.style.display = 'none';
totalReceivedAmtDiv.style.display = 'none';
// switchRequired('modal_received_amt_div',false);
switchRequired('invoice_no_modal',false);
switchRequired('invoice_date_modal',false);
switchRequired('invoice_amount_no_modal',false);
switchRequired('invoice_amount',false,'name');
switchRequired('received_amount',false,'name');
switchRequired('utr_no',false,'name');
switchRequired('payment_date',false,'name');
switchRequired('pk',false,'name');
switchRequired('tds',false,'name');
}
});
@ -417,12 +436,21 @@ table.dataTable tbody td {
$('#invoiceForm').on('submit', function (e) {
e.preventDefault(); // Prevent default form submission
var form = document.getElementById('invoiceForm');
if(!form.checkValidity())
// alert(form.checkValidity());
// alert($('#invoice_date_modal').val());
if((!form.checkValidity()))
{
// console.log('error2');
return false;
}
if($('#invoice_date_modal').val().trim() === '' && $('#invoice_status').val() != 'pending')
{
// console.log('error1');
return false;
}
// console.log('final');
// return false;
// Serialize form data to array and then convert to JSON
var formData = new FormData(form);
var formDataJSON = {};
@ -456,14 +484,13 @@ table.dataTable tbody td {
success: function (response) {
console.log(response);
// Close the modal
var myModal = new bootstrap.Modal(document.getElementById('invoice_modal'));
myModal.hide();
$('.close').click()
// Reset the form data
$('#invoiceForm')[0].reset();
// Optionally display success message or perform further actions
alert('Invoice updated successfully!');
location.reload();
},
error: function (xhr, status, error) {
// Handle any errors
@ -471,6 +498,7 @@ table.dataTable tbody td {
alert('An error occurred while updating the invoice.');
}
});
// location.reload();
$('.loader').fadeOut();
$('.loader-mask').delay(10).fadeOut('slow');
});
@ -484,13 +512,18 @@ table.dataTable tbody td {
newRow.innerHTML = `
<td style="display: none;"><input type="hidden" class="form-control" name="pk[]" placeholder="Enter Amount"></td>
<td><input type="number" class="form-control" name="invoice_amount[]" placeholder="Enter Amount" onchange="checkInvAmont(event)" required></td>
<td><input type="number" class="form-control" name="received_amount[]" placeholder="Enter Amount" onchange="checkInvAmont(event)" required></td>
<td><input type="number" class="form-control" name="tds[]" placeholder="Enter TDS" onchange="checkInvAmont(event)" required></td>
<td><input type="text" class="form-control" name="utr_no[]" placeholder="Enter UTR No" required></td>
<td><input type="date" class="form-control" value="<?php echo date('Y-m-d'); ?>" name="payment_date[]" placeholder="Enter UTR No" required></td>
<td><input type="text" class="form-control payment_date" value="<?php echo date('d-m-Y'); ?>" name="payment_date[]" placeholder="Enter UTR No" required readonly></td>
<td><i class="fa fa-trash mr-2 font-18 vertical-middle text-danger remove-row" style="text-align: center;"></i></td>
`;
tableBody.appendChild(newRow);
$('.payment_date').datepicker({
format: 'dd-mm-yyyy',
autoclose: true
});
});
// Remove row
@ -529,33 +562,7 @@ table.dataTable tbody td {
});
function switchRequired(elementId, isRequired, type = 'id') {
if(type == 'id')//id attribute
{
let element = document.getElementById(elementId);
if (isRequired) {
element.setAttribute('required', 'required');
} else {
element.removeAttribute('required');
}
}
else //name attribute
{
var name_attribute = elementId+'[]';
// Select all elements with the name 'invoice_amt[]'
var elements = document.getElementsByName(name_attribute);
// Loop through the elements and set or remove the 'required' attribute
elements.forEach(function(element) {
if (isRequired) {
element.setAttribute('required', 'required'); // Make required
} else {
element.removeAttribute('required'); // Remove required
}
});
}
}
</script>
@ -568,16 +575,31 @@ function showFileUploadModal(input)
// $(input).val('');
}
function formatDate(date) {
var day = ("0" + date.getDate()).slice(-2);
var month = ("0" + (date.getMonth() + 1)).slice(-2);
var year = date.getFullYear();
return day + "-" + month + "-" + year;
}
function formatDateToDMY(dateStr) {
// Split the date string by the hyphen
var parts = dateStr.split('-');
return parts[2] + '-' + parts[1] + '-' + parts[0]; // Rearrange to DD-MM-YYYY
}
function showInvoiceStatusModal(event)
{
var modal_received_amt_div = document.getElementById('modal_received_amt_div');
modal_received_amt_div.style.display = 'none';
// alert();
// console.log(event.target.data)
var dataId = event.target.getAttribute('data-id');
var dataExpAmt = event.target.getAttribute('data-exp-amt');
var dataReceivedAmt = event.target.getAttribute('data-received-amt');
// Set the value to a hidden input field in the modal
document.getElementById('hidden_statement_id').value = dataId;
document.getElementById('modal_exp_amt').value = dataExpAmt;
// document.getElementById('modal_exp_amt').value = dataExpAmt;
document.getElementById('modal_received_amt').value = dataReceivedAmt;
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
// AJAX call to get the invoice details based on data-id
@ -602,8 +624,14 @@ function showInvoiceStatusModal(event)
}
document.getElementById('invoice_no_modal').value = response.data.invoice_no;
document.getElementById('invoice_date_modal').value = response.data.invoice_date;
document.getElementById('invoice_date_modal').value = response.data.invoice_date === '' ? <?php echo date('d-m-Y')?> : response.data.invoice_date;
document.getElementById('invoice_amount_no_modal').value = response.data.invoice_amount;
if (!$('#invoice_date_modal').val()) {
// alert('nope');
// Set today's date as the default date
$('#invoice_date_modal').datepicker('setDate', new Date());
}
// Clear existing rows in the payment table
var paymentTableBody = document.querySelector('#payment_table_modal tbody');
@ -616,14 +644,15 @@ function showInvoiceStatusModal(event)
var row = paymentTableBody.insertRow();
row.innerHTML = `
<td style="display: none;"><input type="hidden" class="form-control" name="pk[]" value="${payment.id}"></td>
<td><input type="number" class="form-control" name="invoice_amount[]" placeholder="Enter Amount" value="${payment.inv_amt}" onchange="checkInvAmont(event)" required></td>
<td><input type="number" class="form-control" name="received_amount[]" placeholder="Enter Amount" value="${payment.inv_amt}" onchange="checkInvAmont(event)" required></td>
<td><input type="number" class="form-control" name="tds[]" placeholder="Enter Amount" value="${payment.tds}" onchange="checkInvAmont(event)" required></td>
<td><input type="text" class="form-control" name="utr_no[]" placeholder="Enter UTR No" value="${payment.utr_no}" required></td>
<td><input type="date" class="form-control" name="payment_date[]" value="${payment.received_date}" required></td>
<td><input type="text" class="form-control payment_date" name="payment_date[]" value="${formatDateToDMY(payment.received_date)}" required readonly></td>
<td><i class="fa fa-trash mr-2 font-18 vertical-middle text-danger remove-row" style="text-align: center;"></i></td>
`;
});
}
$('.payment_date').datepicker({ format: 'dd-mm-yyyy',autoclose: true});
// Show the modal
var myModal = new bootstrap.Modal(document.getElementById('invoice_modal'));
myModal.show();
@ -641,17 +670,51 @@ function showInvoiceStatusModal(event)
});
$('.loader').fadeOut();
$('.loader-mask').delay(10).fadeOut('slow');
var myModal = new bootstrap.Modal(document.getElementById('invoice_modal'));
myModal.show();
// var myModal = new bootstrap.Modal(document.getElementById('invoice_modal'));
// myModal.show();
// $(input).val('');
}
$(document).ready(function(){
var rollover_date = flatpickr("#statement_month", {
dateFormat: "Y-M-d",
allowInput: true
// var rollover_date = flatpickr("#statement_month", {
// dateFormat: "Y-M",
// allowInput: true
// });
$('#statement_month').datepicker({
format: 'yyyy-M',
viewMode: 'months',
minViewMode: 'months',
autoclose: true
});
$('.payment_date').datepicker({
format: 'dd-mm-yyyy',
autoclose: true
});
// Get today's date
var today = new Date();
// Calculate the minimum date (60 days before today)
var minDate = new Date();
minDate.setDate(today.getDate() - 180);
// Calculate the maximum date (60 days after today)
var maxDate = new Date();
maxDate.setDate(today.getDate() + 180);
$('#invoice_date_modal').datepicker({
format: 'dd-mm-yyyy',
autoclose: true,
startDate: minDate,
endDate: maxDate
});
// var invoice_date_modal = flatpickr("#invoice_date_modal", {
// dateFormat: "d-m-Y",
// allowInput: true
// });
});
@ -692,7 +755,7 @@ $(document).ready(function(){
toastr.success(
'File upload successs',
'success');
$('.close').click()
$('.close').click();
window.location.reload(true);
} else if (response.code === 404 && response.dataStatus === false) {
console.error('no data found', response);
@ -765,19 +828,59 @@ $(document).ready(function(){
}
function checkInvAmont(event)
{
function checkInvAmont(event) {
var total = 0;
document.querySelectorAll('input[name="invoice_amount[]"]').forEach(function(el) {
let val = parseFloat(el.value) || 0;
total += val;
});
var exp_amt = document.getElementById('modal_exp_amt').value;
if(exp_amt < total)
{
alert('Exceeds expected amt');
event.target.value = '';
var receivedAmounts = document.querySelectorAll('input[name="received_amount[]"]');
var tdsAmounts = document.querySelectorAll('input[name="tds[]"]');
// console.log();
receivedAmounts.forEach(function(el, index) {
// Get the received amount
let receivedVal = parseFloat(el.value) || 0;
// Get the corresponding tds amount (paired with the received amount)
let tdsVal = parseFloat(tdsAmounts[index].value) || 0;
// Add received amount and tds amount
// console.log();
total += (receivedVal + tdsVal);
});
// console.log(total);
// Get the expected invoice amount
var exp_amt = parseFloat(document.getElementById('invoice_amount_no_modal').value) || 0;
// Check if the total exceeds the expected amount
if (exp_amt < total) {
alert('Exceeds Invoice amount');
event.target.value = ''; // Reset the value of the element that triggered the event
}
}
function switchRequired(elementId, isRequired, type = 'id') {
// console.log('switchRequired: ' + elementId+' - '+' - '+ type);
if(type == 'id')//id attribute
{
let element = document.getElementById(elementId);
if (isRequired) {
element.setAttribute('required', 'required');
} else {
element.removeAttribute('required');
}
}
else //name attribute
{
var name_attribute = elementId+'[]';
// Select all elements with the name 'invoice_amt[]'
var elements = document.getElementsByName(name_attribute);
// Loop through the elements and set or remove the 'required' attribute
elements.forEach(function(element) {
if (isRequired) {
element.setAttribute('required', 'required'); // Make required
} else {
element.removeAttribute('required'); // Remove required
}
});
}
}
</script>