Subversion Repositories SmartDukaan

Rev

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

Rev 17158 Rev 17171
Line 42... Line 42...
42
dateWiseSaholicOrderMap = {}
42
dateWiseSaholicOrderMap = {}
43
weekWiseSaholicOrderMap = {}
43
weekWiseSaholicOrderMap = {}
44
monthWiseSaholicOrderMap = {}
44
monthWiseSaholicOrderMap = {}
45
 
45
 
46
orderIds = []
46
orderIds = []
47
cutOff = 1425839400
47
cutOff = utils.toTimeStamp(date.today()-timedelta(days=90))
48
#cutOff = 1425234600
48
#cutOff = 1425234600
49
oneDay = 86400
49
oneDay = 86400
50
monthCutOff = 1425148200
50
monthCutOff = 1425148200
51
weekCutOff = 1425839400
51
weekCutOff = 1425839400
52
newWeekCutOff = 1425839400
52
newWeekCutOff = 1425839400
Line 333... Line 333...
333
    worksheet.write(row, 5, 'DTO', boldStyle)
333
    worksheet.write(row, 5, 'DTO', boldStyle)
334
    worksheet.write(row, 6, 'DVOL', boldStyle)   
334
    worksheet.write(row, 6, 'DVOL', boldStyle)   
335
    worksheet.write(row, 7, 'DTV', boldStyle)
335
    worksheet.write(row, 7, 'DTV', boldStyle)
336
    worksheet.write(row, 8, 'DOWNVOL', boldStyle)
336
    worksheet.write(row, 8, 'DOWNVOL', boldStyle)
337
    worksheet.write(row, 9, 'DOWNVAL', boldStyle)
337
    worksheet.write(row, 9, 'DOWNVAL', boldStyle)
-
 
338
    dateMap={}
338
    for r in result:
339
    for r in result:
339
        row += 1
340
        row += 1
340
        column = 0
341
        column = 0
341
        for data in r :
342
        for data in r :
342
            worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
343
            worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
-
 
344
            dateMap[str(data)]=row
343
            column += 1
345
            column += 1
344
 
346
 
345
    row = 0
347
    row = 0
346
    cursor.execute(dnruSql)
348
    cursor.execute(dnruSql)
347
    result = cursor.fetchall()
349
    result = cursor.fetchall()
Line 397... Line 399...
397
    
399
    
398
    row=0
400
    row=0
399
 
401
 
400
    z=0    
402
    z=0    
401
    for x in sorted(dateWiseOrderMap):
403
    for x in sorted(dateWiseOrderMap):
402
        row += 1
-
 
403
        column = 6
404
        column = 6
404
        d = str(datetime.fromtimestamp(x/1000.0))
405
        d = datetime.fromtimestamp(x/1000.0)
-
 
406
        row = dateMap[datetime.strftime(d,'%Y-%m-%d')]
405
        dq=DQ_QUERY%d[:10]
407
        dq=DQ_QUERY%str(d)[:10]
406
        cursor.execute(dq)
408
        cursor.execute(dq)
407
        result = cursor.fetchall()
409
        result = cursor.fetchall()
408
        for r in result:
410
        for r in result:
409
            quantity= r[0]   
411
            quantity= r[0]   
410
            if quantity is None:
412
            if quantity is None:
Line 412... Line 414...
412
        worksheet.write(row,column,(dateWiseOrderMap.get(x).count)+quantity)
414
        worksheet.write(row,column,(dateWiseOrderMap.get(x).count)+quantity)
413
        column += 1
415
        column += 1
414
 
416
 
415
    row =0
417
    row =0
416
    for x in sorted(dateWiseOrderMap):
418
    for x in sorted(dateWiseOrderMap):
417
        row += 1
-
 
418
        column = 7
419
        column = 7
419
        d = str(datetime.fromtimestamp(x/1000.0))
420
        d = datetime.fromtimestamp(x/1000.0)
-
 
421
        row = dateMap[datetime.strftime(d, '%Y-%m-%d')]
420
        dq=DV_QUERY%d[:10]
422
        dq=DV_QUERY%str(d)[:10]
421
        cursor.execute(dq)
423
        cursor.execute(dq)
422
        result = cursor.fetchall()
424
        result = cursor.fetchall()
423
        for r in result:
425
        for r in result:
424
            quantity= r[0]   
426
            quantity= r[0]   
425
            if quantity is None:
427
            if quantity is None:
426
                quantity=0
428
                quantity=0
427
        worksheet.write(row,column,(dateWiseOrderMap.get(x).value)+float(quantity))
429
        worksheet.write(row,column,(dateWiseOrderMap.get(x).value)+float(quantity))
428
        column += 1    
-
 
429
        
430
        
430
    #For Saholic
431
    #For Saholic
431
    row=0
-
 
432
    cursor = conn.cursor()
432
    cursor = conn.cursor()
433
    cursor.execute(datesql)
433
    cursor.execute(datesql)
434
    result = cursor.fetchall()
434
    result = cursor.fetchall()
435
    for x in sorted(dateWiseSaholicOrderMap):
435
    for x in sorted(dateWiseSaholicOrderMap):
436
        row=0
-
 
437
        for r in result:
436
        z= to_x_date(x)
438
            for data in r :
437
        row = dateMap.get(z)
439
                row += 1
438
        if row:
440
                z= to_x_date(x)
-
 
441
                if str(data).strip() == str(z).strip():
-
 
442
                    column = 8
439
            column = 8
443
                    worksheet.write(row,column,dateWiseSaholicOrderMap.get(x).count)
440
            worksheet.write(row,column,dateWiseSaholicOrderMap.get(x).count)
444
                    column += 1
-
 
445
                    
441
                    
446
    for x in sorted(dateWiseSaholicOrderMap):
442
    for x in sorted(dateWiseSaholicOrderMap):
447
        row=0
-
 
448
        for r in result:
443
        z= to_x_date(x)
449
            for data in r :
444
        row=dateMap.get(z)
450
                row += 1
445
        if row:
451
                z= to_x_date(x)
-
 
452
                if str(data).strip() == str(z).strip():
-
 
453
                    column = 9
446
                column = 9
454
                    worksheet.write(row,column,dateWiseSaholicOrderMap.get(x).value)
447
                worksheet.write(row,column,dateWiseSaholicOrderMap.get(x).value)
455
                    column += 1
-
 
456
                                        
448
                                        
457
    
449
    
458
def generateMonthlyReport():
450
def generateMonthlyReport():
459
    monthSql = MONTH_QUERY
451
    monthSql = MONTH_QUERY
460
    mnruSql = MNRU_QUERY
452
    mnruSql = MNRU_QUERY
Line 762... Line 754...
762
    fileMsg.set_payload(file(TMP_FILE).read())
754
    fileMsg.set_payload(file(TMP_FILE).read())
763
    encoders.encode_base64(fileMsg)
755
    encoders.encode_base64(fileMsg)
764
    fileMsg.add_header('Content-Disposition', 'attachment;filename=' + fileName)
756
    fileMsg.add_header('Content-Disposition', 'attachment;filename=' + fileName)
765
    msg.attach(fileMsg)
757
    msg.attach(fileMsg)
766
    
758
    
767
    MAILTO = ['manas.kapoor@saholic.com','rajneesh.arora@saholic.com']
759
    MAILTO = ['manas.kapoor@saholic.com','rajneesh.arora@saholic.com', 'amit.gupta@saholic.com']
768
    #MAILTO = ['manas.kapoor@saholic.com']
760
    #MAILTO = ['amit.gupta@saholic.com']
769
    mailServer.login(SENDER, PASSWORD)
761
    mailServer.login(SENDER, PASSWORD)
770
    mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
762
    mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
771
 
763
 
772
class __Order:
764
class __Order:
773
    
765
    
Line 787... Line 779...
787
            return None
779
            return None
788
    return con
780
    return con
789
 
781
 
790
def populateOrderMap():
782
def populateOrderMap():
791
    global dateWiseOrderMap
783
    global dateWiseOrderMap
792
    allOrders = get_mongo_connection().Dtr.merchantOrder.find({'createdOnInt':{"$gte":cutOff},'storeId':{"$in":[1,3,4,5,6]}}).sort([('createdOnInt',pymongo.ASCENDING)])
784
    allOrders = get_mongo_connection().Dtr.merchantOrder.find({'createdOnInt':{"$gte":cutOff},'storeId':{"$in":[1,3,4,5,6]}}, {"orderId":1,"createdOnInt":1,"subOrders":1}).sort([('createdOnInt',pymongo.ASCENDING)])
793
    for orders in allOrders:
785
    for orders in allOrders:
794
        if orders.get('orderId') not in order_ids:
786
        if orders.get('orderId') not in order_ids:
795
            continue
787
            continue
796
        cdate = ((to_py_date(orders.get('createdOnInt') * 1000)))
788
        cdate = ((to_py_date(orders.get('createdOnInt') * 1000)))
797
        millisec = to_java_date(datetime(cdate.year, cdate.month, cdate.day))
789
        millisec = to_java_date(datetime(cdate.year, cdate.month, cdate.day))
Line 1027... Line 1019...
1027
    populateSaholicWeekWiseMap1()
1019
    populateSaholicWeekWiseMap1()
1028
    populateSaholicMonthWiseMap1()
1020
    populateSaholicMonthWiseMap1()
1029
    generateDailyReport()
1021
    generateDailyReport()
1030
    generateWeeklyReport()
1022
    generateWeeklyReport()
1031
    generateMonthlyReport()
1023
    generateMonthlyReport()
1032
    sendmail(["manas.kapoor@shop2020.in","rajneesh.arora@saholic.com"], "", TMP_FILE, SUBJECT)
1024
    sendmail(["manas.kapoor@shop2020.in","rajneesh.arora@saholic.com", "amit.gupta@shop2020.in"], "", TMP_FILE, SUBJECT)
1033
    #sendmail(["manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
1025
    #sendmail(["manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
1034
    
1026
    
1035
def to_x_date(java_timestamp):
1027
def to_x_date(java_timestamp):
1036
    try:
1028
    try:
1037
        date = datetime.fromtimestamp(java_timestamp / 1e3)       
1029
        date = datetime.fromtimestamp(java_timestamp / 1e3)