mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
obteniendo presupuesto cliente rotativa
This commit is contained in:
@ -548,6 +548,7 @@ $routes->group('presupuestocliente', ['namespace' => 'App\Controllers\Presupuest
|
||||
$routes->post('edit/(:num)', 'Presupuestocliente::edit/$1', ['as' => 'editarPresupuestoCliente']);
|
||||
$routes->post('datatable', 'Cosidotapablanda::datatable', ['as' => 'tablaPresupuestosCliente']);
|
||||
$routes->post('getgramaje', 'Presupuestocliente::getGramaje', ['as' => 'obtenerGramaje']);
|
||||
$routes->post('presupuesto', 'Presupuestocliente::presupuesto', ['as' => 'presupuestoCliente']);
|
||||
});
|
||||
$routes->resource('presupuestocliente', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Presupuestocliente', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
@ -604,6 +604,127 @@ class Presupuestocliente extends \App\Controllers\GoBaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function presupuesto()
|
||||
{
|
||||
$POD = model('App\Models\Configuracion\ConfiguracionSistemaModel')->getPOD();
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
$reqData = $this->request->getPost();
|
||||
|
||||
$tirada = $reqData['tirada'] ?? 0;
|
||||
$tamanio = $reqData['tamanio'];
|
||||
$tipo_impresion_id = $this->getTipoImpresion($reqData['tipo'], $reqData['tapa']);
|
||||
$paginas_color= intval($reqData['paginasColor']) ?? 0;
|
||||
|
||||
$datosPedido = (object)array(
|
||||
'paginas' => intval($reqData['paginas']) ?? 0,
|
||||
'tirada' => $tirada[0],
|
||||
'merma' => $tirada[0]>$POD ? $this->calcular_merma($tirada[0], $POD) : 0,
|
||||
'ancho' => intval($tamanio['ancho']) ?? 100000,
|
||||
'alto' => intval($tamanio['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['papelInterior'] ?? 0,
|
||||
'nombre' => $reqData['papelInteriorNombre'] ?? "",
|
||||
];
|
||||
$gramaje = $reqData['gramajeInterior'] ?? 0;
|
||||
$cliente_id = $reqData['clienteId'] ?? -1;
|
||||
|
||||
$input_data = array(
|
||||
'uso' => 'interior',
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'datosPedido' => $datosPedido,
|
||||
'papel_generico' => $papel_generico,
|
||||
'gramaje' => $gramaje,
|
||||
'isColor' => intval($reqData['isColor']) ?? 0,
|
||||
'isHq' => intval($reqData['isHq']) ?? 0,
|
||||
'cliente_id' => $cliente_id,
|
||||
'paginas_color' => $paginas_color,
|
||||
);
|
||||
|
||||
$interiorPlana = PresupuestoService::obtenerPresupuestoClienteInterior($input_data);
|
||||
return $this->respond($interiorPlana);
|
||||
}
|
||||
else{
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***********************
|
||||
*
|
||||
* Funciones auxiliares
|
||||
*
|
||||
**********************/
|
||||
protected function getTipoImpresion($tipo, $tapa){
|
||||
|
||||
$tipo_impresion_id = 0;
|
||||
|
||||
if($tipo == 'fresado'){
|
||||
|
||||
if($tapa == 'blanda')
|
||||
$tipo_impresion_id = 2;
|
||||
else
|
||||
$tipo_impresion_id = 1;
|
||||
}
|
||||
else if($tipo == 'cosido'){
|
||||
|
||||
if($tapa == 'blanda')
|
||||
$tipo_impresion_id = 4;
|
||||
else
|
||||
$tipo_impresion_id = 3;
|
||||
}
|
||||
else if($tipo == 'espiral'){
|
||||
|
||||
if($tapa == 'blanda')
|
||||
$tipo_impresion_id = 6;
|
||||
else
|
||||
$tipo_impresion_id = 5;
|
||||
}
|
||||
else if($tipo == 'wireo'){
|
||||
|
||||
if($tapa == 'blanda')
|
||||
$tipo_impresion_id = 8;
|
||||
else
|
||||
$tipo_impresion_id = 7;
|
||||
}
|
||||
else if($tipo == 'grapado'){
|
||||
$tipo_impresion_id = 21;
|
||||
}
|
||||
|
||||
return $tipo_impresion_id;
|
||||
}
|
||||
|
||||
|
||||
protected function calcular_merma($tirada, $POD, $formas_lineas_interior = []){
|
||||
|
||||
$merma = 0;
|
||||
|
||||
if($tirada>$POD){
|
||||
$merma = $tirada*0.1<=30 ? $tirada*0.1 : 30;
|
||||
}
|
||||
else{
|
||||
$merma_lineas = [];
|
||||
foreach($formas_lineas_interior as $formas_linea){
|
||||
if($formas_linea > $tirada)
|
||||
array_push($merma_lineas, $formas_linea-$tirada);
|
||||
else
|
||||
array_push($merma_lineas, $tirada%$formas_linea);
|
||||
}
|
||||
if(count($merma_lineas)>0)
|
||||
$merma = max($merma_lineas);
|
||||
}
|
||||
|
||||
|
||||
return round($merma, 0);
|
||||
}
|
||||
|
||||
|
||||
protected function getPapelFormatoListItems($selId = null)
|
||||
{
|
||||
$papelFormatoModel = model('App\Models\Configuracion\PapelFormatoModel');
|
||||
|
||||
@ -187,7 +187,8 @@ class LoginAuthFilter implements FilterInterface
|
||||
'datatable_editor_2',
|
||||
'collect',
|
||||
'cast',
|
||||
'getGramaje'
|
||||
'getGramaje',
|
||||
'presupuesto',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -33,6 +33,115 @@ class PresupuestoService extends BaseService
|
||||
const SANGRE_FORMAS = 5.0;
|
||||
const SANGRE_FORMAS_CUBIERTA = 20.0;
|
||||
|
||||
public static function obtenerPresupuestoClienteInterior($data){
|
||||
|
||||
$uso = $data['uso'];
|
||||
$tipo_impresion_id = $data['tipo_impresion_id'];
|
||||
$datosPedido = $data['datosPedido'];
|
||||
$papel_generico = $data['papel_generico'];
|
||||
$gramaje = $data['gramaje'];
|
||||
$isColor = $data['isColor'];
|
||||
$isHq = $data['isHq'];
|
||||
$cliente_id = $data['cliente_id'];
|
||||
$paginas_color = $data['paginas_color'];
|
||||
|
||||
$paginas_negro = $datosPedido->paginas-$paginas_color;
|
||||
|
||||
|
||||
$linea_negro_plana = [];
|
||||
$linea_color_plana = [];
|
||||
|
||||
// Negro
|
||||
if($datosPedido->paginas > $paginas_color){
|
||||
|
||||
$datosPedido->paginas = $paginas_negro;
|
||||
for ($i=0; $i<2; $i++){
|
||||
|
||||
$lineas = PresupuestoService::obtenerComparadorPlana([
|
||||
'uso' => $uso,
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'datosPedido' => $datosPedido,
|
||||
'papel_generico' => $papel_generico,
|
||||
'gramaje' => $gramaje,
|
||||
'isColor' => false,
|
||||
'isHq' => $isHq,
|
||||
'cliente_id' => $cliente_id,
|
||||
'a_favor_fibra' => $i
|
||||
]);
|
||||
|
||||
if (count($lineas) > 0) {
|
||||
usort($lineas,
|
||||
function($a, $b)
|
||||
{
|
||||
$result = 0;
|
||||
if(floatval($a['fields']['total_impresion']) > floatval($b['fields']['total_impresion']))
|
||||
$result = 1;
|
||||
else if(floatval($a['fields']['total_impresion']) < floatval($b['fields']['total_impresion']))
|
||||
$result = -1;
|
||||
return $result;
|
||||
}
|
||||
);
|
||||
$linea_negro_plana = $lineas[0]['fields'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Color
|
||||
if($isColor){
|
||||
|
||||
$datosPedido->paginas = $paginas_color;
|
||||
for ($i=0; $i<2; $i++){
|
||||
|
||||
$lineas = PresupuestoService::obtenerComparadorPlana([
|
||||
'uso' => $uso,
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'datosPedido' => $datosPedido,
|
||||
'papel_generico' => $papel_generico,
|
||||
'gramaje' => $gramaje,
|
||||
'isColor' => true,
|
||||
'isHq' => $isHq,
|
||||
'cliente_id' => $cliente_id,
|
||||
'a_favor_fibra' => $i
|
||||
]);
|
||||
|
||||
if (count($lineas) > 0) {
|
||||
usort($lineas,
|
||||
function($a, $b)
|
||||
{
|
||||
$result = 0;
|
||||
if(floatval($a['fields']['total_impresion']) > floatval($b['fields']['total_impresion']))
|
||||
$result = 1;
|
||||
else if(floatval($a['fields']['total_impresion']) < floatval($b['fields']['total_impresion']))
|
||||
$result = -1;
|
||||
return $result;
|
||||
}
|
||||
);
|
||||
$linea_color_plana = $lineas[0]['fields'];
|
||||
}
|
||||
}
|
||||
for ($i=0; $i<2; $i++){
|
||||
|
||||
$lineas = PresupuestoService::obtenerComparadorPlana([
|
||||
'uso' => $uso,
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'datosPedido' => $datosPedido,
|
||||
'papel_generico' => $papel_generico,
|
||||
'gramaje' => $gramaje,
|
||||
'isColor' => true,
|
||||
'isHq' => $isHq,
|
||||
'cliente_id' => $cliente_id,
|
||||
'a_favor_fibra' => $i
|
||||
]);
|
||||
|
||||
if (count($lineas) > 0) {
|
||||
$linea_negro_plana = array_merge($linea_negro_plana, $lineas);
|
||||
}
|
||||
}
|
||||
}
|
||||
return [$linea_negro_plana, $linea_color_plana];
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getLineaPresupuestoPlana($data)
|
||||
{
|
||||
|
||||
@ -552,6 +552,7 @@
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
|
||||
window.routes_disenio_libro = {
|
||||
obtenerGramaje: "<?= route_to('obtenerGramaje') ?>",
|
||||
obtenerGramaje: "<?= route_to('obtenerGramaje') ?>",
|
||||
presupuestoCliente: "<?= route_to('presupuestoCliente') ?>",
|
||||
}
|
||||
<?= $this->endSection() ?>
|
||||
@ -157,15 +157,18 @@ function initDisenioLibro() {
|
||||
}
|
||||
|
||||
$('.change-tipo-impresion').on('change', function () {
|
||||
|
||||
isColor = $('#colorNegroDiv').hasClass('checked') ? false : true;
|
||||
isHq = $('#calidadEstandarDiv').hasClass('checked') ? false : true;
|
||||
|
||||
//si es color hay que mostrar el numero de paginas a color
|
||||
if (isColor) {
|
||||
$('#pagColorDiv').show();
|
||||
$('#paginasColor').val('0');
|
||||
}
|
||||
else {
|
||||
$('#pagColorDiv').hide();
|
||||
$('#paginasColor').val('0');
|
||||
}
|
||||
|
||||
var data = [];
|
||||
@ -403,18 +406,18 @@ function getDimensionLibro() {
|
||||
var ancho = 0;
|
||||
var alto = 0;
|
||||
|
||||
|
||||
if ($('#papelFormatoId').select2('data').length > 0) {
|
||||
if ($('#papelFormatoId').select2('data')[0].id.length > 0) {
|
||||
ancho = parseFloat($('#papelFormatoId').select2('data')[0].text.trim().split(" x ")[0]);
|
||||
alto = parseFloat($('#papelFormatoId').select2('data')[0].text.trim().split(" x ")[1]);
|
||||
if ($('#papelFormatoId option:selected').length > 0) {
|
||||
var selectedText = $('#papelFormatoId option:selected').text();
|
||||
if (selectedText.length > 0) {
|
||||
ancho = parseFloat(selectedText.trim().split(" x ")[0]);
|
||||
alto = parseFloat(selectedText.trim().split(" x ")[1]);
|
||||
}
|
||||
else if (document.getElementById('papelFormatoPersonalizado').checked) {
|
||||
ancho = parseFloat(document.getElementById('papelFormatoAncho').value);
|
||||
alto = parseFloat(document.getElementById('papelFormatoAlto').value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else if (document.getElementById('papelFormatoPersonalizado').checked) {
|
||||
ancho = parseFloat(document.getElementById('papelFormatoAncho').value);
|
||||
alto = parseFloat(document.getElementById('papelFormatoAlto').value);
|
||||
@ -565,40 +568,55 @@ async function calcularPresupuesto() {
|
||||
tamanio: getDimensionLibro(),
|
||||
tirada: getTiradas(),
|
||||
paginas: $('#paginas').val(),
|
||||
paginasColor: $('#paginasColor').val(),
|
||||
tipo: $('.custom-option-tipo.checked').attr('id').replace('Div', ''),
|
||||
tapa: $('#tapaDura').is(':checked') ? 'dura' : 'blanda',
|
||||
isColor: $('#colorNegroDiv').hasClass('checked') ? false : true,
|
||||
isHq: $('#calidadEstandarDiv').hasClass('checked') ? false : true,
|
||||
isColor: $('#colorNegroDiv').hasClass('checked') ? 0 : 1,
|
||||
isHq: $('#calidadEstandarDiv').hasClass('checked') ? 0 : 1,
|
||||
papelInterior: $('#papelInterior option:selected').val(),
|
||||
papelInteriorNombre: $('#papelInterior option:selected').text(),
|
||||
gramajeInterior: $('#gramajeInterior option:selected').text(),
|
||||
excluirRotativa: $('#excluirRotativa').is(':checked'),
|
||||
papelCubierta: $('#papelCubierta option:selected').val(),
|
||||
papelCubiertaNombre: $('#papelCubierta option:selected').text(),
|
||||
gramajeCubierta: $('#gramajeCubierta option:selected').text(),
|
||||
carasCubierta: $('#carasCubierta').val(),
|
||||
acabadoCubierta: $('#acabadosCubierta').val(),
|
||||
clienteId: $('#clienteId').val(),
|
||||
servicios: servicios,
|
||||
}
|
||||
// Si hay solapas de cubierta
|
||||
if ($('#solapasCubierta').is(':checked')) {
|
||||
datos.solapasCubierta = $('#anchoSolapasCubierta').val()
|
||||
}
|
||||
|
||||
|
||||
// Si hay sobrecubierta
|
||||
if($('.enable-sobrecubierta').is(':visible')) {
|
||||
if ($('.enable-sobrecubierta').is(':visible')) {
|
||||
datos.sobrecubierta = {
|
||||
papel: $('#papelSobrecubierta option:selected').val(),
|
||||
gramaje: $('#gramajeSobrecubierta option:selected').text(),
|
||||
acabado: $('#acabadosSobrecubierta').val()
|
||||
}
|
||||
if($('#solapasSobrecubierta').is(':checked')) {
|
||||
if ($('#solapasSobrecubierta').is(':checked')) {
|
||||
datos.sobrecubierta.solapas = $('#anchoSolapasSobrecubierta').val()
|
||||
}
|
||||
}
|
||||
|
||||
if($('.guardas').is(':visible')){
|
||||
if ($('.guardas').is(':visible')) {
|
||||
datos.guardas = {
|
||||
papel: $('#papelGuardas option:selected').val(),
|
||||
caras: $('#impresionGuardas option:selected').val()
|
||||
}
|
||||
}
|
||||
|
||||
datos = Object.assign(datos, window.token_ajax)
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_disenio_libro.presupuestoCliente,
|
||||
type: 'POST',
|
||||
data: datos,
|
||||
success: function (response) {
|
||||
console.log(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
10230
xdebug.log
10230
xdebug.log
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user