From b512368f58d30acfad709dad79778bdc6c735359 Mon Sep 17 00:00:00 2001 From: Prajkta_Patkar Date: Sat, 4 Nov 2017 12:42:07 +0530 Subject: [PATCH 1/8] cess retrieved and freeqty code removed as it is no longer has to subtract frpm qty --- gkcore/views/api_reports.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gkcore/views/api_reports.py b/gkcore/views/api_reports.py index 81d2cfd..b854045 100644 --- a/gkcore/views/api_reports.py +++ b/gkcore/views/api_reports.py @@ -3845,11 +3845,11 @@ free replacement or sample are those which are excluded. taxcolumns = [] #sales register(flag = 0) if int(self.request.params["flag"]) == 0: - invquery = self.con.execute("select invid, invoiceno, invoicedate, custid, invoicetotal, contents, tax, freeqty, sourcestate, taxstate,taxflag,discount from invoice where orgcode=%d AND custid IN (select custid from customerandsupplier where orgcode=%d AND csflag=3) AND invoicedate >= '%s' AND invoicedate <= '%s' order by invoicedate"%(authDetails["orgcode"], authDetails["orgcode"], datetime.strptime(str(self.request.params["calculatefrom"]),"%d-%m-%Y").strftime('%Y-%m-%d'), datetime.strptime(str(self.request.params["calculateto"]),"%d-%m-%Y").strftime('%Y-%m-%d'))) + invquery = self.con.execute("select invid, invoiceno, invoicedate, custid, invoicetotal, contents, tax,cess ,freeqty, sourcestate, taxstate,taxflag,discount from invoice where orgcode=%d AND custid IN (select custid from customerandsupplier where orgcode=%d AND csflag=3) AND invoicedate >= '%s' AND invoicedate <= '%s' order by invoicedate"%(authDetails["orgcode"], authDetails["orgcode"], datetime.strptime(str(self.request.params["calculatefrom"]),"%d-%m-%Y").strftime('%Y-%m-%d'), datetime.strptime(str(self.request.params["calculateto"]),"%d-%m-%Y").strftime('%Y-%m-%d'))) #purchase register(flag = 1) elif int(self.request.params["flag"]) == 1: - invquery = self.con.execute("select invid, invoiceno, invoicedate, custid, invoicetotal, contents, tax, freeqty, taxstate,sourcestate,taxflag,discount from invoice where orgcode=%d AND custid IN (select custid from customerandsupplier where orgcode=%d AND csflag=19) AND invoicedate >= '%s' AND invoicedate <= '%s' order by invoicedate"%(authDetails["orgcode"], authDetails["orgcode"], datetime.strptime(str(self.request.params["calculatefrom"]),"%d-%m-%Y").strftime('%Y-%m-%d'), datetime.strptime(str(self.request.params["calculateto"]),"%d-%m-%Y").strftime('%Y-%m-%d'))) + invquery = self.con.execute("select invid, invoiceno, invoicedate, custid, invoicetotal, contents, tax, cess,freeqty, taxstate,sourcestate,taxflag,discount from invoice where orgcode=%d AND custid IN (select custid from customerandsupplier where orgcode=%d AND csflag=19) AND invoicedate >= '%s' AND invoicedate <= '%s' order by invoicedate"%(authDetails["orgcode"], authDetails["orgcode"], datetime.strptime(str(self.request.params["calculatefrom"]),"%d-%m-%Y").strftime('%Y-%m-%d'), datetime.strptime(str(self.request.params["calculateto"]),"%d-%m-%Y").strftime('%Y-%m-%d'))) @@ -3898,7 +3898,7 @@ free replacement or sample are those which are excluded. '''for each product in invoice. row["contents"] is JSONB which has format like this - {"22": {"20.00": "2"}, "61": {"100.00": "1"}} where 22 and 61 is productcode, {"20.00": "2"} here 20.00 is price per unit and quantity is 2. - The other JSONB field in each invoice is row["tax"]. Its format is {"22": "2.00", "61": "2.00"}. Here, 22 and 61 are products and 2.00 is tax applied on those products''' + The other JSONB field in each invoice is row["tax"]. Its format is {"22": "2.00", "61": "2.00"}. Here, 22 and 61 are products and 2.00 is tax applied on those products, similarly for CESS {"22":"0.05"} where 22 is productcode snd 0.05 is cess rate''' for pc in row["contents"].iterkeys(): @@ -3916,7 +3916,7 @@ free replacement or sample are those which are excluded. gspc = self.con.execute(select([product.c.gsflag]).where(product.c.productcode==pc)) flag = gspc.fetchone() if int(flag["gsflag"]) == 7: - qty = float(row["contents"][pc][pcprice]) - float(row["freeqty"][pc]) if row["freeqty"].has_key(pc) else 0.00 + qty = float(row["contents"][pc][pcprice]) taxamount = (float(ppu) - float(discamt)) * float(qty) #(((float("%.2f"%float(ppu))) - (float("%.2f"%float(discamt)))) * float("%.2f"%float(qty)) else: -- GitLab From 8a1754ac59843b7f0405733912ac61a8c790391d Mon Sep 17 00:00:00 2001 From: Prajkta_Patkar Date: Sat, 4 Nov 2017 17:15:49 +0530 Subject: [PATCH 2/8] cess rate sent in dictionaries --- gkcore/views/api_reports.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/gkcore/views/api_reports.py b/gkcore/views/api_reports.py index b854045..5147414 100644 --- a/gkcore/views/api_reports.py +++ b/gkcore/views/api_reports.py @@ -3859,7 +3859,7 @@ free replacement or sample are those which are excluded. #for each invoice result = invquery.fetchall() for row in result: - + print row["invoiceno"] try: disc = row["discount"] @@ -3887,9 +3887,10 @@ free replacement or sample are those which are excluded. totalrow["grossamount"] = "%.2f"%(float(totalrow["grossamount"]) + float("%.2f"%row["invoicetotal"])) qty = 0.00 ppu = 0.00 - #taxrate is in percentage + #taxrate and cessrate are in percentage taxrate = 0.00 - #taxamount is net amount for some tax rate. eg. 2% tax on 200rs. This 200rs is taxamount + cessrate = 0.00 + #taxamount is net amount for some tax rate. eg. 2% tax on 200rs. This 200rs is taxamount, i.e. Taxable amount taxamount = 0.00 '''This taxdata dictionary has key as taxrate and value as amount of tax to be paid on this rate. eg. {"2.00": "2.80"}''' taxdata = {} @@ -3904,6 +3905,7 @@ free replacement or sample are those which are excluded. discamt = 0.00 taxrate = "%.2f"%float(row["tax"][pc]) + cessrate = "%.2f"%float(row["cess"][pc]) if disc != None: discamt = float(disc[pc]) else: @@ -3917,23 +3919,33 @@ free replacement or sample are those which are excluded. flag = gspc.fetchone() if int(flag["gsflag"]) == 7: qty = float(row["contents"][pc][pcprice]) - taxamount = (float(ppu) - float(discamt)) * float(qty) - #(((float("%.2f"%float(ppu))) - (float("%.2f"%float(discamt)))) * float("%.2f"%float(qty)) + taxamount = (float(ppu) * float(qty)) - float(discamt) + #(((float("%.2f"%float(ppu))) * float("%.2f"%float(qty))- (float("%.2f"%float(discamt)))) else: - taxamount = float(ppu) - float(discamt) - # (float("%.2f"%float(ppu))) - (float("%.2f"%float(discamt))) + taxamount = float(ppu) - float(discamt) + # (float("%.2f"%float(ppu))) - (float("%.2f"%float(discamt))) if taxrate == "0.00": invoicedata["taxfree"] = "%.2f"%((float("%.2f"%float(invoicedata["taxfree"])) + taxamount)) totalrow["taxfree"] = "%.2f"%(float(totalrow["taxfree"]) + taxamount) continue '''if taxrate appears in this invoice then update invoice tax and taxamount for that rate Otherwise create new entries in respective dictionaries of that invoice''' + print taxrate if taxdata.has_key(str(taxrate)): taxdata[taxrate]="%.2f"%(float(taxdata[taxrate]) + taxamount) + print taxamount + print taxdata taxamountdata[taxrate]="%.2f"%(float(taxamountdata[taxrate]) + taxamount*float(taxrate)/100.00) else: taxdata.update({taxrate:"%.2f"%taxamount}) taxamountdata.update({taxrate:"%.2f"%(taxamount*float(taxrate)/100.00)}) + + if taxdata.has_key(str(cessrate)): + taxdata[cessrate]="%.2f"%(float(taxdata[cessrate]) + taxamount) + taxamountdata[cessrate]="%.2f"%(float(taxamountdata[cessrate]) + taxamount*float(cessrate)/100.00) + else: + taxdata.update({cessrate:"%.2f"%taxamount}) + taxamountdata.update({cessrate:"%.2f"%(taxamount*float(cessrate)/100.00)}) '''if new taxrate appears(in all invoices), ie. we found this rate for the first time then add this column to taxcolumns and also create new entries in tax & taxamount dictionaries Otherwise update existing data''' if taxrate not in taxcolumns: taxcolumns.append(taxrate) @@ -3942,6 +3954,13 @@ free replacement or sample are those which are excluded. else: totalrow["taxamount"][taxrate] = "%.2f"%(float(totalrow["taxamount"][taxrate]) + float(taxamount*float(taxrate)/100.00)) totalrow["tax"][taxrate] = "%.2f"%(float(totalrow["tax"][taxrate]) + taxamount) + if cessrate not in taxcolumns: + taxcolumns.append(cessrate) + totalrow["taxamount"].update({cessrate:"%.2f"%float(taxamountdata[cessrate])}) + totalrow["tax"].update({cessrate:"%.2f"%taxamount}) + else: + totalrow["taxamount"][cessrate] = "%.2f"%(float(totalrow["taxamount"][cessrate]) + float(taxamount*float(cessrate)/100.00)) + totalrow["tax"][cessrate] = "%.2f"%(float(totalrow["tax"][cessrate]) + taxamount) invoicedata["tax"] = taxdata invoicedata["taxamount"] = taxamountdata spdata.append(invoicedata) -- GitLab From 7eb078b0553416bade784354050854de79e2309c Mon Sep 17 00:00:00 2001 From: Prajkta_Patkar Date: Sat, 4 Nov 2017 19:20:41 +0530 Subject: [PATCH 3/8] all invoices now view (without cess) --- gkcore/views/api_reports.py | 66 ++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/gkcore/views/api_reports.py b/gkcore/views/api_reports.py index 5147414..4e25217 100644 --- a/gkcore/views/api_reports.py +++ b/gkcore/views/api_reports.py @@ -3851,18 +3851,17 @@ free replacement or sample are those which are excluded. elif int(self.request.params["flag"]) == 1: invquery = self.con.execute("select invid, invoiceno, invoicedate, custid, invoicetotal, contents, tax, cess,freeqty, taxstate,sourcestate,taxflag,discount from invoice where orgcode=%d AND custid IN (select custid from customerandsupplier where orgcode=%d AND csflag=19) AND invoicedate >= '%s' AND invoicedate <= '%s' order by invoicedate"%(authDetails["orgcode"], authDetails["orgcode"], datetime.strptime(str(self.request.params["calculatefrom"]),"%d-%m-%Y").strftime('%Y-%m-%d'), datetime.strptime(str(self.request.params["calculateto"]),"%d-%m-%Y").strftime('%Y-%m-%d'))) - - + srno = 1 '''This totalrow dictionary is used for very last row of report which contains sum of all columns in report''' totalrow = {"grossamount":"0.00", "taxfree":"0.00", "tax": {}, "taxamount":{}} #for each invoice result = invquery.fetchall() for row in result: - print row["invoiceno"] - try: + + # try: disc = row["discount"] - + if int(row["taxflag"]) == 7: destinationstate = row["taxstate"] destinationStateCode = getStateCode(row["taxstate"],self.con)["statecode"] @@ -3884,6 +3883,7 @@ free replacement or sample are those which are excluded. except: invoicedata["custgstin"] = None + # print invoicedata totalrow["grossamount"] = "%.2f"%(float(totalrow["grossamount"]) + float("%.2f"%row["invoicetotal"])) qty = 0.00 ppu = 0.00 @@ -3900,17 +3900,16 @@ free replacement or sample are those which are excluded. row["contents"] is JSONB which has format like this - {"22": {"20.00": "2"}, "61": {"100.00": "1"}} where 22 and 61 is productcode, {"20.00": "2"} here 20.00 is price per unit and quantity is 2. The other JSONB field in each invoice is row["tax"]. Its format is {"22": "2.00", "61": "2.00"}. Here, 22 and 61 are products and 2.00 is tax applied on those products, similarly for CESS {"22":"0.05"} where 22 is productcode snd 0.05 is cess rate''' - + #print row["contents"].keys() for pc in row["contents"].iterkeys(): - + print "now we are in inner most loop" discamt = 0.00 taxrate = "%.2f"%float(row["tax"][pc]) - cessrate = "%.2f"%float(row["cess"][pc]) + print"row[cess][pc]" if disc != None: discamt = float(disc[pc]) else: discamt = 0.00 - for pcprice in row["contents"][pc].iterkeys(): ppu = pcprice @@ -3930,45 +3929,52 @@ free replacement or sample are those which are excluded. totalrow["taxfree"] = "%.2f"%(float(totalrow["taxfree"]) + taxamount) continue '''if taxrate appears in this invoice then update invoice tax and taxamount for that rate Otherwise create new entries in respective dictionaries of that invoice''' - print taxrate - if taxdata.has_key(str(taxrate)): + # print taxrate + if taxdata.has_key(str(taxrate)) and taxrate != "0.00": taxdata[taxrate]="%.2f"%(float(taxdata[taxrate]) + taxamount) - print taxamount - print taxdata + # print taxamount + # print taxdata taxamountdata[taxrate]="%.2f"%(float(taxamountdata[taxrate]) + taxamount*float(taxrate)/100.00) else: taxdata.update({taxrate:"%.2f"%taxamount}) taxamountdata.update({taxrate:"%.2f"%(taxamount*float(taxrate)/100.00)}) - if taxdata.has_key(str(cessrate)): - taxdata[cessrate]="%.2f"%(float(taxdata[cessrate]) + taxamount) - taxamountdata[cessrate]="%.2f"%(float(taxamountdata[cessrate]) + taxamount*float(cessrate)/100.00) - else: - taxdata.update({cessrate:"%.2f"%taxamount}) - taxamountdata.update({cessrate:"%.2f"%(taxamount*float(cessrate)/100.00)}) '''if new taxrate appears(in all invoices), ie. we found this rate for the first time then add this column to taxcolumns and also create new entries in tax & taxamount dictionaries Otherwise update existing data''' - if taxrate not in taxcolumns: + if taxrate not in taxcolumns and taxrate != "0.00": taxcolumns.append(taxrate) totalrow["taxamount"].update({taxrate:"%.2f"%float(taxamountdata[taxrate])}) totalrow["tax"].update({taxrate:"%.2f"%taxamount}) else: totalrow["taxamount"][taxrate] = "%.2f"%(float(totalrow["taxamount"][taxrate]) + float(taxamount*float(taxrate)/100.00)) totalrow["tax"][taxrate] = "%.2f"%(float(totalrow["tax"][taxrate]) + taxamount) - if cessrate not in taxcolumns: - taxcolumns.append(cessrate) - totalrow["taxamount"].update({cessrate:"%.2f"%float(taxamountdata[cessrate])}) - totalrow["tax"].update({cessrate:"%.2f"%taxamount}) - else: - totalrow["taxamount"][cessrate] = "%.2f"%(float(totalrow["taxamount"][cessrate]) + float(taxamount*float(cessrate)/100.00)) - totalrow["tax"][cessrate] = "%.2f"%(float(totalrow["tax"][cessrate]) + taxamount) + # print "i canceldate come here" + # print row["cess"][pc] + if row["cess"] != None: + print "cess found" + cessrate = "%.2f"%float(row["cess"][pc]) + if taxdata.has_key(str(cessrate)): + taxdata[cessrate]="%.2f"%(float(taxdata[cessrate]) + taxamount) + taxamountdata[cessrate]="%.2f"%(float(taxamountdata[cessrate]) + taxamount*float(cessrate)/100.00) + else: + taxdata.update({cessrate:"%.2f"%taxamount}) + taxamountdata.update({cessrate:"%.2f"%(taxamount*float(cessrate)/100.00)}) + + if cessrate not in taxcolumns: + taxcolumns.append(cessrate) + totalrow["taxamount"].update({cessrate:"%.2f"%float(taxamountdata[cessrate])}) + totalrow["tax"].update({cessrate:"%.2f"%taxamount}) + else: + totalrow["taxamount"][cessrate] = "%.2f"%(float(totalrow["taxamount"][cessrate]) + float(taxamount*float(cessrate)/100.00)) + totalrow["tax"][cessrate] = "%.2f"%(float(totalrow["tax"][cessrate]) + taxamount) invoicedata["tax"] = taxdata invoicedata["taxamount"] = taxamountdata spdata.append(invoicedata) srno += 1 - except: - pass + # except: + # pass taxcolumns.sort(reverse=True) - + a = {"gkstatus":enumdict["Success"], "gkresult":spdata, "totalrow":totalrow, "taxcolumns":taxcolumns} + #print a return {"gkstatus":enumdict["Success"], "gkresult":spdata, "totalrow":totalrow, "taxcolumns":taxcolumns} except: return {"gkstatus":enumdict["ConnectionFailed"] } -- GitLab From 68e19445aac45dfd84505246ae6ead461b4856dc Mon Sep 17 00:00:00 2001 From: Prajkta_Patkar Date: Sat, 4 Nov 2017 19:48:05 +0530 Subject: [PATCH 4/8] filtered taxrate = 0.00 , further check taxdata {"0.00":1} also coming --- gkcore/views/api_reports.py | 45 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/gkcore/views/api_reports.py b/gkcore/views/api_reports.py index 4e25217..6e576ab 100644 --- a/gkcore/views/api_reports.py +++ b/gkcore/views/api_reports.py @@ -3905,7 +3905,8 @@ free replacement or sample are those which are excluded. print "now we are in inner most loop" discamt = 0.00 taxrate = "%.2f"%float(row["tax"][pc]) - print"row[cess][pc]" + print taxrate + # print"row[cess][pc]" if disc != None: discamt = float(disc[pc]) else: @@ -3929,28 +3930,31 @@ free replacement or sample are those which are excluded. totalrow["taxfree"] = "%.2f"%(float(totalrow["taxfree"]) + taxamount) continue '''if taxrate appears in this invoice then update invoice tax and taxamount for that rate Otherwise create new entries in respective dictionaries of that invoice''' - # print taxrate - if taxdata.has_key(str(taxrate)) and taxrate != "0.00": - taxdata[taxrate]="%.2f"%(float(taxdata[taxrate]) + taxamount) - # print taxamount - # print taxdata - taxamountdata[taxrate]="%.2f"%(float(taxamountdata[taxrate]) + taxamount*float(taxrate)/100.00) - else: - taxdata.update({taxrate:"%.2f"%taxamount}) - taxamountdata.update({taxrate:"%.2f"%(taxamount*float(taxrate)/100.00)}) - - '''if new taxrate appears(in all invoices), ie. we found this rate for the first time then add this column to taxcolumns and also create new entries in tax & taxamount dictionaries Otherwise update existing data''' - if taxrate not in taxcolumns and taxrate != "0.00": - taxcolumns.append(taxrate) - totalrow["taxamount"].update({taxrate:"%.2f"%float(taxamountdata[taxrate])}) - totalrow["tax"].update({taxrate:"%.2f"%taxamount}) - else: - totalrow["taxamount"][taxrate] = "%.2f"%(float(totalrow["taxamount"][taxrate]) + float(taxamount*float(taxrate)/100.00)) - totalrow["tax"][taxrate] = "%.2f"%(float(totalrow["tax"][taxrate]) + taxamount) + print taxrate + if taxrate != "0.00": + print "i am here" + if taxdata.has_key(str(taxrate)): + taxdata[taxrate]="%.2f"%(float(taxdata[taxrate]) + taxamount) + # print taxamount + # print taxdata + taxamountdata[taxrate]="%.2f"%(float(taxamountdata[taxrate]) + taxamount*float(taxrate)/100.00) + else: + taxdata.update({taxrate:"%.2f"%taxamount}) + taxamountdata.update({taxrate:"%.2f"%(taxamount*float(taxrate)/100.00)}) + + '''if new taxrate appears(in all invoices), ie. we found this rate for the first time then add this column to taxcolumns and also create new entries in tax & taxamount dictionaries Otherwise update existing data''' + if taxrate not in taxcolumns: + taxcolumns.append(taxrate) + print taxcolumns + totalrow["taxamount"].update({taxrate:"%.2f"%float(taxamountdata[taxrate])}) + totalrow["tax"].update({taxrate:"%.2f"%taxamount}) + else: + totalrow["taxamount"][taxrate] = "%.2f"%(float(totalrow["taxamount"][taxrate]) + float(taxamount*float(taxrate)/100.00)) + totalrow["tax"][taxrate] = "%.2f"%(float(totalrow["tax"][taxrate]) + taxamount) # print "i canceldate come here" # print row["cess"][pc] if row["cess"] != None: - print "cess found" + # print "cess found" cessrate = "%.2f"%float(row["cess"][pc]) if taxdata.has_key(str(cessrate)): taxdata[cessrate]="%.2f"%(float(taxdata[cessrate]) + taxamount) @@ -3968,6 +3972,7 @@ free replacement or sample are those which are excluded. totalrow["tax"][cessrate] = "%.2f"%(float(totalrow["tax"][cessrate]) + taxamount) invoicedata["tax"] = taxdata invoicedata["taxamount"] = taxamountdata + print taxdata spdata.append(invoicedata) srno += 1 # except: -- GitLab From 51b80075b6f08eabae798a0eda08f30e8dcfedab Mon Sep 17 00:00:00 2001 From: Prajkta_Patkar Date: Mon, 6 Nov 2017 11:47:59 +0530 Subject: [PATCH 5/8] check why 0.00 is appendinfgin tax data and taxcollums --- gkcore/views/api_reports.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/gkcore/views/api_reports.py b/gkcore/views/api_reports.py index 6e576ab..3a18f42 100644 --- a/gkcore/views/api_reports.py +++ b/gkcore/views/api_reports.py @@ -3859,7 +3859,7 @@ free replacement or sample are those which are excluded. result = invquery.fetchall() for row in result: - # try: + try: disc = row["discount"] if int(row["taxflag"]) == 7: @@ -3902,11 +3902,10 @@ free replacement or sample are those which are excluded. The other JSONB field in each invoice is row["tax"]. Its format is {"22": "2.00", "61": "2.00"}. Here, 22 and 61 are products and 2.00 is tax applied on those products, similarly for CESS {"22":"0.05"} where 22 is productcode snd 0.05 is cess rate''' #print row["contents"].keys() for pc in row["contents"].iterkeys(): - print "now we are in inner most loop" + print " i am pc" + pc discamt = 0.00 taxrate = "%.2f"%float(row["tax"][pc]) print taxrate - # print"row[cess][pc]" if disc != None: discamt = float(disc[pc]) else: @@ -3926,6 +3925,7 @@ free replacement or sample are those which are excluded. # (float("%.2f"%float(ppu))) - (float("%.2f"%float(discamt))) if taxrate == "0.00": + print "my taxrate is 0.00" invoicedata["taxfree"] = "%.2f"%((float("%.2f"%float(invoicedata["taxfree"])) + taxamount)) totalrow["taxfree"] = "%.2f"%(float(totalrow["taxfree"]) + taxamount) continue @@ -3935,13 +3935,12 @@ free replacement or sample are those which are excluded. print "i am here" if taxdata.has_key(str(taxrate)): taxdata[taxrate]="%.2f"%(float(taxdata[taxrate]) + taxamount) - # print taxamount - # print taxdata taxamountdata[taxrate]="%.2f"%(float(taxamountdata[taxrate]) + taxamount*float(taxrate)/100.00) else: + print " i am in else" taxdata.update({taxrate:"%.2f"%taxamount}) taxamountdata.update({taxrate:"%.2f"%(taxamount*float(taxrate)/100.00)}) - + '''if new taxrate appears(in all invoices), ie. we found this rate for the first time then add this column to taxcolumns and also create new entries in tax & taxamount dictionaries Otherwise update existing data''' if taxrate not in taxcolumns: taxcolumns.append(taxrate) @@ -3951,10 +3950,9 @@ free replacement or sample are those which are excluded. else: totalrow["taxamount"][taxrate] = "%.2f"%(float(totalrow["taxamount"][taxrate]) + float(taxamount*float(taxrate)/100.00)) totalrow["tax"][taxrate] = "%.2f"%(float(totalrow["tax"][taxrate]) + taxamount) - # print "i canceldate come here" - # print row["cess"][pc] + + if row["cess"] != None: - # print "cess found" cessrate = "%.2f"%float(row["cess"][pc]) if taxdata.has_key(str(cessrate)): taxdata[cessrate]="%.2f"%(float(taxdata[cessrate]) + taxamount) @@ -3970,16 +3968,21 @@ free replacement or sample are those which are excluded. else: totalrow["taxamount"][cessrate] = "%.2f"%(float(totalrow["taxamount"][cessrate]) + float(taxamount*float(cessrate)/100.00)) totalrow["tax"][cessrate] = "%.2f"%(float(totalrow["tax"][cessrate]) + taxamount) + if taxdata.has_key("0.00"): + del taxdata["0.00"] + invoicedata["tax"] = taxdata invoicedata["taxamount"] = taxamountdata - print taxdata spdata.append(invoicedata) srno += 1 - # except: - # pass + except: + pass + if "0.00" in taxcolumns: + ind = taxcolumns.index("0.00") + del [ind] taxcolumns.sort(reverse=True) a = {"gkstatus":enumdict["Success"], "gkresult":spdata, "totalrow":totalrow, "taxcolumns":taxcolumns} - #print a + print a return {"gkstatus":enumdict["Success"], "gkresult":spdata, "totalrow":totalrow, "taxcolumns":taxcolumns} except: return {"gkstatus":enumdict["ConnectionFailed"] } -- GitLab From 5f3f14e6b042069811dfdc06e6cbdc4e420e3963 Mon Sep 17 00:00:00 2001 From: Prajkta_Patkar Date: Mon, 6 Nov 2017 18:29:02 +0530 Subject: [PATCH 6/8] removed print statements also sorted taxcolumns in increasing order --- gkcore/views/api_reports.py | 49 ++++++++++++++----------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/gkcore/views/api_reports.py b/gkcore/views/api_reports.py index 3a18f42..136b5c2 100644 --- a/gkcore/views/api_reports.py +++ b/gkcore/views/api_reports.py @@ -3883,7 +3883,6 @@ free replacement or sample are those which are excluded. except: invoicedata["custgstin"] = None - # print invoicedata totalrow["grossamount"] = "%.2f"%(float(totalrow["grossamount"]) + float("%.2f"%row["invoicetotal"])) qty = 0.00 ppu = 0.00 @@ -3900,12 +3899,10 @@ free replacement or sample are those which are excluded. row["contents"] is JSONB which has format like this - {"22": {"20.00": "2"}, "61": {"100.00": "1"}} where 22 and 61 is productcode, {"20.00": "2"} here 20.00 is price per unit and quantity is 2. The other JSONB field in each invoice is row["tax"]. Its format is {"22": "2.00", "61": "2.00"}. Here, 22 and 61 are products and 2.00 is tax applied on those products, similarly for CESS {"22":"0.05"} where 22 is productcode snd 0.05 is cess rate''' - #print row["contents"].keys() + for pc in row["contents"].iterkeys(): - print " i am pc" + pc discamt = 0.00 taxrate = "%.2f"%float(row["tax"][pc]) - print taxrate if disc != None: discamt = float(disc[pc]) else: @@ -3925,26 +3922,21 @@ free replacement or sample are those which are excluded. # (float("%.2f"%float(ppu))) - (float("%.2f"%float(discamt))) if taxrate == "0.00": - print "my taxrate is 0.00" invoicedata["taxfree"] = "%.2f"%((float("%.2f"%float(invoicedata["taxfree"])) + taxamount)) totalrow["taxfree"] = "%.2f"%(float(totalrow["taxfree"]) + taxamount) continue '''if taxrate appears in this invoice then update invoice tax and taxamount for that rate Otherwise create new entries in respective dictionaries of that invoice''' - print taxrate if taxrate != "0.00": - print "i am here" if taxdata.has_key(str(taxrate)): taxdata[taxrate]="%.2f"%(float(taxdata[taxrate]) + taxamount) taxamountdata[taxrate]="%.2f"%(float(taxamountdata[taxrate]) + taxamount*float(taxrate)/100.00) else: - print " i am in else" taxdata.update({taxrate:"%.2f"%taxamount}) taxamountdata.update({taxrate:"%.2f"%(taxamount*float(taxrate)/100.00)}) '''if new taxrate appears(in all invoices), ie. we found this rate for the first time then add this column to taxcolumns and also create new entries in tax & taxamount dictionaries Otherwise update existing data''' if taxrate not in taxcolumns: taxcolumns.append(taxrate) - print taxcolumns totalrow["taxamount"].update({taxrate:"%.2f"%float(taxamountdata[taxrate])}) totalrow["tax"].update({taxrate:"%.2f"%taxamount}) else: @@ -3953,23 +3945,22 @@ free replacement or sample are those which are excluded. if row["cess"] != None: - cessrate = "%.2f"%float(row["cess"][pc]) - if taxdata.has_key(str(cessrate)): - taxdata[cessrate]="%.2f"%(float(taxdata[cessrate]) + taxamount) - taxamountdata[cessrate]="%.2f"%(float(taxamountdata[cessrate]) + taxamount*float(cessrate)/100.00) - else: - taxdata.update({cessrate:"%.2f"%taxamount}) - taxamountdata.update({cessrate:"%.2f"%(taxamount*float(cessrate)/100.00)}) + cessrate = "%.2f"%float(row["cess"][pc]) + if cessrate != "0.00": + if taxdata.has_key(str(cessrate)): + taxdata[cessrate]="%.2f"%(float(taxdata[cessrate]) + taxamount) + taxamountdata[cessrate]="%.2f"%(float(taxamountdata[cessrate]) + taxamount*float(cessrate)/100.00) + else: + taxdata.update({cessrate:"%.2f"%taxamount}) + taxamountdata.update({cessrate:"%.2f"%(taxamount*float(cessrate)/100.00)}) - if cessrate not in taxcolumns: - taxcolumns.append(cessrate) - totalrow["taxamount"].update({cessrate:"%.2f"%float(taxamountdata[cessrate])}) - totalrow["tax"].update({cessrate:"%.2f"%taxamount}) - else: - totalrow["taxamount"][cessrate] = "%.2f"%(float(totalrow["taxamount"][cessrate]) + float(taxamount*float(cessrate)/100.00)) - totalrow["tax"][cessrate] = "%.2f"%(float(totalrow["tax"][cessrate]) + taxamount) - if taxdata.has_key("0.00"): - del taxdata["0.00"] + if cessrate not in taxcolumns: + taxcolumns.append(cessrate) + totalrow["taxamount"].update({cessrate:"%.2f"%float(taxamountdata[cessrate])}) + totalrow["tax"].update({cessrate:"%.2f"%taxamount}) + else: + totalrow["taxamount"][cessrate] = "%.2f"%(float(totalrow["taxamount"][cessrate]) + float(taxamount*float(cessrate)/100.00)) + totalrow["tax"][cessrate] = "%.2f"%(float(totalrow["tax"][cessrate]) + taxamount) invoicedata["tax"] = taxdata invoicedata["taxamount"] = taxamountdata @@ -3977,12 +3968,10 @@ free replacement or sample are those which are excluded. srno += 1 except: pass - if "0.00" in taxcolumns: - ind = taxcolumns.index("0.00") - del [ind] - taxcolumns.sort(reverse=True) + + taxcolumns.sort(key=float) a = {"gkstatus":enumdict["Success"], "gkresult":spdata, "totalrow":totalrow, "taxcolumns":taxcolumns} - print a + return {"gkstatus":enumdict["Success"], "gkresult":spdata, "totalrow":totalrow, "taxcolumns":taxcolumns} except: return {"gkstatus":enumdict["ConnectionFailed"] } -- GitLab From 4d020532b9a422f8cb156453d28d5f9017de0cf9 Mon Sep 17 00:00:00 2001 From: Prajkta_Patkar Date: Mon, 6 Nov 2017 18:35:10 +0530 Subject: [PATCH 7/8] removed unecessary statements --- gkcore/views/api_reports.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gkcore/views/api_reports.py b/gkcore/views/api_reports.py index 136b5c2..f668324 100644 --- a/gkcore/views/api_reports.py +++ b/gkcore/views/api_reports.py @@ -3969,9 +3969,7 @@ free replacement or sample are those which are excluded. except: pass - taxcolumns.sort(key=float) - a = {"gkstatus":enumdict["Success"], "gkresult":spdata, "totalrow":totalrow, "taxcolumns":taxcolumns} - + taxcolumns.sort(key=float) return {"gkstatus":enumdict["Success"], "gkresult":spdata, "totalrow":totalrow, "taxcolumns":taxcolumns} except: return {"gkstatus":enumdict["ConnectionFailed"] } -- GitLab From 4e2a196d8fd2f06d463d5c465cf6cb9132b4d923 Mon Sep 17 00:00:00 2001 From: Prajkta_Patkar Date: Mon, 6 Nov 2017 19:50:13 +0530 Subject: [PATCH 8/8] issue solved for vat invoice --- gkcore/views/api_reports.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gkcore/views/api_reports.py b/gkcore/views/api_reports.py index f668324..f06d6b1 100644 --- a/gkcore/views/api_reports.py +++ b/gkcore/views/api_reports.py @@ -3858,10 +3858,9 @@ free replacement or sample are those which are excluded. #for each invoice result = invquery.fetchall() for row in result: - + try: disc = row["discount"] - if int(row["taxflag"]) == 7: destinationstate = row["taxstate"] destinationStateCode = getStateCode(row["taxstate"],self.con)["statecode"] @@ -3910,7 +3909,7 @@ free replacement or sample are those which are excluded. for pcprice in row["contents"][pc].iterkeys(): ppu = pcprice - #freeqty is subtracted + gspc = self.con.execute(select([product.c.gsflag]).where(product.c.productcode==pc)) flag = gspc.fetchone() if int(flag["gsflag"]) == 7: @@ -3920,20 +3919,22 @@ free replacement or sample are those which are excluded. else: taxamount = float(ppu) - float(discamt) # (float("%.2f"%float(ppu))) - (float("%.2f"%float(discamt))) - + if taxrate == "0.00": invoicedata["taxfree"] = "%.2f"%((float("%.2f"%float(invoicedata["taxfree"])) + taxamount)) totalrow["taxfree"] = "%.2f"%(float(totalrow["taxfree"]) + taxamount) continue '''if taxrate appears in this invoice then update invoice tax and taxamount for that rate Otherwise create new entries in respective dictionaries of that invoice''' if taxrate != "0.00": + if taxdata.has_key(str(taxrate)): taxdata[taxrate]="%.2f"%(float(taxdata[taxrate]) + taxamount) taxamountdata[taxrate]="%.2f"%(float(taxamountdata[taxrate]) + taxamount*float(taxrate)/100.00) + else: taxdata.update({taxrate:"%.2f"%taxamount}) taxamountdata.update({taxrate:"%.2f"%(taxamount*float(taxrate)/100.00)}) - + '''if new taxrate appears(in all invoices), ie. we found this rate for the first time then add this column to taxcolumns and also create new entries in tax & taxamount dictionaries Otherwise update existing data''' if taxrate not in taxcolumns: taxcolumns.append(taxrate) @@ -3943,6 +3944,8 @@ free replacement or sample are those which are excluded. totalrow["taxamount"][taxrate] = "%.2f"%(float(totalrow["taxamount"][taxrate]) + float(taxamount*float(taxrate)/100.00)) totalrow["tax"][taxrate] = "%.2f"%(float(totalrow["tax"][taxrate]) + taxamount) + if row["taxflag"] == 22: + continue if row["cess"] != None: cessrate = "%.2f"%float(row["cess"][pc]) @@ -3961,6 +3964,7 @@ free replacement or sample are those which are excluded. else: totalrow["taxamount"][cessrate] = "%.2f"%(float(totalrow["taxamount"][cessrate]) + float(taxamount*float(cessrate)/100.00)) totalrow["tax"][cessrate] = "%.2f"%(float(totalrow["tax"][cessrate]) + taxamount) + invoicedata["tax"] = taxdata invoicedata["taxamount"] = taxamountdata @@ -3969,7 +3973,7 @@ free replacement or sample are those which are excluded. except: pass - taxcolumns.sort(key=float) + taxcolumns.sort(key=float) return {"gkstatus":enumdict["Success"], "gkresult":spdata, "totalrow":totalrow, "taxcolumns":taxcolumns} except: return {"gkstatus":enumdict["ConnectionFailed"] } -- GitLab