mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en el form de cliente
This commit is contained in:
@ -323,6 +323,7 @@ $routes->group('clientes', ['namespace' => 'App\Controllers\Clientes'], function
|
||||
/* Cliente */
|
||||
$routes->group('cliente', ['namespace' => 'App\Controllers\Clientes'], function ($routes) {
|
||||
$routes->get('', 'Cliente::index', ['as' => 'clienteList']);
|
||||
$routes->get('edit/(:num)', 'Cliente::edit/$1', ['as' => 'editarCliente']);
|
||||
$routes->match(['get', 'post'], 'add', 'Cliente::add', ['as' => 'clienteAdd']);
|
||||
$routes->match(['get', 'post'], 'edit/(:num)', 'Cliente::edit/$1', ['as' => 'clienteEdit']);
|
||||
$routes->get('delete/(:num)', 'Cliente::delete/$1', ['as' => 'clienteDelete']);
|
||||
@ -596,7 +597,7 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function (
|
||||
$routes->post('datatable', 'Pedido::datatable', ['as' => 'dataTableOfPedidos']);
|
||||
$routes->get('add', 'Pedido::add', ['as' => 'nuevoPedido']);
|
||||
$routes->post('add', 'Pedido::add', ['as' => 'crearPedido']);
|
||||
$routes->post('edit/(:num)', 'Pedido::edit/$1', ['as' => 'editarPedido']);
|
||||
$routes->get('edit/(:any)', 'Pedido::edit/$1', ['as' => 'editarPedido']);
|
||||
});
|
||||
$routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
@ -79,7 +79,25 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
|
||||
public function edit($id=null){
|
||||
echo "Edit";
|
||||
|
||||
if ($id == null) :
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($id, FILTER_SANITIZE_URL);
|
||||
$pedidoEntity = $this->model->find($id);
|
||||
|
||||
if ($pedidoEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.pedido')), $id]);
|
||||
return $this->redirect2listView('sweet-error', $message);
|
||||
endif;
|
||||
|
||||
$this->obtenerDatosFormulario($pedidoEntity);
|
||||
|
||||
$this->viewData['pedidoEntity'] = $pedidoEntity;
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Pedidos.moduleTitle') . ' ' . lang('Basic.global.edit3');
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
}
|
||||
|
||||
public function datatable(){
|
||||
@ -96,7 +114,7 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
$length = $reqData['length'] ?? 5;
|
||||
$search = $reqData['search']['value'];
|
||||
$requestedOrder = $reqData['order']['0']['column'] ?? 0;
|
||||
$order = PedidoModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
|
||||
$order = PedidoModel::SORTABLE_TODOS[$requestedOrder >= 0 ? $requestedOrder : 0];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
|
||||
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
@ -111,5 +129,19 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
private function obtenerDatosFormulario(&$pedidoEntity){
|
||||
|
||||
$pedidoLineaModel = model('\App\Models\Pedidos\PedidoLineaModel');
|
||||
$clienteModel = model('\App\Models\Clientes\ClienteModel');
|
||||
$presupuestoModel = model('\App\Models\Presupuestos\PresupuestoModel');
|
||||
|
||||
$linea = $pedidoLineaModel->where('pedido_id', $pedidoEntity->id)->first();
|
||||
// los clientes son los mismos para todas las lineas de un mismo presupuesto
|
||||
$presupuesto = $presupuestoModel->find($linea->presupuesto_id);
|
||||
$cliente = $clienteModel->find($presupuesto->cliente_id);
|
||||
|
||||
$pedidoEntity->cliente = $cliente->nombre;
|
||||
$pedidoEntity->cliente_id = $cliente->id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ use Exception;
|
||||
|
||||
use function PHPUnit\Framework\containsOnly;
|
||||
|
||||
|
||||
class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
protected $modelName = "PresupuestoModel";
|
||||
@ -787,6 +788,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
if ($confirmar) {
|
||||
$model_presupuesto->confirmarPresupuesto($id);
|
||||
$this->crearPedido($id);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
@ -889,6 +891,44 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
* Funciones auxiliares
|
||||
*
|
||||
**********************/
|
||||
public function crearPedido($presupuesto_id)
|
||||
{
|
||||
$model_pedido = model('App\Models\Pedidos\PedidoModel');
|
||||
$model_pedido_linea = model('App\Models\Pedidos\PedidoLineaModel');
|
||||
$model_cliente = model('App\Models\Clientes\ClienteModel');
|
||||
|
||||
$model_presupuesto = new PresupuestoModel();
|
||||
$datos_presupuesto = $model_presupuesto->find($presupuesto_id);
|
||||
|
||||
$id_linea = 0;
|
||||
|
||||
$data_pedido = [
|
||||
'total_precio' => $datos_presupuesto->total_aceptado,
|
||||
'total_tirada' => $datos_presupuesto->tirada,
|
||||
'estado' => $model_cliente->creditoDisponible($datos_presupuesto->cliente_id) ? "produccion" : "validacion",
|
||||
'user_created_id' => auth()->user()->id,
|
||||
'user_updated_id' => auth()->user()->id,
|
||||
];
|
||||
|
||||
$pedido_id = $model_pedido->insert($data_pedido);
|
||||
if($pedido_id){
|
||||
$data_pedido_linea = [
|
||||
"pedido_id" => $pedido_id,
|
||||
"presupuesto_id" => $presupuesto_id,
|
||||
"ubicacion_id" => 1, // safetak por defecto
|
||||
"user_created_id" => auth()->user()->id,
|
||||
"user_updated_id" => auth()->user()->id,
|
||||
];
|
||||
$id_linea = $model_pedido_linea->insert($data_pedido_linea);
|
||||
}
|
||||
|
||||
if($id_linea != 0 && $pedido_id != 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected function borrarRelacionesPresupuesto($id)
|
||||
{
|
||||
// Se borran las lineas de presupuesto
|
||||
|
||||
@ -15,6 +15,12 @@ return [
|
||||
'tiradas' => 'Print Runs',
|
||||
'total_presupuesto' => 'Total Budget',
|
||||
'estado' => 'Status',
|
||||
|
||||
'validacion' => 'Validation',
|
||||
'produccion' => 'Production',
|
||||
'finalizado' => 'Finished',
|
||||
'enviado' => 'Sent',
|
||||
'cancelado' => 'Cancelled',
|
||||
|
||||
'moduleTitle' => 'Orders',
|
||||
'pedido' => 'Order',
|
||||
|
||||
@ -15,6 +15,12 @@ return [
|
||||
'total_presupuesto' => 'Total',
|
||||
'estado' => 'Estado',
|
||||
|
||||
'validacion' => 'Validación',
|
||||
'produccion' => 'Producción',
|
||||
'finalizado' => 'Finalizado',
|
||||
'enviado' => 'Enviado',
|
||||
'cancelado' => 'Cancelado',
|
||||
|
||||
'moduleTitle' => 'Pedidos',
|
||||
'pedido' => 'Pedido',
|
||||
'pedidos' => 'Pedidos',
|
||||
|
||||
@ -308,4 +308,11 @@ class ClienteModel extends \App\Models\BaseModel
|
||||
->orLike("t7.nombre", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
/*
|
||||
TO-DO: Implementar la lógica de negocio para el crédito disponible
|
||||
*/
|
||||
public function creditoDisponible($cliente_id){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ class PedidoModel extends \App\Models\BaseModel
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
|
||||
const SORTABLE_TODOS = [
|
||||
0 => "t1.id",
|
||||
1 => "t1.updated_at",
|
||||
@ -53,7 +53,7 @@ class PedidoModel extends \App\Models\BaseModel
|
||||
|
||||
public static $labelField = "id";
|
||||
|
||||
public function getResource(string $search = "", $tarifa_envio_id = -1)
|
||||
public function getResource(string $search = "", $estado="")
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
@ -71,6 +71,11 @@ class PedidoModel extends \App\Models\BaseModel
|
||||
$builder->join("users t5", "t5.id = t4.comercial_id", "left");
|
||||
$builder->join("ubicaciones t6", "t6.id = t2.ubicacion_id", "left");
|
||||
|
||||
if($estado != "") {
|
||||
$builder->where("t1.estado", $estado);
|
||||
}
|
||||
|
||||
// Falta implementar la busqueda por grupos
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
|
||||
44
ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php
Normal file
44
ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php
Normal file
@ -0,0 +1,44 @@
|
||||
<div class="accordion accordion-bordered mt-3" id="cabeceraPedido">
|
||||
<div class="card accordion-item active">
|
||||
<h2 class="accordion-header" id="headingOne">
|
||||
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionPedidoTip" aria-expanded="false" aria-controls="accordionPedidoTip">
|
||||
<h4><?= lang("Pedidos.pedido") ?></h4>
|
||||
</button>
|
||||
</h2>
|
||||
|
||||
<div id="accordionPedidoTip" class="accordion-collapse collapse show" data-bs-parent="#accordioPedido">
|
||||
<div class="accordion-body">
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-12 col-lg-2 px-4">
|
||||
|
||||
<div class="mb-1">
|
||||
<label for="paginas" class="form-label">
|
||||
<?= lang('Pedidos.id') ?>
|
||||
</label>
|
||||
<input readonly id="id" name="id" tabindex="1" maxLength="11" class="form-control" value="<?= old('id', $pedidoEntity->id) ?>" >
|
||||
</div>
|
||||
</div><!--//.mb-3 -->
|
||||
|
||||
<div class="col-md-12 col-lg-3 px-4">
|
||||
<div class="mb-1">
|
||||
<label for="paginas" class="form-label">
|
||||
<?= lang('Pedidos.cliente') ?>
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a href="<?= route_to('editarCliente', $pedidoEntity->cliente_id); ?>" target="_blank" ><i class="ti ti-eye ti-sm btn-edit mx-2" data-id="${data.id}"></i></a>
|
||||
</div>
|
||||
</label>
|
||||
<input readonly id="cliente" name="cliente" tabindex="2" maxLength="11" class="form-control" value="<?= old('id', $pedidoEntity->cliente) ?>" >
|
||||
|
||||
|
||||
</div>
|
||||
</div><!--//.mb-3 -->
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
27
ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php
Normal file
27
ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?= $this->include("themes/_commonPartialsBs/datatables") ?>
|
||||
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
|
||||
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
|
||||
<?=$this->extend('themes/vuexy/main/defaultlayout') ?>
|
||||
|
||||
<?= $this->section("content") ?>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card card-info">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><?= $boxTitle ?? $pageTitle ?></h3>
|
||||
</div><!--//.card-header -->
|
||||
<form id="pedidoForm" method="post" class="card-body" action="<?= $formAction ?>">
|
||||
<?= csrf_field() ?>
|
||||
<div class="card-body">
|
||||
<?= view("themes/_commonPartialsBs/_alertBoxes") ?>
|
||||
<?= !empty($validation->getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?>
|
||||
<?= view("themes/vuexy/form/pedidos/_cabeceraItems") ?>
|
||||
</div><!-- /.card-body -->
|
||||
<div class="pt-4">
|
||||
<?= anchor(route_to("listaPresupuestos"), lang("Basic.global.Cancel"), ["class" => "btn btn-secondary float-start"]) ?>
|
||||
</div><!-- /.card-footer -->
|
||||
</form>
|
||||
</div><!-- //.card -->
|
||||
</div><!--//.col -->
|
||||
</div><!--//.row -->
|
||||
<?= $this->endSection() ?>
|
||||
@ -52,7 +52,7 @@
|
||||
return `
|
||||
<td class="text-right py-0 align-middle">
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a>
|
||||
<a href="javascript:void(0);"><i class="ti ti-eye ti-sm btn-edit mx-2" data-id="${data.id}"></i></a>
|
||||
</div>
|
||||
</td>`;
|
||||
};
|
||||
@ -104,10 +104,39 @@
|
||||
{ 'data': 'titulo' },
|
||||
{ 'data': 'ubicacion' },
|
||||
{ 'data': 'inc_rei' },
|
||||
{ 'data': 'num_paginas' },
|
||||
{ 'data': 'tiradas' },
|
||||
{ 'data': 'paginas' },
|
||||
{ 'data': 'tirada' },
|
||||
{ 'data': 'total_presupuesto' },
|
||||
{ 'data': 'estado' },
|
||||
{ 'data': 'estado',
|
||||
render: function(data, type, row, meta) {
|
||||
switch(data){
|
||||
case "validacion":
|
||||
return '<?= lang('Pedidos.validacion') ?>';
|
||||
break;
|
||||
|
||||
case "produccion":
|
||||
return '<?= lang('Pedidos.produccion') ?>';
|
||||
break;
|
||||
|
||||
case "finalizado":
|
||||
return '<?= lang('Pedidos.finalizado') ?>';
|
||||
break;
|
||||
|
||||
case "enviado":
|
||||
return '<?= lang('Pedidos.enviado') ?>';
|
||||
break;
|
||||
|
||||
case "cancelado":
|
||||
return '<?= lang('Pedidos.cancelado') ?>';
|
||||
break;
|
||||
|
||||
default:
|
||||
return data; // Debug
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
{ 'data': actionBtns }
|
||||
]
|
||||
});
|
||||
@ -123,7 +152,9 @@
|
||||
|
||||
|
||||
$(document).on('click', '.btn-edit', function(e) {
|
||||
window.location.href = `/pedidos/edit/${$(this).attr('data-id')}`;
|
||||
var url = '<?= route_to('editarPedido', ':id') ?>';
|
||||
url = url.replace(':id', `${$(this).attr('data-id')}` );
|
||||
window.location.href = url;
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user