示例#1
0
def supplier_booking_data(bookings):
    data = []
    for booking in bookings:
        if to_int(booking.total_amount_to_owner - booking.total_out_ward_amount) != 0:
            data.append(
                {
                    'status': 'unpaid',
                    'lr_number': '\n'.join(booking.lr_numbers.values_list('lr_number',
                                                                          flat=True)) if booking.lr_numbers.exists() else booking.booking_id,
                    'paid': to_int(booking.total_out_ward_amount),
                    'transaction_id': booking.id,
                    'id': booking.id,
                    'vehicle_number': display_format(booking.lorry_number),
                    'source_city': booking.from_city,
                    'destination_city': booking.to_city,
                    'amount': to_int(booking.total_amount_to_owner),
                    'shipment_date': booking.shipment_date.strftime('%d-%b-%Y'),
                    'balance': to_int(booking.total_amount_to_owner - booking.total_out_ward_amount),
                    'booking_id': booking.booking_id,
                    'pod_status': booking.pod_status,
                    'pod_docs': [
                        {'url': pod.s3_url if pod.s3_url else pod.s3_upload.public_url(),
                         'thumb_url': pod.s3_thumb_url if pod.s3_thumb_url else pod.s3_upload.public_url(),
                         'lr_number': pod.lr_number.lr_number if pod.lr_number else ''} for pod in
                        booking.podfile_set.all()
                    ]
                }
            )
        else:
            data.append(
                {
                    'status': 'paid',
                    'lr_number': '\n'.join(booking.lr_numbers.values_list('lr_number',
                                                                          flat=True)) if booking.lr_numbers.exists() else booking.booking_id,
                    'paid': to_int(booking.total_out_ward_amount),
                    'id': booking.id,
                    'transaction_id': booking.id,
                    'booking_id': booking.booking_id,
                    'vehicle_number': display_format(booking.lorry_number),
                    'source_city': booking.from_city,
                    'destination_city': booking.to_city,
                    'amount': to_int(booking.total_amount_to_owner),
                    'shipment_date': booking.shipment_date.strftime('%d-%b-%Y'),
                    'balance': to_int(booking.total_amount_to_owner - booking.total_out_ward_amount),
                    'final_payment_date': final_payment_date(booking=booking),
                    'pod_status': booking.pod_status,
                    'pod_docs': [
                        {'url': pod.s3_url if pod.s3_url else pod.s3_upload.public_url(),
                         'thumb_url': pod.s3_thumb_url if pod.s3_thumb_url else pod.s3_upload.public_url(),
                         'lr_number': pod.lr_number.lr_number if pod.lr_number else ''} for pod in
                        booking.podfile_set.all()
                    ]
                }
            )
    return data
示例#2
0
def get_vehicle_data(trans_id):
    allocated_vehicle = VehicleAllocated.objects.get(id=trans_id)
    if allocated_vehicle.vehicle_number is None:
        data = {
            'vehicle_type': '',
            'vehicle_number': '',
            'dl_number': '',
            'dl_validity': '',
            'driver_name': '',
            'driver_phone': ''
        }
    else:
        data = {}
        data[
            'vehicle_type'] = allocated_vehicle.vehicle_number.vehicle_type.vehicle_type
        data['vehicle_number'] = display_format(
            allocated_vehicle.vehicle_number.vehicle_number)
        if allocated_vehicle.vehicle_number.driver is not None:
            data[
                'dl_number'] = allocated_vehicle.vehicle_number.driver.driving_licence_number
            data['dl_validity'] = datetime.strptime(
                str(allocated_vehicle.vehicle_number.driver.
                    driving_licence_validity), '%Y-%m-%d').strftime('%d %b %Y')
            data['driver_name'] = allocated_vehicle.vehicle_number.driver.name
            data[
                'driver_phone'] = allocated_vehicle.vehicle_number.driver.phone
        else:
            data['dl_number'] = ''
            data['dl_validity'] = ''
            data['driver_name'] = ''
            data['driver_phone'] = ''
    return data
示例#3
0
def fms_booking_data():
    group = Group.objects.get(name='fms')
    for user in group.user_set.all():
        # print user, user.profile.name

        bookings = ManualBooking.objects.filter(
            Q(truck_broker_owner_phone=user.profile.phone)
            | Q(truck_owner_phone=user.profile.phone)).filter(
                shipment_date__gte=datetime.now().date() -
                timedelta(days=90)).exclude(
                    booking_status__icontains='cancelled').order_by(
                        '-shipment_date')
        download_master_table(filename=user.profile.name + '_new.xlsx',
                              bookings=bookings)
        try:
            broker = Broker.objects.filter(name=User.objects.get(
                username=user.profile.phone)).last()
            broker_vehicle = BrokerVehicle.objects.filter(
                broker=broker).values_list('vehicle__vehicle_number',
                                           flat=True)
            vehicles = [display_format(vehicle) for vehicle in broker_vehicle]
            bookings = ManualBooking.objects.filter(
                lorry_number__in=vehicles,
                shipment_date__gte=datetime.now().date() -
                timedelta(days=90)).exclude(
                    booking_status__icontains='cancelled').order_by(
                        '-shipment_date')
            print('old', user.profile.name, bookings.count())
            download_master_table(filename=user.profile.name + '_old.xlsx',
                                  bookings=bookings)
        except:
            print(user)
示例#4
0
def track_shipment_display(request):
    try:
        lr_obj = LrNumber.objects.get(lr_number__iexact=request.GET.get('shipment_id'))
        booking_unloaded = check_booking_status(lr_obj.booking, 'unloaded')
        if lr_obj.booking.pod_status == 'completed' or booking_unloaded:
            messages.info(request, 'This shipment has been delivered at the unloading point.')
            return render(request=request, template_name='index/track_shipment.html',
                          context={'booking': lr_obj.booking, 'lr_obj': lr_obj})
        else:
            gps = shipment_gps_data(booking=lr_obj.booking)
            if gps:
                # if gps['location_time'] > datetime.utcnow() - timedelta(hours=24):
                if gps['location_time'].replace(tzinfo=None) > datetime.utcnow() - timedelta(hours=24):
                    gps_data = google_reverse_geocode(gps['latitude'], gps['longitude'])
                    gps_data['driver_name'] = gps['driver_name']
                    gps_data['driver_number'] = gps['driver_number']
                    gps_data['updated_on'] = gps['location_time']
                    gps_data['vehicle_number'] = display_format(gps['vehicle_number'])
                    context = {'lr_obj': lr_obj, 'gps': gps_data}
                    print(context)
                    return render(request=request, template_name='index/track_shipment.html', context=context)
                else:
                    messages.info(request,
                                  'We apologize but location data for this shipment is not available as of now.')
                    return render(request=request, template_name='index/track_shipment.html',
                                  context={'booking': lr_obj.booking, 'lr_obj': lr_obj})
            else:
                messages.info(request, 'We apologize but location data for this shipment is not available as of now.')
                return render(request=request, template_name='index/track_shipment.html',
                              context={'booking': lr_obj.booking, 'lr_obj': lr_obj})
    except LrNumber.DoesNotExist:
        messages.error(request, 'Incorrect LR, please check and try again.')
        return render(request=request, template_name='index/index-gloify.html')
示例#5
0
def vehicle_trip_data(request):
    data = request.data
    vehicle_id = int_or_none(data.get('vehicleId', None))
    if vehicle_id:
        vehicle = get_or_none(Vehicle, id=vehicle_id)
        if not vehicle:
            return json_error_response(
                'Vehicle with id=%s does not exist' % vehicle_id, 404)
        else:
            broker_vehicle_ids = BrokerVehicle.objects.filter(
                vehicle=vehicle).values_list('vehicle_id', flat=True)
            allocated_vehicles_data = VehicleAllocated.objects.filter(
                vehicle_number_id__in=broker_vehicle_ids).values(
                    'transaction_id', 'total_out_ward_amount',
                    'total_amount_to_owner', 'transaction__shipment_datetime',
                    'source_city', 'destination_city', 'transaction_id',
                    'material', 'transaction__total_vehicle_requested',
                    'transaction__transaction_status',
                    'transaction__transaction_id',
                    'vehicle_number__vehicle_number', 'lr_number')
            transaction_data = [{
                'id':
                v['transaction_id'],
                'transaction_id':
                v['transaction__transaction_id'],
                'status':
                v['transaction__transaction_status'],
                'source_city':
                v['source_city'],
                'destination_city':
                v['destination_city'],
                'paid':
                str(int(v['total_out_ward_amount'])),
                'amount':
                str(int(v['total_amount_to_owner'])),
                'balance':
                str(
                    int(v['total_amount_to_owner'] -
                        v['total_out_ward_amount'])),
                'total_vehicle_requested':
                v['transaction__total_vehicle_requested'],
                'vehicle_number':
                display_format(v['vehicle_number__vehicle_number']),
                'lr_number':
                v['lr_number'],
                'shipment_date':
                v['transaction__shipment_datetime'].strftime('%d-%b-%Y')
            } for v in allocated_vehicles_data]
            return json_response({
                'status': 'success',
                'data': transaction_data
            })
    else:
        vehicle = Vehicle()
示例#6
0
def update_owner_page(request):
    owner = get_or_none(Owner, id=int_or_none(request.GET.get('owner_id')))
    vehicles = [{
        'id': vehicle.id,
        'vehicle_number': display_format(vehicle.vehicle_number)
    } for vehicle in Vehicle.objects.filter(owner=None)]
    owner_vehicles = [{
        'id': vehicle.id,
        'vehicle_number': display_format(vehicle.vehicle_number)
    } for vehicle in Vehicle.objects.filter(owner=owner)]

    return render(
        request=request,
        template_name='team/registrations/owner-update.html',
        context={
            'owner': owner,
            'vehicles': vehicles,
            'owner_vehicles': owner_vehicles,
        },
    )
示例#7
0
def delayed_pod_warning_message(lr_number,
                                shipment_date,
                                vehicle_number,
                                language='hindi'):
    if language == 'hindi':
        return (
            u'%s को Trans IQ (Aaho Logistics) के लिए वाहन नंबर %s जिसका बिल्टी न. %s है, लगाने के लिए धन्यवाद। इस माल की ‘पहुंच’ अभी तक प्राप्त नहीं हुई हैं। डिलीवरी के 10 दिनों बाद भी पहुंच प्राप्त नहीं होने पर प्रतिदिन 50 रुपये की कटौती लागू की जायेगी।'
            % (shipment_date, display_format(vehicle_number),
               lr_number)).encode('utf-8')
    elif language == 'telgu':
        return u''
示例#8
0
def team_booking_data(request, vehicle_id):
    print(request.data)
    if to_int(vehicle_id) != 9999999 and isinstance(get_or_none(Vehicle, id=vehicle_id), Vehicle):
        vehicle = get_or_none(Vehicle, id=vehicle_id)
        bookings = ManualBooking.objects.filter(
            lorry_number__in=[display_format(compare_format(vehicle.vehicle_number))]).exclude(
            booking_status__icontains='cancelled').order_by('-shipment_date')
    else:
        broker = Broker.objects.get(name=User.objects.get(username=request.user.username))
        bookings = ManualBooking.objects.filter(supplier=broker,
                                                shipment_date__gte=datetime(2017, 12, 1).date()).exclude(
            booking_status__icontains='cancelled').order_by('-shipment_date')
    return json_response({'status': 'success', 'data': supplier_booking_data(bookings=bookings)})
示例#9
0
def upload_vehicle_document_page(request):
    document_categories = (
        ('PUC', 'Puc Certificate'),
        ('FIT', 'Fitness Certificate'),
        ('REG', 'Registration Certificate'),
        ('PERM', 'Permit Certificate'),
        ('INS', 'Insurance Certificate'),
    )
    vehicles = [{'id': vehicle.id, 'vehicle_number': display_format(vehicle.vehicle_number)} for vehicle in
                Vehicle.objects.all()]
    return render(
        request=request,
        template_name='fileupload/upload_vehicle_documents.html',
        context={'document_categories': document_categories, 'vehicles': vehicles}
    )
示例#10
0
def vehicles_data(request):
    rows = to_int(request.GET.get('page'))
    search_value = request.GET.get('search')
    vehicles = Vehicle.objects.exclude(Q(vehicle_number=None))
    if search_value:
        vehicles = Vehicle.objects.filter(
            Q(vehicle_number__icontains=''.join(ch.lower()
                                                for ch in search_value
                                                if ch.isalnum()))).exclude(
                                                    Q(vehicle_number=None))
    data = []
    for vehicle in vehicles[:rows]:
        data.append({
            'id': vehicle.id,
            'text': '{}'.format(display_format(vehicle.vehicle_number))
        })
    data = {'results': data}
    return HttpResponse(json.dumps(data), content_type='application/json')
示例#11
0
def booking_history_data(request):
    broker = Broker.objects.get(name=User.objects.get(
        username=request.user.username))
    broker_vehicle_ids = BrokerVehicle.objects.filter(
        broker=broker).values_list('vehicle_id', flat=True)
    allocated_vehicles_data = VehicleAllocated.objects.filter(
        vehicle_number_id__in=broker_vehicle_ids).values(
            'transaction_id', 'total_out_ward_amount', 'total_amount_to_owner',
            'transaction__shipment_datetime', 'id', 'source_city',
            'destination_city', 'transaction_id', 'material',
            'transaction__total_vehicle_requested',
            'transaction__transaction_status', 'transaction__transaction_id',
            'vehicle_number__vehicle_number', 'lr_number')
    transaction_data = [{
        'id':
        v['id'],
        'transaction_id':
        v['transaction__transaction_id'],
        'status':
        v['transaction__transaction_status'],
        'source_city':
        v['source_city'],
        'destination_city':
        v['destination_city'],
        'paid':
        str(int(v['total_out_ward_amount'])),
        'amount':
        str(int(v['total_amount_to_owner'])),
        'balance':
        str(int(v['total_amount_to_owner'] - v['total_out_ward_amount'])),
        'total_vehicle_requested':
        v['transaction__total_vehicle_requested'],
        'vehicle_number':
        display_format(v['vehicle_number__vehicle_number']),
        'lr_number':
        v['lr_number'],
        'shipment_date':
        v['transaction__shipment_datetime'].strftime('%d-%b-%Y')
    } for v in allocated_vehicles_data]
    return json_response({'status': 'success', 'data': transaction_data})
示例#12
0
def get_basic_transaction_data(trans_id):
    allocated_vehicles_data = VehicleAllocated.objects.filter(
        id=trans_id).values(
            'transaction_id', 'total_out_ward_amount', 'total_amount_to_owner',
            'transaction__shipment_datetime', 'id', 'source_city',
            'destination_city', 'transaction_id', 'material',
            'transaction__total_vehicle_requested',
            'transaction__transaction_status', 'transaction__transaction_id',
            'vehicle_number__vehicle_number', 'lr_number')
    transaction_data = [{
        'id':
        v['id'],
        'transaction_id':
        v['transaction__transaction_id'],
        'status':
        v['transaction__transaction_status'],
        'source_city':
        v['source_city'],
        'destination_city':
        v['destination_city'],
        'paid':
        str(int(v['total_out_ward_amount'])),
        'amount':
        str(int(v['total_amount_to_owner'])),
        'balance':
        str(int(v['total_amount_to_owner'] - v['total_out_ward_amount'])),
        'total_vehicle_requested':
        v['transaction__total_vehicle_requested'],
        'vehicle_number':
        display_format(v['vehicle_number__vehicle_number']),
        'lr_number':
        v['lr_number'],
        'shipment_date':
        v['transaction__shipment_datetime'].strftime('%d-%b-%Y')
    } for v in allocated_vehicles_data]
    return transaction_data
示例#13
0
 def vehicles(obj):
     return format_html('<br>'.join([
         '{} ({})'.format(display_format(sv.vehicle.vehicle_number),
                          sv.get_ownership_display())
         for sv in obj.suppliervehicle_set.all()
     ]))
示例#14
0
 def number(self):
     return display_format(self.vehicle_number)
示例#15
0
 def vehicles(self, broker):
     return format_html(
         "<br>".join([display_format(bv.vehicle.vehicle_number) for bv in broker.broker_vehicle.all()]))
示例#16
0
def mb_vehicle_trip_data(request):
    data = request.data
    vehicle_id = int_or_none(data.get('vehicleId', None))
    if vehicle_id:
        vehicle = int_or_none(get_or_none(Vehicle, id=vehicle_id))
        if not vehicle:
            return json_error_response(
                'Vehicle with id=%s does not exist' % vehicle_id, 404)
        else:
            data = []
            for booking in ManualBooking.objects.filter(lorry_number__in=[
                    display_format(compare_format(vehicle.vehicle_number))
            ]).order_by('-shipment_date'):
                if to_int(booking.total_amount_to_owner -
                          booking.total_out_ward_amount) != 0:
                    data.append({
                        'status':
                        'unpaid',
                        'lr_number':
                        '\n'.join(
                            booking.lr_numbers.values_list('lr_number',
                                                           flat=True)),
                        'paid':
                        to_int(booking.total_out_ward_amount),
                        'id':
                        booking.id,
                        'total_vehicle_requested':
                        None,
                        'vehicle_number':
                        display_format(booking.lorry_number),
                        'source_city':
                        booking.from_city,
                        'destination_city':
                        booking.to_city,
                        'amount':
                        to_int(booking.total_amount_to_owner),
                        'shipment_date':
                        booking.shipment_date.strftime('%d-%b-%Y'),
                        'balance':
                        to_int(booking.total_amount_to_owner -
                               booking.total_out_ward_amount),
                        'transaction_id':
                        booking.booking_id
                    })
                else:
                    data.append({
                        'status':
                        'paid',
                        'lr_number':
                        '\n'.join(
                            booking.lr_numbers.values_list('lr_number',
                                                           flat=True)),
                        'paid':
                        to_int(booking.total_out_ward_amount),
                        'id':
                        booking.id,
                        'total_vehicle_requested':
                        None,
                        'vehicle_number':
                        display_format(booking.lorry_number),
                        'source_city':
                        booking.from_city,
                        'destination_city':
                        booking.to_city,
                        'amount':
                        to_int(booking.total_amount_to_owner),
                        'shipment_date':
                        booking.shipment_date.strftime('%d-%b-%Y'),
                        'balance':
                        to_int(booking.total_amount_to_owner -
                               booking.total_out_ward_amount),
                        'final_payment_date':
                        final_payment_date(booking=booking),
                        'transaction_id':
                        booking.booking_id
                    })
            return json_response({'status': 'success', 'data': data})
示例#17
0
def download_master_table(filename, bookings):
    columns = [
        'Booking ID', 'LR Numbers', 'Shipment Date', 'Billing Type',
        'Source Office', 'Destination Office', 'From City', 'To City',
        'Customer who placed order', 'Customer who will make payment',
        'Supplier Name', 'Supplier Phone', 'Owner Name', 'Owner Phone',
        'Vehicle Number', 'Driver Name', 'Driver Phone', 'Actual Weight',
        'Charged Weight to Customer', 'Charged Weight for Supplier',
        'Customer Rate', 'Supplier Rate', 'Total Amount from Customer',
        'Deduction for Customer', 'Total Inward Amount', 'TDS',
        'Total Amount to Owner', 'Commission', 'LR Cost',
        'Deduction for Advance', 'Deduction for Balance', 'Other Deduction',
        'Deduction Remarks', 'Invoice Status', 'Total Outward Amount',
        'Outward Payment Remarks', 'Invoice Number', 'Invoice Date',
        'Invoice Amount', 'OPB Number', 'OPB Date', 'OPB Amount'
    ]
    data = [[
        booking.booking_id, '\n'.join(
            booking.lr_numbers.values_list('lr_number',
                                           flat=True)), booking.shipment_date,
        booking.get_billing_type_display(),
        booking.source_office.branch.name if booking.source_office else '',
        booking.destination_office.branch.name if booking.destination_office
        else '', booking.from_city, booking.to_city,
        booking.company.get_name() if booking.company else '',
        booking.customer_to_be_billed_to.get_name()
        if booking.customer_to_be_billed_to else '',
        booking.truck_broker_owner_name, booking.truck_broker_owner_phone,
        booking.truck_owner_name, booking.truck_owner_phone,
        display_format(compare_format(booking.lorry_number)),
        booking.driver_name, booking.driver_phone, booking.loaded_weight,
        booking.charged_weight, booking.supplier_charged_weight,
        booking.party_rate, booking.supplier_rate,
        booking.total_amount_to_company, booking.deductions_for_company,
        booking.total_in_ward_amount, booking.tds_deducted_amount,
        booking.total_amount_to_owner, booking.commission, booking.lr_cost,
        booking.deduction_for_advance, booking.deduction_for_balance,
        booking.other_deduction, booking.remarks_about_deduction,
        booking.get_invoice_status_display(),
        sum(booking.outward_booking.values_list('actual_amount', flat=True)),
        '\n'.join([
            ', '.join(map(str, row))
            for row in booking.outward_booking.values_list(
                'payment_mode', 'actual_amount', 'remarks')
        ]), ''.join(
            list(booking.invoices.values_list('invoice_number', flat=True)) +
            list(
                booking.to_pay_invoices.values_list('invoice_number',
                                                    flat=True))),
        ''.join([
            invoice_date.strftime('%d-%b-%Y') if invoice_date else ''
            for invoice_date in
            list(booking.invoices.values_list('date', flat=True)) +
            list(booking.to_pay_invoices.values_list('date', flat=True))
        ]), ''.join(
            map(str,
                list(booking.invoices.values_list('total_amount', flat=True)))
            + list(
                booking.to_pay_invoices.values_list(
                    'amount_payable_to_transiq', flat=True))), '\n'.join(
                        booking.outward_payment_bill.values_list('bill_number',
                                                                 flat=True)),
        '\n'.join([
            opb.bill_date.strftime('%d-%b-%Y') if opb.bill_date else ''
            for opb in booking.outward_payment_bill.all()
        ]), '\n'.join(
            map(str,
                booking.outward_payment_bill.values_list('amount', flat=True)))
    ] for booking in bookings]

    df = pd.DataFrame(data=data, columns=columns)
    df.to_excel(filename, index=False)
示例#18
0
 def vehicles(self, obj):
     return format_html(
         '<br>'.join([display_format(vehicle.vehicle_number) for vehicle in Vehicle.objects.filter(owner=obj)]))
示例#19
0
 def get_vehicle_number_display(self, instance):
     return display_format(instance.vehicle_number)
示例#20
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
示例#21
0
def bookings_with_low_profit():
    data = []
    for booking in ManualBooking.objects.filter(shipment_date__gte='2017-04-01').exclude(
            booking_status='cancelled').order_by('-shipment_date'):
        try:
            profit = round(((
                                    booking.total_amount_to_company - booking.total_amount_to_owner) / booking.total_amount_to_owner) * 100,
                           2)
            if profit < 3:
                data.append([
                    booking.booking_id,
                    '\n'.join(booking.lr_numbers.values_list('lr_number', flat=True)),
                    booking.shipment_date,
                    booking.get_billing_type_display(),
                    booking.source_office.branch.name if booking.source_office else '',
                    booking.destination_office.branch.name if booking.destination_office else '',
                    booking.from_city,
                    booking.to_city,
                    booking.company.get_name() if booking.company else '',
                    booking.customer_to_be_billed_to.get_name() if booking.customer_to_be_billed_to else '',
                    booking.truck_broker_owner_name,
                    booking.truck_broker_owner_phone,
                    booking.truck_owner_name,
                    booking.truck_owner_phone,
                    display_format(compare_format(booking.lorry_number)),
                    booking.driver_name,
                    booking.driver_phone,
                    booking.loaded_weight,
                    booking.charged_weight,
                    booking.supplier_charged_weight,
                    booking.party_rate,
                    booking.supplier_rate,
                    booking.total_amount_to_company,
                    booking.deductions_for_company,
                    booking.total_in_ward_amount,
                    booking.tds_deducted_amount,
                    booking.total_amount_to_owner,
                    profit,
                    booking.commission,
                    booking.lr_cost,
                    booking.deduction_for_advance,
                    booking.deduction_for_balance,
                    booking.other_deduction,
                    booking.remarks_about_deduction,
                    sum(booking.outward_booking.values_list('actual_amount', flat=True)),
                    '\n'.join([', '.join(map(str, row)) for row in
                               booking.outward_booking.values_list('payment_mode', 'actual_amount', 'remarks')]),
                    ''.join(list(booking.invoices.values_list('invoice_number', flat=True)) + list(
                        booking.to_pay_invoices.values_list('invoice_number', flat=True))),
                    ''.join([invoice_date.strftime('%d-%b-%Y') if invoice_date else '' for invoice_date in
                             list(booking.invoices.values_list('date', flat=True)) + list(
                                 booking.to_pay_invoices.values_list('date', flat=True))]),
                    ''.join(map(str, list(booking.invoices.values_list('total_amount', flat=True))) + list(
                        booking.to_pay_invoices.values_list('amount_payable_to_transiq', flat=True))),
                    '\n'.join(booking.outward_payment_bill.values_list('bill_number', flat=True)),
                    '\n'.join([opb.bill_date.strftime('%d-%b-%Y') if opb.bill_date else '' for opb in
                               booking.outward_payment_bill.all()]),
                    '\n'.join(map(str, booking.outward_payment_bill.values_list('amount', flat=True)))
                ])

        except ZeroDivisionError:
            print(booking)
    columns = ['Booking ID', 'LR Numbers', 'Shipment Date', 'Billing Type',
               'Source Office', 'Destination Office', 'From City', 'To City',
               'Customer who placed order', 'Customer who will make payment', 'Supplier Name',
               'Supplier Phone',
               'Owner Name', 'Owner Phone', 'Vehicle Number', 'Driver Name', 'Driver Phone',
               'Actual Weight',
               'Charged Weight to Customer',
               'Charged Weight for Supplier',
               'Customer Rate', 'Supplier Rate',
               'Total Amount from Customer', 'Deduction for Customer',
               'Total Inward Amount', 'TDS', 'Total Amount to Owner', '% Profit', 'Commission', 'LR Cost',
               'Deduction for Advance',
               'Deduction for Balance', 'Other Deduction', 'Deduction Remarks',
               'Total Outward Amount', 'Outward Payment Remarks', 'Invoice Number',
               'Invoice Date',
               'Invoice Amount', 'OPB Number', 'OPB Date', 'OPB Amount'

               ]
    df = pd.DataFrame(data=data, columns=columns)
    df.to_excel('profit less than 3%.xlsx', index=False)
示例#22
0
 def veh_num(self, obj):
     return display_format(obj.vehicle_number)
示例#23
0
    def get_queryset(self):
        queryset = self.queryset
        return_response = {
            "status": "failure",
            "queryset": {
                "msg": "Booking Does Not Exist"
            },
            "status_code": status.HTTP_400_BAD_REQUEST
        }
        if isinstance(queryset, QuerySet):
            queryset = queryset.all()
            category_id = self.request.query_params.get('category_id', None)
            vehicle_id = self.request.query_params.get('vehicle_id', None)
            for key, value in self.request.GET.items():
                if key not in ['category_id', 'vehicle_id']:
                    return_response['queryset'] = {
                        "msg": "only category id and vehicle id is supported"
                    }
                    return return_response
            if category_id is None:
                return_response['queryset'] = {
                    "msg": "category_id is required field"
                }
                return return_response
            if vehicle_id is not None:
                # filter bookings only on vehicle id
                vehicle = get_or_none(Vehicle, id=vehicle_id)
                if not vehicle_id.isnumeric():
                    return_response = {
                        "status": "failure",
                        "queryset": {
                            "msg": "Vehicle id should be a number"
                        },
                        "status_code": status.HTTP_400_BAD_REQUEST
                    }
                    return return_response
                if not vehicle:
                    return_response['queryset'] = {
                        "msg": "Vehicle Does not exist"
                    }
                    return return_response
                queryset = queryset.filter(lorry_number__in=[
                    display_format(compare_format(vehicle.vehicle_number))
                ])
                if not queryset:
                    return return_response
                return_response['queryset'] = queryset
                return_response['status'] = 'success'
                return return_response

            # filter bookings on user category
            if not category_id.isnumeric():
                return_response = {
                    "status": "failure",
                    "queryset": {
                        "msg": "Category id should be a number"
                    },
                    "status_code": status.HTTP_400_BAD_REQUEST
                }
                return return_response
            try:
                user_category = UserCategory.objects.get(id=category_id)
            except UserCategory.DoesNotExist:
                return_response['queryset'][
                    'msg'] = 'User Category Does Not Exist'
                return return_response
            if user_category.category == 'Customer':
                return self.get_customer_bookings_data(queryset)
            elif user_category.category == 'Supplier':
                return self.get_supplier_bookings_data(queryset)
            return_response['queryset'][
                'msg'] = 'User Category Is Not Supported'
            return return_response
        else:
            return return_response
示例#24
0
def team_booking_data(request):
    broker = Broker.objects.get(name=User.objects.get(
        username=request.user.username))
    broker_vehicle = BrokerVehicle.objects.filter(broker=broker).values_list(
        'vehicle__vehicle_number', flat=True)
    vehicles = [display_format(vehicle) for vehicle in broker_vehicle]
    data = []
    for booking in ManualBooking.objects.filter(
            lorry_number__in=vehicles,
            shipment_date__gte=datetime.now().date() -
            timedelta(days=90)).exclude(booking_status__icontains='cancelled'
                                        ).order_by('-shipment_date'):
        if to_int(booking.total_amount_to_owner -
                  booking.total_out_ward_amount) != 0:
            data.append({
                'status':
                'unpaid',
                'lr_number':
                '\n'.join(
                    booking.lr_numbers.values_list('lr_number', flat=True)),
                'paid':
                to_int(booking.total_out_ward_amount),
                'id':
                booking.id,
                'total_vehicle_requested':
                None,
                'vehicle_number':
                display_format(booking.lorry_number),
                'source_city':
                booking.from_city,
                'destination_city':
                booking.to_city,
                'amount':
                to_int(booking.total_amount_to_owner),
                'shipment_date':
                booking.shipment_date.strftime('%d-%b-%Y'),
                'balance':
                to_int(booking.total_amount_to_owner -
                       booking.total_out_ward_amount),
                'transaction_id':
                booking.booking_id,
                'pod_status':
                booking.pod_status
            })
        else:
            data.append({
                'status':
                'paid',
                'lr_number':
                '\n'.join(
                    booking.lr_numbers.values_list('lr_number', flat=True)),
                'paid':
                to_int(booking.total_out_ward_amount),
                'id':
                booking.id,
                'total_vehicle_requested':
                None,
                'vehicle_number':
                display_format(booking.lorry_number),
                'source_city':
                booking.from_city,
                'destination_city':
                booking.to_city,
                'amount':
                to_int(booking.total_amount_to_owner),
                'shipment_date':
                booking.shipment_date.strftime('%d-%b-%Y'),
                'balance':
                to_int(booking.total_amount_to_owner -
                       booking.total_out_ward_amount),
                'final_payment_date':
                final_payment_date(booking=booking),
                'transaction_id':
                booking.booking_id,
                'pod_status':
                booking.pod_status
            })
    return json_response({'status': 'success', 'data': data})
示例#25
0
def display_vehicle_number_format(vehicle_number):
    return display_format(vehicle_number)
示例#26
0
def df_full_booking_excel():
    columns = [
        'Booking ID', 'LR Numbers', 'Shipment Date', 'Delivered Date', 'Billing Type', 'Source Office', 'Destination Office', 'From City',
        'To City', 'Customer who placed order', 'Customer who will make payment', 'Supplier Name', 'Supplier Phone',
        'Owner Name', 'Owner Phone', 'Vehicle Number', 'Driver Name', 'Driver Phone', 'Actual Weight',
        'Charged Weight to Customer', 'Charged Weight for Supplier', 'Customer Rate', 'Supplier Rate',
        'Total Amount from Customer', 'Refundable Amount', 'Deduction for Customer', 'Total Inward Amount', 'TDS',
        'Total Amount to Owner', 'Commission', 'LR Cost', 'Deduction for Advance', 'Deduction for Balance',
        'Other Deduction', 'Deduction Remarks', 'Invoice Status', 'Total Outward Amount', 'Outward Payment Remarks',
        'Invoice Number', 'Invoice Date', 'Invoice Amount', 'OPB Number', 'OPB Date', 'OPB Amount', 'POD Status', 'POD Date',
        'Customer who will make payment (Code)', 'Supplier Code', 'Customer Balance', 'Supplier Balance', 'CNCA',
        'CNC', 'CNS', 'DNS', 'DNC', 'Loading Charges', 'Unloading Charges', 'Detention Charges', 'Other Charges - Supplier',
        'Remarks about additional charges - Supplier', 'Additional Charges if any (+) - Customer',
        'Remarks for additional charges - Customer', 'Deductions / Discounts if any (-)',
        'Invoice remarks for deductions/discounts', 'Advance to Trans IQ', 'Booking Status'
    ]

    data = []
    for booking in ManualBooking.objects.filter(shipment_date__gte='2018-04-01').exclude(booking_status='cancelled').order_by('-shipment_date'):
        print('.')
        data.append([
            booking.booking_id,
            '\n'.join(booking.lr_numbers.values_list('lr_number', flat=True)),
            booking.shipment_date,
            booking.delivery_datetime if booking.delivery_datetime else '',
            booking.get_billing_type_display(),
            booking.source_office.branch.name if booking.source_office else '',
            booking.destination_office.branch.name if booking.destination_office else '',
            booking.from_city,
            booking.to_city,
            booking.company.get_name() if booking.company else '',
            booking.customer_to_be_billed_to.get_name() if booking.customer_to_be_billed_to else '',
            booking.truck_broker_owner_name,
            booking.truck_broker_owner_phone,
            booking.truck_owner_name,
            booking.truck_owner_phone,
            display_format(compare_format(booking.lorry_number)),
            booking.driver_name,
            booking.driver_phone,
            booking.loaded_weight,
            booking.charged_weight,
            booking.supplier_charged_weight,
            booking.party_rate,
            booking.supplier_rate,
            booking.total_amount_to_company,
            booking.refund_amount,
            booking.deductions_for_company,
            booking.total_in_ward_amount,
            booking.tds_deducted_amount,
            booking.total_amount_to_owner,
            booking.commission,
            booking.lr_cost,
            booking.deduction_for_advance,
            booking.deduction_for_balance,
            booking.other_deduction,
            booking.remarks_about_deduction,
            booking.get_invoice_status_display(),
            sum(booking.outward_booking.values_list('actual_amount', flat=True)),
            '\n'.join([', '.join(map(str, row)) if row else '' for row in
                       booking.outward_booking.values_list('payment_mode', 'actual_amount', 'remarks')]),
            ''.join(invoice_number if invoice_number else '' for invoice_number in
                    list(booking.invoices.values_list('invoice_number', flat=True)) +
                    list(booking.to_pay_invoices.values_list('invoice_number', flat=True))),
            ''.join([invoice_date.strftime('%d-%b-%Y') if invoice_date else '' for invoice_date in
                     list(booking.invoices.values_list('date', flat=True)) + list(
                         booking.to_pay_invoices.values_list('date', flat=True))]),
            ''.join(list(map(str, list(booking.invoices.values_list('total_amount', flat=True)))) + list(
                amount_payable_to_transiq if amount_payable_to_transiq else '' for amount_payable_to_transiq in booking.to_pay_invoices.values_list('amount_payable_to_transiq', flat=True))),
            '\n'.join(booking.outward_payment_bill.values_list('bill_number',
                                                               flat=True)) if booking.outward_payment_bill else '',
            '\n'.join([opb.bill_date.strftime('%d-%b-%Y') if opb.bill_date else '' for opb in
                       booking.outward_payment_bill.all()]),
            '\n'.join(map(str, booking.outward_payment_bill.values_list('amount',
                                                                        flat=True))) if booking.outward_payment_bill else '',
            booking.pod_status,
            booking.pod_date if booking.pod_date else '',
            booking.customer_to_be_billed_to.company_code if booking.customer_to_be_billed_to else None,
            booking.supplier.code if booking.supplier else None,
            booking.balance_for_customer,
            booking.balance_for_supplier,
            booking.adjusted_cnca_amount,
            booking.credit_amount_customer,
            booking.credit_amount_supplier,
            booking.debit_amount_supplier,
            booking.debit_amount_customer,
            booking.loading_charge,
            booking.unloading_charge,
            booking.detention_charge,
            booking.additional_charges_for_owner,
            booking.note_for_additional_owner_charges,
            booking.additional_charges_for_company,
            booking.remarks_about_additional_charges,
            booking.deductions_for_company,
            booking.invoice_remarks_for_deduction_discount,
            booking.advance_amount_from_company,
            booking.booking_status
        ])

    df = pd.DataFrame(data=data, columns=columns)
    return df