Ejemplo n.º 1
0
class AbsenceLog(db.Model):
    __tablename__ = 'absencelogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id', 'yymm', 'dd'], [
                          'performlogs.person_id', 'performlogs.yymm',
                          'performlogs.dd'
                      ],
                                              onupdate='CASCADE',
                                              ondelete='CASCADE'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.ForeignKeyConstraint(['staff_id'], ['persons.id']),
                      db.Index('absencelogs_yymmdd', 'yymm', 'dd'), {
                          'mysql_engine': 'InnoDB'
                      })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    enabled = db.Column(db.Boolean)  # 月に4回以上であればFalse
    deleted = db.Column(db.Boolean)  # 欠席加算のチェックオフになったらTrue
    contact = db.Column(db.Date)  # 連絡日
    staff_id = db.Column(db.String(36))  # 対応職員
    reason = db.Column(db.String(128))  # 欠席理由
    remarks = db.Column(db.String(128))  # 相談援助
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)
    performlog = db.relationship('PerformLog', back_populates="absencelog")

    def populate_form(self, form):
        form.populate_obj(self)

    @classmethod
    def get(cls, id, yymm, dd):
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm,
                                cls.dd == dd).first()
Ejemplo n.º 2
0
class WorkLog(db.Model, ModelMixInID, ModelMixInYYMMDD):
    __tablename__ = 'worklogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.ForeignKeyConstraint(['company_id'],
                                              ['companies.id']),
                      db.Index('worklogs_yymmdd', 'yymm', 'person_id', 'dd'), {
                          'mysql_engine': 'InnoDB'
                      })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    presented = db.Column(db.Boolean)  # 勤怠として有効ならtrue
    work_in = db.Column(db.String(8))  # 開始時間
    work_out = db.Column(db.String(8))  # 終了時間
    value = db.Column(db.Float)  # 勤務時間
    break_t = db.Column(db.Float)  # 休憩時間
    over_t = db.Column(db.Float)  # 残業時間
    absence = db.Column(db.Boolean)  # 欠勤
    late = db.Column(db.Boolean)  # 遅刻
    leave = db.Column(db.Boolean)  # 早退
    company_id = db.Column(db.String(36))  # 就労先企業
    remarks = db.Column(db.String(128))  # 備考
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def __repr__(self):
        return '<WorkLog: id={0.person_id}, yymm={0.yymm}, dd={0.dd}, name={0.person.name}>'.format(
            self)

    @property
    def date(self):
        yy = int(self.yymm[:4])
        mm = int(self.yymm[4:])
        return date(yy, mm, int(self.dd))

    @property
    def person(self):
        if hasattr(self, '__person'):
            return self.__person
        self.__person = Person.query.get(self.person_id)
        return self.__person

    @property
    def url_edit(self):
        return url_for('worklogs.edit',
                       id=self.person_id,
                       yymm=self.yymm,
                       dd=self.dd)

    @property
    def url_delete(self):
        if self.presented is None:
            return url_for('worklogs.index', id=self.person_id, yymm=self.yymm)
        return url_for('worklogs.destory',
                       id=self.person_id,
                       yymm=self.yymm,
                       dd=self.dd)
Ejemplo n.º 3
0
class AbsenceLog(db.Model, ModelMixInID):
    __tablename__ = 'absencelogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id', 'yymm', 'dd'], [
                          'performlogs.person_id', 'performlogs.yymm',
                          'performlogs.dd'
                      ],
                                              onupdate='CASCADE',
                                              ondelete='CASCADE'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.ForeignKeyConstraint(['staff_id'], ['persons.id']),
                      db.Index('absencelogs_yymmdd', 'yymm', 'dd'), {
                          'mysql_engine': 'InnoDB'
                      })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    contact = db.Column(db.Date)  # 連絡日
    staff_id = db.Column(db.String(36))  # 対応職員
    reason = db.Column(db.String(128))  # 欠席理由
    remarks = db.Column(db.String(128))  # 相談援助
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    @property
    def date(self):
        yy = int(self.yymm[:4])
        mm = int(self.yymm[4:])
        return date(yy, mm, self.dd)

    @property
    def person(self):
        if hasattr(self, '__person'):
            return self.__person
        self.__person = Person.query.get(self.person_id)
        return self.__person

    @property
    def staff(self):
        if hasattr(self, '__staff'):
            return self.__staff
        self.__staff = Person.query.filter(Person.id == self.staff_id).first()
        return self.__staff

    @property
    def date(self):
        yy = int(self.yymm[:4])
        mm = int(self.yymm[4:])
        return date(yy, mm, int(self.dd))
Ejemplo n.º 4
0
class User(db.Model, UserMixin, ModelMixInID):
    __tablename__ = 'users'
    __table_args__ = (db.ForeignKeyConstraint(['person_id'], ['persons.id']), {
        'mysql_engine': 'InnoDB'
    })
    id = db.Column(db.String(36), primary_key=True, default=_get_uuid)
    userid = db.Column(db.String(20), nullable=False, unique=True)
    password = db.Column(db.String(100), nullable=False)
    enabled = db.Column(db.Boolean)  # 有効化
    admin = db.Column(db.Boolean)  # admin権限
    email = db.Column(db.String(128))  # パスワードリセット用
    staff = db.Column(db.Boolean)  # 職員
    person_id = db.Column(db.String(36))  # 利用者ID
    remarks = db.Column(db.String(128))  # 備考
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def __repr__(self):
        return '<User: id={0.id}, userid={0.userid}>'.format(self)

    def set_password(self, password):
        if password:
            password = password.strip()
        self.password = generate_password_hash(password)

    def check_password(self, password):
        password = password.strip()
        if not password:
            return False
        return check_password_hash(self.password, password)

    def is_enabled(self):
        return self.enabled

    def is_admin(self):
        return self.admin

    def is_staff(self):
        return self.staff

    @property
    def person(self):
        if hasattr(self, '__person'):
            return self.__person
        if self.person_id is None:
            self.__person = None
        else:
            self.__person = Person.query.get(self.person_id)
        return self.__person

    @classmethod
    def auth(cls, userid, password):
        user = cls.query.filter(cls.userid == userid).first()
        if user is None:
            return None, False
        if not user.enabled:
            return user, False
        return user, user.check_password(password)
Ejemplo n.º 5
0
class WorkLog(db.Model):
    __tablename__ = 'worklogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.Index('worklogs_yymmdd', 'yymm', 'person_id', 'dd'), {
                          'mysql_engine': 'InnoDB'
                      })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    presented = db.Column(db.Boolean)  # 勤怠として有効ならtrue
    work_in = db.Column(db.String(8))  # 開始時間
    work_out = db.Column(db.String(8))  # 終了時間
    value = db.Column(db.Float)  # 勤務時間
    break_t = db.Column(db.Float)  # 休憩時間
    over_t = db.Column(db.Float)  # 残業時間
    absence = db.Column(db.Boolean)  # 欠勤
    late = db.Column(db.Boolean)  # 遅刻
    leave = db.Column(db.Boolean)  # 早退
    remarks = db.Column(db.String(128))  # 備考
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def populate_form(self, form):
        form.populate_obj(self)
        if (self.work_in is not None) and (len(self.work_in) == 0):
            self.work_in == None
        if (self.work_out is not None) and (len(self.work_out) == 0):
            self.work_out == None
        if (self.remarks is not None) and (len(self.remarks) == 0):
            self.remarks == None
        if bool(self.work_in) or bool(self.work_out) or (self.value
                                                         is not None):
            self.presented = True
        else:
            self.presented = False
        worklog = WorkLog.get(self.person_id, self.yymm, self.dd)
        if (worklog is not None) and (worklog.value is not None):
            self.presented = True

    @classmethod
    def get(cls, id, yymm, dd):
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm,
                                cls.dd == dd).first()

    @classmethod
    def get_date(cls, id, yymmdd):
        yymm = yymmdd.strftime('%Y%m')
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm,
                                cls.dd == yymmdd.day).first()

    @classmethod
    def get_yymm(cls, id, yymm):
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm).all()
Ejemplo n.º 6
0
class Recipient(db.Model):
    __tablename__ = 'recipients'
    __table_args__ = (db.PrimaryKeyConstraint('person_id'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id'],
                                              onupdate='CASCADE',
                                              ondelete='CASCADE'), {
                                                  'mysql_engine': 'InnoDB'
                                              })
    person_id = db.Column(db.String(36))  # 利用者ID
    number = db.Column(db.String(10), nullable=True)  # 受給者番号
    amount = db.Column(db.String(64), nullable=True)  # 契約支給量
    usestart = db.Column(db.Date, nullable=True)  # 利用開始日
    supply_in = db.Column(db.Date, nullable=True)  # 支給決定開始日
    supply_out = db.Column(db.Date, nullable=True)  # 支給決定終了日
    apply_in = db.Column(db.Date, nullable=True)  # 適用決定開始日
    apply_out = db.Column(db.Date, nullable=True)  # 適用決定終了日
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)
    person = db.relationship('Person', back_populates="recipient")

    def get_usestart(self):
        if self.usestart is None:
            return None, None
        return self.usestart, self.usestart + relativedelta(days=30)

    def is_usestart(self, d):
        usestart, usestart30d = self.get_usestart()
        if usestart is None:
            return False
        return (usestart <= d) and (d <= usestart30d)

    def is_apply_over(self, yymmdd=None):
        if (not bool(self.apply_in)) or (not bool(self.apply_out)):
            return False
        if yymmdd is None:
            yymmdd = date.today()
        yymmdd = yymmdd + relativedelta(months=1)
        return self.apply_out < yymmdd

    def is_supply_over(self, yymmdd=None):
        if (not bool(self.supply_in)) or (not bool(self.supply_out)):
            return False
        if yymmdd is None:
            yymmdd = date.today()
        yymmdd = yymmdd + relativedelta(months=1)
        return self.supply_out < yymmdd

    def populate_form(self, form):
        form.populate_obj(self)

    @classmethod
    def get(cls, id):
        return cls.query.filter(cls.person_id == id).first()
Ejemplo n.º 7
0
class Recipient(db.Model, ModelMixInID):
    __tablename__ = 'recipients'
    __table_args__ = (db.PrimaryKeyConstraint('person_id'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id'],
                                              onupdate='CASCADE',
                                              ondelete='CASCADE'), {
                                                  'mysql_engine': 'InnoDB'
                                              })
    person_id = db.Column(db.String(36))  # 利用者ID
    number = db.Column(db.String(10), nullable=True)  # 受給者番号
    amount = db.Column(db.String(64), nullable=True)  # 契約支給量
    usestart = db.Column(db.Date, nullable=True)  # 利用開始日
    supply_in = db.Column(db.Date, nullable=True)  # 支給決定開始日
    supply_out = db.Column(db.Date, nullable=True)  # 支給決定終了日
    apply_in = db.Column(db.Date, nullable=True)  # 適用決定開始日
    apply_out = db.Column(db.Date, nullable=True)  # 適用決定終了日
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def __repr__(self):
        return '<Recipient: id={id}, name="{name}">'.format(
            id=self.person_id, name=self.person.name)

    @property
    def person(self):
        if hasattr(self, '__person'):
            return self.__person
        self.__person = Person.query.get(self.person_id)
        return self.__person

    def is_supply_over(self):
        if not self.person.enabled:
            return False
        if not bool(self.supply_out):
            return False
        dead = date.today()
        dead += relativedelta(months=1)
        return self.supply_out < dead

    def is_apply_over(self):
        if not self.person.enabled:
            return False
        if not bool(self.apply_out):
            return False
        dead = date.today()
        dead += relativedelta(months=1)
        return self.apply_out < dead
Ejemplo n.º 8
0
class Agree(db.Model, ModelMixInID):
    __tablename__ = 'agrees'
    __table_args__ = (db.PrimaryKeyConstraint('id'),
                      db.ForeignKeyConstraint(['company_id'],
                                              ['companies.id']), {
                                                  'mysql_engine': 'InnoDB'
                                              })
    id = db.Column(db.String(36), default=_get_uuid)
    company_id = db.Column(db.String(36))
    caption = db.Column(db.String(64), nullable=False)  # 表示名
    agree_in = db.Column(db.Date, nullable=False)  # 契約開始
    agree_out = db.Column(db.Date, nullable=False)  # 契約終了
    content = db.Column(db.String(128), nullable=False)  # 作業内容、作業場所
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    @property
    def company(self):
        if hasattr(self, '__company'):
            return self.__company
        self.__company = Company.query.get(self.company_id)
        return self.__company
Ejemplo n.º 9
0
class PerformLog(db.Model, ModelMixInID, ModelMixInYYMMDD):
    __tablename__ = 'performlogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.ForeignKeyConstraint(['company_id'],
                                              ['companies.id']),
                      db.Index('performlogs_yymmdd', 'yymm', 'person_id',
                               'dd'), {
                                   'mysql_engine': 'InnoDB'
                               })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    enabled = db.Column(db.Boolean)  # 実績票出力対象はTrue
    presented = db.Column(db.Boolean)  # 月の日数-8を超えたらFalse
    absence = db.Column(db.Boolean, nullable=False)  # 欠席
    absence_add = db.Column(db.Boolean, nullable=False)  # 欠席加算対象
    work_in = db.Column(db.String(8))  # 開始時間
    work_out = db.Column(db.String(8))  # 終了時間
    pickup_in = db.Column(db.Boolean)  # 送迎加算(往路)
    pickup_out = db.Column(db.Boolean)  # 送迎加算(復路)
    visit = db.Column(db.Integer)  # 訪問支援特別加算(時間数)
    meal = db.Column(db.Boolean)  # 食事提供加算
    medical = db.Column(db.Integer)  # 医療連携体制加算
    experience = db.Column(db.Integer)  # 体験利用支援加算
    outside = db.Column(db.Boolean)  # 施設外支援
    company_id = db.Column(db.String(36))  # 就労先企業
    remarks = db.Column(db.String(128))  # 備考
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def __repr__(self):
        return '<PerformLog: id={0.person_id}, yymm={0.yymm}, dd={0.dd}, name={0.person.name}>'.format(
            self)

    @property
    def date(self):
        yy = int(self.yymm[:4])
        mm = int(self.yymm[4:])
        return date(yy, mm, int(self.dd))

    @property
    def person(self):
        if hasattr(self, '__person'):
            return self.__person
        self.__person = Person.query.get(self.person_id)
        return self.__person

    @property
    def absencelog(self):
        if hasattr(self, '__absencelog'):
            return self.__absencelog
        self.__absencelog = AbsenceLog.query.get(
            (self.person.id, self.yymm, self.dd))

    @property
    def company(self):
        if hasattr(self, '__company'):
            return self.__company
        self.__company = Company.query.get(self.company_id) if bool(
            self.company_id) else None
        return self.__company

    @property
    def url_edit(self):
        return url_for('performlogs.edit',
                       id=self.person_id,
                       yymm=self.yymm,
                       dd=self.dd)

    @property
    def url_delete(self):
        if self.enabled is None:
            return url_for('performlogs.index',
                           id=self.person_id,
                           yymm=self.yymm)
        return url_for('performlogs.destroy',
                       id=self.person_id,
                       yymm=self.yymm,
                       dd=self.dd)
Ejemplo n.º 10
0
class PerformLog(db.Model):
    __tablename__ = 'performlogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.Index('performlogs_yymmdd', 'yymm', 'person_id',
                               'dd'), {
                                   'mysql_engine': 'InnoDB'
                               })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    enabled = db.Column(db.Boolean)  # 実績票出力対象はTrue
    presented = db.Column(db.Boolean)  # 月の日数-8を超えたらFalse
    absence = db.Column(db.Boolean, nullable=False)  # 欠席
    absence_add = db.Column(db.Boolean, nullable=False)  # 欠席加算対象
    work_in = db.Column(db.String(8))  # 開始時間
    work_out = db.Column(db.String(8))  # 終了時間
    pickup_in = db.Column(db.Boolean)  # 送迎加算(往路)
    pickup_out = db.Column(db.Boolean)  # 送迎加算(復路)
    visit = db.Column(db.Integer)  # 訪問支援特別加算(時間数)
    meal = db.Column(db.Boolean)  # 食事提供加算
    medical = db.Column(db.Integer)  # 医療連携体制加算
    experience = db.Column(db.Integer)  # 体験利用支援加算
    outside = db.Column(db.Boolean)  # 施設外支援
    outemp = db.Column(db.Boolean)  # 施設外就労
    remarks = db.Column(db.String(128))  # 備考
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)
    absencelog = db.relationship('AbsenceLog',
                                 uselist=False,
                                 back_populates="performlog")

    def populate_form(self, form):
        form.populate_obj(self)
        if not bool(self.work_in):
            self.work_in == None
        if not bool(self.work_out):
            self.work_out == None
        if not bool(self.remarks):
            self.remarks == None

    def validate(self):
        if self.absence:
            if bool(self.work_in) or bool(self.work_out):
                raise ValidationError('開始・終了時刻が入っているため、欠席にはできません')
        if self.absence_add:
            if not self.absence:
                raise ValidationError('欠席にチェックしてください')

    def sync_to_worklog(self, worklog):
        if worklog is None:
            worklog = WorkLog(person_id=self.person_id,
                              yymm=self.yymm,
                              dd=self.dd)
        worklog.absence = self.absence
        worklog.work_in = self.work_in
        worklog.work_out = self.work_out
        if worklog.absence:
            worklog.presented = False
        elif bool(worklog.work_in) or bool(worklog.work_out) or (worklog.value
                                                                 is not None):
            worklog.presented = True
        else:
            worklog.presented = False
        db.session.add(worklog)

    def sync_from_worklog(self, workrec):
        # ICカードから入力なので欠席は取消す
        self.absence = False
        self.absence_add = False
        self.work_in = workrec.work_in
        self.work_out = workrec.work_out
        if bool(self.absencelog):
            self.absencelog.deleted = True

    @classmethod
    def get(cls, id, yymm, dd):
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm,
                                cls.dd == dd).first()

    @classmethod
    def get_date(cls, id, yymmdd):
        yymm = yymmdd.strftime('%Y%m')
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm,
                                cls.dd == yymmdd.day).first()

    @classmethod
    def get_yymm(cls, id, yymm):
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm).all()