<?php

class ModelInventoryPurchaseInvoice extends HModel {

    protected function getTable() {
        return 'inventory_purchase_invoice';
    }

    protected function getView() {
        return 'vw_inventory_purchase_invoice';
    }

    public function getSales($case_no) {
        $sql = '';
        $sql .= " SELECT si.document_date, si.document_identity, p.`name` AS partner_name, sid.total_cubic_feet AS cft, SUM(sid.base_total) as amount";
        $sql .= " FROM `inventory_sale_invoice` si";
        $sql .= " INNER JOIN `inventory_sale_invoice_detail` sid ON sid.sale_invoice_id = si.sale_invoice_id";
        $sql .= " INNER JOIN `partner` p ON p.`partner_type_id` = si.`partner_type_id` AND p.`partner_id` = si.`partner_id`";
        $sql .= " INNER JOIN `inventory_product` pr ON pr.product_id = sid.`product_id`";
        $sql .= " WHERE sid.container_no IN (";
        $sql .= " SELECT DISTINCT container_no";
        $sql .= " FROM `inventory_purchase_invoice` ipi";
        $sql .= " INNER JOIN `inventory_purchase_invoice_detail` ipid ON ipid.`purchase_invoice_id` = ipi.`purchase_invoice_id`";
        $sql .= " WHERE ipi.`manual_ref_no` = '".$case_no."'";
        $sql .= " )";
        $sql .= " GROUP BY si.document_date, si.document_identity";
        $query = $this->db->query($sql);
        return $query->rows;
    }

}

?>