feat: add wartosc_zlecenia field to projects table and update related functionalities

This commit is contained in:
2025-11-14 09:04:46 +01:00
parent 056198ff16
commit 3f87ea16f2
6 changed files with 78 additions and 3 deletions

View File

@@ -421,6 +421,19 @@ export default function ProjectViewPage() {
{project.investment_number || "N/A"}
</p>
</div>
{session?.user?.role === 'team_lead' && project.wartosc_zlecenia && (
<div>
<span className="text-sm font-medium text-gray-500 block mb-1">
Wartość zlecenia
</span>
<p className="text-gray-900 font-medium">
{parseFloat(project.wartosc_zlecenia).toLocaleString('pl-PL', {
style: 'currency',
currency: 'PLN'
})}
</p>
</div>
)}
</div>
{project.contact && (

View File

@@ -2,6 +2,7 @@
import { useState, useEffect, forwardRef, useImperativeHandle } from "react";
import { useRouter } from "next/navigation";
import { useSession } from "next-auth/react";
import { Card, CardHeader, CardContent } from "@/components/ui/Card";
import Button from "@/components/ui/Button";
import { Input } from "@/components/ui/Input";
@@ -10,6 +11,7 @@ import { useTranslation } from "@/lib/i18n";
const ProjectForm = forwardRef(function ProjectForm({ initialData = null }, ref) {
const { t } = useTranslation();
const { data: session } = useSession();
const [form, setForm] = useState({
contract_id: "",
project_name: "",
@@ -24,6 +26,7 @@ const ProjectForm = forwardRef(function ProjectForm({ initialData = null }, ref)
contact: "",
notes: "",
coordinates: "",
wartosc_zlecenia: "",
project_type: "design",
assigned_to: "",
});
@@ -63,12 +66,14 @@ const ProjectForm = forwardRef(function ProjectForm({ initialData = null }, ref)
contact: "",
notes: "",
coordinates: "",
wartosc_zlecenia: "",
project_type: "design",
assigned_to: "",
...initialData,
// Ensure these defaults are preserved if not in initialData
project_type: initialData.project_type || "design",
assigned_to: initialData.assigned_to || "",
wartosc_zlecenia: initialData.wartosc_zlecenia || "",
// Format finish_date for input if it exists
finish_date: initialData.finish_date
? formatDateForInput(initialData.finish_date)
@@ -325,6 +330,23 @@ const ProjectForm = forwardRef(function ProjectForm({ initialData = null }, ref)
/>
</div>
{session?.user?.role === 'team_lead' && (
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Wartość zlecenia
</label>
<Input
type="number"
name="wartosc_zlecenia"
value={form.wartosc_zlecenia || ""}
onChange={handleChange}
placeholder="0.00"
step="0.01"
min="0"
/>
</div>
)}
<div className="md:col-span-2">
<label className="block text-sm font-medium text-gray-700 mb-2">
{t('projects.contact')}

View File

@@ -30,6 +30,7 @@ export default function initializeDatabase() {
wp TEXT,
contact TEXT,
notes TEXT,
wartosc_zlecenia REAL,
project_type TEXT CHECK(project_type IN ('design', 'construction', 'design+construction')) DEFAULT 'design',
project_status TEXT CHECK(project_status IN ('registered', 'in_progress_design', 'in_progress_construction', 'fulfilled', 'cancelled')) DEFAULT 'registered',
FOREIGN KEY (contract_id) REFERENCES contracts(contract_id)

View File

@@ -76,8 +76,8 @@ export function createProject(data, userId = null) {
const stmt = db.prepare(`
INSERT INTO projects (
contract_id, project_name, project_number, address, plot, district, unit, city, investment_number, finish_date,
wp, contact, notes, project_type, project_status, coordinates, created_by, assigned_to, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now', 'localtime'), datetime('now', 'localtime'))
wp, contact, notes, wartosc_zlecenia, project_type, project_status, coordinates, created_by, assigned_to, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now', 'localtime'), datetime('now', 'localtime'))
`);
const result = stmt.run(
@@ -94,6 +94,7 @@ export function createProject(data, userId = null) {
data.wp,
data.contact,
data.notes,
data.wartosc_zlecenia || null,
data.project_type || "design",
data.project_status || "registered",
data.coordinates || null,
@@ -108,7 +109,7 @@ export function updateProject(id, data, userId = null) {
const stmt = db.prepare(`
UPDATE projects SET
contract_id = ?, project_name = ?, project_number = ?, address = ?, plot = ?, district = ?, unit = ?, city = ?,
investment_number = ?, finish_date = ?, wp = ?, contact = ?, notes = ?, project_type = ?, project_status = ?,
investment_number = ?, finish_date = ?, wp = ?, contact = ?, notes = ?, wartosc_zlecenia = ?, project_type = ?, project_status = ?,
coordinates = ?, assigned_to = ?, updated_at = CURRENT_TIMESTAMP
WHERE project_id = ?
`);
@@ -126,6 +127,7 @@ export function updateProject(id, data, userId = null) {
data.wp,
data.contact,
data.notes,
data.wartosc_zlecenia || null,
data.project_type || "design",
data.project_status || "registered",
data.coordinates || null,