2
0
mirror of https://github.com/frappe/books.git synced 2025-01-22 22:58:28 +00:00

Added ability to export B2B GSTR-2 CSV data

This commit is contained in:
Piyush Singhania 2022-01-10 18:54:32 +05:30
parent 1798902835
commit e3e2b43da0
6 changed files with 100 additions and 23 deletions

View File

@ -2,7 +2,7 @@ import { showMessageDialog } from '@/utils';
import frappe from 'frappejs';
import { _ } from 'frappejs/utils';
import { DateTime } from 'luxon';
import { saveExportData } from '../reports/commonExporter';
import { saveExportData, exportCsv } from '../reports/commonExporter';
import { getSavePath } from '../src/utils';
// prettier-ignore
@ -265,9 +265,72 @@ export async function generateGstr2Csv(getReportData) {
const {
rows,
columns,
filters: { transferType, toDate },
} = getReportData();
const { filePath, canceled } = await getSavePath('gstr-2', 'csv');
if (canceled || !filePath) return;
let gstData;
if (transferType === 'B2B') {
gstData = await generateB2bCsvGstr2(rows, columns);
}
await exportCsv(gstData.rows, gstData.columns, filePath);
}
async function generateB2bCsvGstr2(rows, columns) {
const csvColumns = [
{
label: 'GSTIN of Supplier',
fieldname: 'gstin',
},
{
label: 'Invoice Number',
fieldname: 'invNo',
},
{
label: 'Invoice Date',
fieldname: 'invDate',
},
{
label: 'Invoice Value',
fieldname: 'invAmt',
},
{
label: 'Place of supply',
fieldname: 'place',
},
{
label: 'Reverse Charge',
fieldname: 'reverseCharge',
},
{
label: 'Rate',
fieldname: 'rate',
},
{
label: 'Taxable Value',
fieldname: 'taxVal',
},
{
label: 'Intergrated Tax Paid',
fieldname: 'igstAmt',
},
{
label: 'Central Tax Paid',
fieldname: 'cgstAmt',
},
{
label: 'State/UT Tax Paid',
fieldname: 'sgstAmt',
},
]
return {
columns: csvColumns,
rows: rows,
}
}

View File

@ -2,26 +2,10 @@ import { DateTime } from 'luxon';
import { stateCodeMap } from '../../accounting/gst';
import { titleCase } from '../../src/utils';
const transferTypeMap = {
B2B: 'B2B',
B2CL: 'B2C-Large',
B2CS: 'B2C-Small',
NR: 'Nil Rated, Exempted and Non GST supplies',
};
const stateList = Object.keys(stateCodeMap).map(titleCase).sort();
export default {
filterFields: [
{
fieldtype: 'Select',
label: 'Transfer Type',
placeholder: 'Transfer Type',
fieldname: 'transferType',
options: Object.keys(transferTypeMap),
map: transferTypeMap,
default: 'B2B',
size: 'small',
},
{
fieldtype: 'AutoComplete',
label: 'Place',

View File

@ -2,6 +2,24 @@ const title = 'GSTR 1';
import baseConfig from './BaseViewConfig';
import { generateGstr1Json } from '../../accounting/gst';
const transferTypeMap = {
B2B: 'B2B',
B2CL: 'B2C-Large',
B2CS: 'B2C-Small',
NR: 'Nil Rated, Exempted and Non GST supplies',
};
const transferType = {
fieldtype: 'Select',
label: 'Transfer Type',
placeholder: 'Transfer Type',
fieldname: 'transferType',
options: Object.keys(transferTypeMap),
map: transferTypeMap,
default: 'B2B',
size: 'small',
};
const actions = [
{
group: 'Export',
@ -16,7 +34,7 @@ const actions = [
export default {
title: title,
method: 'gstr-1',
filterFields: baseConfig.filterFields,
filterFields: [ transferType, ...baseConfig.filterFields],
actions: actions,
getColumns: baseConfig.getColumns,
};

View File

@ -16,9 +16,6 @@ class GSTR2 extends BaseGSTR {
// prettier-ignore
const conditions = {
'B2B': row => row.gstin,
'B2CL': row => !row.gstin && !row.inState && row.invAmt >= 250000,
'B2CS': row =>
!row.gstin && (row.inState || (row.inState && row.invAmt < 250000))
};
if (!params.transferType) return data;

View File

@ -2,6 +2,21 @@ const title = 'GSTR 2';
import baseConfig from './BaseViewConfig';
import { generateGstr2Csv } from '../../accounting/gst';
const transferTypeMap = {
B2B: 'B2B',
};
const transferType = {
fieldtype: 'Select',
label: 'Transfer Type',
placeholder: 'Transfer Type',
fieldname: 'transferType',
options: Object.keys(transferTypeMap),
map: transferTypeMap,
default: 'B2B',
size: 'small',
};
const actions = [
{
group: 'Export',
@ -16,7 +31,7 @@ const actions = [
export default {
title: title,
method: 'gstr-2',
filterFields: baseConfig.filterFields,
filterFields: [ transferType, ...baseConfig.filterFields],
actions: actions,
getColumns: baseConfig.getColumns,
};

View File

@ -34,7 +34,7 @@ function csvFormat(value) {
return value;
}
async function exportCsv(rows, columns, filePath) {
export async function exportCsv(rows, columns, filePath) {
const fieldnames = columns.map(({ fieldname }) => fieldname);
const labels = columns.map(({ label }) => csvFormat(label));
const csvRows = [