mirror of
https://github.com/frappe/books.git
synced 2024-12-23 11:29:03 +00:00
Added feature to dowload gstr-1
This commit is contained in:
parent
93540b35fd
commit
f4fa8a6d88
@ -105,6 +105,8 @@ import reportViewConfig from '@/../reports/view';
|
||||
import { makeJSON } from '@/utils';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import { IPC_ACTIONS } from '@/messages';
|
||||
import { DateTime } from 'luxon';
|
||||
import { sleep } from 'frappejs/utils';
|
||||
|
||||
export default {
|
||||
name: 'Report',
|
||||
@ -135,6 +137,7 @@ export default {
|
||||
rows: [],
|
||||
columns: [],
|
||||
},
|
||||
printSettings: null,
|
||||
};
|
||||
},
|
||||
async activated() {
|
||||
@ -142,6 +145,9 @@ export default {
|
||||
await this.setDefaultFilters();
|
||||
await this.fetchReportData();
|
||||
},
|
||||
async mounted() {
|
||||
this.printSettings = await frappe.getSingle('PrintSettings');
|
||||
},
|
||||
methods: {
|
||||
onBodyScroll({ scrollLeft }) {
|
||||
this.$nextTick(() => {
|
||||
@ -277,20 +283,124 @@ export default {
|
||||
async downloadAsJson() {
|
||||
const savePath = await this.getSavePath();
|
||||
if (!savePath) return;
|
||||
let jsonData = [];
|
||||
let gstRecord = {};
|
||||
let keys = this.reportData.columns;
|
||||
|
||||
const gstRates = {
|
||||
'GST-0': 0,
|
||||
'GST-0.25': 0.25,
|
||||
'GST-3': 3,
|
||||
'GST-5': 5,
|
||||
'GST-6': 6,
|
||||
'GST-12': 12,
|
||||
'GST-18': 18,
|
||||
'GST-28': 28,
|
||||
'IGST-0': 0,
|
||||
'IGST-0.25': 0.25,
|
||||
'IGST-3': 3,
|
||||
'IGST-5': 5,
|
||||
'IGST-6': 6,
|
||||
'IGST-12': 12,
|
||||
'IGST-18': 18,
|
||||
'IGST-28': 28,
|
||||
};
|
||||
|
||||
const csgstRates = {
|
||||
'GST-0': 0,
|
||||
'GST-0.25': 0.125,
|
||||
'GST-3': 1.5,
|
||||
'GST-5': 2.5,
|
||||
'GST-6': 3,
|
||||
'GST-12': 6,
|
||||
'GST-18': 9,
|
||||
'GST-28': 14,
|
||||
'IGST-0': 0,
|
||||
'IGST-0.25': 0,
|
||||
'IGST-3': 0,
|
||||
'IGST-5': 0,
|
||||
'IGST-6': 0,
|
||||
'IGST-12': 0,
|
||||
'IGST-18': 0,
|
||||
'IGST-28': 0,
|
||||
};
|
||||
|
||||
const igstRates = {
|
||||
'GST-0': 0,
|
||||
'GST-0.25': 0,
|
||||
'GST-3': 0,
|
||||
'GST-5': 0,
|
||||
'GST-6': 0,
|
||||
'GST-12': 0,
|
||||
'GST-18': 0,
|
||||
'GST-28': 0,
|
||||
'IGST-0': 0,
|
||||
'IGST-0.25': 0.25,
|
||||
'IGST-3': 3,
|
||||
'IGST-5': 5,
|
||||
'IGST-6': 6,
|
||||
'IGST-12': 12,
|
||||
'IGST-18': 18,
|
||||
'IGST-28': 28,
|
||||
};
|
||||
|
||||
const gstData = {
|
||||
version: 'GST3.0.4',
|
||||
hash: 'hash',
|
||||
fp: DateTime.local().toFormat('MMyyyy'),
|
||||
gstin: this.printSettings.gstin,
|
||||
b2b: [],
|
||||
};
|
||||
|
||||
let rows = this.reportData.rows;
|
||||
rows.forEach((values) => {
|
||||
keys.forEach((key) => {
|
||||
gstRecord[key.fieldname] = values[key.fieldname];
|
||||
rows.forEach(async (values) => {
|
||||
|
||||
const b2bRecord = {
|
||||
ctin: values.gstin,
|
||||
inv: [],
|
||||
};
|
||||
|
||||
const invRecord = {
|
||||
inum: values.invNo,
|
||||
idt: values.invDate,
|
||||
value: values.invAmt,
|
||||
pos: values.gstin.substring(0, 2),
|
||||
rchrg: values.reverseCharge,
|
||||
itms: [],
|
||||
};
|
||||
|
||||
let items = await frappe.db
|
||||
.knex('SalesInvoiceItem')
|
||||
.where('parent', invRecord.inum);
|
||||
|
||||
items.forEach((_item) => {
|
||||
const item = {
|
||||
num: 1801, // will be replaced by HSN CODE
|
||||
itm_det: {
|
||||
txval: _item.baseAmount,
|
||||
rt: gstRates[_item.tax],
|
||||
cess: 0,
|
||||
camt: (csgstRates[_item.tax] * _item.baseAmount) / 100,
|
||||
samt: (csgstRates[_item.tax] * _item.baseAmount) / 100,
|
||||
iamt: (igstRates[_item.tax] * _item.baseAmount) / 100,
|
||||
},
|
||||
};
|
||||
invRecord.itms.push(item);
|
||||
});
|
||||
jsonData.push(gstRecord);
|
||||
gstRecord = {};
|
||||
|
||||
let found = false;
|
||||
found = gstData.b2b.find((_b2bRecord) => {
|
||||
if(_b2bRecord.ctin === values.gstin) {
|
||||
_b2bRecord.inv.push(invRecord);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!found) {
|
||||
b2bRecord.inv.push(invRecord);
|
||||
gstData.b2b.push(b2bRecord);
|
||||
}
|
||||
});
|
||||
console.log(jsonData);
|
||||
makeJSON(JSON.stringify(jsonData), savePath);
|
||||
console.log('download complete');
|
||||
await sleep(1);
|
||||
const jsonData = JSON.stringify(gstData);
|
||||
makeJSON(jsonData, savePath);
|
||||
},
|
||||
async getSavePath() {
|
||||
const options = {
|
||||
@ -385,4 +495,4 @@ export default {
|
||||
.report-scroll-container::-webkit-scrollbar-track {
|
||||
background-color: white;
|
||||
}
|
||||
</style>
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user