| Line 8... |
Line 8... |
| 8 |
from dtr.reports.amazonreco import generateAmazonReco
|
8 |
from dtr.reports.amazonreco import generateAmazonReco
|
| 9 |
from dtr.storage import Mysql, DataService
|
9 |
from dtr.storage import Mysql, DataService
|
| 10 |
from dtr.storage.DataService import Users, Clicks, FlipkartOrders,\
|
10 |
from dtr.storage.DataService import Users, Clicks, FlipkartOrders,\
|
| 11 |
All_user_addresses
|
11 |
All_user_addresses
|
| 12 |
from dtr.storage.Mysql import getOrdersAfterDate, getOrdersByTag
|
12 |
from dtr.storage.Mysql import getOrdersAfterDate, getOrdersByTag
|
| 13 |
from dtr.utils.utils import fromTimeStamp
|
13 |
from dtr.utils import utils
|
| 14 |
from elixir import *
|
14 |
from elixir import *
|
| 15 |
from sqlalchemy.sql.expression import func, func, or_
|
15 |
from sqlalchemy.sql.expression import func, func, or_
|
| 16 |
from email import encoders
|
16 |
from email import encoders
|
| 17 |
from email.mime.base import MIMEBase
|
17 |
from email.mime.base import MIMEBase
|
| 18 |
from email.mime.multipart import MIMEMultipart
|
18 |
from email.mime.multipart import MIMEMultipart
|
| Line 236... |
Line 236... |
| 236 |
matchedList = []
|
236 |
matchedList = []
|
| 237 |
workbook = xlwt.Workbook()
|
237 |
workbook = xlwt.Workbook()
|
| 238 |
worksheet = workbook.add_sheet("Snapdeal Reconciled")
|
238 |
worksheet = workbook.add_sheet("Snapdeal Reconciled")
|
| 239 |
worksheet1 = workbook.add_sheet("Snapdeal Reconciled All")
|
239 |
worksheet1 = workbook.add_sheet("Snapdeal Reconciled All")
|
| 240 |
worksheet2 = workbook.add_sheet("Snapdeal Orders not reconciled")
|
240 |
worksheet2 = workbook.add_sheet("Snapdeal Orders not reconciled")
|
| - |
|
241 |
worksheet3 = workbook.add_sheet("DateWise Sale Summary")
|
| 241 |
affNotReconciledSheet = workbook.add_sheet("Snapdeal Aff not reconciled")
|
242 |
affNotReconciledSheet = workbook.add_sheet("Snapdeal Aff not reconciled")
|
| 242 |
setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet)
|
243 |
setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet, worksheet3)
|
| 243 |
row = 0
|
244 |
row = 0
|
| 244 |
anotherrow = 0
|
245 |
anotherrow = 0
|
| 245 |
row2 = 0
|
246 |
row2 = 0
|
| 246 |
row5=0
|
247 |
row5=0
|
| - |
|
248 |
datemap={}
|
| 247 |
for row1 in curs:
|
249 |
for row1 in curs:
|
| 248 |
orderId = row1[0]
|
250 |
orderId = row1[0]
|
| 249 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
251 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
| 250 |
if order is None:
|
252 |
if order is None:
|
| 251 |
continue
|
253 |
continue
|
| 252 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
254 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
| - |
|
255 |
saleTime = datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").stftime("%Y-%m-%d")
|
| - |
|
256 |
if not datemap.has_key(saleTime):
|
| - |
|
257 |
datemap[saleTime] = {"totalAmount":0, "paidAmount":0, "rejectedAmount":0, "approvedAmount":0}
|
| - |
|
258 |
|
| - |
|
259 |
obj = datemap.get(saleTime)
|
| - |
|
260 |
obj['paidAmount'] += order["paidAmount"]
|
| - |
|
261 |
|
| - |
|
262 |
|
| - |
|
263 |
|
| 253 |
aff = list(db.snapdealOrderAffiliateInfo.find({"subTagId":order["subTagId"]}))
|
264 |
aff = list(db.snapdealOrderAffiliateInfo.find({"subTagId":order["subTagId"]}))
|
| 254 |
if len(aff) > 1:
|
265 |
if len(aff) > 1:
|
| 255 |
aff = [f for f in aff if f.get("payOut")>0]
|
266 |
aff = [f for f in aff if f.get("payOut")>0]
|
| 256 |
anotherrow += 1
|
267 |
anotherrow += 1
|
| 257 |
try:
|
268 |
try:
|
| 258 |
formattedTimestamp = order['placedOn']
|
269 |
formattedTimestamp = order['placedOn']
|
| 259 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
270 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
| 260 |
except:
|
271 |
except:
|
| 261 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
272 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
| 262 |
formattedTimestamp = datetime.strftime(fromTimeStamp(timestamp1), "%b %d, %Y, %I:%M %p")
|
273 |
formattedTimestamp = datetime.strftime(utils.fromTimeStamp(timestamp1), "%b %d, %Y, %I:%M %p")
|
| 263 |
if len(aff) > 0 and order["subTagId"] not in matchedList and int(order["paidAmount"])==int(aff[0]["saleAmount"]):
|
274 |
if len(aff) > 0 and order["subTagId"] not in matchedList and int(order["paidAmount"])==int(aff[0]["saleAmount"]):
|
| 264 |
|
275 |
|
| 265 |
matchedList.append(order["subTagId"])
|
276 |
matchedList.append(order["subTagId"])
|
| 266 |
db.snapdealOrderAffiliateInfo.update({"adId":aff[0].get("adId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
277 |
db.snapdealOrderAffiliateInfo.update({"adId":aff[0].get("adId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
| 267 |
order['reconciled'] = True
|
278 |
order['reconciled'] = True
|
| Line 410... |
Line 421... |
| 410 |
affNotReconciledSheet.write(row, inc(), offer.get("saleDate"))
|
421 |
affNotReconciledSheet.write(row, inc(), offer.get("saleDate"))
|
| 411 |
affNotReconciledSheet.write(row, inc(), offer.get("saleAmount"))
|
422 |
affNotReconciledSheet.write(row, inc(), offer.get("saleAmount"))
|
| 412 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
423 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
| 413 |
affNotReconciledSheet.write(row, inc(), offer.get("conversionStatus"))
|
424 |
affNotReconciledSheet.write(row, inc(), offer.get("conversionStatus"))
|
| 414 |
affNotReconciledSheet.write(row, inc(), offer.get("ip"))
|
425 |
affNotReconciledSheet.write(row, inc(), offer.get("ip"))
|
| - |
|
426 |
|
| - |
|
427 |
for offer in db.snapdealOrderAffiliateInfo1.find({}):
|
| - |
|
428 |
saleTime = utils.fromTimeStamp(offer.get('saleDate')).stftime("%Y-%m-%d")
|
| - |
|
429 |
obj = datemap.get(saleTime)
|
| - |
|
430 |
if offer.get("payOut"):
|
| - |
|
431 |
obj['approvedAmount'] += order["approvedAmount"]
|
| - |
|
432 |
else:
|
| - |
|
433 |
obj['rejectedAmount'] += order["rejectedAmount"]
|
| - |
|
434 |
|
| 415 |
|
435 |
|
| 416 |
workbook.save(XLS_FILENAME)
|
436 |
workbook.save(XLS_FILENAME)
|
| 417 |
|
437 |
|
| 418 |
def generateShopcluesReco():
|
438 |
def generateShopcluesReco():
|
| 419 |
global i
|
439 |
global i
|
| Line 443... |
Line 463... |
| 443 |
try:
|
463 |
try:
|
| 444 |
formattedTimestamp = order['placedOn']
|
464 |
formattedTimestamp = order['placedOn']
|
| 445 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%d %b %Y %I:%M %p").timetuple()))
|
465 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%d %b %Y %I:%M %p").timetuple()))
|
| 446 |
except:
|
466 |
except:
|
| 447 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
467 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
| 448 |
formattedTimestamp = datetime.strftime(fromTimeStamp(timestamp1), "%d %b %Y %I:%M %p")
|
468 |
formattedTimestamp = datetime.strftime(utils.fromTimeStamp(timestamp1), "%d %b %Y %I:%M %p")
|
| 449 |
|
469 |
|
| 450 |
if len(aff) > 0 and order["subTagId"] not in matchedList and long(order["paidAmount"])==long(float(aff[0]["transactionValue"])):
|
470 |
if len(aff) > 0 and order["subTagId"] not in matchedList and long(order["paidAmount"])==long(float(aff[0]["transactionValue"])):
|
| 451 |
matchedList.append(order["subTagId"])
|
471 |
matchedList.append(order["subTagId"])
|
| 452 |
db.shopcluesOrderAffiliateInfo.update({"merchantOrderId":aff[0].get("merchantOrderId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
472 |
db.shopcluesOrderAffiliateInfo.update({"merchantOrderId":aff[0].get("merchantOrderId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
| 453 |
order['reconciled'] = True
|
473 |
order['reconciled'] = True
|
| Line 474... |
Line 494... |
| 474 |
worksheet1.write(anotherrow, i, order['placedOn'])
|
494 |
worksheet1.write(anotherrow, i, order['placedOn'])
|
| 475 |
worksheet.write(row, inc(), formattedTimestamp)
|
495 |
worksheet.write(row, inc(), formattedTimestamp)
|
| 476 |
worksheet1.write(anotherrow, i, formattedTimestamp)
|
496 |
worksheet1.write(anotherrow, i, formattedTimestamp)
|
| 477 |
worksheet.write(row, inc(), int(order['paidAmount']))
|
497 |
worksheet.write(row, inc(), int(order['paidAmount']))
|
| 478 |
worksheet1.write(anotherrow, i, int(order['paidAmount']))
|
498 |
worksheet1.write(anotherrow, i, int(order['paidAmount']))
|
| 479 |
worksheet.write(row, inc(), datetime.strftime(fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
499 |
worksheet.write(row, inc(), datetime.strftime(utils.fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
| 480 |
worksheet1.write(anotherrow, i, datetime.strftime(fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
500 |
worksheet1.write(anotherrow, i, datetime.strftime(utils.fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
| 481 |
worksheet.write(row, inc(), aff[0]['transactionValue'])
|
501 |
worksheet.write(row, inc(), aff[0]['transactionValue'])
|
| 482 |
worksheet1.write(anotherrow, i, aff[0]['transactionValue'])
|
502 |
worksheet1.write(anotherrow, i, aff[0]['transactionValue'])
|
| 483 |
worksheet.write(row, inc(), aff[0]['payOut'])
|
503 |
worksheet.write(row, inc(), aff[0]['payOut'])
|
| 484 |
worksheet1.write(anotherrow, i, aff[0]['payOut'])
|
504 |
worksheet1.write(anotherrow, i, aff[0]['payOut'])
|
| 485 |
worksheet.write(row, inc(), "NA")
|
505 |
worksheet.write(row, inc(), "NA")
|
| Line 569... |
Line 589... |
| 569 |
for order in orders:
|
589 |
for order in orders:
|
| 570 |
if notReconciled.has_key(order[0]):
|
590 |
if notReconciled.has_key(order[0]):
|
| 571 |
(roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
|
591 |
(roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
|
| 572 |
if paidAmount==int(offer.get("transactionValue")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
|
592 |
if paidAmount==int(offer.get("transactionValue")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
|
| 573 |
i = column
|
593 |
i = column
|
| 574 |
worksheet1.write(roww, inc(), datetime.strftime(fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
594 |
worksheet1.write(roww, inc(), datetime.strftime(utils.fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
| 575 |
worksheet1.write(roww, inc(), offer.get("transactionValue"))
|
595 |
worksheet1.write(roww, inc(), offer.get("transactionValue"))
|
| 576 |
worksheet1.write(roww, inc(), offer.get("payOut"))
|
596 |
worksheet1.write(roww, inc(), offer.get("payOut"))
|
| 577 |
del notReconciled[order[0]]
|
597 |
del notReconciled[order[0]]
|
| 578 |
print "found match for user", order[1]
|
598 |
print "found match for user", order[1]
|
| 579 |
db.shopcluesOrderAffiliateInfo.update({"transactionId":offer.get("transactionId")}, {"$set":{"reconciled":True, "orderId":order[0]}}, multi=True)
|
599 |
db.shopcluesOrderAffiliateInfo.update({"transactionId":offer.get("transactionId")}, {"$set":{"reconciled":True, "orderId":order[0]}}, multi=True)
|
| Line 587... |
Line 607... |
| 587 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
607 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
| 588 |
row += 1
|
608 |
row += 1
|
| 589 |
i=-1
|
609 |
i=-1
|
| 590 |
affNotReconciledSheet.write(row, inc(), offer.get("uniqueKey"))
|
610 |
affNotReconciledSheet.write(row, inc(), offer.get("uniqueKey"))
|
| 591 |
affNotReconciledSheet.write(row, inc(), offer.get("subTagId"))
|
611 |
affNotReconciledSheet.write(row, inc(), offer.get("subTagId"))
|
| 592 |
affNotReconciledSheet.write(row, inc(), datetime.strftime(fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
612 |
affNotReconciledSheet.write(row, inc(), datetime.strftime(utils.fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
| 593 |
affNotReconciledSheet.write(row, inc(), offer.get("transactionValue"))
|
613 |
affNotReconciledSheet.write(row, inc(), offer.get("transactionValue"))
|
| 594 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
614 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
| 595 |
affNotReconciledSheet.write(row, inc(), offer.get("status"))
|
615 |
affNotReconciledSheet.write(row, inc(), offer.get("status"))
|
| 596 |
affNotReconciledSheet.write(row, inc(), 'NA')
|
616 |
affNotReconciledSheet.write(row, inc(), 'NA')
|
| 597 |
|
617 |
|
| Line 624... |
Line 644... |
| 624 |
email.append('amit.gupta@shop2020.in')
|
644 |
email.append('amit.gupta@shop2020.in')
|
| 625 |
MAILTO = email
|
645 |
MAILTO = email
|
| 626 |
mailServer.login(SENDER, PASSWORD)
|
646 |
mailServer.login(SENDER, PASSWORD)
|
| 627 |
mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
|
647 |
mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
|
| 628 |
|
648 |
|
| 629 |
def setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet):
|
649 |
def setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet, worksheet3):
|
| 630 |
boldStyle = xlwt.XFStyle()
|
650 |
boldStyle = xlwt.XFStyle()
|
| 631 |
f = xlwt.Font()
|
651 |
f = xlwt.Font()
|
| 632 |
f.bold = True
|
652 |
f.bold = True
|
| 633 |
boldStyle.font = f
|
653 |
boldStyle.font = f
|
| 634 |
row = 0
|
654 |
row = 0
|
| Line 704... |
Line 724... |
| 704 |
affNotReconciledSheet.write(row, inc(), 'Sale Amount', boldStyle)
|
724 |
affNotReconciledSheet.write(row, inc(), 'Sale Amount', boldStyle)
|
| 705 |
affNotReconciledSheet.write(row, inc(), 'Pay Out', boldStyle)
|
725 |
affNotReconciledSheet.write(row, inc(), 'Pay Out', boldStyle)
|
| 706 |
affNotReconciledSheet.write(row, inc(), 'Status', boldStyle)
|
726 |
affNotReconciledSheet.write(row, inc(), 'Status', boldStyle)
|
| 707 |
affNotReconciledSheet.write(row, inc(), 'IP', boldStyle)
|
727 |
affNotReconciledSheet.write(row, inc(), 'IP', boldStyle)
|
| 708 |
|
728 |
|
| - |
|
729 |
i =-1
|
| - |
|
730 |
worksheet3.write(row, inc(), 'Date', boldStyle)
|
| - |
|
731 |
worksheet3.write(row, inc(), 'Sale Amount', boldStyle)
|
| - |
|
732 |
worksheet3.write(row, inc(), 'Approved Sales', boldStyle)
|
| - |
|
733 |
worksheet3.write(row, inc(), 'Rejected Sales', boldStyle)
|
| - |
|
734 |
|
| 709 |
def getUserAmountReconciled():
|
735 |
def getUserAmountReconciled():
|
| 710 |
pass
|
736 |
pass
|
| 711 |
|
737 |
|
| 712 |
def getUserOrders():
|
738 |
def getUserOrders():
|
| 713 |
global i
|
739 |
global i
|
| Line 973... |
Line 999... |
| 973 |
flipkartOrder.model = skuData.get("model_name")
|
999 |
flipkartOrder.model = skuData.get("model_name")
|
| 974 |
flipkartOrder.category =categoryMap.get(skuData.get("category_id"))
|
1000 |
flipkartOrder.category =categoryMap.get(skuData.get("category_id"))
|
| 975 |
flipkartOrder.title =skuData.get("source_product_name")
|
1001 |
flipkartOrder.title =skuData.get("source_product_name")
|
| 976 |
|
1002 |
|
| 977 |
session.commit()
|
1003 |
session.commit()
|
| - |
|
1004 |
|
| - |
|
1005 |
|
| - |
|
1006 |
def main1():
|
| - |
|
1007 |
db = client.Dtr
|
| - |
|
1008 |
for offer in db.snapdealOrderAffiliateInfo.find({}):
|
| - |
|
1009 |
print offer.get("adId"), offer.get("saleAmount"), type(offer.get("saleAmount"))
|
| - |
|
1010 |
#obj = offer.get(saleTime)
|
| - |
|
1011 |
#obj['paidAmount'] += order["paidAmount"]
|
| 978 |
def addHeaders(sheet):
|
1012 |
def addHeaders(sheet):
|
| 979 |
global i
|
1013 |
global i
|
| 980 |
i = 0
|
1014 |
i = 0
|
| 981 |
sheet.write(0, inc(), )
|
1015 |
sheet.write(0, inc(), )
|
| 982 |
def main():
|
1016 |
def main():
|
| Line 991... |
Line 1025... |
| 991 |
sendmail(["amit.gupta@shop2020.in", "rajneesh.arora@saholic.com", "chaitnaya.vats@saholic.com", "manoj.kumar@saholic.com", "manish.sharma@shop2020.in"], "", "All DTR Orders", XLS_O_FILENAME)
|
1025 |
sendmail(["amit.gupta@shop2020.in", "rajneesh.arora@saholic.com", "chaitnaya.vats@saholic.com", "manoj.kumar@saholic.com", "manish.sharma@shop2020.in"], "", "All DTR Orders", XLS_O_FILENAME)
|
| 992 |
|
1026 |
|
| 993 |
if __name__ == '__main__':
|
1027 |
if __name__ == '__main__':
|
| 994 |
#info = client.Dtr.flipkartOrderAffiliateInfo.find()
|
1028 |
#info = client.Dtr.flipkartOrderAffiliateInfo.find()
|
| 995 |
#print info
|
1029 |
#print info
|
| 996 |
main()
|
1030 |
main1()
|
| 997 |
|
1031 |
|
| 998 |
|
1032 |
|