diff --git a/ci4/app/Config/RBAC/permissionMatrix.php b/ci4/app/Config/RBAC/permissionMatrix.php
index cb1c244e..73df04d0 100644
--- a/ci4/app/Config/RBAC/permissionMatrix.php
+++ b/ci4/app/Config/RBAC/permissionMatrix.php
@@ -9,10 +9,10 @@ const SK_PERMISSION_MATRIX = [
"plantilla-tarifa.edit",
"plantilla-tarifa.delete",
"plantilla-tarifa.menu",
- "perfil.create",
- "perfil.edit",
- "perfil.delete",
- "perfil.menu",
+ "direcciones.create",
+ "direcciones.edit",
+ "direcciones.delete",
+ "direcciones.menu",
"presupuesto.create",
"presupuesto.edit",
"presupuesto.delete",
@@ -21,6 +21,14 @@ const SK_PERMISSION_MATRIX = [
"presupuesto-cliente.edit",
"presupuesto-cliente.delete",
"presupuesto-cliente.menu",
+ "pedidos-activos.view",
+ "pedidos-activos.menu",
+ "pedidos-finalizados.view",
+ "pedidos-finalizados.menu",
+ "pedidos-cancelados.view",
+ "pedidos-cancelados.menu",
+ "pedidos-todos.view",
+ "pedidos-todos.menu",
"tarifa-preimpresion.create",
"tarifa-preimpresion.edit",
"tarifa-preimpresion.delete",
@@ -41,10 +49,6 @@ const SK_PERMISSION_MATRIX = [
"tarifa-envio.edit",
"tarifa-envio.delete",
"tarifa-envio.menu",
- "tarifa-extra.create",
- "tarifa-extra.edit",
- "tarifa-extra.delete",
- "tarifa-extra.menu",
"proveedores.create",
"proveedores.edit",
"proveedores.delete",
@@ -61,10 +65,6 @@ const SK_PERMISSION_MATRIX = [
"paises.edit",
"paises.delete",
"paises.menu",
- "formas-pago.create",
- "formas-pago.edit",
- "formas-pago.delete",
- "formas-pago.menu",
"maquinas.create",
"maquinas.edit",
"maquinas.delete",
@@ -89,48 +89,48 @@ const SK_PERMISSION_MATRIX = [
"roles-permisos.edit",
"roles-permisos.delete",
"roles-permisos.menu",
- "ubicaciones.create",
- "ubicaciones.edit",
- "ubicaciones.delete",
- "ubicaciones.menu",
- "series-facturas.create",
- "series-facturas.edit",
- "series-facturas.delete",
- "series-facturas.menu",
],
"cliente-admin" => [
- "perfil.edit",
- "perfil.menu",
- "direcciones.create",
- "direcciones.edit",
- "direcciones.delete",
- "direcciones.menu",
"presupuesto-cliente.create",
"presupuesto-cliente.edit",
"presupuesto-cliente.delete",
"presupuesto-cliente.menu",
+ "pedidos-activos.view",
+ "pedidos-activos.menu",
+ "pedidos-finalizados.view",
+ "pedidos-finalizados.menu",
+ "pedidos-cancelados.view",
+ "pedidos-cancelados.menu",
+ "pedidos-todos.view",
+ "pedidos-todos.menu",
],
"cliente-editor" => [
- "perfil.create",
- "perfil.edit",
- "perfil.delete",
- "perfil.menu",
- "direcciones.create",
- "direcciones.edit",
- "direcciones.delete",
- "direcciones.menu",
"presupuesto-cliente.create",
"presupuesto-cliente.edit",
- "presupuesto-cliente.delete",
"presupuesto-cliente.menu",
+ "pedidos-activos.view",
+ "pedidos-activos.menu",
+ "pedidos-finalizados.view",
+ "pedidos-finalizados.menu",
+ "pedidos-cancelados.view",
+ "pedidos-cancelados.menu",
+ "pedidos-todos.view",
+ "pedidos-todos.menu",
],
"comercial" => [
"token.token",
"token.menu",
],
"produccion" => [
- "token.token",
- "token.menu",
+ "clientes.create",
+ "clientes.edit",
+ "clientes.menu",
+ "direcciones.create",
+ "direcciones.edit",
+ "direcciones.menu",
+ "presupuesto.create",
+ "presupuesto.edit",
+ "presupuesto.menu",
],
"maquina" => [
"token.token",
@@ -163,10 +163,10 @@ const SK_PERMISSION_MATRIX = [
"plantilla-tarifa.edit",
"plantilla-tarifa.delete",
"plantilla-tarifa.menu",
- "perfil.create",
- "perfil.edit",
- "perfil.delete",
- "perfil.menu",
+ "direcciones.create",
+ "direcciones.edit",
+ "direcciones.delete",
+ "direcciones.menu",
"presupuesto.create",
"presupuesto.edit",
"presupuesto.delete",
@@ -175,6 +175,14 @@ const SK_PERMISSION_MATRIX = [
"presupuesto-cliente.edit",
"presupuesto-cliente.delete",
"presupuesto-cliente.menu",
+ "pedidos-activos.view",
+ "pedidos-activos.menu",
+ "pedidos-finalizados.view",
+ "pedidos-finalizados.menu",
+ "pedidos-cancelados.view",
+ "pedidos-cancelados.menu",
+ "pedidos-todos.view",
+ "pedidos-todos.menu",
"tarifa-preimpresion.create",
"tarifa-preimpresion.edit",
"tarifa-preimpresion.delete",
@@ -195,10 +203,6 @@ const SK_PERMISSION_MATRIX = [
"tarifa-envio.edit",
"tarifa-envio.delete",
"tarifa-envio.menu",
- "tarifa-extra.create",
- "tarifa-extra.edit",
- "tarifa-extra.delete",
- "tarifa-extra.menu",
"proveedores.create",
"proveedores.edit",
"proveedores.delete",
@@ -239,13 +243,5 @@ const SK_PERMISSION_MATRIX = [
"roles-permisos.edit",
"roles-permisos.delete",
"roles-permisos.menu",
- "ubicaciones.create",
- "ubicaciones.edit",
- "ubicaciones.delete",
- "ubicaciones.menu",
- "series-facturas.create",
- "series-facturas.edit",
- "series-facturas.delete",
- "series-facturas.menu",
],
];
diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php
index a974f2ad..14aa7581 100644
--- a/ci4/app/Config/Routes.php
+++ b/ci4/app/Config/Routes.php
@@ -76,6 +76,8 @@ $routes->group('tarifas', ['namespace' => 'App\Controllers\Tarifas'], function (
$routes->get('delete/(:num)', 'TarifaAcabados::delete/$1', ['as' => 'tarifaAcabadoDelete']);
$routes->post('datatable', 'TarifaAcabados::datatable', ['as' => 'tarifaAcabadoDT']);
$routes->get('select', 'TarifaAcabados::show_select', ["as" => "showSelectTarifaAcabado"]);
+ $routes->get('gettarifas', 'TarifaAcabados::getSelect2');
+
$routes->group('lineas', ['namespace' => 'App\Controllers\Tarifas\Acabados'], function ($routes) {
$routes->post('datatable', 'TarifaAcabadosLineas::datatable', ['as' => 'tarifaAcabadoLineasDT']);
$routes->post('datatable_editor', 'TarifaAcabadosLineas::datatable_editor', ['as' => 'tarifaAcabadoLineasDTE']);
@@ -171,6 +173,7 @@ $routes->group('tarifapreimpresion', ['namespace' => 'App\Controllers\Tarifas'],
$routes->get('delete/(:num)', 'Tarifapreimpresion::delete/$1', ['as' => 'deleteTarifapreimpresion']);
$routes->post('allmenuitems', 'Tarifapreimpresion::allItemsSelect', ['as' => 'select2ItemsOfTarifaspreimpresion']);
$routes->post('menuitems', 'Tarifapreimpresion::menuItems', ['as' => 'menuItemsOfTarifaspreimpresion']);
+ $routes->get('gettarifas', 'Tarifapreimpresion::getSelect2');
});
@@ -185,6 +188,7 @@ $routes->group('tarifaextra', ['namespace' => 'App\Controllers\Tarifas'], functi
$routes->get('delete/(:num)', 'Tarifaextra::delete/$1', ['as' => 'deleteTarifaextra']);
$routes->post('allmenuitems', 'Tarifaextra::allItemsSelect', ['as' => 'select2ItemsOfTarifasextra']);
$routes->post('menuitems', 'Tarifaextra::menuItems', ['as' => 'menuItemsOfTarifasextra']);
+ $routes->get('gettarifas', 'Tarifaextra::getSelect2');
});
@@ -200,6 +204,7 @@ $routes->group('tarifasmanipulado', ['namespace' => 'App\Controllers\Tarifas'],
$routes->post('allmenuitems', 'Tarifasmanipulado::allItemsSelect', ['as' => 'select2ItemsOfTarifasManipulado']);
$routes->post('menuitems', 'Tarifasmanipulado::menuItems', ['as' => 'menuItemsOfTarifasManipulado']);
$routes->get('select', 'Tarifasmanipulado::show_select', ["as" => "showSelectTarifaManipulado"]);
+ $routes->get('gettarifas', 'Tarifasmanipulado::getSelect2');
});
$routes->resource('tarifasmanipulado', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasmanipulado', 'except' => 'show,new,create,update']);
@@ -495,6 +500,7 @@ $routes->group('tarifasencuadernacion', ['namespace' => 'App\Controllers\Tarifas
$routes->post('datatable', 'Tarifasencuadernacion::datatable', ['as' => 'dataTableOfTarifasEncuadernacion']);
$routes->post('allmenuitems', 'Tarifasencuadernacion::allItemsSelect', ['as' => 'select2ItemsOfTarifasEncuadernacion']);
$routes->post('menuitems', 'Tarifasencuadernacion::menuItems', ['as' => 'menuItemsOfTarifasEncuadernacion']);
+ $routes->get('gettarifas', 'Tarifasencuadernacion::getSelect2');
});
$routes->resource('tarifasencuadernacion', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasencuadernacion', 'except' => 'show,new,create,update']);
@@ -619,6 +625,16 @@ $routes->group('presupuestoadmin', ['namespace' => 'App\Controllers\Presupuestos
$routes->post('datatable_2', 'Presupuestoadmin::datatable_2', ['as' => 'updateDataOfPresupuestoAdmin']);
$routes->post('allmenuitems', 'Presupuestoadmin::allItemsSelect', ['as' => 'select2ItemsOfPresupuestoAdmin']);
$routes->post('menuitems', 'Presupuestoadmin::menuItems', ['as' => 'menuItemsOfPresupuestoAdmin']);
+
+ $routes->get('cargar/(:any)', 'Presupuestoadmin::cargar/$1');
+ $routes->post('comparadorinterior', 'Presupuestoadmin::obtenerComparadorInterior');
+ $routes->post('comparadorexteriores', 'Presupuestoadmin::obtenerComparadorExteriores');
+ $routes->post('comparadorguardas', 'Presupuestoadmin::obtenerComparadorGuardas');
+ $routes->get('papelgenerico', 'Presupuestoadmin::getPapelGenerico');
+ $routes->get('papelgramaje', 'Presupuestoadmin::getGramaje');
+ $routes->get('papelimpresion', 'Presupuestoadmin::getPapelImpresion');
+ $routes->get('maquinas', 'Presupuestoadmin::getMaquinas');
+ $routes->post('getlinea', 'Presupuestoadmin::getLineaPresupuesto');
});
$routes->resource('presupuestoadmin', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Presupuestoadmin', 'except' => 'show,new,create,update']);
@@ -643,32 +659,43 @@ $routes->group('presupuestocliente', ['namespace' => 'App\Controllers\Presupuest
$routes->resource('presupuestocliente', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Presupuestocliente', 'except' => 'show,new,create,update']);
$routes->group('serviciosacabados', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) {
- $routes->post('datatable', 'Presupuestoacabados::datatable', ['as' => 'dataTableOfPresupuestoAcabados']);
+ $routes->get('getacabados', 'Presupuestoacabados::getAcabados');
+ $routes->post('getvalues', 'Presupuestoacabados::getRowValues');
$routes->post('menuitems', 'Presupuestoacabados::menuItems', ['as' => 'menuItemsOfPresupuestoAcabados']);
$routes->post('edit/(:num)', 'Presupuestoacabados::edit/$1', ['as' => 'updatePresupuestoacabados']);
- $routes->get('getacabados', 'Presupuestoacabados::getAcabados');
+ $routes->get('cargar', 'Presupuestoacabados::cargar');
+ $routes->post('update/(:num)', 'Presupuestoacabados::update/$1');
});
+
$routes->group('serviciosencuadernaciones', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) {
$routes->post('datatable', 'Presupuestoencuadernaciones::datatable', ['as' => 'dataTableOfPresupuestoEncuadernaciones']);
+ $routes->post('getvalues', 'Presupuestoencuadernaciones::getRowValues');
$routes->post('menuitems', 'Presupuestoencuadernaciones::menuItems', ['as' => 'menuItemsOfPresupuestoEncuadernaciones']);
$routes->get('delete/(:num)', 'Presupuestoencuadernaciones::delete/$1', ['as' => 'deletePresupuestoencuadernaciones']);
$routes->post('edit/(:num)', 'Presupuestoencuadernaciones::edit/$1', ['as' => 'updatePresupuestoencuadernaciones']);
+ $routes->post('update/(:num)', 'Presupuestoencuadernaciones::update/$1');
});
$routes->group('serviciosmanipulados', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) {
+ $routes->post('getvalues', 'Presupuestomanipulados::getRowValues');
$routes->post('datatable', 'Presupuestomanipulados::datatable', ['as' => 'dataTableOfPresupuestoManipulados']);
$routes->post('edit/(:num)', 'Presupuestomanipulados::edit/$1', ['as' => 'updatePresupuestomanipulados']);
+ $routes->post('update/(:num)', 'Presupuestomanipulados::update/$1');
+ $routes->get('serviciosolapas', 'Presupuestomanipulados::getServicioSolapas');
});
$routes->group('serviciospreimpresiones', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) {
+ $routes->post('getvalues', 'Presupuestopreimpresiones::getRowValues');
$routes->post('datatable', 'Presupuestopreimpresiones::datatable', ['as' => 'dataTableOfPresupuestoPreimpresiones']);
$routes->post('edit/(:num)', 'Presupuestopreimpresiones::edit/$1', ['as' => 'updatePresupuestopreimpresiones']);
+ $routes->get('cargar', 'Presupuestopreimpresiones::getSelect2');
});
$routes->group('serviciosextra', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) {
$routes->post('datatable', 'Presupuestoserviciosextra::datatable', ['as' => 'dataTableOfPresupuestoServiciosExtra']);
$routes->post('edit/(:num)', 'Presupuestoserviciosextra::edit/$1', ['as' => 'updatePresupuestoServiciosExtra']);
+ $routes->post('getvalues', 'Presupuestoserviciosextra::getRowValues');
});
$routes->group('presupuestodirecciones', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) {
diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php
index 8fcc153e..c537dd57 100755
--- a/ci4/app/Controllers/Configuracion/Users.php
+++ b/ci4/app/Controllers/Configuracion/Users.php
@@ -89,6 +89,8 @@ class Users extends \App\Controllers\GoBaseController
// Marcar el username como NULL
$sanitizedData = $this->sanitized($postData, true);
+ $email = $sanitizedData['email'];
+ unset($sanitizedData['email']);
$noException = true;
@@ -100,7 +102,7 @@ class Users extends \App\Controllers\GoBaseController
try {
// The Email is unique
- if ($this->user_model->isEmailUnique($sanitizedData['email'])) {
+ if ($this->user_model->isEmailUnique($email)) {
// Crear el usuario si pasa la validación
$user = new \CodeIgniter\Shield\Entities\User([
@@ -109,8 +111,6 @@ class Users extends \App\Controllers\GoBaseController
'last_name' => $sanitizedData['last_name'],
'cliente_id' => $sanitizedData['cliente_id'],
'comments' => $sanitizedData['comments'],
- 'email' => $sanitizedData['email'],
- 'password' => $sanitizedData['password'],
'status' => $sanitizedData['status'] ?? 0,
'active' => $sanitizedData['active'] ?? 0,
]);
diff --git a/ci4/app/Controllers/Js_loader.php b/ci4/app/Controllers/Js_loader.php
index e402c125..c2c056ce 100755
--- a/ci4/app/Controllers/Js_loader.php
+++ b/ci4/app/Controllers/Js_loader.php
@@ -33,13 +33,6 @@ class Js_loader extends BaseController
}
-
- function datosLibro_js()
- {
- $this->response->setHeader('Content-Type', 'text/javascript');
- return view('themes/vuexy/form/presupuestos/admin/_datosLibroItems.js');
- }
-
function previsualizador_js()
{
$this->response->setHeader('Content-Type', 'text/javascript');
diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoacabados.php b/ci4/app/Controllers/Presupuestos/Presupuestoacabados.php
index 18dc5743..39f80e0f 100755
--- a/ci4/app/Controllers/Presupuestos/Presupuestoacabados.php
+++ b/ci4/app/Controllers/Presupuestos/Presupuestoacabados.php
@@ -69,30 +69,61 @@ class Presupuestoacabados extends \App\Controllers\BaseResourceController
return;
endif;
- $postData = $this->request->getJSON();
- $tarifas = array_column($postData->datos, 'tarifa_id');
- $tirada = $postData->tirada ?? 0;
- $POD = $postData->POD ?? 0;
- $result = [];
-
- if (count($tarifas) > 0) {
- foreach ($tarifas as $tarifa) {
- $values = $this->model->getPrecioTarifa($tarifa, $tirada, $POD);
- array_push($result, $values);
- }
- }
+ $postData = $this->request->getPost();
+ $datos_tarifas = $postData['datos'] ?? [];
+ $tirada = $postData['tirada'] ?? 0;
+ $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value;
+
+ $result = $this->getServiciosAcabados($datos_tarifas, $tirada, $POD);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
- 'lines' => $result,
+ 'lineas' => $result,
$csrfTokenName => $newTokenHash
];
return $this->respond($data);
}
- public function datatable()
+ public function getServiciosAcabados($datos_tarifas, $tirada, $POD){
+
+ $model = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
+ $result = [];
+ if (count($datos_tarifas) > 0) {
+ foreach ($datos_tarifas as $tarifa) {
+ $proveedor = $tarifa['proveedor_id'] == '' ? -1 : $tarifa['proveedor_id'];
+
+ $values = $model->getPrecioTarifa($tarifa['tarifa_id'], $tirada, $proveedor, $POD);
+ $values[0]->cubierta = $tarifa['cubierta'] ?? 0;
+ $values[0]->sobrecubierta = $tarifa['sobrecubierta'] ?? 0;
+ array_push($result, $values[0]);
+ }
+ }
+ return $result;
+ }
+
+ public function cargar()
+ {
+ if($this->request->isAJAX()) {
+ $presupuesto_id = $this->request->getGet('presupuesto_id') ?? null;
+
+ $rows = $this->model->getResource($presupuesto_id)->get()->getResultObject();
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+ $data = [
+ 'rows' => $rows,
+ $csrfTokenName => $newTokenHash
+ ];
+
+ return $this->respond($data);
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function getRowValues()
{
if ($this->request->isAJAX()) {
$reqData = $this->request->getPost();
@@ -100,7 +131,7 @@ 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;
+ $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value;
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@@ -195,4 +226,6 @@ class Presupuestoacabados extends \App\Controllers\BaseResourceController
return $this->failUnauthorized('Invalid request', 403);
}
}
+
+
}
diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php
index a302751f..f0e9a459 100644
--- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php
+++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php
@@ -6,6 +6,8 @@ use App\Entities\Presupuestos\PresupuestoEntity;
use App\Models\Collection;
use App\Models\Configuracion\MaquinaModel;
use App\Models\Configuracion\PapelGenericoModel;
+use App\Models\Configuracion\PapelFormatoModel;
+use App\Models\Clientes\ClienteModel;
use App\Models\Configuracion\PapelImpresionModel;
use App\Models\Configuracion\TipoPresupuestoModel;
use App\Models\Presupuestos\PresupuestoAcabadosModel;
@@ -17,6 +19,7 @@ use App\Models\Presupuestos\PresupuestoModel;
use App\Models\Presupuestos\PresupuestoPreimpresionesModel;
use App\Models\Presupuestos\PresupuestoServiciosExtraModel;
use App\Services\PresupuestoService;
+use App\Services\PresupuestoClienteService;
use Exception;
class Presupuestoadmin extends \App\Controllers\BaseResourceController
@@ -78,12 +81,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
public function add($tipo_impresion_id = null)
{
+ if ($this->request->getPost()):
-
-
- if ($this->request->getPost()) :
-
- $nullIfEmpty = true; // !(phpversion() >= '8.1');
+ $nullIfEmpty = false; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
@@ -101,36 +101,36 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
}
$noException = true;
- if ($successfulResult = $this->canValidate($this->model->validationRulesAdd, $this->model->validationMessagesAdd)) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
+ if ($successfulResult = $this->canValidate($this->model->validationRulesAdd, $this->model->validationMessagesAdd)): // if ($successfulResult = $this->validate($this->formValidationRules) ) :
- if ($this->canValidate($this->model->validationRulesAdd, $this->model->validationMessagesAdd)) :
+ if ($this->canValidate($this->model->validationRulesAdd, $this->model->validationMessagesAdd)):
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
- else :
+ else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Presupuestos.presupuesto'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif;
- if ($noException && $successfulResult) :
+ if ($noException && $successfulResult):
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
- if ($thenRedirect) :
- if (!empty($this->indexRoute)) :
+ if ($thenRedirect):
+ if (!empty($this->indexRoute)):
//return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
return redirect()->to(site_url('presupuestoadmin/edit/' . $id))->with('sweet-success', $message);
- else :
+ else:
return $this->redirect2listView('sweet-success', $message);
endif;
- else :
+ else:
$this->session->setFlashData('sweet-success', $message);
endif;
@@ -146,8 +146,6 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$this->viewData['clienteList'] = $this->getClienteListItems($presupuestoEntity->cliente_id ?? null);
$this->viewData['incReiList'] = array('incidencia' => lang('Presupuestos.incidencia'), 'reimpresion' => lang('Presupuestos.reimpresion'), 'sin_cargo' => lang('Presupuestos.sinCargo'));
- $this->viewData['paisList'] = $this->getPaisListItems();
- $this->viewData['papelFormatoList'] = $this->getPapelFormatoListItems($presupuestoEntity->papel_formato_id ?? null);
$this->viewData['POD'] = $this->getPOD();
@@ -164,20 +162,20 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
public function edit($requestedId = null)
{
- if ($requestedId == null) :
+ if ($requestedId == null):
return $this->redirect2listView();
endif;
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
$presupuestoEntity = $this->model->find($id);
- if ($presupuestoEntity == false) :
+ if ($presupuestoEntity == false):
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Presupuestos.presupuesto')), $id]);
return $this->redirect2listView('sweet-error', $message);
endif;
-
- if ($this->request->getPost()) :
+
+ if ($this->request->getPost()):
$nullIfEmpty = true; // !(phpversion() >= '8.1');
@@ -249,16 +247,16 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$successfulResult = false;
} else {
- if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) )
+ if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) )
- if ($this->canValidate()) :
+ if ($this->canValidate()):
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
- else :
+ else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Presupuestos.presupuesto'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
@@ -270,16 +268,16 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
endif;
}
- if ($noException && $successfulResult) :
+ if ($noException && $successfulResult):
$id = $presupuestoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Presupuestos.presupuesto'))]) . '.';
// $message .= anchor("admin/presupuestos/{$id}/edit", lang('Basic.global.continueEditing') . '?');
//$message = ucfirst(str_replace("'", "\'", $message));
- if ($thenRedirect) :
- if (!empty($this->indexRoute)) :
+ if ($thenRedirect):
+ if (!empty($this->indexRoute)):
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
- else :
+ else:
if ($this->request->isAJAX()) {
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@@ -293,14 +291,14 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
}
endif;
- else :
+ else:
if ($this->request->isAJAX()) {
- if($presupuestoEntity->estado_id==1 && $presupuestoEntity->confirmar==1){
+ if ($presupuestoEntity->estado_id == 1 && $presupuestoEntity->confirmar == 1) {
$this->model->confirmarPresupuesto($id);
PresupuestoService::crearPedido($id);
}
-
+
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
@@ -327,51 +325,6 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
else
$this->viewData['comp_data'] = "";
- $this->viewData['clienteList'] = $this->getClienteListItems($presupuestoEntity->cliente_id ?? null);
- $this->viewData['paisList'] = $this->getPaisListItems();
- $this->viewData['ccaaList'] = $this->getCcaaListItems();
-
- $this->viewData['clienteList'] = $this->getClienteListItems($presupuestoEntity->cliente_id ?? null);
- $this->viewData['incReiList'] = array('incidencia' => lang('Presupuestos.incidencia'), 'reimpresion' => lang('Presupuestos.reimpresion'), 'sin_cargo' => lang('Presupuestos.sinCargo'));
- $this->viewData['papelFormatoList'] = $this->getPapelFormatoListItems($presupuestoEntity->papel_formato_id ?? null);
- $this->viewData['papelGenericoNegroList'] = $this->getPapelGenericoNegro();
- $this->viewData['papelGenericoNegroHQList'] = $this->getPapelGenericoNegroHQ();
- $this->viewData['papelGenericoColorList'] = $this->getPapelGenericoColor();
- $this->viewData['papelGenericoColorHQList'] = $this->getPapelGenericoColorHQ();
- $this->viewData['papelGenericoCubiertaList'] = $this->getPapelGenericoCubierta();
- $this->viewData['papelGenericoGuardasList'] = $this->getPapelGenericoGuardas();
- $this->viewData['papelGenericoSobrecubiertaList'] = $this->getPapelGenericoSobreCubierta();
- $this->viewData['papelGenericoRotativaNegroList'] = $this->getPapelGenericoRotativaNegro();
- $this->viewData['papelGenericoRotativaColorList'] = $this->getPapelGenericoRotativaColor();
-
- // Acabados exteriores
- $this->viewData['acabadosCubierta'] = $this->getAcabadosCubierta();
- $this->viewData['acabadosSobrecubierta'] = $this->getAcabadosSobrecubierta();
-
- // Lineas Presupuesto
- [$cambios_lineas, $this->viewData['lineasPresupuesto']] = $this->getLineasPresupuesto($presupuestoEntity);
- $this->viewData['presupuestoEntity']->cambios_lineas=$cambios_lineas;
-
- // Servicios
- $this->viewData['serviciosPreimpresion'] = $this->getServiciosPreimpresion();
- $this->viewData['serviciosEncuadernacion'] = $this->getServiciosEncuadernacion();
- $this->viewData['serviciosManipulado'] = $this->getServiciosManipulado();
- $this->viewData['serviciosAcabado'] = $this->getServiciosAcabado();
- $this->viewData['serviciosExtra'] = $this->getServiciosExtra();
-
- [$cambios_en_servicios, $servicios] = $this->getLineasServicios($presupuestoEntity);
- $this->viewData['presupuestoEntity']->cambios_servicios=$cambios_en_servicios;
-
- $this->viewData['serviciosEncuadernacionList'] = $servicios->serviciosEncuadernacion;
- $this->viewData['serviciosAcabadosList'] = $servicios->serviciosAcabado;
- $this->viewData['serviciosManipuladoList'] = $servicios->serviciosManipulado;
- $this->viewData['serviciosPreimpresionList'] = $servicios->serviciosPreimpresion;
- $this->viewData['serviciosExtraList'] = $servicios->serviciosExtra;
-
- // Direciones presupuesto
- [$cambios_en_direcciones, $this->viewData['direccionesList']] = $this->getLineasDirecciones($presupuestoEntity);
- $this->viewData['presupuestoEntity']->cambios_direcciones=$cambios_en_direcciones;
-
$this->viewData['POD'] = $this->getPOD();
$this->viewData['serviciosAutomaticos'] = [
@@ -391,7 +344,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
// Si se ha llamado a esta funcion porque se ha duplicado el presupuesto
// se actualiza la bbdd para que sólo ejecute algunas funciones una vez
- if($presupuestoEntity->is_duplicado){
+ if ($presupuestoEntity->is_duplicado) {
$this->model->removeIsDuplicado($presupuestoEntity->id);
}
@@ -411,22 +364,23 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
public function delete($id = null)
{
if (!empty(static::$pluralObjectNameCc) && !empty(static::$singularObjectNameCc)) {
- $objName = mb_strtolower(lang(ucfirst(static::$pluralObjectNameCc).'.'.static::$singularObjectNameCc));
+ $objName = mb_strtolower(lang(ucfirst(static::$pluralObjectNameCc) . '.' . static::$singularObjectNameCc));
} else {
$objName = lang('Basic.global.record');
}
-
- if (!$this->soft_delete){
+
+ if (!$this->soft_delete) {
if (!$this->model->delete($id)) {
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
}
- }
- else{
+ } else {
$datetime = (new \CodeIgniter\I18n\Time("now"));
- $rawResult = $this->model->where('id',$id)
- ->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
- 'is_deleted' => $this->delete_flag])
+ $rawResult = $this->model->where('id', $id)
+ ->set([
+ 'deleted_at' => $datetime->format('Y-m-d H:i:s'),
+ 'is_deleted' => $this->delete_flag
+ ])
->update();
if (!$rawResult) {
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
@@ -468,6 +422,321 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
return $response;
}
+ public function cargar($id)
+ {
+ if ($this->request->isAJAX()) {
+
+ $modelPapelFormato = new PapelFormatoModel();
+ $modelCliente = new ClienteModel();
+ $modelPapelGenerico = new PapelGenericoModel();
+
+
+ $presupuesto = $this->model->find($id);
+ $data = [];
+ if ($presupuesto) {
+
+ $data['lc'] = $presupuesto->lomo_cubierta;
+ $data['lsc'] = $presupuesto->lomo_sobrecubierta;
+ $data['tipo_impresion'] = $presupuesto->tipo_impresion_id;
+ $data['cosido'] = $presupuesto->cosido;
+ $data['POD'] = $this->getPOD();
+
+ $data['datosGenerales']['id'] = $presupuesto->id;
+ $data['datosGenerales']['state'] = intval($presupuesto->estado_id);
+ $data['datosGenerales']['updated_at'] = date('d/m/Y', strtotime($presupuesto->updated_at));
+ $data['datosGenerales']['created_at'] = date('d/m/Y', strtotime($presupuesto->created_at));
+ $data['datosGenerales']['inc_rei'] = $presupuesto->inc_rei == null ? 0 : $presupuesto->inc_rei;
+ $data['datosGenerales']['titulo'] = $presupuesto->titulo;
+ $data['datosGenerales']['autor'] = $presupuesto->autor;
+ $data['datosGenerales']['coleccion'] = $presupuesto->coleccion;
+ $data['datosGenerales']['numero_edicion'] = $presupuesto->numero_edicion;
+ $data['datosGenerales']['isbn'] = $presupuesto->isbn;
+ $data['datosGenerales']['pais'] = $presupuesto->pais_id;
+ $data['datosGenerales']['pais_nombre'] = model('App\Models\Configuracion\PaisModel')->find($presupuesto->pais_id)->nombre;
+ $data['datosGenerales']['cliente']['id'] = $presupuesto->cliente_id;
+ $data['datosGenerales']['cliente']['nombre'] = $modelCliente->getNombre($presupuesto->cliente_id);
+ $data['datosGenerales']['referenciaCliente'] = $presupuesto->referencia_cliente;
+
+
+ $data['datosLibro']['papelFormatoId'] = $presupuesto->papel_formato_id;
+ $data['datosLibro']['papelFormatoNombre'] = $modelPapelFormato->getNombre($presupuesto->papel_formato_id);
+ $data['datosLibro']['papelFormatoPersonalizado'] = $presupuesto->papel_formato_personalizado;
+ $data['datosLibro']['papelFormatoAncho'] = $presupuesto->papel_formato_ancho;
+ $data['datosLibro']['papelFormatoAlto'] = $presupuesto->papel_formato_alto;
+ $data['datosLibro']['paginas'] = $presupuesto->paginas;
+ $data['datosLibro']['tirada'] = $presupuesto->tirada;
+ $data['datosLibro']['merma'] = $presupuesto->merma;
+ $data['datosLibro']['mermaCubierta'] = $presupuesto->merma_cubierta;
+ $data['datosLibro']['solapasCubierta'] = $presupuesto->solapas;
+ $data['datosLibro']['solapasSobrecubierta'] = $presupuesto->solapas_sobrecubierta;
+ $data['datosLibro']['solapasCubiertaAncho'] = $presupuesto->solapas_ancho;
+ $data['datosLibro']['solapasSobrecubiertaAncho'] = $presupuesto->solapas_ancho_sobrecubierta;
+ $modelAcabado = model("App\Models\Tarifas\Acabados\TarifaAcabadoModel");
+ $data['datosLibro']['acabadoCubierta']['id'] = $presupuesto->acabado_cubierta_id;
+ if ($presupuesto->acabado_cubierta_id == 0) {
+ $data['datosLibro']['acabadoCubierta']['text'] = "Ninguno";
+ } else {
+ $data['datosLibro']['acabadoCubierta']['text'] = $modelAcabado->find($presupuesto->acabado_cubierta_id)->nombre;
+ }
+ $data['datosLibro']['acabadoSobrecubierta']['id'] = $presupuesto->acabado_sobrecubierta_id;
+ if ($presupuesto->acabado_sobrecubierta_id == 0) {
+ $data['datosLibro']['acabadoSobrecubierta']['text'] = "Ninguno";
+ } else {
+ $data['datosLibro']['acabadoSobrecubierta']['text'] = $modelAcabado->find($presupuesto->acabado_sobrecubierta_id)->nombre;
+ }
+ $data['datosLibro']['prototipo'] = $presupuesto->prototipo;
+ $data['datosLibro']['ferro'] = $presupuesto->ferro;
+ $data['datosLibro']['ferroDigital'] = $presupuesto->ferro_digital;
+ $data['datosLibro']['marcapaginas'] = $presupuesto->marcapaginas;
+ $data['datosLibro']['retractilado'] = $presupuesto->retractilado;
+ $data['datosLibro']['retractilado5'] = $presupuesto->retractilado5;
+ $data['datosLibro']['fajaColor'] = $presupuesto->faja_color;
+
+ $data['comparador']['tipo_impresion'] = $presupuesto->comp_tipo_impresion;
+ $data['comparador']['json_data'] = json_decode($presupuesto->comparador_json_data, true);
+ if ($data['comparador']['json_data'] != null) {
+ foreach ($data['comparador']['json_data'] as &$item) {
+ $item['papel_nombre'] = $modelPapelGenerico->getNombre($item['papel_id'])['nombre'];
+ }
+ }
+ $data['comparador']['posPagColor'] = $presupuesto->comp_pos_paginas_color;
+ $data['comparador']['lomoRedondo'] = $presupuesto->lomo_redondo;
+ $data['comparador']['cabezada'] = $presupuesto->cabezada;
+
+ $data['lineasPresupuesto'] = $this->loadLineasPresupuesto($presupuesto);
+
+ $data['servicios'] = $this->getLineasServicios($presupuesto)[1];
+
+ if (intval($presupuesto->envios_recoge_cliente) == 1) {
+ $data['direcciones']['entrega_taller'] = 1;
+ } else {
+ $data['direcciones']['entrega_taller'] = 0;
+ $data['direcciones'] = $this->obtenerDireccionesEnvio($id, $presupuesto->cliente_id);
+ }
+
+ $data['comentarios_cliente'] = $presupuesto->comentarios_cliente;
+ $data['comentarios_safekat'] = $presupuesto->comentarios_safekat;
+ $data['comentarios_presupuesto'] = $presupuesto->comentarios_presupuesto;
+ $data['comentarios_produccion'] = $presupuesto->comentarios_produccion;
+
+ $data['tiradasAlternativas'] = json_decode($presupuesto->tirada_alternativa_json_data);
+
+ $data['resumen']['total_coste_papel'] = $presupuesto->total_coste_papel;
+ $data['resumen']['total_margenPercent_papel'] = $presupuesto->total_margenPercent_papel;
+ $data['resumen']['total_margen_papel'] = $presupuesto->total_margen_papel;
+ $data['resumen']['total_coste_impresion'] = $presupuesto->total_coste_impresion;
+ $data['resumen']['total_margenPercent_impresion'] = $presupuesto->total_margenPercent_impresion;
+ $data['resumen']['total_margen_impresion'] = $presupuesto->total_margen_impresion;
+ $data['resumen']['total_coste_servicios'] = $presupuesto->total_coste_servicios;
+ $data['resumen']['total_margenPercent_servicios'] = $presupuesto->total_margenPercent_servicios;
+ $data['resumen']['total_margen_servicios'] = $presupuesto->total_margen_servicios;
+ $data['resumen']['total_coste_envios'] = $presupuesto->total_coste_envios;
+ $data['resumen']['total_margen_envios'] = $presupuesto->total_margen_envios;
+ $data['resumen']['total_costes'] = $presupuesto->total_costes;
+ $data['resumen']['porcentajeMargen'] =
+ round(($presupuesto->total_costes + $presupuesto->total_margenes) > 0 ?
+ 100 * $presupuesto->total_margenes / ($presupuesto->total_costes + $presupuesto->total_margenes) :
+ 0, 0);
+ $data['resumen']['total_margenes'] = $presupuesto->total_margenes;
+ $data['resumen']['total_antes_descuento'] = $presupuesto->total_antes_descuento;
+ $data['resumen']['total_descuentoPercent'] = $presupuesto->total_descuentoPercent;
+ $data['resumen']['total_descuento'] = $presupuesto->total_descuento;
+ $data['resumen']['total_presupuesto'] = $presupuesto->total_presupuesto;
+ $data['resumen']['total_precio_unidad'] = $presupuesto->total_precio_unidad;
+ $data['resumen']['total_factor'] = is_numeric($presupuesto->total_factor) ? $presupuesto->total_factor : 0;
+ $data['resumen']['total_factor_ponderado'] = is_numeric($presupuesto->total_factor_ponderado) ? $presupuesto->total_factor_ponderado : 0;
+ if ($presupuesto->estado_id == 2) {
+ $data['resumen']['total_aceptado'] = $presupuesto->total_aceptado;
+ }
+ return $this->respond([
+ 'status' => 1,
+ 'data' => $data
+ ]);
+ }
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+
+ public function obtenerComparadorInterior()
+ {
+
+ if ($this->request->isAJAX()) {
+
+ $cliente_id = $this->request->getPost('cliente_id');
+ $datosPedido = $this->request->getPost('datosPedido');
+ $papel_generico = $this->request->getPost('papel_generico');
+ $gramaje = $this->request->getPost('gramaje');
+ $paginas_color = $this->request->getPost('paginas_color');
+ $isColor = $this->request->getPost('isColor') ? 1 : 0;
+ $isHq = $this->request->getPost('isHq') ? 1 : 0;
+ $tipo_impresion_id = $this->request->getPost('tipo_impresion_id');
+ $uso = $this->request->getPost('uso');
+
+ $tipo_maquina = $this->request->getPost('tipo_maquina');
+
+ $data = array(
+ 'cliente_id' => $cliente_id,
+ 'datosPedido' => (object) $datosPedido,
+ 'papel_generico' => $papel_generico,
+ 'gramaje' => $gramaje,
+ 'papelInteriorDiferente' => true,
+ 'paginas_color' => $paginas_color,
+ 'isColor' => $isColor,
+ 'isHq' => $isHq,
+ 'tipo_impresion_id' => $tipo_impresion_id,
+ 'uso' => $uso
+ );
+
+ if ($tipo_maquina == 'rotativa') {
+ $data['papelInteriorDiferente'] = false;
+ $lineas = PresupuestoClienteService::obtenerPresupuestoClienteInteriorRotativa($data, true);
+ } else
+ $lineas = PresupuestoClienteService::obtenerPresupuestoClienteInterior($data, true);
+ return $this->respond(
+ [
+ 'status' => 1,
+ 'data' => $lineas
+ ]
+ );
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+
+ public function obtenerComparadorExteriores()
+ {
+
+ $lineasCubierta = null;
+ $lineasSobrecubierta = null;
+
+ if ($this->request->isAJAX()) {
+
+ $cubierta = $this->request->getPost('cubierta') ?? false;
+ $sobrecubierta = $this->request->getPost('sobrecubierta') ?? false;
+
+ // cubierta y sobrecubierta siempre colorhq
+ $isColor = true;
+ $isHq = true;
+
+ if ($cubierta) {
+
+ $cliente_id = $cubierta['cliente_id'];
+ $datosPedido = $cubierta['datosPedido'];
+ $papel_generico = $cubierta['papel_generico'];
+ $gramaje = $cubierta['gramaje'];
+ $paginas_color = $cubierta['datosPedido']['paginas'] ?? 0;
+ $tipo_impresion_id = $cubierta['tipo_impresion_id'];
+ $uso = $cubierta['uso'];
+ $lomoRedondo = $cubierta['lomoRedondo'] ?? false;
+
+ $data = array(
+ 'cliente_id' => $cliente_id,
+ 'datosPedido' => (object) $datosPedido,
+ 'papel_generico' => $papel_generico,
+ 'gramaje' => $gramaje,
+ 'paginas_color' => $paginas_color,
+ 'isColor' => 1, // cubierta y sobre cubierta colorhq
+ 'isHq' => 1, // cubierta y sobre cubierta colorhq
+ 'tipo_impresion_id' => $tipo_impresion_id,
+ 'uso' => $uso,
+ 'lomoRedondo' => $lomoRedondo
+ );
+ $lineasCubierta = PresupuestoClienteService::obtenerCubierta($data, true);
+ }
+
+ if ($sobrecubierta) {
+
+ $cliente_id = $sobrecubierta['cliente_id'];
+ $datosPedido = $sobrecubierta['datosPedido'];
+ $papel_generico = $sobrecubierta['papel_generico'];
+ $gramaje = $sobrecubierta['gramaje'];
+ $paginas_color = $sobrecubierta['datosPedido']['paginas'] ?? 0;
+ $tipo_impresion_id = $sobrecubierta['tipo_impresion_id'];
+ $uso = $sobrecubierta['uso'];
+
+ $data = array(
+ 'cliente_id' => $cliente_id,
+ 'datosPedido' => (object) $datosPedido,
+ 'papel_generico' => $papel_generico,
+ 'gramaje' => $gramaje,
+ 'paginas_color' => $paginas_color,
+ 'isColor' => 1, // cubierta y sobre cubierta colorhq
+ 'isHq' => 1, // cubierta y sobre cubierta colorhq
+ 'tipo_impresion_id' => $tipo_impresion_id,
+ 'uso' => $uso
+ );
+ $lineasSobrecubierta = PresupuestoClienteService::obtenerSobrecubierta($data, true);
+ }
+
+ return $this->respond(
+ [
+ 'status' => 1,
+ 'data' => (object) array(
+ 'cubierta' => $lineasCubierta,
+ 'sobrecubierta' => $lineasSobrecubierta
+ )
+ ]
+ );
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+
+ public function obtenerComparadorGuardas()
+ {
+
+ if ($this->request->isAJAX()) {
+
+ $cliente_id = $this->request->getPost('cliente_id');
+ $datosPedido = $this->request->getPost('datosPedido');
+ $papel_generico = $this->request->getPost('papel_generico');
+ $gramaje = $this->request->getPost('gramaje');
+ $paginas_color = $this->request->getPost('paginas_color');
+ $isColor = $this->request->getPost('isColor');
+ $isHq = $this->request->getPost('isHq');
+ $tipo_impresion_id = $this->request->getPost('tipo_impresion_id');
+ $uso = $this->request->getPost('uso');
+
+ // Para el caso de Fresado y Cosido tapa dura, las guardas son un diptico
+ // y hay que imprimirlas como "cosido" (dos hojas pegadas). En el caso de espiral
+ // o wire-o tapa dura, las guardas se imprimen como hojas sueltas
+ if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3) {
+ $datosPedido['isCosido'] = true;
+ } else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 7) {
+ $datosPedido['isCosido'] = false;
+ }
+
+ $datosPedido['paginas_impresion'] = $datosPedido['paginas'];
+
+ $data = array(
+ 'cliente_id' => $cliente_id,
+ 'datosPedido' => (object) $datosPedido,
+ 'papel_generico' => $papel_generico,
+ 'gramaje' => $gramaje,
+ 'papelInteriorDiferente' => true,
+ 'paginas_color' => $paginas_color,
+ 'isColor' => $isColor,
+ 'isHq' => $isHq,
+ 'tipo_impresion_id' => $tipo_impresion_id,
+ 'uso' => $uso
+ );
+
+ $lineas = PresupuestoClienteService::obtenerGuardas($data, true);
+ return $this->respond(
+ [
+ 'status' => 1,
+ 'data' => $lineas
+ ]
+ );
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
public function datatable()
{
@@ -506,178 +775,45 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$resourceData = $this->model->getResource($searchValues, $tipo_impresion_id)->orderBy($order1, $dir1)->orderBy($order2, $dir2)
->orderBy($order3, $dir3)->limit($length, $start)->get()->getResultObject();
- foreach ($resourceData as $item) :
- if (isset($item->comentarios_pdf) && strlen($item->comentarios_pdf) > 100) :
+ foreach ($resourceData as $item):
+ if (isset($item->comentarios_pdf) && strlen($item->comentarios_pdf) > 100):
$item->comentarios_pdf = character_limiter($item->comentarios_pdf, 100);
endif;
- if (isset($item->causa_cancelacion) && strlen($item->causa_cancelacion) > 100) :
+ if (isset($item->causa_cancelacion) && strlen($item->causa_cancelacion) > 100):
$item->causa_cancelacion = character_limiter($item->causa_cancelacion, 100);
endif;
- if (isset($item->comentarios_cliente) && strlen($item->comentarios_cliente) > 100) :
+ if (isset($item->comentarios_cliente) && strlen($item->comentarios_cliente) > 100):
$item->comentarios_cliente = character_limiter($item->comentarios_cliente, 100);
endif;
- if (isset($item->comentarios_safekat) && strlen($item->comentarios_safekat) > 100) :
+ if (isset($item->comentarios_safekat) && strlen($item->comentarios_safekat) > 100):
$item->comentarios_safekat = character_limiter($item->comentarios_safekat, 100);
endif;
- if (isset($item->comentarios_tarifa) && strlen($item->comentarios_tarifa) > 100) :
+ if (isset($item->comentarios_tarifa) && strlen($item->comentarios_tarifa) > 100):
$item->comentarios_tarifa = character_limiter($item->comentarios_tarifa, 100);
endif;
- if (isset($item->comentarios_produccion) && strlen($item->comentarios_produccion) > 100) :
+ if (isset($item->comentarios_produccion) && strlen($item->comentarios_produccion) > 100):
$item->comentarios_produccion = character_limiter($item->comentarios_produccion, 100);
endif;
- if (isset($item->tirada_alternativa_json_data) && strlen($item->tirada_alternativa_json_data) > 100) :
+ if (isset($item->tirada_alternativa_json_data) && strlen($item->tirada_alternativa_json_data) > 100):
$item->tirada_alternativa_json_data = character_limiter($item->tirada_alternativa_json_data, 100);
endif;
- if (isset($item->titulo) && strlen($item->titulo) > 100) :
+ if (isset($item->titulo) && strlen($item->titulo) > 100):
$item->titulo = character_limiter($item->titulo, 100);
endif;
- if (isset($item->paginas_color_posicion) && strlen($item->paginas_color_posicion) > 100) :
+ if (isset($item->paginas_color_posicion) && strlen($item->paginas_color_posicion) > 100):
$item->paginas_color_posicion = character_limiter($item->paginas_color_posicion, 100);
endif;
- if (isset($item->aprobado_json_data) && strlen($item->aprobado_json_data) > 100) :
+ if (isset($item->aprobado_json_data) && strlen($item->aprobado_json_data) > 100):
$item->aprobado_json_data = character_limiter($item->aprobado_json_data, 100);
endif;
- if (isset($item->comparador_json_data) && strlen($item->comparador_json_data) > 100) :
+ if (isset($item->comparador_json_data) && strlen($item->comparador_json_data) > 100):
$item->comparador_json_data = character_limiter($item->comparador_json_data, 100);
endif;
- if (isset($item->ws_externo_json_data) && strlen($item->ws_externo_json_data) > 100) :
+ if (isset($item->ws_externo_json_data) && strlen($item->ws_externo_json_data) > 100):
$item->ws_externo_json_data = character_limiter($item->ws_externo_json_data, 100);
endif;
endforeach;
- } else {
-
- $isColor = $reqData['color'] ?? false;
- $isHq = $reqData['hq'] ?? false;
-
- $datosPedido = (object)array(
- 'paginas' => intval($reqData['paginas']) ?? 0,
- 'tirada' => intval($reqData['tirada']) ?? 0,
- 'merma' => intval($reqData['merma']) ?? 0,
- 'ancho' => intval($reqData['ancho']) ?? 100000,
- 'alto' => intval($reqData['alto']) ?? 100000,
- 'a_favor_fibra' => $reqData['a_favor_fibra'] ?? 1,
- 'isCosido' => (new TipoPresupuestoModel())->get_isCosido($tipo_impresion_id), // JJO esto es custom por cada tipo de presupuesto
- );
-
- $papel_generico = [
- 'id' => $reqData['papel_generico_id'] ?? 0,
- 'nombre' => $reqData['papel_generico'] ?? "",
- ];
-
- $gramaje = $reqData['gramaje'] ?? 0;
-
- $cliente_id = $reqData['cliente_id'] ?? -1;
-
- $resourceData = [];
-
- if ($type == 'interior' || $type == 'guardas') {
-
- $datosTipolog = $reqData['negro'] ?? null;
- if (!is_null($datosTipolog)) {
- $datosTipolog = [];
- $data = (object)array(
- 'negro' => floatval($reqData['negro']) ?? 0,
- 'cyan' => floatval($reqData['cyan']) ?? 0,
- 'magenta' => floatval($reqData['magenta']) ?? 0,
- 'amarillo' => floatval($reqData['amarillo']) ?? 0,
- 'cg' => floatval($reqData['cg']) ?? 0,
- 'gota_negro' => floatval($reqData['gota_negro']) ?? 0,
- 'gota_color' => floatval($reqData['gota_color']) ?? 0,
- );
- array_push($datosTipolog, $data);
- }
-
- if ($type == 'guardas') {
-
- $datosPedido->paginas_impresion = intval($reqData['paginas_impresion']) ?? 0;
- // Para el caso de Fresado y Cosido tapa dura, las guardas son un diptico
- // y hay que imprimirlas como "cosido" (dos hojas pegadas). En el caso de espiral
- // o wire-o tapa dura, las guardas se imprimen como hojas sueltas
- if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3) {
- $datosPedido->isCosido = true;
- } else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 7) {
- $datosPedido->isCosido = false;
- }
- }
-
- $a_favor_fibra = $reqData['a_favor_fibra'] ?? false;
-
- $input_data = array(
- 'uso' => $type,
- 'tipo_impresion_id' => $tipo_impresion_id,
- 'datosPedido' => $datosPedido,
- 'papel_generico' => $papel_generico,
- 'gramaje' => $gramaje,
- 'isColor' => $isColor,
- 'isHq' => $isHq,
- 'cliente_id' => $cliente_id,
- 'datosTipolog' => $datosTipolog,
- 'a_favor_fibra' => $a_favor_fibra
- );
-
- $resourceData = PresupuestoService::obtenerComparadorPlana($input_data);
-
- } else if ($type == 'interior_rot') {
-
- $paginas = (object)array(
- 'negro' => intval($reqData['paginas_negro'] ?? 0),
- 'color' => intval($reqData['paginas_color'] ?? 0),
- );
-
- $datosTipolog = $reqData['negro'] ?? null;
- if (!is_null($datosTipolog)) {
- $datosTipolog = [];
- $data = (object)array(
- 'negro' => floatval($reqData['negro']) ?? 0,
- 'cyan' => floatval($reqData['cyan']) ?? 0,
- 'magenta' => floatval($reqData['magenta']) ?? 0,
- 'amarillo' => floatval($reqData['amarillo']) ?? 0,
- 'gota_negro' => floatval($reqData['gota_negro']) ?? 0,
- 'gota_color' => floatval($reqData['gota_color']) ?? 0,
- );
- array_push($datosTipolog, $data);
- }
-
- $input_data = [
- 'datosPedido' => $datosPedido,
- 'papel_generico' => $papel_generico,
- 'gramaje' => $gramaje,
- 'paginas' => $paginas,
- 'cliente_id' => $cliente_id,
- 'datosTipolog' => $datosTipolog
- ];
-
- $resourceData = PresupuestoService::obtenerComparadorRotativa($input_data);
-
- } else if ($type == 'cubierta' || $type == 'sobrecubierta') {
-
- $datosPedido->solapas = $reqData['solapas'];
- $datosPedido->solapas_ancho = $reqData['solapas_ancho'];
- $datosPedido->lomo = $reqData['lomo'];
-
- $input_data = array(
- 'uso' => $type,
- 'tipo_impresion_id' => $tipo_impresion_id,
- 'datosPedido' => $datosPedido,
- 'papel_generico' => $papel_generico,
- 'gramaje' => $gramaje,
- 'isColor' => 1, // Cubierta y sobrecubierta siempre color HQ
- 'isHq' => 1,
- 'cliente_id' => $cliente_id,
- );
-
- $resourceData = PresupuestoService::obtenerComparadorPlana($input_data);
- }
-
- $newTokenHash = csrf_hash();
- $csrfTokenName = csrf_token();
- $data = [
- 'lineas' => $resourceData,
- $csrfTokenName => $newTokenHash
- ];
-
- return $this->respond($data);
}
return $this->respond(Collection::datatable(
@@ -691,6 +827,159 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
}
+ public function getLineaPresupuesto()
+ {
+ if ($this->request->isAJAX()) {
+
+ $reqData = $this->request->getPost();
+
+ $type = $reqData['type'] ?? null;
+ // por defecto, se deja cosido tapa blanda por ahora JJO
+ $tipo_impresion_id = $reqData['tipo_impresion_id'] ?? 4;
+
+ $isColor = $reqData['color'] ?? false;
+ $isHq = $reqData['hq'] ?? false;
+
+ $datosPedido = (object) array(
+ 'paginas' => intval($reqData['paginas']) ?? 0,
+ 'tirada' => intval($reqData['tirada']) ?? 0,
+ 'merma' => intval($reqData['merma']) ?? 0,
+ 'ancho' => intval($reqData['ancho']) ?? 100000,
+ 'alto' => intval($reqData['alto']) ?? 100000,
+ 'a_favor_fibra' => $reqData['a_favor_fibra'] ?? 1,
+ 'isCosido' => (new TipoPresupuestoModel())->get_isCosido($tipo_impresion_id), // JJO esto es custom por cada tipo de presupuesto
+ );
+
+ $papel_generico = [
+ 'id' => $reqData['papel_generico_id'] ?? 0,
+ 'nombre' => $reqData['papel_generico'] ?? "",
+ ];
+
+ if ($papel_generico['id'] != 0 && $papel_generico['nombre'] == "") {
+ $modelPapelGenerico = new PapelGenericoModel();
+ $papel_generico['nombre'] = $modelPapelGenerico->getNombre($papel_generico['id'])['nombre'];
+ }
+
+ $gramaje = $reqData['gramaje'] ?? 0;
+
+ $cliente_id = $reqData['cliente_id'] ?? -1;
+
+ $resourceData = [];
+
+ if ($type == 'interior' || $type == 'guardas') {
+
+ $datosTipolog = $reqData['negro'] ?? null;
+ if (!is_null($datosTipolog)) {
+ $datosTipolog = [];
+ $data = (object) array(
+ 'negro' => floatval($reqData['negro']) ?? 0,
+ 'cyan' => floatval($reqData['cyan']) ?? 0,
+ 'magenta' => floatval($reqData['magenta']) ?? 0,
+ 'amarillo' => floatval($reqData['amarillo']) ?? 0,
+ 'cg' => floatval($reqData['cg']) ?? 0,
+ 'gota_negro' => floatval($reqData['gota_negro']) ?? 0,
+ 'gota_color' => floatval($reqData['gota_color']) ?? 0,
+ );
+ array_push($datosTipolog, $data);
+ }
+
+ if ($type == 'guardas') {
+
+ $datosPedido->paginas_impresion = intval($reqData['paginas_impresion']) ?? 0;
+ // Para el caso de Fresado y Cosido tapa dura, las guardas son un diptico
+ // y hay que imprimirlas como "cosido" (dos hojas pegadas). En el caso de espiral
+ // o wire-o tapa dura, las guardas se imprimen como hojas sueltas
+ if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3) {
+ $datosPedido->isCosido = true;
+ } else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 7) {
+ $datosPedido->isCosido = false;
+ }
+ }
+
+ $a_favor_fibra = $reqData['a_favor_fibra'] ?? false;
+
+ $input_data = array(
+ 'uso' => $type,
+ 'tipo_impresion_id' => $tipo_impresion_id,
+ 'datosPedido' => $datosPedido,
+ 'papel_generico' => $papel_generico,
+ 'gramaje' => $gramaje,
+ 'isColor' => $isColor,
+ 'isHq' => $isHq,
+ 'cliente_id' => $cliente_id,
+ 'datosTipolog' => $datosTipolog,
+ 'a_favor_fibra' => $a_favor_fibra
+ );
+
+ $resourceData = PresupuestoService::obtenerComparadorPlana($input_data);
+
+ } else if ($type == 'interior_rot') {
+
+ $paginas = (object) array(
+ 'negro' => intval($reqData['paginas_negro'] ?? 0),
+ 'color' => intval($reqData['paginas_color'] ?? 0),
+ );
+
+ $datosTipolog = $reqData['negro'] ?? null;
+ if (!is_null($datosTipolog)) {
+ $datosTipolog = [];
+ $data = (object) array(
+ 'negro' => floatval($reqData['negro']) ?? 0,
+ 'cyan' => floatval($reqData['cyan']) ?? 0,
+ 'magenta' => floatval($reqData['magenta']) ?? 0,
+ 'amarillo' => floatval($reqData['amarillo']) ?? 0,
+ 'gota_negro' => floatval($reqData['gota_negro']) ?? 0,
+ 'gota_color' => floatval($reqData['gota_color']) ?? 0,
+ );
+ array_push($datosTipolog, $data);
+ }
+
+ $input_data = [
+ 'datosPedido' => $datosPedido,
+ 'papel_generico' => $papel_generico,
+ 'gramaje' => $gramaje,
+ 'paginas' => $paginas,
+ 'cliente_id' => $cliente_id,
+ 'datosTipolog' => $datosTipolog
+ ];
+
+ $resourceData = PresupuestoService::obtenerComparadorRotativa($input_data);
+
+ } else if ($type == 'cubierta' || $type == 'sobrecubierta') {
+
+ $datosPedido->solapas = $reqData['solapas'];
+ $datosPedido->solapas_ancho = $reqData['solapas_ancho'];
+ $datosPedido->lomo = $reqData['lomo'];
+
+ $input_data = array(
+ 'uso' => $type,
+ 'tipo_impresion_id' => $tipo_impresion_id,
+ 'datosPedido' => $datosPedido,
+ 'papel_generico' => $papel_generico,
+ 'gramaje' => $gramaje,
+ 'isColor' => 1, // Cubierta y sobrecubierta siempre color HQ
+ 'isHq' => 1,
+ 'cliente_id' => $cliente_id,
+ );
+
+ $resourceData = PresupuestoService::obtenerComparadorPlana($input_data);
+ }
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+ $data = [
+ 'lineas' => $resourceData,
+ $csrfTokenName => $newTokenHash
+ ];
+
+ return $this->respond($data);
+
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+
public function datatable_2()
{
if ($this->request->isAJAX()) {
@@ -719,25 +1008,22 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
];
return $this->respond($data);
- }
-
- else if ($tipo == 'duplicar'){
+ } else if ($tipo == 'duplicar') {
$presupuesto_id = $reqData['presupuesto_id'] ?? -1;
$result = $this->duplicarPresupuesto($presupuesto_id);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
- if($result['success']){
+ if ($result['success']) {
$data = [
'id' => $result['id'],
$csrfTokenName => $newTokenHash
- ];
+ ];
return $this->respond($data);
- }
- else{
+ } else {
$data = [
'error' => $result['message'],
$csrfTokenName => $newTokenHash
- ];
+ ];
return $this->respond($data);
}
}
@@ -754,6 +1040,226 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
}
}
+ public function getPapelGenerico()
+ {
+
+ if ($this->request->isAJAX()) {
+
+ $POD_value = $this->getPOD();
+ $tirada = $this->request->getGet("tirada");
+ $isPOD = intval($tirada) <= intval($POD_value);
+
+ $tipo_impresion_id = $this->request->getGet("tipo_impresion");
+ $tapa_dura = model('App\Models\Configuracion\TipoPresupuestoModel')->get_isTapaDura(intval($tipo_impresion_id));
+
+ $tipo = $this->request->getGet("tipo");
+
+ $uso = $this->request->getGet("uso") ?? 'interior';
+ $cubierta = false;
+ if ($uso == 'cubierta') {
+ $cubierta = true;
+ }
+ $sobrecubierta = false;
+ if ($uso == 'sobrecubierta') {
+ $sobrecubierta = true;
+ }
+ $guardas = false;
+ if ($uso == 'guardas') {
+ $guardas = true;
+ }
+ $rotativa = false;
+ if ($uso == 'rotativa') {
+ $rotativa = true;
+ }
+
+ $model = model('App\Models\Configuracion\PapelGenericoModel');
+ $query = $model->getPapelForComparador($tipo, $cubierta, $sobrecubierta, $rotativa, $guardas, $tapa_dura, $isPOD);
+ if ($this->request->getGet("q")) {
+ $query->groupStart()
+ ->orLike("lg_papel_generico.nombre", $this->request->getGet("q"))
+ ->groupEnd();
+ }
+
+ return $this->response->setJSON($query->orderBy("t1.nombre", "asc")->get()->getResultObject());
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function getGramaje()
+ {
+ if ($this->request->isAJAX()) {
+
+ $papel_generico_id = $this->request->getGet("papel_generico");
+
+ $POD_value = $this->getPOD();
+ $tirada = $this->request->getGet("tirada");
+ $isPOD = intval($tirada) <= intval($POD_value);
+
+ $tipo_impresion_id = $this->request->getGet("tipo_impresion");
+ $tapa_dura = model('App\Models\Configuracion\TipoPresupuestoModel')->get_isTapaDura(intval($tipo_impresion_id));
+
+ $tipo = $this->request->getGet("tipo");
+
+ $uso = $this->request->getGet("uso") ?? 'interior';
+ $cubierta = false;
+ if ($uso == 'cubierta') {
+ $cubierta = true;
+ }
+ $sobrecubierta = false;
+ if ($uso == 'sobrecubierta') {
+ $sobrecubierta = true;
+ }
+ $guardas = false;
+ if ($uso == 'guardas') {
+ $guardas = true;
+ }
+ $rotativa = false;
+ if ($uso == 'rotativa') {
+ $rotativa = true;
+ }
+
+ $model = model('App\Models\Configuracion\PapelGenericoModel');
+ $query = $model->getGramajeForComparador($tipo, $papel_generico_id, $cubierta, $sobrecubierta, $rotativa, $guardas, $tapa_dura, $isPOD);
+ if ($this->request->getGet("q")) {
+ $query->groupStart()
+ ->orLike("lg_papel_impresion.gramaje", $this->request->getGet("q"))
+ ->groupEnd();
+ }
+
+ return $this->response->setJSON($query->orderBy("t2.gramaje", "asc")->get()->getResultObject());
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+
+ public function getPapelImpresion()
+ {
+
+ if ($this->request->isAJAX()) {
+
+ $papel_generico_id = $this->request->getGet('papel_generico');
+ $gramaje = $this->request->getGet('gramaje');
+
+ $tipo_impresion_id = $this->request->getGet("tipo_impresion");
+ $tapa_dura = model('App\Models\Configuracion\TipoPresupuestoModel')->get_isTapaDura(intval($tipo_impresion_id));
+
+ $tipo = $this->request->getGet("tipo");
+
+ $uso = $this->request->getGet("uso") ?? 'interior';
+
+ $model = model('App\Models\Configuracion\PapelImpresionModel');
+ $query = $model->getPapelesImpresionForMenu(
+ $papel_generico_id,
+ $gramaje,
+ $tipo,
+ $uso,
+ $tapa_dura,
+ false
+ );
+ if ($this->request->getGet("q")) {
+ $query->groupStart()
+ ->orLike("lg_papel_impresion.nombre", $this->request->getGet("q"))
+ ->groupEnd();
+ }
+
+ return $this->response->setJSON($query->orderBy("t1.nombre", "asc")->get()->getResultObject());
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+
+ public function getMaquinas()
+ {
+
+ if ($this->request->isAJAX()) {
+
+ $ancho = $this->request->getGet('ancho');
+ $alto = $this->request->getGet('alto');
+ $tirada = $this->request->getGet('tirada');
+ $merma = $this->request->getGet('merma');
+ $tipo_impresion_id = $this->request->getGet('tipo_impresion');
+ $isCosido = (new TipoPresupuestoModel())->get_isCosido($tipo_impresion_id);
+ $papel_impresion_id = $this->request->getGet('papel_impresion');
+ $tarifa_tipo = $this->request->getGet("tarifa_tipo"); // negro, color, negrohq, colorhq
+ $uso_tarifa = $this->request->getGet("uso_tarifa") ?? 'interior'; // interior, cubierta, sobrecubierta
+ $is_rotativa = $this->request->getGet('is_rotativa') ?? 0;
+ $lomo_redondo = $this->request->getGet('lomo_redondo');
+ $lomo = $this->request->getGet('lomo');
+ $solapas = $this->request->getGet('solapas');
+ $solapas_ancho = $this->request->getGet('solapas_ancho');
+
+ $model = model('App\Models\Configuracion\MaquinaModel');
+ $query = $model->getMaquinaImpresionForPresupuesto(
+ $is_rotativa,
+ $tarifa_tipo,
+ $uso_tarifa,
+ intval($tirada) + intval($merma),
+ $papel_impresion_id
+ );
+ if ($this->request->getGet("q")) {
+ $query->groupStart()
+ ->orLike("lg_maquinas.nombre", $this->request->getGet("q"))
+ ->groupEnd();
+ }
+ $data = $query->orderBy("t1.nombre", "asc")->get()->getResultObject();
+
+ $query = $model->db->getLastQuery();
+ $datosPedido = ((object) array(
+ 'ancho' => $ancho,
+ 'alto' => $alto,
+ 'isCosido' => $isCosido,
+ 'lomo' => $lomo,
+ 'solapas' => $solapas,
+ 'solapas_ancho' => $solapas_ancho,
+ ));
+
+ for ($i = 0; $i < count($data); $i++) {
+
+ if ($is_rotativa) {
+
+ $has_error = true;
+ for ($f = 0; $f < 2; $f++) {
+
+ $parametrosRotativa = (object) array(
+ 'a_favor_fibra' => $f,
+ );
+ $values = [];
+ [$values['ancho'], $values['alto']] = PresupuestoService::calculoDimForma($datosPedido, $parametrosRotativa);
+
+ $factor_anchura = round($data[$i]->ancho_impresion / $values['ancho'], 2);
+
+ if (floor($factor_anchura) != 0) {
+ $has_error = false;
+ }
+ }
+ if ($has_error) {
+ unset($data[$i]);
+ }
+ } else {
+
+ if ($uso_tarifa != 'interior') {
+ $datosPedido->anchoExteriores = PresupuestoService::getAnchoTotalExteriores($uso_tarifa, $tipo_impresion_id, $datosPedido, $data[$i]->maquina_id, $lomo_redondo);
+ $datosPedido->altoExteriores = PresupuestoService::getAltoTotalExteriores($uso_tarifa, $tipo_impresion_id, $datosPedido);
+ }
+
+ $ancho_calculo = ($uso_tarifa == 'cubierta' || $uso_tarifa == 'sobrecubierta') ? $datosPedido->anchoExteriores : $datosPedido->ancho;
+ $alto_calculo = ($uso_tarifa == 'cubierta' || $uso_tarifa == 'sobrecubierta') ? $datosPedido->altoExteriores : $datosPedido->alto;
+ $formas = PresupuestoService::getNumFormasPlana($uso_tarifa, $data[$i], $ancho_calculo, $alto_calculo, $datosPedido->isCosido);
+ if ($formas['num_formas']['posicion_formas'] == 'n/a') {
+ unset($data[$i]);
+ }
+ }
+ }
+
+ return $this->response->setJSON($data);
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
private function getStringsFromTipoImpresion($tipo_impresion_id)
{
@@ -761,7 +1267,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
switch ($tipo_impresion_id) {
- // Fresado tapa dura
+ // Fresado tapa dura
case 1:
$viewData['pageTitle'] = lang('Presupuestos.moduleTitleFresadoTD');
$viewData['isCosido'] = 0;
@@ -769,7 +1275,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$breadcrumbTitle = lang("App.menu_libros_fresasdo_tapa_dura");
break;
- // Fresado tapa blanda
+ // Fresado tapa blanda
case 2:
$viewData['pageTitle'] = lang('Presupuestos.moduleTitleFresadoTB');
$viewData['isCosido'] = 0;
@@ -777,7 +1283,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$breadcrumbTitle = lang("App.menu_libros_fresasdo_tapa_blanda");
break;
- // Cosido tapa dura
+ // Cosido tapa dura
case 3:
$viewData['pageTitle'] = lang('Presupuestos.moduleTitleCosidoTD');
$viewData['isCosido'] = 1;
@@ -785,7 +1291,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$breadcrumbTitle = lang("App.menu_libros_cosido_tapa_dura");
break;
- // Cosido tapa blanda
+ // Cosido tapa blanda
case 4:
$viewData['pageTitle'] = lang('Presupuestos.moduleTitleCosidoTB');
$viewData['isCosido'] = 1;
@@ -793,7 +1299,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$breadcrumbTitle = lang("App.menu_libros_cosido_tapa_blanda");
break;
- // Espiral tapa dura
+ // Espiral tapa dura
case 5:
$viewData['pageTitle'] = lang('Presupuestos.moduleTitleEspiralTD');
$viewData['isCosido'] = 0;
@@ -801,7 +1307,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$breadcrumbTitle = lang("App.menu_libros_espiral_tapa_dura");
break;
- // Espiral tapa blanda
+ // Espiral tapa blanda
case 6:
$viewData['pageTitle'] = lang('Presupuestos.moduleTitleEspiralTB');
$viewData['isCosido'] = 0;
@@ -809,7 +1315,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$breadcrumbTitle = lang("App.menu_libros_espiral_tapa_blanda");
break;
- // Wire-o tapa dura
+ // Wire-o tapa dura
case 7:
$viewData['pageTitle'] = lang('Presupuestos.moduleTitleWireoTD');
$viewData['isCosido'] = 0;
@@ -817,7 +1323,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$breadcrumbTitle = lang("App.menu_libros_wireo_tapa_dura");
break;
- // Wire-o tapa blanda
+ // Wire-o tapa blanda
case 8:
$viewData['pageTitle'] = lang('Presupuestos.moduleTitleWireoTB');
$viewData['isCosido'] = 0;
@@ -825,7 +1331,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$breadcrumbTitle = lang("App.menu_libros_wireo_tapa_blanda");
break;
- // Grapado
+ // Grapado
case 21:
$viewData['pageTitle'] = lang('Presupuestos.moduleTitleGrapado');
$viewData['isCosido'] = 0;
@@ -845,7 +1351,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
return $viewData;
}
-
+
/**
* Duplica un presupuesto dado por su ID.
@@ -860,67 +1366,68 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
* Si ocurre una excepción, la clave 'success' será false y una clave 'message' contendrá el mensaje de la excepción.
* @throws \Exception Si ocurre un error durante la operación.
*/
- private function duplicarPresupuesto($id){
+ private function duplicarPresupuesto($id)
+ {
- try{
-
- $presupuesto = $this->model->find($id);
- $presupuesto->titulo = $presupuesto->titulo .' - ' . lang('Presupuestos.duplicado');
- $presupuesto->is_duplicado = 1;
- $presupuesto->estado_id = 1;
- $new_id = $this->model->insert($presupuesto);
-
- $presupuestoAcabadosModel = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
- foreach ($presupuestoAcabadosModel->where('presupuesto_id', $presupuesto->id)->findAll() as $acabado) {
- $acabado->presupuesto_id = $new_id;
- $presupuestoAcabadosModel->insert($acabado);
- }
-
- $presupuestoEncuadernacionesModel = model('App\Models\Presupuestos\PresupuestoEncuadernacionesModel');
- foreach ($presupuestoEncuadernacionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $encuadernacion) {
- $encuadernacion->presupuesto_id = $new_id;
- $presupuestoEncuadernacionesModel->insert($encuadernacion);
- }
-
- $presupuestoManipuladosModel = model('App\Models\Presupuestos\PresupuestoManipuladosModel');
- foreach ($presupuestoManipuladosModel->where('presupuesto_id', $presupuesto->id)->findAll() as $manipulado) {
- $manipulado->presupuesto_id = $new_id;
- $presupuestoManipuladosModel->insert($manipulado);
- }
-
- $presupuestoPreimpresionesModel = model('App\Models\Presupuestos\PresupuestoPreimpresionesModel');
- foreach ($presupuestoPreimpresionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $preimpresion) {
- $preimpresion->presupuesto_id = $new_id;
- $presupuestoPreimpresionesModel->insert($preimpresion);
- }
+ try {
- $presupuestoServiciosExtraModel = model('App\Models\Presupuestos\PresupuestoServiciosExtraModel');
- foreach ($presupuestoServiciosExtraModel->where('presupuesto_id', $presupuesto->id)->findAll() as $servicioExtra) {
- $servicioExtra->presupuesto_id = $new_id;
- $presupuestoServiciosExtraModel->insert($preimpresion);
- }
-
- $presupuestoDireccionesModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
- foreach ($presupuestoDireccionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $direccion) {
- $direccion->presupuesto_id = $new_id;
- $presupuestoDireccionesModel->insert($direccion);
- }
-
- $presupuestoLineaModel = model('App\Models\Presupuestos\PresupuestoLineaModel');
- $presupuestoLineaModel->duplicateLineasPresupuesto($presupuesto->id, $new_id);
-
- return [
- 'success' => true,
- 'id' => $new_id
- ];
-
- }catch(\Exception $e){
- return [
- 'success' => false,
- 'message' => $e->getMessage()
- ];
- }
- }
+ $presupuesto = $this->model->find($id);
+ $presupuesto->titulo = $presupuesto->titulo . ' - ' . lang('Presupuestos.duplicado');
+ $presupuesto->is_duplicado = 1;
+ $presupuesto->estado_id = 1;
+ $new_id = $this->model->insert($presupuesto);
+
+ $presupuestoAcabadosModel = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
+ foreach ($presupuestoAcabadosModel->where('presupuesto_id', $presupuesto->id)->findAll() as $acabado) {
+ $acabado->presupuesto_id = $new_id;
+ $presupuestoAcabadosModel->insert($acabado);
+ }
+
+ $presupuestoEncuadernacionesModel = model('App\Models\Presupuestos\PresupuestoEncuadernacionesModel');
+ foreach ($presupuestoEncuadernacionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $encuadernacion) {
+ $encuadernacion->presupuesto_id = $new_id;
+ $presupuestoEncuadernacionesModel->insert($encuadernacion);
+ }
+
+ $presupuestoManipuladosModel = model('App\Models\Presupuestos\PresupuestoManipuladosModel');
+ foreach ($presupuestoManipuladosModel->where('presupuesto_id', $presupuesto->id)->findAll() as $manipulado) {
+ $manipulado->presupuesto_id = $new_id;
+ $presupuestoManipuladosModel->insert($manipulado);
+ }
+
+ $presupuestoPreimpresionesModel = model('App\Models\Presupuestos\PresupuestoPreimpresionesModel');
+ foreach ($presupuestoPreimpresionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $preimpresion) {
+ $preimpresion->presupuesto_id = $new_id;
+ $presupuestoPreimpresionesModel->insert($preimpresion);
+ }
+
+ $presupuestoServiciosExtraModel = model('App\Models\Presupuestos\PresupuestoServiciosExtraModel');
+ foreach ($presupuestoServiciosExtraModel->where('presupuesto_id', $presupuesto->id)->findAll() as $servicioExtra) {
+ $servicioExtra->presupuesto_id = $new_id;
+ $presupuestoServiciosExtraModel->insert($preimpresion);
+ }
+
+ $presupuestoDireccionesModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
+ foreach ($presupuestoDireccionesModel->where('presupuesto_id', $presupuesto->id)->findAll() as $direccion) {
+ $direccion->presupuesto_id = $new_id;
+ $presupuestoDireccionesModel->insert($direccion);
+ }
+
+ $presupuestoLineaModel = model('App\Models\Presupuestos\PresupuestoLineaModel');
+ $presupuestoLineaModel->duplicateLineasPresupuesto($presupuesto->id, $new_id);
+
+ return [
+ 'success' => true,
+ 'id' => $new_id
+ ];
+
+ } catch (\Exception $e) {
+ return [
+ 'success' => false,
+ 'message' => $e->getMessage()
+ ];
+ }
+ }
public function allItemsSelect()
{
@@ -1042,232 +1549,43 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
protected function getClienteListItems($selId = null)
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Clientes.cliente'))])];
- if (!empty($selId)) :
+ if (!empty($selId)):
$clienteModel = model('App\Models\Clientes\ClienteModel');
$selOption = $clienteModel->where('id', $selId)->findColumn('nombre');
- if (!empty($selOption)) :
+ if (!empty($selOption)):
$data[$selId] = $selOption[0];
endif;
endif;
return $data;
}
- protected function getPaisListItems()
- {
- $paisModel = model('App\Models\Configuracion\PaisModel');
- $onlyActiveOnes = true;
- $data = $paisModel->getAllForMenu('id, nombre', 'nombre', $onlyActiveOnes);
-
- return $data;
- }
-
- protected function getCcaaListItems($selId = null)
- {
- $ccaaModel = model('App\Models\Configuracion\ComunidadAutonomaModel');
- $onlyActiveOnes = true;
- $data = $ccaaModel->getAllForMenu('id, nombre', 'nombre', $onlyActiveOnes);
-
- return $data;
- }
-
-
- protected function getAcabadosCubierta()
- {
- $model = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel');
- $data = $model->getServiciosAcabadoCubierta();
- array_unshift($data, (object)['id' => '', 'label' => lang('Basic.global.None')]);
- return $data;
- }
-
- protected function getAcabadosSobrecubierta()
- {
- $model = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel');
- $data = $model->getServiciosAcabadoSobrecubierta();
- array_unshift($data, (object)['id' => '', 'label' => lang('Basic.global.None')]);
- return $data;
- }
-
-
- protected function getPapelGenericoRotativaNegro()
- {
- $model = model('App\Models\Configuracion\PapelGenericoModel');
- $data = $model->getPapelForComparador('negro', false, false, true);
- array_unshift($data, (object)array(
- "id" => 0,
- "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))])
- ));
- return $data;
- }
-
- protected function getPapelGenericoRotativaColor()
- {
- $model = model('App\Models\Configuracion\PapelGenericoModel');
- $data = $model->getPapelForComparador('color', false, false, true);
- array_unshift($data, (object)array(
- "id" => 0,
- "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))])
- ));
- return $data;
- }
-
- protected function getPapelGenericoNegro()
- {
- $model = model('App\Models\Configuracion\PapelGenericoModel');
- $data = $model->getPapelForComparador('negro', false, false);
- array_unshift($data, (object)array(
- "id" => 0,
- "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))])
- ));
- return $data;
- }
-
- protected function getPapelGenericoNegroHQ()
- {
- $model = model('App\Models\Configuracion\PapelGenericoModel');
- $data = $model->getPapelForComparador('negrohq', false, false);
- array_unshift($data, (object)array(
- "id" => 0,
- "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))])
- ));
- return $data;
- }
-
- protected function getPapelGenericoColor()
- {
- $model = model('App\Models\Configuracion\PapelGenericoModel');
- $data = $model->getPapelForComparador('color', false, false);
- array_unshift($data, (object)array(
- "id" => 0,
- "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))])
- ));
- return $data;
- }
-
- protected function getPapelGenericoColorHQ()
- {
- $model = model('App\Models\Configuracion\PapelGenericoModel');
- $data = $model->getPapelForComparador('colorhq', false, false);
- array_unshift($data, (object)array(
- "id" => 0,
- "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))])
- ));
- return $data;
- }
-
- protected function getPapelGenericoCubierta()
- {
- $model = model('App\Models\Configuracion\PapelGenericoModel');
- $data = $model->getPapelForComparador('colorhq', true, false);
- array_unshift($data, (object)array(
- "id" => 0,
- "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))])
- ));
- return $data;
- }
-
- protected function getPapelGenericoGuardas()
- {
- $model = model('App\Models\Configuracion\PapelGenericoModel');
- $data = $model->getPapelForComparador('colorhq', false, false, false, true);
- array_unshift($data, (object)array(
- "id" => 0,
- "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))])
- ));
- return $data;
- }
-
- protected function getPapelGenericoSobreCubierta()
- {
- $model = model('App\Models\Configuracion\PapelGenericoModel');
- $data = $model->getPapelForComparador('colorhq', false, true);
- array_unshift($data, (object)array(
- "id" => 0,
- "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papel'))])
- ));
- return $data;
- }
-
- protected function getServiciosPreimpresion()
- {
- $model = model('App\Models\Tarifas\TarifapreimpresionModel');
- $data = $model->getServiciosPreimpresionSelector();
- array_unshift($data, (object)array(
- "value" => 0,
- "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioPreimpresion'))])
- ));
- return $data;
- }
-
- protected function getServiciosExtra()
- {
- $model = model('App\Models\Tarifas\TarifaextraModel');
- $data = $model->getServiciosExtraSelector();
- array_unshift($data, (object)array(
- "value" => 0,
- "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioExtra'))])
- ));
- return $data;
- }
-
- protected function getServiciosEncuadernacion()
- {
- $model = model('App\Models\Tarifas\TarifaEncuadernacionModel');
- $data = $model->getServiciosEncuadernacionSelector();
- return $data;
- }
-
- protected function getPapelFormatoListItems($selId = null)
- {
- $papelFormatoModel = model('App\Models\Configuracion\PapelFormatoModel');
- $data = $papelFormatoModel->getElementsForMenu();
- array_shift($data);
- array_unshift($data, (object)['id' => '', 'tamanio' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.papelFormatoId'))])]);
- return $data;
- }
-
- protected function getServiciosAcabado()
- {
- $model = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel');
- $data = $model->getServiciosAcabadoSelector();
- return $data;
- }
-
- protected function getServiciosManipulado()
- {
- $model = model('App\Models\Tarifas\TarifaManipuladoModel');
- $data = $model->getServiciosManipuladoSelector();
- array_unshift($data, (object)array(
- "value" => 0,
- "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioManipulado'))])
- ));
- return $data;
- }
-
protected function getPOD()
{
return model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value;
}
- protected function getLineasPresupuesto($presupuestoEntity){
+ protected function loadLineasPresupuesto($presupuestoEntity)
+ {
$lineas = (new PresupuestoLineaModel())->getLineasPresupuesto($presupuestoEntity->id);
-
+
$input_data = [];
$input_data['presupuesto'] = $presupuestoEntity;
-
- return PresupuestoService::checkLineasPresupuesto($input_data, $lineas);
+
+ return [false, $lineas];
}
- protected function getLineasServicios($presupuestoEntity){
-
- $serviciosPresupuesto = (object)array();
+ protected function getLineasServicios($presupuestoEntity)
+ {
+
+ $serviciosPresupuesto = (object) array();
$serviciosPresupuesto->serviciosAcabado = (new PresupuestoAcabadosModel())->getResource($presupuestoEntity->id)->get()->getResultObject();
$serviciosPresupuesto->serviciosPreimpresion = (new PresupuestoPreimpresionesModel())->getResource($presupuestoEntity->id)->get()->getResultObject();
$serviciosPresupuesto->serviciosEncuadernacion = (new PresupuestoEncuadernacionesModel())->getResource($presupuestoEntity->id)->get()->getResultObject();
$serviciosPresupuesto->serviciosManipulado = (new PresupuestoManipuladosModel())->getResource($presupuestoEntity->id)->get()->getResultObject();
$serviciosPresupuesto->serviciosExtra = (new PresupuestoServiciosExtraModel())->getResource($presupuestoEntity->id)->get()->getResultObject();
-
+
$input_data = [];
$input_data['presupuesto_id'] = $presupuestoEntity->id;
$input_data['tipo_impresion_id'] = $presupuestoEntity->tipo_impresion_id;
@@ -1275,19 +1593,17 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$input_data['POD'] = $this->getPOD();
$input_data['paginas'] = $presupuestoEntity->paginas;
$input_data['is_duplicado'] = $presupuestoEntity->is_duplicado;
-
- if($presupuestoEntity->papel_formato_personalizado){
- $input_data['ancho'] = $presupuestoEntity->papel_formato_ancho ;
- $input_data['alto'] = $presupuestoEntity->papel_formato_alto ;
- }
- else{
+
+ if ($presupuestoEntity->papel_formato_personalizado) {
+ $input_data['ancho'] = $presupuestoEntity->papel_formato_ancho;
+ $input_data['alto'] = $presupuestoEntity->papel_formato_alto;
+ } else {
$model = model("App\Models\Configuracion\PapelFormatoModel");
$papel = $model->find($presupuestoEntity->papel_formato_id);
- if($papel){
+ if ($papel) {
$input_data['ancho'] = $papel->ancho;
$input_data['alto'] = $papel->alto;
- }
- else{
+ } else {
$input_data['ancho'] = 0;
$input_data['alto'] = 0;
}
@@ -1296,11 +1612,25 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
return PresupuestoService::checkLineasServicios($input_data, $serviciosPresupuesto);
}
- protected function getLineasDirecciones($presupuestoEntity){
+ protected function getLineasDirecciones($presupuestoEntity)
+ {
$model = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
$direccionesEnvio = $model->where('presupuesto_id', $presupuestoEntity->id)->findAll();
-
+
return PresupuestoService::checkLineasEnvios($direccionesEnvio);
}
+
+ protected function obtenerDireccionesEnvio($id, $cliente_id)
+ {
+ $model = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
+ $model_direcciones = model('App\Models\Clientes\ClienteDireccionesModel');
+ $direcciones = $model
+ ->join('lg_proveedores', 'presupuesto_direcciones.proveedor_id = lg_proveedores.id')
+ ->join('lg_paises', 'presupuesto_direcciones.pais_id = lg_paises.id')
+ ->select('presupuesto_direcciones.*, lg_proveedores.nombre AS proveedor, lg_paises.nombre AS pais')
+ ->where('presupuesto_id', $id)->findAll();
+
+ return $direcciones;
+ }
}
diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php
index 3effc193..4b8ee670 100755
--- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php
+++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php
@@ -126,6 +126,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$this->viewData['POD'] = $POD;
$this->viewData['lomo_maximo'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_maximo')->value;
$this->viewData['lomo_minimo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_minimo_fresado_cosido')->value;
+ $this->viewData['eb'] = 0;
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . $this->viewData['pageTitle'] . ' ' . lang('Basic.global.addNewSuffix');
@@ -166,6 +167,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$this->viewData['POD'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value;
$this->viewData['lomo_maximo'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_maximo')->value;
$this->viewData['lomo_minimo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_minimo_fresado_cosido')->value;
+ $this->viewData['eb'] = $presupuestoEntity->envio_base;
+
// Si se ha llamado a esta funcion porque se ha duplicado el presupuesto
// se actualiza la bbdd para que sólo ejecute algunas funciones una vez
if ($presupuestoEntity->is_duplicado) {
@@ -308,7 +311,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$datosPedido = (object) array(
'paginas' => $paginas,
'tirada' => $tirada[0],
- 'merma' => $tirada[0] > $POD ? $this->calcular_merma($tirada[0], $POD) : 0,
+ 'merma' => $this->calcular_merma($tirada[0], $POD),
'ancho' => intval($tamanio['ancho']) ?? 100000,
'alto' => intval($tamanio['alto']) ?? 100000,
'isCosido' => $is_cosido,
@@ -345,6 +348,51 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$lomo += floatval($linea['mano']);
}
}
+
+ //Guardas
+ $guardas = $reqData['guardas'] ?? [];
+ if ($guardas != "false" && $guardas != null) {
+ $datos_guardas = [
+ 'papel' => $modelPapelGenerico->getIdFromCode($guardas['papel']),
+ 'gramaje' => intval($guardas['gramaje']),
+ 'caras' => intval($guardas['caras']),
+ ];
+ } else
+ $datos_guardas = false;
+ $guardas = [];
+ $peso_guardas = 0.0;
+ $coste_guardas = 0.0;
+ if ($datos_guardas != 0) {
+ if (count($datos_guardas) != 0 && $datos_guardas) {
+
+ $guardas = $datos_guardas;
+ $input_data['papel_generico'] = $datos_guardas['papel'] ?? 0;
+ $input_data['gramaje'] = $datos_guardas['gramaje'] ?? 0;
+ $input_data['datosPedido']->paginas = 8;
+ $input_data['paginas_color'] = 8;
+ $input_data['datosPedido']->paginas_impresion = $datos_guardas['caras'] ?? 0;
+ $input_data['datosPedido']->solapas_ancho = 0;
+ $input_data['datosPedido']->solapas = 0;
+ $input_data['isColor'] = 1;
+ $input_data['isHq'] = 1;
+ $input_data['uso'] = 'guardas';
+
+ // Para el caso de Fresado y Cosido tapa dura, las guardas son un diptico
+ // y hay que imprimirlas como "cosido" (dos hojas pegadas). En el caso de espiral
+ // o wire-o tapa dura, las guardas se imprimen como hojas sueltas
+ if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3) {
+ $input_data['datosPedido']->isCosido = true;
+ } else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 7) {
+ $input_data['datosPedido']->isCosido = false;
+ }
+
+ $guardas = PresupuestoClienteService::obtenerGuardas($input_data);
+
+ if ($guardas != null && count($guardas) > 0) {
+ $lomo += floatval($guardas['mano']);
+ }
+ }
+ }
$lomo = round($lomo, 2);
$errors = [
'status' => 0,
@@ -356,20 +404,22 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
if ($tipo == 'cosido' || $tipo == 'fresado') {
if ($lomo < $lomo_minimo_fresado_cosido) {
$errors['status'] = 1;
- $errors['value'] = 'No se pueden encuadernar libros cosidos o fresados con lomo inferior a '
- . $lomo_minimo_fresado_cosido . ' mm. El lomo actual es de ' . $lomo . ' mm. ' .
- "Por favor, aumente el número de páginas o el gramaje del papel para que sea encuadernable.";
+ $errors['value'] = 'No se pueden encuadernar libros cosidos o fresados con lomo inferior a '
+ . $lomo_minimo_fresado_cosido . ' mm. El lomo actual es de ' . $lomo . ' mm. ' .
+ "Por favor, aumente el número de páginas o el gramaje del papel para que sea encuadernable.";
}
if ($lomo > $lomo_maximo) {
$errors['status'] = 1;
- $errors['value'] = 'No se pueden encuadernar con un lomo superior a '
- . $lomo_maximo . ' mm. El lomo actual es de ' . $lomo . ' mm. ' .
- "Por favor, disminuya el número de páginas o el gramaje del papel para que sea encuadernable.";
+ $errors['value'] = 'No se pueden encuadernar con un lomo superior a '
+ . $lomo_maximo . ' mm. El lomo actual es de ' . $lomo . ' mm. ' .
+ "Por favor, disminuya el número de páginas o el gramaje del papel para que sea encuadernable.";
}
}
- $data = (object) array('lomo' => $lomo,
- 'errors' => $errors);
+ $data = (object) array(
+ 'lomo' => $lomo,
+ 'errors' => $errors
+ );
return $this->respond($data);
} else {
@@ -377,185 +427,209 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
}
}
- public function calcular()
+ public function calcular($data = -1)
{
- if ($this->request->isAJAX()) {
-
- try {
-
+ if ($this->request) {
+ if ($this->request->isAJAX())
$reqData = $this->request->getPost();
- $modelPapelGenerico = new PapelGenericoModel();
+ } else {
+ if ($data == -1) {
+ return "Error: sin datos";
+ }
+ $reqData = $data;
+ }
+
+ try {
+
+ $reqData = $this->request->getPost();
+ $modelPapelGenerico = new PapelGenericoModel();
- $id = $reqData['id'] ?? 0;
+ $id = $reqData['id'] ?? 0;
- $cliente_id = $reqData['clienteId'] ?? -1;
+ $cliente_id = $reqData['clienteId'] ?? -1;
- $tirada = $reqData['tirada'] ?? 0;
- $tamanio = $reqData['tamanio'];
- $paginas = $reqData['paginas'] ?? 0;
- $paginas_color = $reqData['paginasColor'] ?? 0;
- $tipo = $reqData['tipo'];
+ $tirada = $reqData['tirada'] ?? 0;
+ $selectedTirada = $reqData['selectedTirada'] ?? -1;
+ $tamanio = $reqData['tamanio'];
+ $paginas = $reqData['paginas'] ?? 0;
+ $paginas_color = $reqData['paginasColor'] ?? 0;
+ $tipo = $reqData['tipo'];
- $paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null;
- $papelInteriorDiferente = intval($reqData['papelInteriorDiferente']) ?? null;
+ $paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null;
+ $papelInteriorDiferente = intval($reqData['papelInteriorDiferente']) ?? null;
- $isColor = intval($reqData['isColor']) ?? 0;
- $isHq = intval($reqData['isHq']) ?? 0;
+ $isColor = intval($reqData['isColor']) ?? 0;
+ $isHq = intval($reqData['isHq']) ?? 0;
- $interior = $reqData['interior'] ?? [];
- $cubierta = $reqData['cubierta'] ?? [];
- $sobrecubierta = $reqData['sobrecubierta'] ?? [];
- $guardas = $reqData['guardas'] ?? [];
- $faja = $reqData['faja'] ?? [];
- $excluirRotativa = $reqData['excluirRotativa'] ?? 0;
- $excluirRotativa = intval($excluirRotativa);
+ $interior = $reqData['interior'] ?? [];
+ $cubierta = $reqData['cubierta'] ?? [];
+ $sobrecubierta = $reqData['sobrecubierta'] ?? [];
+ $guardas = $reqData['guardas'] ?? [];
+ $faja = $reqData['faja'] ?? [];
+ $excluirRotativa = $reqData['excluirRotativa'] ?? 0;
+ $excluirRotativa = intval($excluirRotativa);
- $direcciones = $reqData['direcciones'] ?? [];
+ $direcciones = $reqData['direcciones'] ?? [];
- $tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']);
- $lomoRedondo = $cubierta['lomoRedondo'] ?? 0;
+ $tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']);
+ $lomoRedondo = $cubierta['lomoRedondo'] ?? 0;
- if ($papelInteriorDiferente) {
- $papel['negro'] = $modelPapelGenerico->where('id', $interior['papelInterior']['negro'])->first()->toArray();
- $papel['color'] = $modelPapelGenerico->where('id', $interior['papelInterior']['color'])->first()->toArray();
- $gramaje['negro'] = intval($interior['gramajeInterior']['negro']);
- $gramaje['color'] = intval($interior['gramajeInterior']['color']);
- } else {
- $papel = $modelPapelGenerico->where('id', $interior['papelInterior'])->first()->toArray();
- $gramaje = intval($interior['gramajeInterior']);
+ if ($papelInteriorDiferente) {
+ $papel['negro'] = $modelPapelGenerico->where('id', $interior['papelInterior']['negro'])->first()->toArray();
+ $papel['color'] = $modelPapelGenerico->where('id', $interior['papelInterior']['color'])->first()->toArray();
+ $gramaje['negro'] = intval($interior['gramajeInterior']['negro']);
+ $gramaje['color'] = intval($interior['gramajeInterior']['color']);
+ } else {
+ $papel = $modelPapelGenerico->where('id', $interior['papelInterior'])->first()->toArray();
+ $gramaje = intval($interior['gramajeInterior']);
+ }
+ // Interior
+ $interior = [
+ 'papel_generico' => $papel,
+ 'gramaje' => $gramaje,
+ 'excluirRotativa' => $excluirRotativa,
+ 'paginas' => $paginas,
+ 'paginas_color' => $paginas_color,
+ 'papelInteriorDiferente' => $papelInteriorDiferente
+ ];
+
+
+ // Cubierta
+ $cubierta = [
+ 'papel_generico_cubierta' => $modelPapelGenerico->where('id', $cubierta['papelCubierta'])->first()->toArray(),
+ 'gramajeCubierta' => intval($cubierta['gramajeCubierta']),
+ 'carasCubierta' => intval($cubierta['carasImpresion'] ?? 0),
+ 'solapasCubierta' => intval($cubierta['solapas'] ?? 0) == 1 ? intval($cubierta['tamanioSolapas']) : 0,
+ 'acabado' => $cubierta['acabado'] ?? 0,
+ 'lomoRedondo' => $lomoRedondo,
+ ];
+
+ // Sobrecubierta
+ if ($sobrecubierta != "false" && $sobrecubierta != null) {
+ $sobrecubierta = [
+ 'papel' => $modelPapelGenerico->getIdFromCode($sobrecubierta['papel']),
+ 'gramaje' => intval($sobrecubierta['gramaje']),
+ 'solapas' => intval($sobrecubierta['solapas'] ?? 0),
+ 'acabado' => $sobrecubierta['acabado'] ?? 0,
+ ];
+ } else
+ $sobrecubierta = false;
+
+ // Guardas
+ if ($guardas != "false" && $guardas != null) {
+ $datos_guardas = [
+ 'papel' => $modelPapelGenerico->getIdFromCode($guardas['papel']),
+ 'gramaje' => intval($guardas['gramaje']),
+ 'caras' => intval($guardas['caras']),
+ ];
+ } else
+ $datos_guardas = false;
+
+ $datos_presupuesto = array(
+ 'id' => $id,
+ 'tirada' => $tirada,
+ 'tamanio' => $tamanio,
+ 'tipo_impresion_id' => $tipo_impresion_id,
+ 'clienteId' => $cliente_id,
+ 'isColor' => $isColor,
+ 'isHq' => $isHq,
+ 'paginasCuadernillo' => $paginasCuadernillo,
+
+ 'interior' => $interior,
+ 'cubierta' => $cubierta,
+ 'sobrecubierta' => $sobrecubierta,
+ 'datos_guardas' => $datos_guardas,
+
+ 'servicios' => $reqData['servicios'] ?? [],
+ );
+
+ $return_data = $this->calcular_presupuesto($datos_presupuesto, 0, false); //TRUE FOR DEBUG
+ if (array_key_exists('errors', $return_data)) {
+ if ($return_data['errors']->status == 1) {
+ $return_data = [
+ 'errors' => (object) ([
+ 'status' => 1
+ ]),
+ ];
+ return $return_data;
}
- // Interior
- $interior = [
- 'papel_generico' => $papel,
- 'gramaje' => $gramaje,
- 'excluirRotativa' => $excluirRotativa,
- 'paginas' => $paginas,
- 'paginas_color' => $paginas_color,
- 'papelInteriorDiferente' => $papelInteriorDiferente
- ];
+ }
+ if (array_key_exists('exception', $return_data)) {
+ return $this->failServerError(
+ $return_data['exception'] . ' - ' .
+ $return_data['file'] . ' - ' . $return_data['line']
+ );
+ }
- // Cubierta
- $cubierta = [
- 'papel_generico_cubierta' => $modelPapelGenerico->where('id', $cubierta['papelCubierta'])->first()->toArray(),
- 'gramajeCubierta' => intval($cubierta['gramajeCubierta']),
- 'carasCubierta' => intval($cubierta['carasImpresion'] ?? 0),
- 'solapasCubierta' => intval($cubierta['solapas'] ?? 0) == 1 ? intval($cubierta['tamanioSolapas']) : 0,
- 'acabado' => $cubierta['acabado'] ?? 0,
- 'lomoRedondo' => $lomoRedondo,
- ];
-
- // Sobrecubierta
- if ($sobrecubierta != "false" && $sobrecubierta != null) {
- $sobrecubierta = [
- 'papel' => $modelPapelGenerico->getIdFromCode($sobrecubierta['papel']),
- 'gramaje' => intval($sobrecubierta['gramaje']),
- 'solapas' => intval($sobrecubierta['solapas'] ?? 0),
- 'acabado' => $sobrecubierta['acabado'] ?? 0,
- ];
- } else
- $sobrecubierta = false;
-
- // Guardas
- if ($guardas != "false" && $guardas != null) {
- $datos_guardas = [
- 'papel' => $modelPapelGenerico->getIdFromCode($guardas['papel']),
- 'gramaje' => intval($guardas['gramaje']),
- 'caras' => intval($guardas['caras']),
- ];
- } else
- $datos_guardas = false;
-
- $datos_presupuesto = array(
- 'id' => $id,
- 'tirada' => $tirada,
- 'tamanio' => $tamanio,
- 'tipo_impresion_id' => $tipo_impresion_id,
- 'clienteId' => $cliente_id,
- 'isColor' => $isColor,
- 'isHq' => $isHq,
- 'paginasCuadernillo' => $paginasCuadernillo,
-
- 'interior' => $interior,
- 'cubierta' => $cubierta,
- 'sobrecubierta' => $sobrecubierta,
- 'datos_guardas' => $datos_guardas,
-
- 'servicios' => $reqData['servicios'] ?? [],
+ // calculo del envio base (tirada_maxima)
+ $return_data['eb'] = [];
+ for ($i = 0; $i < count($tirada); $i++) {
+ $direccion = [];
+ $coste_direccion = $this->getCosteEnvio(
+ $direccion,
+ $return_data['peso'][$i],
+ $tirada[$i],
+ false,
+ true
);
- $return_data = $this->calcular_presupuesto($datos_presupuesto, 0, false); //TRUE FOR DEBUG
- if (array_key_exists('errors', $return_data)) {
- if ($return_data['errors']->status == 1) {
- $return_data = [
- 'errors' => (object) ([
- 'status' => 1
- ]),
- ];
- return $return_data;
- }
- }
-
- if (array_key_exists('exception', $return_data)) {
- return $this->failServerError(
- $return_data['exception'] . ' - ' .
- $return_data['file'] . ' - ' . $return_data['line']
+ if (!property_exists($coste_direccion, 'coste')) {
+ $errorModel = new ErrorPresupuesto();
+ $data['direccion'] = 'Sin direccion';
+ $data['peso'] = $return_data['peso'][$i];
+ $data['palets'] = 'Sin direccion';
+ $errorModel->insertError(
+ $id,
+ auth()->user()->id,
+ 'No se ha podido calcular el coste de envío',
+ $data
);
- }
-
- if (count($direcciones) > 1) {
-
- for ($i = 0; $i < count($tirada); $i++) {
-
- $coste_envio = 0.0;
- $primer_envio = false;
- foreach ($direcciones as $direccion) {
- $coste_direccion = $this->getCosteEnvio(
- $direccion['id'],
- $return_data['peso'][$i],
- !$primer_envio ? intval($tirada[$i]) : $direccion['unidades'],
- $direccion['entregaPalets'] == 'true' ? 1 : 0
- )[0];
-
- $primer_envio = true;
-
- if (!property_exists($coste_direccion, 'coste')) {
-
- $errorModel = new ErrorPresupuesto();
- $data['direccion'] = $direccion;
- $data['peso'] = $return_data['peso'][$i];
- $data['palets'] = $direccion['entregaPalets'] == 'true' ? 1 : 0;
- $errorModel->insertError(
- $id,
- auth()->user()->id,
- 'No se ha podido calcular el coste de envío',
- $data
- );
- $return_data = [
- 'errors' => (object) ([
- 'status' => 1
- ]),
- ];
- return $return_data;
- } else {
- $coste_envio += $coste_direccion->coste;
- }
- }
- $return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio / $tirada[$i], 4);
- }
+ $return_data = [
+ 'errors' => (object) ([
+ 'status' => 1
+ ]),
+ ];
+ return $return_data;
} else {
+ $return_data['eb'][$i] = round($coste_direccion->coste, 2);
+ }
+ }
- for ($i = 0; $i < count($tirada); $i++) {
- $coste_envio = 0.0;
- $coste_direccion = $this->getCosteEnvio(null, $return_data['peso'][$i], $tirada[$i], false)[0];
+ $envio_base = true;
+ if (count($direcciones) > 0) {
+
+ for ($i = 0; $i < count($tirada); $i++) {
+ $coste_envio = 0.0;
+ foreach ($direcciones as $direccion) {
+ // El primer envio no se calcula ya que se añade el base
+ if ($envio_base) {
+ //aporte del envio al precio unidad
+ $coste_envio += ($return_data['eb'][$i] / $tirada[$i]);
+ $envio_base = false;
+ continue;
+ }
+ if ($selectedTirada > 0) {
+ $unidades = floor($direccion['unidades'] * $tirada[$i] / $selectedTirada);
+ } else {
+ $unidades = $direccion['unidades'];
+ }
+ $coste_direccion = $this->getCosteEnvio(
+ $direccion['direccion'],
+ $return_data['peso'][$i],
+ $unidades,
+ $direccion['entregaPalets'] == 'true' ? 1 : 0,
+ false,
+ );
if (!property_exists($coste_direccion, 'coste')) {
+
$errorModel = new ErrorPresupuesto();
- $data['direccion'] = 'Sin direccion';
+ $data['direccion'] = $direccion;
$data['peso'] = $return_data['peso'][$i];
- $data['palets'] = 'Sin direccion';
+ $data['palets'] = $direccion['entregaPalets'] == 'true' ? 1 : 0;
$errorModel->insertError(
$id,
auth()->user()->id,
@@ -569,20 +643,35 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
];
return $return_data;
} else {
- $coste_envio += $coste_direccion->coste;
+ //aporte del envio al precio unidad
+ $coste_envio += ($coste_direccion->coste / $tirada[$i]);
}
-
- $return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio / $tirada[$i], 4);
}
+ $return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio, 4);
+ }
+ } else {
+ for ($i = 0; $i < count($tirada); $i++) {
+ $coste_envio = 0.0;
+ $coste_envio += ($return_data['eb'][$i] / $tirada[$i]);
+ $return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio, 4);
}
-
- return $this->respond($return_data);
- } catch (Exception $e) {
- return $this->failServerError($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine());
}
- } else {
- return $this->failUnauthorized('Invalid request', 403);
+ if ($this->request) {
+ if ($this->request->isAJAX())
+ return $this->respond($return_data);
+ } else {
+ return $return_data;
+ }
+
+ } catch (Exception $e) {
+ if ($this->request) {
+ if ($this->request->isAJAX())
+ return $this->failServerError($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine());
+ } else {
+ return "Error: " . $e->getMessage();
+ }
}
+
}
@@ -659,7 +748,20 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
if ($interior == null) {
return $this->failServerError('Error al calcular el interior');
}
- $anchoTotal = $interior[0]['mano'];
+
+ $anchoTotal = 0;
+ if (count($interior) == 2) {
+
+ if (count($interior[0]) > 0)
+ $anchoTotal += $interior[0]['mano'];
+ if (count($interior[1]) > 0)
+ $anchoTotal += $interior[1]['mano'];
+ } else {
+ if (count($interior) > 0)
+ $anchoTotal += $interior['mano'];
+ }
+
+
// le añadimos 2*ancho libro
$anchoTotal += 2 * $datosPedido->ancho;
// le añadimos los dobleces de las solapas
@@ -839,17 +941,20 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$datosCabecera = $reqData['datosCabecera'] ?? [];
+
$confirmar = $reqData['confirmar'] ?? 0;
$confirmar = intval($confirmar);
$cliente_id = $reqData['clienteId'] ?? -1;
- $tirada = $reqData['tirada'] ?? 0;
+ $tirada = $reqData['tirada'] ?? [];
$selected_tirada = $reqData['selectedTirada'] ?? 0;
$tamanio = $reqData['tamanio'];
$paginas = $reqData['paginas'] ?? 0;
$paginas_color = $reqData['paginasColor'] ?? 0;
+ $envio_base = $reqData['eb'] ?? 0;
+
$posPaginasColor = $reqData['posPaginasColor'] ?? "";
$paginasColorConsecutivas = $reqData['pagColorConsecutivas'] ?? 0;
$papelInteriorDiferente = $reqData['papelInteriorDiferente'] ?? 0;
@@ -977,43 +1082,119 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
// seleccionamos el peso de la tirada seleccionada
$peso_libro = $resultado_presupuesto['peso'][array_search($selected_tirada, $tirada)];
+ // calculo del envio base (tirada_maxima)
+ $resultado_presupuesto['eb'] = [];
+ $datos_presupuesto['envio_base'] = 0;
+ for ($i = 0; $i < count($tirada); $i++) {
+ $direccion = [];
+ $coste_direccion = $this->getCosteEnvio(
+ $direccion,
+ $resultado_presupuesto['peso'][$i],
+ $tirada[$i],
+ false,
+ true
+ );
- if (count($direcciones) > 1) {
-
- for ($i = 0; $i < count($tirada); $i++) {
-
- $resultado_presupuesto['info']['totales'][$i]['coste_envio'] = 0.0;
- $resultado_presupuesto['info']['totales'][$i]['margen_envio'] = 0.0;
-
- $coste_envio = 0.0;
- foreach ($direcciones as $direccion) {
- $precio_envio = $this->getCosteEnvio(
- $direccion['id'],
- $resultado_presupuesto['peso'][$i],
- $direccion['unidades'],
- $direccion['entregaPalets'] == 'true' ? 1 : 0
- )[0];
- $coste_envio += $precio_envio->coste;
- $margen_envio = $precio_envio->margen;
- $resultado_presupuesto['info']['totales'][$i]['coste_envio'] += $coste_envio - $margen_envio;
- $resultado_presupuesto['info']['totales'][$i]['margen_envio'] += $margen_envio;
- }
- $resultado_presupuesto['precio_u'][$i] = round(floatval($resultado_presupuesto['precio_u'][$i]) + $coste_envio / $tirada[$i], 4);
+ if (intval($selected_tirada) == intval($tirada[$i])) {
+ $datos_presupuesto['envio_base'] = round($coste_direccion->coste * (1 + $coste_direccion->margen / 100.0), 2);
}
- } else {
- for ($i = 0; $i < count($tirada); $i++) {
- $coste_envio = 0.0;
- $precio_envio = $this->getCosteEnvio(null, $resultado_presupuesto['peso'][$i], $tirada[$i], false)[0];
- $coste_envio += $precio_envio->coste;
- $margen_envio = $precio_envio->margen;
- $resultado_presupuesto['precio_u'][$i] = round(floatval($resultado_presupuesto['precio_u'][$i]) + $coste_envio / $tirada[$i], 4);
-
- $resultado_presupuesto['info']['totales'][$i]['coste_envio'] = $coste_envio - $margen_envio;
- $resultado_presupuesto['info']['totales'][$i]['margen_envio'] = $margen_envio;
+ if (!property_exists($coste_direccion, 'coste')) {
+ $errorModel = new ErrorPresupuesto();
+ $data['direccion'] = 'Sin direccion';
+ $data['peso'] = $resultado_presupuesto['peso'][$i];
+ $data['palets'] = 'Sin direccion';
+ $errorModel->insertError(
+ $id,
+ auth()->user()->id,
+ 'No se ha podido calcular el coste de envío',
+ $data
+ );
+ $resultado_presupuesto = [
+ 'errors' => (object) ([
+ 'status' => 1
+ ]),
+ ];
+ return $resultado_presupuesto;
+ } else {
+ $resultado_presupuesto['eb'][$i] = round($coste_direccion->coste, 2);
+ $resultado_presupuesto['eb_margen'][$i] = round($coste_direccion->margen, 2);
}
}
+
+ for ($i = 0; $i < count($tirada); $i++) {
+
+ $resultado_presupuesto['info']['totales'][$i]['coste_envio'] = 0.0;
+ $resultado_presupuesto['info']['totales'][$i]['margen_envio'] = 0.0;
+ }
+ if (count($direcciones) > 0) {
+
+ for ($i = 0; $i < count($tirada); $i++) {
+
+ $envio_base = true;
+ $coste_envio = 0.0;
+ $margen_envio = 0.0;
+ foreach ($direcciones as $direccion) {
+ // El primer envio no se calcula ya que se añade el base
+ if ($envio_base) {
+ //aporte del envio al precio unidad
+ $coste_envio += ($resultado_presupuesto['eb'][$i] / $tirada[$i]);
+ $margen_envio += ($resultado_presupuesto['eb_margen'][$i] / $tirada[$i]);
+ $resultado_presupuesto['info']['totales'][$i]['coste_envio'] += $resultado_presupuesto['eb'][$i] - $resultado_presupuesto['eb_margen'][$i];
+ $resultado_presupuesto['info']['totales'][$i]['margen_envio'] += $resultado_presupuesto['eb_margen'][$i];
+ $envio_base = false;
+ continue;
+ }
+
+ $unidades = floor($direccion['unidades'] * $tirada[$i] / $selected_tirada);
+ $coste_direccion = $this->getCosteEnvio(
+ $direccion['direccion'],
+ $resultado_presupuesto['peso'][$i],
+ $unidades,
+ $direccion['entregaPalets'] == 'true' ? 1 : 0,
+ false,
+ );
+
+ if (!property_exists($coste_direccion, 'coste')) {
+
+ $errorModel = new ErrorPresupuesto();
+ $data['direccion'] = $direccion;
+ $data['peso'] = $resultado_presupuesto['peso'][$i];
+ $data['palets'] = $direccion['entregaPalets'] == 'true' ? 1 : 0;
+ $errorModel->insertError(
+ $id,
+ auth()->user()->id,
+ 'No se ha podido calcular el coste de envío',
+ $data
+ );
+ $resultado_presupuesto = [
+ 'errors' => (object) ([
+ 'status' => 1
+ ]),
+ ];
+ return $resultado_presupuesto;
+ } else {
+ //aporte del envio al precio unidad
+ $coste_envio += ($coste_direccion->coste / $tirada[$i]);
+ $resultado_presupuesto['info']['totales'][$i]['coste_envio'] += $coste_direccion->coste - $coste_direccion->margen;
+ $resultado_presupuesto['info']['totales'][$i]['margen_envio'] += $coste_direccion->margen;
+
+ }
+ }
+ $resultado_presupuesto['precio_u'][$i] = round(floatval($resultado_presupuesto['precio_u'][$i]) + $coste_envio, 4);
+ }
+ } else {
+ for ($i = 0; $i < count($tirada); $i++) {
+ $coste_envio = 0.0;
+ $coste_envio += ($resultado_presupuesto['eb'][$i] / $tirada[$i]);
+ $resultado_presupuesto['info']['totales'][$i]['coste_envio'] = $resultado_presupuesto['eb'][$i] - $resultado_presupuesto['eb_margen'][$i];
+ $resultado_presupuesto['info']['totales'][$i]['margen_envio'] = $resultado_presupuesto['eb_margen'][$i];
+ $resultado_presupuesto['precio_u'][$i] = round(floatval($resultado_presupuesto['precio_u'][$i]) + $coste_envio, 4);
+ }
+ }
+
+
$model_presupuesto = new PresupuestoModel();
$tiradas_alternativas = [];
$resumen_totales = [];
@@ -1057,6 +1238,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$datos_presupuesto['retractilado5'] = $retractilado5;
$datos_presupuesto['entrega_taller'] = $reqData['entrega_taller'] ?? 0;
+
+ $resultado_presupuesto['info']['merma'] = $this->calcular_merma($selected_tirada, $POD);
+
$id = $model_presupuesto->insertarPresupuestoCliente(
$id,
$selected_tirada,
@@ -1074,17 +1258,17 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$this->borrarRelacionesPresupuesto($id);
}
- foreach ($resultado_presupuesto['info']['interior'] as $linea) {
+ foreach ($resultado_presupuesto['values']['interior'] as $linea) {
if (count($linea) > 0)
$this->guardarLineaPresupuesto($id, $linea);
}
- if (count($resultado_presupuesto['info']['cubierta']) > 0)
- $this->guardarLineaPresupuesto($id, $resultado_presupuesto['info']['cubierta']);
- if (count($resultado_presupuesto['info']['sobrecubierta']) > 0)
- $this->guardarLineaPresupuesto($id, $resultado_presupuesto['info']['sobrecubierta']);
- if (count($resultado_presupuesto['info']['guardas']) > 0)
- $this->guardarLineaPresupuesto($id, $resultado_presupuesto['info']['guardas']);
+ if (count($resultado_presupuesto['values']['cubierta']) > 0)
+ $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['cubierta']);
+ if (count($resultado_presupuesto['values']['sobrecubierta']) > 0)
+ $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['sobrecubierta']);
+ if (count($resultado_presupuesto['values']['guardas']) > 0)
+ $this->guardarLineaPresupuesto($id, $resultado_presupuesto['values']['guardas']);
// Servicios
if ($sobrecubierta) {
@@ -1110,13 +1294,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
}
}
- foreach ($resultado_presupuesto['info']['serviciosDefecto']['encuadernacion'] as $servicio) {
+ foreach ($resultado_presupuesto['values']['serviciosDefecto']['encuadernacion'] as $servicio) {
$this->guardarServicio($id, $servicio, 'encuadernacion');
}
- foreach ($resultado_presupuesto['info']['serviciosDefecto']['manipulado'] as $servicio) {
+ foreach ($resultado_presupuesto['values']['serviciosDefecto']['manipulado'] as $servicio) {
$this->guardarServicio($id, $servicio, 'manipulado');
}
- foreach ($resultado_presupuesto['info']['servicios_automaticos'] as $servicio) {
+ foreach ($resultado_presupuesto['values']['servicios_automaticos'] as $servicio) {
if ($servicio->tarifa_id == 3 || $servicio->tarifa_id == 5 || $servicio->tarifa_id == 16) {
// Servicios acabado
$this->guardarServicio($id, $servicio, 'acabado');
@@ -1171,6 +1355,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
if ($presupuesto) {
$data['lc'] = $presupuesto->lomo_cubierta;
$data['lsc'] = $presupuesto->lomo_sobrecubierta;
+ $data['eb'] = $presupuesto->envio_base;
$data['state'] = intval($presupuesto->estado_id);
$data['datosGenerales']['titulo'] = $presupuesto->titulo;
$data['datosGenerales']['autor'] = $presupuesto->autor;
@@ -1180,6 +1365,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$data['datosGenerales']['paginas'] = $presupuesto->paginas;
$data['datosGenerales']['paginasCuadernillo'] = $presupuesto->paginasCuadernillo;
$data['datosGenerales']['tirada'] = $presupuesto->tirada;
+ $data['datosGenerales']['selectedTirada'] = $presupuesto->tirada;
$data['datosGenerales']['ivaReducido'] = $presupuesto->iva_reducido;
$data['datosGenerales']['excluirRotativa'] = $presupuesto->excluir_rotativa;
$data['datosGenerales']['clienteId'] = $presupuesto->cliente_id;
@@ -1205,9 +1391,17 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$data['datosGenerales']['retractilado5'] = $presupuesto->retractilado5;
$datos_papel = $this->obtenerDatosPapel($presupuesto->id);
- $data['interior'] = $datos_papel['interior'] ? $datos_papel['interior'] : [];
+ if (array_key_exists('interior', $datos_papel)) {
+ $data['interior'] = $datos_papel['interior'];
+ } else {
+ $data['interior'] = [];
+ }
- $data['cubierta'] = $datos_papel['cubierta'] ? $datos_papel['cubierta'] : [];
+ if (array_key_exists('cubierta', $datos_papel)) {
+ $data['cubierta'] = $datos_papel['cubierta'];
+ } else {
+ $data['cubierta'] = [];
+ }
$data['cubierta']['tapa'] = $this->obtenerTipoTapa($presupuesto->tipo_impresion_id ?? null);
$data['cubierta']['lomoRedondo'] = $presupuesto->lomo_redondo ? 1 : 0;
$data['cubierta']['solapas'] = $presupuesto->solapas ? 1 : 0;
@@ -1243,7 +1437,6 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
if (intval($presupuesto->recoger_en_taller) == 1) {
$data['direcciones']['entrega_taller'] = 1;
} else {
- $data['direcciones']['entrega_taller'] = 0;
$data['direcciones'] = $this->obtenerDireccionesEnvio($id, $presupuesto->cliente_id);
}
@@ -1410,26 +1603,27 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$peso_envio = $peso_libro * $unidades / 1000.0;
$data = $this->getCosteEnvio(
- $direccion['id'],
+ $direccion['direccion'],
$peso_libro,
$direccion['unidades'],
- $direccion['entregaPalets'] == 'false' ? 0 : 1
+ $direccion['entregaPalets'] == 'false' ? 0 : 1,
+ false
);
- if (count($data) > 0) {
+ if (isset($data->coste)) {
- $data[0]->presupuesto_id = $presupuestoId;
- $data[0]->tarifa_id = $data[0]->id;
- unset($data[0]->id);
- $data[0]->precio = $data[0]->coste;
- unset($data[0]->coste);
- $data[0]->entregaPieCalle = $direccion['entregaPalets'] == 'false' ? 0 : 1;
- unset($data[0]->tipo);
- $data[0]->peso = $peso_envio;
- $data[0]->cantidad = $unidades;
+ $data->presupuesto_id = $presupuestoId;
+ $data->tarifa_id = $data->id;
+ unset($data->id);
+ $data->precio = $data->coste;
+ unset($data->coste);
+ $data->entregaPieCalle = $direccion['entregaPalets'] == 'false' ? 0 : 1;
+ unset($data->tipo);
+ $data->peso = $peso_envio;
+ $data->cantidad = $unidades;
$model = new PresupuestoDireccionesModel();
- $model->insert($data[0]);
+ $model->insert($data);
}
}
@@ -1495,18 +1689,17 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
}
- protected function getCosteEnvio($direccionId = null, $peso, $unidades, $entregaPieCalle)
+ protected function getCosteEnvio($direccion, $peso, $unidades, $entregaPieCalle, $calcular_envio_base)
{
+ $return_data = $direccion;
- if ($direccionId != null) {
- $model = model('App\Models\Clientes\ClienteDireccionesModel');
- $data = $model->getDireccion($direccionId);
+ if ($calcular_envio_base) {
+
+ $pais_id = 1; // españa
+ $cp = 18000; // envio nacional
} else {
- $data = [];
- array_push($data, (object) [
- 'pais_id' => 1, // españa
- 'cp' => 18000, // envio nacional
- ]);
+ $pais_id = $direccion['pais_id'];
+ $cp = $direccion['cp'];
}
@@ -1514,41 +1707,40 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$coste = 0;
$margen = 0;
- if (count($data) > 0) {
- $peso_envio = round(floatval($peso * $unidades / 1000.0)); // peso libro * unidades y se pasa a kilogramos
- $tarifas_envio = $modelTarifaEnvio->getTarifaEnvio($data[0]->pais_id, $data[0]->cp, $peso_envio, $entregaPieCalle ? 'palets' : 'cajas');
- for ($i = 0; $i < count($tarifas_envio); $i++) {
- if ($peso_envio > $tarifas_envio[$i]->peso_max || floatval($tarifas_envio[$i]->precio_max) == 0) {
- $tarifas_envio[$i]->precio = number_format(floatval($tarifas_envio[$i]->precio_min) + ($peso_envio - floatval($tarifas_envio[$i]->peso_min)) * floatval($tarifas_envio[$i]->precio_adicional), 2);
- }
- // si no se calcula linealmente
- else {
- $m = (($tarifas_envio[$i]->precio_max - $tarifas_envio[$i]->precio_min) / ($tarifas_envio[$i]->peso_max - $tarifas_envio[$i]->peso_min));
- $b = $tarifas_envio[$i]->precio_max - $m * $tarifas_envio[$i]->peso_max;
- $tarifas_envio[$i]->precio = number_format($m * $peso_envio + $b, 2);
- }
- $margen = $tarifas_envio[$i]->margen;
- }
- if (count($tarifas_envio) > 1) {
- $tarifa_final = array_reduce($tarifas_envio, function ($previous, $current) {
- return $current->precio < $previous->precio ? $current : $previous;
- });
- $coste = $tarifa_final->precio;
- } else {
- if (count($tarifas_envio) > 0)
- $coste = $tarifas_envio[0]->precio;
+ $peso_envio = round(floatval(floatval($peso) * floatval($unidades) / 1000.0)); // peso libro * unidades y se pasa a kilogramos
+ $tarifas_envio = $modelTarifaEnvio->getTarifaEnvio($pais_id, $cp, $peso_envio, $entregaPieCalle ? 'palets' : 'cajas');
+ for ($i = 0; $i < count($tarifas_envio); $i++) {
+ if ($peso_envio > $tarifas_envio[$i]->peso_max || floatval($tarifas_envio[$i]->precio_max) == 0) {
+ $tarifas_envio[$i]->precio = number_format(floatval($tarifas_envio[$i]->precio_min) + ($peso_envio - floatval($tarifas_envio[$i]->peso_min)) * floatval($tarifas_envio[$i]->precio_adicional), 2);
}
- }
- if (count($data) > 0 && count($tarifas_envio) > 0) {
- $data[0]->coste = $coste;
- $data[0]->tipo = $entregaPieCalle ? 'palets' : 'cajas';
- $data[0]->margen = $margen;
- $data[0]->proveedor = $tarifas_envio[0]->proveedor;
- $data[0]->proveedor_id = $tarifas_envio[0]->proveedor_id;
+ // si no se calcula linealmente
+ else {
+ $m = (($tarifas_envio[$i]->precio_max - $tarifas_envio[$i]->precio_min) / ($tarifas_envio[$i]->peso_max - $tarifas_envio[$i]->peso_min));
+ $b = $tarifas_envio[$i]->precio_max - $m * $tarifas_envio[$i]->peso_max;
+ $tarifas_envio[$i]->precio = number_format($m * $peso_envio + $b, 2);
+ }
+ $margen = $tarifas_envio[$i]->margen;
}
- return $data;
+ if (count($tarifas_envio) > 1) {
+ $tarifa_final = array_reduce($tarifas_envio, function ($previous, $current) {
+ return $current->precio < $previous->precio ? $current : $previous;
+ });
+ $coste = $tarifa_final->precio;
+ } else {
+ if (count($tarifas_envio) > 0)
+ $coste = $tarifas_envio[0]->precio;
+ $margen = $tarifas_envio[0]->margen;
+ }
+
+ $return_data['coste'] = $coste;
+ $return_data['tipo'] = $entregaPieCalle ? 'palets' : 'cajas';
+ $return_data['margen'] = $margen;
+ $return_data['proveedor'] = $tarifas_envio[0]->proveedor;
+ $return_data['proveedor_id'] = $tarifas_envio[0]->proveedor_id;
+
+ return (object) $return_data;
}
protected function calcular_presupuesto($datos_entrada, $selected_tirada, $extra_info = false)
@@ -1630,7 +1822,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$datosPedido = (object) array(
'paginas' => $paginas,
'tirada' => $tirada[$t],
- 'merma' => $tirada[$t] > $POD ? $this->calcular_merma($tirada[$t], $POD) : 0,
+ 'merma' => $this->calcular_merma($tirada[$t], $POD),
'ancho' => intval($tamanio['ancho']) ?? 100000,
'alto' => intval($tamanio['alto']) ?? 100000,
'isCosido' => $is_cosido,
@@ -2261,15 +2453,15 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$return_data['info'] = $info;
- if ($extra_info) { // && $tirada[$t] == $selected_tirada) {
+ if ($extra_info && ($tirada[$t] == $selected_tirada)) {
- $return_data['info']['interior'] = $interior;
- $return_data['info']['cubierta'] = $cubierta;
- $return_data['info']['sobrecubierta'] = $linea_sobrecubierta;
- $return_data['info']['guardas'] = $guardas;
- $return_data['info']['serviciosDefecto']['encuadernacion'] = $servDefectoEnc;
- $return_data['info']['serviciosDefecto']['manipulado'] = $servDefectoMan;
- $return_data['info']['servicios_automaticos'] = $serviciosAutomaticos;
+ $return_data['values']['interior'] = $interior;
+ $return_data['values']['cubierta'] = $cubierta;
+ $return_data['values']['sobrecubierta'] = $linea_sobrecubierta;
+ $return_data['values']['guardas'] = $guardas;
+ $return_data['values']['serviciosDefecto']['encuadernacion'] = $servDefectoEnc;
+ $return_data['values']['serviciosDefecto']['manipulado'] = $servDefectoMan;
+ $return_data['values']['servicios_automaticos'] = $serviciosAutomaticos;
}
}
@@ -2384,7 +2576,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$merma = 0;
if ($tirada > $POD) {
- $merma = $tirada * 0.1 <= 30 ? $tirada * 0.1 : 30;
+ $merma = $tirada * 0.1;
} else {
$merma_lineas = [];
foreach ($formas_lineas_interior as $formas_linea) {
@@ -2547,7 +2739,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
{
$model = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
$model_direcciones = model('App\Models\Clientes\ClienteDireccionesModel');
- $direcciones = $model->where('presupuesto_id', $id)->findAll();
+ $direcciones = $model->where('presupuesto_id', $id)->asArray()->findAll();
+
+ return $direcciones;
$result = [];
$temp = [];
diff --git a/ci4/app/Controllers/Presupuestos/Presupuestodirecciones.php b/ci4/app/Controllers/Presupuestos/Presupuestodirecciones.php
index d99d9fd3..ddbe042a 100755
--- a/ci4/app/Controllers/Presupuestos/Presupuestodirecciones.php
+++ b/ci4/app/Controllers/Presupuestos/Presupuestodirecciones.php
@@ -44,7 +44,7 @@ class Presupuestodirecciones extends \App\Controllers\BaseResourceController
$att = $reqData['att'] ?? "";
$email = $reqData['email'] ?? "";
$direccion = $reqData['direccion'] ?? "";
- $pais_id = $reqData['paisId'] ?? -1;
+ $pais_id = $reqData['pais_id'] ?? -1;
$provincia = $reqData['provincia'] ?? "";
$municipio = $reqData['municipio'] ?? "";
$cp = $reqData['cp'] ?? "";
@@ -145,6 +145,7 @@ class Presupuestodirecciones extends \App\Controllers\BaseResourceController
$reqData = $this->request->getJSON();
if($reqData->tipo=='get_tarifa'){
+
$peso = $reqData->peso ?? 0;
$paisId = $reqData->paisId ?? 0;
$cp = $reqData->cp ?? 0;
diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php b/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php
index 69198d50..c66085b1 100755
--- a/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php
+++ b/ci4/app/Controllers/Presupuestos/Presupuestoencuadernaciones.php
@@ -1,4 +1,5 @@
-request->getJSON();
$tarifas = array_column($postData->datos, 'tarifa_id');
- if(count($tarifas)>0){
+ if (count($tarifas) > 0) {
$this->model->deleteServiciosNotInArray($requestedId, $tarifas);
- }
- else{
+ } else {
$this->model->deleteAllServicios($requestedId);
}
- if(count($tarifas)>0){
+ if (count($tarifas) > 0) {
$this->model->updateTarifas($requestedId, $postData->datos);
}
@@ -57,7 +57,7 @@ class Presupuestoencuadernaciones extends \App\Controllers\BaseResourceControlle
$data = [
$csrfTokenName => $newTokenHash
];
-
+
return $this->respond($data);
}
@@ -65,136 +65,177 @@ class Presupuestoencuadernaciones extends \App\Controllers\BaseResourceControlle
{
$tarifaModel = model('App\Models\Tarifas\TarifaEncuadernacionModel');
- if ($requestedId == null) :
+ if ($requestedId == null):
return;
endif;
- $postData = $this->request->getJSON();
- $tarifas = array_column($postData->datos, 'tarifa_id');
- $tirada = $postData->tirada ?? 0;
- $paginas = $postData->paginas ?? 0;
- $POD = $postData->POD ?? 0;
- $ancho = $postData->ancho ?? 0;
- $alto = $postData->alto ?? 0;
- $result = [];
-
- if(count($tarifas)>0){
- foreach ($tarifas as $tarifa){
- if($tarifaModel->isTarifaPorHoras($tarifa)){
- $values = $this->model->getPrecioTarifaHoras($tarifa, $paginas, $tirada, -1, $POD);
- }else{
- $values = $this->model->getPrecioTarifa($tarifa, $paginas, $tirada, $ancho, $alto, -1, $POD);
- }
- array_push($result, $values);
- }
- }
+ $postData = $this->request->getPost();
+ $datos_tarifas = $postData['datos'] ?? [];
+ $tirada = $postData['tirada'] ?? 0;
+ $paginas = $postData['paginas'] ?? 0;
+ $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value;
+ $ancho = $postData['ancho'] ?? 0;
+ $alto = $postData['alto'] ?? 0;
+ $result = $this->getServiciosEncuadernacion($datos_tarifas, $tirada, $paginas, $ancho, $alto, $POD);
+
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
- 'lines' => $result,
+ 'lineas' => $result,
$csrfTokenName => $newTokenHash
];
-
+
return $this->respond($data);
}
+ public function getServiciosEncuadernacion($datos_tarifas, $tirada, $paginas, $ancho, $alto, $POD)
+ {
+ $result = [];
+ $tarifaModel = model('App\Models\Tarifas\TarifaEncuadernacionModel');
+ $model = model('App\Models\Presupuestos\PresupuestoEncuadernacionesModel');
+
+
+ if (count($datos_tarifas) > 0) {
+ foreach ($datos_tarifas as $tarifa) {
+ if ($tarifaModel->isTarifaPorHoras($tarifa['tarifa_id'])) {
+ $values = $model->getPrecioTarifaHoras($tarifa['tarifa_id'], $paginas, $tirada, -1, $POD);
+ } else {
+ $values = $model->getPrecioTarifa($tarifa['tarifa_id'], $paginas, $tirada, $ancho, $alto, -1, $POD);
+ }
+ array_push($result, $values[0]);
+ }
+ }
+ return $result;
+ }
+
public function datatable()
{
if ($this->request->isAJAX()) {
$reqData = $this->request->getPost();
$tipo = $reqData['tipo'] ?? null;
- if(is_null($tipo) || $tipo=='tarifa'){
+ if (is_null($tipo) || $tipo == 'tarifa') {
$tarifa_encuadernacion_id = $reqData['tarifa_encuadernacion_id'] ?? 0;
$proveedor_id = $reqData['proveedor_id'] ?? 0;
- }
- else{
+ } else {
$solapas = $reqData['solapas'] ?? 0;
}
$paginas = $reqData['paginas'] ?? 0;
$tirada = $reqData['tirada'] ?? 0;
$ancho = $reqData['ancho'] ?? 0;
$alto = $reqData['alto'] ?? 0;
-
+
$POD = $reqData['POD'] ?? 0;
$paginas_cuadernillo = $reqData['paginas_por_cuadernillo'] ?? null;
-
+
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
-
+
$tarifaModel = model('App\Models\Tarifas\TarifaEncuadernacionModel');
- if(is_null($tipo)){
- if($tarifaModel->isTarifaPorHoras($tarifa_encuadernacion_id)){
+ if (is_null($tipo)) {
+ if ($tarifaModel->isTarifaPorHoras($tarifa_encuadernacion_id)) {
$values = $this->model->getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo);
- }else{
+ } else {
$values = $this->model->getPrecioTarifa($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, $proveedor_id, $POD);
}
- }
-
- else if($tipo=='tarifa'){
- if($tarifaModel->isTarifaPorHoras($tarifa_encuadernacion_id)){
+ } else if ($tipo == 'tarifa') {
+ if ($tarifaModel->isTarifaPorHoras($tarifa_encuadernacion_id)) {
$values = $this->model->getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, -1, $POD);
- }
- else{
+ } else {
$values = $this->model->getPrecioTarifa($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, -1, $POD);
}
- }
-
- else{
+ } else {
$tipo_impresion_id = $reqData['tipo_impresion_id'] ?? 4;
$values = $this->model->initPresupuesto($tipo_impresion_id, $solapas, $tirada, $paginas, $ancho, $alto, $POD);
}
-
+
$data = [
'values' => $values,
$csrfTokenName => $newTokenHash
];
-
+
return $this->respond($data);
-
+
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
-
+
+ public function getRowValues()
+ {
+ if ($this->request->isAJAX()) {
+
+ $tarifaModel = model('App\Models\Tarifas\TarifaEncuadernacionModel');
+
+ $reqData = $this->request->getPost();
+
+ $tarifa_enc_id = $reqData['tarifa_enc_id'] ?? 0;
+ $tirada = $reqData['tirada'] ?? 0;
+ $paginas = $reqData['paginas'] ?? 0;
+ $ancho = $reqData['ancho'] ?? 0;
+ $alto = $reqData['alto'] ?? 0;
+ $proveedor_id = $reqData['proveedor_id'] ?? -1;
+ $paginas_cuadernillo = $reqData['paginas_por_cuadernillo'] ?? 32;
+ $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value;
+
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+
+ if ($tarifaModel->isTarifaPorHoras($tarifa_enc_id)) {
+ $values = $this->model->getPrecioTarifaHoras($tarifa_enc_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo);
+ } else {
+ $values = $this->model->getPrecioTarifa($tarifa_enc_id, $paginas, $tirada, $ancho, $alto, $proveedor_id, $POD);
+ }
+
+ $data = [
+ 'values' => $values,
+ $csrfTokenName => $newTokenHash
+ ];
+
+ return $this->respond($data);
+
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
public function menuItems()
{
if ($this->request->isAJAX()) {
$reqData = $this->request->getPost();
- try{
+ try {
$tarifa_id = $reqData['tarifa_id'] ?? -1;
$paginas = $reqData['paginas'] ?? 0;
$tirada = $reqData['tirada'] ?? 0;
$ancho = $reqData['ancho'] ?? 0;
$alto = $reqData['alto'] ?? 0;
- //$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
+ $paginas_cuadernillo = $reqData['paginas_por_cuadernillo'] ?? 32;
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
- $menu = $this->model->getProveedoresForSelector($tarifa_id, $paginas, $tirada, $ancho, $alto);
+ $menu = $this->model->getProveedoresForSelector($tarifa_id, $paginas, $tirada, $ancho, $alto, $paginas_cuadernillo);
$data = [
'menu' => $menu,
$csrfTokenName => $newTokenHash
];
- }
- catch(Exception $e){
+ } catch (Exception $e) {
$data = [
'error' => $e,
$csrfTokenName => $newTokenHash
];
- }
- finally{
+ } finally {
return $this->respond($data);
}
-
+
} else {
return $this->failUnauthorized('Invalid request', 403);
}
diff --git a/ci4/app/Controllers/Presupuestos/Presupuestomanipulados.php b/ci4/app/Controllers/Presupuestos/Presupuestomanipulados.php
index 0423bb19..f5844851 100755
--- a/ci4/app/Controllers/Presupuestos/Presupuestomanipulados.php
+++ b/ci4/app/Controllers/Presupuestos/Presupuestomanipulados.php
@@ -63,6 +63,27 @@ class Presupuestomanipulados extends \App\Controllers\BaseResourceController
return $this->respond($data);
}
+ public function getServicioSolapas(){
+
+ if($this->request->isAJAX()){
+
+ $servicio = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('servicio_solapas')->value;
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+
+ $data = [
+ 'service' => $servicio,
+ $csrfTokenName => $newTokenHash
+ ];
+
+ return $this->respond($data);
+ }
+ else{
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
public function update($requestedId = null)
{
@@ -70,28 +91,38 @@ class Presupuestomanipulados extends \App\Controllers\BaseResourceController
return;
endif;
- $postData = $this->request->getJSON();
- $tarifas = array_column($postData->datos, 'tarifa_id');
- $tirada = $postData->tirada ?? 0;
- $POD = $postData->POD ?? 0;
- $result = [];
-
- if(count($tarifas)>0){
- foreach ($tarifas as $tarifa){
- $values = $this->model->getPrecioTarifa($tarifa, $tirada, $POD);
- array_push($result, $values);
- }
- }
+ $postData = $this->request->getPost();
+ $tarifas = $postData['datos'] ?? [];
+ $tirada = $postData['tirada'] ?? 0;
+ $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value;
+
+ $result = $this->getServiciosManipulado($tarifas, $tirada, $POD);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
- 'lines' => $result,
+ 'lineas' => $result,
$csrfTokenName => $newTokenHash
];
return $this->respond($data);
}
+
+ public function getServiciosManipulado($datos_tarifas, $tirada, $POD)
+ {
+ $result = [];
+ $model = model('App\Models\Presupuestos\PresupuestoManipuladosModel');
+
+ if (count($datos_tarifas) > 0) {
+ foreach ($datos_tarifas as $tarifa) {
+ $values = $model->getPrecioTarifa($tarifa['tarifa_id'], $tirada, $POD);
+ $values[0]->cubierta = $tarifa['cubierta'] ?? 0;
+ $values[0]->sobrecubierta = $tarifa['sobrecubierta'] ?? 0;
+ array_push($result, $values[0]);
+ }
+ }
+ return $result;
+ }
public function datatable()
@@ -101,7 +132,7 @@ class Presupuestomanipulados extends \App\Controllers\BaseResourceController
$tarifa_manipulado_id = $reqData['tarifa_manipulado_id'] ?? 0;
$tirada = $reqData['tirada'] ?? 0;
- $POD = $reqData['POD'] ?? 0;
+ $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value;
$tipo = $reqData['tipo'] ?? null;
@@ -129,4 +160,29 @@ class Presupuestomanipulados extends \App\Controllers\BaseResourceController
}
}
+ public function getRowValues()
+ {
+ if ($this->request->isAJAX()) {
+ $reqData = $this->request->getPost();
+
+ $tarifa_manipulado_id = $reqData['tarifa_manipulado_id'] ?? 0;
+ $tirada = $reqData['tirada'] ?? 0;
+ $POD = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('POD')->value;
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+
+ $values = $this->model->getPrecioTarifa($tarifa_manipulado_id, $tirada, $POD);
+
+ $data = [
+ 'values' => $values,
+ $csrfTokenName => $newTokenHash
+ ];
+
+ return $this->respond($data);
+
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
}
diff --git a/ci4/app/Controllers/Presupuestos/Presupuestopreimpresiones.php b/ci4/app/Controllers/Presupuestos/Presupuestopreimpresiones.php
index 465ad7be..06e99718 100755
--- a/ci4/app/Controllers/Presupuestos/Presupuestopreimpresiones.php
+++ b/ci4/app/Controllers/Presupuestos/Presupuestopreimpresiones.php
@@ -110,4 +110,47 @@ class Presupuestopreimpresiones extends \App\Controllers\BaseResourceController
}
}
+ public function getRowValues()
+ {
+ if ($this->request->isAJAX()) {
+ $reqData = $this->request->getPost();
+
+ $tarifa_preimpresion_id = $reqData['tarifa_preimpresion_id'] ?? 0;
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+
+ $values = $this->model->getPrecioTarifa($tarifa_preimpresion_id);
+
+ $data = [
+ 'values' => $values,
+ $csrfTokenName => $newTokenHash
+ ];
+
+ return $this->respond($data);
+
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function cargar()
+ {
+ if($this->request->isAJAX()) {
+ $presupuesto_id = $this->request->getGet('presupuesto_id') ?? null;
+
+ $rows = $this->model->getResource($presupuesto_id)->get()->getResultObject();
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+ $data = [
+ 'rows' => $rows,
+ $csrfTokenName => $newTokenHash
+ ];
+
+ return $this->respond($data);
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
}
diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoserviciosextra.php b/ci4/app/Controllers/Presupuestos/Presupuestoserviciosextra.php
index 09497d14..0e5bc23b 100755
--- a/ci4/app/Controllers/Presupuestos/Presupuestoserviciosextra.php
+++ b/ci4/app/Controllers/Presupuestos/Presupuestoserviciosextra.php
@@ -110,4 +110,28 @@ class Presupuestoserviciosextra extends \App\Controllers\BaseResourceController
}
}
+ public function getRowValues()
+ {
+ if ($this->request->isAJAX()) {
+ $reqData = $this->request->getPost();
+
+ $tarifa_extra_id = $reqData['tarifa_extra_id'] ?? 0;
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+
+ $values = $this->model->getPrecioTarifa($tarifa_extra_id);
+
+ $data = [
+ 'values' => $values,
+ $csrfTokenName => $newTokenHash
+ ];
+
+ return $this->respond($data);
+
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
}
diff --git a/ci4/app/Controllers/Presupuestos/Presupuestotiradasalternativas.php b/ci4/app/Controllers/Presupuestos/Presupuestotiradasalternativas.php
index 05702a7e..60b5e12f 100644
--- a/ci4/app/Controllers/Presupuestos/Presupuestotiradasalternativas.php
+++ b/ci4/app/Controllers/Presupuestos/Presupuestotiradasalternativas.php
@@ -82,7 +82,12 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
+ $id = $reqData['id'] ?? 0;
+
$json_data = $reqData['json_tiradas'] ?? null;
+ $json_data_acabados = $reqData['json_acabados'] ?? null;
+ $json_data_encuadernacion = $reqData['json_encuadernaciones'] ?? null;
+ $json_data_manipulado = $reqData['json_manipulado'] ?? null;
$cliente_id = $reqData['cliente_id'] ?? 0;
$tipo_impresion_id = $reqData['tipo_impresion_id'] ?? 4;
@@ -95,7 +100,7 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
foreach ($data as $linea) {
// Se obtienen los valores de cada linea para el calculo del precio
- $datosPedido = (object)array(
+ $datosPedido = (object) array(
'paginas' => intval($linea['paginas']) ?? 0,
'tirada' => intval($reqData['tirada']) ?? 0,
'merma' => intval($reqData['merma']) ?? 0,
@@ -144,24 +149,24 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
$uso = 'interior';
$tipo = strpos($linea['row_id'], "_bn") !== false ? 'negro' : 'color';
$paginas_negro = isset($linea['numPagColor']) ? intval($datosPedido->paginas) - intval($linea['numPagColor']) : 0;
- $paginas_color = $linea['numPagColor'] ?? 0;
- $paginas = (object)array(
+ $paginas_color = $linea['numPagColor'] ?? 0;
+ $paginas = (object) array(
'negro' => $paginas_negro,
'color' => $paginas_color,
);
- $parametrosRotativa = (object)array(
+ $parametrosRotativa = (object) array(
'a_favor_fibra' => $datosPedido->a_favor_fibra,
- 'bnPages' => $paginas->negro,
- 'colorPages' => $paginas->color,
+ 'bnPages' => $paginas->negro,
+ 'colorPages' => $paginas->color,
'rotativa_gota_negro' => 0,
'rotativa_gota_color' => 0,
);
- $parametrosRotativa->rotativa_gota_negro = floatval($linea['gotaNegro']?? 0);
- $parametrosRotativa->rotativa_gota_color = floatval($linea['gotaColor']?? 0);
- $parametrosRotativa->rotativa_negro = floatval($linea['cobNegro'] ?? 0);
- $parametrosRotativa->rotativa_cyan = floatval($linea['cobCyan'] ?? 0);
- $parametrosRotativa->rotativa_magenta = floatval($linea['cobMagenta']?? 0);
- $parametrosRotativa->rotativa_amarillo = floatval($linea['cobAmarillo']?? 0);
+ $parametrosRotativa->rotativa_gota_negro = floatval($linea['gotaNegro'] ?? 0);
+ $parametrosRotativa->rotativa_gota_color = floatval($linea['gotaColor'] ?? 0);
+ $parametrosRotativa->rotativa_negro = floatval($linea['cobNegro'] ?? 0);
+ $parametrosRotativa->rotativa_cyan = floatval($linea['cobCyan'] ?? 0);
+ $parametrosRotativa->rotativa_magenta = floatval($linea['cobMagenta'] ?? 0);
+ $parametrosRotativa->rotativa_amarillo = floatval($linea['cobAmarillo'] ?? 0);
break;
case 'lp_cubierta':
$uso = 'cubierta';
@@ -194,14 +199,14 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
$datosTipolog = $linea['gotaNegro'] ?? null;
if (!is_null($datosTipolog)) {
$datosTipolog = [];
- $data_temp = (object)array(
+ $data_temp = (object) array(
'negro' => floatval($linea['cobNegro'] ?? 0),
'cyan' => floatval($linea['cobCyan'] ?? 0),
- 'magenta' => floatval($linea['cobMagenta']?? 0),
- 'amarillo' => floatval($linea['cobAmarillo']?? 0),
+ 'magenta' => floatval($linea['cobMagenta'] ?? 0),
+ 'amarillo' => floatval($linea['cobAmarillo'] ?? 0),
'cg' => floatval($linea['cobCG'] ?? 0),
- 'gota_negro' => floatval($linea['gotaNegro']?? 0),
- 'gota_color' => floatval($linea['gotaColor']?? 0),
+ 'gota_negro' => floatval($linea['gotaNegro'] ?? 0),
+ 'gota_color' => floatval($linea['gotaColor'] ?? 0),
);
array_push($datosTipolog, $data_temp);
}
@@ -213,13 +218,13 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
$datosLinea['datosPedido'] = $datosPedido;
$datosLinea['cliente_id'] = $cliente_id;
$datosLinea['papel'] = $papel;
- if(isset($isColor))
- $datosLinea['isColor'] = $isColor;
- if(isset($opciones_papel))
+ if (isset($isColor))
+ $datosLinea['isColor'] = $isColor;
+ if (isset($opciones_papel))
$datosLinea['opciones_papel'] = $opciones_papel;
- if(isset($parametrosRotativa))
+ if (isset($parametrosRotativa))
$datosLinea['parametrosRotativa'] = $parametrosRotativa;
- if(isset($paginas))
+ if (isset($paginas))
$datosLinea['paginas'] = $paginas;
$datosLinea['maquina'] = $maquina;
$datosLinea['papel_generico'] = $papel_generico;
@@ -257,19 +262,113 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
$linea_coste['total_coste'] +=
$linea_coste['fields']['precio_tinta'];
if (strpos($linea['row_id'], 'lp_rot') === 0) {
- $linea_coste['total_coste'] +=
- $linea_coste['fields']['total_corte'];
- }
+ $linea_coste['total_coste'] +=
+ $linea_coste['fields']['total_corte'];
+ }
}
-
+
$linea_coste['total_margen'] = $linea_coste['fields']['margen_papel_pedido'] +
$linea_coste['fields']['margen_impresion_horas'] +
$linea_coste['fields']['margen_click_pedido'];
-
+
unset($linea_coste['fields']);
array_push($values, $linea_coste);
}
+
+ // Calculo de los servicios (presimpresion y extra no dependen de nada)
+ $servicios = (object) (['coste' => 0.0, 'margen' => 0.0]);
+
+ if ($json_data_acabados) {
+ $json_data_acabados = json_decode($json_data_acabados, true);
+ if (count($json_data_acabados) > 0) {
+
+ $acabados = new Presupuestoacabados();
+ $POD = (new \App\Models\Configuracion\ConfigVariableModel())->getVariable('POD')->value;
+ $result = $acabados->getServiciosAcabados($json_data_acabados, $reqData['tirada'], $POD);
+ if (count($result) > 0) {
+ foreach ($result as $servicio) {
+ $coste = round($servicio->total / (1 + $servicio->margen / 100), 2);
+ $margen = round($servicio->total - $coste, 2);
+ $servicios->coste += $coste;
+ $servicios->margen += $margen;
+ }
+ }
+ }
+ }
+
+ if ($json_data_encuadernacion) {
+ $json_data_encuadernacion = json_decode($json_data_encuadernacion, true);
+ if (count($json_data_encuadernacion) > 0) {
+
+ $encuadernacion = new Presupuestoencuadernaciones();
+ $POD = (new \App\Models\Configuracion\ConfigVariableModel())->getVariable('POD')->value;
+ $result = $encuadernacion->getServiciosEncuadernacion($json_data_encuadernacion, $reqData['tirada'], $reqData['paginas'], $reqData['ancho'], $reqData['alto'], $POD);
+ if (count($result) > 0) {
+ foreach ($result as $servicio) {
+ $coste = round($servicio->total / (1 + $servicio->margen / 100), 2);
+ $margen = round($servicio->total - $coste, 2);
+ $servicios->coste += $coste;
+ $servicios->margen += $margen;
+ }
+ }
+ }
+ }
+
+ if ($json_data_manipulado) {
+ $json_data_manipulado = json_decode($json_data_manipulado, true);
+ if (count($json_data_manipulado) > 0) {
+ $manipulados = new Presupuestomanipulados();
+ $POD = (new \App\Models\Configuracion\ConfigVariableModel())->getVariable('POD')->value;
+ $result = $manipulados->getServiciosManipulado($json_data_manipulado, $reqData['tirada'], $POD);
+ if (count($result) > 0) {
+ foreach ($result as $servicio) {
+ $coste = round($servicio->total / (1 + $servicio->margen / 100), 2);
+ $margen = round($servicio->total - $coste, 2);
+ $servicios->coste += $coste;
+ $servicios->margen += $margen;
+ }
+ }
+ }
+ }
+
+ $json_envios = $reqData['json_envios'] ?? null;
+ $coste_envio = 0.0;
+ $margen_envio = 0.0;
+ $tirada_base = floatval($reqData['tirada_base']);
+ $peso_libro = floatval($reqData['peso_libro']);
+ // el primer envio con la tirada base
+ $model = model('App\Models\Tarifas\TarifaEnvioModel');
+ $envios = $model->getTarifaEnvio(1, 18000, $tirada_base * $peso_libro/1000.0, "cajas");
+ $resultado = $this->calcular_envio($envios, $tirada_base * $peso_libro/1000.0);
+ $coste_envio += $resultado->coste;
+ $margen_envio += $resultado->margen;
+
+ if ($json_envios) {
+ $json_envios = json_decode($json_envios, true);
+ if (count($json_envios) > 0) {
+ //la primera linea es el envio base
+ for($i = 1; $i < count($json_envios); $i++) {
+
+ $porcentaje = ($json_envios[$i]['cantidad']) / $tirada_base * 100.0;
+ $cantidad = floor($reqData['tirada'] * $porcentaje / 100.0);
+ $peso_envio = $cantidad * $peso_libro / 1000.0;
+
+ $paisId = $json_envios[$i]['pais_id'];
+ $cp = $json_envios[$i]['cp'];
+ $tipo_envio = $json_envios[$i]['entregaPieCalle'] == 1 ? 'palets' : 'cajas';
+
+ $model = model('App\Models\Tarifas\TarifaEnvioModel');
+ $envios = $model->getTarifaEnvio($paisId, $cp, $peso_envio, $tipo_envio);
+
+ $resultado = $this->calcular_envio($envios, $peso_envio);
+ $coste_envio += $resultado->coste;
+ $margen_envio += $resultado->margen;
+ }
+ }
+ }
+
+
} else {
$values = [];
}
@@ -279,8 +378,36 @@ class Presupuestotiradasalternativas extends \App\Controllers\BaseResourceContro
$response[$csrfTokenName] = $newTokenHash;
$response['lineas'] = $values;
+ $response['servicios'] = $servicios;
+ $response['envios'] = (object) (['coste' => $coste_envio, 'margen' => $margen_envio]);
return $this->respond($response);
-
+
+ }
+
+ private function calcular_envio($envio, $peso_envio)
+ {
+ $coste_envio = 0.0;
+ $margen_envio = 0.0;
+ if (count(value: $envio) > 0) {
+ $envio = $envio[0];
+ if ($envio->id != null) {
+
+ if ($peso_envio > $envio->peso_max || floatval($envio->precio_max) == 0) {
+ $coste_envio += number_format(floatval($envio->precio_min) + ($peso_envio - floatval($envio->peso_min)) * floatval($envio->precio_adicional), 2);
+ }
+ // si no se calcula linealmente
+ else {
+ $m = (($envio->precio_max - $envio->precio_min) / ($envio->peso_max - $envio->peso_min));
+ $b = $envio->precio_max - $m * $envio->peso_max;
+ $coste_envio = number_format($m * $peso_envio + $b, 2);
+
+ }
+
+ $margen_envio += $coste_envio * $envio->margen / 100.0;
+ }
+ }
+
+ return (object) (['coste' => $coste_envio, 'margen' => $margen_envio]);
}
}
diff --git a/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php b/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php
index 7c4d4c54..e2553235 100644
--- a/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php
+++ b/ci4/app/Controllers/Tarifas/Acabados/TarifaAcabados.php
@@ -336,4 +336,25 @@ class TarifaAcabados extends BaseResourceController
}
return $this->response->setJSON($query->get()->getResultObject());
}
+
+ public function getSelect2()
+ {
+ if ($this->request->isAJAX()) {
+ $query = $this->model->builder()->select(
+ [
+ "id",
+ "nombre as name"
+ ]
+ )->where("deleted_at", null);
+ if ($this->request->getGet("q")) {
+ $query->groupStart()
+ ->orLike("lg_tarifas_acabado.nombre", $this->request->getGet("q"))
+ ->groupEnd();
+ }
+
+ return $this->response->setJSON($query->get()->getResultObject());
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
}
diff --git a/ci4/app/Controllers/Tarifas/Tarifaextra.php b/ci4/app/Controllers/Tarifas/Tarifaextra.php
index 1b5591a4..28ea2f1b 100755
--- a/ci4/app/Controllers/Tarifas/Tarifaextra.php
+++ b/ci4/app/Controllers/Tarifas/Tarifaextra.php
@@ -239,4 +239,25 @@ class Tarifaextra extends \App\Controllers\GoBaseController
}
}
+ public function getSelect2()
+ {
+ if ($this->request->isAJAX()) {
+ $query = $this->model->builder()->select(
+ [
+ "id",
+ "nombre as name"
+ ]
+ )->where("deleted_at", null)
+ ->where("mostrar_en_presupuesto", 1);
+ if ($this->request->getGet("q")) {
+ $query->groupStart()
+ ->orLike("tarifa_extra.nombre", $this->request->getGet("q"))
+ ->groupEnd();
+ }
+
+ return $this->response->setJSON($query->get()->getResultObject());
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
}
diff --git a/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php b/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php
index 5b6ada95..6d26178e 100755
--- a/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php
+++ b/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php
@@ -242,4 +242,25 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController
}
}
+ public function getSelect2()
+ {
+ if ($this->request->isAJAX()) {
+ $query = $this->model->builder()->select(
+ [
+ "id",
+ "nombre as name"
+ ]
+ )->where("deleted_at", null)
+ ->where("mostrar_en_presupuesto", 1);
+ if ($this->request->getGet("q")) {
+ $query->groupStart()
+ ->orLike("lg_tarifa_preimpresion.nombre", $this->request->getGet("q"))
+ ->groupEnd();
+ }
+
+ return $this->response->setJSON($query->get()->getResultObject());
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
}
diff --git a/ci4/app/Controllers/Tarifas/Tarifasencuadernacion.php b/ci4/app/Controllers/Tarifas/Tarifasencuadernacion.php
index 4fea5fe3..11d8b273 100755
--- a/ci4/app/Controllers/Tarifas/Tarifasencuadernacion.php
+++ b/ci4/app/Controllers/Tarifas/Tarifasencuadernacion.php
@@ -356,4 +356,26 @@ class Tarifasencuadernacion extends \App\Controllers\BaseResourceController
}
return $dimensiones;
}
+
+ public function getSelect2()
+ {
+ if ($this->request->isAJAX()) {
+ $query = $this->model->builder()->select(
+ [
+ "id",
+ "nombre as name"
+ ]
+ )->where("deleted_at", null)
+ ->where("mostrar_en_presupuesto", 1);
+ if ($this->request->getGet("q")) {
+ $query->groupStart()
+ ->orLike("tarifa_encuadernacion.nombre", $this->request->getGet("q"))
+ ->groupEnd();
+ }
+
+ return $this->response->setJSON($query->get()->getResultObject());
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
}
diff --git a/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php b/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php
index ce497cd4..a55c900b 100755
--- a/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php
+++ b/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php
@@ -310,4 +310,26 @@ class Tarifasmanipulado extends \App\Controllers\BaseResourceController
}
return $this->response->setJSON($query->get()->getResultObject());
}
+
+ public function getSelect2()
+ {
+ if ($this->request->isAJAX()) {
+ $query = $this->model->builder()->select(
+ [
+ "id",
+ "nombre as name"
+ ]
+ )->where("deleted_at", null)
+ ->where("mostrar_en_presupuesto", 1);
+ if ($this->request->getGet("q")) {
+ $query->groupStart()
+ ->orLike("lg_tarifa_manipulado.nombre", $this->request->getGet("q"))
+ ->groupEnd();
+ }
+
+ return $this->response->setJSON($query->get()->getResultObject());
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
}
diff --git a/ci4/app/Entities/Presupuestos/PresupuestoEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoEntity.php
index 660beb08..7d736a94 100755
--- a/ci4/app/Entities/Presupuestos/PresupuestoEntity.php
+++ b/ci4/app/Entities/Presupuestos/PresupuestoEntity.php
@@ -63,6 +63,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
"comentarios_pdf" => null,
"comentarios_tarifa" => null,
"comentarios_produccion" => null,
+ "comentarios_presupuesto" => null,
"lomo_cubierta" => null,
"lomo_sobrecubierta" => null,
"total_presupuesto" => null,
@@ -107,6 +108,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
'paginasCuadernillo' => null,
'lomo_redondo' => null,
'cabezada' => null,
+ 'envio_base' => null,
];
protected $casts = [
"cliente_id" => "int",
@@ -116,7 +118,6 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
"tipologia_id" => "?int",
"pais_id" => "int",
"estado_id" => "int",
- "inc_rei" => "?int",
"retractilado" => "boolean",
"retractilado5" => "boolean",
"guardas" => "boolean",
diff --git a/ci4/app/Entities/Usuarios/UserEntity.php b/ci4/app/Entities/Usuarios/UserEntity.php
index 61f750ce..34206cad 100755
--- a/ci4/app/Entities/Usuarios/UserEntity.php
+++ b/ci4/app/Entities/Usuarios/UserEntity.php
@@ -13,6 +13,7 @@ class UserEntity extends \CodeIgniter\Entity\Entity
"status" => null,
"status_message" => null,
'active' => null,
+ "comments" => null,
"last_active" => null,
"created_at" => null,
"updated_at" => null,
diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php
index b9bcfc34..3404b63a 100755
--- a/ci4/app/Language/es/Presupuestos.php
+++ b/ci4/app/Language/es/Presupuestos.php
@@ -143,6 +143,7 @@ return [
'libro' => 'Libro',
'totalPapelPedido' => 'Papel pedido',
'lomo' => 'Lomo',
+ 'lomoRedondo' => 'Lomo redondo',
'peso' => 'Peso',
'click' => 'Click',
'totalClicks' => 'Total clicks',
@@ -195,6 +196,7 @@ return [
'totalLinea' => 'TOTAL LÍNEA',
'verCalculos' => 'Cálculos',
'metrosMinuto' => 'Metros x min.',
+ 'clicksMinuto' => 'Clicks x min.',
'resolucion' => 'Resolución (dpi)',
'areaPaginas' => 'Área páginas (in)',
'gotasNegro' => 'Nº gotas negro',
@@ -313,7 +315,7 @@ return [
'tiradasAlternativas' => 'Tiradas alternativas',
'tiradasInfoIVA' => 'Los precios mostrados no incluyen IVA',
'tiradaMargen' => 'Margen',
- 'tiradaEnvio' => 'Coste Envío',
+ 'tiradaEnvio' => 'Precio Envío',
'tiradaImpresion' => 'Coste Impresión',
'duplicado' => 'DUPLICADO',
@@ -369,6 +371,9 @@ return [
'paginas' => 'El campo páginas tiene que ser mayor que cero',
'paginasLP' => 'El número de páginas no coincide con el total',
'tiradas' => 'El campo tiradas tiene que ser mayor que cero',
+ 'seleccionePapel' => 'Seleccione un papel',
+ 'seleccioneGramaje' => 'Seleccione un gramaje',
+ 'seleccioneCliente' => 'Seleccione un cliente',
'dimension' => 'La dimensión del libro tiene que ser mayor que 60mm',
'lineaDuplicada' => 'Ya existe ese tipo de linea en el presupuesto',
'errorRotColor' => 'Papeles y gramajes deben ser iguales en color y BN',
diff --git a/ci4/app/Language/es/Tarifaacabado.php b/ci4/app/Language/es/Tarifaacabado.php
index 3c6622ff..5bdd61e9 100755
--- a/ci4/app/Language/es/Tarifaacabado.php
+++ b/ci4/app/Language/es/Tarifaacabado.php
@@ -9,6 +9,7 @@ return [
'id' => 'ID',
'moduleTitle' => 'Tarifas Acabado',
'nombre' => 'Nombre',
+ 'margen' => 'Margen',
'precioMin' => 'Precio Mínimo',
'importeFijo' => 'Importe Fijo',
'mostrar_en_presupuesto' => 'Mostrar en presupuesto',
diff --git a/ci4/app/Models/Clientes/ClienteDireccionesModel.php b/ci4/app/Models/Clientes/ClienteDireccionesModel.php
index e60eab05..7f2c96a6 100755
--- a/ci4/app/Models/Clientes/ClienteDireccionesModel.php
+++ b/ci4/app/Models/Clientes/ClienteDireccionesModel.php
@@ -99,7 +99,7 @@ class ClienteDireccionesModel extends \App\Models\BaseModel
->table($this->table . " t1")
->select(
"t1.id AS id, t1.cliente_id AS cliente_id, t2.nombre as cliente_nombre, t1.att AS att, t1.alias AS alias,
- t1.email AS email, t1.direccion AS direccion, t1.pais_id AS pais_id, t3.nombre AS pais,
+ t1.email AS email, t1.direccion AS direccion, t1.pais_id AS pais_id, t3.nombre AS pais, t3.nombre AS pais,
t1.municipio AS municipio, t1.provincia AS provincia, t1.cp AS cp, t1.telefono AS telefono"
);
diff --git a/ci4/app/Models/Configuracion/MaquinaModel.php b/ci4/app/Models/Configuracion/MaquinaModel.php
index c1f5424b..159d5e02 100755
--- a/ci4/app/Models/Configuracion/MaquinaModel.php
+++ b/ci4/app/Models/Configuracion/MaquinaModel.php
@@ -330,7 +330,7 @@ class MaquinaModel extends \App\Models\BaseModel
->table($this->table . " t1")
->distinct('t1.id')
->select(
- "t1.id AS maquina_id, t1.nombre AS maquina, t1.ancho_impresion AS ancho_impresion,
+ "t1.id AS id, t1.id AS maquina_id, t1.nombre AS maquina, t1.nombre AS nombre, t1.ancho_impresion AS ancho_impresion,
t1.alto_impresion AS alto_impresion, t1.ancho AS ancho, t1.alto AS alto,
t1.is_rotativa AS is_rotativa, t1.is_inkjet AS is_inkjet, t1.alto_click AS alto_click, t1.velocidad AS velocidad,
t1.precio_tinta_negro AS precio_tinta_negro, t1.precio_tinta_color AS precio_tinta_color, t1.precio_tinta_cg AS precio_tinta_cg,
@@ -361,7 +361,7 @@ class MaquinaModel extends \App\Models\BaseModel
$builder->where("t2.uso", $uso_tarifa);
}
- return $builder->orderBy("t1.id", "asc")->get()->getResultObject();
+ return $builder;
}
diff --git a/ci4/app/Models/Configuracion/PapelGenericoModel.php b/ci4/app/Models/Configuracion/PapelGenericoModel.php
index 4f2d8cf9..739ccf6d 100755
--- a/ci4/app/Models/Configuracion/PapelGenericoModel.php
+++ b/ci4/app/Models/Configuracion/PapelGenericoModel.php
@@ -129,141 +129,185 @@ class PapelGenericoModel extends \App\Models\BaseModel
return empty($search)
? $builder
: $builder
- ->groupStart()
- ->like("t1.id", $search)
- ->orLike("t1.nombre", $search)
- ->orLike("t1.code", $search)
- ->orLike("t1.code_ot", $search)
- ->orLike("t1.id", $search)
- ->orLike("t1.nombre", $search)
- ->orLike("t1.code", $search)
- ->orLike("t1.code_ot", $search)
- ->groupEnd();
+ ->groupStart()
+ ->like("t1.id", $search)
+ ->orLike("t1.nombre", $search)
+ ->orLike("t1.code", $search)
+ ->orLike("t1.code_ot", $search)
+ ->orLike("t1.id", $search)
+ ->orLike("t1.nombre", $search)
+ ->orLike("t1.code", $search)
+ ->orLike("t1.code_ot", $search)
+ ->groupEnd();
}
- public function getPapelForComparador($tipo, $is_cubierta = false, $is_sobrecubierta = false, $rotativa = false, $is_guardas = false, $mostrar_cliente = null)
- {
+ public function getPapelForComparador(
+ $tipo,
+ $is_cubierta = false,
+ $is_sobrecubierta = false,
+ $rotativa = false,
+ $is_guardas = false,
+ $tapa_dura = false,
+ $POD = false
+ ) {
/*
1.-> Tipo impresion
2.-> Maquina
3.-> Papeles impresion asociados a esa maquina
4.-> papeles genericos que aparecen en esos papeles impresion
*/
+
+ if ($POD == true && ($tipo == 'color' || $tipo == 'negro')) {
+ if ($tipo == 'color')
+ $tipo = 'colorhq';
+ else if ($tipo == 'negro')
+ $tipo = 'negrohq';
+ }
+
$builder = $this->db
->table($this->table . " t1")
->select(
- "t1.id as id, t1.nombre AS nombre"
+ "t1.id as id, t1.nombre AS nombre",
// for debug, t2.nombre AS nombre_papel_impresion, t4.nombre AS maquina_nombre, t5.uso AS tarifa_uso, t5.tipo AS tarifa_tipo"
)
- ->distinct('t1.id')
- ->join("lg_papel_impresion t2", "t2.papel_generico_id = t1.id", "left")
- ->join("lg_maquina_papel_impresion t3", "t3.papel_impresion_id = t2.id", "left")
- ->join("lg_maquinas t4", "t3.maquina_id = t4.id", "left")
- ->join("lg_maquinas_tarifas_impresion t5", "t5.maquina_id = t4.id", "left")
+ ->join("lg_papel_impresion t2", "t2.papel_generico_id = t1.id", "inner")
+ ->join("lg_maquina_papel_impresion t3", "t3.papel_impresion_id = t2.id", "inner")
+ ->join("lg_maquinas t4", "t3.maquina_id = t4.id", "inner")
+ ->join("lg_maquinas_tarifas_impresion t5", "t5.maquina_id = t4.id", "inner")
->where("t1.is_deleted", 0)
+ ->where("t1.show_in_client", 1)
->where("t2.is_deleted", 0)
->where("t2.isActivo", 1)
->where("t3.active", 1)
->where("t4.is_deleted", 0)
->where("t4.tipo", "impresion")
->where("t5.is_deleted", 0)
- ->where("t5.tipo", $tipo);
+ ->where("t5.tipo", $tipo)
+ ->distinct('t1.id');
+
+ // Validación adicional para asegurar que t1.id esté presente en las combinaciones con t3.active = 1
+ $builder->whereIn("t1.id", function ($subQuery) {
+ $subQuery->select("t1_inner.id")
+ ->from("lg_papel_generico t1_inner")
+ ->join("lg_papel_impresion t2_inner", "t2_inner.papel_generico_id = t1_inner.id", "inner")
+ ->join("lg_maquina_papel_impresion t3_inner", "t3_inner.papel_impresion_id = t2_inner.id", "inner")
+ ->where("t3_inner.active", 1);
+ });
if ($is_cubierta == true) {
-
$builder->where("t2.cubierta", 1);
$builder->where("t5.uso", 'cubierta');
- }
-
- if ($is_sobrecubierta == true) {
+ if ($tapa_dura == true) {
+ $builder->where("t2.use_for_tapa_dura", 1);
+ }
+ } else if ($is_sobrecubierta == true) {
$builder->where("t2.sobrecubierta", 1);
$builder->where("t5.uso", 'sobrecubierta');
- }
-
- if ($is_cubierta == false && $is_sobrecubierta == false) {
- $builder->where("t5.uso", 'interior');
- }
-
- if ($is_guardas == true) {
+ } else if ($is_guardas == true) {
$builder->where("t2.guardas", 1);
+ } else {
+ $builder->where("t2.interior", 1);
+ $builder->where("t5.uso", 'interior');
+ if ($tipo == 'negro' || $tipo == 'negrohq')
+ $builder->where("t2.bn", 1);
+ else if ($tipo == 'color' || $tipo == 'colorhq')
+ $builder->where("t2.color", 1);
}
- if ($rotativa == true) {
+ if ($tipo == 'colorhq' || $tipo == 'negrohq') {
+ $builder->where("t2.rotativa", 0);
+ } else if ($rotativa && $POD == false) {
$builder->where("t2.rotativa", 1);
+ } else if ($POD) {
+ $builder->where("t2.rotativa", 0);
}
- if ($mostrar_cliente != null) {
- $builder->where("t1.show_in_client", $mostrar_cliente);
- }
-
- $data = $builder->orderBy("t1.nombre", "asc")->get()->getResultObject();
- //var_dump($this->db->getLastQuery());
- return $data;
+ //$query = $this->db->getLastQuery();
+ return $builder;
}
- public function getGramajeComparador(string $papel_generico_nombre = "", $uso = "", $ejemplares = 0)
- {
- if ($uso == 'cubierta' || $uso == 'sobrecubierta')
- $tipo = 'colorhq';
- else
- $tipo = $uso; // color y colorhq valen para los dos
- if ($uso == 'bn')
- $tipo = "negro";
- if ($uso == 'bnhq')
- $tipo = "negrohq";
+ public function getGramajeForComparador(
+ $tipo,
+ $selected_papel_id,
+ $is_cubierta = false,
+ $is_sobrecubierta = false,
+ $rotativa = false,
+ $is_guardas = false,
+ $tapa_dura = false,
+ $POD = false
+ ) {
+ if ($POD == true && ($tipo == 'color' || $tipo == 'negro')) {
+ if ($tipo == 'color')
+ $tipo = 'colorhq';
+ else if ($tipo == 'negro')
+ $tipo = 'negrohq';
+ }
+
$builder = $this->db
->table($this->table . " t1")
->select(
- "t2.gramaje AS text"
+ "t2.gramaje as id, t2.gramaje as nombre",
+ // for debug, t2.nombre AS nombre_papel_impresion, t4.nombre AS maquina_nombre, t5.uso AS tarifa_uso, t5.tipo AS tarifa_tipo"
)
- ->join("lg_papel_impresion t2", "t2.papel_generico_id = t1.id", "left")
- ->join("lg_maquina_papel_impresion t3", "t3.papel_impresion_id = t2.id", "left")
- ->join("lg_maquinas t4", "t3.maquina_id = t4.id", "left")
- ->join("lg_maquinas_tarifas_impresion t5", "t5.maquina_id = t4.id", "left")
+ ->join("lg_papel_impresion t2", "t2.papel_generico_id = t1.id", "inner")
+ ->join("lg_maquina_papel_impresion t3", "t3.papel_impresion_id = t2.id", "inner")
+ ->join("lg_maquinas t4", "t3.maquina_id = t4.id", "inner")
+ ->join("lg_maquinas_tarifas_impresion t5", "t5.maquina_id = t4.id", "inner")
+ ->where("t1.id", $selected_papel_id)
->where("t1.is_deleted", 0)
+ ->where("t1.show_in_client", 1)
->where("t2.is_deleted", 0)
->where("t2.isActivo", 1)
->where("t3.active", 1)
->where("t4.is_deleted", 0)
->where("t4.tipo", "impresion")
+ ->where("t5.is_deleted", 0)
->where("t5.tipo", $tipo)
- ->where("t1.nombre", $papel_generico_nombre);
+ ->distinct('t2.gramaje');
- $uso_tarifa = 'interior';
+ // Validación adicional para asegurar que t1.id esté presente en las combinaciones con t3.active = 1
+ $builder->whereIn("t1.id", function ($subQuery) {
+ $subQuery->select("t1_inner.id")
+ ->from("lg_papel_generico t1_inner")
+ ->join("lg_papel_impresion t2_inner", "t2_inner.papel_generico_id = t1_inner.id", "inner")
+ ->join("lg_maquina_papel_impresion t3_inner", "t3_inner.papel_impresion_id = t2_inner.id", "inner")
+ ->where("t3_inner.active", 1);
+ });
- if ($uso == 'bn' || $uso == 'bnhq')
- $builder->where("t2.bn", 1);
- else if ($uso == 'color' || $uso == 'colorhq')
- $builder->where("t2.color", 1);
- else if ($uso == 'cubierta') {
- $uso_tarifa = 'cubierta';
+ if ($is_cubierta == true) {
$builder->where("t2.cubierta", 1);
- } else if ($uso == 'sobrecubierta') {
- $uso_tarifa = 'sobrecubierta';
+ $builder->where("t5.uso", 'cubierta');
+ if ($tapa_dura == true) {
+ $builder->where("t2.use_for_tapa_dura", 1);
+ }
+ } else if ($is_sobrecubierta == true) {
$builder->where("t2.sobrecubierta", 1);
+ $builder->where("t5.uso", 'sobrecubierta');
+ } else if ($is_guardas == true) {
+ $builder->where("t2.guardas", 1);
+ } else {
+ $builder->where("t2.interior", 1);
+ $builder->where("t5.uso", 'interior');
+ if ($tipo == 'negro' || $tipo == 'negrohq')
+ $builder->where("t2.bn", 1);
+ else if ($tipo == 'color' || $tipo == 'colorhq')
+ $builder->where("t2.color", 1);
}
- $builder->where("t5.uso", $uso_tarifa);
-
- $builder->where("t4.min <=", $ejemplares);
- $builder->where("t4.max >=", $ejemplares);
-
- $values = $builder->orderBy("t2.gramaje", "asc")->get()->getResultObject();
- $id = 1;
- foreach ($values as $value) {
- $value->id = $id;
- $id++;
+ if ($tipo == 'colorhq' || $tipo == 'negrohq') {
+ $builder->where("t2.rotativa", 0);
+ } else if ($rotativa && $POD == false) {
+ $builder->where("t2.rotativa", 1);
+ } else if ($POD) {
+ $builder->where("t2.rotativa", 0);
}
- $values_array = array_map(function ($value) {
- return $value->text;
- }, $values);
- $unique_values = array_unique($values_array);
- return array_values(array_intersect_key($values, $unique_values));
+ //$query = $this->db->getLastQuery();
+ return $builder;
}
//tipo: negro, negrohq, color, colorhq
@@ -323,7 +367,6 @@ class PapelGenericoModel extends \App\Models\BaseModel
}, $values);
$unique_values = array_unique($values_array);
return array_values(array_intersect_key($values, $unique_values));
-
}
@@ -337,9 +380,9 @@ class PapelGenericoModel extends \App\Models\BaseModel
*/
if ($POD == true && ($tipo == 'color' || $tipo == 'negro')) {
- if($tipo == 'color')
+ if ($tipo == 'color')
$tipo = 'colorhq';
- else if($tipo == 'negro')
+ else if ($tipo == 'negro')
$tipo = 'negrohq';
}
@@ -403,7 +446,7 @@ class PapelGenericoModel extends \App\Models\BaseModel
if ($is_cubierta == true) {
$builder->where("t2.cubierta", 1);
$builder->where("t5.uso", 'cubierta');
- if($tapa_dura == true){
+ if ($tapa_dura == true) {
$builder->where("t2.use_for_tapa_dura", 1);
}
} else {
@@ -417,19 +460,16 @@ class PapelGenericoModel extends \App\Models\BaseModel
if ($papel_especial == true) {
$builder->where("t1.show_in_client_special", 1);
- }
- else{
+ } else {
$builder->where("t1.show_in_client_special", 0);
}
if ($tipo == 'colorhq' || $tipo == 'negrohq') {
$builder->where("t2.rotativa", 0);
- }
- else{
- if($POD == false){
+ } else {
+ if ($POD == false) {
$builder->where("t2.rotativa", 1);
- }
- else if ($POD == true){
+ } else if ($POD == true) {
$builder->where("t2.rotativa", 0);
}
}
diff --git a/ci4/app/Models/Configuracion/PapelImpresionModel.php b/ci4/app/Models/Configuracion/PapelImpresionModel.php
index de9473b9..3625daa7 100755
--- a/ci4/app/Models/Configuracion/PapelImpresionModel.php
+++ b/ci4/app/Models/Configuracion/PapelImpresionModel.php
@@ -279,8 +279,15 @@ class PapelImpresionModel extends \App\Models\BaseModel
//tipo: negro, negrohq, color, colorhq
//uso: interior, rotativa, cubierta, sobrecubierta
- public function getPapelesImpresionForMenu($papel_generico = null, $gramaje = null, $tipo = null, $uso = "")
- {
+ public function getPapelesImpresionForMenu(
+ $papel_generico = null,
+ $gramaje = null,
+ $tipo = null,
+ $uso = "",
+ $tapaDura = false,
+ $forInkjet = false
+ ) {
+
$builder = $this->db
->table($this->table . " t1")
->distinct("t1.id")
@@ -289,7 +296,7 @@ class PapelImpresionModel extends \App\Models\BaseModel
->join("lg_maquinas t4", "t3.maquina_id = t4.id", "left")
->join("lg_maquinas_tarifas_impresion t5", "t4.id = t5.maquina_id", "left")
->select(
- "t1.id AS id, t1.nombre AS text"
+ "t1.id AS id, t1.nombre AS nombre"
);
$builder->where("t1.is_deleted", 0);
@@ -304,24 +311,31 @@ class PapelImpresionModel extends \App\Models\BaseModel
$builder->where("t2.id", $papel_generico);
$builder->where("t1.gramaje", $gramaje);
- if ($uso == 'cubierta')
+ if ($uso == 'cubierta') {
+ if ($tapaDura)
+ $builder->where("t1.use_for_tapa_dura", 1);
$builder->where("t1.cubierta", 1);
- else if ($uso == 'sobrecubierta')
+ } else if ($uso == 'sobrecubierta')
$builder->where("t1.sobrecubierta", 1);
else if ($uso == 'guardas')
$builder->where("t1.guardas", 1);
else {
+ $builder->where("t1.interior", 1);
if ($tipo == 'negro' || $tipo == 'negrohq')
$builder->where("t1.bn", 1);
else if ($tipo == 'color' || $tipo == 'colorhq')
$builder->where("t1.color", 1);
}
- if ($uso == 'rotativa')
+ if ($uso == 'rotativa') {
$builder->where("t1.rotativa", 1);
- else
+ $builder->where("t4.is_rotativa", 1);
+ } else
$builder->where("t1.rotativa", 0);
- return $builder->orderBy("t1.id", "asc")->get()->getResultObject();
+ if ($forInkjet)
+ $builder->where("t1.inkjet", 1);
+
+ return $builder;
}
public function getNombre($id)
@@ -355,5 +369,5 @@ class PapelImpresionModel extends \App\Models\BaseModel
return "";
}
-
+
}
diff --git a/ci4/app/Models/Presupuestos/PresupuestoAcabadosModel.php b/ci4/app/Models/Presupuestos/PresupuestoAcabadosModel.php
index c0dcf401..410f3117 100755
--- a/ci4/app/Models/Presupuestos/PresupuestoAcabadosModel.php
+++ b/ci4/app/Models/Presupuestos/PresupuestoAcabadosModel.php
@@ -72,25 +72,37 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
$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);
- $ret_array[] = (object)[
- 'tarifa_id'=> $tarifa_value[0]->tarifa_acabado_id,
- 'tarifa_nombre'=> $tarifa_value[0]->tarifa_acabado_nombre,
- '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,
- ];
+ $ret_array = [];
+ foreach ($tarifa_value as $tarifa) {
+ $result_data = $this->calcularTarifa($tarifa, $tirada, $POD<$tirada?false:true);
+ array_push($ret_array, (object)[
+ 'tarifa_id'=> $tarifa->tarifa_acabado_id,
+ 'tarifa_nombre'=> $tarifa->tarifa_acabado_nombre,
+ 'nombre'=> $tarifa->tarifa_acabado_nombre,
+ 'precio_unidad'=> round($result_data[0], 2),
+ 'total'=> round($result_data[1], 2),
+ 'precio_total'=> round($result_data[1], 2),
+ 'margen'=> $result_data[2],
+ 'proveedor' => $tarifa->proveedor_nombre,
+ 'proveedor_id' => $tarifa->proveedor_id,
+ ]);
+ }
+ usort($ret_array, function($a, $b) {
+ return $a->precio_total <=> $b->precio_total;
+ });
return $ret_array;
}
else{
$ret_array[] = (object)[
'tarifa_id'=> $tarifa_acabado_id,
'tarifa_nombre'=> $modelTarifa->getNombreTarifaAcabado($tarifa_acabado_id)[0]->nombre,
+ 'nombre'=> $modelTarifa->getNombreTarifaAcabado($tarifa_acabado_id)[0]->nombre,
'precio_unidad' => 0,
+ 'total' => 0,
+ 'precio_total' => 0,
'margen' => 0,
- 'total'=> 0,
+ 'proveedor' => '',
+ 'proveedor_id' => 0,
];
return $ret_array;
}
@@ -194,7 +206,7 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
- "t1.id AS id, t1.tarifa_acabado_id AS tarifa_acabado_id, t1.precio_unidad AS precio_unidad,
+ "t1.id AS id, t1.tarifa_acabado_id AS tarifa_acabado_id, t1.tarifa_acabado_id AS tarifa_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.proveedor_id AS proveedor_id, t3.nombre AS proveedor,"
);
diff --git a/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php
index 7ce6c1c4..b4360ea1 100755
--- a/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php
+++ b/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php
@@ -84,9 +84,11 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
$datos = [
'tarifa_id'=> $tarifa['tarifa_id'],
'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
+ 'nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
'precio_unidad'=> $result_data[0],
'tiempo' => $tiempo,
'total'=> $result_data[1],
+ 'precio_total'=> $result_data[1],
'margen' => $result_data[2],
'proveedor' => $tarifa_proveedor->proveedor_nombre,
'proveedor_id' => $tarifa_proveedor->proveedor_id,
@@ -117,10 +119,12 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
(object)[
'tarifa_id'=> $tarifa['tarifa_id'],
'tarifa_nombre'=> $tarifa['tarifa_nombre'],
+ 'nombre'=> $tarifa['tarifa_nombre'],
'proveedor' => lang('Presupuestos.no_disponible'),
'precio_unidad'=> 0,
'tiempo' => null,
'total'=> 0,
+ 'precio_total'=> 0,
'margen' => 0,
]);
}
@@ -135,9 +139,11 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
array_push($result_array, (object)[
'tarifa_id'=> $tarifa_proveedor->tarifa_enc_id,
'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
+ 'nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
'precio_unidad'=> $result_data[0],
'tiempo' => null,
'total'=> $result_data[1],
+ 'precio_total'=> $result_data[1],
'margen'=> $result_data[2],
'proveedor' => $tarifa_proveedor->proveedor_nombre,
'proveedor_id' => $tarifa_proveedor->proveedor_id,
@@ -159,10 +165,12 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
(object)[
'tarifa_id'=> $tarifa['tarifa_id'] ,
'tarifa_nombre'=> $tarifa['tarifa_nombre'],
+ 'nombre'=> $tarifa['tarifa_nombre'],
'proveedor' => lang('Presupuestos.no_disponible'),
'precio_unidad'=> 0,
'tiempo' => null,
'total'=> 0,
+ 'precio_total'=> 0,
'margen' => 0,
]);
}
@@ -173,17 +181,17 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
}
- public function getProveedoresForSelector($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto){
+ public function getProveedoresForSelector($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto, $paginasCuadernillo = 32){
$proveedores = [];
$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($modelTarifa->isTarifaPorHoras($tarifa_encuadernacion_id)){
+ $tiempo = $this->calcularTiempoCosido(16, $paginas, $tirada, $paginasCuadernillo); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada);
}
else{
+ $tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto);
}
if (count($tarifa_value)>0) {
@@ -215,9 +223,11 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
array_push($ret_array, (object)[
'tarifa_id'=> $tarifa->tarifa_enc_id,
'tarifa_nombre'=> $tarifa->tarifa_enc_nombre,
+ 'nombre'=> $tarifa->tarifa_enc_nombre,
'precio_unidad'=> $result_data[0],
'tiempo' => null,
'total'=> $result_data[1],
+ 'precio_total'=> $result_data[1],
'margen'=> $result_data[2],
'proveedor' => $tarifa->proveedor_nombre,
'proveedor_id' => $tarifa->proveedor_id,
@@ -237,10 +247,12 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
$ret_array[] = (object)[
'tarifa_id'=> $tarifa_encuadernacion_id,
'tarifa_nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
+ 'nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
'proveedor' => lang('Presupuestos.no_disponible'),
'precio_unidad'=> 0,
'tiempo' => null,
'total'=> 0,
+ 'precio_total'=> 0,
'margen'=> 0,
];
return $ret_array;
@@ -286,9 +298,11 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
(object)[
'tarifa_id'=> $tarifa_proveedor->tarifa_enc_id,
'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
+ 'nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
'precio_unidad'=> $result_data[0],
'tiempo' => $tiempo,
'paginas_por_cuadernillo' => $paginas_cuadernillo,
+ 'precio_total'=> $result_data[1],
'total'=> $result_data[1],
'margen' => $result_data[2],
'proveedor' => $tarifa_proveedor->proveedor_nombre,
@@ -310,11 +324,13 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
$ret_array[] = (object)[
'tarifa_id'=> $tarifa_encuadernacion_id,
'tarifa_nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
+ 'nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
'proveedor' => lang('Presupuestos.no_disponible'),
'precio_unidad'=> 0,
'tiempo' => null,
'paginas_por_cuadernillo' => null,
'total'=> 0,
+ 'precio_total'=> 0,
'margen' => 0,
];
return $ret_array;
diff --git a/ci4/app/Models/Presupuestos/PresupuestoLineaModel.php b/ci4/app/Models/Presupuestos/PresupuestoLineaModel.php
index 6a34a602..47e6ec82 100755
--- a/ci4/app/Models/Presupuestos/PresupuestoLineaModel.php
+++ b/ci4/app/Models/Presupuestos/PresupuestoLineaModel.php
@@ -330,8 +330,9 @@ class PresupuestoLineaModel extends \App\Models\BaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
- "*"
+ "*, t2.nombre AS papel_generico"
)
+ ->join("lg_papel_generico t2", "t1.papel_id = t2.id", "left")
->where("t1.presupuesto_id", $presupuesto_id);
return $builder->orderBy("t1.id", "asc")->get()->getResultObject();
diff --git a/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php b/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php
index 8612e8a4..72211db4 100755
--- a/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php
+++ b/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php
@@ -50,28 +50,37 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
$modelTarifa = model('App\Models\Tarifas\TarifaManipuladoModel');
$tarifa_value = $modelTarifa->getTarifaPresupuestoManipulado($tarifa_manipulado_id, $tirada);
if (count($tarifa_value)>0) {
+ $ret_array = [];
+ foreach($tarifa_value as $tarifa){
+ $result_data = $this->calcularTarifa($tarifa, $tirada, $POD<$tirada?false:true);
+ array_push($ret_array, (object)[
+ 'tarifa_id'=> $tarifa->tarifa_manipulado_id,
+ 'tarifa_nombre'=> $tarifa->tarifa_manipulado_nombre,
+ 'nombre'=> $tarifa->tarifa_manipulado_nombre,
+ 'precio_unidad'=> $result_data[0],
+ 'total'=> $result_data[1],
+ 'precio_total'=> $result_data[1],
+ 'margen' => $result_data[2],
+ ]);
+ }
+
+ usort($ret_array, function($a, $b) {
+ return $a->precio_total <=> $b->precio_total;
+ });
- $result_data = $this->calcularTarifa($tarifa_value[0], $tirada, $POD<$tirada?false:true);
- $ret_array[] = (object)[
- 'tarifa_id'=> $tarifa_value[0]->tarifa_manipulado_id,
- 'tarifa_nombre'=> $tarifa_value[0]->tarifa_manipulado_nombre,
- 'precio_unidad'=> $result_data[0],
- 'total'=> $result_data[1],
- 'margen' => $result_data[2],
- ];
return $ret_array;
}
else{
$ret_array[] = (object)[
'tarifa_id'=> $tarifa_manipulado_id,
'tarifa_nombre'=> $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre,
+ 'nombre'=> $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre,
'precio_unidad' => 0,
'total'=> 0,
'margen' => 0,
];
return $ret_array;
}
- return [];
}
private function calcularTarifa($tarifa, $tirada, $is_POD=false){
@@ -170,8 +179,10 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
array_push($tarifas, (object)[
'tarifa_id'=> $tarifa_value[0]->tarifa_manipulado_id,
'tarifa_nombre'=> $tarifa_value[0]->tarifa_manipulado_nombre,
+ 'nombre'=> $tarifa_value[0]->tarifa_manipulado_nombre,
'precio_unidad'=> $result_data[0],
'total'=> $result_data[1],
+ 'precio_total'=> $result_data[1],
'margen'=> $result_data[2],
]);
}
@@ -180,8 +191,10 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
(object)[
'tarifa_id'=> $tarifa['tarifa_id'] ,
'tarifa_nombre'=> $tarifa['tarifa_nombre'],
+ 'nombre'=> $tarifa['tarifa_nombre'],
'precio_unidad' => 0,
'total'=> 0,
+ 'precio_total'=> 0,
'margen' => 0,
]);
}
diff --git a/ci4/app/Models/Presupuestos/PresupuestoModel.php b/ci4/app/Models/Presupuestos/PresupuestoModel.php
index 135efbc2..4a80cd50 100755
--- a/ci4/app/Models/Presupuestos/PresupuestoModel.php
+++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php
@@ -85,6 +85,7 @@ class PresupuestoModel extends \App\Models\BaseModel
"comentarios_safekat",
"comentarios_pdf",
"comentarios_tarifa",
+ "comentarios_presupuesto",
"comentarios_produccion",
"lomo_cubierta",
"lomo_sobrecubierta",
@@ -132,6 +133,7 @@ class PresupuestoModel extends \App\Models\BaseModel
'paginasCuadernillo',
'lomo_redondo',
'cabezada',
+ 'envio_base',
];
protected $returnType = "App\Entities\Presupuestos\PresupuestoEntity";
@@ -412,6 +414,7 @@ class PresupuestoModel extends \App\Models\BaseModel
'ferro_digital' => $data['ferro_digital'] ? 1 : 0,
'marcapaginas' => $data['marcapaginas'] ? 1 : 0,
'prototipo' => $data['prototipo'] ? 1 : 0,
+ 'envio_base' => $data['envio_base'],
'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,
@@ -557,7 +560,7 @@ class PresupuestoModel extends \App\Models\BaseModel
// -- SOBRECUBIERTA --
if ($data['sobrecubierta']) {
$values['sobrecubierta'] = array(
- 'papel_id' => intval($data['sobrecubierta']['papel']),
+ 'papel_id' => intval($data['sobrecubierta']['papel']['id']),
'gramaje' => intval($data['sobrecubierta']['gramaje']),
'imprimir' => 1,
);
diff --git a/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php
index a2828855..f59520ea 100755
--- a/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php
+++ b/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php
@@ -51,19 +51,30 @@ class PresupuestoPreimpresionesModel extends \App\Models\BaseModel
$tarifa_value = $modelTarifa->getTarifaPresupuestoPreimpresion($tarifa_preimpresion_id);
if (count($tarifa_value)>0) {
- $result_data = $this->calcularTarifa($tarifa_value[0]);
- $ret_array[] = (object)[
- 'tarifa_id'=> $tarifa_value[0]->tarifa_preimpresion_id,
- 'tarifa_nombre'=> $tarifa_value[0]->tarifa_preimpresion_nombre,
- 'precio'=> $result_data[0],
- 'margen'=> $result_data[1],
- ];
+
+ $ret_array = [];
+ foreach ($tarifa_value as $tarifa) {
+ $result_data = $this->calcularTarifa($tarifa);
+ array_push($ret_array, (object)[
+ 'tarifa_id'=> $tarifa->tarifa_preimpresion_id,
+ 'tarifa_nombre'=> $tarifa->tarifa_preimpresion_nombre,
+ 'nombre'=> $tarifa->tarifa_preimpresion_nombre,
+ 'precio'=> $result_data[0],
+ 'margen'=> $result_data[1],
+ ]);
+ }
+
+ usort($ret_array, function($a, $b) {
+ return $a->precio <=> $b->precio;
+ });
+
return $ret_array;
}
else{
$ret_array[] = (object)[
'tarifa_id'=> $tarifa_preimpresion_id,
'tarifa_nombre'=> $modelTarifa->getNombreTarifaPreimpresion($tarifa_preimpresion_id)[0]->nombre,
+ 'nombre'=> $modelTarifa->getNombreTarifaPreimpresion($tarifa_preimpresion_id)[0]->nombre,
'precio' => 0,
'margen' => 0,
];
@@ -146,7 +157,7 @@ class PresupuestoPreimpresionesModel extends \App\Models\BaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
- "t1.id AS id, t1.tarifa_preimpresion_id AS tarifa_preimpresion_id, t1.precio AS precio, t1.margen AS margen, t2.nombre AS nombre"
+ "t1.id AS id, t1.tarifa_preimpresion_id AS tarifa_preimpresion_id, t1.tarifa_preimpresion_id AS tarifa_id, t1.precio AS precio, t1.margen AS margen, t2.nombre AS nombre"
);
$builder->where('t1.presupuesto_id', $presupuesto_id);
diff --git a/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php b/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php
index 75e9b1ef..f7141ebb 100755
--- a/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php
+++ b/ci4/app/Models/Presupuestos/PresupuestoServiciosExtraModel.php
@@ -50,19 +50,27 @@ class PresupuestoServiciosExtraModel extends \App\Models\BaseModel
$tarifa_value = $modelTarifa->getTarifaPresupuestoExtra($tarifa_extra_id);
if (count($tarifa_value)>0) {
- $result_data = $this->calcularTarifa($tarifa_value[0]);
- $ret_array[] = (object)[
- 'tarifa_id'=> $tarifa_value[0]->tarifa_extra_id,
- 'tarifa_nombre'=> $tarifa_value[0]->tarifa_extra_nombre,
- 'precio'=> $result_data[0],
- 'margen'=> $result_data[1],
- ];
+ $ret_array = [];
+ foreach($tarifa_value as $tarifa){
+ $result_data = $this->calcularTarifa($tarifa);
+ array_push($ret_array, (object)[
+ 'tarifa_id'=> $tarifa->tarifa_extra_id,
+ 'tarifa_nombre'=> $tarifa->tarifa_extra_nombre,
+ 'nombre'=> $tarifa->tarifa_extra_nombre,
+ 'precio'=> $result_data[0],
+ 'margen'=> $result_data[1],
+ ]);
+ }
+ usort($ret_array, function($a, $b) {
+ return $a->precio <=> $b->precio;
+ });
return $ret_array;
}
else{
$ret_array[] = (object)[
'tarifa_id'=> $tarifa_extra_id,
'tarifa_nombre'=> $modelTarifa->getNombreTarifaExtra($tarifa_extra_id)[0]->nombre,
+ 'tarifa'=> $modelTarifa->getNombreTarifaExtra($tarifa_extra_id)[0]->nombre,
'precio' => 0,
'margen' => 0,
];
diff --git a/ci4/app/Models/Tarifas/TarifaEnvioModel.php b/ci4/app/Models/Tarifas/TarifaEnvioModel.php
index c5348c6e..c73aff07 100755
--- a/ci4/app/Models/Tarifas/TarifaEnvioModel.php
+++ b/ci4/app/Models/Tarifas/TarifaEnvioModel.php
@@ -98,11 +98,13 @@ class TarifaEnvioModel extends \App\Models\BaseModel
// Si el pais es españa se tienen que tener en cuenta los postales
// Se busca primero la tarifa a la que corresponde
$builder = $this->db->table($this->table . " t1")
- ->select("t1.id AS tarifa_envio_id, t2.importe_fijo as importe_fijo")
+ ->select("t1.id AS tarifa_envio_id, t2.importe_fijo as importe_fijo, t3.nombre as pais")
->join("tarifas_envios_zonas t2", "t1.id = t2.tarifa_envio_id")
+ ->join("lg_paises t3", "t1.pais_id = t3.id")
->where("t1.pais_id", $paisId)
->where("t1.is_deleted", 0)
->where("t2.is_deleted", 0);
+
if ($paisId == 1) { // España
$builder->where("CAST(t2.cp_inicial AS UNSIGNED)<=", intval($cp))
@@ -117,10 +119,12 @@ class TarifaEnvioModel extends \App\Models\BaseModel
$precio_tarifas = $model->getEnvioPrecio($tarifa->tarifa_envio_id, $peso, $tipo_envio);
foreach ($precio_tarifas as $precio_tarifa) {
$precio_tarifa->importe_fijo = $tarifa->importe_fijo;
+ $precio_tarifa->pais = $tarifa->pais;
array_push($resultado, $precio_tarifa);
}
}
+
return $resultado;
}
}
diff --git a/ci4/app/Models/Usuarios/UserModel.php b/ci4/app/Models/Usuarios/UserModel.php
index a4748d14..d4e2d993 100755
--- a/ci4/app/Models/Usuarios/UserModel.php
+++ b/ci4/app/Models/Usuarios/UserModel.php
@@ -20,14 +20,13 @@ class UserModel extends \App\Models\BaseModel
protected $allowedFields = [
"username",
- "email",
"first_name",
"last_name",
"client_id",
"status",
"status_message",
"active",
- "country",
+ "comments",
"last_active",
"created_at",
"updated_at",
@@ -39,143 +38,25 @@ class UserModel extends \App\Models\BaseModel
protected $validationRules = [
- "address" => [
- "label" => "Users.address",
- "rules" => "trim|max_length[255]",
- ],
- "blocked" => [
- "label" => "Users.blocked",
- "rules" => "required|permit_empty",
- ],
- "city" => [
- "label" => "Users.city",
- "rules" => "trim|max_length[255]",
- ],
- "country" => [
- "label" => "Users.country",
- "rules" => "trim|max_length[2]",
- ],
- "date_birth" => [
- "label" => "Users.dateBirth",
- "rules" => "valid_date|permit_empty",
- ],
- "email" => [
- "label" => "Users.email",
- "rules" => "trim|required|max_length[150]|valid_email",
- ],
- "email_confirmed" => [
- "label" => "Users.emailConfirmed",
- "rules" => "required|integer",
- ],
"first_name" => [
"label" => "Users.firstName",
"rules" => "trim|max_length[150]",
],
- "language" => [
- "label" => "Users.language",
- "rules" => "trim|max_length[10]",
- ],/*
- "last_access" => [
- "label" => "Users.lastAccess",
- "rules" => "valid_date",
- ],*/
- "last_ip" => [
- "label" => "Users.lastIp",
- "rules" => "max_length[50]",
- ],
"last_name" => [
"label" => "Users.lastName",
"rules" => "trim|max_length[150]",
],
- "mobile" => [
- "label" => "Users.mobile",
- "rules" => "trim|max_length[50]",
- ],
- "password" => [
- "label" => "Users.password",
- "rules" => "required|max_length[35]",
- ],
- "picture" => [
- "label" => "Users.picture",
- "rules" => "trim|max_length[150]",
- ],
- "state" => [
- "label" => "Users.state",
- "rules" => "trim|max_length[255]",
- ],
- "zip_code" => [
- "label" => "Users.zipCode",
- "rules" => "trim|max_length[50]",
- ],
];
protected $validationMessages = [
- "address" => [
- "max_length" => "Users.validation.address.max_length",
- ],
-
- "blocked" => [
- "required" => "Users.validation.email_confirmed.required",
- ],
- "city" => [
- "max_length" => "Users.validation.city.max_length",
- ],
- "country" => [
- "max_length" => "Users.validation.country.max_length",
- "required" => "Users.validation.country.required",
- ],
- "date_birth" => [
- "valid_date" => "Users.validation.date_birth.valid_date",
- ],
- "email" => [
- "max_length" => "Users.validation.email.max_length",
- "required" => "Users.validation.email.required",
- "valid_email" => "Users.validation.email.valid_email",
- ],
- "email_confirmed" => [
- "integer" => "Users.validation.email_confirmed.integer",
- "required" => "Users.validation.email_confirmed.required",
- ],
"first_name" => [
"max_length" => "Users.validation.first_name.max_length",
"required" => "Users.validation.first_name.required",
],
-
- "language" => [
- "max_length" => "Users.validation.language.max_length",
- "required" => "Users.validation.language.required",
- ],
- "last_access" => [
- "required" => "Users.validation.last_access.required",
- "valid_date" => "Users.validation.last_access.valid_date",
- ],
- "last_ip" => [
- "max_length" => "Users.validation.last_ip.max_length",
- "required" => "Users.validation.last_ip.required",
- ],
"last_name" => [
"max_length" => "Users.validation.last_name.max_length",
"required" => "Users.validation.last_name.required",
- ],
- "mobile" => [
- "max_length" => "Users.validation.mobile.max_length",
- "required" => "Users.validation.mobile.required",
- ],
- "password" => [
- "max_length" => "Users.validation.password.max_length",
- "required" => "Users.validation.password.required",
- ],
- "picture" => [
- "max_length" => "Users.validation.picture.max_length",
- "required" => "Users.validation.picture.required",
- ],
- "state" => [
- "max_length" => "Users.validation.state.max_length",
- "required" => "Users.validation.state.required",
- ],
- "zip_code" => [
- "max_length" => "Users.validation.zip_code.max_length",
- ],
+ ],
];
public function getGroupsTitles($user_token){
diff --git a/ci4/app/Services/PresupuestoClienteService.php b/ci4/app/Services/PresupuestoClienteService.php
index 2868f4bf..17c4acc8 100644
--- a/ci4/app/Services/PresupuestoClienteService.php
+++ b/ci4/app/Services/PresupuestoClienteService.php
@@ -65,7 +65,7 @@ class PresupuestoClienteService extends BaseService
}
}
- public static function obtenerCubierta($data)
+ public static function obtenerCubierta($data, $return_raw=false)
{
$uso = $data['uso'];
@@ -76,7 +76,6 @@ class PresupuestoClienteService extends BaseService
$isColor = $data['isColor'];
$isHq = $data['isHq'];
$cliente_id = $data['cliente_id'];
- $paginas_color = $data['paginas_color'];
$lomoRedondo = $data['lomoRedondo'];
$lineas_cubierta = [];
@@ -102,6 +101,14 @@ class PresupuestoClienteService extends BaseService
}
if (count($lineas_cubierta) > 0) {
+ if($return_raw){
+ $lineas_cubierta = array_values(array_unique($lineas_cubierta, SORT_REGULAR));
+
+ return[
+ 'cubierta' => $lineas_cubierta
+ ];
+ }
+
usort(
$lineas_cubierta,
function ($a, $b) {
@@ -119,7 +126,7 @@ class PresupuestoClienteService extends BaseService
return $lineas_cubierta;
}
- public static function obtenerSobrecubierta($data)
+ public static function obtenerSobrecubierta($data, $return_raw=false)
{
$uso = $data['uso'];
@@ -154,6 +161,14 @@ class PresupuestoClienteService extends BaseService
}
if (count($lineas_sobrecubierta) > 0) {
+ if($return_raw){
+ $lineas_sobrecubierta = array_values(array_unique($lineas_sobrecubierta, SORT_REGULAR));
+
+ return[
+ 'sobrecubierta' => $lineas_sobrecubierta
+ ];
+ }
+
usort(
$lineas_sobrecubierta,
function ($a, $b) {
@@ -171,7 +186,7 @@ class PresupuestoClienteService extends BaseService
return $lineas_sobrecubierta;
}
- public static function obtenerGuardas($data)
+ public static function obtenerGuardas($data, $return_raw=false)
{
$uso = $data['uso'];
@@ -205,6 +220,14 @@ class PresupuestoClienteService extends BaseService
}
if (count($lineas_guardas) > 0) {
+ if($return_raw){
+ $lineas_guardas = array_values(array_unique($lineas_guardas, SORT_REGULAR));
+
+ return[
+ 'guardas' => $lineas_guardas
+ ];
+ }
+
usort(
$lineas_guardas,
function ($a, $b) {
@@ -241,28 +264,31 @@ class PresupuestoClienteService extends BaseService
* - isHq: si es alta calidad
* - paginas_color: número de páginas a color
*/
- private static function obtenerPresupuestoClienteInterior($data)
+ public static function obtenerPresupuestoClienteInterior($data, $return_raw = false)
{
$uso = $data['uso'];
$tipo_impresion_id = $data['tipo_impresion_id'];
$datosPedido = $data['datosPedido'];
+ $paginas_color = $data['paginas_color'];
if ($data['papelInteriorDiferente'] == false)
$papel_generico = $data['papel_generico'];
else {
$papel_generico = $data['papel_generico']['negro'];
- $papel_generico_color = $data['papel_generico']['color'];
+ if($paginas_color>0)
+ $papel_generico_color = $data['papel_generico']['color'];
}
if ($data['papelInteriorDiferente'] == false)
$gramaje = $data['gramaje'];
else {
$gramaje = $data['gramaje']['negro'];
- $gramaje_color = $data['gramaje']['color'];
+ if($paginas_color>0)
+ $gramaje_color = $data['gramaje']['color'];
}
$isColor = $data['isColor'];
$isHq = $data['isHq'];
$cliente_id = $data['cliente_id'];
- $paginas_color = $data['paginas_color'];
+
$paginas_negro = $datosPedido->paginas - $paginas_color;
@@ -293,6 +319,14 @@ class PresupuestoClienteService extends BaseService
}
if (count($linea_negro_plana) > 0) {
+ /*if($return_raw){
+ $linea_negro_plana = array_values(array_unique($linea_color_plana, SORT_REGULAR));
+
+ return[
+ 'negro' => $linea_negro_plana
+ ];
+ }*/
+
usort(
$linea_negro_plana,
function ($a, $b) {
@@ -335,6 +369,14 @@ class PresupuestoClienteService extends BaseService
}
if (count($linea_color_plana) > 0) {
+ /*if($return_raw){
+ $linea_color_plana = array_values(array_unique($linea_color_plana, SORT_REGULAR));
+
+ return[
+ 'color' => $linea_color_plana
+ ];
+ }*/
+
usort(
$linea_color_plana,
function ($a, $b) {
@@ -349,6 +391,16 @@ class PresupuestoClienteService extends BaseService
}
}
+
+ if($return_raw){
+ $linea_negro_plana = array_values(array_unique($linea_negro_plana, SORT_REGULAR));
+ $linea_color_plana = array_values(array_unique($linea_color_plana, SORT_REGULAR));
+
+ return[
+ 'negro' => $linea_negro_plana,
+ 'color' => $linea_color_plana
+ ];
+ }
// Si hay negro y color, y se hace con el mismo papel, hay que buscar la combinación
// más económica con la misma máquna
if (
@@ -493,7 +545,7 @@ class PresupuestoClienteService extends BaseService
* - isHq: si es alta calidad
* - paginas_color: número de páginas a color
*/
- private static function obtenerPresupuestoClienteInteriorRotativa($data)
+ public static function obtenerPresupuestoClienteInteriorRotativa($data, $return_raw = false)
{
$datosPedido = $data['datosPedido'];
$papel_generico = $data['papel_generico'];
@@ -532,6 +584,14 @@ class PresupuestoClienteService extends BaseService
if (count($linea_rotativa) > 0) {
+ if($return_raw){
+ $linea_rotativa = array_values(array_unique($linea_rotativa, SORT_REGULAR));
+
+ return[
+ 'rotativa' => $linea_rotativa,
+ ];
+ }
+
usort(
$linea_rotativa,
function ($a, $b) {
diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php
index a9495780..153813ea 100755
--- a/ci4/app/Services/PresupuestoService.php
+++ b/ci4/app/Services/PresupuestoService.php
@@ -462,7 +462,7 @@ class PresupuestoService extends BaseService
[$data['ancho'], $data['alto']] = PresupuestoService::calculoDimForma($datosPedido, $parametrosRotativa);
// calculo de papel y clicks
- $factor_anchura = round($maquina->ancho_impresion / $data['ancho'], 2);
+ $factor_anchura = floor($maquina->ancho_impresion / $data['ancho']);
$factor_altura = round($maquina->alto_impresion / ($data['alto'] + self::MARGEN_PAGINAS_ROTATIVA), 2);
$factor_altura_click = round($maquina->alto_click / ($data['alto'] + self::MARGEN_PAGINAS_ROTATIVA), 2);
@@ -470,13 +470,13 @@ class PresupuestoService extends BaseService
return [];
}
- $multiplicador_pliego = $datosPedido->isCosido ? 4 : 2;
- $paginas_por_pliego = round(floor($factor_anchura) * $factor_altura * $multiplicador_pliego, 2);
+ //$multiplicador_pliego = $datosPedido->isCosido ? 4 : 2;
+ $paginas_por_pliego = round($factor_anchura * $factor_altura * 2 /** $multiplicador_pliego*/, 2);
$pliegos_libro = round($paginas_por_pliego ? $datosPedido->paginas / $paginas_por_pliego : 0, 2);
$metros_papel_libro = round($pliegos_libro * ($maquina->alto_impresion / 1000.0), 2);
$metros_papel_total = round($metros_papel_libro * ($datosPedido->tirada + $datosPedido->merma), 2);
- $paginas_por_pliego_click = round(floor($factor_anchura) * $factor_altura_click * $multiplicador_pliego, 2);
+ $paginas_por_pliego_click = round($factor_anchura * $factor_altura_click * 2/** $multiplicador_pliego*/, 2);
$pliegos_libro_click = round($paginas_por_pliego_click ? $datosPedido->paginas / $paginas_por_pliego_click : 0, 2);
$clicks_libro = round(ceil($pliegos_libro_click) * 2, 2);
$clicks_pedido = round($clicks_libro * ($datosPedido->tirada + $datosPedido->merma), 2);
@@ -843,7 +843,7 @@ class PresupuestoService extends BaseService
$ancho_total = 0;
$sangre_cubierta = self::SANGRE_FORMAS_CUBIERTA;
if ($datosPedido->ancho >= 210) {
- $sangre_cubierta = 15;
+ $sangre_cubierta = 10;
}
if ($datosPedido) {
@@ -925,7 +925,7 @@ class PresupuestoService extends BaseService
$alto_total = floatval($datosPedido->alto);
$sangre_cubierta = self::SANGRE_FORMAS_CUBIERTA;
if ($datosPedido->alto >= 297) {
- $sangre_cubierta = 15;
+ $sangre_cubierta = 10;
}
// Tapa dura (cosido y fresado)
if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3) {
@@ -1687,7 +1687,7 @@ class PresupuestoService extends BaseService
uso_tarifa: $uso,
tirada: $datosPedido->tirada + $datosPedido->merma,
papel_impresion_id: $papel->id,
- );
+ )->orderBy("t1.id", "asc")->get()->getResultObject();
$data['uso'] = $uso;
$data['tipo'] = $tipo;
@@ -1775,7 +1775,7 @@ class PresupuestoService extends BaseService
uso_tarifa: ($uso == 'guardas') ? 'interior' : $uso,
tirada: $datosPedido->tirada + $datosPedido->merma,
papel_impresion_id: $papel->id,
- );
+ )->orderBy("t1.id", "asc")->get()->getResultObject();
// Se recorren las máquinas y se calcula el coste de linea por cada una
foreach ($maquinas as $maquina) {
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_comentariosItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_comentariosItems.php
index 64c4289c..f5b3c691 100644
--- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_comentariosItems.php
+++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_comentariosItems.php
@@ -158,7 +158,7 @@
= $this->section("additionalInlineJs") ?>
-
+/*
$("textarea[name*='comentarios_']").each(function(){
if (!$.trim($(this).val())) {
// textarea is empty or contains only white-space
@@ -167,7 +167,7 @@ $("textarea[name*='comentarios_']").each(function(){
$("#mostrar_" + $(this).attr('name')).show();
}
});
-
+*/
= $this->endSection() ?>
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.js b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.js
deleted file mode 100644
index dcfde390..00000000
--- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.js
+++ /dev/null
@@ -1,423 +0,0 @@
-const actionBtns_direcciones = function(data) {
- return `
-
-
- `;
-};
-
-// Funcion para obtener el peso total del libro
-function get_peso_libro(){
-
- var peso_total_libro = 0.0
- $('#tableLineasPresupuesto').DataTable().rows().every( function ( rowIdx, tableLoop, rowLoop ) {
- var rowData = this.data();
- peso_total_libro += parseFloat(rowData.peso)
- })
- return peso_total_libro;
-}
-
-
-async function get_precio_envio(peso, paisId, cp, tipo_envio){
-
- data = {
- tipo: 'get_tarifa',
- peso: peso,
- paisId: paisId,
- cp: cp,
- tipo_envio: tipo_envio,
- }
- data = Object.assign(data, window.token_ajax);
-
- const response = await fetch(window.location.origin + window.url_get_precio_envio , {
- method: "POST",
- body: JSON.stringify(data),
- headers: {
- "Content-type": "application/json; charset=UTF-8",
- }
- });
-
- const values = await response.json();
- yeniden(values[window.csrf_token]);
- return values.data;
-}
-
-
-async function get_coste_envio_tiradasAlternativas(tirada){
-
- var peso_libro = get_peso_libro();
- var tirada_inicial = parseInt($('#tirada').val());
- var coste = 0.0;
- var margen = 0.0;
-
- const table = $('#tableOfDireccionesEnvio').DataTable();
- const rows = table.rows().nodes();
-
- for (let i = 0; i < rows.length; i++) {
- const rowData = table.row(rows[i]).data();
- const porcentaje = parseInt(rowData.cantidad)/tirada_inicial*100.0;
- const cantidad = Math.floor(tirada*porcentaje/100.0);
- const peso_envio = cantidad*peso_libro/1000.0;
- const datos_tarifa = await get_precio_envio(peso_envio, rowData.paisId, rowData.cp, parseInt(rowData.entregaPieCalle)==1?'palets':'cajas');
-
- if(datos_tarifa.id!=null){
-
- if(peso_envio>parseFloat(datos_tarifa.peso_max)){
- coste += (parseFloat(datos_tarifa.precio_min) + (peso_envio-parseFloat(datos_tarifa.peso_min)) * parseFloat(datos_tarifa.precio_adicional)).toFixed(2);
- }
- // si no se calcula linealmente
- else{
- m=((parseFloat(datos_tarifa.precio_max)-parseFloat(datos_tarifa.precio_min))/(parseFloat(datos_tarifa.peso_max)-parseFloat(datos_tarifa.peso_min)));
- b=parseFloat(datos_tarifa.precio_max)-m*parseFloat(datos_tarifa.peso_max);
- coste += parseFloat(m*peso_envio+b);
- }
- }
- margen += coste*datos_tarifa.margen/100.0;
- }
-
- return {coste, margen};
-}
-
-
-function checkInsertar(){
-
- var cantidad_total = 0
- $('#tableOfDireccionesEnvio').DataTable().rows().every( function ( rowIdx, tableLoop, rowLoop ) {
- var data = this.data();
- cantidad_total += parseInt(data.cantidad )
- } );
- var htmlString = ''
- if(cantidad_total < parseInt($('#tirada').val())){
- $('#rowInsertar').css('display', 'flex')
- }
- else{
- $('#rowInsertar').css('display', 'none')
- }
-
- if(cantidad_total != parseInt($('#tirada').val())){
- htmlString = `
-
-
-
-
-
-
` +
- window.Presupuestos.validation.ejemplares_envio +
- `
-
-
`;
- }
- $('#alert-envios').html(htmlString)
-}
-
-
-async function updateTablaEnvios(tirada_inicial = null, tirada = null){
-
- var peso_total_libro = get_peso_libro();
-
- $('#tableOfDireccionesEnvio').DataTable().rows().every(async function ( rowIdx, tableLoop, rowLoop ) {
-
- var rowData = this.data();
-
- if(tirada_inicial!=null && tirada!=null){
- const porcentaje = parseInt(rowData.cantidad)/tirada_inicial*100.0;
- const cantidad = Math.floor(tirada*porcentaje/100.0);
- rowData.cantidad = cantidad
- }
- const peso_envio = peso_total_libro*parseInt(rowData.cantidad)/1000.0;
-
- var datos_tarifa = await get_precio_envio(peso_envio, rowData.paisId, rowData.cp, parseInt(rowData.entregaPieCalle)==1?'palets':'cajas');
-
-
- if(datos_tarifa.id!=null){
-
- if(peso_envio>parseFloat(datos_tarifa.peso_max) || parseFloat(datos_tarifa.peso_max) == 0){
- datos_tarifa.precio = parseFloat(datos_tarifa.peso_min) + (peso_envio-parseFloat(datos_tarifa.peso_min))*parseFloat(datos_tarifa.precio_adicional);
- }
- // si no se calcula linealmente
- else{
- m=((parseFloat(datos_tarifa.precio_max)-parseFloat(datos_tarifa.precio_min))/(parseFloat(datos_tarifa.peso_max)-parseFloat(datos_tarifa.peso_min)));
- b=parseFloat(datos_tarifa.precio_max)-m*parseFloat(datos_tarifa.peso_max);
- datos_tarifa.precio = parseFloat(m*peso_envio+b);
- }
-
-
- datos_tarifa.cantidad = parseInt($('#add_cantidad').val());
- datos_tarifa.peso = peso_envio;
-
- $('#tableOfDireccionesEnvio').DataTable().row(rowIdx)
- .data({
- 'tarifa_id': datos_tarifa.id,
- 'cantidad': rowData.cantidad,
- 'peso': datos_tarifa.peso.toFixed(3),
- 'att': rowData.att,
- 'email': rowData.email,
- 'direccion': rowData.direccion,
- 'cp': rowData.cp,
- 'municipio': rowData.municipio,
- 'provincia': rowData.provincia,
- 'paisId': rowData.paisId,
- 'telefono': rowData.telefono,
- 'proveedor': datos_tarifa.proveedor,
- 'proveedor_id': datos_tarifa.proveedor_id,
- 'precio': datos_tarifa.precio.toFixed(2),
- 'margen': datos_tarifa.margen,
- 'entregaPieCalle': rowData.entregaPieCalle,
- 'actionBtns_direcciones': actionBtns_direcciones,
- })
- .draw();
-
- checkInsertar()
- //updateTotales(false, false, true)
- updatePresupuesto({
- update_lineas: false,
- update_servicios: false,
- update_envios: false,
- update_resumen: true,
- update_tiradas_alternativas: true
- })
- }
- else{
- popErrorAlert(window.error_no_tarifa_envio, 'error-tarifa')
- }
- })
-}
-
-$('#insertar_direccion').on('click', function(){
-
- $("#addressForm").attr('action','create')
- var $newAddDialog = $("#addressForm")
- var maximaCantidad = parseInt($('#tirada').val())
- $("#add_cantidad").attr("max" , maximaCantidad);
- $("#add_cantidad").val( maximaCantidad);
- $("#add_cantidad").on('change', function(){
- $("#add_cantidad").val(parseInt($("#add_cantidad").val())>maximaCantidad ? maximaCantidad : $("#add_cantidad").val())
- })
-
- cantidad_total = 0
- tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
- var data = this.data();
- cantidad_total += parseInt(data.cantidad)
- } );
- $('#add_cantidad').attr('max-value', parseInt($('#tirada').val())-cantidad_total)
- $('#add_cantidad').val(parseInt($('#tirada').val())-cantidad_total)
- $newAddDialog.modal('show')
-})
-
-const lastColNr_direcciones = $('#tableOfDireccionesEnvio').find("tr:first th").length - 1;
-
-
-$(document).on('click', '.delete-add-row', function(e) {
- const row = $(this).closest('tr');
- tableEnvios.row( row )
- .remove()
- .draw();
- checkInsertar()
- //updateTotales(false, false, true)
- updatePresupuesto({
- update_lineas: false,
- update_servicios: false,
- update_envios: false,
- update_resumen: true,
- update_tiradas_alternativas: true
- })
- showBreadCrumbSaveButton(true);
-
-})
-
-$(document).on('click', '.btn-edit-add', function(e) {
- const row = $(this).closest('tr');
- var data = tableEnvios.row( row ).data()
-
- $("#addressForm").attr('action','edit')
- $("#addressForm").attr('row', row[0]._DT_RowIndex)
- $("#addressForm").attr('presupuestodireccion_id', $(this).attr('data-id'))
- var $newAddDialog = $("#addressForm")
- var maximaCantidad = parseInt($('#tirada').val())
- $("#add_cantidad").attr("max" , maximaCantidad);
- $("#add_cantidad").val( maximaCantidad);
- $("#add_cantidad").on('change', function(){
- $("#add_cantidad").val(parseInt($("#add_cantidad").val())>maximaCantidad ? maximaCantidad : $("#add_cantidad").val())
- })
-
- cantidad_total = 0
- tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
- var data2 = this.data();
- cantidad_total += parseInt(data2.cantidad)
- } );
- cantidad_total -= parseInt(data.cantidad) // Si es editar tienes que restar los de la linea actual
- $('#add_cantidad').attr('max-value', parseInt($('#tirada').val())-cantidad_total)
- $('#add_cantidad').val(parseInt($('#tirada').val())-cantidad_total)
-
- $('#add_att').val(data.att)
- $('#add_direccion').val(data.direccion)
- $('#add_email').val(data.email)
- $('#add_cp').val(data.cp)
- $('#add_municipio').val(data.municipio)
- $('#add_provincia').val(data.provincia)
- $('#add_pais_id').val(data.paisId)
- $('#add_telefono').val(data.telefono)
- $('#add_cantidad').val(data.cantidad)
- $('#add_entregaPieCalle').prop('checked', data.entregaPieCalle==1?true:false)
-
- $newAddDialog.modal('show')
-})
-
-
-
-
-
-$('#recoger_en_taller').change(function(){
- if(this.checked) {
- $('#rowTable').css('display', 'none')
- $('#rowInsertar').css('display', 'none')
- tableEnvios.clear().draw()
- }
- else{
- $('#rowTable').css('display', 'flex')
- $('#rowInsertar').css('display', 'flex')
- tableEnvios.columns.adjust();
- }
-})
-
-
-let tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
- draw:5,
- serverSide: false,
- processing: true,
- autoWidth: true,
- responsive: true,
- order: [[ 0, "asc" ]],
- pageLength: 20,
- lengthChange: false,
- searching: false,
- paging: false,
- info: false,
- scrollX: true,
-
- columns: [
- { 'data': 'tarifa_id' },
- { 'data': 'cantidad' },
- { 'data': 'peso' },
- { 'data': 'att' },
- { 'data': 'email' },
- { 'data': 'direccion' },
- { 'data': 'cp' },
- { 'data': 'municipio' },
- { 'data': 'paisId' ,
- render: function(data, type, row, meta) {
- var pais = window.paisList.find(element => element.id == data);
- return pais['nombre'];
- },
- },
- { 'data': 'telefono' },
- { 'data': 'proveedor'},
- { 'data': 'proveedor_id'},
- { 'data': 'precio' },
- { 'data': 'margen' },
- { 'data': 'entregaPieCalle' },
- {
- data: actionBtns_direcciones,
- className: 'row-edit dt-center'
- }
- ],
- columnDefs: [
- {
- orderable: false,
- searchable: false,
- targets: [lastColNr_direcciones]
- },
- {"orderData": [ 0], "targets": 0 },
-
- ],
- columnDefs: [
- {
- target: [0,11,13,14],
- visible: false,
- searchable: false
- },
- ],
- language: {
- url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
- },
-
- } );
-
-
-
-
-
-function save_datos_envios(){
-
- var id = $('#presupuesto_id').val()
-
- $.post( window.routes_envios.dataTableOfPresupuestoDirecciones,
- Object.assign({tipo: "clear_lineas", presupuesto_id: id}, window.token_ajax))
- .done(function( data ) {
-
- $('#tableOfDireccionesEnvio').DataTable().rows().every( function ( rowIdx, tableLoop, rowLoop ) {
- var data = this.data();
- $.post( '/presupuestos/presupuestodirecciones/add',
- Object.assign({
- presupuesto_id : id,
- tarifa_id : data.tarifa_id,
- cantidad : data.cantidad,
- peso : data.peso,
- att : data.att,
- email : data.email,
- direccion : data.direccion,
- paisId : data.paisId,
- provincia : data.provincia,
- municipio : data.municipio,
- cp : data.cp,
- telefono : data.telefono,
- precio : data.precio,
- margen : data.margen,
- proveedor : data.proveedor,
- proveedor_id : data.proveedor_id,
- entregaPieCalle : data.entregaPieCalle}, window.token_ajax))
- });
-
- })
-
-}
-
-
-function load_datos_envios(){
-
- window.direccionesList.forEach((linea) => {
- tableEnvios.row
- .add({
- 'tarifa_id': linea.tarifa_id,
- 'cantidad': linea.cantidad,
- 'peso': linea.peso,
- 'att': linea.att,
- 'email': linea.email,
- 'direccion': linea.direccion,
- 'cp': linea.cp,
- 'municipio': linea.municipio,
- 'provincia': linea.provincia,
- 'paisId': linea.pais_id,
- 'telefono': linea.telefono,
- 'proveedor': linea.proveedor,
- 'proveedor_id': linea.proveedor_id,
- 'precio': linea.precio,
- 'margen': linea.margen,
- 'entregaPieCalle': linea.entregaPieCalle,
- 'actionBtns_direcciones': actionBtns_direcciones,
- })
- .draw();
- checkInsertar()
-
-
- });
-
- updatePresupuesto({
- update_lineas: false,
- update_servicios: false,
- update_envios: false,
- update_resumen: true,
- update_tiradas_alternativas: false
- })
-
-}
-
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.php
index 26a0f0b7..9d3b89e7 100644
--- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.php
+++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosEnvios.php
@@ -10,11 +10,20 @@
= view("themes/vuexy/form/presupuestos/admin/_presupuestoDireccionesForm") ?>
+
+
+
+
+
+
+
-
+
-
+
@@ -23,12 +32,13 @@
+
- | Proveedor_id |
+
- Margen |
- Entrega a pie |
+
+
@@ -55,24 +65,3 @@
-
-
-
-= $this->section("additionalInlineJs") ?>
-
-window.paisList = ;
-window.direccionesList = ;
-
-window.routes_envios = {
- dataTableOfPresupuestoDirecciones: '= route_to('dataTableOfPresupuestoDirecciones') ?>'
-}
-
-window.url_get_precio_envio = '= route_to('processDataDirecciones') ?>';
-window.error_no_tarifa_envio = '= lang('PresupuestosDirecciones.validation.no_tarifa') ?>'
-window.token_ajax= {= csrf_token() ?? "token" ?>: = csrf_token() ?>v};
-
-$( document ).ready(function() {
- load_datos_envios();
-});
-
-= $this->endSection() ?>
\ No newline at end of file
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.js b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.js
deleted file mode 100644
index 2e974ab5..00000000
--- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.js
+++ /dev/null
@@ -1,144 +0,0 @@
-$('#paginas').on("change", function () {
-
- const url2 = window.location.href;
- const url_parts2 = url2.split('/');
-
- if($('#tipo_impresion_id').val() == 21){
- if(parseInt($('#paginas').val()) > 80){
- $('#paginas').val(80)
- }
- }
-
- if(url_parts2[url_parts2.length-2] == 'edit'){
-
- checkPaginasPresupuesto()
-
- // Si es negro o color
- if ($('#tipoImpresion').select2('data')[0].id == 'negro' ||
- $('#tipoImpresion').select2('data')[0].id == 'color') {
- $('#compPaginasNegro').val(parseInt($('#paginas').val())-parseInt($('#compPaginasColor').val()));
- $('#compPaginasNegro').trigger('change')
- }
- // Si es negrohq o colorhq
- if ($('#tipoImpresion').select2('data')[0].id == 'negrohq' ||
- $('#tipoImpresion').select2('data')[0].id == 'colorhq') {
- $('#compPaginasNegrohq').val(parseInt($('#paginas').val())-parseInt($('#compPaginasColorhq').val()));
- $('#compPaginasNegrohq').trigger('change');
- }
-
- //update_servicios(false)
- //updateLineasPresupuesto()
- updatePresupuesto({
- update_lineas: true,
- update_servicios: true,
- update_envios: true,
- update_resumen: true,
- update_tiradas_alternativas: true
- })
- }
-});
-
-
-$('#tirada').on("change", function (update_tiradas_alternativas = true) {
-
- calcular_mermas()
-
- const url2 = window.location.href;
- const url_parts2 = url2.split('/');
-
- if(url_parts2[url_parts2.length-2] == 'edit'){
- //update_servicios(false)
- //updateLineasPresupuesto()
- if(update_tiradas_alternativas)
- updatePresupuesto({
- update_lineas: true,
- update_servicios: false,
- update_envios: false,
- update_resumen: false,
- update_tiradas_alternativas: false
- })
- else
- updatePresupuesto({
- update_lineas: true,
- update_servicios: false,
- update_envios: false,
- update_resumen: false,
- update_tiradas_alternativas: false
- })
- checkInsertar()
- }
-})
-
-function calcular_mermas(){
-
- const tirada = parseInt($('#tirada').val())
- var merma = 0
- htmlString = ''
-
- if(tirada> parseInt($('#POD').val())){
- merma = tirada*0.1<=30 ? tirada*0.1 : 30
- }
- else{
- merma_lineas = []
- tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
- var rowData = this.data();
- if(rowData.row_id != 'lp_guardas' && rowData.row_id != 'lp_cubierta' && rowData.row_id != 'lp_sobrecubierta'){
- const formas_linea = parseInt($('#isCosido').val())==0?parseInt(rowData.formas):parseInt(rowData.formas)/2
- if(formas_linea > tirada)
- merma_lineas.push(formas_linea-tirada)
- else
- merma_lineas.push(tirada%formas_linea)
- }
-
- })
-
-
- if(merma_lineas.length>0)
- merma = Math.max(...merma_lineas)
- else{
- htmlString = `
-
-
-
-
-
-
` +
- window.Presupuestos.validation.no_lp_for_merma +
- `
-
-
`;
-
-
- merma = 0
-
- }
-
- }
- $('#mermacubierta').val(parseInt(merma))
- $('#merma').val(parseInt(merma))
- $('#alert-datosLibro').html(htmlString)
-}
-
-
-$('#papelFormatoPersonalizado').on("click",function(){
-
- if($('#papelFormatoPersonalizado').is(':checked')){
- document.getElementById("papelFormatoAncho").style.display = "block";
- document.getElementById("papelFormatoAlto").style.display = "block";
- $('#papelFormatoId').hide();
- $('#papelFormatoId').val(0).change();
- document.getElementById("label_papelFormatoId").innerHTML =
- window.Presupuestos.papelFormatoId + " (" +
- window.Presupuestos.papelFormatoAncho + " x " + window.Presupuestos.papelFormatoAncho + ")*";
- }
- else{
- document.getElementById("papelFormatoAncho").value= "";
- document.getElementById("papelFormatoAlto").value= "";
- document.getElementById("papelFormatoAncho").style.display = "none";
- document.getElementById("papelFormatoAlto").style.display = "none";
- $('#papelFormatoId').show();
- document.getElementById("label_papelFormatoId").innerHTML =
- window.Presupuestos.papelFormatoId + '*';
- }
-});
-
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.php
index bd524b58..6adb6fc9 100644
--- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.php
+++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.php
@@ -19,7 +19,7 @@
- >
+ >
@@ -30,7 +30,7 @@
-
+
@@ -41,28 +41,22 @@
-
-