Subversion Repositories SmartDukaan

Rev

Rev 16995 | Rev 17008 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16995 Rev 17001
Line 24... Line 24...
24
import MySQLdb
24
import MySQLdb
25
import smtplib
25
import smtplib
26
import time
26
import time
27
import xlwt
27
import xlwt
28
from dtr.utils import utils
28
from dtr.utils import utils
-
 
29
from dtr.utils.utils import toTimeStamp
29
#from xlwt import 
30
#from xlwt import 
30
 
31
 
31
DataService.initialize()
32
DataService.initialize()
32
client = MongoClient('mongodb://localhost:27017/')
33
client = MongoClient('mongodb://localhost:27017/')
33
 
34
 
Line 241... Line 242...
241
    worksheet3 = workbook.add_sheet("DateWise Sale Summary")
242
    worksheet3 = workbook.add_sheet("DateWise Sale Summary")
242
    affNotReconciledSheet = workbook.add_sheet("Snapdeal Aff not reconciled")
243
    affNotReconciledSheet = workbook.add_sheet("Snapdeal Aff not reconciled")
243
    setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet, worksheet3)
244
    setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet, worksheet3)
244
    row = 0
245
    row = 0
245
    anotherrow = 0
246
    anotherrow = 0
246
    row2 = 0
-
 
247
    row5=0
247
    row5=0
248
    datemap={}
248
    datemap={}
249
    for row1 in curs:
249
    for row1 in curs:
250
        orderId = row1[0]
250
        orderId = row1[0]
251
        order = db.merchantOrder.find_one({"orderId":orderId})
251
        order = db.merchantOrder.find_one({"orderId":orderId})
Line 253... Line 253...
253
            continue
253
            continue
254
        #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
        try:
255
        try:
256
            saleTime = datetime.strptime(order['placedOn'], "%a, %d %b, %Y").strftime("%Y-%m-%d")
256
            saleTime = datetime.strptime(order['placedOn'], "%a, %d %b, %Y").strftime("%Y-%m-%d")
257
        except:
257
        except:
258
            saleTime = datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").strftime("%Y-%m-%d")
258
            saleTime = datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").strftime("%Y-%m-%d")    
259
        
-
 
260
        if not datemap.has_key(saleTime):
-
 
261
            datemap[saleTime] = {"totalAmount":0, "paidAmount":0, "rejectedAmount":0, "approvedAmount":0}
-
 
262
            
-
 
263
        obj = datemap.get(saleTime)
-
 
264
        obj['paidAmount'] += order["paidAmount"] 
-
 
265
        
-
 
266
        
-
 
267
            
259
            
268
        aff = list(db.snapdealOrderAffiliateInfo.find({"subTagId":order["subTagId"]}))
260
        aff = list(db.snapdealOrderAffiliateInfo.find({"subTagId":order["subTagId"]}))
269
        if len(aff) > 1:
261
        if len(aff) > 1:
270
            aff = [f for f in aff if f.get("payOut")>0]
262
            aff = [f for f in aff if f.get("payOut")>0]
271
        anotherrow += 1
263
        anotherrow += 1
Line 426... Line 418...
426
        affNotReconciledSheet.write(row, inc(), offer.get("saleAmount")) 
418
        affNotReconciledSheet.write(row, inc(), offer.get("saleAmount")) 
427
        affNotReconciledSheet.write(row, inc(), offer.get("payOut")) 
419
        affNotReconciledSheet.write(row, inc(), offer.get("payOut")) 
428
        affNotReconciledSheet.write(row, inc(), offer.get("conversionStatus"))
420
        affNotReconciledSheet.write(row, inc(), offer.get("conversionStatus"))
429
        affNotReconciledSheet.write(row, inc(), offer.get("ip"))
421
        affNotReconciledSheet.write(row, inc(), offer.get("ip"))
430
    
422
    
431
    for offer in db.snapdealOrderAffiliateInfo1.find({}):
-
 
432
        saleTime =  utils.fromTimeStamp(offer.get('saleDate')).strftime("%Y-%m-%d")
-
 
433
        obj = datemap.get(saleTime)
-
 
434
        if offer.get("payOut"):
-
 
435
            obj['approvedAmount'] += order["approvedAmount"]
-
 
436
        else:
-
 
437
            obj['rejectedAmount'] += order["rejectedAmount"] 
-
 
438
    
423
    
439
    message=""
424
    message=""
440
    for key,valmap in  datemap.iteritems():
-
 
441
        valmap['_id'] = key
-
 
442
        db.flSaleSnapshot.save(valmap)
-
 
443
        
-
 
444
        mailBodyTemplate="""
425
#    mailBodyTemplate="""
445
        <html>
426
#        <html>
446
            <body>
427
#            <body>
447
            <table cellspacing="0" border="1" style="text-align:right">
428
#            <table cellspacing="0" border="1" style="text-align:right">
448
                <thead>
429
#                <thead>
449
                    <tr>
430
#                    <tr>
450
                        <th style="text-align:center">Date</th>
431
#                        <th style="text-align:center">Date</th>
451
                        <th  style="text-align:center">Sale</th>
432
#                        <th  style="text-align:center">Sale</th>
452
                        <th  style="text-align:center">Approved</th>
433
#                        <th  style="text-align:center">Approved</th>
453
                        <th  style="text-align:center">Rejected</th>
434
#                        <th  style="text-align:center">Rejected</th>
454
                    </tr>
435
#                    </tr>
455
                </thead>
436
#                </thead>
456
                <tbody>
437
#                <tbody>
457
                    {10}
438
#                    {0}
458
                </tbody>
439
#                </tbody>
459
            </table>
440
#            </table>
460
            </body>
441
#            </body>
461
        </html>
442
#        </html>
462
    """
443
#    """
463
    tbody=[]
444
#    tbody=[]
464
    rowtemplate="<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>"
445
#    rowtemplate="<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>"
465
    for offer in db.flSaleSnapshot.find({}):
446
#    for offer in db.flSaleSnapshot.find({}):
466
        tbody.append(rowtemplate.format(offer.get("_id"), offer.get("paidAmount"), offer.get("saleAmount"), offer.get("rejectedAmount")))
447
#        tbody.append(rowtemplate.format(offer.get("_id"), offer.get("paidAmount"), offer.get("saleAmount"), offer.get("rejectedAmount")))
467
    message = mailBodyTemplate.format("".join(tbody))
448
#    message = mailBodyTemplate.format("".join(tbody))
468
    workbook.save(XLS_FILENAME)
449
    workbook.save(XLS_FILENAME)
469
    
450
    
470
    return message
451
    return message
471
    
452
    
472
def generateShopcluesReco():
453
def generateShopcluesReco():
Line 1054... Line 1035...
1054
    generateFlipkartReco()
1035
    generateFlipkartReco()
1055
    generateShopcluesReco()
1036
    generateShopcluesReco()
1056
    generateAmazonReco(XLS_A_FILENAME)
1037
    generateAmazonReco(XLS_A_FILENAME)
1057
    getUserOrders()
1038
    getUserOrders()
1058
    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)
1039
    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)
1059
    #sendmail(["amit.gupta@shop2020.in"], "", "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME)
1040
    #sendmail(["amit.gupta@shop2020.in"], "", "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME, XLS_SC_FILENAME)
1060
    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)
1041
    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)
-
 
1042
    
-
 
1043
    
-
 
1044
def main2():
-
 
1045
    db = client.Dtr
-
 
1046
    curs = getOrdersAfterDate(datetime.now() - timedelta(days=1), 3)
-
 
1047
    datemap={}
-
 
1048
    for row1 in curs:
-
 
1049
        orderId = row1[0]
-
 
1050
        order = db.merchantOrder.find_one({"orderId":orderId})
-
 
1051
        if order is None:
-
 
1052
            continue
-
 
1053
        #saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
-
 
1054
        try:
-
 
1055
            saleTime = datetime.strptime(order['placedOn'], "%a, %d %b, %Y").strftime("%Y-%m-%d")
-
 
1056
        except:
-
 
1057
            saleTime = datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").strftime("%Y-%m-%d")
-
 
1058
        print "%s\t%s\t%s\t%s"%(orderId, order['placedOn'], saleTime, order['paidAmount'])
-
 
1059
        if not datemap.has_key(saleTime):
-
 
1060
            datemap[saleTime] = {"totalAmount":0, "paidAmount":0, "rejectedAmount":0, "approvedAmount":0, "count":0}
-
 
1061
            
-
 
1062
        obj = datemap.get(saleTime)
-
 
1063
        obj['paidAmount'] += order["paidAmount"]
-
 
1064
        obj['count'] += 1
-
 
1065
        
-
 
1066
    for offer in db.snapdealOrderAffiliateInfo1.find({"saleDate":{"$gte":toTimeStamp(datetime.now() - timedelta(days=1))}}):
-
 
1067
        saleTime =  utils.fromTimeStamp(offer.get('saleDate')).strftime("%Y-%m-%d")
-
 
1068
        obj = datemap.get(saleTime)
-
 
1069
        if obj is not None:
-
 
1070
            try:
-
 
1071
                if offer.get("payOut"):
-
 
1072
                    obj['approvedAmount'] += offer["saleAmount"]
-
 
1073
                else:
-
 
1074
                    obj['rejectedAmount'] += offer["saleAmount"]
-
 
1075
            except:
-
 
1076
                print "Exception for orderId" , offer.get("orderId")
-
 
1077
        else:
-
 
1078
            print "Could not find sale date", saleTime
-
 
1079
            continue
-
 
1080
    
-
 
1081
    for key,valmap in  datemap.iteritems():
-
 
1082
        valmap['_id'] = key
-
 
1083
        db.flSaleSnapshot.save(valmap)
1061
 
1084
 
1062
if __name__ == '__main__':
1085
if __name__ == '__main__':
1063
    #info = client.Dtr.flipkartOrderAffiliateInfo.find()
1086
    #info = client.Dtr.flipkartOrderAffiliateInfo.find()
1064
    #print info
1087
    #print info
1065
    main()
1088
    main1()
1066
    
1089
    
1067
1090