mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
botones albaran finalizado
This commit is contained in:
@ -519,6 +519,9 @@ $routes->group('albaranes', ['namespace' => 'App\Controllers\Albaranes'], functi
|
|||||||
$routes->post('updateAlbaran', 'Albaran::updateAlbaran');
|
$routes->post('updateAlbaran', 'Albaran::updateAlbaran');
|
||||||
$routes->post('borrarAlbaranLinea', 'Albaran::borrarLinea');
|
$routes->post('borrarAlbaranLinea', 'Albaran::borrarLinea');
|
||||||
$routes->post('borrarAlbaran', 'Albaran::borrarAlbaran');
|
$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']);
|
$routes->resource('albaranes', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Albaran', 'except' => 'show,new,create,update']);
|
||||||
|
|
||||||
|
|||||||
@ -339,8 +339,11 @@ class Albaran extends \App\Controllers\BaseResourceController
|
|||||||
return '<a href="' . base_url('pedidos/edit/' . $q->pedido) . '" target="_blank">' . $q->pedido . '</a>';
|
return '<a href="' . base_url('pedidos/edit/' . $q->pedido) . '" target="_blank">' . $q->pedido . '</a>';
|
||||||
})
|
})
|
||||||
->edit('unidades', function ($q) {
|
->edit('unidades', function ($q) {
|
||||||
return '<input type="number" class="form-control form-control-sm input-albaran-linea text-center"
|
if(str_contains($q->titulo, 'IVA'))
|
||||||
value="' . $q->unidades . '" data-id="' . $q->id . '" data-field="cantidad" />';
|
return null;
|
||||||
|
else
|
||||||
|
return '<input type="number" class="form-control form-control-sm input-albaran-linea text-center"
|
||||||
|
value="' . $q->unidades . '" data-id="' . $q->id . '" data-field="cantidad" />';
|
||||||
})
|
})
|
||||||
->edit('titulo', function ($q) {
|
->edit('titulo', function ($q) {
|
||||||
return '<input type="text" class="form-control form-control-sm input-albaran-linea" value="' . $q->titulo .
|
return '<input type="text" class="form-control form-control-sm input-albaran-linea" value="' . $q->titulo .
|
||||||
@ -351,9 +354,12 @@ class Albaran extends \App\Controllers\BaseResourceController
|
|||||||
form-control-sm text-center" value="' . $q->total . '" data-id="' . $q->id . '" data-field="total" />';
|
form-control-sm text-center" value="' . $q->total . '" data-id="' . $q->id . '" data-field="total" />';
|
||||||
})
|
})
|
||||||
->edit('precio_unidad', function ($q) {
|
->edit('precio_unidad', function ($q) {
|
||||||
return '<input class="form-control autonumeric-4 form-control-sm text-center input-albaran-linea" value="' .
|
if(str_contains($q->titulo, 'IVA'))
|
||||||
number_format((float) $q->precio_unidad, 4, ',', '') .
|
return null;
|
||||||
'" data-id="' . $q->id . '" data-field="precio_unidad" />';
|
else
|
||||||
|
return '<input class="form-control autonumeric-4 form-control-sm text-center input-albaran-linea" value="' .
|
||||||
|
number_format((float) $q->precio_unidad, 4, ',', '') .
|
||||||
|
'" data-id="' . $q->id . '" data-field="precio_unidad" />';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -364,28 +370,122 @@ class Albaran extends \App\Controllers\BaseResourceController
|
|||||||
|
|
||||||
if ($this->request->isAJAX()) {
|
if ($this->request->isAJAX()) {
|
||||||
|
|
||||||
|
$model_linea = model('App\Models\Albaranes\AlbaranLineaModel');
|
||||||
|
|
||||||
|
|
||||||
$fieldName = $this->request->getPost('fieldName');
|
$fieldName = $this->request->getPost('fieldName');
|
||||||
$fieldValue = $this->request->getPost('fieldValue');
|
$fieldValue = $this->request->getPost('fieldValue');
|
||||||
$id = $this->request->getPost('lineaId');
|
$id = $this->request->getPost('lineaId');
|
||||||
|
|
||||||
if ($id == null) {
|
$linea = $model_linea->find($id);
|
||||||
|
if ($linea == false) {
|
||||||
$data = [
|
$data = [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'message' => lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]),
|
'message' => lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]),
|
||||||
];
|
];
|
||||||
return $this->respond($data);
|
return $this->respond($data);
|
||||||
}
|
}
|
||||||
$albaranEntity = model('App\Models\Albaranes\AlbaranLineaModel')->find($id);
|
if($fieldName == 'cantidad') {
|
||||||
|
$linea->total = round($linea->precio_unidad * intval($fieldValue), 4);
|
||||||
if ($albaranEntity == false) {
|
$linea->cantidad = intval($fieldValue);
|
||||||
$data = [
|
|
||||||
'success' => false,
|
|
||||||
'message' => lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]),
|
|
||||||
];
|
|
||||||
return $this->respond($data);
|
|
||||||
}
|
}
|
||||||
|
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 {
|
} else {
|
||||||
return $this->failUnauthorized('Invalid request', 403);
|
return $this->failUnauthorized('Invalid request', 403);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,14 @@ class PrintAlbaranes extends BaseController
|
|||||||
$data['albaranLineas'] = $lineasAlbaranModel->getResourceForPdf($albaran_id)->get()->getResultObject();
|
$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 = "<style>$css</style>" . $html;
|
||||||
|
|
||||||
// Crear una instancia de Dompdf
|
// Crear una instancia de Dompdf
|
||||||
$options = new \Dompdf\Options();
|
$options = new \Dompdf\Options();
|
||||||
$options->set('isHtml5ParserEnabled', true);
|
$options->set('isHtml5ParserEnabled', true);
|
||||||
@ -41,7 +49,7 @@ class PrintAlbaranes extends BaseController
|
|||||||
$dompdf = new \Dompdf\Dompdf($options);
|
$dompdf = new \Dompdf\Dompdf($options);
|
||||||
|
|
||||||
// Contenido HTML del documento
|
// Contenido HTML del documento
|
||||||
$dompdf->loadHtml(view(getenv('theme.path').'pdfs/albaran', $data));
|
$dompdf->loadHtml($html_con_css);
|
||||||
|
|
||||||
// Establecer el tamaño del papel
|
// Establecer el tamaño del papel
|
||||||
$dompdf->setPaper('A4', 'portrait');
|
$dompdf->setPaper('A4', 'portrait');
|
||||||
|
|||||||
@ -26,4 +26,6 @@ return [
|
|||||||
'borrar' => 'Borrar',
|
'borrar' => 'Borrar',
|
||||||
'cancelar' => 'Cancelar',
|
'cancelar' => 'Cancelar',
|
||||||
|
|
||||||
|
'iva4' => 'IVA 4%',
|
||||||
|
'iva21' => 'IVA 21%',
|
||||||
];
|
];
|
||||||
@ -36,7 +36,7 @@ class AlbaranLineaModel extends \App\Models\BaseModel
|
|||||||
protected $useTimestamps = true;
|
protected $useTimestamps = true;
|
||||||
protected $createdField = 'created_at';
|
protected $createdField = 'created_at';
|
||||||
protected $updatedField = 'updated_at';
|
protected $updatedField = 'updated_at';
|
||||||
protected $deletedField = 'deleted_at';
|
protected $deletedField = 'deleted_at';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get resource data for creating PDFs.
|
* Get resource data for creating PDFs.
|
||||||
@ -48,24 +48,24 @@ class AlbaranLineaModel extends \App\Models\BaseModel
|
|||||||
public function getResourceForPdf($albaran_id = -1)
|
public function getResourceForPdf($albaran_id = -1)
|
||||||
{
|
{
|
||||||
$builder = $this->db
|
$builder = $this->db
|
||||||
|
|
||||||
->table($this->table . " t1")
|
->table($this->table . " t1")
|
||||||
->select(
|
->select(
|
||||||
"t1.id AS id, t1.albaran_id AS albaran_id, t1.titulo AS titulo, t1.isbn AS isbn,
|
"t1.id, t1.titulo as titulo, t1.isbn as isbn, t1.ref_cliente as ref_cliente,
|
||||||
t1.ref_cliente AS ref_cliente, t1.cantidad AS cantidad, t1.cajas AS cajas,
|
t1.cantidad as unidades, t1.precio_unidad as precio_unidad, t1.iva_reducido as iva_reducido,
|
||||||
t1.ejemplares_por_caja AS ejemplares_por_caja, t1.precio_unidad AS precio_unidad,
|
t1.total as total, pedidos.id AS pedido"
|
||||||
t1.total AS total, pedidos.id AS pedido"
|
|
||||||
)
|
)
|
||||||
->join("pedidos_linea", "t1.pedido_linea_id = pedidos_linea.id", "left")
|
->join("pedidos_linea", "t1.pedido_linea_id = pedidos_linea.id", "left")
|
||||||
->join("pedidos", "pedidos_linea.pedido_id = pedidos.id", "left");
|
->join("pedidos", "pedidos_linea.pedido_id = pedidos.id", "left");
|
||||||
|
|
||||||
|
|
||||||
$builder->where("t1.deleted_at IS NULL");
|
$builder->where("t1.deleted_at IS NULL");
|
||||||
$builder->where("t1.albaran_id", $albaran_id);
|
$builder->where("t1.albaran_id", $albaran_id);
|
||||||
|
|
||||||
return $builder;
|
return $builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDatatableQuery($albaran_id = null){
|
public function getDatatableQuery($albaran_id = null)
|
||||||
|
{
|
||||||
$builder = $this->db
|
$builder = $this->db
|
||||||
->table($this->table . " t1")
|
->table($this->table . " t1")
|
||||||
->select(
|
->select(
|
||||||
|
|||||||
@ -182,17 +182,19 @@ class AlbaranModel extends \App\Models\BaseModel
|
|||||||
public function getResourceForPdf($albaran_id = -1)
|
public function getResourceForPdf($albaran_id = -1)
|
||||||
{
|
{
|
||||||
$builder = $this->db
|
$builder = $this->db
|
||||||
|
|
||||||
->table($this->table . " t1")
|
->table($this->table . " t1")
|
||||||
->select(
|
->select("
|
||||||
"t1.id AS id, t1.pedido_id AS pedido_id, t1.presupuesto_id AS presupuesto_id,
|
t1.id,
|
||||||
t1.presupuesto_direccion_id AS presupuesto_direccion_id, t1.cliente_id AS cliente_id,
|
t1.att_albaran AS att,
|
||||||
t1.serie_id AS serie_id, t1.numero_albaran AS numero_albaran, t1.mostrar_precios AS mostrar_precios,
|
t1.direccion_albaran AS direccion,
|
||||||
t1.total AS total, t1.direccion_albaran AS direccion_albaran, t1.att_albaran AS att_albaran,
|
t1.envio_id,
|
||||||
t1.user_created_id AS user_created_id, t1.user_updated_id AS user_updated_id,
|
t1.numero_albaran AS numero_albaran,
|
||||||
t1.created_at AS created_at, t1.updated_at AS updated_at,
|
DATE_FORMAT(t1.created_at, '%d/%m/%Y') AS fecha_creacion,
|
||||||
t2.nombre AS cliente"
|
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->join("clientes t2", "t1.cliente_id = t2.id", "left");
|
||||||
|
|
||||||
$builder->where("t1.deleted_at IS NULL");
|
$builder->where("t1.deleted_at IS NULL");
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -471,6 +471,83 @@ class AlbaranComponent {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#add_iva_albaran_' + this.id).on('click', (e) => {
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
const albaranId = this.id;
|
||||||
|
const url = `/albaranes/addIvaAlbaran`;
|
||||||
|
const data = { albaranId: albaranId };
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
type: 'POST',
|
||||||
|
data: data,
|
||||||
|
success: (response) => {
|
||||||
|
if (response.success) {
|
||||||
|
this.table.ajax.reload(null, false);
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error',
|
||||||
|
text: 'No se ha podido añadir el IVA al albarán',
|
||||||
|
icon: 'error',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Ok',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary me-1',
|
||||||
|
},
|
||||||
|
buttonsStyling: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: (xhr, status, error) => {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#nueva_linea_albaran_' + this.id).on('click', (e) => {
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
const albaranId = this.id;
|
||||||
|
const url = `/albaranes/nuevaLineaAlbaran`;
|
||||||
|
const data = { albaranId: albaranId };
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
type: 'POST',
|
||||||
|
data: data,
|
||||||
|
success: (response) => {
|
||||||
|
if (response.success) {
|
||||||
|
this.table.ajax.reload(null, false);
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Error',
|
||||||
|
text: 'No se ha podido añadir la línea al albarán',
|
||||||
|
icon: 'error',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Ok',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary me-1',
|
||||||
|
},
|
||||||
|
buttonsStyling: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: (xhr, status, error) => {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#imprimir_albaran_' + this.id).on('click', (e) => {
|
||||||
|
|
||||||
|
var albaran_id = this.id;
|
||||||
|
window.open('/print-albaran/generar/'+ albaran_id , '_blank');
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_initAutoNumericInputs() {
|
_initAutoNumericInputs() {
|
||||||
|
|||||||
Reference in New Issue
Block a user