diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php
index be8eef6a..96e0e1dc 100755
--- a/ci4/app/Config/Routes.php
+++ b/ci4/app/Config/Routes.php
@@ -519,6 +519,9 @@ $routes->group('albaranes', ['namespace' => 'App\Controllers\Albaranes'], functi
$routes->post('updateAlbaran', 'Albaran::updateAlbaran');
$routes->post('borrarAlbaranLinea', 'Albaran::borrarLinea');
$routes->post('borrarAlbaran', 'Albaran::borrarAlbaran');
+ $routes->post('updateAlbaranLinea', 'Albaran::updateAlbaranLinea');
+ $routes->post('addIvaAlbaran', 'Albaran::addLineasIva');
+ $routes->post('nuevaLineaAlbaran', 'Albaran::addBlankLineaAlbaran');
});
$routes->resource('albaranes', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Albaran', 'except' => 'show,new,create,update']);
diff --git a/ci4/app/Controllers/Albaranes/Albaran.php b/ci4/app/Controllers/Albaranes/Albaran.php
index a9680853..3531c2c4 100755
--- a/ci4/app/Controllers/Albaranes/Albaran.php
+++ b/ci4/app/Controllers/Albaranes/Albaran.php
@@ -339,8 +339,11 @@ class Albaran extends \App\Controllers\BaseResourceController
return '' . $q->pedido . '';
})
->edit('unidades', function ($q) {
- return '';
+ if(str_contains($q->titulo, 'IVA'))
+ return null;
+ else
+ return '';
})
->edit('titulo', function ($q) {
return '';
})
->edit('precio_unidad', function ($q) {
- return '';
+ if(str_contains($q->titulo, 'IVA'))
+ return null;
+ else
+ return '';
});
@@ -364,28 +370,122 @@ class Albaran extends \App\Controllers\BaseResourceController
if ($this->request->isAJAX()) {
+ $model_linea = model('App\Models\Albaranes\AlbaranLineaModel');
+
+
$fieldName = $this->request->getPost('fieldName');
$fieldValue = $this->request->getPost('fieldValue');
$id = $this->request->getPost('lineaId');
- if ($id == null) {
+ $linea = $model_linea->find($id);
+ if ($linea == false) {
$data = [
'success' => false,
'message' => lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]),
];
return $this->respond($data);
}
- $albaranEntity = model('App\Models\Albaranes\AlbaranLineaModel')->find($id);
-
- if ($albaranEntity == false) {
- $data = [
- 'success' => false,
- 'message' => lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]),
- ];
- return $this->respond($data);
+ if($fieldName == 'cantidad') {
+ $linea->total = round($linea->precio_unidad * intval($fieldValue), 4);
+ $linea->cantidad = intval($fieldValue);
+ }
+ else if($fieldName == 'precio_unidad') {
+ $fieldValue2 = str_replace(',', '.', $fieldValue);
+ $linea->total = round(round(floatval($fieldValue2), 4) * intval($linea->cantidad), 2);
+ $linea->precio_unidad = round(floatval($fieldValue2), 4);
+ }
+ else if($fieldName == 'total') {
+ $linea->total = round(floatval($fieldValue), 2);
+ $linea->precio_unidad = round(floatval($fieldValue) / intval($linea->cantidad), 4);
}
-
+ else{
+ $linea->$fieldName = $fieldValue;
+ }
+ $linea->user_updated_id = auth()->user()->id;
+ $linea->updated_at = date('Y-m-d H:i:s');
+ $model_linea->update($id, $linea->toArray());
+
+ $data = [
+ 'success' => true,
+ 'message' => lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.',
+ ];
+ return $this->respond($data);
+
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function addLineasIva(){
+
+ if ($this->request->isAJAX()) {
+
+ $albaran_id = $this->request->getPost('albaranId');
+ $model_linea = model('App\Models\Albaranes\AlbaranLineaModel');
+
+ $lineas_albaran = $model_linea->where('albaran_id', $albaran_id)->findAll();
+ $iva_reducido = 0;
+ $iva_no_reducido = 0;
+ foreach ($lineas_albaran as $linea) {
+ if($linea->iva_reducido == 1) {
+ $iva_reducido += round(floatval($linea->total)*0.04, 2);
+ } else {
+ $iva_no_reducido += round(floatval($linea->total)*0.21, 2);
+ }
+ }
+ $iva_reducido = round($iva_reducido, 2);
+ $iva_no_reducido = round($iva_no_reducido, 2);
+ if($iva_reducido > 0) {
+ $linea = [
+ 'albaran_id' => $albaran_id,
+ 'titulo' => lang('Albaran.iva4'),
+ 'total' => round($iva_reducido, 2),
+ 'user_created_id' => auth()->user()->id,
+ 'user_updated_id' => auth()->user()->id
+ ];
+ $model_linea->insert($linea);
+ }
+ if($iva_no_reducido > 0) {
+ $linea = [
+ 'albaran_id' => $albaran_id,
+ 'titulo' => lang('Albaran.iva21'),
+ 'total' => round($iva_no_reducido, 2),
+ 'user_created_id' => auth()->user()->id,
+ 'user_updated_id' => auth()->user()->id
+ ];
+ $model_linea->insert($linea);
+ }
+ $data = [
+ 'success' => true,
+ 'message' => lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.',
+ ];
+ return $this->respond($data);
+
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function addBlankLineaAlbaran(){
+
+ if ($this->request->isAJAX()) {
+
+ $albaran_id = $this->request->getPost('albaranId');
+ $model_linea = model('App\Models\Albaranes\AlbaranLineaModel');
+
+ $linea = [
+ 'albaran_id' => $albaran_id,
+ 'user_created_id' => auth()->user()->id,
+ 'user_updated_id' => auth()->user()->id
+ ];
+ $id_linea = $model_linea->insert($linea);
+ $data = $model_linea->find($id_linea);
+
+ $data = [
+ 'success' => true,
+ ];
+ return $this->respond($data);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
diff --git a/ci4/app/Controllers/Pdf/PrintAlbaranes.php b/ci4/app/Controllers/Pdf/PrintAlbaranes.php
index f5d88265..4ebaeb73 100755
--- a/ci4/app/Controllers/Pdf/PrintAlbaranes.php
+++ b/ci4/app/Controllers/Pdf/PrintAlbaranes.php
@@ -33,6 +33,14 @@ class PrintAlbaranes extends BaseController
$data['albaranLineas'] = $lineasAlbaranModel->getResourceForPdf($albaran_id)->get()->getResultObject();
+ // Obtener contenido HTML de la vista
+ $html = view(getenv('theme.path') . 'pdfs/albaran', $data);
+
+ // Cargar CSS desde archivo local
+ $css = file_get_contents(FCPATH . 'themes/vuexy/css/pdf.albaran.css');
+ // Combinar CSS y HTML
+ $html_con_css = "" . $html;
+
// Crear una instancia de Dompdf
$options = new \Dompdf\Options();
$options->set('isHtml5ParserEnabled', true);
@@ -41,7 +49,7 @@ class PrintAlbaranes extends BaseController
$dompdf = new \Dompdf\Dompdf($options);
// Contenido HTML del documento
- $dompdf->loadHtml(view(getenv('theme.path').'pdfs/albaran', $data));
+ $dompdf->loadHtml($html_con_css);
// Establecer el tamaño del papel
$dompdf->setPaper('A4', 'portrait');
diff --git a/ci4/app/Language/es/Albaran.php b/ci4/app/Language/es/Albaran.php
index 88131b0f..31966e67 100644
--- a/ci4/app/Language/es/Albaran.php
+++ b/ci4/app/Language/es/Albaran.php
@@ -26,4 +26,6 @@ return [
'borrar' => 'Borrar',
'cancelar' => 'Cancelar',
+ 'iva4' => 'IVA 4%',
+ 'iva21' => 'IVA 21%',
];
\ No newline at end of file
diff --git a/ci4/app/Models/Albaranes/AlbaranLineaModel.php b/ci4/app/Models/Albaranes/AlbaranLineaModel.php
index 83f05e34..0cc160d5 100755
--- a/ci4/app/Models/Albaranes/AlbaranLineaModel.php
+++ b/ci4/app/Models/Albaranes/AlbaranLineaModel.php
@@ -36,7 +36,7 @@ class AlbaranLineaModel extends \App\Models\BaseModel
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
- protected $deletedField = 'deleted_at';
+ protected $deletedField = 'deleted_at';
/**
* Get resource data for creating PDFs.
@@ -48,24 +48,24 @@ class AlbaranLineaModel extends \App\Models\BaseModel
public function getResourceForPdf($albaran_id = -1)
{
$builder = $this->db
-
->table($this->table . " t1")
->select(
- "t1.id AS id, t1.albaran_id AS albaran_id, t1.titulo AS titulo, t1.isbn AS isbn,
- t1.ref_cliente AS ref_cliente, t1.cantidad AS cantidad, t1.cajas AS cajas,
- t1.ejemplares_por_caja AS ejemplares_por_caja, t1.precio_unidad AS precio_unidad,
- t1.total AS total, pedidos.id AS pedido"
+ "t1.id, t1.titulo as titulo, t1.isbn as isbn, t1.ref_cliente as ref_cliente,
+ t1.cantidad as unidades, t1.precio_unidad as precio_unidad, t1.iva_reducido as iva_reducido,
+ t1.total as total, pedidos.id AS pedido"
)
->join("pedidos_linea", "t1.pedido_linea_id = pedidos_linea.id", "left")
->join("pedidos", "pedidos_linea.pedido_id = pedidos.id", "left");
+
$builder->where("t1.deleted_at IS NULL");
$builder->where("t1.albaran_id", $albaran_id);
return $builder;
}
- public function getDatatableQuery($albaran_id = null){
+ public function getDatatableQuery($albaran_id = null)
+ {
$builder = $this->db
->table($this->table . " t1")
->select(
diff --git a/ci4/app/Models/Albaranes/AlbaranModel.php b/ci4/app/Models/Albaranes/AlbaranModel.php
index 40e418e5..acd67487 100644
--- a/ci4/app/Models/Albaranes/AlbaranModel.php
+++ b/ci4/app/Models/Albaranes/AlbaranModel.php
@@ -182,17 +182,19 @@ class AlbaranModel extends \App\Models\BaseModel
public function getResourceForPdf($albaran_id = -1)
{
$builder = $this->db
-
->table($this->table . " t1")
- ->select(
- "t1.id AS id, t1.pedido_id AS pedido_id, t1.presupuesto_id AS presupuesto_id,
- t1.presupuesto_direccion_id AS presupuesto_direccion_id, t1.cliente_id AS cliente_id,
- t1.serie_id AS serie_id, t1.numero_albaran AS numero_albaran, t1.mostrar_precios AS mostrar_precios,
- t1.total AS total, t1.direccion_albaran AS direccion_albaran, t1.att_albaran AS att_albaran,
- t1.user_created_id AS user_created_id, t1.user_updated_id AS user_updated_id,
- t1.created_at AS created_at, t1.updated_at AS updated_at,
- t2.nombre AS cliente"
- );
+ ->select("
+ t1.id,
+ t1.att_albaran AS att,
+ t1.direccion_albaran AS direccion,
+ t1.envio_id,
+ t1.numero_albaran AS numero_albaran,
+ DATE_FORMAT(t1.created_at, '%d/%m/%Y') AS fecha_creacion,
+ DATE_FORMAT(t1.fecha_albaran, '%d/%m/%Y') AS fecha_albaran,
+ t1.mostrar_precios AS mostrar_precios,
+ t2.nombre AS cliente,
+ t1.cajas AS cajas
+ ") ;
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
$builder->where("t1.deleted_at IS NULL");
diff --git a/ci4/app/Views/themes/vuexy/pdfs/albaran.php b/ci4/app/Views/themes/vuexy/pdfs/albaran.php
index 2d49654b..f7effbe6 100755
--- a/ci4/app/Views/themes/vuexy/pdfs/albaran.php
+++ b/ci4/app/Views/themes/vuexy/pdfs/albaran.php
@@ -1,5 +1,6 @@
+
@@ -19,159 +20,163 @@
-
-
-
-
-
- |
-
-
-
- mostrar_precios == 1;
- ?>
-
-
-
-
-
- |
- Nº ALBARÁN:
- |
-
- = $albaran->id ?>
- |
-
- Nº PEDIDO:
- |
-
- = $albaran->pedido_id ?>
- |
-
- FECHA:
- |
-
- = date('d-m-Y', strtotime($albaran->created_at)) ?>
- |
-
-
-
-
- | Cliente: |
-
- | = $albaran->cliente ?> |
-
-
- | Att: = $albaran->att_albaran ?> |
-
-
- | = $albaran->direccion_albaran ?> |
-
-
-
-
-
-
-
- | Nº Unid. |
- Título |
- ISBN |
- Ref. Cliente |
- Cajas |
- Ejempl./Cajas |
-
- €/ud. |
- Subtotal |
-
-
-
-
-
-
- total;
- ?>
+
+
- | = $linea->cantidad ?> |
-
- = $linea->titulo ?>
+ |
+
|
-
- = $linea->isbn ?>
+ |
+
+
+ mostrar_precios == 1;
+ ?>
+
+
+
+
+
+ |
+ Nº ALBARÁN:
+ |
+
+ = $albaran->id ?>
+ |
+
+ |
+
+ |
+
+ FECHA:
+ |
+
+ = $albaran->fecha_albaran ? date('d-m-Y', strtotime($albaran->fecha_albaran)) : date('d-m-Y') ?>
+ |
+
+
+
+
+ | Cliente: = $albaran->cliente ?> |
+
+
+ | Att: = $albaran->att ?> |
+
+
+ | = $albaran->direccion ?> |
+
+
+
+
+ | Cajas: = $albaran->cajas ?> |
+
+
+
+
+
+
+
+ | Nº Unid. |
+ Pedido |
+ Título |
+ ISBN |
+ Ref. Cliente |
+
+ €/ud. |
+ Subtotal |
+
+
+
+
+
+
+ total;
+ ?>
+
+ |
+ = $linea->unidades ?>
+ |
+
+ = $linea->pedido ?>
+ |
+
+ = $linea->titulo ?>
+ |
+
+ = $linea->isbn ?>
+ |
+
+ = $linea->ref_cliente ?>
+ |
+
+
+ titulo, "IVA")): ?>
+ = number_format($linea->precio_unidad, 4, ',', '.') ?>
+
+ |
+
+ = number_format($linea->total, 2, ',', '.') ?>
+ |
+
+
+
+
+
+
+
+ |
+
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+
+
+ |
+ RECIBÍ
|
-
- = $linea->ref_cliente ?>
- |
- = $linea->cajas ?> |
- = $linea->ejemplares_por_caja ?> |
-
- = $linea->precio_unidad ?>
+ |
+ TOTAL
|
- = ($linea->total) ?>
+ = ($total_precio) ?>
|
-
+
-
-
-
- |
-
- |
-
-
- |
-
-
- |
-
-
- |
-
-
- |
-
-
- |
-
-
-
- |
-
-
- |
-
-
-
-
-
-
-
-
-
- |
- RECIBÍ
- |
-
-
- TOTAL
- |
-
- = ($total_precio) ?>
- |
-
-
-
-
-
+
-
+
+