def payment_mode_date(current_datetime, bank, amount, payment_date): if not isinstance(bank, Bank) and not isinstance(payment_date, datetime): return None, payment_date if is_hdfc_bank_account(bank=bank): mode = 'hdfc_internal_account' if payment_date.weekday() == 6: payment_date = (payment_date + timedelta(days=1)) else: payment_date = payment_date elif payment_date > current_datetime: while is_neft_holiday(payment_date): payment_date = next_neft_working_day(payment_date) if is_hdfc_bank_account(bank=bank): mode = 'hdfc_internal_account' else: mode = 'neft' if to_int(amount) <= 200000 else 'rtgs' elif is_neft_hour(current_datetime): if is_hdfc_bank_account(bank=bank): mode = 'hdfc_internal_account' payment_date = current_datetime else: mode = 'neft' if to_int(amount) <= 200000 else 'rtgs' payment_date = current_datetime elif is_imps_hour(current_datetime): if is_hdfc_bank_account(bank=bank): mode = 'hdfc_internal_account' if current_datetime.weekday() == 6: payment_date = (current_datetime + timedelta(days=1)) else: payment_date = current_datetime else: if current_datetime.weekday() == 6: if is_neft_holiday(current_datetime + timedelta(days=1)): mode = 'imps' payment_date = (current_datetime + timedelta(days=1)) else: mode = 'neft' if to_int(amount) <= 200000 else 'rtgs' payment_date = (current_datetime + timedelta(days=1)) else: mode = 'imps' payment_date = current_datetime.date() elif is_neft_holiday(payment_date) and payment_date.date( ) == current_datetime.date() and current_datetime.weekday() != 6 and ( time(0, 0) <= current_datetime.time() <= time(17, 0) or is_imps_hour(current_datetime)): mode = 'imps' payment_date = current_datetime.date() else: payment_date = payment_date + timedelta(days=1) while is_neft_holiday(payment_date): payment_date = next_neft_working_day(payment_date) if is_hdfc_bank_account(bank=bank): mode = 'hdfc_internal_account' else: mode = 'neft' if to_int(amount) <= 200000 else 'rtgs' return mode, payment_date.date() if isinstance(payment_date, datetime) else payment_date
def excess_supplier_payment(): for booking in ManualBooking.objects.exclude( outward_payment_status='no_payment_made'): if to_int(booking.total_amount_to_owner) < to_int( sum( booking.outward_booking.exclude( is_refund_amount=True).values_list('actual_amount', flat=True))): pass
def parse_pending_inward_adjustment_data(data): credit_note_number = ', '.join( CreditNoteCustomer.objects.filter( id__in=[row.get('id') for row in data.get('cnc', [])]).values_list( 'credit_note_number', flat=True)) debit_note_number = ', '.join( DebitNoteCustomer.objects.filter( id__in=[row.get('id') for row in data.get('dnc', [])]).values_list( 'debit_note_number', flat=True)) pending_inward = get_or_none(PendingInwardPaymentEntry, id=data.get('payment_id', None)) bookings_id = [] inward_payments_data = [] if isinstance(pending_inward, PendingInwardPaymentEntry): for booking in data.get('bookings', []): if to_int(booking.get('amount', None)) != 0: remarks_data = [] remarks = booking.get('remarks') if booking.get( 'remarks', None) else data.get( 'common_inward_payment_remarks', None) if remarks: remarks_data.append(remarks) if credit_note_number: remarks_data.append(credit_note_number) if debit_note_number: remarks_data.append(debit_note_number) bookings_id.append(booking.get('booking_id', None)) inward_payments_data.append({ 'booking_id': [booking.get('booking_id', None)], 'received_from': pending_inward.customer.get_name() if pending_inward.customer else pending_inward.customer_name, 'actual_amount': to_int(booking.get('amount', 0)), 'tds': to_int(booking.get('tds', 0)), 'payment_mode': pending_inward.payment_mode, 'payment_date': pending_inward.payment_date, 'invoice_number': booking.get('invoice_number', None), 'trn': pending_inward.trn, 'remarks': ', '.join(remarks_data), 'created_by': data.get('username', None), 'changed_by': data.get('username', None), }) return inward_payments_data, bookings_id
def generate_invoice_satvik_girija(): from restapi.serializers.team import InvoiceSerializer df = pd.read_excel('/Users/mani/Downloads/satvik.xlsm') for i, row in df.iterrows(): booking = ManualBooking.objects.get(booking_id=row['Booking No']) sme = Sme.objects.get(name__profile__name=row['Company Name']) data = { 'invoice_number': row['Invoice No'], 'bookings': [booking.id], 'date': row['Invoice Date'].date(), 'company_name': row['Company Name'], 'customer_fk': sme.id, 'address': row['Address'], 'pin': row['pin'], 'city': row['City'], 'total_amount': to_int(row['Invoice Amt']), 'created_by': '*****@*****.**', 'changed_by': '*****@*****.**', 'gstin': None, 'service_tax_paid_by': None, 'service_tax_aaho': 0, 's3_upload': None } invoice_serializer = InvoiceSerializer(data=data) if invoice_serializer.is_valid(): invoice_serializer.save() print(invoice_serializer.errors)
def booking_id_lr_data(request): rows = to_int(request.GET.get('page')) search_value = request.GET.get('search') bookings = ManualBooking.objects.exclude( booking_status__iexact='cancelled').order_by('-id', '-shipment_date') if search_value: bookings = ManualBooking.objects.filter( Q(booking_id__icontains=search_value) | Q(id__in=LrNumber.objects.filter( lr_number__icontains=search_value).values_list( 'booking__id', flat=True))).exclude( booking_status__iexact='cancelled').order_by( '-id', '-shipment_date') data = [] for booking in bookings[:rows]: data.append({ 'id': booking.id, 'text': '{}( {} )'.format( booking.booking_id, ', '.join( booking.lr_numbers.values_list('lr_number', flat=True))) if booking.lr_numbers.exists() else booking.booking_id }) data = {'results': data} print(data) return HttpResponse(json.dumps(data), content_type='application/json')
def full_booking_id(): if datetime.today().date() < date(2018, 3, 26): try: booking = ManualBooking.objects.filter(Q(booking_id__istartswith='AH') | Q( booking_id__istartswith='AAHO')).latest('created_on') id = str(booking.booking_id) temp = to_int(id[4:]) + 1 booking_id = id[0:4] + '{0:05d}'.format(temp) except ManualBooking.DoesNotExist: booking_id = 'AAHO00001' else: try: booking = ManualBooking.objects.filter( Q(booking_id__istartswith='AH') | Q(booking_id__istartswith='AAHO')).latest('created_on') temp = to_int(booking.booking_id[4:]) + 1 booking_id = 'AH' + str(financial_year_yy(datetime.today().date())) + '{0:05d}'.format(temp) except ManualBooking.DoesNotExist: booking_id = 'AH' + str(financial_year_yy(datetime.today().date())) + '00001' return booking_id
def pending_payment_adjustment_data(data): btn_submit = data.get('accept_choice') try: payment = PendingInwardPaymentEntry.objects.get( id=data.get('payment_id')) payment.customer = get_or_none(Sme, id=data.get('customer')) payment.tds = to_int(data.get('tds')) payment.save() if isinstance(payment.customer, Sme): placed_order_accounting_summary(sme_id=payment.customer.id) billed_customer_accounting_summary(sme_id=payment.customer.id) except PendingInwardPaymentEntry.DoesNotExist: return {'msg': "Pending payment does not exists", 'status': 404} if btn_submit == 'save': return {'msg': 'customer and tds saved successful', 'status': 200} elif btn_submit == 'proceed': payment = PendingInwardPaymentEntry.objects.get( id=data.get('payment_id')) credit_note = CreditNoteCustomer.objects.filter( status__in=['approved', 'partial'], customer=payment.customer) debit_note = DebitNoteCustomer.objects.filter( status__in=['approved', 'partial'], customer=payment.customer) credit_note_direct_advance = CreditNoteCustomerDirectAdvance.objects.filter( status__in=['approved', 'partial'], customer=payment.customer) debit_note_direct_advance = DebitNoteSupplierDirectAdvance.objects.filter( status__in=['approved', 'partial'], customer=payment.customer) invoice_data, tds_amount, total_amount, tds_rate = adjust_inward_payment( payment=payment, user=get_or_none(User, username=data.get('username'))) payment = PendingInwardPaymentEntrySerializer(payment).data return { 'data': { 'payment': payment, 'invoices': invoice_data, 'total_amount': total_amount, 'tds_amount': tds_amount, 'tds_rate': tds_rate, 'credit_note': credit_note, 'debit_note': debit_note, 'credit_note_direct_advance': credit_note_direct_advance, 'debit_note_direct_advance': debit_note_direct_advance }, 'msg': 'success', 'status': 200 } else: return { 'msg': 'something went wrong, Please try later', 'status': 400, 'data': {} }
def state_data(request): states = State.objects.all() rows = to_int(request.GET.get('page')) search_value = request.GET.get('search') if search_value: states = State.objects.filter(Q(name__icontains=search_value)) data = [] for state in states.order_by('name')[:rows]: data.append({'id': state.id, 'text': '{}'.format(state.name)}) data = { 'results': data, } return HttpResponse(json.dumps(data), content_type='application/json')
def invoice_number_data(request): rows = to_int(request.GET.get('page')) search_key = request.GET.get('search') tbb_invoices = Invoice.objects.order_by('-id', '-date') if search_key: tbb_invoices = Invoice.objects.filter( invoice_number__iexact=search_key).order_by('-id', '-date') data = [] for invoice in tbb_invoices[:rows]: data.append({ 'id': invoice.invoice_number, 'text': invoice.invoice_number }) data = {'results': data} return HttpResponse(json.dumps(data), content_type='application/json')
def credit_debit_note_reason_data(request): rows = to_int(request.GET.get('page')) credit_debit_note_reasons = CreditDebitNoteReason.objects.exclude( Q(deleted=True)) search_value = request.GET.get('search') if search_value: credit_debit_note_reasons = CreditDebitNoteReason.objects.filter( name__icontains=search_value).exclude(Q(deleted=True)) data = [] for credit_debit_note_reason in credit_debit_note_reasons[:rows]: data.append({ 'id': credit_debit_note_reason.id, 'text': '{}'.format(credit_debit_note_reason.name) }) data = {'results': data} return HttpResponse(json.dumps(data), content_type='application/json')
def vehicle_categories_data(request): rows = to_int(request.GET.get('page')) search_key = request.GET.get('search') vehicle_categories = VehicleCategory.objects.all() if search_key: vehicle_categories = VehicleCategory.objects.filter( Q(vehicle_type__icontains=search_key) | Q(capacity__icontains=search_key) | Q(truck_body_type__icontains=search_key)) data = [] for vehicle_category in vehicle_categories.order_by('vehicle_type')[:rows]: data.append({ 'id': vehicle_category.id, 'text': vehicle_category.vehicle_category }) data = {'results': data} return HttpResponse(json.dumps(data), content_type='application/json')
def outward_payment_status(booking): if isinstance(booking, ManualBooking): if to_int(booking.amount_paid_to_supplier) == 0: return 'no_payment_made' elif 0 < to_int(booking.amount_paid_to_supplier) < to_int( booking.supplier_amount): return 'partial' elif to_int(booking.amount_paid_to_supplier) == to_int( booking.supplier_amount): return 'complete' elif to_int(booking.amount_paid_to_supplier) > to_int( booking.supplier_amount): return 'excess' else: return None return None
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')
def drivers_data(request): rows = to_int(request.GET.get('page')) search_value = request.GET.get('search') drivers = Driver.objects.all() if search_value: drivers = Driver.objects.filter( Q(name__icontains=search_value) | Q(phone__icontains=search_value)).exclude(Q(phone=None)) data = [] for driver in drivers.order_by('-name')[:rows]: data.append({ 'id': driver.id, 'text': '{}, {}'.format(driver.name if driver.name else '', driver.phone) }) data = {'results': data} return HttpResponse(json.dumps(data), content_type='application/json')
def broker_data(request): rows = to_int(request.GET.get('page')) brokers = Broker.objects.all() search_value = request.GET.get('search') if search_value: brokers = Broker.objects.filter( Q(name__profile__name__icontains=search_value) | Q(name__profile__phone__icontains=search_value)) data = [] for broker in brokers[:rows]: data.append({ 'id': broker.id, 'text': '{}, {}'.format(broker.get_name(), broker.get_phone()) }) data = { 'results': data } return HttpResponse(json.dumps(data), content_type='application/json')
def customers_data(request): customers = Sme.objects.all() rows = to_int(request.GET.get('page')) search_value = request.GET.get('search') if search_value: customers = Sme.objects.filter( Q(name__profile__name__icontains=search_value) | Q(company_code__iexact=search_value)) data = [] for customer in customers[:rows]: data.append({ 'id': customer.id, 'text': '{}, {}'.format(customer.get_name(), customer.company_code), }) data = {'results': data} return HttpResponse(json.dumps(data), content_type='application/json')
def employees_data(request): employees = Employee.objects.exclude(status__iexact='inactive') rows = to_int(request.GET.get('page')) search_value = request.GET.get('search') if search_value: employees = Employee.objects.filter( Q(username__profile__name__icontains=search_value) | Q(username__profile__phone__icontains=search_value)).exclude( status__iexact='inactive') data = [] for employee in employees[:rows]: data.append({ 'id': employee.id, 'text': '{}, {}'.format(employee.emp_name(), employee.emp_phone()), }) data = {'results': data} return HttpResponse(json.dumps(data), content_type='application/json')
def owners_data(request): rows = to_int(request.GET.get('page')) owners = Owner.objects.exclude(Q(name__profile__name=None)) search_value = request.GET.get('search') if search_value: owners = Owner.objects.filter( Q(name__profile__name__icontains=search_value) | Q(name__profile__name__icontains=search_value)).exclude( Q(name__profile__name=None)) data = [] for owner in owners[:rows]: data.append({ 'id': owner.id, 'text': '{}, {}'.format(owner.get_name(), owner.get_phone()) }) data = {'results': data} return HttpResponse(json.dumps(data), content_type='application/json')
def aaho_office_data(request): rows = to_int(request.GET.get('page')) search_value = request.GET.get('search') aaho_offices = AahoOffice.objects.all() if search_value: aaho_offices = AahoOffice.objects.filter( Q(branch_name__icontains=search_value) | Q(branch__name__icontains=search_value) | Q(branch__code__icontains=search_value)) data = [] for aaho_office in aaho_offices.order_by('branch_name')[:rows]: data.append({ 'id': aaho_office.id, 'text': '{}'.format(aaho_office.branch_name) }) data = { 'results': data, } return HttpResponse(json.dumps(data), content_type='application/json')
def commission_booking_id(): if datetime.today().date() < date(2018, 3, 26): try: booking = ManualBooking.objects.filter(Q(booking_id__istartswith='AB') | Q( booking_id__istartswith='BROKER')).latest('created_on') ids = str(booking.booking_id) temp = int(ids[6:]) + 1 booking_id = ids[0:6] + '{0:05d}'.format(temp) except ManualBooking.DoesNotExist: booking_id = 'BROKER00001' else: try: booking = ManualBooking.objects.filter( Q(booking_id__istartswith='BROKER') | Q(booking_id__istartswith='AB')).latest('created_on') id = str(booking.booking_id) temp = to_int(id[4:]) + 1 if booking.booking_id.startswith('AB') else int(booking.booking_id[6:]) + 1 booking_id = 'AB' + str(financial_year_yy(datetime.today().date())) + '{0:05d}'.format(temp) except ManualBooking.DoesNotExist: booking_id = 'AB' + str(financial_year_yy(datetime.today().date())) + '00001' return booking_id
def inward_payment_status(booking): if isinstance(booking, ManualBooking): if to_int(booking.amount_received_from_customer) == 0: return 'no_payment' elif 0 < to_int(booking.amount_received_from_customer ) < booking.customer_amount: return 'partial_received' elif to_int(booking.amount_received_from_customer) == to_int( booking.customer_amount): return 'full_received' elif to_int(booking.amount_received_from_customer) > to_int( booking.customer_amount): return 'excess' else: return None return None
def city_data(request): cities = City.objects.all() rows = to_int(request.GET.get('page')) search_value = request.GET.get('search') if search_value: cities = City.objects.filter( Q(name__icontains=search_value) | Q(state__name__icontains=search_value) | Q(code__icontains=search_value)) data = [] for city in cities.order_by('name')[:rows]: data.append({ 'id': city.id, 'text': '{}, {}, {}'.format(city.name, city.code, city.state.name if city.state else '') }) data = { 'results': data, } return HttpResponse(json.dumps(data), content_type='application/json')
def notify_invoice_customers_email_page(request): sme = Sme.objects.get(company_code='ACJ') invoices_data = [] number_of_shipment = 0 invoices = Invoice.objects.filter( created_on__date=(datetime.now() - timedelta(days=INVOICE_EMAIL_PERIOD)).date(), customer_fk=sme) pod_files = [] invoices_file = [] for invoice in invoices: number_of_shipment += invoice.bookings.count() invoices_data.append({ 'invoice_number': invoice.invoice_number, 'invoice_date': invoice.date.strftime('%d-%b-%Y') if invoice.date else '', 'invoice_amount': '{}'.format(format_inr(invoice.total_amount)), 'due_date': invoice.date.strftime('%d-%b-%Y') if invoice.date else '' }) if isinstance(invoice.s3_upload, S3Upload): invoices_file.append(invoice.s3_upload.public_url()) for booking in invoice.bookings.all(): for pod in booking.podfile_set.filter(verified=True, is_valid=True).all(): if isinstance(pod.s3_upload, S3Upload): pod_files.append(pod.s3_upload.public_url()) email_id_list = [] if sme.aaho_poc_email: email_id_list.append(sme.aaho_poc_email) if sme.sme_email: email_id_list.append(sme.sme_email) if sme.sme_alt_email: email_id_list.append(sme.sme_alt_email) data = { 'invoices_data': invoices_data, 'number_of_shipment': number_of_shipment, 'email_id_list': email_id_list, 'invoices_file': invoices_file, 'pod_files': pod_files, 'credit_period': to_int(sme.credit_period) } return render(request=request, template_name='team/emails/notify_invoice_customers_email.html', context=data)
def test_to_int_success(self): self.assertEqual(to_int(2), 2) self.assertEqual(to_int(3.9999), 3) self.assertEqual(to_int("21.11112"), 21) self.assertEqual(to_int(8.000001), 8) self.assertEqual(to_int("1.22313"), 1) self.assertEqual(to_int("19.00001"), 19) self.assertEqual(to_int("0.000"), 0) self.assertEqual(to_int(0.999), 0) self.assertEqual(to_int("999.9999"), 999) self.assertEqual(to_int(None), 0) self.assertEqual(to_int('None'), 0)
def test_to_int_failure(self): self.assertNotEqual(to_int('1.99999'), 2) self.assertNotEqual(to_int(None), 1) self.assertNotEqual(to_int('None'), 1)
def booking_create_data(data): customer = get_or_none(Sme, id=data.get('customer_placed_order')) source_office = get_or_none(AahoOffice, id=data.get('source_office')) destination_office = get_or_none(AahoOffice, id=data.get('destination_office')) if (isinstance(source_office, AahoOffice) and isinstance(destination_office, AahoOffice)) and ( source_office == '2' or source_office == '3' or destination_office == '2' or destination_office == '3'): is_advance = data.get('is_print_payment_mode_instruction') else: is_advance = None shipment_date = None if not data.get('shipment_datetime') or is_blank( data.get('shipment_datetime')) else datetime.strptime( data.get('shipment_datetime'), '%d-%b-%Y %I:%M %p') update_vehicles = update_vehicle( vehicle_number=data.get('vehicle_number', None), supplier_id=data.get('supplier_id', None), owner_id=data.get('truck_owner_id', None), driver_id=data.get('truck_driver_id', None), vehicle_category_id=data.get('vehicle_category_id', None), user=data.get('user', None) ) supplier = get_or_none(Supplier, id=data.get('supplier_id', None)) owner = get_or_none(Supplier, id=data.get('truck_owner_id', None)) driver = get_or_none(Driver, id=data.get('truck_driver_id', None)) vehicle = get_or_none(Vehicle, vehicle_number=compare_format(data.get('vehicle_number', None))) vehicle_type = get_or_none(VehicleCategory, id=data.get('vehicle_category_id', None)) generate_booking_and_finish = data.get('generate-booking-and-finish') if generate_booking_and_finish == 'quick_full_booking': booking_id = full_booking_id() deductions = supplier_deductions( source_office=data.get('source_office', None), destination_office=data.get('destination_office', None), supplier_charged_weight=data.get('supplier_charged_weight', None), supplier_rate=data.get('supplier_rate', None), company=data.get('customer_placed_order', None), gst_liability=data.get('gst_liability', None), supplier=data.get('supplier_id', None), ) commission = deductions['commission']['amount'] lr_cost = deductions['lr_cost']['amount'] deduction_for_advance = deductions['deduction_for_advance']['amount'] deduction_for_balance = deductions['deduction_for_balance']['amount'] amount_to_owner = to_int(data.get('total_amount_to_owner', 0)) - ( commission + lr_cost + deduction_for_advance + deduction_for_balance) elif generate_booking_and_finish == 'quick_commission_booking': booking_id = commission_booking_id() commission = 0 lr_cost = 0 deduction_for_advance = 0 deduction_for_balance = 0 amount_to_owner = to_int(data.get('total_amount_to_owner', 0)) - ( commission + lr_cost + deduction_for_advance + deduction_for_balance) elif generate_booking_and_finish == 'detailed_full_booking' or generate_booking_and_finish == 'detailed_commission_booking': if generate_booking_and_finish == 'detailed_commission_booking': booking_id = commission_booking_id() else: booking_id = full_booking_id() commission = data.get('commission') lr_cost = data.get('lr_cost') deduction_for_advance = data.get('deduction_for_advance') deduction_for_balance = data.get('deduction_for_balance') amount_to_owner = to_int(data.get('freight_owner', 0)) + ( to_int(data.get('loading_charge', 0)) + to_int(data.get('unloading_charge', 0)) + to_int( data.get('detention_charge')) + to_int( data.get('additional_charges_for_owner', 0))) - ( commission + lr_cost + deduction_for_advance + deduction_for_balance + to_int( data.get('other_deduction', 0))) else: booking_id = full_booking_id() commission = data.get('commission', 0) lr_cost = data.get('lr_cost', 0) deduction_for_advance = data.get('deduction_for_advance', 0) deduction_for_balance = data.get('deduction_for_balance', 0) amount_to_owner = to_int(data.get('total_amount_to_owner', 0)) + ( to_int(data.get('loading_charge')) + to_int(data.get('unloading_charge')) + to_int( data.get('detention_charge')) + to_int(data.get('additional_charges_for_owner'))) - ( commission + lr_cost + deduction_for_advance + deduction_for_balance) from_city = get_or_none(City, id=data.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=data.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=data.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=data.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 if get_contract_party_rate(from_city=from_city_fk, to_city=to_city_fk, customer=customer): party_rate = get_contract_party_rate(from_city=from_city_fk, to_city=to_city_fk, customer=customer) party_weight = to_float(data.get('charged_weight')) total_amount_to_party = party_rate * party_weight else: party_rate = data.get('party_rate') party_weight = to_float(data.get('charged_weight')) total_amount_to_party = data.get('total_amount_to_party', 0) data = { 'booking_id': booking_id, 'company': data.get('customer_placed_order', None), 'company_code': customer.company_code if isinstance(customer, Sme) else None, 'customer_to_be_billed_to': data.get('customer_to_be_billed', None), 'to_be_billed_to': data.get('to_be_billed_to', None), 'source_office': source_office.id if isinstance(source_office, AahoOffice) else None, 'destination_office': destination_office.id if isinstance(destination_office, AahoOffice) else None, 'supplier': data.get('supplier_id', None), 'owner_supplier': data.get('truck_owner_id', None), 'invoice_status': data.get('invoice_status', None), 'truck_broker_owner_name': supplier.name if isinstance(supplier, Supplier) else None, 'truck_broker_owner_phone': supplier.phone if isinstance(supplier, Supplier) else None, 'truck_owner_name': owner.name if isinstance(owner, Supplier) else None, 'truck_owner_phone': owner.phone if isinstance(owner, Supplier) else None, 'driver_supplier': data.get('truck_driver_id', None), 'driver_name': driver.name if isinstance(driver, Driver) else None, 'driver_phone': driver.phone if isinstance(driver, Driver) else None, 'driver_dl_number': driver.driving_licence_number if isinstance(driver, Driver) and driver.driving_licence_number else None, 'driver_dl_validity': driver.driving_licence_validity if isinstance(driver, Driver) else None, 'is_advance': data.get('is_print_payment_mode_instruction', None), 'consignor_name': data.get('consignor_name', None), 'consignor_address': data.get('consignor_address', None), 'consignor_city': consignor_city, 'consignor_city_fk': data.get('consignor_city', None), 'consignor_pin': data.get('consignor_pin', None), 'consignor_phone': data.get('consignor_phone', None), 'consignor_gstin': data.get('consignor_gstin', None), 'consignee_name': data.get('consignee_name', None), 'consignee_address': data.get('consignee_address', None), 'consignee_city': consignee_city, 'consignee_city_fk': data.get('consignee_city', None), 'consignee_pin': data.get('consignee_pin', None), 'consignee_phone': data.get('consignee_phone', None), 'consignee_gstin': data.get('consignee_gstin', None), 'party_invoice_number': data.get('party_invoice_number', None), 'party_invoice_date': data.get('party_invoice_date'), 'party_invoice_amount': to_float(data.get('party_invoice_amount')), 'road_permit_number': data.get('road_permit_number', None), 'shipment_date': shipment_date.date() if isinstance(shipment_date, datetime) else None, 'billing_type': data.get('billing_type', None), 'number_of_package': data.get('number_of_package', None), 'material': data.get('material', None), 'from_city': from_city, 'from_city_fk': data.get('from_city', None), 'to_city': to_city, 'to_city_fk': data.get('to_city', None), 'liability_of_service_tax': data.get('liability_of_service_tax', None), 'lorry_number': vehicle.vehicle_number if isinstance(vehicle, Vehicle) else None, 'vehicle': vehicle.id if isinstance(vehicle, Vehicle) else None, 'type_of_vehicle': vehicle_type.vehicle_category if vehicle_type else '', 'vehicle_category': data.get('vehicle_category_id', None), 'gst_liability': data.get('gst_liability', None), 'comments': data.get('comments', None), 'invoice_summary': data.get('invoice_summary', None), 'loading_charge': data.get('loading_charge', 0), 'unloading_charge': data.get('unloading_charge', 0), 'detention_charge': data.get('detention_charge', 0), 'additional_charges_for_owner': data.get('additional_charges_for_owner', 0), 'note_for_additional_owner_charges': data.get('note_for_additional_owner_charges', None), 'commission': commission, 'lr_cost': lr_cost, 'deduction_for_advance': deduction_for_advance, 'deduction_for_balance': deduction_for_balance, 'other_deduction': data.get('other_deduction', 0), 'remarks_about_deduction': data.get('remarks_about_deduction'), 'loaded_weight': to_float(data.get('loaded_weight')), 'supplier_charged_weight': to_float(data.get('supplier_charged_weight')), 'supplier_rate': data.get('supplier_rate'), 'total_amount_to_owner': amount_to_owner, 'charged_weight': to_float(data.get('charged_weight', 0)), 'party_rate': party_rate, 'total_amount_to_company': total_amount_to_party, 'refund_amount': data.get('refundable_amount', 0), 'additional_charges_for_company': data.get('additional_charges_for_company', 0), 'deductions_for_company': data.get('deductions_for_company', 0), 'invoice_remarks_for_deduction_discount': data.get('invoice_remarks_for_deduction_discount', None), 'advance_amount_from_company': data.get('advance_from_company', 0), 'invoice_remarks_for_additional_charges': data.get('invoice_remarks_for_additional_charges', None), 'tds_deducted_amount': data.get('tds_deducted_amount', 0), 'insurance_provider': data.get('insurance_provider', None), 'insurance_policy_number': data.get('insurance_policy_number', None), 'insured_amount': data.get('insurance_amount', 0), 'insurance_date': data.get('insurance_date', None), 'inward_payment_status': data.get('inward_payment_status', 'no_payment'), 'pod_status': data.get('pod_status', 'pending'), 'outward_payment_status': data.get('outward_payment_status', 'no_payment_made'), 'pod_date': data.get('pod_date', None), 'tds_certificate_status': data.get('tds_certificate_status', 'n'), 'invoice_number': data.get('invoice_number', None), 'insurance_risk': data.get('insurance_risk', None), 'is_insured': data.get('insured', None) == 'insured', 'consignee_cst_tin': data.get('consignee_cst_tin', None), 'billing_invoice_date': data.get('billing_invoice_date', None), 'created_by': data.get('user', None), 'changed_by': data.get('user', None), 'loading_points': data.get('loading_points', None), 'unloading_points': data.get('unloading_points', None), 'is_print_payment_mode_instruction': data.get('is_print_payment_mode_instruction', None) == 'yes' } return data
def adjust_outward_payment_adjustment_mode(payment_id, username): try: payment = OutWardPayment.objects.get(id=payment_id) booking = payment.booking_id.last() if isinstance(booking, ManualBooking): booking_supplier = booking.booking_supplier amount = to_int(payment.actual_amount) dn_amount = amount for dn in DebitNoteSupplier.objects.filter( status__in=['approved', 'partial']).exclude(deleted=True): if amount > dn.debit_amount - dn.adjusted_amount: adjusted_amount = dn.debit_amount - dn.adjusted_amount dn_amount -= dn.debit_amount - dn.adjusted_amount else: adjusted_amount = dn_amount dn.adjusted_amount += adjusted_amount if to_int(dn.debit_amount - dn.adjusted_amount) == 0: dn.status = 'adjusted' else: dn.status = 'partial' dn.save() if ManualBooking.objects.filter( booking_supplier=booking_supplier, outward_payment_status='excess').exclude( booking_status='cancelled').exclude( booking_supplier=None).exists(): for mb in ManualBooking.objects.filter( booking_supplier=booking_supplier, outward_payment_status='excess').exclude( booking_status='cancelled').exclude( booking_supplier=None).exclude(id=booking.id): if amount >= abs(mb.balance_for_supplier): adjusted_amount = mb.outward_amount - mb.total_amount_to_owner amount -= mb.outward_amount - mb.total_amount_to_owner else: adjusted_amount = amount amount = 0 if adjusted_amount > 0: payment_data = { 'booking_id': [mb.id], 'paid_to': payment.paid_to, 'tds': 0, 'actual_amount': -adjusted_amount, 'payment_mode': 'adjustment', 'remarks': payment.remarks, 'payment_date': datetime.now().date().strftime('%d-%b-%Y'), 'changed_by': username } outward_payment_serializer = OutWardPaymentSerializer( data=payment_data) if outward_payment_serializer.is_valid(): op = outward_payment_serializer.save() payment.adjusted_outward_payments.add(op) except OutWardPayment.DoesNotExist: pass except TypeError: pass
def get_today_payments(): outward = OutWardPayment.objects.filter( payment_date__lte=datetime.now().today()).exclude( bank_account=None).exclude(status__in=['paid', 'reconciled']) if outward.exists(): bank_transfer_payments(payments=outward) payment_list = [] for payment in outward: data = [] if payment.payment_mode == 'neft': mode = 'N' elif payment.payment_mode == 'rtgs': mode = 'R' elif payment.payment_mode == 'imps': mode = 'M' elif payment.payment_mode == 'hdfc_internal_account': mode = 'I' else: mode = 'I' data.append(mode) data.append(payment.bank_account.beneficiary_code[:14] if payment. bank_account else '') data.append(payment.bank_account.account_number if payment. bank_account else '') data.append(str(to_int(payment.actual_amount))) data.append(payment.bank_account.account_holder_name if payment. bank_account else '') data.append('') data.append('') data.append('') data.append('') data.append('') data.append('') data.append('') data.append('') if payment.booking_id.exclude(lr_numbers=None).exists(): booking = payment.booking_id.first() lr_number = booking.lr_numbers.all().first().lr_number narration = '{}OW{}'.format(lr_number[:12], str(payment.id).zfill(6)) else: booking = payment.booking_id.first() narration = '{}OW{}'.format(booking.booking_id[:12], str(payment.id).zfill(6)) data.append(narration[:20]) data.append('') data.append('') data.append('') data.append('') data.append('') data.append('') data.append('') data.append('') data.append(str(payment.payment_date.strftime('%d/%m/%Y'))) data.append('') data.append( payment.bank_account.ifsc if payment.bank_account else '') data.append('') data.append('') data.append('') payment_list.append(data) payment.status = 'paid' payment.save() df = pd.DataFrame(payment_list) string_io = StringIO() df.to_csv(string_io, index=False, header=False) content = string_io.getvalue() or '\n' date = timezone.now().date() new_file_name = PaymentFile.get_next_file_name(date=date) dl_url = create_payment_file(new_file_name, date, content) task = TaskEmail.objects.get(task_id=4, office_id=1) email_id_list = list( task.employee.values_list('username__profile__email', flat=True)) send_payment_file_email(filename=new_file_name, link=dl_url, to=email_id_list) return dl_url return None
def get_lr_numbers(booking, source_office, destination_office, shipment_datetime, company_code, number_of_lr, created_by): if company_code in ['IDK', 'IDR', 'IDS', 'IDL', 'IDH']: company_code = 'IDL' lr_numbers = [] date_str = shipment_datetime.strftime("%y%m%d") if isinstance(shipment_datetime, date) else '000000' for value in range(number_of_lr): if Sme.objects.filter(company_code__iexact=company_code, lr_format_type='S').exists(): lr = LrNumber.objects.filter(lr_number__istartswith=company_code).latest('id') lr_number = '{}{}{}'.format( company_code.upper(), office_code(source_office), '{0:04d}'.format( to_int(lr.lr_number[4:]) + 1 if isinstance(lr, LrNumber) and len(lr.lr_number) == 8 else 1) ) for i in range(2, 9999999): if LrNumber.objects.filter(lr_number__iexact=lr_number).exists(): lr_number = '{}{}{}'.format( company_code.upper(), office_code(source_office), '{0:04d}'.format( to_int(lr.lr_number[4:]) + i if isinstance(lr, LrNumber) and len(lr.lr_number) == 8 else 1) ) continue break else: try: lr = LrNumber.objects.filter( datetime__date=shipment_datetime, source_office=source_office ).latest('id') lr_number = '{}{}{}{}'.format( company_code.upper(), date_str, office_code(source_office), '{0:02d}'.format(to_int(lr.lr_number[10:]) + 1) ) for i in range(2, 9999999): if LrNumber.objects.filter(lr_number__iexact=lr_number).exists(): lr_number = '{}{}{}{}'.format( company_code.upper(), date_str, office_code(source_office), '{0:02d}'.format(to_int(lr.lr_number[10:]) + i) ) continue break except LrNumber.DoesNotExist: lr_number = '{}{}{}{}'.format( company_code.upper(), date_str, office_code(source_office), '01' ) lr_numbers.append(lr_number) LrNumber.objects.create( booking=booking, lr_number=lr_number, datetime=shipment_datetime, destination_office=destination_office, source_office=source_office, created_by=created_by, changed_by=created_by ) return lr_numbers
def supplier_deductions(gst_liability, supplier, source_office, destination_office, supplier_charged_weight, supplier_rate, company): freight_to_owner = to_int(to_float(supplier_charged_weight) * to_float(supplier_rate)) sme = get_or_none(Sme, id=company) company_code = sme.company_code if isinstance(sme, Sme) else None source_office_id = to_int(source_office) destination_office_id = to_int(destination_office) destination_office = get_or_none(AahoOffice, id=destination_office_id) if source_office_id == 2 and destination_office_id == 3: if gst_liability != 'exempted': try: booking = ManualBooking.objects.filter( source_office_id=2, destination_office_id=3, supplier=supplier).exclude( gst_liability='exempted').latest('created_on') except ManualBooking.DoesNotExist: booking = None data = { 'commission': { 'amount': booking.commission if booking else 0, 'editable': True if booking else True }, 'lr_cost': { 'amount': 200, 'editable': True }, 'deduction_for_advance': { 'amount': 0, 'editable': True }, 'deduction_for_balance': { 'amount': 200, 'editable': True }, } elif company_code in ['JSM', 'CNS']: try: booking = ManualBooking.objects.filter( source_office_id=2, destination_office_id=3, supplier=supplier, company_code=company_code, gst_liability='exempted').latest('created_on') except ManualBooking.DoesNotExist: booking = None data = { 'commission': { 'amount': booking.commission if booking else 0, 'editable': True if booking else True }, 'lr_cost': { 'amount': 200, 'editable': True }, 'deduction_for_advance': { 'amount': 0, 'editable': True }, 'deduction_for_balance': { 'amount': 0, 'editable': True }, } else: try: booking = ManualBooking.objects.filter( source_office_id=2, destination_office_id=3, supplier=supplier, gst_liability='exempted').latest( 'created_on') except ManualBooking.DoesNotExist: booking = None data = { 'commission': { 'amount': booking.commission if booking else 0, 'editable': True if booking else True }, 'lr_cost': { 'amount': 200, 'editable': True }, 'deduction_for_advance': { 'amount': 0, 'editable': True }, 'deduction_for_balance': { 'amount': 350, 'editable': True }, } elif source_office_id == 2 and destination_office_id == 1: data = { 'commission': { 'amount': 1000, 'editable': True }, 'lr_cost': { 'amount': 200, 'editable': True }, 'deduction_for_advance': { 'amount': 0, 'editable': True }, 'deduction_for_balance': { 'amount': 0, 'editable': True }, } elif source_office_id == 2: try: booking = ManualBooking.objects.filter( source_office_id=2, destination_office_id=destination_office.id if isinstance(destination_office, AahoOffice) else 1, supplier=supplier ).exclude(destination_office_id__in=[1, 3]).latest('created_on') except ManualBooking.DoesNotExist: booking = None data = { 'commission': { 'amount': booking.commission if booking else 0, 'editable': True if booking else True }, 'lr_cost': { 'amount': 200, 'editable': True }, 'deduction_for_advance': { 'amount': 0, 'editable': True }, 'deduction_for_balance': { 'amount': 0, 'editable': True }, } elif source_office_id == 3: data = { 'commission': { 'amount': 0, 'editable': True }, 'lr_cost': { 'amount': 200, 'editable': True }, 'deduction_for_advance': { 'amount': 0, 'editable': True }, 'deduction_for_balance': { 'amount': 200, 'editable': True }, } elif source_office_id == 1: if freight_to_owner < 10000: data = { 'commission': { 'amount': 0, 'editable': True }, 'lr_cost': { 'amount': 0, 'editable': True }, 'deduction_for_advance': { 'amount': 100, 'editable': True }, 'deduction_for_balance': { 'amount': 0, 'editable': True }, } elif 10000 <= freight_to_owner < 30000: data = { 'commission': { 'amount': 0, 'editable': True }, 'lr_cost': { 'amount': 0, 'editable': True }, 'deduction_for_advance': { 'amount': 200, 'editable': True }, 'deduction_for_balance': { 'amount': 0, 'editable': True }, } elif 30000 <= freight_to_owner < 70000: data = { 'commission': { 'amount': 0, 'editable': True }, 'lr_cost': { 'amount': 0, 'editable': True }, 'deduction_for_advance': { 'amount': 300, 'editable': True }, 'deduction_for_balance': { 'amount': 0, 'editable': True }, } else: data = { 'commission': { 'amount': 0, 'editable': True }, 'lr_cost': { 'amount': 0, 'editable': True }, 'deduction_for_advance': { 'amount': 400, 'editable': True }, 'deduction_for_balance': { 'amount': 0, 'editable': True } } else: data = { 'commission': { 'amount': 0, 'editable': True }, 'lr_cost': { 'amount': 0, 'editable': True }, 'deduction_for_advance': { 'amount': 0, 'editable': True }, 'deduction_for_balance': { 'amount': 0, 'editable': True } } return data