def index(yymm=None): if yymm is None: now = date.today() yymm = now.strftime('%Y%m') yy = int(yymm[:4]) mm = int(yymm[4:]) today = date(yy, mm, 1) prev = today - relativedelta(months=1) next = today + relativedelta(months=1) head = dict(ym='{}年{}月'.format(yy, mm), prev=prev.strftime('%Y%m'), next=next.strftime('%Y%m')) absencelogs = AbsenceLog.query.filter(AbsenceLog.yymm == yymm).order_by( AbsenceLog.yymm, AbsenceLog.dd, AbsenceLog.create_at).all() items = [] for absencelog in absencelogs: person = Person.get(absencelog.person_id) staff = Person.get(absencelog.staff_id) item = dict( id=absencelog.person_id, dd=absencelog.dd, enabled='○' if absencelog.enabled else '×', deleted=absencelog.deleted, contact=absencelog.contact, name=person.get_display() if bool(person) else '', staff=staff.name if bool(staff) else '', reason=absencelog.reason if bool(absencelog.reason) else '', remarks=absencelog.remarks if bool(absencelog.remarks) else '') items.append(item) return render_template('absences/index.pug', yymm=yymm, head=head, items=items)
def make_head(id, yymm): person = Person.get(id) if person is None: return None yy = int(yymm[:4]) gg = yy - 1988 mm = int(yymm[4:]) head = {} head['gm'] = '平成{}年{}月分'.format(gg, mm) head['name'] = person.name head['idm'] = person.idm head['number'] = person.recipient.number head['amount'] = person.recipient.amount head['usestart'] = '' head['usestart30d'] = '' usestart, usestart30d = person.recipient.get_usestart() if usestart is not None: yy1 = usestart.year mm1 = usestart.month yy2 = usestart30d.year mm2 = usestart30d.month if ((yy1 == yy) and (mm1 == mm)) or ((yy2 == yy) or (mm2 == mm)): head['usestart'] = usestart head['usestart30d'] = usestart30d return head
def enabled_workrec(person_id, yymm): app.logger.info('Enabled WorkRec person_id={} yymm={}'.format( person_id, yymm)) person = Person.get(person_id) if person.staff: return yy = int(yymm[:4]) mm = int(yymm[4:]) first = datetime(yy, mm, 1) last = first + relativedelta(months=1) - relativedelta(days=1) last = last.day - 8 workrecs = WorkRec.get_yymm(person_id, yymm) count = 0 for workrec in workrecs: if workrec.value is None: workrec.value = None else: count = count + 1 if count <= last: workrec.enabled = True else: workrec.enabled = False db.session.add(workrec) try: db.session.commit() except Exception as e: db.session.rollback() app.logger.error(e.message)
def edit(id, yymm, dd): person = Person.get(id) if person is None: abort(404) workrec = WorkRec.get(id, yymm, dd) if workrec is None: abort(404) idm = cache.get('idm') if idm != person.idm: form = WorkRecAbsenceForm(obj=workrec) else: form = WorkRecForm(obj=workrec) if form.validate_on_submit(): workrec.populate_form(form) db.session.add(workrec) try: db.session.commit() enabled_workrec.delay(id, yymm) flash('WorkRec saved successfully.', 'success') return redirect(url_for('workrecs.index', id=id, yymm=yymm)) except: db.session.rollback() flash('Error update workrec!', 'danger') return render_template('workrecs/edit.pug', person=person, form=form, yymm=yymm)
def export2(): workrecs = WorkRec.query.filter(WorkRec.export == False).all() for w in workrecs: person = Person.get(w.person_id) if not person.staff: sql = 'INSERT INTO performlogs(person_id, yymm, dd, enabled, absence, absence_add, work_in, work_out, remarks, create_at, update_at) VALUES({},{},{},{},{},{},{},{},{},{},{});'.format( '"{}"'.format(w.person_id), '"{}"'.format(w.yymm), w.dd, 1 if w.enabled else 0, 1 if w.situation == '欠席' else 0, 0, '"{}"'.format(w.work_in) if bool(w.work_in) else 'NULL', '"{}"'.format(w.work_out) if bool(w.work_out) else 'NULL', '"{}"'.format(w.reason) if bool(w.reason) else 'NULL', '"{}"'.format(w.create_at) if bool(w.create_at) else 'NULL', '"{}"'.format(w.update_at) if bool(w.update_at) else 'NULL') print(sql) sql = 'INSERT INTO worklogs(person_id, yymm, dd, work_in, work_out, value, break_t, over_t, absence, create_at, update_at) VALUES({},{},{},{},{},{},{},{},{},{},{});'.format( '"{}"'.format(w.person_id), '"{}"'.format(w.yymm), w.dd, '"{}"'.format(w.work_in) if bool(w.work_in) else 'NULL', '"{}"'.format(w.work_out) if bool(w.work_out) else 'NULL', 'NULL', 'NULL', 'NULL', 1 if w.situation == '欠席' else 0, '"{}"'.format(w.create_at) if bool(w.create_at) else 'NULL', '"{}"'.format(w.update_at) if bool(w.update_at) else 'NULL') print(sql) w.export = True db.session.add(w) try: db.session.commit() except Exception as e: db.session.rollback() print(e) print('COMMIT;')
def destroy(id, yymm, dd): if (not _check_yymmdd(yymm, dd=dd)): abort(400) person = Person.get(id) if person is None: abort(404) if not person.is_idm(): flash('利用者のICカードをセットしてください', 'danger') return redirect(url_for('performlogs.index', id=id, yymm=yymm)) performlog = PerformLog.get(id, yymm, dd) if performlog is None: abort(404) if bool(performlog.absencelog): db.session.delete(performlog.absencelog) db.session.delete(performlog) worklog = WorkLog.get(id, yymm, dd) db.session.delete(worklog) try: db.session.commit() update_performlogs_enabled.delay(id, yymm) update_absencelog_enabled.delay(id, yymm) flash('実績の削除ができました', 'success') except Exception as e: db.session.rollback() flash('実績削除時にエラーが発生しました "{}"'.format(e), 'danger') return redirect(url_for('performlogs.index', id=id, yymm=yymm))
def update_performlogs_enabled(id, yymm): app.logger.info('Update PerformLogs enabled. id={} yymm={}'.format( id, yymm)) person = Person.get(id) if person is None: return yy = yymm[:4] mm = yymm[4:] first = date(int(yy), int(mm), 1) last = first + relativedelta(months=1) - relativedelta(days=1) last = last.day - 8 performlogs = PerformLog.get_yymm(id, yymm) count = 0 absence = 0 visit = 0 for performlog in performlogs: if _is_persent(performlog): count = count + 1 if count <= last: performlog.presented = True performlog.enabled = True else: performlog.presented = False performlog.enabled = False else: performlog.enabled = _is_enabled(performlog) performlog.presented = False db.session.add(performlog) try: db.session.commit() except Exception as e: db.session.rollback() app.logger.error(e)
def make_head(id,yymm): person = Person.get(id) if person == None: return None head = {} yy = int(yymm[:4]) gg = yy - 1988 mm = int(yymm[4:]) head['gm'] = '平成{gg}年{mm}月分'.format(gg=gg,mm=mm) head['ym'] = '{yy}年{mm}月'.format(yy=yy,mm=mm) head['name'] = person.name head['idm'] = person.idm head['number'] = person.number head['amount'] = person.amount head['staff'] = person.staff usestart = person.usestart if usestart is not None: usestart30d = usestart + relativedelta(days=30) yy1 = usestart.year mm1 = usestart.month yy2 = usestart30d.year mm2 = usestart30d.month if ((yy1 == yy) and (mm1 == mm)) or ((yy2 == yy) and (mm2 == mm)): pass else: usestart = '' usestart30d = '' else: usestart30d = '' head['usestart'] = usestart head['usestart30'] = usestart30d return head
def make_head(id, yymm): person = Person.get(id) if person is None: return None yy = int(yymm[:4]) mm = int(yymm[4:]) head = {} head['ym'] = '{}年{}月'.format(yy,mm) head['name'] = person.name return head
def make_items(id, yymm): yy = int(yymm[:4]) mm = int(yymm[4:]) foot = dict(count=0, absence=0, pickup=0, visit=0, meal=0, medical=0, experience=0, outside=0, usestart=0) person = Person.get(id) performlogs = PerformLog.get_yymm(id, yymm) items = [] for performlog in performlogs: item = dict(dd=performlog.dd, ww=weeka[date(yy, mm, performlog.dd).weekday()], stat='欠席' if performlog.absence_add else '', work_in='', work_out='', pickup_in='', pickup_out='', visit='', meal='', medical='', experience='', outside='', remarks='') if not performlog.enabled: continue foot['count'] += 1 if bool(performlog.presented) else 0 item['work_in'] = performlog.work_in if bool( performlog.work_in) else '' item['work_out'] = performlog.work_out if bool( performlog.work_out) else '' item['pickup_in'] = 1 if bool(performlog.pickup_in) else '' item['pickup_out'] = 1 if bool(performlog.pickup_out) else '' item['visit'] = performlog.visit item['meal'] = 1 if bool(performlog.meal) else '' item['medical'] = performlog.medical item['experience'] = performlog.experience item['outside'] = 1 if bool(performlog.outside) else '' foot['pickup'] += 1 if bool(performlog.pickup_in) else 0 foot['pickup'] += 1 if bool(performlog.pickup_out) else 0 foot['visit'] += 1 if bool(performlog.visit) else 0 foot['meal'] += 1 if bool(performlog.meal) else 0 foot['medical'] += 1 if bool(performlog.medical) else 0 foot['experience'] += 1 if bool(performlog.experience) else 0 foot['outside'] += 1 if bool(performlog.outside) else 0 foot['usestart'] += 1 if person.recipient.is_usestart( date(yy, mm, performlog.dd)) else 0 item['remarks'] = performlog.remarks items.append(item) return items, foot
def destroy(id): item = Person.get(id) db.session.delete(item) try: db.session.commit() flash('職員の削除ができました', 'success') except Exception as e: db.session.rollback() flash('職員削除時にエラーが発生しました {}'.format(e), 'danger') app.logger.exception(e) return redirect(url_for('staffs.index'))
def index(id, yymm=None): if (yymm is not None) and (not _check_yymmdd(yymm)): abort(400) person = Person.get(id) if person is None: abort(404) if yymm is None: now = datetime.now() yymm = now.strftime('%Y%m') else: now = datetime(int(yymm[:4]), int(yymm[4:]), 1) first = datetime(now.year, now.month, 1) last = first + relativedelta(months=1) prev = first - relativedelta(months=1) items = [] head = dict(prev=prev.strftime('%Y%m'), next=last.strftime('%Y%m'), idm=person.idm == cache.get('idm')) foot = dict(sum=0.0, count=0, avg=0.0) while first < last: item = dict(dd=first.day, week=weeka[first.weekday()], situation=None, work_in=None, work_out=None, value=None, reson=None, enabled=None, creation=True) workrec = WorkRec.get_date(id, first) if workrec != None: item['situation'] = workrec.situation item['work_in'] = workrec.work_in item['work_out'] = workrec.work_out item['value'] = workrec.value item['reson'] = workrec.reason item['enabled'] = workrec.enabled item['creation'] = False if workrec.value != None: foot['sum'] = foot['sum'] + workrec.value foot['count'] = foot['count'] + 1 items.append(item) first = first + relativedelta(days=1) if foot['count'] > 0: foot['avg'] = round(foot['sum'] / foot['count'], 1) else: foot['avg'] = 0.0 return render_template('workrecs/index.pug', person=person, items=items, yymm=yymm, head=head, foot=foot)
def edit(id, yymm, dd): if (not _check_yymmdd(yymm, dd=dd)): abort(400) person = Person.get(id) if person is None: abort(404) yymmdd = date(int(yymm[:4]), int(yymm[4:]), int(dd)) worklog = WorkLog.get(id, yymm, dd) item = dict( id=person.id, yymm=yymm, name=person.get_display(), yymmdd=yymmdd.strftime('%Y/%m/%d(%a)'), absence=worklog.absence, work_in=worklog.work_in if worklog.work_in is not None else '', work_out=worklog.work_out if worklog.work_out is not None else '') if worklog is None: abort(404) if person.staff: form = WorkLogFormStaff(obj=worklog) else: if worklog.absence: form = WorkLogFormRemarks(obj=worklog) else: form = WorkLogForm(obj=worklog) if form.validate_on_submit(): worklog.populate_form(form) try: db.session.add(worklog) try: db.session.commit() if (person.staff) and (worklog.value is None): update_worklog_value.delay(id, yymm, dd) if not person.staff: update_performlogs_enabled(id, yymm) flash('勤怠の更新ができました', 'success') return redirect(url_for('worklogs.index', id=id, yymm=yymm)) except Exception as e: db.session.rollback() flash('勤怠更新時にエラーが発生しました "{}"'.format(e), 'danger') except ValidationError as e: flash(e, 'danger') if person.staff: return render_template('worklogs/edit_staff.pug', id=id, yymm=yymm, form=form, item=item) return render_template('worklogs/edit.pug', id=id, yymm=yymm, form=form, item=item)
def edit(id): item = Person.get(id) form = PersonForm(obj=item) if form.validate_on_submit(): form.populate_obj(item) try: db.session.commit() flash('職員の変更ができました', 'success') return redirect(url_for('staffs.index')) except Exception as e: db.session.rollback() flash('職員変更時にエラーが発生しました {}'.format(e), 'danger') app.logger.exception(e) return render_template('staffs/edit.pug', id=id, form=form)
def edit(id, yymm, dd): if (not _check_yymmdd(yymm, dd=dd)): abort(400) person = Person.get(id) if person is None: abort(404) yymmdd = date(int(yymm[:4]), int(yymm[4:]), int(dd)) item = dict(name=person.get_display(), yymmdd=yymmdd.strftime('%Y/%m/%d(%a)')) performlog = PerformLog.get(id, yymm, dd) if performlog is None: abort(404) if person.is_idm(): form = PerformLogsFormIDM(obj=performlog) else: form = PerformLogsForm(obj=performlog) if form.validate_on_submit(): performlog.populate_form(form) try: performlog.validate() if performlog.absence_add: if bool(performlog.absencelog): performlog.absencelog.deleted = False else: absencelog = AbsenceLog() performlog.absencelog = absencelog else: if bool(performlog.absencelog): performlog.absencelog.deleted = True db.session.add(performlog) worklog = WorkLog.get(id, yymm, dd) performlog.sync_to_worklog(worklog) try: db.session.commit() update_performlogs_enabled.delay(id, yymm) update_absencelog_enabled.delay(id, yymm) update_worklog_value.delay(id, yymm, dd) flash('実績の更新ができました', 'success') return redirect(url_for('performlogs.index', id=id, yymm=yymm)) except Exception as e: db.session.rollback() flash('実績更新時にエラーが発生しました "{}"'.format(e), 'danger') except ValidationError as e: flash(e, 'danger') return render_template('performlogs/edit.pug', id=id, yymm=yymm, item=item, form=form)
def make_report_page(self, p, items): p.setFont('Gothic', 16) p.drawString(110.0*mm, 180.0*mm, '欠席時対応加算記録') p.setFont('Gothic', 9) p.drawString(105.0*mm, 174.0*mm, '※利用を中止した日の前々日、前日または当日に連絡があった場合に利用者の状況を確認し、その内容を記録する。') colw = (18.0*mm, 18.0*mm, 23.5*mm, 23.5*mm, 35.0*mm, 148*mm) data = [['利用予定日','連絡日','連絡者','対応職員','欠席理由','相談援助']] count = 0 while count < len(items): person = Person.get(items[count].person_id) staff = Person.get(items[count].staff_id) item = [ date(self.yy, self.mm, items[count].dd), items[count].contact, person.name if person is not None else '', staff.name if staff is not None else '', items[count].reason, items[count].remarks ] data.append(item) count = count + 1 while self.MAX_ROW_COUNT > count: data.append([]) count = count + 1 table = Table(data, colWidths=colw, rowHeights=10.0*mm) table.setStyle([ ('FONT', ( 0, 0), (-1,-1), 'Gothic', 9), ('GRID', ( 0, 0), (-1,-1), 0.5, colors.black), ('BOX', ( 0, 0), (-1,-1), 1.8, colors.black), ('VALIGN', ( 0, 0), (-1,-1), 'MIDDLE'), ('ALIGN', ( 0, 0), (-1,-1), 'CENTER'), ('ALIGN', ( 5, 1), ( 5,-1), 'LEFT'), ]) table.wrapOn(p, 18.0*mm, 20.0*mm) table.drawOn(p, 18.0*mm, 20.0*mm) p.showPage()
def edit(id): person = Person.get(id) if person is None: abort(404) form = PersonForm(obj=person) if form.validate_on_submit(): person.populate_form(form) db.session.add(person) try: db.session.commit() flash('職員の更新ができました', 'success') return redirect(url_for('staffs.index')) except Exception as e: db.session.rollback() flash('職員更新時にエラーが発生しました "{}"'.format(e), 'danger') return render_template('staffs/edit.pug', form=form)
def destroy(id): person = Person.get(id) if person is None: abort(404) q=db.session.\ query(func.count(WorkRec.yymm)).\ filter_by(person_id=id).\ group_by(WorkRec.person_id).first() if q is not None: flash('このユーザは勤怠データが存在しています', 'danger') return redirect(url_for('persons.index')) db.session.delete(person) try: db.session.commit() flash('Person delete successfully.', 'success') except Exception as e: db.session.rollback() flash('Error delete person! {}'.format(e.message), 'danger') return redirect(url_for('persons.index'))
def edit(id): person = Person.get(id) if person is None: abort(404) form = PersonForm(obj=person) if form.validate_on_submit(): person.populate_form(form) db.session.add(person) try: db.session.commit() flash('Person saved successfully.', 'success') return redirect(url_for('persons.index')) except IntegrityError: db.session.rollback() flash('同一IDMが指定された可能性が有ります', 'danger') except Exception as e: db.session.rollback() flash('Error update person! {}'.format(e.message), 'danger') return render_template('persons/edit.pug', form=form)
def destroy(id, yymm, dd): if (not _check_yymmdd(yymm, dd=dd)): abort(400) person = Person.get(id) if person is None: abort(404) if not person.staff: flash('職員以外は勤怠削除はできません。実績削除で行ってください "{}"'.format(e), 'danger') return redirect(url_for('performlogs.index', id=id, yymm=yymm)) worklog = WorkLog.get(id, yymm, dd) if worklog is None: abort(404) db.session.delete(worklog) try: db.session.commit() flash('勤怠の削除ができました', 'success') except Exception as e: db.session.rollback() flash('勤怠削除時にエラーが発生しました "{}"'.format(e), 'danger') return redirect(url_for('worklogs.index', id=id, yymm=yymm))
def destroy(id, yymm, dd): person = Person.get(id) if person is None: abort(404) idm = cache.get('idm') workrec = WorkRec.get(id, yymm, dd) if (idm != person.idm) and ((workrec is not None) and (workrec.work_in is not None)): flash('利用者のICカードをタッチしてください', 'danger') if (workrec is not None) and ((idm == person.idm) or (workrec.work_in is None)): db.session.delete(workrec) try: db.session.commit() enabled_workrec.delay(id, yymm) flash('Entry delete successfully.', 'success') except: db.session.rollback() flash('Error delete entry!', 'danger') return redirect(url_for('workrecs.index', id=id, yymm=yymm))
def destroy(id): person = Person.get(id) if person is None: abort(404) q = db.session.query( func.count(WorkLog.yymm) ).filter( WorkLog.person_id==id ).group_by( WorkLog.person_id ).first() if q is not None: flash('勤怠データが存在しているため削除できません','danger') return redirect(url_for('staffs.index')) db.session.delete(person) try: db.session.commit() flash('職員の削除ができました', 'success') except Exception as e: db.session.rollback() flash('職員削除時にエラーが発生しました "{}"'.format(e), 'danger') return redirect(url_for('staffs.index'))
def update_absencelog_enabled(id, yymm): app.logger.info('Update AbsenceLogs enabled. id={} yymm={}'.format(id,yymm)) person = Person.get(id) if person is None: return absencelogs = AbsenceLog.query.filter(AbsenceLog.person_id==id, AbsenceLog.yymm==yymm).order_by(AbsenceLog.dd).all() count = 0 for absencelog in absencelogs: if bool(absencelog.deleted): absencelog.enabled = False else: count = count + 1 if count <= 4: absencelog.enabled = True else: absencelog.enabled = False db.session.add(absencelog) try: db.session.commit() except Exception as e: db.session.rollback() app.logger.error(e)
def edit(id, yymm, dd): absencelog = AbsenceLog.get(id, yymm, dd) if absencelog is None: abort(404) person = Person.get(id) if person is None: abort(404) yymmdd = date(int(yymm[:4]), int(yymm[4:]), int(dd)) form = AbsenceForm(obj=absencelog) if form.validate_on_submit(): absencelog.populate_form(form) db.session.add(absencelog) try: db.session.commit() flash('欠席時対応加算記録を保存しました', 'success') return redirect(url_for('absences.index', yymm=yymm)) except Exception as e: db.session.rollback() flash('欠席時対応加算記録更新時にエラーが発生しました "{}"'.format(e), 'danger') return render_template('absences/edit.pug', form=form, yymmdd=yymmdd, name=person.name)
def create(id, yymm, dd): if (not _check_yymmdd(yymm, dd=dd)): abort(400) person = Person.get(id) if person is None: abort(404) yymmdd = date(int(yymm[:4]), int(yymm[4:]), int(dd)) item = dict(id=person.id, yymm=yymm, name=person.get_display(), yymmdd=yymmdd.strftime('%Y/%m/%d(%a)')) if not person.staff: flash('職員以外は勤怠登録はできません。実績登録で行ってください ', 'danger') return redirect(url_for('worklogs.index', id=id, yymm=yymm)) form = WorkLogFormStaff() if form.validate_on_submit(): worklog = WorkLog(person_id=id, yymm=yymm, dd=dd) worklog.populate_form(form) try: db.session.add(worklog) try: db.session.commit() if (person.staff) and (worklog.value is None): update_worklog_value.delay(id, yymm, dd) flash('勤怠の追加ができました', 'success') return redirect(url_for('worklogs.index', id=id, yymm=yymm)) except Exception as e: db.session.rollback() flash('勤怠追加時にエラーが発生しました "{}"'.format(e), 'danger') except ValidationError as e: flash(e, 'danger') return render_template('worklogs/edit_staff.pug', id=id, yymm=yymm, form=form, item=item)
def person(self): return Person.get(self.id)
def index(id, yymm=None): if (yymm is not None) and (not _check_yymmdd(yymm)): abort(400) person = Person.get(id) if person is None: abort(404) if yymm is None: now = date.today() yymm = now.strftime('%Y%m') else: now = date(int(yymm[:4]), int(yymm[4:]), 1) first = date(now.year, now.month, 1) last = first + relativedelta(months=1) prev = first - relativedelta(months=1) head = dict(name=person.get_display(), ym='{}年{}月'.format(first.year, first.month), prev=prev.strftime('%Y%m'), next=last.strftime('%Y%m')) foot = dict(count=0, pickup=0, visit=0, meal=0, medical=0, experience=0, outside=0) items = [] while first < last: item = dict(dd=first.day, week=weeka[first.weekday()], edit=False, create=True, delete=False, enabled=None, presented=None, absence=False, absence_add=False, work_in=None, work_out=None, pickup_in=None, pickup_out=None, visit=None, meal=None, medical=None, experience=None, outside=None, remarks=None) performlog = PerformLog.get_date(id, first) if performlog is None: item['create'] = True else: if person.is_idm(): item['edit'] = True item['delete'] = True else: if (not bool(performlog.work_in)) and (not bool( performlog.work_out)): item['edit'] = True item['delete'] = True else: item['edit'] = True item['enabled'] = performlog.enabled item['presented'] = performlog.presented item['absence'] = performlog.absence item['absence_add'] = performlog.absence_add item['work_in'] = performlog.work_in item['work_out'] = performlog.work_out item['pickup_in'] = '○' if performlog.pickup_in else '' item['pickup_out'] = '○' if performlog.pickup_out else '' item['visit'] = performlog.visit item['meal'] = '○' if performlog.meal else '' item['medical'] = performlog.medical item['experience'] = performlog.experience item['outside'] = '○' if performlog.outside else '' item['remarks'] = performlog.remarks foot['count'] += 1 if bool(performlog.presented) else 0 foot['pickup'] += 1 if bool(item['pickup_in']) else 0 foot['pickup'] += 1 if bool(item['pickup_out']) else 0 foot['visit'] += 1 if bool(item['visit']) else 0 foot['meal'] += 1 if bool(item['meal']) else 0 foot['medical'] += 1 if bool(item['medical']) else 0 foot['experience'] += 1 if bool(item['experience']) else 0 foot['outside'] += 1 if bool(item['outside']) else 0 items.append(item) first = first + relativedelta(days=1) return render_template('performlogs/index.pug', id=id, yymm=yymm, head=head, items=items, foot=foot)
def index(id, yymm=None): if (yymm is not None) and (not _check_yymmdd(yymm)): abort(400) person = Person.get(id) if person is None: abort(404) if yymm is None: now = date.today() yymm = now.strftime('%Y%m') else: now = date(int(yymm[:4]), int(yymm[4:]), 1) first = date(now.year, now.month, 1) last = first + relativedelta(months=1) prev = first - relativedelta(months=1) head = dict(id=person.id, name=person.get_display(), staff=person.staff, yymm=yymm, ym='{}年{}月'.format(first.year, first.month), prev=prev.strftime('%Y%m'), next=last.strftime('%Y%m')) foot = dict(cnt=0, sum=0, avg=0, break_t=0, over_t=0, absence=0, late=0, leave=0) items = [] while first < last: item = dict(dd=first.day, presented=None, week=weeka[first.weekday()], situation=None, work_in=None, work_out=None, value=None, break_t=None, over_t=None, remarks=None, absence=False, late=False, leave=False, edit=False) worklog = WorkLog.get_date(id, first) if worklog is not None: item['edit'] = True item['presented'] = worklog.presented item['work_in'] = worklog.work_in item['work_out'] = worklog.work_out item['value'] = worklog.value item['break_t'] = worklog.break_t item['over_t'] = worklog.over_t item['absence'] = worklog.absence item['late'] = worklog.late item['leave'] = worklog.leave item['remarks'] = worklog.remarks foot['cnt'] += 1 if bool(worklog.value) else 0 foot['sum'] += worklog.value if bool(worklog.value) else 0 foot['break_t'] += worklog.break_t if bool(worklog.break_t) else 0 foot['over_t'] += worklog.over_t if bool(worklog.over_t) else 0 foot['absence'] += 1 if bool(worklog.absence) else 0 foot['late'] += 1 if bool(worklog.late) else 0 foot['leave'] += 1 if bool(worklog.leave) else 0 items.append(item) first = first + relativedelta(days=1) return render_template('worklogs/index.pug', id=id, yymm=yymm, head=head, items=items, foot=foot)
def update_worklog_value(id, yymm, dd=None): app.logger.info( 'Update WorkLog value from Time-Table. id={} yymm={} dd={}'.format( id, yymm, dd)) person = Person.get(id) if person is None: return if person.timerule_id is None: return timerule = TimeRule.get(person.timerule_id) if timerule is None: return if dd is None: dds = range(1, 32) else: dds = (dd, ) for d in dds: worklog = WorkLog.get(id, yymm, d) if worklog is None: continue if worklog.value is not None: continue app.logger.info( 'Updating WorkLog value from Time-Table. id={} yymm={} dd={}'. format(id, yymm, d)) if not bool(worklog.work_in): continue if not bool(worklog.work_out): continue rules = json.loads(timerule.rules) work_in = rules['core']['start'] work_out = rules['core']['end'] for i in rules['times']: if (i['in']) and (i['start'] <= worklog.work_in) and ( worklog.work_in < i['end']): work_in = i['value'] break for i in rules['times']: if (i['out']) and (i['start'] <= worklog.work_out) and ( worklog.work_out < i['end']): work_out = i['value'] break value = work_out - work_in break_t = 0.0 if 'break' in rules: for i in rules['break']: if (work_in <= i['start']) and (work_out >= i['end']): break_t = break_t + i['value'] if value < 0: value = 0 elif ('max' in rules) and (value > rules['max']): value = rules['max'] worklog.value = value - break_t worklog.break_t = break_t worklog.over_t = worklog.value - rules['core']['value'] if worklog.over_t < 0: worklog.over_t = 0 worklog.late = work_in > rules['core']['start'] worklog.leave = work_out < rules['core']['end'] db.session.add(worklog) try: db.session.commit() except Exception as e: db.session.rollback() app.logger.error(e)