Ejemplo n.º 1
0
    def update(self, day=None):
        """Updates all timesheet entries starting with day if provided,
        14 days before the latest entry if day is not provided
        or 1-1-2021 if there was no last entry."""

        sim = simplicate()

        if not day:
            # Find newest day in database
            newest_result = self.db.execute(
                'select max(day) as day from timesheet')[0]['day']
            if newest_result:
                day = Day(newest_result).plus_days(-14)
            else:
                day = Day(2021, 1, 1)
        today = Day()
        if day >= today:
            return

        while day < today:
            print('updating', day)
            data = sim.hours({'day': day})
            if data:
                flat_data = flatten_hours_data(data)
                flat_df = pd.DataFrame(flat_data)
                grouped_data = group_by_daypersonservice(flat_data)
                grouped_df = pd.DataFrame(grouped_data)
                complemented_data = [
                    complement_timesheet_data(te) for te in grouped_data
                ]  # %(name)s
                comp_df = pd.DataFrame(complemented_data)
                self.db.execute(f'delete from timesheet where day = "{day}"')
                self.insert_dicts(complemented_data)
            day = day.next()  # Move to the next day before repeating the loop
Ejemplo n.º 2
0
def beschikbare_uren_volgens_rooster(period: Period, employees=None):

    if employees is None:
        employees = []
    sim = simplicate()
    # Get the list of current employees
    if not employees:
        interns = Employee().interns()
    else:
        interns = []

    # Roosteruren
    timetables = get_timetables(sim)
    tot = 0
    for timetable in timetables:
        if (not timetable["employee"]["name"]
                or employees and timetable["employee"]["name"] not in employees
                or not employees and timetable["employee"]["name"] in interns
                or period.untilday
                and timetable["start_date"] >= period.untilday.str
                or timetable.get("end_date", "9999") < period.fromday.str):
            continue
        day = Day(max(timetable["start_date"], period.fromday.str))
        table = [(
            timetable["even_week"][f"day_{i}"]["hours"],
            timetable["odd_week"][f"day_{i}"]["hours"],
        ) for i in range(1, 8)]
        untilday = period.untilday if period.untilday else Day()
        ending_day_of_roster = min(timetable.get("end_date", "9999"),
                                   untilday.str)
        while day.str < ending_day_of_roster:
            index = day.week_number() % 2
            tot += table[day.day_of_week()][index]
            day = day.next()

    # Vrij
    timesheet = Timesheet()
    leave = timesheet.leave_hours(period, employees)

    # Ziek
    absence = timesheet.absence_hours(period, employees)

    return float(tot), float(leave), float(absence)
Ejemplo n.º 3
0
def testqueries():
    df = hours_dataframe()

    def get_diff(row):
        return row['tariff'] and not (row['tariff'] > 0)

    # diff = df.apply( get_diff, axis=1 )
    users = None  # ['Jurriaan Ruitenberg'] #['Caspar Geerlings', 'Kevin Lobine']
    day = Day('2021-01-08')
    end_day = Day('2021-02-01')

    period = Period(day, end_day)
    oud = geboekt_oud(period, users=users, only_clients=1, only_billable=1)
    oudsum = int(oud['hours'].sum() + oud['corrections'].sum())
    oudhours = int(oud['hours'].sum())
    oudcorr = int(oud['corrections'].sum())
    nieuw = geboekt_nieuw(period, users=users, only_clients=1, only_billable=1)
    nieuwsum = int(nieuw['hours'].sum() + nieuw['corrections'].sum())
    nieuwhours = int(nieuw['hours'].sum())
    nieuwcorr = int(nieuw['corrections'].sum())
    if oudsum != nieuwsum:
        a = 1

    while day < end_day:
        print(day)
        next = day.next()
        period = Period(day, next)
        oud = geboekt_oud(period, users=users, only_clients=1, only_billable=1)
        oud_per_user = oud.groupby(['employee'])[['corrections']].sum()
        oudsum = int(oud['corrections'].sum())
        nieuw = geboekt_nieuw(period,
                              users=users,
                              only_clients=1,
                              only_billable=1)
        nieuw_per_user = nieuw.groupby(['employee'])[['corrections']].sum()
        nieuwsum = int(nieuw['corrections'].sum())
        if oudsum != nieuwsum:
            a = 1
        day = next
    pass