mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadiendo lineas
This commit is contained in:
@ -322,12 +322,49 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
$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){
|
||||
|
||||
// Se añade la linea de factura
|
||||
$descripcion = $model_presupuesto->generarLineaPedido($presupuesto->id, true, $linea->pedido_id);
|
||||
$cantidad = intval($presupuesto->tirada) - intval($this->model->getCantidadLineaPedidoFacturada($linea->id));
|
||||
$base = $cantidad * floatval($presupuesto->total_precio_unidad);
|
||||
$total_iva = $base * ($presupuesto->iva_reducido==1 ? 0.04 : 0.21);
|
||||
// se redondea a dos decimales
|
||||
$total_iva = round($total_iva, 2);
|
||||
$total = $base + $total_iva;
|
||||
|
||||
$data = (object)[
|
||||
'factura_id'=>$factura_id,
|
||||
'pedido_linea_impresion_id'=>$linea->pedido_linea_impresion_id,
|
||||
'descripcion'=>$descripcion,
|
||||
'cantidad'=>$cantidad,
|
||||
'precio_unidad'=>$presupuesto->total_precio_unidad,
|
||||
'iva' => $presupuesto->iva_reducido==1 ? 4 : 21,
|
||||
'base' => $base,
|
||||
'total_iva' => $total_iva,
|
||||
'total' => $total,
|
||||
'user_updated_id' => auth()->user()->id,
|
||||
];
|
||||
|
||||
$model_factura_linea->insert($data);
|
||||
|
||||
$id = $model_factura_linea->getInsertID();
|
||||
|
||||
if($id){
|
||||
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'error' => 0,
|
||||
'id' => $id,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,15 +20,20 @@ class Test extends BaseController
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
/*
|
||||
$model = model("\App\Models\Pedidos\PedidoLineaModel");
|
||||
$data = $model->obtenerLineasPedidoSinFacturar(999);
|
||||
*/
|
||||
|
||||
$model = model("\App\Models\Facturas\FacturaModel");
|
||||
$data = $model->getCantidadLineaPedidoFacturada(5);
|
||||
|
||||
echo('<pre>');
|
||||
var_dump($data);
|
||||
echo('</pre>');
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function clonar_tarifa_encuadernacion($teOrigen, $teDestino){
|
||||
|
||||
Reference in New Issue
Block a user