diff --git a/pyproject.toml b/pyproject.toml index bcc1cf2..40e1f81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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' }, ] diff --git a/setup.py b/setup.py index c4a5a6d..21a255b 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/zakat/zakat_tracker.py b/zakat/zakat_tracker.py index 62d852f..a24ed78 100644 --- a/zakat/zakat_tracker.py +++ b/zakat/zakat_tracker.py @@ -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: @@ -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. @@ -3225,4 +3274,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file