mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
129 lines
8.0 KiB
PHP
129 lines
8.0 KiB
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 DOMNode;
|
|
|
|
class PedidoXMLService extends BaseService
|
|
{
|
|
|
|
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 / 2)); //! 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));
|
|
//? Retractilado5 y Retractilado o ambas
|
|
//! MIRAR
|
|
$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)); PEDIDO URGENTE
|
|
$xml_services_el->appendChild($xml->createElement('Prototype', $data->pedido_presupuesto->prototipo)); //
|
|
//? $xml_services_el->appendChild($xml->createElement('Layout', $data->pedido_presupuesto->maquetacion)); , MAQUETACION
|
|
//? $xml_services_el->appendChild($xml->createElement('Correction', $data->pedido_presupuesto->correccion)); CORRECCION ORTOGRAFICA
|
|
//? $xml_services_el->appendChild($xml->createElement('Review', $data->pedido_presupuesto->revision)); REVISION ??
|
|
//? $xml_services_el->appendChild($xml->createElement('Design', $data->pedido_presupuesto->diseno)); DISEÑO DE CUBIERTA
|
|
$xml_products_el->appendChild($xml_services_el);
|
|
|
|
$xml_envios_el = $xml->createElement('Shipments');
|
|
foreach ($data->pedido_presupuesto_direcciones as $pedido_presupuesto_direccion) {
|
|
$xml_envio_el = $xml->createElement('Shipment');
|
|
$xml_envio_el->appendChild($xml->createElement('Qty', $pedido_presupuesto_direccion->cantidad));
|
|
$xml_envio_el->appendChild($xml->createElement('Price', $data->pedido_presupuesto_direccion->precio));
|
|
$xml_envio_el->appendChild($xml->createElement('Attention', $pedido_presupuesto_direccion->att));
|
|
$xml_envio_el->appendChild($xml->createElement('Email', $pedido_presupuesto_direccion->email));
|
|
$xml_envio_el->appendChild($xml->createElement('Address', $pedido_presupuesto_direccion->direccion));
|
|
$xml_envio_el->appendChild($xml->createElement('Province', $pedido_presupuesto_direccion->provincia));
|
|
$xml_envio_el->appendChild($xml->createElement('City', $pedido_presupuesto_direccion->ciudad));
|
|
$xml_envio_el->appendChild($xml->createElement('Zip', $pedido_presupuesto_direccion->cp));
|
|
$xml_envio_el->appendChild($xml->createElement('CountryCode', $pedido_presupuesto_direccion->code3));
|
|
$xml_envio_el->appendChild($xml->createElement('Telephone', $pedido_presupuesto_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;
|
|
}
|
|
}
|