susee
This commit is contained in:
parent
a69a472329
commit
fa96221cab
@ -100,6 +100,9 @@ $routes->match(['get','post'],'/manage_availability','Admin_controller::manage_a
|
||||
$routes->match(['get','post'],'/add_to_cart_package','Admin_controller::add_to_cart_package');
|
||||
$routes->match(['post'],'/order_details','Admin_controller::order_details');
|
||||
$routes->match(['get'],'/view_credit_details/(:any)','Admin_controller::view_credit_details/$1');
|
||||
$routes->match(['post'],'/update_creditsModel/(:any)','Admin_controller::update_creditsModel/$1');
|
||||
$routes->match(['get','post'],'/get_pack_list','Admin_controller::get_pack_list');
|
||||
$routes->match(['get','post'],'/add_creditsModel','Admin_controller::add_creditsModel');
|
||||
|
||||
$routes->match(['get'],'/product_list','Admin_controller::product_list');
|
||||
$routes->match(['get'],'/product_edit/(:any)','Admin_controller::product_edit/$1');
|
||||
|
||||
@ -495,7 +495,19 @@ class Admin_controller extends BaseController
|
||||
|
||||
|
||||
|
||||
|
||||
public function get_pack_list()
|
||||
{
|
||||
if($this->request->getmethod() == 'get')
|
||||
{
|
||||
$data = $this->PackagesModel->findAll();
|
||||
echo json_encode($data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = $this->PackagesModel->where('id',$this->request->getVar('id'))->find();
|
||||
echo json_encode($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1087,30 +1099,68 @@ class Admin_controller extends BaseController
|
||||
|
||||
}
|
||||
|
||||
public function update_creditsModel($con)
|
||||
{
|
||||
$data['total'] = $this->request->getVar('total');
|
||||
$id = $this->request->getVar('id');
|
||||
if($con == 'del')
|
||||
$upt_data = $this->creditsModel->where('id', $id )->set(array( 'is_active' => 0 ))->update();
|
||||
else
|
||||
$upt_data = $this->creditsModel->where('id', $id )->set(array( 'is_active' => 1 ))->update();
|
||||
echo $upt_data ? true : false;
|
||||
}
|
||||
|
||||
public function add_creditsModel()
|
||||
{
|
||||
$data = $this->request->getVar();
|
||||
$count = $this->request->getVar('count') ?? 1;
|
||||
for ($i=0; $i < $count ; $i++)
|
||||
{
|
||||
$data['running_balance'] = $this->request->getVar('credit_points');
|
||||
$data['updated_by'] = session()->get('logged_admin_user');
|
||||
$this->creditsModel->save($data);
|
||||
}
|
||||
return redirect()->to(base_url()."members_list");
|
||||
}
|
||||
|
||||
public function view_credit_details($member_id)
|
||||
|
||||
{
|
||||
|
||||
|
||||
$creditsData = $this->creditsModel->where('md5(member_id)',$member_id)->where('is_active',1)->orderBy('id' , 'ASC')->findAll();
|
||||
$fname = $this->MemberModel->select('name')->where('md5(id)', $member_id )->get()->getRow()->name;
|
||||
$lname = $this->MemberModel->select('last_name')->where('md5(id)', $member_id )->get()->getRow()->last_name;
|
||||
$id = $this->MemberModel->select('id')->where('md5(id)', $member_id )->get()->getRow()->id;
|
||||
$creditsData = $this->creditsModel->where('md5(member_id)',$member_id)->orderBy('id' , 'ASC')->findAll();
|
||||
$data['credit_data'] = [];
|
||||
$data['avaiable_credit'] = 0;
|
||||
$data['country'] = $this->CountryModel->findAll();
|
||||
foreach ($creditsData as $creditsDataindex => $creditsDataValue)
|
||||
{
|
||||
|
||||
$data['avaiable_credit'] = $data['avaiable_credit'] + $creditsDataValue['running_balance'];
|
||||
$creditsDataValue['avaiable_credit'] = $data['avaiable_credit'];
|
||||
array_push($data['credit_data'] , $creditsDataValue);
|
||||
if($creditsDataValue['is_active'] == 1)
|
||||
{
|
||||
$data['avaiable_credit'] = $data['avaiable_credit'] + $creditsDataValue['running_balance'];
|
||||
$creditsDataValue['avaiable_credit'] = $data['avaiable_credit'];
|
||||
array_push($data['credit_data'] , $creditsDataValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['avaiable_credit'] = $data['avaiable_credit'];
|
||||
$creditsDataValue['avaiable_credit'] = 0;
|
||||
array_push($data['credit_data'] , $creditsDataValue);
|
||||
}
|
||||
}
|
||||
|
||||
$output = '<div class="table-responsive"><table class="table mb-0"><thead class="thead-light"><tr> <th>Order Id</th><th>Order Date</th><th>Expiry Date</th><th>Credit Transactions</th><th>Credit Balance</th></tr></thead><tbody>';
|
||||
$output = '<input id="empName" type="hidden" value="'.$fname.' '.$lname.'"><input id="empId" type="hidden" value="'.$id.'"><div class="table-responsive"><table class="table mb-0"><thead class="thead-light"><tr> <th>Order Id</th><th>Order Date</th><th>Expiry Date</th><th>Credit Transactions</th><th>Credit Balance</th></th><th>Action</th></tr></thead><tbody>';
|
||||
for( $i = count($data['credit_data']) - 1; $i >= 0 ; $i--) {
|
||||
$date = new DateTime($data['credit_data'][$i]['created_at']);
|
||||
$expirydate = new DateTime($data['credit_data'][$i]['expiring_date']);
|
||||
if($data['credit_data'][$i]['running_balance'] > 0)
|
||||
{$balance = "+ ".$data['credit_data'][$i]['running_balance'];}else{$balance = "- ".$data['credit_data'][$i]['used_points'];}
|
||||
$output .='<tr><td>'.$data['credit_data'][$i]['order_id'].'</td><td>'.$date->format('M d , Y').'</td><td>'.$expirydate->format('M d , Y').'</td><td style="text-align: center;">'.$balance.'</td><td style="text-align: center;">'.$data['credit_data'][$i]['avaiable_credit'].'</td></tr>';
|
||||
// if($data['credit_data'][$i]['is_active'] == 0) $balance = 0;
|
||||
if($data['credit_data'][$i]['is_active'] == 1)
|
||||
$output .='<tr><td>'.$data['credit_data'][$i]['order_id'].'</td><td>'.$date->format('M d , Y').'</td><td>'.$expirydate->format('M d , Y').'</td><td style="text-align: center;">'.$balance.'</td><td class="balance" style="text-align: center;">'.$data['credit_data'][$i]['avaiable_credit'].'</td><td style="text-align: center;" title="delete"><i id="'.$balance.'|'.$data['credit_data'][$i]['id'].'|'.$member_id.'" class="mdi mdi-delete del-balance" style="font-size:20px;"></i></td></tr>';
|
||||
else
|
||||
$output .='<tr style="background-color:#de57574f;"><td>'.$data['credit_data'][$i]['order_id'].'</td><td>'.$date->format('M d , Y').'</td><td>'.$expirydate->format('M d , Y').'</td><td style="text-align: center;">'.$balance.'</td><td class="balance" style="text-align: center;">'.$data['credit_data'][$i]['avaiable_credit'].'</td><td style="text-align: center;" title="add"><i id="'.$balance.'|'.$data['credit_data'][$i]['id'].'|'.$member_id.'" class="mdi mdi-file-plus add-balance" style="font-size:20px;"></i></td></tr>';
|
||||
}
|
||||
echo $output .= '</tbody></table></div> ';
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ class Member_credits_model extends Model
|
||||
protected $table = 'member_credits';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $allowedFields = ['member_id','pack_id','package_name','package_type','credit_points','running_balance','used_points', 'expired_points','expiring_date', 'cost' ,'is_active', 'order_id','transaction_id' ,'cost_with_tax'];
|
||||
protected $allowedFields = ['member_id','pack_id','package_name','package_type','credit_points','running_balance','used_points', 'expired_points','expiring_date', 'cost' ,'is_active', 'order_id','transaction_id' ,'cost_with_tax','method','created_by'];
|
||||
|
||||
|
||||
}
|
||||
@ -107,17 +107,15 @@
|
||||
|
||||
<!-- Modal content for the Large example -->
|
||||
<div class="modal fade" id="bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="myLargeModalLabel"></h4>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<div class="modal-dialog modal-lg" id="modalname">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="myLargeModalLabel"></h4>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
</div>
|
||||
<div class="modal-body" id="model-table" >
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="plus-ico" style="font-size:25px;text-align: end;padding-right: 40px;"></div>
|
||||
<div class="modal-body" id="model-table" ></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -126,6 +124,102 @@
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
$(document).on('click','.mdi-plus-box',function(){
|
||||
$.ajax({
|
||||
url:"<?= base_url(); ?>get_pack_list",
|
||||
method: 'GET',
|
||||
success: function(response) {
|
||||
pack=[];
|
||||
JSON.parse(response).forEach((val,index) => {
|
||||
pack[index] = `<option value="${val.id}">${val.package_name}</option>`;
|
||||
});
|
||||
addForm = `<div class="myform">
|
||||
<form id="myform" method="POST" action="<?= base_url(); ?>add_creditsModel">
|
||||
<input id="member_id" type="hidden" name="member_id" value="${ $('#empId').val() }">
|
||||
<div class="row" style="width:80%;margin:auto;">
|
||||
<div class="mb-1 mt-2 col-md-12 changeClass">
|
||||
<label class="form-label">Pack</label>
|
||||
<select name="package_name" id="packs" class="form-control">
|
||||
<option value="">--SELECT--</option>
|
||||
${pack}
|
||||
</select>
|
||||
</div>
|
||||
<div id="count_hide_show" class="mb-1 mt-2"></div>
|
||||
<div class="mb-1 mt-2 col-md-4">
|
||||
<label class="form-label">Credit<span style="color: red;margin-left: 4px;">*</label>
|
||||
<input type="text" class="form-control" name="credit_points" id="credit" required>
|
||||
</div>
|
||||
<div class="mb-1 mt-2 col-md-4">
|
||||
<label class="form-label">Cost<span style="color: red;margin-left: 4px;">*</label>
|
||||
<input type="text" class="form-control" name="cost" id="cost" required>
|
||||
</div>
|
||||
<div class="mb-1 mt-2 col-md-4">
|
||||
<label class="form-label">Method<span style="color: red;margin-left: 4px;">*</label>
|
||||
<select name="method" id="method" class="form-control" required>
|
||||
<option value="">--SELECT--</option>
|
||||
<option value="card">Card</option>
|
||||
<option value="cash">Cash</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-1 mt-2 col-md-12">
|
||||
<label class="form-label">Remarks</label>
|
||||
<input type="text" class="form-control" name="remarks">
|
||||
</div>
|
||||
</div>
|
||||
<div style="text-align:center;margin-top:30px;"><button type="submit" class="btn btn-primary waves-effect waves-light">Add</button></div>
|
||||
</form>
|
||||
</div>`
|
||||
$('.plus-ico').html('');
|
||||
$('#myLargeModalLabel').html("Add Credits ("+$('#empName').val()+" )")
|
||||
$('#model-table').html(addForm);
|
||||
$('#bs-example-modal-lg').modal('show');
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle the error here
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).on('change','#packs',function(){
|
||||
id = $(this).val();
|
||||
$.ajax({
|
||||
url:"<?= base_url(); ?>get_pack_list",
|
||||
method: 'POST',
|
||||
data: { 'id' : id },
|
||||
success: function(response) {
|
||||
if(JSON.parse(response).length > 0)
|
||||
{
|
||||
$('.changeClass').removeClass('col-md-12').addClass('col-md-8');
|
||||
count_hide_show = `<label class="form-label">Count</label><input type="number" class="form-control" name="count" min="1" value="1" onKeyDown="return false">`;
|
||||
$("#count_hide_show").addClass("col-md-4");
|
||||
$('#count_hide_show').html(count_hide_show);
|
||||
$('#credit').val(JSON.parse(response)[0].credit);
|
||||
$('#credit').attr('readonly', true);
|
||||
$('#cost').val(Number(JSON.parse(response)[0].cost).toFixed(2));
|
||||
$('#cost').attr('readonly', true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('.changeClass').removeClass('col-md-8').addClass('col-md-12');
|
||||
$('#count_hide_show').removeClass('col-md-4');
|
||||
$('#count_hide_show').html('');
|
||||
$('#credit').removeAttr('readonly');
|
||||
$('#credit').val('');
|
||||
$('#cost').val('');
|
||||
$('#cost').removeAttr('readonly');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle the error here
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).on('click','.credit_usage',function(){
|
||||
@ -136,8 +230,10 @@ $(document).on('click','.credit_usage',function(){
|
||||
url:"<?= base_url(); ?>view_credit_details/"+member_id,
|
||||
method: 'GET',
|
||||
success: function(response) {
|
||||
$('#myLargeModalLabel').html('Credits Details')
|
||||
// $("#modalname").removeClass("modal-sm").addClass("modal-lg");
|
||||
$('#myLargeModalLabel').html('Credits Details')
|
||||
$('#model-table').html(response);
|
||||
$('.plus-ico').html('<i class="mdi mdi-plus-box" title="add"></i>');
|
||||
$('#bs-example-modal-lg').modal('show');
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
@ -147,6 +243,7 @@ $(document).on('click','.credit_usage',function(){
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).on('click','.transaction',function(){
|
||||
|
||||
@ -156,7 +253,9 @@ $(document).on('click','.transaction',function(){
|
||||
url:"<?= base_url(); ?>/transactions_list/"+member_id,
|
||||
method: 'GET',
|
||||
success: function(response) {
|
||||
// $("#modalname").removeClass("modal-sm").addClass("modal-lg");
|
||||
$('#myLargeModalLabel').html('Transaction Details')
|
||||
// $('.plus-ico').html('<i class="mdi mdi-plus-box" title="add" style="font-size:25px;text-align: end;padding-right: 40px;"></i>');
|
||||
$('#model-table').html(response);
|
||||
$('#bs-example-modal-lg').modal('show');
|
||||
},
|
||||
@ -168,6 +267,52 @@ $(document).on('click','.transaction',function(){
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).on('click','.del-balance',function(){
|
||||
// alert($(this).attr('id').split('|')[2])
|
||||
alert($(this).attr('id').split('|')[1])
|
||||
bal = $('.balance').html();
|
||||
cer_trans = $(this).attr('id').split('|')[0];
|
||||
tot = bal - cer_trans;
|
||||
|
||||
$.ajax({
|
||||
url:"<?= base_url(); ?>/update_creditsModel/del",
|
||||
method: 'POST',
|
||||
data: { 'id' : $(this).attr('id').split('|')[1] , 'total' : tot },
|
||||
success: function(response) {
|
||||
location.reload();
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle the error here
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).on('click','.add-balance',function(){
|
||||
// alert($(this).attr('id').split('|')[2])
|
||||
alert($(this).attr('id').split('|')[1])
|
||||
bal = $('.balance').html();
|
||||
cer_trans = $(this).attr('id').split('|')[0];
|
||||
tot = bal + cer_trans;
|
||||
|
||||
$.ajax({
|
||||
url:"<?= base_url(); ?>/update_creditsModel/add",
|
||||
method: 'POST',
|
||||
data: { 'id' : $(this).attr('id').split('|')[1] , 'total' : tot },
|
||||
success: function(response) {
|
||||
location.reload();
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle the error here
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
@ -182,4 +327,5 @@ $(document).on('click','.transaction',function(){
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user