diff --git a/app/repositories/report.py b/app/repositories/report.py index 16a20e3..74bb01d 100644 --- a/app/repositories/report.py +++ b/app/repositories/report.py @@ -487,6 +487,55 @@ class ReportRepository(): ]).to_list(None) return result + async def get_extra_project(self,project_id:uuid): + res = {} + records_status = await ( + use_collection(TaskEnv.CLN_AUDIT_STATUS) + .find({"project_id": project_id}) + .sort('$natural', -1) + .to_list(None) + ) + res['count_audit_status'] = len(records_status) + res['last_audit_status'] = records_status[0].get('amount') if records_status else None + + financial_adjust = await use_collection(TaskEnv.CLN_FINANCIAL_ADJUST).count_documents({'project_id': project_id}) + res['count_financial_adjust'] = financial_adjust + financial_adjust_accept = await use_collection(TaskEnv.CLN_FINANCIAL_ADJUST).find({'project_id': project_id,'amount_cycle_supervisor':{"$exists":1}}).sort('$natural', -1).to_list(None) + + if financial_adjust_accept and len(financial_adjust_accept) > 0 and 'amount_cycle_supervisor' in financial_adjust_accept[0]: + res['last_financial_adjust'] = financial_adjust_accept[0]['amount_cycle_supervisor'] + else: + res['last_financial_adjust'] = None + stats = await use_collection(TaskEnv.CLN_AUDIT_PROGRAM).aggregate([ + {"$match": {"project_id": project_id}}, + { + "$group": { + "_id": None, + "sum_diff": {"$sum": "$diff_price"}, + "count": {"$sum": 1}, + "diff_prices": { + "$push": "$diff_price" + } + } + } + ]).to_list(None) + if stats: + sum_diff = stats[0]["sum_diff"] + diff_prices = stats[0]["diff_prices"] + + result = [] + for diff in diff_prices: + percentage = round((diff / sum_diff) * 100, 2) if sum_diff else 0 + result.append({ + "diff_price": diff, + "percentage": percentage + }) + res['audit_program'] = result + + + return res + + diff --git a/app/urls/report.py b/app/urls/report.py index b7a25e5..56ee303 100644 --- a/app/urls/report.py +++ b/app/urls/report.py @@ -132,4 +132,11 @@ def status_agreement(): def status_agreement_progress(): pass +#extra information in map +# مورد 18 +@router.get('/extra/map/{project_id}', tags=_tag_base) +@shrink(repo.get_extra_project) +def get_extra_project(project_id: uuid.UUID): + pass + app.include_router(router) \ No newline at end of file