Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Update Prisma Schema for Financial Analysis and Internal Invoicing #65

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions apps/www/src/actions/create-analyse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function createAnalysis(analysisData) {
const newAnalysis = await prisma.financialAnalysisBuilding.create({
data: {
buildingId: analysisData.buildingId,
name: analysisData.name, // Include the name field
name: analysisData.name,
rentableArea: 1000,
ratioAreaOffice: 0.5,
ratioAreaMerch: 0.3,
Expand All @@ -43,19 +43,6 @@ export async function createAnalysis(analysisData) {
sumValueNow: 1000000,
sumValueExit: 1200000,
vacancyPerYear: JSON.stringify({ "2024": "10.5", "2025": "9.8" }),
ownerCostsMethod: true,
ownerCostsManual: 50000,
costMaintenance: 10000,
costInsurance: 5000,
costRevision: 3000,
costAdm: 2000,
costOther: 1000,
costNegotiation: 2000,
costLegalFees: 1000,
costConsultFees: 1500,
costAssetMgmt: 2500,
costSum: 45000,
costBigExpenses: JSON.stringify({ "2024": "100000", "2025": "20500" }),
useCalcROI: true,
roiWeightedYield: 0.05,
roiInflation: 0.02,
Expand All @@ -73,6 +60,35 @@ export async function createAnalysis(analysisData) {
kpi2: 0,
kpi3: 0,
kpi4: 0,
costs: {
create: {
ownerCostsMethod: true,
ownerCostsManual: 50000,
costMaintenance: 10000,
costInsurance: 5000,
costRevision: 3000,
costAdm: 2000,
costOther: 1000,
costNegotiation: 2000,
costLegalFees: 1000,
costConsultFees: 1500,
costAssetMgmt: 2500,
costSum: 45000,
},
},
incomeUnits: {
create: [
{
numberOfUnits: 8,
typeDescription: "Office Space",
areaPerUnit: 125,
valuePerUnit: 62500,
totalArea: 1000,
totalValue: 500000,
},
// You can add more income units here if needed
],
},
},
})
console.log(
Expand Down
6 changes: 3 additions & 3 deletions apps/www/src/actions/get-analysis-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { prisma } from "@/lib/db"

export async function getAnalysisDetails(analysisId: string) {
try {
const numericId = parseInt(analysisId, 10)
if (isNaN(numericId)) {
if (!analysisId) {
throw new Error("Invalid analysis ID")
}

const analysisDetails = await prisma.financialAnalysisBuilding.findUnique({
where: { id: numericId },
where: { id: analysisId },
include: {
building: {
select: {
name: true,
},
},
costs: true, // Include the costs relation
},
})

Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/actions/update-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function updateAnalysis(analysisId, updateData) {

try {
const updatedAnalysis = await prisma.financialAnalysisBuilding.update({
where: { id: parseInt(analysisId, 10) },
where: { id: analysisId },
data: {
...updateData,
},
Expand Down
32 changes: 13 additions & 19 deletions apps/www/src/app/(analytics)/analytics/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ export default async function AnalysisDetailsPage({
<DashboardHeader
heading={analysisDetails.name}
text="Detaljer om analysen."
>
{/* <Button>
<Link href={`/analytics/${analysisDetails.id}/edit`}>
Rediger Analyse
</Link>
</Button> */}
</DashboardHeader>
></DashboardHeader>
<Tabs defaultValue="overview" className="w-full">
<TabsList>
<TabsTrigger value="overview">Oversikt</TabsTrigger>
Expand Down Expand Up @@ -97,18 +91,18 @@ export default async function AnalysisDetailsPage({
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
<EditOwnerCostsCard
analysisId={analysisDetails.id}
initialOwnerCostsMethod={analysisDetails.ownerCostsMethod}
initialOwnerCostsManual={analysisDetails.ownerCostsManual ?? 0}
initialCostMaintenance={analysisDetails.costMaintenance ?? 0}
initialCostInsurance={analysisDetails.costInsurance ?? 0}
initialCostRevision={analysisDetails.costRevision ?? 0}
initialCostAdm={analysisDetails.costAdm ?? 0}
initialCostOther={analysisDetails.costOther ?? 0}
initialCostNegotiation={analysisDetails.costNegotiation ?? 0}
initialCostLegalFees={analysisDetails.costLegalFees ?? 0}
initialCostConsultFees={analysisDetails.costConsultFees ?? 0}
initialCostAssetMgmt={analysisDetails.costAssetMgmt ?? 0}
initialCostSum={analysisDetails.costSum ?? 0}
initialOwnerCostsMethod={analysisDetails.costs.ownerCostsMethod}
initialOwnerCostsManual={analysisDetails.costs.ownerCostsManual}
initialCostMaintenance={analysisDetails.costs.costMaintenance}
initialCostInsurance={analysisDetails.costs.costInsurance}
initialCostRevision={analysisDetails.costs.costRevision}
initialCostAdm={analysisDetails.costs.costAdm}
initialCostOther={analysisDetails.costs.costOther}
initialCostNegotiation={analysisDetails.costs.costNegotiation}
initialCostLegalFees={analysisDetails.costs.costLegalFees}
initialCostConsultFees={analysisDetails.costs.costConsultFees}
initialCostAssetMgmt={analysisDetails.costs.costAssetMgmt}
initialCostSum={analysisDetails.costs.costSum}
/>
<EditROICard
analysisId={analysisDetails.id}
Expand Down
17 changes: 16 additions & 1 deletion apps/www/src/app/(tenant)/tenant/[id]/invoice/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,22 @@ export default async function InvoicePage({
console.error("Error in InvoicePage:", error)
return (
<DashboardShell>
<DashboardHeader heading="Error" text={error.message} />
<DashboardHeader
heading="Faktura"
text="Du må først legge til regnskapsprogram for å sende faktura."
/>
<EmptyPlaceholder>
<EmptyPlaceholder.Icon name="user" />
<EmptyPlaceholder.Title>
Legg til regnskapsprogram
</EmptyPlaceholder.Title>
<EmptyPlaceholder.Description>
Legg til regnskapsprogram for å sende faktura.
</EmptyPlaceholder.Description>
<Button variant="outline">
<Link href="/settings/import">Legg til regnskapsprogram</Link>
</Button>
</EmptyPlaceholder>
</DashboardShell>
)
}
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/analyse/EditAnalysisNameCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const FormSchema = z.object({
})

interface EditAnalysisNameCardProps {
analysisId: number
analysisId: string
initialName: string
initialDate: Date
}
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/analyse/EditKpiCard.tsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const FormSchema = z.object({
})

interface EditKpiCardProps {
analysisId: number
analysisId: string
initialKpi1: number
initialKpi2: number
initialKpi3: number
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/analyse/EditMarketDataCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const FormSchema = z.object({
})

interface EditMarketDataCardProps {
analysisId: number
analysisId: string
initialMarketRentOffice: number
initialMarketRentMerch: number
initialMarketRentMisc: number
Expand Down
55 changes: 27 additions & 28 deletions apps/www/src/components/analyse/EditOwnerCostsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const FormSchema = z.object({
})

interface EditOwnerCostsCardProps {
analysisId: number
analysisId: string
initialOwnerCostsMethod: boolean
initialOwnerCostsManual?: number
initialCostMaintenance?: number
Expand Down Expand Up @@ -99,8 +99,8 @@ export function EditOwnerCostsCard({
initialCostAssetMgmt,
initialCostSum,
}: EditOwnerCostsCardProps) {
console.log(analysisId)
const [isLoading, setIsLoading] = useState(false)

const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
Expand All @@ -123,33 +123,32 @@ export function EditOwnerCostsCard({
setIsLoading(true)
try {
const result = await updateAnalysis(analysisId, {
ownerCostsMethod: data.ownerCostsMethod,
ownerCostsManual: data.ownerCostsManual
? Number(data.ownerCostsManual)
: undefined,
costMaintenance: data.costMaintenance
? Number(data.costMaintenance)
: undefined,
costInsurance: data.costInsurance
? Number(data.costInsurance)
: undefined,
costRevision: data.costRevision ? Number(data.costRevision) : undefined,
costAdm: data.costAdm ? Number(data.costAdm) : undefined,
costOther: data.costOther ? Number(data.costOther) : undefined,
costNegotiation: data.costNegotiation
? Number(data.costNegotiation)
: undefined,
costLegalFees: data.costLegalFees
? Number(data.costLegalFees)
: undefined,
costConsultFees: data.costConsultFees
? Number(data.costConsultFees)
: undefined,
costAssetMgmt: data.costAssetMgmt
? Number(data.costAssetMgmt)
: undefined,
costSum: data.costSum ? Number(data.costSum) : undefined,
costs: {
update: {
ownerCostsMethod: data.ownerCostsMethod,
ownerCostsManual: data.ownerCostsManual
? Number(data.ownerCostsManual)
: 0,
costMaintenance: data.costMaintenance
? Number(data.costMaintenance)
: 0,
costInsurance: data.costInsurance ? Number(data.costInsurance) : 0,
costRevision: data.costRevision ? Number(data.costRevision) : 0,
costAdm: data.costAdm ? Number(data.costAdm) : 0,
costOther: data.costOther ? Number(data.costOther) : 0,
costNegotiation: data.costNegotiation
? Number(data.costNegotiation)
: 0,
costLegalFees: data.costLegalFees ? Number(data.costLegalFees) : 0,
costConsultFees: data.costConsultFees
? Number(data.costConsultFees)
: 0,
costAssetMgmt: data.costAssetMgmt ? Number(data.costAssetMgmt) : 0,
costSum: data.costSum ? Number(data.costSum) : 0,
},
},
})

if (result.success) {
toast.success("Analysen ble oppdatert.")
} else {
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/analyse/EditROICard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const FormSchema = z.object({
})

interface EditROICardProps {
analysisId: number
analysisId: string
initialUseCalcROI: boolean
initialROIWeightedYield?: number
initialROIInflation?: number
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/analyse/EditRentableAreaCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const FormSchema = z.object({
})

interface EditRentableAreaCardProps {
analysisId: number
analysisId: string
initialRentableArea: number
initialRatioAreaOffice: number
initialRatioAreaMerch: number
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/analyse/EditVacancyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const FormSchema = z.object({
})

interface EditVacancyCardProps {
analysisId: number
analysisId: string
initialVacancyPerYear: string // JSON-streng av ledighet per år
}

Expand Down
Loading