diff --git a/application/config/constants.php b/application/config/constants.php index 16860c8..527b5a1 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -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); + diff --git a/application/controllers/Bkosmember.php b/application/controllers/Bkosmember.php index 1023f59..e68a258 100644 --- a/application/controllers/Bkosmember.php +++ b/application/controllers/Bkosmember.php @@ -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 , + '
' 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) { + mapf = 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']); diff --git a/application/views/bko/view_bko_usercoupon.php b/application/views/bko/view_bko_usercoupon.php index 60ab27d..16cef91 100644 --- a/application/views/bko/view_bko_usercoupon.php +++ b/application/views/bko/view_bko_usercoupon.php @@ -49,11 +49,14 @@ Coupon Range - + +
+ +
@@ -113,42 +116,39 @@ \ No newline at end of file