<?php



namespace App\Models;



use CodeIgniter\Model;



class PaymentRecordsModel extends Model

{

    protected $table = 'payment_records';

    protected $primaryKey = 'id'; // Assuming your primary key field name is 'id'

    protected $allowedFields = ['transaction_code', 'client_key', 'bill_no', 'customer_name', 'tanggal_order', 'net_amount', 'date_created', 'paid_status', 'payment_code']; // Add other fields as needed
    public function sumNetAmountByBillNo($billNo)
    {
        $query = $this->selectSum('net_amount')
                      ->where('bill_no', $billNo)
                      ->first();

        return $query['net_amount'] ?? 0;
    }

    public function getItemby($kode)
    {

            if ($kode) {
                return $this->where('bill_no', $kode)
                ->findAll();
            } else {
                return $this->orderBy('bill_no', 'DESC')->findAll();
            }

    }
}

