<?php namespace App\Models;
/**
 * File			: AntrianModel.php
 * Description  : Model untuk halaman antrian
 * Created By	: Hendi
 * Created Date : 16 Maret 2021
 * Last Update  : 16 Maret 2021
**/
use CodeIgniter\Model;
 
class AntrianModel extends Model
{
    protected $table = 'antrian';
	protected $primaryKey = 'antrian_id';
    protected $allowedFields = ['tanggal', 'no_antrian', 'menu_id', 'qty', 'start', 'finish', 'status', 'user_id', 'created_at', 'updated_at', 'deleted_at'];
	# bukan hapus data permanen tapi saat call method delete hanya ngisi deleted_at saja
	protected $useSoftDeletes = true;
	# field created_at, updated_at, deleted_at akan diisi otomatis saat call method insert, update, delete
	protected $useTimestamps = true;
	protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';
    protected $deletedField  = 'deleted_at';
	
	# fungsi untuk cek no antrian
	public function cekNoAntrian($post = []) {
		$sql = "
				select count(no_antrian) as jumlah from antrian
				where DATE_FORMAT(tanggal, '%Y-%m-%d') = '".substr($post['tanggal'], 0, 10)."'
				and no_antrian = ".$post['no_antrian']." and menu_id = '".$post['menu_id']."'
			   ";
		return $this->db->query($sql)->getRow()->jumlah;
	}
}
