| 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 |
from datetime import timedelta
|
| 11 |
from elixir import *
|
12 |
from elixir import *
|
| - |
|
13 |
from sqlalchemy.sql import func
|
| 12 |
|
14 |
import urllib
|
| - |
|
15 |
import httplib
|
| 13 |
|
16 |
|
| 14 |
|
17 |
|
| 15 |
|
18 |
|
| 16 |
if __name__ == '__main__' and __package__ is None:
|
19 |
if __name__ == '__main__' and __package__ is None:
|
| 17 |
import os
|
20 |
import os
|
| Line 19... |
Line 22... |
| 19 |
|
22 |
|
| 20 |
from shop2020.thriftpy.model.v1.order.ttypes import RechargeOrderStatus
|
23 |
from shop2020.thriftpy.model.v1.order.ttypes import RechargeOrderStatus
|
| 21 |
from shop2020.model.v1.order.impl.DataAccessors import get_recharge_orders_for_status, update_recharge_order_status,\
|
24 |
from shop2020.model.v1.order.impl.DataAccessors import get_recharge_orders_for_status, update_recharge_order_status,\
|
| 22 |
update_amount_in_wallet, update_recharge_transaction_status
|
25 |
update_amount_in_wallet, update_recharge_transaction_status
|
| 23 |
from shop2020.model.v1.order.impl import DataService
|
26 |
from shop2020.model.v1.order.impl import DataService
|
| 24 |
from shop2020.model.v1.order.impl.DataService import RechargeTransaction
|
27 |
from shop2020.model.v1.order.impl.DataService import RechargeTransaction, HotspotStore
|
| 25 |
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
|
28 |
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
|
| 26 |
from shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus, getRefunds
|
29 |
from shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus, getRefunds
|
| 27 |
|
30 |
|
| 28 |
|
31 |
|
| 29 |
def main():
|
32 |
def main():
|
| Line 39... |
Line 42... |
| 39 |
action="store_true",
|
42 |
action="store_true",
|
| 40 |
help="")
|
43 |
help="")
|
| 41 |
parser.add_option("-a", "--authorized", dest="authorized",
|
44 |
parser.add_option("-a", "--authorized", dest="authorized",
|
| 42 |
action="store_true",
|
45 |
action="store_true",
|
| 43 |
help="")
|
46 |
help="")
|
| - |
|
47 |
parser.add_option("-c", "--collection", dest="collection",
|
| - |
|
48 |
action="store_true",
|
| - |
|
49 |
help="")
|
| 44 |
parser.add_option("-t", "--txn-id", dest="txn_id",
|
50 |
parser.add_option("-t", "--txn-id", dest="txn_id",
|
| 45 |
type="int",
|
51 |
type="int",
|
| 46 |
help="mark the transaction(recharge order id) TXN_ID as successful",
|
52 |
help="mark the transaction(recharge order id) TXN_ID as successful",
|
| 47 |
metavar="TXN_ID")
|
53 |
metavar="TXN_ID")
|
| 48 |
|
54 |
|
| Line 55... |
Line 61... |
| 55 |
processRefunds()
|
61 |
processRefunds()
|
| 56 |
if options.unknown:
|
62 |
if options.unknown:
|
| 57 |
processUnknownTransactions()
|
63 |
processUnknownTransactions()
|
| 58 |
if options.authorized:
|
64 |
if options.authorized:
|
| 59 |
processAuthorizedTransactions(options.txn_id)
|
65 |
processAuthorizedTransactions(options.txn_id)
|
| - |
|
66 |
if options.collection:
|
| - |
|
67 |
d = datetime.datetime.now()
|
| - |
|
68 |
#d = d + timedelta(days = -10)
|
| - |
|
69 |
compute_recharge_collection(d)
|
| 60 |
|
70 |
|
| 61 |
def processRefunds():
|
71 |
def processRefunds():
|
| 62 |
todate = datetime.datetime.now()
|
72 |
todate = datetime.datetime.now()
|
| 63 |
for i in range(15):
|
73 |
for i in range(15):
|
| 64 |
orderDate = todate + datetime.timedelta(days= -i)
|
74 |
orderDate = todate + datetime.timedelta(days= -i)
|
| Line 104... |
Line 114... |
| 104 |
print "Do Nothing"
|
114 |
print "Do Nothing"
|
| 105 |
|
115 |
|
| 106 |
def processAuthorizedTransactions(txn_id):
|
116 |
def processAuthorizedTransactions(txn_id):
|
| 107 |
update_recharge_order_status(txn_id, RechargeOrderStatus.PAYMENT_SUCCESSFUL)
|
117 |
update_recharge_order_status(txn_id, RechargeOrderStatus.PAYMENT_SUCCESSFUL)
|
| 108 |
|
118 |
|
| - |
|
119 |
|
| - |
|
120 |
def compute_recharge_collection(cdate):
|
| - |
|
121 |
todate = datetime.datetime(cdate.year, cdate.month, cdate.day)
|
| - |
|
122 |
tomorrow = todate + timedelta(days=1)
|
| - |
|
123 |
txns = session.query(RechargeTransaction.storeId, RechargeTransaction.payMethod, RechargeTransaction.status, func.sum(RechargeTransaction.amount), func.sum(RechargeTransaction.discount)).filter(RechargeTransaction.status.in_([RechargeOrderStatus.RECHARGE_SUCCESSFUL, RechargeOrderStatus.RECHARGE_FAILED_REFUNDED])).filter(RechargeTransaction.transactionTime >= todate).filter(RechargeTransaction.transactionTime < tomorrow).group_by(RechargeTransaction.storeId, RechargeTransaction.payMethod, RechargeTransaction.status).order_by(RechargeTransaction.storeId).all()
|
| - |
|
124 |
storeData = {}
|
| - |
|
125 |
for txn in txns:
|
| - |
|
126 |
print txn
|
| - |
|
127 |
if not storeData.has_key(txn[0]):
|
| - |
|
128 |
data = [0,0,0,0,0]
|
| - |
|
129 |
storeData[txn[0]] = data
|
| - |
|
130 |
else:
|
| - |
|
131 |
data = storeData[txn[0]]
|
| - |
|
132 |
if txn[1] == 0:
|
| - |
|
133 |
data[0] += int(txn[3]) - int(txn[4])
|
| - |
|
134 |
if txn[1] == 1:
|
| - |
|
135 |
data[1] += int(txn[3]) - int(txn[4])
|
| - |
|
136 |
if txn[2] in (RechargeOrderStatus.RECHARGE_SUCCESSFUL, RechargeOrderStatus.RECHARGE_FAILED_REFUNDED):
|
| - |
|
137 |
data[2] += int(txn[3])
|
| - |
|
138 |
data[3] += int(txn[4])
|
| - |
|
139 |
data[4] += int(txn[3]) - int(txn[4])
|
| - |
|
140 |
storeData[txn[0]] = data
|
| - |
|
141 |
|
| - |
|
142 |
reftxns = session.query(RechargeTransaction.storeId, RechargeTransaction.payMethod, RechargeTransaction.status, func.sum(RechargeTransaction.amount), func.sum(RechargeTransaction.discount)).filter(RechargeTransaction.status == RechargeOrderStatus.RECHARGE_FAILED_REFUNDED).filter(RechargeTransaction.responseTime >= todate).filter(RechargeTransaction.responseTime < tomorrow).group_by(RechargeTransaction.storeId, RechargeTransaction.payMethod, RechargeTransaction.status).order_by(RechargeTransaction.storeId).all()
|
| - |
|
143 |
for txn in reftxns:
|
| - |
|
144 |
print txn
|
| - |
|
145 |
if not storeData.has_key(txn[0]):
|
| - |
|
146 |
data = [0,0,0,0,0]
|
| - |
|
147 |
storeData[txn[0]] = data
|
| - |
|
148 |
else:
|
| - |
|
149 |
data = storeData[txn[0]]
|
| - |
|
150 |
if txn[1] == 0:
|
| - |
|
151 |
data[0] += int(txn[3]) - int(txn[4])
|
| - |
|
152 |
if txn[1] == 1:
|
| - |
|
153 |
data[1] += int(txn[3]) - int(txn[4])
|
| - |
|
154 |
data[2] -= int(txn[3])
|
| - |
|
155 |
data[3] -= int(txn[4])
|
| - |
|
156 |
data[4] -= int(txn[3]) - int(txn[4])
|
| - |
|
157 |
print storeData
|
| - |
|
158 |
|
| - |
|
159 |
push_recharge_collection_to_ocr(storeData, todate)
|
| - |
|
160 |
|
| - |
|
161 |
def push_recharge_collection_to_ocr(storeData, todate):
|
| - |
|
162 |
|
| - |
|
163 |
for storeId in storeData.keys():
|
| - |
|
164 |
store = HotspotStore.get_by(id = storeId)
|
| - |
|
165 |
store.collectedAmount = 0
|
| - |
|
166 |
store.availableLimit = store.creditLimit
|
| - |
|
167 |
|
| - |
|
168 |
data = storeData.get(storeId)
|
| - |
|
169 |
|
| - |
|
170 |
if store.hotspotId == 'C93':
|
| - |
|
171 |
continue
|
| - |
|
172 |
store_string = "<Store>" + store.hotspotId + "</Store>"
|
| - |
|
173 |
date_string = "<ReconDate>" + todate.strftime("%Y%m%d") + "</ReconDate>"
|
| - |
|
174 |
cash_string = "<Cash>" + str(data[0]) + "</Cash>"
|
| - |
|
175 |
card_string = "<Hdfc>" + str(data[1]) + "</Hdfc>"
|
| - |
|
176 |
type_string = "<Type>RechargeSale</Type>"
|
| - |
|
177 |
amount_string = "<GrossRechargeAmount>" + str(data[2]) + "</GrossRechargeAmount><Discount>" + str(data[3]) + "</Discount><NetCollection>" + str(data[4]) + "</NetCollection>";
|
| - |
|
178 |
|
| - |
|
179 |
#SaholicRechargeSaleTransfer(string Store, int ReconDate, decimal Cash, decimal Hdfc, string Type, decimal GrossRechargeAmount, decimal Discount, decimal NetCollection)
|
| - |
|
180 |
|
| - |
|
181 |
conn = httplib.HTTPConnection("182.71.104.182")
|
| - |
|
182 |
XML="""
|
| - |
|
183 |
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
| - |
|
184 |
<soap:Body>
|
| - |
|
185 |
<SaholicRechargeSaleTransfer xmlns="http://tempuri.org/">
|
| - |
|
186 |
"""
|
| - |
|
187 |
|
| - |
|
188 |
XML = XML + store_string + date_string + cash_string + card_string + type_string + amount_string
|
| - |
|
189 |
|
| - |
|
190 |
footer = """
|
| - |
|
191 |
</SaholicRechargeSaleTransfer>
|
| - |
|
192 |
</soap:Body>
|
| - |
|
193 |
</soap:Envelope>
|
| - |
|
194 |
"""
|
| - |
|
195 |
XML = XML + footer
|
| - |
|
196 |
|
| - |
|
197 |
print XML
|
| - |
|
198 |
params = urllib.urlencode({'op': 'SaholicRechargeSaleTransfer'})
|
| - |
|
199 |
headers = { "Content-type": "text/xml", "Content-Length": "%d" % len(XML)}
|
| - |
|
200 |
conn.request("POST", "/loaddetect/Service.asmx?"+params, "", headers)
|
| - |
|
201 |
conn.send(XML)
|
| - |
|
202 |
response = conn.getresponse()
|
| - |
|
203 |
print response.status, response.reason
|
| - |
|
204 |
resp = response.read()
|
| - |
|
205 |
conn.close()
|
| - |
|
206 |
print resp
|
| - |
|
207 |
|
| 109 |
if __name__ == '__main__':
|
208 |
if __name__ == '__main__':
|
| 110 |
main()
|
209 |
main()
|
| 111 |
|
210 |
|