Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
parthpetkar authored Jun 28, 2024
2 parents c32c9fc + b90e152 commit eec686f
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 171 deletions.
33 changes: 19 additions & 14 deletions Backend/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ $(document).ready(async () => {
}
if (!isValid) {
alert('Form is invalid');
return false;
} else {

return {
Expand Down Expand Up @@ -103,9 +104,8 @@ $(document).ready(async () => {

if (!isValid) {
alert('Form is invalid');
return false;
} else {
console.log(projectNumber)

return {
customerName: customerName,
projectNumber: projectNumber,
Expand Down Expand Up @@ -224,11 +224,10 @@ $(document).ready(async () => {

if (milestones.length > 0) {
// Handle saving milestones
console.log("Saving milestones:", milestones);
await window.electron.send('insertMilestone', { milestones, projectData });
window.electron.receive('createProjectResponse', (response) => {
if (response.success) {
alert(`Project created successfully`);
alert(`Project created successfully with ID: ${response.internalProjectId}`,);
} else {
alert(`Error: ${response.message}\n${response.error}`);
}
Expand All @@ -255,14 +254,17 @@ $(document).ready(async () => {
$("#saveCustomer").click(async () => {
try {
const customerData = saveCustomerData();
await window.electron.send('createCustomer', { customerData });
window.electron.receive('createCustomerResponse', (response) => {
if (response.success) {
alert(`Customer created successfully with ID: ${response.customerId}`);
} else {
alert(`Error: ${response.message}\n${response.error}`);
}
});
if (customerData) {
// Handle the case where customerData is null or undefined (optional)
await window.electron.send('createCustomer', { customerData });
window.electron.receive('createCustomerResponse', (response) => {
if (response.success) {
alert(`Customer created successfully with ID: ${response.customerId}`);
} else {
alert(`Error: ${response.message}\n${response.error}`);
}
});
}
} catch (error) {
console.log(error);
}
Expand All @@ -271,8 +273,11 @@ $(document).ready(async () => {
$("#saveProject").click(async () => {
try {
projectData = saveProjectData();
$('#milestone_table').show();
$('#customer_form').hide();
if (projectData) {
// Handle the case where customerData is null or undefined (optional)
$('#milestone_table').show();
$('#customer_form').hide();
}
} catch (error) {
console.log(error);
}
Expand Down
95 changes: 63 additions & 32 deletions Backend/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
$(document).ready(async () => {
try {
const summaryData = await window.electron.invoke("get-summary-data");
$("#totalInvoices").text(summaryData.totalMilestones);
$("#totalAmount").text(`₹${summaryData.totalAmount.toLocaleString()}`);
$("#totalCollected").text(`₹${summaryData.amountCollected.toLocaleString()}`);
$("#totalPending").text(`₹${summaryData.amountPending.toLocaleString()}`);
} catch (error) {
console.error("Error fetching data:", error);
}

try {
const invoiceData = await window.electron.invoke("get-invoice-data");

// Group invoices by date and calculate the total amount for each day
const groupedByDate = invoiceData.reduce((acc, invoice) => {
const dateKey = new Date(invoice.invoice_date).toDateString(); // Ensure it's a Date object
const dateKey = new Date(invoice.invoice_date).toDateString();
if (!acc[dateKey]) {
acc[dateKey] = { totalAmount: 0, count: 0 };
}
acc[dateKey].totalAmount += parseFloat(invoice.total_prices); // Adjust field name
acc[dateKey].totalAmount += parseFloat(invoice.total_prices);
acc[dateKey].count++;
return acc;
}, {});

// Calculate the average amount for each day
const dates = Object.keys(groupedByDate);
const avgAmounts = dates.map((date) => {
const avg = groupedByDate[date].totalAmount / groupedByDate[date].count;
return avg.toFixed(2); // Round to 2 decimal places
return avg.toFixed(2);
});

const invoicesData = [
Expand All @@ -37,18 +39,16 @@ $(document).ready(async () => {

const layout = {
title: "Average Invoice Amount Over Time",
xaxis: {
showgrid: false,
zeroline: false,
},
yaxis: {
title: "Average Amount",
showline: false,
},
xaxis: { showgrid: false, zeroline: false },
yaxis: { title: "Average Amount", showline: false },
};

Plotly.newPlot("invoicesChart", invoicesData, layout);
} catch (error) {
console.error("Error fetching data:", error);
}

try {
const invoiceStatusData = await window.electron.invoke("get-invoice-status-data");
const statuses = invoiceStatusData.map((item) => item.status);
const counts = invoiceStatusData.map((item) => item.count);
Expand All @@ -64,35 +64,33 @@ $(document).ready(async () => {

const statusLayout = {
title: "Invoices by Status",
xaxis: {
title: "Status",
showgrid: false,
zeroline: false,
},
yaxis: {
title: "Count",
showline: false,
},
xaxis: { title: "Status", showgrid: false, zeroline: false },
yaxis: { title: "Count", showline: false },
};

Plotly.newPlot("statusChart", statusData, statusLayout);
} catch (error) {
console.error("Error fetching data:", error);
}

try {
const projects = await window.electron.invoke("get-projects");
projects.forEach((project) => {
const projectCard = $(`
<div class="project-card" data-customer-id="${project.customer_id}" data-project-id="${project.internal_project_id}">
<h3>${project.project_name}</h3>
<p>Customer ID: ${project.customer_id}</p>
<p>Internal Project Number: ${project.internal_project_id}</p>
<p>Internal PO No. : ${project.pono}</p>
<p>Total Price: ₹ ${project.total_prices}</p>
<p>Project Date: ${new Date(project.project_date).toLocaleDateString()}</p>
<p>PO No. : ${project.pono}</p>
<p>Total Price: ₹ ${project.total_prices.toLocaleString()}</p>
<button class="extend-button">Extend</button>
<button class="edit-button">Edit</button>
</div>
`);
$("#projectsContainer").append(projectCard);
});

// Event listener for the "Extend" button
$(".project-card").on("click", ".extend-button", async function () {
const projectCard = $(this).closest(".project-card");
const projectdata = {
Expand All @@ -101,7 +99,6 @@ $(document).ready(async () => {
};

const { milestones, customers } = await window.electron.invoke("get-milestones", projectdata);
console.log(customers)
const modalContent = $("#milestonesModal .modal-content");
modalContent.empty();
modalContent.append($(`<h2>${customers[0].company_name}</h2>`));
Expand All @@ -118,17 +115,51 @@ $(document).ready(async () => {
modalContent.append(milestoneCard);
});

// Show the modal
$("#milestonesModal").css("display", "block");
});

// Close the modal when clicking on the close button or outside the modal content
$("#milestonesModal .close, #milestonesModal").on("click", function (event) {
if (event.target === this) {
$("#milestonesModal").css("display", "none");
$(".project-card").on("click", ".edit-button", function () {
const projectCard = $(this).closest(".project-card");
const projectId = projectCard.data("project-id");
const customerId = projectCard.data("customer-id");

$("#projectName").val(projectCard.find("h3").text());
$("#projectDate").val(new Date(projectCard.find("p:nth-child(4)").text().split(": ")[1]).toISOString().split("T")[0]);
$("#poNo").val(projectCard.find("p:nth-child(5)").text().split(": ")[1]);
$("#totalPrices").val(projectCard.find("p:nth-child(6)").text().split("₹ ")[1].replace(/,/g, ''));

$("#editProjectForm").data("project-id", projectId).data("customer-id", customerId);

$("#editProjectModal").css("display", "block");
});

$("#editProjectForm").submit(async function (event) {
event.preventDefault();

const projectData = {
project_id: $(this).data("project-id"),
customer_id: $(this).data("customer-id"),
project_name: $("#projectName").val(),
project_date: $("#projectDate").val(),
pono: $("#poNo").val(),
total_prices: $("#totalPrices").val(),
};

try {
await window.electron.invoke("update-project", projectData);
alert("Project updated successfully!");
$("#editProjectModal").css("display", "none");
location.reload();
} catch (error) {
console.error("Error updating project:", error);
}
});

$("#editProjectModal .close, #editProjectModal").on("click", function (event) {
if (event.target === this) {
$("#editProjectModal").css("display", "none");
}
});
} catch (error) {
console.error("Error fetching data:", error);
}
Expand Down
9 changes: 5 additions & 4 deletions Backend/milestonepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $(document).ready(async () => {

// Add indicator for due date
if (invoice) {
const daysLeft = daysUntilDue(invoice.due_date);
const daysLeft = daysUntilDue(invoice.invoice_date);
let textColor;
if (daysLeft < 0) {
textColor = 'red'; // Overdue
Expand Down Expand Up @@ -137,8 +137,9 @@ $(document).ready(async () => {
milestone.custom_date = customDate;
});

await window.electron.send('createInvoice', { selectedMilestones });
await window.electron.send('createForm', { selectedMilestones });
const invoiceType = $('#invoiceType').val();
// await window.electron.send('createInvoice', { selectedMilestones });
await window.electron.send('createForm', { selectedMilestones, invoiceType });

$('#invoiceModal').hide();
displayMilestones(displayedMilestones); // Refresh the table
Expand Down Expand Up @@ -198,4 +199,4 @@ $(document).ready(async () => {
} catch (error) {
console.error('Error fetching data:', error);
}
});
});
10 changes: 10 additions & 0 deletions CSS/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ color: #666;
cursor: pointer;
transition: background-color 0.3s ease;
}
.edit-button {
display: inline-block;
padding: 10px 20px;
background-color: var(--primary-color);
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}

.extend-button:hover {
background-color: var(--secondary-color);
Expand Down
58 changes: 54 additions & 4 deletions CSS/display.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,14 @@
padding: 10px;
}

/* Invoice Details Card Styling */
.invoicedrop {
margin: 20px;
padding: 10px;
}

.createInvoiceBtn {
margin: 20px;
}
#invoiceDetailsCard {
position: fixed;
top: 50%;
Expand All @@ -183,7 +190,9 @@
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
z-index: 1000;
width: 400px;
max-width: 90%;
/* Fixed width */
max-width: 90%;
/* Maximum width as a percentage of the viewport */
}

.card {
Expand All @@ -195,16 +204,57 @@
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #ccc;
margin-bottom: 10px;
padding-bottom: 10px;
/* Improved spacing */
}

.card-header h2 {
font-size: 1.2em;
/* Adjusted font size for header */
margin: 0;
/* Reset margin for consistency */
}

.card-body {
padding: 10px 0;
/* Improved padding */
}

.card-footer {
display: flex;
justify-content: center;
justify-content: flex-end;
/* Adjusted alignment */
padding-top: 10px;
border-top: 1px solid #ccc;
}
.card-footer button {
padding: 8px 16px;
/* Improved button padding */
margin-left: 10px;
/* Space between buttons */
cursor: pointer;
background-color: #4285f4;
color: white;
border: none;
border-radius: 4px;
font-size: 14px;
transition: background-color 0.3s ease;
}

.card-footer button:hover {
background-color: #3367d6;
/* Darker shade on hover */
}

.close-btn {
color: #aaa;
font-size: 24px;
cursor: pointer;
}

.close-btn:hover,
.close-btn:focus {
color: #555;
/* Darker on hover/focus */
text-decoration: none;
}
Binary file added Templates/Dollar-Invoice.xlsx
Binary file not shown.
Binary file not shown.
Binary file added Templates/Proforma-Invoice.xlsx
Binary file not shown.
Binary file added Templates/Regular-2-Invoice.xlsx
Binary file not shown.
Binary file added Templates/Regular-Invoice.xlsx
Binary file not shown.
Loading

0 comments on commit eec686f

Please sign in to comment.