mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'fix/generar_albaranes_ocultar' into 'main'
arreglado bug en albaranes See merge request jjimenez/safekat!610
This commit is contained in:
@ -54,8 +54,27 @@ class AlbaranModel extends \App\Models\BaseModel
|
||||
foreach ($presupuestos as $presupuesto) {
|
||||
|
||||
$envios = $model_presupuesto_direcciones->where('presupuesto_id', $presupuesto->id)->findAll();
|
||||
|
||||
foreach($envios as $envio){
|
||||
|
||||
// se buscan los albaranes en este presupuesto con la misma direccion y con el mismo presupuesto_id en albaran
|
||||
// en albaran linea para obtener la cantidad total enviada
|
||||
$model_albaran = model('App\Models\Pedidos\AlbaranModel');
|
||||
$model_albaran_linea = model('App\Models\Pedidos\AlbaranLineaModel');
|
||||
$albaranes = $model_albaran->where('presupuesto_id', $presupuesto->id)
|
||||
->where('presupuesto_direccion_id', $envio->id)->findAll();
|
||||
// se suman las cantidades de los albaranes
|
||||
$cantidad_enviada = 0;
|
||||
foreach($albaranes as $albaran){
|
||||
$lineas = $model_albaran_linea->where('albaran_id', $albaran->id)->findAll();
|
||||
foreach($lineas as $linea){
|
||||
$cantidad_enviada += $linea->cantidad;
|
||||
}
|
||||
}
|
||||
|
||||
if($cantidad_enviada >= intval($envio->cantidad)){
|
||||
continue;
|
||||
}
|
||||
// calculo precio_unidad
|
||||
$precio_unidad = $presupuesto->total_aceptado/$presupuesto->tirada;
|
||||
|
||||
@ -64,9 +83,9 @@ class AlbaranModel extends \App\Models\BaseModel
|
||||
'titulo' => $presupuesto->titulo,
|
||||
'isbn' => $presupuesto->isbn,
|
||||
'ref_cliente' => $presupuesto->ref_cliente,
|
||||
'cantidad' => $envio->cantidad,
|
||||
'cantidad' => intval($envio->cantidad)-$cantidad_enviada,
|
||||
'cajas' => 1,
|
||||
'ejemplares_por_caja' => $envio->cantidad,
|
||||
'ejemplares_por_caja' => intval($envio->cantidad)-$cantidad_enviada,
|
||||
'precio_unidad' => $precio_unidad,
|
||||
'total' => $precio_unidad * $envio->cantidad,
|
||||
'user_created_id' => $user_id,
|
||||
|
||||
@ -449,31 +449,6 @@ function generarAlbaran(item){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$(document).on('change', '#tablaAlbaran' + item.albaran.id + ' .cantidad-albaran', function(){
|
||||
|
||||
let table = $('#tablaAlbaran' + item.albaran.id).DataTable();
|
||||
let row = $(this).closest('tr'); // Encuentra la fila actual
|
||||
let rowIndex = table.row(row).index(); // Obtiene el índice de la fila
|
||||
|
||||
const previousValue = table.cell(rowIndex, 2).data();
|
||||
const newValue = parseInt($(this).val()); // Obtiene el nuevo valor del input
|
||||
|
||||
let cantidad = calcular_cantidad_albaranes();
|
||||
|
||||
if(cantidad-previousValue+newValue <= parseInt($('#total_tirada').val()) ){
|
||||
// Actualiza el DataTable
|
||||
table.cell(rowIndex, 2).data(newValue);
|
||||
const cajas = parseInt(table.cell(rowIndex, 6).data());
|
||||
table.cell(rowIndex, 7).data(parseInt(newValue/cajas));
|
||||
cambios_cantidad_albaranes();
|
||||
}
|
||||
else{
|
||||
$(this).val(previousValue);
|
||||
table.cell(rowIndex, 7).data(previousValue);
|
||||
table.draw();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on('click', '.accordion-button', function(){
|
||||
@ -575,6 +550,35 @@ $(document).on('change', '.albaran_linea', function(){
|
||||
|
||||
var elementId = $(this).attr('id');
|
||||
|
||||
if(elementId.includes('cantidad')){
|
||||
const item_id = elementId.split('_').slice(-1)[0];
|
||||
let table = $(this).closest('table').DataTable(); // Obtiene la tabla DataTable
|
||||
let row = $(this).closest('tr'); // Encuentra la fila actual
|
||||
let rowIndex = table.row(row).index(); // Obtiene el índice de la fila
|
||||
|
||||
const previousValue = table.cell(rowIndex, 2).data();
|
||||
const newValue = parseInt($(this).val()); // Obtiene el nuevo valor del input
|
||||
|
||||
let cantidad = calcular_cantidad_albaranes();
|
||||
|
||||
if(cantidad-previousValue+newValue <= parseInt($('#total_tirada').val()) ){
|
||||
// Actualiza el DataTable
|
||||
table.cell(rowIndex, 2).data(newValue);
|
||||
const cajas = parseInt(table.cell(rowIndex, 6).data());
|
||||
table.cell(rowIndex, 7).data(parseInt(newValue/cajas));
|
||||
table.cell(rowIndex, 9).data(parseFloat(parseFloat(table.cell(rowIndex, 8).data()) * newValue).toFixed(2));
|
||||
$('#ejemplares_por_caja_' + item_id).val(parseInt(newValue/cajas)).trigger('change');
|
||||
$('#total_' + item_id).val(parseFloat((table.cell(rowIndex, 8).data()) * newValue).toFixed(2)).trigger('change');
|
||||
cambios_cantidad_albaranes();
|
||||
table.draw();
|
||||
}
|
||||
else{
|
||||
$(this).val(previousValue);
|
||||
table.cell(rowIndex, 7).data(previousValue);
|
||||
table.draw();
|
||||
}
|
||||
}
|
||||
|
||||
data = {
|
||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
||||
};
|
||||
@ -771,10 +775,12 @@ function check_cantidad_albaranes(unidades_albaranes){
|
||||
html('<?= lang('Pedidos.validation.errorCantidadAlbaranes') ?>'
|
||||
.replace('{0}', unidades_albaranes)
|
||||
.replace('{1}', $('#total_tirada').val()));
|
||||
$('#generar_albaranes').removeClass('d-none');
|
||||
}
|
||||
else{
|
||||
$('#alert-albaranes').addClass('d-none');
|
||||
$('#error-albaranes').html('');
|
||||
$('#generar_albaranes').addClass('d-none');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user