mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadido facturas. faltan filtros pedidos
This commit is contained in:
@ -757,6 +757,7 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function (
|
||||
$routes->post('insertfactura', 'Pedido::addFactura');
|
||||
$routes->get('xml/(:num)', 'Pedido::get_xml_pedido/$1', ['as' => 'getXMLPedido']);
|
||||
$routes->post('produccion/(:num)', 'Pedido::to_produccion/$1', ['as' => 'toProduccion']);
|
||||
$routes->get('pedidosCliente', 'Pedido::tablaClienteForm');
|
||||
});
|
||||
$routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']);
|
||||
|
||||
@ -797,6 +798,7 @@ $routes->group('facturas', ['namespace' => 'App\Controllers\Facturacion'], funct
|
||||
$routes->post('datatablePagos/(:any)', 'FacturasPagos::datatable/$1', ['as' => 'dataTableOfPagosFacturas']);
|
||||
$routes->post('editorPagos', 'FacturasPagos::datatable_editor', ['as' => 'editorOfPagosFacturas']);
|
||||
$routes->post('datatablePedidos', 'Facturas::datatablePedidos', ['as' => 'dataTableOfFacturasPedido']);
|
||||
$routes->get('getdatoscliente/(:any)', 'Facturas::getDatosFacturacionClienteForm/$1');
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -236,13 +236,16 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
public function datatable()
|
||||
{
|
||||
|
||||
$dataForClienteForm = false;
|
||||
if (auth()->user()->inGroup('cliente-admin') || auth()->user()->inGroup('cliente-editor')) {
|
||||
// Se obtiene el cliente ID a partir del usuario de la sesion
|
||||
$model_user = model('App\Models\Usuarios\UserModel');
|
||||
$user = $model_user->find(auth()->user()->id);
|
||||
$clienteId = $user->cliente_id;
|
||||
} else {
|
||||
$clienteId = -1;
|
||||
$temp = $this->request->getGet('cliente_id');
|
||||
$clienteId = ($temp && $temp != null && $temp != "") ? $temp : -1;
|
||||
$dataForClienteForm = ($temp && $temp != null && $temp != "") ? true : false;
|
||||
}
|
||||
|
||||
$model = model(FacturaModel::class);
|
||||
@ -342,8 +345,10 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
if ($clienteId != -1) {
|
||||
$result->hide('cliente');
|
||||
$result->hide('creditoAsegurado');
|
||||
$result->hide('estado');
|
||||
$result->hide('estado_pago');
|
||||
if(!$dataForClienteForm){
|
||||
$result->hide('estado');
|
||||
$result->hide('estado_pago');
|
||||
}
|
||||
$result->hide('forma_pago');
|
||||
$result->hide('vencimiento');
|
||||
$result->hide('dias_vencimiento');
|
||||
@ -352,6 +357,11 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
return $result->toJson(returnAsObject: true);
|
||||
}
|
||||
|
||||
public function getDatosFacturacionClienteForm($cliente_id){
|
||||
|
||||
return $this->respond($this->model->getSumatoriosFacturacionCliente($cliente_id));
|
||||
}
|
||||
|
||||
|
||||
public function datatablePedidos()
|
||||
{
|
||||
|
||||
@ -8,6 +8,8 @@ use App\Models\Collection;
|
||||
use App\Models\Pedidos\PedidoModel;
|
||||
use App\Services\PedidoXMLService;
|
||||
use App\Services\ProductionService;
|
||||
use Hermawan\DataTables\DataTable;
|
||||
use CodeIgniter\I18n\Time;
|
||||
|
||||
class Pedido extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
@ -34,6 +36,7 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("App.menu_pedidos"), 'route' => "javascript:void(0);", 'active' => false],
|
||||
];
|
||||
helper("time");
|
||||
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
@ -371,6 +374,73 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
public function tablaClienteForm()
|
||||
{
|
||||
|
||||
$clienteId = $this->request->getGet('cliente_id') ?? -1;
|
||||
|
||||
$q = $this->model->getPedidosClienteForm($clienteId);
|
||||
|
||||
/*$searchValue = $this->request->getGet('fecha') ?? '';
|
||||
if (!empty($searchValue)) {
|
||||
// Extraer las fechas del formato "YYYY-MM-DD|YYYY-MM-DD"
|
||||
$dates = explode('|', $searchValue);
|
||||
if (count($dates) == 2) {
|
||||
$q->where('created_at >=', $dates[0] . ' 00:00:00')
|
||||
->where('created_at <=', $dates[1] . ' 23:59:59');
|
||||
}
|
||||
}
|
||||
$searchValue = $this->request->getGet('fecha_entrega') ?? '';
|
||||
if (!empty($searchValue)) {
|
||||
// Extraer las fechas del formato "YYYY-MM-DD|YYYY-MM-DD"
|
||||
$dates = explode('|', $searchValue);
|
||||
if (count($dates) == 2) {
|
||||
$q->where('fecha_entrega_real >=', $dates[0] . ' 00:00:00')
|
||||
->where('fecha_entrega_real <=', $dates[1] . ' 23:59:59');
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
$result = DataTable::of($q)
|
||||
->edit(
|
||||
'fecha',
|
||||
fn($q) => $q->fecha?Time::createFromFormat("Y-m-d H:i:s", $q->fecha)->format("d/m/Y"):""
|
||||
)
|
||||
->edit(
|
||||
'fecha_entrega',
|
||||
fn($q) => $q->fecha_entrega?Time::createFromFormat("Y-m-d H:i:s", $q->fecha_entrega)->format("d/m/Y"):""
|
||||
)
|
||||
->edit(
|
||||
"estado",
|
||||
function ($row, $meta) {
|
||||
switch ($row->estado) {
|
||||
case "validacion":
|
||||
return lang('Pedidos.validacion');
|
||||
case "produccion":
|
||||
return lang('Pedidos.produccion');
|
||||
case "finalizado":
|
||||
return lang('Pedidos.finalizado');
|
||||
case "enviado":
|
||||
return lang('Pedidos.enviado');
|
||||
case "cancelado":
|
||||
return lang('Pedidos.cancelado');
|
||||
default:
|
||||
return '--'; // Debug
|
||||
}
|
||||
}
|
||||
)
|
||||
->add("action", callback: function ($q) {
|
||||
return '
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a href="javascript:void(0);"><i class="ti ti-eye ti-sm btn-edit mx-2" data-id="' . $q->id . '"></i></a>
|
||||
</div>
|
||||
';
|
||||
|
||||
});
|
||||
|
||||
return $result->toJson(returnAsObject: true) ;
|
||||
}
|
||||
|
||||
|
||||
public function obtenerPedidosForFacturas(){
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
@ -74,6 +74,9 @@ return [
|
||||
"ejemplares" => "Ejemplares",
|
||||
"addPago" => "Añadir Pago",
|
||||
"facturaPagada" => "Factura rectificativa ya abonada",
|
||||
|
||||
"acumuladoFacturacion" => "Acumulado Facturación",
|
||||
"totalPendientePago" => "Pendiente de pago",
|
||||
|
||||
'errors' => [
|
||||
'requiredFields' => 'Los campos marcados con * son obligatorios',
|
||||
|
||||
@ -82,6 +82,10 @@ return [
|
||||
|
||||
'showTotal' => 'Mostrar totales',
|
||||
|
||||
'pedidosImpresion' => 'Pedidos impresión',
|
||||
'pedidosMaquetacion' => 'Pedidos maquetación',
|
||||
'pedidosTotal' => 'Total en pedidos',
|
||||
|
||||
'validation' => [
|
||||
'errorCantidadAlbaranes' => 'Total en albaranes {0} no coincide con la tirada {1}',
|
||||
|
||||
|
||||
@ -145,6 +145,40 @@ class FacturaModel extends \App\Models\BaseModel
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public function getSumatoriosFacturacionCliente($cliente_id = -1){
|
||||
|
||||
if($cliente_id == -1){
|
||||
return [
|
||||
'total_facturacion' => 0,
|
||||
'total_pendiente' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
$data = $this->db->table('facturas f')
|
||||
->select('sum(f.total) as total')
|
||||
->where('f.cliente_id', $cliente_id)
|
||||
->where('f.deleted_at IS NULL')
|
||||
->where('f.estado', 'validada')
|
||||
->get()
|
||||
->getResultObject();
|
||||
$result['total_facturacion'] =
|
||||
round(floatval(($data && $data[0]->total != null) ? $data[0]->total : 0), 2);
|
||||
|
||||
$data = $this->db->table('facturas f')
|
||||
->select('sum(f.pendiente) as pendiente')
|
||||
->where('f.cliente_id', $cliente_id)
|
||||
->where('f.deleted_at IS NULL')
|
||||
->where('f.estado', 'validada')
|
||||
->where('f.estado_pago', 'pendiente')
|
||||
->get()
|
||||
->getResultObject();
|
||||
$result['total_pendiente'] =
|
||||
round(floatval(($data && $data[0]->pendiente != null) ? $data[0]->pendiente : 0), 2);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get resource data for creating PDFs.
|
||||
|
||||
@ -232,6 +232,21 @@ class PedidoModel extends \App\Models\BaseModel
|
||||
return $presupuesto_ficheros;
|
||||
}
|
||||
|
||||
|
||||
public function getPedidosClienteForm($cliente_id = -1){
|
||||
$builder = $this->db
|
||||
->table($this->table . " p")
|
||||
->select('p.id, p.created_at as fecha, p.fecha_entrega_real as fecha_entrega,
|
||||
pr.paginas as paginas, p.total_tirada, p.total_precio, p.estado')
|
||||
->join('pedidos_linea pl', 'pl.pedido_id = p.id', 'left')
|
||||
->join('presupuestos pr', 'pr.id = pl.presupuesto_id', 'left')
|
||||
//->where('pr.deleted_at IS NULL')
|
||||
->where('pr.cliente_id', $cliente_id)
|
||||
->orderBy('p.created_at', 'DESC')
|
||||
->groupBy('p.id');
|
||||
return $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una orden de trabajo asociada al pedido
|
||||
*
|
||||
|
||||
@ -56,19 +56,7 @@
|
||||
<li class="nav-item">
|
||||
<button
|
||||
type="button"
|
||||
class="nav-link"
|
||||
role="tab"
|
||||
data-bs-toggle="tab"
|
||||
data-bs-target="#facturacion"
|
||||
aria-controls="facturacion"
|
||||
aria-selected="false">
|
||||
Facturación
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button
|
||||
type="button"
|
||||
class="nav-link"
|
||||
class="nav-link pedidos-btn"
|
||||
role="tab"
|
||||
data-bs-toggle="tab"
|
||||
data-bs-target="#pedidos"
|
||||
@ -77,6 +65,18 @@
|
||||
Pedidos
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button
|
||||
type="button"
|
||||
class="nav-link facturacion-btn"
|
||||
role="tab"
|
||||
data-bs-toggle="tab"
|
||||
data-bs-target="#facturacion"
|
||||
aria-controls="facturacion"
|
||||
aria-selected="false">
|
||||
Facturación
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button
|
||||
type="button"
|
||||
@ -646,11 +646,11 @@
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="facturacion" role="tabpanel">
|
||||
<h3>Proximanente</h3>
|
||||
<?= view("themes/vuexy/form/clientes/cliente/_facturacionClienteItems") ?>
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="pedidos" role="tabpanel">
|
||||
<h3>Proximanente</h3>
|
||||
<?= view("themes/vuexy/form/clientes/cliente/_pedidosClienteItems") ?>
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="usuarios" role="tabpanel">
|
||||
@ -910,7 +910,6 @@ const actionBtns_add = function(data) {
|
||||
`;
|
||||
};
|
||||
|
||||
|
||||
function saveAdd_callback(){
|
||||
if($('#addressForm').attr('action')=='create'){
|
||||
editorAddress
|
||||
@ -1127,9 +1126,11 @@ function delete_direccion_envio(dataId){
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/datatables-editor/editor.bootstrap5.min.css') ?>">
|
||||
<link rel="stylesheet" href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.css") ?>">
|
||||
<link rel="stylesheet" href="<?= site_url("/themes/vuexy/vendor/libs/datatables-bs5/datatables.bootstrap5.css") ?>">
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.css') ?>" />
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
<?= $this->section('additionalExternalJs') ?>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.js') ?>"></script>
|
||||
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/dataTables.buttons.min.js") ?>"></script>
|
||||
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.js") ?>"></script>
|
||||
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.html5.min.js") ?>"></script>
|
||||
@ -1138,6 +1139,7 @@ function delete_direccion_envio(dataId){
|
||||
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/pdfmake.min.js") ?>" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/vfs_fonts.js") ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/js/datatables-editor/dataTables.editor.min.js') ?>"></script>
|
||||
<script type="module" src="<?= site_url("assets/js/safekat/pages/cliente/clienteFacturacion.js") ?>"></script>
|
||||
<?=$this->endSection() ?>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><?= $boxTitle ?? $pageTitle ?></h3>
|
||||
</div><!--//.card-header -->
|
||||
<form id="clienteForm" method="post" class="card-body" action="<?= $formAction ?>">
|
||||
<form id="clienteForm" data-cliente="<?=$clienteEntity->id?>" method="post" class="card-body" action="<?= $formAction ?>">
|
||||
<?= csrf_field() ?>
|
||||
<div class="card-body">
|
||||
<?= view("themes/_commonPartialsBs/_alertBoxes") ?>
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import ClassSelect from '../../components/select2.js';
|
||||
import tarifasClienteView from './tarifasCliente.js';
|
||||
import ClienteUsuarios from './clienteUsuarios.js';
|
||||
import ClienteFacturacion from './clienteFacturacion.js';
|
||||
import ClientePedidos from './clientePedidos.js';
|
||||
|
||||
import Ajax from '../../components/ajax.js';
|
||||
|
||||
@ -23,6 +25,13 @@ class Cliente {
|
||||
|
||||
init() {
|
||||
|
||||
AutoNumeric.multiple('.autonumeric-currency-totales',
|
||||
{ decimalPlaces: 2,
|
||||
currencySymbol: '€',
|
||||
currencySymbolPlacement: 's',
|
||||
digitGroupSeparator: '.',
|
||||
decimalCharacter: ',' });
|
||||
|
||||
// Fuerza el foco en el campo de búsqueda de select2
|
||||
$(document).on('select2:open', () => {
|
||||
document.querySelector('.select2-search__field').focus();
|
||||
@ -55,12 +64,16 @@ class Cliente {
|
||||
}
|
||||
});
|
||||
|
||||
(new ClienteFacturacion()).init();
|
||||
(new ClientePedidos()).init();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
|
||||
const dropdown = document.querySelector(".dropdown-language");
|
||||
const activeItem = dropdown.querySelector(".dropdown-menu .dropdown-item");
|
||||
let locale = 'es';
|
||||
@ -68,7 +81,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
locale = activeItem.getAttribute("data-language");
|
||||
}
|
||||
|
||||
new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['ClienteContactos', 'ClientePrecios'] }, {},
|
||||
new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['ClienteContactos', 'ClientePrecios', 'datePicker'] }, {},
|
||||
function(translations) {
|
||||
window.language = JSON.parse(translations);
|
||||
new Cliente().init();
|
||||
|
||||
Reference in New Issue
Block a user