Merge branch 'main' into 'dev/chat'

Main

See merge request jjimenez/safekat!305
This commit is contained in:
Ignacio Martinez Navajas
2024-08-16 08:51:39 +00:00
30 changed files with 770 additions and 367 deletions

View File

@ -395,7 +395,7 @@ class Cliente extends \App\Controllers\BaseResourceController
protected function getFormaDePagoListItems($selId = null)
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('FormasPagoes.formaDePago'))])];
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('FormasPago.formaDePago'))])];
if (!empty($selId)) :
$formaPagoModel = model('App\Models\Configuracion\FormaPagoModel');

View File

@ -9,7 +9,7 @@ use App\Entities\Configuracion\FormaPagoEntity;
use App\Models\Configuracion\FormaPagoModel;
class Formaspagos extends \App\Controllers\BaseResourceController
class FormasPago extends \App\Controllers\BaseResourceController
{
protected $modelName = FormaPagoModel::class;
@ -22,15 +22,22 @@ class Formaspagos extends \App\Controllers\BaseResourceController
protected static $controllerSlug = 'formas-pagos';
protected static $viewPath = 'themes/vuexy/form/configuracion/formasPagoViews/';
protected static $viewPath = 'themes/vuexy/form/configuracion/formas-pago/';
protected $indexRoute = 'formaDePagoList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('FormasPagoes.moduleTitle');
$this->viewData['pageTitle'] = lang('FormasPago.moduleTitle');
$this->viewData['usingSweetAlert'] = true;
// Breadcrumbs (IMN)
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_configuration"), 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("App.menu_formas_pago"), 'route' => route_to('formasPagoList'), 'active' => true]
];
parent::initController($request, $response, $logger);
}
@ -40,7 +47,7 @@ class Formaspagos extends \App\Controllers\BaseResourceController
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('FormasPagoes.formaDePago')]),
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('FormasPago.formaDePago')]),
'formaPagoEntity' => new FormaPagoEntity(),
'usingServerSideDataTable' => true,
@ -55,22 +62,15 @@ class Formaspagos extends \App\Controllers\BaseResourceController
public function add()
{
if ($this->request->getPost()) :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, true);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
@ -93,7 +93,8 @@ class Formaspagos extends \App\Controllers\BaseResourceController
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
return redirect()->to(site_url('/configuracion/formas-pago/edit/' . $id))->with('sweet-success', $message);
//return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else:
return $this->redirect2listView('sweet-success', $message);
endif;
@ -106,11 +107,8 @@ class Formaspagos extends \App\Controllers\BaseResourceController
endif; // ($requestMethod === 'post')
$this->viewData['formaPagoEntity'] = isset($sanitizedData) ? new FormaPagoEntity($sanitizedData) : new FormaPagoEntity();
$this->viewData['formAction'] = route_to('createFormaDePago');
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('FormasPagoes.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
$this->viewData['formAction'] = route_to('formasPagoAdd');
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('FormasPago.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__);
} // end function add()
@ -125,25 +123,18 @@ class Formaspagos extends \App\Controllers\BaseResourceController
$formaPagoEntity = $this->model->find($id);
if ($formaPagoEntity == false) :
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('FormasPagoes.formaDePago')), $id]);
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('FormasPago.formaDePago')), $id]);
return $this->redirect2listView('sweet-error', $message);
endif;
if ($this->request->getPost()) :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, true);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
@ -152,13 +143,12 @@ class Formaspagos extends \App\Controllers\BaseResourceController
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('FormasPagoes.formaDePago'))]);
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('FormasPago.formaDePago'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$formaPagoEntity->fill($sanitizedData);
$thenRedirect = false;
endif;
if ($noException && $successfulResult) :
@ -179,11 +169,8 @@ class Formaspagos extends \App\Controllers\BaseResourceController
endif; // ($requestMethod === 'post')
$this->viewData['formaPagoEntity'] = $formaPagoEntity;
$this->viewData['formAction'] = route_to('updateFormaDePago', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('FormasPagoes.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['formAction'] = route_to('formasPagoEdit', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('FormasPago.moduleTitle') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id);
} // end function edit(...)

View File

@ -66,7 +66,6 @@ class SeriesFacturas extends BaseResourceController
$noException = true;
if ($successfulResult = $this->canValidate()) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
@ -105,7 +104,6 @@ class SeriesFacturas extends BaseResourceController
$this->viewData['formAction'] = route_to('seriesFacturasAdd');
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('SeriesFacturas.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__);
} // end function add()
@ -126,7 +124,6 @@ class SeriesFacturas extends BaseResourceController
if ($this->request->getPost()) :
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, true);
if ($this->request->getPost('show_erp') == null) {
$sanitizedData['show_erp'] = false;

View File

@ -392,13 +392,16 @@ class Facturas extends \App\Controllers\BaseResourceController
$postData = $this->request->getPost();
$pendiente = $postData['pendiente'] ?? 0;
$total = $postData['total'] ?? 0;
$data = [
'base' => $postData['base'] ?? 0,
'total' => $postData['total'] ?? 0,
'pendiente' => $postData['pendiente'] ?? 0,
'total' => $total,
'pendiente' => $pendiente,
'total_pagos' => $postData['total_pagos'] ?? 0,
'user_updated_id' => auth()->user()->id,
'estado_pago' => (intval($postData['pendiente'] ?? 0)==0) ? 'pagada' : 'pendiente',
'estado_pago' => (intval($pendiente)==0 && intval($total)!=0) ? 'pagada' : 'pendiente',
];
$newTokenHash = csrf_hash();
@ -422,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){
@ -433,48 +484,55 @@ class Facturas extends \App\Controllers\BaseResourceController
try{
$pedido_linea_id = $this->request->getPost('lineaPedido') ?? 0;
$linea = $model_pedido_linea->find($pedido_linea_id);
$factura = $this->model->find($factura_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;
if($factura){
$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,
];
if($linea){
$presupuesto = $model_presupuesto->find($linea->presupuesto_id);
$model_factura_linea->insert($data);
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);
$base = round($base, 2);
$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;
$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
$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);
}
}
}
}

View File

@ -245,13 +245,31 @@ class Pedido extends \App\Controllers\BaseResourceController
$estado = $reqData['estado'] ?? 'todos';
if($estado == 'todos') $estado = '';
$model_linea = model('\App\Models\Pedidos\PedidoLineaModel');
$resourceData = $model_linea->getResource($search, $estado)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
$showTotal = $reqData['showTotal'] ?? false;
$searchValues = get_filter_datatables_columns($reqData);
$model_linea = model('\App\Models\Pedidos\PedidoLineaModel');
$resourceData = $model_linea->getResource($searchValues, $estado)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
$totalTirada = $model_linea->getSumOfTirada($searchValues, $estado, $start, $length);
$total = $model_linea->getSumOfTotalAceptado($searchValues, $estado, $start, $length);
$total2 = 0;
if($showTotal){
$total2 = $model_linea->getTotalOfTotalAceptado();
}
if($total2 != 0){
$total = "" . $total . " \n(" . $total2 . ")";
}
return $this->respond(Collection::datatable(
$resourceData,
$model_linea->getResource("", $estado)->countAllResults(),
$model_linea->getResource($search, $estado)->countAllResults()
$model_linea->getResource($searchValues, $estado)->countAllResults(),
"",
[
'total_tirada' => $totalTirada,
'total' => $total
]
));
} else {
return $this->failUnauthorized('Invalid request', 403);

View File

@ -111,7 +111,7 @@ class Buscador extends \App\Controllers\BaseResourceController
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResource("")->countAllResults(),
$this->model->getResource($search)->countAllResults()
$this->model->getResource($searchValues)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);

View File

@ -1073,14 +1073,12 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
try {
$return_data = [];
if ($extra_info) {
$info = [
'merma' => 0,
'lomo_cubierta' => 0.0,
'lomo_sobrecubierta' => 0.0,
'user_id' => auth()->user()->id,
];
}
$info = [
'merma' => 0,
'lomo_cubierta' => 0.0,
'lomo_sobrecubierta' => 0.0,
'user_id' => auth()->user()->id,
];
$tirada = $datos_entrada['tirada'];
$tamanio = $datos_entrada['tamanio'];
@ -1568,11 +1566,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
));
}
$info['lomo_cubierta'] = $lomo;
$info['lomo_sobrecubierta'] = $lomo_sobrecubierta;
$return_data['info'] = $info;
if ($extra_info) { // && $tirada[$t] == $selected_tirada) {
$info['lomo_cubierta'] = $lomo;
$info['lomo_sobrecubierta'] = $lomo_sobrecubierta;
$return_data['info'] = $info;
$return_data['info']['interior'] = $interior;
$return_data['info']['cubierta'] = $cubierta;
$return_data['info']['sobrecubierta'] = $linea_sobrecubierta;