From 665dc2d86db4e42aa3492961e7e13b7e33ce7586 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sat, 10 Aug 2024 21:09:56 +0200 Subject: [PATCH 01/24] xml service --- ci4/app/Services/PedidoXMLService.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 ci4/app/Services/PedidoXMLService.php diff --git a/ci4/app/Services/PedidoXMLService.php b/ci4/app/Services/PedidoXMLService.php new file mode 100644 index 00000000..4281b6d9 --- /dev/null +++ b/ci4/app/Services/PedidoXMLService.php @@ -0,0 +1,16 @@ +pedido = $pedido; + } + +} \ No newline at end of file From 5648f4341380d9655a80920550ca2b004c27c10d Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 12 Aug 2024 08:02:14 +0200 Subject: [PATCH 02/24] xml service --- ci4/app/Config/Routes.php | 3 +- ci4/app/Controllers/Pedidos/Pedido.php | 11 ++- ci4/app/Models/Pedidos/PedidoModel.php | 67 +++++++++++++ ci4/app/Services/PedidoXMLService.php | 128 +++++++++++++++++++++++-- 4 files changed, 199 insertions(+), 10 deletions(-) diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 9ddf7463..adcad4bf 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -1,7 +1,6 @@ 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']); diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index 647ff134..345d9807 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -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]); + } } \ No newline at end of file diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 04755c6e..7f938a54 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -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; + } } \ No newline at end of file diff --git a/ci4/app/Services/PedidoXMLService.php b/ci4/app/Services/PedidoXMLService.php index 4281b6d9..9882a18e 100644 --- a/ci4/app/Services/PedidoXMLService.php +++ b/ci4/app/Services/PedidoXMLService.php @@ -1,16 +1,130 @@ -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)); + } - -} \ No newline at end of file + 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; + } +} From 070ffb934dc4976bca7f62c26d01e5a69901f7e0 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 12 Aug 2024 10:59:53 +0200 Subject: [PATCH 03/24] xml envios --- ci4/app/Models/Pedidos/PedidoModel.php | 121 +++++++++++++------------ ci4/app/Services/PedidoXMLService.php | 43 ++++----- 2 files changed, 82 insertions(+), 82 deletions(-) diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 7f938a54..37b40e6c 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -31,11 +31,11 @@ class PedidoModel extends \App\Models\BaseModel ]; protected $allowedFields = [ - "total_precio", - "total_tirada", - "estado", - "user_created_id", - "user_updated_id", + "total_precio", + "total_tirada", + "estado", + "user_created_id", + "user_updated_id", "user_validated_id", "fecha_entrega_real", "fecha_impresion", @@ -55,22 +55,25 @@ class PedidoModel extends \App\Models\BaseModel public static $labelField = "id"; - public function obtenerDatosForm($pedido_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"); + "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("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){ + public function obtenerLineasPedido($pedido_id) + { $builder = $this->db ->table($this->table . " t1") ->select( @@ -81,7 +84,7 @@ class PedidoModel extends \App\Models\BaseModel $model_presupuesto = model("App\Models\Presupuestos\PresupuestoModel"); $lineasPresupuesto = []; - foreach($builder->get()->getResultObject() as $row){ + foreach ($builder->get()->getResultObject() as $row) { array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]); } @@ -90,66 +93,66 @@ class PedidoModel extends \App\Models\BaseModel 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') + ->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); + ->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', + ->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') + ]) + ->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); + ->where('pedidos.id', $pedido_id); $pedido_presupuesto_lineas = $query->get()->getResultObject(); return $pedido_presupuesto_lineas; } - public function getPedidoClienteDirecciones($pedido_id){ + public function getPedidoPresupuestoDirecciones($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); + ->select([ + 'clientes.nombre as customerName', + 'presupuesto_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 = presupuesto_direcciones.pais_id', 'left') + ->where('pedidos.id', $pedido_id); $pedido_cliente_direcciones = $query->get()->getResultObject(); return $pedido_cliente_direcciones; } -} \ No newline at end of file +} diff --git a/ci4/app/Services/PedidoXMLService.php b/ci4/app/Services/PedidoXMLService.php index 9882a18e..a535ebab 100644 --- a/ci4/app/Services/PedidoXMLService.php +++ b/ci4/app/Services/PedidoXMLService.php @@ -64,13 +64,13 @@ class PedidoXMLService extends BaseService $xml_products_el->appendChild($xml_presupuesto_lineas_el); if ($presupuestoLineaTipoCubierta) { $lgTarifaAcabadoNombre = $data->pedido_presupuesto->lgTarifaAcabadoNombre; - if(str_contains('brillo',$lgTarifaAcabadoNombre)){ + if (str_contains('brillo', $lgTarifaAcabadoNombre)) { $acabado = "brillo"; - }else{ + } else { $acabado = "mate"; } $xmlCover = $xml->createElement('Cover'); - $xmlCover->appendChild($xml->createElement('Sides', $presupuestoLineaTipoCubierta->paginas)); //! PAGINAS CUBIERTA + $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)); @@ -80,38 +80,35 @@ class PedidoXMLService extends BaseService } $xml_services_el = $xml->createElement('Services'); $xml_services_el->appendChild($xml->createElement('Bookmark', $data->pedido_presupuesto->marcapaginas)); + //? Retractilado5 y Retractilado o ambas $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('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_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) { + foreach ($data->pedido_presupuesto_direcciones as $pedido_presupuesto_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_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 { From 5169174e57166c3401fe8ef09b8b387590a43ba1 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 12 Aug 2024 12:16:04 +0200 Subject: [PATCH 04/24] git push --- ci4/app/Services/PedidoXMLService.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ci4/app/Services/PedidoXMLService.php b/ci4/app/Services/PedidoXMLService.php index a535ebab..55751ba1 100644 --- a/ci4/app/Services/PedidoXMLService.php +++ b/ci4/app/Services/PedidoXMLService.php @@ -81,14 +81,15 @@ class PedidoXMLService extends BaseService $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)); - $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_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'); From ee45baec3b7f7fef9ba2bdf367bdd3bdc4c3591c Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 19 Aug 2024 08:23:39 +0200 Subject: [PATCH 05/24] xml file generation --- ci4/app/Controllers/Pedidos/Pedido.php | 7 +- ci4/app/Models/Pedidos/PedidoModel.php | 40 ++- .../Models/Presupuestos/PresupuestoModel.php | 268 +++++++++++------- ci4/app/Services/PedidoXMLService.php | 127 ++++++--- 4 files changed, 297 insertions(+), 145 deletions(-) diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index 345d9807..af2dbfc7 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -328,11 +328,10 @@ class Pedido extends \App\Controllers\BaseResourceController } 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); + + $data = PedidoXMLService::generate_xml($pedido_id); // $xml_service = new PedidoXMLService($this->model); - return $this->respond(["pedido_presupuesto" => $data_pedido,"pedido_presupuesto_linea" => $data_pedido_presupuesto]); + return $this->respond($data); } } \ No newline at end of file diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 37b40e6c..3d238a84 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -97,25 +97,31 @@ class PedidoModel extends \App\Models\BaseModel 'pedidos.id as pedidoId', 'clientes.nombre as customerName', 'presupuestos.total_aceptado as totalAceptado', + 'presupuestos.id as presupuestoId', 'presupuestos.margen', 'presupuestos.inc_rei', 'presupuestos.tirada', 'presupuestos.titulo', 'presupuestos.paginas', + 'presupuestos.solapas', + 'presupuestos.solapas_ancho', + 'presupuestos.marcapaginas', + 'presupuestos.comentarios_cliente', + 'presupuestos.comentarios_safekat', '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_ficheros', 'presupuesto_ficheros.presupuesto_id = presupuestos.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; @@ -124,17 +130,18 @@ class PedidoModel extends \App\Models\BaseModel { $query = $this->db->table($this->table) ->select([ - 'presupuesto_linea.*', + 'pedidos.id as pedidoId', + 'presupuesto_linea.tipo', + 'presupuesto_linea.paginas', + 'presupuesto_linea.gramaje', '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; } @@ -142,12 +149,15 @@ class PedidoModel extends \App\Models\BaseModel { $query = $this->db->table($this->table) ->select([ + 'pedidos.id as pedidoId', + 'presupuestos.id as presupuestoId', 'clientes.nombre as customerName', 'presupuesto_direcciones.*', - 'lg_paises.code3' + 'lg_paises.code3 as paisCode3' ]) ->join('pedidos_linea', 'pedidos_linea.id = pedidos.id', 'left') ->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id', 'left') + ->join('presupuesto_direcciones', 'presupuestos.id = presupuesto_direcciones.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 = presupuesto_direcciones.pais_id', 'left') @@ -155,4 +165,18 @@ class PedidoModel extends \App\Models\BaseModel $pedido_cliente_direcciones = $query->get()->getResultObject(); return $pedido_cliente_direcciones; } + public function getPedidoPresupuestoFicheros($pedido_id) + { + $query = $this->db->table($this->table) + ->select([ + 'presupuesto_ficheros.nombre as fileName', + 'presupuesto_ficheros.file_path as filePath' + ]) + ->join('pedidos_linea', 'pedidos_linea.id = pedidos.id', 'left') + ->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id', 'left') + ->join('presupuesto_ficheros', 'presupuesto_ficheros.presupuesto_id = presupuestos.id', 'left') + ->where('pedidos.id', $pedido_id); + $presupuesto_ficheros = $query->get()->getFirstRow(); + return $presupuesto_ficheros; + } } diff --git a/ci4/app/Models/Presupuestos/PresupuestoModel.php b/ci4/app/Models/Presupuestos/PresupuestoModel.php index 424ba107..6c8bc26a 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php @@ -326,7 +326,8 @@ class PresupuestoModel extends \App\Models\BaseModel return $builder; } - function getListaPresupuestosCliente($search = [] , $clienteId){ + function getListaPresupuestosCliente($search = [], $clienteId) + { $builder = $this->db ->table($this->table . " t1") @@ -343,7 +344,7 @@ class PresupuestoModel extends \App\Models\BaseModel $builder->join("presupuesto_estados t6", "t1.estado_id = t6.id", "left"); $builder->join("tipos_presupuestos t7", "t1.tipo_impresion_id = t7.id", "left"); - if($clienteId != 0) + if ($clienteId != 0) $builder->where("t1.cliente_id", $clienteId); $builder->where("t1.is_deleted", 0); @@ -363,7 +364,7 @@ class PresupuestoModel extends \App\Models\BaseModel } $builder->groupEnd(); return $builder; - } + } } function confirmarPresupuesto($presupuesto_id) @@ -377,16 +378,16 @@ class PresupuestoModel extends \App\Models\BaseModel function insertarPresupuestoCliente($id, $tirada, $data, $data_cabecera, $extra_info, $resumen_totales, $iva_reducido, $excluir_rotativa, $tiradas_alternativas) { - + helper('date'); $model = model('App\Models\Configuracion\PapelFormatoModel'); $papel_formato_id = $model->where('ancho', $data['tamanio']['ancho'])->where('alto', $data['tamanio']['alto'])->first(); - + $is_cosido = (new TipoPresupuestoModel())->get_isCosido($data['tipo_impresion_id']); - $totalCostes = $resumen_totales['totalPapel'] + $resumen_totales['totalImpresion'] + - $resumen_totales['totalServicios']+$resumen_totales['coste_envio']; + $totalCostes = $resumen_totales['totalPapel'] + $resumen_totales['totalImpresion'] + + $resumen_totales['totalServicios'] + $resumen_totales['coste_envio']; $totalMargenes = $resumen_totales['margenPapel'] + $resumen_totales['margenImpresion'] + $resumen_totales['margenServicios'] + $resumen_totales['margen_envio']; @@ -400,22 +401,22 @@ class PresupuestoModel extends \App\Models\BaseModel 'faja_color' => in_array(16, $data['servicios']) ? 1 : 0, 'ferro' => in_array(24, $data['servicios']) ? 1 : 0, 'prototipo' => in_array(9, $data['servicios']) ? 1 : 0, - 'papel_formato_id' => is_null($papel_formato_id) ? 0: $papel_formato_id->id, - 'papel_formato_personalizado' => !$papel_formato_id ? 1:0, - 'papel_formato_ancho' => !$papel_formato_id ? $data['tamanio']['ancho']:null, - 'papel_formato_alto' => !$papel_formato_id ? $data['tamanio']['alto']:null, + 'papel_formato_id' => is_null($papel_formato_id) ? 0 : $papel_formato_id->id, + 'papel_formato_personalizado' => !$papel_formato_id ? 1 : 0, + 'papel_formato_ancho' => !$papel_formato_id ? $data['tamanio']['ancho'] : null, + 'papel_formato_alto' => !$papel_formato_id ? $data['tamanio']['alto'] : null, 'titulo' => $data_cabecera['titulo'], 'referencia_cliente' => $data_cabecera['referenciaCliente'], 'paginas' => $data['interior']['paginas'], 'tirada' => $tirada, - 'solapas' => $data['cubierta']['solapasCubierta']>0 ? 1 : 0, - 'solapas_ancho' => $data['cubierta']['solapasCubierta']>0 ? $data['cubierta']['solapasCubierta'] : 0, - 'solapas_sobrecubierta' => is_null($data['sobrecubierta']) ? 0 :1, + 'solapas' => $data['cubierta']['solapasCubierta'] > 0 ? 1 : 0, + 'solapas_ancho' => $data['cubierta']['solapasCubierta'] > 0 ? $data['cubierta']['solapasCubierta'] : 0, + 'solapas_sobrecubierta' => is_null($data['sobrecubierta']) ? 0 : 1, 'solapas_ancho_sobrecubierta' => is_null($data['sobrecubierta']) ? 0 : $data['sobrecubierta']['solapas'], 'cosido' => $is_cosido, 'merma' => $extra_info['merma'], 'merma_cubierta' => $extra_info['merma'], - + 'lomo_cubierta' => $extra_info['lomo_cubierta'], 'lomo_sobrecubierta' => $extra_info['lomo_sobrecubierta'], @@ -424,12 +425,12 @@ class PresupuestoModel extends \App\Models\BaseModel 'acabado_cubierta_id' => $data['acabadoCubierta'], 'acabado_sobrecubierta_id' => is_null($data['sobrecubierta']) ? 0 : $data['sobrecubierta']['acabado'], - 'comp_tipo_impresion' => $data['isHq']? ($data['isColor']? 'colorhq':'negrohq'):($data['isColor']? 'color':'negro'), + 'comp_tipo_impresion' => $data['isHq'] ? ($data['isColor'] ? 'colorhq' : 'negrohq') : ($data['isColor'] ? 'color' : 'negro'), 'user_created_id' => $extra_info['user_id'], 'created_at' => date('Y-m-d H:i:s', now()), 'updated_at' => date('Y-m-d H:i:s', now()), - + 'tirada_alternativa_json_data' => json_encode($tiradas_alternativas), 'total_coste_papel' => round($resumen_totales['totalPapel'], 2), @@ -445,32 +446,31 @@ class PresupuestoModel extends \App\Models\BaseModel 'total_margen_envios' => round($resumen_totales['margen_envio'], 2), 'total_costes' => round($totalCostes, 2), 'total_margenes' => round($totalMargenes, 2), - + 'total_antes_descuento' => round($totalCostes + $totalMargenes, 2), 'total_descuento' => 0, 'total_descuentoPercent' => 0, - 'total_precio_unidad' => round(($totalCostes + $totalMargenes)/$tirada, 4), - 'total_presupuesto' => round($totalCostes + $totalMargenes, 2), - 'total_aceptado' => round($totalCostes + $totalMargenes, 2), + 'total_precio_unidad' => round(($totalCostes + $totalMargenes) / $tirada, 4), + 'total_presupuesto' => round($totalCostes + $totalMargenes, 2), + 'total_aceptado' => round($totalCostes + $totalMargenes, 2), - 'total_factor' => round(($totalCostes + $totalMargenes-$resumen_totales['coste_envio']-$resumen_totales['margen_envio'])/$resumen_totales['sumForFactor'], 2), - 'total_factor_ponderado' => round(($totalCostes + $totalMargenes-$resumen_totales['coste_envio']-$resumen_totales['margen_envio'])/$resumen_totales['sumForFactorPonderado'], 2), + 'total_factor' => round(($totalCostes + $totalMargenes - $resumen_totales['coste_envio'] - $resumen_totales['margen_envio']) / $resumen_totales['sumForFactor'], 2), + 'total_factor_ponderado' => round(($totalCostes + $totalMargenes - $resumen_totales['coste_envio'] - $resumen_totales['margen_envio']) / $resumen_totales['sumForFactorPonderado'], 2), 'iva_reducido' => $iva_reducido, 'excluir_rotativa' => $excluir_rotativa, ]; - if($id != 0){ + if ($id != 0) { $fields['id'] = $id; $fields['updated_at'] = date('Y-m-d H:i:s', now()); } - if($id != 0){ + if ($id != 0) { $this->db->table($this->table)->where('id', $id)->update($fields); return $id; - } - else{ + } else { $this->db->table($this->table)->insert($fields); return $this->db->insertID(); } @@ -482,27 +482,27 @@ class PresupuestoModel extends \App\Models\BaseModel if (is_array($data)) { // -- INTERIOR -- // Si hay negro - if($data['interior']['paginas'] > $data['interior']['paginas_color']){ + if ($data['interior']['paginas'] > $data['interior']['paginas_color']) { - if($data['isHq']) + if ($data['isHq']) $key = 'bnhq'; else $key = 'bn'; $values[$key] = array( - 'paginas'=> intval($data['interior']['paginas'])-intval($data['interior']['paginas_color']), + 'paginas' => intval($data['interior']['paginas']) - intval($data['interior']['paginas_color']), 'papel_id' => intval($data['interior']['papel_generico']['id']), 'gramaje' => intval($data['interior']['gramaje']), ); } - // Si hay color - if($data['interior']['paginas_color']>0){ + // Si hay color + if ($data['interior']['paginas_color'] > 0) { - if($data['isHq']) + if ($data['isHq']) $key = 'colorhq'; else $key = 'color'; $values[$key] = array( - 'paginas'=> intval($data['interior']['paginas_color']), + 'paginas' => intval($data['interior']['paginas_color']), 'papel_id' => intval($data['interior']['papel_generico']['id']), 'gramaje' => intval($data['interior']['gramaje']), ); @@ -516,7 +516,7 @@ class PresupuestoModel extends \App\Models\BaseModel ); // -- SOBRECUBIERTA -- - if(!is_null($data['sobrecubierta'])){ + if (!is_null($data['sobrecubierta'])) { $values['sobrecubierta'] = array( 'papel_id' => intval($data['sobrecubierta']['papel']), 'gramaje' => intval($data['sobrecubierta']['gramaje']), @@ -525,14 +525,13 @@ class PresupuestoModel extends \App\Models\BaseModel } // -- GUARDAS -- - if($data['datos_guardas'] != 0){ + if ($data['datos_guardas'] != 0) { $values['guardas'] = array( 'papel_id' => intval($data['datos_guardas']['papel']), 'gramaje' => intval($data['datos_guardas']['gramaje']), 'paginas' => intval($data['datos_guardas']['caras']), ); } - } $json = json_encode($values); return $json; @@ -557,32 +556,33 @@ class PresupuestoModel extends \App\Models\BaseModel $builder->where("t1.is_deleted", 0); $builder->where("t1.id", $presupuesto_id); $presupuesto = $builder->get()->getResultObject(); - if(count($presupuesto) > 0){ + if (count($presupuesto) > 0) { $modelLinea = model('App\Models\Presupuestos\PresupuestoLineaModel'); - $lineas = $modelLinea->where('presupuesto_id', $presupuesto_id)->findAll(); + $lineas = $modelLinea->where('presupuesto_id', $presupuesto_id)->findAll(); $presupuesto = $presupuesto[0]; // Libro - if($presupuesto->tipo < 10 || $presupuesto->tipo==20 || $presupuesto->tipo==21){ - if($presupuesto->papel_formato_personalizado == 1){ - $presupuesto->tamanio= $presupuesto->papel_formato_ancho . "x" . $presupuesto->papel_formato_alto; + if ($presupuesto->tipo < 10 || $presupuesto->tipo == 20 || $presupuesto->tipo == 21) { + if ($presupuesto->papel_formato_personalizado == 1) { + $presupuesto->tamanio = $presupuesto->papel_formato_ancho . "x" . $presupuesto->papel_formato_alto; } - - if($forFactura){ + + if ($forFactura) { $presupuesto->concepto = sprintf(lang('Pedidos.lineasTemplates.pedido'), $pedido_id); - } - else{ + } else { $presupuesto->concepto = sprintf(lang('Pedidos.lineasTemplates.presupuesto'), $presupuesto->numero); } - $presupuesto->concepto .= sprintf(lang('Pedidos.lineasTemplates.libro'), + $presupuesto->concepto .= sprintf( + lang('Pedidos.lineasTemplates.libro'), $presupuesto->unidades, $presupuesto->paginas, $presupuesto->titulo, $presupuesto->autor, $presupuesto->isbn, - $presupuesto->tamanio); + $presupuesto->tamanio + ); $presupuesto->concepto .= $this->generarConceptoLineasPresupuestoLibro($lineas, $presupuesto); $presupuesto = (object)[ @@ -594,10 +594,67 @@ class PresupuestoModel extends \App\Models\BaseModel } return [$presupuesto]; } - } + public function getServiciosPresupuesto($presupuesto_id) + { + $queryAcabado = $this->db->table($this->table) + ->select( + [ + 'lg_tarifa_acabado.id', + 'lg_tarifa_acabado.nombre', - private function generarConceptoLineasPresupuestoLibro($lineas, $presupuesto){ + + ] + ) + ->join('presupuesto_acabados', 'presupuesto_acabados.presupuesto_id = presupuestos.id', 'left') + ->join('lg_tarifa_acabado', 'lg_tarifa_acabado.id = presupuesto_acabados.tarifa_acabado_id', 'left') + ->where('presupuestos.id', $presupuesto_id); + + $queryPreimpresion = $this->db->table($this->table) + ->select( + [ + 'lg_tarifa_preimpresion.id', + 'lg_tarifa_preimpresion.nombre', + 'lg_tarifa_preimpresion.precio', + + ] + ) + ->join('presupuesto_preimpresiones', 'presupuesto_preimpresiones.presupuesto_id = presupuestos.id', 'left') + ->join('lg_tarifa_preimpresion', 'lg_tarifa_preimpresion.id = presupuesto_preimpresiones.tarifa_preimpresion_id', 'left') + ->where('presupuestos.id', $presupuesto_id); + + $queryManipulado = $this->db->table($this->table) + ->select( + [ + 'lg_tarifa_manipulado.id', + 'lg_tarifa_manipulado.nombre', + + ] + ) + ->join('presupuesto_manipulados', 'presupuesto_manipulados.presupuesto_id = presupuestos.id', 'left') + ->join('lg_tarifa_manipulado', 'lg_tarifa_manipulado.id = presupuesto_manipulados.tarifa_manipulado_id', 'left') + ->where('presupuestos.id', $presupuesto_id); + + $queryExtras = $this->db->table($this->table) + ->select( + [ + 'lg_tarifa_preimpresion.id', + 'lg_tarifa_preimpresion.nombre', + + ] + ) + ->join('presupuesto_serviciosExtra', 'presupuesto_serviciosExtra.presupuesto_id = presupuestos.id', 'left') + ->join('lg_tarifa_preimpresion', 'lg_tarifa_preimpresion.id = presupuesto_serviciosExtra.tarifa_extra_id', 'left') + ->where('presupuestos.id', $presupuesto_id); + + $servicios['acabado'] = $queryAcabado->get()->getResultObject(); + $servicios['manipulado'] = $queryManipulado->get()->getResultObject(); + $servicios['preimpresion'] = $queryPreimpresion->get()->getResultObject(); + $servicios['extra'] = $queryExtras->get()->getResultObject(); + return $servicios; + } + private function generarConceptoLineasPresupuestoLibro($lineas, $presupuesto) + { $model_papel = model('App\Models\Configuracion\PapelImpresionModel'); $description_interior = ""; @@ -610,105 +667,118 @@ class PresupuestoModel extends \App\Models\BaseModel $gramaje_negro = 0; $gramaje_color = 0; - $lp_bn_lines = array_filter($lineas, function($linea) { + $lp_bn_lines = array_filter($lineas, function ($linea) { return strpos($linea->tipo, 'lp_bn') === 0; }); - $lp_color_lines = array_filter($lineas, function($linea) { + $lp_color_lines = array_filter($lineas, function ($linea) { return strpos($linea->tipo, 'lp_color') === 0; }); - $lp_rot_bn = array_filter($lineas, function($linea) { + $lp_rot_bn = array_filter($lineas, function ($linea) { return strpos($linea->tipo, 'lp_rot_bn') === 0; }); - $lp_rot_color = array_filter($lineas, function($linea) { + $lp_rot_color = array_filter($lineas, function ($linea) { return strpos($linea->tipo, 'lp_rot_color') === 0; }); - - if(count($lp_bn_lines) > 0){ + + if (count($lp_bn_lines) > 0) { $lp_bn_lines = array_values($lp_bn_lines)[0]; $paginas_negro = $lp_bn_lines->paginas; $gramaje_negro = $lp_bn_lines->gramaje; - $papel_negro = $model_papel->where('id', $lp_bn_lines->papel_impresion_id)->first()->nombre; - $description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'), + $papel_negro = $model_papel->where('id', $lp_bn_lines->papel_impresion_id)->first()->nombre; + $description_interior .= sprintf( + lang('Pedidos.lineasTemplates.libro_linea_interior'), strval($paginas_negro), $papel_negro, - strval($gramaje_negro)) . ". "; + strval($gramaje_negro) + ) . ". "; } - if(count($lp_color_lines) > 0){ + if (count($lp_color_lines) > 0) { $lp_color_lines = array_values($lp_color_lines)[0]; $paginas_color = $lp_color_lines->paginas; $gramaje_color = $lp_color_lines->gramaje; - $papel_color = $model_papel->where('id', $lp_color_lines->papel_impresion_id)->first()->nombre; - $description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'), + $papel_color = $model_papel->where('id', $lp_color_lines->papel_impresion_id)->first()->nombre; + $description_interior .= sprintf( + lang('Pedidos.lineasTemplates.libro_linea_interior'), strval($paginas_color), $papel_color, - strval($gramaje_color)) . ". "; + strval($gramaje_color) + ) . ". "; } - if(count($lp_rot_bn) > 0){ + if (count($lp_rot_bn) > 0) { $lp_rot_bn = array_values($lp_rot_bn)[0]; $paginas_negro = $lp_rot_bn->paginas; $gramaje_negro = $lp_rot_bn->gramaje; - $papel_negro = $model_papel->where('id', $lp_rot_bn->papel_impresion_id)->first()->nombre; - $description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'), + $papel_negro = $model_papel->where('id', $lp_rot_bn->papel_impresion_id)->first()->nombre; + $description_interior .= sprintf( + lang('Pedidos.lineasTemplates.libro_linea_interior'), strval($paginas_negro), $papel_negro, - strval($gramaje_negro)) . ". "; + strval($gramaje_negro) + ) . ". "; } - if(count($lp_rot_color) > 0){ + if (count($lp_rot_color) > 0) { $lp_rot_color = array_values($lp_rot_color)[0]; - $paginas_negro = intval($lp_rot_color->paginas)-intval($lp_rot_color->rotativa_pag_color); + $paginas_negro = intval($lp_rot_color->paginas) - intval($lp_rot_color->rotativa_pag_color); $gramaje = $lp_rot_color->gramaje; - $papel = $model_papel->where('id', $lp_rot_color->papel_impresion_id)->first()->nombre; - if($paginas_negro > 0){ - $description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'), - strval($paginas_negro), - $papel, - strval($gramaje)) . ". "; + $papel = $model_papel->where('id', $lp_rot_color->papel_impresion_id)->first()->nombre; + if ($paginas_negro > 0) { + $description_interior .= sprintf( + lang('Pedidos.lineasTemplates.libro_linea_interior'), + strval($paginas_negro), + $papel, + strval($gramaje) + ) . ". "; } - $description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'), + $description_interior .= sprintf( + lang('Pedidos.lineasTemplates.libro_linea_interior'), strval($lp_rot_color->rotativa_pag_color), $papel, - strval($gramaje)) . ". "; + strval($gramaje) + ) . ". "; } - $lp_cubierta = array_filter($lineas, function($linea) { + $lp_cubierta = array_filter($lineas, function ($linea) { return strpos($linea->tipo, 'lp_cubierta') === 0; }); - $lp_sobrecubierta = array_filter($lineas, function($linea) { + $lp_sobrecubierta = array_filter($lineas, function ($linea) { return strpos($linea->tipo, 'lp_sobrecubierta') === 0; }); - if(count($lp_cubierta) > 0){ + if (count($lp_cubierta) > 0) { $lp_cubierta = array_values($lp_cubierta)[0]; - if($lp_cubierta->paginas == 2){ + if ($lp_cubierta->paginas == 2) { $lp_cubierta->caras = lang('Pedidos.unaCara'); - } - else{ + } else { $lp_cubierta->caras = lang('Pedidos.dosCaras'); } - $description_cubierta = sprintf(lang('Pedidos.lineasTemplates.libro_linea_cubierta'), + $description_cubierta = sprintf( + lang('Pedidos.lineasTemplates.libro_linea_cubierta'), $lp_cubierta->caras, - $model_papel->where('id', $lp_cubierta->papel_impresion_id)->first()->nombre, - strval($lp_cubierta->gramaje)); - $description_cubierta .= ($presupuesto->solapas_cubierta==1? sprintf(lang('Pedidos.lineasTemplates.libro_solapas'), $presupuesto->solapas_ancho_cubierta):". "); - } - if(count($lp_sobrecubierta) > 0){ + $model_papel->where('id', $lp_cubierta->papel_impresion_id)->first()->nombre, + strval($lp_cubierta->gramaje) + ); + $description_cubierta .= ($presupuesto->solapas_cubierta == 1 ? sprintf(lang('Pedidos.lineasTemplates.libro_solapas'), $presupuesto->solapas_ancho_cubierta) : ". "); + } + if (count($lp_sobrecubierta) > 0) { $lp_sobrecubierta = array_values($lp_sobrecubierta)[0]; - $description_sobrecubierta = sprintf(lang('Pedidos.lineasTemplates.libro_linea_sobrecubierta'), - $model_papel->where('id', $lp_sobrecubierta->papel_impresion_id)->first()->nombre, - strval($lp_sobrecubierta->gramaje)); - $description_sobrecubierta .= ($presupuesto->solapas_sobrecubierta==1? sprintf(lang('Pedidos.lineasTemplates.libro_solapas'), $presupuesto->solapas_ancho_sobrecubierta):". "); - } + $description_sobrecubierta = sprintf( + lang('Pedidos.lineasTemplates.libro_linea_sobrecubierta'), + $model_papel->where('id', $lp_sobrecubierta->papel_impresion_id)->first()->nombre, + strval($lp_sobrecubierta->gramaje) + ); + $description_sobrecubierta .= ($presupuesto->solapas_sobrecubierta == 1 ? sprintf(lang('Pedidos.lineasTemplates.libro_solapas'), $presupuesto->solapas_ancho_sobrecubierta) : ". "); + } - $acabado = sprintf(lang('Pedidos.lineasTemplates.libro_encuadernacion'), - lang('Presupuestos.' . $presupuesto->codigo_encuadernacion)); - - return $description_interior. $description_cubierta . $description_sobrecubierta . $acabado; + $acabado = sprintf( + lang('Pedidos.lineasTemplates.libro_encuadernacion'), + lang('Presupuestos.' . $presupuesto->codigo_encuadernacion) + ); + return $description_interior . $description_cubierta . $description_sobrecubierta . $acabado; } - } diff --git a/ci4/app/Services/PedidoXMLService.php b/ci4/app/Services/PedidoXMLService.php index 55751ba1..b09edaa1 100644 --- a/ci4/app/Services/PedidoXMLService.php +++ b/ci4/app/Services/PedidoXMLService.php @@ -6,45 +6,104 @@ use App\Entities\Pedidos\PedidoEntity; use CodeIgniter\Config\BaseService; use App\Models\Pedidos\PedidoModel; use App\Models\Pedidos\PedidoLineaModel; +use App\Models\Presupuestos\PresupuestoModel; use DOMDocument; use DOMNode; class PedidoXMLService extends BaseService { - public static function generate_xml($data) + public static function get_pedido_presupuesto(int $pedido_id) + { + $data_xml = []; + $pedidoModel = model(PedidoModel::class); + $presupuestoModel = model(PresupuestoModel::class); + $data_xml['pedido_cliente_presupuesto'] = $pedidoModel->getPedidoClientePresupuesto($pedido_id); + $data_xml['pedido_presupuesto_direcciones'] = $pedidoModel->getPedidoPresupuestoDirecciones($pedido_id); + $data_xml['pedido_presupuesto_lineas'] = $pedidoModel->getPedidoPresupuestoLineas($pedido_id); + $servicios = $presupuestoModel->getServiciosPresupuesto($data_xml['pedido_cliente_presupuesto']->presupuestoId); + $data_xml['servicios'] = $servicios; + $data_xml['preimpresion'] = PedidoXMLService::parse_servicio_preimpresion($servicios['preimpresion']); + $data_xml["acabado"] = PedidoXMLService::parse_servicio_acabado($servicios['acabado']); + return $data_xml; + + } + protected static function parse_servicio_acabado(array $data_xml_servicios_acabado) + { + $xml_element = []; + $service_xml_key_value = [ + "ShrinkWrapping" => fn($nombre) => str_contains($nombre,"retractilado"), + "Finish" => fn($nombre) => str_contains($nombre,"brillo"), + "PlakeneT" =>fn($nombre) => str_contains($nombre,"plakene traslúcido"),]; + foreach($data_xml_servicios_acabado as $servicio_acabado) + { + $service_name = strtolower($servicio_acabado->nombre); + foreach ($service_xml_key_value as $key => $value) { + $xml_element[$key] = $value($service_name) ? 1 : 0 ; + } + + } + return $xml_element; + } + protected static function parse_servicio_preimpresion(array $data_xml_servicios_preimpresion) + { + $xml_element = []; + $service_xml_key_value = [ + "Urgent" => fn($nombre) => str_contains($nombre,"Pedido urgente"), + "Prototype" => fn($nombre) => str_contains($nombre,"Prototipo"), + "Layout" =>fn($nombre) => str_contains($nombre,"Maquetación"), + "Correction" =>fn($nombre) => str_contains($nombre,"Corrección ortográfica"), + // "Review" =>fn($nombre) => str_contains($nombre,"Revisión Profesional de archivo"), + "Design" =>fn($nombre) => str_contains($nombre,'Diseño de Cubierta'), + ]; + foreach($data_xml_servicios_preimpresion as $servicio_pre) + { + $service_name = $servicio_pre->nombre; + foreach ($service_xml_key_value as $key => $value) { + $value_service = $value($service_name) ? 1 : 0 ; + if( $value_service){ + $xml_element[$key] = $servicio_pre->precio ; + }else if(!isset($xml_element[$key])){ + $xml_element[$key] = $value_service; + } + } + } + return $xml_element; + } + public static function generate_xml($pedido_id) { $papel_formato_ancho = 0; $papel_formato_alto = 0; + $data = PedidoXMLService::get_pedido_presupuesto($pedido_id); $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('ExternId', $data["pedido_cliente_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)); + $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)); - if ($data->pedido_presupuesto->papel_formato_personalizado) { - $papel_formato_ancho = $data->pedido_presupuesto->papelAnchoPersonalidado; - $papel_formato_alto = $data->pedido_presupuesto->papelAltoPersonalidado; + if ($data["pedido_cliente_presupuesto"]->papel_formato_personalizado) { + $papel_formato_ancho = $data["pedido_cliente_presupuesto"]->papelAnchoPersonalidado; + $papel_formato_alto = $data["pedido_cliente_presupuesto"]->papelAltoPersonalidado; } else { - $papel_formato_ancho = $data->pedido_presupuesto->lgPapelFormatoAncho; - $papel_formato_alto = $data->pedido_presupuesto->lgPapelFormatoAlto; + $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)); $presupuestoLineaTipoCubierta = null; $xml_presupuesto_lineas_el = $xml->createElement('Lines'); ## Iterate throught presupuesto_lineas - foreach ($data->pedido_presupuesto_lineas as $row) { + 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'); @@ -63,8 +122,8 @@ class PedidoXMLService extends BaseService $xml_products_el->appendChild($xml_presupuesto_lineas_el); if ($presupuestoLineaTipoCubierta) { - $lgTarifaAcabadoNombre = $data->pedido_presupuesto->lgTarifaAcabadoNombre; - if (str_contains('brillo', $lgTarifaAcabadoNombre)) { + $containsTarifaAcabadoBrillo = isset($data['acabado']['Finish']) ? true : false; + if ($containsTarifaAcabadoBrillo) { $acabado = "brillo"; } else { $acabado = "mate"; @@ -73,43 +132,43 @@ class PedidoXMLService extends BaseService $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('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_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_services_el->appendChild($xml->createElement('Bookmark', $data["pedido_cliente_presupuesto"]->marcapaginas)); + foreach ($data['preimpresion'] as $key => $value) { + $xml_services_el->appendChild($xml->createElement($key, $value)); + } + foreach ($data['acabado'] as $key => $value) { + $xml_services_el->appendChild($xml->createElement($key, $value)); + } + $xml_products_el->appendChild($xml_services_el); $xml_envios_el = $xml->createElement('Shipments'); - foreach ($data->pedido_presupuesto_direcciones as $pedido_presupuesto_direccion) { + 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('Price', $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('City', $pedido_presupuesto_direccion->municipio)); $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('CountryCode', $pedido_presupuesto_direccion->paisCode3)); $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)); + $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); + return $data; } protected static function get_color_interior($pre_linea): ?string { From da379a7af966a6b229a5110605106cf5bf795a54 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Wed, 28 Aug 2024 22:28:34 +0200 Subject: [PATCH 06/24] ftp service --- ci4/app/Config/FTP.php | 58 +++ ci4/app/Config/Services.php | 8 + ci4/app/Controllers/Pedidos/Pedido.php | 1 - ci4/app/Helpers/general_helper.php | 683 ------------------------- ci4/app/Services/FTPService.php | 48 ++ ci4/app/Services/PedidoXMLService.php | 8 + 6 files changed, 122 insertions(+), 684 deletions(-) create mode 100644 ci4/app/Config/FTP.php delete mode 100755 ci4/app/Helpers/general_helper.php create mode 100644 ci4/app/Services/FTPService.php diff --git a/ci4/app/Config/FTP.php b/ci4/app/Config/FTP.php new file mode 100644 index 00000000..f3faf0a0 --- /dev/null +++ b/ci4/app/Config/FTP.php @@ -0,0 +1,58 @@ + "sk-ftp", + "user" => "admin", + "password" => "A77h3b0X4OA2rOYAf4w2", + "base_dir" => "/home/admin/safekat" # FTP server directory + ]; + /** + * This database connection is used when + * running PHPUnit database tests. + */ + public array $production = [ + "host" => "sk-ftp", + "user" => "admin", + "password" => "A77h3b0X4OA2rOYAf4w2", + "base_dir" => "/home/admin/safekat" # FTP server directory + ]; + /** + * This database connection is used when + * running PHPUnit database tests. + */ + public array $development = [ + "host" => "sk-ftp", + "port" => "21000", + "user" => "admin", + "password" => "A77h3b0X4OA2rOYAf4w2", + "base_dir" => "/home/admin/safekat" # FTP server directory + + ]; + + public function __construct() + { + parent::__construct(); + + // Ensure that we always set the database group to 'tests' if + // we are currently running an automated test suite, so that + // we don't overwrite live data on accident. + if (ENVIRONMENT === 'development') { + $this->defaultGroup = 'development'; + } + } +} diff --git a/ci4/app/Config/Services.php b/ci4/app/Config/Services.php index df7c8ad0..572aec46 100755 --- a/ci4/app/Config/Services.php +++ b/ci4/app/Config/Services.php @@ -2,6 +2,7 @@ namespace Config; +use App\Services\FTPService; use CodeIgniter\Config\BaseService; /** @@ -29,4 +30,11 @@ class Services extends BaseService * return new \CodeIgniter\Example(); * } */ + public static function ftp(bool $getShared = true): FTPService + { + if ($getShared) { + return static::getSharedInstance('ftp'); + } + return new FTPService(); + } } diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index af2dbfc7..6ff1ca79 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -328,7 +328,6 @@ class Pedido extends \App\Controllers\BaseResourceController } public function get_xml_pedido($pedido_id) { - $data = PedidoXMLService::generate_xml($pedido_id); // $xml_service = new PedidoXMLService($this->model); return $this->respond($data); diff --git a/ci4/app/Helpers/general_helper.php b/ci4/app/Helpers/general_helper.php deleted file mode 100755 index e0578134..00000000 --- a/ci4/app/Helpers/general_helper.php +++ /dev/null @@ -1,683 +0,0 @@ -$value){ - if($key==$section){ - foreach($value as $item){ - if($item==$method){ - return true; - } - } - } - } - return false; - - /*var_dump($key. ' '. $value[0]); - - echo '
';
-        $rules = 
-        echo '
'; - dd();*/ -} - -function getAllClass($controller = null){ - try { - helper('filesystem'); - helper('directory'); - if(strtolower(PHP_OS) == 'linux'){ - $compatibility = '/'; - }else{ - $compatibility = '\\'; - } - if(empty($controller)){ - $map = directory_map(APPPATH.'Controllers'); - foreach ($map as $key=>$item) - { - if(!strpos(strtolower($key),$compatibility)){ - $name = str_replace('.php', '', $item); - if(!getIgnoreController($name)){ - $controllers[] = [ - 'name' => $name, - 'path' => '', - 'methods' => get_class_methods('App\Controllers\\'.$name) - ]; - } - }else{ - foreach ($item as $subitem){ - $name = str_replace('.php', '', $subitem); - if(!getIgnoreController($name)) { - $controllers[] = [ - 'name' => $name, - 'path' => $key, - 'methods' => get_class_methods('App\Controllers\\' . str_replace('/', '\\', $key) . $name) - ]; - } - } - } - } - }else{ - $array = explode('/',$controller); - $dir = count($array) > 1 ? $array[0] : ''; - $name = count($array) > 1 ? '\\'.$array[1] : $array[0]; - $controllers[] = [ - 'name' => $name, - 'path' => $dir, - 'methods' => get_class_methods('App\Controllers\\'.str_replace('/','\\',$dir).$name) - ]; - } - return $controllers??[]; - } catch (Exception $e) { - return []; - } -} - - -// IMN -function getCurrentLanguageFlag(){ - try { - $session = session(); - - if($session->get('lang') == 'en'){ - return "fi-gb"; - }else{ - return "fi-es"; - } - } catch (Exception $e) { - return "fi-es"; - } -} - - -function getAllClassFolder($folder = null){ - try { - helper('filesystem'); - helper('directory'); - - if(!empty($folder)){ - $map = directory_map(APPPATH.'Controllers'); - foreach ($map as $key=>$item) - { - if(strtolower(PHP_OS) == 'linux'){ - $compatibility = '/'; - }else{ - $compatibility = '\\'; - } - if(str_replace($compatibility,'',strtolower($key)) == strtolower($folder)){ - foreach ($item as $subitem){ - $name = str_replace('.php', '', $subitem); - $controllers[] = [ - 'name' => $name, - 'path' => $key, - 'methods' => get_class_methods('App\Controllers\\'.str_replace('/','\\',$key).$name) - ]; - } - } - } - } - return $controllers??[]; - } catch (Exception $e) { - return []; - } -} - -function getAllFolder(){ - try { - helper('filesystem'); - helper('directory'); - $map = directory_map(APPPATH.'Controllers',1); - if(strtolower(PHP_OS) == 'linux'){ - $compatibility = '/'; - }else{ - $compatibility = '\\'; - } - foreach ($map as $item) { - if(strpos(strtolower($item),$compatibility)){ - $folders[] = str_replace($compatibility,"",$item); - } - } - return $folders??[]; - } catch (Exception $e) { - return []; - } -} - - - -function getIgnoreController($controller) -{ - try { - $loginAuthFilter = new \App\Filters\LoginAuthFilter(); - foreach ($loginAuthFilter->whiteListController() as $item){ - if($controller == $item){ - return true; - } - } - return false; - } catch (Exception $e) { - return []; - } -} - -function getIgnoreMethod($method) -{ - try { - $loginAuthFilter = new \App\Filters\LoginAuthFilter(); - foreach ($loginAuthFilter->whiteListMethod() as $item){ - if($method == $item){ - return true; - } - } - return false; - } catch (Exception $e) { - return []; - } -} - -function getDictionary($word=''){ - try { - $dictionary = [ - 'index' => lang("App.permisos_index"), - 'view' => lang("App.permisos_view"), - 'add' => lang("App.permisos_add"), - 'edit' => lang("App.permisos_editar"), - 'delete' => lang("App.permisos_del"), - 'store' => lang("App.permisos_save"), - 'import' => lang("App.permisos_import"), - 'export' => lang("App.permisos_export"), - - 'Profile' => lang("App.permisos_perfil"), - 'Activity' => lang("App.permisos_actividad"), - 'Settings' => lang("App.permisos_configuracion"), - 'my' => lang("App.permisos_my"), - 'Notification' => lang("App.permisos_notificacion"), - - 'Users' => lang("App.permisos_usuarios"), - 'User' => lang("App.permisos_usuario"), - 'Group' => lang("App.permisos_roles"), - - 'Logistica' => lang("App.permisos_logistica"), - - 'Tarifas' => lang("App.permisos_tarifas"), - 'Tarifapreimpresion' => lang("App.permisos_tarifapreimpresion"), - 'Tarifamanipulado' => lang("App.permisos_tarifamanipulado"), - 'Tarifapapelcompra' => lang("App.permisos_tarifapapelcompra"), - 'Tarifaacabado' => lang("App.permisos_tarifaacabado"), - 'Tarifapapeldefecto' => lang("App.permisos_tarifapapeldefecto"), - 'Tarifaenvio' => lang("App.permisos_tarifaenvio"), - 'Tarifaimpresion' => lang("App.permisos_tarifaimpresion"), - - 'Configuracion' => lang("App.permisos_configuracion"), - 'Tareaservicio' => lang("App.permisos_tareasservicio"), - 'Formaspago' => lang("App.permisos_formaspago"), - 'Papelgenerico' => lang("App.permisos_papelgenerico"), - 'Tiposimpresion' => lang("App.permisos_tiposimpresion"), - 'Trabajo' => lang("App.permisos_trabajo"), - 'Maquina' => lang("App.permisos_maquina"), - 'Tamaniolibros' => lang("App.permisos_tamaniolibros"), - 'Imposiciones' => lang("App.permisos_imposiciones"), - 'Seriefactura' => lang("App.permisos_seriefactura"), - 'Tamanioformatos' => lang("App.permisos_tamanioformatos"), - 'Serviciocliente' => lang("App.permisos_serviciocliente"), - 'Calendario' => lang("App.permisos_calendario"), - 'Correo' => lang("App.permisos_correo"), - 'Paises' => lang("App.permisos_paises"), - 'Tipologias' => lang("App.permisos_tipologias"), - - 'Presupuestos' => lang("App.permisos_presupuestos"), - 'Presupuesto' => lang("App.permisos_presupuestos"), - 'Presupuestomaquetacion' => lang("App.permisos_presupuestomaquetacion"), - - 'Catalogo' => lang("App.permisos_catalogo"), - - 'Cliente' => lang("App.permisos_clientes"), - 'Tarifacliente' => lang("App.permisos_tarifacliente"), - - 'Proveedores' => lang("App.permisos_proveedores"), - 'Proveedor' => lang("App.permisos_proveedores"), - - 'Informes' => lang("App.permisos_informes"), - 'Informe' => lang("App.permisos_informes"), - - 'Facturacion' => lang("App.permisos_facturación"), - 'Albaran' => lang("App.permisos_albaran"), - 'Factura' => lang("App.permisos_facturas"), - - 'Pedidos' => lang("App.permisos_pedidos"), - 'Pedido' => lang("App.permisos_pedidos"), - - 'Serviciosdigitalizacion' => lang("App.permisos_digitalización"), - 'Digitalizacion' => lang("App.permisos_digitalización"), - - 'Produccion' => lang("App.permisos_produccion"), - 'Ordentrabajomaquetacion' => lang("App.permisos_ordentrabajomaquetacion"), - 'Ordenmaquina' => lang("App.permisos_ordenmaquina"), - 'Pedidoproduccion' => lang("App.permisos_pedidoproduccion"), - 'Ordentrabajo' => lang("App.permisos_ordentrabajo"), - - 'oauth' => lang("App.group_rules_label_oauth"), - 'template' => lang("App.group_rules_label_template"), - 'all' => lang("App.group_rules_label_all"), - 'oauth_store' => lang("App.group_rules_label_oauth_store"), - 'template_store' => lang("App.group_rules_label_template_store"), - - ]; - return array_key_exists($word,$dictionary)?$dictionary[$word] : $word; - } catch (Exception $e) { - return ''; - } -} - -function getMenuControl(){ - try { - $getClass = getAllClass(); - $getRules = json_decode(session()->get('rules')??'[]'); - foreach ($getClass as $item){ - foreach ($getRules as $key=>$value){ - if($key == $item['name']){ - $item['methods'] = $value; - $data[] = $item; - } - } - } - return $data??[]; - } catch (Exception $e) { - session()->setFlashdata('alert', 'error_acesso'); - return []; - } -} - -function allowMenuSection(array $array, array $keys, $method){ - try{ - $value = false; - foreach($keys as $key){ - if (count($temp=getArrayItem($array,'name',$key)) > 0){ - if (count(getArrayItem($temp,'methods','index',true)) > 0){ - $value = true; - } - } - } - return $value; - - } catch (Exception $e) { - return []; - } -} - -function getArrayItem(array $array, $key, $word, $isArray=false) -{ - try { - foreach ($array as $item){ - if ($isArray){ - foreach ($item[$key] as $subitem){ - if($subitem == $word){ - $data[]=$subitem; - } - } - }else{ - if($item[$key] == $word){ - $data[]=$item; - } - } - } - return $data??[]; - } catch (Exception $e) { - return []; - } -} - -//////////////////////////////////////////////////// -/// Notification Messages -//////////////////////////////////////////////////// - -function formAlert() -{ - $session = session(); - $alert = $session->getFlashdata('error'); - $validation = \Config\Services::validation()->listErrors(); - if (!empty($alert)){ - return '
'. - ' '. $validation . - '
'; - } -} - -function sweetAlert() -{ - try { - $session = session(); - $alert = $session->getFlashdata('sweet'); - if (count((array)$alert) == 2){ - return ""; - } - if (count((array)$alert) == 4){ - return ""; - } - }catch (Exception $ex){ - } -} - -function toastAlert() -{ - try { - $session = session(); - $alert = $session->getFlashdata('toast'); - if (count((array)$alert) == 3) { - return ""; - } - }catch (Exception $ex){ - } -} - -//////////////////////////////////////////////////// -/// Security -//////////////////////////////////////////////////// - -function generatePassword($length = 8) { - $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_!@#$%&*()-+{[]}'; - $count = mb_strlen($chars); - for ($i = 0, $result = ''; $i < $length; $i++) { - $index = Rand(0, $count - 1); - $result .= mb_substr($chars, $index, 1); - } - return $result; -} - -//////////////////////////////////////////////////// -/// Others -//////////////////////////////////////////////////// - -function now_db() { - $unixdatetime = time(); - return strftime("%Y-%m-%d %H:%M:%S", $unixdatetime); -} - -function escape_value($value='') { - $value = strip_tags(htmlentities($value)); - return filter_var($value, FILTER_SANITIZE_STRING); -} - -function escape_only($value='') { - $value = strip_tags(htmlentities($value), '

'); - return filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS); -} - -function unescape($value='') { - //return html_entity_decode($value,null,'UTF-8');; - return html_entity_decode($value,ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401,'UTF-8'); -} - -function redirect_to( $location = NULL ) { - if ($location != NULL) { - header("Location: {$location}"); - exit; - } -} - -function momentDateJS() { - $format = session()->get('settings')['default_date_format']; - switch ($format) { - case "Y-m-d": - return "YYYY-MM-DD"; - case "d-m-Y": - return "DD-MM-YYYY"; - case "d/m/Y": - return "DD/MM/YYYY"; - case "m-d-Y": - return "MM-DD-YYYY"; - case "m/d/Y": - return "MM/DD/YYYY"; - default: - return ""; - } -} - -function momentDateTimeJS() { - $format = session()->get('settings')['default_date_format']; - switch ($format) { - case "Y-m-d": - return "YYYY-MM-DD HH:mm:ss"; - case "d-m-Y": - return "DD-MM-YYYY HH:mm:ss"; - case "d/m/Y": - return "DD/MM/YYYY HH:mm:ss"; - case "m-d-Y": - return "MM-DD-YYYY HH:mm:ss"; - case "m/d/Y": - return "MM/DD/YYYY HH:mm:ss"; - default: - return ""; - } -} - -function dateFormatWeb($date) { - $format = session()->get('settings')['default_date_format']; - switch ($format) { - case "Y-m-d": - return $date; - case "d-m-Y": - case "d/m/Y": - case "m-d-Y": - case "m/d/Y": - $phpDate = strtotime($date); - if(strlen($date) > 10){ - return date( $format.' H:i:s', $phpDate); - }else{ - return date( $format, $phpDate); - } - default: - return null; - } -} - -function dateFormatMysql($date) { - $format = session()->get('settings')['default_date_format']; - switch ($format) { - case "Y-m-d": - return $date; - case "d-m-Y": - $dateTimeSplit = explode(' ',$date); - $dateSplit = explode('-',$dateTimeSplit[0]); - if(count($dateTimeSplit) > 1){ - return $dateSplit[2].'-'.$dateSplit[1].'-'.$dateSplit[0].' '. $dateTimeSplit[1]; - }else{ - return $dateSplit[2].'-'.$dateSplit[1].'-'.$dateSplit[0]; - } - case "d/m/Y": - $dateTimeSplit = explode(' ',$date); - $dateSplit = explode('/',$dateTimeSplit[0]); - if(count($dateTimeSplit) > 1){ - return $dateSplit[2].'-'.$dateSplit[1].'-'.$dateSplit[0].' '. $dateTimeSplit[1]; - }else{ - return $dateSplit[2].'-'.$dateSplit[1].'-'.$dateSplit[0]; - } - case "m-d-Y": - $dateTimeSplit = explode(' ',$date); - $dateSplit = explode('-',$dateTimeSplit[0]); - if(count($dateTimeSplit) > 1){ - return $dateSplit[2].'-'.$dateSplit[0].'-'.$dateSplit[1].' '. $dateTimeSplit[1]; - }else{ - return $dateSplit[2].'-'.$dateSplit[0].'-'.$dateSplit[1]; - } - case "m/d/Y": - $dateTimeSplit = explode(' ',$date); - $dateSplit = explode('/',$dateTimeSplit[0]); - if(count($dateTimeSplit) > 1){ - return $dateSplit[2].'-'.$dateSplit[0].'-'.$dateSplit[1].' '. $dateTimeSplit[1]; - }else { - return $dateSplit[2] . '-' . $dateSplit[0] . '-' . $dateSplit[1]; - } - default: - return null; - } -} - -function langJS() { - $lang = session()->get('lang')??'en'; - switch ($lang) { - case "pt": - return "pt-br"; - default: - return $lang; - } -} - -function socialBG() { - return [ - "facebook" => "bg-facebook", - "linkedin" => "bg-linkedin", - "google" => "bg-google-plus", - "youtube" => "bg-youtube", - "twitter" => "bg-twitter", - "instagram" => "bg-instagram", - "tiktok" => "bg-tiktok", - "whatsapp" => "bg-whatsapp", - "website" => "bg-website", - "api" => "bg-api", - "github" => "bg-github", - "slack" => "bg-slack", - "spotify" => "btn-spotify", - "reddit" => "btn-reddit", - "discord" => "btn-discord", - "dribbble" => "btn-dribbble", - "dropbox" => "btn-dropbox", - "gitlab" => "btn-gitlab", - "tumblr" => "btn-tumblr", - "strava" => "btn-strava", - "twitch" => "btn-twitch", - "vkontakte" => "btn-vk", - "wordpress" => "btn-wordpress", - "yahoo" => "btn-yahoo", - "bitbucket" => "btn-bitbucket", - "wechat" => "btn-wechat", - ]; -} -function keywordEmail() { - return [ - 'user_first_name', - 'user_last_name', - 'user_date_birth', - 'user_address', - 'user_city', - 'user_state', - 'user_country', - 'user_zip_code', - 'user_mobile', - 'user_email', - 'user_picture' - ]; -} - -function templateSelect($templates=[],$name='',$type='') { - foreach ($templates as $item){ - if($item['type'] == $type){ - if($item['name'] == $name){ - return $item; - } - } - } - return null; -} - -function get_filter_datatables_columns($request){ - $columnSearch = array(); - - if ( isset( $request['columns'] ) ) { - for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) { - $requestColumn = $request['columns'][$i]; - - $str = $requestColumn['search']['value']; - - if ( $requestColumn['searchable'] == 'true' && - $str != '' ) { - array_push($columnSearch, [$i, $requestColumn['data'], $str]); - } - } - } - - return $columnSearch; -} - -// Devuelve true si los intervalos (a1,a2) (b1,b2) se solapan -// https://stackoverflow.com/questions/3269434/whats-the-most-efficient-way-to-test-if-two-ranges-overlap -function check_overlap($a1, $a2, $b1, $b2){ - - if (max($a2, $b2) - min($a1, $b1) <= ($a2 - $a1) + ($b2 - $b1)) - return true; - return false; -} - -function check_overlap_with_extremos($a1, $a2, $b1, $b2){ - - if (max($a2, $b2) - min($a1, $b1) < ($a2 - $a1) + ($b2 - $b1)) - return true; - return false; -} - -function version() { - return "1.2.1"; -} \ No newline at end of file diff --git a/ci4/app/Services/FTPService.php b/ci4/app/Services/FTPService.php new file mode 100644 index 00000000..fa4650cc --- /dev/null +++ b/ci4/app/Services/FTPService.php @@ -0,0 +1,48 @@ +ftp = new FtpClient(); + $this->ftp_config = config("FTP"); + $this->host = $this->ftp_config->host; + $this->username = $this->ftp_config->username; + $this->password = $this->ftp_config->password; + $this->base_dir = $this->ftp_config->base_dir; + } + /** + * Upload the content of $filename to the base directory declared in App\Config\FTP.php + * + * @param string $content + * @param string $filename + * @return boolean + */ + public function uploadXML(string $content, string $filename): bool + { + try { + $remotePath = implode("/", [$this->base_dir, $filename]); + $this->ftp->connect(host: $this->host, port: $this->port); + $this->ftp->login(username: $this->username, password: $this->password); + $this->ftp->putFromString($remotePath, $content); + return true; + } catch (\Throwable $th) { + log_message('error',$th->getMessage()); + return false; + } + } +} diff --git a/ci4/app/Services/PedidoXMLService.php b/ci4/app/Services/PedidoXMLService.php index b09edaa1..3ece7f7c 100644 --- a/ci4/app/Services/PedidoXMLService.php +++ b/ci4/app/Services/PedidoXMLService.php @@ -9,6 +9,7 @@ use App\Models\Pedidos\PedidoLineaModel; use App\Models\Presupuestos\PresupuestoModel; use DOMDocument; use DOMNode; +use FTP; class PedidoXMLService extends BaseService { @@ -168,8 +169,15 @@ class PedidoXMLService extends BaseService $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); + $file_name = PedidoXMLService::generate_xml_file_name($file_has_suffix); + $ftp = service('FTPService'); + $ftp->uploadXML($xml->textContent,$file_name); return $data; } + protected static function generate_xml_file_name(string $hash) : string + { + return implode("",["Safekat_",$hash,".xml"]); + } protected static function get_color_interior($pre_linea): ?string { $color_interior = null; From eb4ea31cefdf8186378263fc5ffbfe498cd7afc2 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Wed, 28 Aug 2024 22:28:49 +0200 Subject: [PATCH 07/24] add php ftp lib --- ci4/composer.json | 3 ++- ci4/composer.lock | 54 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/ci4/composer.json b/ci4/composer.json index 8fe6ffc5..1b6032ae 100755 --- a/ci4/composer.json +++ b/ci4/composer.json @@ -13,7 +13,8 @@ "php": "^8.2", "codeigniter4/framework": "^4.0", "codeigniter4/shield": "^1.0", - "dompdf/dompdf": "^2.0" + "dompdf/dompdf": "^2.0", + "nicolab/php-ftp-client": "^2.0" }, "require-dev": { "fakerphp/faker": "^1.9", diff --git a/ci4/composer.lock b/ci4/composer.lock index 4596b329..72107154 100644 --- a/ci4/composer.lock +++ b/ci4/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b2eee64c89c81ed0f0edef73637b9199", + "content-hash": "ad46e8d1c155c881b11c8b8054611788", "packages": [ { "name": "codeigniter4/framework", @@ -399,6 +399,58 @@ }, "time": "2024-03-31T07:05:07+00:00" }, + { + "name": "nicolab/php-ftp-client", + "version": "v2.0.2", + "source": { + "type": "git", + "url": "https://github.com/Nicolab/php-ftp-client.git", + "reference": "a1d007c8b203895611f68b0da314281d4a5c3d49" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Nicolab/php-ftp-client/zipball/a1d007c8b203895611f68b0da314281d4a5c3d49", + "reference": "a1d007c8b203895611f68b0da314281d4a5c3d49", + "shasum": "" + }, + "require": { + "ext-ftp": "*", + "php": ">=5.4" + }, + "type": "library", + "autoload": { + "psr-0": { + "FtpClient": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Tallefourtane", + "email": "dev@nicolab.net", + "homepage": "http://nicolab.net" + } + ], + "description": "A flexible FTP and SSL-FTP client for PHP. This lib provides helpers easy to use to manage the remote files.", + "homepage": "https://github.com/Nicolab/php-ftp-client", + "keywords": [ + "file", + "ftp", + "helper", + "lib", + "server", + "sftp", + "ssl", + "ssl-ftp" + ], + "support": { + "source": "https://github.com/Nicolab/php-ftp-client/tree/v2.0.2" + }, + "time": "2022-08-10T11:09:32+00:00" + }, { "name": "phenx/php-font-lib", "version": "0.5.6", From 251268fb246999751f5948bcb5ca4f5652f319bf Mon Sep 17 00:00:00 2001 From: amazuecos Date: Thu, 29 Aug 2024 01:02:15 +0200 Subject: [PATCH 08/24] add Libraries path --- ci4/app/Config/Autoload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ci4/app/Config/Autoload.php b/ci4/app/Config/Autoload.php index dbe37194..acc365fc 100755 --- a/ci4/app/Config/Autoload.php +++ b/ci4/app/Config/Autoload.php @@ -46,6 +46,7 @@ class Autoload extends AutoloadConfig public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', + 'Libraries' => APPPATH . 'Libraries', 'Dompdf' => APPPATH . 'ThirdParty/dompdf/src', ]; From c3248cd3ec7ed46c16faff8215fc0bd551310812 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Thu, 29 Aug 2024 01:02:33 +0200 Subject: [PATCH 09/24] add FTP Config file --- ci4/app/Config/FTP.php | 50 +++++------------------------------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/ci4/app/Config/FTP.php b/ci4/app/Config/FTP.php index f3faf0a0..d3b963f1 100644 --- a/ci4/app/Config/FTP.php +++ b/ci4/app/Config/FTP.php @@ -6,53 +6,13 @@ use CodeIgniter\Config\BaseConfig; class FTP extends BaseConfig { - /** - * Lets you choose which connection group to - * use if no other is specified. - */ - public string $defaultGroup = 'default'; - /** - * The default ftp connection. - */ - public array $default = [ - "host" => "sk-ftp", - "user" => "admin", - "password" => "A77h3b0X4OA2rOYAf4w2", - "base_dir" => "/home/admin/safekat" # FTP server directory - ]; - /** - * This database connection is used when - * running PHPUnit database tests. - */ - public array $production = [ - "host" => "sk-ftp", - "user" => "admin", - "password" => "A77h3b0X4OA2rOYAf4w2", - "base_dir" => "/home/admin/safekat" # FTP server directory - ]; - /** - * This database connection is used when - * running PHPUnit database tests. - */ - public array $development = [ - "host" => "sk-ftp", - "port" => "21000", - "user" => "admin", - "password" => "A77h3b0X4OA2rOYAf4w2", - "base_dir" => "/home/admin/safekat" # FTP server directory + public string $host = "10.5.0.6"; + public int $port = 21; + public string $username = "admin"; + public string $password = "A77h3b0X4OA2rOYAf4w2"; + public string $base_dir = "/home/admin/safekat"; # FTP server directory - ]; - public function __construct() - { - parent::__construct(); - // Ensure that we always set the database group to 'tests' if - // we are currently running an automated test suite, so that - // we don't overwrite live data on accident. - if (ENVIRONMENT === 'development') { - $this->defaultGroup = 'development'; - } - } } From 01cc74ed60293d526ca11b009daa40f7eb71a402 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Thu, 29 Aug 2024 01:03:00 +0200 Subject: [PATCH 10/24] delete ftp method --- ci4/app/Config/Services.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ci4/app/Config/Services.php b/ci4/app/Config/Services.php index 572aec46..a802b838 100755 --- a/ci4/app/Config/Services.php +++ b/ci4/app/Config/Services.php @@ -30,11 +30,4 @@ class Services extends BaseService * return new \CodeIgniter\Example(); * } */ - public static function ftp(bool $getShared = true): FTPService - { - if ($getShared) { - return static::getSharedInstance('ftp'); - } - return new FTPService(); - } } From 8e5d208bbf9b50ff97787a809ba5059cfc6dcdec Mon Sep 17 00:00:00 2001 From: amazuecos Date: Thu, 29 Aug 2024 01:03:29 +0200 Subject: [PATCH 11/24] add general_helper, deleted by error --- ci4/app/Helpers/general_helper.php | 683 +++++++++++++++++++++++++++++ 1 file changed, 683 insertions(+) create mode 100644 ci4/app/Helpers/general_helper.php diff --git a/ci4/app/Helpers/general_helper.php b/ci4/app/Helpers/general_helper.php new file mode 100644 index 00000000..e0578134 --- /dev/null +++ b/ci4/app/Helpers/general_helper.php @@ -0,0 +1,683 @@ +$value){ + if($key==$section){ + foreach($value as $item){ + if($item==$method){ + return true; + } + } + } + } + return false; + + /*var_dump($key. ' '. $value[0]); + + echo '

';
+        $rules = 
+        echo '
'; + dd();*/ +} + +function getAllClass($controller = null){ + try { + helper('filesystem'); + helper('directory'); + if(strtolower(PHP_OS) == 'linux'){ + $compatibility = '/'; + }else{ + $compatibility = '\\'; + } + if(empty($controller)){ + $map = directory_map(APPPATH.'Controllers'); + foreach ($map as $key=>$item) + { + if(!strpos(strtolower($key),$compatibility)){ + $name = str_replace('.php', '', $item); + if(!getIgnoreController($name)){ + $controllers[] = [ + 'name' => $name, + 'path' => '', + 'methods' => get_class_methods('App\Controllers\\'.$name) + ]; + } + }else{ + foreach ($item as $subitem){ + $name = str_replace('.php', '', $subitem); + if(!getIgnoreController($name)) { + $controllers[] = [ + 'name' => $name, + 'path' => $key, + 'methods' => get_class_methods('App\Controllers\\' . str_replace('/', '\\', $key) . $name) + ]; + } + } + } + } + }else{ + $array = explode('/',$controller); + $dir = count($array) > 1 ? $array[0] : ''; + $name = count($array) > 1 ? '\\'.$array[1] : $array[0]; + $controllers[] = [ + 'name' => $name, + 'path' => $dir, + 'methods' => get_class_methods('App\Controllers\\'.str_replace('/','\\',$dir).$name) + ]; + } + return $controllers??[]; + } catch (Exception $e) { + return []; + } +} + + +// IMN +function getCurrentLanguageFlag(){ + try { + $session = session(); + + if($session->get('lang') == 'en'){ + return "fi-gb"; + }else{ + return "fi-es"; + } + } catch (Exception $e) { + return "fi-es"; + } +} + + +function getAllClassFolder($folder = null){ + try { + helper('filesystem'); + helper('directory'); + + if(!empty($folder)){ + $map = directory_map(APPPATH.'Controllers'); + foreach ($map as $key=>$item) + { + if(strtolower(PHP_OS) == 'linux'){ + $compatibility = '/'; + }else{ + $compatibility = '\\'; + } + if(str_replace($compatibility,'',strtolower($key)) == strtolower($folder)){ + foreach ($item as $subitem){ + $name = str_replace('.php', '', $subitem); + $controllers[] = [ + 'name' => $name, + 'path' => $key, + 'methods' => get_class_methods('App\Controllers\\'.str_replace('/','\\',$key).$name) + ]; + } + } + } + } + return $controllers??[]; + } catch (Exception $e) { + return []; + } +} + +function getAllFolder(){ + try { + helper('filesystem'); + helper('directory'); + $map = directory_map(APPPATH.'Controllers',1); + if(strtolower(PHP_OS) == 'linux'){ + $compatibility = '/'; + }else{ + $compatibility = '\\'; + } + foreach ($map as $item) { + if(strpos(strtolower($item),$compatibility)){ + $folders[] = str_replace($compatibility,"",$item); + } + } + return $folders??[]; + } catch (Exception $e) { + return []; + } +} + + + +function getIgnoreController($controller) +{ + try { + $loginAuthFilter = new \App\Filters\LoginAuthFilter(); + foreach ($loginAuthFilter->whiteListController() as $item){ + if($controller == $item){ + return true; + } + } + return false; + } catch (Exception $e) { + return []; + } +} + +function getIgnoreMethod($method) +{ + try { + $loginAuthFilter = new \App\Filters\LoginAuthFilter(); + foreach ($loginAuthFilter->whiteListMethod() as $item){ + if($method == $item){ + return true; + } + } + return false; + } catch (Exception $e) { + return []; + } +} + +function getDictionary($word=''){ + try { + $dictionary = [ + 'index' => lang("App.permisos_index"), + 'view' => lang("App.permisos_view"), + 'add' => lang("App.permisos_add"), + 'edit' => lang("App.permisos_editar"), + 'delete' => lang("App.permisos_del"), + 'store' => lang("App.permisos_save"), + 'import' => lang("App.permisos_import"), + 'export' => lang("App.permisos_export"), + + 'Profile' => lang("App.permisos_perfil"), + 'Activity' => lang("App.permisos_actividad"), + 'Settings' => lang("App.permisos_configuracion"), + 'my' => lang("App.permisos_my"), + 'Notification' => lang("App.permisos_notificacion"), + + 'Users' => lang("App.permisos_usuarios"), + 'User' => lang("App.permisos_usuario"), + 'Group' => lang("App.permisos_roles"), + + 'Logistica' => lang("App.permisos_logistica"), + + 'Tarifas' => lang("App.permisos_tarifas"), + 'Tarifapreimpresion' => lang("App.permisos_tarifapreimpresion"), + 'Tarifamanipulado' => lang("App.permisos_tarifamanipulado"), + 'Tarifapapelcompra' => lang("App.permisos_tarifapapelcompra"), + 'Tarifaacabado' => lang("App.permisos_tarifaacabado"), + 'Tarifapapeldefecto' => lang("App.permisos_tarifapapeldefecto"), + 'Tarifaenvio' => lang("App.permisos_tarifaenvio"), + 'Tarifaimpresion' => lang("App.permisos_tarifaimpresion"), + + 'Configuracion' => lang("App.permisos_configuracion"), + 'Tareaservicio' => lang("App.permisos_tareasservicio"), + 'Formaspago' => lang("App.permisos_formaspago"), + 'Papelgenerico' => lang("App.permisos_papelgenerico"), + 'Tiposimpresion' => lang("App.permisos_tiposimpresion"), + 'Trabajo' => lang("App.permisos_trabajo"), + 'Maquina' => lang("App.permisos_maquina"), + 'Tamaniolibros' => lang("App.permisos_tamaniolibros"), + 'Imposiciones' => lang("App.permisos_imposiciones"), + 'Seriefactura' => lang("App.permisos_seriefactura"), + 'Tamanioformatos' => lang("App.permisos_tamanioformatos"), + 'Serviciocliente' => lang("App.permisos_serviciocliente"), + 'Calendario' => lang("App.permisos_calendario"), + 'Correo' => lang("App.permisos_correo"), + 'Paises' => lang("App.permisos_paises"), + 'Tipologias' => lang("App.permisos_tipologias"), + + 'Presupuestos' => lang("App.permisos_presupuestos"), + 'Presupuesto' => lang("App.permisos_presupuestos"), + 'Presupuestomaquetacion' => lang("App.permisos_presupuestomaquetacion"), + + 'Catalogo' => lang("App.permisos_catalogo"), + + 'Cliente' => lang("App.permisos_clientes"), + 'Tarifacliente' => lang("App.permisos_tarifacliente"), + + 'Proveedores' => lang("App.permisos_proveedores"), + 'Proveedor' => lang("App.permisos_proveedores"), + + 'Informes' => lang("App.permisos_informes"), + 'Informe' => lang("App.permisos_informes"), + + 'Facturacion' => lang("App.permisos_facturación"), + 'Albaran' => lang("App.permisos_albaran"), + 'Factura' => lang("App.permisos_facturas"), + + 'Pedidos' => lang("App.permisos_pedidos"), + 'Pedido' => lang("App.permisos_pedidos"), + + 'Serviciosdigitalizacion' => lang("App.permisos_digitalización"), + 'Digitalizacion' => lang("App.permisos_digitalización"), + + 'Produccion' => lang("App.permisos_produccion"), + 'Ordentrabajomaquetacion' => lang("App.permisos_ordentrabajomaquetacion"), + 'Ordenmaquina' => lang("App.permisos_ordenmaquina"), + 'Pedidoproduccion' => lang("App.permisos_pedidoproduccion"), + 'Ordentrabajo' => lang("App.permisos_ordentrabajo"), + + 'oauth' => lang("App.group_rules_label_oauth"), + 'template' => lang("App.group_rules_label_template"), + 'all' => lang("App.group_rules_label_all"), + 'oauth_store' => lang("App.group_rules_label_oauth_store"), + 'template_store' => lang("App.group_rules_label_template_store"), + + ]; + return array_key_exists($word,$dictionary)?$dictionary[$word] : $word; + } catch (Exception $e) { + return ''; + } +} + +function getMenuControl(){ + try { + $getClass = getAllClass(); + $getRules = json_decode(session()->get('rules')??'[]'); + foreach ($getClass as $item){ + foreach ($getRules as $key=>$value){ + if($key == $item['name']){ + $item['methods'] = $value; + $data[] = $item; + } + } + } + return $data??[]; + } catch (Exception $e) { + session()->setFlashdata('alert', 'error_acesso'); + return []; + } +} + +function allowMenuSection(array $array, array $keys, $method){ + try{ + $value = false; + foreach($keys as $key){ + if (count($temp=getArrayItem($array,'name',$key)) > 0){ + if (count(getArrayItem($temp,'methods','index',true)) > 0){ + $value = true; + } + } + } + return $value; + + } catch (Exception $e) { + return []; + } +} + +function getArrayItem(array $array, $key, $word, $isArray=false) +{ + try { + foreach ($array as $item){ + if ($isArray){ + foreach ($item[$key] as $subitem){ + if($subitem == $word){ + $data[]=$subitem; + } + } + }else{ + if($item[$key] == $word){ + $data[]=$item; + } + } + } + return $data??[]; + } catch (Exception $e) { + return []; + } +} + +//////////////////////////////////////////////////// +/// Notification Messages +//////////////////////////////////////////////////// + +function formAlert() +{ + $session = session(); + $alert = $session->getFlashdata('error'); + $validation = \Config\Services::validation()->listErrors(); + if (!empty($alert)){ + return '
'. + ' '. $validation . + '
'; + } +} + +function sweetAlert() +{ + try { + $session = session(); + $alert = $session->getFlashdata('sweet'); + if (count((array)$alert) == 2){ + return ""; + } + if (count((array)$alert) == 4){ + return ""; + } + }catch (Exception $ex){ + } +} + +function toastAlert() +{ + try { + $session = session(); + $alert = $session->getFlashdata('toast'); + if (count((array)$alert) == 3) { + return ""; + } + }catch (Exception $ex){ + } +} + +//////////////////////////////////////////////////// +/// Security +//////////////////////////////////////////////////// + +function generatePassword($length = 8) { + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_!@#$%&*()-+{[]}'; + $count = mb_strlen($chars); + for ($i = 0, $result = ''; $i < $length; $i++) { + $index = Rand(0, $count - 1); + $result .= mb_substr($chars, $index, 1); + } + return $result; +} + +//////////////////////////////////////////////////// +/// Others +//////////////////////////////////////////////////// + +function now_db() { + $unixdatetime = time(); + return strftime("%Y-%m-%d %H:%M:%S", $unixdatetime); +} + +function escape_value($value='') { + $value = strip_tags(htmlentities($value)); + return filter_var($value, FILTER_SANITIZE_STRING); +} + +function escape_only($value='') { + $value = strip_tags(htmlentities($value), '

'); + return filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS); +} + +function unescape($value='') { + //return html_entity_decode($value,null,'UTF-8');; + return html_entity_decode($value,ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401,'UTF-8'); +} + +function redirect_to( $location = NULL ) { + if ($location != NULL) { + header("Location: {$location}"); + exit; + } +} + +function momentDateJS() { + $format = session()->get('settings')['default_date_format']; + switch ($format) { + case "Y-m-d": + return "YYYY-MM-DD"; + case "d-m-Y": + return "DD-MM-YYYY"; + case "d/m/Y": + return "DD/MM/YYYY"; + case "m-d-Y": + return "MM-DD-YYYY"; + case "m/d/Y": + return "MM/DD/YYYY"; + default: + return ""; + } +} + +function momentDateTimeJS() { + $format = session()->get('settings')['default_date_format']; + switch ($format) { + case "Y-m-d": + return "YYYY-MM-DD HH:mm:ss"; + case "d-m-Y": + return "DD-MM-YYYY HH:mm:ss"; + case "d/m/Y": + return "DD/MM/YYYY HH:mm:ss"; + case "m-d-Y": + return "MM-DD-YYYY HH:mm:ss"; + case "m/d/Y": + return "MM/DD/YYYY HH:mm:ss"; + default: + return ""; + } +} + +function dateFormatWeb($date) { + $format = session()->get('settings')['default_date_format']; + switch ($format) { + case "Y-m-d": + return $date; + case "d-m-Y": + case "d/m/Y": + case "m-d-Y": + case "m/d/Y": + $phpDate = strtotime($date); + if(strlen($date) > 10){ + return date( $format.' H:i:s', $phpDate); + }else{ + return date( $format, $phpDate); + } + default: + return null; + } +} + +function dateFormatMysql($date) { + $format = session()->get('settings')['default_date_format']; + switch ($format) { + case "Y-m-d": + return $date; + case "d-m-Y": + $dateTimeSplit = explode(' ',$date); + $dateSplit = explode('-',$dateTimeSplit[0]); + if(count($dateTimeSplit) > 1){ + return $dateSplit[2].'-'.$dateSplit[1].'-'.$dateSplit[0].' '. $dateTimeSplit[1]; + }else{ + return $dateSplit[2].'-'.$dateSplit[1].'-'.$dateSplit[0]; + } + case "d/m/Y": + $dateTimeSplit = explode(' ',$date); + $dateSplit = explode('/',$dateTimeSplit[0]); + if(count($dateTimeSplit) > 1){ + return $dateSplit[2].'-'.$dateSplit[1].'-'.$dateSplit[0].' '. $dateTimeSplit[1]; + }else{ + return $dateSplit[2].'-'.$dateSplit[1].'-'.$dateSplit[0]; + } + case "m-d-Y": + $dateTimeSplit = explode(' ',$date); + $dateSplit = explode('-',$dateTimeSplit[0]); + if(count($dateTimeSplit) > 1){ + return $dateSplit[2].'-'.$dateSplit[0].'-'.$dateSplit[1].' '. $dateTimeSplit[1]; + }else{ + return $dateSplit[2].'-'.$dateSplit[0].'-'.$dateSplit[1]; + } + case "m/d/Y": + $dateTimeSplit = explode(' ',$date); + $dateSplit = explode('/',$dateTimeSplit[0]); + if(count($dateTimeSplit) > 1){ + return $dateSplit[2].'-'.$dateSplit[0].'-'.$dateSplit[1].' '. $dateTimeSplit[1]; + }else { + return $dateSplit[2] . '-' . $dateSplit[0] . '-' . $dateSplit[1]; + } + default: + return null; + } +} + +function langJS() { + $lang = session()->get('lang')??'en'; + switch ($lang) { + case "pt": + return "pt-br"; + default: + return $lang; + } +} + +function socialBG() { + return [ + "facebook" => "bg-facebook", + "linkedin" => "bg-linkedin", + "google" => "bg-google-plus", + "youtube" => "bg-youtube", + "twitter" => "bg-twitter", + "instagram" => "bg-instagram", + "tiktok" => "bg-tiktok", + "whatsapp" => "bg-whatsapp", + "website" => "bg-website", + "api" => "bg-api", + "github" => "bg-github", + "slack" => "bg-slack", + "spotify" => "btn-spotify", + "reddit" => "btn-reddit", + "discord" => "btn-discord", + "dribbble" => "btn-dribbble", + "dropbox" => "btn-dropbox", + "gitlab" => "btn-gitlab", + "tumblr" => "btn-tumblr", + "strava" => "btn-strava", + "twitch" => "btn-twitch", + "vkontakte" => "btn-vk", + "wordpress" => "btn-wordpress", + "yahoo" => "btn-yahoo", + "bitbucket" => "btn-bitbucket", + "wechat" => "btn-wechat", + ]; +} +function keywordEmail() { + return [ + 'user_first_name', + 'user_last_name', + 'user_date_birth', + 'user_address', + 'user_city', + 'user_state', + 'user_country', + 'user_zip_code', + 'user_mobile', + 'user_email', + 'user_picture' + ]; +} + +function templateSelect($templates=[],$name='',$type='') { + foreach ($templates as $item){ + if($item['type'] == $type){ + if($item['name'] == $name){ + return $item; + } + } + } + return null; +} + +function get_filter_datatables_columns($request){ + $columnSearch = array(); + + if ( isset( $request['columns'] ) ) { + for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) { + $requestColumn = $request['columns'][$i]; + + $str = $requestColumn['search']['value']; + + if ( $requestColumn['searchable'] == 'true' && + $str != '' ) { + array_push($columnSearch, [$i, $requestColumn['data'], $str]); + } + } + } + + return $columnSearch; +} + +// Devuelve true si los intervalos (a1,a2) (b1,b2) se solapan +// https://stackoverflow.com/questions/3269434/whats-the-most-efficient-way-to-test-if-two-ranges-overlap +function check_overlap($a1, $a2, $b1, $b2){ + + if (max($a2, $b2) - min($a1, $b1) <= ($a2 - $a1) + ($b2 - $b1)) + return true; + return false; +} + +function check_overlap_with_extremos($a1, $a2, $b1, $b2){ + + if (max($a2, $b2) - min($a1, $b1) < ($a2 - $a1) + ($b2 - $b1)) + return true; + return false; +} + +function version() { + return "1.2.1"; +} \ No newline at end of file From c8335b5740a59d11b811c56cf0bf4f909f9b2296 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Thu, 29 Aug 2024 01:03:50 +0200 Subject: [PATCH 12/24] add SafekatFtpClient Library --- ci4/app/Libraries/SafekatFtpClient.php | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 ci4/app/Libraries/SafekatFtpClient.php diff --git a/ci4/app/Libraries/SafekatFtpClient.php b/ci4/app/Libraries/SafekatFtpClient.php new file mode 100644 index 00000000..a5ee2f7e --- /dev/null +++ b/ci4/app/Libraries/SafekatFtpClient.php @@ -0,0 +1,48 @@ +ftp = new FtpClient(); + $this->ftp_config = config("FTP"); + $this->host = $this->ftp_config->host; + $this->username = $this->ftp_config->username; + $this->password = $this->ftp_config->password; + $this->port = $this->ftp_config->port; + $this->base_dir = $this->ftp_config->base_dir; + } + /** + * Upload the content of $filename to the base directory declared in App\Config\FTP.php + * + * @param string $content + * @param string $filename + * @return boolean + */ + public function uploadXML(string $content, string $filename): bool + { + try { + $remotePath = implode("/", [$this->base_dir, $filename]); + $this->ftp->connect(host: $this->host, port: $this->port); + $this->ftp->login(username: $this->username, password: $this->password); + $this->ftp->putFromString($remotePath, $content); + return true; + } catch (\Throwable $th) { + throw $th; + log_message('error',$th->getMessage()); + return false; + } + } +} From 3a0011b49ac6a8a766af7d1986eb0b12a61ddf93 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Thu, 29 Aug 2024 01:04:10 +0200 Subject: [PATCH 13/24] delete FTPService, moved to Libraries --- ci4/app/Services/FTPService.php | 48 --------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 ci4/app/Services/FTPService.php diff --git a/ci4/app/Services/FTPService.php b/ci4/app/Services/FTPService.php deleted file mode 100644 index fa4650cc..00000000 --- a/ci4/app/Services/FTPService.php +++ /dev/null @@ -1,48 +0,0 @@ -ftp = new FtpClient(); - $this->ftp_config = config("FTP"); - $this->host = $this->ftp_config->host; - $this->username = $this->ftp_config->username; - $this->password = $this->ftp_config->password; - $this->base_dir = $this->ftp_config->base_dir; - } - /** - * Upload the content of $filename to the base directory declared in App\Config\FTP.php - * - * @param string $content - * @param string $filename - * @return boolean - */ - public function uploadXML(string $content, string $filename): bool - { - try { - $remotePath = implode("/", [$this->base_dir, $filename]); - $this->ftp->connect(host: $this->host, port: $this->port); - $this->ftp->login(username: $this->username, password: $this->password); - $this->ftp->putFromString($remotePath, $content); - return true; - } catch (\Throwable $th) { - log_message('error',$th->getMessage()); - return false; - } - } -} From 43fdafc09980058b47904536613eb30f293fa2a5 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Thu, 29 Aug 2024 01:04:44 +0200 Subject: [PATCH 14/24] upload xml to server by ftp --- ci4/app/Services/PedidoXMLService.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ci4/app/Services/PedidoXMLService.php b/ci4/app/Services/PedidoXMLService.php index 3ece7f7c..9af64ea1 100644 --- a/ci4/app/Services/PedidoXMLService.php +++ b/ci4/app/Services/PedidoXMLService.php @@ -2,14 +2,11 @@ namespace App\Services; -use App\Entities\Pedidos\PedidoEntity; +use DOMDocument; +use App\Libraries\SafekatFtpClient; use CodeIgniter\Config\BaseService; use App\Models\Pedidos\PedidoModel; -use App\Models\Pedidos\PedidoLineaModel; use App\Models\Presupuestos\PresupuestoModel; -use DOMDocument; -use DOMNode; -use FTP; class PedidoXMLService extends BaseService { @@ -170,8 +167,8 @@ class PedidoXMLService extends BaseService $xml->appendChild($xml_products_el); $file_has_suffix = hash('sha512',$data["pedido_cliente_presupuesto"]->pedidoId); $file_name = PedidoXMLService::generate_xml_file_name($file_has_suffix); - $ftp = service('FTPService'); - $ftp->uploadXML($xml->textContent,$file_name); + $ftp = new SafekatFtpClient(); + $ftp->uploadXML($xml->saveXML(),$file_name); return $data; } protected static function generate_xml_file_name(string $hash) : string From 121708b71c80d9ff6840ca4a81d331efe6f93ddc Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 2 Sep 2024 23:27:54 +0200 Subject: [PATCH 15/24] add package phpseclib/phpseclib for stfp --- ci4/composer.json | 3 +- ci4/composer.lock | 229 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 230 insertions(+), 2 deletions(-) diff --git a/ci4/composer.json b/ci4/composer.json index 1b6032ae..70688ebd 100755 --- a/ci4/composer.json +++ b/ci4/composer.json @@ -14,7 +14,8 @@ "codeigniter4/framework": "^4.0", "codeigniter4/shield": "^1.0", "dompdf/dompdf": "^2.0", - "nicolab/php-ftp-client": "^2.0" + "nicolab/php-ftp-client": "^2.0", + "phpseclib/phpseclib": "~3.0" }, "require-dev": { "fakerphp/faker": "^1.9", diff --git a/ci4/composer.lock b/ci4/composer.lock index 72107154..723c548f 100644 --- a/ci4/composer.lock +++ b/ci4/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ad46e8d1c155c881b11c8b8054611788", + "content-hash": "0cf49081609029ebf2165c9cebed577e", "packages": [ { "name": "codeigniter4/framework", @@ -451,6 +451,123 @@ }, "time": "2022-08-10T11:09:32+00:00" }, + { + "name": "paragonie/constant_time_encoding", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/paragonie/constant_time_encoding.git", + "reference": "df1e7fde177501eee2037dd159cf04f5f301a512" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/df1e7fde177501eee2037dd159cf04f5f301a512", + "reference": "df1e7fde177501eee2037dd159cf04f5f301a512", + "shasum": "" + }, + "require": { + "php": "^8" + }, + "require-dev": { + "phpunit/phpunit": "^9", + "vimeo/psalm": "^4|^5" + }, + "type": "library", + "autoload": { + "psr-4": { + "ParagonIE\\ConstantTime\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com", + "role": "Maintainer" + }, + { + "name": "Steve 'Sc00bz' Thomas", + "email": "steve@tobtu.com", + "homepage": "https://www.tobtu.com", + "role": "Original Developer" + } + ], + "description": "Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)", + "keywords": [ + "base16", + "base32", + "base32_decode", + "base32_encode", + "base64", + "base64_decode", + "base64_encode", + "bin2hex", + "encoding", + "hex", + "hex2bin", + "rfc4648" + ], + "support": { + "email": "info@paragonie.com", + "issues": "https://github.com/paragonie/constant_time_encoding/issues", + "source": "https://github.com/paragonie/constant_time_encoding" + }, + "time": "2024-05-08T12:36:18+00:00" + }, + { + "name": "paragonie/random_compat", + "version": "v9.99.100", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a", + "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a", + "shasum": "" + }, + "require": { + "php": ">= 7" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*", + "vimeo/psalm": "^1" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "polyfill", + "pseudorandom", + "random" + ], + "support": { + "email": "info@paragonie.com", + "issues": "https://github.com/paragonie/random_compat/issues", + "source": "https://github.com/paragonie/random_compat" + }, + "time": "2020-10-15T08:29:30+00:00" + }, { "name": "phenx/php-font-lib", "version": "0.5.6", @@ -541,6 +658,116 @@ }, "time": "2024-04-08T12:52:34+00:00" }, + { + "name": "phpseclib/phpseclib", + "version": "3.0.41", + "source": { + "type": "git", + "url": "https://github.com/phpseclib/phpseclib.git", + "reference": "621c73f7dcb310b61de34d1da4c4204e8ace6ceb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/621c73f7dcb310b61de34d1da4c4204e8ace6ceb", + "reference": "621c73f7dcb310b61de34d1da4c4204e8ace6ceb", + "shasum": "" + }, + "require": { + "paragonie/constant_time_encoding": "^1|^2|^3", + "paragonie/random_compat": "^1.4|^2.0|^9.99.99", + "php": ">=5.6.1" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "suggest": { + "ext-dom": "Install the DOM extension to load XML formatted public keys.", + "ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.", + "ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.", + "ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.", + "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations." + }, + "type": "library", + "autoload": { + "files": [ + "phpseclib/bootstrap.php" + ], + "psr-4": { + "phpseclib3\\": "phpseclib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jim Wigginton", + "email": "terrafrost@php.net", + "role": "Lead Developer" + }, + { + "name": "Patrick Monnerat", + "email": "pm@datasphere.ch", + "role": "Developer" + }, + { + "name": "Andreas Fischer", + "email": "bantu@phpbb.com", + "role": "Developer" + }, + { + "name": "Hans-Jürgen Petrich", + "email": "petrich@tronic-media.com", + "role": "Developer" + }, + { + "name": "Graham Campbell", + "email": "graham@alt-three.com", + "role": "Developer" + } + ], + "description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.", + "homepage": "http://phpseclib.sourceforge.net", + "keywords": [ + "BigInteger", + "aes", + "asn.1", + "asn1", + "blowfish", + "crypto", + "cryptography", + "encryption", + "rsa", + "security", + "sftp", + "signature", + "signing", + "ssh", + "twofish", + "x.509", + "x509" + ], + "support": { + "issues": "https://github.com/phpseclib/phpseclib/issues", + "source": "https://github.com/phpseclib/phpseclib/tree/3.0.41" + }, + "funding": [ + { + "url": "https://github.com/terrafrost", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpseclib", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpseclib/phpseclib", + "type": "tidelift" + } + ], + "time": "2024-08-12T00:13:54+00:00" + }, { "name": "psr/log", "version": "3.0.0", From 23a34d10b0e2148b5fa2dc737fa1b295b87ba657 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 2 Sep 2024 23:28:03 +0200 Subject: [PATCH 16/24] delete --- ci4/app/Config/FTP.php | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 ci4/app/Config/FTP.php diff --git a/ci4/app/Config/FTP.php b/ci4/app/Config/FTP.php deleted file mode 100644 index d3b963f1..00000000 --- a/ci4/app/Config/FTP.php +++ /dev/null @@ -1,18 +0,0 @@ - Date: Mon, 2 Sep 2024 23:28:54 +0200 Subject: [PATCH 17/24] feat: add config class for XML export to sftp --- ci4/app/Config/PedidoXML.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ci4/app/Config/PedidoXML.php diff --git a/ci4/app/Config/PedidoXML.php b/ci4/app/Config/PedidoXML.php new file mode 100644 index 00000000..b55b7697 --- /dev/null +++ b/ci4/app/Config/PedidoXML.php @@ -0,0 +1,27 @@ +host = env("HIDRIVE_HOST","10.5.0.6"); + $this->port = env("HIDRIVE_USER",21); + $this->username = env("HIDRIVE_PASS","admin"); + $this->password = env("FTP_XML_PASSWORD","A77h3b0X4OA2rOYAf4w2"); + $this->base_dir = env("HIDRIVE_PATH_ROOT","/home/admin/safekat"); # FTP server directory + $this->xml_enabled = env("FTP_XML_ENABLED",false); + + } +} From 295fd882018e205d34a22a79ff3bcc1b42b7cfa9 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 2 Sep 2024 23:29:14 +0200 Subject: [PATCH 18/24] feat: add class config for SFTP xml export --- ci4/app/Config/PedidoXML.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci4/app/Config/PedidoXML.php b/ci4/app/Config/PedidoXML.php index b55b7697..f4d78928 100644 --- a/ci4/app/Config/PedidoXML.php +++ b/ci4/app/Config/PedidoXML.php @@ -19,7 +19,7 @@ class PedidoXML extends BaseConfig $this->host = env("HIDRIVE_HOST","10.5.0.6"); $this->port = env("HIDRIVE_USER",21); $this->username = env("HIDRIVE_PASS","admin"); - $this->password = env("FTP_XML_PASSWORD","A77h3b0X4OA2rOYAf4w2"); + $this->password = env("HIDRIVE_PASS","A77h3b0X4OA2rOYAf4w2"); $this->base_dir = env("HIDRIVE_PATH_ROOT","/home/admin/safekat"); # FTP server directory $this->xml_enabled = env("FTP_XML_ENABLED",false); From 1d7f06b018d89b9646799d2d262f77c37e9d7164 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 2 Sep 2024 23:30:59 +0200 Subject: [PATCH 19/24] feat : after upload presupuesto file send to sftp server --- ci4/app/Controllers/Presupuestos/Presupuestocliente.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index cfd405ad..31a7af10 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -3,6 +3,7 @@ namespace App\Controllers\Presupuestos; use App\Entities\Presupuestos\PresupuestoEntity; +use App\Libraries\SafekatFtpClient; use App\Models\Collection; use App\Models\Configuracion\PapelGenericoModel; use App\Models\Configuracion\TipoPresupuestoModel; @@ -892,7 +893,10 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } if(!is_null($new_name)){ - move_uploaded_file($tmp_name, WRITEPATH . 'uploads/presupuestos/' . $new_name); + $path = WRITEPATH . 'uploads/presupuestos/' . $new_name; + move_uploaded_file($tmp_name,$path); + $ftp = new SafekatFtpClient(); + $ftp->uploadFilePresupuesto($presupuesto_id); } } } From 68f2ccb1c5ba4abaac41e293305dd883e01e0443 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 2 Sep 2024 23:31:20 +0200 Subject: [PATCH 20/24] feat : add class library for sftp --- ci4/app/Libraries/SafekatFtpClient.php | 63 ++++++++++++++++++++------ 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/ci4/app/Libraries/SafekatFtpClient.php b/ci4/app/Libraries/SafekatFtpClient.php index a5ee2f7e..3b96781e 100644 --- a/ci4/app/Libraries/SafekatFtpClient.php +++ b/ci4/app/Libraries/SafekatFtpClient.php @@ -2,27 +2,33 @@ namespace App\Libraries; -use FtpClient\FtpClient; +use App\Models\Pedidos\PedidoLineaModel; +use App\Models\Presupuestos\PresupuestoFicheroModel; +use Exception; +use phpseclib3\Net\SFTP; -class SafekatFtpClient +class SafekatFtpClient { - protected FtpClient $ftp; + protected SFTP $ftp; protected string $host; protected int $port; protected string $username; protected string $password; protected string $base_dir; - protected object $ftp_config; + protected bool $xml_enabled; + protected object $pedido_xml_config; public function __construct() { - $this->ftp = new FtpClient(); - $this->ftp_config = config("FTP"); - $this->host = $this->ftp_config->host; - $this->username = $this->ftp_config->username; - $this->password = $this->ftp_config->password; - $this->port = $this->ftp_config->port; - $this->base_dir = $this->ftp_config->base_dir; + $this->pedido_xml_config = config("PedidoXML"); + $this->host = $this->pedido_xml_config->host; + $this->username = $this->pedido_xml_config->username; + $this->password = $this->pedido_xml_config->password; + $this->port = $this->pedido_xml_config->port; + $this->base_dir = $this->pedido_xml_config->base_dir; + $this->xml_enabled = $this->pedido_xml_config->xml_enabled; + $this->ftp = new SFTP($this->host); + } /** * Upload the content of $filename to the base directory declared in App\Config\FTP.php @@ -34,15 +40,42 @@ class SafekatFtpClient public function uploadXML(string $content, string $filename): bool { try { - $remotePath = implode("/", [$this->base_dir, $filename]); - $this->ftp->connect(host: $this->host, port: $this->port); + if ($this->xml_enabled == false) return false; + $remotePath = implode("/", [$this->base_dir,'xml_nuevos']); $this->ftp->login(username: $this->username, password: $this->password); - $this->ftp->putFromString($remotePath, $content); + if(!$this->ftp->is_dir($remotePath)){ + $this->ftp->mkdir($remotePath,recursive:true); + } + $this->ftp->put($remotePath.'/'.$filename, $content); + return true; } catch (\Throwable $th) { throw $th; - log_message('error',$th->getMessage()); + log_message('error', $th->getMessage()); return false; } } + public function uploadFilePresupuesto(int $presupuesto_id) + { + try { + $model = model(PresupuestoFicheroModel::class); + $modelPedidoLinea = model(PedidoLineaModel::class); + $pedidoLinea = $modelPedidoLinea->findByPresupuesto($presupuesto_id); + $rootIdExtern = 1e6 + $pedidoLinea->pedido_id; + $presupuestoFiles = $model->getFiles($presupuesto_id); + $this->ftp->login(username: $this->username, password: $this->password); + foreach ($presupuestoFiles as $key => $value) { + $filename = array_reverse(explode("/", $value->file_path))[0]; + $remoteDir = implode("/", [$this->base_dir,$rootIdExtern]); + $remoteFile = implode("/", [$this->base_dir,$rootIdExtern,$filename]); + if(!$this->ftp->is_dir($remoteDir)){ + $this->ftp->mkdir($remoteDir,recursive:true); + } + $this->ftp->put($remoteFile,$value->file_path,mode:$this->ftp::SOURCE_LOCAL_FILE); + } + } catch (Exception $e) { + log_message('error', $e->getMessage()); + throw $e; + } + } } From ebe649c7d8a585bf9c689b752d2a48fc4ad86dab Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 2 Sep 2024 23:31:50 +0200 Subject: [PATCH 21/24] feat : add method findByPresupuesto --- ci4/app/Models/Pedidos/PedidoLineaModel.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ci4/app/Models/Pedidos/PedidoLineaModel.php b/ci4/app/Models/Pedidos/PedidoLineaModel.php index 52284cb4..44a9f946 100644 --- a/ci4/app/Models/Pedidos/PedidoLineaModel.php +++ b/ci4/app/Models/Pedidos/PedidoLineaModel.php @@ -216,5 +216,10 @@ class PedidoLineaModel extends \App\Models\BaseModel return $resultaArray; } - + public function findByPresupuesto(int $presupuestoId){ + $builder = $this->db + ->table($this->table) + ->select(); + return $builder->where('presupuesto_id',$presupuestoId)->get()->getFirstRow(); + } } \ No newline at end of file From 6e41e7399786025afd8ec5741c56ad5f2092a2c5 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 2 Sep 2024 23:32:11 +0200 Subject: [PATCH 22/24] feat : add method getPedidoPresupuestoTipoImpresion --- ci4/app/Models/Pedidos/PedidoModel.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 3d238a84..e67db27d 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -90,6 +90,19 @@ class PedidoModel extends \App\Models\BaseModel return $lineasPresupuesto; } + public function getPedidoPresupuestoTipoImpresion(int $presupuesto_id) : array|object|null + { + $q = $this->db->table($this->table) + ->select( + [ + 'tipos_presupuesto.codigo', + 'presupuestos.solapas' + ] + ) + ->join('tipos_presupuestos', 'tipos_presupuestos.id = presupuestos.tipo_impresion_id', 'left') + ->where('presupuestos.id', $presupuesto_id); + return $q->get()->getFirstRow(); + } public function getPedidoClientePresupuesto(int $pedido_id) { $query = $this->db->table($this->table) @@ -98,9 +111,11 @@ class PedidoModel extends \App\Models\BaseModel 'clientes.nombre as customerName', 'presupuestos.total_aceptado as totalAceptado', 'presupuestos.id as presupuestoId', + 'presupuestos.cliente_id as presupuestoClienteId', 'presupuestos.margen', 'presupuestos.inc_rei', 'presupuestos.tirada', + 'presupuestos.tirada', 'presupuestos.titulo', 'presupuestos.paginas', 'presupuestos.solapas', @@ -111,6 +126,7 @@ class PedidoModel extends \App\Models\BaseModel 'presupuestos.papel_formato_personalizado', 'presupuestos.papel_formato_ancho as papelAnchoPersonalidado ', 'presupuestos.papel_formato_alto as papelAltoPersonalidado', + 'tipos_presupuestos.codigo as codigoTipoImpresion', 'lg_papel_formato.ancho as lgPapelFormatoAncho ', 'lg_papel_formato.alto as lgPapelFormatoAlto', @@ -119,6 +135,7 @@ class PedidoModel extends \App\Models\BaseModel ->join('pedidos_linea', 'pedidos_linea.id = pedidos.id', 'left') ->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id', 'left') ->join('presupuesto_ficheros', 'presupuesto_ficheros.presupuesto_id = presupuestos.id', 'left') + ->join('tipos_presupuestos', 'tipos_presupuestos.id = presupuestos.tipo_impresion_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') From fe4fdb86071b3d3bce1f348473c4d5c997a67035 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 2 Sep 2024 23:33:05 +0200 Subject: [PATCH 23/24] feat: generateXML finished --- ci4/app/Services/PedidoXMLService.php | 80 ++++++++++++++++++--------- 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/ci4/app/Services/PedidoXMLService.php b/ci4/app/Services/PedidoXMLService.php index 9af64ea1..103aa41d 100644 --- a/ci4/app/Services/PedidoXMLService.php +++ b/ci4/app/Services/PedidoXMLService.php @@ -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 { From 93714ac9551c5ea63cd5ab176d0979400fd01a08 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 2 Sep 2024 23:33:48 +0200 Subject: [PATCH 24/24] feat : add generate XML functionality in crearPedido --- ci4/app/Services/PresupuestoService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index 0fe6e6f3..e42fb832 100755 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -1822,6 +1822,7 @@ class PresupuestoService extends BaseService "user_updated_id" => auth()->user()->id, ]; $id_linea = $model_pedido_linea->insert($data_pedido_linea); + PedidoXMLService::generate_xml($pedido_id); } if($id_linea != 0 && $pedido_id != 0){