feat: generateXML finished

This commit is contained in:
amazuecos
2024-09-02 23:33:05 +02:00
parent 6e41e73997
commit fe4fdb8607

View File

@ -23,6 +23,7 @@ class PedidoXMLService extends BaseService
$data_xml['servicios'] = $servicios;
$data_xml['preimpresion'] = PedidoXMLService::parse_servicio_preimpresion($servicios['preimpresion']);
$data_xml["acabado"] = PedidoXMLService::parse_servicio_acabado($servicios['acabado']);
$data_xml["binding"] = PedidoXMLService::get_binding_code($data_xml['pedido_cliente_presupuesto']->codigoTipoImpresion,$data_xml['pedido_cliente_presupuesto']->solapas);
return $data_xml;
}
@ -76,18 +77,20 @@ class PedidoXMLService extends BaseService
$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_cliente_presupuesto"]->pedidoId));
$xml_header_el->appendChild($xml->createElement('NumProducts', 988));
$offset_pedido_id = env('XML_OFFSET_CUSTOMER_ID',1000000) + $data["pedido_cliente_presupuesto"]->pedidoId;
$xml_header_el->appendChild($xml->createElement('CustomerCode', $data["pedido_cliente_presupuesto"]->presupuestoClienteId));
$xml_header_el->appendChild($xml->createElement('CodeNode', env('NODE_CODE_XML','SFK')));
$xml_header_el->appendChild($xml->createElement('ExternId', $offset_pedido_id));
$xml_header_el->appendChild($xml->createElement('NumProducts', 1));
$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_cliente_presupuesto"]->pedidoId));
$xml_products_el->appendChild($xml->createElement('Quantity', $data["pedido_cliente_presupuesto"]->tirada));
$xml_products_el->appendChild($xml->createElement('Title', $data["pedido_cliente_presupuesto"]->titulo));
$xml_products_el->appendChild($xml->createElement('Pages', $data["pedido_cliente_presupuesto"]->paginas));
$xml_products_el->appendChild($xml->createElement('Reprint', $data["pedido_cliente_presupuesto"]->inc_rei));
$xml_product_el = $xml->createElement('Product');
$xml_product_el->appendChild($xml->createElement('ItemId', $offset_pedido_id));
$xml_product_el->appendChild($xml->createElement('Quantity', $data["pedido_cliente_presupuesto"]->tirada));
$xml_product_el->appendChild($xml->createElement('Title', $data["pedido_cliente_presupuesto"]->titulo));
$xml_product_el->appendChild($xml->createElement('Pages', $data["pedido_cliente_presupuesto"]->paginas));
$xml_product_el->appendChild($xml->createElement('Reprint', $data["pedido_cliente_presupuesto"]->inc_rei ?? 0));
if ($data["pedido_cliente_presupuesto"]->papel_formato_personalizado) {
$papel_formato_ancho = $data["pedido_cliente_presupuesto"]->papelAnchoPersonalidado;
@ -96,12 +99,13 @@ class PedidoXMLService extends BaseService
$papel_formato_ancho = $data["pedido_cliente_presupuesto"]->lgPapelFormatoAncho;
$papel_formato_alto = $data["pedido_cliente_presupuesto"]->lgPapelFormatoAlto;
}
$xml_products_el->appendChild($xml->createElement('Width', $papel_formato_ancho));
$xml_products_el->appendChild($xml->createElement('Height', $papel_formato_alto));
$xml_product_el->appendChild($xml->createElement('Width', $papel_formato_ancho));
$xml_product_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');
@ -111,14 +115,14 @@ class PedidoXMLService extends BaseService
$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")) {
} else if (str_contains($row->tipo, "lp_cubierta") ) {//|| str_contains($row->tipo, "sobrecubierta")
//? If both exists presupuestoLineaTipoCubierta is override by sobreCubierta making null and not adding
$papelCubiertaCode = $row->papelCode;
$papelCubiertaGramaje = $row->gramaje;
$presupuestoLineaTipoCubierta = $row->tipo == "lp_cubierta" ? $row : null;
}
}
$xml_products_el->appendChild($xml_presupuesto_lineas_el);
$xml_product_el->appendChild($xml_presupuesto_lineas_el);
if ($presupuestoLineaTipoCubierta) {
$containsTarifaAcabadoBrillo = isset($data['acabado']['Finish']) ? true : false;
if ($containsTarifaAcabadoBrillo) {
@ -127,14 +131,15 @@ class PedidoXMLService extends BaseService
$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('Sides', $presupuestoLineaTipoCubierta->paginas / 2));
$xmlCover->appendChild($xml->createElement('Paper', $presupuestoLineaTipoCubierta->papelCode));
$xmlCover->appendChild($xml->createElement('Weight', $presupuestoLineaTipoCubierta->gramaje));
$xmlCover->appendChild($xml->createElement('Flaps', $data["pedido_cliente_presupuesto"]->solapas));
$xmlCover->appendChild($xml->createElement('WidthFlaps', $data["pedido_cliente_presupuesto"]->solapas_ancho));
$xmlCover->appendChild($xml->createElement('Finish', $acabado));
$xml_products_el->appendChild($xmlCover);
$xml_product_el->appendChild($xmlCover);
}
$xml_product_el->appendChild($xml->createElement('Binding', $data['binding']));
$xml_services_el = $xml->createElement('Services');
$xml_services_el->appendChild($xml->createElement('Bookmark', $data["pedido_cliente_presupuesto"]->marcapaginas));
foreach ($data['preimpresion'] as $key => $value) {
@ -144,8 +149,8 @@ class PedidoXMLService extends BaseService
$xml_services_el->appendChild($xml->createElement($key, $value));
}
$xml_products_el->appendChild($xml_services_el);
$xml_product_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');
@ -161,11 +166,13 @@ class PedidoXMLService extends BaseService
$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_cliente_presupuesto"]->comentarios_safekat));
$xml_products_el->appendChild($xml->createElement('CommentsClient', $data["pedido_cliente_presupuesto"]->comentarios_cliente));
$xml->appendChild($xml_products_el);
$file_has_suffix = hash('sha512',$data["pedido_cliente_presupuesto"]->pedidoId);
$xml_product_el->appendChild($xml_envios_el);
$xml_product_el->appendChild($xml->createElement('Comments', $data["pedido_cliente_presupuesto"]->comentarios_safekat));
$xml_product_el->appendChild($xml->createElement('CommentsClient', $data["pedido_cliente_presupuesto"]->comentarios_cliente));
$xml_products_el->appendChild($xml_product_el);
$xml_order_el->appendChild($xml_products_el);
$xml->appendChild($xml_order_el);
$file_has_suffix = hash('sha512',$offset_pedido_id);
$file_name = PedidoXMLService::generate_xml_file_name($file_has_suffix);
$ftp = new SafekatFtpClient();
$ftp->uploadXML($xml->saveXML(),$file_name);
@ -173,7 +180,30 @@ class PedidoXMLService extends BaseService
}
protected static function generate_xml_file_name(string $hash) : string
{
return implode("",["Safekat_",$hash,".xml"]);
return implode("",["SafekatNew_",$hash,".xml"]);
}
protected static function get_binding_code(string $tipo_impresion_nombre,bool $solapas) : ?string
{
$solapa = $solapas ? '1' : '0';
$key = implode("_",[$tipo_impresion_nombre,$solapa]);
$xml_mapping_binding =
[
"libroFresadoTapaBlanda_0" => 'RF',
"libroFresadoTapaBlanda_1" => 'RFS',
"libroCosidoTapaBlanda_0" => 'RCHV',
"libroCosidoTapaBlanda_1" => 'RCHVS',
"libroGrapado_0" => 'CC2',
"libroGrapado_1" => 'CC2S',
"libroCosidoTapaDura_0" => 'TDC',
"libroCosidoTapaDura_1" => 'TDC',
"libroFresadoTapaDura_0" => 'RDF',
"libroFresadoTapaDura_1" => 'RDF',
"libroEspiralTapaBlanda_0" => 'ESP',
"libroEspiralTapaBlanda_1" => 'ESP',
"libroWireoTapaBlanda_0" => 'WIO',
"libroWireoTapaBlanda_1" => 'WIO',
];
return $xml_mapping_binding[$key] ?? null;
}
protected static function get_color_interior($pre_linea): ?string
{