Exemple #1
0
def edit(id, yymm, dd):
    try:
        date_x.yymm_dd(yymm, dd)
    except ValueError:
        abort(400)
    person = Person.get_or_404(id)
    worklog = WorkLogService.get_or_new(id, yymm, dd)
    if person.staff:
        form = WorkLogFormStaff(obj=worklog)
    else:
        form = WorkLogForm(obj=worklog)
    if form.validate_on_submit():
        try:
            if person.staff:
                worklog.update_staff(form)
            else:
                worklog.update_no_staff(form)
            update_worklogs_value.delay(id, yymm, dd)
            if not person.staff:
                update_performlogs_enabled.delay(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')
            app.logger.exception(e)
    kw = dict(
        id = id,
        yymm = yymm,
        dd = dd,
        form = form,
        item = worklog
    )
    return render_template('worklogs/edit.pug', **kw)
Exemple #2
0
def post(idm, company=None):
    cache.set('person.id', None)
    cache.set('person.idm', None)
    cache.set('person.name', None)
    person = Person.query.filter(Person.idm == idm).first()
    if person is None:
        return jsonify({'name': '該当者無し'}), 404
    if not person.enabled:
        return jsonify({'name': '該当者無し'}), 404
    now = datetime.now()
    yymm = now.strftime('%Y%m')
    dd = now.day
    worklog = WorkLogService.get_or_new(person.id, yymm, dd)
    try:
        worklog.update_api(now, company)
        update_worklogs_value.run(person.id, yymm, dd)
        if not person.staff:
            update_performlogs_enabled.delay(person.id, yymm)
    except Exception as e:
        db.session.rollback()
        app.logger.exception(e)
        return jsonify({'message': str(e)}), 500
    if bool(worklog.work_out):
        result = dict(work_in=worklog.work_in, work_out=worklog.work_out)
    else:
        result = dict(work_in=worklog.work_in, work_out='--:--')
    return jsonify(result), 200
Exemple #3
0
 def make_items(self):
     foot = dict(
         count = 0,
         value = 0.0,
         break_t = 0.0,
         over_t = 0.0,
         absence = 0,
         late = 0,
         leave = 0
     )
     first = date(self.yy, self.mm, 1)
     items = []
     for dd in range(1, 32):
         if first.month != self.mm:
             items.append(None)
             continue
         log = WorkLogService.get_or_new(self.id, self.yymm, dd)
         item = dict(
             dd = dd,
             ww = weeka(log.date),
             work_in = '',
             work_out = '',
             break_t = '',
             value = '',
             over_t = '',
             absence = '',
             leave = '',
             late = '',
             remarks = ''
         )
         item['work_in'] = log.work_in if bool(log.work_in) else ''
         item['work_out'] = log.work_out if bool(log.work_out) else ''
         if log.break_t is not None:
             item['break_t'] = log.break_t
             foot['break_t'] +=  log.break_t
         if log.value is not None:
             item['value'] = log.value
             foot['value'] += log.value
         if log.presented:
             foot['count'] += 1
         if log.over_t is not None:
             item['over_t'] = log.over_t
             foot['over_t'] += log.over_t
         item['absence'] = '○' if bool(log.absence) else ''
         foot['absence'] = foot['absence'] + (1 if bool(log.absence) else 0) 
         item['leave'] = '○' if bool(log.leave) else ''
         foot['leave'] = foot['leave'] + (1 if bool(log.leave) else 0)
         item['late'] = '○' if bool(log.late) else ''
         foot['late'] = foot['late'] + (1 if bool(log.late) else 0)
         item['remarks'] = log.remarks if bool(log.remarks) else ''
         items.append(item)
         first += relativedelta(days=1)
     return items, foot
Exemple #4
0
def destory(id, yymm, dd):
    worklog = WorkLogService.get_or_404((id, yymm, dd))
    try:
        worklog.delete()
        flash('勤怠の削除ができました', 'success')
    except ValueError as e:
        db.session.rollback()
        flash(str(e), 'danger')
    except Exception as e:
        db.session.rollback()
        flash('勤怠削除時にエラーが発生しました {}'.format(e), 'danger')
        app.logger.exception(e)
    return redirect(url_for('worklogs.index', id=id, yymm=yymm))
Exemple #5
0
def _get_caption(person, date):
    worklog = WorkLogService.get_date(person.id, date)
    yymm = date.strftime('%Y%m')
    dd = date.day
    if worklog is None:
        caption = 'ー'
    else:
        if worklog.absence:
            caption = '欠席'
        else:
            caption = '{}−{}'.format(
                worklog.work_in if bool(worklog.work_in) else '',
                worklog.work_out if bool(worklog.work_out) else '')
    return caption
Exemple #6
0
def destroy(id, yymm, dd):
    person = Person.get_or_404(id)
    if person.staff:
        flash('職員はこの画面はサポートしておりません', 'danger')
        return redirect(url_for('index'))
    performlog = PerformLogService.get_or_404((id, yymm, dd))
    worklog = WorkLogService.get_or_404((id, yymm, dd))
    if not check_idm(person):
        if bool(performlog.work_in) or bool(performlog.work_out) or bool(
                worklog.value):
            flash('利用者のICカードをタッチしてください', 'danger')
            return redirect(url_for('performlogs.index', id=id, yymm=yymm))
    try:
        performlog.delete()
        update_performlogs_enabled.delay(id, yymm)
        flash('実績の削除ができました', 'success')
    except Exception as e:
        db.session.rollback()
        flash('実績削除時にエラーが出ました {}'.format(e), 'danger')
        app.logger.exception(e)
    return redirect(url_for('performlogs.index', id=id, yymm=yymm))
Exemple #7
0
def index(id, yymm):
    person = Person.get_or_404(id)
    today = date_x.yymm_dd(yymm, 1)
    first = today
    last = first + relativedelta(months=1)
    prev = first - relativedelta(months=1)
    this = date.today()
    items = []
    while first.date < last.date:
        ym = first.date.strftime('%Y%m')
        d = first.date.day
        worklog = WorkLogService.get_or_new(id, ym, d)
        items.append(worklog)
        first += relativedelta(days=1)
    Foot = namedtuple('Foor', ('presented', 'value', 'break_t', 'over_t', 'absence', 'late', 'leave'))
    foot = Foot(
        len([i for i in items if i.presented]),
        sum([i.value for i in items if i.value is not None]),
        sum([i.break_t for i in items if i.break_t is not None]),
        sum([i.over_t for i in items if i.over_t is not None]),
        len([i for i in items if i.absence]),
        len([i for i in items if i.late]),
        len([i for i in items if i.leave]),
    )
    kw = dict(
        id = id,
        yymm = yymm,
        staff = person.staff,
        name = person.name,
        today = today.date,
        this = this.strftime('%Y%m'),
        prev = prev.date.strftime('%Y%m'),
        next = last.date.strftime('%Y%m'),
        items = items,
        foot = foot
    )
    return render_template('worklogs/index.pug', **kw)