mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando
This commit is contained in:
@ -632,6 +632,12 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function (
|
||||
$routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
$routes->group('albaranes', ['namespace' => 'App\Controllers\Pedidos'], function ($routes) {
|
||||
$routes->post('add', 'Albaran::add', ['as' => 'crearAlbaranesPedido']);
|
||||
});
|
||||
$routes->resource('albaranes', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Albaran', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
|
||||
$routes->group(
|
||||
'printpresupuestos',
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Facturacion;
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
|
||||
class Albaran extends BaseController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo 'Albaran';
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
63
ci4/app/Controllers/Pedidos/Albaran.php
Normal file
63
ci4/app/Controllers/Pedidos/Albaran.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Pedidos;
|
||||
use App\Models\Pedidos\AlbaranModel;
|
||||
|
||||
|
||||
class Albaran extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
protected $modelName = AlbaranModel::class;
|
||||
protected $format = 'json';
|
||||
|
||||
protected static $singularObjectNameCc = 'albaran';
|
||||
protected static $singularObjectName = 'Albaran';
|
||||
protected static $pluralObjectName = 'Albaranes';
|
||||
protected static $controllerSlug = 'albaran';
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function delete($id = null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
$user = auth()->user()->id;
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
$pedido_id = $reqData['pedido_id'] ?? 0;
|
||||
$presupuestos_id = $reqData['presupuestos_id'] ?? 0;
|
||||
|
||||
$return_data = $this->model->generarAlbaranes($pedido_id, $presupuestos_id, $user);
|
||||
$data = [
|
||||
'data' => $return_data,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
|
||||
return $this->respond($data);
|
||||
|
||||
}
|
||||
else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
$this->viewData['pageTitle'] = lang('Tarifaextra.moduleTitle');
|
||||
$this->viewData['pageTitle'] = lang('Pedidos.moduleTitle');
|
||||
// Se indica que este controlador trabaja con soft_delete
|
||||
|
||||
$this->viewData = ['usingServerSideDataTable' => true];
|
||||
|
||||
46
ci4/app/Entities/Pedidos/AlbaranEntity.php
Normal file
46
ci4/app/Entities/Pedidos/AlbaranEntity.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace App\Entities\Pedidos;
|
||||
|
||||
use CodeIgniter\Entity;
|
||||
|
||||
class AlbaranEntity extends \CodeIgniter\Entity\Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
'id' => null,
|
||||
'pedido_id' => null,
|
||||
'presupuesto_id' => null,
|
||||
'presupuesto_direccion_id' => null,
|
||||
'cliente_id' => null,
|
||||
'serie_id' => null,
|
||||
'numero_albaran' => null,
|
||||
'mostar_precios' => null,
|
||||
'total' => null,
|
||||
'direccion_albaran' => null,
|
||||
'att_albaran' => null,
|
||||
'user_created_id' => null,
|
||||
'user_updated_id' => null,
|
||||
'created_at' => null,
|
||||
'updated_at' => null,
|
||||
'deleted_at' => null,
|
||||
];
|
||||
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'pedido_id' => '?integer',
|
||||
'presupuesto_id' => '?integer',
|
||||
'presupuesto_direccion_id' => '?integer',
|
||||
'cliente_id' => '?integer',
|
||||
'serie_id' => '?integer',
|
||||
'numero_albaran' => '?string',
|
||||
'mostar_precios' => '?boolean',
|
||||
'total' => 'float',
|
||||
'direccion_albaran' => '?string',
|
||||
'att_albaran' => '?string',
|
||||
'user_created_id' => 'integer',
|
||||
'user_updated_id' => 'integer',
|
||||
];
|
||||
|
||||
// Agrega tus métodos personalizados aquí
|
||||
}
|
||||
33
ci4/app/Entities/Pedidos/AlbaranLineaEntity.php
Normal file
33
ci4/app/Entities/Pedidos/AlbaranLineaEntity.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace App\Entities\Pedidos;
|
||||
|
||||
use CodeIgniter\Entity;
|
||||
|
||||
class AlbaranLineaEntity extends \CodeIgniter\Entity\Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
'id' => null,
|
||||
'albaran_id' => null,
|
||||
'titulo' => null,
|
||||
'isbn' => null,
|
||||
'ref_cliente' => null,
|
||||
'cantidad' => null,
|
||||
'cajas' => null,
|
||||
'ejemplares_por_caja' => null,
|
||||
'precio_unidad' => null,
|
||||
'total' => null,
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'albaran_id' => '?integer',
|
||||
'titulo' => 'string',
|
||||
'isbn' => '?string',
|
||||
'ref_cliente' => '?string',
|
||||
'cantidad' => '?integer',
|
||||
'cajas' => '?integer',
|
||||
'ejemplares_por_caja' => '?integer',
|
||||
'precio_unidad' => 'float',
|
||||
'total' => 'float',
|
||||
];
|
||||
}
|
||||
@ -58,6 +58,8 @@ return [
|
||||
],
|
||||
|
||||
'albaranes' => 'Delivery Notes',
|
||||
'generarAlbaranes' => 'Generate delivery notes',
|
||||
'borrarAlbaranes' => 'Delete delivery notes',
|
||||
|
||||
'facturas' => 'Invoices',
|
||||
|
||||
|
||||
@ -57,6 +57,8 @@ return [
|
||||
],
|
||||
|
||||
'albaranes' => 'Albaranes',
|
||||
'generarAlbaranes' => 'Generar albaranes',
|
||||
'borrarAlbaranes' => 'Borrar albaranes',
|
||||
|
||||
'facturas' => 'Facturas',
|
||||
|
||||
|
||||
34
ci4/app/Models/Pedidos/AlbaranLineaModel.php
Normal file
34
ci4/app/Models/Pedidos/AlbaranLineaModel.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Pedidos;
|
||||
|
||||
class AlbaranLineaModel extends \App\Models\BaseModel
|
||||
{
|
||||
protected $table = "albaranes_lineas";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
protected $returnType = 'App\Entities\Pedidos\AlbaranLineaEntity';
|
||||
protected $allowedFields = [
|
||||
'albaran_id',
|
||||
'titulo',
|
||||
'isbn',
|
||||
'ref_cliente',
|
||||
'cantidad',
|
||||
'cajas',
|
||||
'ejemplares_por_caja',
|
||||
'precio_unidad',
|
||||
'total',
|
||||
];
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
}
|
||||
103
ci4/app/Models/Pedidos/AlbaranModel.php
Normal file
103
ci4/app/Models/Pedidos/AlbaranModel.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Pedidos;
|
||||
|
||||
class AlbaranModel extends \App\Models\BaseModel
|
||||
{
|
||||
protected $table = "albaranes";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
protected $returnType = 'App\Entities\Pedidos\AlbaranEntity';
|
||||
protected $allowedFields = [
|
||||
'pedido_id',
|
||||
'presupuesto_id',
|
||||
'presupuesto_direccion_id',
|
||||
'cliente_id',
|
||||
'serie_id',
|
||||
'numero_albaran',
|
||||
'mostar_precios',
|
||||
'total',
|
||||
'direccion_albaran',
|
||||
'att_albaran',
|
||||
'user_created_id',
|
||||
'user_updated_id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
public function generarAlbaranes($pedido_id, $presupuestos_id, $user_id){
|
||||
|
||||
$model_presupuesto = model('App\Models\Presupuestos\PresupuestoModel');
|
||||
$model_presupuesto_direcciones = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
||||
$model_series = model('App\Models\Configuracion\SeriesFacturasModel');
|
||||
|
||||
$presupuestos = $model_presupuesto->find($presupuestos_id);
|
||||
|
||||
foreach ($presupuestos as $presupuesto) {
|
||||
|
||||
$envios = $model_presupuesto_direcciones->where('presupuesto_id', $presupuesto->id)->findAll();
|
||||
foreach($envios as $envio){
|
||||
|
||||
// calculo precio_unidad
|
||||
$precio_unidad = $presupuesto->total_aceptado/$presupuesto->tirada;
|
||||
|
||||
$albaran_linea = [];
|
||||
$albaran_linea = array(
|
||||
'titulo' => $presupuesto->titulo,
|
||||
'isbn' => $presupuesto->isbn,
|
||||
'ref_cliente' => $presupuesto->ref_cliente,
|
||||
'cantidad' => $envio->cantidad,
|
||||
'cajas' => 1,
|
||||
'ejemplares_por_caja' => $envio->cantidad,
|
||||
'precio_unidad' => $precio_unidad,
|
||||
'total' => $precio_unidad * $envio->cantidad
|
||||
);
|
||||
|
||||
|
||||
$serie = $model_series->find(11);
|
||||
$numero_albaran = str_replace($serie->next, 'number', $serie->formato);
|
||||
$numero_albaran = str_replace(date("Y"), 'year', $numero_albaran);
|
||||
|
||||
$serie->next = $serie->next + 1;
|
||||
$model_series->save($serie);
|
||||
|
||||
$albaran = array(
|
||||
'pedido_id' => $pedido_id,
|
||||
'presupuesto_id' => $presupuesto->id,
|
||||
'presupuesto_direccion_id' => $envio->id,
|
||||
'cliente_id' => $presupuesto->cliente_id,
|
||||
'serie_id' => 11, // Serie de albaranes
|
||||
'numero_albaran' => $numero_albaran,
|
||||
'mostar_precios' => 0,
|
||||
'total' => $albaran_linea['total'],
|
||||
'direccion_albaran' => $envio->direccion,
|
||||
'att_albaran' => $envio->att,
|
||||
'created_at' => date("Y-m-d H:i:s"),
|
||||
'updated_at' => date("Y-m-d H:i:s"),
|
||||
'user_created_id' => $user_id,
|
||||
'user_updated_id' => $user_id
|
||||
);
|
||||
|
||||
$id_albaran = $this->insert($albaran);
|
||||
$model_albaran_linea = model('App\Models\Pedidos\AlbaranLineaModel');
|
||||
$model_albaran_linea->insert($albaran_linea);
|
||||
|
||||
return $id_albaran;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,18 @@
|
||||
<div id="accordionAlbaranesTip" class="accordion-collapse collapse show" data-bs-parent="#accordioAlbaranes">
|
||||
<div class="accordion-body">
|
||||
|
||||
|
||||
<div class="col-12 d-flex flex-row-reverse mt-4 gap-2">
|
||||
<div id="generar_albaranes" class="btn mt-3 btn-success waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.generarAlbaranes') ?></span>
|
||||
<i class="ti ti-player-play ti-xs"></i>
|
||||
</div>
|
||||
|
||||
<div id="borrar_albaranes" class="btn mt-3 btn-danger waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.borrarAlbaranes') ?></span>
|
||||
<i class="ti ti-trash ti-xs"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> <!-- /.accordion-body -->
|
||||
</div>
|
||||
@ -19,6 +31,24 @@
|
||||
|
||||
<?=$this->section('additionalInlineJs') ?>
|
||||
|
||||
$('#generar_albaranes').on('click', function(){
|
||||
|
||||
var lineasPedido = $('#tableOfLineasPedido').DataTable();
|
||||
var presupuestos = lineasPedido.column(0).data().unique().toArray();
|
||||
|
||||
$.ajax({
|
||||
url: '<?= route_to('crearAlbaranesPedido') ?>',
|
||||
type: 'POST',
|
||||
data: {
|
||||
pedido_id: <?= $pedidoEntity->id ?>,
|
||||
presupuestos_id: presupuestos,
|
||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
||||
},
|
||||
success: function(response){
|
||||
console.log(response);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
@ -13,8 +13,9 @@
|
||||
<table id="tableOfLineasPedido" class="table table-striped table-hover" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th><?= lang('Pedidos.presupuesto') ?></th>
|
||||
<th><?=lang('Pedidos.unidades')?></th>
|
||||
<th><?= lang('Pedidos.unidades')?></th>
|
||||
<th><?= lang('Pedidos.concepto') ?></th>
|
||||
<th><?= lang('Pedidos.total') ?></th>
|
||||
</tr>
|
||||
@ -25,7 +26,7 @@
|
||||
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="4" style="text-align:right">Total:</th>
|
||||
<th colspan="5" style="text-align:right">Total:</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
@ -37,7 +38,6 @@
|
||||
|
||||
<?=$this->section('additionalInlineJs') ?>
|
||||
|
||||
const lastColNr = $('#tableOfLineasPedido').find("tr:first th").length - 1;
|
||||
const viewPresupuestoBtns = function(data) {
|
||||
return `
|
||||
<td class="text-right py-0 align-middle">
|
||||
@ -55,7 +55,7 @@ var tableOfLineasPedido = new DataTable('#tableOfLineasPedido',{
|
||||
scrollX: true,
|
||||
searchable: false,
|
||||
info: false,
|
||||
dom: '',
|
||||
dom: 't',
|
||||
language: {
|
||||
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
||||
},
|
||||
@ -68,19 +68,8 @@ var tableOfLineasPedido = new DataTable('#tableOfLineasPedido',{
|
||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||
async: true,
|
||||
}),
|
||||
columnDefs: [
|
||||
{
|
||||
targets: 0,
|
||||
orderable: false,
|
||||
data: null,
|
||||
defaultContent: ''
|
||||
},
|
||||
{
|
||||
targets: [1,2,3],
|
||||
orderable: false,
|
||||
},
|
||||
],
|
||||
columns: [
|
||||
{data: 'numero'},
|
||||
{
|
||||
data: viewPresupuestoBtns,
|
||||
className: 'dt-center'
|
||||
@ -89,6 +78,24 @@ var tableOfLineasPedido = new DataTable('#tableOfLineasPedido',{
|
||||
{data: 'concepto'},
|
||||
{data: 'total'},
|
||||
],
|
||||
columnDefs: [
|
||||
{
|
||||
targets: 0,
|
||||
visible: false,
|
||||
orderable: false,
|
||||
searchable: false
|
||||
},
|
||||
{
|
||||
targets: 1,
|
||||
orderable: false,
|
||||
data: null,
|
||||
defaultContent: ''
|
||||
},
|
||||
{
|
||||
targets: [2,3,4],
|
||||
orderable: false,
|
||||
},
|
||||
],
|
||||
footerCallback: function (row, data, start, end, display) {
|
||||
let api = this.api();
|
||||
|
||||
@ -103,14 +110,14 @@ var tableOfLineasPedido = new DataTable('#tableOfLineasPedido',{
|
||||
|
||||
// Total over all pages
|
||||
total = api
|
||||
.column(3)
|
||||
.column(4)
|
||||
.data()
|
||||
.reduce((a, b) => intVal(a) + intVal(b), 0);
|
||||
|
||||
// Update footer
|
||||
api.column(3).footer().innerHTML =
|
||||
api.column(4).footer().innerHTML =
|
||||
'Total: ' + total;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user