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) { + map