Ejemplo n.º 1
0
def save_rate_details(request, booking):
    booking.loaded_weight = to_float(request.POST.get('loaded_weight'))
    booking.supplier_charged_weight = to_float(
        request.POST.get('supplier_charged_weight'))
    booking.supplier_rate = to_int(request.POST.get('supplier_rate'))
    booking.total_amount_to_owner = to_int(
        request.POST.get('total_amount_to_owner'))
    if EMP_GROUP1 in request.user.groups.values_list(
            'name',
            flat=True) or EMP_GROUP2 in request.user.groups.values_list(
                'name', flat=True):
        booking.charged_weight = to_float(request.POST.get('charged_weight'))
        booking.party_rate = to_int(request.POST.get('party_rate'))
        booking.total_amount_to_company = to_int(
            request.POST.get('total_amount_to_party'))
        booking.refund_amount = to_int(request.POST.get('refundable_amount'))
        booking.additional_charges_for_company = to_int(
            request.POST.get('additional_charges_for_company'))
        booking.deductions_for_company = to_int(
            request.POST.get('deductions_for_company'))
        booking.invoice_remarks_for_deduction_discount = request.POST.get(
            'invoice_remarks_for_deduction_discount')
        booking.advance_amount_from_company = request.POST.get(
            'advance_from_company')
        booking.invoice_remarks_for_additional_charges = request.POST.get(
            'invoice_remarks_for_additional_charges')
        booking.tds_deducted_amount = to_int(
            request.POST.get('tds_deducted_amount'))
    return booking
Ejemplo n.º 2
0
def update_booking_pod_data(request):
    approve_type = request.POST.get('accept_choice')
    if approve_type == 'accept':
        booking = ManualBooking.objects.get(id=request.POST.get('booking_id'))
        booking.supplier_charged_weight = to_float(
            request.POST.get('supplier_weight'))
        booking.charged_weight = to_float(request.POST.get('party_weight'))
        booking.loaded_weight = to_float(request.POST.get('loaded_weight'))
        booking.delivered_weight = to_float(
            request.POST.get('delivered_weight'))
        booking.pod_date = datetime.now()
        booking.delivery_datetime = django_date_format(
            request.POST.get('delivery_datetime'))
        for pod in PODFile.objects.filter(booking=booking).exclude(
                verified=True):
            pod.is_valid = True
            pod.verified = True
            pod.verified_by = request.user
            pod.verified_datetime = datetime.now()
            pod.save()
            S3Upload.objects.filter(id=pod.s3_upload_id).update(is_valid=True,
                                                                verified=True)
        # if verify_pod(booking=booking):
        booking.pod_status = 'completed'
        booking.save()
        return json_success_response(
            msg='POD for booking ID {} is Accepted'.format(booking.booking_id))
    elif approve_type == 'reject':
        booking = ManualBooking.objects.get(id=request.POST.get('booking_id'))
        booking.pod_status = 'rejected'
        booking.save()
        for lr in booking.lr_numbers.all():
            RejectedPOD.objects.create(
                booking=booking,
                lr=lr,
                remarks=request.POST.get('rejection_remark'),
                rejected_by=request.user)
        if not booking.lr_numbers.exists():
            RejectedPOD.objects.create(
                booking=booking,
                remarks=request.POST.get('rejection_remark'),
                rejected_by=request.user)
        for pod in PODFile.objects.filter(booking=booking).exclude(
                verified=True):
            pod.is_valid = False
            pod.verified = True
            pod.verified_by = request.user
            pod.verified_datetime = datetime.now()
            pod.save()
            S3Upload.objects.filter(id=pod.s3_upload_id).update(is_valid=False,
                                                                verified=True)
        return json_success_response(
            msg='POD for booking ID {} is rejected'.format(booking.booking_id))
    return json_error_response(msg='fail', status=404)
Ejemplo n.º 3
0
def save_rate_details(request, booking):
    booking.loaded_weight = to_float(request.POST.get('loaded_weight'))
    booking.supplier_charged_weight = to_float(
        request.POST.get('supplier_charged_weight'))
    if EMP_GROUP1 in request.user.groups.values_list(
            'name',
            flat=True) or EMP_GROUP2 in request.user.groups.values_list(
                'name', flat=True):
        booking.party_rate = to_int(request.POST.get('party_rate'))
        booking.total_amount_to_company = to_int(
            request.POST.get('total_amount_to_party'))
        booking.charged_weight = to_float(request.POST.get('charged_weight'))
    booking.supplier_rate = to_int(request.POST.get('supplier_rate'))
    booking.total_amount_to_owner = to_int(
        request.POST.get('total_amount_to_owner'))
    booking.save()
Ejemplo n.º 4
0
def save_invoice_details(request, booking):
    booking.party_invoice_number = request.POST.get('party_invoice_number')
    booking.party_invoice_date = django_date_format(
        request.POST.get('party_invoice_date'))
    booking.party_invoice_amount = to_float(
        request.POST.get('party_invoice_amount'))
    booking.road_permit_number = request.POST.get('road_permit_number')
    booking.save()
Ejemplo n.º 5
0
def parse_waytracker_data(html_data):
    table = BeautifulSoup(html_data, 'lxml')
    table = table.tbody
    records = []
    for tr in table.findAll("tr"):
        trs = tr.findAll("td")
        gps = ((trs[3].a['onclick'])[14:-7]).split(',')
        records.append({
            "latitude": to_float(gps[0]),
            "longitude": to_float(gps[1]),
            "vehicle_id": compare_format(gps[4].replace("'", "")),
            "sno": gps[3].replace("'", ""),
            "vehicle_no": compare_format(gps[4].replace("'", "")),
            "datetime": datetime.strptime(trs[4].text, '%d %b %Y %H:%M'),
            "engine_on": (trs[5].text).lower() != 'off',
            "fuel": trs[6].text,
            "nearest_site": trs[8].text,
            "nearest_location": trs[9].text,
            "speed": trs[10].text,
            "idle_time": trs[11].text}
        )
    return records
Ejemplo n.º 6
0
def save_insurance_details(request, booking):
    booking.insurance_provider = request.POST.get('insurance_provider')
    booking.insurance_policy_number = request.POST.get(
        'insurance_policy_number')
    booking.insured_amount = to_float(request.POST.get('insurance_amount'))
    booking.insurance_date = django_date_format(
        request.POST.get('insurance_date'))
    is_insured = request.POST.get('insured')
    if is_insured == 'insured':
        booking.is_insured = True
    else:
        booking.is_insured = False
    booking.save()
Ejemplo n.º 7
0
def multiply_numbers(num1, num2):
    return to_float(num1) * to_float(num2)
Ejemplo n.º 8
0
def update_commission_booking(request):
    try:
        booking = ManualBooking.objects.get(
            booking_id=request.POST.get('booking_id'))
    except ManualBooking.DoesNotExist:
        booking = ManualBooking.objects.get(id=request.POST.get('booking_id'))
    # Basic Details
    booking.billing_type = request.POST.get('billing_type')
    booking.number_of_package = request.POST.get('number_of_package')
    booking.material = request.POST.get('material')
    booking.from_city = request.POST.get('from_city')
    booking.to_city = request.POST.get('to_city')
    booking.lorry_number = request.POST.get('lorry_number')
    vehicle_category = get_or_none(VehicleCategory,
                                   id=request.POST.get('vehicle_category_id'))
    booking.type_of_vehicle = None if not vehicle_category else vehicle_category.name(
    )
    booking.loading_points = request.POST.get('loading_points')
    booking.unloading_points = request.POST.get('unloading_points')
    # booking.supplier = get_or_none(Broker, id=request.POST.get('supplier_id'))
    # booking.owner = get_or_none(Owner, id=request.POST.get('truck_owner_id'))
    booking.driver = get_or_none(Driver,
                                 id=request.POST.get('truck_driver_id'))

    # rate details
    booking.loaded_weight = to_float(request.POST.get('loaded_weight'))
    booking.supplier_charged_weight = to_float(
        request.POST.get('supplier_charged_weight'))
    booking.supplier_rate = to_int(request.POST.get('supplier_rate'))

    # additional charges
    booking.loading_charge = to_int(request.POST.get('loading_charge'))
    booking.unloading_charge = to_int(request.POST.get('unloading_charge'))
    booking.detention_charge = to_int(request.POST.get('detention_charge'))
    booking.additional_charges_for_owner = to_int(
        request.POST.get('additional_charges_for_owner'))
    booking.note_for_additional_owner_charges = request.POST.get(
        'note_for_additional_owner_charges')

    # deduction for vendor
    booking.commission = to_int(request.POST.get('commission'))
    booking.lr_cost = to_int(request.POST.get('lr_cost'))
    booking.deduction_for_advance = to_int(
        request.POST.get('deduction_for_advance'))
    booking.deduction_for_balance = to_int(
        request.POST.get('deduction_for_balance'))
    booking.other_deduction = to_int(request.POST.get('other_deduction'))
    booking.remarks_about_deduction = request.POST.get(
        'remarks_about_deduction')

    # total amount
    booking.total_amount_to_owner = to_int(
        request.POST.get('total_amount_to_owner'))
    booking.total_amount_to_company = to_int(
        request.POST.get('total_amount_to_party'))

    if not EMP_GROUP3 in request.user.groups.values_list('name', flat=True):
        # invoice details
        booking.additional_charges_for_company = to_int(
            request.POST.get('additional_charges_for_company'))
        booking.invoice_remarks_for_additional_charges = request.POST.get(
            'invoice_remarks_for_additional_charges')
        booking.deductions_for_company = to_int(
            request.POST.get('deductions_for_company'))
        booking.invoice_remarks_for_deduction_discount = request.POST.get(
            'invoice_remarks_for_deduction_discount')
        booking.advance_amount_from_company = to_int(
            request.POST.get('advance_from_company'))
        booking.tds_deducted_amount = to_int(
            request.POST.get('tds_deducted_amount'))

        # Rate Details
        booking.charged_weight = to_float(request.POST.get('charged_weight'))
        booking.party_rate = to_int(request.POST.get('party_rate'))

    # status update
    booking.pod_status = request.POST.get('pod_status')
    booking.invoice_status = request.POST.get('invoice_status')
    booking.save()
    Vehicle.objects.filter(
        vehicle_number=compare_format(booking.lorry_number)).update(
            vehicle_type=vehicle_category)
    update_inward_payments(booking)
    update_outward_payments(booking)
    update_invoice_status(booking)
    return booking
Ejemplo n.º 9
0
def adjust_pending_inward_payment_data():
    data = {
        'common_inward_payment_remarks':
        '1233',
        'payment_id':
        '112',
        'booking': [{
            'booking_id': '2326',
            'amount': '16000',
            'tds': '0',
            'balance': '0',
            'remarks': '23'
        }, {
            'booking_id': '2846',
            'amount': '2950',
            'tds': '0',
            'balance': '0',
            'remarks': '443'
        }, {
            'booking_id': '2878',
            'amount': '44100',
            'tds': '0',
            'balance': '0',
            'remarks': '222'
        }, {
            'booking_id': '2907',
            'amount': '44100',
            'tds': '0',
            'balance': '0',
            'remarks': '222'
        }, {
            'booking_id': '2905',
            'amount': '18850',
            'tds': '0',
            'balance': '33650',
            'remarks': '22122'
        }, {
            'booking_id': '2906',
            'amount': '0',
            'tds': '0',
            'balance': '0'
        }, {
            'booking_id': '2920',
            'amount': '0',
            'tds': '0',
            'balance': '0'
        }]
    }
    parsed_data = []
    pending_payment = get_or_none(PendingInwardPaymentEntry,
                                  id=data.get('payment_id'))
    if isinstance(pending_payment, PendingInwardPaymentEntry):
        received_from = pending_payment.customer.get_name() if isinstance(
            pending_payment.customer, Sme) else None,
        trn = pending_payment.trn
        payment_mode = pending_payment.payment_mode
        payment_date = pending_payment.payment_date
    else:
        received_from = None,
        trn = None
        payment_mode = None
        payment_date = None

    for row in data.get('booking', []):
        if to_int(row['amount']) > 0:
            parsed_data.append({
                'booking_id': [row.get('booking_id')],
                'received_from':
                received_from,
                'tds':
                to_float(row['tds']),
                'actual_amount':
                to_float(row['amount']),
                'expected_amount':
                to_float(row['amount']),
                'payment_mode':
                payment_mode,
                'trn':
                trn,
                'remarks':
                row.get('remarks') if row.get('remarks', None) else data.get(
                    'common_inward_payment_remarks', None),
                'payment_date':
                payment_date
            })
Ejemplo n.º 10
0
def adjust_inward_payment(payment, user):
    tds_amount = to_int(payment.tds)
    total_amount = to_int(payment.amount)
    try:
        tds_rate = tds_amount / (total_amount + tds_amount)
    except ZeroDivisionError:
        tds_rate = 0
    user_group = user.groups.values_list('name', flat=True)[0]
    if user_group == EMP_GROUP2 or user_group == EMP_GROUP3:
        invoices = Invoice.objects.filter(
            customer_fk=payment.customer,
            payment_received=False,
            bookings__in=ManualBooking.objects.filter(
                customer_to_be_billed_to=payment.customer).exclude(
                    billing_type='contract')).distinct().order_by('date')
    else:
        invoices = Invoice.objects.filter(
            customer_fk=payment.customer,
            payment_received=False).order_by('date')
    invoices_data = []
    for invoice in invoices:
        if sum([
                booking.balance_for_customer
                for booking in invoice.bookings.exclude(
                    booking_status='cancelled')
        ]) != 0:
            data = {}
            data['invoice_date'] = invoice.date
            data['invoice_number'] = slugify(invoice.invoice_number)
            data['amount'] = invoice.total_amount
            data['remarks'] = invoice.remarks
            data['to_receive'] = sum([
                booking.balance_for_customer
                for booking in invoice.bookings.exclude(
                    booking_status='cancelled')
            ])
            data['btnFullPaymentReceived'] = '_'.join(
                ['btnFullPaymentReceived',
                 slugify(invoice.invoice_number)])
            data['btnResetPaymentReceived'] = '_'.join(
                ['btnResetPaymentReceived',
                 slugify(invoice.invoice_number)])
            data['txtToReceiveInvoice'] = '_'.join(
                ['txtToReceiveInvoice',
                 slugify(invoice.invoice_number)])
            bookings = []
            for booking in invoice.bookings.exclude(
                    booking_status='cancelled').order_by('shipment_date'):
                amount_to_be_received = to_int(booking.balance_for_customer)
                if amount_to_be_received != 0:
                    if to_float(amount_to_be_received
                                ) < total_amount and total_amount > 0:
                        received_amount = to_int(amount_to_be_received -
                                                 amount_to_be_received *
                                                 tds_rate)
                        received_tds = to_int(amount_to_be_received * tds_rate)
                        balance_amount = amount_to_be_received - received_amount - received_tds
                        if balance_amount == 1:
                            received_amount += 1
                            balance_amount = 0
                        total_amount -= received_amount
                        tds_amount -= received_tds
                    elif to_float(amount_to_be_received
                                  ) > total_amount and total_amount > 0:
                        received_amount = to_int(total_amount -
                                                 total_amount * tds_rate)
                        received_tds = to_int(total_amount * tds_rate)
                        balance_amount = amount_to_be_received - received_amount - received_tds
                        total_amount = 0
                        if balance_amount == 1:
                            received_amount += 1
                            balance_amount = 0
                        tds_amount -= received_tds
                    else:
                        total_amount = 0
                        tds_amount = 0
                        received_amount = None
                        received_tds = None
                        balance_amount = to_int(
                            amount_to_be_received) - to_int(
                                received_amount) - to_int(received_tds)
                    received_amount = 0
                    received_tds = 0
                    balance_amount = 0
                    bookings.append({
                        'mb_id':
                        booking.id,
                        'booking_id':
                        booking.booking_id,
                        'lr_numbers':
                        booking.booking_id if not '\n'.join(
                            booking.lr_numbers.values_list(
                                'lr_number', flat=True)) else '\n'.join(
                                    booking.lr_numbers.values_list('lr_number',
                                                                   flat=True)),
                        'weight':
                        booking.charged_weight,
                        'rate':
                        booking.party_rate,
                        'total_amount':
                        booking.total_amount_to_company,
                        'amount_to_be_received':
                        amount_to_be_received,
                        'received_amount':
                        received_amount,
                        'received_tds':
                        received_tds,
                        'balance_amount':
                        balance_amount,
                        'amountId':
                        '_'.join([booking.booking_id, 'receivedAmountId']),
                        'tdsId':
                        '_'.join([booking.booking_id, 'tdsId']),
                        'remarksId':
                        '_'.join([booking.booking_id, 'remarksId']),
                        'balanceId':
                        '_'.join([booking.booking_id, 'balanceId']),
                    })

            data['bookings'] = bookings
            invoices_data.append(data)

    data = invoices_data
    return data, tds_amount, total_amount, tds_rate
Ejemplo n.º 11
0
def save_existing_manual_booking_data(request, booking_id):
    booking = ManualBooking.objects.get(id=booking_id)
    from_city = get_or_none(City, id=request.POST.get('from_city'))
    if isinstance(from_city, City):
        from_city_fk = from_city
        from_city = from_city.name

    else:
        from_city = None
        from_city_fk = None
    to_city = get_or_none(City, id=request.POST.get('to_city'))
    if isinstance(to_city, City):
        to_city_fk = to_city
        to_city = to_city.name
    else:
        to_city = None
        to_city_fk = None
    consignor_city = get_or_none(City, id=request.POST.get('consignor_city'))
    if isinstance(consignor_city, City):
        consignor_city_fk = consignor_city
        consignor_city = consignor_city.name
    else:
        consignor_city_fk = None
        consignor_city = None
    consignee_city = get_or_none(City, id=request.POST.get('consignee_city'))
    if isinstance(consignee_city, City):
        consignee_city_fk = consignee_city
        consignee_city = consignee_city.name
    else:
        consignee_city_fk = None
        consignee_city = None
    vehicle_category = get_or_none(VehicleCategory,
                                   id=request.POST.get('vehicle_category_id'))
    if isinstance(vehicle_category, VehicleCategory):
        type_of_vehicle = vehicle_category.vehicle_category
    else:
        type_of_vehicle = None
    vehicle = get_or_none(Vehicle,
                          vehicle_number=compare_format(
                              request.POST.get('vehicle_number')))
    if isinstance(vehicle, Vehicle):
        lorry_number = display_format(vehicle.vehicle_number)
    else:
        lorry_number = None
    if not EMP_GROUP3 in request.user.groups.values_list('name', flat=True):
        booking.party_rate = to_int(request.POST.get('party_rate'))
        booking.charged_weight = to_float(request.POST.get('charged_weight'))
        booking.additional_charges_for_company = to_int(
            request.POST.get('additional_charges_for_company'))
        booking.deductions_for_company = to_int(
            request.POST.get('deductions_for_company'))
        booking.total_amount_to_company = to_int(
            request.POST.get('total_amount_to_party'))
        booking.refund_amount = to_int(request.POST.get('refundable_amount'))
        booking.invoice_amount = to_int(request.POST.get('invoice_amount'))
        booking.invoice_remarks_for_deduction_discount = request.POST.get(
            'invoice_remarks_for_deduction_discount')
        booking.advance_amount_from_company = request.POST.get(
            'advance_from_company')
        booking.invoice_remarks_for_additional_charges = request.POST.get(
            'invoice_remarks_for_additional_charges')

    booking.consignor_name = request.POST.get('consignor_name')
    booking.consignor_address = request.POST.get('consignor_address')
    booking.consignor_city = consignor_city
    booking.consignor_city_fk = consignor_city_fk
    booking.consignor_pin = request.POST.get('consignor_pin')
    booking.consignor_phone = request.POST.get('consignor_phone')
    booking.consignor_gstin = request.POST.get('consignor_gstin')

    booking.consignee_name = request.POST.get('consignee_name')
    booking.consignee_address = request.POST.get('consignee_address')
    booking.consignee_city = consignee_city
    booking.consignee_city_fk = consignee_city_fk
    booking.consignee_pin = request.POST.get('consignee_pin')
    booking.consignee_phone = request.POST.get('consignee_phone')
    booking.consignee_gstin = request.POST.get('consignee_gstin')

    booking.driver = get_or_none(Driver,
                                 id=request.POST.get('truck_driver_id'))
    shipment_date = request.POST.get('shipment_datetime')
    booking.shipment_date = None if is_blank(
        shipment_date) else datetime.strptime(shipment_date, '%Y-%m-%d')
    booking.billing_type = request.POST.get('billing_type')
    booking.number_of_package = request.POST.get('number_of_package')
    booking.material = request.POST.get('material')
    booking.from_city = from_city
    booking.from_city_fk = from_city_fk
    booking.to_city = to_city
    booking.to_city_fk = to_city_fk
    booking.lorry_number = lorry_number
    booking.vehicle = vehicle
    booking.party_invoice_number = request.POST.get('party_invoice_number')
    booking.party_invoice_date = django_date_format(
        request.POST.get('party_invoice_date'))
    booking.party_invoice_amount = to_float(
        request.POST.get('party_invoice_amount'))
    booking.road_permit_number = request.POST.get('road_permit_number')
    booking.vehicle_category = vehicle_category
    booking.type_of_vehicle = type_of_vehicle

    booking.liability_of_service_tax = request.POST.get(
        'liability_of_service_tax')

    booking.loaded_weight = to_float(request.POST.get('loaded_weight'))

    booking.supplier_charged_weight = to_float(
        request.POST.get('supplier_charged_weight'))

    booking.supplier_rate = to_int(request.POST.get('supplier_rate'))

    save_insurance_details(request, booking)
    booking.comments = request.POST.get('comments')
    booking.billing_type = request.POST.get('billing_type')

    booking.loading_charge = to_int(request.POST.get('loading_charge'))
    booking.unloading_charge = to_int(request.POST.get('unloading_charge'))
    booking.detention_charge = to_int(request.POST.get('detention_charge'))
    booking.additional_charges_for_owner = to_int(
        request.POST.get('additional_charges_for_owner'))

    booking.commission = to_int(request.POST.get('commission'))
    booking.lr_cost = to_int(request.POST.get('lr_cost'))
    booking.deduction_for_advance = to_int(
        request.POST.get('deduction_for_advance'))
    booking.deduction_for_balance = to_int(
        request.POST.get('deduction_for_balance'))
    booking.other_deduction = to_int(request.POST.get('other_deduction'))

    booking.remarks_about_deduction = request.POST.get(
        'remarks_about_deduction')

    booking.total_amount_to_owner = to_int(
        request.POST.get('total_amount_to_owner'))
    booking.tds_deducted_amount = to_int(
        request.POST.get('tds_deducted_amount'))
    booking.invoice_status = request.POST.get('invoice_status')
    booking.note_for_additional_owner_charges = request.POST.get(
        'note_for_additional_owner_charges')
    booking.is_advance = request.POST.get('is_print_payment_mode_instruction')
    booking.changed_by = request.user
    booking.save()
    Vehicle.objects.filter(
        vehicle_number=compare_format(booking.lorry_number)).update(
            vehicle_type=vehicle_category)
    save_vendor_details(booking)
    update_inward_payments(booking)
    update_outward_payments(booking)
    update_invoice_status(booking)
    return booking