# Sales findings (PHP)

Method: revenue = `quantity * unit_price` for `status == completed` only.
Cancelled orders excluded. Input `sales.csv` left unchanged.
Currency: PHP. All bar charts use zero-baseline bars with labelled axes and units.

## Completed revenue by product

| Product | Revenue (PHP) |
|---|---:|
| Pen set | 2,520 |
| Notebook | 2,280 |
| Planner | 2,250 |
| Total | 7,050 |

Chart: `revenue-by-product.svg`

## Completed revenue by channel

| Channel | Revenue (PHP) |
|---|---:|
| Direct | 2,870 |
| Referral | 2,100 |
| Marketplace | 2,080 |
| Total | 7,050 |

Chart: `revenue-by-channel.svg`

## Checks

- Product sum: 2,520 + 2,280 + 2,250 = 7,050
- Channel sum: 2,870 + 2,100 + 2,080 = 7,050
- Completed orders: 10; cancelled excluded: 2 (Planner/Referral 2026-09-04: 500; Notebook/Marketplace 2026-09-09: 240; excluded total 740)
- `checked-totals.csv` contains the product and channel breakdowns plus the grand total and filtered total.

## Follow-up: completed orders on or after 2026-09-08

Filter: `status == completed` and `date >= 2026-09-08` (5 orders).

| Product | Revenue (PHP) |
|---|---:|
| Planner | 1,500 |
| Pen set | 1,260 |
| Notebook | 960 |
| Total | 3,720 |

Chart: `revenue-by-product-filtered-2026-09-08.svg`

Takeaway: Pen set leads full-period revenue; Direct is the top channel; in the 2026-09-08+ window Planner leads, followed by Pen set.

## Calculation code (Python standard library only)

```python
import csv
from collections import defaultdict

sales_path = "sales.csv"
by_product = defaultdict(int)
by_channel = defaultdict(int)
by_product_filt = defaultdict(int)
cutoff = "2026-09-08"

with open(sales_path, newline='', encoding='utf-8') as f:
    for row in csv.DictReader(f):
        if row['status'] != 'completed':
            continue
        rev = int(row['quantity']) * int(row['unit_price'])
        by_product[row['product']] += rev
        by_channel[row['channel']] += rev
        if row['date'] >= cutoff:
            by_product_filt[row['product']] += rev

total = sum(by_product.values())
total_filt = sum(by_product_filt.values())
assert total == sum(by_channel.values()) == 7050
assert total_filt == 3720

with open('checked-totals.csv', 'w', newline='', encoding='utf-8') as f:
    w = csv.writer(f)
    w.writerow(['group_type', 'group_name', 'revenue_php'])
    for k in sorted(by_product):
        w.writerow(['product', k, by_product[k]])
    for k in sorted(by_channel):
        w.writerow(['channel', k, by_channel[k]])
    w.writerow(['total', 'completed_revenue', total])
    w.writerow(['total', 'completed_revenue_filtered_on_or_after_2026-09-08', total_filt])
```

SVG charts were generated with Python standard library only (manual SVG XML, no third-party packages), with y-axis from 0, axis labels including units, and values labelled on bars.
