<?php

namespace App\Modelos;

use Core\Database;

class CmpPedidosArticulos extends Database
{
    protected $table = 'app_cmppedidos_articulos';
    protected $id = 'cmppeart_id';

    public function articulos($id_factura)
    {
        return $this->consultar("SELECT * FROM app_cmppedidos_articulos WHERE cmppeart_peid=$id_factura")->all();
    }

    public function eliminarArticulos($id_factura)
    {
        return $this->consultar("DELETE FROM app_cmppedidos_articulos WHERE cmppeart_peid=$id_factura")->run();
    }

    public function eliminarArticulo($id_factura, $id_producto)
    {
        return $this->consultar("DELETE FROM app_cmppedidos_articulos WHERE cmppeart_peid=$id_factura AND cmppeart_proid=$id_producto")->run();
    }

    public function obtenerDetalleProductoFacturado($id_factura, $id_producto, $id_alamcen)
    {
        return $this->consultar("SELECT * FROM app_cmppedidos_articulos WHERE cmppeart_peid=$id_factura AND (cmppeart_proid=$id_producto AND cmppeart_almid=$id_alamcen)")->row();
    }
}
