Files
safekat/ci4/app/Models/Presupuestos/ImportadorModel.php

98 lines
3.6 KiB
PHP

<?php
namespace App\Models\Presupuestos;
class ImportadorModel extends \App\Models\BaseModel
{
protected $table = 'pedido_libro';
protected $primaryKey = 'id';
protected $DBGroup = 'old_erp';
public function getClientList(){
$db = \Config\Database::connect($this->DBGroup); // Conectar a olderp
$builder = $db->table('customers');
$builder->select('id, name');
$builder->where('deleted_at', NULL);
$query = $builder->get();
return $query->getResultObject();
}
public function getPresupuestosList($clienteId, $search = ""){
$db = \Config\Database::connect($this->DBGroup); // Conectar a olderp
$builder = $db->table('pedido_libro');
$builder->select('id as id, CONCAT(id, " - ", titulo) as name');
$builder->where('customer_id', $clienteId);
$builder->whereIn('estado', ['finalizado', 'validado']);
$builder->where('deleted_at', NULL);
$builder->orderBy('updated_at', 'DESC');
return empty($search) ?
$builder->get()->getResultObject() :
$builder->groupStart()->
like('titulo', $search)->
orLike('id', $search)->
groupEnd()->get()->getResultObject();
}
public function getPresupuestoForImport($id){
$db = \Config\Database::connect($this->DBGroup); // Conectar a olderp
$builder = $db->table('pedido_libro t1')
->select('t1.paginas, t1.tirada, t1.papel_formato_personalizado,
t1.papel_formato_ancho as papel_formato_personalizado_ancho,
t1.papel_formato_alto as papel_formato_personalizado_alto,
t2.ancho as papel_formato_ancho, t2.alto as papel_formato_alto,
t1.ferro as ferro,t1.ferro_digital as ferro_digital, t1.marcapaginas as marcapaginas')
->join('papel_formato t2', 't1.papel_formato_id = t2.id', 'left')
->where('t1.id', $id)
->where('t1.deleted_at', NULL);
$query = $builder->get();
$datosGenerales = $query->getRow();
$builder = $db->table('pedido_libro_manipulado')
->select('nombre')
->where('pedido_libro_id', $id);
$query = $builder->get();
$manipulados = $query->getResultObject();
$builder = $db->table('pedido_libro_acabado')
->select('nombre')
->where('pedido_libro_id', $id);
$query = $builder->get();
$acabados = $query->getResultObject();
$builder = $db->table('pedido_libro_preimpresion')
->select('nombre')
->where('pedido_libro_id', $id)
->where('nombre', 'Prototipo');
$query = $builder->countAllResults();
if($query > 0){
$datosGenerales->prototipo = 1;
}
$builder = $db->table('pedido_libro_linea t1')
->select('t1.tipo as tipo, t1.hq as hq, t1.paginas as paginas, t1.papel_id as papel_id,
t2.nombre as papel_nombre, t2.code as papel_code, t1.gramaje as gramaje, t1.rotativa_pag_color as rotativa_pag_color,
t1.rotativa_impresion as rotativa_impresion, t1.solapas_ancho as solapas_ancho')
->join('papel_generico t2', 't1.papel_id = t2.id', 'left')
->where('pedido_libro_id', $id);
$query = $builder->get();
$lineas = $query->getResultObject();
return [
'datosGenerales' => $datosGenerales,
'manipulados' => $manipulados,
'acabados' => $acabados,
'lineas' => $lineas
];
}
}