Exemplo n.º 1
0
def index(yymm=None):
    if yymm is None:
        now = date.today()
        yymm = now.strftime('%Y%m')
    yy = int(yymm[:4])
    mm = int(yymm[4:])
    today = date(yy, mm, 1)
    prev = today - relativedelta(months=1)
    next = today + relativedelta(months=1)
    head = dict(ym='{}年{}月'.format(yy, mm),
                prev=prev.strftime('%Y%m'),
                next=next.strftime('%Y%m'))
    absencelogs = AbsenceLog.query.filter(AbsenceLog.yymm == yymm).order_by(
        AbsenceLog.yymm, AbsenceLog.dd, AbsenceLog.create_at).all()
    items = []
    for absencelog in absencelogs:
        person = Person.get(absencelog.person_id)
        staff = Person.get(absencelog.staff_id)
        item = dict(
            id=absencelog.person_id,
            dd=absencelog.dd,
            enabled='○' if absencelog.enabled else '×',
            deleted=absencelog.deleted,
            contact=absencelog.contact,
            name=person.get_display() if bool(person) else '',
            staff=staff.name if bool(staff) else '',
            reason=absencelog.reason if bool(absencelog.reason) else '',
            remarks=absencelog.remarks if bool(absencelog.remarks) else '')
        items.append(item)
    return render_template('absences/index.pug',
                           yymm=yymm,
                           head=head,
                           items=items)
Exemplo n.º 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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
def make_head(id,yymm):
    person = Person.get(id)
    if person == None:
        return None

    head = {}
    yy = int(yymm[:4])
    gg = yy - 1988
    mm = int(yymm[4:])
    head['gm']     = '平成{gg}年{mm}月分'.format(gg=gg,mm=mm)
    head['ym']     = '{yy}年{mm}月'.format(yy=yy,mm=mm)
    head['name']   = person.name
    head['idm']    = person.idm
    head['number'] = person.number
    head['amount'] = person.amount
    head['staff']  = person.staff
    usestart = person.usestart
    if usestart is not None:
        usestart30d = usestart + relativedelta(days=30)
        yy1 = usestart.year
        mm1 = usestart.month
        yy2 = usestart30d.year
        mm2 = usestart30d.month
        if ((yy1 == yy) and (mm1 == mm)) or ((yy2 == yy) and (mm2 == mm)):
            pass
        else:
            usestart = ''
            usestart30d = '' 
    else:
        usestart30d = ''
    head['usestart'] = usestart
    head['usestart30'] = usestart30d 
    return head
Exemplo n.º 5
0
def make_head(id, yymm):
    person = Person.get(id)
    if person is None:
        return None
    yy = int(yymm[:4])
    gg = yy - 1988
    mm = int(yymm[4:])
    head = {}
    head['gm'] = '平成{}年{}月分'.format(gg, mm)
    head['name'] = person.name
    head['idm'] = person.idm
    head['number'] = person.recipient.number
    head['amount'] = person.recipient.amount
    head['usestart'] = ''
    head['usestart30d'] = ''
    usestart, usestart30d = person.recipient.get_usestart()
    if usestart is not None:
        yy1 = usestart.year
        mm1 = usestart.month
        yy2 = usestart30d.year
        mm2 = usestart30d.month
        if ((yy1 == yy) and (mm1 == mm)) or ((yy2 == yy) or (mm2 == mm)):
            head['usestart'] = usestart
            head['usestart30d'] = usestart30d
    return head
Exemplo n.º 6
0
def enabled_workrec(person_id, yymm):
    app.logger.info('Enabled WorkRec person_id={} yymm={}'.format(
        person_id, yymm))
    person = Person.get(person_id)
    if person.staff:
        return
    yy = int(yymm[:4])
    mm = int(yymm[4:])
    first = datetime(yy, mm, 1)
    last = first + relativedelta(months=1) - relativedelta(days=1)
    last = last.day - 8
    workrecs = WorkRec.get_yymm(person_id, yymm)
    count = 0
    for workrec in workrecs:
        if workrec.value is None:
            workrec.value = None
        else:
            count = count + 1
            if count <= last:
                workrec.enabled = True
            else:
                workrec.enabled = False
        db.session.add(workrec)
        try:
            db.session.commit()
        except Exception as e:
            db.session.rollback()
            app.logger.error(e.message)
Exemplo n.º 7
0
def edit(id, yymm, dd):
    person = Person.get(id)
    if person is None:
        abort(404)
    workrec = WorkRec.get(id, yymm, dd)
    if workrec is None:
        abort(404)
    idm = cache.get('idm')
    if idm != person.idm:
        form = WorkRecAbsenceForm(obj=workrec)
    else:
        form = WorkRecForm(obj=workrec)
    if form.validate_on_submit():
        workrec.populate_form(form)
        db.session.add(workrec)
        try:
            db.session.commit()
            enabled_workrec.delay(id, yymm)
            flash('WorkRec saved successfully.', 'success')
            return redirect(url_for('workrecs.index', id=id, yymm=yymm))
        except:
            db.session.rollback()
            flash('Error update workrec!', 'danger')
    return render_template('workrecs/edit.pug',
                           person=person,
                           form=form,
                           yymm=yymm)
Exemplo n.º 8
0
def export2():
    workrecs = WorkRec.query.filter(WorkRec.export == False).all()
    for w in workrecs:
        person = Person.get(w.person_id)
        if not person.staff:
            sql = 'INSERT INTO performlogs(person_id, yymm, dd, enabled, absence, absence_add, work_in, work_out, remarks, create_at, update_at) VALUES({},{},{},{},{},{},{},{},{},{},{});'.format(
                '"{}"'.format(w.person_id), '"{}"'.format(w.yymm), w.dd,
                1 if w.enabled else 0, 1 if w.situation == '欠席' else 0, 0,
                '"{}"'.format(w.work_in) if bool(w.work_in) else 'NULL',
                '"{}"'.format(w.work_out) if bool(w.work_out) else 'NULL',
                '"{}"'.format(w.reason) if bool(w.reason) else 'NULL',
                '"{}"'.format(w.create_at) if bool(w.create_at) else 'NULL',
                '"{}"'.format(w.update_at) if bool(w.update_at) else 'NULL')
            print(sql)
        sql = 'INSERT INTO worklogs(person_id, yymm, dd, work_in, work_out, value, break_t, over_t, absence, create_at, update_at) VALUES({},{},{},{},{},{},{},{},{},{},{});'.format(
            '"{}"'.format(w.person_id), '"{}"'.format(w.yymm), w.dd,
            '"{}"'.format(w.work_in) if bool(w.work_in) else 'NULL',
            '"{}"'.format(w.work_out) if bool(w.work_out) else 'NULL', 'NULL',
            'NULL', 'NULL', 1 if w.situation == '欠席' else 0,
            '"{}"'.format(w.create_at) if bool(w.create_at) else 'NULL',
            '"{}"'.format(w.update_at) if bool(w.update_at) else 'NULL')
        print(sql)
        w.export = True
        db.session.add(w)
        try:
            db.session.commit()
        except Exception as e:
            db.session.rollback()
            print(e)
    print('COMMIT;')
Exemplo n.º 9
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)
Exemplo n.º 10
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))
Exemplo n.º 11
0
def create():
    form = PersonForm()
    if form.validate_on_submit():
        person = Person()
        person.populate_form(form)
        db.session.add(person)
        try:
            db.session.commit()
            flash('Person created correctly.', 'success')
            return redirect(url_for('persons.index'))
        except IntegrityError:
            db.session.rollback()
            flash('同一IDMが指定された可能性が有ります', 'danger')
        except Exception as e:
            db.session.rollback()
            flash('Error generating person! {}'.format(e.message), 'danger')
    return render_template('persons/create.pug', form=form)
Exemplo n.º 12
0
def book_edit_creators(id, role):
    session['ids'] = []
    book = Book.query.get_or_404(id)
    if role == 'authors':
        person_list = [p.person for p in book.authors()]
    elif role == 'translators':
        person_list = [p.person for p in book.translators()]
    elif role == 'redaction':
        person_list = [p.person for p in book.redaction()]
    elif role == 'introduction':
        person_list = [p.person for p in book.introduction()]
    else:
        print('return 404')
    form = CreatorForm()
    default = role[0].upper()
    if request.method == 'POST':
        if form.validate_on_submit():
            new_person_list =[]
            for f in form.creators:
                if f.form.name_id.data:
                    person = Person.query.get_or_404(f.form.name_id.data)
                    new_person_list.append(person)
                elif f.form.name.data and not f.form.name_id.data:
                    person = Person(name=f.form.name.data)
                    new_person_list.append(person)
            for p in new_person_list:
                if p not in person_list:
                    c = Creator(person=p, book=book, role=default)
                    db.session.add(c)
            db.session.commit()
            
            for p in person_list:
                if p not in new_person_list:
                    c = book.creator.filter_by(person_id = p.id).first()
                    db.session.delete(c)
                    if p.creator.count() < 1:
                        db.session.delete(p)
            db.session.commit()
            
            return redirect(url_for('repair.book_edit', id=book.id))
        else: 
            print(form.errors)
            return render_template('repair/book_edit_creators.html', form=form, role=role)
    
    for i in range(3):
        if i < len(person_list):
            data = {'name': person_list[i].name, 
                    'name_id': person_list[i].id,
                    'approuved': person_list[i].approuved,
                    'incorrect': person_list[i].incorrect,
                    'role': default
                    }
            form.creators.append_entry(data)
        else:
            form.creators.append_entry({'role': default})
    return render_template('repair/book_edit_creators.html', form=form, role=role)
Exemplo n.º 13
0
def make_head(id, yymm):
    person = Person.get(id)
    if person is None:
        return None
    yy = int(yymm[:4])
    mm = int(yymm[4:])
    head = {}
    head['ym'] = '{}年{}月'.format(yy,mm)
    head['name'] = person.name
    return head
Exemplo n.º 14
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
Exemplo n.º 15
0
def destroy(id):
    item = Person.get(id)
    db.session.delete(item)
    try:
        db.session.commit()
        flash('職員の削除ができました', 'success')
    except Exception as e:
        db.session.rollback()
        flash('職員削除時にエラーが発生しました {}'.format(e), 'danger')
        app.logger.exception(e)       
    return redirect(url_for('staffs.index'))
Exemplo n.º 16
0
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 = datetime.now()
        yymm = now.strftime('%Y%m')
    else:
        now = datetime(int(yymm[:4]), int(yymm[4:]), 1)
    first = datetime(now.year, now.month, 1)
    last = first + relativedelta(months=1)
    prev = first - relativedelta(months=1)
    items = []
    head = dict(prev=prev.strftime('%Y%m'),
                next=last.strftime('%Y%m'),
                idm=person.idm == cache.get('idm'))
    foot = dict(sum=0.0, count=0, avg=0.0)
    while first < last:
        item = dict(dd=first.day,
                    week=weeka[first.weekday()],
                    situation=None,
                    work_in=None,
                    work_out=None,
                    value=None,
                    reson=None,
                    enabled=None,
                    creation=True)
        workrec = WorkRec.get_date(id, first)
        if workrec != None:
            item['situation'] = workrec.situation
            item['work_in'] = workrec.work_in
            item['work_out'] = workrec.work_out
            item['value'] = workrec.value
            item['reson'] = workrec.reason
            item['enabled'] = workrec.enabled
            item['creation'] = False
            if workrec.value != None:
                foot['sum'] = foot['sum'] + workrec.value
                foot['count'] = foot['count'] + 1
        items.append(item)
        first = first + relativedelta(days=1)
    if foot['count'] > 0:
        foot['avg'] = round(foot['sum'] / foot['count'], 1)
    else:
        foot['avg'] = 0.0
    return render_template('workrecs/index.pug',
                           person=person,
                           items=items,
                           yymm=yymm,
                           head=head,
                           foot=foot)
Exemplo n.º 17
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))
    worklog = WorkLog.get(id, yymm, dd)
    item = dict(
        id=person.id,
        yymm=yymm,
        name=person.get_display(),
        yymmdd=yymmdd.strftime('%Y/%m/%d(%a)'),
        absence=worklog.absence,
        work_in=worklog.work_in if worklog.work_in is not None else '',
        work_out=worklog.work_out if worklog.work_out is not None else '')
    if worklog is None:
        abort(404)
    if person.staff:
        form = WorkLogFormStaff(obj=worklog)
    else:
        if worklog.absence:
            form = WorkLogFormRemarks(obj=worklog)
        else:
            form = WorkLogForm(obj=worklog)
    if form.validate_on_submit():
        worklog.populate_form(form)
        try:
            db.session.add(worklog)
            try:
                db.session.commit()
                if (person.staff) and (worklog.value is None):
                    update_worklog_value.delay(id, yymm, dd)
                if not person.staff:
                    update_performlogs_enabled(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')
        except ValidationError as e:
            flash(e, 'danger')
    if person.staff:
        return render_template('worklogs/edit_staff.pug',
                               id=id,
                               yymm=yymm,
                               form=form,
                               item=item)
    return render_template('worklogs/edit.pug',
                           id=id,
                           yymm=yymm,
                           form=form,
                           item=item)
Exemplo n.º 18
0
def index():
    today = date.today()
    yesterday1 = today - relativedelta(days=1)
    yesterday2 = today - relativedelta(days=2)
    yesterday3 = today - relativedelta(days=3)
    prev = today - relativedelta(months=1)
    Item = namedtuple(
        'Item',
        ('name', 'idm', 'staff', 'caption', 'url', 'caption1', 'url1',
         'caption2', 'url2', 'caption3', 'url3', 'url_performlogs',
         'utl_performlogs_report', 'url_performlogs_report1', 'url_worklogs',
         'url_worklogs_report', 'url_worklogs_report1'))
    if current_user.is_staff():
        persons = Person.query.filter(Person.enabled == True).order_by(
            Person.staff, Person.name).all()
    else:
        persons = (Person.get_or_404(current_user.person_id), )
    items = []
    for person in persons:
        item = Item(
            person.display_or_name,
            check_idm(person),
            person.staff,
            _get_caption(person, today),
            _get_url(person, today),
            _get_caption(person, yesterday1),
            _get_url(person, yesterday1),
            _get_caption(person, yesterday2),
            _get_url(person, yesterday2),
            _get_caption(person, yesterday3),
            _get_url(person, yesterday3),
            url_for('performlogs.index',
                    id=person.id,
                    yymm=today.strftime('%Y%m')),
            url_for('performlogs.report',
                    id=person.id,
                    yymm=today.strftime('%Y%m')),
            url_for('performlogs.report',
                    id=person.id,
                    yymm=prev.strftime('%Y%m')),
            url_for('worklogs.index',
                    id=person.id,
                    yymm=today.strftime('%Y%m')),
            url_for('worklogs.report',
                    id=person.id,
                    yymm=today.strftime('%Y%m')),
            url_for('worklogs.report',
                    id=person.id,
                    yymm=prev.strftime('%Y%m')),
        )
        items.append(item)
    return render_template('index.pug', items=items)
Exemplo n.º 19
0
def persons_list():
    session['ids'] = []

    scope = request.args.get('filter', 'all', type=str)
    name = request.args.get('name', None)
    page = request.args.get('page', 1, type=int)

    form = SearchForm()
    if request.method == 'GET':
        if name:
            persons, total = Person.fuzzy_search(name, page, 20)
            if scope == 'incorrect':
                persons = persons.filter_by(incorrect=True)
            next_url = url_for('repair.persons_list', name=name, page=page + 1) \
                if total > page * 20 else None
            prev_url = url_for('repair.persons_list', name=name, page=page - 1) \
                if page > 1 else None
            return render_template('repair/persons_list.html',
                                   page=page,
                                   persons=persons,
                                   form=form,
                                   next_url=next_url,
                                   prev_url=prev_url)
        elif scope == 'incorrect':
            p = Person.query.filter_by(
                incorrect=True).order_by('name').paginate(page, 20, False)
        elif scope == 'all':
            p = Person.query.order_by('name').paginate(page, 20, False)

    elif request.method == 'POST':
        id_list = request.form.getlist('person_id')
        if len(id_list) > 4:
            flash("You can't merge more than 4 items at once.")
            return render_template('repair/persons_list.html',
                                   persons=p.items,
                                   p=p,
                                   form=form,
                                   scope=scope)
        elif len(id_list) < 2:
            flash("You need at least 2 items to merge.")
            return render_template('repair/persons_list.html',
                                   persons=p.items,
                                   p=p,
                                   form=form,
                                   scope=scope)
        session['ids'] = id_list
        return redirect(url_for('repair.persons_merge'))
    return render_template('repair/persons_list.html',
                           persons=p.items,
                           p=p,
                           form=form,
                           scope=scope)
Exemplo n.º 20
0
def destroy(id):
    item = Person.get_or_404(id)
    if bool(item.recipient):
        db.session.delete(item.recipient)
    db.session.delete(item)
    try:
        db.session.commit()
        flash('利用者の削除ができました', 'success')
    except Exception as e:
        db.session.rollback()
        flash('利用者削除時にエラーが発生しました {}'.format(e), 'danger')
        app.logger.exception(e)
    return redirect(url_for('persons.index'))
Exemplo n.º 21
0
def edit(id):
    item = Person.get(id)
    form = PersonForm(obj=item)
    if form.validate_on_submit():
        form.populate_obj(item)
        try:
            db.session.commit()
            flash('職員の変更ができました', 'success')
            return redirect(url_for('staffs.index'))
        except Exception as e:
            db.session.rollback()
            flash('職員変更時にエラーが発生しました {}'.format(e), 'danger')
            app.logger.exception(e)
    return render_template('staffs/edit.pug', id=id, form=form)
Exemplo n.º 22
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)
Exemplo n.º 23
0
def create():
    form = PersonForm()
    if form.validate_on_submit():
        item = Person(staff=True)
        form.populate_obj(item)
        db.session.add(item)
        try:
            db.session.commit()
            flash('職員の登録ができました', 'success')
            return redirect(url_for('staffs.index'))
        except Exception as e:
            db.session.rollback()
            flash('職員登録時にエラーが発生しました {}'.format(e), 'danger')
            app.logger.exception(e)
    return render_template('staffs/edit.pug', form=form)
Exemplo n.º 24
0
 def make_report_page(self, p, items):
     p.setFont('Gothic', 16)
     p.drawString(110.0*mm, 180.0*mm, '欠席時対応加算記録')
     p.setFont('Gothic', 9)
     p.drawString(105.0*mm, 174.0*mm, '※利用を中止した日の前々日、前日または当日に連絡があった場合に利用者の状況を確認し、その内容を記録する。')
     colw = (18.0*mm, 18.0*mm, 23.5*mm, 23.5*mm, 35.0*mm, 148*mm)
     data = [['利用予定日','連絡日','連絡者','対応職員','欠席理由','相談援助']]
     count = 0
     while count < len(items):
         person = Person.get(items[count].person_id)
         staff = Person.get(items[count].staff_id)
         item = [
             date(self.yy, self.mm, items[count].dd),
             items[count].contact,
             person.name if person is not None else '',
             staff.name if staff is not None else '',
             items[count].reason,
             items[count].remarks
         ]
         data.append(item)
         count = count + 1
     while self.MAX_ROW_COUNT > count:
         data.append([])
         count = count + 1
     table = Table(data, colWidths=colw, rowHeights=10.0*mm)
     table.setStyle([
         ('FONT',   ( 0, 0), (-1,-1), 'Gothic', 9),
         ('GRID',   ( 0, 0), (-1,-1), 0.5, colors.black),
         ('BOX',    ( 0, 0), (-1,-1), 1.8, colors.black),
         ('VALIGN', ( 0, 0), (-1,-1), 'MIDDLE'),
         ('ALIGN',  ( 0, 0), (-1,-1), 'CENTER'),
         ('ALIGN',  ( 5, 1), ( 5,-1), 'LEFT'),
     ])
     table.wrapOn(p, 18.0*mm, 20.0*mm)
     table.drawOn(p, 18.0*mm, 20.0*mm)
     p.showPage()
Exemplo n.º 25
0
def edit(id):
    person = Person.get(id)
    if person is None:
        abort(404)
    form = PersonForm(obj=person)
    if form.validate_on_submit():
        person.populate_form(form)
        db.session.add(person)
        try:
            db.session.commit()
            flash('職員の更新ができました', 'success')
            return redirect(url_for('staffs.index'))
        except Exception as e:
            db.session.rollback()
            flash('職員更新時にエラーが発生しました "{}"'.format(e), 'danger')
    return render_template('staffs/edit.pug', form=form)
Exemplo n.º 26
0
def destroy(id):
    person = Person.get(id)
    if person is None:
        abort(404)
    q=db.session.\
        query(func.count(WorkRec.yymm)).\
        filter_by(person_id=id).\
        group_by(WorkRec.person_id).first()
    if q is not None:
        flash('このユーザは勤怠データが存在しています', 'danger')
        return redirect(url_for('persons.index'))
    db.session.delete(person)
    try:
        db.session.commit()
        flash('Person delete successfully.', 'success')
    except Exception as e:
        db.session.rollback()
        flash('Error delete person! {}'.format(e.message), 'danger')
    return redirect(url_for('persons.index'))
Exemplo n.º 27
0
def edit(id):
    person = Person.get(id)
    if person is None:
        abort(404)
    form = PersonForm(obj=person)
    if form.validate_on_submit():
        person.populate_form(form)
        db.session.add(person)
        try:
            db.session.commit()
            flash('Person saved successfully.', 'success')
            return redirect(url_for('persons.index'))
        except IntegrityError:
            db.session.rollback()
            flash('同一IDMが指定された可能性が有ります', 'danger')
        except Exception as e:
            db.session.rollback()
            flash('Error update person! {}'.format(e.message), 'danger')
    return render_template('persons/edit.pug', form=form)
Exemplo n.º 28
0
def create():
    form = PersonForm()
    if form.validate_on_submit():
        person = Person()
        person.populate_form(form)
        person.id = None
        person.staff = False
        recipient = Recipient()
        person.recipient = recipient
        db.session.add(person)
        try:
            db.session.commit()
            flash('メンバーの追加ができました', 'success')
            return redirect(url_for('persons.index'))
        except Exception as e:
            db.session.rollback()
            flash('メンバー追加時にエラーが発生しました "{}"'.format(e), 'danger')
    return render_template('persons/edit.pug', form=form)
Exemplo n.º 29
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.staff:
        flash('職員以外は勤怠削除はできません。実績削除で行ってください "{}"'.format(e), 'danger')
        return redirect(url_for('performlogs.index', id=id, yymm=yymm))
    worklog = WorkLog.get(id, yymm, dd)
    if worklog is None:
        abort(404)
    db.session.delete(worklog)
    try:
        db.session.commit()
        flash('勤怠の削除ができました', 'success')
    except Exception as e:
        db.session.rollback()
        flash('勤怠削除時にエラーが発生しました "{}"'.format(e), 'danger')
    return redirect(url_for('worklogs.index', id=id, yymm=yymm))
Exemplo n.º 30
0
def destroy(id, yymm, dd):
    person = Person.get(id)
    if person is None:
        abort(404)
    idm = cache.get('idm')
    workrec = WorkRec.get(id, yymm, dd)
    if (idm != person.idm) and ((workrec is not None) and
                                (workrec.work_in is not None)):
        flash('利用者のICカードをタッチしてください', 'danger')
    if (workrec is not None) and ((idm == person.idm) or
                                  (workrec.work_in is None)):
        db.session.delete(workrec)
        try:
            db.session.commit()
            enabled_workrec.delay(id, yymm)
            flash('Entry delete successfully.', 'success')
        except:
            db.session.rollback()
            flash('Error delete entry!', 'danger')
    return redirect(url_for('workrecs.index', id=id, yymm=yymm))