From 06cef24f96e71a584340b3a720a564176f0b1dbd Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Thu, 30 Dec 2021 15:19:54 +0530 Subject: [PATCH] fix: place filter, formatting --- accounting/gst.js | 27 +++++++------- reports/GoodsAndServiceTax/BaseGSTR.js | 51 +++++++++++++++++++------- reports/GoodsAndServiceTax/GSTR1.js | 2 + 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/accounting/gst.js b/accounting/gst.js index fa3da123..136110e6 100644 --- a/accounting/gst.js +++ b/accounting/gst.js @@ -5,6 +5,7 @@ import { DateTime } from 'luxon'; import { saveExportData } from '../reports/commonExporter'; import { getSavePath } from '../src/utils'; +// prettier-ignore export const stateCodeMap = { 'JAMMU AND KASHMIR': '1', 'HIMACHAL PRADESH': '2', @@ -184,7 +185,7 @@ async function generateB2clData(invoices) { for (let invoice of invoices) { const stateInvoiceRecord = { pos: stateCodeMap[invoice.place.toUpperCase()], - inv: [] + inv: [], }; const invRecord = { @@ -194,7 +195,7 @@ async function generateB2clData(invoices) { ), val: invoice.invAmt, itms: [], - } + }; let items = await frappe.db .knex('SalesInvoiceItem') @@ -231,22 +232,20 @@ async function generateB2csData(invoices) { const b2cs = []; for (let invoice of invoices) { - const pos = invoice.place.toUpperCase(); const invRecord = { - "sply_ty": invoice.inState ? "INTRA" : "INTER", - "pos": stateCodeMap[pos], + sply_ty: invoice.inState ? 'INTRA' : 'INTER', + pos: stateCodeMap[pos], // "OE" - Abbreviation for errors and omissions excepted. - // https://specialties.bayt.com/en/specialties/q/53093/what-is-meant-by-e-amp-oe-on-bill-or-invoice-or-any-document/#:~:text=E%26OE%20on,not%20purposely%20written - "typ": "OE", - "txval": invoice.taxVal, - "rt": invoice.rate, - "iamt": !invoice.inState ? (invoice.taxVal * invoice.rate / 100) : 0, - "camt": invoice.inState ? invoice.cgstAmt : 0, - "samt": invoice.inState ? invoice.sgstAmt : 0, - "csamt": 0 - } + typ: 'OE', + txval: invoice.taxVal, + rt: invoice.rate, + iamt: !invoice.inState ? (invoice.taxVal * invoice.rate) / 100 : 0, + camt: invoice.inState ? invoice.cgstAmt : 0, + samt: invoice.inState ? invoice.sgstAmt : 0, + csamt: 0, + }; b2cs.push(invRecord); } diff --git a/reports/GoodsAndServiceTax/BaseGSTR.js b/reports/GoodsAndServiceTax/BaseGSTR.js index c42c22e6..118aff0a 100644 --- a/reports/GoodsAndServiceTax/BaseGSTR.js +++ b/reports/GoodsAndServiceTax/BaseGSTR.js @@ -1,23 +1,27 @@ import frappe from 'frappejs'; -import { stateCodeMap } from '../../accounting/gst' +import { stateCodeMap } from '../../accounting/gst'; class BaseGSTR { async getCompleteReport(gstrType, filters) { if (['GSTR-1', 'GSTR-2'].includes(gstrType)) { + const place = filters.place; + delete filters.place; let entries = await frappe.db.getAll({ doctype: gstrType === 'GSTR-1' ? 'SalesInvoice' : 'PurchaseInvoice', - filters + filters, }); + filters.place = place; let tableData = []; for (let entry of entries) { - entry.doctype = gstrType === 'GSTR-1' ? 'SalesInvoice' : 'PurchaseInvoice'; + entry.doctype = + gstrType === 'GSTR-1' ? 'SalesInvoice' : 'PurchaseInvoice'; const row = await this.getRow(entry); tableData.push(row); } if (Object.keys(filters).length != 0) { - tableData = tableData.filter(row => { + tableData = tableData.filter((row) => { if (filters.account) return row.account === filters.account; if (filters.transferType) return row.transferType === filters.transferType; @@ -25,6 +29,7 @@ class BaseGSTR { return true; }); } + return tableData; } else { return []; @@ -32,37 +37,55 @@ class BaseGSTR { } async getRow(ledgerEntry) { - let row = {}; ledgerEntry = await frappe.getDoc(ledgerEntry.doctype, ledgerEntry.name); + + const row = {}; const { gstin } = frappe.AccountingSettings; + let party = await frappe.getDoc( 'Party', ledgerEntry.customer || ledgerEntry.supplier ); + if (party.address) { let addressDetails = await frappe.getDoc('Address', party.address); row.place = addressDetails.pos || ''; } + row.gstin = party.gstin; row.partyName = ledgerEntry.customer || ledgerEntry.supplier; row.invNo = ledgerEntry.name; row.invDate = ledgerEntry.date; row.rate = 0; - row.inState = gstin && gstin.substring(0, 2) === stateCodeMap[row.place.toUpperCase()]; + row.inState = + gstin && gstin.substring(0, 2) === stateCodeMap[row.place?.toUpperCase()]; row.reverseCharge = !party.gstin ? 'Y' : 'N'; - ledgerEntry.taxes?.forEach(tax => { + + ledgerEntry.taxes?.forEach((tax) => { row.rate += tax.rate; const taxAmt = (tax.rate * ledgerEntry.netTotal) / 100; - 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; + + switch (tax.account) { + case 'IGST': { + row.igstAmt = taxAmt; + row.inState = false; + } + case 'CGST': + row.cgstAmt = taxAmt; + case 'SGST': + row.sgstAmt = taxAmt; + case 'Nil Rated': + row.nilRated = true; + case 'Exempt': + row.exempt = true; + case 'Non GST': + row.nonGST = true; + } }); + row.invAmt = ledgerEntry.grandTotal; row.taxVal = ledgerEntry.netTotal; + return row; } } diff --git a/reports/GoodsAndServiceTax/GSTR1.js b/reports/GoodsAndServiceTax/GSTR1.js index e0a8e7d3..8759da5e 100644 --- a/reports/GoodsAndServiceTax/GSTR1.js +++ b/reports/GoodsAndServiceTax/GSTR1.js @@ -8,6 +8,8 @@ class GSTR1 extends BaseGSTR { filters.cancelled = 0; if (params.toDate || params.fromDate) { filters.date = []; + + if (params.place) filters.place = params.place; if (params.toDate) filters.date.push('<=', params.toDate); if (params.fromDate) filters.date.push('>=', params.fromDate); }