function getdeuda($residencia_id, $mes, $año) { $maestra = json_decode(File::get(app_path("config/maestra.php")), true); $total = Facturas::wherenull("residencia_id")->where("mes", "=", $mes)->where("año", "=", $año)->where("porcentual", "=", 1)->sum('monto') * (Residencias::find($residencia_id)->alicuota / 100); $total += Facturas::wherenull("residencia_id")->where("mes", "=", $mes)->where("año", "=", $año)->where("porcentual", "=", 0)->sum('monto') / Residencias::where("id", "<>", "1")->count(); $total += Facturas::where("residencia_id", "=", $residencia_id)->where("mes", "=", $mes)->where("año", "=", $año)->sum('monto'); if ($maestra['is_fondo']) { $total += $total * ($maestra['fondo_%'] / 100); } return $total; }