FEAT_PAYOUT
This commit is contained in:
parent
3fcb6bdee5
commit
d27a892ce8
113
app/Controllers/PayoutController.php
Normal file
113
app/Controllers/PayoutController.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Models\InvoiceItemModel;
|
||||
use App\Models\InvoiceModel;
|
||||
use App\Models\InvoiceUtrModel;
|
||||
use App\Models\PolicyTransactionModel;
|
||||
|
||||
class PayoutController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
protected $myLogger;
|
||||
protected $invoiceItemModel;
|
||||
protected $invoiceModel;
|
||||
protected $invoiceUtrModel;
|
||||
protected $policyTransactionModel;
|
||||
protected $payout_status;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
set_session_context('PayoutController');
|
||||
$this->myLogger = \Config\Services::mylogger();
|
||||
|
||||
$this->payout_status = [
|
||||
1 => "Draft",
|
||||
2 => "Pending",
|
||||
3 => "Complete",
|
||||
];
|
||||
|
||||
$this->invoiceItemModel = new InvoiceItemModel();
|
||||
$this->invoiceModel = new InvoiceModel();
|
||||
$this->invoiceUtrModel = new InvoiceUtrModel();
|
||||
$this->policyTransactionModel = new PolicyTransactionModel();
|
||||
}
|
||||
|
||||
public function payoutList()
|
||||
{
|
||||
// for filtering list
|
||||
if($this->request->is('post')){
|
||||
try{
|
||||
$data = $this->request->getPost();
|
||||
// print_r($data); die;
|
||||
|
||||
$agent_id = $data['agent_id'] ?? null;
|
||||
$status_id = $data['status_id'] ?? null;
|
||||
$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['payout_list_data'] = $payout_data;
|
||||
$payout_data = view('payout_list', $payout_data);
|
||||
|
||||
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);
|
||||
}
|
||||
}catch (\Throwable $th) {
|
||||
|
||||
$this->myLogger->logme("error", "PayoutController - payoutList: Exception: " . $th->getMessage() . " --- Line: " . $th->getLine() . " --- Trace: " . $th->getTraceAsString());
|
||||
$errorData = [
|
||||
'message' => $th->getMessage(),
|
||||
'file' => $th->getFile(),
|
||||
'line' => $th->getLine(),
|
||||
'code' => $th->getCode(),
|
||||
'trace' => $th->getTraceAsString(),
|
||||
'trace_array' => $th->getTrace(), // full array version (optional)
|
||||
'function' => $th->getTrace()[0]['function'] ?? null,
|
||||
'class' => $th->getTrace()[0]['class'] ?? null,
|
||||
];
|
||||
$payout_data = view('payout_list');
|
||||
return $this->respond(['status' => false, 'code' => 500, 'data' => $payout_data, "message" => "No data found", 'error_data' => $errorData], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
$data['payout_list'] = view('payout_list', $payout_data);
|
||||
|
||||
// dd($data);
|
||||
return $this->loadLayout('payout_list_handler', $data);
|
||||
}
|
||||
|
||||
public function fetchUtrDetails()
|
||||
{
|
||||
$invoice_id = $this->request->getPost('invoice_id') ?? null;
|
||||
|
||||
$payout_data = $this->invoiceModel->invoiceList();
|
||||
|
||||
$data['utr_data'] = $payout_data;
|
||||
$payout_data = view('partner_utr_details', $data);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveUtrDetails()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
41
app/Models/InvoiceItemModel.php
Normal file
41
app/Models/InvoiceItemModel.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class InvoiceItemModel extends Model
|
||||
{
|
||||
protected $table = 'partner_invoice_items';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $allowedFields = [
|
||||
'invoice_id',
|
||||
'policy_id',
|
||||
'policy_no',
|
||||
'commission_amount',
|
||||
'is_active',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
protected $useTimestamps = false;
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
protected $validationRules = [
|
||||
'invoice_id' => 'required|integer',
|
||||
'policy_id' => 'required|integer',
|
||||
'policy_no' => 'required|max_length[100]',
|
||||
'commission_amount' => 'decimal'
|
||||
];
|
||||
|
||||
protected $validationMessages = [];
|
||||
protected $skipValidation = false;
|
||||
}
|
||||
117
app/Models/InvoiceModel.php
Normal file
117
app/Models/InvoiceModel.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class InvoiceModel extends Model
|
||||
{
|
||||
protected $table = 'partner_invoice';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $allowedFields = [
|
||||
'invoice_no',
|
||||
'invoice_amount',
|
||||
'agent_id',
|
||||
'invoice_date',
|
||||
'is_active',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'payout_status',
|
||||
];
|
||||
|
||||
// Timestamps
|
||||
protected $useTimestamps = false;
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
// Validation (optional)
|
||||
protected $validationRules = [
|
||||
'invoice_no' => 'required|max_length[100]',
|
||||
'invoice_amount' => 'decimal',
|
||||
'agent_id' => 'required|integer',
|
||||
'invoice_date' => 'required|valid_date',
|
||||
];
|
||||
|
||||
protected $validationMessages = [];
|
||||
protected $skipValidation = false;
|
||||
|
||||
|
||||
public function invoiceList($status = [], $agent_id = null, $status_id = null, $start_date = null, $end_date = null)
|
||||
{
|
||||
$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 'Draft'
|
||||
WHEN payout_status = 2 THEN 'Pending'
|
||||
WHEN payout_status = 3 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);
|
||||
|
||||
if(!empty($agent_id)){
|
||||
$data->where('partner_invoice.agent_id', $agent_id);
|
||||
}
|
||||
|
||||
if(!empty($status_id)){
|
||||
$data->where('partner_invoice.payout_status', $status_id);
|
||||
}
|
||||
|
||||
if (!empty($start_date) && !empty($end_date)) {
|
||||
|
||||
$startDate = date('Y-m-d 00:00:00', strtotime($start_date));
|
||||
$endDate = date('Y-m-d 23:59:59', strtotime($end_date));
|
||||
|
||||
$data->where('partner_invoice.invoice_date >=', $startDate)
|
||||
->where('partner_invoice.invoice_date <=', $endDate);
|
||||
}
|
||||
|
||||
if(!empty($agent_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){
|
||||
|
||||
$fromDate = date('Y-m-d', strtotime('-60 days'));
|
||||
$toDate = date('Y-m-d 23:59:59');
|
||||
|
||||
$data->where('partner_invoice.created_at >=', $fromDate)
|
||||
->where('partner_invoice.created_at <=', $toDate);
|
||||
|
||||
}
|
||||
|
||||
$return_data = $data->orderBy('partner_invoice.id','desc')->findAll();
|
||||
|
||||
// print_r($this->db->getLastQuery()); die;
|
||||
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
public function agentList(){
|
||||
return $this->db->table('partner_agent')->where('is_active', 1)->get()->getResultArray();
|
||||
}
|
||||
}
|
||||
39
app/Models/InvoiceUtrModel.php
Normal file
39
app/Models/InvoiceUtrModel.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class InvoiceUtrModel extends Model
|
||||
{
|
||||
protected $table = 'partner_invoice_utr';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $allowedFields = [
|
||||
'invoice_id',
|
||||
'utr_no',
|
||||
'amount',
|
||||
'is_active',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
protected $useTimestamps = false;
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
protected $validationRules = [
|
||||
'invoice_id' => 'required|integer',
|
||||
'utr_no' => 'required|max_length[100]',
|
||||
'amount' => 'decimal'
|
||||
];
|
||||
|
||||
protected $validationMessages = [];
|
||||
protected $skipValidation = false;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user