2
0
mirror of https://github.com/frappe/books.git synced 2024-11-09 23:30:56 +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.fromDate) filters.date.push('>=', params.fromDate);
}
if (params.transferType) filters.transferType = params.transferType;
const data = await this.getReport(params.reportType, filters);
return data;
if (params.reportType === 'GSTR-3B') {
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) {
if (['GSTR-1', 'GSTR-2'].includes(type)) {
async getCompleteReport(gstrType, filters) {
if (['GSTR-1', 'GSTR-2'].includes(gstrType)) {
let entries = await frappe.db.getAll({
doctype: type === 'GSTR-1' ? 'Invoice' : 'Bill',
doctype: gstrType === 'GSTR-1' ? 'Invoice' : 'Bill',
filter: filters
});
let tableData = [];
for (let entry of entries) {
const row = await this.getRow({
doctype: type === 'GSTR-1' ? 'Invoice' : 'Bill',
doctype: gstrType === 'GSTR-1' ? 'Invoice' : 'Bill',
name: entry.name
});
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) {
let row = {};
let entryDetails = await frappe.getDoc(entry.doctype, entry.name);
let customerDetails = await frappe.getDoc(
let party = await frappe.getDoc(
'Party',
entryDetails.customer || entryDetails.supplier
);
if (customerDetails.address) {
let addressDetails = await frappe.getDoc(
'Address',
customerDetails.address
);
if (party.address) {
let addressDetails = await frappe.getDoc('Address', party.address);
row.place = addressDetails.state || '';
}
row.gstin = customerDetails.gstin;
row.gstin = party.gstin;
row.partyName = entryDetails.customer || entryDetails.supplier;
row.invNo = entryDetails.name;
row.invDate = entryDetails.date;
row.rate = 0;
row.transferType = 'In State';
row.inState = true;
row.reverseCharge = !party.gstin ? 'Y' : 'N';
entryDetails.taxes.forEach(tax => {
row.rate += tax.rate;
const taxAmt = (tax.rate * entryDetails.netTotal) / 100;
if (tax.account === 'IGST') {
row.transferType = 'Out of State';
row.igstAmt = taxAmt;
}
if (tax.account === 'IGST') row.igstAmt = taxAmt;
if (tax.account === 'IGST') row.inState = false;
if (tax.account === 'CGST') row.cgstAmt = 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.taxAmt = entryDetails.netTotal;
row.taxVal = entryDetails.netTotal;
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']
},
{
fieldtype: 'Data',
fieldtype: 'Select',
label: 'Transfer Type',
fieldname: 'transferType'
fieldname: 'transferType',
options: [
'',
'B2B',
'B2C-Large',
'B2C-Small',
'Nil Rated, Exempted and Non GST supplies'
]
},
{
fieldtype: 'Data',
@ -109,11 +116,17 @@ module.exports = {
width: 80
},
{
label: 'Taxable Amount',
fieldname: 'taxAmt',
label: 'Taxable Value',
fieldname: 'taxVal',
fieldtype: 'Currency',
width: 100
},
{
label: 'Reverse Chrg.',
fieldname: 'reverseCharge',
fieldtype: 'Data',
width: 80
},
{
label: 'Intergrated Tax',
fieldname: 'igstAmt',

View File

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