<?php

namespace App\Models;

use CodeIgniter\Model;

class FinanceModel extends Model
{
    // Mengambil total laba per periode 
    // Pastikan tabel products memiliki kolom 'harga_modal'
    public function getLabaPeriode($start, $end)
    {
        return $this->db->table('order_items oi')
            ->join('products p', 'p.id_product = oi.id_product')
            ->join('orders o', 'o.id_order = oi.id_order')
            ->where('o.tanggal_order >=', $start)
            ->where('o.tanggal_order <=', $end)
            ->selectSum('(oi.harga - p.harga_modal) * oi.qty', 'total_laba') // Pastikan 'harga' di order_items
            ->get()->getRow()->total_laba;
    }
}