Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/mesinpolesshinemate.com/application/models/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Voucher_m extends MY_Model { protected $_table_name = 'vouchers'; protected $_primary_key = 'id_vouchers'; protected $_order_by = 'id_vouchers'; public $rules = array( array( 'field' => 'voucher_name', 'label' => 'Voucher Name', 'rules' => 'trim|required' ), array( 'field' => 'voucher_code', 'label' => 'Voucher code', 'rules' => 'trim|required|callback__cek_existing_voucher_code' ), array( 'field' => 'qty_ready', 'label' => 'Quantity Available', 'rules' => 'trim|numeric' ), array( 'field' => 'maxqty_per_person', 'label' => 'Max Quantity per person', 'rules' => 'trim|numeric' ), array( 'field' => 'min_order', 'label' => 'min_order', 'rules' => 'trim|numeric' ), array( 'field' => 'discount_value', 'label' => 'discount value', 'rules' => 'trim|required|numeric' ), array( 'field' => 'expired_date', 'label' => 'expired date', 'rules' => 'trim' ), ); function __construct() { parent::__construct(); } //pagination included function get_all_vouchers($limit, $start) { $this->db->select('*'); $this->db->from('vouchers'); $this->db->order_by('created_date', 'DESC'); $this->db->limit($limit, $start); $query = $this->db->get(); return $query->result(); } //function to display new voucher, where all fields are empty public function get_new() { $vouchers = new stdClass(); $vouchers->voucher_name = ''; $vouchers->voucher_code = ''; $vouchers->display_at_checkout = ''; $vouchers->qty_ready = ''; $vouchers->maxqty_per_person = ''; $vouchers->min_order = ''; $vouchers->discount_type = ''; $vouchers->discount_value = ''; $vouchers->expired_date = ''; $vouchers->voucher_type = ''; $vouchers->birthmonth = ''; $vouchers->gender = ''; $vouchers->promostart = ''; $vouchers->promoend = ''; $vouchers->quantitypromo = ''; $vouchers->provincepromo = ''; return $vouchers; } //get all vouchers function get_vouchers() { $this->db->select('*'); $this->db->from('vouchers'); $this->db->order_by('id_vouchers asc'); $query = $this->db->get(); return $query->result(); } //function add new voucher function add_voucher($data) { $this->db->insert('vouchers', $data); return $this->db->insert_id(); } //function edit voucher function edit_voucher($id, $data) { $this->db->where('id_vouchers', $id); $this->db->update('vouchers', $data); } //function count all record for voucher public function record_count() { return $this->db->get('vouchers')->num_rows(); } //function count if existing record exist public function count_exist($id) { $this->db->select('*'); $this->db->from('vouchers'); $this->db->where('id_vouchers', $id); $query = $this->db->get(); return $query->num_rows(); } //FOR FRONT END REGISTRATION PAGE //get all vouchers to display at front registration page, with status display 1 only function get_vouchers_display_on() { $this->db->select('*'); $this->db->from('vouchers'); $this->db->where('status', '1'); $this->db->where('id_vouchers !=', '0'); $this->db->order_by('id_vouchers asc'); $query = $this->db->get(); return $query->result(); } //cek if voucher title already exist public function cek_existing_voucher_code($str, $voucher_id) { $this->db->select('id_vouchers'); $this->db->from('vouchers'); $this->db->where('voucher_code', $str); if ($voucher_id != NULL) { $this->db->where('id_vouchers !=', $voucher_id); } $query = $this->db->get(); return $query->num_rows(); } }