<?php

namespace App\Models;

use CodeIgniter\Model;

class PolaModel extends Model
{
    protected $table = 'ticket_item';
    protected $primaryKey = 'id'; // Assuming your primary key field name is 'id'

    protected $allowedFields = ['id', 'kode', 'item_code',  'client_key', 'reference_id', 'image_url', 'description', 'width', 'length', 'qty', 'subtotal','date_created', 'claim',  'status_id'];

    public function getByItemCode($kode)
    {
        return $this->where('kode', $kode)->first();
    }

    public function getItemby($id)
    {
        if ($id) {
            return $this->select('ticket_item.*, orders_item.details AS details') // Pilih semua kolom dari ticket_item dan nama dari orders_item
                        ->join('orders_item', 'orders_item.item_code = ticket_item.item_code', 'left') // Join dengan orders_item berdasarkan item_code
                        ->where('ticket_item.reference_id', $id)
                        ->findAll();
        } else {
            return $this->select('ticket_item.*, orders_item.details AS details')
                        ->join('orders_item', 'orders_item.item_code = ticket_item.item_code', 'left')
                        ->orderBy('ticket_item.reference_id', 'DESC')
                        ->findAll();
        }
    }


 
    
}