mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
falta boton excedentes
This commit is contained in:
@ -669,7 +669,6 @@ $routes->group('facturas', ['namespace' => 'App\Controllers\Facturacion'], funct
|
||||
$routes->post('datatable/(:any)', 'FacturasLineas::datatable/$1', ['as' => 'dataTableOfLineasFacturas']);
|
||||
$routes->post('menuPedidosPendientes/(:num)', 'Facturas::menuPedidosPendientes/$1', ['as' => 'menuPedidosPendientesImpresion']);
|
||||
$routes->post('addLineaPedidoImpresion/(:num)', 'Facturas::addLineaPedidoImpresion/$1', ['as' => 'addLineaPedidoImpresion2Factura']);
|
||||
$routes->post('addLineaPedidoImpresion/(:num)', 'Facturas::addLineaPedidoImpresion/$1', ['as' => 'addLineaPedidoImpresion2Factura']);
|
||||
$routes->get('deleteLinea/(:any)', 'FacturasLineas::deleteLinea/$1', ['as' => 'deleteLineaFactura']);
|
||||
$routes->get('delete/(:any)', 'Facturas::delete/$1', ['as' => 'borrarFactura']);
|
||||
$routes->post('deleteFacturaLineaPedido', 'Facturas::deleteLineaPedidoImpresion', ['as' => 'deleteLineaPedidoImpresion']);
|
||||
|
||||
@ -392,13 +392,16 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$pendiente = $postData['pendiente'] ?? 0;
|
||||
$total = $postData['total'] ?? 0;
|
||||
|
||||
$data = [
|
||||
'base' => $postData['base'] ?? 0,
|
||||
'total' => $postData['total'] ?? 0,
|
||||
'pendiente' => $postData['pendiente'] ?? 0,
|
||||
'total' => $total,
|
||||
'pendiente' => $pendiente,
|
||||
'total_pagos' => $postData['total_pagos'] ?? 0,
|
||||
'user_updated_id' => auth()->user()->id,
|
||||
'estado_pago' => (intval($postData['pendiente'] ?? 0)==0) ? 'pagada' : 'pendiente',
|
||||
'estado_pago' => (intval($pendiente)==0 && intval($total)!=0) ? 'pagada' : 'pendiente',
|
||||
];
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
@ -433,48 +436,55 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
try{
|
||||
$pedido_linea_id = $this->request->getPost('lineaPedido') ?? 0;
|
||||
$linea = $model_pedido_linea->find($pedido_linea_id);
|
||||
|
||||
$factura = $this->model->find($factura_id);
|
||||
|
||||
if($linea){
|
||||
$presupuesto = $model_presupuesto->find($linea->presupuesto_id);
|
||||
if($presupuesto){
|
||||
// Se añade la linea de factura
|
||||
$descripcion = $model_presupuesto->generarLineaPedido($presupuesto->id, true, $linea->pedido_id);
|
||||
$cantidad = intval($presupuesto->tirada) - intval($this->model->getCantidadLineaPedidoFacturada($linea->id));
|
||||
$base = $cantidad * floatval($presupuesto->total_precio_unidad);
|
||||
$total_iva = $base * ($presupuesto->iva_reducido==1 ? 0.04 : 0.21);
|
||||
// se redondea a dos decimales
|
||||
$total_iva = round($total_iva, 2);
|
||||
$total = $base + $total_iva;
|
||||
if($factura){
|
||||
|
||||
$data = (object)[
|
||||
'factura_id'=>$factura_id,
|
||||
'pedido_linea_impresion_id'=>$linea->pedido_id,
|
||||
'descripcion'=>$descripcion[0]->concepto,
|
||||
'cantidad'=>$cantidad,
|
||||
'precio_unidad'=>$presupuesto->total_precio_unidad,
|
||||
'iva' => $presupuesto->iva_reducido==1 ? 4 : 21,
|
||||
'base' => $base,
|
||||
'total_iva' => $total_iva,
|
||||
'total' => $total,
|
||||
'user_updated_id' => auth()->user()->id,
|
||||
];
|
||||
if($linea){
|
||||
$presupuesto = $model_presupuesto->find($linea->presupuesto_id);
|
||||
|
||||
$model_factura_linea->insert($data);
|
||||
if($presupuesto){
|
||||
// Se añade la linea de factura
|
||||
$descripcion = $model_presupuesto->generarLineaPedido($presupuesto->id, true, $linea->pedido_id);
|
||||
$cantidad = intval($presupuesto->tirada) - intval($this->model->getCantidadLineaPedidoFacturada($linea->id));
|
||||
$base = $cantidad * floatval($presupuesto->total_precio_unidad);
|
||||
$base = round($base, 2);
|
||||
$total_iva = $base * ($presupuesto->iva_reducido==1 ? 0.04 : 0.21);
|
||||
// se redondea a dos decimales
|
||||
$total_iva = round($total_iva, 2);
|
||||
$total = $base + $total_iva;
|
||||
|
||||
$id = $model_factura_linea->getInsertID();
|
||||
|
||||
if($id){
|
||||
|
||||
$model_factura_linea->addFacturaPedidoLinea($factura_id, $linea->id, $cantidad);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'error' => 0,
|
||||
'id' => $id,
|
||||
$csrfTokenName => $newTokenHash
|
||||
$data = (object)[
|
||||
'factura_id'=>$factura_id,
|
||||
'pedido_linea_impresion_id'=>$linea->pedido_id,
|
||||
'descripcion'=>$descripcion[0]->concepto,
|
||||
'cantidad'=>$cantidad,
|
||||
'precio_unidad'=>$presupuesto->total_precio_unidad,
|
||||
'iva' => $presupuesto->iva_reducido==1 ? 4 : 21,
|
||||
'base' => $base,
|
||||
'total_iva' => $total_iva,
|
||||
'total' => $total,
|
||||
'user_updated_id' => auth()->user()->id,
|
||||
];
|
||||
return $this->respond($data);
|
||||
|
||||
$model_factura_linea->insert($data);
|
||||
|
||||
$id = $model_factura_linea->getInsertID();
|
||||
|
||||
if($id){
|
||||
|
||||
$model_factura_linea->addFacturaPedidoLinea($factura_id, $linea->id, $cantidad);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'error' => 0,
|
||||
'id' => $id,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1073,14 +1073,12 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
try {
|
||||
$return_data = [];
|
||||
|
||||
if ($extra_info) {
|
||||
$info = [
|
||||
'merma' => 0,
|
||||
'lomo_cubierta' => 0.0,
|
||||
'lomo_sobrecubierta' => 0.0,
|
||||
'user_id' => auth()->user()->id,
|
||||
];
|
||||
}
|
||||
$info = [
|
||||
'merma' => 0,
|
||||
'lomo_cubierta' => 0.0,
|
||||
'lomo_sobrecubierta' => 0.0,
|
||||
'user_id' => auth()->user()->id,
|
||||
];
|
||||
|
||||
$tirada = $datos_entrada['tirada'];
|
||||
$tamanio = $datos_entrada['tamanio'];
|
||||
@ -1568,11 +1566,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
));
|
||||
}
|
||||
|
||||
$info['lomo_cubierta'] = $lomo;
|
||||
$info['lomo_sobrecubierta'] = $lomo_sobrecubierta;
|
||||
$return_data['info'] = $info;
|
||||
|
||||
|
||||
if ($extra_info) { // && $tirada[$t] == $selected_tirada) {
|
||||
|
||||
$info['lomo_cubierta'] = $lomo;
|
||||
$info['lomo_sobrecubierta'] = $lomo_sobrecubierta;
|
||||
$return_data['info'] = $info;
|
||||
$return_data['info']['interior'] = $interior;
|
||||
$return_data['info']['cubierta'] = $cubierta;
|
||||
$return_data['info']['sobrecubierta'] = $linea_sobrecubierta;
|
||||
|
||||
@ -40,10 +40,14 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
t1.pedido_linea_impresion_id AS pedido_linea_impresion_id, t1.pedido_maquetacion_id AS pedido_maquetacion_id,
|
||||
t1.descripcion AS descripcion, t1.cantidad as cantidad, t1.precio_unidad AS precio_unidad, t1.iva AS iva,
|
||||
t1.base AS base, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data, t2.pedido_id AS pedido_id,
|
||||
t3.total_aceptado AS total_aceptado"
|
||||
t3.total_aceptado AS total_aceptado, t4.tirada_flexible AS tirada_flexible, t4.descuento_tirada_flexible AS descuento_tirada_flexible,
|
||||
t6.cantidad AS cantidad_albaran"
|
||||
)
|
||||
->join("pedidos_linea t2", "t2.id = t1.pedido_linea_impresion_id", "left")
|
||||
->join("presupuestos t3", "t3.id = t2.presupuesto_id", "left")
|
||||
->join("clientes t4", "t4.id = t3.cliente_id", "left")
|
||||
->join("albaranes t5", "t5.pedido_id = t2.pedido_id", "left")
|
||||
->join("albaranes_lineas t6", "t6.albaran_id = t5.id", "left")
|
||||
->where("t1.factura_id", $factura_id)
|
||||
->where("t1.deleted_at", null);
|
||||
|
||||
|
||||
@ -118,11 +118,10 @@ $('#addNewPedidoImpresion').on('click', function(){
|
||||
yeniden(response.<?= csrf_token() ?>);
|
||||
|
||||
// se ajustan el ancho de las columnas
|
||||
$('#tableOfLineasFactura').DataTable().columns.adjust().draw();
|
||||
$('#pedidoImpresion').val(null).trigger('change');
|
||||
// Se actualiza la tabla de lineas de factura
|
||||
tableLineas.clearPipeline();
|
||||
tableLineas.draw();
|
||||
$('#tableOfLineasFactura').DataTable().columns.adjust().draw();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -255,7 +255,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
||||
error_text = 'El total del pedido ('+ total_aceptado + '€) no coincide con la línea ('+ subtotal + '€)';
|
||||
}
|
||||
|
||||
return `
|
||||
var returned_data = `
|
||||
<div>
|
||||
${data}
|
||||
</div>
|
||||
@ -265,11 +265,55 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
||||
<span style="color: red;" id="error-${meta.row}">${error_text}</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-2">
|
||||
<label for="input-${meta.row}">Total aceptado</label>
|
||||
<input readonly type="text" id="input-${meta.row}" value="${row.total_aceptado}">
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div style="margin-top: auto;" class="col-md-12 col-lg-2 px-4">
|
||||
<label for="total-aceptado_-${meta.row}">Total aceptado</label>
|
||||
<input readonly style="max-width: 110px;" type="text" id="total-aceptado_${meta.row}" value="${row.total_aceptado}">
|
||||
</div>
|
||||
`;
|
||||
|
||||
if (row.tirada_flexible === "1"){
|
||||
returned_data += `
|
||||
<div style="margin-top: auto;" class="col-md-12 col-lg-2 px-4">
|
||||
<label for="descuento-tf_${meta.row}">Descuento tirada flexible</label>
|
||||
<input readonly style="max-width: 110px;" type="text" id="descuento-tf_${meta.row}" value="${row.descuento_tirada_flexible}">
|
||||
</div>
|
||||
<div style="margin-top: auto;" class="col-md-12 col-lg-2 px-4">
|
||||
<label for="tirada-albaran_${meta.row}">Tirada albarán</label>
|
||||
<input readonly style="max-width: 110px;" type="text" id="tirada-albaran_${meta.row}" value="${row.cantidad_albaran}">
|
||||
</div>
|
||||
`;
|
||||
if(row.cantidad<row.cantidad_albaran){
|
||||
returned_data += `
|
||||
|
||||
<div style="margin-top: auto;" class="col-md-12 col-lg-2 px-4">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-label-primary float-start me-sm-3 me-1 btn-excedentes"
|
||||
name="btn-excedentes_${meta.row}"
|
||||
id="btn-excedentes_${meta.row}"
|
||||
data-row="${meta.row}"
|
||||
>
|
||||
<span class="ti-xs ti ti-circle-plus me-1"></span>
|
||||
Excedentes
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
else{
|
||||
returned_data += `
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
else{
|
||||
returned_data += `
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
return returned_data;
|
||||
}
|
||||
else{
|
||||
return `
|
||||
@ -397,12 +441,12 @@ $(document).on('click', '.btn-delete', function(e) {
|
||||
asyncConfirmDialogWithParams(
|
||||
"Borrar Linea de Factura",
|
||||
"¿Está seguro de borrar la línea? Esta acción no se puede deshacer.",
|
||||
deleteConfirmed, function(){}, [dataId, row])
|
||||
deleteConfirmedLinea, function(){}, [dataId, row])
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function deleteConfirmed(params){
|
||||
function deleteConfirmedLinea(params){
|
||||
var factura_linea_id = params[0];
|
||||
var row = params[1];
|
||||
const row_data = tableLineas.row($(row)).data();
|
||||
@ -456,5 +500,18 @@ $('#addLineaFactura').on('click', function() {
|
||||
editor_lineas.inlineCreate('end', formOptions);
|
||||
});
|
||||
|
||||
$('.btn-excedentes').on('click', function() {
|
||||
const row = $(this).data('row');
|
||||
console.row(row);
|
||||
/*
|
||||
const row_data = tableLineas.row(row).data();
|
||||
const url = '<?= route_to('excedentes') ?>';
|
||||
const formOptions= {
|
||||
submitTrigger: 0,
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
|
||||
};
|
||||
editor_lineas.inlineCreate('end', formOptions);
|
||||
*/
|
||||
});
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
Reference in New Issue
Block a user