2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +00:00

fix: place filter, formatting

This commit is contained in:
18alantom 2021-12-30 15:19:54 +05:30
parent ddb46f8bee
commit 06cef24f96
3 changed files with 52 additions and 28 deletions

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);
}