コード例 #1
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
コード例 #2
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)
コード例 #3
0
ファイル: performlogs.py プロジェクト: abtoc/ofpp-app-old
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))
コード例 #4
0
def edit(id, yymm, dd):
    try:
        date_x.yymm_dd(yymm, dd)
    except ValueError:
        abort(400)
    person = Person.get_or_404(id)
    if person.staff:
        flash('職員はこの画面はサポートしておりません', 'danger')
        return redirect(url_for('index'))
    performlog = PerformLogService.get_or_new(id, yymm, dd)
    if check_idm(person):
        form = PerformLogFormIDM(obj=performlog)
    else:
        form = PerformLogForm(obj=performlog)
    if form.validate_on_submit():
        try:
            performlog.update(form)
            update_worklogs_value.delay(id, yymm, dd)
            update_performlogs_enabled.delay(id, yymm)
            flash('実績の登録ができました', 'success')
            return redirect(url_for('performlogs.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=performlog)
    return render_template('performlogs/edit.pug', **kw)
コード例 #5
0
ファイル: performlogs.py プロジェクト: abtoc/ofpp-app-old
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)
コード例 #6
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
コード例 #7
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))
コード例 #8
0
ファイル: performlogs.py プロジェクト: abtoc/ofpp-app-old
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))
コード例 #9
0
def update(id, yymm):
    update_performlogs_enabled.delay(id, yymm)
    return redirect(url_for('performlogs.index', id=id, yymm=yymm))