FEAT_PAYOUT_CHANGES
This commit is contained in:
parent
16135992fa
commit
ab1f3d6a9f
@ -772,5 +772,6 @@ $routes->group('payout', function($routes) {
|
||||
$routes->match (['get','post'],'list',"PayoutController::payoutList");
|
||||
$routes->post('fetchUtrDetails',"PayoutController::fetchUtrDetails");
|
||||
$routes->post('saveUtrDetails',"PayoutController::saveUtrDetails");
|
||||
$routes->post('removeUtrDetails',"PayoutController::removeUtrDetails");
|
||||
});
|
||||
|
||||
|
||||
@ -5673,6 +5673,10 @@ class ClientController extends AdminController
|
||||
// $response = $ticketServiceController->extractExcelData("claims_dump_form_client.xlsx");
|
||||
// dd($response);
|
||||
|
||||
// $TicketController = new TicketController();
|
||||
// $response = $TicketController->getMoreInfo($requestFrom = 'rest', $ticket_id = 70);
|
||||
// dd($response);
|
||||
|
||||
// ---------- EMP SERVICE CONTROLLER --------------------------------------------------------------------------------
|
||||
|
||||
$empServiceController = new EmployeeServiceController();
|
||||
|
||||
@ -50,7 +50,7 @@ class PayoutController extends BaseController
|
||||
$start_date = $data['start_date'] ?? null;
|
||||
$end_date = $data['end_date'] ?? null;
|
||||
|
||||
$payout_data = $this->invoiceModel->invoiceList($this->payout_status, $agent_id, $status_id, $start_date, $end_date);
|
||||
$payout_data = $this->invoiceModel->invoiceList($agent_id, $status_id, $start_date, $end_date);
|
||||
|
||||
$payout_data['payout_list_data'] = $payout_data;
|
||||
$payout_data = view('payout_list', $payout_data);
|
||||
@ -81,7 +81,7 @@ class PayoutController extends BaseController
|
||||
// for list
|
||||
$data['payout_status'] = $this->payout_status;
|
||||
$data['agent_list'] = $this->invoiceModel->agentList();
|
||||
$payout_data['payout_list_data'] = $this->invoiceModel->invoiceList($this->payout_status);
|
||||
$payout_data['payout_list_data'] = $this->invoiceModel->invoiceList();
|
||||
$data['payout_list'] = view('payout_list', $payout_data);
|
||||
|
||||
// dd($data);
|
||||
@ -90,23 +90,101 @@ class PayoutController extends BaseController
|
||||
|
||||
public function fetchUtrDetails()
|
||||
{
|
||||
$invoice_id = $this->request->getPost('invoice_id') ?? null;
|
||||
$invoice_id = $this->request->getPost('invoice_id') ?? null;
|
||||
$payout_data = $this->constructUtrDetails($invoice_id);
|
||||
|
||||
$payout_data = $this->invoiceModel->invoiceList();
|
||||
if(!empty($payout_data)){
|
||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200);
|
||||
}else{
|
||||
return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200);
|
||||
}
|
||||
}
|
||||
|
||||
$data['utr_data'] = $payout_data;
|
||||
$payout_data = view('partner_utr_details', $data);
|
||||
public function constructUtrDetails($invoice_id)
|
||||
{
|
||||
$utr_data = $this->invoiceUtrModel->where('is_active', 1)->where('invoice_id', $invoice_id)->findAll();
|
||||
$summary_data = $this->invoiceModel->utrSummary($invoice_id);
|
||||
|
||||
if(!empty($payout_data)){
|
||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200);
|
||||
}else{
|
||||
return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200);
|
||||
}
|
||||
if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']) {
|
||||
$data['invoice_completed'] = true;
|
||||
}
|
||||
|
||||
$data['utr_list_data'] = $utr_data;
|
||||
$data['summary'] = $summary_data;
|
||||
$data = view('payout_utr_details', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function saveUtrDetails()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
$invoice_id = $this->request->getPost('invoice_id') ?? null;
|
||||
$utr_id = $this->request->getPost('utr_pk') ?? null;
|
||||
|
||||
if(isset($data['utr_date'])){
|
||||
$data['utr_date'] = change_date_format($data['utr_date']);
|
||||
}
|
||||
|
||||
|
||||
if(!empty($utr_id)){
|
||||
|
||||
$update = $this->invoiceUtrModel->where('id', $utr_id)->set($data)->update();
|
||||
$payout_edit_data = $this->constructUtrDetails($invoice_id);
|
||||
|
||||
if($update){
|
||||
|
||||
$summary_data = $this->invoiceModel->utrSummary($invoice_id);
|
||||
if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']){
|
||||
$sql = "UPDATE partner_invoice SET payout_status = 2 WHERE id = ?";
|
||||
db_connect()->query($sql, [$invoice_id]);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_edit_data, "message" => "UTR successfully updated"], 200);
|
||||
}else{
|
||||
return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_edit_data, "message" => "Failed to update UTR"], 200);
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
unset($data['utr_pk']);
|
||||
$insert_id = $this->invoiceUtrModel->insert($data);
|
||||
$payout_data = $this->constructUtrDetails($invoice_id);
|
||||
|
||||
if($insert_id){
|
||||
|
||||
$summary_data = $this->invoiceModel->utrSummary($invoice_id);
|
||||
if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']){
|
||||
$sql = "UPDATE partner_invoice SET payout_status = 2 WHERE id = ?";
|
||||
db_connect()->query($sql, [$invoice_id]);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data, "message" => "UTR added successfully"], 200);
|
||||
}else{
|
||||
return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "Failed to add UTR"], 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function removeUtrDetails()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
|
||||
if(isset($data['utr_id'])){
|
||||
|
||||
$sql = "UPDATE partner_invoice_utr SET is_active = 0 WHERE id = ?";
|
||||
$update = db_connect()->query($sql, [$data['utr_id']]);
|
||||
|
||||
$payout_data = $this->constructUtrDetails($data['invoice_id'] ?? "");
|
||||
|
||||
if($update){
|
||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data, "message" => "UTR removed successfully"], 200);
|
||||
}else{
|
||||
return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "Failed to remove UTR"], 200);
|
||||
}
|
||||
}else {
|
||||
return $this->respond(['status' => false, 'code' => 500, 'data' => "", "message" => "Failed to remove UTR"], 200);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -41,8 +41,41 @@ class InvoiceModel extends Model
|
||||
protected $validationMessages = [];
|
||||
protected $skipValidation = false;
|
||||
|
||||
// Callbacks
|
||||
protected $allowCallbacks = true;
|
||||
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
||||
protected $afterInsert = [];
|
||||
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
||||
protected $afterUpdate = [];
|
||||
protected $beforeFind = [];
|
||||
protected $afterFind = [];
|
||||
protected $beforeDelete = [];
|
||||
protected $afterDelete = [];
|
||||
|
||||
public function invoiceList($status = [], $agent_id = null, $status_id = null, $start_date = null, $end_date = null)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public function invoiceList($agent_id = null, $status_id = null, $start_date = null, $end_date = null)
|
||||
{
|
||||
$data = $this->select("
|
||||
partner_invoice.*,
|
||||
@ -67,9 +100,8 @@ class InvoiceModel extends Model
|
||||
|
||||
-- Payout status
|
||||
CASE
|
||||
WHEN payout_status = 1 THEN 'Draft'
|
||||
WHEN payout_status = 2 THEN 'Pending'
|
||||
WHEN payout_status = 3 THEN 'Complete'
|
||||
WHEN payout_status = 1 THEN 'Pending'
|
||||
WHEN payout_status = 2 THEN 'Complete'
|
||||
END AS status_text,
|
||||
|
||||
partner_agent.name as agent_name
|
||||
@ -111,7 +143,48 @@ class InvoiceModel extends Model
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
public function agentList(){
|
||||
public function agentList()
|
||||
{
|
||||
return $this->db->table('partner_agent')->where('is_active', 1)->get()->getResultArray();
|
||||
}
|
||||
|
||||
public function utrSummary($invoice_id)
|
||||
{
|
||||
$data = $this->select("
|
||||
|
||||
partner_invoice.*,
|
||||
|
||||
-- Total UTR Amount
|
||||
(SELECT SUM(piu.amount)
|
||||
FROM partner_invoice_utr piu
|
||||
WHERE piu.invoice_id = partner_invoice.id
|
||||
AND piu.is_active = 1
|
||||
) AS total_utr_amount,
|
||||
|
||||
-- Balance Amount
|
||||
(partner_invoice.invoice_amount -
|
||||
IFNULL(
|
||||
(SELECT SUM(piu2.amount)
|
||||
FROM partner_invoice_utr piu2
|
||||
WHERE piu2.invoice_id = partner_invoice.id
|
||||
AND piu2.is_active = 1
|
||||
),
|
||||
0)
|
||||
) AS balance_amount,
|
||||
|
||||
-- Payout status
|
||||
CASE
|
||||
WHEN payout_status = 1 THEN 'Pending'
|
||||
WHEN payout_status = 2 THEN 'Complete'
|
||||
END AS status_text,
|
||||
|
||||
partner_agent.name as agent_name
|
||||
")
|
||||
->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id')
|
||||
->where('partner_invoice.is_active', 1)
|
||||
->where('partner_invoice.id', $invoice_id)
|
||||
->first();
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ class InvoiceUtrModel extends Model
|
||||
'invoice_id',
|
||||
'utr_no',
|
||||
'amount',
|
||||
'utr_date',
|
||||
'is_active',
|
||||
'created_at',
|
||||
'created_by',
|
||||
@ -36,4 +37,37 @@ class InvoiceUtrModel extends Model
|
||||
|
||||
protected $validationMessages = [];
|
||||
protected $skipValidation = false;
|
||||
|
||||
// Callbacks
|
||||
protected $allowCallbacks = true;
|
||||
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
||||
protected $afterInsert = [];
|
||||
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
||||
protected $afterUpdate = [];
|
||||
protected $beforeFind = [];
|
||||
protected $afterFind = [];
|
||||
protected $beforeDelete = [];
|
||||
protected $afterDelete = [];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,21 +38,145 @@
|
||||
border-left: 4px solid #2196F3;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<style>
|
||||
|
||||
.summary-box {
|
||||
padding: 10px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.summary-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.summary-row:last-child {
|
||||
margin-bottom: 0;
|
||||
font-size: 16px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
padding-top: 8px;
|
||||
padding-top: 4px;
|
||||
border-top: 1px solid #2196F3;
|
||||
}
|
||||
|
||||
.summary-row {
|
||||
padding: 0px 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.summary-row span:last-child {
|
||||
font-weight: bold;
|
||||
font-size: 12px !important;
|
||||
}
|
||||
|
||||
.utr-section {
|
||||
margin-top: 15px;
|
||||
padding-top: 15px;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
.utr-heading {
|
||||
margin-bottom: 10px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.utr-form-group {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.utr-label {
|
||||
font-size: 13px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.utr-small-text {
|
||||
color: #666;
|
||||
display: block;
|
||||
margin-top: 3px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.utr-submit-wrapper {
|
||||
margin-bottom: 10px;
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.utr-list {
|
||||
margin-top: 15px;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
.utr-table {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.utr-table thead tr {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.utr-table tbody {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.utr-dropdown-item {
|
||||
font-size: 13px;
|
||||
padding: 5px 15px;
|
||||
}
|
||||
|
||||
.utr-icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#payout_modal .modal-body {
|
||||
max-height: 550px; /* adjust as needed */
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<style>
|
||||
.utr-table td,
|
||||
.utr-table th {
|
||||
padding: 3px 8px !important;
|
||||
vertical-align: middle;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.utr-table tbody tr {
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
.utr-table thead th {
|
||||
padding: 5px 8px !important;
|
||||
}
|
||||
|
||||
.utr-table .btn-sm {
|
||||
padding: 1px 6px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.utr-table .mdi {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.utr-table .dropdown-menu {
|
||||
min-width: 110px;
|
||||
}
|
||||
|
||||
.utr-dropdown-item {
|
||||
padding: 7px 10px !important;
|
||||
}
|
||||
|
||||
table[data-custom-table-css="table"] tbody tr td {
|
||||
padding: 1px 10px !important;
|
||||
line-height: 12px;
|
||||
min-height: 40px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div class="col-12">
|
||||
@ -94,7 +218,7 @@
|
||||
<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">
|
||||
<a class="dropdown-item" onclick="showUtrModal(this)"><i class="mdi mdi-bank-transfer mr-2 text-muted font-18 vertical-middle"></i>UTR</a>
|
||||
<a class="dropdown-item" onclick="fetchUtrDetails(<?= $row['id'] ?>, '<?= $row['invoice_no'] ?>')"><i class="mdi mdi-bank-transfer mr-2 text-muted font-18 vertical-middle"></i>UTR</a>
|
||||
<a href="<?= base_url('payout/invoices/save?type="edit"') ?>" class="dropdown-item"><i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
|
||||
<a href="<?= base_url('payout/invoices/save?type="adjustment"') ?>" class="dropdown-item"><i class="mdi mdi-tune mr-2 text-muted font-18 vertical-middle"></i>Adjustment</a>
|
||||
</div>
|
||||
@ -110,67 +234,14 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="payout_modal" tabindex="-1" role="dialog" aria-hidden="true" aria-modal="true" data-backdrop="static">
|
||||
<div class="modal-dialog modal-lg" style="max-width: 1100px;">
|
||||
<div class="modal fade" id="payout_modal" tabindex="-1" role="dialog" aria-hidden="true" aria-modal="true" data-bs-backdrop="static">
|
||||
<div class="modal-dialog modal-lg" style="max-width: 800px;">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="background-color: gainsboro;">
|
||||
<h4 class="modal-title" id="myCenterModalLabel">UTR Management<span id="heading"></span></h4>
|
||||
<h5 class="modal-title" id="myCenterModalLabel">UTR <span id="heading"></span></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
</div>
|
||||
<div class="modal-body" id="modal_body">
|
||||
|
||||
<div class="summary-box">
|
||||
<div class="summary-row">
|
||||
<span>Invoice Amount:</span>
|
||||
<span id="utrInvoiceAmount" style="font-weight: bold;">₹0.00</span>
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span>Total UTR Paid:</span>
|
||||
<span id="utrTotalPaid" style="font-weight: bold;">₹0.00</span>
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span>Remaining Balance:</span>
|
||||
<span id="utrRemaining" style="font-weight: bold;">₹0.00</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="utrContent">
|
||||
<div style="margin-top: 20px; padding-top: 20px; border-top: 2px solid #eee;">
|
||||
<h3 style="margin-bottom: 15px;">Add New UTR</h3>
|
||||
<form id="utrForm" method="POST" action="">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label>UTR Number *</label>
|
||||
<input type="text" name="utrNumber" id="utrNumber" class="form-control" placeholder="Enter UTR number" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label>Amount (₹) *</label>
|
||||
<input type="number" name="utrAmount" id="utrAmount" class="form-control" step="0.01" placeholder="Enter amount" required>
|
||||
<small style="color: #666; display: block; margin-top: 5px;">
|
||||
Maximum: <span id="maxUtrAmount">₹0.00</span>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label>Date *</label>
|
||||
<input type="text" name="utrDate" id="utrDate" class="form-control" placeholder="DD/MM/YYYY" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group" style="margin-top: 27px;">
|
||||
<button type="submit" class="btn btn-primary" style="width: 100%;">Add UTR</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="utr-list" id="utrList"></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -233,14 +304,22 @@
|
||||
|
||||
});
|
||||
|
||||
function fetchUtrDetails(invoice_id)
|
||||
{
|
||||
let invoice_id = $('#agent_id').val();
|
||||
function fetchUtrDetails(invoice_id, invoice_no)
|
||||
{
|
||||
if (!invoice_id) {
|
||||
toastr.warning("Invoice Id not found!", "WARNING");
|
||||
return false;
|
||||
}
|
||||
|
||||
let heading_text = ' - ( Invoice No : ' + invoice_no + ' )';
|
||||
|
||||
$('#modal_body').empty();
|
||||
$('#heading').text(heading_text);
|
||||
$('#modal_body').append('<div class="text-center p-5"><div class="spinner-border text-primary" role="status"><span class="sr-only">Loading...</span></div></div>');
|
||||
|
||||
var myModal = new bootstrap.Modal(document.getElementById('payout_modal'));
|
||||
myModal.show();
|
||||
|
||||
let url = '<?= base_url('payout/fetchUtrDetails') ?>';
|
||||
|
||||
// Data to send in the AJAX request
|
||||
@ -256,6 +335,7 @@
|
||||
console.log('Data fetched successfully:', response);
|
||||
|
||||
$('#modal_body').empty();
|
||||
$('#heading').text(heading_text);
|
||||
$('#modal_body').append(response.data);
|
||||
|
||||
if (response.status == false) {
|
||||
@ -274,45 +354,4 @@
|
||||
});
|
||||
}
|
||||
|
||||
function saveUtrDetails(invoice_id)
|
||||
{
|
||||
let invoice_id = $('#agent_id').val();
|
||||
if (!invoice_id) {
|
||||
toastr.warning("Invoice Id not found!", "WARNING");
|
||||
return false;
|
||||
}
|
||||
|
||||
let url = '<?= base_url('payout/fetchUtrDetails') ?>';
|
||||
|
||||
// Data to send in the AJAX request
|
||||
let requestData = {
|
||||
invoice_id: invoice_id,
|
||||
};
|
||||
|
||||
$('.loader').fadeIn();
|
||||
$('.loader-mask').fadeIn();
|
||||
// Send AJAX request
|
||||
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
|
||||
|
||||
console.log('Data fetched successfully:', response);
|
||||
|
||||
$('#payout_list').empty();
|
||||
$('#payout_list').append(response.data);
|
||||
|
||||
if (response.status == false) {
|
||||
toastr.warning(response.message || 'Unable to fetch data', 'WARNING');
|
||||
}
|
||||
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
|
||||
}, function(xhr, status, error) {
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
console.error('Error fetching data:', error);
|
||||
console.error(xhr.responseText);
|
||||
toastr.error('An error occurred while fetching the data.', 'ERROR');
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
@ -180,129 +180,5 @@
|
||||
toastr.error('An error occurred while fetching the data.', 'ERROR');
|
||||
});
|
||||
}
|
||||
|
||||
function showUtrModal(){
|
||||
var myModal = new bootstrap.Modal(document.getElementById('payout_modal'));
|
||||
myModal.show();
|
||||
}
|
||||
|
||||
function updateUTRSummary() {
|
||||
|
||||
const totalUTR = currentInvoice.utrs.reduce((sum, utr) => sum + utr.amount, 0);
|
||||
const remaining = currentInvoice.currentAmount - totalUTR;
|
||||
|
||||
document.getElementById('utrInvoiceAmount').textContent = '₹' + currentInvoice.currentAmount.toFixed(2);
|
||||
document.getElementById('utrTotalPaid').textContent = '₹' + totalUTR.toFixed(2);
|
||||
document.getElementById('utrRemaining').textContent = '₹' + remaining.toFixed(2);
|
||||
document.getElementById('maxUtrAmount').textContent = '₹' + remaining.toFixed(2);
|
||||
|
||||
// Color code remaining amount
|
||||
const remainingSpan = document.getElementById('utrRemaining');
|
||||
if (remaining === 0) {
|
||||
remainingSpan.style.color = '#4CAF50';
|
||||
} else if (remaining < 0) {
|
||||
remainingSpan.style.color = '#f44336';
|
||||
} else {
|
||||
remainingSpan.style.color = '#ff9800';
|
||||
}
|
||||
}
|
||||
|
||||
function renderUTRList() {
|
||||
const list = document.getElementById('utrList');
|
||||
|
||||
if (currentInvoice.utrs.length === 0) {
|
||||
list.innerHTML = '<div class="no-data">No UTR records found</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '<h3 style="margin-bottom: 15px;">Existing UTRs</h3>';
|
||||
currentInvoice.utrs.forEach((utr, idx) => {
|
||||
html += `
|
||||
<div class="utr-item">
|
||||
<div class="utr-info">
|
||||
<div class="utr-number">${idx + 1}. ${utr.utrNo}</div>
|
||||
<div class="utr-date">${utr.date}</div>
|
||||
</div>
|
||||
<div class="utr-amount">₹${utr.amount.toFixed(2)}</div>
|
||||
<button class="delete-btn" onclick="deleteUTR(${idx})" title="Delete">×</button>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
list.innerHTML = html;
|
||||
}
|
||||
|
||||
function addUTR() {
|
||||
const utrNo = document.getElementById('utrNumber').value.trim();
|
||||
const amount = parseFloat(document.getElementById('utrAmount').value);
|
||||
const date = document.getElementById('utrDate').value;
|
||||
|
||||
if (!utrNo || !amount || !date) {
|
||||
alert('Please fill in all fields');
|
||||
return;
|
||||
}
|
||||
|
||||
if (amount <= 0) {
|
||||
alert('Amount must be greater than 0');
|
||||
return;
|
||||
}
|
||||
|
||||
const totalUTR = currentInvoice.utrs.reduce((sum, utr) => sum + utr.amount, 0);
|
||||
const remaining = currentInvoice.currentAmount - totalUTR;
|
||||
|
||||
if (amount > remaining) {
|
||||
alert(`Amount exceeds remaining balance. Maximum allowed: ₹${remaining.toFixed(2)}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add to current invoice
|
||||
currentInvoice.utrs.push({
|
||||
utrNo: utrNo,
|
||||
amount: amount,
|
||||
date: date
|
||||
});
|
||||
|
||||
// Check if invoice is fully paid
|
||||
const newTotalUTR = currentInvoice.utrs.reduce((sum, utr) => sum + utr.amount, 0);
|
||||
if (newTotalUTR >= currentInvoice.currentAmount) {
|
||||
currentInvoice.status = 'completed';
|
||||
}
|
||||
|
||||
// Clear form
|
||||
document.getElementById('utrNumber').value = '';
|
||||
document.getElementById('utrAmount').value = '';
|
||||
|
||||
// Refresh displays
|
||||
updateUTRSummary();
|
||||
renderUTRList();
|
||||
renderInvoices();
|
||||
|
||||
alert('UTR added successfully!');
|
||||
}
|
||||
|
||||
function deleteUTR(index) {
|
||||
if (!confirm('Are you sure you want to delete this UTR?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentInvoice.utrs.splice(index, 1);
|
||||
|
||||
// Update status
|
||||
const totalUTR = currentInvoice.utrs.reduce((sum, utr) => sum + utr.amount, 0);
|
||||
if (totalUTR >= currentInvoice.currentAmount) {
|
||||
currentInvoice.status = 'completed';
|
||||
} else {
|
||||
currentInvoice.status = 'pending';
|
||||
}
|
||||
|
||||
updateUTRSummary();
|
||||
renderUTRList();
|
||||
renderInvoices();
|
||||
}
|
||||
|
||||
function closeModal(modalId) {
|
||||
document.getElementById(modalId).classList.remove('active');
|
||||
currentInvoice = null;
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
280
app/Views/payout_utr_details.php
Normal file
280
app/Views/payout_utr_details.php
Normal file
@ -0,0 +1,280 @@
|
||||
<div>
|
||||
|
||||
<div class="summary-box">
|
||||
<div class="summary-row">
|
||||
<span>Invoice Amount:</span>
|
||||
<span id="utrInvoiceAmount" data-id="<?php echo isset($summary['invoice_amount']) && !empty($summary['invoice_amount']) ? $summary['invoice_amount'] : ""?>">
|
||||
₹<?php echo isset($summary['invoice_amount']) && !empty($summary['invoice_amount']) ? format_indian_number($summary['invoice_amount']) : "0.00"?>
|
||||
</span>
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span>Total Paid:</span>
|
||||
<span id="utrTotalPaid" data-id="<?php echo isset($summary['total_utr_amount']) && !empty($summary['total_utr_amount']) ? $summary['total_utr_amount'] : ""?>">
|
||||
₹<?php echo isset($summary['total_utr_amount']) && !empty($summary['total_utr_amount']) ? format_indian_number($summary['total_utr_amount']) : "0.00"?>
|
||||
</span>
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span>Remaining Balance:</span>
|
||||
<span id="utrRemaining" data-id="<?php echo isset($summary['balance_amount']) && !empty($summary['balance_amount']) ? $summary['balance_amount'] : ""?>">
|
||||
₹<?php echo isset($summary['balance_amount']) && !empty($summary['balance_amount']) ? format_indian_number($summary['balance_amount']) : "0.00"?>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="utrContent">
|
||||
<div class="utr-section">
|
||||
<!-- <h5 class="utr-heading">Add New UTR</h5> -->
|
||||
<form id="utrForm" role="form" class="parsley-examples">
|
||||
<input type="hidden" name="utr_pk" id="utr_pk">
|
||||
<input type="hidden" name="invoice_id" value="<?php echo isset($summary['id']) && !empty($summary['id']) ? $summary['id'] : ""?>">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="form-group utr-form-group">
|
||||
<label class="utr-label">UTR Number <span class="text-danger">*</span></label>
|
||||
<input type="text" name="utr_no" id="utrNumber" class="form-control form-control-sm" placeholder="Enter UTR number" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group utr-form-group">
|
||||
<label class="utr-label">Amount (₹) <span class="text-danger">*</span></label>
|
||||
<input type="number" name="amount" id="utrAmount" oninput="checkSum(this)" class="form-control form-control-sm" step="0.01" placeholder="Enter amount" required>
|
||||
<!-- <small class="utr-small-text">
|
||||
Max: <span id="maxUtrAmount">₹0.00</span>
|
||||
</small> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group utr-form-group">
|
||||
<label class="utr-label">Date <span class="text-danger">*</span></label>
|
||||
<input type="text" name="utr_date" id="utrDate" class="form-control form-control-sm" placeholder="DD/MM/YYYY" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3" style="<?= !isset($invoice_completed) ? 'display: block;' : 'display: none;' ?>">
|
||||
<div class="form-group utr-submit-wrapper">
|
||||
<a onclick="resetvalues()" class="btn btn-secondary btn-sm">Clear</a>
|
||||
<button id="utr_submit_btn" onclick="saveUtrDetails(event)" class="btn btn-primary btn-sm">Add UTR</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="utr-list" id="utrList">
|
||||
<h5 class="utr-heading">Existing UTRs</h5>
|
||||
<div class="table-responsive">
|
||||
<table data-custom-table-css="table" id="ticket-table" class="table table-sm w-100 nowrap utr-table">
|
||||
<thead class="bg-light">
|
||||
<tr>
|
||||
<th class="font-weight-medium">S.No.</th>
|
||||
<th class="font-weight-medium">UTR No</th>
|
||||
<th class="font-weight-medium">Amount</th>
|
||||
<th class="font-weight-medium">Date</th>
|
||||
<!-- <th class="font-weight-medium">User</th> -->
|
||||
<th class="font-weight-medium">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (isset($utr_list_data) && !empty($utr_list_data)) { ?>
|
||||
<?php foreach($utr_list_data as $index => $row){
|
||||
$row['utr_date'] = change_date_format($row['utr_date'], null, 'd/m/Y') ?? " - "
|
||||
?>
|
||||
<tr>
|
||||
<td> <?= $index + 1 ?> </td>
|
||||
<td> <?= $row['utr_no'] ?> </td>
|
||||
<td> <?= format_indian_number($row['amount']) ?> </td>
|
||||
<td> <?= $row['utr_date'] ?> </td>
|
||||
<!-- <td> <?php // format_indian_number($row['created_user']) ?> </td> -->
|
||||
<td>
|
||||
<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">
|
||||
|
||||
<a style="<?= !isset($invoice_completed) ? 'display: block;' : 'display: none;' ?>" class="dropdown-item utr-dropdown-item" onclick='updateUtr(<?= htmlspecialchars(json_encode($row ?? []), ENT_QUOTES, "UTF-8") ?>)'><i class="mdi mdi-pencil mr-2 text-muted utr-icon vertical-middle"></i>Edit</a>
|
||||
<a class="dropdown-item utr-dropdown-item" onclick="removeUtrApi(<?php echo isset($summary['id']) && !empty($summary['id']) ? $summary['id'] : ''?>, <?= $row['id'] ?>)"><i class="mdi mdi-delete mr-2 text-muted utr-icon vertical-middle"></i>Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
var dob = flatpickr("#utrDate", {
|
||||
dateFormat: "d/m/Y",
|
||||
allowInput: false,
|
||||
maxDate: "today"
|
||||
});
|
||||
|
||||
function saveUtrDetails(e) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
console.log('saveUtrDetails function called');
|
||||
|
||||
var isValid = $('#utrForm').parsley().validate();
|
||||
if (!isValid) {
|
||||
$('#utrForm').find('input, select, textarea').each(function() {
|
||||
if ($(this).parsley().isValid() === false && !$(this).val()) {
|
||||
console.log(' :) Empty field ID:', this.id);
|
||||
}
|
||||
});
|
||||
console.log('Form is Empty', 'Warning');
|
||||
return;
|
||||
}
|
||||
|
||||
var formData = new FormData($('#utrForm')[0]);
|
||||
|
||||
// Show loading state
|
||||
$('#utr_submit_btn').prop('disabled', true).text('Saving...');
|
||||
|
||||
let url = '<?= base_url('payout/saveUtrDetails') ?>';
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
|
||||
console.log('Data fetched successfully:', response);
|
||||
|
||||
if (response.status == true) {
|
||||
toastr.success(response.message, 'SUCCESS');
|
||||
$('#modal_body').empty();
|
||||
$('#modal_body').append(response.data);
|
||||
}else{
|
||||
toastr.warning(response.message || 'Unable to fetch data', 'WARNING');
|
||||
}
|
||||
|
||||
// Re-enable button
|
||||
$('#utr_submit_btn').prop('disabled', false).text('Add UTR');
|
||||
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
console.error('Error fetching data:', error);
|
||||
console.error(xhr.responseText);
|
||||
toastr.error('An error occurred while fetching the data.', 'ERROR');
|
||||
},
|
||||
complete: function() {
|
||||
$('#utr_submit_btn').prop('disabled', false).text('Add UTR');
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
resetvalues();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateUtr(data){
|
||||
console.log("data", data)
|
||||
if(data){
|
||||
$('#utr_pk').val(data.id);
|
||||
$('#utrNumber').val(data.utr_no);
|
||||
$('#utrAmount').val(data.amount);
|
||||
$('#utrDate').val(data.utr_date);
|
||||
$('#utr_submit_btn').text('Update UTR');
|
||||
$('#utrNumber').trigger('focus');
|
||||
}
|
||||
}
|
||||
|
||||
function resetvalues(){
|
||||
$('#utr_pk').val("");
|
||||
$('#utrNumber').val("");
|
||||
$('#utrAmount').val("");
|
||||
$('#utrDate').val("");
|
||||
$('#utr_submit_btn').text('Add UTR');
|
||||
}
|
||||
|
||||
function removeUtrApi(invoice_id, utr_id) {
|
||||
Swal.fire({
|
||||
title: "Are you sure?",
|
||||
text: "Do you want to remove this UTR?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Yes, Proceed!",
|
||||
cancelButtonText: "Cancel"
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
removeUtr(invoice_id, utr_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function removeUtr(invoice_id, utr_id){
|
||||
|
||||
let url = '<?= base_url('payout/removeUtrDetails') ?>';
|
||||
|
||||
// Data to send in the AJAX request
|
||||
let requestData = {
|
||||
invoice_id: invoice_id,
|
||||
utr_id: utr_id,
|
||||
};
|
||||
|
||||
$('.loader').fadeIn();
|
||||
$('.loader-mask').fadeIn();
|
||||
|
||||
// Send AJAX request
|
||||
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
|
||||
|
||||
console.log('Data fetched successfully:', response);
|
||||
|
||||
$('#modal_body').empty();
|
||||
$('#modal_body').append(response.data);
|
||||
|
||||
if (response.status == true) {
|
||||
toastr.success(response.message, 'SUCCESS');
|
||||
}else{
|
||||
toastr.warning(response.message || 'Unable to fetch data', 'WARNING');
|
||||
}
|
||||
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
|
||||
}, function(xhr, status, error) {
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
console.error('Error fetching data:', error);
|
||||
console.error(xhr.responseText);
|
||||
toastr.error('An error occurred while fetching the data.', 'ERROR');
|
||||
});
|
||||
}
|
||||
|
||||
function checkSum(input) {
|
||||
|
||||
let invoice_amt = parseFloat($('#utrInvoiceAmount').data('id')) || 0;
|
||||
let utr_amt = parseFloat($('#utrTotalPaid').data('id')) || 0;
|
||||
let balance_amt = parseFloat($('#utrRemaining').data('id')) || 0;
|
||||
|
||||
let input_amt = parseFloat($(input).val()) || 0;
|
||||
|
||||
console.log({ invoice_amt, utr_amt, balance_amt, input_amt });
|
||||
|
||||
let total_amt = utr_amt + input_amt;
|
||||
|
||||
if (total_amt > invoice_amt) {
|
||||
toastr.warning('UTR amount exceeds the invoice amount');
|
||||
$(input).val('');
|
||||
$('#utr_submit_btn').prop('disabled', true);
|
||||
}else{
|
||||
$('#utr_submit_btn').prop('disabled', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user