-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPM_SPCall.py
222 lines (172 loc) · 11.5 KB
/
IPM_SPCall.py
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
try:
import sys
#import Mail
import datetime
import SQL_Connections
from Logger import Logger
import IPM_Select_And_Updates
# package should be install, if not [Command: pip install modulename]
except ModuleNotFoundError as err:
print(str({err.name.strip()})," module is missing, Command to Install - {"" pip install ", str(err.name.strip()), "}")
sys.exit(1)
######################################################################################################################################################
logger = Logger()
######################################################################################################################################################
def SP_Call_ChangeFileStatus(Connection_String, IPMFileSequence):
try:
SP_result = SQL_Connections.udf_SPCall(Connection_String,f"EXEC PR_ChangeFileStatusInQueuetoNew '{IPMFileSequence}'")
except Exception as e:
ErrorReason = f"Error Raised PR_ChangeFileStatusInQueuetoNew : {e} and result of SP = {SP_result[-1][-1]}"
logger.debug(ErrorReason, True)
logger.log_exception(*sys.exc_info())
sys.exit()
return SP_result[-1][-1]
#############################################################################################################################################
def IPM_SPCall(Connection_String, Inp_Jobid, Parse_rec_count, ValidationEnable, UseCCard, Stage_StartTime, EmailTo, EmailFrom, SMTP_SERVER, SMTP_PORT, FileSource,AgingFLag):
pfurther = False
SP_result = 0
SP_result = SQL_Connections.udf_SPCall(Connection_String,f"EXEC PR_MCIPM_UpdAdditionalDetails {Inp_Jobid},{Parse_rec_count},{AgingFLag}",Inp_Jobid)
logger.info(f"SP Result = {SP_result[-1][-1]}")
pfurther = CheckFileStatus(Connection_String, Inp_Jobid)
if pfurther and SP_result[-1][-1] == 1 :
pfurther = False
SP_result = 0
Stage_EndTime = datetime.datetime.now()
TimeDiff = str(Stage_EndTime - Stage_StartTime)
TimeTaken = f"PARSING {TimeDiff[:-3]}"
IPM_Select_And_Updates.IPM_Update(1, Connection_String, Inp_Jobid, 'UPDATEACCOUNT', 'PARSING', TimeTaken, To = 4, From = 2)
Stage_StartTime = datetime.datetime.now()
logger.info("************************************ PARSING END ************************************",True)
#Mail.SendEmail(3, 'Clearing And Settlement', EmailTo, EmailFrom, SMTP_SERVER, SMTP_PORT, Connection_String, Inp_Jobid, FileSource)
SP_result = SQL_Connections.udf_SPCall(Connection_String,f"EXEC PR_MCIPMUpdateAcctDetails {Inp_Jobid},{ValidationEnable}",Inp_Jobid)
logger.info(f"SP Result = {SP_result[-1][-1]}")
pfurther = CheckFileStatus(Connection_String, Inp_Jobid)
else:
ErrorReason = "File Status in ClearingFiles gets ERROR while executing PR_MCIPM_UpdAdditionalDetails Or SP Fail To Execute Successfully"
ErrorReason = ErrorReason.replace("'","")
IPM_Select_And_Updates.IPM_Update(5,Connection_String, Inp_Jobid, 'ERROR', ErrorReason)
logger.error(ErrorReason)
sys.exit()
if pfurther and SP_result[-1][-1] == 1 :
pfurther = False
SP_result = 0
Stage_EndTime = datetime.datetime.now()
TimeDiff = str(Stage_EndTime - Stage_StartTime)
TimeTaken = f"UPDATEACCOUNT {TimeDiff[:-3]}"
Stage_StartTime = datetime.datetime.now()
IPM_Select_And_Updates.IPM_Update(1, Connection_String, Inp_Jobid, 'AUTHMATCHING','UPDATEACCOUNT', TimeTaken, To = 5, From = 3)
#Mail.SendEmail(3, 'Clearing And Settlement', EmailTo, EmailFrom, SMTP_SERVER, SMTP_PORT, Connection_String, Inp_Jobid, FileSource)
ProcessingDateTime = datetime.datetime.now()
Ins_ProcessingDateTime = ProcessingDateTime.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
SP_result = SQL_Connections.udf_SPCall(Connection_String,f"EXEC PR_MCIPMAuthMatchingDynamic '{Ins_ProcessingDateTime}',{Inp_Jobid},{ValidationEnable}",Inp_Jobid)
logger.info(f"SP Result = {SP_result[-1][-1]}")
pfurther = CheckFileStatus(Connection_String, Inp_Jobid)
else:
ErrorReason = f"File Status in ClearingFiles gets ERROR while executing PR_MCIPMUpdateAcctDetails Or SP Fail To Execute Successfully"
logger.debug(ErrorReason)
IPM_Select_And_Updates.IPM_Update(5,Connection_String, Inp_Jobid, 'ERROR', ErrorReason)
sys.exit()
if pfurther and SP_result[-1][-1] == 1 :
pfurther = False
SP_result = 0
ProcessingDateTime = datetime.datetime.now()
Ins_ProcessingDateTime = ProcessingDateTime.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
SP_result = SQL_Connections.udf_SPCall(Connection_String,f"EXEC PR_MCIPMGenerateLCIDForUnMatchedClr {Inp_Jobid},'{Ins_ProcessingDateTime}'",Inp_Jobid)
logger.info(f"SP Result = {SP_result[-1][-1]}")
pfurther = CheckFileStatus(Connection_String, Inp_Jobid)
else:
ErrorReason = "File Status in ClearingFiles gets ERROR while executing PR_MCIPMAuthMatchingDynamic Or SP Fail To Execute Successfully"
logger.debug(ErrorReason)
IPM_Select_And_Updates.IPM_Update(5,Connection_String, Inp_Jobid, 'ERROR', ErrorReason)
sys.exit()
if pfurther and SP_result[-1][-1] == 1 :
pfurther = False
SP_result = 0
Stage_EndTime = datetime.datetime.now()
TimeDiff = str(Stage_EndTime - Stage_StartTime)
TimeTaken = f"AUTHMATCHING {TimeDiff[:-3]}"
Stage_StartTime = datetime.datetime.now()
IPM_Select_And_Updates.IPM_Update(1, Connection_String, Inp_Jobid, 'REVMATCHING','AUTHMATCHING', TimeTaken, To = 6, From = 4)
#Mail.SendEmail(3, 'Clearing And Settlement', EmailTo, EmailFrom, SMTP_SERVER, SMTP_PORT, Connection_String, Inp_Jobid, FileSource)
SP_result = SQL_Connections.udf_SPCall(Connection_String,f"EXEC PR_MCIPMRevMatchingDynamic {Inp_Jobid},{ValidationEnable}",Inp_Jobid)
logger.info(f"SP Result = {SP_result[-1][-1]}")
pfurther = CheckFileStatus(Connection_String, Inp_Jobid)
else:
ErrorReason = "File Status in ClearingFiles gets ERROR while executing PR_MCIPMGenerateLCIDForUnMatchedClr Or SP Fail To Execute Successfully"
logger.debug(ErrorReason)
IPM_Select_And_Updates.IPM_Update(5,Connection_String, Inp_Jobid, 'ERROR', ErrorReason)
sys.exit()
if pfurther and SP_result[-1][-1] == 1 :
pfurther = False
SP_result = 0
Stage_EndTime = datetime.datetime.now()
TimeDiff = str(Stage_EndTime - Stage_StartTime)
TimeTaken = f"REVMATCHING {TimeDiff[:-3]}"
Stage_StartTime = datetime.datetime.now()
IPM_Select_And_Updates.IPM_Update(1, Connection_String, Inp_Jobid, 'INVALIDTXN','REVMATCHING', TimeTaken, To = 7, From = 5)
#Mail.SendEmail(3, 'Clearing And Settlement', EmailTo, EmailFrom, SMTP_SERVER, SMTP_PORT, Connection_String, Inp_Jobid, FileSource)
SP_result = SQL_Connections.udf_SPCall(Connection_String,f"EXEC PR_GenerateIPMTxnForInvalidCard {Inp_Jobid},{ValidationEnable}",Inp_Jobid)
logger.info(f"SP Result = {SP_result[-1][-1]}")
pfurther = CheckFileStatus(Connection_String, Inp_Jobid)
else:
ErrorReason = "File Status in ClearingFiles gets ERROR while executing PR_MCIPMRevMatchingDynamic Or SP Fail To Execute Successfully"
logger.debug(ErrorReason)
IPM_Select_And_Updates.IPM_Update(5,Connection_String, Inp_Jobid, 'ERROR', ErrorReason)
sys.exit()
if pfurther and SP_result[-1][-1] == 1 :
pfurther = False
SP_result = 0
Stage_EndTime = datetime.datetime.now()
TimeDiff = str(Stage_EndTime - Stage_StartTime)
TimeTaken = f"INVALIDTXN {TimeDiff[:-3]}"
Stage_StartTime = datetime.datetime.now()
IPM_Select_And_Updates.IPM_Update(1, Connection_String, Inp_Jobid, 'SECONDPRESENTMENT','INVALIDTXN', TimeTaken, To = 8, From = 6)
#Mail.SendEmail(3, 'Clearing And Settlement', EmailTo, EmailFrom, SMTP_SERVER, SMTP_PORT, Connection_String, Inp_Jobid, FileSource)
SP_result = SQL_Connections.udf_SPCall(Connection_String,f"EXEC pr_IPMSecondPresentment {Inp_Jobid},{ValidationEnable}",Inp_Jobid)
logger.info(f"SP Result = {SP_result[-1][-1]}")
pfurther = CheckFileStatus(Connection_String, Inp_Jobid)
else:
ErrorReason = "File Status in ClearingFiles gets ERROR while executing PR_GenerateIPMTxnForInvalidCard Or SP Fail To Execute Successfully"
logger.debug(ErrorReason)
IPM_Select_And_Updates.IPM_Update(5,Connection_String, Inp_Jobid, 'ERROR', ErrorReason)
sys.exit()
if pfurther and SP_result[-1][-1] == 1 :
pfurther = False
SP_result = 0
Stage_EndTime = datetime.datetime.now()
TimeDiff = str(Stage_EndTime - Stage_StartTime)
TimeTaken = f"SECONDPRESENTMENT {TimeDiff[:-3]}"
Stage_StartTime = datetime.datetime.now()
IPM_Select_And_Updates.IPM_Update(1, Connection_String, Inp_Jobid, 'CLEARING','SECONDPRESENTMENT', TimeTaken, To = 9, From = 7)
#Mail.SendEmail(3, 'Clearing And Settlement', EmailTo, EmailFrom, SMTP_SERVER, SMTP_PORT, Connection_String, Inp_Jobid, FileSource)
SP_result = SQL_Connections.udf_SPCall(Connection_String,f"EXEC PR_GenerateIPMTransactions {Inp_Jobid},{UseCCard},{ValidationEnable},'{FileSource}'",Inp_Jobid)
logger.info(f"SP Result = {SP_result[-1][-1]}")
pfurther = CheckFileStatus(Connection_String, Inp_Jobid)
else:
ErrorReason = "File Status in ClearingFiles gets ERROR while executing pr_IPMSecondPresentment Or SP Fail To Execute Successfully"
logger.debug(ErrorReason)
IPM_Select_And_Updates.IPM_Update(5,Connection_String, Inp_Jobid, 'ERROR', ErrorReason)
sys.exit()
if pfurther and SP_result[-1][-1] == 1 :
pfurther = True
Stage_EndTime = datetime.datetime.now()
TimeDiff = str(Stage_EndTime - Stage_StartTime)
TimeTaken = f"CLEARING {TimeDiff[:-3]}"
Stage_StartTime = datetime.datetime.now()
IPM_Select_And_Updates.IPM_Update(1, Connection_String, Inp_Jobid, 'DONE','CLEARING', TimeTaken, To = 10, From = 8)
#Mail.SendEmail(3, 'Clearing And Settlement', EmailTo, EmailFrom, SMTP_SERVER, SMTP_PORT, Connection_String, Inp_Jobid, FileSource)
else:
pfurther = False
ErrorReason = "File Status in ClearingFiles gets ERROR while executing PR_GenerateIPMTransactions Or SP Fail To Execute Successfully"
logger.debug(ErrorReason)
IPM_Select_And_Updates.IPM_Update(5,Connection_String, Inp_Jobid, 'ERROR', ErrorReason)
sys.exit()
return pfurther
######################################################################################################################################################
def CheckFileStatus(Connection_String, Inp_Jobid):
res = IPM_Select_And_Updates.IPM_Select(8,Connection_String, Inp_Jobid, ArgVar_1 = 'MASTERCARDIPM')
if res[0][0] == 'ERROR':
return False
else:
return True
######################################################################################################################################################