Exemple #1
0
def tada_result(request):
    if 'Submit' in request.GET:
       suspense = request.GET['suspense']
       departure_time_from_tcc = request.GET['departure_time_from_tcc']
       arrival_time_at_site = request.GET['arrival_time_at_site']
       departure_time_from_site= request.GET['departure_time_from_site']
       arrival_time_at_tcc= request.GET['arrival_time_at_tcc']
       tada_amount= request.GET['tada_amount']
       start_test_date=request.GET['start_test_date']
       end_test_date= request.GET['end_test_date']
       source_site= request.GET['source_site']
       testing_site= request.GET['testing_site']
       testing_staff= request.GET['testing_staff']
       obj= TaDa(suspense=suspense, departure_time_from_tcc =
            departure_time_from_tcc,arrival_time_at_site=arrival_time_at_site,
            departure_time_from_site=departure_time_from_site,
            arrival_time_at_tcc=arrival_time_at_tcc,tada_amount=tada_amount,
            start_test_date=start_test_date,end_test_date=end_test_date, 
            source_site=source_site, testing_site=testing_site,
            testing_staff=testing_staff )
       obj.save()
       i=TaDa.objects.all().aggregate(Max('id'))
       j=i['id__max']
       staff = testing_staff.split(",")
       total_cost = 0
       for person in staff:
         total_cost= total_cost + int(tada_amount)
       rupees_in_words = num2eng(total_cost)
       obj1 = TaDa.objects.filter(id=j).values('departure_time_from_tcc' ,
              'arrival_time_at_site','departure_time_from_site',
              'arrival_time_at_tcc', 'tada_amount','start_test_date',
              'end_test_date','source_site', 'testing_site','testing_staff')
       return render(request, 'suspense/tada_result.html', { 'obj':obj1, 
       'total_cost':total_cost, 'staff':staff, 'rupees_in_words':
       rupees_in_words })
Exemple #2
0
def receipt(request):
    """
    It generates a Receipt.
    """
    id = request.GET['order_id']
    voucherid = VoucherId.objects.values('purchase_order_of_session').\
    filter(purchase_order=id)[0]
    bill = Bill.objects.values('amount_received').get(purchase_order=id)
    purchase_order = PurchaseOrder.objects.values('buyer', 'date_time',\
    'delivery_address', 'mode_of_payment__method','mode_of_payment',\
    'cheque_dd_number', 'cheque_dd_date','buyer__customer__company').get(id=id)
    date = purchase_order['date_time']
    total_in_words = num2eng(bill['amount_received'])
    customer_obj = PurchaseOrder.objects.values('buyer',\
        'buyer__first_name', 'buyer__last_name','buyer__customer__title').\
    get(id = id)
    address = Customer.objects.values('address__street_address',\
    'address__city', 'address__pin', 'address__province').\
    get(user = purchase_order['buyer'])
    purchased_item = PurchasedItem.objects.values('item__category__name').\
    filter(purchase_order=id).distinct()
    header = HeaderFooter.objects.values('header').get(is_active=True)
    return render(request, 'prints/receipt.html', {\
        'receiptno': voucherid['purchase_order_of_session'],\
        'date': date, 'cost':bill, 'amount':total_in_words, 'address':address,\
        'method': purchase_order, 'buyer':customer_obj,\
        'material':purchased_item, 'header':header})
Exemple #3
0
def receipt(request):
    """
    It generates a Receipt.
    Argument:Http Request
    Return:Render Receipt
    """
    id = request.GET['order_id']
    voucherid_temp = VoucherId.objects.values('receipt_no_of_session').filter(
        purchase_order=id)[0]
    if not voucherid_temp['receipt_no_of_session']:
        today_date = datetime.date.today()
        financialsession = FinancialSession.objects.\
        values('id','session_start_date','session_end_date')
        for value in financialsession:
            start_date = value['session_start_date']
            end_date = value['session_end_date']
            if start_date <= today_date <= end_date:
                session_id = value['id']
        max_receipt_no = VoucherId.objects.filter(session=session_id).aggregate(Max('receipt_no_of_session'))
        if max_receipt_no['receipt_no_of_session__max']:
            voucherid_obj = VoucherId.objects.values('receipt_no_of_session',
                'session', 'purchase_order__date_time').filter(
                receipt_no_of_session=max_receipt_no['receipt_no_of_session__max'],
                session_id=session_id)[0]
            voucherid_obj2 = VoucherId.objects.values('receipt_no_of_session',
                'session', 'purchase_order__date_time').filter(purchase_order=id)[0]
            if voucherid_obj['session'] == voucherid_obj2['session']:
                VoucherId.objects.filter(purchase_order=id).update(
                    receipt_no_of_session=max_receipt_no['receipt_no_of_session__max']+1,
                    receipt_date=today_date)
            else:
                VoucherId.objects.filter(purchase_order=id).update(
                    receipt_no_of_session=1,receipt_date=today_date)
        else:
            VoucherId.objects.filter(purchase_order=id).update(
                receipt_no_of_session=1,receipt_date=today_date)
    voucherid = VoucherId.objects.values('purchase_order_of_session',
        'receipt_no_of_session').\
    filter(purchase_order=id)[0]
    bill = Bill.objects.values('amount_received').get(purchase_order=id)
    purchase_order = PurchaseOrder.objects.values('buyer', 'date_time',\
    'delivery_address', 'mode_of_payment__method','mode_of_payment',\
    'cheque_dd_number', 'cheque_dd_date','buyer__customer__company').get(id=id)
    date = purchase_order['date_time']
    total_in_words = num2eng(bill['amount_received'])
    customer_obj = PurchaseOrder.objects.values('buyer',\
        'buyer__first_name', 'buyer__last_name','buyer__customer__title').\
    get(id = id)
    address = Customer.objects.values('address__street_address',\
    'address__district', 'address__pin', 'address__province').\
    get(user = purchase_order['buyer'])
    purchased_item = PurchasedItem.objects.values('item__category__name').\
    filter(purchase_order=id).distinct()
    header = HeaderFooter.objects.values('header').get(is_active=True)
    return render(request, 'prints/receipt.html', {\
        'receiptno': voucherid['receipt_no_of_session'],
        'order_no':voucherid['purchase_order_of_session'],
        'date': date, 'cost':bill, 'amount':total_in_words, 'address':address,\
        'method': purchase_order, 'buyer':customer_obj,\
        'material':purchased_item, 'header':header})
Exemple #4
0
def transport_bill(request):
    if request.method == 'POST':
        form = TransportForm1(request.POST)
        if form.is_valid():

            if 'button1' in request.POST:
                vehicle_id = request.POST['vehicle_id']
                job_id = request.POST['job_id']
                kilometer = float(request.POST['kilometer'])
                date = request.POST['date']
                rate = float(request.POST['rate'])
                total = rate * kilometer
                obj = Transport(vehicle_id=vehicle_id,
                                job_id=job_id,
                                kilometer=kilometer,
                                Date=date,
                                rate=rate,
                                total=total)
                obj.save()
                temp = Transport.objects.filter(job_id=obj.job_id)
                total_amount = Transport.objects.filter(
                    job_id=obj.job_id).aggregate(Sum('total')).get(
                        'total__sum', 0.00)
                return render(
                    request, 'bills/transport_bill.html', {
                        'temp': temp,
                        'words': num2eng(total_amount),
                        'total_amount': total_amount
                    })

            else:
                vehicle_id = request.POST['vehicle_id']
                job_id = request.POST['job_id']
                kilometer = float(request.POST['kilometer'])
                date = request.POST['date']
                rate = float(request.POST['rate'])
                total = rate * kilometer
                obj = Transport(vehicle_id=vehicle_id,
                                job_id=job_id,
                                kilometer=kilometer,
                                Date=date,
                                rate=rate,
                                total=total)
                obj.save()

    else:
        form = TransportForm1()
    return render(request, 'bills/form.html', {'TransportForm': form})
Exemple #5
0
def tada_result(request):
    if 'Submit' in request.GET:
        suspense = request.GET['suspense']
        departure_time_from_tcc = request.GET['departure_time_from_tcc']
        arrival_time_at_site = request.GET['arrival_time_at_site']
        departure_time_from_site = request.GET['departure_time_from_site']
        arrival_time_at_tcc = request.GET['arrival_time_at_tcc']
        tada_amount = request.GET['tada_amount']
        start_test_date = request.GET['start_test_date']
        end_test_date = request.GET['end_test_date']
        source_site = request.GET['source_site']
        testing_site = request.GET['testing_site']
        testing_staff = request.GET['testing_staff']
        obj = TaDa(suspense=suspense,
                   departure_time_from_tcc=departure_time_from_tcc,
                   arrival_time_at_site=arrival_time_at_site,
                   departure_time_from_site=departure_time_from_site,
                   arrival_time_at_tcc=arrival_time_at_tcc,
                   tada_amount=tada_amount,
                   start_test_date=start_test_date,
                   end_test_date=end_test_date,
                   source_site=source_site,
                   testing_site=testing_site,
                   testing_staff=testing_staff)
        obj.save()
        i = TaDa.objects.all().aggregate(Max('id'))
        j = i['id__max']
        staff = testing_staff.split(",")
        total_cost = 0
        for person in staff:
            total_cost = total_cost + int(tada_amount)
        rupees_in_words = num2eng(total_cost)
        obj1 = TaDa.objects.filter(id=j).values(
            'departure_time_from_tcc', 'arrival_time_at_site',
            'departure_time_from_site', 'arrival_time_at_tcc', 'tada_amount',
            'start_test_date', 'end_test_date', 'source_site', 'testing_site',
            'testing_staff')
        return render(
            request, 'suspense/tada_result.html', {
                'obj': obj1,
                'total_cost': total_cost,
                'staff': staff,
                'rupees_in_words': rupees_in_words
            })
Exemple #6
0
def transport_bill(request):
    if request.method == 'POST':
        form = TransportForm1(request.POST)
        if form.is_valid():
           
            if 'button1' in request.POST:
                    vehicle_id = request.POST['vehicle_id']
                    job_id = request.POST['job_id']
                    kilometer = float(request.POST['kilometer'])          
                    date = request.POST['date']
                    rate = float(request.POST['rate'])
                    total = rate*kilometer
                    obj = Transport(vehicle_id=vehicle_id, job_id=job_id, 
                           kilometer=kilometer, Date=date, rate=rate, 
                           total=total) 
                    obj.save()
                    temp = Transport.objects.filter(job_id=obj.job_id)
                    total_amount = Transport.objects.filter(job_id=obj.job_id
                           ).aggregate(Sum('total')).get('total__sum', 0.00)
                    return render(request,'bills/transport_bill.html', 
                           {'temp' : temp, 'words' : num2eng(total_amount), 
                            'total_amount' : total_amount}) 

            else:
                    vehicle_id = request.POST['vehicle_id']
                    job_id = request.POST['job_id']
                    kilometer = float(request.POST['kilometer'])
                    date = request.POST['date']
                    rate = float(request.POST['rate'])
                    total = rate * kilometer
                    obj = Transport(vehicle_id=vehicle_id, job_id=job_id, 
                                    kilometer=kilometer, Date=date, rate=rate, 
                                    total=total) 
                    obj.save()
                         
    else:
        form = TransportForm1()
    return render(request, 'bills/form.html', {'TransportForm':form})         
Exemple #7
0
def quoted_bill(request):
    """
    It generates a proforma bill for the user which lists all the items,
    their quantity , subtotal and then adds it to the surcharges
    and generates the Grand total.
    Argument:Http Request
    Return:Render Proforma Bill
    """
    quoted_order_id = request.GET["quoted_order_id"]
    quoted_order = QuotedOrder.objects.filter(id=quoted_order_id)
    quoted_item = (QuotedItem.objects.filter(
        quoted_order=quoted_order_id).values(
            "item__category__name",
            "item__category",
            "item__category__unit",
            "item__category__unit__unit",
        ).order_by("item__category").distinct())
    quoted_item_obj = (QuotedItem.objects.filter(
        quoted_order=quoted_order_id).values(
            "item__name", "item__category", "qty",
            "price_per_unit").order_by("item__category"))
    cost = (QuotedItem.objects.filter(quoted_order=quoted_order_id).values(
        "price", "item__category", "item__name").order_by("item__category"))
    quoted_order_sessionid = QuotedOrderofSession.objects.filter(
        quoted_order_id=quoted_order_id).values("quoted_order_session")[0]
    bill_values = []
    for category in quoted_item:
        flag1 = 1
        list = []
        list.append(category["item__category__name"])
        item_names = []
        for item in quoted_item_obj:
            if category["item__category"] == item["item__category"]:
                if flag1 == 1:
                    item_names.append(":")
                    item_names.append(item["item__name"])
                    flag1 = 0
                else:
                    item_names.append(",")
                    item_names.append(item["item__name"])
        flag1 = 1
        item_qty = []
        for qty in quoted_item_obj:
            if category["item__category"] == qty["item__category"]:
                if flag1 == 1:
                    item_qty.append(qty["qty"])
                    flag1 = 0
                else:
                    item_qty.append(",")
                    item_qty.append(qty["qty"])
        if category["item__category__unit"]:
            item_qty.append(category["item__category__unit__unit"])
        else:
            item_qty.append("no_unit")
        flag1 = 1
        price_unit = []
        for price_per in quoted_item_obj:
            if category["item__category"] == price_per["item__category"]:
                if flag1 == 1:
                    price_unit.append(price_per["price_per_unit"])
                    flag1 = 0
                else:
                    price_unit.append(",")
                    price_unit.append(price_per["price_per_unit"])
        total = 0
        for itemcost in cost:
            if category["item__category"] == itemcost["item__category"]:
                total = total + itemcost["price"]
        list.append(item_names)
        list.append(item_qty)
        list.append(price_unit)
        list.append(total)
        bill_values.append(list)
    taxes_applied = QuotedTaxesApplied.objects.filter(
        quoted_order=quoted_order).values("surcharge", "tax", "surcharge_name",
                                          "surcharge_value")
    bill = QuotedBill.objects.values(
        "total_cost", "grand_total", "delivery_charges",
        "totalplusdelivery").get(quoted_order=quoted_order_id)
    total_cost = bill["total_cost"]
    grand_total = bill["grand_total"]
    delivery_charges = bill["delivery_charges"]
    totalplusdelivery = bill["totalplusdelivery"]
    quoted_order_obj = QuotedOrder.objects.values(
        "buyer",
        "buyer__first_name",
        "buyer__last_name",
        "reference",
        "delivery_address",
        "organisation",
        "date_time",
        "total_discount",
        "buyer__customer__title",
        "reference_date",
    ).get(id=quoted_order_id)
    total_discount = quoted_order_obj["total_discount"]
    taxes_applied_obj = QuotedTaxesApplied.objects.filter(
        quoted_order=quoted_order).aggregate(Count("id"))
    try:
        suspense_order = QuotedSuspenseOrder.objects.values(
            "distance_estimated").get(quoted_order=quoted_order_id)
        if suspense_order["distance_estimated"] == 0:
            if total_discount == 0:
                tax_count = taxes_applied_obj["id__count"] + 2
            else:
                tax_count = taxes_applied_obj["id__count"] + 3
        else:
            if total_discount == 0:
                tax_count = taxes_applied_obj["id__count"] + 4
            else:
                tax_count = taxes_applied_obj["id__count"] + 5
    except BaseException:
        if total_discount == 0:
            tax_count = taxes_applied_obj["id__count"] + 2
        else:
            tax_count = taxes_applied_obj["id__count"] + 3
    if taxes_applied_obj["id__count"] == 0:
        tax_count = tax_count + 1
    buyer = quoted_order_obj["buyer"]
    address = Customer.objects.values(
        "address__street_address",
        "address__district",
        "address__pin",
        "address__province",
    ).get(user=buyer)
    organisation_id = quoted_order_obj["organisation"]
    date = quoted_order_obj["date_time"]
    customer_obj = Customer.objects.values("company").get(user=buyer)
    admin_organisations = AdminOrganisations.objects.values(
        "pan_no", "stc_no", "gst_in").get(id=organisation_id)
    header = HeaderFooter.objects.values("header").get(is_active=True)
    footer = HeaderFooter.objects.values("footer").get(is_active=True)
    permanent_note = NoteLine.objects.values("note").filter(is_permanent=True)
    quoted_note = QuotedOrderNote.objects.values("note").filter(
        quoted_order=quoted_order_id)
    account_holder = ACCOUNT_HOLDER
    name_of_bank = NAME_OF_BANK
    branch = BRANCH
    online_account = ONLINE_ACCOUNT
    ifsc_code = IFSC_CODE
    ref_letter = YOUR_LETTER_No
    total_in_words = num2eng(grand_total)
    return render(
        request,
        "bills/quote_bill.html",
        {
            "admin_org": admin_organisations,
            "ref": quoted_order_obj,
            "date": date,
            "quoted_order": quoted_order,
            "address": address,
            "total_cost": total_cost,
            "grand_cost": grand_total,
            "taxes_applied": taxes_applied,
            "buyer": quoted_order_obj,
            "buyer_name": customer_obj,
            "site": quoted_order_obj,
            "delivery_charges": delivery_charges,
            "total_discount": total_discount,
            "tax_count": tax_count,
            "bill_values": bill_values,
            "total_in_words": total_in_words,
            "quoted_order_id": quoted_order_sessionid["quoted_order_session"],
            "header": header,
            "footer": footer,
            "permanent_note": permanent_note,
            "quoted_note": quoted_note,
            "account_holder": account_holder,
            "name_of_bank": name_of_bank,
            "branch": branch,
            "online_account": online_account,
            "ifsc_code": ifsc_code,
            "totalplusdelivery": totalplusdelivery,
            "ref_letter": ref_letter,
        },
    )
Exemple #8
0
def suspense_bill(request):
    """
    It generates a Suspense Bill for the user which lists all the items,
    their quantity , subtotal and then adds it to the surcharges
    and generates the Grand total.
    Argument:Http Request
    Return:Render Suspense Bill
    """
    id = request.GET['order_id']
    voucherid = VoucherId.objects.filter(purchase_order=id).\
    values('voucher_no', 'purchased_item__item__category', 'session').distinct()
    suspenseorder = SuspenseOrder.objects.values('voucher', 'session_id',\
        'distance_estimated').filter(purchase_order=id)
    rate = Surcharge.objects.values('value').\
        filter(tax_name = 'Transportation')[0]
    for distance_temp in suspenseorder:
        distance = distance_temp['distance_estimated'] * rate['value']
        distance_temp['distance_estimated'] = distance
    purchased_item = PurchasedItem.objects.filter(\
        purchase_order=id).values('item__category__name',\
        'item__category','item__category__parent__name').\
        order_by('item__category').distinct()
    purchased_item_obj = PurchasedItem.objects.filter(\
        purchase_order=id).values('item__name', 'item__category',\
        'qty', 'price_per_unit').order_by('item__category')
    cost = PurchasedItem.objects.filter(purchase_order=id).\
    values('price', 'item__category', 'item__name',\
        'item__category__parent__name').order_by('item__category')
    bill = Bill.objects.values('totalplusdelivery','grand_total').get(purchase_order=id)
    bill_values = []
    field_check = 1
    for category in purchased_item:
        flag1 = 1
        list = []
        list.append(category['item__category__name'])
        item_names = []
        for item in purchased_item_obj:
            if category['item__category'] == item['item__category']:
                if flag1 == 1:
                    item_names.append(':')
                    item_names.append(item['item__name'])
                    flag1 = 0
                else:
                    item_names.append(',')
                    item_names.append(item['item__name'])
        flag1 = 1
        total=0
        for itemcost in cost:
            if category['item__category'] == itemcost['item__category']:
                total = total + itemcost['price']
        for voucher_obj in voucherid:
            if category['item__category'] == voucher_obj['purchased_item__item__category']:
                try:
                    suspense_obj = SuspenseOrder.objects.values(\
                        'distance_estimated').get(\
                        voucher=voucher_obj['voucher_no'],\
                        session_id=voucher_obj['session'])
                    total = total + suspense_obj['distance_estimated'] * rate['value']
                except:
                    pass
        list.append(item_names)
        list.append(int(total))
        bill_values.append(list)
    taxes_applied = TaxesApplied.objects.\
    filter(purchase_order=id).values('surcharge', 'tax')
    taxes_applied_obj = TaxesApplied.objects.\
    filter(purchase_order=id).aggregate(Count('id'))
    surcharge = Surcharge.objects.values('id', 'tax_name', 'value')
    totalplusdelivery = bill['totalplusdelivery']
    grand_total = bill['grand_total']
    purchase_order_obj = PurchaseOrder.objects.values('buyer',\
        'buyer__first_name', 'buyer__last_name', 'reference','reference_date',\
        'delivery_address', 'organisation', 'date_time', 'total_discount',\
        'buyer__customer__title').get(id = id)
    taxes_applied_obj = TaxesApplied.objects.\
    filter(purchase_order=id).aggregate(Count('id'))
    buyer = purchase_order_obj['buyer']
    address = Customer.objects.values('address__street_address',\
    'address__district', 'address__pin', 'address__province').get(user=buyer)
    organisation_id = purchase_order_obj['organisation']
    date = purchase_order_obj['date_time']
    customer_obj = Customer.objects.values('company').get(user=buyer)
    admin_organisations = AdminOrganisations.objects.values('pan_no',\
        'stc_no').get(id=organisation_id)
    voucherid = VoucherId.objects.values('purchase_order_of_session').\
    filter(purchase_order=id)[0]
    total_in_words=num2eng(grand_total)
    ref_letter = _YOUR_LETTER_No
    header = HeaderFooter.objects.values('header').get(is_active=True)
    footer = HeaderFooter.objects.values('footer').get(is_active=True)
    return render(request, 'prints/suspense_bill.html', {\
        'stc_no' : admin_organisations, 'pan_no' : admin_organisations,\
        'id':voucherid['purchase_order_of_session'], 'ref':purchase_order_obj,\
        'date':date, 'address':address,\
        'grand_cost':grand_total,\
        'taxes_applied':taxes_applied, 'surcharge':surcharge,\
        'buyer':purchase_order_obj, 'buyer_name':customer_obj,\
        'site':purchase_order_obj,\
        'bill_values':bill_values, 'header':header, 'footer': footer,\
        'totalplusdelivery':totalplusdelivery,\
        'total_in_words':total_in_words, 'ref_letter':ref_letter})
Exemple #9
0
def transportbill(request):
    if request.method == 'POST':
        form = TransportForm1(request.POST)
        if form.is_valid():
            if not 'session' in request.POST:
                HttpResponseRedirect(\
                    reverse("librehatti.suspense.views.sessionselect"))
            session = FinancialSession.objects.\
            get(id=request.POST['session'])
            voucher = request.POST['voucher']
            date_of_generation = request.POST['Date_of_generation']
            vehicle = Vehicle.objects.get(id=request.POST['Vehicle'])
            kilometers_list = simplejson.dumps(\
                request.POST.getlist("kilometer"))
            kilometers = json.loads(kilometers_list)
            dated = simplejson.dumps(request.POST.getlist("date"))
            date = json.loads(dated)
            rate_object = Surcharge.objects.filter(\
                tax_name='transportation').values('value')[0]
            rate = int(rate_object['value'])
            distance = 0
            for temp_var in kilometers:
                distance = distance + int(temp_var)
            total = rate * distance
            suspense_object = SuspenseOrder.objects.filter(voucher=voucher,\
            session_id=session).update(is_cleared=0)
            try:
                if Transport.objects.filter(voucher_no=voucher).exists():
                    Transport.objects.filter(voucher_no = voucher).\
                    update(vehicle=vehicle,kilometer=kilometers ,\
                    date_of_generation=date_of_generation, total = total,\
                    date=date, rate=rate, voucher_no=voucher,\
                    session=session)
                else:
                    obj = Transport(vehicle=vehicle, kilometer=kilometers,\
                    date_of_generation=date_of_generation, total=total,\
                    date=date, rate=rate, voucher_no=voucher,\
                    session=session)
                    obj.save()
            except:
                pass 
            temp = Transport.objects.filter(voucher_no=voucher).values()
            total_amount = Transport.objects.filter(voucher_no=voucher).\
            aggregate(Sum('total')).get('total__sum', 0.00)
            zipped_data = zip(date, kilometers)
            transport_total = [] 
            for date_var,kilometers_var in zipped_data:
                cal_total = rate * int(kilometers_var)
                transport_total.append(cal_total)
            zip_data = zip(date, kilometers, transport_total)
            header = HeaderFooter.objects.values('header').\
            get(is_active=True)
            footer = HeaderFooter.objects.values('footer').\
            get(is_active=True)
            request_status = request_notify()
            session_id = session.id
            return render(request, 'suspense/transport_summary.html',
                   {'words':num2eng(total_amount), 'total':total,
                   'header':header, 'kilometers':kilometers, 'rate':rate,\
                   'date':date, "voucherid":voucher, "temp":temp,\
                   'zip_data':zip_data, 'total_amount':total_amount,\
                   'date_of_generation':date_of_generation,\
                   'vehicle':vehicle,'request':request_status,\
                   'session':session_id})
        else:
            message = " Fields are mandatory"
            session = request.POST['session']
            voucher = request.POST['voucher']
            object = SuspenseOrder.objects.filter(session_id=session).\
            filter(voucher=voucher).values()
            if object:
                TransportForm = TransportForm1(request.POST)
                message = " Fields are mandatory"
                request_status = request_notify()
                temp = {"TransportForm":TransportForm, "session":session,\
                "voucher":voucher, "message":message, 'request':request_status}
                return render(request, 'suspense/transportform.html', temp)
    else:
        form = SessionSelectForm()
        request_status = request_notify()
        temp = {"SelectForm":form,'request':request_status}
        return render(request, 'voucher/sessionselect.html', temp)
Exemple #10
0
def voucher_print(request):
    number = request.GET['voucher_no']
    session = request.GET['session']
    purchase_order_id = request.GET['purchase_order']
    flag = 0
    voucherid = VoucherId.objects.values('voucher_no').\
    filter(purchase_order = purchase_order_id)
    for value in voucherid:
        try:
            suspense_order = SuspenseOrder.objects.\
            get(voucher = value['voucher_no'],\
             purchase_order = purchase_order_id)
            flag = 1
        except:
            continue
    calculatedistribution = CalculateDistribution.objects.\
    values('college_income_calculated', 'admin_charges_calculated',\
    'consultancy_asset', 'development_fund', 'total').\
    get(voucher_no = number, session = session)
    total_in_words = num2eng(calculatedistribution['total'])
    voucherid = VoucherId.objects.values('purchase_order', 'ratio',\
    'college_income', 'admin_charges', 'distribution__name',\
    'purchased_item__item__category__name',\
    'purchased_item__item__category__parent__parent').\
    filter(voucher_no = number, session = session)[0]
    purchase_order = voucherid['purchase_order']
    distribution = voucherid['distribution__name']
    ratio = voucherid['ratio']
    college_income = voucherid['college_income']
    admin_charges = voucherid['admin_charges']
    category_name = voucherid['purchased_item__item__category__name']
    lab_id = voucherid['purchased_item__item__category__parent__parent']
    emp = Staff.objects.values('name','position__position').filter(lab=lab_id).\
    order_by('position__rank')
    purchase_order_obj = PurchaseOrder.objects.\
    values('date_time', 'buyer','buyer__first_name','buyer__last_name',\
    'tds','buyer__customer__title','buyer__customer__company').\
    get(id = purchase_order)
    address = Customer.objects.values('address__street_address',\
    'address__city', 'address__pin', 'address__province').\
    get(user = purchase_order_obj['buyer'])
    date = purchase_order_obj['date_time']
    bill = Bill.objects.values('delivery_charges','total_cost',\
        'grand_total','amount_received','totalplusdelivery').\
    get(purchase_order = purchase_order_id)
    amount_received_inwords = num2eng(bill['amount_received'])
    taxes_applied = TaxesApplied.objects.values('surcharge__tax_name',\
        'surcharge__value','tax').filter(purchase_order = purchase_order_id)
    voucheridobj = VoucherId.objects.values('purchase_order_of_session',
        'purchase_order__mode_of_payment__method').\
    filter(purchase_order=purchase_order_id)[0]
    header = HeaderFooter.objects.values('header').get(is_active=True)
    footer = HeaderFooter.objects.values('footer').get(is_active=True)
    if flag == 0:
        return render(request, 'voucher/voucher_report.html', {\
            'calculate_distribution' : calculatedistribution,\
            'admin_charges': admin_charges, 'college_income': college_income, \
            'ratio':ratio,'d_name': distribution,\
            'purchase_order': voucheridobj['purchase_order_of_session'],\
            'voucher':number, 'date': date,'address': address,\
            'buyer': purchase_order_obj, 'material': category_name,\
            'total_in_words': total_in_words, 'employee' : emp,\
             'header': header})
    else:
        return render(request, 'voucher/voucher_report_suspence.html',{
            'address':address, 'cost':bill, 'inwords':amount_received_inwords,\
            'date':date, 'suspense_voucher':number,\
            'job':voucheridobj['purchase_order_of_session'],\
            'tds':purchase_order_obj, 'tax':taxes_applied, 'header': header,\
            'material':category_name, 'buyer': purchase_order_obj,
            'method':voucheridobj['purchase_order__mode_of_payment__method']})
Exemple #11
0
def with_transport(request):
    number = request.GET['voucher_no']
    session = request.GET['session']
    financialsession = FinancialSession.objects.values('id').\
    get(id=session)
    try:
        transport = Transport.objects.values('total').get(voucher_no=number,\
            session=financialsession['id'])
        transport_total = transport['total']
    except:
        transport_total = 0
    try:
        tada = TaDa.objects.values('tada_amount').get(voucher_no=number,\
            session=financialsession['id'])
        tada_amount = tada['tada_amount']
    except:
        tada_amount = 0
    suspenseclearance = SuspenseClearance.objects.values('work_charge',\
    'labour_charge', 'car_taxi_charge', 'boring_charge_internal',\
    'boring_charge_external', 'lab_testing_staff', 'field_testing_staff',\
    'test_date', 'clear_date').\
    get(voucher_no=number, session=financialsession['id'])
    othercharge = transport_total + suspenseclearance['labour_charge'] +\
    suspenseclearance['car_taxi_charge'] +\
    suspenseclearance['boring_charge_external']
    boring_charge_internal = suspenseclearance['boring_charge_internal']
    lab_staff_list = suspenseclearance['lab_testing_staff'].split(',')
    lab_staff_name_list = []
    for lab_staff_value in lab_staff_list:
        lab_temp = []
        lab_staff_obj = Staff.objects.values('name', 'position').\
        filter(code=lab_staff_value)[0]
        lab_temp.append(lab_staff_obj['name'])
        lab_temp.append(lab_staff_obj['position'])
        lab_staff_name_list.append(lab_temp)
    field_staff_list = suspenseclearance['field_testing_staff'].split(',')
    field_staff_name_list = []
    for field_staff_value in field_staff_list:
        field_temp = []
        field_staff_obj = Staff.objects.values('name','position').\
        filter(code=field_staff_value)[0]
        field_temp.append(field_staff_obj['name'])
        field_temp.append(field_staff_obj['position'])
        field_staff_name_list.append(field_temp)
    ta_da_total = tada_amount
    voucherid = VoucherId.objects.values('ratio', 'purchase_order_of_session',\
    'purchase_order__date_time', 'purchase_order__buyer__first_name',\
    'purchase_order__buyer__last_name', 'purchase_order__mode_of_payment',\
    'purchase_order__buyer__customer__address__street_address',\
    'purchase_order__buyer__customer__address__city',\
    'purchase_order__buyer__customer__address__pin',\
    'purchase_order__buyer__customer__address__province','college_income',\
    'admin_charges', 'purchase_order__cheque_dd_number',\
    'purchase_order__cheque_dd_date','purchase_order__mode_of_payment__method',\
    'purchase_order__buyer__customer__title').filter(voucher_no=number,\
    session=financialsession['id'])[0]
    distribution = Distribution.objects.values('name').\
    get(ratio=voucherid['ratio'])
    calculate_distribution = CalculateDistribution.objects.\
    values('college_income_calculated', 'admin_charges_calculated',\
    'consultancy_asset', 'development_fund', 'total').\
    get(voucher_no=number, session=financialsession['id'])
    total = calculate_distribution['total'] + othercharge + ta_da_total +\
    suspenseclearance['work_charge'] + boring_charge_internal
    total_in_words = num2eng(total)
    rowspan = 9
    header = HeaderFooter.objects.values('header').get(is_active=True)
    return render(request,'suspense/with_transport.html', {'header':header,\
                'voucher_no':number, 'date':suspenseclearance['clear_date'],\
                'calculate_distribution':calculate_distribution,\
                'suspense_clearance':suspenseclearance,\
                'field_staff':field_staff_name_list,\
                'lab_staff':lab_staff_name_list, 'ratio':voucherid['ratio'],\
                'distribution':distribution['name'],\
                'purchase_order':voucherid['purchase_order_of_session'],\
                'order_date':voucherid['purchase_order__date_time'],\
                'address':voucherid, 'ta_da':ta_da_total,\
                'othercharge':othercharge, 'total':total,\
                'total_in_words':total_in_words,\
                'test_date':suspenseclearance['test_date'],\
                'charges':voucherid, 'rowspan':rowspan, 'payment':voucherid})
Exemple #12
0
def voucher_print(request):
    """
    This function displays a particular voucher
    Argument:Http Request
    Return:Render Voucher 
    """
    number = request.GET['voucher_no']
    session = request.GET['session']
    purchase_order_id = request.GET['purchase_order']
    flag = 0
    suspense_order = SuspenseOrder.objects.filter(voucher = number,
        purchase_order = purchase_order_id)
    if suspense_order:
        flag = 1
    calculatedistribution = CalculateDistribution.objects.\
    values('college_income_calculated', 'admin_charges_calculated',\
    'consultancy_asset', 'development_fund', 'total').\
    get(voucher_no = number, session = session)
    total_in_words = num2eng(calculatedistribution['total'])
    voucherid = VoucherId.objects.values('purchase_order', 'ratio',\
    'college_income', 'admin_charges', 'distribution__name',\
    'purchased_item__item__category__name',\
    'purchased_item__item__category__parent__parent',
    'purchased_item__item__category__parent').\
    filter(voucher_no = number, session = session)[0]
    purchase_order = voucherid['purchase_order']
    distribution = voucherid['distribution__name']
    ratio = voucherid['ratio']
    college_income = voucherid['college_income']
    admin_charges = voucherid['admin_charges']
    category_name = voucherid['purchased_item__item__category__name']
    lab_id = voucherid['purchased_item__item__category__parent__parent']
    lab_id_level_down = voucherid['purchased_item__item__category__parent']
    emp = Staff.objects.values('name','position__position').filter(lab=lab_id).\
    filter(always_included=1).order_by('position__rank','-seniority_credits')
    if emp:
        pass
    else:
        emp = Staff.objects.values('name','position__position').filter(
            lab=lab_id_level_down).filter(always_included=1).order_by(
            'position__rank','-seniority_credits')
    purchase_order_obj = PurchaseOrder.objects.\
    values('date_time', 'buyer','buyer__first_name','buyer__last_name',\
    'tds','buyer__customer__title','buyer__customer__company').\
    get(id = purchase_order)
    address = Customer.objects.values('address__street_address',\
    'address__district', 'address__pin', 'address__province').\
    get(user = purchase_order_obj['buyer'])
    date = purchase_order_obj['date_time']
    bill = Bill.objects.values('delivery_charges','total_cost',\
        'grand_total','amount_received','totalplusdelivery').\
    get(purchase_order = purchase_order_id)
    amount_received_inwords = num2eng(bill['amount_received'])
    taxes_applied = TaxesApplied.objects.values('surcharge__tax_name',\
        'surcharge__value','tax').filter(purchase_order = purchase_order_id)
    voucheridobj = VoucherId.objects.values('purchase_order_of_session',
        'purchase_order__mode_of_payment__method',
        'purchase_order__cheque_dd_number','purchase_order__cheque_dd_date',
        'purchase_order__mode_of_payment').\
    filter(purchase_order=purchase_order_id)[0]
    header = HeaderFooter.objects.values('header').get(is_active=True)
    footer = HeaderFooter.objects.values('footer').get(is_active=True)
    if flag == 0:
        return render(request, 'voucher/voucher_report.html', {\
            'calculate_distribution' : calculatedistribution,\
            'admin_charges': admin_charges, 'college_income': college_income, \
            'ratio':ratio,'d_name': distribution,\
            'purchase_order': voucheridobj['purchase_order_of_session'],\
            'voucher':number, 'date': date,'address': address,\
            'buyer': purchase_order_obj, 'material': category_name,\
            'total_in_words': total_in_words, 'employee' : emp,\
             'header': header})
    else:
        return render(request, 'voucher/voucher_report_suspence.html',{
            'address':address, 'cost':bill, 'inwords':amount_received_inwords,\
            'date':date, 'suspense_voucher':number,\
            'job':voucheridobj['purchase_order_of_session'],\
            'tds':purchase_order_obj, 'tax':taxes_applied, 'header': header,\
            'material':category_name, 'buyer': purchase_order_obj,
            'method':voucheridobj['purchase_order__mode_of_payment__method'],
            'method_number':voucheridobj['purchase_order__cheque_dd_number'],
            'method_date':voucheridobj['purchase_order__cheque_dd_date'],
            'method_id':voucheridobj['purchase_order__mode_of_payment']})
Exemple #13
0
def quoted_bill(request):
    """
    It generates a proforma bill for the user which lists all the items,
    their quantity , subtotal and then adds it to the surcharges
    and generates the Grand total.
    Argument:Http Request
    Return:Render Proforma Bill
    """
    quoted_order_id = request.GET['quoted_order_id']
    quoted_order = QuotedOrder.objects.filter(id=quoted_order_id)
    quoted_item = QuotedItem.objects.filter(quoted_order=quoted_order_id).\
    values('item__category__name', 'item__category', 'item__category__unit',
        'item__category__unit__unit').\
    order_by('item__category').distinct()
    quoted_item_obj = QuotedItem.objects.filter(quoted_order=quoted_order_id).\
    values('item__name',\
    'item__category', 'qty', 'price_per_unit').order_by('item__category')
    cost = QuotedItem.objects.filter(quoted_order=quoted_order_id).\
    values('price', 'item__category', 'item__name').order_by('item__category')
    quoted_order_sessionid = QuotedOrderofSession.objects.filter\
    (quoted_order_id=quoted_order_id).values('quoted_order_session')[0]
    bill_values = []
    for category in quoted_item:
        flag1 = 1
        list = []
        list.append(category['item__category__name'])
        item_names = []
        for item in quoted_item_obj:
            if category['item__category'] == item['item__category']:
                if flag1 == 1:
                    item_names.append(':')
                    item_names.append(item['item__name'])
                    flag1 = 0
                else:
                    item_names.append(',')
                    item_names.append(item['item__name'])
        flag1 = 1
        item_qty = []
        for qty in quoted_item_obj:
            if category['item__category'] == qty['item__category']:
                if flag1 == 1:
                    item_qty.append(qty['qty'])
                    flag1 = 0
                else:
                    item_qty.append(',')
                    item_qty.append(qty['qty'])
        if category['item__category__unit']:
            item_qty.append(category['item__category__unit__unit'])
        else:
            item_qty.append('no_unit')
        flag1 = 1
        price_unit = []
        for price_per in quoted_item_obj:
            if category['item__category'] == price_per['item__category']:
                if flag1 == 1:
                    price_unit.append(price_per['price_per_unit'])
                    flag1 = 0
                else:
                    price_unit.append(',')
                    price_unit.append(price_per['price_per_unit'])
        total = 0
        for itemcost in cost:
            if category['item__category'] == itemcost['item__category']:
                total = total + itemcost['price']
        list.append(item_names)
        list.append(item_qty)
        list.append(price_unit)
        list.append(total)
        bill_values.append(list)
    taxes_applied = QuotedTaxesApplied.objects.\
    filter(quoted_order=quoted_order).values('surcharge', 'tax', 'surcharge_name',
        'surcharge_value')
    taxes_applied_obj = QuotedTaxesApplied.objects.\
    filter(quoted_order=quoted_order).aggregate(Count('id'))
    bill = QuotedBill.objects.values('total_cost', 'grand_total',\
        'delivery_charges', 'totalplusdelivery').get(quoted_order=quoted_order_id)
    total_cost = bill['total_cost']
    grand_total = bill['grand_total']
    delivery_charges = bill['delivery_charges']
    totalplusdelivery = bill['totalplusdelivery']
    quoted_order_obj = QuotedOrder.objects.values('buyer','buyer__first_name',\
        'buyer__last_name','reference','delivery_address','organisation',\
        'date_time','total_discount','buyer__customer__title',\
        'reference_date').get(id = quoted_order_id)
    total_discount = quoted_order_obj['total_discount']
    taxes_applied_obj = QuotedTaxesApplied.objects.\
    filter(quoted_order=quoted_order).aggregate(Count('id'))
    try:
        suspense_order = QuotedSuspenseOrder.objects.\
        values('distance_estimated').get(quoted_order=quoted_order_id)
        if suspense_order['distance_estimated'] == 0:
            if total_discount == 0:
                tax_count = taxes_applied_obj['id__count'] + 2
            else:
                tax_count = taxes_applied_obj['id__count'] + 3
        else:
            if total_discount == 0:
                tax_count = taxes_applied_obj['id__count'] + 4
            else:
                tax_count = taxes_applied_obj['id__count'] + 5
    except:
        if total_discount == 0:
            tax_count = taxes_applied_obj['id__count'] + 2
        else:
            tax_count = taxes_applied_obj['id__count'] + 3
    if taxes_applied_obj['id__count'] == 0:
        tax_count = tax_count + 1
    buyer = quoted_order_obj['buyer']
    address = Customer.objects.values('address__street_address',\
    'address__district', 'address__pin', 'address__province').get(user=buyer)
    organisation_id = quoted_order_obj['organisation']
    date = quoted_order_obj['date_time']
    customer_obj = Customer.objects.values('company').get(user=buyer)
    admin_organisations = AdminOrganisations.objects.values('pan_no',\
        'stc_no').get(id = organisation_id)
    header = HeaderFooter.objects.values('header').get(is_active=True)
    footer = HeaderFooter.objects.values('footer').get(is_active=True)
    permanent_note = NoteLine.objects.values('note').filter(is_permanent=True)
    quoted_note = QuotedOrderNote.objects.values('note').\
    filter(quoted_order=quoted_order_id)
    account_holder = _ACCOUNT_HOLDER
    name_of_bank = _NAME_OF_BANK
    branch = _BRANCH
    online_account = _ONLINE_ACCOUNT
    ifsc_code = _IFSC_CODE
    ref_letter = _YOUR_LETTER_No
    total_in_words = num2eng(grand_total)
    return render(request, 'bills/quote_bill.html', {
        'stc_no':admin_organisations,'pan_no':admin_organisations,\
        'ref':quoted_order_obj, 'date':date,\
        'quoted_order':quoted_order, 'address':address,\
        'total_cost': total_cost, 'grand_cost':grand_total,\
        'taxes_applied': taxes_applied,\
        'buyer':quoted_order_obj, 'buyer_name':customer_obj,\
        'site': quoted_order_obj, 'delivery_charges':delivery_charges,\
        'total_discount':total_discount, 'tax_count':tax_count,\
        'bill_values':bill_values, 'total_in_words':total_in_words,\
        'quoted_order_id':quoted_order_sessionid['quoted_order_session'],\
        'header':header,'footer':footer, 'permanent_note':permanent_note,\
        'quoted_note':quoted_note, 'account_holder':account_holder,\
        'name_of_bank':name_of_bank, 'branch':branch,\
        'online_account':online_account, 'ifsc_code':ifsc_code,\
        'totalplusdelivery':totalplusdelivery, 'ref_letter':ref_letter})
Exemple #14
0
def bill(request):
    """
    It generates a bill for the user which lists all the items,
    their quantity , subtotal and then adds it to the surcharges
    and generates the Grand total.
    Argument:Http Request
    Return:Render Bill
    """
    id = request.GET["order_id"]
    purchase_order = PurchaseOrder.objects.filter(id=id)
    purchased_item = (PurchasedItem.objects.filter(
        purchase_order__in=purchase_order).values(
            "item__category__name",
            "item__category",
            "item__category__parent__name",
            "item__category__unit",
            "item__category__unit__unit",
        ).order_by("item__category").distinct())
    purchased_item_obj = (PurchasedItem.objects.filter(
        purchase_order__in=purchase_order).values(
            "item__name", "item__category", "qty",
            "price_per_unit").order_by("item__category"))
    cost = (PurchasedItem.objects.filter(
        purchase_order__in=purchase_order).values(
            "price",
            "item__category",
            "item__name",
            "item__category__parent__name",
        ).order_by("item__category"))
    bill_values = []
    for category in purchased_item:
        flag1 = 1
        list = []
        list.append(category["item__category__name"])
        item_names = []
        for item in purchased_item_obj:
            if category["item__category"] == item["item__category"]:
                if flag1 == 1:
                    item_names.append(":")
                    item_names.append(item["item__name"])
                    flag1 = 0
                else:
                    item_names.append(",")
                    item_names.append(item["item__name"])
        flag1 = 1
        item_qty = []
        for qty in purchased_item_obj:
            if category["item__category"] == qty["item__category"]:
                if flag1 == 1:
                    item_qty.append(qty["qty"])
                    flag1 = 0
                else:
                    item_qty.append(",")
                    item_qty.append(qty["qty"])
        if category["item__category__unit"]:
            item_qty.append(category["item__category__unit__unit"])
        else:
            item_qty.append("no_unit")
        flag1 = 1
        price_unit = []
        for price_per in purchased_item_obj:
            if category["item__category"] == price_per["item__category"]:
                if flag1 == 1:
                    price_unit.append(price_per["price_per_unit"])
                    flag1 = 0
                else:
                    price_unit.append(",")
                    price_unit.append(price_per["price_per_unit"])
        total = 0
        for itemcost in cost:
            if category["item__category"] == itemcost["item__category"]:
                total = total + itemcost["price"]
        list.append(item_names)
        list.append(item_qty)
        list.append(price_unit)
        list.append(total)
        bill_values.append(list)
    taxes_applied = TaxesApplied.objects.filter(
        purchase_order__in=purchase_order).values("surcharge", "tax",
                                                  "surcharge_name",
                                                  "surcharge_value")
    TaxesApplied.objects.filter(purchase_order__in=purchase_order).aggregate(
        Count("id"))
    bill = Bill.objects.values("total_cost", "totalplusdelivery",
                               "grand_total",
                               "delivery_charges").get(purchase_order=id)
    total_cost = bill["total_cost"]
    totalplusdelivery = bill["totalplusdelivery"]
    grand_total = bill["grand_total"]
    delivery_charges = bill["delivery_charges"]
    purchase_order_obj = PurchaseOrder.objects.values(
        "buyer",
        "buyer__first_name",
        "buyer__last_name",
        "reference",
        "reference_date",
        "delivery_address",
        "organisation",
        "date_time",
        "total_discount",
        "buyer__customer__title",
    ).get(id=id)
    total_discount = purchase_order_obj["total_discount"]
    taxes_applied_obj = TaxesApplied.objects.filter(
        purchase_order__in=purchase_order).aggregate(Count("id"))
    suspense_order = SuspenseOrder.objects.values("distance_estimated").filter(
        purchase_order=id)
    total_distance = 0
    if suspense_order:
        for distance in suspense_order:
            total_distance = total_distance + distance["distance_estimated"]
        if total_distance == 0:
            if total_discount == 0:
                tax_count = taxes_applied_obj["id__count"] + 2
            else:
                tax_count = taxes_applied_obj["id__count"] + 3
        else:
            if total_discount == 0:
                tax_count = taxes_applied_obj["id__count"] + 4
            else:
                tax_count = taxes_applied_obj["id__count"] + 5
    else:
        if total_discount == 0:
            tax_count = taxes_applied_obj["id__count"] + 2
        else:
            tax_count = taxes_applied_obj["id__count"] + 3
    if taxes_applied_obj["id__count"] == 0:
        tax_count = tax_count + 1
    buyer = purchase_order_obj["buyer"]
    address = Customer.objects.values(
        "address__street_address",
        "address__district",
        "address__pin",
        "address__province",
    ).get(user=buyer)
    organisation_id = purchase_order_obj["organisation"]
    date = purchase_order_obj["date_time"]
    customer_obj = Customer.objects.values("company").get(user=buyer)
    customer_gst_details = Customer.objects.values(
        "gst_in", "state", "state_code").get(user=buyer)
    admin_organisations = AdminOrganisations.objects.values(
        "pan_no", "stc_no", "gst_in", "state",
        "state_code").get(id=organisation_id)
    voucherid = VoucherId.objects.values("purchase_order_of_session").filter(
        purchase_order=id)[0]
    total_in_words = num2eng(grand_total)
    ref_letter = YOUR_LETTER_No
    header = HeaderFooter.objects.values("header").get(is_active=True)
    footer = HeaderFooter.objects.values("footer").get(is_active=True)
    return render(
        request,
        "prints/bill.html",
        {
            "admin_org": admin_organisations,
            "id": voucherid["purchase_order_of_session"],
            "ref": purchase_order_obj,
            "date": date,
            "purchase_order": purchase_order,
            "address": address,
            "total_cost": total_cost,
            "grand_cost": grand_total,
            "taxes_applied": taxes_applied,
            "customer_gst_details": customer_gst_details,
            "buyer": purchase_order_obj,
            "buyer_name": customer_obj,
            "site": purchase_order_obj,
            "delivery_charges": delivery_charges,
            "total_discount": total_discount,
            "tax_count": tax_count,
            "bill_values": bill_values,
            "header": header,
            "footer": footer,
            "totalplusdelivery": totalplusdelivery,
            "total_in_words": total_in_words,
            "ref_letter": ref_letter,
        },
    )
Exemple #15
0
def receipt(request):
    """
    It generates a Receipt.
    Argument:Http Request
    Return:Render Receipt
    """
    id = request.GET["order_id"]
    voucherid_temp = VoucherId.objects.values("receipt_no_of_session").filter(
        purchase_order=id)[0]
    if not voucherid_temp["receipt_no_of_session"]:
        today_date = datetime.date.today()
        financialsession = FinancialSession.objects.values(
            "id", "session_start_date", "session_end_date")
        for value in financialsession:
            start_date = value["session_start_date"]
            end_date = value["session_end_date"]
            if start_date <= today_date <= end_date:
                session_id = value["id"]
        max_receipt_no = VoucherId.objects.filter(
            session=session_id).aggregate(Max("receipt_no_of_session"))
        if max_receipt_no["receipt_no_of_session__max"]:
            voucherid_obj = VoucherId.objects.values(
                "receipt_no_of_session", "session",
                "purchase_order__date_time").filter(
                    receipt_no_of_session=max_receipt_no[
                        "receipt_no_of_session__max"],
                    session_id=session_id,
                )[0]
            voucherid_obj2 = VoucherId.objects.values(
                "receipt_no_of_session", "session",
                "purchase_order__date_time").filter(purchase_order=id)[0]
            if voucherid_obj["session"] == voucherid_obj2["session"]:
                VoucherId.objects.filter(purchase_order=id).update(
                    receipt_no_of_session=max_receipt_no[
                        "receipt_no_of_session__max"] + 1,
                    receipt_date=today_date,
                )
            else:
                VoucherId.objects.filter(purchase_order=id).update(
                    receipt_no_of_session=1, receipt_date=today_date)
        else:
            VoucherId.objects.filter(purchase_order=id).update(
                receipt_no_of_session=1, receipt_date=today_date)
    voucherid = VoucherId.objects.values(
        "purchase_order_of_session",
        "receipt_no_of_session").filter(purchase_order=id)[0]
    bill = Bill.objects.values("amount_received").get(purchase_order=id)
    purchase_order = PurchaseOrder.objects.values(
        "buyer",
        "date_time",
        "delivery_address",
        "mode_of_payment__method",
        "mode_of_payment",
        "cheque_dd_number",
        "cheque_dd_date",
        "buyer__customer__company",
    ).get(id=id)
    date = purchase_order["date_time"]
    total_in_words = num2eng(bill["amount_received"])
    customer_obj = PurchaseOrder.objects.values(
        "buyer",
        "buyer__first_name",
        "buyer__last_name",
        "buyer__customer__title",
    ).get(id=id)
    address = Customer.objects.values(
        "address__street_address",
        "address__district",
        "address__pin",
        "address__province",
    ).get(user=purchase_order["buyer"])
    purchased_item = (
        PurchasedItem.objects.values("item__category__name").filter(
            purchase_order=id).distinct())
    header = HeaderFooter.objects.values("header").get(is_active=True)
    return render(
        request,
        "prints/receipt.html",
        {
            "receiptno": voucherid["receipt_no_of_session"],
            "order_no": voucherid["purchase_order_of_session"],
            "date": date,
            "cost": bill,
            "amount": total_in_words,
            "address": address,
            "method": purchase_order,
            "buyer": customer_obj,
            "material": purchased_item,
            "header": header,
        },
    )
Exemple #16
0
def suspense_bill(request):
    """
    It generates a Suspense Bill for the user which lists all the items,
    their quantity , subtotal and then adds it to the surcharges
    and generates the Grand total.
    Argument:Http Request
    Return:Render Suspense Bill
    """
    id = request.GET["order_id"]
    voucherid = (VoucherId.objects.filter(purchase_order=id).values(
        "voucher_no", "purchased_item__item__category", "session").distinct())
    suspenseorder = SuspenseOrder.objects.values(
        "voucher", "session_id",
        "distance_estimated").filter(purchase_order=id)
    rate = Surcharge.objects.values("value").filter(
        tax_name="Transportation")[0]
    for distance_temp in suspenseorder:
        distance = distance_temp["distance_estimated"] * rate["value"]
        distance_temp["distance_estimated"] = distance
    purchased_item = (PurchasedItem.objects.filter(purchase_order=id).values(
        "item__category__name",
        "item__category",
        "item__category__parent__name",
    ).order_by("item__category").distinct())
    purchased_item_obj = (PurchasedItem.objects.filter(
        purchase_order=id).values("item__name", "item__category", "qty",
                                  "price_per_unit").order_by("item__category"))
    cost = (PurchasedItem.objects.filter(purchase_order=id).values(
        "price",
        "item__category",
        "item__name",
        "item__category__parent__name",
    ).order_by("item__category"))
    bill = Bill.objects.values("totalplusdelivery",
                               "grand_total").get(purchase_order=id)
    bill_values = []
    for category in purchased_item:
        flag1 = 1
        list = []
        list.append(category["item__category__name"])
        item_names = []
        for item in purchased_item_obj:
            if category["item__category"] == item["item__category"]:
                if flag1 == 1:
                    item_names.append(":")
                    item_names.append(item["item__name"])
                    flag1 = 0
                else:
                    item_names.append(",")
                    item_names.append(item["item__name"])
        flag1 = 1
        total = 0
        for itemcost in cost:
            if category["item__category"] == itemcost["item__category"]:
                total = total + itemcost["price"]
        for voucher_obj in voucherid:
            if (category["item__category"] ==
                    voucher_obj["purchased_item__item__category"]):
                try:
                    suspense_obj = SuspenseOrder.objects.values(
                        "distance_estimated").get(
                            voucher=voucher_obj["voucher_no"],
                            session_id=voucher_obj["session"],
                        )
                    total = (
                        total +
                        suspense_obj["distance_estimated"] * rate["value"])
                except BaseException:
                    pass
        list.append(item_names)
        list.append(int(total))
        bill_values.append(list)
    taxes_applied = TaxesApplied.objects.filter(purchase_order=id).values(
        "surcharge", "tax")
    surcharge = Surcharge.objects.values("id", "tax_name", "value")
    totalplusdelivery = bill["totalplusdelivery"]
    grand_total = bill["grand_total"]
    purchase_order_obj = PurchaseOrder.objects.values(
        "buyer",
        "buyer__first_name",
        "buyer__last_name",
        "reference",
        "reference_date",
        "delivery_address",
        "organisation",
        "date_time",
        "total_discount",
        "buyer__customer__title",
    ).get(id=id)
    buyer = purchase_order_obj["buyer"]
    address = Customer.objects.values(
        "address__street_address",
        "address__district",
        "address__pin",
        "address__province",
    ).get(user=buyer)
    organisation_id = purchase_order_obj["organisation"]
    date = purchase_order_obj["date_time"]
    customer_obj = Customer.objects.values("company").get(user=buyer)
    admin_organisations = AdminOrganisations.objects.values(
        "pan_no", "stc_no").get(id=organisation_id)
    voucherid = VoucherId.objects.values("purchase_order_of_session").filter(
        purchase_order=id)[0]
    total_in_words = num2eng(grand_total)
    ref_letter = YOUR_LETTER_No
    header = HeaderFooter.objects.values("header").get(is_active=True)
    footer = HeaderFooter.objects.values("footer").get(is_active=True)
    return render(
        request,
        "prints/suspense_bill.html",
        {
            "stc_no": admin_organisations,
            "pan_no": admin_organisations,
            "id": voucherid["purchase_order_of_session"],
            "ref": purchase_order_obj,
            "date": date,
            "address": address,
            "grand_cost": grand_total,
            "taxes_applied": taxes_applied,
            "surcharge": surcharge,
            "buyer": purchase_order_obj,
            "buyer_name": customer_obj,
            "site": purchase_order_obj,
            "bill_values": bill_values,
            "header": header,
            "footer": footer,
            "totalplusdelivery": totalplusdelivery,
            "total_in_words": total_in_words,
            "ref_letter": ref_letter,
        },
    )
Exemple #17
0
def tada_result(request):
    if request.method == 'POST':
        form = TaDaForm(request.POST)
        if form.is_valid():
            session = request.POST['session']
            voucher = request.POST['voucher_no']
            departure_time_from_tcc = request.POST['departure_time_from_tcc']
            arrival_time_at_site = request.POST['arrival_time_at_site']
            departure_time_from_site = request.POST['departure_time_from_site']
            arrival_time_at_tcc = request.POST['arrival_time_at_tcc']
            start_test_date = request.POST['start_test_date']
            end_test_date = request.POST['end_test_date']
            source_site = request.POST['source_site']
            testing_site = request.POST['testing_site']
            testing_staff = request.POST['testing_staff']
            testing_staff_list = testing_staff.split(',')
            list_staff = []
            if start_test_date == end_test_date:
                days = 1
            else:
                no_of_days = datetime.strptime(end_test_date, '%Y-%m-%d') -\
                datetime.strptime(start_test_date, '%Y-%m-%d')
                days = no_of_days.days + 1
            for testing_staff_var in testing_staff_list:
                testing_staff_details = Staff.objects.filter(\
                    code=testing_staff_var).values('name','daily_ta_da')
                for tada_val in testing_staff_details:
                    tada_val['daily_ta_da'] = tada_val['daily_ta_da'] * days
                list_staff.append(testing_staff_details)
            header = HeaderFooter.objects.values('header').get(is_active=True)
            footer = HeaderFooter.objects.values('footer').get(is_active=True)
            voucher_obj = VoucherId.objects.filter(session=session).\
            filter(voucher_no=voucher).\
            values_list('purchase_order_id', flat=True)
            purchase_order_var = 0
            for temp_var in voucher_obj:
                purchase_order_var = temp_var
            purchase_order_object = PurchaseOrder.objects.filter(\
                id = purchase_order_var).values('id', 'buyer_id__username',\
                'buyer_id__first_name', 'buyer_id__last_name')
            tada_total = 0
            for temp_var in list_staff:
                for tada_value in temp_var:
                    tada_total = tada_value['daily_ta_da'] + tada_total
            suspense_object = SuspenseOrder.objects.filter(voucher=voucher,\
                session_id=session).update(is_cleared=0)
            if TaDa.objects.filter(voucher_no=voucher).\
            filter(session=session).exists():
                TaDa.objects.filter(voucher_no=voucher).\
                update(voucher_no=voucher, session=session,\
                departure_time_from_tcc=departure_time_from_tcc,\
                arrival_time_at_site=arrival_time_at_site,\
                departure_time_from_site=departure_time_from_site,\
                arrival_time_at_tcc=arrival_time_at_tcc,\
                tada_amount=tada_total, start_test_date=start_test_date,\
                end_test_date=end_test_date, source_site=source_site,\
                testing_site=testing_site , testing_staff=testing_staff,)

            else:
                obj = TaDa(voucher_no=voucher, session=session,\
                departure_time_from_tcc=departure_time_from_tcc,\
                arrival_time_at_site=arrival_time_at_site,\
                departure_time_from_site=departure_time_from_site,\
                arrival_time_at_tcc=arrival_time_at_tcc,\
                tada_amount=tada_total, start_test_date=start_test_date,\
                end_test_date=end_test_date, source_site=source_site,\
                testing_site=testing_site , testing_staff=testing_staff )
                obj.save()
            tada_obj = TaDa.objects.values('departure_time_from_tcc',\
                'arrival_time_at_site', 'departure_time_from_site',\
                'arrival_time_at_tcc', 'tada_amount', 'start_test_date',\
                'end_test_date', 'source_site', 'testing_site',\
                'date_of_generation').get(voucher_no=voucher)
            tada_amount_in_words = tada_total
            header = HeaderFooter.objects.values('header').get(is_active=True)
            footer = HeaderFooter.objects.values('footer').get(is_active=True)
            request_status = request_notify()
            return render(request, 'suspense/tada_summary.html',{\
                'purchase_order_object':purchase_order_object,
                'tada':tada_obj, 'purchase_order_id':voucher,\
                'list_staff':list_staff, 'words':num2eng(int(tada_total)),\
                'total':tada_total, 'request':request_status})
        else:    
            session = request.POST['session']
            voucher = request.POST['voucher_no']
            form = TaDaForm(request.POST,initial={'voucher_no':voucher,\
                'session': session})
            message = 'Fields are mandatory'
            tada = 'enable'
            request_status = request_notify()
            return render(request, 'suspense/form.html',{
                'form':form,'message':message,'request':request_status})
    else:
        return HttpResponseRedirect(\
            reverse('librehatti.suspense.views.tada_order_session'))
Exemple #18
0
def bill(request):
    """
    It generates a bill for the user which lists all the items,
    their quantity , subtotal and then adds it to the surcharges
    and generates the Grand total.
    Argument:Http Request
    Return:Render Bill
    """
    id = request.GET['order_id']
    purchase_order = PurchaseOrder.objects.filter(id=id)
    purchased_item = PurchasedItem.objects.filter(\
        purchase_order=purchase_order).values('item__category__name',\
        'item__category','item__category__parent__name','item__category__unit',\
        'item__category__unit__unit').\
        order_by('item__category').distinct()
    purchased_item_obj = PurchasedItem.objects.filter(\
        purchase_order=purchase_order).values('item__name', 'item__category',\
        'qty', 'price_per_unit').order_by('item__category')
    cost = PurchasedItem.objects.filter(purchase_order=purchase_order).\
    values('price', 'item__category', 'item__name',\
        'item__category__parent__name').order_by('item__category')
    bill_obj = Bill.objects.values('delivery_charges').get(purchase_order=id)
    bill_values = []
    field_check = 1
    for category in purchased_item:
        flag1 = 1
        list = []
        list.append(category['item__category__name'])
        item_names = []
        for item in purchased_item_obj:
            if category['item__category'] == item['item__category']:
                if flag1 == 1:
                    item_names.append(':')
                    item_names.append(item['item__name'])
                    flag1 = 0
                else:
                    item_names.append(',')
                    item_names.append(item['item__name'])
        flag1 = 1
        item_qty = []
        for qty in purchased_item_obj:
            if category['item__category'] == qty['item__category']:
                if flag1 == 1:
                    item_qty.append(qty['qty'])
                    flag1 = 0
                else:
                    item_qty.append(',')
                    item_qty.append(qty['qty'])
        if category['item__category__unit']:
            item_qty.append(category['item__category__unit__unit'])
        else:
            item_qty.append('no_unit')
        flag1 = 1
        price_unit = []
        for price_per in purchased_item_obj:
            if category['item__category'] == price_per['item__category']:
                if flag1 == 1:
                    price_unit.append(price_per['price_per_unit'])
                    flag1 = 0
                else:
                    price_unit.append(',')
                    price_unit.append(price_per['price_per_unit'])
        total=0
        for itemcost in cost:
            if category['item__category'] == itemcost['item__category']:
                total = total + itemcost['price']
        list.append(item_names)
        list.append(item_qty)
        list.append(price_unit)
        list.append(total)
        bill_values.append(list)
    taxes_applied = TaxesApplied.objects.\
    filter(purchase_order=purchase_order).values('surcharge', 'tax',
        'surcharge_name', 'surcharge_value')
    taxes_applied_obj = TaxesApplied.objects.\
    filter(purchase_order=purchase_order).aggregate(Count('id'))
    bill = Bill.objects.values('total_cost', 'totalplusdelivery',\
        'grand_total', 'delivery_charges').get(purchase_order=id)
    total_cost = bill['total_cost']
    totalplusdelivery = bill['totalplusdelivery']
    grand_total = bill['grand_total']
    delivery_charges = bill['delivery_charges']
    purchase_order_obj = PurchaseOrder.objects.values('buyer',\
        'buyer__first_name', 'buyer__last_name', 'reference','reference_date',\
        'delivery_address', 'organisation', 'date_time', 'total_discount',\
        'buyer__customer__title').get(id = id)
    total_discount = purchase_order_obj['total_discount']
    taxes_applied_obj = TaxesApplied.objects.\
    filter(purchase_order=purchase_order).aggregate(Count('id'))
    suspense_order = SuspenseOrder.objects.values('distance_estimated').\
    filter(purchase_order=id)
    total_distance = 0
    if suspense_order:
        for distance in suspense_order:
            total_distance = total_distance + distance['distance_estimated']
        if total_distance == 0:
            if total_discount == 0:
                tax_count = taxes_applied_obj['id__count'] + 2
            else:
                tax_count = taxes_applied_obj['id__count'] + 3
        else:
            if total_discount == 0:
                tax_count = taxes_applied_obj['id__count'] + 4
            else:
                tax_count = taxes_applied_obj['id__count'] + 5
    else:
        if total_discount == 0:
            tax_count = taxes_applied_obj['id__count'] + 2
        else:
            tax_count = taxes_applied_obj['id__count'] + 3
    if taxes_applied_obj['id__count'] == 0:
        tax_count = tax_count + 1
    buyer = purchase_order_obj['buyer']
    address = Customer.objects.values('address__street_address',\
    'address__district', 'address__pin', 'address__province').get(user=buyer)
    organisation_id = purchase_order_obj['organisation']
    date = purchase_order_obj['date_time']
    customer_obj = Customer.objects.values('company').get(user=buyer)
    admin_organisations = AdminOrganisations.objects.values('pan_no',\
        'stc_no').get(id=organisation_id)
    voucherid = VoucherId.objects.values('purchase_order_of_session').\
    filter(purchase_order=id)[0]
    total_in_words=num2eng(grand_total)
    ref_letter = _YOUR_LETTER_No
    header = HeaderFooter.objects.values('header').get(is_active=True)
    footer = HeaderFooter.objects.values('footer').get(is_active=True)
    return render(request, 'prints/bill.html', {\
        'stc_no' : admin_organisations, 'pan_no' : admin_organisations,\
        'id':voucherid['purchase_order_of_session'], 'ref':purchase_order_obj,\
        'date':date, 'purchase_order':purchase_order, 'address':address,\
        'total_cost':total_cost, 'grand_cost':grand_total,\
        'taxes_applied':taxes_applied,\
        'buyer':purchase_order_obj, 'buyer_name':customer_obj,\
        'site':purchase_order_obj, 'delivery_charges':delivery_charges,\
        'total_discount':total_discount, 'tax_count':tax_count,\
        'bill_values':bill_values, 'header':header, 'footer': footer,\
        'totalplusdelivery':totalplusdelivery,\
        'total_in_words':total_in_words, 'ref_letter':ref_letter})
Exemple #19
0
def voucher_print(request):
    number = request.GET["voucher_no"]
    session = request.GET["session"]
    purchase_order_id = request.GET["purchase_order"]
    flag = 0
    voucherid = VoucherId.objects.values("voucher_no").filter(purchase_order=purchase_order_id)
    for value in voucherid:
        try:
            suspense_order = SuspenseOrder.objects.get(voucher=value["voucher_no"], purchase_order=purchase_order_id)
            flag = 1
        except:
            continue
    calculatedistribution = CalculateDistribution.objects.values(
        "college_income_calculated", "admin_charges_calculated", "consultancy_asset", "development_fund", "total"
    ).get(voucher_no=number, session=session)
    total_in_words = num2eng(calculatedistribution["total"])
    voucherid = VoucherId.objects.values(
        "purchase_order",
        "ratio",
        "college_income",
        "admin_charges",
        "distribution__name",
        "purchased_item__item__category__name",
        "purchased_item__item__category__parent__parent",
    ).filter(voucher_no=number, session=session)[0]
    purchase_order = voucherid["purchase_order"]
    distribution = voucherid["distribution__name"]
    ratio = voucherid["ratio"]
    college_income = voucherid["college_income"]
    admin_charges = voucherid["admin_charges"]
    category_name = voucherid["purchased_item__item__category__name"]
    lab_id = voucherid["purchased_item__item__category__parent__parent"]
    emp = Staff.objects.values("name", "position__position").filter(lab=lab_id).order_by("position__rank")
    purchase_order_obj = PurchaseOrder.objects.values(
        "date_time",
        "buyer",
        "buyer__first_name",
        "buyer__last_name",
        "tds",
        "buyer__customer__title",
        "buyer__customer__company",
    ).get(id=purchase_order)
    address = Customer.objects.values(
        "address__street_address", "address__city", "address__pin", "address__province"
    ).get(user=purchase_order_obj["buyer"])
    date = purchase_order_obj["date_time"]
    bill = Bill.objects.values(
        "delivery_charges", "total_cost", "grand_total", "amount_received", "totalplusdelivery"
    ).get(purchase_order=purchase_order_id)
    amount_received_inwords = num2eng(bill["amount_received"])
    taxes_applied = TaxesApplied.objects.values("surcharge__tax_name", "surcharge__value", "tax").filter(
        purchase_order=purchase_order_id
    )
    voucheridobj = VoucherId.objects.values(
        "purchase_order_of_session", "purchase_order__mode_of_payment__method"
    ).filter(purchase_order=purchase_order_id)[0]
    header = HeaderFooter.objects.values("header").get(is_active=True)
    footer = HeaderFooter.objects.values("footer").get(is_active=True)
    if flag == 0:
        return render(
            request,
            "voucher/voucher_report.html",
            {
                "calculate_distribution": calculatedistribution,
                "admin_charges": admin_charges,
                "college_income": college_income,
                "ratio": ratio,
                "d_name": distribution,
                "purchase_order": voucheridobj["purchase_order_of_session"],
                "voucher": number,
                "date": date,
                "address": address,
                "buyer": purchase_order_obj,
                "material": category_name,
                "total_in_words": total_in_words,
                "employee": emp,
                "header": header,
            },
        )
    else:
        return render(
            request,
            "voucher/voucher_report_suspence.html",
            {
                "address": address,
                "cost": bill,
                "inwords": amount_received_inwords,
                "date": date,
                "suspense_voucher": number,
                "job": voucheridobj["purchase_order_of_session"],
                "tds": purchase_order_obj,
                "tax": taxes_applied,
                "header": header,
                "material": category_name,
                "buyer": purchase_order_obj,
                "method": voucheridobj["purchase_order__mode_of_payment__method"],
            },
        )