Created
February 4, 2021 10:48
-
-
Save tejavarma-aln/37bc9db7a2a5fd8c20736bf248804e88 to your computer and use it in GitHub Desktop.
Http post from tally
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Collection:LedMasterColl] | |
Type:Ledger | |
Fetch:Name,Parent,Address,LedStateName,CountryofResidence,PartyGSTIN | |
[Collection:LedMastersPost] | |
Data Source:HTTP JSON:"http://127.0.0.1:5000/Ledgers/Add" | |
RemoteRequest:LedMasters:UTF8 | |
[#Menu:GatewayOfTally] | |
Add:Key Item:PostLedgers:P:Call:PostLedgers | |
[Function:PostLedgers] | |
0:Walk Collection:LedMastersPost | |
2:Msg Box:(IF $Status then "Success" else "Failed"):$Message | |
3:End Walk | |
[Report:LedMasters] | |
Form:LedMsaters | |
Plain JSON:Yes | |
[Form:LedMsaters] | |
Part:LedMsaters | |
JSONTag:"DATA" | |
[Part:LedMsaters] | |
Scrolled:Vertical | |
Line:LedMsaters | |
Repeat:LedMsaters:LedMasterColl | |
[Line:LedMsaters] | |
JSONTag:"LEDGER" | |
Fields:Ledmst1,Ledmst2,Ledmst3,Ledmst4,Ledmst5,Ledmst6 | |
[Field:Ledmst1] | |
Set as:$Name | |
JSONTag:"NAME" | |
[Field:Ledmst2] | |
Set as:$Parent | |
JSONTag:"PARENT" | |
[Field:Ledmst3] | |
Set as:$Address | |
JSONTag:"ADDRESS" | |
[Field:Ledmst4] | |
Set as:$LedStateName | |
JSONTag:"STATE" | |
[Field:Ledmst5] | |
Set as:$CountryOfResidence | |
JSONTag:"COUNTRY" | |
[Field:Ledmst6] | |
Set as:$PartyGSTIN | |
JSONTag:"GSTIN" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>{{ led["name"] }}</title> | |
<style> | |
body{ | |
font-family:sans-serif | |
} | |
h3{ | |
color:tomato; | |
} | |
table{ | |
width:100% | |
} | |
table,td{ | |
border: 1px solid black; | |
border-collapse: collapse; | |
border-spacing: 5px; | |
} | |
td { | |
padding: 15px; | |
} | |
td{ | |
background-color:rgba(255, 99, 71, 0.5); | |
font-weight:bold | |
} | |
</style> | |
</head> | |
<body> | |
<H3>(Ledger - {{ led["name"] }})</H3> | |
<table> | |
<tr> | |
<td>NAME</td> | |
<td>{{ led["name"] }}</td> | |
</tr> | |
<tr> | |
<td>GROUP</td> | |
<td>{{ led["parent"] }}</td> | |
</tr> | |
<tr> | |
<td>ADDRESS</td> | |
<td>{{ led["address"] }}</td> | |
</tr> | |
<tr> | |
<td>STATE</td> | |
<td>{{ led["state"] }}</td> | |
</tr> | |
<tr> | |
<td>COUNTRY</td> | |
<td>{{ led["country"] }}</td> | |
</tr> | |
<tr> | |
<td>GSTIN</td> | |
<td>{{ led["gstin"] }}</td> | |
</tr> | |
</table> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>List Of Ledgers</title> | |
<style> | |
body{ | |
font-family:sans-serif | |
} | |
h2{ | |
color:tomato; | |
text-decoration:underline | |
} | |
table{ | |
width:100% | |
} | |
table,th,td{ | |
border: 1px solid black; | |
border-collapse: collapse; | |
border-spacing: 5px; | |
} | |
th, td { | |
padding: 15px; | |
} | |
th{ | |
color:white; | |
background-color:green | |
} | |
td{ | |
background-color:rgba(255, 99, 71, 0.5); | |
font-weight:bold | |
} | |
</style> | |
</head> | |
<body> | |
<center><H2>LEDGERS</H2></center> | |
<table> | |
<tr> | |
<th>NAME</th> | |
<th>GROUP</th> | |
<th>ADDRESS</th> | |
<th>STATE</th> | |
<th>COUNTRY</th> | |
<th>GSTIN</th> | |
</tr> | |
{% for led in data %} | |
<tr> | |
<td>{{led["name"]}}</td> | |
<td>{{led["parent"]}}</td> | |
<td>{{led["address"]}}</td> | |
<td>{{led["state"]}}</td> | |
<td>{{led["country"]}}</td> | |
<td>{{led["gstin"]}}</td> | |
</tr> | |
{% endfor %} | |
</table> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
from flask import Flask, request, jsonify, render_template | |
app = Flask(__name__) | |
@app.route('/') | |
def home(): | |
return "<H1>Welcome</H1>" | |
@app.route('/Ledgers/List') | |
def ledgers(): | |
db = get_db() | |
db.row_factory = sqlite3.Row | |
cur = db.cursor() | |
cur.execute("select * from Ledgers") | |
rows = cur.fetchall() | |
cur.close() | |
db.close() | |
if len(rows) > 0: | |
return render_template("Ledgers.html", data=rows) | |
else: | |
return "<center><H3>No data found</H3></center>" | |
@app.route('/Ledgers/<string:name>', methods=['GET']) | |
def get_ledger(name): | |
db = get_db() | |
db.row_factory = sqlite3.Row | |
cur = db.cursor() | |
cur.execute("select * from Ledgers where name = ?", [name]) | |
row = cur.fetchone() | |
cur.close() | |
db.close() | |
if row: | |
return render_template("Ledger.html", led=row) | |
else: | |
return "<center><H3>No data found</H3></center>" | |
@app.route('/Ledgers/Add', methods=['POST']) | |
def add_ledgers(): | |
data = request.get_json() | |
db = get_db() | |
try: | |
for led in data['DATA']['LEDGER']: | |
name = led["NAME"] | |
group = led["PARENT"] | |
address = led["ADDRESS"] if "ADDRESS" in led else "NIL" | |
state = led["STATE"] if "STATE" in led else "NIL" | |
country = led["COUNTRY"] if "COUNTRY" in led else "NIL" | |
gst = led["GSTIN"] if "GSTIN" in led else "NIL" | |
db.execute("INSERT INTO Ledgers (name,parent,address,state,country,gstin) VALUES(?,?,?,?,?,?)", | |
(name, group, address, state, country, gst)) | |
db.commit() | |
except Exception as e: | |
print(e) | |
return jsonify(status=False, message=str(e)) | |
finally: | |
db.close() | |
return jsonify(status=True, message="Ledgers inserted successfully") | |
def get_db(): | |
db = sqlite3.connect("ledgers.db") | |
db.execute( | |
"CREATE TABLE IF NOT EXISTS Ledgers (id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,parent TEXT,address TEXT,state TEXT,country TEXT,gstin TEXT)") | |
db.commit() | |
return db | |
if __name__ == "__main__": | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment