<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Minum_model extends CI_Model {

    /**
     * CONSTRUCTOR | LOAD DB
    */
    public function __construct() {
     parent::__construct();
     $this->load->database();
 }

    /**
     * SHOW | GET method.
     *
     * @return Response
    */
    public function show($id_cust = 0,$id_club = 0, $page = 0, $limit = 10, $id_vip = 0)
    {
        if(empty($id_cust)) $id_cust=0;
        if(empty($id_club)) $id_club=0;
        if(empty($page)) $page=0;
        if(empty($limit)) $limit=10;

        $filter_vip = "";
        if ($id_vip) {
            $filter_vip = " and id_vip='".$id_vip."' ";
        }
        $offset = ($page-1)*$limit;
        $sql = "SELECT * ".
            " FROM `transaksi` ".
            " where id_customer='".$id_cust."' and id_club='".$id_club."' and terhapus=0 ".$filter_vip.
            " order by id DESC limit ".$offset.",".$limit;      
        $query = $this->db->query($sql);

        $data = array();
        foreach ($query->result() as $row) {
            $sql2 = "SELECT * FROM `transaksi_detail` ".
                " where id_transaksi='".$row->id."' and id_club='".$row->id_club."' ".
                " order by id ASC ";        
            $query2 = $this->db->query($sql2)->result();
            
            $final['status'] = true;
            $final['message'] = 'Data confirmed';
            $data [] = array(
                'trx' => $row,
                'detail' => $query2
            );
        }

        return $data;
    }


}
