mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
falta mostrar precios albaran
This commit is contained in:
@ -58,8 +58,15 @@ return [
|
||||
],
|
||||
|
||||
'albaranes' => 'Delivery Notes',
|
||||
'albaran' => 'Delivery Note',
|
||||
'generarAlbaranes' => 'Generate delivery notes',
|
||||
'borrarAlbaranes' => 'Delete delivery notes',
|
||||
'att' => "Att",
|
||||
'direccion' => 'Address',
|
||||
'borrarAlbaran' => 'Delete delivery note',
|
||||
'imprimirAlbaran' => 'Print',
|
||||
'nuevaLinea' => 'New line',
|
||||
'addIva' => "Add VAT",
|
||||
|
||||
'facturas' => 'Invoices',
|
||||
|
||||
|
||||
@ -57,8 +57,15 @@ return [
|
||||
],
|
||||
|
||||
'albaranes' => 'Albaranes',
|
||||
'albaran' => 'Albarán',
|
||||
'generarAlbaranes' => 'Generar albaranes',
|
||||
'borrarAlbaranes' => 'Borrar albaranes',
|
||||
'att' => "Att",
|
||||
'direccion' => 'Direccion',
|
||||
'borrarAlbaran' => 'Borrar albarán',
|
||||
'imprimirAlbaran' => 'Imprimir',
|
||||
'nuevaLinea' => 'Nueva línea',
|
||||
'addIva' => "Añadir IVA",
|
||||
|
||||
'facturas' => 'Facturas',
|
||||
|
||||
|
||||
@ -26,9 +26,5 @@ class AlbaranLineaModel extends \App\Models\BaseModel
|
||||
'precio_unidad',
|
||||
'total',
|
||||
];
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
}
|
||||
@ -45,6 +45,8 @@ class AlbaranModel extends \App\Models\BaseModel
|
||||
|
||||
$presupuestos = $model_presupuesto->find($presupuestos_id);
|
||||
|
||||
$return_data = [];
|
||||
|
||||
foreach ($presupuestos as $presupuesto) {
|
||||
|
||||
$envios = $model_presupuesto_direcciones->where('presupuesto_id', $presupuesto->id)->findAll();
|
||||
@ -54,7 +56,7 @@ class AlbaranModel extends \App\Models\BaseModel
|
||||
$precio_unidad = $presupuesto->total_aceptado/$presupuesto->tirada;
|
||||
|
||||
$albaran_linea = [];
|
||||
$albaran_linea = array(
|
||||
$albaran_linea = [
|
||||
'titulo' => $presupuesto->titulo,
|
||||
'isbn' => $presupuesto->isbn,
|
||||
'ref_cliente' => $presupuesto->ref_cliente,
|
||||
@ -63,17 +65,17 @@ class AlbaranModel extends \App\Models\BaseModel
|
||||
'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);
|
||||
$numero_albaran = str_replace('{number}', $serie->next, $serie->formato);
|
||||
$numero_albaran = str_replace( '{year}', date("Y"), $numero_albaran);
|
||||
|
||||
$serie->next = $serie->next + 1;
|
||||
$model_series->save($serie);
|
||||
|
||||
$albaran = array(
|
||||
$albaran = [
|
||||
'pedido_id' => $pedido_id,
|
||||
'presupuesto_id' => $presupuesto->id,
|
||||
'presupuesto_direccion_id' => $envio->id,
|
||||
@ -84,20 +86,22 @@ class AlbaranModel extends \App\Models\BaseModel
|
||||
'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
|
||||
);
|
||||
'user_updated_id' => $user_id,
|
||||
'fecha_albaran' => date('d/m/Y'),
|
||||
];
|
||||
|
||||
$id_albaran = $this->insert($albaran);
|
||||
$model_albaran_linea = model('App\Models\Pedidos\AlbaranLineaModel');
|
||||
$model_albaran_linea->insert($albaran_linea);
|
||||
$albaran['id'] = $id_albaran;
|
||||
$albaran_linea['albaran_id'] = $id_albaran;
|
||||
$id_albaran_linea =$model_albaran_linea->insert($albaran_linea);
|
||||
$albaran_linea['id'] = $id_albaran_linea;
|
||||
|
||||
return $id_albaran;
|
||||
array_push($return_data, ["albaran"=>$albaran, "albaran_linea" =>$albaran_linea]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return $return_data;
|
||||
}
|
||||
}
|
||||
@ -8,10 +8,10 @@
|
||||
</h2>
|
||||
|
||||
<div id="accordionAlbaranesTip" class="accordion-collapse collapse show" data-bs-parent="#accordioAlbaranes">
|
||||
<div class="accordion-body">
|
||||
<div class="accordion-body">
|
||||
|
||||
|
||||
<div class="col-12 d-flex flex-row-reverse mt-4 gap-2">
|
||||
<div id="bonotes_albaranes" 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>
|
||||
@ -45,10 +45,376 @@ $('#generar_albaranes').on('click', function(){
|
||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
||||
},
|
||||
success: function(response){
|
||||
console.log(response);
|
||||
|
||||
if(response.data.length > 0){
|
||||
Object.values(response.data).forEach(function(item){
|
||||
generarAlbaran(item);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
const deleteLineaBtns = function(data) {
|
||||
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-trash ti-sm btn-delete mx-2" data-id="${data.id}"></i></a>
|
||||
</div>
|
||||
</td>`;
|
||||
};
|
||||
|
||||
function generarAlbaran(item){
|
||||
|
||||
// Crear los elementos necesarios
|
||||
const accordion = $('<div>', {
|
||||
class: 'accordion accordion-bordered mt-3',
|
||||
id: 'albaran' + item.albaran_linea.id
|
||||
});
|
||||
|
||||
const card = $('<div>', {
|
||||
class: 'card accordion-item active'
|
||||
});
|
||||
|
||||
const header = $('<h2>', {
|
||||
class: 'accordion-header',
|
||||
id: 'headingAlbaran' + item.albaran_linea.id
|
||||
});
|
||||
|
||||
const button = $('<button>', {
|
||||
type: 'button',
|
||||
class: 'accordion-button',
|
||||
'data-bs-toggle': 'collapse',
|
||||
'data-bs-target': '#accordionAlbaranesTip' + item.albaran_linea.id,
|
||||
'aria-expanded': 'false',
|
||||
'aria-controls': 'accordionAlbaranesTip' + item.albaran_linea.id,
|
||||
}).css({
|
||||
'background-color': '#F0F8FF'
|
||||
});
|
||||
|
||||
const h3 = $('<h5>').html(item.albaran.numero_albaran);
|
||||
|
||||
const collapseDiv = $('<div>', {
|
||||
id: 'accordionAlbaranTip' + item.albaran_linea.id,
|
||||
class: 'accordion-collapse collapse show',
|
||||
'data-bs-parent': '#accordioAlbaran' + item.albaran_linea.id
|
||||
});
|
||||
|
||||
const body = $('<div>', {
|
||||
class: 'accordion-body'
|
||||
});
|
||||
|
||||
const cabecera =
|
||||
`
|
||||
<div class="col-12 d-flex justify-content-between mb-3">
|
||||
<div class="col-6 d-flex flex-row">
|
||||
<div class="col-2">
|
||||
<label><?= lang('Pedidos.fecha') ?>:</label>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<label>${item.albaran.fecha_albaran}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6 d-flex flex-row-reverse">
|
||||
<div class="col-2">
|
||||
<label style="text-align: right; display:block">${item.albaran.pedido_id}</label>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<label style="text-align: right"><?= lang('Pedidos.pedido') ?>:</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 d-flex justify-content-between mb-3">
|
||||
<div class="col-6 d-flex flex-row">
|
||||
<div class="col-2">
|
||||
<label><?= lang('Pedidos.cliente') ?>:</label>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label>${$('#cliente').val()}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6 d-flex flex-row-reverse">
|
||||
<div class="col-2">
|
||||
<label style="text-align: right; display:block">${item.albaran.numero_albaran}</label>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<label style="text-align: right"><?= lang('Pedidos.albaran') ?>:</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 d-flex justify-content-between mb-3">
|
||||
<div class="col-1">
|
||||
<label><?= lang('Pedidos.att') ?>:</label>
|
||||
</div>
|
||||
<div class="col-11">
|
||||
<input id="att_" + ${item.albaran.id} value=${item.albaran.att_albaran} class="form-control"></input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 d-flex justify-content-between mb-3">
|
||||
<div class="col-1">
|
||||
<label><?= lang('Pedidos.direccion') ?>:</label>
|
||||
</div>
|
||||
<div class="col-11">
|
||||
<input id="att_" + ${item.albaran.id} value=${item.albaran.direccion_albaran} class="form-control"></input>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const table = $('<table>',
|
||||
{ id: 'tablaAlbaran' + item.albaran_linea.id, width:'100%', class: 'table table-responsive table-striped table-hover' })
|
||||
.css({
|
||||
'width': '100%',
|
||||
}).append(
|
||||
$('<thead>').append(
|
||||
$('<tr>').append(
|
||||
$('<th>').css({'max-width':'20px'}),
|
||||
$('<th>'),
|
||||
$('<th>', { class:'lp-header', scope: 'col' }).css({'font-size':'smaller'}).text('Unidades'),
|
||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('Título'),
|
||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('ISBN'),
|
||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('Ref. Cliente'),
|
||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('Cajas'),
|
||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('Ej./Cajas'),
|
||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('€/u'),
|
||||
$('<th>', { class:'lp-header',scope: 'col' }).css({'font-size':'smaller'}).text('Subtotal')
|
||||
)
|
||||
),
|
||||
$('<tbody>'),
|
||||
$('<tfoot>').append(
|
||||
$('<tr>').append(
|
||||
$('<th>', { colspan: '5', style: 'text-align:right' }).text('')
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
const botones_albaran =
|
||||
`
|
||||
<div id="bonotes_albaran" + ${item.albaran.id} class="col-12 d-flex flex-row-reverse mt-4 gap-2">
|
||||
<div id="borrar_albaran" + ${item.albaran.id} class="btn mt-3 button-albaran btn-label-danger waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.borrarAlbaran') ?></span>
|
||||
<i class="ti ti-trash ti-xs"></i>
|
||||
</div>
|
||||
|
||||
<div id="borrar_albaran" + ${item.albaran.id} class="btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.imprimirAlbaran') ?></span>
|
||||
<i class="ti ti-printer ti-xs"></i>
|
||||
</div>
|
||||
<div id="nueva_linea_albaran" + ${item.albaran.id} class="btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.nuevaLinea') ?></span>
|
||||
<i class="ti ti-plus ti-xs"></i>
|
||||
</div>
|
||||
<div id="add_iva_albaran" + ${item.albaran.id} class="btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.addIva') ?></span>
|
||||
<i class="ti ti-plus ti-xs"></i>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Armar la estructura
|
||||
button.append(h3);
|
||||
header.append(button);
|
||||
card.append(header);
|
||||
collapseDiv.append(body);
|
||||
body.append(cabecera);
|
||||
body.append(table);
|
||||
body.append(botones_albaran);
|
||||
card.append(collapseDiv);
|
||||
accordion.append(card);
|
||||
|
||||
// Agregar el elemento al accordioAlbaranes
|
||||
$('#bonotes_albaranes').before(accordion);
|
||||
|
||||
|
||||
|
||||
const datatableAlbaran = new DataTable('#tablaAlbaran' + item.albaran_linea.id,{
|
||||
scrollX: true,
|
||||
searching: false,
|
||||
paging: false,
|
||||
info: false,
|
||||
ordering: false,
|
||||
responsive: true,
|
||||
select: false,
|
||||
dom: 't',
|
||||
language: {
|
||||
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
||||
},
|
||||
columns: [
|
||||
{ data: 'id'},
|
||||
{
|
||||
data: deleteLineaBtns,
|
||||
className: 'dt-center'
|
||||
},
|
||||
{
|
||||
data: 'cantidad',
|
||||
render: function ( data, type, row, meta ) {
|
||||
|
||||
var input = $('<input>', {
|
||||
id: 'unidades_' + item.albaran_linea.id,
|
||||
name: 'unidades_' + item.albaran_linea.id,
|
||||
class: 'lp-cell lp-input albaran_linea',
|
||||
albaran: item.albaran.numero_albaran,
|
||||
type: 'text',
|
||||
value: data
|
||||
}).css({
|
||||
'text-align': 'center',
|
||||
'font-size': 'smaller',
|
||||
'max-width': '50px'
|
||||
});
|
||||
return input.prop('outerHTML');
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'titulo',
|
||||
render: function ( data, type, row, meta ) {
|
||||
|
||||
var input = $('<input>', {
|
||||
id: 'titulo_' + item.albaran_linea.id,
|
||||
name: 'titulo_' + item.albaran_linea.id,
|
||||
class: 'lp-cell lp-input albaran_linea',
|
||||
albaran: item.albaran.numero_albaran,
|
||||
type: 'text',
|
||||
value: data
|
||||
}).css({
|
||||
'text-align': 'center',
|
||||
'font-size': 'smaller',
|
||||
'min-width': '300px'
|
||||
});
|
||||
return input.prop('outerHTML');
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'isbn',
|
||||
render: function ( data, type, row, meta ) {
|
||||
|
||||
var input = $('<input>', {
|
||||
id: 'isbn_' + item.albaran_linea.id,
|
||||
name: 'isbn_' + item.albaran_linea.id,
|
||||
class: 'lp-cell lp-input albaran_linea',
|
||||
albaran: item.albaran.numero_albaran,
|
||||
type: 'text',
|
||||
value: data
|
||||
}).css({
|
||||
'text-align': 'center',
|
||||
'font-size': 'smaller'
|
||||
});
|
||||
return input.prop('outerHTML');
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'ref_cliente',
|
||||
render: function ( data, type, row, meta ) {
|
||||
|
||||
var input = $('<input>', {
|
||||
id: 'ref_cliente_' + item.albaran_linea.id,
|
||||
name: 'ref_cliente_' + item.albaran_linea.id,
|
||||
class: 'lp-cell lp-input albaran_linea',
|
||||
albaran: item.albaran.numero_albaran,
|
||||
type: 'text',
|
||||
value: data
|
||||
}).css({
|
||||
'text-align': 'center',
|
||||
'font-size': 'smaller'
|
||||
});
|
||||
return input.prop('outerHTML');
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'cajas',
|
||||
render: function ( data, type, row, meta ) {
|
||||
|
||||
var input = $('<input>', {
|
||||
id: 'cajas_' + item.albaran_linea.id,
|
||||
name: 'cajas_' + item.albaran_linea.id,
|
||||
class: 'lp-cell lp-input albaran_linea',
|
||||
albaran: item.albaran.numero_albaran,
|
||||
type: 'text',
|
||||
value: data
|
||||
}).css({
|
||||
'text-align': 'center',
|
||||
'font-size': 'smaller',
|
||||
'max-width': '50px'
|
||||
});
|
||||
return input.prop('outerHTML');
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'ejemplares_por_caja',
|
||||
render: function ( data, type, row, meta ) {
|
||||
|
||||
var input = $('<input>', {
|
||||
id: 'ejemplares_por_caja_' + item.albaran_linea.id,
|
||||
name: 'ejemplares_por_caja_' + item.albaran_linea.id,
|
||||
class: 'lp-cell lp-input albaran_linea',
|
||||
albaran: item.albaran.numero_albaran,
|
||||
type: 'text',
|
||||
value: data
|
||||
}).css({
|
||||
'text-align': 'center',
|
||||
'font-size': 'smaller',
|
||||
'max-width': '50px'
|
||||
});
|
||||
return input.prop('outerHTML');
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'precio_unidad',
|
||||
render: function ( data, type, row, meta ) {
|
||||
|
||||
value = parseFloat(data).toFixed(4);
|
||||
var input = $('<input>', {
|
||||
id: 'precio_unidad_' + item.albaran_linea.id,
|
||||
name: 'precio_unidad_' + item.albaran_linea.id,
|
||||
class: 'lp-cell lp-input albaran_linea',
|
||||
albaran: item.albaran.numero_albaran,
|
||||
type: 'text',
|
||||
value: value
|
||||
}).css({
|
||||
'text-align': 'center',
|
||||
'font-size': 'smaller',
|
||||
'max-width': '50px'
|
||||
});
|
||||
return input.prop('outerHTML');
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'total',
|
||||
render: function ( data, type, row, meta ) {
|
||||
|
||||
var input = $('<input>', {
|
||||
id: 'total_' + item.albaran_linea.id,
|
||||
name: 'total_' + item.albaran_linea.id,
|
||||
class: 'lp-cell lp-input albaran_linea',
|
||||
albaran: item.albaran.numero_albaran,
|
||||
type: 'text',
|
||||
value: data
|
||||
}).css({
|
||||
'text-align': 'center',
|
||||
'font-size': 'smaller',
|
||||
'max-width': '50px'
|
||||
});
|
||||
return input.prop('outerHTML');
|
||||
}
|
||||
}
|
||||
|
||||
],
|
||||
columnDefs: [
|
||||
{ targets: [0], visible: false, searchable: false },
|
||||
{ targets: [1], orderable: false },
|
||||
{ targets: [2, 3, 4, 5, 6, 7, 8, 9], className: 'dt-center' }
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
/*var nuevaFila = [
|
||||
item.algunDato1, // Reemplaza estos valores con los datos reales de tu objeto
|
||||
item.algunDato2,
|
||||
// Añade tantos elementos como columnas tenga tu tabla
|
||||
];*/
|
||||
|
||||
// Añadir la nueva fila a la tabla
|
||||
datatableAlbaran.row.add(item.albaran_linea).draw();
|
||||
|
||||
|
||||
}
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
@ -33,6 +33,7 @@
|
||||
<?=$this->section('css') ?>
|
||||
<link rel="stylesheet" href="<?= site_url("/themes/vuexy/vendor/libs/flatpickr/flatpickr.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/css/sk-datatables.css') ?>">
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
<?= $this->section('additionalExternalJs') ?>
|
||||
|
||||
Reference in New Issue
Block a user