Esempio n. 1
0
def inward_payment(booking_id_list,
                   receive_from,
                   amount,
                   payment_mode,
                   date,
                   invoice_number,
                   remarks,
                   trn,
                   username,
                   tds_amount=0):
    manual_bookings = ManualBooking.objects.filter(id__in=booking_id_list)
    payment = InWardPayment()
    payment.received_from = receive_from
    payment.actual_amount = amount
    payment.payment_mode = payment_mode
    payment.tds = tds_amount
    payment.remarks = remarks
    if trn:
        payment.trn = trn
    payment.payment_date = django_date_format(date)
    payment.invoice_number = invoice_number
    payment.created_by = User.objects.get(username=username)
    payment.changed_by = User.objects.get(username=username)
    payment.save()
    for booking in payment.booking_id.all():
        booking.tds_deducted_amount += sum(
            booking.inward_booking.values_list('tds', flat=True))
        booking.total_in_ward_amount += sum(
            booking.inward_booking.values_list('actual_amount', flat=True))
        booking.save()
    for booking in manual_bookings:
        payment.booking_id.add(booking)
    for booking in manual_bookings:
        update_inward_payments(booking)
    return payment
Esempio n. 2
0
def update_inward_payment(booking_id_list,
                          payment_id,
                          received_from,
                          amount,
                          payment_mode,
                          remarks,
                          date,
                          invoice_number,
                          trn,
                          tds_amount=0):
    manual_bookings = ManualBooking.objects.filter(id__in=booking_id_list)
    payment = InWardPayment.objects.get(id=payment_id)
    payment.received_from = received_from
    payment.tds = tds_amount
    payment.actual_amount = amount
    payment.payment_mode = payment_mode
    payment.remarks = remarks
    payment.payment_date = django_date_format(date)
    payment.invoice_number = invoice_number
    payment.trn = trn
    payment.save()
    for value in payment.booking_id.all():
        value.total_in_ward_amount -= to_int(amount)
        value.tds_deducted_amount += int(float(tds_amount))
        value.save()
    payment.booking_id.clear()
    for booking in manual_bookings:
        payment.booking_id.add(booking)
    for booking in manual_bookings:
        update_inward_payments(booking)
Esempio n. 3
0
def in_ward_payments(request):
    if request.method == 'POST':
        payment = InWardPayment.objects.create(
            received_from=request.POST.get('received_from'),
            actual_amount=request.POST.get('actual_amount'),
            payment_mode=request.POST.get('payment_mode'),
            remarks=request.POST.get('remarks'),
            payment_date=django_date_format(
                request.POST.get('inward_payment_date')),
            invoice_number=request.POST.get('invoice_number'),
            created_by=User.objects.get(username=request.user.username))
        booking_id_list = request.POST.getlist('booking_id[]')
        for booking_id in booking_id_list:
            manual_booking_id = ManualBooking.objects.get(
                booking_id=booking_id)
            in_ward_payment = InWardPayment.objects.filter(
                booking_id=manual_booking_id)
            amount = 0
            for value in in_ward_payment:
                amount += value.actual_amount
            amount += to_int(float(request.POST.get('actual_amount')))
            manual_booking_id.total_in_ward_amount = amount
            manual_booking_id.save()
            payment.booking_id.add(manual_booking_id)
            update_inward_payments(manual_booking_id)
Esempio n. 4
0
def change_status_existing_booking(booking_id):
    try:
        booking = ManualBooking.objects.get(booking_id=booking_id)
    except ManualBooking.DoesNotExist:
        booking = ManualBooking.objects.get(id=booking_id)
    out_ward_payment = OutWardPayment.objects.filter(booking_id=booking)
    outward_amount = 0
    for value in out_ward_payment:
        outward_amount += value.actual_amount
    if outward_amount == 0:
        booking.outward_payment_status = 'no_payment_made'
    elif booking.total_amount_to_owner > outward_amount:
        booking.outward_payment_status = 'partial'
    elif booking.total_amount_to_owner == outward_amount:
        booking.outward_payment_status = 'complete'
    elif booking.total_amount_to_owner < outward_amount:
        booking.outward_payment_status = 'excess'
    in_ward_payment = InWardPayment.objects.filter(booking_id=booking)
    inward_amount = 0
    for value in in_ward_payment:
        inward_amount += value.actual_amount
    update_inward_payments(booking)
Esempio n. 5
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
Esempio n. 6
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