/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $lineas = $request->input('lineas'); $factura = $request->input('factura'); $fac = Factura::find($factura); if ($lineas != null && $fac->pendiente == 1) { foreach ($lineas as $linea) { if ($linea[0] == "") { $tarifa = new TarifaServicios(); $tarifa->concepto = $linea[2]; $tarifa->importe = $linea[4]; $tarifa->codigo = $linea[1]; $tarifa->tipo = 1; $tarifa->save(); // id $l = new LineaFactura(); $l->GC_Tarifa_servicios_id = $tarifa->id; $l->GC_Factura_id = $factura; $l->cantidad = $linea[3]; $l->save(); } else { $l = new LineaFactura(); $l->GC_Tarifa_servicios_id = $linea[0]; $l->GC_Factura_id = $factura; $l->cantidad = $linea[3]; $l->save(); } $fac->pendiente = 0; $fac->save(); } $iva = Iva2::first(); $iva = $iva->tipo; $aux = VLinea::select(\DB::raw('sum(importe * cantidad) as total'))->where('factura', $factura)->get()[0]; $total = $aux->total; $fac->update(['base' => $total, 'iva' => $total * ($iva / 100), 'total' => $total + $total * ($iva / 100)]); } }
function nuevoservicio(Request $r) { $servicio = new TarifaServicios(); $servicio->concepto = $r->input('concepto'); $servicio->codigo = $r->input('codigo'); $servicio->importe = $r->input('importe'); $servicio->tipo = 0; //TARIFA PREDEFINIDA - LAS QUE CREAS TU PA SIEMPRE $servicio->save(); echo $servicio->id; }