You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
6.2 KiB
169 lines
6.2 KiB
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class Event_payment_model extends CI_Model {
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->db->query("SET @@group_concat_max_len =30000");
|
|
}
|
|
|
|
public function getActiveEventsPayment($where = [], $joinEvent = true) {
|
|
$this->load->helper('number');
|
|
$result = $joinEvent === true
|
|
? $this->db
|
|
->select("*")
|
|
->select('FORMAT(((ep.total_amount / ep.seats_reserved) * er.number_of_guest), 2) as g_total')
|
|
->from('event_payment as ep')
|
|
->join('event as e', 'e.event_id = ep.event_id')
|
|
->join('event_registration as er', 'er.registration_id = ep.registration_id AND er.status=1')
|
|
->join('event_file_attachment as efa', 'e.event_id = efa.event_id')
|
|
->where($where)
|
|
->where([
|
|
'efa.status' => '1',
|
|
'efa.display' => '0',
|
|
'er.is_expired' => '1'
|
|
])
|
|
->where("DATEDIFF(e.end_date_time, now())>=", 0)
|
|
->or_where('er.registration_type', 'soir-distance')
|
|
->or_where('er.workshop_session', 'DISTANCE')
|
|
// Exclude deleted events
|
|
->where_not_in('e.back_office_status', [
|
|
BO_STAT['del'],
|
|
])
|
|
->group_by('ep.id')
|
|
->get()
|
|
: $this->db
|
|
->where($where)
|
|
->get('event_payment');
|
|
|
|
return $result->result();
|
|
}
|
|
|
|
public function getPastEventsPayment($where = [], $joinEvent = true) {
|
|
$this->load->helper('number');
|
|
$result = $joinEvent === true
|
|
? $this->db
|
|
->select("*")
|
|
->select('FORMAT(((ep.total_amount / ep.seats_reserved) * er.number_of_guest), 2) as g_total')
|
|
->from('event_payment as ep')
|
|
->join('event as e', 'e.event_id = ep.event_id')
|
|
->join('event_registration as er', 'er.registration_id = ep.registration_id AND er.status=1')
|
|
->join('event_file_attachment as efa', 'e.event_id = efa.event_id')
|
|
->where($where)
|
|
->where([
|
|
'efa.status' => '1',
|
|
'efa.display' => '0',
|
|
])
|
|
//->where("DATEDIFF(e.end_date_time, now())<", 0)
|
|
->or_where('er.is_expired', 0)
|
|
// Exclude deleted events
|
|
->where_not_in('e.back_office_status', [
|
|
BO_STAT['del'],
|
|
])
|
|
->group_by('ep.id')
|
|
->get()
|
|
: $this->db
|
|
->where($where)
|
|
->get('event_payment');
|
|
|
|
return $result->result();
|
|
}
|
|
|
|
public function add($data) {
|
|
if(sizeof($data) > 0){
|
|
$this->db->insert("event_payment", $data);
|
|
$event_id = $this->db->insert_id();
|
|
if($event_id){
|
|
return $event_id;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
public function get_tax_rate() {
|
|
$this->db->select("*");
|
|
$this->db->from("event_payment_tax_rate");
|
|
$this->db->where("status ", 1);
|
|
$this->db->limit(1);
|
|
return $this->db->get()->row();
|
|
}
|
|
public function update($id, $data) {
|
|
if(sizeof($data)){
|
|
$this->db->where("id", $id);
|
|
$update = $this->db->update("event_payment", $data);
|
|
if($update){
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function delete($id) {
|
|
return $this->db->delete('event_payment', ['id' => $id]);
|
|
}
|
|
|
|
public function hasUserAlreadyPaidEvent($userId, $eventId) {
|
|
$result = $this->db->where([
|
|
'user_id' => $userId,
|
|
'event_id' => $eventId,
|
|
])->get('event_payment');
|
|
|
|
return $result->num_rows() > 0;
|
|
}
|
|
|
|
public function update_payment($user_id, $event_id, $date, $registration_id) {
|
|
// $this->db->set('registration_id', $registration_id);
|
|
// AND TIMESTAMPDIFF(YEAR, e.date, ?)=0
|
|
// AND TIMESTAMPDIFF(MONTH, e.date, ?)=0
|
|
// AND TIMESTAMPDIFF(DAY, e.date, ?)=0
|
|
// AND TIMESTAMPDIFF(MINUTE, e.date, ?)= 0
|
|
// AND TIMESTAMPDIFF(SECOND, e.date, ?)>=-1
|
|
// AND TIMESTAMPDIFF(SECOND, e.date, ?)<=2
|
|
$query = $this->db->query("
|
|
SELECT e.id, e.date
|
|
FROM event_payment e
|
|
WHERE e.user_id = ?
|
|
AND e.event_id = ?
|
|
", array($user_id, $event_id));
|
|
$payments = $query->result();
|
|
$results = array();
|
|
if($payments) {
|
|
foreach($payments as $row) {
|
|
$dt1 = new DateTime(date('Y-m-d H:i:s',strtotime($row->date)));
|
|
$dt2 = new DateTime(date('Y-m-d H:i:s',strtotime($date)));
|
|
$dt = $dt1->diff($dt2);
|
|
if($dt->y == 0 && $dt->m == 0 && $dt->d == 0 && ($dt->i >= -1 && $dt->i <= 1) && ($dt->s >= -1 && $dt->s <= 4)) {
|
|
array_push($results, ['id'=> $row->id,'second' =>$dt->s]);
|
|
$this->db->set('registration_id', $registration_id);
|
|
$this->db->set('date', $date);
|
|
$this->db->where('id', $row->id);
|
|
$this->db->update('event_payment');
|
|
}
|
|
}
|
|
return $results;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function add_payment_created_at($user_id, $event_id, $registration_id, $created_at) {
|
|
$query = $this->db->query("
|
|
SELECT e.id, e.date
|
|
FROM event_payment e
|
|
WHERE e.user_id = ?
|
|
AND e.event_id = ?
|
|
AND e.registration_id = ?
|
|
", array($user_id, $event_id, $registration_id));
|
|
$payments = $query->result();
|
|
$results = array();
|
|
if($payments) {
|
|
foreach($payments as $row) {
|
|
array_push($results, (array) $row);
|
|
$this->db->set('date', $created_at);
|
|
$this->db->where('id', $row->id);
|
|
$this->db->update('event_payment');
|
|
}
|
|
return $results;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|