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..9bce6c7c --- /dev/null +++ b/ci4/app/Config/PedidoXML.php @@ -0,0 +1,27 @@ +host = env("HIDRIVE_HOST","10.5.0.6"); + $this->port = env("HIDRIVE_PORT",21); + $this->username = env("HIDRIVE_USER","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 e204ca63..09691d62 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -1,7 +1,6 @@ resource('presupuestocliente', ['namespace' => 'App\Controllers\Presupu $routes->group('serviciosacabados', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { $routes->post('datatable', 'Presupuestoacabados::datatable', ['as' => 'dataTableOfPresupuestoAcabados']); + $routes->post('menuitems', 'Presupuestoacabados::menuItems', ['as' => 'menuItemsOfPresupuestoAcabados']); $routes->post('edit/(:num)', 'Presupuestoacabados::edit/$1', ['as' => 'updatePresupuestoacabados']); }); @@ -638,6 +638,8 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function ( $routes->post('getlineas', 'Pedido::getLineas', ['as' => 'tablaLineasPedido']); $routes->post('cambiarestado', 'Pedido::cambiarEstado', ['as' => 'cambiarEstadoPedido']); $routes->post('update/(:any)', 'Pedido::update/$1', ['as' => 'actualizarPedido']); + $routes->get('xml/(:num)', 'Pedido::get_xml_pedido/$1',['as' => 'getXMLPedido']); + }); $routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']); @@ -700,6 +702,15 @@ $routes->group( } ); +$routes->group( + 'print-factura', + ['namespace' => 'App\Controllers\Pdf'], + function ($routes) { + $routes->get('index/(:num)', 'PrintFacturas::index/$1', ['as' => 'viewFacturaPDF']); + $routes->get('generar/(:num)', 'PrintFacturas::generar/$1', ['as' => 'facturaToPdf']); + } +); + $routes->group( 'export-giros', ['namespace' => 'App\Controllers\Excel'], @@ -708,6 +719,14 @@ $routes->group( } ); +$routes->group( + 'export-lineas', + ['namespace' => 'App\Controllers\Excel'], + function ($routes) { + $routes->get('generar/(:num)', 'PrintLineas::generateExcel/$1', ['as' => 'lineasToExcel']); + } +); + $routes->group( 'buscadorpresupuestos', ['namespace' => 'App\Controllers\Presupuestos'], 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/Excel/PrintLineas.php b/ci4/app/Controllers/Excel/PrintLineas.php new file mode 100644 index 00000000..729c79ff --- /dev/null +++ b/ci4/app/Controllers/Excel/PrintLineas.php @@ -0,0 +1,70 @@ +getResourceForExcel($factura_id)->get()->getResultObject(); + + + // Crear un nuevo Spreadsheet + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + + // Especificar encabezados + $headers = [ + 'Factura', + 'ID Pedido', + 'Ref. Cliente', + 'Base' + ]; + + // Establecer los encabezados en la primera fila + $column = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($column . '1', $header); + $column++; + } + + // Rellenar las filas con datos + $rowNumber = 2; // Empezar en la segunda fila + foreach ($infoLineasFactura as $infoLineaFactura) { + $column = 'A'; + foreach ($infoLineaFactura as $cell) { + $sheet->setCellValue($column . $rowNumber, $cell); + $column++; + } + $rowNumber++; + } + + // Ajustar automáticamente el tamaño de las columnas + foreach (range('A', $column) as $col) { + $sheet->getColumnDimension($col)->setAutoSize(true); + } + + // Crear un escritor para guardar el archivo + $writer = new Xlsx($spreadsheet); + + // Configurar la respuesta para descarga + $fileName = 'lineas-pedido.xlsx'; + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $fileName . '"'); + header('Cache-Control: max-age=0'); + + // Escribir el archivo a la salida + $writer->save('php://output'); + exit; + + } + +} \ No newline at end of file diff --git a/ci4/app/Controllers/Pdf/PrintFacturas.php b/ci4/app/Controllers/Pdf/PrintFacturas.php new file mode 100644 index 00000000..08e6e230 --- /dev/null +++ b/ci4/app/Controllers/Pdf/PrintFacturas.php @@ -0,0 +1,65 @@ +getResourceForPdf($id_factura)->get()->getRow(); + $data['lineas_factura'] = $lineasFacturaModel->getResourceForPdf($id_factura)->get()->getResultObject(); + $data['resumen_por_iva'] = $lineasFacturaModel->getResourceResumenIVAsForPdf($id_factura)->get()->getResultObject(); + + return view(getenv('theme.path') . 'pdfs/factura', $data); + } + + public function generar($id_factura) + { + + // Cargar modelos + $facturaModel = model('App\Models\Facturas\FacturaModel'); + $lineasFacturaModel = model('App\Models\Facturas\FacturaLineaModel'); + + // Informacion del presupuesto + $data['factura'] = $facturaModel->getResourceForPdf($id_factura)->get()->getRow(); + $data['lineas_factura'] = $lineasFacturaModel->getResourceForPdf($id_factura)->get()->getResultObject(); + $data['resumen_por_iva'] = $lineasFacturaModel->getResourceResumenIVAsForPdf($id_factura)->get()->getResultObject(); + + // Crear una instancia de Dompdf + $options = new \Dompdf\Options(); + $options->set('isHtml5ParserEnabled', true); + $options->set('isPhpEnabled', true); + $options->set('isRemoteEnabled', true); + $dompdf = new \Dompdf\Dompdf($options); + + // Contenido HTML del documento + $dompdf->loadHtml(view(getenv('theme.path').'pdfs/factura', $data)); + + // Establecer el tamaño del papel + $dompdf->setPaper('A4', 'portrait'); + + // Renderizar el PDF + $dompdf->render(); + + // Obtener el contenido generado + $output = $dompdf->output(); + + // Establecer las cabeceras para visualizar en lugar de descargar + $file_name = $data['factura']->numero . ".pdf"; + return $this->response + ->setStatusCode(200) + ->setHeader('Content-Type', 'application/pdf') + ->setHeader('Content-Disposition', 'inline; filename="' . $file_name . '"') + ->setHeader('Cache-Control', 'private, max-age=0, must-revalidate') + ->setHeader('Pragma', 'public') + ->setHeader('Content-Length', strlen($output)) + ->setBody($output); + } +} \ No newline at end of file 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/Presupuestoacabados.php b/ci4/app/Controllers/Presupuestos/Presupuestoacabados.php index 47f2eb68..48fa392c 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestoacabados.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoacabados.php @@ -99,12 +99,13 @@ class Presupuestoacabados extends \App\Controllers\BaseResourceController $tarifa_acabado_id = $reqData['tarifa_acabado_id'] ?? 0; $tirada = $reqData['tirada'] ?? 0; + $proveedor_id = $reqData['proveedor_id'] ?? -1; $POD = $reqData['POD'] ?? 0; $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); - $values = $this->model->getPrecioTarifa($tarifa_acabado_id, $tirada, $POD); + $values = $this->model->getPrecioTarifa($tarifa_acabado_id, $tirada, $proveedor_id, $POD); $data = [ 'values' => $values, @@ -119,4 +120,39 @@ class Presupuestoacabados extends \App\Controllers\BaseResourceController } + public function menuItems() + { + if ($this->request->isAJAX()) { + + $reqData = $this->request->getPost(); + try{ + + $tarifa_id = $reqData['tarifa_id'] ?? -1; + $tirada = $reqData['tirada'] ?? 0; + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $menu = $this->model->getProveedoresForSelector($tarifa_id, $tirada); + + $data = [ + 'menu' => $menu, + $csrfTokenName => $newTokenHash + ]; + + } + catch(Exception $e){ + $data = [ + 'error' => $e, + $csrfTokenName => $newTokenHash + ]; + } + finally{ + return $this->respond($data); + } + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } } diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index 03ff9410..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; @@ -118,7 +119,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $datosPresupuesto->tapa = 'blanda'; $datosPresupuesto->clienteList = $this->getClienteListItems($clienteId ?? null); + $datosPresupuesto->paginasCuadernillo = [32, 28, 24, 20 , 16]; $presupuestoEntity->estado_id = 1; + $presupuestoEntity->paginas_por_cuadernillo = 32; $this->viewData['formAction'] = 'add'; @@ -185,6 +188,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if($presupuestoEntity->estado_id == 2){ $this->generarResumen($presupuestoEntity); } + + $datosPresupuesto->paginasCuadernillo = [32, 28, 24, 20 , 16]; + $presupuestoEntity->paginas_por_cuadernillo = $this->obtenerPaginasCuadernillo($presupuestoEntity); $this->viewData['formAction'] = 'edit'; @@ -371,6 +377,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $servicios = $reqData['servicios'] ?? []; + $paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null; + $datos_presupuesto = array( 'tirada' => $tirada, 'tamanio' => $tamanio, @@ -378,6 +386,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController 'clienteId' => $cliente_id, 'isColor' => $isColor, 'isHq' => $isHq, + 'paginasCuadernillo' => $paginasCuadernillo, 'interior' => array( 'papel_generico' => $papel_generico, @@ -600,6 +609,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $cliente_id = $reqData['datos_libro']['clienteId'] ?? -1; $isColor = intval($reqData['datos_libro']['isColor']) ?? 0; $isHq = intval($reqData['datos_libro']['isHq']) ?? 0; + $paginasCuadernillo = $reqData['datos_libro']['paginasCuadernillo'] ?? null; // Interior $papel_generico = [ @@ -637,6 +647,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController 'clienteId' => $cliente_id, 'isColor' => $isColor, 'isHq' => $isHq, + 'paginasCuadernillo' => $paginasCuadernillo, 'interior' => array( 'papel_generico' => $papel_generico, @@ -882,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); } } } @@ -983,6 +997,12 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController 'precio_unidad' => $servicio->precio_unidad, 'margen' => $servicio->margen, ]; + + // Se comprueba que $servicio tiene paginasCuadernillo + if (isset($servicio->paginas_por_cuadernillo)) { + $data['paginas_por_cuadernillo'] = $servicio->paginas_por_cuadernillo; + } + $model->insert($data); } else if ($tipo == 'extra') { $model = new PresupuestoServiciosExtraModel(); @@ -1086,6 +1106,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $cliente_id = $datos_entrada['clienteId'] ?? -1; $isColor = $datos_entrada['isColor']; $isHq = $datos_entrada['isHq']; + $paginasCuadernillo = $datos_entrada['paginasCuadernillo'] ?? null; // Interior $papel_generico = $datos_entrada['interior']['papel_generico']; @@ -1429,6 +1450,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController 'alto' => $datosPedido->alto, 'POD' => $POD, 'solapas' => intval($solapasCubierta) > 0 ? 1 : 0, + 'paginasCuadernillo' => $paginasCuadernillo, ]); $costeServiciosDefecto = 0.0; foreach ($servDefecto as $servicio) { @@ -1996,4 +2018,17 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $tipo = "" . ($isColor ? "Color" : "Negro") . " " . ($isHq ? "premium" : "estándar"); return $tipo; } + + protected function obtenerPaginasCuadernillo($presupuestoEntity){ + + $model = model('App\Models\Presupuestos\PresupuestoEncuadernacionesModel'); + $lineas = $model->getResource($presupuestoEntity->id)->get()->getResultObject(); + + foreach ($lineas as $linea){ + // check if exist + if($linea->paginas_por_cuadernillo != null) + return $linea->paginas_por_cuadernillo; + } + return 32; // valor por defecto + } } diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php b/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php index 323fd818..2a617768 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php @@ -118,6 +118,7 @@ class Presupuestoencuadernaciones extends \App\Controllers\BaseResourceControlle $alto = $reqData['alto'] ?? 0; $POD = $reqData['POD'] ?? 0; + $paginas_cuadernillo = $reqData['paginas_por_cuadernillo'] ?? null; $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); @@ -125,7 +126,7 @@ class Presupuestoencuadernaciones extends \App\Controllers\BaseResourceControlle $tarifaModel = model('App\Models\Tarifas\TarifaEncuadernacionModel'); if(is_null($tipo)){ if($tarifaModel->isTarifaPorHoras($tarifa_encuadernacion_id)){ - $values = $this->model->getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD); + $values = $this->model->getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo); }else{ $values = $this->model->getPrecioTarifa($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, $proveedor_id, $POD); } diff --git a/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php b/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php index 3c1c7236..eb9e47eb 100644 --- a/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php +++ b/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php @@ -5,6 +5,10 @@ use App\Entities\Tarifas\Acabados\TarifaAcabadoEntity; use App\Models\Collection; use App\Models\Tarifas\Acabados\TarifaAcabadoModel; +use App\Models\Compras\ProveedorModel; +use App\Models\Compras\ProveedorTipoModel; + + class TarifaAcabados extends BaseResourceController { @@ -217,6 +221,7 @@ class TarifaAcabados extends BaseResourceController endif; // ($requestMethod === 'post') $this->viewData['tarifaacabadoEntity'] = $tarifaacabadoEntity; + $this->viewData['proveedores'] = $this->getProveedores(); $this->viewData['formAction'] = route_to('updateTarifaAcabado', $id); @@ -305,4 +310,12 @@ class TarifaAcabados extends BaseResourceController } } + private function getProveedores(){ + $provTipoModel = new ProveedorTipoModel(); + $provModel = new ProveedorModel(); + + $tipoId = $provTipoModel->getTipoId("Acabados"); + return $provModel->getProvList($tipoId); + } + } diff --git a/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabadosLineas.php b/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabadosLineas.php index 15f7e901..e3021245 100644 --- a/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabadosLineas.php +++ b/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabadosLineas.php @@ -213,13 +213,14 @@ class TarifaAcabadosLineas extends \App\Controllers\BaseResourceController $id_TA = $reqData['id_tarifaacabado'] ?? -1; + $searchValues = get_filter_datatables_columns($reqData); - $resourceData = $this->model->getResource("", $id_TA)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); - + $resourceData = $this->model->getResource($searchValues, $id_TA)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + return $this->respond(Collection::datatable( $resourceData, $this->model->getResource()->countAllResults(), - $this->model->getResource($search, $id_TA)->countAllResults() + $this->model->getResource($searchValues, $id_TA)->countAllResults() )); } else { return $this->failUnauthorized('Invalid request', 403); @@ -280,6 +281,7 @@ class TarifaAcabadosLineas extends \App\Controllers\BaseResourceController ->validator('Validate::notEmpty', array( 'message' => lang('TarifaAcabadoLineas.validation.margen.required')) ), + Field::inst('proveedor_id'), Field::inst('tarifa_acabado_id'), Field::inst('user_created_id'), Field::inst('created_at'), @@ -297,6 +299,7 @@ class TarifaAcabadosLineas extends \App\Controllers\BaseResourceController $process_data['tirada_min'] = $data['data'][$pkey]['tirada_min']; $process_data['tirada_max'] = $data['data'][$pkey]['tirada_max']; + $process_data['proveedor_id'] = $data['data'][$pkey]['proveedor_id']; $response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_acabado_id']); // No se pueden duplicar valores al crear o al editar if (!empty($response)) { diff --git a/ci4/app/Entities/Presupuestos/PresupuestoAcabadosEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoAcabadosEntity.php index 71c10315..02af9b3a 100755 --- a/ci4/app/Entities/Presupuestos/PresupuestoAcabadosEntity.php +++ b/ci4/app/Entities/Presupuestos/PresupuestoAcabadosEntity.php @@ -9,6 +9,7 @@ class PresupuestoAcabadosEntity extends \CodeIgniter\Entity\Entity "id" => null, "presupuesto_id" => null, "tarifa_acabado_id" => null, + "proveedor_id" => null, "precio_unidad" => null, "precio_total" => null, "margen" => null, @@ -20,6 +21,7 @@ class PresupuestoAcabadosEntity extends \CodeIgniter\Entity\Entity protected $casts = [ "presupuesto_id" => "int", "tarifa_acabado_id" => "int", + "proveedor_id" => "int", "precio_unidad" => "float", "precio_total" => "float", "margen" => "float", diff --git a/ci4/app/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php index cb8e4ce4..560fa668 100755 --- a/ci4/app/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php +++ b/ci4/app/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php @@ -11,6 +11,7 @@ class PresupuestoEncuadernacionesEntity extends \CodeIgniter\Entity\Entity "tarifa_encuadernado_id" => null, "proveedor_id" => null, "precio_unidad" => null, + "paginas_por_cuadernillo" => null, "tiempo" => null, "precio_total" => null, "margen" => null, @@ -22,6 +23,7 @@ class PresupuestoEncuadernacionesEntity extends \CodeIgniter\Entity\Entity "tarifa_encuadernado_id" => "int", "proveedor_id" => "int", "precio_unidad" => "float", + "paginas_por_cuadernillo" => "int", "tiempo" => "float", "precio_total" => "float", "margen" => "float", diff --git a/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoLineaEntity.php b/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoLineaEntity.php index fb9ad299..b50a8c7f 100644 --- a/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoLineaEntity.php +++ b/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoLineaEntity.php @@ -8,6 +8,7 @@ class TarifaAcabadoLineaEntity extends \CodeIgniter\Entity\Entity protected $attributes = [ "id" => null, "tarifa_acabado_id" => 0, + "proveedor_id" => 0, "tirada_min" => 0, "tirada_max" => 0, "precio_min" => 0, @@ -21,6 +22,7 @@ class TarifaAcabadoLineaEntity extends \CodeIgniter\Entity\Entity ]; protected $casts = [ "tarifa_acabado_id" => "int", + "proveedor_id" => "int", "tirada_min" => "int", "tirada_max" => "int", "precio_min" => "float", 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/Language/en/TarifaAcabadoLineas.php b/ci4/app/Language/en/TarifaAcabadoLineas.php index 35361c39..71c6e647 100755 --- a/ci4/app/Language/en/TarifaAcabadoLineas.php +++ b/ci4/app/Language/en/TarifaAcabadoLineas.php @@ -6,6 +6,7 @@ return [ 'id' => 'ID', 'moduleTitle' => 'Finish rates Lines', 'deleteLine' => 'the selected register', + 'proveedor' => 'Provider', 'precioMax' => 'Max Price', 'precioMin' => 'Min Price', 'precioUnidad' => 'Price Unit', diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index e61122b3..4904fd8d 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -247,6 +247,7 @@ return [ 'precio' => 'Precio', 'precioUnidad' => 'Precio unidad', 'tiempo' => 'Tiempo', + "paginasCuadernillo" => "Páginas/cuadernillo", 'precioTotal' => 'Precio total', 'serviciosDefault' => 'Servicios por defecto', 'tarifa' => 'Tarifa', diff --git a/ci4/app/Language/es/TarifaAcabadoLineas.php b/ci4/app/Language/es/TarifaAcabadoLineas.php index 6a671ac7..eecfe599 100755 --- a/ci4/app/Language/es/TarifaAcabadoLineas.php +++ b/ci4/app/Language/es/TarifaAcabadoLineas.php @@ -6,8 +6,9 @@ return [ 'id' => 'ID', 'moduleTitle' => 'Tarifa Acabado Líneas', 'deleteLine' => 'el registro seleccionado', - 'precioMax' => 'Precio Max', - 'precioMin' => 'Precio Min', + 'proveedor' => 'Proveedor', + 'precioMax' => 'Precio T. Mín', + 'precioMin' => 'Precio T. Máx', 'precioUnidad' => 'Precio Unidad', 'tiradaMax' => 'Tirada Max', 'tiradaMin' => 'Tirada Min', diff --git a/ci4/app/Language/es/TarifaManipuladoLineas.php b/ci4/app/Language/es/TarifaManipuladoLineas.php index 93ac435b..9a5afebd 100755 --- a/ci4/app/Language/es/TarifaManipuladoLineas.php +++ b/ci4/app/Language/es/TarifaManipuladoLineas.php @@ -6,8 +6,8 @@ return [ 'id' => 'ID', 'moduleTitle' => 'Tarifa Manipulado Lineas', 'deleteLine' => 'el registro seleccionado', - 'precioMax' => 'Precio Max', - 'precioMin' => 'Precio Min', + 'precioMax' => 'Precio T. Mín', + 'precioMin' => 'Precio T. Máx', 'precioUnidad' => 'Precio Unidad', 'tiradaMax' => 'Tirada Max', 'tiradaMin' => 'Tirada Min', diff --git a/ci4/app/Language/es/Tarifaencuadernacion.php b/ci4/app/Language/es/Tarifaencuadernacion.php index ad8accb7..34c01087 100755 --- a/ci4/app/Language/es/Tarifaencuadernacion.php +++ b/ci4/app/Language/es/Tarifaencuadernacion.php @@ -10,9 +10,10 @@ return [ 'id' => 'ID', 'moduleTitle' => 'Tarifas Encuadernación', 'nombre' => 'Nombre', - 'precioMax' => 'Precio Max', - 'precioMin' => 'Precio Min', + 'precioMax' => 'Precio T. Mín', + 'precioMin' => 'Precio T. Máx', 'importeFijo' => 'Importe Fijo', + 'importeMin' => 'Importe mínimo', 'tarifaencuadernacion' => 'Tarifa Encuadernación', 'tarifaencuadernacionList' => 'Lista Tarifas Encuadernación', 'tarifasencuadernacion' => 'Tarifas Encuadernación', diff --git a/ci4/app/Language/es/Tarifamanipulado.php b/ci4/app/Language/es/Tarifamanipulado.php index 3e1fc7c5..9e391d46 100755 --- a/ci4/app/Language/es/Tarifamanipulado.php +++ b/ci4/app/Language/es/Tarifamanipulado.php @@ -10,8 +10,8 @@ return [ 'id' => 'ID', 'moduleTitle' => 'Tarifas Manipulado', 'nombre' => 'Nombre', - 'precioMax' => 'Precio Max', - 'precioMin' => 'Precio Min', + 'precioMax' => 'Precio T. Mín', + 'precioMin' => 'Precio T. Máx', 'importeFijo' => 'Importe Fijo', 'mostrar_en_presupuesto' => 'Mostrar en presupuesto', 'tarifamanipulado' => 'Tarifa Manipulado', diff --git a/ci4/app/Libraries/SafekatFtpClient.php b/ci4/app/Libraries/SafekatFtpClient.php new file mode 100644 index 00000000..98259ba2 --- /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,'pedidos','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,"pedidos_files",$rootIdExtern]); + $remoteFile = implode("/", [$this->base_dir,"pedidos_files",$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/Facturas/FacturaLineaModel.php b/ci4/app/Models/Facturas/FacturaLineaModel.php index b808ac8c..2abb52e2 100644 --- a/ci4/app/Models/Facturas/FacturaLineaModel.php +++ b/ci4/app/Models/Facturas/FacturaLineaModel.php @@ -54,6 +54,76 @@ class FacturaLineaModel extends \App\Models\BaseModel { return $builder; } + + public function getResourceResumenIVAsForPdf($factura_id = -1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.iva, + ROUND(SUM(t1.base), 2) AS base, + ROUND(SUM(t1.total_iva), 2) AS total_iva, + ROUND(SUM(t1.total), 2) AS total" + ) + ->where("t1.factura_id", $factura_id) + ->where("t1.deleted_at", null) + ->groupBy('t1.iva') + ->orderBy('t1.iva', 'ASC'); // Ordena por iva en forma ascendente + + return $builder; + } + + + /** + * Get resource data for creating PDFs. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResourceForPdf($factura_id = -1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.factura_id AS factura_id, + t1.pedido_linea_impresion_id AS pedido_linea_impresion_id, t1.pedido_maquetacion_id AS pedido_maquetacion_id, + t1.descripcion AS descripcion, t1.cantidad as cantidad, t1.precio_unidad AS precio_unidad, t1.iva AS iva, + t1.base AS base, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data" + ) + ->where("t1.factura_id", $factura_id) + ->where("t1.deleted_at", null); + + return $builder; + } + + /** + * Get resource data for creating PDFs. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResourceForExcel($factura_id = -1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t2.numero AS ref_factura, + t3.pedido_id AS pedido_id, + t4.referencia_cliente AS referencia_cliente, + t1.base AS base" + ) + ->join("facturas t2", "t2.id = t1.factura_id", "left") + ->join("pedidos_linea t3", "t3.id = t1.pedido_linea_impresion_id", "left") + ->join("presupuestos t4", "t4.id = t3.presupuesto_id", "left") + ->where("t1.factura_id", $factura_id) + ->where("t1.deleted_at", null); + + return $builder; + } + + public function addFacturaPedidoLinea($factura_id, $pedido_linea_id, $cantidad) { $data = [ diff --git a/ci4/app/Models/Facturas/FacturaModel.php b/ci4/app/Models/Facturas/FacturaModel.php index ccdf7f43..f79d5044 100644 --- a/ci4/app/Models/Facturas/FacturaModel.php +++ b/ci4/app/Models/Facturas/FacturaModel.php @@ -102,6 +102,41 @@ class FacturaModel extends \App\Models\BaseModel { } + /** + * Get resource data for creating PDFs. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResourceForPdf($factura_id = -1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.numero AS numero, DATE_FORMAT(t1.fecha_factura_at, '%d/%m/%Y') AS fecha_factura_at, + t1.base AS base, t1.total AS total, t1.pendiente AS pendiente, + t1.creditoAsegurado AS creditoAsegurado, t1.estado AS estado, t1.estado_pago AS estado_pago, + t4.nombre AS forma_pago, + DATE_FORMAT(MIN(CASE WHEN t3.fecha_vencimiento_at != '0000-00-00 00:00:00' THEN t3.fecha_vencimiento_at ELSE NULL END), '%d/%m/%Y') AS vencimiento, + t2.nombre AS cliente, t2.direccion AS cliente_direccion, t2.ciudad AS cliente_ciudad, + t2.cp AS cliente_cp, t2.cif AS cliente_cif, t2.vencimiento AS dias_vencimiento, t2.ccc AS cliente_ccc, + t5.nombre AS cliente_pais" + ); + + $builder->join("clientes t2", "t2.id = t1.cliente_id", "left"); + $builder->join("facturas_pagos t3", "t3.factura_id = t1.id", "left"); + $builder->join("formas_pago t4", "t3.forma_pago_id = t4.id", "left"); + $builder->join("lg_paises t5", "t2.pais_id = t5.id", "left"); + + $builder->where("t1.id", $factura_id); + $builder->where("t1.deleted_at IS NULL"); + $builder->groupBy("t1.id"); // Agrupa por id de la factura + + return $builder; + } + + public function getResourcePedidos($pedido_id) { $builder = $this->db 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/PresupuestoAcabadosModel.php b/ci4/app/Models/Presupuestos/PresupuestoAcabadosModel.php index 9eadaf14..08d98bfb 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoAcabadosModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoAcabadosModel.php @@ -17,11 +17,12 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel const SORTABLE = [ 0 => "t2.nombre", - 1 => "t1.precio_unidad", - 2 => "t1.precio_total" + 1 => "t1.proveedor_id", + 2 => "t1.precio_unidad", + 3 => "t1.precio_total" ]; - protected $allowedFields = ["presupuesto_id", "tarifa_acabado_id", "nombre", "precio_total", "precio_unidad", "margen", "cubierta", "sobrecubierta"]; + protected $allowedFields = ["presupuesto_id", "tarifa_acabado_id", "proveedor_id", "nombre", "precio_total", "precio_unidad", "margen", "cubierta", "sobrecubierta"]; protected $returnType = "App\Entities\Presupuestos\PresupuestoAcabadosEntity"; protected $useTimestamps = true; @@ -46,10 +47,29 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel ], ]; - public function getPrecioTarifa($tarifa_acabado_id, $tirada, $POD){ + + public function getProveedoresForSelector($tarifa_acabado_id, $tirada){ + + $proveedores = []; + $modelTarifa = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel'); + + $tarifa_value = $modelTarifa->getTarifaPresupuestoAcabado($tarifa_acabado_id, $tirada); + + if (count($tarifa_value)>0) { + foreach($tarifa_value as $tarifa) + array_push($proveedores, + (object)[ + 'id'=> $tarifa->proveedor_id, + 'text'=> $tarifa->proveedor_nombre, + ]); + } + return $proveedores; + } + + public function getPrecioTarifa($tarifa_acabado_id, $tirada, $proveedor_id, $POD){ $modelTarifa = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel'); - $tarifa_value = $modelTarifa->getTarifaPresupuestoAcabado($tarifa_acabado_id, $tirada); + $tarifa_value = $modelTarifa->getTarifaPresupuestoAcabado($tarifa_acabado_id, $tirada, $proveedor_id); if (count($tarifa_value)>0) { $result_data = $this->calcularTarifa($tarifa_value[0], $tirada, $POD<$tirada?false:true); @@ -59,6 +79,8 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel 'precio_unidad'=> $result_data[0], 'total'=> $result_data[1], 'margen'=> $result_data[2], + 'proveedor' => $tarifa_value[0]->proveedor_nombre, + 'proveedor_id' => $tarifa_value[0]->proveedor_id, ]; return $ret_array; } @@ -119,6 +141,8 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel foreach($tarifas as $tarifa){ + $proveedor = $tarifa->proveedor_id=='undefined'?'NULL':$tarifa->proveedor_id; + $builder = $this->db ->table($this->table . " t1"); $builder->select("id"); @@ -132,6 +156,7 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel ->table($this->table . " t1") ->where('presupuesto_id', $presupuesto_id) ->where('tarifa_acabado_id', $tarifa->tarifa_id) + ->set('proveedor_id', $proveedor) ->set('precio_unidad', $tarifa->precio_unidad) ->set('precio_total', $tarifa->precio_total) ->set('margen', $tarifa->margen) @@ -146,6 +171,7 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel ->table($this->table . " t1") ->set('presupuesto_id', $presupuesto_id) ->set('tarifa_acabado_id', $tarifa->tarifa_id) + ->set('proveedor_id', $proveedor, false) ->set('precio_unidad', $tarifa->precio_unidad) ->set('precio_total', $tarifa->precio_total) ->set('margen', $tarifa->margen) @@ -169,11 +195,13 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel ->table($this->table . " t1") ->select( "t1.id AS id, t1.tarifa_acabado_id AS tarifa_acabado_id, t1.precio_unidad AS precio_unidad, - t1.precio_total AS precio_total, t1.margen AS margen, t2.nombre AS nombre, t1.cubierta AS cubierta, t1.sobrecubierta AS sobrecubierta" + t1.precio_total AS precio_total, t1.margen AS margen, t2.nombre AS nombre, t1.cubierta AS cubierta, t1.sobrecubierta AS sobrecubierta, + t1.proveedor_id AS proveedor_id, t3.nombre AS proveedor," ); $builder->where('t1.presupuesto_id', $presupuesto_id); $builder->join("lg_tarifa_acabado t2", "t1.tarifa_acabado_id = t2.id", "left"); + $builder->join("lg_proveedores t3", "t1.proveedor_id = t3.id", "left"); return $builder; } diff --git a/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php index 50b45fea..3958b2ec 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php @@ -21,7 +21,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel 4 => "t1.precio_total" ]; - protected $allowedFields = ["presupuesto_id", "tarifa_encuadernado_id", "proveedor_id", "nombre", "precio_total", "precio_unidad", "tiempo", "margen"]; + protected $allowedFields = ["presupuesto_id", "tarifa_encuadernado_id", "proveedor_id", "nombre", "precio_total", "precio_unidad", "paginas_por_cuadernillo", "tiempo", "margen"]; protected $returnType = "App\Entities\Presupuestos\PresupuestoEncuadernacionesEntity"; protected $useTimestamps = true; @@ -48,7 +48,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel - public function initPresupuesto($tipo_presupuesto, $solapas, $tirada, $paginas, $ancho, $alto, $POD){ + public function initPresupuesto($tipo_presupuesto, $solapas, $tirada, $paginas, $ancho, $alto, $POD, $paginasCuadernillo = 32){ $model = model('App\Models\Presupuestos\TipoPresupuestoServiciosDefectoModel'); $tarifas_procesar = $model->get_tarifas($tipo_presupuesto, $solapas, "encuadernacion"); @@ -60,7 +60,12 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel if($modelTarifa->isTarifaPorHoras($tarifa['tarifa_id'])){ - $tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos + if($tarifa['tarifa_id'] == 2 || $tarifa['tarifa_id'] == 14){ // Rústica cosido hilo vegetal y Rústica cosido hilo vegetal solapas + $tiempo = $this->calcularTiempoCosido(16, $paginas, $tirada, $paginasCuadernillo); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos + } + else{ + $tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos + } $tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa['tarifa_id'], $tiempo, $tirada); if (count($tarifa_value)>0) { @@ -76,8 +81,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel $result_data[1] = $precio_total; $result_data[2] = $tarifa_proveedor->margen ; // margen - array_push($result_array, - (object)[ + $datos = [ 'tarifa_id'=> $tarifa['tarifa_id'], 'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre, 'precio_unidad'=> $result_data[0], @@ -86,7 +90,14 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel 'margen' => $result_data[2], 'proveedor' => $tarifa_proveedor->proveedor_nombre, 'proveedor_id' => $tarifa_proveedor->proveedor_id, - ]); + ]; + + if($tarifa['tarifa_id'] == 2 || $tarifa['tarifa_id'] == 14){ + $datos['paginas_por_cuadernillo'] = $paginasCuadernillo; + } + + array_push($result_array, + (object)$datos); } usort($result_array, function($a, $b) { @@ -237,11 +248,16 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel return []; } - public function getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD){ + public function getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo = null){ $modelTarifa = model('App\Models\Tarifas\TarifaEncuadernacionModel'); - $tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos + if($tarifa_encuadernacion_id == 2 || $tarifa_encuadernacion_id == 14){ // Rústica cosido hilo vegetal y Rústica cosido hilo vegetal solapas + $tiempo = $this->calcularTiempoCosido(16, $paginas, $tirada, $paginas_cuadernillo); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos + } + else{ + $tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos + } $tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada, $proveedor_id); if (count($tarifa_value)>0) { @@ -256,6 +272,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel $result_data[0] = floatval($precio_total / $tirada); // Precio/unidad $result_data[1] = $precio_total; $result_data[2] = $tarifa_proveedor->margen ; // margen + array_push($ret_array, (object)[ @@ -263,6 +280,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel 'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre, 'precio_unidad'=> $result_data[0], 'tiempo' => $tiempo, + 'paginas_por_cuadernillo' => $paginas_cuadernillo, 'total'=> $result_data[1], 'margen' => $result_data[2], 'proveedor' => $tarifa_proveedor->proveedor_nombre, @@ -287,6 +305,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel 'proveedor' => lang('Presupuestos.no_disponible'), 'precio_unidad'=> 0, 'tiempo' => null, + 'paginas_por_cuadernillo' => null, 'total'=> 0, 'margen' => 0, ]; @@ -355,6 +374,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel $builder->where('presupuesto_id', $presupuesto_id); $builder->where('tarifa_encuadernado_id', $tarifa->tarifa_id); $result = $builder->get()->getResultObject(); + $paginas_cuadernillo = $tarifa->paginas_por_cuadernillo??null; if(count($result)>0){ $this->db ->table($this->table . " t1") @@ -365,6 +385,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel ->set('tiempo', $tarifa->tiempo) ->set('precio_total', $tarifa->precio_total) ->set('margen', $tarifa->margen) + ->set('paginas_por_cuadernillo', $paginas_cuadernillo) ->update(); @@ -397,7 +418,8 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel ->table($this->table . " t1") ->select( "t1.id AS id, t1.tarifa_encuadernado_id AS tarifa_encuadernado_id, t1.precio_unidad AS precio_unidad, t1.tiempo AS tiempo, - t1.precio_total AS precio_total, t1.margen AS margen, t2.nombre AS nombre, t1.proveedor_id AS proveedor_id, t3.nombre AS proveedor" + t1.precio_total AS precio_total, t1.margen AS margen, t2.nombre AS nombre, t1.proveedor_id AS proveedor_id, t3.nombre AS proveedor, + t1.paginas_por_cuadernillo AS paginas_por_cuadernillo" ); $builder->where('t1.presupuesto_id', $presupuesto_id); @@ -415,4 +437,13 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel $velocidad = $maquinaModel->getVelocidad($maquina_id); return round($cuadernillos_pedido/($velocidad*60.0), 2); } + + private function calcularTiempoCosido($maquina_id, $paginas, $tirada, $cuadernillos_por_pagina = 32){ + + $maquinaModel = model("App\Models\Configuracion\MaquinaModel"); + $velocidad = $maquinaModel->getVelocidad($maquina_id); // cuadernillos por minuto + $cuadernillos_libro = ceil($paginas/intval($cuadernillos_por_pagina)); + $cuadernillos_pedido = $cuadernillos_libro*$tirada; + return round($cuadernillos_pedido/($velocidad*60.0), 2); // tiempo en segundos + } } diff --git a/ci4/app/Models/Presupuestos/PresupuestoModel.php b/ci4/app/Models/Presupuestos/PresupuestoModel.php index 424ba107..85eb6e8f 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php @@ -162,7 +162,7 @@ class PresupuestoModel extends \App\Models\BaseModel ], "pais_id" => [ "label" => "Presupuestos.paisId", - "rules" => "required|integer|greater_than[0]", + "rules" => "integer", ], "cliente_id" => [ "label" => "Presupuestos.clienteId", @@ -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/Models/Tarifas/Acabados/TarifaAcabadoLineaModel.php b/ci4/app/Models/Tarifas/Acabados/TarifaAcabadoLineaModel.php index 84e890cc..67ee7a73 100644 --- a/ci4/app/Models/Tarifas/Acabados/TarifaAcabadoLineaModel.php +++ b/ci4/app/Models/Tarifas/Acabados/TarifaAcabadoLineaModel.php @@ -1,6 +1,9 @@ "t1.tirada_min", - 1 => "t1.tirada_max", - 2 => "t1.precio_min", - 3 => "t1.precio_max", - 4 => "t1.margen", + 0 => "t3.nombre", + 1 => "t1.tirada_min", + 2 => "t1.precio_max", + 3 => "t1.tirada_max", + 4 => "t1.precio_min", + 5 => "t1.margen", ]; protected $allowedFields = [ + "proveedor_id", "tirada_min", "tirada_max", "precio_min", @@ -126,12 +131,12 @@ class TarifaAcabadoLineaModel extends \App\Models\BaseModel * * @return \CodeIgniter\Database\BaseBuilder */ - public function getResource(string $search = "", $tarifa_acabado_id = -1) + public function getResource($search = [], $tarifa_acabado_id = -1) { $builder = $this->db ->table($this->table . " t1") ->select( - "t1.id AS id, t1.tirada_min AS tirada_min, t1.tirada_max AS tirada_max, t1.precio_min AS precio_min, t1.precio_max AS precio_max, t1.margen AS margen, t2.id AS tarifa_acabado" + "t1.id AS id, t1.proveedor_id AS proveedor_id, t3.nombre AS proveedor_nombre, t1.tirada_min AS tirada_min, t1.tirada_max AS tirada_max, t1.precio_min AS precio_min, t1.precio_max AS precio_max, t1.margen AS margen, t2.id AS tarifa_acabado" ); //JJO @@ -139,21 +144,66 @@ class TarifaAcabadoLineaModel extends \App\Models\BaseModel $builder->where("t1.is_deleted", 0); $builder->join("lg_tarifa_acabado t2", "t1.tarifa_acabado_id = t2.id", "left"); + $builder->join("lg_proveedores t3", "t1.proveedor_id = t3.id", "left"); - return empty($search) - ? $builder - : $builder - ->groupStart() - ->like("t1.tirada_min", $search) - ->orLike("t1.tirada_max", $search) - ->orLike("t1.precio_min", $search) - ->orLike("t1.precio_max", $search) - ->orLike("t1.tirada_min", $search) - ->orLike("t1.tirada_max", $search) - ->orLike("t1.precio_min", $search) - ->orLike("t1.precio_max", $search) - ->groupEnd(); + if (empty($search)) + return $builder; + else { + $filterEnabled = 0; + + foreach ($search as $col_search) { + if($col_search[0] != 0){ + if(strlen($col_search[2]) > 1){ + $values = explode(",",$col_search[2]); + $min_val = floatval($values[0]); + $max_val = floatval($values[1]); + if(!is_nan($min_val) && !is_null($min_val) && strlen($values[0]) > 0){ + if($filterEnabled == 0){ + $builder->groupStart(); + $filterEnabled = 1; + } + $builder->where(self::SORTABLE[$col_search[0]] . " >=", $min_val); + } + if(!is_nan($max_val) && !is_null($max_val) && strlen($values[1]) > 0){ + if($filterEnabled == 0){ + $builder->groupStart(); + $filterEnabled = 1; + } + $builder->where(self::SORTABLE[$col_search[0]] . " <", $max_val); + } + } + } + else{ + if(strlen($col_search[2]) > 1){ + $values = explode(",",$col_search[2]); + if(count($values) > 1){ + foreach ($values as $value) { + if($filterEnabled == 0){ + $builder->groupStart(); + $filterEnabled = 1; + } + $builder->orWhere("t1.proveedor_id", $value); + } + } + else{ + if($filterEnabled == 0){ + $builder->groupStart(); + $filterEnabled = 1; + } + $builder->where("t1.proveedor_id", $col_search[2]); + } + } + } + + } + if($filterEnabled == 1){ + $builder->groupEnd(); + } + + + return $builder; + } } public function findLineasForTarifaAcabado(int $tarifaacabado_id){ @@ -181,6 +231,7 @@ class TarifaAcabadoLineaModel extends \App\Models\BaseModel ->select("id, tirada_min, tirada_max") ->where("is_deleted", 0) ->where("tarifa_acabado_id", $id_tarifa_acabado) + ->where("proveedor_id", $data["proveedor_id"]) ->get()->getResultObject(); diff --git a/ci4/app/Models/Tarifas/Acabados/TarifaAcabadoModel.php b/ci4/app/Models/Tarifas/Acabados/TarifaAcabadoModel.php index 3d2e3162..4ae2b09f 100644 --- a/ci4/app/Models/Tarifas/Acabados/TarifaAcabadoModel.php +++ b/ci4/app/Models/Tarifas/Acabados/TarifaAcabadoModel.php @@ -114,16 +114,17 @@ class TarifaAcabadoModel extends \App\Models\BaseModel return $builder->orderBy("t1.nombre", "asc")->get()->getResultObject(); } - public function getTarifaPresupuestoAcabado($tarifa_id, $tirada){ + public function getTarifaPresupuestoAcabado($tarifa_id, $tirada, $proveedor_id = -1){ $builder = $this->db ->table($this->table . " t1") ->select( "t1.id AS tarifa_acabado_id, t1.nombre AS tarifa_acabado_nombre, t1.precio_min AS tarifa_precio_min, t1.importe_fijo AS tarifa_importe_fijo, t1.acabado_cubierta AS acabado_cubierta, t1.acabado_sobrecubierta AS acabado_sobrecubierta, t2.id AS tarifa_linea_id, t2.tirada_min AS tirada_min, t2.tirada_max AS tirada_max, - t2.precio_min AS precio_min, t2.precio_max AS precio_max, t2.margen AS margen" + t2.precio_min AS precio_min, t2.precio_max AS precio_max, t2.margen AS margen, t2.proveedor_id AS proveedor_id, t3.nombre AS proveedor_nombre" ) ->join("tarifa_acabado_lineas t2", "t1.id = t2.tarifa_acabado_id", "left") + ->join("lg_proveedores t3", "t2.proveedor_id = t3.id", "left") ->where("t1.is_deleted", 0) //->where("t1.mostrar_en_presupuesto", 1) ->where("t2.is_deleted", 0); @@ -132,6 +133,9 @@ class TarifaAcabadoModel extends \App\Models\BaseModel $builder->where('t2.tirada_min <=', $tirada); $builder->where('t2.tirada_max >=', $tirada); + if($proveedor_id != -1){ + $builder->where('t2.proveedor_id', $proveedor_id); + } return $builder->get()->getResultObject(); } 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/PresupuestoClienteService.php b/ci4/app/Services/PresupuestoClienteService.php index d4e91877..bf6c6408 100644 --- a/ci4/app/Services/PresupuestoClienteService.php +++ b/ci4/app/Services/PresupuestoClienteService.php @@ -341,9 +341,10 @@ class PresupuestoClienteService extends BaseService $alto = $data['alto'] ?? -1; $POD = $data['POD'] ?? -1; $solapas = $data['solapas'] ?? -1; + $paginasCuadernillo = $data['paginasCuadernillo'] ?? null; $model = model('App\Models\Presupuestos\PresupuestoEncuadernacionesModel'); - $values = $model->initPresupuesto($tipo_impresion_id, $solapas, $tirada, $paginas, $ancho, $alto, $POD); + $values = $model->initPresupuesto($tipo_impresion_id, $solapas, $tirada, $paginas, $ancho, $alto, $POD, $paginasCuadernillo); return $values; } @@ -384,7 +385,7 @@ class PresupuestoClienteService extends BaseService $POD = $data['POD'] ?? -1; $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel'); - $values = $model->getPrecioTarifa($tarifa_id, $tirada, $POD); + $values = $model->getPrecioTarifa($tarifa_id, $tirada, -1, $POD); // proveedor más barato return $values; } diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index e7d4899e..781b8127 100755 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -1353,7 +1353,14 @@ class PresupuestoService extends BaseService $model = new PresupuestoAcabadosModel(); foreach ($servicios as $servicio) { - $nueva_tarifa = $model->getPrecioTarifa($servicio->tarifa_acabado_id, $input_data['tirada'], $input_data['POD']); + // Si es un presupuesto duplicado hay que buscar el proveedor más barato + if($input_data['is_duplicado']){ + $nueva_tarifa = $model->getPrecioTarifa($servicio->tarifa_acabado_id, $input_data['tirada'], -1, $input_data['POD']); + } + else{ + $nueva_tarifa = $model->getPrecioTarifa($servicio->tarifa_acabado_id, $input_data['tirada'], $servicio->proveedor_id, $input_data['POD']); + } + if($nueva_tarifa && count($nueva_tarifa)>0){ if(round($nueva_tarifa[0]->precio_unidad, 2) != round($servicio->precio_unidad,2) || $nueva_tarifa[0]->margen != $servicio->margen){ @@ -1421,12 +1428,14 @@ class PresupuestoService extends BaseService // Si es un presupuesto duplicado hay que buscar el proveedor más barato if($input_data['is_duplicado']){ if($tarifaModel->isTarifaPorHoras($servicio->tarifa_encuadernado_id)){ + $paginas_cuadernillo = $servicio->paginas_por_cuadernillo??null; $nueva_tarifa = $model->getPrecioTarifaHoras( $servicio->tarifa_encuadernado_id, $input_data['paginas'], $input_data['tirada'], -1, - $input_data['POD']); + $input_data['POD'], + $paginas_cuadernillo); }else{ $nueva_tarifa = $model->getPrecioTarifa( $servicio->tarifa_encuadernado_id, @@ -1443,12 +1452,14 @@ class PresupuestoService extends BaseService // con el mismo proveedor else{ if($tarifaModel->isTarifaPorHoras($servicio->tarifa_encuadernado_id)){ + $paginas_cuadernillo = $servicio->paginas_por_cuadernillo??null; $nueva_tarifa = $model->getPrecioTarifaHoras( $servicio->tarifa_encuadernado_id, $input_data['paginas'], $input_data['tirada'], $servicio->proveedor_id, - $input_data['POD']); + $input_data['POD'], + $paginas_cuadernillo); }else{ $nueva_tarifa = $model->getPrecioTarifa( $servicio->tarifa_encuadernado_id, @@ -1818,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/app/Views/themes/vuexy/form/facturas/_facturaCabeceraItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_facturaCabeceraItems.php index 4bba5e7f..06227a6f 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/_facturaCabeceraItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_facturaCabeceraItems.php @@ -191,15 +191,15 @@ - - + + id), + '' . + lang("Facturas.exportarLineas"), + [ + "class" => "btn btn-label-primary float-start me-sm-3 me-1", + ] + ) ?>