Assign coupons

This commit is contained in:
dev-chiefworks
2022-06-02 21:05:53 -04:00
parent d3e28d2aad
commit 51f2b550bc
3 changed files with 143 additions and 22 deletions
+9
View File
@@ -269,3 +269,12 @@ define('PAY_MODE_BONUS', 9);
define('APPROVED_BALANCE', 5);
define('DISAPROVE_BALANCE', 3);
// for coupon table
define('COUPON_ALLOC_STARTED', 100);
define('COUPON_ALLOC_ALLOCATED', 200);
// for allocation table
define('COUPON_ACTIVE', 500);
+112
View File
@@ -4,6 +4,8 @@ defined('BASEPATH') OR exit('No direct script access allowed');
class Bkosmember extends Bkomember_Controller {
public function userdash() {
// $this->load->view('bko/view_bko_header', $data);
$data = array();
@@ -14,6 +16,116 @@ class Bkosmember extends Bkomember_Controller {
$this->load->view('bko/view_bko_footer', $data);
}
public function listcoupon(){
$data = array();
$data = $this->bkoUserDashData($_SESSION['bko_selected_id']);
if ($_GET){
$data['from_coupon'] = $this->input->get('from_coupon')*100;
$data['to_coupon'] = $this->input->get('to_coupon')*100;
$sql = "SELECT id ,
substring(code,0,4)||'XXXXXXXX' AS code,
amount*0.01 AS amount,
description,
created::date ,
'<div id=\"c_sec'||id||'\"><button type=\"button\" class=\"btn btn-primary btn-sm\" onclick=\"assignCoupon('||id||')\">Assign</button></div>' AS assign
FROM coupons
WHERE active IS NULL
AND amount BETWEEN ".$data['from_coupon']." AND ".$data['to_coupon']."
ORDER BY amount ASC LIMIT 5";
$q = $this->db->query($sql);
echo $this->table->generate( $q);
}
else
{
echo "Wrong Call";
}
}
public function assigncoupon(){
if ($_GET){
$data['coupon_id'] = $this->input->get('coupon_id');
echo 'ameye olusesan';
$sql1= "SELECT * FROM coupons WHERE id=". $data['coupon_id']." AND status = 0";
$q1 = $this->db->query($sql1);
if ($q1->num_rows()) {
$member_id = $_SESSION['bko_selected_id'];
$couponArr = $q1->result_array();
$code = $couponArr[0]['code'];
$amount = $couponArr[0]['amount'];
$sql2 = "INSERT INTO coupons_allocation (member_id,code,amount,status) VALUES ( $member_id, '$code', $amount, ".COUPON_ACTIVE." ) ";
$this->db->query($sql2);
$sql0 = "UPDATE coupons SET active=now(), status=".COUPON_ALLOC_STARTED." WHERE code='".$code."'";
$this->db->query($sql0);
echo "Assigned";
} else {
echo 0;
}
/*
xx["member_id"] = in["member_id"]; xx["member_id"].set_valid(true);
xx["code"] = rec["code"]; xx["code"].set_valid(true);
xx["amount"] = rec["amount"]; xx["amount"].set_valid(true);
xx["status"] = COUPON_ACTIVE;
res = pgsql_query("SELECT * FROM coupons WHERE code='%s' AND status = 0", in["code"].c_str());
if (res != NULL && pgsql_num_rows(res) > 0) {
map<const char*, const char*>f = pgsql_fetch_assoc(res, 0);
CVars rec;
map_to_cvars(f, rec);
pgsql_exec("UPDATE coupons SET status=%lu WHERE code='%s' AND status=%lu",COUPON_ALLOC_ALLOCATED,in["code"].c_str(),COUPON_ALLOC_STARTED);
// Now We start
CREATE TABLE coupons_allocation (
id SERIAL,
code VARCHAR(15) UNIQUE REFERENCES coupons( code ) NOT NULL,
amount INT DEFAULT 0,
member_id INT REFERENCES members(id) NOT NULL,
added timestamp without time zone DEFAULT now(),
active timestamp DEFAULT NULL,
loc INET,
status INT DEFAULT 0
);
wrenchboard=> SELECT substring(ca.code,0,4)||'XXXXXXXX' as code, ca.amount,m.email,m.firstname FROM coupons_allocation ca LEFT JOIN members m ON m.id=ca.member_id;
code | amount | email | firstname
-------------+--------+----------------------+-----------
1M5XXXXXXXX | 0 | ses66181+1@gmail.com | Olusesan
CVars xx;
xx["member_id"] = in["member_id"]; xx["member_id"].set_valid(true);
xx["code"] = rec["code"]; xx["code"].set_valid(true);
xx["amount"] = rec["amount"]; xx["amount"].set_valid(true);
xx["status"] = COUPON_ACTIVE; xx["status"].set_valid(true);
coupon_id = insert_db_record(DBS_VALID, "coupons_allocation", "coupons_allocation_id_seq", xx);
if (coupon_id > 0 ){
CVars inx;
inx["member_id"] = xx["member_id"]; inx["member_id"].set_valid(true);
inx["coupon_id"] = coupon_id; inx["coupon_id"].set_valid(true);
// mark status on coupon
pgsql_exec("UPDATE coupons SET active=now(), status=%lu WHERE code='%s' AND status=0",COUPON_ALLOC_STARTED,in["code"].c_str());
// send allocation email
*/
}
}
public function usercoupon(){
$data = array();
$data = $this->bkoUserDashData($_SESSION['bko_selected_id']);
+22 -22
View File
@@ -49,11 +49,14 @@
<th scope="row">Coupon Range</th>
<td><input type="number" class="form-control" id="from_coupon" aria-describedby="emailHelp" value="1000" placeholder="Amount From"></td>
<td><input type="number" class="form-control" id="to_coupon" aria-describedby="emailHelp" value="10000" placeholder="Amount To"></td>
<td><button type="submit" class="btn btn-primary">Submit</button></td>
<td><button type="submit" onclick="findCoupon(0)" class="btn btn-primary">Submit</button></td>
</tr>
</tbody>
</table>
</div>
<div id="coupon_sec">
</div>
</div>
@@ -113,42 +116,39 @@
<!-- /main content -->
<script type="text/javascript">
<!--
function resendLink(link_id) {
if (confirm("Are you sure you want to resend this link?")) {
// do something
} else {
return false;
}
$('#btu' + link_id).html('Processing...');
$('#acc' + link_id).prop('disabled', true);
function findCoupon(coupon_id) {
var from_coupon = $('#from_coupon').val();
var to_coupon = $('#to_coupon').val();
$.ajax({
url: "/bkouser/resend_pending?link_id=" + link_id
url: "/bkosmember/listcoupon?from_coupon=" + from_coupon + "&to_coupon=" +to_coupon
}).done(function (data) {
$('#btu' + link_id).html(data);
document.offer_individual.rec_email.value = '';
$('#acc' + link_id).prop('disabled', false);
$('#coupon_sec').html(data);
// document.offer_individual.rec_email.value = '';
// $('#acc' + link_id).prop('disabled', false);
});
return false;
}
function assignCoupon(coupon_id) {
function deleteLink(link_id) {
if (confirm("Are you sure you want to delete this link?")) {
if (confirm("Are you sure you want to assign this coupon ?")) {
// do something
} else {
return false;
}
$('#dtu' + link_id).html('Processing...');
$('#del' + link_id).prop('disabled', true);
$.ajax({
url: "/bkouser/delete_pending?link_id=" + link_id
url: "/bkosmember/assigncoupon?coupon_id=" + coupon_id
}).done(function (data) {
$('#dtu' + link_id).html(data);
document.offer_individual.rec_email.value = '';
$('#del' + link_id).prop('disabled', false);
$('#c_sec'+coupon_id).html(data);
// document.offer_individual.rec_email.value = '';
// $('#acc' + link_id).prop('disabled', false);
});
return false;
}
// -->
</script>