<?php

namespace App\Models;

use CodeIgniter\Model;

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

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

    public function getByItemCode($kode)
    {
        return $this->where('kode', $kode)->first();
    }
    public function listticket()
    {
        return $this->select('ticket_file.*, client.client_name AS client_name')
                    ->join('client', 'client.client_key = ticket_file.client_Key', 'left') 
                    ->orderby('ticket_file.date_created', 'DESC')
                    ->findAll();

       
    }

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



 
    
}