Compare commits

..

3 Commits

4 changed files with 35 additions and 18 deletions

View File

@@ -10,6 +10,7 @@ async function getContractsHandler() {
contract_id,
contract_number,
contract_name,
customer_contract_number,
customer,
investor,
date_signed,
@@ -24,7 +25,7 @@ async function getContractsHandler() {
async function createContractHandler(req) {
const data = await req.json();
db.prepare(
const result = db.prepare(
`
INSERT INTO contracts (
contract_number,
@@ -45,7 +46,10 @@ async function createContractHandler(req) {
data.date_signed,
data.finish_date
);
return NextResponse.json({ success: true });
// Return the newly created contract with its ID
const contract = db.prepare("SELECT * FROM contracts WHERE contract_id = ?").get(result.lastInsertRowid);
return NextResponse.json(contract);
}
// Protected routes - require authentication

View File

@@ -19,8 +19,8 @@ export default function ContractsMainPage() {
const [loading, setLoading] = useState(true);
const [searchTerm, setSearchTerm] = useState("");
const [filteredContracts, setFilteredContracts] = useState([]);
const [sortBy, setSortBy] = useState("contract_number");
const [sortOrder, setSortOrder] = useState("asc");
const [sortBy, setSortBy] = useState("date_signed");
const [sortOrder, setSortOrder] = useState("desc");
const [statusFilter, setStatusFilter] = useState("all");
useEffect(() => {
@@ -53,6 +53,9 @@ export default function ContractsMainPage() {
contract.contract_name
?.toLowerCase()
.includes(searchTerm.toLowerCase()) ||
contract.customer_contract_number
?.toLowerCase()
.includes(searchTerm.toLowerCase()) ||
contract.customer?.toLowerCase().includes(searchTerm.toLowerCase()) ||
contract.investor?.toLowerCase().includes(searchTerm.toLowerCase())
);
@@ -64,9 +67,9 @@ export default function ContractsMainPage() {
filtered = filtered.filter((contract) => {
if (statusFilter === "active" && contract.finish_date) {
return new Date(contract.finish_date) >= currentDate;
} else if (statusFilter === "completed" && contract.finish_date) {
} else if (statusFilter === "expired" && contract.finish_date) {
return new Date(contract.finish_date) < currentDate;
} else if (statusFilter === "no_end_date") {
} else if (statusFilter === "ongoing") {
return !contract.finish_date;
}
return true;
@@ -117,27 +120,27 @@ export default function ContractsMainPage() {
const active = contracts.filter(
(c) => !c.finish_date || new Date(c.finish_date) >= currentDate
).length;
const completed = contracts.filter(
const expired = contracts.filter(
(c) => c.finish_date && new Date(c.finish_date) < currentDate
).length;
const withoutEndDate = contracts.filter((c) => !c.finish_date).length;
return { total, active, completed, withoutEndDate };
return { total, active, expired, withoutEndDate };
};
const getContractStatus = (contract) => {
if (!contract.finish_date) return "ongoing";
const currentDate = new Date();
const finishDate = new Date(contract.finish_date);
return finishDate >= currentDate ? "active" : "completed";
return finishDate >= currentDate ? "active" : "expired";
};
const getStatusBadge = (status) => {
switch (status) {
case "active":
return <Badge variant="success">{t('contracts.active')}</Badge>;
case "completed":
return <Badge variant="secondary">{t('common.completed')}</Badge>;
case "expired":
return <Badge variant="danger">{t('contracts.expired')}</Badge>;
case "ongoing":
return <Badge variant="primary">{t('contracts.withoutEndDate')}</Badge>;
default:
@@ -209,8 +212,8 @@ export default function ContractsMainPage() {
options: [
{ value: "all", label: "Wszystkie" },
{ value: "active", label: "Aktywne" },
{ value: "completed", label: "Zakończone" },
{ value: "no_end_date", label: "Bez daty końca" },
{ value: "expired", label: "Przeterminowane" },
{ value: "ongoing", label: "W trakcie" },
],
},
{
@@ -221,7 +224,7 @@ export default function ContractsMainPage() {
{ value: "contract_number", label: "Numer umowy" },
{ value: "contract_name", label: "Nazwa umowy" },
{ value: "customer", label: "Klient" },
{ value: "start_date", label: "Data rozpoczęcia" },
{ value: "date_signed", label: "Data podpisania" },
{ value: "finish_date", label: "Data zakończenia" },
],
},
@@ -338,9 +341,9 @@ export default function ContractsMainPage() {
</svg>
</div>
<div className="ml-4">
<p className="text-sm font-medium text-gray-600">Zakończone</p>
<p className="text-sm font-medium text-gray-600">Przeterminowane</p>
<p className="text-2xl font-bold text-gray-900">
{stats.completed}
{stats.expired}
</p>
</div>
</div>

View File

@@ -588,10 +588,19 @@ export default function ProjectViewPage() {
</div>
<div>
<span className="text-sm font-medium text-gray-500 block mb-1">
Nazwa umowy
Numer umowy klienta
</span>
<p className="text-gray-900 font-medium">
{project.contract_name || "N/A"}
{project.customer_contract_number ? (
<Link
href={`/contracts/${project.contract_id}`}
className="text-inherit hover:text-inherit no-underline"
>
{project.customer_contract_number}
</Link>
) : (
"N/A"
)}
</p>
</div>
<div>

View File

@@ -222,6 +222,7 @@ export function getProjectWithContract(id) {
p.*,
c.contract_number,
c.contract_name,
c.customer_contract_number,
c.customer,
c.investor,
creator.name as created_by_name,