feat: Add NoteForm, ProjectForm, and ProjectTaskForm components
- Implemented NoteForm for adding notes to projects. - Created ProjectForm for managing project details with contract selection. - Developed ProjectTaskForm for adding tasks to projects, supporting both templates and custom tasks. feat: Add ProjectTasksSection component - Introduced ProjectTasksSection to display and manage tasks for a specific project. - Includes functionality for adding, updating, and deleting tasks. feat: Create TaskTemplateForm for managing task templates - Added TaskTemplateForm for creating new task templates with required wait days. feat: Implement UI components - Created reusable UI components: Badge, Button, Card, Input, Loading, Navigation. - Enhanced user experience with consistent styling and functionality. feat: Set up database and queries - Initialized SQLite database with tables for contracts, projects, tasks, project tasks, and notes. - Implemented queries for managing contracts, projects, tasks, and notes. chore: Add error handling and loading states - Improved error handling in forms and data fetching. - Added loading states for better user feedback during data operations.
This commit is contained in:
105
src/lib/queries/projects.js
Normal file
105
src/lib/queries/projects.js
Normal file
@@ -0,0 +1,105 @@
|
||||
import db from "../db.js";
|
||||
|
||||
export function getAllProjects() {
|
||||
return db.prepare("SELECT * FROM projects ORDER BY finish_date DESC").all();
|
||||
}
|
||||
|
||||
export function getProjectById(id) {
|
||||
return db.prepare("SELECT * FROM projects WHERE project_id = ?").get(id);
|
||||
}
|
||||
|
||||
export function createProject(data) {
|
||||
// 1. Get the max project_number under this contract
|
||||
const existing = db
|
||||
.prepare(
|
||||
`
|
||||
SELECT MAX(project_number) as max_number
|
||||
FROM projects
|
||||
WHERE contract_id = ?
|
||||
`
|
||||
)
|
||||
.get(data.contract_id);
|
||||
|
||||
const nextNumber = (existing.max_number || 0) + 1;
|
||||
|
||||
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
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`);
|
||||
stmt.run(
|
||||
data.contract_id,
|
||||
data.project_name,
|
||||
parseInt(nextNumber),
|
||||
data.address,
|
||||
data.plot,
|
||||
data.district,
|
||||
data.unit,
|
||||
data.city,
|
||||
data.investment_number,
|
||||
data.finish_date,
|
||||
data.wp,
|
||||
data.contact,
|
||||
data.notes
|
||||
);
|
||||
}
|
||||
|
||||
export function updateProject(id, data) {
|
||||
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 = ?
|
||||
WHERE project_id = ?
|
||||
`);
|
||||
stmt.run(
|
||||
data.contract_id,
|
||||
data.project_name,
|
||||
data.project_number,
|
||||
data.address,
|
||||
data.plot,
|
||||
data.district,
|
||||
data.unit,
|
||||
data.city,
|
||||
data.investment_number,
|
||||
data.finish_date,
|
||||
data.wp,
|
||||
data.contact,
|
||||
data.notes,
|
||||
id
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteProject(id) {
|
||||
db.prepare("DELETE FROM projects WHERE project_id = ?").run(id);
|
||||
}
|
||||
|
||||
export function getProjectWithContract(id) {
|
||||
return db
|
||||
.prepare(
|
||||
`
|
||||
SELECT
|
||||
p.*,
|
||||
c.contract_number,
|
||||
c.contract_name,
|
||||
c.customer,
|
||||
c.investor
|
||||
FROM projects p
|
||||
LEFT JOIN contracts c ON p.contract_id = c.contract_id
|
||||
WHERE p.project_id = ?
|
||||
`
|
||||
)
|
||||
.get(id);
|
||||
}
|
||||
|
||||
export function getNotesForProject(projectId) {
|
||||
return db
|
||||
.prepare(
|
||||
`
|
||||
SELECT * FROM notes
|
||||
WHERE project_id = ?
|
||||
ORDER BY note_date DESC
|
||||
`
|
||||
)
|
||||
.all(projectId);
|
||||
}
|
||||
Reference in New Issue
Block a user