Пример #1
0
def get_sms(request):
    get_data = request.GET
    # print(get_data)
    # todo have to change the parameters of get data
    # sender_phone = get_data['From']
    # if sender_phone[0] == '+':
    #     sender_phone = sender_phone[1:]
    #     print(sender_phone)
    sms_body = get_data['Body']
    sms_body_into_array = sms_body.split(' ')
    sender_phone = sms_body_into_array[0]
    print(sender_phone)
    if len(sms_body_into_array) > 3:
        if sender_phone[0] == '+':
            sender_phone = sender_phone[1:]
            print(sender_phone)

        other_party_phone = sms_body_into_array[1]
        print(other_party_phone)
        if other_party_phone[0] == '+':
            other_party_phone = other_party_phone[1:]
            print(other_party_phone)
        amount = 0
        if is_number(sms_body_into_array[2]):
            amount = int(sms_body_into_array[2])
        elif is_float((sms_body_into_array[2])):
            amount = float(sms_body_into_array[2])
        if not Consumer.objects.filter(phone__endswith=sender_phone).exists():
            amount = 0
        if not Consumer.objects.filter(phone__endswith=other_party_phone).exists():
            amount = 0
        if amount > 0:
            if Consumer.objects.filter(phone__endswith=sender_phone).exists():
                sender_object = Consumer.objects.get(phone__endswith=sender_phone)
                if Consumer.objects.filter(phone__endswith=other_party_phone).exists():
                    other_party_object = Consumer.objects.get(phone__endswith=other_party_phone)
                else:
                    if Consumer.objects.filter(name='Unknown ' + sender_object.name).exists():
                        other_party_object = Consumer.objects.get(phone__endswith=other_party_phone)
                    else:
                        subscriber_type = ConsumerType.objects.get(type_name__exact='Buyer')
                        other_party_object = Consumer(name=('Unknown ' + sender_object.name),
                                                      type=subscriber_type,
                                                      phone='',
                                                      gender='None')
                        other_party_object.save()
                if sender_object.type.type_name == 'Buyer':
                    buyer_object = sender_object
                    seller_object = other_party_object
                else:
                    if other_party_object.type.type_name == 'Buyer':
                        buyer_object = other_party_object
                        seller_object = sender_object
                    else:
                        buyer_object = sender_object
                        seller_object = other_party_object
                if BuyerSellerAccount.objects.filter(seller=seller_object, buyer=buyer_object).exists():
                    balance = BuyerSellerAccount.objects.get(seller=seller_object, buyer=buyer_object)
                    # previousDue = balance.total_due
                    balance.total_paid += amount
                    remain_due = balance.total_due - amount
                    balance.total_due = remain_due
                    balance.last_paid_amount = amount
                    balance.save()
                else:
                    remain_due = 0
                    # previousDue = 0
                    balance = BuyerSellerAccount(seller=seller_object,
                                                 buyer=buyer_object,
                                                 total_amount_of_transaction=0,
                                                 total_paid=amount,
                                                 total_due=0,
                                                 last_paid_amount=amount)
                    balance.save()
                new_sms_payment = SMSPayment(buyer=buyer_object,
                                             seller=seller_object,
                                             amount=amount)
                new_sms_payment.save()

                transaction = dueTransaction(seller=seller_object,
                                             buyer=buyer_object,
                                             total_amount=0,
                                             total_paid=amount,
                                             total_due=0)
                transaction.save()
                sms_text = 'You have received taka %s from %s. The remaining due amount is taka %s. Thanks for shopping with Hishab Limited.' %(format(amount,'.2f'), buyer_object.name, format(remain_due, '.2f'))
                send_sms(sms_text, seller_object.phone)
                sms_text = 'You have paid taka %s due to %s. The remaining due amount is taka %s. Thanks for shopping with Hishab Limited.' %(format(amount,'.2f'), seller_object.name, format(remain_due, '.2f'))
                send_sms(sms_text, buyer_object.phone)
            return HttpResponse('got_it', content_type="plain/text")
        else:
            sender_object = Consumer.objects.get(phone__endswith=sender_phone)
            sms_text = 'You have entered wrong input. Please try again with correct information. Thanks for shopping with Hishab Limited.'
            send_sms(sms_text, sender_object.phone)
Пример #2
0
def add_subscriber(request):
    post_data = request.POST
    print(post_data)
    if 'csrfmiddlewaretoken' in post_data:
        name = post_data['name']
        phone = post_data['phone']
        add_notification = True
        if is_bangladeshi_number(phone) or is_japanese_number(phone):
            if Consumer.objects.filter(name__exact=name).exists():
                notification = 'This name ' + name + ' is already taken'
            else:
                if Consumer.objects.filter(phone__exact=phone).exists():
                    notification = 'This number ' + phone + ' is already taken'
                else:
                    child = 0
                    if 'child' in post_data:

                        child = post_data['child']
                    gender = 'None'
                    if 'gender' in post_data:
                        if not post_data['gender'] == 'Not Defined':
                            gender = post_data['gender']
                    age = 0
                    if 'age' in post_data:
                        if is_number(post_data['age']):
                            age = int(post_data['age'])
                        if is_float(post_data['age']):
                            age = float(post_data['age'])
                    married = False
                    if 'married' in post_data:
                        if post_data['married'] == 'Married':
                            married = True
                    address = ''
                    if 'address' in post_data:
                        address = post_data['address']
                    subscriber_type = ConsumerType.objects.get(type_name__exact='SR')
                    if 'type' in post_data:
                        subscriber_type = ConsumerType.objects.get(type_name__exact=post_data['type'])

                    email = ''
                    if 'email' in post_data:
                        email = post_data['email']

                    new_consumer = Consumer(name=name,
                                            type=subscriber_type,
                                            phone=phone,
                                            address=address,
                                            email=email,
                                            number_of_child=child,
                                            gender=gender,
                                            age=age,
                                            married=married)
                    new_consumer.save()
                    print(phone[-9:])
                    print(post_data['child'])
                    user = User.objects.create_user(phone[-9:], phone[-9:]+'@sense.ai',
                                                    post_data['child'])
                    user.save()
                    transcriber_name = request.session['user']
                    if ACL.objects.filter(loginID=transcriber_name).exists():
                        login_user = ACL.objects.get(loginID=transcriber_name)
                        if login_user.loginUser.type.type_name == 'Distributor':
                            add_new_subscriber = ACL(loginUser=new_consumer,
                                                     distUser=login_user.loginUser,
                                                     loginID=phone[-9:])
                            add_new_subscriber.save()
                    else:
                        add_new_subscriber = ACL(loginUser=new_consumer,
                                                 loginID=phone[-9:])
                        add_new_subscriber.save()
                    notification = 'Transcriber Successfully Added.'
                    # add_to_transcriber = Transcriber(name=post_data['username'])
                    # add_to_transcriber.save()
                    welcome_sms = 'Thanks for connecting with hishab Limited. Use %s as username and %s as password while logging in to app.hishab.co . For more info go to www.hishab.co .' % (phone, child)
                    send_sms(welcome_sms, phone)
                    notification = 'New User ' + name + ' was added successfully'
        else:
            notification = 'Invalid Phone Number : ' + phone
    else:
        add_notification = False
        notification = ''
    all_subscriber = Consumer.objects.all()
    type_of_subscriber = ConsumerType.objects.all()
    transcriber_name = request.session['user']
    shop_consumer = ConsumerType.objects.get(type_name='Seller')
    all_shop_for_base = Consumer.objects.filter(type=shop_consumer)
    all_user_for_base = Consumer.objects.all()
    shop_consumer2 = ConsumerType.objects.get(type_name='Buyer')
    all_consumer_for_base = Consumer.objects.filter(type=shop_consumer2)
    res = render(request, 'pages/add_subscriber.html', {'subscribers': all_subscriber, 'types': type_of_subscriber,
                                                        'notification': notification,
                                                        'shop_list_base': all_shop_for_base,
                                                        'all_consumer_for_base' :all_consumer_for_base,
                                                        'all_user_for_base': all_user_for_base,
                                                        'transcriber_name': transcriber_name,
                                                        'add_notification': add_notification})

    res['Access-Control-Allow-Origin'] = "*"
    res['Access-Control-Allow-Headers'] = "Origin, X-Requested-With, Content-Type, Accept"
    res['Access-Control-Allow-Methods'] = "PUT, GET, POST, DELETE, OPTIONS"

    return res
Пример #3
0
def add_product_outside(request):
    post_data = request.POST
    print(post_data)
    add_notification = True
    name = post_data['name'].capitalize()
    if Product.objects.filter(name=name).exists():
        notification = 'Product ' + name + ' is already in the List'
        res = HttpResponse(notification)
    else:
        if 'retail_unit' in post_data:
            notification = 'Product ' + name + ' was added successfully'
            retail_unit = post_data['retail_unit'].upper()
            if 'altr_name' in post_data:
                altr_name = post_data['altr_name']
            else:
                altr_name = ''
            if 'bangla_name' in post_data:
                bangla_name = post_data['bangla_name']
            else:
                bangla_name = ''
            if 'bulk_unit' in post_data:
                bulk_unit = post_data['bulk_unit'].upper()
            else:
                bulk_unit = post_data['bulk_unit'].upper()
            if 'bulk_price' in post_data:
                if is_float(post_data['retail_price']) or is_number(post_data['retail_price']):
                    bulk_price = post_data['bulk_price']
                else:
                    bulk_price = 0
            else:
                bulk_price = 0
            if 'converter' in post_data:
                if is_float(post_data['converter']) or is_number(post_data['converter']):
                    converter = post_data['converter']
                else:
                    converter = 1
            else:
                converter = 1
            if 'retail_price' in post_data:
                if is_float(post_data['retail_price']) or is_number(post_data['retail_price']):
                    retail_price = post_data['retail_price']
                else:
                    retail_price = 0
            else:
                retail_price = 0
            add_notification = True
            new_product = Product(name=name,
                                  alternative_name=altr_name,
                                  bangle_name=bangla_name,
                                  retail_unit=retail_unit,
                                  bulk_wholesale_unit=bulk_unit,
                                  price_per_retail_unit=retail_price,
                                  price_per_bulk_wholesale_unit=bulk_price,
                                  bulk_to_retail_unit=converter)
            new_product.save()
            res = HttpResponse('ok')
        else:
            res = HttpResponse('not_ok')

    res['Access-Control-Allow-Origin'] = "*"
    res['Access-Control-Allow-Headers'] = "Origin, X-Requested-With, Content-Type, Accept"
    res['Access-Control-Allow-Methods'] = "PUT, GET, POST, DELETE, OPTIONS"
    return res
Пример #4
0
def add_subscriber_outside(request):
    print('here')
    post_data = request.POST
    print(post_data)
    name = post_data['name']
    phone = post_data['phone']
    if phone[0] == ' ':
        phone = phone[1:]
    # # todo error handeling in jS with error text

    add_notification = True

    if Consumer.objects.filter(name__exact=name).exists():
        notification = 'This name ' + name + ' is already taken'
        res = HttpResponse('error')
    else:
        if Consumer.objects.filter(phone__exact=phone).exists():
            notification = 'This number ' + phone + ' is already taken'
            res = HttpResponse('error')
        else:
            child = 0
            if 'child' in post_data:
               child = post_data['child']
            gender = 'None'
            if 'gender' in post_data:
                if not post_data['gender'] == 'Not Defined':
                    gender = post_data['gender']
            age = 0
            if 'age' in post_data:
                if is_number(post_data['age']):
                    age = int(post_data['age'])
                if is_float(post_data['age']):
                    age = float(post_data['age'])
            married = False
            if 'married' in post_data:
                if post_data['married'] == 'Married':
                    married = True
            address = ''
            if 'address' in post_data:
                address = post_data['address']
            subscriber_type = ConsumerType.objects.get(type_name__exact='Buyer')
            if 'type' in post_data:
                subscriber_type = ConsumerType.objects.get(type_name__exact=post_data['type'])
            email = ''
            if 'email' in post_data:
                email = post_data['email']

            new_consumer = Consumer(name=name,
                                    type=subscriber_type,
                                    phone=phone,
                                    address=address,
                                    email=email,
                                    number_of_child=child,
                                    gender=gender,
                                    age=age,
                                    married=married)
            new_consumer.save()
            print(phone[-9:])
            print(post_data['child'])
            user = User.objects.create_user(phone[-9:], phone[-9:]+'@sense.ai',
                                            post_data['child'])
            user.save()
            add_new_subscriber = ACL(loginUser=new_consumer,
                                     loginID=phone[-9:])
            add_new_subscriber.save()
            welcome_sms = 'Thanks for connecting with hishab Limited. Use %s as username and %s as password while logging in to app.hishab.co . For more info go to www.hishab.co .' % (phone, child)
            if 'record_id' in post_data:
                if not post_data['record_id'] == '':
                    call_record = VoiceReg.objects.get(pk=post_data['record_id'])
                    call_record.completed = True
                    call_record.save()
            if 'introduced_by' in post_data:
                if not post_data['introduced_by'] == '':
                    introduced_by = post_data['introduced_by']
                    introduced_by_object = Consumer.objects.get(pk=int(introduced_by))
                    new_dependency = Connectivity(user=new_consumer, introduced_by=introduced_by_object)
                    new_dependency.save()
            notification = 'New User ' + name + ' was added successfully'
            # welcome_sms = 'Thanks for connecting with Hishab Limited. For more info go to www.hishab.co .'
            send_sms(welcome_sms, phone)
            res = HttpResponse(new_consumer.id)



    all_subscriber = Consumer.objects.all()
    type_of_subscriber = ConsumerType.objects.all()
    shop_consumer = ConsumerType.objects.get(type_name='Seller')
    all_shop_for_base = Consumer.objects.filter(type=shop_consumer)
    all_user_for_base = Consumer.objects.all()

    res['Access-Control-Allow-Origin'] = "*"
    res['Access-Control-Allow-Headers'] = "Origin, X-Requested-With, Content-Type, Accept"
    res['Access-Control-Allow-Methods'] = "PUT, GET, POST, DELETE, OPTIONS"
    return res
Пример #5
0
def add_product(request):
    post_data = request.POST
    print(post_data)
    if 'csrfmiddlewaretoken' in post_data:
        add_notification = True
        name = post_data['name'].capitalize()
        if Product.objects.filter(name=name).exists():
            notification = 'Product ' + name + ' is already in the List'
        else:
            if 'retail_unit' in post_data:
                notification = 'Product ' + name + ' was added successfully'
                retail_unit = post_data['retail_unit'].upper()
                if 'altr_name' in post_data:
                    altr_name = post_data['altr_name']
                else:
                    altr_name = ''
                if 'bangla_name' in post_data:
                    bangla_name = post_data['bangla_name']
                else:
                    bangla_name = ''
                if 'bulk_unit' in post_data:
                    bulk_unit = post_data['bulk_unit'].upper()
                else:
                    bulk_unit = post_data['bulk_unit'].upper()
                if 'bulk_price' in post_data:
                    if is_float(post_data['retail_price']) or is_number(post_data['retail_price']):
                        bulk_price = post_data['bulk_price']
                    else:
                        bulk_price = 0
                else:
                    bulk_price = 0
                if 'converter' in post_data:
                    if is_float(post_data['converter']) or is_number(post_data['converter']):
                        converter = post_data['converter']
                    else:
                        converter = 1
                else:
                    converter = 1
                if 'retail_price' in post_data:
                    if is_float(post_data['retail_price']) or is_number(post_data['retail_price']):
                        retail_price = post_data['retail_price']
                    else:
                        retail_price = 0
                else:
                    retail_price = 0
                add_notification = True
                new_product = Product(name=name,
                                      alternative_name=altr_name,
                                      bangle_name=bangla_name,
                                      retail_unit=retail_unit,
                                      bulk_wholesale_unit=bulk_unit,
                                      price_per_retail_unit=retail_price,
                                      price_per_bulk_wholesale_unit=bulk_price,
                                      bulk_to_retail_unit=converter)
                new_product.save()
            else:
                notification = 'Product Details Not Found!'
    else:
        add_notification = False
        notification = ''
    all_product = Product.objects.all()
    shop_consumer = ConsumerType.objects.get(type_name='Seller')
    all_shop_for_base = Consumer.objects.filter(type=shop_consumer)
    all_user_for_base = Consumer.objects.all()
    shop_consumer2 = ConsumerType.objects.get(type_name='Buyer')
    all_consumer_for_base = Consumer.objects.filter(type=shop_consumer2)

    transcriber_name = request.session['user']
    res = render(request, 'pages/add_product.html', {'all_product': all_product,
                                                     'notification': notification,
                                                     'transcriber_name': transcriber_name,
                                                     'all_consumer_for_base': all_consumer_for_base,
                                                     'add_notification': add_notification,
                                                     'shop_list_base': all_shop_for_base,
                                                     'all_user_for_base': all_user_for_base})

    res['Access-Control-Allow-Origin'] = "*"
    res['Access-Control-Allow-Headers'] = "Origin, X-Requested-With, Content-Type, Accept"
    res['Access-Control-Allow-Methods'] = "PUT, GET, POST, DELETE, OPTIONS"
    return res