mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando boton ver pedido
This commit is contained in:
@ -659,6 +659,8 @@ $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']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -318,55 +318,61 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
$model_pedido_linea = model('\App\Models\Pedidos\PedidoLineaModel');
|
||||
$model_presupuesto = model('\App\Models\Pedidos\PedidoLineaModel');
|
||||
$model_presupuesto = model('\App\Models\Presupuestos\PresupuestoModel');
|
||||
$model_factura_linea = model('\App\Models\Facturas\FacturaLineaModel');
|
||||
|
||||
$pedido_linea_id = $this->request->getPost('lineaPedido') ?? 0;
|
||||
$linea = $model_pedido_linea->find($pedido_linea_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;
|
||||
try{
|
||||
$pedido_linea_id = $this->request->getPost('lineaPedido') ?? 0;
|
||||
$linea = $model_pedido_linea->find($pedido_linea_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;
|
||||
|
||||
$data = (object)[
|
||||
'factura_id'=>$factura_id,
|
||||
'pedido_linea_impresion_id'=>$linea->pedido_linea_impresion_id,
|
||||
'descripcion'=>$descripcion,
|
||||
'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,
|
||||
];
|
||||
|
||||
$model_factura_linea->insert($data);
|
||||
|
||||
$id = $model_factura_linea->getInsertID();
|
||||
|
||||
if($id){
|
||||
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception $e){
|
||||
|
||||
}
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
@ -42,4 +42,36 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function deleteLinea($factura_linea_id = 0){
|
||||
|
||||
if (!empty(static::$pluralObjectNameCc) && !empty(static::$singularObjectNameCc)) {
|
||||
$objName = mb_strtolower(lang(ucfirst(static::$pluralObjectNameCc).'.'.static::$singularObjectNameCc));
|
||||
} else {
|
||||
$objName = lang('Basic.global.record');
|
||||
}
|
||||
|
||||
if($factura_linea_id == 0){
|
||||
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
|
||||
}
|
||||
|
||||
$facturaLinea = $this->model->find($factura_linea_id);
|
||||
if($facturaLinea == null){
|
||||
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
|
||||
}
|
||||
|
||||
if($facturaLinea->pedido_linea_impresion_id != null){
|
||||
$this->model->deleteFacturasLineasPedido($facturaLinea->factura_id, $facturaLinea->pedido_linea_impresion_id, $facturaLinea->cantidad);
|
||||
}
|
||||
|
||||
if($facturaLinea->pedido_maquetacion_id != null){
|
||||
//$this->model->deleteFacturasLineasPedido($facturaLinea->factura_id, $facturaLinea->pedido_maquetacion_id, $facturaLinea->cantidad);
|
||||
}
|
||||
|
||||
$facturaLinea = $this->model->delete($factura_linea_id);
|
||||
$message = lang('Basic.global.deleteSuccess', [lang('Basic.global.record')]);
|
||||
$response = $this->respondDeleted(['id' => $factura_linea_id, 'msg' => $message]);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,7 @@ class FacturaLineaEntity extends \CodeIgniter\Entity\Entity
|
||||
'total' => null,
|
||||
'data' => null,
|
||||
'deleted_at' => null,
|
||||
'user_update_id' => null,
|
||||
'user_updated_id' => null,
|
||||
|
||||
];
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
'total',
|
||||
'data',
|
||||
'deleted_at',
|
||||
'user_update_id'
|
||||
'user_updated_id'
|
||||
];
|
||||
|
||||
protected $returnType = "App\Entities\Facturas\FacturaLineaEntity";
|
||||
@ -38,11 +38,32 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
->select(
|
||||
"t1.id AS id, t1.factura_id AS factura_id,
|
||||
t1.pedido_linea_impresion_id AS pedido_linea_impresion_id, t1.pedido_maquetacion_id AS pedido_maquetacion_id,
|
||||
t1.descripcion AS concepto, 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,"
|
||||
t1.descripcion AS concepto, t1.cantidad as unidades, t1.precio_unidad AS precio_unidad, t1.iva AS iva,
|
||||
t1.base AS subtotal, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data,"
|
||||
)
|
||||
->where("t1.factura_id", $factura_id);
|
||||
->where("t1.factura_id", $factura_id)
|
||||
->where("t1.deleted_at", null);
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public function addFacturaPedidoLinea($factura_id, $pedido_linea_id, $cantidad)
|
||||
{
|
||||
$data = [
|
||||
"factura_id" => $factura_id,
|
||||
"pedido_linea_id" => $pedido_linea_id,
|
||||
"cantidad" => $cantidad
|
||||
];
|
||||
|
||||
return $this->db->table("facturas_pedidos_lineas")->insert($data);
|
||||
}
|
||||
|
||||
public function deleteFacturasLineasPedido($factura_id, $pedido_linea_id, $cantidad){
|
||||
|
||||
$this->db->table("facturas_pedidos_lineas")
|
||||
->where("factura_id", $factura_id)
|
||||
->where("pedido_linea_id", $pedido_linea_id)
|
||||
->where("cantidad", $cantidad)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
@ -98,4 +98,5 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
|
||||
return $builder->get()->getRow()->cantidad;
|
||||
}
|
||||
|
||||
}
|
||||
@ -26,20 +26,34 @@
|
||||
|
||||
|
||||
function asyncConfirmDialog(title, msg, yesCallbackFn, noCallbackFn) {
|
||||
var $confirmDialog = $("#modalConfirmYesNo");
|
||||
$confirmDialog.modal('show');
|
||||
$("#labelTitleConfirmDialog").html(title);
|
||||
$("#labelMsgConfirmDialog").html(msg);
|
||||
$("#btnYesConfirmDialog").off('click').click(function () {
|
||||
yesCallbackFn();
|
||||
$confirmDialog.modal("hide");
|
||||
});
|
||||
$("#btnNoConfirmDialog").off('click').click(function () {
|
||||
noCallbackFn();
|
||||
$confirmDialog.modal("hide");
|
||||
});
|
||||
}
|
||||
var $confirmDialog = $("#modalConfirmYesNo");
|
||||
$confirmDialog.modal('show');
|
||||
$("#labelTitleConfirmDialog").html(title);
|
||||
$("#labelMsgConfirmDialog").html(msg);
|
||||
$("#btnYesConfirmDialog").off('click').click(function () {
|
||||
yesCallbackFn();
|
||||
$confirmDialog.modal("hide");
|
||||
});
|
||||
$("#btnNoConfirmDialog").off('click').click(function () {
|
||||
noCallbackFn();
|
||||
$confirmDialog.modal("hide");
|
||||
});
|
||||
}
|
||||
|
||||
function asyncConfirmDialogWithParams(title, msg, yesCallbackFn, noCallbackFn, params) {
|
||||
var $confirmDialog = $("#modalConfirmYesNo");
|
||||
$confirmDialog.modal('show');
|
||||
$("#labelTitleConfirmDialog").html(title);
|
||||
$("#labelMsgConfirmDialog").html(msg);
|
||||
$("#btnYesConfirmDialog").off('click').click(function () {
|
||||
yesCallbackFn(params);
|
||||
$confirmDialog.modal("hide");
|
||||
});
|
||||
$("#btnNoConfirmDialog").off('click').click(function () {
|
||||
noCallbackFn(params);
|
||||
$confirmDialog.modal("hide");
|
||||
});
|
||||
}
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
|
||||
|
||||
@ -116,7 +116,13 @@ $('#addNewPedidoImpresion').on('click', function(){
|
||||
},
|
||||
success: function(response) {
|
||||
yeniden(response.<?= csrf_token() ?>);
|
||||
$('#lineaPedido').val(null).trigger('change');
|
||||
$('#pedidoImpresion').val(null).trigger('change');
|
||||
// Se actualiza la tabla de lineas de factura
|
||||
$('#tableOfLineasFactura').DataTable().clearPipeline();
|
||||
$('#tableOfLineasFactura').DataTable().ajax.reload();
|
||||
// se ajustan el ancho de las columnas
|
||||
$('#tableOfLineasFactura').DataTable().columns.adjust().draw();
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -52,9 +52,14 @@
|
||||
const actionBtns = function(data) {
|
||||
return `
|
||||
<td class="text-right py-0 align-middle">
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-edit mx-2" data-id="${data.id}"></i></a>
|
||||
<a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a>
|
||||
<div class="row mb-2">
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}"></i></a>
|
||||
<a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button type="button" class="btn btn-sm btn-primary btn-view_pedido" data-id="${data.pedido_linea_impresion_id}">Ver pedido</button>
|
||||
</div>
|
||||
</td>`;
|
||||
};
|
||||
@ -160,5 +165,43 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
||||
});
|
||||
|
||||
|
||||
// Delete row
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
//$(".btn-remove").attr('data-id', $(this).attr('data-id'));
|
||||
const dataId = $(this).attr('data-id');
|
||||
const row = $(this).closest('tr');
|
||||
if ($.isNumeric(dataId)) {
|
||||
asyncConfirmDialogWithParams(
|
||||
"Borrar Linea de Factura",
|
||||
"¿Está seguro de borrar la línea? Esta acción no se puede deshacer.",
|
||||
deleteConfirmed, null, [dataId, row])
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function deleteConfirmed(params){
|
||||
var factura_linea_id = params[0];
|
||||
var row = params[1];
|
||||
var url = '<?= route_to('deleteLineaFactura', ':id') ?>';
|
||||
url = url.replace(':id', factura_linea_id );
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'GET',
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
$('#tableOfLineasFactura').DataTable().clearPipeline();
|
||||
$('#tableOfLineasFactura').DataTable().row($(row)).invalidate().draw();
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
popErrorAlert(jqXHR.responseJSON.messages.error)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
$('.btn-view_pedido').on('click', function(e){
|
||||
var pedido_linea_id = $(this).data('id');
|
||||
var url = '<?= route_to('viewPedidoImpresion', ':id') ?>';
|
||||
url = url.replace(':id', pedido_linea_id );
|
||||
window.open(url, '_blank');
|
||||
});
|
||||
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
@ -34,6 +34,8 @@
|
||||
</form>
|
||||
</div><!-- //.card -->
|
||||
</div><!--//.col -->
|
||||
|
||||
<?= view("themes/_commonPartialsBs/_modalConfirmDialog") ?>
|
||||
|
||||
</div><!--//.row -->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user