Пример #1
0
    def get_initial(self):
        date = self.get_object().date
        np_date = str(NepaliDate.to_nepali_date(date).strfdate("%Y-%m-%d"))

        initial_data = {'date': np_date}

        return initial_data
Пример #2
0
 def __init__(self, date, *args, **kwargs):
     '''
         date must be of type nepali_date.date.NepaliDate
     '''
     if not isinstance(date, datetime.date):
         raise ValueError("Date must be instance of datetime.date")
     date_in_bs = NepaliDate.to_nepali_date(date)
     self.np_date = date_in_bs
Пример #3
0
 def get_context_data(self, **kwargs):
     context = super(TransactionCreateView, self).get_context_data(**kwargs)
     context['member'] = self.get_member()
     query = self.get_member().transaction_set.last()
     if query is not None:
         date = query.date
         nepali_date = NepaliDate.to_nepali_date(date)
         context['last_paid_date'] = nepali_date
     return context
Пример #4
0
def term_monthly_details(request, term, vat=False): 
    opening_bals = OpeningBalance.objects.filter(term__id = term)
    opening_term = Term.objects.get(id=term)
    monthly_opening = sum(opening_bals.values_list('amount', flat=True))
    nep_start = NepaliDate.to_nepali_date(opening_term.start_date)
    nep_end = NepaliDate.to_nepali_date(opening_term.end_date)
    if NepaliDate.today()< nep_end:
        nep_end = NepaliDate.today()
    all_calendar = pd.read_csv(nepali_datetime.calendar_file.name, index_col = 0)
    
    current_year = int(nep_start.year)
    current_month = int(nep_start.month)
    i = True
    titles = []
    openings = []
    sales = []
    payments = []
    id_tags = []
    opening_dates = []
    cash_payments = []

    while (i):
        if current_month == 1:
            prev_month = 12
            prev_year = current_year - 1
        else:
            prev_month = current_month - 1
            prev_year = current_year

        
        year_calendar = all_calendar.loc[current_year]
        titles.append('%s:%s' % (current_year, year_calendar.index[current_month-1]))
        month_days = int(year_calendar[current_month-1])
        prev_month_days = int(year_calendar[prev_month-1])
        
        start_day = NepaliDate(current_year, current_month, 1).to_english_date()
        end_day = NepaliDate(current_year, current_month, month_days).to_english_date()
        opening_dates.append(start_day)
        monthly_invoices = Invoice.objects.filter(
            Q(date__gte = start_day) & Q(date__lte = end_day) 
        ).filter(is_vat=vat).prefetch_related('issued_for')
        monthly_payments = Payment.objects.filter(
            Q(date__gte=start_day) & Q(date__lte=end_day) & Q(Q(term__isnull=True) | Q(term__id=term))
        ).prefetch_related('customer')
        
        i, current_month, current_year = update_loop(i, current_month, current_year, nep_end)
        if vat:
            payments.append([])
            monthly_opening = 0
            openings.append(0)
        else:
            payments.append(monthly_payments)
            openings.append(monthly_opening)
            monthly_opening += sum(monthly_invoices.values_list('total', flat=True)) - sum(monthly_payments.values_list('amount', flat=True)) - sum(monthly_invoices.values_list('paid_amount', flat=True))
        sales.append(monthly_invoices)
        
        id_tags.append('%s%s'%(current_year, current_month))
        cash_payments.append({'amount':sum(monthly_invoices.values_list('paid_amount', flat=True)), 'date': end_day})

    context = {
        'page_title': "Monthly Summary",
        'titles':titles, 'openings': openings, 'sales': sales, 'debits':payments, 'ids': id_tags,
        'titles_ids': zip(titles, id_tags),
        'accounts': zip(id_tags, openings, opening_dates, sales, payments, titles, cash_payments), 
        "vat": vat
    }
    return render(request, 'invoice/monthly_details_term.html', context=context)
Пример #5
0
def monthly_details(request, id, term, vat=False): 
    customer = Customer.objects.get(id =id)
    opening = OpeningBalance.objects.get(term__id = term, customer = customer)
    nep_start = NepaliDate.to_nepali_date(opening.term.start_date)
    nep_end = NepaliDate.to_nepali_date(opening.term.end_date)
    if NepaliDate.today()< nep_end:
        nep_end = NepaliDate.today()
    all_calendar = pd.read_csv(nepali_datetime.calendar_file.name, index_col = 0)
    
    current_year = int(nep_start.year)
    current_month = int(nep_start.month)
    i = True
    titles = []
    openings = []
    sales = []
    payments = []
    id_tags = []
    opening_dates = []

    while (i):
        if current_month == 1:
            prev_month = 12
            prev_year = current_year - 1
        else:
            prev_month = current_month - 1
            prev_year = current_year

        
        year_calendar = all_calendar.loc[current_year]
        titles.append('%s:%s' % (current_year, year_calendar.index[current_month-1]))
        month_days = int(year_calendar[current_month-1])
        prev_month_days = int(year_calendar[prev_month-1])
        
        start_day = NepaliDate(prev_year, prev_month, prev_month_days).to_english_date()
        end_day = NepaliDate(current_year, current_month, month_days).to_english_date()
        opening_dates.append(start_day)
        monthly_opening = opening.amount + sum(opening.sales_until(start_day)) - sum(opening.payments_until(start_day))
        monthly_invoices = Invoice.objects.filter(
            Q(date__gte = start_day) & Q(date__lte = end_day) & Q(issued_for=customer)
        ).filter(is_vat=vat)
        monthly_payments = Payment.objects.filter(
            Q(date__gte=start_day) & Q(date__lte=end_day) & Q(Q(term__isnull=True) | Q(term__id=term)) & Q(customer=customer)
        )
        
        i, current_month, current_year = update_loop(i, current_month, current_year, nep_end)
        sales.append(monthly_invoices)
        if vat:
            payments.append([])
            openings.append(0)
        else:
            payments.append(monthly_payments)
            openings.append(monthly_opening)
        id_tags.append('%s%s'%(current_year, current_month))

    context = {
        'page_title': customer.name,
        'titles':titles, 'openings': openings, 'sales': sales, 'debits':payments, 'ids': id_tags,
        # 'titles_ids': zip(titles, id_tags),
        'accounts': zip(id_tags, openings, opening_dates, sales, payments, titles),
        "vat": vat
    }
    return render(request, 'invoice/monthly_details.html', context=context)
Пример #6
0
def nepali_date(value, arg):
    nepali_date = NepaliDate.to_nepali_date(value)
    formatted_nepali_date = nepali_date.strfdate(arg)
    return formatted_nepali_date
Пример #7
0
def individual_transaction_to_excel(request, member_id, start_date, end_date):
    response = HttpResponse(content_type="application/ms-excel")
    response['Content-Disposition'] = 'attachment; filename="kosh.xls"'

    wb = xlwt.Workbook(encoding='utf-8')
    ws = wb.add_sheet('Individual_Transactions')

    row_num = 0

    font_style = xlwt.XFStyle()
    font_style.font.bold = True

    member = get_object_or_404(Member, pk=member_id)

    ws.write(row_num, 0, "Member's Name", font_style)
    ws.write(row_num, 1, member.name, font_style)

    row_num += 1
    ws.write(row_num, 0, 'Number of Share', font_style)
    ws.write(row_num, 1, member.number_of_share, font_style)

    row_num += 1
    ws.write(row_num, 0, 'Total Saving', font_style)
    ws.write(row_num, 1, member.membersaving.amount, font_style)

    row_num += 1
    ws.write(row_num, 0, 'Total Loan Amount', font_style)
    ws.write(row_num, 1, member.loan.amount, font_style)

    row_num += 1
    row_num += 1

    columns = [
        'Date',
        'Previous Month Loan',
        'Monthly Saving',
        'Loan Amount Paid',
        'Interest',
        'Fine',
        'Others',
        'Total Amount Paid',
        'Remaining Loan Amount',
        'Additional Loan Amount',
        'Total Loan Amount',
    ]

    for col_num, column in enumerate(columns):
        ws.write(row_num, col_num, column, font_style)

    font_style = xlwt.XFStyle()

    from_date = datetime.strptime(start_date, '%Y-%m-%d')
    to_date = datetime.strptime(end_date, '%Y-%m-%d')
    transactions = Transaction.objects.filter(member=member,
                                              date__range=(from_date, to_date))
    members = Member.objects.all().order_by('membership_id')

    for transaction in transactions:
        transaction_nepali_date = NepaliDate.to_nepali_date(transaction.date)
        transaction_strdate_in_bs = transaction_nepali_date.strfdate(
            '%Y-%m-%d')
        row_num += 1
        ws.write(row_num, 0, transaction_strdate_in_bs, font_style)
        ws.write(row_num, 1, transaction.previous_month_loan, font_style)
        ws.write(row_num, 2, transaction.monthly_saving, font_style)
        ws.write(row_num, 3, transaction.loan_amount_paid, font_style)
        ws.write(row_num, 4, transaction.interest, font_style)
        ws.write(row_num, 5, transaction.fine, font_style)
        ws.write(row_num, 6, transaction.others, font_style)
        ws.write(row_num, 7, transaction.total_amount_paid, font_style)
        ws.write(row_num, 8, transaction.remaining_loan_amount, font_style)
        ws.write(row_num, 9, transaction.additional_loan_amount, font_style)
        ws.write(row_num, 10, transaction.total_loan_amount, font_style)

    wb.save(response)
    return response
Пример #8
0
def convert_to_nepali(date):
    en_date = datetime.datetime.strptime(date, "%Y-%m-%d").date()
    nepali_date = NepaliDate.to_nepali_date(en_date)
    return nepali_date