| 14450 |
amit.gupta |
1 |
'''
|
|
|
2 |
Created on Mar 13, 2015
|
|
|
3 |
|
|
|
4 |
@author: amit
|
|
|
5 |
'''
|
|
|
6 |
from datetime import date, datetime, timedelta
|
| 14632 |
amit.gupta |
7 |
from dtr.main import Store, sourceMap
|
| 14650 |
amit.gupta |
8 |
from dtr.reports.amazonreco import generateAmazonReco
|
| 15445 |
amit.gupta |
9 |
from dtr.storage import Mysql, DataService
|
| 15932 |
amit.gupta |
10 |
from dtr.storage.DataService import Users, Clicks, FlipkartOrders,\
|
|
|
11 |
All_user_addresses
|
| 14613 |
amit.gupta |
12 |
from dtr.storage.Mysql import getOrdersAfterDate, getOrdersByTag
|
| 16947 |
amit.gupta |
13 |
from dtr.utils import utils
|
| 15423 |
amit.gupta |
14 |
from elixir import *
|
| 15440 |
amit.gupta |
15 |
from sqlalchemy.sql.expression import func, func, or_
|
| 14450 |
amit.gupta |
16 |
from email import encoders
|
|
|
17 |
from email.mime.base import MIMEBase
|
|
|
18 |
from email.mime.multipart import MIMEMultipart
|
|
|
19 |
from email.mime.text import MIMEText
|
|
|
20 |
from pymongo.mongo_client import MongoClient
|
| 14460 |
amit.gupta |
21 |
from xlrd import open_workbook
|
| 14524 |
amit.gupta |
22 |
from xlutils.copy import copy
|
| 14460 |
amit.gupta |
23 |
from xlwt.Workbook import Workbook
|
| 17137 |
naman |
24 |
import _mysql
|
| 14450 |
amit.gupta |
25 |
import MySQLdb
|
|
|
26 |
import smtplib
|
|
|
27 |
import time
|
|
|
28 |
import xlwt
|
| 16317 |
amit.gupta |
29 |
from dtr.utils import utils
|
| 17001 |
amit.gupta |
30 |
from dtr.utils.utils import toTimeStamp
|
| 17137 |
naman |
31 |
from dtr.reports import getdata
|
| 14460 |
amit.gupta |
32 |
#from xlwt import
|
| 14450 |
amit.gupta |
33 |
|
| 15445 |
amit.gupta |
34 |
DataService.initialize()
|
| 14450 |
amit.gupta |
35 |
client = MongoClient('mongodb://localhost:27017/')
|
|
|
36 |
|
|
|
37 |
SENDER = "cnc.center@shop2020.in"
|
|
|
38 |
PASSWORD = "5h0p2o2o"
|
|
|
39 |
SUBJECT = "DTR User Segmentation report for " + date.today().isoformat()
|
|
|
40 |
SMTP_SERVER = "smtp.gmail.com"
|
|
|
41 |
SMTP_PORT = 587
|
|
|
42 |
|
| 14647 |
amit.gupta |
43 |
XLS_FILENAME = "snapdealaffiliatereco.xls"
|
| 14632 |
amit.gupta |
44 |
XLS_O_FILENAME = "allorders.xls"
|
| 14647 |
amit.gupta |
45 |
XLS_F_FILENAME = "flipkartaffiliatereco.xls"
|
| 14650 |
amit.gupta |
46 |
XLS_A_FILENAME = "amazonaffiliatereco.xls"
|
| 15791 |
manish.sha |
47 |
XLS_SC_FILENAME = "shopcluesaffiliatereco.xls"
|
| 17013 |
manish.sha |
48 |
XLS_HS_FILENAME = "homeshopaffiliatereco.xls"
|
| 14460 |
amit.gupta |
49 |
boldStyle = xlwt.XFStyle()
|
|
|
50 |
f = xlwt.Font()
|
|
|
51 |
f.bold = True
|
|
|
52 |
boldStyle.font = f
|
|
|
53 |
i = -1
|
| 14616 |
amit.gupta |
54 |
|
|
|
55 |
datetime_format = xlwt.XFStyle()
|
|
|
56 |
datetime_format.num_format_str = 'dd/mm/yyyy HH:MM AM/PM'
|
| 15540 |
amit.gupta |
57 |
categoryMap = {3:"Mobiles", 5:"Tablets"}
|
| 17199 |
amit.gupta |
58 |
|
|
|
59 |
curDate = date.today()
|
| 17234 |
amit.gupta |
60 |
cutOffMonth = (datetime.now().month + 11)%12
|
|
|
61 |
cutOffYear = curDate.year - (0 if curDate.month-1 > 0 else 1)
|
| 17199 |
amit.gupta |
62 |
cutOff = datetime(cutOffYear, cutOffMonth, 1)
|
|
|
63 |
|
|
|
64 |
|
| 14450 |
amit.gupta |
65 |
def generateFlipkartReco():
|
| 14508 |
amit.gupta |
66 |
global i
|
|
|
67 |
i = -1
|
| 17234 |
amit.gupta |
68 |
curs = getOrdersAfterDate(cutOff, 2)
|
| 14460 |
amit.gupta |
69 |
db = client.Dtr
|
| 14647 |
amit.gupta |
70 |
wb = xlwt.Workbook()
|
|
|
71 |
#rb = open_workbook(XLS_F_FILENAME)
|
|
|
72 |
#wb = copy(rb)
|
| 14460 |
amit.gupta |
73 |
#wb = xlwt.Workbook()
|
|
|
74 |
row = 0
|
| 14647 |
amit.gupta |
75 |
row2 = 0
|
|
|
76 |
row3 = 0
|
|
|
77 |
row4 = 0
|
|
|
78 |
worksheet = wb.add_sheet("All Orders")
|
|
|
79 |
worksheet1 = wb.add_sheet("Orders Reconciled")
|
|
|
80 |
worksheet2 = wb.add_sheet("Orders not Reconciled")
|
|
|
81 |
worksheet3 = wb.add_sheet("Aff not Reconciled")
|
| 14460 |
amit.gupta |
82 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
| 14647 |
amit.gupta |
83 |
worksheet1.write(row, i, 'Order Id', boldStyle)
|
|
|
84 |
worksheet2.write(row, i, 'Order Id', boldStyle)
|
| 14460 |
amit.gupta |
85 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| 14647 |
amit.gupta |
86 |
worksheet1.write(row, i, 'User Id', boldStyle)
|
|
|
87 |
worksheet2.write(row, i, 'User Id', boldStyle)
|
| 14474 |
amit.gupta |
88 |
worksheet.write(row, inc(), 'Username', boldStyle)
|
| 14647 |
amit.gupta |
89 |
worksheet1.write(row, i, 'Username', boldStyle)
|
|
|
90 |
worksheet2.write(row, i, 'Username', boldStyle)
|
| 14771 |
amit.gupta |
91 |
worksheet.write(row, inc(), 'Version code', boldStyle)
|
|
|
92 |
worksheet1.write(row, i, 'Version code', boldStyle)
|
|
|
93 |
worksheet2.write(row, i, 'Version code', boldStyle)
|
|
|
94 |
worksheet.write(row, inc(), 'Device', boldStyle)
|
|
|
95 |
worksheet1.write(row, i, 'Device', boldStyle)
|
|
|
96 |
worksheet2.write(row, i, 'Device', boldStyle)
|
| 14460 |
amit.gupta |
97 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| 14647 |
amit.gupta |
98 |
worksheet1.write(row, i, 'Merchant Order Id', boldStyle)
|
|
|
99 |
worksheet2.write(row, i, 'Merchant Order Id', boldStyle)
|
| 14460 |
amit.gupta |
100 |
worksheet.write(row, inc(), 'Product Title', boldStyle)
|
| 14647 |
amit.gupta |
101 |
worksheet1.write(row, i, 'Product Title', boldStyle)
|
|
|
102 |
worksheet2.write(row, i, 'Product Title', boldStyle)
|
| 14460 |
amit.gupta |
103 |
worksheet.write(row, inc(), 'Price', boldStyle)
|
| 14647 |
amit.gupta |
104 |
worksheet1.write(row, i, 'Price', boldStyle)
|
|
|
105 |
worksheet2.write(row, i, 'Price', boldStyle)
|
| 14460 |
amit.gupta |
106 |
worksheet.write(row, inc(), 'Quantity', boldStyle)
|
| 14647 |
amit.gupta |
107 |
worksheet1.write(row, i, 'Quantity', boldStyle)
|
|
|
108 |
worksheet2.write(row, i, 'Quantity', boldStyle)
|
| 14460 |
amit.gupta |
109 |
worksheet.write(row, inc(), 'Status', boldStyle)
|
| 14647 |
amit.gupta |
110 |
worksheet1.write(row, i, 'Status', boldStyle)
|
|
|
111 |
worksheet2.write(row, i, 'Status', boldStyle)
|
| 14460 |
amit.gupta |
112 |
worksheet.write(row, inc(), 'Detailed Status', boldStyle)
|
| 14647 |
amit.gupta |
113 |
worksheet1.write(row, i, 'Detailed Status', boldStyle)
|
|
|
114 |
worksheet2.write(row, i, 'Detailed Status', boldStyle)
|
| 14460 |
amit.gupta |
115 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
| 14647 |
amit.gupta |
116 |
worksheet1.write(row, i, 'Cashback Status', boldStyle)
|
|
|
117 |
worksheet2.write(row, i, 'Cashback Status', boldStyle)
|
| 14460 |
amit.gupta |
118 |
worksheet.write(row, inc(), 'Our CashBack', boldStyle)
|
| 14647 |
amit.gupta |
119 |
worksheet1.write(row, i, 'Our CashBack', boldStyle)
|
|
|
120 |
worksheet2.write(row, i, 'Our CashBack', boldStyle)
|
|
|
121 |
worksheet.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
122 |
worksheet1.write(row, i, 'Sale Date', boldStyle)
|
|
|
123 |
worksheet2.write(row, i, 'Sale Date', boldStyle)
|
| 14460 |
amit.gupta |
124 |
worksheet.write(row, inc(), 'SubtagId', boldStyle)
|
| 14647 |
amit.gupta |
125 |
worksheet1.write(row, i, 'SubtagId', boldStyle)
|
|
|
126 |
worksheet2.write(row, i, 'SubtagId', boldStyle)
|
| 14460 |
amit.gupta |
127 |
worksheet.write(row, inc(), 'Category', boldStyle)
|
| 14647 |
amit.gupta |
128 |
worksheet1.write(row, i, 'Category', boldStyle)
|
| 14460 |
amit.gupta |
129 |
worksheet.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 14647 |
amit.gupta |
130 |
worksheet1.write(row, i, 'Aff PayOut', boldStyle)
|
| 14460 |
amit.gupta |
131 |
worksheet.write(row, inc(), 'Aff Sale Amount', boldStyle)
|
| 14647 |
amit.gupta |
132 |
worksheet1.write(row, i, 'Aff Sale Amount', boldStyle)
|
| 14460 |
amit.gupta |
133 |
worksheet.write(row, inc(), 'Aff Sale Date', boldStyle)
|
| 14647 |
amit.gupta |
134 |
worksheet1.write(row, i, 'Aff Sale Date', boldStyle)
|
| 14460 |
amit.gupta |
135 |
for row1 in curs:
|
|
|
136 |
orderId = row1[0]
|
|
|
137 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
138 |
if order is None:
|
|
|
139 |
continue
|
|
|
140 |
saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%d %B, %Y %I:%M %p").replace(hour=0, minute=0, second=0, microsecond=0).timetuple()))
|
|
|
141 |
#saleTime1 = int(time.mktime((datetime.strptime(order['placedOn'], "%b %d, %Y %I:%M %p") + timedelta(seconds=-60)).timetuple()))
|
| 14647 |
amit.gupta |
142 |
reconciled_affiliates = []
|
| 14460 |
amit.gupta |
143 |
for subOrder in order['subOrders']:
|
| 14647 |
amit.gupta |
144 |
affs = list(db.flipkartOrderAffiliateInfo.find({"productCode":subOrder.get("productCode"), "saleDateInt":saleTime}))
|
| 14460 |
amit.gupta |
145 |
row += 1
|
|
|
146 |
i=-1
|
|
|
147 |
worksheet.write(row, inc(), orderId)
|
|
|
148 |
worksheet.write(row, inc(), row1[1])
|
| 14474 |
amit.gupta |
149 |
worksheet.write(row, inc(), row1[-1])
|
| 14771 |
amit.gupta |
150 |
worksheet.write(row, inc(), row1[-2])
|
|
|
151 |
worksheet.write(row, inc(), row1[-3])
|
| 14460 |
amit.gupta |
152 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
153 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
154 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
155 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
156 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
157 |
worksheet.write(row, inc(), subOrder['detailedStatus'])
|
|
|
158 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
159 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
160 |
worksheet.write(row, inc(), subOrder['placedOn'])
|
|
|
161 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
162 |
for aff in affs:
|
| 14647 |
amit.gupta |
163 |
if aff["_id"] not in reconciled_affiliates and aff['subTagId']== order['subTagId']:
|
|
|
164 |
reconciled_affiliates.append(aff["_id"])
|
|
|
165 |
row2 += 1
|
|
|
166 |
i = -1
|
|
|
167 |
worksheet1.write(row2, inc(), orderId)
|
|
|
168 |
worksheet1.write(row2, inc(), row1[1])
|
|
|
169 |
worksheet1.write(row2, inc(), row1[-1])
|
| 14771 |
amit.gupta |
170 |
worksheet1.write(row2, inc(), row1[-2])
|
|
|
171 |
worksheet1.write(row2, inc(), row1[-3])
|
| 14647 |
amit.gupta |
172 |
worksheet1.write(row2, inc(), order['merchantOrderId'])
|
|
|
173 |
worksheet1.write(row2, inc(), subOrder['productTitle'])
|
|
|
174 |
worksheet1.write(row2, inc(), subOrder['amountPaid'])
|
|
|
175 |
worksheet1.write(row2, inc(), subOrder['quantity'])
|
|
|
176 |
worksheet1.write(row2, inc(), subOrder['status'])
|
|
|
177 |
worksheet1.write(row2, inc(), subOrder['detailedStatus'])
|
|
|
178 |
worksheet1.write(row2, inc(), subOrder['cashBackStatus'])
|
|
|
179 |
worksheet1.write(row2, inc(), subOrder['cashBackAmount'])
|
|
|
180 |
worksheet1.write(row2, inc(), subOrder['placedOn'])
|
|
|
181 |
worksheet1.write(row2, inc(), order['subTagId'])
|
|
|
182 |
db.flipkartOrderAffiliateInfo.update(
|
|
|
183 |
{"productCode":subOrder.get("productCode"), "saleDateInt":saleTime, "subTagId":aff['subTagId']},
|
|
|
184 |
{"$set":{"reconciled":True}})
|
|
|
185 |
db.merchantOrder.update({"merchantOrderId":order["merchantOrderId"]},
|
|
|
186 |
{"$set":{"reconciled":True}})
|
| 14460 |
amit.gupta |
187 |
worksheet.write(row, inc(), aff['category'])
|
| 14647 |
amit.gupta |
188 |
worksheet1.write(row2, i, aff['category'])
|
| 14460 |
amit.gupta |
189 |
worksheet.write(row, inc(), aff['payOut'])
|
| 14647 |
amit.gupta |
190 |
worksheet1.write(row2, i, aff['payOut'])
|
| 14460 |
amit.gupta |
191 |
worksheet.write(row, inc(), aff['saleAmount'])
|
| 14647 |
amit.gupta |
192 |
worksheet1.write(row2, i, aff['saleAmount'])
|
| 14460 |
amit.gupta |
193 |
worksheet.write(row, inc(), aff['saleDate'])
|
| 14647 |
amit.gupta |
194 |
worksheet1.write(row2, i, aff['saleDate'])
|
| 14460 |
amit.gupta |
195 |
break
|
| 14647 |
amit.gupta |
196 |
row3 += 1
|
|
|
197 |
i=-1
|
|
|
198 |
worksheet2.write(row3, inc(), orderId)
|
|
|
199 |
worksheet2.write(row3, inc(), row1[1])
|
|
|
200 |
worksheet2.write(row3, inc(), row1[-1])
|
| 14771 |
amit.gupta |
201 |
worksheet2.write(row3, inc(), row1[-2])
|
|
|
202 |
worksheet2.write(row3, inc(), row1[-3])
|
| 14647 |
amit.gupta |
203 |
worksheet2.write(row3, inc(), order['merchantOrderId'])
|
|
|
204 |
worksheet2.write(row3, inc(), subOrder['productTitle'])
|
|
|
205 |
worksheet2.write(row3, inc(), subOrder['amountPaid'])
|
|
|
206 |
worksheet2.write(row3, inc(), subOrder['quantity'])
|
|
|
207 |
worksheet2.write(row3, inc(), subOrder['status'])
|
|
|
208 |
worksheet2.write(row3, inc(), subOrder['detailedStatus'])
|
|
|
209 |
worksheet2.write(row3, inc(), subOrder['cashBackStatus'])
|
|
|
210 |
worksheet2.write(row3, inc(), subOrder['cashBackAmount'])
|
|
|
211 |
worksheet2.write(row3, inc(), subOrder['placedOn'])
|
|
|
212 |
worksheet2.write(row3, inc(), order['subTagId'])
|
|
|
213 |
|
|
|
214 |
i=-1
|
|
|
215 |
worksheet3.write(0, inc(), "category",boldStyle)
|
|
|
216 |
worksheet3.write(0, inc(), "conversionStatus",boldStyle)
|
|
|
217 |
worksheet3.write(0, inc(), "Product Title",boldStyle)
|
|
|
218 |
worksheet3.write(0, inc(), "price",boldStyle)
|
|
|
219 |
worksheet3.write(0, inc(), "quantity",boldStyle)
|
|
|
220 |
worksheet3.write(0, inc(), "payOut",boldStyle)
|
|
|
221 |
worksheet3.write(0, inc(), "saleDate",boldStyle)
|
|
|
222 |
worksheet3.write(0, inc(), "subTagId",boldStyle)
|
|
|
223 |
for aff in db.flipkartOrderAffiliateInfo.find({"reconciled":{"$exists":False}}):
|
|
|
224 |
row4 += 1
|
|
|
225 |
i =-1
|
|
|
226 |
worksheet3.write(row4, inc(), aff["category"])
|
|
|
227 |
worksheet3.write(row4, inc(), aff["conversionStatus"])
|
|
|
228 |
skuData = getSkuData(2, aff["productCode"])
|
|
|
229 |
if skuData is None:
|
|
|
230 |
worksheet3.write(row4, inc(), aff["productTitle"])
|
|
|
231 |
else:
|
|
|
232 |
worksheet3.write(row4, inc(), skuData["product_name"])
|
|
|
233 |
worksheet3.write(row4, inc(), aff['price'])
|
|
|
234 |
worksheet3.write(row4, inc(), aff['quantity'])
|
|
|
235 |
worksheet3.write(row4, inc(), aff['payOut'])
|
|
|
236 |
worksheet3.write(row4, inc(), aff['saleDate'])
|
|
|
237 |
worksheet3.write(row4, inc(), aff['subTagId'])
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
wb.save(XLS_F_FILENAME)
|
| 14450 |
amit.gupta |
242 |
def generateSnapDealReco():
|
| 14524 |
amit.gupta |
243 |
global i
|
| 14460 |
amit.gupta |
244 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 3)
|
| 14450 |
amit.gupta |
245 |
db = client.Dtr
|
| 14487 |
amit.gupta |
246 |
matchedList = []
|
| 17168 |
amit.gupta |
247 |
|
| 14450 |
amit.gupta |
248 |
workbook = xlwt.Workbook()
|
| 14501 |
amit.gupta |
249 |
worksheet = workbook.add_sheet("Snapdeal Reconciled")
|
| 14508 |
amit.gupta |
250 |
worksheet2 = workbook.add_sheet("Snapdeal Orders not reconciled")
|
| 17168 |
amit.gupta |
251 |
affNotReconciledSheet = workbook.add_sheet("Snapdeal Aff not reconciled")
|
| 16947 |
amit.gupta |
252 |
worksheet3 = workbook.add_sheet("DateWise Sale Summary")
|
| 17168 |
amit.gupta |
253 |
worksheet1 = workbook.add_sheet("Snapdeal Reconciled All")
|
| 16947 |
amit.gupta |
254 |
setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet, worksheet3)
|
| 14450 |
amit.gupta |
255 |
row = 0
|
| 15577 |
amit.gupta |
256 |
row5=0
|
| 14450 |
amit.gupta |
257 |
for row1 in curs:
|
|
|
258 |
orderId = row1[0]
|
|
|
259 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
260 |
if order is None:
|
|
|
261 |
continue
|
| 14496 |
amit.gupta |
262 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
| 16949 |
amit.gupta |
263 |
try:
|
| 16951 |
amit.gupta |
264 |
saleTime = datetime.strptime(order['placedOn'], "%a, %d %b, %Y").strftime("%Y-%m-%d")
|
| 16949 |
amit.gupta |
265 |
except:
|
| 17001 |
amit.gupta |
266 |
saleTime = datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").strftime("%Y-%m-%d")
|
| 16947 |
amit.gupta |
267 |
|
| 14988 |
amit.gupta |
268 |
try:
|
|
|
269 |
formattedTimestamp = order['placedOn']
|
|
|
270 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
|
|
271 |
except:
|
|
|
272 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
| 16947 |
amit.gupta |
273 |
formattedTimestamp = datetime.strftime(utils.fromTimeStamp(timestamp1), "%b %d, %Y, %I:%M %p")
|
| 17167 |
amit.gupta |
274 |
|
|
|
275 |
affs = list(db.snapdealOrderAffiliateInfo1.find({"orderId":order["merchantOrderId"]}))
|
|
|
276 |
if len(affs) > 0:
|
| 17168 |
amit.gupta |
277 |
for aff in affs:
|
|
|
278 |
if aff.get("missingOrder"):
|
|
|
279 |
aff["missingOrder"] = False
|
|
|
280 |
db.snapdealOrderAffiliateInfo1.save(aff)
|
| 17167 |
amit.gupta |
281 |
matchedList.append(order["merchantOrderId"])
|
| 14501 |
amit.gupta |
282 |
order['reconciled'] = True
|
|
|
283 |
row += 1
|
|
|
284 |
i=-1
|
|
|
285 |
worksheet.write(row, inc(), orderId)
|
|
|
286 |
worksheet.write(row, inc(), row1[1])
|
| 14850 |
amit.gupta |
287 |
worksheet.write(row, inc(), row1[-1])
|
|
|
288 |
worksheet.write(row, inc(), row1[-2])
|
| 14771 |
amit.gupta |
289 |
worksheet.write(row, inc(), row1[-3])
|
| 14501 |
amit.gupta |
290 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
291 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
292 |
worksheet.write(row, inc(), order['placedOn'])
|
| 14988 |
amit.gupta |
293 |
worksheet.write(row, inc(), formattedTimestamp)
|
| 14501 |
amit.gupta |
294 |
worksheet.write(row, inc(), int(order['paidAmount']))
|
|
|
295 |
k = i
|
| 14504 |
amit.gupta |
296 |
row -= 1
|
| 14501 |
amit.gupta |
297 |
for subOrder in order['subOrders']:
|
|
|
298 |
i = k
|
| 17168 |
amit.gupta |
299 |
matched=False
|
| 14503 |
amit.gupta |
300 |
row += 1
|
| 17167 |
amit.gupta |
301 |
for aff in affs:
|
| 17168 |
amit.gupta |
302 |
if subOrder['productTitle']==aff['productCode']:
|
|
|
303 |
worksheet.write(row, inc(), utils.fromTimeStamp(aff['saleDate']),datetime_format)
|
|
|
304 |
worksheet.write(row, inc(), aff['unitPrice'])
|
|
|
305 |
worksheet.write(row, inc(), 0 if not aff.get('payOut') else aff['payOut']/aff.get('quantity'))
|
| 17234 |
amit.gupta |
306 |
worksheet.write(row, inc(), aff.get('status'))
|
|
|
307 |
subOrder['affStatus'] = aff.get('status')
|
| 17168 |
amit.gupta |
308 |
matched=True
|
|
|
309 |
break
|
|
|
310 |
if not matched:
|
|
|
311 |
inc()
|
|
|
312 |
inc()
|
|
|
313 |
inc()
|
| 17234 |
amit.gupta |
314 |
inc()
|
| 17168 |
amit.gupta |
315 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
316 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
317 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
318 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
319 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
320 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
| 17244 |
amit.gupta |
321 |
db.merchantOrder.save(order)
|
| 14504 |
amit.gupta |
322 |
|
| 14501 |
amit.gupta |
323 |
else:
|
| 15577 |
amit.gupta |
324 |
row5 += 1
|
|
|
325 |
i=-1
|
|
|
326 |
worksheet2.write(row5, inc(), order["orderId"])
|
|
|
327 |
worksheet2.write(row5, inc(), row1[1])
|
|
|
328 |
worksheet2.write(row5, inc(), row1[-1])
|
|
|
329 |
worksheet2.write(row5, inc(), row1[-2])
|
|
|
330 |
worksheet2.write(row5, inc(), row1[-3])
|
|
|
331 |
worksheet2.write(row5, inc(), order['merchantOrderId'])
|
|
|
332 |
worksheet2.write(row5, inc(), order['subTagId'])
|
|
|
333 |
worksheet2.write(row5, inc(), order['placedOn'])
|
|
|
334 |
worksheet2.write(row5, inc(), formattedTimestamp)
|
|
|
335 |
worksheet2.write(row5, inc(), int(order['paidAmount']))
|
|
|
336 |
row5 -=1
|
|
|
337 |
k=i
|
|
|
338 |
for subOrder in order['subOrders']:
|
|
|
339 |
i = k
|
| 15578 |
amit.gupta |
340 |
row5 += 1
|
| 15577 |
amit.gupta |
341 |
worksheet2.write(row5, inc(), subOrder['productTitle'])
|
|
|
342 |
worksheet2.write(row5, inc(), subOrder['amountPaid'])
|
|
|
343 |
worksheet2.write(row5, inc(), subOrder['quantity'])
|
|
|
344 |
worksheet2.write(row5, inc(), subOrder['status'])
|
|
|
345 |
worksheet2.write(row5, inc(), subOrder['cashBackStatus'])
|
| 15578 |
amit.gupta |
346 |
worksheet2.write(row5, inc(), subOrder['cashBackAmount'])
|
| 14524 |
amit.gupta |
347 |
|
|
|
348 |
last30Days = date.today() - timedelta(days=30)
|
|
|
349 |
int(time.mktime(last30Days.timetuple()))
|
|
|
350 |
row = 0
|
| 17168 |
amit.gupta |
351 |
for offer in db.snapdealOrderAffiliateInfo1.find({"missingOrder":True,
|
|
|
352 |
"saleDate":{"$gte":int(time.mktime(last30Days.timetuple())),
|
| 14570 |
amit.gupta |
353 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
354 |
row += 1
|
|
|
355 |
i=-1
|
|
|
356 |
affNotReconciledSheet.write(row, inc(), offer.get("subTagId"))
|
| 17168 |
amit.gupta |
357 |
affNotReconciledSheet.write(row, inc(), offer.get("orderId"))
|
|
|
358 |
affNotReconciledSheet.write(row, inc(), utils.fromTimeStamp(offer.get("saleDate")), datetime_format)
|
| 14570 |
amit.gupta |
359 |
affNotReconciledSheet.write(row, inc(), offer.get("saleAmount"))
|
| 17168 |
amit.gupta |
360 |
affNotReconciledSheet.write(row, inc(), offer.get("productCode"))
|
|
|
361 |
affNotReconciledSheet.write(row, inc(), offer.get("quantity"))
|
| 14570 |
amit.gupta |
362 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
| 16947 |
amit.gupta |
363 |
|
| 17010 |
amit.gupta |
364 |
mailBodyTemplate="""
|
|
|
365 |
<html>
|
|
|
366 |
<body>
|
|
|
367 |
<table cellspacing="0" border="1" style="text-align:right">
|
|
|
368 |
<thead>
|
|
|
369 |
<tr>
|
|
|
370 |
<th style="text-align:center">Date</th>
|
|
|
371 |
<th style="text-align:center">Sale</th>
|
|
|
372 |
<th style="text-align:center">Approved</th>
|
|
|
373 |
<th style="text-align:center">Approved %</th>
|
|
|
374 |
<th style="text-align:center">Rejected</th>
|
|
|
375 |
<th style="text-align:center">Rejected %</th>
|
| 17033 |
amit.gupta |
376 |
<th style="text-align:center">Missing %</th>
|
|
|
377 |
<th style="text-align:center">Approved % against Sale</th>
|
| 17010 |
amit.gupta |
378 |
</tr>
|
|
|
379 |
</thead>
|
|
|
380 |
<tbody>
|
|
|
381 |
{0}
|
|
|
382 |
</tbody>
|
|
|
383 |
</table>
|
|
|
384 |
</body>
|
|
|
385 |
</html>
|
|
|
386 |
"""
|
|
|
387 |
tbody=[]
|
| 17033 |
amit.gupta |
388 |
rowtemplate="<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td></tr>"
|
| 17010 |
amit.gupta |
389 |
for offer in db.flSaleSnapshot.find().limit(61).sort("_id",-1):
|
|
|
390 |
approved = offer.get("approvedAmount")
|
|
|
391 |
rejected = offer.get("rejectedAmount")
|
| 17245 |
amit.gupta |
392 |
sale = offer.get("subAmount")
|
| 17250 |
amit.gupta |
393 |
if not sale:
|
|
|
394 |
sale = offer.get("paidAmount")
|
| 17010 |
amit.gupta |
395 |
total = approved + rejected
|
|
|
396 |
if total ==0:
|
|
|
397 |
continue
|
| 17033 |
amit.gupta |
398 |
tbody.append(rowtemplate.format(offer.get("_id"), sale, approved, int((approved*100/total)), rejected, int((rejected*100/total)), int((sale-approved-rejected)*100/sale),int((approved)*100/sale)))
|
| 17010 |
amit.gupta |
399 |
message = mailBodyTemplate.format("".join(tbody))
|
| 15540 |
amit.gupta |
400 |
workbook.save(XLS_FILENAME)
|
| 17024 |
amit.gupta |
401 |
return message
|
| 17013 |
manish.sha |
402 |
|
|
|
403 |
def generateHomeShopReco():
|
|
|
404 |
global i
|
|
|
405 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 7)
|
|
|
406 |
db = client.Dtr
|
|
|
407 |
notReconciled = {}
|
|
|
408 |
matchedList = []
|
|
|
409 |
workbook = xlwt.Workbook()
|
|
|
410 |
worksheet = workbook.add_sheet("HomeShop18 Reconciled")
|
|
|
411 |
worksheet1 = workbook.add_sheet("HomeShop18 Reconciled All")
|
|
|
412 |
worksheet2 = workbook.add_sheet("HomeShop18 Orders not reconciled")
|
|
|
413 |
affNotReconciledSheet = workbook.add_sheet("HomeShop18 Aff not reconciled")
|
|
|
414 |
setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet)
|
|
|
415 |
row = 0
|
|
|
416 |
anotherrow = 0
|
|
|
417 |
row2 = 0
|
|
|
418 |
row5=0
|
|
|
419 |
|
|
|
420 |
for row1 in curs:
|
|
|
421 |
orderId = row1[0]
|
|
|
422 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
423 |
if order is None:
|
|
|
424 |
continue
|
|
|
425 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple())) 26 May 2015 02:12 PM
|
|
|
426 |
aff = list(db.shopcluesOrderAffiliateInfo.find({"merchantOrderId":order["merchantOrderId"]}))
|
|
|
427 |
anotherrow += 1
|
|
|
428 |
try:
|
|
|
429 |
formattedTimestamp = order['placedOn']
|
|
|
430 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%d %b %Y %I:%M %p").timetuple()))
|
|
|
431 |
except:
|
|
|
432 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
|
|
433 |
formattedTimestamp = datetime.strftime(utils.fromTimeStamp(timestamp1), "%d %b %Y %I:%M %p")
|
|
|
434 |
|
|
|
435 |
if len(aff) > 0 and order["subTagId"] not in matchedList and long(order["paidAmount"])==long(float(aff[0]["transactionValue"])):
|
|
|
436 |
matchedList.append(order["subTagId"])
|
|
|
437 |
db.shopcluesOrderAffiliateInfo.update({"merchantOrderId":aff[0].get("merchantOrderId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
|
|
438 |
order['reconciled'] = True
|
|
|
439 |
order['adId'] = aff[0].get("uniqueKey")
|
|
|
440 |
db.merchantOrder.save(order)
|
|
|
441 |
row += 1
|
|
|
442 |
i=-1
|
|
|
443 |
|
|
|
444 |
worksheet.write(row, inc(), orderId)
|
|
|
445 |
worksheet1.write(anotherrow, i, orderId)
|
|
|
446 |
worksheet.write(row, inc(), row1[1])
|
|
|
447 |
worksheet1.write(anotherrow, i, row1[1])
|
|
|
448 |
worksheet.write(row, inc(), row1[-1])
|
|
|
449 |
worksheet1.write(anotherrow, i, row1[-1])
|
|
|
450 |
worksheet.write(row, inc(), row1[-2])
|
|
|
451 |
worksheet1.write(anotherrow, i, row1[-2])
|
|
|
452 |
worksheet.write(row, inc(), row1[-3])
|
|
|
453 |
worksheet1.write(anotherrow, i, row1[-3])
|
|
|
454 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
455 |
worksheet1.write(anotherrow, i, order['merchantOrderId'])
|
|
|
456 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
457 |
worksheet1.write(anotherrow, i, order['subTagId'])
|
|
|
458 |
worksheet.write(row, inc(), order['placedOn'])
|
|
|
459 |
worksheet1.write(anotherrow, i, order['placedOn'])
|
|
|
460 |
worksheet.write(row, inc(), formattedTimestamp)
|
|
|
461 |
worksheet1.write(anotherrow, i, formattedTimestamp)
|
|
|
462 |
worksheet.write(row, inc(), int(order['paidAmount']))
|
|
|
463 |
worksheet1.write(anotherrow, i, int(order['paidAmount']))
|
|
|
464 |
worksheet.write(row, inc(), datetime.strftime(utils.fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
|
|
465 |
worksheet1.write(anotherrow, i, datetime.strftime(utils.fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
|
|
466 |
worksheet.write(row, inc(), aff[0]['transactionValue'])
|
|
|
467 |
worksheet1.write(anotherrow, i, aff[0]['transactionValue'])
|
|
|
468 |
worksheet.write(row, inc(), aff[0]['payOut'])
|
|
|
469 |
worksheet1.write(anotherrow, i, aff[0]['payOut'])
|
|
|
470 |
worksheet.write(row, inc(), "NA")
|
|
|
471 |
worksheet1.write(anotherrow, i, "NA")
|
|
|
472 |
k = i
|
|
|
473 |
row -= 1
|
|
|
474 |
anotherrow -= 1
|
|
|
475 |
for subOrder in order['subOrders']:
|
|
|
476 |
i = k
|
|
|
477 |
row += 1
|
|
|
478 |
anotherrow += 1
|
|
|
479 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
480 |
worksheet1.write(anotherrow, i, subOrder['productTitle'])
|
|
|
481 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
482 |
worksheet1.write(anotherrow, i, subOrder['amountPaid'])
|
|
|
483 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
484 |
worksheet1.write(anotherrow, i, subOrder['quantity'])
|
|
|
485 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
486 |
worksheet1.write(anotherrow, i, subOrder['status'])
|
|
|
487 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
488 |
worksheet1.write(anotherrow, i, subOrder['cashBackStatus'])
|
|
|
489 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
490 |
worksheet1.write(anotherrow, i, subOrder['cashBackAmount'])
|
|
|
491 |
|
|
|
492 |
else:
|
|
|
493 |
i=-1
|
|
|
494 |
worksheet1.write(anotherrow, inc(), orderId)
|
|
|
495 |
worksheet1.write(anotherrow, inc(), row1[1])
|
|
|
496 |
worksheet1.write(anotherrow, inc(), row1[-1])
|
|
|
497 |
worksheet1.write(anotherrow, inc(), row1[-2])
|
|
|
498 |
worksheet1.write(anotherrow, inc(), row1[-3])
|
|
|
499 |
worksheet1.write(anotherrow, inc(), order['merchantOrderId'])
|
|
|
500 |
worksheet1.write(anotherrow, inc(), order['subTagId'])
|
|
|
501 |
worksheet1.write(anotherrow, inc(), order['placedOn'])
|
|
|
502 |
worksheet1.write(anotherrow, inc(), formattedTimestamp)
|
|
|
503 |
worksheet1.write(anotherrow, inc(), int(order['paidAmount']))
|
|
|
504 |
|
|
|
505 |
notReconciled[orderId] = (anotherrow, i, int(order['paidAmount']), timestamp1, order["subTagId"])
|
|
|
506 |
inc()
|
|
|
507 |
inc()
|
|
|
508 |
inc()
|
|
|
509 |
inc()
|
|
|
510 |
k = i
|
|
|
511 |
anotherrow -= 1
|
|
|
512 |
for subOrder in order['subOrders']:
|
|
|
513 |
anotherrow += 1
|
|
|
514 |
i = k
|
|
|
515 |
worksheet1.write(anotherrow, inc(), subOrder['productTitle'])
|
|
|
516 |
worksheet1.write(anotherrow, inc(), subOrder['amountPaid'])
|
|
|
517 |
worksheet1.write(anotherrow, inc(), subOrder['quantity'])
|
|
|
518 |
worksheet1.write(anotherrow, inc(), subOrder['status'])
|
|
|
519 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackStatus'])
|
|
|
520 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackAmount'])
|
|
|
521 |
row5 += 1
|
|
|
522 |
i=-1
|
|
|
523 |
worksheet2.write(row5, inc(), order["orderId"])
|
|
|
524 |
worksheet2.write(row5, inc(), row1[1])
|
|
|
525 |
worksheet2.write(row5, inc(), row1[-1])
|
|
|
526 |
worksheet2.write(row5, inc(), row1[-2])
|
|
|
527 |
worksheet2.write(row5, inc(), row1[-3])
|
|
|
528 |
worksheet2.write(row5, inc(), order['merchantOrderId'])
|
|
|
529 |
worksheet2.write(row5, inc(), order['subTagId'])
|
|
|
530 |
worksheet2.write(row5, inc(), order['placedOn'])
|
|
|
531 |
worksheet2.write(row5, inc(), formattedTimestamp)
|
|
|
532 |
worksheet2.write(row5, inc(), int(order['paidAmount']))
|
|
|
533 |
row5 -=1
|
|
|
534 |
k=i
|
|
|
535 |
for subOrder in order['subOrders']:
|
|
|
536 |
i = k
|
|
|
537 |
row5 += 1
|
|
|
538 |
worksheet2.write(row5, inc(), subOrder['productTitle'])
|
|
|
539 |
worksheet2.write(row5, inc(), subOrder['amountPaid'])
|
|
|
540 |
worksheet2.write(row5, inc(), subOrder['quantity'])
|
|
|
541 |
worksheet2.write(row5, inc(), subOrder['status'])
|
|
|
542 |
worksheet2.write(row5, inc(), subOrder['cashBackStatus'])
|
|
|
543 |
worksheet2.write(row5, inc(), subOrder['cashBackAmount'])
|
|
|
544 |
last30Days = date.today() - timedelta(days=30)
|
|
|
545 |
int(time.mktime(last30Days.timetuple()))
|
|
|
546 |
row = 0
|
|
|
547 |
for offer in db.homeshopOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
548 |
"transactionTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
549 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
550 |
subTagId = offer.get("subTagId")
|
|
|
551 |
saleTime = offer.get("transactionTime")
|
|
|
552 |
orders = getOrdersByTag(subTagId, 7)
|
|
|
553 |
for order in orders:
|
|
|
554 |
if notReconciled.has_key(order[0]):
|
|
|
555 |
(roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
|
|
|
556 |
if paidAmount==int(offer.get("transactionValue")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
|
|
|
557 |
i = column
|
|
|
558 |
worksheet1.write(roww, inc(), datetime.strftime(utils.fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
|
|
559 |
worksheet1.write(roww, inc(), offer.get("transactionValue"))
|
|
|
560 |
worksheet1.write(roww, inc(), offer.get("payOut"))
|
|
|
561 |
del notReconciled[order[0]]
|
|
|
562 |
print "found match for user", order[1]
|
|
|
563 |
db.homeshopOrderAffiliateInfo.update({"transactionId":offer.get("transactionId")}, {"$set":{"reconciled":True, "orderId":order[0]}}, multi=True)
|
|
|
564 |
db.merchantOrder.update({"orderId":order[0]}, {"$set":{"reconciled":True, "adId":offer.get("uniqueKey")}}, multi=True)
|
|
|
565 |
break
|
|
|
566 |
|
|
|
567 |
unreconciledOrders = notReconciled.keys()
|
|
|
568 |
|
|
|
569 |
for offer in db.homeshopOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
570 |
"transactionTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
571 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
572 |
row += 1
|
|
|
573 |
i=-1
|
|
|
574 |
affNotReconciledSheet.write(row, inc(), offer.get("uniqueKey"))
|
|
|
575 |
affNotReconciledSheet.write(row, inc(), offer.get("subTagId"))
|
|
|
576 |
affNotReconciledSheet.write(row, inc(), datetime.strftime(utils.fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
|
|
577 |
affNotReconciledSheet.write(row, inc(), offer.get("transactionValue"))
|
|
|
578 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
|
|
579 |
affNotReconciledSheet.write(row, inc(), offer.get("status"))
|
|
|
580 |
affNotReconciledSheet.write(row, inc(), 'NA')
|
|
|
581 |
|
|
|
582 |
workbook.save(XLS_HS_FILENAME)
|
|
|
583 |
|
| 16995 |
amit.gupta |
584 |
|
| 15791 |
manish.sha |
585 |
def generateShopcluesReco():
|
|
|
586 |
global i
|
| 16238 |
manish.sha |
587 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 5)
|
| 15791 |
manish.sha |
588 |
db = client.Dtr
|
|
|
589 |
notReconciled = {}
|
|
|
590 |
matchedList = []
|
|
|
591 |
workbook = xlwt.Workbook()
|
|
|
592 |
worksheet = workbook.add_sheet("Shopclues Reconciled")
|
|
|
593 |
worksheet1 = workbook.add_sheet("Shopclues Reconciled All")
|
|
|
594 |
worksheet2 = workbook.add_sheet("Shopclues Orders not reconciled")
|
|
|
595 |
affNotReconciledSheet = workbook.add_sheet("Shopclues Aff not reconciled")
|
|
|
596 |
setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet)
|
|
|
597 |
row = 0
|
|
|
598 |
anotherrow = 0
|
|
|
599 |
row2 = 0
|
|
|
600 |
row5=0
|
|
|
601 |
|
|
|
602 |
for row1 in curs:
|
|
|
603 |
orderId = row1[0]
|
|
|
604 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
605 |
if order is None:
|
|
|
606 |
continue
|
|
|
607 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple())) 26 May 2015 02:12 PM
|
| 16204 |
manish.sha |
608 |
aff = list(db.shopcluesOrderAffiliateInfo.find({"merchantOrderId":order["merchantOrderId"]}))
|
| 15791 |
manish.sha |
609 |
anotherrow += 1
|
|
|
610 |
try:
|
|
|
611 |
formattedTimestamp = order['placedOn']
|
|
|
612 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%d %b %Y %I:%M %p").timetuple()))
|
|
|
613 |
except:
|
|
|
614 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
| 16947 |
amit.gupta |
615 |
formattedTimestamp = datetime.strftime(utils.fromTimeStamp(timestamp1), "%d %b %Y %I:%M %p")
|
| 15791 |
manish.sha |
616 |
|
|
|
617 |
if len(aff) > 0 and order["subTagId"] not in matchedList and long(order["paidAmount"])==long(float(aff[0]["transactionValue"])):
|
|
|
618 |
matchedList.append(order["subTagId"])
|
| 16204 |
manish.sha |
619 |
db.shopcluesOrderAffiliateInfo.update({"merchantOrderId":aff[0].get("merchantOrderId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
| 15791 |
manish.sha |
620 |
order['reconciled'] = True
|
|
|
621 |
order['adId'] = aff[0].get("uniqueKey")
|
|
|
622 |
db.merchantOrder.save(order)
|
|
|
623 |
row += 1
|
|
|
624 |
i=-1
|
| 14450 |
amit.gupta |
625 |
|
| 15791 |
manish.sha |
626 |
worksheet.write(row, inc(), orderId)
|
|
|
627 |
worksheet1.write(anotherrow, i, orderId)
|
|
|
628 |
worksheet.write(row, inc(), row1[1])
|
|
|
629 |
worksheet1.write(anotherrow, i, row1[1])
|
|
|
630 |
worksheet.write(row, inc(), row1[-1])
|
|
|
631 |
worksheet1.write(anotherrow, i, row1[-1])
|
|
|
632 |
worksheet.write(row, inc(), row1[-2])
|
|
|
633 |
worksheet1.write(anotherrow, i, row1[-2])
|
|
|
634 |
worksheet.write(row, inc(), row1[-3])
|
|
|
635 |
worksheet1.write(anotherrow, i, row1[-3])
|
|
|
636 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
637 |
worksheet1.write(anotherrow, i, order['merchantOrderId'])
|
|
|
638 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
639 |
worksheet1.write(anotherrow, i, order['subTagId'])
|
|
|
640 |
worksheet.write(row, inc(), order['placedOn'])
|
|
|
641 |
worksheet1.write(anotherrow, i, order['placedOn'])
|
|
|
642 |
worksheet.write(row, inc(), formattedTimestamp)
|
|
|
643 |
worksheet1.write(anotherrow, i, formattedTimestamp)
|
|
|
644 |
worksheet.write(row, inc(), int(order['paidAmount']))
|
|
|
645 |
worksheet1.write(anotherrow, i, int(order['paidAmount']))
|
| 16947 |
amit.gupta |
646 |
worksheet.write(row, inc(), datetime.strftime(utils.fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
|
|
647 |
worksheet1.write(anotherrow, i, datetime.strftime(utils.fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
| 15791 |
manish.sha |
648 |
worksheet.write(row, inc(), aff[0]['transactionValue'])
|
|
|
649 |
worksheet1.write(anotherrow, i, aff[0]['transactionValue'])
|
|
|
650 |
worksheet.write(row, inc(), aff[0]['payOut'])
|
|
|
651 |
worksheet1.write(anotherrow, i, aff[0]['payOut'])
|
| 16238 |
manish.sha |
652 |
worksheet.write(row, inc(), "NA")
|
|
|
653 |
worksheet1.write(anotherrow, i, "NA")
|
| 15791 |
manish.sha |
654 |
k = i
|
|
|
655 |
row -= 1
|
|
|
656 |
anotherrow -= 1
|
|
|
657 |
for subOrder in order['subOrders']:
|
|
|
658 |
i = k
|
|
|
659 |
row += 1
|
|
|
660 |
anotherrow += 1
|
|
|
661 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
662 |
worksheet1.write(anotherrow, i, subOrder['productTitle'])
|
|
|
663 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
664 |
worksheet1.write(anotherrow, i, subOrder['amountPaid'])
|
|
|
665 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
666 |
worksheet1.write(anotherrow, i, subOrder['quantity'])
|
|
|
667 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
668 |
worksheet1.write(anotherrow, i, subOrder['status'])
|
|
|
669 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
670 |
worksheet1.write(anotherrow, i, subOrder['cashBackStatus'])
|
|
|
671 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
672 |
worksheet1.write(anotherrow, i, subOrder['cashBackAmount'])
|
|
|
673 |
|
|
|
674 |
else:
|
|
|
675 |
i=-1
|
|
|
676 |
worksheet1.write(anotherrow, inc(), orderId)
|
|
|
677 |
worksheet1.write(anotherrow, inc(), row1[1])
|
|
|
678 |
worksheet1.write(anotherrow, inc(), row1[-1])
|
|
|
679 |
worksheet1.write(anotherrow, inc(), row1[-2])
|
|
|
680 |
worksheet1.write(anotherrow, inc(), row1[-3])
|
|
|
681 |
worksheet1.write(anotherrow, inc(), order['merchantOrderId'])
|
|
|
682 |
worksheet1.write(anotherrow, inc(), order['subTagId'])
|
|
|
683 |
worksheet1.write(anotherrow, inc(), order['placedOn'])
|
|
|
684 |
worksheet1.write(anotherrow, inc(), formattedTimestamp)
|
|
|
685 |
worksheet1.write(anotherrow, inc(), int(order['paidAmount']))
|
|
|
686 |
|
|
|
687 |
notReconciled[orderId] = (anotherrow, i, int(order['paidAmount']), timestamp1, order["subTagId"])
|
|
|
688 |
inc()
|
|
|
689 |
inc()
|
|
|
690 |
inc()
|
|
|
691 |
inc()
|
|
|
692 |
k = i
|
|
|
693 |
anotherrow -= 1
|
|
|
694 |
for subOrder in order['subOrders']:
|
|
|
695 |
anotherrow += 1
|
|
|
696 |
i = k
|
|
|
697 |
worksheet1.write(anotherrow, inc(), subOrder['productTitle'])
|
|
|
698 |
worksheet1.write(anotherrow, inc(), subOrder['amountPaid'])
|
|
|
699 |
worksheet1.write(anotherrow, inc(), subOrder['quantity'])
|
|
|
700 |
worksheet1.write(anotherrow, inc(), subOrder['status'])
|
|
|
701 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackStatus'])
|
|
|
702 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackAmount'])
|
|
|
703 |
row5 += 1
|
|
|
704 |
i=-1
|
|
|
705 |
worksheet2.write(row5, inc(), order["orderId"])
|
|
|
706 |
worksheet2.write(row5, inc(), row1[1])
|
|
|
707 |
worksheet2.write(row5, inc(), row1[-1])
|
|
|
708 |
worksheet2.write(row5, inc(), row1[-2])
|
|
|
709 |
worksheet2.write(row5, inc(), row1[-3])
|
|
|
710 |
worksheet2.write(row5, inc(), order['merchantOrderId'])
|
|
|
711 |
worksheet2.write(row5, inc(), order['subTagId'])
|
|
|
712 |
worksheet2.write(row5, inc(), order['placedOn'])
|
|
|
713 |
worksheet2.write(row5, inc(), formattedTimestamp)
|
|
|
714 |
worksheet2.write(row5, inc(), int(order['paidAmount']))
|
|
|
715 |
row5 -=1
|
|
|
716 |
k=i
|
|
|
717 |
for subOrder in order['subOrders']:
|
|
|
718 |
i = k
|
|
|
719 |
row5 += 1
|
|
|
720 |
worksheet2.write(row5, inc(), subOrder['productTitle'])
|
|
|
721 |
worksheet2.write(row5, inc(), subOrder['amountPaid'])
|
|
|
722 |
worksheet2.write(row5, inc(), subOrder['quantity'])
|
|
|
723 |
worksheet2.write(row5, inc(), subOrder['status'])
|
|
|
724 |
worksheet2.write(row5, inc(), subOrder['cashBackStatus'])
|
|
|
725 |
worksheet2.write(row5, inc(), subOrder['cashBackAmount'])
|
|
|
726 |
|
|
|
727 |
last30Days = date.today() - timedelta(days=30)
|
|
|
728 |
int(time.mktime(last30Days.timetuple()))
|
|
|
729 |
row = 0
|
|
|
730 |
for offer in db.shopcluesOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
731 |
"transactionTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
732 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
733 |
subTagId = offer.get("subTagId")
|
|
|
734 |
saleTime = offer.get("transactionTime")
|
| 15794 |
manish.sha |
735 |
orders = getOrdersByTag(subTagId, 5)
|
| 15791 |
manish.sha |
736 |
for order in orders:
|
|
|
737 |
if notReconciled.has_key(order[0]):
|
|
|
738 |
(roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
|
|
|
739 |
if paidAmount==int(offer.get("transactionValue")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
|
|
|
740 |
i = column
|
| 16947 |
amit.gupta |
741 |
worksheet1.write(roww, inc(), datetime.strftime(utils.fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
| 15791 |
manish.sha |
742 |
worksheet1.write(roww, inc(), offer.get("transactionValue"))
|
|
|
743 |
worksheet1.write(roww, inc(), offer.get("payOut"))
|
|
|
744 |
del notReconciled[order[0]]
|
|
|
745 |
print "found match for user", order[1]
|
|
|
746 |
db.shopcluesOrderAffiliateInfo.update({"transactionId":offer.get("transactionId")}, {"$set":{"reconciled":True, "orderId":order[0]}}, multi=True)
|
|
|
747 |
db.merchantOrder.update({"orderId":order[0]}, {"$set":{"reconciled":True, "adId":offer.get("uniqueKey")}}, multi=True)
|
|
|
748 |
break
|
|
|
749 |
|
|
|
750 |
unreconciledOrders = notReconciled.keys()
|
|
|
751 |
|
|
|
752 |
for offer in db.shopcluesOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
753 |
"transactionTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
754 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
755 |
row += 1
|
|
|
756 |
i=-1
|
|
|
757 |
affNotReconciledSheet.write(row, inc(), offer.get("uniqueKey"))
|
|
|
758 |
affNotReconciledSheet.write(row, inc(), offer.get("subTagId"))
|
| 16947 |
amit.gupta |
759 |
affNotReconciledSheet.write(row, inc(), datetime.strftime(utils.fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
| 15791 |
manish.sha |
760 |
affNotReconciledSheet.write(row, inc(), offer.get("transactionValue"))
|
|
|
761 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
|
|
762 |
affNotReconciledSheet.write(row, inc(), offer.get("status"))
|
|
|
763 |
affNotReconciledSheet.write(row, inc(), 'NA')
|
|
|
764 |
|
|
|
765 |
workbook.save(XLS_SC_FILENAME)
|
|
|
766 |
|
| 14647 |
amit.gupta |
767 |
def sendmail(email, message, title, *varargs):
|
| 14450 |
amit.gupta |
768 |
if email == "":
|
|
|
769 |
return
|
|
|
770 |
mailServer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
|
|
|
771 |
mailServer.ehlo()
|
|
|
772 |
mailServer.starttls()
|
|
|
773 |
mailServer.ehlo()
|
|
|
774 |
|
|
|
775 |
# Create the container (outer) email message.
|
|
|
776 |
msg = MIMEMultipart()
|
|
|
777 |
msg['Subject'] = title
|
|
|
778 |
msg.preamble = title
|
|
|
779 |
html_msg = MIMEText(message, 'html')
|
|
|
780 |
msg.attach(html_msg)
|
|
|
781 |
|
|
|
782 |
#snapdeal more to be added here
|
| 14647 |
amit.gupta |
783 |
for fileName in varargs:
|
|
|
784 |
snapdeal = MIMEBase('application', 'vnd.ms-excel')
|
|
|
785 |
snapdeal.set_payload(file(fileName).read())
|
|
|
786 |
encoders.encode_base64(snapdeal)
|
|
|
787 |
snapdeal.add_header('Content-Disposition', 'attachment;filename=' + fileName)
|
|
|
788 |
msg.attach(snapdeal)
|
| 14450 |
amit.gupta |
789 |
|
|
|
790 |
|
|
|
791 |
email.append('amit.gupta@shop2020.in')
|
|
|
792 |
MAILTO = email
|
|
|
793 |
mailServer.login(SENDER, PASSWORD)
|
| 17445 |
amit.gupta |
794 |
mailServer.sendmail(SENDER, MAILTO, msg.as_string())
|
| 14450 |
amit.gupta |
795 |
|
| 16958 |
amit.gupta |
796 |
def setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet, worksheet3=None):
|
| 14505 |
amit.gupta |
797 |
boldStyle = xlwt.XFStyle()
|
|
|
798 |
f = xlwt.Font()
|
|
|
799 |
f.bold = True
|
|
|
800 |
boldStyle.font = f
|
| 14501 |
amit.gupta |
801 |
row = 0
|
|
|
802 |
global i
|
|
|
803 |
i=-1
|
|
|
804 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
|
|
805 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| 14850 |
amit.gupta |
806 |
worksheet.write(row, inc(), 'Username', boldStyle)
|
| 14601 |
amit.gupta |
807 |
worksheet.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
808 |
worksheet.write(row, inc(), 'Device', boldStyle)
|
| 14501 |
amit.gupta |
809 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
810 |
worksheet.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
811 |
worksheet.write(row, inc(), 'Sale Date', boldStyle)
|
| 14988 |
amit.gupta |
812 |
worksheet.write(row, inc(), 'Dtr Sale Date', boldStyle)
|
| 14501 |
amit.gupta |
813 |
worksheet.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
814 |
worksheet.write(row, inc(), 'Aff Sale Date', boldStyle)
|
|
|
815 |
worksheet.write(row, inc(), 'Aff Sale Amt', boldStyle)
|
|
|
816 |
worksheet.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 17234 |
amit.gupta |
817 |
worksheet.write(row, inc(), 'Aff Status', boldStyle)
|
| 14501 |
amit.gupta |
818 |
worksheet.write(row, inc(), 'Product Title', boldStyle)
|
|
|
819 |
worksheet.write(row, inc(), 'Price', boldStyle)
|
|
|
820 |
worksheet.write(row, inc(), 'Quantity', boldStyle)
|
|
|
821 |
worksheet.write(row, inc(), 'Status', boldStyle)
|
|
|
822 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
823 |
worksheet.write(row, inc(), 'CashBack', boldStyle)
|
|
|
824 |
|
| 14508 |
amit.gupta |
825 |
|
|
|
826 |
i = -1
|
|
|
827 |
worksheet2.write(row, inc(), 'Order Id', boldStyle)
|
|
|
828 |
worksheet2.write(row, inc(), 'User Id', boldStyle)
|
| 14850 |
amit.gupta |
829 |
worksheet2.write(row, inc(), 'Username', boldStyle)
|
| 14605 |
amit.gupta |
830 |
worksheet2.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
831 |
worksheet2.write(row, inc(), 'Device', boldStyle)
|
| 14508 |
amit.gupta |
832 |
worksheet2.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
833 |
worksheet2.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
834 |
worksheet2.write(row, inc(), 'Sale Date', boldStyle)
|
| 14988 |
amit.gupta |
835 |
worksheet2.write(row, inc(), 'Dtr Sale Date', boldStyle)
|
| 14508 |
amit.gupta |
836 |
worksheet2.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
837 |
worksheet2.write(row, inc(), 'Product Title', boldStyle)
|
|
|
838 |
worksheet2.write(row, inc(), 'Price', boldStyle)
|
|
|
839 |
worksheet2.write(row, inc(), 'Quantity', boldStyle)
|
|
|
840 |
worksheet2.write(row, inc(), 'Status', boldStyle)
|
|
|
841 |
worksheet2.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
842 |
worksheet2.write(row, inc(), 'CashBack', boldStyle)
|
| 14450 |
amit.gupta |
843 |
|
| 14508 |
amit.gupta |
844 |
i =-1
|
| 17168 |
amit.gupta |
845 |
affNotReconciledSheet.write(row, inc(), 'Sub Tag Id', boldStyle)
|
|
|
846 |
affNotReconciledSheet.write(row, inc(), 'Order Id', boldStyle)
|
| 14508 |
amit.gupta |
847 |
affNotReconciledSheet.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
848 |
affNotReconciledSheet.write(row, inc(), 'Sale Amount', boldStyle)
|
| 17168 |
amit.gupta |
849 |
affNotReconciledSheet.write(row, inc(), 'Product', boldStyle)
|
|
|
850 |
affNotReconciledSheet.write(row, inc(), 'Quantity', boldStyle)
|
| 14508 |
amit.gupta |
851 |
affNotReconciledSheet.write(row, inc(), 'Pay Out', boldStyle)
|
| 14524 |
amit.gupta |
852 |
|
| 16958 |
amit.gupta |
853 |
if worksheet3:
|
|
|
854 |
i =-1
|
|
|
855 |
worksheet3.write(row, inc(), 'Date', boldStyle)
|
|
|
856 |
worksheet3.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
857 |
worksheet3.write(row, inc(), 'Approved Sales', boldStyle)
|
|
|
858 |
worksheet3.write(row, inc(), 'Rejected Sales', boldStyle)
|
| 16947 |
amit.gupta |
859 |
|
| 14524 |
amit.gupta |
860 |
def getUserAmountReconciled():
|
|
|
861 |
pass
|
|
|
862 |
|
| 14613 |
amit.gupta |
863 |
def getUserOrders():
|
|
|
864 |
global i
|
| 16726 |
amit.gupta |
865 |
#worksheet1 = wb.add_sheet("Suspected Users")
|
| 17159 |
amit.gupta |
866 |
workbook = xlwt.Workbook("ISO8859-1")
|
| 14632 |
amit.gupta |
867 |
sh1 = workbook.add_sheet("All Orders")
|
| 15423 |
amit.gupta |
868 |
sh2 = workbook.add_sheet("Flipkart Orders")
|
| 17245 |
amit.gupta |
869 |
#worksheet = workbook.add_sheet("All Users")
|
| 14632 |
amit.gupta |
870 |
|
| 14613 |
amit.gupta |
871 |
db=client.Dtr
|
| 17199 |
amit.gupta |
872 |
prevDate = cutOff
|
| 17159 |
amit.gupta |
873 |
results = Mysql.fetchResult("select * from allorder where created_on > %s", prevDate)
|
| 14613 |
amit.gupta |
874 |
row = 0
|
|
|
875 |
i=-1
|
| 17245 |
amit.gupta |
876 |
# worksheet.write(row, inc(), 'User Id', boldStyle)
|
|
|
877 |
# worksheet.write(row, inc(), 'User name', boldStyle)
|
|
|
878 |
# worksheet.write(row, inc(), 'Order Id', boldStyle)
|
|
|
879 |
# worksheet.write(row, inc(), 'Created On', boldStyle)
|
|
|
880 |
# worksheet.write(row, inc(), 'Store Id', boldStyle)
|
|
|
881 |
# worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
882 |
# worksheet.write(row, inc(), 'SubOrder Id', boldStyle)
|
|
|
883 |
# worksheet.write(row, inc(), 'Product title', boldStyle)
|
|
|
884 |
# worksheet.write(row, inc(), 'Amount Paid', boldStyle)
|
|
|
885 |
# worksheet.write(row, inc(), 'Cashback', boldStyle)
|
|
|
886 |
# worksheet.write(row, inc(), 'Order Status', boldStyle)
|
|
|
887 |
# worksheet.write(row, inc(), 'Detailed Status', boldStyle)
|
|
|
888 |
# worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
889 |
# worksheet.write(row, inc(), 'Reconciled', boldStyle)
|
|
|
890 |
# worksheet.write(row, inc(), 'IP', boldStyle)
|
|
|
891 |
# worksheet.write(row, inc(), 'Aff Status', boldStyle)
|
| 14693 |
amit.gupta |
892 |
i=-1
|
|
|
893 |
sh1.write(row, inc(), 'User Id', boldStyle)
|
|
|
894 |
sh1.write(row, inc(), 'User name', boldStyle)
|
|
|
895 |
sh1.write(row, inc(), 'Order Id', boldStyle)
|
|
|
896 |
sh1.write(row, inc(), 'Created On', boldStyle)
|
|
|
897 |
sh1.write(row, inc(), 'Store Id', boldStyle)
|
|
|
898 |
sh1.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| 14771 |
amit.gupta |
899 |
sh1.write(row, inc(), 'Status', boldStyle)
|
| 15932 |
amit.gupta |
900 |
sh1.write(row, inc(), 'Detailed Status', boldStyle)
|
| 14693 |
amit.gupta |
901 |
sh1.write(row, inc(), 'Product title', boldStyle)
|
|
|
902 |
sh1.write(row, inc(), 'Referrer', boldStyle)
|
|
|
903 |
sh1.write(row, inc(), 'Amount Paid', boldStyle)
|
| 14771 |
amit.gupta |
904 |
sh1.write(row, inc(), 'Catalog Id', boldStyle)
|
| 14693 |
amit.gupta |
905 |
sh1.write(row, inc(), 'Brand', boldStyle)
|
|
|
906 |
sh1.write(row, inc(), 'Model', boldStyle)
|
|
|
907 |
sh1.write(row, inc(), 'Category', boldStyle)
|
| 15932 |
amit.gupta |
908 |
sh1.write(row, inc(), 'Deal Rank', boldStyle)
|
| 16286 |
amit.gupta |
909 |
sh1.write(row, inc(), 'Max Nlc', boldStyle)
|
|
|
910 |
sh1.write(row, inc(), 'Min Nlc', boldStyle)
|
|
|
911 |
sh1.write(row, inc(), 'DP', boldStyle)
|
|
|
912 |
sh1.write(row, inc(), 'Item status', boldStyle)
|
| 15932 |
amit.gupta |
913 |
sh1.write(row, inc(), 'City', boldStyle)
|
|
|
914 |
sh1.write(row, inc(), 'State', boldStyle)
|
|
|
915 |
sh1.write(row, inc(), 'Pincode', boldStyle)
|
| 17159 |
amit.gupta |
916 |
sh1.write(row, inc(), 'SubOrder Id', boldStyle)
|
|
|
917 |
sh1.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
918 |
sh1.write(row, inc(), 'Cashback Amount', boldStyle)
|
| 17234 |
amit.gupta |
919 |
sh1.write(row, inc(), 'Quantity', boldStyle)
|
|
|
920 |
sh1.write(row, inc(), 'Reconciled', boldStyle)
|
|
|
921 |
sh1.write(row, inc(), 'Aff Status', boldStyle)
|
| 15423 |
amit.gupta |
922 |
i =-1
|
|
|
923 |
sh2.write(row, inc(), 'User Id', boldStyle)
|
|
|
924 |
sh2.write(row, inc(), 'User name', boldStyle)
|
|
|
925 |
sh2.write(row, inc(), 'Created On', boldStyle)
|
|
|
926 |
sh2.write(row, inc(), 'Store', boldStyle)
|
|
|
927 |
sh2.write(row, inc(), 'Status', boldStyle)
|
|
|
928 |
sh2.write(row, inc(), 'Product title', boldStyle)
|
|
|
929 |
sh2.write(row, inc(), 'Price', boldStyle)
|
|
|
930 |
sh2.write(row, inc(), 'Quantity', boldStyle)
|
|
|
931 |
sh2.write(row, inc(), 'Catalog Id', boldStyle)
|
|
|
932 |
sh2.write(row, inc(), 'Brand', boldStyle)
|
|
|
933 |
sh2.write(row, inc(), 'Model', boldStyle)
|
|
|
934 |
sh2.write(row, inc(), 'Category', boldStyle)
|
| 14613 |
amit.gupta |
935 |
|
| 17159 |
amit.gupta |
936 |
default_format = xlwt.XFStyle()
|
|
|
937 |
date_format = xlwt.XFStyle()
|
|
|
938 |
date_format.num_format_str = 'dd/mm/yyyy'
|
|
|
939 |
|
|
|
940 |
datetime_format = xlwt.XFStyle()
|
|
|
941 |
datetime_format.num_format_str = 'dd/mm/yyyy HH:MM AM/PM'
|
|
|
942 |
|
|
|
943 |
number_format = xlwt.XFStyle()
|
|
|
944 |
number_format.num_format_str = '#,##0'
|
|
|
945 |
|
|
|
946 |
|
| 14613 |
amit.gupta |
947 |
row=0
|
| 17159 |
amit.gupta |
948 |
for r in results:
|
|
|
949 |
row += 1
|
|
|
950 |
column = 0
|
|
|
951 |
for data in r :
|
|
|
952 |
sh1.write(row, column, int(data) if type(data) is float else data, datetime_format if type(data) is datetime else default_format)
|
|
|
953 |
column += 1
|
|
|
954 |
i=-1
|
| 17245 |
amit.gupta |
955 |
# worksheet.write(row, inc(), r[0])
|
|
|
956 |
# worksheet.write(row, inc(), r[1])
|
|
|
957 |
# worksheet.write(row, inc(), r[2])
|
|
|
958 |
# worksheet.write(row, inc(), r[3], datetime_format)
|
|
|
959 |
# worksheet.write(row, inc(), r[4])
|
|
|
960 |
# worksheet.write(row, inc(), r[5])
|
|
|
961 |
# worksheet.write(row, inc(), r[23])
|
|
|
962 |
# worksheet.write(row, inc(), r[8])
|
|
|
963 |
# worksheet.write(row, inc(), r[10])
|
|
|
964 |
# worksheet.write(row, inc(), r[25])
|
|
|
965 |
# worksheet.write(row, inc(), r[6])
|
|
|
966 |
# worksheet.write(row, inc(), r[7])
|
|
|
967 |
# worksheet.write(row, inc(), r[24])
|
| 15423 |
amit.gupta |
968 |
|
| 15542 |
amit.gupta |
969 |
flipkartOrders = session.query(FlipkartOrders).order_by(FlipkartOrders.created.desc()).all()
|
| 15540 |
amit.gupta |
970 |
flipkartOrders.reverse()
|
| 15423 |
amit.gupta |
971 |
row3=0
|
| 15430 |
amit.gupta |
972 |
#try:
|
| 15540 |
amit.gupta |
973 |
for order in flipkartOrders:
|
| 15423 |
amit.gupta |
974 |
row3 += 1
|
|
|
975 |
i=-1
|
| 15540 |
amit.gupta |
976 |
sh2.write(row3, inc(), order.user_id)
|
|
|
977 |
sh2.write(row3, inc(), order.email)
|
|
|
978 |
sh2.write(row3, inc(), order.created, datetime_format)
|
| 15423 |
amit.gupta |
979 |
sh2.write(row3, inc(), "Flipkart")
|
| 15540 |
amit.gupta |
980 |
sh2.write(row3, inc(), order.status)
|
|
|
981 |
sh2.write(row3, inc(), order.title)
|
|
|
982 |
sh2.write(row3, inc(), order.price)
|
|
|
983 |
sh2.write(row3, inc(), order.quantity)
|
|
|
984 |
sh2.write(row3, inc(), order.catalogId)
|
|
|
985 |
sh2.write(row3, inc(), order.brand)
|
|
|
986 |
sh2.write(row3, inc(), order.model)
|
|
|
987 |
sh2.write(row3, inc(), order.category)
|
| 14632 |
amit.gupta |
988 |
|
|
|
989 |
workbook.save(XLS_O_FILENAME)
|
| 14647 |
amit.gupta |
990 |
|
|
|
991 |
def getSkuData(storeId, identifier):
|
| 16492 |
amit.gupta |
992 |
if storeId in (1,2,4,5,6):
|
| 14647 |
amit.gupta |
993 |
skuData = client.Catalog.MasterData.find_one({'identifier':identifier, 'source_id':storeId})
|
|
|
994 |
elif storeId == 3:
|
|
|
995 |
skuData = client.Catalog.MasterData.find_one({'secondaryIdentifier':identifier, 'source_id':storeId})
|
|
|
996 |
return skuData
|
|
|
997 |
|
| 14460 |
amit.gupta |
998 |
def inc():
|
|
|
999 |
global i
|
|
|
1000 |
i+=1
|
|
|
1001 |
return i
|
| 15540 |
amit.gupta |
1002 |
|
|
|
1003 |
def migrateFlipkartOrders():
|
|
|
1004 |
db = client.Dtr
|
|
|
1005 |
info = reversed(list(db.flipkartOrderAffiliateInfo.find()))
|
|
|
1006 |
#try:
|
|
|
1007 |
for order in info:
|
|
|
1008 |
userId = None
|
|
|
1009 |
subTagId = None
|
|
|
1010 |
email = None
|
|
|
1011 |
subTagId = order.get("subTagId")
|
|
|
1012 |
if subTagId:
|
|
|
1013 |
click = session.query(Clicks).filter_by(tag = subTagId).first()
|
|
|
1014 |
if click is not None:
|
|
|
1015 |
userId= click.user_id
|
|
|
1016 |
user = session.query(Users.email).filter_by(id = userId).first()
|
|
|
1017 |
if user is not None:
|
|
|
1018 |
email = user.email
|
|
|
1019 |
|
|
|
1020 |
flipkartOrder = FlipkartOrders()
|
|
|
1021 |
flipkartOrder.user_id = userId
|
|
|
1022 |
flipkartOrder.identifier = order.get("identifier")
|
|
|
1023 |
flipkartOrder.email = email
|
|
|
1024 |
flipkartOrder.subtagId = order.get("subTagId")
|
|
|
1025 |
flipkartOrder.created = datetime.strptime(order.get("saleDate"), "%Y-%m-%d")
|
|
|
1026 |
flipkartOrder.status = order.get("conversionStatus")
|
|
|
1027 |
flipkartOrder.title = order.get("productTitle")
|
|
|
1028 |
flipkartOrder.price = order.get("price")
|
|
|
1029 |
flipkartOrder.quantity = order.get("quantity")
|
|
|
1030 |
flipkartOrder.productCode = order.get("productCode")
|
|
|
1031 |
skuData = getSkuData(2, order.get("productCode"))
|
|
|
1032 |
if skuData is not None:
|
|
|
1033 |
flipkartOrder.catalogId = skuData.get("skuBundleId")
|
|
|
1034 |
flipkartOrder.brand = skuData.get("brand")
|
|
|
1035 |
flipkartOrder.model = skuData.get("model_name")
|
|
|
1036 |
flipkartOrder.category =categoryMap.get(skuData.get("category_id"))
|
|
|
1037 |
flipkartOrder.title =skuData.get("source_product_name")
|
|
|
1038 |
|
|
|
1039 |
session.commit()
|
| 16947 |
amit.gupta |
1040 |
|
|
|
1041 |
|
|
|
1042 |
def main1():
|
|
|
1043 |
db = client.Dtr
|
|
|
1044 |
for offer in db.snapdealOrderAffiliateInfo.find({}):
|
|
|
1045 |
print offer.get("adId"), offer.get("saleAmount"), type(offer.get("saleAmount"))
|
|
|
1046 |
#obj = offer.get(saleTime)
|
|
|
1047 |
#obj['paidAmount'] += order["paidAmount"]
|
| 14632 |
amit.gupta |
1048 |
def addHeaders(sheet):
|
|
|
1049 |
global i
|
|
|
1050 |
i = 0
|
|
|
1051 |
sheet.write(0, inc(), )
|
| 14450 |
amit.gupta |
1052 |
def main():
|
| 17161 |
amit.gupta |
1053 |
message = generateSnapDealReco()
|
| 17169 |
amit.gupta |
1054 |
generateFlipkartReco()
|
|
|
1055 |
generateShopcluesReco()
|
|
|
1056 |
generateAmazonReco(XLS_A_FILENAME)
|
|
|
1057 |
message1 = getdata.summaryByBrandAndStore()
|
|
|
1058 |
getUserOrders()
|
|
|
1059 |
#sendmail(["amit.gupta@shop2020.in"], message, "Affiliate Reco", XLS_FILENAME)
|
| 17137 |
naman |
1060 |
#sendmail(["naman.kumar@shop2020.in"], message1, "All DTR Orders", XLS_O_FILENAME)
|
| 17169 |
amit.gupta |
1061 |
sendmail(["amit.gupta@shop2020.in", "rajneesh.arora@saholic.com", "chaitnaya.vats@saholic.com", "manoj.kumar@saholic.com", "manish.sharma@shop2020.in"], message1, "All DTR Orders", XLS_O_FILENAME)
|
|
|
1062 |
sendmail(["amit.gupta@shop2020.in","rajneesh.arora@saholic.com","manish.sharma@shop2020.in"], message, "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME, XLS_SC_FILENAME)
|
| 17001 |
amit.gupta |
1063 |
#sendmail(["amit.gupta@shop2020.in"], "", "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME, XLS_SC_FILENAME)
|
|
|
1064 |
|
| 17053 |
amit.gupta |
1065 |
def main3():
|
|
|
1066 |
db = client.Dtr
|
|
|
1067 |
#main()
|
|
|
1068 |
mailBodyTemplate="""
|
|
|
1069 |
<html>
|
|
|
1070 |
<body>
|
|
|
1071 |
<table cellspacing="0" border="1" style="text-align:right">
|
|
|
1072 |
<thead>
|
|
|
1073 |
<tr>
|
|
|
1074 |
<th style="text-align:center">Date</th>
|
|
|
1075 |
<th style="text-align:center">Sale</th>
|
|
|
1076 |
<th style="text-align:center">Approved</th>
|
|
|
1077 |
<th style="text-align:center">Approved %</th>
|
|
|
1078 |
<th style="text-align:center">Rejected</th>
|
|
|
1079 |
<th style="text-align:center">Rejected %</th>
|
|
|
1080 |
<th style="text-align:center">Missing %</th>
|
|
|
1081 |
<th style="text-align:center">Approved % against Sale</th>
|
|
|
1082 |
</tr>
|
|
|
1083 |
</thead>
|
|
|
1084 |
<tbody>
|
|
|
1085 |
{0}
|
|
|
1086 |
</tbody>
|
|
|
1087 |
</table>
|
|
|
1088 |
</body>
|
|
|
1089 |
</html>
|
|
|
1090 |
"""
|
|
|
1091 |
tbody=[]
|
|
|
1092 |
rowtemplate="<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td></tr>"
|
|
|
1093 |
for offer in db.flSaleSnapshot.find().limit(61).sort("_id",-1):
|
|
|
1094 |
approved = offer.get("approvedAmount")
|
|
|
1095 |
rejected = offer.get("rejectedAmount")
|
|
|
1096 |
sale = offer.get("paidAmount")
|
|
|
1097 |
total = approved + rejected
|
|
|
1098 |
if total ==0:
|
|
|
1099 |
continue
|
|
|
1100 |
tbody.append(rowtemplate.format(offer.get("_id"), sale, approved, int((approved*100/total)), rejected, int((rejected*100/total)), int((sale-approved-rejected)*100/sale),int((approved)*100/sale)))
|
|
|
1101 |
message = mailBodyTemplate.format("".join(tbody))
|
|
|
1102 |
print message
|
| 17001 |
amit.gupta |
1103 |
def main2():
|
|
|
1104 |
db = client.Dtr
|
| 17053 |
amit.gupta |
1105 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=46), 3)
|
| 17001 |
amit.gupta |
1106 |
datemap={}
|
|
|
1107 |
for row1 in curs:
|
|
|
1108 |
orderId = row1[0]
|
|
|
1109 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
1110 |
if order is None:
|
|
|
1111 |
continue
|
|
|
1112 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
|
|
1113 |
try:
|
|
|
1114 |
saleTime = datetime.strptime(order['placedOn'], "%a, %d %b, %Y").strftime("%Y-%m-%d")
|
|
|
1115 |
except:
|
|
|
1116 |
saleTime = datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").strftime("%Y-%m-%d")
|
|
|
1117 |
print "%s\t%s\t%s\t%s"%(orderId, order['placedOn'], saleTime, order['paidAmount'])
|
|
|
1118 |
if not datemap.has_key(saleTime):
|
| 17245 |
amit.gupta |
1119 |
datemap[saleTime] = {"totalAmount":0, "paidAmount":0, "rejectedAmount":0, "approvedAmount":0, "count":0, "subAmount":0}
|
| 17001 |
amit.gupta |
1120 |
|
|
|
1121 |
obj = datemap.get(saleTime)
|
|
|
1122 |
obj['paidAmount'] += order["paidAmount"]
|
| 17245 |
amit.gupta |
1123 |
for so in order['subOrders']:
|
|
|
1124 |
obj['subAmount'] += int(so['amountPaid'])
|
| 17001 |
amit.gupta |
1125 |
obj['count'] += 1
|
|
|
1126 |
|
| 17053 |
amit.gupta |
1127 |
for offer in db.snapdealOrderAffiliateInfo1.find({"saleDate":{"$gte":toTimeStamp(datetime.now() - timedelta(days=46))}}):
|
| 17001 |
amit.gupta |
1128 |
saleTime = utils.fromTimeStamp(offer.get('saleDate')).strftime("%Y-%m-%d")
|
|
|
1129 |
obj = datemap.get(saleTime)
|
|
|
1130 |
if obj is not None:
|
|
|
1131 |
try:
|
|
|
1132 |
if offer.get("payOut"):
|
|
|
1133 |
obj['approvedAmount'] += offer["saleAmount"]
|
|
|
1134 |
else:
|
|
|
1135 |
obj['rejectedAmount'] += offer["saleAmount"]
|
|
|
1136 |
except:
|
|
|
1137 |
print "Exception for orderId" , offer.get("orderId")
|
|
|
1138 |
else:
|
|
|
1139 |
print "Could not find sale date", saleTime
|
|
|
1140 |
continue
|
|
|
1141 |
|
|
|
1142 |
for key,valmap in datemap.iteritems():
|
|
|
1143 |
valmap['_id'] = key
|
|
|
1144 |
db.flSaleSnapshot.save(valmap)
|
| 14450 |
amit.gupta |
1145 |
|
|
|
1146 |
if __name__ == '__main__':
|
| 17169 |
amit.gupta |
1147 |
getdata.addToAllOrders(date.today()-timedelta(days=20))
|
|
|
1148 |
main2()
|
| 17008 |
amit.gupta |
1149 |
main()
|