Subversion Repositories SmartDukaan

Rev

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

Rev 18422 Rev 18495
Line 286... Line 286...
286
ACCS_CART_PRODUCT_PRICING="""
286
ACCS_CART_PRODUCT_PRICING="""
287
select user_id,call_disposition,product_input,pricing_input from productpricinginputs where 
287
select user_id,call_disposition,product_input,pricing_input from productpricinginputs where 
288
date(created)=date(now() - interval 1 day) and product_input not like '';
288
date(created)=date(now() - interval 1 day) and product_input not like '';
289
"""
289
"""
290
 
290
 
-
 
291
ACCS_TAB_QUERY="""
-
 
292
select call_disposition,count(1) from 
-
 
293
(select * from (select * from callhistorycrm where date(created)=date(now() - interval 1 day) 
-
 
294
and project_id=2 order by created desc) 
-
 
295
as a group by user_id) 
-
 
296
a1 group by date(created), call_disposition;
-
 
297
"""
-
 
298
 
-
 
299
ACCS_TAB_AGENTS_CALLED_COUNT="""
-
 
300
select distinct(agent_id) from callhistorycrm where project_id=2 and date(created) = date(now() - interval 1 day)
-
 
301
"""
-
 
302
 
-
 
303
ACCS_TAB_QUERY_LOGIN_TIME="""
-
 
304
select agent_id,TIMEDIFF(logoutTime,loginTime) from agentlogintimings where role='accs_active' and date(created)=date(now() - interval 1 day);
-
 
305
"""
-
 
306
 
-
 
307
ACCS_TAB_DISPOSITION_DESCRIPTION="""
-
 
308
select user_id,call_disposition,disposition_description,disposition_comments 
-
 
309
from callhistorycrm where call_disposition not in ('ringing_no_answer','not_reachable','switch_off','call_later') 
-
 
310
and date(created)=date(now() - interval 1 day) and project_id=2"""
-
 
311
 
-
 
312
ACCS_TAB_PRODUCT_PRICING="""
-
 
313
select user_id,call_disposition,product_input,pricing_input from productpricinginputs where 
-
 
314
date(created)=date(now() - interval 1 day) and product_input not like '' and project_id=2;
-
 
315
"""
-
 
316
 
291
def getDbConnection():
317
def getDbConnection():
292
    return MySQLdb.connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
318
    return MySQLdb.connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
293
 
319
 
294
def generateAccessoriesCartReport():
320
def generateAccessoriesCartReport():
295
    datesql=ACCS_CART_QUERY 
321
    datesql=ACCS_CART_QUERY 
Line 433... Line 459...
433
            worksheet.write(row,column,data)
459
            worksheet.write(row,column,data)
434
            column+=1
460
            column+=1
435
        
461
        
436
    newWorkbook.save(RET_FILE)
462
    newWorkbook.save(RET_FILE)
437
    
463
    
-
 
464
def generateAccessoriesTabsReport():
-
 
465
    datesql=ACCS_TAB_QUERY 
-
 
466
    conn = getDbConnection()
-
 
467
    
-
 
468
    cursor = conn.cursor()
-
 
469
    cursor.execute(datesql)
-
 
470
    result = cursor.fetchall()
-
 
471
    rb = open_workbook(RET_FILE,formatting_info=True)
-
 
472
    newWorkbook = copy(rb)
-
 
473
    
-
 
474
    worksheet = newWorkbook.add_sheet("Accessories Tab")
-
 
475
    boldStyle = xlwt.XFStyle()
-
 
476
    newStyle= xlwt.XFStyle()
-
 
477
    style = xlwt.XFStyle()
-
 
478
    pattern = xlwt.Pattern()
-
 
479
    pattern.pattern = xlwt.Pattern.SOLID_PATTERN
-
 
480
    pattern.pattern_fore_colour = xlwt.Style.colour_map['yellow']
-
 
481
    style.pattern = pattern
-
 
482
    f = xlwt.Font()
-
 
483
    f.bold = True
-
 
484
    boldStyle.font = f
-
 
485
    
-
 
486
    column = 0
-
 
487
    row = 0
-
 
488
    currentList=[]
-
 
489
    
-
 
490
    worksheet.write(0,0,'Call Disposition Type',style)
-
 
491
    worksheet.write(0,1,'Count',style)
-
 
492
    worksheet.write(1, column, 'Call Later', newStyle)
-
 
493
    worksheet.write(2,column, 'Ringing No Answer', newStyle)
-
 
494
    worksheet.write(3,column, 'Not Reachable', newStyle)
-
 
495
    worksheet.write(4,column, 'Switched Off', newStyle)
-
 
496
    worksheet.write(5,column, 'Technical Issue', newStyle)
-
 
497
    worksheet.write(6,column, 'Pricing Issue', newStyle)
-
 
498
    worksheet.write(7,column, 'Shipping Issue', newStyle)
-
 
499
    worksheet.write(8,column, 'Internet Issue', newStyle)
-
 
500
    worksheet.write(9,column, 'Checking Price', newStyle)   
-
 
501
    worksheet.write(10,column, 'Order Process', newStyle)
-
 
502
    worksheet.write(11,column, 'Placed Order', newStyle)
-
 
503
    worksheet.write(12,column, 'Will Place Order', boldStyle)
-
 
504
    worksheet.write(13,column, 'Contactable Data (%)', newStyle)
-
 
505
    worksheet.write(14,column, 'Non Contactable Data (%)', newStyle)
-
 
506
    worksheet.write(15,column, 'Agents Logged In', style)
-
 
507
    worksheet.write(16,column, 'Average Login Time (In Hrs)', style)
-
 
508
    worksheet.write(17,column, 'Total Dialed Out', style)
-
 
509
    worksheet.write(18,column, 'Average Dialed Out per agent', style)
-
 
510
 
-
 
511
    contactableData=0
-
 
512
    nonContactableData=0
-
 
513
    global ACCS_TAB_WILL_PLACE_ORDER
-
 
514
    for r in result:
-
 
515
        row = accsDispositionMap.get(r[0])
-
 
516
        if accsDispositionMap.get(r[0]) == 2 or accsDispositionMap.get(r[0]) == 3 or accsDispositionMap.get(r[0]) == 4:
-
 
517
            nonContactableData+=int(r[1])
-
 
518
        else:
-
 
519
            if accsDispositionMap.get(r[0])==12:
-
 
520
                ACCS_TAB_WILL_PLACE_ORDER = r[1]
-
 
521
            contactableData+=r[1] 
-
 
522
        currentList.append(str(row))
-
 
523
        column = 1
-
 
524
        worksheet.write(row, column, r[1],center_alignment)
-
 
525
        
-
 
526
    remainingList = list(set(accsList) - set(currentList))
-
 
527
    for i,val in enumerate(remainingList):
-
 
528
        row = int(val)
-
 
529
        column = 1
-
 
530
        worksheet.write(row, column, 0,center_alignment)
-
 
531
    totalDispositions=contactableData+nonContactableData
-
 
532
    global ACCS_TAB_TOTAL
-
 
533
    global ACCS_TAB_SUCCESSFUL
-
 
534
    ACCS_TAB_TOTAL = totalDispositions
-
 
535
    ACCS_TAB_SUCCESSFUL=contactableData
-
 
536
    if totalDispositions > 0:
-
 
537
        worksheet.write(13,1,round((contactableData/float(totalDispositions))*100,2),center_alignment)
-
 
538
        worksheet.write(14,1,round((nonContactableData/float(totalDispositions))*100,2),center_alignment)
-
 
539
    
-
 
540
    conn.close()
-
 
541
    
-
 
542
    datesql=ACCS_TAB_AGENTS_CALLED_COUNT 
-
 
543
    conn = getDbConnection()
-
 
544
    cursor = conn.cursor()
-
 
545
    cursor.execute(datesql)
-
 
546
    result = cursor.fetchall()
-
 
547
    agentLoginList=[]
-
 
548
    for r in result:
-
 
549
        agentLoginList.append(str(r[0]))
-
 
550
    conn.close()
-
 
551
    global ACCS_TAB_LOGIN
-
 
552
    ACCS_TAB_LOGIN = len(list(set(agentLoginList)))
-
 
553
    if len(list(set(agentLoginList))) > 0:    
-
 
554
        datesql=ACCS_TAB_QUERY_LOGIN_TIME
-
 
555
        conn = getDbConnection()
-
 
556
        cursor = conn.cursor()
-
 
557
        cursor.execute(datesql)
-
 
558
        result = cursor.fetchall()
-
 
559
        loginTime=0
-
 
560
        for r in result:
-
 
561
            loginTime+=r[1].seconds
-
 
562
        averageLoginTime=loginTime/len(list(set(agentLoginList)))
-
 
563
        hours=averageLoginTime/3600
-
 
564
        minutesLeft=(averageLoginTime%3600)/60
-
 
565
        worksheet.write(15,1,len(list(set(agentLoginList))),center_alignment)
-
 
566
        worksheet.write(16,1,str(hours) + ':'+ str(minutesLeft),center_alignment)   
-
 
567
        worksheet.write(17,1,totalDispositions,center_alignment)
-
 
568
        worksheet.write(18,1,totalDispositions/float(len(list(set(agentLoginList)))),center_alignment)
-
 
569
        conn.close()
-
 
570
    
-
 
571
    
-
 
572
    worksheet.write(0,5, 'User Id', style)
-
 
573
    worksheet.write(0,6, 'Call Disposition', style)
-
 
574
    worksheet.write(0,7, 'Disposition Description', style)
-
 
575
    worksheet.write(0,8, 'Disposition Comments', style)    
-
 
576
    datesql = ACCS_TAB_DISPOSITION_DESCRIPTION
-
 
577
    conn = getDbConnection()
-
 
578
    cursor = conn.cursor()
-
 
579
    cursor.execute(datesql)
-
 
580
    result = cursor.fetchall()
-
 
581
    row=0
-
 
582
    for r in result:
-
 
583
        row=row+1
-
 
584
        column =5
-
 
585
        for data in r:
-
 
586
            worksheet.write(row,column,data)
-
 
587
            column+=1
-
 
588
    conn.close()
-
 
589
    
-
 
590
    worksheet.write(20,0, 'User Id', style)
-
 
591
    worksheet.write(20,1, 'Call Disposition', style)
-
 
592
    worksheet.write(20,2, 'Product Inputs', style)
-
 
593
    worksheet.write(20,3, 'Pricing Inputs', style)    
-
 
594
    datesql = ACCS_TAB_PRODUCT_PRICING
-
 
595
    conn = getDbConnection()
-
 
596
    cursor = conn.cursor()
-
 
597
    cursor.execute(datesql)
-
 
598
    result = cursor.fetchall()
-
 
599
    row=20
-
 
600
    for r in result:
-
 
601
        row=row+1
-
 
602
        column =0
-
 
603
        for data in r:
-
 
604
            worksheet.write(row,column,data)
-
 
605
            column+=1
-
 
606
        
-
 
607
    newWorkbook.save(RET_FILE)
-
 
608
    
438
def generateFreshCallingReport():
609
def generateFreshCallingReport():
439
    datesql=FRESH_QUERY 
610
    datesql=FRESH_QUERY 
440
    conn = getDbConnection()
611
    conn = getDbConnection()
441
    
612
    
442
    cursor = conn.cursor()
613
    cursor = conn.cursor()
Line 1414... Line 1585...
1414
        generateAgentWiseOnboardingCallingReport()
1585
        generateAgentWiseOnboardingCallingReport()
1415
        #sendmail(["manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
1586
        #sendmail(["manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
1416
        sendmail(["amit.sirohi@shop2020.in","rajneesh.arora@saholic.com","ritesh.chauhan@shop2020.in", "shailesh.kumar@shop2020.in","utkarsh@coreoutsourcingservices.com","gupta.varun@coreoutsourcingservices.com","manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
1587
        sendmail(["amit.sirohi@shop2020.in","rajneesh.arora@saholic.com","ritesh.chauhan@shop2020.in", "shailesh.kumar@shop2020.in","utkarsh@coreoutsourcingservices.com","gupta.varun@coreoutsourcingservices.com","manas.kapoor@shop2020.in"], "", TMP_FILE, SUBJECT)
1417
    if options.reporttype == 'retention':
1588
    if options.reporttype == 'retention':
1418
        generateAccessoriesCartReport()
1589
        generateAccessoriesCartReport()
-
 
1590
        generateAccessoriesTabsReport()
1419
        #sendmailretention(["manas.kapoor@shop2020.in"], "", RET_FILE, RET_SUBJECT)
1591
        #sendmailretention(["manas.kapoor@shop2020.in"], "", RET_FILE, RET_SUBJECT)
1420
        sendmailretention(["amit.sirohi@shop2020.in","rajneesh.arora@saholic.com", "shailesh.kumar@shop2020.in","chaitnaya.vats@shop2020.in","manas.kapoor@shop2020.in"], "", RET_FILE, RET_SUBJECT)
1592
        sendmailretention(["amit.sirohi@shop2020.in","rajneesh.arora@saholic.com", "shailesh.kumar@shop2020.in","chaitnaya.vats@shop2020.in","manas.kapoor@shop2020.in"], "", RET_FILE, RET_SUBJECT)
1421
         
1593
         
1422
def sendmail(email, message, fileName, title):
1594
def sendmail(email, message, fileName, title):
1423
    if email == "":
1595
    if email == "":
Line 1465... Line 1637...
1465
    message2="Total Successful calls " + str(ACCS_CART_SUCCESSFUL)
1637
    message2="Total Successful calls " + str(ACCS_CART_SUCCESSFUL)
1466
    message3="Will Order "+ str(ACCS_CART_WILL_PLACE_ORDER)
1638
    message3="Will Order "+ str(ACCS_CART_WILL_PLACE_ORDER)
1467
    message4="Will Order % " +str(round((ACCS_CART_WILL_PLACE_ORDER/float(ACCS_CART_TOTAL))*100,2)) 
1639
    message4="Will Order % " +str(round((ACCS_CART_WILL_PLACE_ORDER/float(ACCS_CART_TOTAL))*100,2)) 
1468
    return "<u>" + heading + "</u><br>" +message+"<br>"+message1+"<br>"+message2+"<br>"+message3+"<br>"+message4+"<br>"
1640
    return "<u>" + heading + "</u><br>" +message+"<br>"+message1+"<br>"+message2+"<br>"+message3+"<br>"+message4+"<br>"
1469
 
1641
 
-
 
1642
def getAccsTabHtml():
-
 
1643
    heading = "Accessories Active Users(Project 2)"
-
 
1644
    message="No. of Agents " + str(ACCS_TAB_LOGIN)
-
 
1645
    message1="Total Calls attempted " + str(ACCS_TAB_TOTAL)
-
 
1646
    message2="Total Successful calls " + str(ACCS_TAB_SUCCESSFUL)
-
 
1647
    message3="Will Order "+ str(ACCS_TAB_WILL_PLACE_ORDER)
-
 
1648
    message4="Will Order % " +str(round((ACCS_TAB_WILL_PLACE_ORDER/float(ACCS_TAB_TOTAL))*100,2)) 
-
 
1649
    return "<br><br><u>" + heading + "</u><br>" +message+"<br>"+message1+"<br>"+message2+"<br>"+message3+"<br>"+message4+"<br>"
-
 
1650
 
1470
def getAccsCartOrders():
1651
def getAccsCartOrders():
1471
    datesql = "select  date(now() - interval 1 day), count(distinct user_id),count(distinct order_id), sum(quantity),sum(amount_paid) from allorder where store_id='spice' and category='Accs' and date(created_on)=date(now() - interval 1 day) and user_id in (select user_id from usercrmcallingdata where project_id=1 and date(created)>=date(now()- interval 7 day));"
1652
    datesql = "select  date(now() - interval 1 day), count(distinct user_id),count(distinct order_id), sum(quantity),sum(amount_paid) from allorder where store_id='spice' and category='Accs' and date(created_on)=date(now() - interval 1 day) and user_id in (select user_id from usercrmcallingdata where project_id=1 and date(created)>=date(now()- interval 7 day));"
1472
    conn = getDbConnection()
1653
    conn = getDbConnection()
1473
    cursor = conn.cursor()
1654
    cursor = conn.cursor()
1474
    cursor.execute(datesql)
1655
    cursor.execute(datesql)
1475
    result = cursor.fetchall()
1656
    result = cursor.fetchall()
1476
    inputs = "No of users who placed orders on Date " + str(result[0][0]) + "<br> Number of Users " + str(result[0][1])+ " <br> Total Orders " + str(result[0][2]) + "<br>Total Quantity " + str(result[0][3]) + "<br>Total Value " + str(result[0][4]) + "<br>"  
1657
    inputs = "No of users who placed orders on Date " + str(result[0][0]) + "<br> Number of Users " + str(result[0][1])+ " <br> Total Orders " + str(result[0][2]) + "<br>Total Quantity " + str(result[0][3]) + "<br>Total Value " + str(result[0][4]) + "<br>"  
1477
    conn.close()        
1658
    conn.close()        
1478
    return inputs
1659
    return inputs
1479
 
1660
 
-
 
1661
def getAccsTabOrders():
-
 
1662
    datesql = "select  date(now() - interval 1 day), count(distinct user_id),count(distinct order_id), sum(quantity),sum(amount_paid) from allorder where store_id='spice' and category='Accs' and date(created_on)=date(now() - interval 1 day) and user_id in (select user_id from usercrmcallingdata where project_id=2 and date(created)>=date(now()- interval 7 day));"
-
 
1663
    conn = getDbConnection()
-
 
1664
    cursor = conn.cursor()
-
 
1665
    cursor.execute(datesql)
-
 
1666
    result = cursor.fetchall()
-
 
1667
    inputs = "No of users who placed orders on Date " + str(result[0][0]) + "<br> Number of Users " + str(result[0][1])+ " <br> Total Orders " + str(result[0][2]) + "<br>Total Quantity " + str(result[0][3]) + "<br>Total Value " + str(result[0][4]) + "<br>"  
-
 
1668
    conn.close()        
-
 
1669
    return inputs
-
 
1670
 
1480
def getAccsCartProductPricingInput():
1671
def getAccsCartProductPricingInput():
1481
    datesql = "select product_input,pricing_input from productpricinginputs where date(created)=date(now() - interval 1 day) and project_id=1 and product_input not like '';"
1672
    datesql = "select product_input,pricing_input from productpricinginputs where date(created)=date(now() - interval 1 day) and project_id=1 and product_input not like '';"
1482
    conn = getDbConnection()
1673
    conn = getDbConnection()
1483
    cursor = conn.cursor()
1674
    cursor = conn.cursor()
1484
    cursor.execute(datesql)
1675
    cursor.execute(datesql)
Line 1486... Line 1677...
1486
    inputs="Product Pricing Inputs"
1677
    inputs="Product Pricing Inputs"
1487
    for r in result:
1678
    for r in result:
1488
        inputs = inputs + "<br>" + r[0] + "-----" + str(r[1])
1679
        inputs = inputs + "<br>" + r[0] + "-----" + str(r[1])
1489
    conn.close()        
1680
    conn.close()        
1490
    return inputs
1681
    return inputs
-
 
1682
 
-
 
1683
def getAccsTabProductPricingInput():
-
 
1684
    datesql = "select product_input,pricing_input from productpricinginputs where date(created)=date(now() - interval 1 day) and project_id=2 and product_input not like '';"
-
 
1685
    conn = getDbConnection()
-
 
1686
    cursor = conn.cursor()
-
 
1687
    cursor.execute(datesql)
-
 
1688
    result = cursor.fetchall()
-
 
1689
    inputs="Product Pricing Inputs"
-
 
1690
    for r in result:
-
 
1691
        inputs = inputs + "<br>" + r[0] + "-----" + str(r[1])
-
 
1692
    conn.close()        
-
 
1693
    return inputs
-
 
1694
 
1491
        
1695
        
1492
def sendmailretention(email, message, fileName, title):
1696
def sendmailretention(email, message, fileName, title):
1493
    if email == "":
1697
    if email == "":
1494
        return
1698
        return
1495
    mailServer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
1699
    mailServer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
Line 1504... Line 1708...
1504
    
1708
    
1505
    msg.attach(MIMEText(getAccsCartHtml(), 'html'))
1709
    msg.attach(MIMEText(getAccsCartHtml(), 'html'))
1506
    msg.attach(MIMEText(getAccsCartOrders(),'html'))
1710
    msg.attach(MIMEText(getAccsCartOrders(),'html'))
1507
    msg.attach(MIMEText(getAccsCartProductPricingInput(),'html'))
1711
    msg.attach(MIMEText(getAccsCartProductPricingInput(),'html'))
1508
    
1712
    
-
 
1713
    msg.attach(MIMEText(getAccsTabHtml(), 'html'))
-
 
1714
    msg.attach(MIMEText(getAccsTabOrders(),'html'))
-
 
1715
    msg.attach(MIMEText(getAccsTabProductPricingInput(),'html'))
-
 
1716
    
-
 
1717
    
1509
    fileMsg = MIMEBase('application', 'vnd.ms-excel')
1718
    fileMsg = MIMEBase('application', 'vnd.ms-excel')
1510
    fileMsg.set_payload(file(RET_FILE).read())
1719
    fileMsg.set_payload(file(RET_FILE).read())
1511
    encoders.encode_base64(fileMsg)
1720
    encoders.encode_base64(fileMsg)
1512
    fileMsg.add_header('Content-Disposition', 'attachment;filename=' + fileName)
1721
    fileMsg.add_header('Content-Disposition', 'attachment;filename=' + fileName)
1513
    msg.attach(fileMsg)
1722
    msg.attach(fileMsg)