kohir.py
3.78 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from sqlalchemy import (
Column,
Integer,
DateTime,
UniqueConstraint,
String,
SmallInteger,
Index,
BigInteger,
text,
func
)
from datetime import datetime
from dateutil.relativedelta import relativedelta
from opensipkd.pjdl.models.spt_invoice import PjdlInvoice
from . import DBSession
from . import PAD_TABLE_ARGS, DefaultModel, Base
class PjdlKohir(Base, DefaultModel):
__tablename__ = 'pad_kohir'
__table_args__ = (
UniqueConstraint('tahun', 'kohirno', 'usaha_id'),
Index('pad_kohir_tahun_usaha_id_kohirno_idx',
'tahun', 'usaha_id', 'kohirno'),
PAD_TABLE_ARGS
)
id = Column(BigInteger, primary_key=True)
tahun = Column(Integer, nullable=False, index=True)
usaha_id = Column(Integer)
kohirno = Column(Integer, nullable=False, index=True)
kohirtgl = Column(DateTime, nullable=False, index=True)
sptpd_id = Column(BigInteger, nullable=False, index=True)
spt_id = Column(BigInteger, nullable=False, index=True)
enabled = Column(SmallInteger)
create_date = Column(DateTime)
create_uid = Column(Integer)
write_date = Column(DateTime)
write_uid = Column(Integer)
is_cancel = Column(Integer, server_default=text("0"))
bap_no = Column(String)
bap_date = Column(DateTime)
cancel_no = Column(BigInteger)
cancel_date = Column(DateTime)
cancel_thn = Column(Integer)
cancel_uid = Column(Integer)
@classmethod
def get_kohir_no(cls, row=None):
if not row:
tahun = datetime.now().year
else:
tahun = row.tahun
result = DBSession.query(func.max(cls.kohirno)).\
filter_by(tahun=tahun).scalar()
result = result and result > 0 and result+1 or 1
return result
@classmethod
def generate_cancelno(cls, row=None):
if not row:
tahun = datetime.now().year
else:
tahun = row.tahun
result = DBSession.query(func.max(cls.cancel_no)).\
filter_by(cancel_thn=tahun).scalar()
result = result and result > 0 and result+1 or 1
return result
@classmethod
def query_spt_id(cls, spt_id=None):
q = DBSession.query(cls).\
filter_by(spt_id=spt_id)
return q
@classmethod
def get_spt_kohirno(self):
kohirno = func.get_spt_kohirno(self.spt_id)
return kohirno
@classmethod
def get_spt_kohirno2(self):
kohirno = func.get_spt_kohirno(self.id)
return kohirno
@classmethod
def proses(cls, row, user):
now = datetime.now()
kohir = PjdlKohir.query().filter(PjdlKohir.spt_id == row.id).first()
if kohir:
return ("error", "Data sudah ditetapkan")
if row.sptno < 0:
row.sptno = PjdlInvoice.get_spt_no(row)
no_urut = str(row.sptno).zfill(5)
no_urut6 = str(row.sptno).zfill(6)
from opensipkd.pjdl.apps import MODULE_CLASS
spt_no_tpl = MODULE_CLASS.spt_no_tpl
row.spt_no = spt_no_tpl.format(kd_pemda=MODULE_CLASS.kd_pemda,
tahun=row.tahun, no_urut=no_urut,
no_urut6=no_urut6)
row.terimatgl = now.date()
row.jatuhtempotgl = now+relativedelta(days=row.spt_typ.max_day)
row.status_pembayaran = 0
DBSession.add(row)
kohir = PjdlKohir()
kohir.spt_id = row.id
kohir.kohirtgl = now.date()
kohir.tahun = now.year
kohir.enabled = 1
kohir.create_date = now
kohir.create_uid = user.id
kohir.kohirno = PjdlKohir.get_kohir_no(row=kohir)
kohir.usaha_id = row.op.usaha_id
DBSession.add(kohir)
DBSession.flush()
return ("success", "Data sudah ditetapkan")