示例#1
0
def PurchaseUpdateStock(request):
    if request.method == "POST":
        medName = request.POST.getlist('name')
        medCompany = request.POST.getlist('company')
        batch_no=request.POST.getlist('batch_number')
        quantity=request.POST.getlist('quantity')
        cursor = connection.cursor()
        #loop
        i=0
        l=len(medName)
        while(i<l):
            cursor.execute("SELECT id FROM company_company where comp_name=%s",[medCompany[i]])
            medCompanyID = cursor.fetchone()[0]
            cursor.execute("SELECT id,free FROM company_product where name=%s and company_id=%s",[medName[i],medCompanyID])
            a=cursor.fetchone()
            medID=a[0]
            pro_quantity=a[1]
            new_pro_quantity=int(pro_quantity)+int(quantity[i])
            cursor.execute("Update company_product SET free=%s where id=%s",[new_pro_quantity,medID])
            cursor.execute('select id,quantity from company_batch where product_id=%s and batch_number=%s',[medID,batch_no[i]])
            a=cursor.fetchone()
            batchID=a[0]
            batch_quantity=a[1]
            new_batch_quantity=int(batch_quantity)+int(quantity[i])
            cursor.execute("Update company_batch SET quantity=%s where id=%s",[new_batch_quantity,batchID])
            i+=1
        a='done'
        return HttpResponse(json.dumps({'a': a}), content_type="application/json")
    else:
        return ErrorPage(request,"Only POST allowed")
示例#2
0
def ComputeLoss(request):
    if request.method == "GET":
        medName = request.GET.getlist('medName')
        medCompany = request.GET.getlist('medCompany')
        batch_no = request.GET.getlist('batch_no')
        sale_rate = request.GET.getlist('sale_rate')
        cursor = connection.cursor()
        loss=[]
        profit=0
        i=0
        l=len(medName)
        while(i<l):
            cursor.execute("SELECT id FROM company_company where comp_name=%s",[medCompany[i]])
            medCompanyID = cursor.fetchone()[0]
            cursor.execute("SELECT id FROM company_product where name=%s and company_id=%s",[medName[i],medCompanyID])
            medProductID = cursor.fetchone()[0]
            cursor.execute("SELECT purchase_rate FROM company_batch where product_id=%s and batch_number=%s",[medProductID,batch_no[i]])
            purchase_rate=cursor.fetchone()[0]
            pro=float(sale_rate[i]) - float(purchase_rate)
            profit+=pro
            if(float(purchase_rate) < float(sale_rate[i])):
                loss.append('False')
            else:
                loss.append('True')
            i+=1
        loss.append(profit)
        return HttpResponse(json.dumps(loss), content_type='application/json')
    else:
        return ErrorPage(request,"POST requests are not allowed")
示例#3
0
def GetPartyWholesellerID(request):
    if request.method == "GET":
        partyName = request.GET['party_wholeseller']
        cursor = connection.cursor()
        cursor.execute("SELECT party_id FROM party_party_wholeseller where name=%s",[partyName])
        return HttpResponse(json.dumps(cursor.fetchone()), content_type='application/json')
    else:
        return ErrorPage(request,"Only GET allowed")
示例#4
0
def GetPartyWholeseller(request):
    if request.method=="GET":
        cursor = connection.cursor()
        cursor.execute("SELECT name FROM party_party_wholeseller")
        data= cursor.fetchall()
        b=[]
        [b.append(a[0]) for a in data if a[0] not in b]
        return HttpResponse(json.dumps(b), content_type='application/json')
    else:
        return ErrorPage(request,"only GET requests are allowed")
示例#5
0
def GetMedName(request):
    if request.method=="GET":
        cursor = connection.cursor()
        cursor.execute("SELECT name FROM company_product")
        data= cursor.fetchall()
        b=[]
        [b.append(a[0]) for a in data if a[0] not in b]
        return HttpResponse(json.dumps(b), content_type='application/json')
    else:
        return ErrorPage(request,"Only GET allowed")
示例#6
0
def GetMedTax(request):
    if request.method == "GET":
        medName = request.GET['medName']
        medCompany = request.GET['medCompany']
        cursor = connection.cursor()
        cursor.execute("SELECT id FROM company_company where comp_name=%s",[medCompany])
        medCompanyID = cursor.fetchone()[0]
        cursor.execute("SELECT gst FROM company_product where name=%s and company_id=%s",[medName,medCompanyID])
        return HttpResponse(json.dumps(cursor.fetchone()), content_type='application/json')
    else:
        return ErrorPage(request,"Only GET allowed")
示例#7
0
def getPurchaseRate(request):
    if request.method=="GET":
        medName=request.GET['medName']
        medCompany = request.GET['medCompany']
        batch_no = request.GET['batch']
        cursor = connection.cursor()
        cursor.execute('select id from company_company where comp_name=%s',[medCompany])
        comp_id = comp_id = cursor.fetchone()[0]
        cursor.execute('select id from company_product where name=%s and company_id=%s ',[medName,comp_id])
        med_id = cursor.fetchone()[0]
        cursor.execute('select purchase_rate from company_batch where product_id=%s and batch_number=%s',[med_id,batch_no])
        purchase_rate = cursor.fetchone()[0]
        return HttpResponse(json.dumps(purchase_rate),content_type='application/json')
    else:
        return ErrorPage("Only GET requests are allowed")
示例#8
0
def GetMedBatch(request):
    if request.method=="GET":
        medName=request.GET['medName']
        medCompany=request.GET['medCompany']
        cursor = connection.cursor()
        cursor.execute("SELECT id FROM company_company where comp_name=%s",[medCompany])
        medCompany=cursor.fetchone()[0]
        cursor.execute("SELECT id FROM company_product where name=%s and company_id=%s",[medName,medCompany])
        pro_id=cursor.fetchall()[0]
        cursor.execute("SELECT batch_number FROM company_batch where product_id=%s",[pro_id])
        temp_batches=cursor.fetchall()
        batches=[a[0] for a in temp_batches]
        return HttpResponse(json.dumps(batches), content_type='application/json')
    else:
        ErrorPage(request,"POST requests are not allowed")
示例#9
0
def getMrp(request):
    if request.method=="GET":
        medName=request.GET['medName']
        medCompany = request.GET['medCompany']
        batch_no = request.GET['batch']
        cursor = connection.cursor()
        cursor.execute("select id from company_company where comp_name=%s",[medCompany])
        comp_id = cursor.fetchone()[0]
        # print("comp id: ",comp_id)
        cursor.execute('select id from company_product where name=%s and company_id=%s ',[medName,comp_id])
        med_id = cursor.fetchone()[0]
        # print("medId : ",med_id)
        cursor.execute('select mrp from company_batch where product_id=%s and batch_number=%s',[med_id,batch_no])
        quan = cursor.fetchone()[0]

        return HttpResponse(json.dumps(quan),content_type='application/json')
    else:
        return ErrorPage(request,"POST requests are not allowed")
示例#10
0
def GSTPurchaseReport(request):
    if request.method=='GET':
        month = request.GET['month']
        year = request.GET['year']
        query = Purchase.objects.filter(date__year=year,date__month=month)
        fields=['bill no','date','party','mode of payment','total bill (Rs.)']
        filename='D:/Purchase_GSTR-'+month+"-"+year+".csv"
        data = []
        for i in query:
            data.append([i.id,i.date,i.party,i.mode_of_payment,i.total_bill])
            

        with open(filename,'w',newline='') as csvf:
            csvw = csv.writer(csvf)
            csvw.writerow(fields)
            csvw.writerows(data)
            
    else:
        return ErrorPage(request,"Only GET req. allowed")       
示例#11
0
def ComputeRowLoss(request):
    if request.method == "GET":
        medName = request.GET['medName']
        medCompany = request.GET['medCompany']
        batch_no = request.GET['batch_no']
        rate = request.GET['rate']
        cursor = connection.cursor()
        loss=''
        cursor.execute("SELECT id FROM company_company where comp_name=%s",[medCompany])
        medCompanyID = cursor.fetchone()[0]
        cursor.execute("SELECT id FROM company_product where name=%s and company_id=%s",[medName,medCompanyID])
        medProductID = cursor.fetchone()[0]
        cursor.execute("SELECT purchase_rate FROM company_batch where product_id=%s and batch_number=%s",[medProductID,batch_no])
        purchase_rate=cursor.fetchone()[0]
        if(float(purchase_rate) < float(rate)):
            loss='False'
        else:
            loss='True'

        return HttpResponse(json.dumps(loss), content_type='application/json')
    else:
        return ErrorPage(request,"POST requests are not allowed")
示例#12
0
def GeneratePDF(request):
    cursor = connection.cursor()
    cursor.execute("SELECT max(id) FROM bill_bill_retailer")
    bill_id=cursor.fetchone()[0]
    cursor.execute("SELECT * FROM bill_bill_retailer where id=%s",[bill_id])
    bill=cursor.fetchone()
    data={}
    data['id']=bill[0]
    data['date']=bill[1]
    data['customer_name']=bill[2]
    data['customer_email']=bill[3]
    if(bill[4] == 1):
        mop='Cash'
    else:
        mop='Card'
    data['mode_of_payment']=mop
    data['total_bill']=bill[5]
    data['bill_id'] = bill_id

    i=0
    l=len(bill[6])
    product_list=[]
    while(i<l):
        temp={}
        temp['name']=bill[6][i]
        temp['company']=bill[7][i]
        temp['batch_number']=bill[8][i]
        temp['quantity']=bill[9][i]
        temp['discount']=bill[10][i]
        temp['deal']=bill[11][i]
        temp['tax']=bill[12][i]
        temp['loss']=bill[13][i]
        temp['sale_rate']=bill[14][i]
        product_list.append(temp)
        i+=1
    
    data['product_list']=product_list
    try:
        obj = Profile_Retailer.objects.all()[0]
        shop_name = obj.Shop_Name
        Address  = obj.Address
        GST = obj.GST
        DL = obj.DL_no
        contact = obj.contact
        # print("shop",shop_details)
    except Exception as e:
        print(e)
        shop_name = "NULL"
        Address  = "NULL"
        GST = "NULL"
        DL = "NULL"
        contact = "NULL"
        
    data['shop_name'] = shop_name
    data['address']=Address
    data['GST'] = GST
    data['dl'] = DL
    data['contact'] = contact

    #code to generate pdf
    template = get_template("bill/sale_pdf_page.html")
    # html  = template.render(data)
    # result = BytesIO()
    # pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
    result, pdf = render_to_pdf('bill/sale_pdf_page.html',data)
    if pdf:
        response = HttpResponse(pdf, content_type='application/pdf')
        filename = "Sale_Invoice_{cust_name}_{date}.pdf".format(cust_name=bill[2], date=bill[1])
        content = "inline; filename=%s" %(filename)
        content = "attachment; filename=%s" %(filename)
        response['Content-Disposition'] = content
        email = EmailMessage('MedAssistanceERP', 'Thank You for choosing our pharmacy. A copy of your bill has been attached below.', settings.EMAIL_HOST_USER, [bill[3]])
        email.attach("{filename}".format(filename=filename),result.getvalue(),"application/pdf")
        email.send()
        return response
    return ErrorPage(request,"PDF Not Found")