Commit 9a31d936 authored by Krishnakant Mane's avatar Krishnakant Mane
Browse files

Merge branch 'invoicedetails' into 'devel'

Organisation details in invoice.

1. 'getbillingdetails' function is written for getting organisation details and respected state's gstin.

2. 'bankdetails' column is added in organisation table and respected changes in gkupgrade function. 

3. 'getbillingdetails' function also returns 'bankdetails' .

4. "address" field added in 'invoice' table and changes in gkupgrade function for same field. 

5. "bankdetails" field added in 'customerandsupplier' table and changes in gkupgrade function for same field.

6. 'paymentmode' column is added in invoice table and respected changes in gkupgrade function.

7. If invoice have address then 'getInvoiceDetails' sends respected address else gives null value.

closes #378

See merge request !34
parents a8e5fbdd 8a91dbb5
......@@ -59,6 +59,7 @@ signature = Table('signature', metadata,
Column('secretcode',UnicodeText, primary_key=True))
""" organisation table for saving basic details including type, financial year start and end, flags for roll over and close books.
Also stores other details like the pan or sales tax number.
bankdetails is a dictionary will have bankname,accountno., branchname and ifsccode
Every time a new organisation is created or recreated for it's new financial year, a new record is added.
ivflag = inventory flag , billflag = billwise accounting , invsflag = invoicing
"""
......@@ -102,6 +103,7 @@ organisation = Table( 'organisation' , metadata,
Column('invsflag',Integer,default=1),
Column('logo',JSON),
Column('gstin',JSONB),
Column('bankdetails',JSON),
UniqueConstraint('orgname','orgtype','yearstart'),
UniqueConstraint('orgname','orgtype','yearend'),
Index("orgindex", "orgname","yearstart","yearend")
......@@ -196,6 +198,7 @@ Also when we purchase the same.
The reason to store this data is that we may need it in both invoice and delivery chalan.
Here the csflag is 3 for customer and 19 for supplier
gstin to store unique code of cust/supp for gst for every state (json)
Bankdetails is a dictionary will have bankname,accountno., branchname and ifsccode.
"""
customerandsupplier = Table('customerandsupplier',metadata,
Column('custid',Integer,primary_key=True),
......@@ -210,6 +213,7 @@ customerandsupplier = Table('customerandsupplier',metadata,
Column('custdoc',JSONB),
Column('state', UnicodeText),
Column('csflag',Integer,nullable=False),
Column('bankdetails',JSONB),
Column('orgcode',Integer, ForeignKey('organisation.orgcode', ondelete="CASCADE"), nullable=False),
UniqueConstraint('orgcode','custname'),
UniqueConstraint('orgcode','custname','custemail','csflag'),
......@@ -296,7 +300,8 @@ Bankdetails is a dictionary will have bankname,accountno., branchname and ifscco
taxstate is a destination sate.
sourcestate is source state from where invoice is initiated.
Structure of a tax field is {productcode:taxrate}
save orgstategstin of sourcestate for organisation.
save orgstategstin of sourcestate for organisation.
paymentmode states that Mode of payment i.e 'bank' or 'cash'. Default value is set as 2 for 'bank' and 3 for 'cash'.
"""
invoice = Table('invoice',metadata,
Column('invid',Integer,primary_key=True),
......@@ -327,6 +332,8 @@ invoice = Table('invoice',metadata,
Column('vehicleno',UnicodeText),
Column('dateofsupply',DateTime),
Column('discount',JSONB),
Column('paymentmode',Integer,default=2),
Column('address',UnicodeText),
UniqueConstraint('orgcode','invoiceno','custid','icflag'),
Index("invoice_orgcodeindex","orgcode"),
Index("invoice_invoicenoindex","invoiceno")
......
......@@ -268,6 +268,7 @@ There will be an icFlag which will determine if it's an incrementing or decreme
Depending on the invoice type it will return the details on customer or supplier.
It also calculates total amount, taxable amount with all the taxes.
The function returns a nested dictionary with dicts for products with their costing details, free quantyty etc.
if address equal to none then send null value otherwise respected address.
Note: the details such as state code, place of supplyer etc depends on the tax type.
The above mentioned and some more fields are only returned if the tax is GST.
"""
......@@ -288,6 +289,10 @@ There will be an icFlag which will determine if it's an incrementing or decreme
inv["sourcestate"] = invrow["sourcestate"]
inv["sourcestatecode"] = getStateCode(invrow["sourcestate"],self.con)["statecode"]
sourceStateCode = getStateCode(invrow["sourcestate"],self.con)["statecode"]
if invrow["address"] == None:
inv["address"]= ""
else:
inv["address"]=invrow["address"]
if invrow["icflag"]==9:
inv["issuername"]=invrow["issuername"]
inv["designation"]=invrow["designation"]
......
......@@ -44,6 +44,7 @@ from gkcore.models.meta import dbconnect
from Crypto.PublicKey import RSA
from gkcore.models.gkdb import metadata
from gkcore.models.meta import inventoryMigration,addFields
from gkcore.views.api_invoice import getStateCode
con= Connection
@view_defaults(route_name='organisations')
......@@ -61,6 +62,10 @@ class api_organisation(object):
"""
self.con = eng.connect()
try:
self.con.execute(select(gkdb.invoice.c.address))
self.con.execute(select(gkdb.customerandsupplier.c.bankdetails))
self.con.execute(select(gkdb.invoice.c.paymentmode))
self.con.execute(select(gkdb.organisation.c.bankdetails))
self.con.execute(select([func.count(gkdb.delchal.c.consignee)]))
self.con.execute(select([func.count(gkdb.invoice.c.orgstategstin)]))
self.con.execute(select([func.count(gkdb.invoice.c.cess)]))
......@@ -85,6 +90,10 @@ 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("alter table invoice add address text")
self.con.execute("alter table customerandsupplier add bankdetails jsonb")
self.con.execute("alter table invoice add paymentmode integer")
self.con.execute("alter table organisation add bankdetails json")
self.con.execute("alter table delchal add consignee jsonb")
self.con.execute("alter table invoice add orgstategstin text")
self.con.execute("alter table invoice add cess jsonb")
......@@ -471,6 +480,72 @@ class api_organisation(object):
except:
self.con.close()
return {"gkstatus":enumdict["ConnectionFailed"]}
"""
This function returns Organisation Details for Invoicing.
'statecode' receiving from frontend view & depending on statecode gstin will get.
"""
@view_config(request_method="GET", renderer="json", request_param="billingdetails")
def getbillingdetails(self):
token = self.request.headers['gktoken']
authDetails = authCheck(token)
if authDetails["auth"]==False:
return {"gkstatus":enumdict["UnauthorisedAccess"]}
else:
try:
self.con = eng.connect()
statecode =self.request.params["statecode"]
result = self.con.execute(select([gkdb.organisation]).where(gkdb.organisation.c.orgcode==authDetails["orgcode"]))
row = result.fetchone()
if(row["orgcity"]==None):
orgcity=""
else:
orgcity=row["orgcity"]
if(row["orgaddr"]==None):
orgaddr=""
else:
orgaddr=row["orgaddr"]
if(row["orgpincode"]==None):
orgpincode=""
else:
orgpincode=row["orgpincode"]
if(row["orgstate"]==None):
orgstate=""
else:
orgstate = row["orgstate"]
if(row["orgwebsite"]==None):
orgwebsite=""
else:
orgwebsite=row["orgwebsite"]
if(row["orgpan"]==None):
orgpan=""
else:
orgpan=row["orgpan"]
if(row["orgtelno"]==None):
orgtelno=""
else:
orgtelno=row["orgtelno"]
if(row["orgemail"]==None):
orgemail=""
else:
orgemail=row["orgemail"]
if(row["gstin"]==None):
gstin=""
elif(row["gstin"].has_key(str(statecode))):
gstin = row["gstin"][str(statecode)]
else:
gstin=""
if(row["bankdetails"]==None):
bankdetails = ""
else:
bankdetails = row["bankdetails"]
orgDetails={"orgname":row["orgname"], "orgaddr":orgaddr, "orgpincode":orgpincode, "orgstate":orgstate, "orgwebsite":orgwebsite, "orgpan":orgpan, "orgstategstin":gstin, "orgcity":orgcity, "bankdetails":bankdetails, "orgtelno":orgtelno, "orgemail":orgemail}
self.con.close()
return {"gkstatus":enumdict["Success"],"gkdata":orgDetails}
except:
return {"gkstatus": enumdict["ConnectionFailed"]}
@view_config(request_method="GET",renderer="json",request_param="osg=true")
def getOrgStateGstin(self):
token = self.request.headers['gktoken']
......
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