Changes between Initial Version and Version 1 of GenerateReports


Ignore:
Timestamp:
12/30/25 17:39:41 (14 hours ago)
Author:
235018
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GenerateReports

    v1 v1  
     1== Generating Store Reports
     2
     3=== Actors: **Registered Boss**
     4
     5**1.** One of the bosses of the store request data for monthly profit for the past month from {{{orders}}} and {{{refund}}}.
     6
     7**2.** The system gets information from {{{orders}}} and {{{refunds}}} for the month and calculates the overall profit for the month.
     8
     9
     10{{{#!sql
     11SELECT SUM(order.total) AS sales FROM order
     12WHERE order.placement_date >= DATE_TRUNC('month', CURRENT_DATE) AND
     13order.placement_date < (DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month') AND
     14order.store_ID = '001';
     15
     16SELECT SUM(refund.amount) AS damages FROM refund
     17WHERE refund.approval_date >= DATE_TRUNC('month', CURRENT_DATE) AND
     18order.approval_date < (DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month') AND
     19order.store_ID = '001';
     20
     21
     22**3.** One of the boss of the store sends data for the store through {{{exchanges_data}}} and {{{worked}}} for the current month in the last days of the month.
     23
     24{{{#!sql
     25INSERT INTO exchanges_data(report_date, store_ID, monthly_profit, date, sales, damages) VALUES
     26('2025-12-31 23:59:59', '001', 60000.00 , '2025-12-30 15:28:46', 62000.00, 2000.00);
     27
     28}}}
     29
     30{{{#!sql
     31INSERT INTO worked (personal_ID, report_date, store_ID, wage, pay_method, total_hours, week) VALUES
     32('0010001', '2025-12-31 23:59:59', '001', 15000, 'monthly', 52, '2025-12-29 - 2025-12-31'),
     33('0010002', '2025-12-31 23:59:59', '001', 10000, 'monthly', 34, '2025-12-29 - 2025-12-31');
     34
     35}}}
     36
     37**4.** The system automatically generates a monthly report for the store on the last day of each month. The data is noted in {{{report}}}.
     38
     39{{{#!sql
     40INSERT INTO report (date, store_ID, overall_profit, sales_trend, marketing_growth, owner_signature) VALUES
     41('2025-12-31 23:59:59', '001', 0.00, '', '', ''),
     42
     43}}}
     44
     45
     46**5.** The system collects ''hours worked, wages'', and ''pay_type'' from the {{{worked}}} table:
     47
     48{{{#!sql
     49SELECT personal_ID, SUM(total_hours) AS total_hours, wage, pay_method FROM worked
     50WHERE store_ID='001'
     51AND week.first_date >= DATE_TRUNC('month', CURRENT_DATE)
     52AND week.last_date < (DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month')
     53GROUP BY personal_ID;
     54
     55}}}
     56
     57**6.** The system collects the ''monthly_profit, sales'' and ''damages'' from {{{exchanges_data}}}:
     58
     59{{{#!sql
     60SELECT monthly_profit AS total_monthly_profit, sales AS total_sales, damages AS total_damages
     61FROM exchanges_data
     62WHERE store_ID='001'
     63AND date >= DATE_TRUNC('month', CURRENT_DATE)
     64AND date < (DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month');
     65
     66}}}
     67
     68**7.** The report is in the {{{report}}} table is updated with the data:
     69
     70{{{#!sql
     71UPDATE report
     72SET overall_profit='35000',
     73sales_trend='Growing',
     74markething_growth='Stable'
     75WHERE report.date >= DATE_TRUNC('month', CURRENT_DATE) AND
     76report.date < (DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month') AND
     77report.store_ID = '001';
     78
     79}}}
     80
     81**8.** The system sends the report to all bosses of the store for approval.
     82
     83{{{#!sql
     84SELECT b.boss_ID, p.first_name, p.last_name, p.email
     85FROM boss b
     86JOIN personal p ON b.boss_ID = p.id
     87JOIN works_in_store w ON p.id = w.personal_ID
     88WHERE w.store_ID='001';
     89}}}
     90
     91**9.** Each boss reviews and signs the report. Once at least one boss signs, the report is considered approved.
     92
     93{{{#!sql
     94UPDATE report
     95SET owner_signature = boss.signature
     96WHERE store_ID='001' AND date = '2025-12-30 00:00:00' AND boss.boss_ID = works_in.personal_ID and works_id.store_ID = '001';
     97}}}