Merge branch 'mod/presupuesto_resumenes2' into 'main'

terminado resumenes + bugs

See merge request jjimenez/safekat!115
This commit is contained in:
2024-01-08 13:30:54 +00:00
9 changed files with 90 additions and 64 deletions

View File

@ -22,8 +22,8 @@ CI_ENVIRONMENT = development
# APP
#--------------------------------------------------------------------
#app.baseURL = 'https://sk-jjo.imnavajas.es'
app.baseURL = 'https://sk-imn.imnavajas.es'
app.baseURL = 'https://sk-jjo.imnavajas.es'
#app.baseURL = 'https://sk-imn.imnavajas.es'
# app.baseURL = "http://safekat.test/"
# app.forceGlobalSecureRequests = false

View File

@ -125,9 +125,6 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController
$id = $this->model->db->insertID();
$lp_model = model('App\Models\Presupuestos\PresupuestoLineaModel');
$lp_model->createForPresupuesto($id);
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
@ -547,6 +544,8 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController
$datos = $reqData['datos'] ?? null;
$presupuesto_id = $reqData['presupuesto_id'] ?? -1;
$model->where("presupuesto_id", $presupuesto_id)->delete();
if($datos != null){
$model->insertLineasPresupuesto($presupuesto_id, $datos);

View File

@ -176,6 +176,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
"total_margenes" => null,
"total_antes_descuento" => null,
"total_descuento" => null,
"total_descuentoPercent" => null,
"total_presupuesto" => null,
"total_precio_unidad" => null,
];
@ -318,6 +319,7 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
"total_margenes" => "?float",
"total_antes_descuento" => "?float",
"total_descuento" => "?float",
"total_descuentoPercent" => "?float",
"total_presupuesto" => "?float",
"total_precio_unidad" => "?float",
];

View File

@ -193,6 +193,7 @@ class PresupuestoModel extends \App\Models\GoBaseModel
"total_margenes",
"total_antes_descuento",
"total_descuento",
"total_descuentoPercent",
"total_presupuesto",
"total_precio_unidad",
];

View File

@ -22,7 +22,6 @@
<th class="lp-header"><?= lang('PresupuestosDirecciones.direccion') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.cp') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.municipio') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.provincia') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.pais') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.telefono') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.proveedor') ?></th>
@ -97,6 +96,7 @@ $(document).on('click', '.delete-add-row', function(e) {
.remove()
.draw();
checkInsertar()
updateTotales(false, false, true)
})
$(document).on('click', '.btn-edit-add', function(e) {
@ -119,7 +119,7 @@ $(document).on('click', '.btn-edit-add', function(e) {
var data2 = this.data();
cantidad_total += parseInt(data2.cantidad)
} );
cantidad_total += parseInt(data.cantidad) // Si es editar tienes que sumar los de la linea actual
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)
@ -178,7 +178,6 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
{ 'data': 'direccion' },
{ 'data': 'cp' },
{ 'data': 'municipio' },
{ 'data': 'provincia' },
{ 'data': 'paisId' ,
render: function(data, type, row, meta) {
var value = paisList.find(element => element.id === data);
@ -207,7 +206,7 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
],
columnDefs: [
{
target: [0,12,14,15],
target: [0,11,13,14],
visible: false,
searchable: false
},
@ -285,6 +284,8 @@ function save_datos_envios(){
}
load_datos_envios()
function load_datos_envios(){
$.post( '<?= route_to('dataTableOfPresupuestoDirecciones') ?>',
{

View File

@ -249,37 +249,45 @@
<?= $this->section("additionalInlineJs") ?>
$('#paginas').on("change", function () {
checkPaginasPresupuesto()
updateLineasPresupuesto()
// 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');
}
if(url_parts[url_parts.length-2] == 'edit'){
update_servicios(false)
checkPaginasPresupuesto()
updateLineasPresupuesto()
// 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)
}
});
$('#tirada').on("change", function () {
update_servicios(false)
calcular_mermas()
updateLineasPresupuesto()
checkInsertar()
const url = window.location.href;
const url_parts = url.split('/');
if(url_parts[url_parts.length-2] == 'edit'){
update_servicios(false)
updateLineasPresupuesto()
checkInsertar()
}
})
function calcular_mermas(){
const tirada = parseInt($('#tirada').val())
var merma = 0
htmlString = ''
if(tirada><?php echo $POD; ?>){
merma = tirada*0.1<=30 ? tirada*0.1 : 30
@ -296,7 +304,6 @@ function calcular_mermas(){
}
})
htmlString = ''
if(merma_lineas.length>0)
merma = Math.max(...merma_lineas)
else{
@ -376,7 +383,6 @@ $('#papelFormatoPersonalizado').on("click",function(){
servicioFerro()
});
<?php endif; ?>
$('#papelFormatoId').on('select2:select', function (e){
ancho_libro = getDimensionLibro().ancho;
@ -384,6 +390,8 @@ $('#papelFormatoId').on('select2:select', function (e){
update_servicios(false)
})
<?php endif; ?>
$('#papelFormatoAncho').on('change', function (e){
ancho_libro = getDimensionLibro().ancho;
alto_libro = getDimensionLibro().alto;

View File

@ -3056,6 +3056,14 @@ function fill_lp_from_bbdd(){
lp['total_impresion'] = lp['total_linea']
lp['precios_pliegos'] = lp['pliegos_precio']
lp['papel_generico_id'] = lp['papel_id']
dateObj = new Date(lp['tiempo_maquina'] * 1000);
hours = dateObj.getUTCHours();
minutes = dateObj.getUTCMinutes();
seconds = dateObj.getSeconds();
lp['tiempo_maquina'] = hours.toString().padStart(2, '0') + ':' +
minutes.toString().padStart(2, '0') + ':' +
seconds.toString().padStart(2, '0');
if(lp.maquina_tipo=='inkjet'){
@ -3159,7 +3167,9 @@ async function fill_bbdd_from_lp(presupuesto_id){
tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
var rowData = this.data();
//console.log(rowData)
console.log(rowData)
console.log(rowData.formas_v)
console.log(rowData.formas_v)
const formas = {
maquina_ancho: rowData.maquina_ancho,
maquina_alto: rowData.maquina_alto,
@ -3170,9 +3180,10 @@ async function fill_bbdd_from_lp(presupuesto_id){
formas_h: rowData.formas_h,
formas_orientacion: rowData.formas_orientacion,
}
console.log(JSON.stringify(formas))
var t_maq_str = rowData.tiempo.split(':'); // split it at the colons
var t_maq = 0
var t_maq = 0
if(t_maq_str.length == 3)
t_maq = (+t_maq_str[0]) * 3600 + (+t_maq_str[1]) * 60 + (+t_maq_str[2]);
@ -3270,29 +3281,28 @@ async function fill_bbdd_from_lp(presupuesto_id){
data.push(linea_data)
} );
if(data.lengh > 0){
await $.ajax({
type: 'post',
url: '<?= route_to("updateDataOfCosidotapablanda") ?>',
await $.ajax({
type: 'post',
url: '<?= route_to("updateDataOfCosidotapablanda") ?>',
data: {
tipo: 'lineasPresupuesto',
datos: data,
presupuesto_id: presupuesto_id,
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v
},
dataType: 'json',
success:function(response){
data: {
tipo: 'lineasPresupuesto',
datos: data,
presupuesto_id: presupuesto_id,
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v
},
dataType: 'json',
success:function(response){
token=response.<?= csrf_token() ?>;
yeniden(token);
}
}).fail(function (jqXHR, textStatus, error) {
// Handle error here
console.log(jqXHR)
});
}
token=response.<?= csrf_token() ?>;
yeniden(token);
}
}).fail(function (jqXHR, textStatus, error) {
// Handle error here
console.log(jqXHR)
});
}
function updateLineasPresupuesto(){

View File

@ -56,7 +56,7 @@
<dt class="col-6 fw-normal text-end">Total</dt>
<dd id="totalAntesDescuento" class="col-6 text-end"><?= old('0', $presupuestoEntity->total_antes_descuento) ?>€</dd>
<dt class="col-6 py-1 fw-normal text-end">Descuento</dt>
<div class="d-flex col-4 flex-row-reverse"><input id="descuento" name="total_descuentoPercent" type='number' value="<?= old('0', $presupuestoEntity->total_descuentoPercent) ?>" class="update-totales form-control" style="width:50% !important;"></div>
<div class="d-flex col-4 flex-row-reverse"><input id="total_descuentoPercent" type='number' value="<?= old('0', $presupuestoEntity->total_descuentoPercent) ?>" class="update-totales form-control" style="width:50% !important;"></div>
<dd id="descuentoTotal" class="col-2 py-1 text-end"><?= old('0', $presupuestoEntity->total_descuento) ?>€</dd>
<dt class="col-6 text-end">Total presupuesto</dt>
<dd id="totalDespuesDecuento" class="col-6 fw-semibold text-end"><?= old('0', $presupuestoEntity->total_presupuesto) ?>€</dd>
@ -85,14 +85,17 @@
function updateTotales(updateLP=true, updateServicios=true, updateEnvio=true){
totalPapel = 0
margenPapel = 0
var totalPapel = 0
var margenPapel = 0
totalImpresion = 0
margenImpresion = 0
var totalImpresion = 0
var margenImpresion = 0
totalServicios = 0
margenServicios = 0
var totalServicios = 0
var margenServicios = 0
var totalEnvios = 0
var margenEnvios = 0
if(updateLP){
if(typeof tableLineasPresupuesto !== 'undefined'){
@ -168,15 +171,13 @@ function updateTotales(updateLP=true, updateServicios=true, updateEnvio=true){
totalServicios -= margenServicios;
var porcentajeMargenServicios = margenServicios/(margenServicios+totalServicios)*100
$('#porcentajeMargenServicios').text(porcentajeMargenServicios.toFixed(0) + '%')
$('#porcentajeMargenServicios').text(isNaN(porcentajeMargenServicios.toFixed(0))?0:porcentajeMargenServicios.toFixed(0) + '%')
$('#totalServicios').text(totalServicios.toFixed(2) + '€')
$('#margenServicios').text(margenServicios.toFixed(2) + '€')
}
if(updateEnvio){
var totalEnvios = 0
var margenEnvios = 0
if ( typeof tableEnvios !== 'undefined' && tableEnvios.rows().count() > 0){
tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
var data = this.data()
@ -196,7 +197,7 @@ function updateTotales(updateLP=true, updateServicios=true, updateEnvio=true){
$('#totalMargenes').text((totalMargenes).toFixed(2) + '€')
var totalAntesDescuento = totalCostes + totalMargenes
var totalDescuento = totalAntesDescuento * parseInt($('#descuento').val())/100
var totalDescuento = totalAntesDescuento * parseInt($('#total_descuentoPercent').val())/100
var totalPresupuesto = totalAntesDescuento - totalDescuento
var precioUnidad = totalPresupuesto/parseInt($('#tirada').val())
@ -229,6 +230,7 @@ function getValuesResumenForm(){
formResumen += '&total_antes_descuento=' + $('#totalAntesDescuento').text().replace('€', '')
formResumen += '&total_descuento=' + $('#descuentoTotal').text().replace('€', '')
formResumen += '&total_descuentoPercent=' + $('#total_descuentoPercent').val()
formResumen += '&total_presupuesto=' + $('#totalDespuesDecuento').text().replace('€', '')
formResumen += '&total_precio_unidad=' + $('#precioUnidadPresupuesto').text().replace('€', '')

View File

@ -116,6 +116,9 @@
<!------------------------------------------->
<!-- Acciones antes de submit... -->
<!------------------------------------------->
const url = window.location.href;
const url_parts = url.split('/');
<?php if(str_contains($formAction,'edit')): ?>
<?= $this->section("additionalInlineJs") ?>