Subversion Repositories SmartDukaan

Rev

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

Rev 12944 Rev 12962
Line 687... Line 687...
687
    return diff - (non_business_days + sundays)
687
    return diff - (non_business_days + sundays)
688
            
688
            
689
 
689
 
690
def enqueue_transaction_info_email(transaction_id):
690
def enqueue_transaction_info_email(transaction_id):
691
    transaction = get_transaction(transaction_id)
691
    transaction = get_transaction(transaction_id)
692
    '''
692
    
693
    smsText = "Dear Customer, Thanks for ordering "
693
    smsText = "Dear Customer, Thanks for ordering "
694
    otgSms = False
694
    otgSms = False
695
    mobileNo = None
695
    mobileNo = None
696
    customerId = 0
696
    customerId = 0
697
    '''
697
    
698
    subject = source_name + " - Order Details"
698
    subject = source_name + " - Order Details"
699
    orders = transaction.orders
699
    orders = transaction.orders
700
    advance_amount = orders[0].advanceAmount
700
    advance_amount = orders[0].advanceAmount
701
    saddress = ""
701
    saddress = ""
702
    bcc = []
702
    bcc = []
Line 707... Line 707...
707
    otgLink = ""
707
    otgLink = ""
708
    inOrderOtg = "<div>On Time Guarantee<br><span style=color:red>We pay if we delay</span></div>"
708
    inOrderOtg = "<div>On Time Guarantee<br><span style=color:red>We pay if we delay</span></div>"
709
    if len(transaction.orders) == 1:
709
    if len(transaction.orders) == 1:
710
        inOrderOtg = ""
710
        inOrderOtg = ""
711
        if transaction.orders[0].otg :
711
        if transaction.orders[0].otg :
712
            #otgSms = True
712
            otgSms = True
713
            subject = "Your Order is confirmed with On Time Guarantee We Pay if we Delay"
713
            subject = "Your Order is confirmed with On Time Guarantee We Pay if we Delay"
714
            otgLink = ' Your Order is covered under the <a href="http://www.saholic.com/static/on-time-guarantee">On Time Guarantee, We pay If we Delay.</a>'
714
            otgLink = ' Your Order is covered under the <a href="http://www.saholic.com/static/on-time-guarantee">On Time Guarantee, We pay If we Delay.</a>'
715
    
715
    
716
    customer_name = "" 
716
    customer_name = "" 
717
    html_header = """
717
    html_header = """
Line 749... Line 749...
749
    if orders[0].pickupStoreId:
749
    if orders[0].pickupStoreId:
750
        random_text = str(randrange(100000, 999999)) 
750
        random_text = str(randrange(100000, 999999)) 
751
    
751
    
752
    first = True    
752
    first = True    
753
    for order in orders:
753
    for order in orders:
754
        '''mobileNo = order.customer_mobilenumber
754
        mobileNo = order.customer_mobilenumber
755
        customerId = order.customer_id
755
        customerId = order.customer_id
756
        '''
756
        
757
        customer_name = order.customer_name
757
        customer_name = order.customer_name
758
        order_date = order.created_timestamp
758
        order_date = order.created_timestamp
759
        user_email = order.customer_email
759
        user_email = order.customer_email
760
        if first:
760
        if first:
761
            first = False
761
            first = False
Line 773... Line 773...
773
            attribute.name = "SECRET_CODE"
773
            attribute.name = "SECRET_CODE"
774
            attribute.value = random_text
774
            attribute.value = random_text
775
            session.commit()
775
            session.commit()
776
        
776
        
777
        for lineitem in order.lineitems:
777
        for lineitem in order.lineitems:
778
            #smsText = smsText + lineitem.brand + " " + lineitem.model_name + " " + lineitem.model_number + "("+str(lineitem.quantity)+ ")" +". "
778
            smsText = smsText + lineitem.brand + " " + lineitem.model_name + " " + lineitem.model_number + "("+str(lineitem.quantity)+ ")" +". "
779
            lineitem_total_price = round(lineitem.total_price, 2)
779
            lineitem_total_price = round(lineitem.total_price, 2)
780
            
780
            
781
            html_tr += "<td>" + str(lineitem) + "</td>"
781
            html_tr += "<td>" + str(lineitem) + "</td>"
782
            if order.otg:
782
            if order.otg:
783
                html_tr += "<td align='center'><div>" + store_delivery_date + "</div>" + inOrderOtg + "</td>"
783
                html_tr += "<td align='center'><div>" + store_delivery_date + "</div>" + inOrderOtg + "</td>"
Line 786... Line 786...
786
            html_tr += "<td align='center'>" + ("%.0f" % lineitem.quantity) + "</td>"
786
            html_tr += "<td align='center'>" + ("%.0f" % lineitem.quantity) + "</td>"
787
            html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem.unit_price) + "</td>"
787
            html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem.unit_price) + "</td>"
788
            html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem_total_price) + "</td></tr>"
788
            html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem_total_price) + "</td></tr>"
789
            total_amount += lineitem_total_price
789
            total_amount += lineitem_total_price
790
            html_table += html_tr
790
            html_table += html_tr
791
        #smsText = smsText + "Order Id: "+str(order.id)+" "
791
        smsText = smsText + "Order Id: "+str(order.id)+" "
792
        if order.freebieItemId:
792
        if order.freebieItemId:
793
            catalog_client = CatalogClient().get_client()
793
            catalog_client = CatalogClient().get_client()
794
            item = catalog_client.getItem(order.freebieItemId)
794
            item = catalog_client.getItem(order.freebieItemId)
795
            html_table += "<tr><td align='center'></td><td style='font-style:italic;' colspan='5'> Free Item: "+item.brand + " " + item.modelName + " " + item.modelNumber+"</td></tr>"
795
            html_table += "<tr><td align='center'></td><td style='font-style:italic;' colspan='5'> Free Item: "+item.brand + " " + item.modelName + " " + item.modelNumber+"</td></tr>"
796
        if order.insurer:
796
        if order.insurer:
797
            html_table += "<tr><td colspan=6>&nbsp;</td></tr>"
797
            html_table += "<tr><td colspan=6>&nbsp;</td></tr>"
798
            html_table += "<tr><td align='center'></td><td style='font-style:italic;'>Insured Against Theft for 1 Year. <a href='http://www.saholic.com/static/insurance-terms'>Know More</a></td><td align='center'></td><td align='center'></td><td align='center'></td>"
798
            html_table += "<tr><td align='center'></td><td style='font-style:italic;'>Insured Against Theft for 1 Year. <a href='http://www.saholic.com/static/insurance-terms'>Know More</a></td><td align='center'></td><td align='center'></td><td align='center'></td>"
799
            html_table += "<td align='center'>" + str(order.insuranceAmount) + "</td></tr>"
799
            html_table += "<td align='center'>" + str(order.insuranceAmount) + "</td></tr>"
800
            total_amount += order.insuranceAmount
800
            total_amount += order.insuranceAmount
801
            
801
            
802
    #smsText = smsText + "Saholic.com." 
802
    smsText = smsText + "Saholic.com." 
803
    emi_amount = 0
803
    emi_amount = 0
804
    miscCharges = get_misc_charges(transaction_id)
804
    miscCharges = get_misc_charges(transaction_id)
805
    if miscCharges.get(1):
805
    if miscCharges.get(1):
806
        emi_amount = miscCharges.get(1)
806
        emi_amount = miscCharges.get(1)
807
        
807
        
Line 883... Line 883...
883
    store_delivery_date = sdt.strftime("%A, %d %B %Y")
883
    store_delivery_date = sdt.strftime("%A, %d %B %Y")
884
 
884
 
885
    email_header = Template(html_header).substitute(dict(order_date = formated_order_date, customer_name = customer_name, source_url = source_url, otgLink = otgLink, saddress = saddress))
885
    email_header = Template(html_header).substitute(dict(order_date = formated_order_date, customer_name = customer_name, source_url = source_url, otgLink = otgLink, saddress = saddress))
886
    email_footer = Template(html_footer).substitute(dict(total_amount = "%.2f" % total_amount, emi_amount = "%.2f" % emi_amount, advance_amount = "%.2f" % advance_amount, net_amount = "%.2f" % (total_amount-order.gvAmount), secret_code = random_text, store_address = store_address, store_delivery_date = store_delivery_date, source_url = source_url, source_name = source_name, amount_string = amount_string))
886
    email_footer = Template(html_footer).substitute(dict(total_amount = "%.2f" % total_amount, emi_amount = "%.2f" % emi_amount, advance_amount = "%.2f" % advance_amount, net_amount = "%.2f" % (total_amount-order.gvAmount), secret_code = random_text, store_address = store_address, store_delivery_date = store_delivery_date, source_url = source_url, source_name = source_name, amount_string = amount_string))
887
 
887
 
888
    try:
-
 
889
        helper_client = HelperClient().get_client()
-
 
890
        helper_client.saveUserEmailForSending([user_email], "", subject, email_header + html_table + email_footer, str(transaction_id), "TransactionInfo", [], bcc, orders[0].source)
-
 
891
         
-
 
892
        return True
-
 
893
    except Exception as e:
-
 
894
        print e
-
 
895
        return False
-
 
896
    '''
-
 
897
    if otgSms:
888
    if otgSms:
898
        smsText = smsText +" Order comes under On Time Guarantee We Pay if we Delay. T&C Apply"
889
        smsText = smsText +" Order comes under On Time Guarantee We Pay if we Delay. T&C Apply"
899
    
890
 
900
    try:
891
    try:
901
        helper_client = HelperClient().get_client()
892
        helper_client = HelperClient().get_client()
902
        helper_client.saveUserEmailForSending([user_email], "", subject, email_header + html_table + email_footer, str(transaction_id), "TransactionInfo", [], bcc, orders[0].source)
893
        helper_client.saveUserEmailForSending([user_email], "", subject, email_header + html_table + email_footer, str(transaction_id), "TransactionInfo", [], bcc, orders[0].source)
903
    except Exception as e:
-
 
904
        print e        
-
 
905
        try:
-
 
906
            send_transaction_sms(customerId, mobileNo, smsText, SmsType.TRANSACTIONAL)
-
 
907
            return True
-
 
908
        except Exception as e:
-
 
909
            print e
-
 
910
            print sys.exc_info()[0]
-
 
911
            return False
-
 
912
    
-
 
913
    try:
-
 
914
        send_transaction_sms(customerId, mobileNo, smsText, SmsType.TRANSACTIONAL)
894
        send_transaction_sms(customerId, mobileNo, smsText, SmsType.TRANSACTIONAL)
915
        return True
895
        return True
916
    except Exception as e:
896
    except Exception as e:
917
        print e
897
        print e
918
        print sys.exc_info()[0]
-
 
919
        return True
898
        return False
920
    '''
-
 
921
    
899
    
922
def send_transaction_sms(customerId, mobileNo, smsText, smsType):
900
def send_transaction_sms(customerId, mobileNo, smsText, smsType):
923
    if mobileNo is not None:
901
    if mobileNo is not None:
924
            helper_client = HelperClient().get_client()
902
            helper_client = HelperClient().get_client()
925
            helper_client.saveUserSmsForSending(customerId, mobileNo, smsText, SmsType.TRANSACTIONAL)
903
            helper_client.saveUserSmsForSending(customerId, mobileNo, smsText, SmsType.TRANSACTIONAL)
Line 1196... Line 1174...
1196
    email_footer = Template(html_footer).substitute(dict(total_amount = "%.2f" % total_amount, source_name = source_name, freebie_text = freebie_text))
1174
    email_footer = Template(html_footer).substitute(dict(total_amount = "%.2f" % total_amount, source_name = source_name, freebie_text = freebie_text))
1197
    
1175
    
1198
    try:
1176
    try:
1199
        helper_client = HelperClient(host_key = "helper_service_server_host_prod").get_client()
1177
        helper_client = HelperClient(host_key = "helper_service_server_host_prod").get_client()
1200
        helper_client.saveUserEmailForSending([user_email], "", subject, email_header + html_table + email_footer, str(order.id), "DeliverySuccess", [], [], order.source)
1178
        helper_client.saveUserEmailForSending([user_email], "", subject, email_header + html_table + email_footer, str(order.id), "DeliverySuccess", [], [], order.source)
1201
        '''
1179
        
1202
        if order.source == OrderSource.WEBSITE:
1180
        if order.source == OrderSource.WEBSITE:
1203
            send_transaction_sms(order.customer_id, order.customer_mobilenumber, "Dear Customer, Your order: " + str(order.id) + " has been delivered now. For any queries please call 0120-2479977." , SmsType.TRANSACTIONAL)
1181
            send_transaction_sms(order.customer_id, order.customer_mobilenumber, "Dear Customer, Your order: " + str(order.id) + " has been delivered now. For any queries please call 0120-2479977." , SmsType.TRANSACTIONAL)
1204
        '''
1182
        
1205
        return True
1183
        return True
1206
    except Exception as e:
1184
    except Exception as e:
1207
        print e
1185
        print e
1208
        return False
1186
        return False
1209
 
1187
 
Line 4456... Line 4434...
4456
    helperClient = HelperClient(host_key = "helper_service_server_host_prod").get_client()
4434
    helperClient = HelperClient(host_key = "helper_service_server_host_prod").get_client()
4457
    try:
4435
    try:
4458
        emailSubject = 'Shipping Details for Order ID: ' + str(order.id)
4436
        emailSubject = 'Shipping Details for Order ID: ' + str(order.id)
4459
        emailBody = get_shipping_confirmation_email_body(order)
4437
        emailBody = get_shipping_confirmation_email_body(order)
4460
        helperClient.saveUserEmailForSending([order.customer_email], None, emailSubject, emailBody, str(order.id), 'ShippingConfirmation', [], [], order.source)
4438
        helperClient.saveUserEmailForSending([order.customer_email], None, emailSubject, emailBody, str(order.id), 'ShippingConfirmation', [], [], order.source)
4461
        '''
4439
        
4462
        logistics_providers = {1: {'name': 'BlueDart', 'phone': '011-66111234'}, 6: {'name': 'RedExpress', 'phone': '8373915813'}, 3: {'name': 'Delhivery', 'phone' : '0124- 4212200'}, 7: {'name': 'FedEx', 'phone' : '0120-4354176'}}
4440
        logistics_providers = {1: {'name': 'BlueDart', 'phone': '011-66111234'}, 6: {'name': 'RedExpress', 'phone': '8373915813'}, 3: {'name': 'Delhivery', 'phone' : '0124- 4212200'}, 7: {'name': 'FedEx', 'phone' : '0120-4354176'}}
4463
        provider_name = logistics_providers[order.logistics_provider_id]['name']
4441
        provider_name = logistics_providers[order.logistics_provider_id]['name']
4464
        if order.source == OrderSource.WEBSITE :
4442
        if order.source == OrderSource.WEBSITE :
4465
            send_transaction_sms(order.customer_id, order.customer_mobilenumber, "Dear Customer, We have shipped your order: " + str(order.id) + " through "+provider_name + " AWB No. " + order.airwaybill_no, SmsType.TRANSACTIONAL)
4443
            send_transaction_sms(order.customer_id, order.customer_mobilenumber, "Dear Customer, We have shipped your order: " + str(order.id) + " through "+provider_name + " AWB No. " + order.airwaybill_no, SmsType.TRANSACTIONAL)    
4466
        '''    
-
 
4467
    except Exception as e:
4444
    except Exception as e:
4468
        print e
4445
        print e
4469
    
4446
    
4470
def get_order_distribution_by_status(start_date, end_date):
4447
def get_order_distribution_by_status(start_date, end_date):
4471
    query = session.query(Order.status, func.count(Order.id)).group_by(Order.status)
4448
    query = session.query(Order.status, func.count(Order.id)).group_by(Order.status)