mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
falta autonumeric
This commit is contained in:
@ -692,7 +692,9 @@ class Facturas extends \App\Controllers\BaseResourceController
|
|||||||
// Se añade la linea de factura
|
// Se añade la linea de factura
|
||||||
$descripcion = $model_presupuesto->generarLineaPedido($presupuesto->id, true, $linea->pedido_id);
|
$descripcion = $model_presupuesto->generarLineaPedido($presupuesto->id, true, $linea->pedido_id);
|
||||||
$cantidad = intval($presupuesto->tirada) - intval($model_factura->getCantidadLineaPedidoFacturada($linea->id));
|
$cantidad = intval($presupuesto->tirada) - intval($model_factura->getCantidadLineaPedidoFacturada($linea->id));
|
||||||
$base = $cantidad * floatval($presupuesto->total_precio_unidad);
|
$base =
|
||||||
|
floatval($presupuesto->total_aceptado_revisado && $presupuesto->total_aceptado_revisado != 0 ?
|
||||||
|
$presupuesto->total_aceptado_revisado : $presupuesto->total_aceptado);
|
||||||
$base = round($base, 2);
|
$base = round($base, 2);
|
||||||
$total_iva = $base * ($presupuesto->iva_reducido == 1 ? 0.04 : 0.21);
|
$total_iva = $base * ($presupuesto->iva_reducido == 1 ? 0.04 : 0.21);
|
||||||
// se redondea a dos decimales
|
// se redondea a dos decimales
|
||||||
@ -704,7 +706,6 @@ class Facturas extends \App\Controllers\BaseResourceController
|
|||||||
'pedido_linea_impresion_id' => $linea->pedido_id,
|
'pedido_linea_impresion_id' => $linea->pedido_id,
|
||||||
'descripcion' => $descripcion[0]->concepto,
|
'descripcion' => $descripcion[0]->concepto,
|
||||||
'cantidad' => $cantidad,
|
'cantidad' => $cantidad,
|
||||||
'precio_unidad' => $presupuesto->total_precio_unidad,
|
|
||||||
'iva' => $presupuesto->iva_reducido == 1 ? 4 : 21,
|
'iva' => $presupuesto->iva_reducido == 1 ? 4 : 21,
|
||||||
'base' => $base,
|
'base' => $base,
|
||||||
'total_iva' => $total_iva,
|
'total_iva' => $total_iva,
|
||||||
|
|||||||
@ -101,15 +101,6 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
|||||||
->validator('Validate::notEmpty', array(
|
->validator('Validate::notEmpty', array(
|
||||||
'message' => lang('Facturas.validation.requerido'))
|
'message' => lang('Facturas.validation.requerido'))
|
||||||
),
|
),
|
||||||
Field::inst( 'precio_unidad' )
|
|
||||||
->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar')
|
|
||||||
->validator('Validate::numeric', array(
|
|
||||||
"decimal" => ',',
|
|
||||||
'message' => lang('Facturas.validation.decimal'))
|
|
||||||
)
|
|
||||||
->validator('Validate::notEmpty', array(
|
|
||||||
'message' => lang('Facturas.validation.requerido'))
|
|
||||||
),
|
|
||||||
Field::inst( 'iva' )
|
Field::inst( 'iva' )
|
||||||
->validator('Validate::numeric', array(
|
->validator('Validate::numeric', array(
|
||||||
'message' => lang('Facturas.validation.numerico'))
|
'message' => lang('Facturas.validation.numerico'))
|
||||||
@ -128,7 +119,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
|||||||
$totales = $this->generate_totales(
|
$totales = $this->generate_totales(
|
||||||
$values['factura_id'],
|
$values['factura_id'],
|
||||||
$values['pedido_linea_impresion_id'],
|
$values['pedido_linea_impresion_id'],
|
||||||
$values['precio_unidad'],
|
$values['total'],
|
||||||
$values['iva'],
|
$values['iva'],
|
||||||
$values['cantidad'],
|
$values['cantidad'],
|
||||||
$values['old_cantidad']);
|
$values['old_cantidad']);
|
||||||
@ -152,7 +143,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
|||||||
$totales = $this->generate_totales(
|
$totales = $this->generate_totales(
|
||||||
$values['factura_id'],
|
$values['factura_id'],
|
||||||
$values['pedido_linea_impresion_id'],
|
$values['pedido_linea_impresion_id'],
|
||||||
$values['precio_unidad'],
|
$values['total'],
|
||||||
$values['iva'],
|
$values['iva'],
|
||||||
$values['cantidad'],
|
$values['cantidad'],
|
||||||
$values['old_cantidad']);
|
$values['old_cantidad']);
|
||||||
@ -203,7 +194,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
|||||||
$model->updateTotales($factura_id);
|
$model->updateTotales($factura_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generate_totales($factura_id, $pedido_linea_id, $precio_unidad, $iva, $cantidad, $old_cantidad)
|
private function generate_totales($factura_id, $pedido_linea_id, $total, $iva, $cantidad, $old_cantidad)
|
||||||
{
|
{
|
||||||
|
|
||||||
// si es una linea que se refiere a pedido
|
// si es una linea que se refiere a pedido
|
||||||
@ -214,6 +205,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
|||||||
|
|
||||||
// se calcula y se actualiza el subtotal, total_iva y total
|
// se calcula y se actualiza el subtotal, total_iva y total
|
||||||
// redondeando a 4 decimales el precio_unidad y a dos el resto
|
// redondeando a 4 decimales el precio_unidad y a dos el resto
|
||||||
|
$precio_unidad = round($total / $old_cantidad, 4);
|
||||||
$base = round($precio_unidad * $cantidad, 2);
|
$base = round($precio_unidad * $cantidad, 2);
|
||||||
$total_iva = round($base * $iva / 100, 2);
|
$total_iva = round($base * $iva / 100, 2);
|
||||||
$total = round($base + $total_iva, 2);
|
$total = round($base + $total_iva, 2);
|
||||||
|
|||||||
@ -57,10 +57,7 @@ class FacturasPagos extends \App\Controllers\BaseResourceController
|
|||||||
->fields(
|
->fields(
|
||||||
Field::inst( 'id' ),
|
Field::inst( 'id' ),
|
||||||
Field::inst( 'forma_pago_id' ),
|
Field::inst( 'forma_pago_id' ),
|
||||||
Field::inst( 'notes' )
|
Field::inst( 'notes' ),
|
||||||
->validator('Validate::notEmpty', array(
|
|
||||||
'message' => lang('Facturas.validation.requerido'))
|
|
||||||
),
|
|
||||||
Field::inst( 'fecha_pago_at' )
|
Field::inst( 'fecha_pago_at' )
|
||||||
->validator( Validate::dateFormat( 'Y-m-d H:i:s' ) )
|
->validator( Validate::dateFormat( 'Y-m-d H:i:s' ) )
|
||||||
->getFormatter( Format::dateSqlToFormat( 'Y-m-d H:i:s' ) )
|
->getFormatter( Format::dateSqlToFormat( 'Y-m-d H:i:s' ) )
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Database\Migrations;
|
||||||
|
|
||||||
|
use CodeIgniter\Database\Migration;
|
||||||
|
|
||||||
|
class RemovePrecioUnidadFacturas extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$this->forge->dropColumn('facturas_lineas', 'precio_unidad');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$fields = [
|
||||||
|
'precio_unidad' => [
|
||||||
|
'type' => 'DOUBLE',
|
||||||
|
'null' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$this->forge->addColumn('facturas_lineas', $fields);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,7 +12,6 @@ class FacturaLineaEntity extends \CodeIgniter\Entity\Entity
|
|||||||
'pedido_maquetacion_id' => null,
|
'pedido_maquetacion_id' => null,
|
||||||
'descripcion' => null,
|
'descripcion' => null,
|
||||||
'cantidad' => null,
|
'cantidad' => null,
|
||||||
'precio_unidad' => null,
|
|
||||||
'iva' => null,
|
'iva' => null,
|
||||||
'base' => null,
|
'base' => null,
|
||||||
'total_iva' => null,
|
'total_iva' => null,
|
||||||
@ -29,7 +28,6 @@ class FacturaLineaEntity extends \CodeIgniter\Entity\Entity
|
|||||||
'pedido_linea_impresion_id' => 'int',
|
'pedido_linea_impresion_id' => 'int',
|
||||||
'pedido_maquetacion_id' => 'int',
|
'pedido_maquetacion_id' => 'int',
|
||||||
'cantidad' => 'float',
|
'cantidad' => 'float',
|
||||||
'precio_unidad' => 'float',
|
|
||||||
'iva' => 'float',
|
'iva' => 'float',
|
||||||
'base' => 'float',
|
'base' => 'float',
|
||||||
'total_iva' => 'float',
|
'total_iva' => 'float',
|
||||||
|
|||||||
@ -14,7 +14,6 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
|||||||
'pedido_maquetacion_id',
|
'pedido_maquetacion_id',
|
||||||
'descripcion',
|
'descripcion',
|
||||||
'cantidad',
|
'cantidad',
|
||||||
'precio_unidad',
|
|
||||||
'iva',
|
'iva',
|
||||||
'base',
|
'base',
|
||||||
'total_iva',
|
'total_iva',
|
||||||
@ -38,7 +37,7 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
|||||||
->select(
|
->select(
|
||||||
"t1.id AS id, t1.factura_id AS factura_id,
|
"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.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.descripcion AS descripcion, t1.cantidad as cantidad, 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,
|
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, t4.tirada_flexible AS tirada_flexible, t4.descuento_tirada_flexible AS descuento_tirada_flexible,
|
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"
|
t6.cantidad AS cantidad_albaran"
|
||||||
@ -89,7 +88,7 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
|||||||
->select(
|
->select(
|
||||||
"t1.id AS id, t1.factura_id AS factura_id,
|
"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.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.descripcion AS descripcion, t1.cantidad as cantidad, t1.iva AS iva,
|
||||||
t1.base AS base, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data"
|
t1.base AS base, 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)
|
||||||
|
|||||||
@ -20,7 +20,6 @@
|
|||||||
<th ></th>
|
<th ></th>
|
||||||
<th style="width: 10%;"><?= lang('Facturas.unidades') ?></th>
|
<th style="width: 10%;"><?= lang('Facturas.unidades') ?></th>
|
||||||
<th ><?= lang('Facturas.concepto') ?></th>
|
<th ><?= lang('Facturas.concepto') ?></th>
|
||||||
<th style="width: 10%;"><?= lang('Facturas.precioUnidad') ?></th>
|
|
||||||
<th style="width: 10%;"><?= lang('Facturas.iva') ?></th>
|
<th style="width: 10%;"><?= lang('Facturas.iva') ?></th>
|
||||||
<th style="width: 10%;"><?= lang('Facturas.subtotal') ?></th>
|
<th style="width: 10%;"><?= lang('Facturas.subtotal') ?></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
@ -31,25 +30,25 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="9" style="text-align:right">Subtotal:</td>
|
<td colspan="8" style="text-align:right">Subtotal:</td>
|
||||||
<td id="subtotal-sum"></td>
|
<td id="subtotal-sum"></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="9" style="text-align:right">I.V.A.:</td>
|
<td colspan="8" style="text-align:right">I.V.A.:</td>
|
||||||
<td id="total-iva-sum"></td>
|
<td id="total-iva-sum"></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="9" style="text-align:right">Total:</td>
|
<td colspan="8" style="text-align:right">Total:</td>
|
||||||
<td id="total-sum"></td>
|
<td id="total-sum"></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td <?= ($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> colspan="9" style="text-align:right">Pendiente de pago:</td>
|
<td <?= ($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> colspan="8" style="text-align:right">Pendiente de pago:</td>
|
||||||
<td <?= ($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> id="pendiente-pago"></td>
|
<td <?= ($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> id="pendiente-pago"></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
@ -79,56 +78,52 @@
|
|||||||
<?=$this->section('additionalInlineJs') ?>
|
<?=$this->section('additionalInlineJs') ?>
|
||||||
|
|
||||||
const actionBtns = function(data) {
|
const actionBtns = function(data) {
|
||||||
|
<?php if ($facturaEntity->estado != 'borrador') : ?>
|
||||||
// se comprueba si data es null
|
if (data.pedido_id != null) {
|
||||||
<?php if($facturaEntity->estado != 'borrador') :?>
|
return `
|
||||||
if (data.pedido_id != null) {
|
<div class="text-right py-0 align-middle">
|
||||||
return `
|
<div class="row">
|
||||||
<div class="text-right py-0 align-middle">
|
<button type="button" class="btn btn-sm btn-primary btn-view_pedido" data-id="${data.pedido_id}">Ver pedido</button>
|
||||||
<div class="row">
|
</div>
|
||||||
<button type="button" class="btn btn-sm btn-primary btn-view_pedido" data-id="${data.pedido_id}">Ver pedido</button>
|
</div>
|
||||||
</div>
|
`;
|
||||||
</div>
|
} else {
|
||||||
`;
|
return ``;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return ``;
|
|
||||||
}
|
|
||||||
|
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
if (data.pedido_id === null) {
|
if (data.pedido_id === null) {
|
||||||
return `
|
return `
|
||||||
<td class="text-right py-0 align-middle">
|
<div class="text-right py-0 align-middle">
|
||||||
<div class="row mb-2">
|
<div class="row mb-2">
|
||||||
<div class="btn-group btn-group-sm">
|
<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-trash ti-sm btn-delete mx-2" data-id="${data.id}"></i></a>
|
||||||
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
|
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
|
||||||
<span class="cancel"></span>
|
<span class="cancel"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
`;
|
||||||
</td>`;
|
} else {
|
||||||
}
|
return `
|
||||||
else{
|
<div class="text-right py-0 align-middle">
|
||||||
return `
|
<div class="row mb-2 align-middle">
|
||||||
<div class="text-right py-0 align-middle">
|
<div class="btn-group btn-group-sm">
|
||||||
<div class="row mb-2 align-middle">
|
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}"></i></a>
|
||||||
<div class="btn-group btn-group-sm">
|
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
|
||||||
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}"></i></a>
|
<span class="cancel"></span>
|
||||||
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
|
</div>
|
||||||
<span class="cancel"></span>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<button type="button" class="btn btn-sm btn-primary btn-view_pedido" data-id="${data.pedido_id}">Ver pedido</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
`;
|
||||||
<div class="row">
|
}
|
||||||
<button type="button" class="btn btn-sm btn-primary btn-view_pedido" data-id="${data.pedido_id}">Ver pedido</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var editor_lineas = new $.fn.dataTable.Editor( {
|
var editor_lineas = new $.fn.dataTable.Editor( {
|
||||||
ajax: {
|
ajax: {
|
||||||
url: "<?= route_to('editorOfLineasFacturas') ?>",
|
url: "<?= route_to('editorOfLineasFacturas') ?>",
|
||||||
@ -153,14 +148,6 @@ var editor_lineas = new $.fn.dataTable.Editor( {
|
|||||||
rows: 5,
|
rows: 5,
|
||||||
style: "height: 120px;"
|
style: "height: 120px;"
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
name: "precio_unidad",
|
|
||||||
attr: {
|
|
||||||
type: "text",
|
|
||||||
name : "precio_unidad",
|
|
||||||
class :"autonumeric",
|
|
||||||
style: "min-width: 65px;"
|
|
||||||
}
|
|
||||||
}, {
|
}, {
|
||||||
name: "iva",
|
name: "iva",
|
||||||
attr: {
|
attr: {
|
||||||
@ -310,7 +297,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
|||||||
<div class="row mt-2">
|
<div class="row mt-2">
|
||||||
<div style="margin-top: auto;" class="col-md-12 col-lg-2 px-4">
|
<div style="margin-top: auto;" class="col-md-12 col-lg-2 px-4">
|
||||||
<label for="total-aceptado_-${meta.row}">Total aceptado</label>
|
<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}">
|
<input readonly class="autonumeric" style="max-width: 110px;" type="text" id="total-aceptado_${meta.row}" value="${row.total_aceptado}">
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -366,7 +353,6 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{data: "precio_unidad",render : (d) => `<span class="autonumeric">${d}</span>`},
|
|
||||||
{data: "iva",render : (d) => `<span class="autonumeric">${d}</span>`},
|
{data: "iva",render : (d) => `<span class="autonumeric">${d}</span>`},
|
||||||
{data: "base",render : (d) => `<span class="autonumeric">${d}</span>`},
|
{data: "base",render : (d) => `<span class="autonumeric">${d}</span>`},
|
||||||
{data: "total_iva",render : (d) => `<span class="autonumeric">${d}</span>`},
|
{data: "total_iva",render : (d) => `<span class="autonumeric">${d}</span>`},
|
||||||
@ -391,7 +377,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
visible: false,
|
visible: false,
|
||||||
targets: [1, 2, 3, 4, 10, 11]
|
targets: [1, 2, 3, 4, 9, 10]
|
||||||
}
|
}
|
||||||
|
|
||||||
],
|
],
|
||||||
@ -400,85 +386,54 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
|
|||||||
this.api().columns.adjust();
|
this.api().columns.adjust();
|
||||||
},
|
},
|
||||||
footerCallback: function (row, data, start, end, display) {
|
footerCallback: function (row, data, start, end, display) {
|
||||||
updateFooterLineas(this.api());
|
const table = this.api();
|
||||||
|
|
||||||
|
const intVal = i => typeof i === 'string' ? parseFloat(i.replace(/\./g, '').replace(',', '.')) || 0 : i || 0;
|
||||||
|
|
||||||
|
const totalSubtotal = table.column(8).data().reduce((a, b) => intVal(a) + intVal(b), 0);
|
||||||
|
const totalIVA = table.column(9).data().reduce((a, b) => intVal(a) + intVal(b), 0);
|
||||||
|
const totalTotal = table.column(10).data().reduce((a, b) => intVal(a) + intVal(b), 0);
|
||||||
|
|
||||||
|
$('#subtotal-sum').html(totalSubtotal.toFixed(2));
|
||||||
|
$('#total-iva-sum').html(totalIVA.toFixed(2));
|
||||||
|
$('#total-sum').html(totalTotal.toFixed(2));
|
||||||
|
|
||||||
|
<?php if($facturaEntity->estado == 'borrador') :?>
|
||||||
|
var pendientePago = totalTotal;
|
||||||
|
var total_pagos = 0;
|
||||||
|
<?php else: ?>
|
||||||
|
var total_pagos = parseFloat($('#totalCobrado-sum').html().replace(',', '.')) || 0;
|
||||||
|
var pendientePago = totalTotal - total_pagos;
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
if (isNaN(pendientePago)) pendientePago = 0;
|
||||||
|
|
||||||
|
$('#pendiente-pago').html(pendientePago.toFixed(2));
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
base: totalSubtotal,
|
||||||
|
total: totalTotal,
|
||||||
|
total_pagos: total_pagos,
|
||||||
|
pendiente: pendientePago,
|
||||||
|
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
||||||
|
}
|
||||||
|
}).done(function (data) {
|
||||||
|
if (data.estado_pago === 'pagada') {
|
||||||
|
$('#estado_pago_text').text('<?= lang('Facturas.pagada') ?>').css('color', 'green');
|
||||||
|
} else {
|
||||||
|
$('#estado_pago_text').text('<?= lang('Facturas.pendiente') ?>').css('color', 'red');
|
||||||
|
}
|
||||||
|
}).fail(function (jqXHR) {
|
||||||
|
popErrorAlert(jqXHR.responseJSON.messages.error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function updateFooterLineas(table){
|
|
||||||
|
|
||||||
// Remove the formatting to get integer data for summation
|
|
||||||
var intVal = function (i) {
|
|
||||||
return typeof i === 'string' ?
|
|
||||||
i.replace(/[\$,]/g, '')*1 :
|
|
||||||
typeof i === 'number' ?
|
|
||||||
i : 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Total over all pages
|
|
||||||
var totalSubtotal = table
|
|
||||||
.column(9)
|
|
||||||
.data()
|
|
||||||
.reduce(function (a, b) {
|
|
||||||
return intVal(a) + intVal(b);
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
var totalIVA = table
|
|
||||||
.column(10)
|
|
||||||
.data()
|
|
||||||
.reduce(function (a, b) {
|
|
||||||
return intVal(a) + intVal(b);
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
var totalTotal = table
|
|
||||||
.column(11)
|
|
||||||
.data()
|
|
||||||
.reduce(function (a, b) {
|
|
||||||
return intVal(a) + intVal(b);
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
// Update footer
|
|
||||||
$('#subtotal-sum').html(totalSubtotal.toFixed(2));
|
|
||||||
$('#total-iva-sum').html(totalIVA.toFixed(2));
|
|
||||||
$('#total-sum').html(totalTotal.toFixed(2));
|
|
||||||
|
|
||||||
// Assuming pendiente de pago is totalTotal - totalIVA for this example
|
|
||||||
<?php if($facturaEntity->estado == 'borrador') :?>
|
|
||||||
var pendientePago = totalTotal ;
|
|
||||||
var total_pagos = 0;
|
|
||||||
<?php else: ?>
|
|
||||||
var total_pagos = parseFloat($('#totalCobrado-sum').html()).toFixed(2);
|
|
||||||
var pendientePago = totalTotal - total_pagos;
|
|
||||||
<?php endif; ?>
|
|
||||||
if(isNaN(pendientePago)){
|
|
||||||
pendientePago = 0;
|
|
||||||
}
|
|
||||||
$('#pendiente-pago').html(pendientePago.toFixed(2));
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
|
|
||||||
method: 'POST',
|
|
||||||
data: {
|
|
||||||
base: totalSubtotal,
|
|
||||||
total: totalTotal,
|
|
||||||
total_pagos: total_pagos,
|
|
||||||
pendiente: pendientePago,
|
|
||||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
|
||||||
}
|
|
||||||
}).done((data, textStatus, jqXHR) => {
|
|
||||||
if(data.estado_pago == 'pagada'){
|
|
||||||
$('#estado_pago_text').text('<?= lang('Facturas.pagada') ?>');
|
|
||||||
$('#estado_pago_text').css('color', 'green');
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$('#estado_pago_text').text('<?= lang('Facturas.pendiente') ?>');
|
|
||||||
$('#estado_pago_text').css('color', 'red');
|
|
||||||
}
|
|
||||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
|
||||||
popErrorAlert(jqXHR.responseJSON.messages.error)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete row
|
// Delete row
|
||||||
$(document).on('click', '.btn-delete', function(e) {
|
$(document).on('click', '.btn-delete', function(e) {
|
||||||
|
|
||||||
@ -577,7 +532,6 @@ $(document).on('click', '.btn-excedentes', function(e) {
|
|||||||
pedido_id: pedido_id,
|
pedido_id: pedido_id,
|
||||||
pedido_linea_impresion_id: pedido_linea_impresion_id,
|
pedido_linea_impresion_id: pedido_linea_impresion_id,
|
||||||
pedido_linea_maquetacion_id: pedido_linea_maquetacion_id,
|
pedido_linea_maquetacion_id: pedido_linea_maquetacion_id,
|
||||||
precio_unidad: row_data.precio_unidad,
|
|
||||||
descripcion: row_data.descripcion,
|
descripcion: row_data.descripcion,
|
||||||
iva: row_data.iva,
|
iva: row_data.iva,
|
||||||
descuento: row_data.descuento_tirada_flexible,
|
descuento: row_data.descuento_tirada_flexible,
|
||||||
|
|||||||
@ -281,21 +281,21 @@ function updateFooterLineas(table){
|
|||||||
|
|
||||||
// Total over all pages
|
// Total over all pages
|
||||||
var totalSubtotal = table
|
var totalSubtotal = table
|
||||||
.column(9)
|
.column(8)
|
||||||
.data()
|
.data()
|
||||||
.reduce(function (a, b) {
|
.reduce(function (a, b) {
|
||||||
return intVal(a) + intVal(b);
|
return intVal(a) + intVal(b);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
var totalIVA = table
|
var totalIVA = table
|
||||||
.column(10)
|
.column(9)
|
||||||
.data()
|
.data()
|
||||||
.reduce(function (a, b) {
|
.reduce(function (a, b) {
|
||||||
return intVal(a) + intVal(b);
|
return intVal(a) + intVal(b);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
var totalTotal = table
|
var totalTotal = table
|
||||||
.column(11)
|
.column(10)
|
||||||
.data()
|
.data()
|
||||||
.reduce(function (a, b) {
|
.reduce(function (a, b) {
|
||||||
return intVal(a) + intVal(b);
|
return intVal(a) + intVal(b);
|
||||||
|
|||||||
Reference in New Issue
Block a user