Detailed Code Explanation Shop Management
Detailed Code Explanation Shop Management
1. HTML Layout
The HTML file is structured to show the app title, current day label, a date selector to switch
between daily records, a form for adding/updating product data, a summary section, a
responsive table to list all products added on the current day, and a canvas element for the
bar chart that visualizes product quantities sold. The layout is mobile responsive.
2. Form Fields
The form uses `<input>` elements for the product name, quantity, supplier, type, sold
quantity, sold price, supplied amount, supplied time, and sold time. These inputs are
submitted through a 'submit' button which either adds a new product or updates an
existing one if it's being edited.
5. populateDateSelector()
This function extracts all unique dates from the product records and populates the
`<select>` dropdown so users can switch between viewing different days. The current date
is automatically selected.
6. updateTable()
This is the main function that updates the product table and summary when the selected
date changes or products are added. It filters `products` for the selected date, counts total
quantity sold, total revenue (sold × price), collects unique product types, and updates the
HTML table with the results. It also builds the bar chart.
8. Summary Section
The summary area is updated to show total products entered, how many different products
exist, total sold amount in kg, and total revenue in birr (calculated by multiplying sold ×
price).
9. Chart Rendering
`renderChart()` uses Chart.js to display a bar chart showing total sold quantity per product
name. Old charts are destroyed before rendering a new one.
1. Layout Overview
This page contains a search input and a container that holds product records grouped by
date. It is fully responsive and scrollable on mobile.
2. Load Products
Uses `localStorage.getItem("products")` to load product data saved by index.html. If none
exists, an empty array is loaded.
5. Search Filtering
A search bar lets users filter by product or supplier name in real time. The search is case-
insensitive and updates on `input` event.
6. Responsive Table
Each day’s products are shown in a responsive scrollable table. On small screens, the full
table is still accessible via horizontal scrolling.