Skip to content

Commit

Permalink
Added payroll summary stream.
Browse files Browse the repository at this point in the history
  • Loading branch information
xacadil committed May 14, 2024
1 parent 56c58fa commit 618d151
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tap_restaurant365/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ def get_new_paginator(self) -> BaseAPIPaginator:

def get_starting_time(self, context):
start_date = self.config.get("start_date")
rep_key = None
if start_date:
start_date = parser.parse(self.config.get("start_date"))
rep_key = self.get_starting_timestamp(context) + timedelta(seconds=1)
if context:
rep_key = self.get_starting_timestamp(context) + timedelta(seconds=1)
return rep_key or start_date

def get_url_params(
Expand Down
80 changes: 80 additions & 0 deletions tap_restaurant365/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def get_url_params(
params["$filter"] += f" and type eq 'Stock Count'"
if self.name == "bank_expenses":
params["$filter"] += f" and type eq 'Bank Expense'"
if self.name == "payroll_summary":
params["$filter"] = f"payrollStart ge {start_date.strftime('%Y-%m-%dT%H:%M:%SZ')} and payrollEnd le {end_date.strftime('%Y-%m-%dT23:59:59Z')}"
#
if skip > 0:
params["$skip"] = skip
Expand Down Expand Up @@ -650,3 +652,81 @@ def get_url_params(
if skip > 0:
params["$skip"] = skip
return params

class PayrollSummaryStream(LimitedTimeframeStream):
"""Define custom stream."""

name = "payroll_summary"
path = "/PayrollSummary"
primary_keys = None
replication_key = None
pagination_date = None
schema = th.PropertiesList(
th.Property("employeeID", th.StringType),
th.Property("location", th.StringType),
th.Property("locationNumber", th.StringType),
th.Property("jobCode", th.StringType),
th.Property("payRate", th.NumberType),
th.Property("regularHours", th.NumberType),
th.Property("overtimeHours", th.NumberType),
th.Property("doubleOvertime", th.NumberType),
th.Property("breakPenalty", th.NumberType),
th.Property("grossReceipts", th.NumberType),
th.Property("splitShiftPenalty", th.NumberType),
th.Property("chargeTips", th.NumberType),
th.Property("declaredTips", th.NumberType),
th.Property("percentageOfSales", th.NumberType),
th.Property("percent", th.IntegerType),
th.Property("payrollStart", th.DateTimeType),
th.Property("payrollEnd", th.DateTimeType),
).to_dict()
def get_next_page_token(
self, response: requests.Response, previous_token: t.Optional[t.Any]
) -> t.Optional[t.Any]:
"""
Return a token for identifying next page or None if no more pages.
The token is a datetime object that is used to filter the next page
of results. The token is calculated by adding the days_delta
parameter to the previous token. If the new token is in the future,
the pagination is disabled.
Args:
response: The response object from the latest request.
previous_token: The token from the previous page, or None if
this is the first page.
Returns:
A token for the next page, or None if no more pages are available.
"""
today = datetime.today() # noqa: DTZ002
if self.pagination_date:
previous_token = self.pagination_date
if isinstance(previous_token,str):
previous_token = parser.parse(previous_token)
# Add a day to previous token
next_token = previous_token + timedelta(days=1)
next_token = next_token.replace(tzinfo=None)

# Disable pagination if the next token's date is in the future
if (today - next_token).days < 0:
return None
# Return the next token and the current skip value
return next_token


def get_url_params(
self,
context: dict | None, # noqa: ARG002
next_page_token: Any | None, # noqa: ANN401
) -> dict[str, Any]:

params: dict = {}
token_date = None
if next_page_token:
token_date = next_page_token
start_date = token_date or self.get_starting_time(context)
end_date = start_date + timedelta(days=self.days_delta)
self.pagination_date = end_date
params["$filter"] = f"payrollStart ge {start_date.strftime('%Y-%m-%dT%H:%M:%SZ')} and payrollEnd le {end_date.strftime('%Y-%m-%dT23:59:59Z')}"
return params
1 change: 1 addition & 0 deletions tap_restaurant365/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def discover_streams(self) -> list[streams.Restaurant365Stream]:
streams.StockCountStream(self),
streams.TransactionsStream(self),
streams.TransactionDetailsStream(self),
streams.PayrollSummaryStream(self),
]


Expand Down

0 comments on commit 618d151

Please sign in to comment.