Esempio n. 1
0
def get_idm(idm):
    cache.set('idm', idm, 30 * 60)
    person = Person.query.filter_by(idm=idm).first()
    if person is None:
        return jsonify({"name": "該当者無し"}), 404
    result = dict(name=person.display)
    return jsonify(result), 200
Esempio n. 2
0
def get(idm):
    person = Person.query.filter(Person.idm == idm).first()
    if person is None:
        return jsonify({"name": "該当者無し"}), 404
    result = dict(
        name=person.get_display()
    )
    cache.set('person.id', person.id, timeout=10*60)
    cache.set('person.idm', person.idm, timeout=10*60)
    return jsonify(result), 200
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 post_idm(idm):
    cache.set('idm', None, 5 * 60)
    person = Person.query.filter_by(idm=idm).first()
    if person is None:
        return jsonify({"message": "Not Found!"}), 404
    now = datetime.now()
    yymm = now.strftime('%Y%m')
    dd = now.day
    hhmm = now.strftime('%H:%M')
    workrec = WorkRec.get(person.id, yymm, dd)
    creation = False
    if workrec is None:
        creation = True
        work_in = get_work_in(hhmm, person.staff)
        workrec = WorkRec(person_id=person.id, yymm=yymm, dd=dd, work_in=hhmm)
    else:
        work_in = get_work_in(workrec.work_in, person.staff)
        work_out = get_work_out(hhmm, person.staff)
        break_t = 0.0
        if (work_in['value'] < 12.0) and (work_out['value'] > 13.0):
            break_t = 1.0
        value = work_out['value'] - work_in['value'] - break_t
        if value < 0:
            value = 0
            break_t = 0
        over_t = 0.0
        if value > 8.0:
            over_t = value - 8.0
        workrec.work_out = hhmm
        workrec.value = value
        workrec.break_t = break_t
        workrec.over_t = over_t
    db.session.add(workrec)
    try:
        db.session.commit()
        enabled_workrec.delay(person.id, yymm)
    except:
        db.session.rollback()
        return jsonify({}), 500
    if creation:
        result = dict(work_in=workrec.work_in, work_out='--:--')
        return jsonify(result), 201
    result = dict(work_in=workrec.work_in, work_out=workrec.work_out)
    return jsonify(result), 200
Esempio n. 5
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
Esempio n. 6
0
def get(idm, company=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
    cache.set('person.id', person.id)
    cache.set('person.idm', person.idm)
    cache.set('person.name', person.display_or_name)
    result = dict(name=person.display_or_name)
    return jsonify(result), 200
Esempio n. 7
0
def logout():
    cache.set('person.id', None)
    cache.set('person.idm', None)
    logout_user()
    return redirect(url_for('index'))
Esempio n. 8
0
def delete(idm):
    cache.set('person.id', None)
    cache.set('person.idm', None)
    return jsonify({}), 200
Esempio n. 9
0
def logout():
    logout_user()
    cache.set('idm', None, 5*60)
    return redirect(url_for('index'))
Esempio n. 10
0
def delete(idm, company=None):
    cache.set('person.id', None)
    cache.set('person.idm', None)
    cache.set('person.name', None)
    return jsonify({}), 200
Esempio n. 11
0
def delete_idm(idm):
    cache.set('idm', None, 30 * 60)
    return jsonify({}), 200