2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 03:29:00 +00:00

GSTR3B Json generation

This commit is contained in:
thefalconx33 2019-07-25 15:20:48 +05:30
parent 4f9d82c7ca
commit 472451203c
4 changed files with 234 additions and 25 deletions

View File

@ -8,23 +8,36 @@ class GoodsAndServiceTax {
if (params.toDate) filters.date.push('<=', params.toDate); if (params.toDate) filters.date.push('<=', params.toDate);
if (params.fromDate) filters.date.push('>=', params.fromDate); if (params.fromDate) filters.date.push('>=', params.fromDate);
} }
if (params.transferType) filters.transferType = params.transferType;
const data = await this.getReport(params.reportType, filters); if (params.reportType === 'GSTR-3B') {
return data; this.getGSTR3bJson(filters);
return [];
}
const data = await this.getCompleteReport(params.reportType, filters);
const conditions = {
B2B: row => row.gstin,
'B2C-Large': row => !row.gstin && !row.inState && row.invAmt >= 250000,
'B2C-Small': row =>
!row.gstin && (row.inState || (row.inState && row.invAmt < 250000))
};
if (!params.transferType) return data;
return data.filter(row => conditions[params.transferType](row));
} }
async getReport(type, filters) { async getCompleteReport(gstrType, filters) {
if (['GSTR-1', 'GSTR-2'].includes(type)) { if (['GSTR-1', 'GSTR-2'].includes(gstrType)) {
let entries = await frappe.db.getAll({ let entries = await frappe.db.getAll({
doctype: type === 'GSTR-1' ? 'Invoice' : 'Bill', doctype: gstrType === 'GSTR-1' ? 'Invoice' : 'Bill',
filter: filters filter: filters
}); });
let tableData = []; let tableData = [];
for (let entry of entries) { for (let entry of entries) {
const row = await this.getRow({ const row = await this.getRow({
doctype: type === 'GSTR-1' ? 'Invoice' : 'Bill', doctype: gstrType === 'GSTR-1' ? 'Invoice' : 'Bill',
name: entry.name name: entry.name
}); });
tableData.push(row); tableData.push(row);
@ -45,39 +58,91 @@ class GoodsAndServiceTax {
} }
} }
async getGSTR3bJson(filters) {
const gstr1Data = this.getCompleteReport('GSTR-1', filters);
const gsrt2Data = this.getCompleteReport('GSTR-2', filters);
const gstr3bData = await Promise.all([gstr1Data, gsrt2Data]);
let gstr3bJson = require('./gstr3b.json');
for (let entry of gstr3bData[0]) {
if (entry.rate > 0) {
gstr3bJson['sup_details']['osup_det']['samt'] += entry.sgstAmt || 0;
gstr3bJson['sup_details']['osup_det']['camt'] += entry.cgstAmt || 0;
gstr3bJson['sup_details']['osup_det']['iamt'] += entry.igstAmt || 0;
gstr3bJson['sup_details']['osup_det']['txval'] += entry.taxVal;
}
if (entry.rate === 0) {
gstr3bJson['sup_details']['osup_zero']['txval'] += entry.taxVal;
}
if (entry.nilRated || entry.exempt) {
gstr3bJson['sup_details']['osup_nil_exmp']['txval'] += entry.taxVal;
}
if (entry.nonGST) {
gstr3bJson['sup_details']['osup_nongst']['txval'] += entry.taxVal;
}
if (!entry.inState && !entry.gstin) {
gstr3bJson['inter_sup']['unreg_details'].push = {
place: entry.place,
taxVal: entry.taxVal,
igstAmt: entry.igstAmt
};
}
}
for (let entry of gstr3bData[1]) {
if (entry.reverseCharge === 'Y') {
gstr3bJson['sup_details']['isup_rev']['samt'] += entry.sgstAmt || 0;
gstr3bJson['sup_details']['isup_rev']['camt'] += entry.cgstAmt || 0;
gstr3bJson['sup_details']['isup_rev']['iamt'] += entry.igstAmt || 0;
gstr3bJson['sup_details']['isup_rev']['txval'] += entry.taxVal;
}
if (entry.nilRated || entry.exempt) {
gstr3bJson['inward_sup']['isup_details'][0][
entry.inState ? 'intra' : 'inter'
] += entry.taxVal;
}
if (entry.nonGST) {
gstr3bJson['inward_sup']['isup_details'][0][
entry.inState ? 'intra' : 'inter'
] += entry.taxVal;
}
}
return gstr3bJson;
}
async getRow(entry) { async getRow(entry) {
let row = {}; let row = {};
let entryDetails = await frappe.getDoc(entry.doctype, entry.name); let entryDetails = await frappe.getDoc(entry.doctype, entry.name);
let customerDetails = await frappe.getDoc( let party = await frappe.getDoc(
'Party', 'Party',
entryDetails.customer || entryDetails.supplier entryDetails.customer || entryDetails.supplier
); );
if (customerDetails.address) { if (party.address) {
let addressDetails = await frappe.getDoc( let addressDetails = await frappe.getDoc('Address', party.address);
'Address',
customerDetails.address
);
row.place = addressDetails.state || ''; row.place = addressDetails.state || '';
} }
row.gstin = customerDetails.gstin; row.gstin = party.gstin;
row.partyName = entryDetails.customer || entryDetails.supplier; row.partyName = entryDetails.customer || entryDetails.supplier;
row.invNo = entryDetails.name; row.invNo = entryDetails.name;
row.invDate = entryDetails.date; row.invDate = entryDetails.date;
row.rate = 0; row.rate = 0;
row.transferType = 'In State'; row.inState = true;
row.reverseCharge = !party.gstin ? 'Y' : 'N';
entryDetails.taxes.forEach(tax => { entryDetails.taxes.forEach(tax => {
row.rate += tax.rate; row.rate += tax.rate;
const taxAmt = (tax.rate * entryDetails.netTotal) / 100; const taxAmt = (tax.rate * entryDetails.netTotal) / 100;
if (tax.account === 'IGST') { if (tax.account === 'IGST') row.igstAmt = taxAmt;
row.transferType = 'Out of State'; if (tax.account === 'IGST') row.inState = false;
row.igstAmt = taxAmt;
}
if (tax.account === 'CGST') row.cgstAmt = taxAmt; if (tax.account === 'CGST') row.cgstAmt = taxAmt;
if (tax.account === 'SGST') row.sgstAmt = taxAmt; if (tax.account === 'SGST') row.sgstAmt = taxAmt;
if (tax.account === 'Nil Rated') row.nilRated = true;
if (tax.account === 'Exempt') row.exempt = true;
if (tax.account === 'Non GST') row.nonGST = true;
}); });
row.invAmt = entryDetails.grandTotal; row.invAmt = entryDetails.grandTotal;
row.taxAmt = entryDetails.netTotal; row.taxVal = entryDetails.netTotal;
return row; return row;
} }
} }

View File

@ -0,0 +1,127 @@
{
"gstin": "",
"ret_period": "",
"inward_sup": {
"isup_details": [
{
"ty": "GST",
"intra": 0,
"inter": 0
},
{
"ty": "NONGST",
"inter": 0,
"intra": 0
}
]
},
"sup_details": {
"osup_zero": {
"csamt": 0,
"txval": 0,
"iamt": 0
},
"osup_nil_exmp": {
"txval": 0
},
"osup_det": {
"samt": 0,
"csamt": 0,
"txval": 0,
"camt": 0,
"iamt": 0
},
"isup_rev": {
"samt": 0,
"csamt": 0,
"txval": 0,
"camt": 0,
"iamt": 0
},
"osup_nongst": {
"txval": 0
}
},
"inter_sup": {
"unreg_details": [],
"comp_details": [],
"uin_details": []
},
"itc_elg": {
"itc_avl": [
{
"csamt": 0,
"samt": 0,
"ty": "IMPG",
"camt": 0,
"iamt": 0
},
{
"csamt": 0,
"samt": 0,
"ty": "IMPS",
"camt": 0,
"iamt": 0
},
{
"samt": 0,
"csamt": 0,
"ty": "ISRC",
"camt": 0,
"iamt": 0
},
{
"ty": "ISD",
"iamt": 0,
"camt": 0,
"samt": 0,
"csamt": 0
},
{
"samt": 0,
"csamt": 0,
"ty": "OTH",
"camt": 0,
"iamt": 0
}
],
"itc_rev": [
{
"ty": "RUL",
"iamt": 0,
"camt": 0,
"samt": 0,
"csamt": 0
},
{
"ty": "OTH",
"iamt": 0,
"camt": 0,
"samt": 0,
"csamt": 0
}
],
"itc_net": {
"samt": 0,
"csamt": 0,
"camt": 0,
"iamt": 0
},
"itc_inelg": [
{
"ty": "RUL",
"iamt": 0,
"camt": 0,
"samt": 0,
"csamt": 0
},
{
"ty": "OTH",
"iamt": 0,
"camt": 0,
"samt": 0,
"csamt": 0
}
]
}
}

View File

@ -10,9 +10,16 @@ module.exports = {
options: ['', 'GSTR-1', 'GSTR-2', 'GSTR-3B'] options: ['', 'GSTR-1', 'GSTR-2', 'GSTR-3B']
}, },
{ {
fieldtype: 'Data', fieldtype: 'Select',
label: 'Transfer Type', label: 'Transfer Type',
fieldname: 'transferType' fieldname: 'transferType',
options: [
'',
'B2B',
'B2C-Large',
'B2C-Small',
'Nil Rated, Exempted and Non GST supplies'
]
}, },
{ {
fieldtype: 'Data', fieldtype: 'Data',
@ -109,11 +116,17 @@ module.exports = {
width: 80 width: 80
}, },
{ {
label: 'Taxable Amount', label: 'Taxable Value',
fieldname: 'taxAmt', fieldname: 'taxVal',
fieldtype: 'Currency', fieldtype: 'Currency',
width: 100 width: 100
}, },
{
label: 'Reverse Chrg.',
fieldname: 'reverseCharge',
fieldtype: 'Data',
width: 80
},
{ {
label: 'Intergrated Tax', label: 'Intergrated Tax',
fieldname: 'igstAmt', fieldname: 'igstAmt',

View File

@ -20,6 +20,10 @@ import Tree from 'frappejs/ui/components/Tree';
Vue.use(Router); Vue.use(Router);
const routes = [ const routes = [
{
path: '/',
redirect: '/chartOfAccounts'
},
{ {
path: '/list/:listName', path: '/list/:listName',
name: 'ListView', name: 'ListView',