mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
xml service
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
use CodeIgniter\Router\RouteCollection;
|
||||
|
||||
/**
|
||||
* @var RouteCollection $routes
|
||||
*/
|
||||
@ -638,6 +637,8 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function (
|
||||
$routes->post('getlineas', 'Pedido::getLineas', ['as' => 'tablaLineasPedido']);
|
||||
$routes->post('cambiarestado', 'Pedido::cambiarEstado', ['as' => 'cambiarEstadoPedido']);
|
||||
$routes->post('update/(:any)', 'Pedido::update/$1', ['as' => 'actualizarPedido']);
|
||||
$routes->get('xml/(:num)', 'Pedido::get_xml_pedido/$1',['as' => 'getXMLPedido']);
|
||||
|
||||
|
||||
});
|
||||
$routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']);
|
||||
|
||||
@ -5,7 +5,7 @@ use App\Controllers\BaseController;
|
||||
use App\Entities\Pedidos\PedidoEntity;
|
||||
use App\Models\Collection;
|
||||
use App\Models\Pedidos\PedidoModel;
|
||||
|
||||
use App\Services\PedidoXMLService;
|
||||
|
||||
class Pedido extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
@ -21,7 +21,6 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
|
||||
protected $indexRoute = 'pedidoList';
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
$this->viewData['pageTitle'] = lang('Pedidos.moduleTitle');
|
||||
@ -327,5 +326,13 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
$pedidoEntity->fecha_encuadernado_text = $pedidoEntity->fecha_encuadernado ? date('d/m/Y', strtotime($pedidoEntity->fecha_encuadernado)) : '';
|
||||
$pedidoEntity->fecha_entrega_externo_text = $pedidoEntity->fecha_entrega_externo ? date('d/m/Y', strtotime($pedidoEntity->fecha_entrega_externo)) : '';
|
||||
}
|
||||
public function get_xml_pedido($pedido_id)
|
||||
{
|
||||
$data_pedido = $this->model->getPedidoClientePresupuesto($pedido_id);
|
||||
$data_pedido_presupuesto = $this->model->getPedidoPresupuestoLineas($pedido_id);
|
||||
// PedidoXMLService::generate_xml($data);
|
||||
// $xml_service = new PedidoXMLService($this->model);
|
||||
return $this->respond(["pedido_presupuesto" => $data_pedido,"pedido_presupuesto_linea" => $data_pedido_presupuesto]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models\Pedidos;
|
||||
|
||||
use function PHPSTORM_META\map;
|
||||
|
||||
class PedidoModel extends \App\Models\BaseModel
|
||||
{
|
||||
protected $table = "pedidos";
|
||||
@ -85,4 +87,69 @@ class PedidoModel extends \App\Models\BaseModel
|
||||
|
||||
return $lineasPresupuesto;
|
||||
}
|
||||
public function getPedidoClientePresupuesto(int $pedido_id)
|
||||
{
|
||||
$query = $this->db->table($this->table)
|
||||
->select([
|
||||
'pedidos.id as pedidoId',
|
||||
'clientes.nombre as customerName',
|
||||
'presupuestos.total_aceptado as totalAceptado',
|
||||
'presupuestos.margen',
|
||||
'presupuestos.inc_rei',
|
||||
'presupuestos.tirada',
|
||||
'presupuestos.titulo',
|
||||
'presupuestos.paginas',
|
||||
'presupuestos.papel_formato_personalizado',
|
||||
'presupuestos.papel_formato_ancho as papelAnchoPersonalidado ',
|
||||
'presupuestos.papel_formato_alto as papelAltoPersonalidado',
|
||||
'lg_papel_formato.ancho as lgPapelFormatoAncho ',
|
||||
'lg_papel_formato.alto as lgPapelFormatoAlto',
|
||||
'lg_tarifa_acabado.nombre as lgTarifaAcabadoNombre',
|
||||
])
|
||||
->join('pedidos_linea','pedidos_linea.id = pedidos.id','left')
|
||||
->join('presupuestos','presupuestos.id = pedidos_linea.presupuesto_id','left')
|
||||
// ->join('presupuesto_linea','presupuestos.id = presupuesto_linea.presupuesto_id','left')
|
||||
->join('clientes','clientes.id = presupuestos.cliente_id','left')
|
||||
->join('lg_papel_formato','lg_papel_formato.id = presupuestos.papel_formato_id','left')
|
||||
->join('lg_tarifa_acabado','lg_tarifa_acabado.id = presupuestos.acabado_cubierta_id','left')
|
||||
|
||||
->where('pedidos.id',$pedido_id);
|
||||
$cliente_presupuesto = $query->get()->getFirstRow();
|
||||
return $cliente_presupuesto;
|
||||
}
|
||||
public function getPedidoPresupuestoLineas(int $pedido_id)
|
||||
{
|
||||
$query = $this->db->table($this->table)
|
||||
->select([
|
||||
'presupuesto_linea.*',
|
||||
'lg_papel_generico.code as papelCode',
|
||||
|
||||
])
|
||||
->join('pedidos_linea','pedidos_linea.id = pedidos.id','left')
|
||||
->join('presupuestos','presupuestos.id = pedidos_linea.presupuesto_id','left')
|
||||
->join('presupuesto_linea','presupuestos.id = presupuesto_linea.presupuesto_id','left')
|
||||
->join('lg_papel_generico','lg_papel_generico.id = presupuesto_linea.papel_id','left')
|
||||
|
||||
|
||||
->where('pedidos.id',$pedido_id);
|
||||
$pedido_presupuesto_lineas = $query->get()->getResultObject();
|
||||
return $pedido_presupuesto_lineas;
|
||||
}
|
||||
public function getPedidoClienteDirecciones($pedido_id){
|
||||
$query = $this->db->table($this->table)
|
||||
->select([
|
||||
'pedidos.id as pedidoId',
|
||||
'clientes.nombre as customerName',
|
||||
'cliente_direcciones.*',
|
||||
'lg_paises.code3'
|
||||
])
|
||||
->join('pedidos_linea','pedidos_linea.id = pedidos.id','left')
|
||||
->join('presupuestos','presupuestos.id = pedidos_linea.presupuesto_id','left')
|
||||
->join('clientes','clientes.id = presupuestos.cliente_id','left')
|
||||
->join('cliente_direcciones','clientes.id = cliente_direcciones.cliente_id','left')
|
||||
->join('lg_paises','lg_paises.id = cliente_direcciones.pais_id','left')
|
||||
->where('pedidos.id',$pedido_id);
|
||||
$pedido_cliente_direcciones = $query->get()->getResultObject();
|
||||
return $pedido_cliente_direcciones;
|
||||
}
|
||||
}
|
||||
@ -1,16 +1,130 @@
|
||||
<?php
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Entities\Pedidos\PedidoEntity;
|
||||
use CodeIgniter\Config\BaseService;
|
||||
use App\Models\Pedidos\PedidoModel;
|
||||
use App\Models\Pedidos\PedidoLineaModel;
|
||||
use \DOMDocument;
|
||||
use DOMDocument;
|
||||
use DOMNode;
|
||||
|
||||
class PedidoXMLService extends BaseService
|
||||
{
|
||||
public PedidoModel $pedido;
|
||||
public function __construct(PedidoModel $pedido) {
|
||||
$this->pedido = $pedido;
|
||||
|
||||
public static function generate_xml($data)
|
||||
{
|
||||
$papel_formato_ancho = 0;
|
||||
$papel_formato_alto = 0;
|
||||
$xml = new DOMDocument('1.0', 'utf-8');
|
||||
$xml_order_el = $xml->createElement('Order');
|
||||
$xml_header_el = $xml->createElement('Header');
|
||||
$xml_header_el->appendChild($xml->createElement('CustomerCode', 988));
|
||||
$xml_header_el->appendChild($xml->createElement('CodeNode', "false"));
|
||||
$xml_header_el->appendChild($xml->createElement('ExternId', $data->pedido_presupuesto->pedidoId));
|
||||
$xml_header_el->appendChild($xml->createElement('NumProducts', 988));
|
||||
$xml_header_el->appendChild($xml->createElement('Date', now_db()));
|
||||
$xml_order_el->appendChild($xml_header_el);
|
||||
$xml_products_el = $xml->createElement('Products');
|
||||
$xml_products_el->appendChild($xml->createElement('ItemId', $data->pedido_presupuesto->pedidoId));
|
||||
$xml_products_el->appendChild($xml->createElement('Quantity', $data->pedido_presupuesto->tirada));
|
||||
$xml_products_el->appendChild($xml->createElement('Title', $data->pedido_presupuesto->titulo));
|
||||
$xml_products_el->appendChild($xml->createElement('Pages', $data->pedido_presupuesto->paginas));
|
||||
$xml_products_el->appendChild($xml->createElement('Reprint', $data->pedido_presupuesto->inc_rei));
|
||||
|
||||
if ($data->pedido_presupuesto->papel_formato_personalizado) {
|
||||
$papel_formato_ancho = $data->pedido_presupuesto->papelAnchoPersonalidado;
|
||||
$papel_formato_alto = $data->pedido_presupuesto->papelAltoPersonalidado;
|
||||
} else {
|
||||
$papel_formato_ancho = $data->pedido_presupuesto->lgPapelFormatoAncho;
|
||||
$papel_formato_alto = $data->pedido_presupuesto->lgPapelFormatoAlto;
|
||||
}
|
||||
$xml_products_el->appendChild($xml->createElement('Width', $papel_formato_ancho));
|
||||
$xml_products_el->appendChild($xml->createElement('Height', $papel_formato_alto));
|
||||
$presupuestoLineaTipoCubierta = null;
|
||||
$xml_presupuesto_lineas_el = $xml->createElement('Lines');
|
||||
## Iterate throught presupuesto_lineas
|
||||
foreach ($data->pedido_presupuesto_lineas as $row) {
|
||||
if (str_contains($row->tipo, "rot") || str_contains($row->tipo, "bn") || str_contains($row->tipo, "color")) {
|
||||
$colorInterior = PedidoXMLService::get_color_interior($row);
|
||||
$xmlInside = $xml->createElement('Inside');
|
||||
$xmlInside->appendChild($xml->createElement('TypeOfPrint', $colorInterior));
|
||||
$xmlInside->appendChild($xml->createElement('HQ', str_contains($row->tipo, 'hq') ? 1 : 0));
|
||||
$xmlInside->appendChild($xml->createElement('Pages', $row->paginas));
|
||||
$xmlInside->appendChild($xml->createElement('Paper', $row->papelCode));
|
||||
$xmlInside->appendChild($xml->createElement('Weight', $row->gramaje));
|
||||
$xml_presupuesto_lineas_el->appendChild($xmlInside);
|
||||
} else if (str_contains($row->tipo, "cubierta") || str_contains($row->tipo, "sobrecubierta")) {
|
||||
$papelCubiertaCode = $row->papelCode;
|
||||
$papelCubiertaGramaje = $row->gramaje;
|
||||
$presupuestoLineaTipoCubierta = $row->tipo == "lp_cubierta" ? $row : null;
|
||||
}
|
||||
}
|
||||
|
||||
$xml_products_el->appendChild($xml_presupuesto_lineas_el);
|
||||
if ($presupuestoLineaTipoCubierta) {
|
||||
$lgTarifaAcabadoNombre = $data->pedido_presupuesto->lgTarifaAcabadoNombre;
|
||||
if(str_contains('brillo',$lgTarifaAcabadoNombre)){
|
||||
$acabado = "brillo";
|
||||
}else{
|
||||
$acabado = "mate";
|
||||
}
|
||||
$xmlCover = $xml->createElement('Cover');
|
||||
$xmlCover->appendChild($xml->createElement('Sides', $presupuestoLineaTipoCubierta->paginas)); //! PAGINAS CUBIERTA
|
||||
$xmlCover->appendChild($xml->createElement('Paper', $presupuestoLineaTipoCubierta->papelCode)); //?
|
||||
$xmlCover->appendChild($xml->createElement('Weight', $presupuestoLineaTipoCubierta->gramaje));
|
||||
$xmlCover->appendChild($xml->createElement('Flaps', $data->pedido_presupuesto->solapas));
|
||||
$xmlCover->appendChild($xml->createElement('WidthFlaps', $data->pedido_presupuesto->solapas_ancho));
|
||||
$xmlCover->appendChild($xml->createElement('Finish', $acabado));
|
||||
$xml_products_el->appendChild($xmlCover);
|
||||
}
|
||||
$xml_services_el = $xml->createElement('Services');
|
||||
$xml_services_el->appendChild($xml->createElement('Bookmark', $data->pedido_presupuesto->marcapaginas));
|
||||
$xml_services_el->appendChild($xml->createElement('ShrinkWrapping', $data->pedido_presupuesto->retractilado));
|
||||
//? $xml_services_el->appendChild($xml->createElement('PlakeneT', $data->pedido_presupuesto->plakeneT));
|
||||
$xml_services_el->appendChild($xml->createElement('Urgent', $data->pedido_presupuesto->urgent));
|
||||
$xml_services_el->appendChild($xml->createElement('Prototype', $data->pedido_presupuesto->prototipo));
|
||||
$xml_services_el->appendChild($xml->createElement('Layout', $data->pedido_presupuesto->maquetacion));
|
||||
$xml_services_el->appendChild($xml->createElement('Correction', $data->pedido_presupuesto->correccion));
|
||||
$xml_services_el->appendChild($xml->createElement('Review', $data->pedido_presupuesto->revision));
|
||||
$xml_services_el->appendChild($xml->createElement('Design', $data->pedido_presupuesto->diseno));
|
||||
$xml_products_el->appendChild($xml_services_el);
|
||||
|
||||
$xml_envios_el = $xml->createElement('Shipments');
|
||||
foreach ($data->pedido_cliente_direcciones as $pedido_cliente_direccion) {
|
||||
$xml_envio_el = $xml->createElement('Shipment');
|
||||
//! Tirada o cantidad de envios?
|
||||
$xml_envio_el->appendChild($xml->createElement('Qty', $data->pedido_presupuesto->tirada));
|
||||
//! Precio del presupuesto o del envio?
|
||||
$xml_envio_el->appendChild($xml->createElement('Price', $data->pedido_presupuesto->total_aceptado));
|
||||
$xml_envio_el->appendChild($xml->createElement('Attention', $pedido_cliente_direccion->att));
|
||||
$xml_envio_el->appendChild($xml->createElement('Email', $pedido_cliente_direccion->email));
|
||||
$xml_envio_el->appendChild($xml->createElement('Address', $pedido_cliente_direccion->direccion));
|
||||
$xml_envio_el->appendChild($xml->createElement('Province', $pedido_cliente_direccion->provincia));
|
||||
$xml_envio_el->appendChild($xml->createElement('City', $pedido_cliente_direccion->ciudad));
|
||||
$xml_envio_el->appendChild($xml->createElement('Zip', $pedido_cliente_direccion->cp));
|
||||
$xml_envio_el->appendChild($xml->createElement('CountryCode', $pedido_cliente_direccion->code3));
|
||||
$xml_envio_el->appendChild($xml->createElement('Telephone', $pedido_cliente_direccion->telefono));
|
||||
$xml_envios_el->appendChild($xml_envio_el);
|
||||
|
||||
}
|
||||
$xml_products_el->appendChild($xml_envios_el);
|
||||
$xml_products_el->appendChild($xml->createElement('Comments', $data->pedido_presupuesto->comentarios_safekat));
|
||||
$xml_products_el->appendChild($xml->createElement('CommentsClient', $data->pedido_presupuesto->comentarios_cliente));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
protected static function get_color_interior($pre_linea): ?string
|
||||
{
|
||||
$color_interior = null;
|
||||
$bn_tipo_array = ['lp_bn', 'lp_bnhq', 'lp_rot_bn'];
|
||||
$color_tipo_array = ['lp_color', 'lp_color_hq', 'lp_rot_color'];
|
||||
|
||||
if (in_array($pre_linea->tipo, $bn_tipo_array)) {
|
||||
$color_interior = "bn";
|
||||
};
|
||||
if (in_array($pre_linea->tipo, $color_tipo_array)) {
|
||||
$color_interior = "color";
|
||||
};
|
||||
return $color_interior;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user