mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminado tirada flexible
This commit is contained in:
@ -669,6 +669,7 @@ $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('addExcedentes/(:any)', 'Facturas::addExcedentes/$1', ['as' => 'addLineaExcedentes']);
|
||||
$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']);
|
||||
|
||||
@ -425,6 +425,54 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
public function addExcedentes($factura_id){
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
$model_factura_linea = model('\App\Models\Facturas\FacturaLineaModel');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$cantidad = $postData['cantidad'] ?? 0;
|
||||
$precio_unidad = $postData['precio_unidad'] ?? 0;
|
||||
$iva = $postData['iva'] ?? 0;
|
||||
$descripcion = $postData['descripcion'] ?? '';
|
||||
$descuento = $postData['descuento'] ?? 0;
|
||||
$pedido_linea_impresion_id = $postData['pedido_linea_impresion_id'] ?? null;
|
||||
$pedido_linea_maquetacion_id = $postData['pedido_linea_maquetacion_id'] ?? null;
|
||||
$pedido_id = $postData['pedido_id'] ?? 0;
|
||||
|
||||
$nuevo_precio_unidad = round($precio_unidad*(100-floatval($descuento))/100, 4);
|
||||
$base = round($cantidad * $nuevo_precio_unidad, 2);
|
||||
$total_iva = round($base * $iva / 100, 2);
|
||||
|
||||
$data = (object)[
|
||||
'factura_id'=>$factura_id,
|
||||
'pedido_linea_impresion_id'=>$pedido_linea_impresion_id,
|
||||
'pedido_linea_maquetacion_id'=>$pedido_linea_maquetacion_id,
|
||||
'descripcion'=>$newString = preg_replace_callback('/Impresión de (\d+) ejemplares/', function ($matches) use ($cantidad) {
|
||||
return 'Impresión de ' . $cantidad . ' ejemplares';
|
||||
}, $descripcion),
|
||||
'cantidad'=>$cantidad,
|
||||
'precio_unidad'=> $nuevo_precio_unidad,
|
||||
'iva' => $iva,
|
||||
'base' => $base,
|
||||
'total_iva' => $total_iva,
|
||||
'total' => round($base + $total_iva, 2),
|
||||
'user_updated_id' => auth()->user()->id,
|
||||
];
|
||||
|
||||
$model_factura_linea->insert($data);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data_ret = [
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data_ret);
|
||||
}
|
||||
else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function addLineaPedidoImpresion($factura_id){
|
||||
|
||||
|
||||
@ -416,7 +416,8 @@ function updateFooterLineas(table){
|
||||
base: totalSubtotal,
|
||||
total: totalTotal,
|
||||
total_pagos: total_pagos,
|
||||
pendiente: pendientePago
|
||||
pendiente: pendientePago,
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
||||
}
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
if(data.estado_pago == 'pagada'){
|
||||
@ -459,7 +460,8 @@ function deleteConfirmedLinea(params){
|
||||
data: {
|
||||
factura_id: <?= $facturaEntity->id ?>,
|
||||
pedido_linea_impresion_id: row_data.pedido_linea_impresion_id,
|
||||
cantidad: row_data.cantidad
|
||||
cantidad: row_data.cantidad,
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
||||
}
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
|
||||
@ -500,18 +502,48 @@ $('#addLineaFactura').on('click', function() {
|
||||
editor_lineas.inlineCreate('end', formOptions);
|
||||
});
|
||||
|
||||
$('.btn-excedentes').on('click', function() {
|
||||
|
||||
$(document).on('click', '.btn-excedentes', function(e) {
|
||||
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);
|
||||
*/
|
||||
|
||||
const pedido_id = row_data.pedido_id;
|
||||
|
||||
var pedido_linea_impresion_id = null;
|
||||
var pedido_linea_maquetacion_id = null;
|
||||
|
||||
if(row_data.pedido_linea_impresion_id != null){
|
||||
pedido_linea_impresion_id = row_data.pedido_linea_impresion_id
|
||||
}
|
||||
else{
|
||||
pedido_linea_maquetacion_id = row_data.pedido_maquetacion_id
|
||||
}
|
||||
|
||||
var factura_id = <?= $facturaEntity->id ?>;
|
||||
|
||||
var url = '<?= route_to('addLineaExcedentes', ':factura_id') ?>';
|
||||
url = url.replace(':factura_id', factura_id );
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'POST',
|
||||
data: {
|
||||
pedido_id: pedido_id,
|
||||
pedido_linea_impresion_id: pedido_linea_impresion_id,
|
||||
pedido_linea_maquetacion_id: pedido_linea_maquetacion_id,
|
||||
precio_unidad: row_data.precio_unidad,
|
||||
descripcion: row_data.descripcion,
|
||||
iva: row_data.iva,
|
||||
descuento: row_data.descuento_tirada_flexible,
|
||||
cantidad: parseInt(row_data.cantidad_albaran)-parseInt(row_data.cantidad),
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
||||
}
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
$('#tableOfLineasFactura').DataTable().clearPipeline();
|
||||
$('#tableOfLineasFactura').DataTable().draw();
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
popErrorAlert(jqXHR.responseJSON.messages.error)
|
||||
})
|
||||
});
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
Reference in New Issue
Block a user