spt_tegur.py
2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from datetime import datetime
from sqlalchemy import (Column, Integer, DateTime, ForeignKey,
UniqueConstraint, BigInteger, func)
from sqlalchemy.orm import (relationship)
from . import PAD_TABLE_ARGS, DefaultModel, Base
from . import (PjdlWp, PjdlOp, PjdlPajak,)
class PjdlSptTegur(Base, DefaultModel):
__tablename__ = 'pad_spt_tegur'
__table_args__ = (
UniqueConstraint('tahun', 'tegurno'),
PAD_TABLE_ARGS
)
id = Column(BigInteger, primary_key=True, index=True)
create_date = Column(DateTime)
create_uid = Column(Integer)
write_date = Column(DateTime)
write_uid = Column(Integer)
tahun = Column(Integer, nullable=False, index=True)
tegurno = Column(Integer, nullable=False, index=True)
tegurtgl = Column(DateTime, nullable=False, index=True)
masa_bln = Column(Integer, nullable=False, index=True)
masa_thn = Column(Integer, nullable=False, index=True)
masa_dari = Column(DateTime, nullable=False, index=True)
masa_sd = Column(DateTime, nullable=False, index=True)
jatuhtempotgl = Column(DateTime, nullable=False, index=True)
ke = Column(Integer, nullable=False, index=True)
customer_id = Column(ForeignKey(
PjdlWp.id, onupdate='CASCADE'), nullable=False, index=True)
customer_usaha_id = Column(
ForeignKey(PjdlOp.id, ondelete='CASCADE', onupdate='CASCADE'),
nullable=False, index=True)
pajak_id = Column(ForeignKey(PjdlPajak.id, onupdate='CASCADE'),
nullable=False)
wp = relationship('PjdlWp', backref='pad_spt_tegur')
op = relationship('PjdlOp', backref='pad_spt_tegur')
pajak = relationship('PjdlPajak', backref='pad_spt_tegur')
@classmethod
def get_tegurno(cls, tahun=None):
if not tahun:
tahun = datetime.now().year
no = cls.query_from([func.max(cls.tegurno)])\
.filter_by(tahun=tahun).scalar()
return no and no + 1 or 1
@classmethod
def get_ke(cls, value):
customer_usaha_id = value["customer_usaha_id"]
ke = cls.query_from([func.max(cls.ke)])\
.filter_by(customer_usaha_id=customer_usaha_id,
masa_thn=value["masa_thn"],
masa_bln=value["masa_bln"],
).scalar()
ke = ke and ke + 1 or 1
if ke>3:
raise Exception("Teguran hanya 3 kali silahkan tetapkan dengan SKPD Jabatan")
return ke
@classmethod
def get_prev(cls, value):
customer_usaha_id = value["customer_usaha_id"]
jth_tempo = cls.query_from([func.max(cls.jatuhtempotgl)])\
.filter_by(customer_usaha_id=customer_usaha_id,
masa_thn=value["masa_thn"],
masa_bln=value["masa_bln"],
).scalar()
if jth_tempo and jth_tempo > value["tegurtgl"]:
raise Exception("Teguran sebelumnya belum jatuh tempo")