feat: Add finish date update tracking for projects
This commit is contained in:
@@ -4,11 +4,16 @@ export function getAllProjects(contractId = null) {
|
||||
const baseQuery = `
|
||||
SELECT
|
||||
p.*,
|
||||
c.contract_number,
|
||||
c.contract_name,
|
||||
c.customer,
|
||||
c.investor,
|
||||
creator.name as created_by_name,
|
||||
creator.username as created_by_username,
|
||||
assignee.name as assigned_to_name,
|
||||
assignee.username as assigned_to_username
|
||||
FROM projects p
|
||||
LEFT JOIN contracts c ON p.contract_id = c.contract_id
|
||||
LEFT JOIN users creator ON p.created_by = creator.id
|
||||
LEFT JOIN users assignee ON p.assigned_to = assignee.id
|
||||
`;
|
||||
@@ -233,3 +238,39 @@ export function getNotesForProject(projectId) {
|
||||
)
|
||||
.all(projectId);
|
||||
}
|
||||
|
||||
// Get finish date update history for a project
|
||||
export function getFinishDateUpdates(projectId) {
|
||||
return db
|
||||
.prepare(
|
||||
`
|
||||
SELECT fdu.*,
|
||||
u.name as updated_by_name,
|
||||
u.username as updated_by_username
|
||||
FROM project_finish_date_updates fdu
|
||||
LEFT JOIN users u ON fdu.updated_by = u.id
|
||||
WHERE fdu.project_id = ?
|
||||
ORDER BY fdu.updated_at DESC
|
||||
`
|
||||
)
|
||||
.all(projectId);
|
||||
}
|
||||
|
||||
// Log a finish date update
|
||||
export function logFinishDateUpdate(projectId, oldDate, newDate, userId, reason = null) {
|
||||
const stmt = db.prepare(`
|
||||
INSERT INTO project_finish_date_updates (
|
||||
project_id, old_finish_date, new_finish_date, updated_by, reason, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
`);
|
||||
|
||||
return stmt.run(projectId, oldDate, newDate, userId, reason);
|
||||
}
|
||||
|
||||
// Check if project has finish date updates
|
||||
export function hasFinishDateUpdates(projectId) {
|
||||
const result = db
|
||||
.prepare('SELECT COUNT(*) as count FROM project_finish_date_updates WHERE project_id = ?')
|
||||
.get(projectId);
|
||||
return result.count > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user