예제 #1
0
def all(request):
    news = News.objects.order_by('-published_at')
    business_news = Business_News.objects.order_by('-published_at')
    news_portal = News.objects.order_by('-published_at')
    covid_news = Covid_News.objects.order_by('-published_at')
    lifestyle_news = Lifestyle_News.objects.order_by('-published_at')
    tech_news = Tech_News.objects.order_by('-published_at')
    entertainment_news = Entertainment_News.objects.order_by('-published_at')
    sports_news = Sports_News.objects.order_by('-published_at')
    trending_news = Trending_News.objects.order_by('-published_at')
    advertise = Advertising.objects.order_by('-timestamp')
    nep_date = NepaliDate.today()
    now = datetime.datetime.now()

    context = {
        'news': news,
        'business_news': business_news,
        'news_portal': news_portal,
        'covid_news': covid_news,
        'lifestyle_news': lifestyle_news,
        'tech_news': tech_news,
        'entertainment_news': entertainment_news,
        'sports_news': sports_news,
        'trending_news': trending_news,
        'advertise': advertise,
        'nep_date': nep_date,
        'now': now
    }

    template = 'newsportalapp/all.html'
    return render(request, template, context)
예제 #2
0
def all(request):
    news = Lifestyle_News.objects.order_by('-published_at')
    nep_date = NepaliDate.today()
    now = datetime.datetime.now()

    context = {'news': news, 'nep_date': nep_date, 'now':now}
    template = 'lifestyle/all.html'
    return render(request, template, context)
예제 #3
0
def all(request):
    covid_news = Covid_News.objects.all()
    advertise = Advertising.objects.order_by('-timestamp')
    nep_date = NepaliDate.today()
    now = datetime.datetime.now()

    context = {'covid_news': covid_news, 'advertise': advertise, 'nep_date': nep_date, 'now':now}
    template = 'covid/all.html'
    return render(request, template, context)
예제 #4
0
def all(request):
    news = Tech_News.objects.order_by('-published_at')
    advertise = Advertising.objects.order_by('-timestamp')
    nep_date = NepaliDate.today()
    now = datetime.datetime.now()
    context = {
        'news': news,
        'advertise': advertise,
        'nep_date': nep_date,
        'now': now
    }
    template = 'tech/all.html'
    return render(request, template, context)
예제 #5
0
def single(request, slug):
    try:
        news = Covid_News.objects.get(slug=slug)
        all_news = Covid_News.objects.order_by('-published_at')[:4]
        advertise = Advertising.objects.order_by('-timestamp')
        nep_date = NepaliDate.today()
        now = datetime.datetime.now()

        context = {'news': news, 'advertise': advertise, 'all_news':all_news, 'nep_date': nep_date, 'now':now}
        template = 'covid/single.html'
        return render(request, template, context)

    except:
        raise Http404
예제 #6
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)
예제 #7
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)
import re
import os
import datetime

from nepali_date import NepaliDate

from get_event import GetPageContent
from set_event import SetSlackStatus

TODAY = NepaliDate.today().isoformat()

DOMAIN = 'www.hamropatro.com'
PATH = "/date/{0}".format(re.sub(r"\b0", "", TODAY))
TAG = 'title'

AUTHORIZATION = os.getenv('BEARER_AUTH_KEY', None)


def get_left_time():
    today_date = datetime.datetime.combine(datetime.date.today(),
                                           datetime.datetime.max.time())

    epoch = datetime.datetime.utcfromtimestamp(0)
    total_utc = (today_date - epoch).total_seconds()

    return total_utc + datetime.timedelta(hours=-5,
                                          minutes=-45).total_seconds()


def set_my_slack_status():
    page_content = GetPageContent(DOMAIN, PATH, TAG)