コード例 #1
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
コード例 #2
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))
コード例 #3
0
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)
コード例 #4
0
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
コード例 #5
0
ファイル: performlogs.py プロジェクト: abtoc/ofpp-app-old
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(name=person.get_display(),
                yymmdd=yymmdd.strftime('%Y/%m/%d(%a)'))
    if person.is_idm():
        form = PerformLogsFormIDM()
    else:
        form = PerformLogsForm()
    if form.validate_on_submit():
        performlog = PerformLog(person_id=id, yymm=yymm, dd=dd)
        performlog.populate_form(form)
        try:
            performlog.validate()
            if performlog.absence_add:
                absencelog = AbsenceLog()
                absencelog.deleted = False
                performlog.absencelog = absencelog
            db.session.add(performlog)
            worklog = WorkLog(person_id=id, yymm=yymm, dd=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
ファイル: performlogs.py プロジェクト: abtoc/ofpp-app-old
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)