Esempio n. 1
0
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))
Esempio n. 2
0
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)
Esempio n. 3
0
def post(idm):
    person = Person.query.filter(Person.idm == idm).first()
    if person is None:
        return jsonify({"name": "該当者無し"}), 404
    cache.set('person.id', None)
    cache.set('person.idm', None)
    now = datetime.now()
    yymm = now.strftime('%Y%m')
    dd = now.day
    hhmm = now.strftime('%H:%M')
    worklog = WorkLog.get(person.id, yymm, dd)
    if worklog is None:
        worklog = WorkLog(person_id=person.id, yymm=yymm, dd=dd)
    worklog.absence = False
    if not bool(worklog.work_in):
        worklog.work_in = hhmm
    else:
        worklog.work_out = hhmm
        worklog.value = None
        worklog.break_t = None
        worklog.over_t = None
    worklog.presented = True
    db.session.add(worklog)
    if not person.staff:
        performlog = PerformLog.get(person.id, yymm, dd)
        if performlog is None:
            performlog = PerformLog(person_id=person.id, yymm=yymm, dd=dd)
        performlog.sync_from_worklog(worklog)
        db.session.add(performlog)
    try:
        db.session.commit()
        update_worklog_value.delay(person.id, yymm, dd)
        if not person.staff:
            update_performlogs_enabled.delay(person.id, yymm)
            update_absencelog_enabled.delay(person.id, yymm)
    except Exception as e:
        db.session.rollback()
        return jsonify({"message": "{}".format(e)}), 500
    if bool(worklog.work_out):
        result = dict(
            work_in = worklog.work_in,
            work_out = worklog.work_out
        )
        return jsonify(result), 200
    result = dict(
        work_in = worklog.work_in,
        work_out = '--:--'
    )
    return jsonify(result), 201
Esempio n. 4
0
def update(id, yymm):
    update_performlogs_enabled.delay(id, yymm)
    update_absencelog_enabled.delay(id, yymm)
    update_worklog_value.delay(id, yymm)
    return redirect(url_for('performlogs.index', id=id, yymm=yymm))