Files
safekat/ci4/app/Models/Pedidos/PedidoModel.php
jaimejimenezortega c9d8875392 trabajando en pedidos 3
2024-06-13 23:53:20 +02:00

88 lines
2.5 KiB
PHP

<?php
namespace App\Models\Pedidos;
class PedidoModel extends \App\Models\BaseModel
{
protected $table = "pedidos";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
const SORTABLE_TODOS = [
0 => "t1.id",
1 => "t1.updated_at",
2 => "t1.fecha_entrega_real",
3 => "t4.nombre",
4 => "t5.first_name",
5 => "t3.titulo",
6 => "t6.ubicacion",
7 => "t3.inc_rei",
8 => "t3.paginas",
9 => "t3.tirada",
10 => "t3.total_aceptado",
11 => "t1.estado"
];
protected $allowedFields = [
"total_precio",
"total_tirada",
"estado",
"user_created_id",
"user_updated_id",
"user_validated_id",
"fecha_entrega_real",
"fecha_impresion",
"fecha_encuadernado",
"fecha_entrega_externo",
"created_at",
"updated_at",
"validated_at",
];
protected $returnType = "App\Entities\Pedidos\PedidoEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $createdField = "created_at";
protected $updatedField = "updated_at";
public static $labelField = "id";
public function obtenerDatosForm($pedido_id){
$builder = $this->db
->table($this->table . " t1")
->select(
"t4.id AS cliente_id, t4.nombre AS cliente, CONCAT(t5.first_name, ' ', t5.last_name) AS comercial");
$builder->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left");
$builder->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left");
$builder->join("clientes t4", "t4.id = t3.cliente_id", "left");
$builder->join("users t5", "t5.id = t4.comercial_id", "left");
return $builder->get()->getResultObject();
}
public function obtenerLineasPedido($pedido_id){
$builder = $this->db
->table($this->table . " t1")
->select(
"t2.presupuesto_id"
);
$builder->where("t1.id", $pedido_id);
$builder->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left");
$model_presupuesto = model("App\Models\Presupuestos\PresupuestoModel");
$lineasPresupuesto = [];
foreach($builder->get()->getResultObject() as $row){
array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]);
}
return $lineasPresupuesto;
}
}