| Line 6... |
Line 6... |
| 6 |
@author: Rajveer
|
6 |
@author: Rajveer
|
| 7 |
'''
|
7 |
'''
|
| 8 |
import optparse
|
8 |
import optparse
|
| 9 |
import sys
|
9 |
import sys
|
| 10 |
import datetime
|
10 |
import datetime
|
| - |
|
11 |
import base64, re
|
| 11 |
from datetime import timedelta
|
12 |
from datetime import timedelta
|
| 12 |
from elixir import *
|
13 |
from elixir import *
|
| 13 |
from sqlalchemy.sql import func
|
14 |
from sqlalchemy.sql import func
|
| 14 |
import urllib
|
15 |
import urllib
|
| 15 |
import httplib
|
16 |
import httplib
|
| - |
|
17 |
from xml.dom.minidom import parseString
|
| 16 |
from shop2020.utils.EmailAttachmentSender import mail, mail_html
|
18 |
from shop2020.utils.EmailAttachmentSender import mail, mail_html
|
| 17 |
from shop2020.model.v1.order.impl.model.UserWalletHistory import UserWalletHistory
|
19 |
from shop2020.model.v1.order.impl.model.UserWalletHistory import UserWalletHistory
|
| 18 |
from shop2020.utils.Utils import to_java_date, to_py_date
|
20 |
from shop2020.utils.Utils import to_java_date, to_py_date
|
| 19 |
from shop2020.clients.PaymentClient import PaymentClient
|
21 |
from shop2020.clients.PaymentClient import PaymentClient
|
| - |
|
22 |
from shop2020.model.v1.order.impl.model.BaseOrder import BaseOrder
|
| 20 |
|
23 |
|
| - |
|
24 |
from shop2020.clients.TransactionClient import TransactionClient
|
| 21 |
|
25 |
|
| 22 |
|
26 |
|
| 23 |
if __name__ == '__main__' and __package__ is None:
|
27 |
if __name__ == '__main__' and __package__ is None:
|
| 24 |
import os
|
28 |
import os
|
| 25 |
sys.path.insert(0, os.getcwd())
|
29 |
sys.path.insert(0, os.getcwd())
|
| Line 30... |
Line 34... |
| 30 |
from shop2020.model.v1.order.impl.DataAccessors import get_recharge_orders_for_status, update_recharge_order_status,\
|
34 |
from shop2020.model.v1.order.impl.DataAccessors import get_recharge_orders_for_status, update_recharge_order_status,\
|
| 31 |
update_recharge_transaction_status, get_next_invoice_number
|
35 |
update_recharge_transaction_status, get_next_invoice_number
|
| 32 |
from shop2020.model.v1.order.impl import DataService
|
36 |
from shop2020.model.v1.order.impl import DataService
|
| 33 |
from shop2020.model.v1.order.impl.DataService import RechargeTransaction, HotspotStore,\
|
37 |
from shop2020.model.v1.order.impl.DataService import RechargeTransaction, HotspotStore,\
|
| 34 |
WalletForCompany, WalletHistoryForCompany, RechargeCollection, Company, HotspotServiceMatrix,\
|
38 |
WalletForCompany, WalletHistoryForCompany, RechargeCollection, Company, HotspotServiceMatrix,\
|
| 35 |
RechargeVoucherTracker
|
39 |
RechargeVoucherTracker, SpiceTransactionHistory
|
| 36 |
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
|
40 |
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
|
| 37 |
from shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus, getRefunds, getBalance
|
41 |
from shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus, getRefunds, getBalance,\
|
| - |
|
42 |
getRechargeClient, checkTransactionStatus, getAllTransactions
|
| 38 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, between
|
43 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, between
|
| 39 |
|
44 |
|
| 40 |
def main():
|
45 |
def main():
|
| 41 |
parser = optparse.OptionParser()
|
46 |
parser = optparse.OptionParser()
|
| 42 |
parser.add_option("-H", "--host", dest="hostname",
|
47 |
parser.add_option("-H", "--host", dest="hostname",
|
| Line 53... |
Line 58... |
| 53 |
action="store_true",
|
58 |
action="store_true",
|
| 54 |
help="")
|
59 |
help="")
|
| 55 |
parser.add_option("-c", "--collection", dest="collection",
|
60 |
parser.add_option("-c", "--collection", dest="collection",
|
| 56 |
action="store_true",
|
61 |
action="store_true",
|
| 57 |
help="")
|
62 |
help="")
|
| - |
|
63 |
parser.add_option("-m", "--mobisoc", dest="mobisoc",
|
| - |
|
64 |
action="store_true",
|
| - |
|
65 |
help="")
|
| 58 |
parser.add_option("-R", "--recon", dest="recon",
|
66 |
parser.add_option("-R", "--recon", dest="recon",
|
| 59 |
action="store_true",
|
67 |
action="store_true",
|
| 60 |
help="")
|
68 |
help="")
|
| 61 |
parser.add_option("-T", "--topup", dest="topup",
|
69 |
parser.add_option("-T", "--topup", dest="topup",
|
| 62 |
action="store_true",
|
70 |
action="store_true",
|
| Line 90... |
Line 98... |
| 90 |
d = d + timedelta(days = -1)
|
98 |
d = d + timedelta(days = -1)
|
| 91 |
compute_recharge_collection(d)
|
99 |
compute_recharge_collection(d)
|
| 92 |
compute_website_recharge_collection(d, oldBalance, newBalance)
|
100 |
compute_website_recharge_collection(d, oldBalance, newBalance)
|
| 93 |
if options.topup:
|
101 |
if options.topup:
|
| 94 |
topup_company_wallet(1,100000)
|
102 |
topup_company_wallet(1,100000)
|
| - |
|
103 |
|
| - |
|
104 |
if options.mobisoc:
|
| - |
|
105 |
reconcileWithMobisoc()
|
| - |
|
106 |
|
| - |
|
107 |
def reconcileWithMobisoc():
|
| - |
|
108 |
startTime = datetime.datetime.now() + timedelta(days = -1)
|
| - |
|
109 |
endTime = datetime.datetime.now()
|
| - |
|
110 |
websiteOrders = {}
|
| - |
|
111 |
storeOrders = {}
|
| - |
|
112 |
spiceOrders = {}
|
| - |
|
113 |
rechargeOrders = RechargeOrder.query.filter(not_(RechargeOrder.status.in_([RechargeOrderStatus.INIT, RechargeOrderStatus.PAYMENT_FAILED, RechargeOrderStatus.PAYMENT_PENDING]))).filter(RechargeOrder.creationTimestamp.between(startTime, endTime)).all()
|
| - |
|
114 |
rechargeTransactions = RechargeTransaction.query.filter(not_(RechargeTransaction.status.in_([RechargeOrderStatus.INIT, RechargeOrderStatus.PAYMENT_FAILED, RechargeOrderStatus.PAYMENT_PENDING]))).filter(RechargeTransaction.transactionTime.between(startTime, endTime)).all()
|
| - |
|
115 |
print "Creating MAps"
|
| - |
|
116 |
for rechargeOrder in rechargeOrders:
|
| - |
|
117 |
websiteOrders[int(rechargeOrder.id)] = rechargeOrder
|
| - |
|
118 |
|
| - |
|
119 |
for rechargeTxn in rechargeTransactions:
|
| - |
|
120 |
storeOrders[int(rechargeTxn.id)] = rechargeTxn
|
| - |
|
121 |
|
| - |
|
122 |
print "***** Getting transactions from mobisoc..."
|
| - |
|
123 |
transactions = getAllTransactions(startTime, endTime)
|
| - |
|
124 |
print "***** Got all transactions"
|
| - |
|
125 |
|
| - |
|
126 |
for txn in transactions:
|
| - |
|
127 |
try:
|
| - |
|
128 |
print "in for loop"
|
| - |
|
129 |
respCode = txn.getElementsByTagName('transactionResponseCode')[0].childNodes[0].data
|
| - |
|
130 |
merchantTid = txn.getElementsByTagName('merchantTid')[0].childNodes[0].data
|
| - |
|
131 |
spiceTid = txn.getElementsByTagName('spiceTid')[0].childNodes[0].data
|
| - |
|
132 |
rechargeTime = txn.getElementsByTagName('rechargeDate')[0].childNodes[0].data
|
| - |
|
133 |
sth = SpiceTransactionHistory()
|
| - |
|
134 |
sth.rechargeTime = rechargeTime
|
| - |
|
135 |
sth.orderId = merchantTid
|
| - |
|
136 |
sth.spiceTID = spiceTid
|
| - |
|
137 |
sth.reponseCode = respCode
|
| - |
|
138 |
session.commit()
|
| - |
|
139 |
spiceOrders[int(merchantTid)] = respCode
|
| - |
|
140 |
except:
|
| - |
|
141 |
continue
|
| - |
|
142 |
|
| - |
|
143 |
print "Length of storeOrders : " + str(len(storeOrders.keys()))
|
| - |
|
144 |
print "Length of websiteOrders : " + str(len(websiteOrders.keys()))
|
| - |
|
145 |
print "Length of spiceOrders : " + str(len(spiceOrders.keys()))
|
| - |
|
146 |
|
| - |
|
147 |
for id in spiceOrders.keys():
|
| - |
|
148 |
spiceorder = spiceOrders.get(id)
|
| - |
|
149 |
order = storeOrders.get(id)
|
| - |
|
150 |
if order is None:
|
| - |
|
151 |
order = websiteOrders.get(id)
|
| - |
|
152 |
|
| - |
|
153 |
if order:
|
| - |
|
154 |
if spiceorder == '00' and order.status in (5, 6):
|
| - |
|
155 |
removed = storeOrders.pop(id, -1)
|
| - |
|
156 |
print str(removed)
|
| - |
|
157 |
if removed == -1:
|
| - |
|
158 |
removed = websiteOrders.pop(id, -1)
|
| - |
|
159 |
if removed != -1:
|
| - |
|
160 |
removed = spiceOrders.pop(id, -1)
|
| - |
|
161 |
|
| - |
|
162 |
elif spiceorder in ('STO','US', 'UP') and order.status in (3, 4, 5, 10, 6, 7, 8):
|
| - |
|
163 |
removed = storeOrders.pop(id, -1)
|
| - |
|
164 |
if removed == -1:
|
| - |
|
165 |
removed = websiteOrders.pop(id, -1)
|
| - |
|
166 |
if removed != -1:
|
| - |
|
167 |
removed = spiceOrders.pop(id, -1)
|
| - |
|
168 |
|
| - |
|
169 |
elif spiceorder not in ('STO','US', 'UP', '00') and order.status in (4, 6, 7, 8) :
|
| - |
|
170 |
removed = storeOrders.pop(id, -1)
|
| - |
|
171 |
if removed == -1:
|
| - |
|
172 |
removed = websiteOrders.pop(id, -1)
|
| - |
|
173 |
if removed != -1:
|
| - |
|
174 |
removed = spiceOrders.pop(id, -1)
|
| - |
|
175 |
|
| - |
|
176 |
print "Length of storeOrders : " + str(len(storeOrders.keys()))
|
| - |
|
177 |
print "Length of websiteOrders : " + str(len(websiteOrders.keys()))
|
| - |
|
178 |
print "Length of spiceOrders : " + str(len(spiceOrders.keys()))
|
| - |
|
179 |
|
| - |
|
180 |
if len(websiteOrders.keys()) > 0:
|
| - |
|
181 |
for woid in websiteOrders.keys():
|
| - |
|
182 |
try:
|
| - |
|
183 |
result = checkTransactionStatus("", str(woid))
|
| - |
|
184 |
except Exception:
|
| - |
|
185 |
pass
|
| - |
|
186 |
if result:
|
| - |
|
187 |
removed = websiteOrders.pop(woid, -1)
|
| - |
|
188 |
|
| - |
|
189 |
if len(storeOrders.keys()) > 0:
|
| - |
|
190 |
for soid in storeOrders.keys():
|
| - |
|
191 |
try:
|
| - |
|
192 |
result = checkTransactionStatus("", str(soid))
|
| - |
|
193 |
except Exception:
|
| - |
|
194 |
pass
|
| - |
|
195 |
if result[0] == False:
|
| - |
|
196 |
removed = storeOrders.pop(soid, -1)
|
| - |
|
197 |
|
| - |
|
198 |
if len(spiceOrders.keys()) > 0:
|
| - |
|
199 |
for id in spiceOrders.keys():
|
| - |
|
200 |
order = RechargeOrder.query.filter(RechargeOrder.id == id).first()
|
| - |
|
201 |
if order is None:
|
| - |
|
202 |
order = RechargeTransaction.query.filter(RechargeTransaction.id == id).first()
|
| - |
|
203 |
if order:
|
| - |
|
204 |
spiceorder = spiceOrders.get(id)
|
| - |
|
205 |
if spiceorder == '00' and order.status in (5, 6):
|
| - |
|
206 |
removed = spiceOrders.pop(id, -1)
|
| - |
|
207 |
|
| - |
|
208 |
elif spiceorder in ('STO','US', 'UP') and order.status in (3, 4, 10, 5, 6, 7, 8):
|
| - |
|
209 |
removed = spiceOrders.pop(id, -1)
|
| - |
|
210 |
|
| - |
|
211 |
elif spiceorder not in ('STO','US', 'UP', '00') and order.status in (4, 6, 7, 8) :
|
| - |
|
212 |
removed = spiceOrders.pop(id, -1)
|
| - |
|
213 |
|
| - |
|
214 |
maildata = "<html><body><b>Website Recharges</b><br><br>"
|
| - |
|
215 |
for woid in websiteOrders.keys():
|
| - |
|
216 |
wo = websiteOrders.get(woid)
|
| - |
|
217 |
maildata = maildata + str(wo.id) + " : " + str(wo.status) + "<br>"
|
| - |
|
218 |
|
| - |
|
219 |
maildata = maildata + "<br><br><b>Store recharges</b><br><br>"
|
| - |
|
220 |
for soid in storeOrders.keys():
|
| - |
|
221 |
so = storeOrders.get(soid)
|
| - |
|
222 |
maildata = maildata + str(so.id) + " : " + str(so.status) + "<br>"
|
| - |
|
223 |
|
| - |
|
224 |
maildata = maildata + "<br><br><b>Spice Orders</b><br><br>"
|
| - |
|
225 |
for id in spiceOrders.keys():
|
| - |
|
226 |
maildata = maildata + str(id) + " : " + str(spiceOrders.get(id)) + "<br>"
|
| - |
|
227 |
|
| - |
|
228 |
maildata = maildata + "</body></html>"
|
| - |
|
229 |
mail_html("cnc.center@shop2020.in", "5h0p2o2o", ["rajveer.singh@shop2020.in", "anupam.singh@shop2020.in"], "Mobisoc Recharge Reconciliation for Date:- " + startTime.strftime("%d-%m-%Y"), maildata, [])
|
| - |
|
230 |
|
| 95 |
|
231 |
|
| 96 |
def processRecon():
|
232 |
def processRecon():
|
| 97 |
cdate = datetime.datetime.now() + timedelta(days = -1)
|
233 |
cdate = datetime.datetime.now() + timedelta(days = -1)
|
| 98 |
startTime = datetime.datetime(cdate.year, cdate.month, cdate.day)
|
234 |
startTime = datetime.datetime(cdate.year, cdate.month, cdate.day)
|
| 99 |
endTime = startTime + timedelta(days=1)
|
235 |
endTime = startTime + timedelta(days=1)
|
| Line 491... |
Line 627... |
| 491 |
hamount = int(rcs[0])
|
627 |
hamount = int(rcs[0])
|
| 492 |
|
628 |
|
| 493 |
maildata = "(A) Old Wallet Amount is : " + str(oldBalance) + "<br>(B) New Wallet Amount is : " + str(newBalance) + "<br>(C) Recharge Amount is : " + str(rAmount) + "<br>---------------------------<br>(D) Total Debit Amount for Recharge(A-B+C) is : " + str(oldBalance - newBalance + rAmount) + "<br><br><br>(E) Saholic Recharge Amount is :" + str(tamount) + "<br>(F) Hotspot Recharge Amount is :" + str(hamount) + "<br>---------------------------<br>(G) Total Recharge Amount (E+F) is : " + str(tamount + hamount)
|
629 |
maildata = "(A) Old Wallet Amount is : " + str(oldBalance) + "<br>(B) New Wallet Amount is : " + str(newBalance) + "<br>(C) Recharge Amount is : " + str(rAmount) + "<br>---------------------------<br>(D) Total Debit Amount for Recharge(A-B+C) is : " + str(oldBalance - newBalance + rAmount) + "<br><br><br>(E) Saholic Recharge Amount is :" + str(tamount) + "<br>(F) Hotspot Recharge Amount is :" + str(hamount) + "<br>---------------------------<br>(G) Total Recharge Amount (E+F) is : " + str(tamount + hamount)
|
| 494 |
mail_html("cnc.center@shop2020.in", "5h0p2o2o", ["pardeep.panwar@spiceretail.co.in>", "amit.tyagi@spiceretail.co.in", "rajveer.singh@shop2020.in", "anupam.singh@shop2020.in", "j.p.gupta@shop2020.in", "rajneesh.arora@shop2020.in"], "MIS :- Wallet and Recharge (Date - " + startTime.strftime("%d-%m-%Y") + ")", maildata, [])
|
630 |
mail_html("cnc.center@shop2020.in", "5h0p2o2o", ["pardeep.panwar@spiceretail.co.in>", "amit.tyagi@spiceretail.co.in", "rajveer.singh@shop2020.in", "anupam.singh@shop2020.in", "j.p.gupta@shop2020.in", "rajneesh.arora@shop2020.in"], "MIS :- Wallet and Recharge (Date - " + startTime.strftime("%d-%m-%Y") + ")", maildata, [])
|
| 495 |
|
631 |
|
| 496 |
|
- |
|
| 497 |
if __name__ == '__main__':
|
632 |
if __name__ == '__main__':
|
| 498 |
main()
|
633 |
main()
|
| 499 |
|
634 |
|
| 500 |
|
635 |
|