mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadiendo linea factura
This commit is contained in:
@ -657,6 +657,8 @@ $routes->group('facturas', ['namespace' => 'App\Controllers\Facturacion'], funct
|
|||||||
$routes->get('edit/(:any)', 'Facturas::edit/$1', ['as' => 'editarFactura']);
|
$routes->get('edit/(:any)', 'Facturas::edit/$1', ['as' => 'editarFactura']);
|
||||||
$routes->post('update/(:any)', 'Facturas::update/$1', ['as' => 'actualizarFactura']);
|
$routes->post('update/(:any)', 'Facturas::update/$1', ['as' => 'actualizarFactura']);
|
||||||
$routes->post('datatable/(:any)', 'FacturasLineas::datatable/$1', ['as' => 'dataTableOfLineasFacturas']);
|
$routes->post('datatable/(:any)', 'FacturasLineas::datatable/$1', ['as' => 'dataTableOfLineasFacturas']);
|
||||||
|
$routes->post('menuPedidosPendientes/(:num)', 'Facturas::menuPedidosPendientes/$1', ['as' => 'menuPedidosPendientesImpresion']);
|
||||||
|
$routes->post('addLineaPedidoImpresion/(:num)', 'Facturas::addLineaPedidoImpresion/$1', ['as' => 'addLineaPedidoImpresion2Factura']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -287,6 +287,62 @@ class Facturas extends \App\Controllers\BaseResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function menuPedidosPendientes($cliente_id){
|
||||||
|
|
||||||
|
if ($this->request->isAJAX()) {
|
||||||
|
$model = model('\App\Models\Pedidos\PedidoLineaModel');
|
||||||
|
|
||||||
|
$pedidos = [];
|
||||||
|
try{
|
||||||
|
$pedidos = $model->obtenerLineasPedidoSinFacturar($cliente_id);
|
||||||
|
}
|
||||||
|
catch(Exception $e){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$newTokenHash = csrf_hash();
|
||||||
|
$csrfTokenName = csrf_token();
|
||||||
|
$data = [
|
||||||
|
'menu' => $pedidos,
|
||||||
|
$csrfTokenName => $newTokenHash
|
||||||
|
];
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $this->failUnauthorized('Invalid request', 403);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function addLineaPedidoImpresion($factura_id){
|
||||||
|
|
||||||
|
if ($this->request->isAJAX()) {
|
||||||
|
$model_pedido_linea = model('\App\Models\Pedidos\PedidoLineaModel');
|
||||||
|
$model_presupuesto = model('\App\Models\Pedidos\PedidoLineaModel');
|
||||||
|
$model_factura_linea = model('\App\Models\Facturas\FacturaLineaModel');
|
||||||
|
|
||||||
|
$pedido_linea_id = $this->request->getPost('lineaPedido') ?? 0;
|
||||||
|
|
||||||
|
$linea = $model_pedido_linea->find($pedido_linea_id);
|
||||||
|
if($linea){
|
||||||
|
$presupuesto = $model_presupuesto->find($linea->presupuesto_id);
|
||||||
|
if($presupuesto){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$newTokenHash = csrf_hash();
|
||||||
|
$csrfTokenName = csrf_token();
|
||||||
|
$data = [
|
||||||
|
$csrfTokenName => $newTokenHash
|
||||||
|
];
|
||||||
|
return $this->respond($data);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $this->failUnauthorized('Invalid request', 403);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************
|
/*************************************
|
||||||
* FUNCIONES AUXILIARES
|
* FUNCIONES AUXILIARES
|
||||||
************************************/
|
************************************/
|
||||||
|
|||||||
@ -20,11 +20,13 @@ class Test extends BaseController
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$model = new PresupuestoModel();
|
|
||||||
$data = $model->generarLineaPedido(123);
|
$model = model("\App\Models\Pedidos\PedidoLineaModel");
|
||||||
echo '<pre>';
|
$data = $model->obtenerLineasPedidoSinFacturar(999);
|
||||||
|
|
||||||
|
echo('<pre>');
|
||||||
var_dump($data);
|
var_dump($data);
|
||||||
echo '</pre>';
|
echo('</pre>');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,4 +76,40 @@ class PedidoLineaModel extends \App\Models\BaseModel
|
|||||||
->orLike("t1.id", $search)
|
->orLike("t1.id", $search)
|
||||||
->groupEnd();
|
->groupEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function obtenerLineasPedidoSinFacturar($cliente_id){
|
||||||
|
|
||||||
|
$resultaArray = [];
|
||||||
|
|
||||||
|
$builder = $this->db
|
||||||
|
->table($this->table . " t1")
|
||||||
|
->select("t1.id AS id, t1.pedido_id AS pedido_id, t3.titulo AS titulo, t4.codigo AS tipo_impresion");
|
||||||
|
|
||||||
|
$builder->join("pedidos t2", "t2.id = t1.pedido_id", "left");
|
||||||
|
$builder->join("presupuestos t3", "t3.id = t1.presupuesto_id", "left");
|
||||||
|
$builder->join("tipos_presupuestos t4", "t4.id = t3.tipo_impresion_id", "left");
|
||||||
|
|
||||||
|
$builder->join("facturas_pedidos_lineas fpl", "fpl.pedido_linea_id = t1.id", "left");
|
||||||
|
|
||||||
|
$builder->where("t3.cliente_id", $cliente_id);
|
||||||
|
$builder->where("t2.estado", "finalizado");
|
||||||
|
|
||||||
|
|
||||||
|
$builder->where("(`t3`.`tirada` > `fpl`.`cantidad` OR fpl.pedido_linea_id IS NULL)");
|
||||||
|
|
||||||
|
// Ejecutar la consulta y devolver resultados
|
||||||
|
$query = $builder->get();
|
||||||
|
$data = $query->getResult();
|
||||||
|
|
||||||
|
foreach($data as $register){
|
||||||
|
$item = (object)[
|
||||||
|
'id' => $register->id,
|
||||||
|
'text' => '['. lang('Pedidos.pedido') . ' ' . $register->pedido_id . '] ' . $register->titulo . ' - ' . lang('Presupuestos.' . $register->tipo_impresion),
|
||||||
|
];
|
||||||
|
array_push($resultaArray, $item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $resultaArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -75,9 +75,54 @@
|
|||||||
$('#pedidoImpresion').select2({
|
$('#pedidoImpresion').select2({
|
||||||
placeholder: "<?= lang('Facturas.pedidoImpresion') ?>",
|
placeholder: "<?= lang('Facturas.pedidoImpresion') ?>",
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
width: '100%'
|
ajax: {
|
||||||
|
url: '<?= route_to("menuPedidosPendientesImpresion", $facturaEntity->cliente_id) ?>',
|
||||||
|
type: 'post',
|
||||||
|
dataType: 'json',
|
||||||
|
|
||||||
|
data: function (params) {
|
||||||
|
return {
|
||||||
|
id: 'id',
|
||||||
|
text: 'nombre',
|
||||||
|
searchTerm: params.term,
|
||||||
|
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
||||||
|
};
|
||||||
|
},
|
||||||
|
delay: 60,
|
||||||
|
processResults: function (response) {
|
||||||
|
|
||||||
|
yeniden(response.<?= csrf_token() ?>);
|
||||||
|
|
||||||
|
return {
|
||||||
|
results: response.menu
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
cache: true
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#addNewPedidoImpresion').on('click', function(){
|
||||||
|
var lineaPedido = $('#pedidoImpresion').val();
|
||||||
|
if(lineaPedido == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: '<?= route_to("addLineaPedidoImpresion2Factura", $facturaEntity->id) ?>',
|
||||||
|
type: 'post',
|
||||||
|
data: {
|
||||||
|
lineaPedido: lineaPedido,
|
||||||
|
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
yeniden(response.<?= csrf_token() ?>);
|
||||||
|
$('#lineaPedido').val(null).trigger('change');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$('#pedidoMaquetacion').select2({
|
$('#pedidoMaquetacion').select2({
|
||||||
placeholder: "<?= lang('Facturas.pedidoMaquetacion') ?>",
|
placeholder: "<?= lang('Facturas.pedidoMaquetacion') ?>",
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user