|
@@ -269,11 +269,13 @@ class WorkRecordService:
|
|
|
Dictionary with yearly summary data including:
|
|
Dictionary with yearly summary data including:
|
|
|
- year: The year
|
|
- year: The year
|
|
|
- persons: List of person summaries with monthly_earnings, yearly_total,
|
|
- persons: List of person summaries with monthly_earnings, yearly_total,
|
|
|
- settled_total, and unsettled_total
|
|
|
|
|
|
|
+ settled_total, unsettled_total, monthly_settled, monthly_unsettled
|
|
|
- monthly_totals: Array of 12 monthly totals across all persons
|
|
- monthly_totals: Array of 12 monthly totals across all persons
|
|
|
- grand_total: Overall yearly total
|
|
- grand_total: Overall yearly total
|
|
|
- settled_grand_total: Total settled earnings for the year
|
|
- settled_grand_total: Total settled earnings for the year
|
|
|
- unsettled_grand_total: Total unsettled earnings for the year
|
|
- unsettled_grand_total: Total unsettled earnings for the year
|
|
|
|
|
+ - monthly_settled_totals: Array of 12 monthly settled totals
|
|
|
|
|
+ - monthly_unsettled_totals: Array of 12 monthly unsettled totals
|
|
|
"""
|
|
"""
|
|
|
# Calculate date range for the year
|
|
# Calculate date range for the year
|
|
|
start_date = date(year, 1, 1)
|
|
start_date = date(year, 1, 1)
|
|
@@ -286,7 +288,7 @@ class WorkRecordService:
|
|
|
).join(Person).order_by(Person.name).all()
|
|
).join(Person).order_by(Person.name).all()
|
|
|
|
|
|
|
|
# Calculate totals by person and month (same logic as ExportService)
|
|
# Calculate totals by person and month (same logic as ExportService)
|
|
|
- # Also track settlement status per person
|
|
|
|
|
|
|
+ # Also track settlement status per person and per month
|
|
|
person_monthly_totals = {}
|
|
person_monthly_totals = {}
|
|
|
for record in work_records:
|
|
for record in work_records:
|
|
|
person_id = record.person_id
|
|
person_id = record.person_id
|
|
@@ -298,33 +300,47 @@ class WorkRecordService:
|
|
|
'person_id': person_id,
|
|
'person_id': person_id,
|
|
|
'person_name': person_name,
|
|
'person_name': person_name,
|
|
|
'monthly_data': {m: 0.0 for m in range(1, 13)},
|
|
'monthly_data': {m: 0.0 for m in range(1, 13)},
|
|
|
|
|
+ 'monthly_settled': {m: 0.0 for m in range(1, 13)},
|
|
|
|
|
+ 'monthly_unsettled': {m: 0.0 for m in range(1, 13)},
|
|
|
'settled_total': 0.0,
|
|
'settled_total': 0.0,
|
|
|
'unsettled_total': 0.0
|
|
'unsettled_total': 0.0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
person_monthly_totals[person_id]['monthly_data'][month] += record.total_price
|
|
person_monthly_totals[person_id]['monthly_data'][month] += record.total_price
|
|
|
|
|
|
|
|
- # Track settlement status
|
|
|
|
|
|
|
+ # Track settlement status per month
|
|
|
if record.is_settled:
|
|
if record.is_settled:
|
|
|
person_monthly_totals[person_id]['settled_total'] += record.total_price
|
|
person_monthly_totals[person_id]['settled_total'] += record.total_price
|
|
|
|
|
+ person_monthly_totals[person_id]['monthly_settled'][month] += record.total_price
|
|
|
else:
|
|
else:
|
|
|
person_monthly_totals[person_id]['unsettled_total'] += record.total_price
|
|
person_monthly_totals[person_id]['unsettled_total'] += record.total_price
|
|
|
|
|
+ person_monthly_totals[person_id]['monthly_unsettled'][month] += record.total_price
|
|
|
|
|
|
|
|
# Build persons list sorted alphabetically by name
|
|
# Build persons list sorted alphabetically by name
|
|
|
persons = []
|
|
persons = []
|
|
|
monthly_grand_totals = [0.0] * 12
|
|
monthly_grand_totals = [0.0] * 12
|
|
|
|
|
+ monthly_settled_totals = [0.0] * 12
|
|
|
|
|
+ monthly_unsettled_totals = [0.0] * 12
|
|
|
settled_grand_total = 0.0
|
|
settled_grand_total = 0.0
|
|
|
unsettled_grand_total = 0.0
|
|
unsettled_grand_total = 0.0
|
|
|
|
|
|
|
|
for person_data in sorted(person_monthly_totals.values(), key=lambda x: x['person_name']):
|
|
for person_data in sorted(person_monthly_totals.values(), key=lambda x: x['person_name']):
|
|
|
monthly_earnings = []
|
|
monthly_earnings = []
|
|
|
|
|
+ monthly_settled = []
|
|
|
|
|
+ monthly_unsettled = []
|
|
|
yearly_total = 0.0
|
|
yearly_total = 0.0
|
|
|
|
|
|
|
|
for month in range(1, 13):
|
|
for month in range(1, 13):
|
|
|
value = round(person_data['monthly_data'][month], 2)
|
|
value = round(person_data['monthly_data'][month], 2)
|
|
|
|
|
+ settled_value = round(person_data['monthly_settled'][month], 2)
|
|
|
|
|
+ unsettled_value = round(person_data['monthly_unsettled'][month], 2)
|
|
|
monthly_earnings.append(value)
|
|
monthly_earnings.append(value)
|
|
|
|
|
+ monthly_settled.append(settled_value)
|
|
|
|
|
+ monthly_unsettled.append(unsettled_value)
|
|
|
yearly_total += value
|
|
yearly_total += value
|
|
|
monthly_grand_totals[month - 1] += value
|
|
monthly_grand_totals[month - 1] += value
|
|
|
|
|
+ monthly_settled_totals[month - 1] += settled_value
|
|
|
|
|
+ monthly_unsettled_totals[month - 1] += unsettled_value
|
|
|
|
|
|
|
|
settled_total = round(person_data['settled_total'], 2)
|
|
settled_total = round(person_data['settled_total'], 2)
|
|
|
unsettled_total = round(person_data['unsettled_total'], 2)
|
|
unsettled_total = round(person_data['unsettled_total'], 2)
|
|
@@ -333,6 +349,8 @@ class WorkRecordService:
|
|
|
'person_id': person_data['person_id'],
|
|
'person_id': person_data['person_id'],
|
|
|
'person_name': person_data['person_name'],
|
|
'person_name': person_data['person_name'],
|
|
|
'monthly_earnings': monthly_earnings,
|
|
'monthly_earnings': monthly_earnings,
|
|
|
|
|
+ 'monthly_settled': monthly_settled,
|
|
|
|
|
+ 'monthly_unsettled': monthly_unsettled,
|
|
|
'yearly_total': round(yearly_total, 2),
|
|
'yearly_total': round(yearly_total, 2),
|
|
|
'settled_total': settled_total,
|
|
'settled_total': settled_total,
|
|
|
'unsettled_total': unsettled_total
|
|
'unsettled_total': unsettled_total
|
|
@@ -344,12 +362,16 @@ class WorkRecordService:
|
|
|
|
|
|
|
|
# Round monthly totals
|
|
# Round monthly totals
|
|
|
monthly_totals = [round(total, 2) for total in monthly_grand_totals]
|
|
monthly_totals = [round(total, 2) for total in monthly_grand_totals]
|
|
|
|
|
+ monthly_settled = [round(total, 2) for total in monthly_settled_totals]
|
|
|
|
|
+ monthly_unsettled = [round(total, 2) for total in monthly_unsettled_totals]
|
|
|
grand_total = round(sum(monthly_totals), 2)
|
|
grand_total = round(sum(monthly_totals), 2)
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
'year': year,
|
|
'year': year,
|
|
|
'persons': persons,
|
|
'persons': persons,
|
|
|
'monthly_totals': monthly_totals,
|
|
'monthly_totals': monthly_totals,
|
|
|
|
|
+ 'monthly_settled_totals': monthly_settled,
|
|
|
|
|
+ 'monthly_unsettled_totals': monthly_unsettled,
|
|
|
'grand_total': grand_total,
|
|
'grand_total': grand_total,
|
|
|
'settled_grand_total': round(settled_grand_total, 2),
|
|
'settled_grand_total': round(settled_grand_total, 2),
|
|
|
'unsettled_grand_total': round(unsettled_grand_total, 2)
|
|
'unsettled_grand_total': round(unsettled_grand_total, 2)
|