Commit decc6bfe authored by Prajkta Patkar's avatar Prajkta Patkar
Browse files

Merge branch 'devel' into 'master'

Merge branch Devel to Master

See merge request !16
parents b0e08fb1 126297a6
Active Contributors
"Abhijith Balan" <abhijith@dff.org.in>
"Bhavesh Bawadhane" <bbhavesh07@gmail.com>
"Mohd. Talha Pawaty"<mtalha456@gmail.com>
"Prajkta Patkar" <prajakta@dff.org.in>
"Reshma Bhatawadekar" <bhatawadekar1reshma@gmail.com>
"Rohini Baraskar"<robaraskar@gmail.com>
"Vaibhav Kurhe" <vaibspidy@openmailbox.org>
"Reshma Bhatawadekar" <reshma@dff.org.in>
"Arun Kelkar" - Domain Expert - <arunkelkar@dff.org.in>
......@@ -16,8 +14,8 @@ Past contributers
Abhijeet Mote, Abhishek Alai, Aditi Patil, Akshay Puradkar, Amit Chaugule,
Ankita Shanbhag, Aparna Kokirkar, Ashwini Jogdand, Ashwini Shinde, Ashutosh Paralikar
Avinash Pathak, Dinesh Sutar, Ganesh Mashram, Girish Joshi, Girish Mane, Ishan Masdekar
Avinash Pathak,Bhavesh Bawadhane,Dinesh Sutar, Ganesh Mashram, Girish Joshi, Girish Mane, Ishan Masdekar
Kanchan Kayande, Kanchan Palatane,Namita Dubey,Navin Karkera ,Nutan Nivate, Payal Mamidwar,
Parabjyot Singh,, Poonam Dhane, Pornima Kolte,Prasad Shegokar, Priyali Mhetre,Radhika Vadegaonkar kulkarni,
Rahul Chaurasiya ,Ravindra Lakal, Rupali Markad, Sachin Patil,Sadhana Bagal,Sayali Yawle, Snehal Nighut, Shruti Surve,
Shweta Pawar, Sundeep Padmanabh,Trupti Kini, Ujwala Pawde, Vaishali Kamble,Vanita Rajpurohit, Vinayak Kusumkar and Vishakha Divekar.
Rahul Chaurasiya ,Ravindra Lakal, Rupali Markad,Rohini Baraskar,Sachin Patil,Sadhana Bagal,Sayali Yawle, Snehal Nighut, Shruti Surve,
Shweta Pawar, Sundeep Padmanabh,Trupti Kini, Ujwala Pawde, Vaibhav Kurhe,Vaishali Kamble,Vanita Rajpurohit, Vinayak Kusumkar and Vishakha Divekar.
[10-November-2017 Release 4.25 Update]
* Permissions to Godown In Charge modified.
* CESS field added in invoice and cash memo.
* Sales and purchase register now reflects along with CESS.
* Gkupgrade modified as per modifications in gkdb.
* Transfer Note get all function modified.
* A function to get user role.
* Get all delchal function.
* Minor bugs solved.
[21-September-2017 Release 4.25]
*Gkupgrade modified as per modifications in gkdb
*List of users report
......
......@@ -291,9 +291,11 @@ Note that invoice is connected to a voucher.
So the accounting part is thus connected with stock movement of that cost.
A new json field called freeqty.
Consignee (shipped to) is a json field which has name , address, state, statecode,gstin as keys along with its value.
Bankdetails is a dictionary will have bankname,accountno. and ifsccode.
Bankdetails is a dictionary will have bankname,accountno., branchname and ifsccode.
taxstate is a destination sate.
sourcestate is source state from where invoice is initiated
sourcestate is source state from where invoice is initiated.
Structure of a tax field is {productcode:taxrate}
save orgstategstin of sourcestate for organisation.
"""
invoice = Table('invoice',metadata,
Column('invid',Integer,primary_key=True),
......@@ -304,11 +306,13 @@ invoice = Table('invoice',metadata,
Column('issuername', UnicodeText),
Column('designation', UnicodeText),
Column('tax', JSONB),
Column('cess',JSONB),
Column('amountpaid',Numeric(13,2),default=0.00),
Column('invoicetotal', Numeric(13,2),nullable=False),
Column('icflag',Integer,default=9),
Column('taxstate',UnicodeText),
Column('sourcestate',UnicodeText),
Column('orgstategstin',UnicodeText),
Column('attachment',JSON),
Column('attachmentcount',Integer,default=0),
Column('orderid', Integer,ForeignKey('purchaseorder.orderid')),
......
......@@ -40,6 +40,7 @@ import jwt
import gkcore
from gkcore.views.api_login import authCheck
from gkcore.views.api_user import getUserRole
from gkcore.views.api_godown import getusergodowns
@view_defaults(route_name='delchal')
class api_delchal(object):
......@@ -155,12 +156,39 @@ class api_delchal(object):
else:
try:
self.con = eng.connect()
'''
Retreiving details of all delivery notes.
'''
result = self.con.execute(select([delchal.c.dcid,delchal.c.dcno,delchal.c.custid,delchal.c.dcdate, delchal.c.noofpackages, delchal.c.modeoftransport, delchal.c.attachmentcount]).where(delchal.c.orgcode==authDetails["orgcode"]).order_by(delchal.c.dcno))
'''
An empty list is created. Details of each delivery note and customer/supplier associated with it is stored in it.
Loop is used to go through the result, fetch customer/supplier data and append them to the list.
Each entry in the list is in the form of a dictionary. See line 171 to find the structure of the dictionary.
'''
delchals = []
for row in result:
custdata = self.con.execute(select([customerandsupplier.c.custname,customerandsupplier.c.csflag]).where(customerandsupplier.c.custid==row["custid"]))
custrow = custdata.fetchone()
delchals.append({"dcid":row["dcid"],"dcno":row["dcno"],"custname":custrow["custname"],"csflag":custrow["csflag"],"dcdate":datetime.strftime(row["dcdate"],'%d-%m-%Y'), "attachmentcount":row["attachmentcount"]})
'''
A list of all godowns assigned to a user is retreived from API for godowns using the method usergodowmns.
If user is not a godown keeper this list will be empty.
If user has godowns assigned, only those delivery notes for moving goods into those godowns are appended into the above list.
'''
usergodowmns = getusergodowns(authDetails["userid"])["gkresult"]
if usergodowmns:
godowns = []
for godown in usergodowmns:
godowns.append(godown["goid"])
for row in result:
delchalgodown = self.con.execute(select([stock.c.goid]).where(and_(stock.c.dcinvtnid == row["dcid"], stock.c.dcinvtnflag == 4)))
delchalgodata = delchalgodown.fetchone()
delchalgoid = delchalgodata["goid"]
if delchalgoid in godowns:
custdata = self.con.execute(select([customerandsupplier.c.custname,customerandsupplier.c.csflag]).where(customerandsupplier.c.custid==row["custid"]))
custrow = custdata.fetchone()
delchals.append({"dcid":row["dcid"],"dcno":row["dcno"],"custname":custrow["custname"],"csflag":custrow["csflag"],"dcdate":datetime.strftime(row["dcdate"],'%d-%m-%Y'), "attachmentcount":row["attachmentcount"]})
else:
for row in result:
custdata = self.con.execute(select([customerandsupplier.c.custname,customerandsupplier.c.csflag]).where(customerandsupplier.c.custid==row["custid"]))
custrow = custdata.fetchone()
delchals.append({"dcid":row["dcid"],"dcno":row["dcno"],"custname":custrow["custname"],"csflag":custrow["csflag"],"dcdate":datetime.strftime(row["dcdate"],'%d-%m-%Y'), "attachmentcount":row["attachmentcount"]})
return {"gkstatus": gkcore.enumdict["Success"], "gkresult":delchals }
except:
return {"gkstatus":gkcore.enumdict["ConnectionFailed"] }
......@@ -177,7 +205,7 @@ class api_delchal(object):
if authDetails["auth"] == False:
return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]}
else:
# try:
try:
self.con = eng.connect()
result = self.con.execute(select([delchal]).where(delchal.c.dcid==self.request.params["dcid"]))
delchaldata = result.fetchone()
......@@ -192,7 +220,6 @@ class api_delchal(object):
for stockrow in stockdata:
productdata = self.con.execute(select([product.c.productdesc,product.c.uomid]).where(and_(product.c.productcode==stockrow["productcode"],product.c.gsflag==7)))
productdesc = productdata.fetchone()
print productdesc
uomresult = self.con.execute(select([unitofmeasurement.c.unitname]).where(unitofmeasurement.c.uomid==productdesc["uomid"]))
unitnamrrow = uomresult.fetchone()
items[stockrow["productcode"]] = {"qty":"%.2f"%float(stockrow["qty"]),"productdesc":productdesc["productdesc"],"unitname":unitnamrrow["unitname"]}
......@@ -225,10 +252,10 @@ class api_delchal(object):
singledelchal["delchaldata"]["goname"]=goname["goname"]
singledelchal["delchaldata"]["gostate"]=goname["state"]
return {"gkstatus": gkcore.enumdict["Success"], "gkresult":singledelchal }
# except:
# return {"gkstatus":gkcore.enumdict["ConnectionFailed"] }
# finally:
# self.con.close()
except:
return {"gkstatus":gkcore.enumdict["ConnectionFailed"] }
finally:
self.con.close()
@view_config(request_param="delchal=last",request_method='GET',renderer='json')
def getLastDelChalDetails(self):
......
......@@ -216,13 +216,13 @@ class api_godown(object):
if authDetails["auth"] == False:
return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]}
else:
#try:
try:
self.con = eng.connect()
result = getusergodowns(self.request.params["userid"])
return {"gkstatus": gkcore.enumdict["Success"], "gkresult":result["gkresult"]}
#except:
except:
return {"gkstatus":gkcore.enumdict["ConnectionFailed"] }
#finally:
finally:
self.con.close()
......
......@@ -268,7 +268,7 @@ There will be an icFlag which will determine if it's an incrementing or decreme
self.con = eng.connect()
result = self.con.execute(select([invoice]).where(invoice.c.invid==self.request.params["invid"]))
invrow = result.fetchone()
inv = {"invid":invrow["invid"],"taxflag":invrow["taxflag"],"invoiceno":invrow["invoiceno"],"invoicedate":datetime.strftime(invrow["invoicedate"],"%d-%m-%Y"),"icflag":invrow["icflag"],"invoicetotal":"%.2f"%float(invrow["invoicetotal"]),"bankdetails":invrow["bankdetails"]}
inv = {"invid":invrow["invid"],"taxflag":invrow["taxflag"],"invoiceno":invrow["invoiceno"],"invoicedate":datetime.strftime(invrow["invoicedate"],"%d-%m-%Y"),"icflag":invrow["icflag"],"invoicetotal":"%.2f"%float(invrow["invoicetotal"]),"bankdetails":invrow["bankdetails"], "orgstategstin":invrow["orgstategstin"]}
if invrow["sourcestate"] != None:
inv["sourcestate"] = invrow["sourcestate"]
inv["sourcestatecode"] = getStateCode(invrow["sourcestate"],self.con)["statecode"]
......@@ -302,7 +302,7 @@ There will be an icFlag which will determine if it's an incrementing or decreme
delchalData = dc.fetchone()
inv["dcid"]=dcid["dcid"]
inv["dcno"]=delchalData["dcno"]
inOut = self.con.execute(select([stock.c.inout]).where(stock.c.dcinvtnid==dcid["dcid"]))
inOut = self.con.execute(select([stock.c.inout]).where(and_(stock.c.dcinvtnid==dcid["dcid"], stock.c.dcinvtnflag==4)))
inOutData = inOut.fetchone()
if inOutData != None:
inv["inoutflag"] = int(inOutData["inout"])
......@@ -337,6 +337,7 @@ There will be an icFlag which will determine if it's an incrementing or decreme
totalDisc = 0.00
totalTaxableVal = 0.00
totalTaxAmt = 0.00
totalCessAmt = 0.00
discounts = invrow["discount"]
freeqtys = invrow["freeqty"]
#now looping through the contents.
......@@ -369,6 +370,7 @@ There will be an icFlag which will determine if it's an incrementing or decreme
if int(invrow["taxflag"]) == 22:
taxRate = float(invrow["tax"][pc])
taxAmount = (taxableAmount * float(taxRate/100))
taxname = 'VAT'
totalAmount = float(taxableAmount) + (float(taxableAmount) * float(taxRate/100))
totalDisc = totalDisc + float(discount)
totalTaxableVal = totalTaxableVal + taxableAmount
......@@ -378,24 +380,37 @@ There will be an icFlag which will determine if it's an incrementing or decreme
else:
TaxData = calTax(7,invrow["sourcestate"],invrow["taxstate"],pc,self.con)
taxResult = TaxData["gkresult"]
taxRate = float(taxResult["taxrate"])
inv["taxname"] = taxResult["taxname"]
if taxResult["taxname"] == "IGST":
cessRate = 0.00
cessAmount = 0.00
cessVal = 0.00
taxname = ""
if taxResult.has_key('CESS'):
cessVal = float(taxResult["CESS"])
cessAmount = (taxableAmount * (cessVal/100))
totalCessAmt = totalCessAmt + cessAmount
if taxResult.has_key('IGST'):
taxname = "IGST"
taxRate = float(taxResult["IGST"])
taxAmount = (taxableAmount * (taxRate/100))
totalAmount = taxableAmount + (taxableAmount * (taxRate/100))
totalAmount = taxableAmount + taxAmount + cessAmount
else:
taxname = "SGST"
taxRate = float(taxResult["SGST"])
taxAmount = (taxableAmount * (taxRate/100))
totalAmount = taxableAmount + (taxableAmount * ((taxRate * 2)/100))
totalAmount = taxableAmount + (taxableAmount * ((taxRate * 2)/100)) + cessAmount
totalDisc = totalDisc + float(discount)
totalTaxableVal = totalTaxableVal + taxableAmount
totalTaxAmt = totalTaxAmt + taxAmount
invContents[pc] = {"proddesc":prodrow["productdesc"],"gscode":prodrow["gscode"],"uom":unitofMeasurement,"qty":"%.2f"% (float(contentsData[pc][contentsData[pc].keys()[0]])),"freeqty":"%.2f"% (float(freeqty)),"priceperunit":"%.2f"% (float(contentsData[pc].keys()[0])),"discount":"%.2f"% (float(discount)),"taxableamount":"%.2f"%(float(taxableAmount)),"totalAmount":"%.2f"% (float(totalAmount)),"taxname":taxResult["taxname"],"taxrate":"%.2f"% (float(taxRate)),"taxamount":"%.2f"% (float(taxAmount))}
invContents[pc] = {"proddesc":prodrow["productdesc"],"gscode":prodrow["gscode"],"uom":unitofMeasurement,"qty":"%.2f"% (float(contentsData[pc][contentsData[pc].keys()[0]])),"freeqty":"%.2f"% (float(freeqty)),"priceperunit":"%.2f"% (float(contentsData[pc].keys()[0])),"discount":"%.2f"% (float(discount)),"taxableamount":"%.2f"%(float(taxableAmount)),"totalAmount":"%.2f"% (float(totalAmount)),"taxname":taxname,"taxrate":"%.2f"% (float(taxRate)),"taxamount":"%.2f"% (float(taxAmount)),"cess":"%.2f"%(float(cessAmount)),"cessrate":"%.2f"%(float(cessVal))}
inv["totaldiscount"] = "%.2f"% (float(totalDisc))
inv["totaltaxablevalue"] = "%.2f"% (float(totalTaxableVal))
inv["totaltaxamt"] = "%.2f"% (float(totalTaxAmt))
inv["totalcessamt"] = "%.2f"% (float(totalCessAmt))
inv['taxname'] = taxname
inv["invcontents"] = invContents
return {"gkstatus":gkcore.enumdict["Success"],"gkresult":inv}
except:
......@@ -471,9 +486,16 @@ The bills grid calld gkresult will return a list as it's value.
result = self.con.execute(select([invoice.c.invoiceno,invoice.c.invid,invoice.c.invoicedate,invoice.c.custid,invoice.c.invoicetotal,invoice.c.attachmentcount]).where(and_(invoice.c.orgcode==authDetails["orgcode"],invoice.c.icflag==9)).order_by(invoice.c.invoicedate))
invoices = []
for row in result:
result = self.con.execute(select([customerandsupplier.c.custname,customerandsupplier.c.csflag]).where(customerandsupplier.c.custid==row["custid"]))
custname = result.fetchone()
invoices.append({"invoiceno":row["invoiceno"], "invid":row["invid"],"custname":custname["custname"],"csflag":custname["csflag"],"invoicedate":datetime.strftime(row["invoicedate"],'%d-%m-%Y'),"invoicetotal":"%.2f"%float(row["invoicetotal"]), "attachmentcount":row["attachmentcount"]})
customer = self.con.execute(select([customerandsupplier.c.custname,customerandsupplier.c.csflag]).where(customerandsupplier.c.custid==row["custid"]))
custname = customer.fetchone()
if self.request.params.has_key('type'):
if str(self.request.params["type"]) == 'sale' and int(custname['csflag']) == 3:
invoices.append({"invoiceno":row["invoiceno"], "invid":row["invid"],"custname":custname["custname"],"csflag":custname["csflag"],"invoicedate":datetime.strftime(row["invoicedate"],'%d-%m-%Y'),"invoicetotal":"%.2f"%float(row["invoicetotal"]), "attachmentcount":row["attachmentcount"]})
elif str(self.request.params["type"]) == 'purchase' and int(custname['csflag']) == 19:
invoices.append({"invoiceno":row["invoiceno"], "invid":row["invid"],"custname":custname["custname"],"csflag":custname["csflag"],"invoicedate":datetime.strftime(row["invoicedate"],'%d-%m-%Y'),"invoicetotal":"%.2f"%float(row["invoicetotal"]), "attachmentcount":row["attachmentcount"]})
else:
invoices.append({"invoiceno":row["invoiceno"], "invid":row["invid"],"custname":custname["custname"],"csflag":custname["csflag"],"invoicedate":datetime.strftime(row["invoicedate"],'%d-%m-%Y'),"invoicetotal":"%.2f"%float(row["invoicetotal"]), "attachmentcount":row["attachmentcount"]})
return {"gkstatus": gkcore.enumdict["Success"], "gkresult":invoices }
except:
return {"gkstatus":gkcore.enumdict["ConnectionFailed"]}
......
......@@ -20,11 +20,11 @@ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation
Contributors:
"Krishnakant Mane" <kk@gmail.com>
"Krishnakant Mane" <kkmane@riseup.net>
"Ishan Masdekar " <imasdekar@dff.org.in>
"Navin Karkera" <navin@dff.org.in>
'Prajkta Patkar'<prajkta@dff.org.in>
'Reshma Bhatwadekar'<bhatawadekar1reshma@gmail.com>
'Prajkta Patkar'<prajakta@dff.org.in>
'Reshma Bhatwadekar'<reshma_b@riseup.net>
"""
from pyramid.view import view_defaults, view_config
......@@ -60,6 +60,8 @@ class api_organisation(object):
"""
self.con = eng.connect()
try:
self.con.execute(select([func.count(gkdb.invoice.c.orgstategstin)]))
self.con.execute(select([func.count(gkdb.invoice.c.cess)]))
self.con.execute(select([func.count(gkdb.state.c.statecode)]))
self.con.execute(select([func.count(gkdb.invoice.c.reversecharge)]))
self.con.execute(select(gkdb.organisation.c.gstin))
......@@ -78,6 +80,9 @@ class api_organisation(object):
self.con.execute(select(gkdb.organisation.c.billflag))
self.con.execute(select([func.count(gkdb.billwise.c.billid)]))
except:
self.con.execute("update invoice set reversecharge = '0'" )
self.con.execute("alter table invoice add orgstategstin text")
self.con.execute("alter table invoice add cess jsonb")
self.con.execute("alter table product add UNIQUE(productdesc,orgcode)")
self.con.execute("create table state( statecode integer,statename text,primary key (statecode))")
self.con.execute("insert into state( statecode, statename)values(1, 'Jammu and Kashmir')")
......@@ -461,11 +466,24 @@ class api_organisation(object):
except:
self.con.close()
return {"gkstatus":enumdict["ConnectionFailed"]}
@view_config(request_method="GET",renderer="json",request_param="osg=true")
def getOrgStateGstin(self):
token = self.request.headers['gktoken']
authDetails = authCheck(token)
if authDetails["auth"]==False:
return {"gkstatus":enumdict["UnauthorisedAccess"]}
else:
try:
self.con =eng.connect()
gstinResult = self.con.execute("select gstin ->> '%d' as stgstin from organisation where gstin ? '%d' and orgcode = %d "%(int(self.request.params["statecode"]),int(self.request.params["statecode"]),int(authDetails["orgcode"])))
gstinval = ""
if gstinResult.rowcount > 0 :
gstinrow = gstinResult.fetchone()
gstinval = str(gstinrow["stgstin"])
return{"gkstatus":enumdict["Success"],"gkresult":gstinval}
except:
return {"gkstatus": enumdict["ConnectionFailed"]}
@view_config(request_method='PUT', renderer='json')
def putOrg(self):
token = self.request.headers['gktoken']
......
This diff is collapsed.
......@@ -3845,14 +3845,13 @@ 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')))
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":{}}
......@@ -3862,7 +3861,6 @@ free replacement or sample are those which are excluded.
try:
disc = row["discount"]
if int(row["taxflag"]) == 7:
destinationstate = row["taxstate"]
destinationStateCode = getStateCode(row["taxstate"],self.con)["statecode"]
......@@ -3887,9 +3885,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 = {}
......@@ -3898,58 +3897,83 @@ 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():
discamt = 0.00
taxrate = "%.2f"%float(row["tax"][pc])
if disc != None:
discamt = float(disc[pc])
else:
discamt = 0.00
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:
qty = float(row["contents"][pc][pcprice]) - float(row["freeqty"][pc]) if row["freeqty"].has_key(pc) else 0.00
taxamount = (float(ppu) - float(discamt)) * float(qty)
#(((float("%.2f"%float(ppu))) - (float("%.2f"%float(discamt)))) * float("%.2f"%float(qty))
qty = float(row["contents"][pc][pcprice])
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'''
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)
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 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)
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 row["taxflag"] == 22:
continue
if row["cess"] != None:
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)
invoicedata["tax"] = taxdata
invoicedata["taxamount"] = taxamountdata
spdata.append(invoicedata)
srno += 1
except:
pass
taxcolumns.sort(reverse=True)
taxcolumns.sort(key=float)
return {"gkstatus":enumdict["Success"], "gkresult":spdata, "totalrow":totalrow, "taxcolumns":taxcolumns}
except:
return {"gkstatus":enumdict["ConnectionFailed"] }
......
This diff is collapsed.
......@@ -39,6 +39,7 @@ from datetime import datetime,date
import jwt
import gkcore
from gkcore.models.meta import dbconnect
from gkcore.views.api_godown import getusergodowns
@view_defaults(route_name='transfernote')
class api_transfernote(object):
......@@ -120,10 +121,30 @@ class api_transfernote(object):
else:
try:
self.con = eng.connect()
result = self.con.execute(select([transfernote.c.transfernotedate,transfernote.c.transfernoteid,transfernote.c.transfernoteno]).where(and_(transfernote.c.recieved==False,transfernote.c.orgcode==authDetails["orgcode"])).order_by(transfernote.c.transfernotedate))
'''
Retreiving date, id, number and togodown of all transfernotes.
'''
result = self.con.execute(select([transfernote.c.transfernotedate,transfernote.c.transfernoteid,transfernote.c.transfernoteno,transfernote.c.togodown]).where(and_(transfernote.c.recieved==False,transfernote.c.orgcode==authDetails["orgcode"])).order_by(transfernote.c.transfernotedate))
'''
A list of all godowns assigned to a user is retreived from API for godowns using the method usergodowmns.
If user is not a godown keeper this list will be empty.
'''
usergodowmns = getusergodowns(authDetails["userid"])["gkresult"]
'''
If user has godowns assigned only those unreceived transfernotes for moving goods into those godowns are returned.
Otherwise all transfernotes that have not been received are returned.
'''
tn = []
for row in result:
tn.append({"transfernoteno": row["transfernoteno"],"transfernoteid": row["transfernoteid"], "transfernotedate":datetime.strftime(row["transfernotedate"],'%d-%m-%Y')})
if usergodowmns:
godowns = []
for godown in usergodowmns:
godowns.append(godown["goid"])
for row in result:
if row["togodown"] in godowns:
tn.append({"transfernoteno": row["transfernoteno"],"transfernoteid": row["transfernoteid"], "transfernotedate":datetime.strftime(row["transfernotedate"],'%d-%m-%Y')})
else:
for row in result:
tn.append({"transfernoteno": row["transfernoteno"],"transfernoteid": row["transfernoteid"], "transfernotedate":datetime.strftime(row["transfernotedate"],'%d-%m-%Y')})
self.con.close()
return {"gkstatus":enumdict["Success"], "gkresult":tn}
except:
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment