mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminado el flujo completo de facturas, incluyendo cambio en el texto de pedidos y facturas cuando no tiene factura validada
This commit is contained in:
@ -707,7 +707,7 @@ class Facturas extends \App\Controllers\BaseResourceController
|
|||||||
|
|
||||||
$data = (object) [
|
$data = (object) [
|
||||||
'factura_id' => $factura_id,
|
'factura_id' => $factura_id,
|
||||||
'pedido_linea_impresion_id' => $linea->pedido_id,
|
'pedido_linea_impresion_id' => $pedido_linea_id,
|
||||||
'descripcion' => $descripcion[0]->concepto,
|
'descripcion' => $descripcion[0]->concepto,
|
||||||
'cantidad' => $cantidad,
|
'cantidad' => $cantidad,
|
||||||
'iva' => $presupuesto->iva_reducido == 1 ? 4 : 21,
|
'iva' => $presupuesto->iva_reducido == 1 ? 4 : 21,
|
||||||
|
|||||||
@ -366,6 +366,36 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
PresupuestoService::crearPedido($id);
|
PresupuestoService::crearPedido($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// modificar los datos del pedido y de la factura si no está la factura validada
|
||||||
|
if ($presupuestoEntity->estado_id == 2){
|
||||||
|
$facturaModel = model('App\Models\Facturas\FacturaModel');
|
||||||
|
if(!$facturaModel->presupuestoHasFacturaValidada($id)){
|
||||||
|
// se actualiza primero el pedido
|
||||||
|
$pedidoModel = model('App\Models\Pedidos\PedidoLineaModel');
|
||||||
|
$pedidoLineaId = $pedidoModel->where('presupuesto_id', $id)->first()->id;
|
||||||
|
$linea_pedido = $this->model->generarLineaPedido($id)[0];
|
||||||
|
$idPedido = $pedidoModel->join('pedidos', 'pedidos_linea.pedido_id = pedidos.id')
|
||||||
|
->where('pedidos_linea.presupuesto_id', $id)
|
||||||
|
->first()->pedido_id;
|
||||||
|
$pedidoModel->update($pedidoLineaId, [
|
||||||
|
'cantidad' => $linea_pedido->unidades,
|
||||||
|
'descripcion' => $linea_pedido->concepto
|
||||||
|
]);
|
||||||
|
|
||||||
|
// se actualiza la factura
|
||||||
|
$linea_pedido = $this->model->generarLineaPedido($id, true, $idPedido)[0];
|
||||||
|
$facturaLineaModel = model('App\Models\Facturas\FacturaLineaModel');
|
||||||
|
$facturaLineaId = $facturaLineaModel->where('pedido_linea_impresion_id', $pedidoLineaId)->
|
||||||
|
where('deleted_at', null)->first()->id;
|
||||||
|
$facturaLineaModel->update($facturaLineaId, [
|
||||||
|
'cantidad' => $linea_pedido->unidades,
|
||||||
|
'descripcion' => $linea_pedido->concepto
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$newTokenHash = csrf_hash();
|
$newTokenHash = csrf_hash();
|
||||||
$csrfTokenName = csrf_token();
|
$csrfTokenName = csrf_token();
|
||||||
$data = [
|
$data = [
|
||||||
|
|||||||
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Database\Migrations;
|
||||||
|
|
||||||
|
use CodeIgniter\Database\Migration;
|
||||||
|
use CodeIgniter\Database\RawSql;
|
||||||
|
|
||||||
|
class AddCantidadConceptoPedidoLinea extends Migration
|
||||||
|
{
|
||||||
|
protected array $USER_COLUMNS = [
|
||||||
|
"cantidad" => [
|
||||||
|
"type" => "INT",
|
||||||
|
"unsigned" => true,
|
||||||
|
"constraint" => 10,
|
||||||
|
"null" => true,
|
||||||
|
],
|
||||||
|
'descripcion' => [
|
||||||
|
'type' => 'TEXT',
|
||||||
|
"null" => true,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$this->forge->addColumn("pedidos_linea", $this->USER_COLUMNS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$this->forge->dropColumn("pedidos_linea", array_keys($this->USER_COLUMNS));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,6 +16,8 @@ class PedidoLineaEntity extends \CodeIgniter\Entity\Entity
|
|||||||
"user_updated_id" => null,
|
"user_updated_id" => null,
|
||||||
"created_at" => null,
|
"created_at" => null,
|
||||||
"updated_at" => null,
|
"updated_at" => null,
|
||||||
|
"cantidad" => null,
|
||||||
|
"descripcion" => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -23,6 +25,7 @@ class PedidoLineaEntity extends \CodeIgniter\Entity\Entity
|
|||||||
"pedido_id" => "int",
|
"pedido_id" => "int",
|
||||||
"presupuesto_id" => "int",
|
"presupuesto_id" => "int",
|
||||||
"ubicacion_id" => "int",
|
"ubicacion_id" => "int",
|
||||||
|
"cantidad" => "int",
|
||||||
];
|
];
|
||||||
public function ubicacion() : UbicacionesEntity
|
public function ubicacion() : UbicacionesEntity
|
||||||
{
|
{
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
|||||||
t1.pedido_linea_impresion_id AS pedido_linea_impresion_id, t1.pedido_maquetacion_id AS pedido_maquetacion_id,
|
t1.pedido_linea_impresion_id AS pedido_linea_impresion_id, t1.pedido_maquetacion_id AS pedido_maquetacion_id,
|
||||||
t1.descripcion AS descripcion, t1.cantidad as cantidad, t1.iva AS iva,
|
t1.descripcion AS descripcion, t1.cantidad as cantidad, t1.iva AS iva,
|
||||||
t1.base AS base, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data, t2.pedido_id AS pedido_id,
|
t1.base AS base, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data, t2.pedido_id AS pedido_id,
|
||||||
t3.total_aceptado AS total_aceptado, t4.tirada_flexible AS tirada_flexible, t4.descuento_tirada_flexible AS descuento_tirada_flexible,
|
t3.total_aceptado_revisado AS total_aceptado, t4.tirada_flexible AS tirada_flexible, t4.descuento_tirada_flexible AS descuento_tirada_flexible,
|
||||||
t6.cantidad AS cantidad_albaran"
|
t6.cantidad AS cantidad_albaran"
|
||||||
)
|
)
|
||||||
->join("pedidos_linea t2", "t2.id = t1.pedido_linea_impresion_id", "left")
|
->join("pedidos_linea t2", "t2.id = t1.pedido_linea_impresion_id", "left")
|
||||||
|
|||||||
@ -145,6 +145,27 @@ class FacturaModel extends \App\Models\BaseModel
|
|||||||
return $builder;
|
return $builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function presupuestoHasFacturaValidada($presupuesto_id = null)
|
||||||
|
{
|
||||||
|
if ($presupuesto_id == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->db->table($this->table . " t1")
|
||||||
|
->select("t1.id")
|
||||||
|
->join("facturas_lineas t2", "t2.factura_id = t1.id", "left")
|
||||||
|
->join("pedidos_linea t3", "t2.pedido_linea_impresion_id = t3.id", "left")
|
||||||
|
->where("t3.presupuesto_id", $presupuesto_id)
|
||||||
|
->where("t1.deleted_at IS NULL")
|
||||||
|
->where("t2.deleted_at IS NULL")
|
||||||
|
->where("t1.estado", "validada")
|
||||||
|
->get()
|
||||||
|
->getResultObject();
|
||||||
|
|
||||||
|
return !empty($result);
|
||||||
|
}
|
||||||
|
|
||||||
public function getSumatoriosFacturacionCliente($cliente_id = -1){
|
public function getSumatoriosFacturacionCliente($cliente_id = -1){
|
||||||
|
|
||||||
if($cliente_id == -1){
|
if($cliente_id == -1){
|
||||||
|
|||||||
@ -36,6 +36,8 @@ class PedidoLineaModel extends \App\Models\BaseModel
|
|||||||
"user_updated_id",
|
"user_updated_id",
|
||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
|
"cantidad",
|
||||||
|
"descripcion",
|
||||||
];
|
];
|
||||||
protected $returnType = "App\Entities\Pedidos\PedidoLineaEntity";
|
protected $returnType = "App\Entities\Pedidos\PedidoLineaEntity";
|
||||||
|
|
||||||
|
|||||||
@ -117,15 +117,28 @@ class PedidoModel extends \App\Models\BaseModel
|
|||||||
$builder = $this->db
|
$builder = $this->db
|
||||||
->table($this->table . " t1")
|
->table($this->table . " t1")
|
||||||
->select(
|
->select(
|
||||||
"t2.presupuesto_id"
|
"t2.presupuesto_id, t3.total_aceptado, t2.descripcion, t2.cantidad"
|
||||||
);
|
);
|
||||||
$builder->where("t1.id", $pedido_id);
|
$builder->where("t1.id", $pedido_id);
|
||||||
$builder->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left");
|
$builder->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left");
|
||||||
|
$builder->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left");
|
||||||
$model_presupuesto = model("App\Models\Presupuestos\PresupuestoModel");
|
$model_presupuesto = model("App\Models\Presupuestos\PresupuestoModel");
|
||||||
$lineasPresupuesto = [];
|
$lineasPresupuesto = [];
|
||||||
|
|
||||||
foreach ($builder->get()->getResultObject() as $row) {
|
foreach ($builder->get()->getResultObject() as $row) {
|
||||||
array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]);
|
if($row->descripcion == null){
|
||||||
|
array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$presupuesto = (object) [
|
||||||
|
'numero' => $row->presupuesto_id,
|
||||||
|
'unidades' => $row->cantidad,
|
||||||
|
'total' => $row->total_aceptado,
|
||||||
|
'concepto' => $row->descripcion,
|
||||||
|
];
|
||||||
|
array_push($lineasPresupuesto, $presupuesto);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
$builder->groupBy("t1.id");
|
$builder->groupBy("t1.id");
|
||||||
|
|
||||||
|
|||||||
@ -1885,9 +1885,12 @@ class PresupuestoService extends BaseService
|
|||||||
|
|
||||||
$pedido_id = $model_pedido->insert($data_pedido);
|
$pedido_id = $model_pedido->insert($data_pedido);
|
||||||
if ($pedido_id) {
|
if ($pedido_id) {
|
||||||
|
$lineas_pedido = $model_presupuesto->generarLineaPedido($presupuesto_id)[0];
|
||||||
$data_pedido_linea = [
|
$data_pedido_linea = [
|
||||||
"pedido_id" => $pedido_id,
|
"pedido_id" => $pedido_id,
|
||||||
"presupuesto_id" => $presupuesto_id,
|
"presupuesto_id" => $presupuesto_id,
|
||||||
|
'cantidad' => $lineas_pedido->unidades,
|
||||||
|
'descripcion' => $lineas_pedido->concepto,
|
||||||
"ubicacion_id" => 1, // safetak por defecto
|
"ubicacion_id" => 1, // safetak por defecto
|
||||||
"user_created_id" => auth()->user()->id,
|
"user_created_id" => auth()->user()->id,
|
||||||
"user_updated_id" => auth()->user()->id,
|
"user_updated_id" => auth()->user()->id,
|
||||||
|
|||||||
@ -86,7 +86,7 @@
|
|||||||
<label for="total_precio" class="form-label">
|
<label for="total_precio" class="form-label">
|
||||||
<?= lang('Pedidos.total_precio') ?>
|
<?= lang('Pedidos.total_precio') ?>
|
||||||
</label>
|
</label>
|
||||||
<input readonly id="total_precio" name="total_precio" tabindex="1" maxLength="11" class="form-control" value="<?= old('total_precio', $pedidoEntity->total_precio) ?>" >
|
<input readonly id="total_precio" name="total_precio" tabindex="1" maxLength="11" class="form-control autonumeric" value="<?= old('total_precio', $pedidoEntity->total_precio) ?>" >
|
||||||
</div>
|
</div>
|
||||||
</div><!--//.mb-3 -->
|
</div><!--//.mb-3 -->
|
||||||
|
|
||||||
@ -210,6 +210,15 @@ if(<?= $pedidoEntity->inaplazable?1:0 ?>){
|
|||||||
$('.inaplazable-date').addClass('text-danger fw-bold');
|
$('.inaplazable-date').addClass('text-danger fw-bold');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const autonumericTotalPrecio = new AutoNumeric('#total_precio', {
|
||||||
|
decimalPlaces: 2,
|
||||||
|
digitGroupSeparator: '.',
|
||||||
|
decimalCharacter: ',',
|
||||||
|
allowDecimalPadding: true,
|
||||||
|
unformatOnSubmit: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$("#fecha_entrega_real").flatpickr({
|
$("#fecha_entrega_real").flatpickr({
|
||||||
defaultDate: <?= $pedidoEntity->fecha_entrega_real_text ? "'".$pedidoEntity->fecha_entrega_real_text."'" : 'null' ?>,
|
defaultDate: <?= $pedidoEntity->fecha_entrega_real_text ? "'".$pedidoEntity->fecha_entrega_real_text."'" : 'null' ?>,
|
||||||
|
|||||||
Reference in New Issue
Block a user