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

class Produk_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)
    {
        if(empty($id_cust)) $id_cust=0;
        if(empty($id_club)) $id_club=0;
        if(empty($page)) $page=0;
        if(empty($limit)) $limit=10;

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

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

            $data [] = array(
                'trx' => $row,
                'detail' => $query2
            );

            // $data = $row;
            // $data['detail'] = $query2;
        }


        return $data;
    }


}
