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', ]; diff --git a/ci4/app/Config/PedidoXML.php b/ci4/app/Config/PedidoXML.php new file mode 100644 index 00000000..f4d78928 --- /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("HIDRIVE_PASS","A77h3b0X4OA2rOYAf4w2"); + $this->base_dir = env("HIDRIVE_PATH_ROOT","/home/admin/safekat"); # FTP server directory + $this->xml_enabled = env("FTP_XML_ENABLED",false); + + } +} diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 05556596..a44885c5 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/Config/Services.php b/ci4/app/Config/Services.php index df7c8ad0..a802b838 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; /** diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index 647ff134..6ff1ca79 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,11 @@ 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 = PedidoXMLService::generate_xml($pedido_id); + // $xml_service = new PedidoXMLService($this->model); + return $this->respond($data); + } } \ No newline at end of file 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); } } } diff --git a/ci4/app/Helpers/general_helper.php b/ci4/app/Helpers/general_helper.php old mode 100755 new mode 100644 diff --git a/ci4/app/Libraries/SafekatFtpClient.php b/ci4/app/Libraries/SafekatFtpClient.php new file mode 100644 index 00000000..3b96781e --- /dev/null +++ b/ci4/app/Libraries/SafekatFtpClient.php @@ -0,0 +1,81 @@ +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 + * + * @param string $content + * @param string $filename + * @return boolean + */ + public function uploadXML(string $content, string $filename): bool + { + try { + if ($this->xml_enabled == false) return false; + $remotePath = implode("/", [$this->base_dir,'xml_nuevos']); + $this->ftp->login(username: $this->username, password: $this->password); + 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()); + 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; + } + } +} 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 diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 04755c6e..e67db27d 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"; @@ -29,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", @@ -53,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( @@ -79,10 +84,116 @@ 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]); } return $lineasPresupuesto; } -} \ No newline at end of file + 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) + ->select([ + 'pedidos.id as pedidoId', + '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', + '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', + 'tipos_presupuestos.codigo as codigoTipoImpresion', + 'lg_papel_formato.ancho as lgPapelFormatoAncho ', + 'lg_papel_formato.alto as lgPapelFormatoAlto', + + + ]) + ->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') + ->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([ + '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; + } + public function getPedidoPresupuestoDirecciones($pedido_id) + { + $query = $this->db->table($this->table) + ->select([ + 'pedidos.id as pedidoId', + 'presupuestos.id as presupuestoId', + 'clientes.nombre as customerName', + 'presupuesto_direcciones.*', + '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') + ->where('pedidos.id', $pedido_id); + $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 aa88fd61..85eb6e8f 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 new file mode 100644 index 00000000..103aa41d --- /dev/null +++ b/ci4/app/Services/PedidoXMLService.php @@ -0,0 +1,222 @@ +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']); + $data_xml["binding"] = PedidoXMLService::get_binding_code($data_xml['pedido_cliente_presupuesto']->codigoTipoImpresion,$data_xml['pedido_cliente_presupuesto']->solapas); + 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'); + $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_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; + $papel_formato_alto = $data["pedido_cliente_presupuesto"]->papelAltoPersonalidado; + } else { + $papel_formato_ancho = $data["pedido_cliente_presupuesto"]->lgPapelFormatoAncho; + $papel_formato_alto = $data["pedido_cliente_presupuesto"]->lgPapelFormatoAlto; + } + $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'); + $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, "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_product_el->appendChild($xml_presupuesto_lineas_el); + if ($presupuestoLineaTipoCubierta) { + $containsTarifaAcabadoBrillo = isset($data['acabado']['Finish']) ? true : false; + if ($containsTarifaAcabadoBrillo) { + $acabado = "brillo"; + } else { + $acabado = "mate"; + } + $xmlCover = $xml->createElement('Cover'); + $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_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) { + $xml_services_el->appendChild($xml->createElement($key, $value)); + } + foreach ($data['acabado'] as $key => $value) { + $xml_services_el->appendChild($xml->createElement($key, $value)); + } + + $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'); + $xml_envio_el->appendChild($xml->createElement('Qty', $pedido_presupuesto_direccion->cantidad)); + $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->municipio)); + $xml_envio_el->appendChild($xml->createElement('Zip', $pedido_presupuesto_direccion->cp)); + $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_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); + return $data; + } + protected static function generate_xml_file_name(string $hash) : string + { + 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 + { + $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; + } +} diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index 94bac7e7..781b8127 100755 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -1829,6 +1829,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){ diff --git a/ci4/composer.json b/ci4/composer.json index 8fe6ffc5..70688ebd 100755 --- a/ci4/composer.json +++ b/ci4/composer.json @@ -13,7 +13,9 @@ "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", + "phpseclib/phpseclib": "~3.0" }, "require-dev": { "fakerphp/faker": "^1.9", diff --git a/ci4/composer.lock b/ci4/composer.lock index 4596b329..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": "b2eee64c89c81ed0f0edef73637b9199", + "content-hash": "0cf49081609029ebf2165c9cebed577e", "packages": [ { "name": "codeigniter4/framework", @@ -399,6 +399,175 @@ }, "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": "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", @@ -489,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",