Commit 9dd05c70 authored by Prajkta Patkar's avatar Prajkta Patkar
Browse files

Merge branch 'branchmenu' into 'devel'

Branchmenu

See merge request gnukhata/gkcore!476
parents 1f63c6af 03983305
......@@ -307,6 +307,7 @@ vouchers=Table('vouchers', metadata,
Column('orgcode',Integer, ForeignKey('organisation.orgcode',ondelete="CASCADE"), nullable=False),
Column('invid',Integer,ForeignKey('invoice.invid')),
Column('drcrid',Integer,ForeignKey('drcr.drcrid')),
Column('goid', Integer,ForeignKey('godown.goid')),
Column('instrumentno',UnicodeText),
Column('bankname',UnicodeText),
Column('branchname',UnicodeText),
......@@ -358,6 +359,7 @@ invoice = Table('invoice',metadata,
Column('attachment',JSON),
Column('attachmentcount',Integer,default=0),
Column('orderid', Integer,ForeignKey('purchaseorder.orderid')),
Column('goid', Integer,ForeignKey('godown.goid')),
Column('orgcode',Integer, ForeignKey('organisation.orgcode',ondelete="CASCADE"), nullable=False),
Column('custid',Integer, ForeignKey('customerandsupplier.custid')),
Column('consignee',JSONB),
......@@ -548,6 +550,7 @@ purchaseorder = Table( 'purchaseorder' , metadata,
Column('schedule',JSONB),
Column('taxstate',UnicodeText),
Column('psflag',Integer,nullable=False),
Column('goid', Integer,ForeignKey('godown.goid')),
Column('orgcode',Integer, ForeignKey('organisation.orgcode',ondelete="CASCADE"), nullable=False),
Column('csid',Integer,ForeignKey('customerandsupplier.custid',ondelete="CASCADE"), nullable=False),
Column('togodown',Integer,ForeignKey('godown.goid', ondelete = "CASCADE")),
......@@ -681,6 +684,7 @@ rejectionnote = Table('rejectionnote',metadata,
Column('rndate', DateTime, nullable=False),
Column('inout', Integer, nullable=False),
Column('rejprods',JSONB,nullable=False),
Column('goid', Integer,ForeignKey('godown.goid')),
Column('dcid',Integer ,ForeignKey('delchal.dcid',ondelete = "CASCADE")),
Column('invid',Integer ,ForeignKey('invoice.invid',ondelete = "CASCADE")),
Column('issuerid',Integer,ForeignKey('users.userid',ondelete="CASCADE")),
......@@ -717,6 +721,7 @@ drcr = Table('drcr', metadata,
Column('attachment',JSON),
Column('attachmentcount',Integer,default=0),
Column('userid',Integer,ForeignKey('users.userid')),
Column('goid', Integer,ForeignKey('godown.goid')),
UniqueConstraint('orgcode','drcrno','dctypeflag'),
UniqueConstraint('orgcode','invid','dctypeflag'),
UniqueConstraint('orgcode','rnid','dctypeflag')
......
This diff is collapsed.
......@@ -90,7 +90,11 @@ class api_drcr(object):
if av["avflag"] == 1:
mafl = self.con.execute(select([organisation.c.maflag]).where(organisation.c.orgcode == dataset["orgcode"]))
maFlag = mafl.fetchone()
queryParams = {"maflag":maFlag["maflag"], "cessname":"CESS", "drcrid":drcrid["drcrid"]}
# adding goid which is branchid below to add that id into voucher if branchvise.
if "goid" in dataset:
queryParams = {"maflag":maFlag["maflag"], "cessname":"CESS", "drcrid":drcrid["drcrid"],"goid":dataset["goid"]}
else:
queryParams = {"maflag":maFlag["maflag"], "cessname":"CESS", "drcrid":drcrid["drcrid"]}
queryParams.update(dataset)
queryParams.update(vdataset)
try:
......@@ -289,8 +293,13 @@ class api_drcr(object):
return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]}
else:
try:
# below goid is used as branchid when it selected as brancvise.
# it will give only that branch related.
self.con = eng.connect()
result = self.con.execute(select([drcr.c.drcrno,drcr.c.drcrid,drcr.c.drcrdate,drcr.c.invid,drcr.c.dctypeflag,drcr.c.totreduct,drcr.c.attachmentcount]).where(drcr.c.orgcode==authDetails["orgcode"]).order_by(drcr.c.drcrdate))
if "goid" in authDetails:
result = self.con.execute(select([drcr.c.drcrno,drcr.c.drcrid,drcr.c.drcrdate,drcr.c.invid,drcr.c.dctypeflag,drcr.c.totreduct,drcr.c.attachmentcount]).where(and_(drcr.c.orgcode==authDetails["orgcode"],drcr.c.goid==authDetails["goid"])).order_by(drcr.c.drcrdate))
else:
result = self.con.execute(select([drcr.c.drcrno,drcr.c.drcrid,drcr.c.drcrdate,drcr.c.invid,drcr.c.dctypeflag,drcr.c.totreduct,drcr.c.attachmentcount]).where(drcr.c.orgcode==authDetails["orgcode"]).order_by(drcr.c.drcrdate))
drcrdata = []
for row in result:
#invoice,cust
......@@ -397,10 +406,15 @@ class api_drcr(object):
self.con = eng.connect()
drcrflag = int(self.request.params["drcrflag"])
DrCrInvs = []
invsInDrCr = self.con.execute(select([drcr.c.invid]).where(and_(drcr.c.orgcode==authDetails["orgcode"], drcr.c.dctypeflag == drcrflag)))
# goid is used as branchid
if "goid" in authDetails:
invsInDrCr = self.con.execute(select([drcr.c.invid]).where(and_(drcr.c.orgcode==authDetails["orgcode"], drcr.c.dctypeflag == drcrflag,drcr.c.goid==authDetails["goid"])))
invData = 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.goid==authDetails["goid"],invoice.c.icflag==9)).order_by(invoice.c.invoicedate))
else:
invsInDrCr = self.con.execute(select([drcr.c.invid]).where(and_(drcr.c.orgcode==authDetails["orgcode"], drcr.c.dctypeflag == drcrflag)))
invData = 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))
for DrCrInv in invsInDrCr:
DrCrInvs.append(DrCrInv["invid"])
invData = 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 invData:
if row["invid"] not in DrCrInvs:
......@@ -1066,6 +1080,11 @@ def drcrVoucher(queryParams, orgcode):
vchCode = vchCodeResult.fetchone()
initialType = initialType + str(vchCode["vcode"])
voucherDict["vouchernumber"] = initialType
# goid is acts as branchid which will add into goid field of voucher table.
# so the voucher will be related to that branch.
if "goid" in queryParams:
voucherDict["goid"] = queryParams["goid"]
result = con.execute(vouchers.insert(),[voucherDict])
for drkeys in drs.keys():
con.execute("update accounts set vouchercount = vouchercount +1 where accountcode = %d"%(int(drkeys)))
......
This diff is collapsed.
......@@ -33,13 +33,14 @@ from gkcore.models import gkdb
from sqlalchemy.sql import select
import json
from sqlalchemy.engine.base import Connection
from sqlalchemy import and_
from sqlalchemy import and_ , func
from pyramid.request import Request
from pyramid.response import Response
from pyramid.view import view_defaults, view_config
from sqlalchemy.ext.baked import Result
from Crypto.PublicKey import RSA
from gkcore.models.meta import inventoryMigration,addFields
from gkcore.models.gkdb import godown, usergodown
import jwt
import gkcore
con= Connection
......@@ -47,16 +48,16 @@ con= Connection
@view_config(route_name='login',request_method='POST',renderer='json')
def gkLogin(request):
"""
purpose: take org code, username and password and authenticate the user.
Return true if username and password matches or false otherwise.
description:
The function takes the orgcode and matches the username and password.
if it is correct then the user is authorised and a jwt object is created.
The object will have the userid and orgcode and this will be sent back as a response.
Else the function will not issue any token.
"""
try:
# """
# purpose: take org code, username and password and authenticate the user.
# Return true if username and password matches or false otherwise.
# description:
# The function takes the orgcode and matches the username and password.
# if it is correct then the user is authorised and a jwt object is created.
# The object will have the userid and orgcode and this will be sent back as a response.
# Else the function will not issue any token.
# """
# try:
con= eng.connect()
try:
con.execute(select([gkdb.organisation.c.invflag]))
......@@ -67,10 +68,8 @@ def gkLogin(request):
con.execute(select([gkdb.transfernote.c.recieveddate]))
except:
addFields(con,eng)
dataset = request.json_body
result = con.execute(select([gkdb.users.c.userid]).where(and_(gkdb.users.c.username==dataset["username"], gkdb.users.c.userpassword== dataset["userpassword"], gkdb.users.c.orgcode==dataset["orgcode"])) )
result = con.execute(select([gkdb.users.c.userid, gkdb.users.c.userrole]).where(and_(gkdb.users.c.username==dataset["username"], gkdb.users.c.userpassword== dataset["userpassword"], gkdb.users.c.orgcode==dataset["orgcode"])) )
if result.rowcount == 1:
record = result.fetchone()
result = con.execute(select([gkdb.signature]))
......@@ -89,14 +88,35 @@ def gkLogin(request):
sig = {"secretcode":privatekey}
gkcore.secret = privatekey
result = con.execute(gkdb.signature.insert(),[sig])
token = jwt.encode({"orgcode":dataset["orgcode"],"userid":record["userid"]},gkcore.secret,algorithm='HS256')
return {"gkstatus":enumdict["Success"],"token":token }
# goid is use for branch. Its acts as branchid.
# when loged in branchvise.
# if userrole is -1 then it is super user and can have full access.
if record["userrole"] == -1:
token = jwt.encode({"orgcode":dataset["orgcode"],"userid":record["userid"]},gkcore.secret,algorithm='HS256')
return {"gkstatus":enumdict["Success"],"token":token }
elif "goid" in dataset:
godow = con.execute(select([usergodown.c.goid]).where(usergodown.c.userid == record["userid"]))
# fetch goid asign to userid enter. if that goid matches with enter goid then gives access to that branch.
# either generate error.
for row in godow:
if (row["goid"] == int(dataset["goid"])):
token = jwt.encode({"orgcode":dataset["orgcode"],"userid":record["userid"],"goid":dataset["goid"]},gkcore.secret,algorithm='HS256')
return {"gkstatus":enumdict["Success"],"token":token }
# if goid is not asign to user then it will show an error.
return {"gkstatus":enumdict["BadPrivilege"]}
else:
godown = con.execute("select count(godown.goid) as bcount from godown inner join usergodown on godown.goid = usergodown.goid where usergodown.userid = '%d' and godown.gbflag=2"%int(record["userid"]))
count = godown.fetchone()
if (count["bcount"] > 0):
return {"gkstatus":enumdict["BadPrivilege"]}
token = jwt.encode({"orgcode":dataset["orgcode"],"userid":record["userid"]},gkcore.secret,algorithm='HS256')
return {"gkstatus":enumdict["Success"],"token":token }
else:
return {"gkstatus":enumdict["UnauthorisedAccess"]}
except:
return {"gkstatus":enumdict["ConnectionFailed"]}
finally:
con.close()
# except:
# return {"gkstatus":enumdict["ConnectionFailed"]}
# finally:
# con.close()
@view_config(route_name='login',request_method='GET',renderer='json')
def getuserorgdetails(request):
......@@ -129,6 +149,9 @@ def authCheck(token):
tokendict["auth"] = True
tokendict["orgcode"]=int(tokendict["orgcode"])
tokendict["userid"]=int(tokendict["userid"])
#updated for branch feature. goid is for branchid.
if "goid" in tokendict:
tokendict["goid"]=int(tokendict["goid"])
return tokendict
except:
tokendict = {"auth":False}
......
......@@ -49,6 +49,7 @@ from Crypto.PublicKey import RSA
from gkcore.models.gkdb import metadata
from gkcore.models.meta import inventoryMigration,addFields, columnExists, tableExists
from gkcore.views.api_invoice import getStateCode
from gkcore.models.gkdb import godown, usergodown, stock, goprod
con= Connection
@view_defaults(route_name='organisations')
......@@ -111,6 +112,16 @@ class api_organisation(object):
except:
self.con.execute("update unitofmeasurement set sysunit=1, description='%s' where unitname='%s'"%(desc,unit))
dictofuqc.pop(unit,0)
# In below 5 queries we are adding goid in that tables which will acts as branch id their and that id is refer from godown table
# In that godown table goid is also acts for branch id, That depends on gbflag in godown table.
# if gbflag is 2 then it is branch and only that is going to use in bellow tables
if not columnExists("invoice","goid"):
self.con.execute("alter table invoice add column goid integer, add constraint fk_goid foreign key(goid) references godown(goid)")
self.con.execute("alter table vouchers add column goid integer, add constraint fk_goid foreign key(goid) references godown(goid)")
self.con.execute("alter table rejectionnote add column goid integer, add constraint fk_goid foreign key(goid) references godown(goid)")
self.con.execute("alter table drcr add column goid integer, add constraint fk_goid foreign key(goid) references godown(goid)")
self.con.execute("alter table purchaseorder add column goid integer, add constraint fk_goid foreign key(goid) references godown(goid)")
if not columnExists("organisation","avnoflag"):
self.con.execute("alter table organisation add avnoflag integer default 0")
if not columnExists("organisation","modeflag"):
......@@ -512,7 +523,7 @@ class api_organisation(object):
orgs = []
for row in result:
orgs.append({"orgname":row["orgname"], "orgtype":row["orgtype"]})
orgs.sort()
orgs.sort()
self.con.close()
return {"gkstatus":enumdict["Success"], "gkdata":orgs}
except:
......@@ -533,6 +544,20 @@ class api_organisation(object):
except:
self.con.close()
return {"gkstatus":enumdict["ConnectionFailed"]}
# get all branchid of perticuler username to login in to that branch
@view_config(request_method='GET',request_param='type=orgbranch', renderer ='json')
def getBranch(self):
try:
self.con = eng.connect()
branch = []
godowns = self.con.execute("select goid,goname from godown where orgcode=%d and gbflag=%d and goid in (select goid from usergodown where userid in (select userid from users where username='%s'))"%(int(self.request.params["orgcode"]),int(self.request.params["gbflag"]),str(self.request.params["username"])))
for row in godowns:
branch.append({"bid":int(row["goid"]), "bname":str(row["goname"])})
self.con.close()
return{"gkstatus":enumdict["Success"],"gkdata":branch}
except:
self.con.close()
return {"gkstatus":enumdict["ConnectionFailed"]}
@view_config(route_name='orgyears', request_method='GET', renderer ='json')
def getYears(self):
......@@ -1000,8 +1025,9 @@ class api_organisation(object):
else:
return {"gkstatus":enumdict["Success"]}
except:
self.con.close()
return {"gkstatus": enumdict["ConnectionFailed"]}
finally:
self.con.close()
@view_config(request_param='orgcode', request_method='GET',renderer='json')
......
......@@ -98,10 +98,17 @@ class api_purchaseorder(object):
else:
try:
self.con = eng.connect()
if "psflag" in self.request.params:
result = self.con.execute(select([purchaseorder.c.orderid, purchaseorder.c.orderdate, purchaseorder.c.orderno, purchaseorder.c.csid,purchaseorder.c.attachmentcount]).where(and_(purchaseorder.c.orgcode==authDetails["orgcode"], purchaseorder.c.psflag == "%d"%int(self.request.params["psflag"]))).order_by(purchaseorder.c.orderdate))
# goid is use for branchid to select poso as per branch
if "goid" in authDetails:
if "psflag" in self.request.params:
result = self.con.execute(select([purchaseorder.c.orderid, purchaseorder.c.orderdate, purchaseorder.c.orderno, purchaseorder.c.csid,purchaseorder.c.attachmentcount]).where(and_(purchaseorder.c.goid==authDetails["goid"],purchaseorder.c.orgcode==authDetails["orgcode"], purchaseorder.c.psflag == "%d"%int(self.request.params["psflag"]))).order_by(purchaseorder.c.orderdate))
else:
result = self.con.execute(select([purchaseorder.c.orderid, purchaseorder.c.orderdate, purchaseorder.c.orderno, purchaseorder.c.csid,purchaseorder.c.attachmentcount]).where(and_(purchaseorder.c.goid==authDetails["goid"],purchaseorder.c.orgcode==authDetails["orgcode"])).order_by(purchaseorder.c.orderdate))
else:
result = self.con.execute(select([purchaseorder.c.orderid, purchaseorder.c.orderdate, purchaseorder.c.orderno, purchaseorder.c.csid,purchaseorder.c.attachmentcount]).where(purchaseorder.c.orgcode==authDetails["orgcode"]).order_by(purchaseorder.c.orderdate))
if "psflag" in self.request.params:
result = self.con.execute(select([purchaseorder.c.orderid, purchaseorder.c.orderdate, purchaseorder.c.orderno, purchaseorder.c.csid,purchaseorder.c.attachmentcount]).where(and_(purchaseorder.c.orgcode==authDetails["orgcode"], purchaseorder.c.psflag == "%d"%int(self.request.params["psflag"]))).order_by(purchaseorder.c.orderdate))
else:
result = self.con.execute(select([purchaseorder.c.orderid, purchaseorder.c.orderdate, purchaseorder.c.orderno, purchaseorder.c.csid,purchaseorder.c.attachmentcount]).where(purchaseorder.c.orgcode==authDetails["orgcode"]).order_by(purchaseorder.c.orderdate))
allposo = []
for row in result:
custdata = self.con.execute(select([customerandsupplier.c.custname]).where(customerandsupplier.c.custid==row["csid"]))
......
......@@ -114,8 +114,12 @@ class api_rejectionnote(object):
return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]}
else:
try:
# goid is use as branchid to select rej.note branchvise.
self.con = eng.connect()
result = self.con.execute(select([rejectionnote]).where(rejectionnote.c.orgcode==authDetails["orgcode"]).order_by(rejectionnote.c.rnno))
if "goid" in authDetails:
result = self.con.execute(select([rejectionnote]).where(and_(rejectionnote.c.orgcode==authDetails["orgcode"],rejectionnote.c.goid==authDetails["goid"])).order_by(rejectionnote.c.rnno))
else:
result = self.con.execute(select([rejectionnote]).where(rejectionnote.c.orgcode==authDetails["orgcode"]).order_by(rejectionnote.c.rnno))
rnotes = []
for row in result:
rnotes.append({"rnid":row["rnid"],"rnno":row["rnno"], "inout":row["inout"], "dcid":row["dcid"], "invid":row["invid"], "rndate":datetime.strftime(row["rndate"],'%d-%m-%Y')})
......
This diff is collapsed.
......@@ -299,7 +299,11 @@ class api_transaction(object):
else:
try:
self.con = eng.connect()
result = self.con.execute(select([vouchers.c.vouchernumber,vouchers.c.narration,vouchers.c.voucherdate]).where(vouchers.c.vouchercode==(select([func.max(vouchers.c.vouchercode)]).where(and_(vouchers.c.delflag==False, vouchers.c.vouchertype==self.request.params["type"],vouchers.c.orgcode==authDetails["orgcode"] )))) )
# goid is branchid. get voucher as per branch logged in
if "goid" in authDetails:
result = self.con.execute(select([vouchers.c.vouchernumber,vouchers.c.narration,vouchers.c.voucherdate]).where(vouchers.c.vouchercode==(select([func.max(vouchers.c.vouchercode)]).where(and_(vouchers.c.delflag==False, vouchers.c.vouchertype==self.request.params["type"],vouchers.c.orgcode==authDetails["orgcode"],vouchers.c.goid==authDetails["goid"] )))) )
else:
result = self.con.execute(select([vouchers.c.vouchernumber,vouchers.c.narration,vouchers.c.voucherdate]).where(vouchers.c.vouchercode==(select([func.max(vouchers.c.vouchercode)]).where(and_(vouchers.c.delflag==False, vouchers.c.vouchertype==self.request.params["type"],vouchers.c.orgcode==authDetails["orgcode"] )))) )
row = result.fetchone()
if row== None:
voucher = {"vdate": "","vno":"","narration":""}
......@@ -311,9 +315,6 @@ class api_transaction(object):
self.con.close()
return {"gkstatus":enumdict["ConnectionFailed"]}
@view_config(request_method='GET',renderer='json')
def getVoucher(self):
try:
......@@ -378,7 +379,11 @@ class api_transaction(object):
ur = getUserRole(authDetails["userid"])
urole = ur["gkresult"]
voucherType = self.request.params["vouchertype"]
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.orgcode == authDetails['orgcode'],func.lower(vouchers.c.vouchertype)==func.lower(voucherType),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
# goid is branchid. get voucher as per branch logged in
if "goid" in authDetails:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.goid == authDetails['goid'],vouchers.c.orgcode == authDetails['orgcode'],func.lower(vouchers.c.vouchertype)==func.lower(voucherType),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
else:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.orgcode == authDetails['orgcode'],func.lower(vouchers.c.vouchertype)==func.lower(voucherType),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
voucherRecords = []
for voucher in vouchersData:
......@@ -417,8 +422,6 @@ class api_transaction(object):
if voucher["narration"]=="null":
voucher["narration"]=""
voucherRecords.append({"vouchercode":voucher["vouchercode"],"attachmentcount":voucher["attachmentcount"],"vouchernumber":voucher["vouchernumber"],"voucherdate":datetime.strftime(voucher["voucherdate"],"%d-%m-%Y"),"narration":voucher["narration"],"drs":finalDR,"crs":finalCR,"prjdrs":voucher["prjdrs"],"prjcrs":voucher["prjcrs"],"vouchertype":voucher["vouchertype"],"delflag":voucher["delflag"],"orgcode":voucher["orgcode"],"status":voucher["lockflag"]})
self.con.close()
return {"gkstatus":enumdict["Success"],"gkresult":voucherRecords,"userrole":urole["userrole"]}
......@@ -442,7 +445,11 @@ class api_transaction(object):
ur = getUserRole(authDetails["userid"])
urole = ur["gkresult"]
voucherNo = self.request.params["voucherno"]
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.orgcode == authDetails['orgcode'],func.lower(vouchers.c.vouchernumber)==func.lower(voucherNo),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
# goid is branchid. get voucher as per branch logged in
if "goid" in authDetails:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.goid == authDetails['goid'],vouchers.c.orgcode == authDetails['orgcode'],func.lower(vouchers.c.vouchernumber)==func.lower(voucherNo),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
else:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.orgcode == authDetails['orgcode'],func.lower(vouchers.c.vouchernumber)==func.lower(voucherNo),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
voucherRecords = []
for voucher in vouchersData:
......@@ -452,6 +459,7 @@ class api_transaction(object):
finalCR = {}
tdr=0.00
tcr=0.00
accname = self.con.execute(select([accounts.c.accountname]).where(accounts.c.accountcode==int(rawDr.keys()[0])))
account = accname.fetchone()
......@@ -502,7 +510,11 @@ class api_transaction(object):
ur = getUserRole(authDetails["userid"])
urole = ur["gkresult"]
voucherAmount = self.request.params["total"]
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.drs]).where(and_(vouchers.c.orgcode == authDetails['orgcode'],vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
# goid is branchid. get voucher as per branch logged in
if "goid" in authDetails:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.drs]).where(and_(vouchers.c.goid == authDetails['goid'],vouchers.c.orgcode == authDetails['orgcode'],vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
else:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.drs]).where(and_(vouchers.c.orgcode == authDetails['orgcode'],vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
voucherRecords = []
for vr in vouchersData:
......@@ -571,7 +583,11 @@ class api_transaction(object):
urole = ur["gkresult"]
fromDate = self.request.params["from"]
toDate = self.request.params["to"]
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.orgcode == authDetails['orgcode'], between(vouchers.c.voucherdate,fromDate,toDate),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
# goid is branchid. get voucher as per branch logged in
if "goid" in authDetails:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.goid == authDetails['goid'],vouchers.c.orgcode == authDetails['orgcode'], between(vouchers.c.voucherdate,fromDate,toDate),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
else:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.orgcode == authDetails['orgcode'], between(vouchers.c.voucherdate,fromDate,toDate),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
voucherRecords = []
for voucher in vouchersData:
......@@ -632,7 +648,11 @@ class api_transaction(object):
ur = getUserRole(authDetails["userid"])
urole = ur["gkresult"]
voucherNarration = self.request.params["nartext"]
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.orgcode == authDetails['orgcode'],func.lower(vouchers.c.narration).like("%"+func.lower(voucherNarration)+"%"),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
# goid is branchid. get voucher as per branch logged in
if "goid" in authDetails:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.goid == authDetails['goid'],vouchers.c.orgcode == authDetails['orgcode'],func.lower(vouchers.c.narration).like("%"+func.lower(voucherNarration)+"%"),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
else:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.prjcrs,vouchers.c.prjdrs,vouchers.c.vouchertype,vouchers.c.lockflag,vouchers.c.delflag,vouchers.c.projectcode,vouchers.c.orgcode]).where(and_(vouchers.c.orgcode == authDetails['orgcode'],func.lower(vouchers.c.narration).like("%"+func.lower(voucherNarration)+"%"),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
voucherRecords = []
for voucher in vouchersData:
......@@ -815,7 +835,11 @@ class api_transaction(object):
urole = ur["gkresult"]
fromDate = self.request.params["from"]
toDate = self.request.params["to"]
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.vouchertype,vouchers.c.orgcode]).where(and_(vouchers.c.orgcode == authDetails['orgcode'], between(vouchers.c.voucherdate,fromDate,toDate),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
# goid is branchid. get vouchera as per branch.
if "goid" in authDetails:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.vouchertype,vouchers.c.orgcode]).where(and_(vouchers.c.goid == authDetails['goid'],vouchers.c.orgcode == authDetails['orgcode'], between(vouchers.c.voucherdate,fromDate,toDate),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
else:
vouchersData = self.con.execute(select([vouchers.c.vouchercode,vouchers.c.attachmentcount,vouchers.c.vouchernumber,vouchers.c.voucherdate,vouchers.c.narration,vouchers.c.drs,vouchers.c.crs,vouchers.c.vouchertype,vouchers.c.orgcode]).where(and_(vouchers.c.orgcode == authDetails['orgcode'], between(vouchers.c.voucherdate,fromDate,toDate),vouchers.c.delflag==False)).order_by(vouchers.c.voucherdate,vouchers.c.vouchercode))
voucherRecords = []
for voucher in vouchersData:
......
......@@ -93,7 +93,8 @@ class api_user(object):
dataset = self.request.json_body
if userRole[0]==-1 or (userRole[0]==0 and dataset["userrole"]==1):
dataset["orgcode"] = authDetails["orgcode"]
if dataset["userrole"]== 3:
# golist is present when godown / branch are assign
if "golist" in dataset:
golist = tuple(dataset.pop("golist"))
result = self.con.execute(gkdb.users.insert(),[dataset])
userdata = self.con.execute(select([gkdb.users.c.userid]).where(and_( gkdb.users.c.username == dataset["username"],gkdb.users.c.orgcode == dataset["orgcode"])))
......@@ -148,16 +149,16 @@ class api_user(object):
# if user is godown in-charge we need to retrive associated godown/s
if User["userrole"] == 3:
User["userroleName"] = "Godown In Charge"
usgo = self.con.execute(select([gkdb.usergodown.c.goid]).where(gkdb.usergodown.c.userid == self.request.params["userid"]))
goids = usgo.fetchall()
userGodowns = {}
for g in goids:
godownid = g["goid"]
# now we have associated godown ids, by which we can get godown name
godownData = self.con.execute(select([gkdb.godown.c.goname]).where(gkdb.godown.c.goid == godownid))
gNameRow = godownData.fetchone()
userGodowns[godownid] = gNameRow["goname"]
User["godowns"] = userGodowns
usgo = self.con.execute(select([gkdb.usergodown.c.goid]).where(gkdb.usergodown.c.userid == self.request.params["userid"]))
goids = usgo.fetchall()
userGodowns = {}
for g in goids:
godownid = g["goid"]
# now we have associated godown ids, by which we can get godown name
godownData = self.con.execute(select([gkdb.godown.c.goname]).where(gkdb.godown.c.goid == godownid))
gNameRow = godownData.fetchone()
userGodowns[godownid] = gNameRow["goname"]
User["godowns"] = userGodowns
return {"gkstatus": gkcore.enumdict["Success"], "gkresult":User}
else:
......@@ -259,6 +260,7 @@ class api_user(object):
@view_config(request_method='POST', request_param="userloginstatus", renderer='json')
def userLoginstatus(self):
try:
print("ggg")
self.con = eng.connect()
token = self.request.headers["gktoken"]
except:
......@@ -302,11 +304,13 @@ class api_user(object):
dataset["orgcode"] = authDetails["orgcode"]
# "originalrole" gives userrole of old user
originalrole = getUserRole(dataset["userid"])
if int(originalrole["gkresult"]["userrole"]==3):
# if golist is present then it has access related to godown / branch
if "golist" in dataset:
result = self.con.execute(gkdb.usergodown.delete().where(gkdb.usergodown.c.userid==dataset["userid"]))
#dataset["userrole"] gives userrole of new user
if dataset.has_key("userrole"):
if int(dataset["userrole"])== 3:
# if golist is present then it has access related to godown / branch
if "golist" in dataset:
golists = tuple(dataset.pop("golist"))
result = self.con.execute(gkdb.users.update().where(gkdb.users.c.userid==dataset["userid"]).values(dataset))
currentid = dataset["userid"]
......
Markdown is supported
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