Skip to content

Commit

Permalink
إضافة دالة جديدة لتجميع القيود لجميع الحسابات وتقسيمها على أيام وفق ل…
Browse files Browse the repository at this point in the history
…يوم القيد
  • Loading branch information
vzool committed Aug 3, 2024
1 parent c6df941 commit ce157a1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = 'zakat'
version = '0.2.88'
version = '0.2.89'
authors = [
{ name='Abdelaziz Elrashed Elshaikh Mohamed', email='aeemh.sdn@gmail.com' },
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='zakat',
version='0.2.88',
version='0.2.89',
description='A Python Library for Islamic Financial Management.',
author='Abdelaziz Elrashed Elshaikh Mohamed',
author_email='aeemh.sdn@gmail.com',
Expand Down
53 changes: 51 additions & 2 deletions zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def Version() -> str:
Returns:
str: The current version of the software.
"""
return '0.2.88'
return '0.2.89'

@staticmethod
def ZakatCut(x: float) -> float:
Expand Down Expand Up @@ -1215,6 +1215,55 @@ def logs(self, account) -> dict:
return self._vault['account'][account]['log']
return {}

def daily_logs(self):
"""
Retrieve the daily logs (transactions) from all accounts.
The function groups the logs by day, month, and year, and calculates the total value for each group.
It returns a dictionary where the keys are the timestamps of the daily groups,
and the values are dictionaries containing the total value and the logs for that group.
Parameters:
None
Returns:
dict: A dictionary containing the daily logs.
Example:
>>> tracker = ZakatTracker()
>>> tracker.track(51, 'desc', 'account1')
>>> tracker.track(100, 'desc', 'account2')
>>> tracker.daily_logs()
{
1632057600: {
'total': 151,
'rows': [
{'value': 51, 'account': 'account1', 'file': {}, 'ref': 1690977015000000000, 'desc': 'desc'},
{'value': 100, 'account': 'account2', 'file': {}, 'ref': 1690977015000000000, 'desc': 'desc'}
]
}
}
"""
x = {}
for account in self.accounts():
logs = {}
for k, v in self.logs(account).items():
v['account'] = account
logs[k] = v
x.update(logs)
y = {}
for i in sorted(x, reverse=True):
dt = self.time_to_datetime(i)
group = self.day_to_time(dt.day, dt.month, dt.year)
if group not in y:
y[group] = {
'total': 0,
'rows': [],
}
y[group]['total'] += x[i]['value']
y[group]['rows'].append(x[i])
return y

def add_file(self, account: str, ref: int, path: str) -> int:
"""
Adds a file reference to a specific transaction log entry in the vault.
Expand Down Expand Up @@ -3225,4 +3274,4 @@ def main():


if __name__ == "__main__":
main()
main()

0 comments on commit ce157a1

Please sign in to comment.