@keshavsoft/tallyextract 1.2.4 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/index.js +1 -1
  2. package/package.json +1 -1
  3. package/src/v5/api/Import/Templates/inventory.json +121 -0
  4. package/src/v5/api/Import/Templates/ledgers.json +28 -0
  5. package/src/v5/api/Import/Templates/template.json +224 -0
  6. package/src/v5/api/PrepareDataObject/ChangeCustomerDetails/index.js +47 -0
  7. package/src/v5/api/PrepareDataObject/ForInventory/entryFile.js +24 -0
  8. package/src/v5/api/PrepareDataObject/ForInventory/prepareInventory.js +85 -0
  9. package/src/v5/api/PrepareDataObject/ForLedger/entryFile.js +46 -0
  10. package/src/v5/api/PrepareDataObject/ForLedger/prepareLedger.js +24 -0
  11. package/src/v5/api/PrepareDataObject/entryFile.js +20 -0
  12. package/src/v5/api/PrepareDataObject/prepareClientData.js +58 -0
  13. package/src/v5/api/PrepareDataObject/prepareTallyJson/entryFile.js +25 -0
  14. package/src/v5/api/importVoucher.js +16 -0
  15. package/src/v5/api/index.js +5 -0
  16. package/src/v5/api/ledger.js +6 -0
  17. package/src/v5/api/stockItems.js +6 -0
  18. package/src/v5/api/utils/validateInput.js +36 -0
  19. package/src/v5/cli.js +11 -0
  20. package/src/v5/core/impotToTally.js +14 -0
  21. package/src/v5/core/sendToTally.js +21 -0
  22. package/src/v5/index.js +1 -0
  23. package/src/v5/utils/readJson.js +6 -0
  24. package/src/v6/api/Import/Templates/inventory.json +121 -0
  25. package/src/v6/api/Import/Templates/ledgers.json +27 -0
  26. package/src/v6/api/Import/Templates/template.json +224 -0
  27. package/src/v6/api/PrepareDataObject/ChangeCustomerDetails/index.js +47 -0
  28. package/src/v6/api/PrepareDataObject/ForInventory/entryFile.js +24 -0
  29. package/src/v6/api/PrepareDataObject/ForInventory/prepareInventory.js +85 -0
  30. package/src/v6/api/PrepareDataObject/ForLedger/entryFile.js +46 -0
  31. package/src/v6/api/PrepareDataObject/ForLedger/prepareGstLedgers.js +25 -0
  32. package/src/v6/api/PrepareDataObject/ForLedger/prepareLedger.js +25 -0
  33. package/src/v6/api/PrepareDataObject/entryFile.js +20 -0
  34. package/src/v6/api/PrepareDataObject/prepareClientData.js +58 -0
  35. package/src/v6/api/PrepareDataObject/prepareTallyJson/entryFile.js +25 -0
  36. package/src/v6/api/importVoucher.js +16 -0
  37. package/src/v6/api/index.js +5 -0
  38. package/src/v6/api/ledger.js +6 -0
  39. package/src/v6/api/stockItems.js +6 -0
  40. package/src/v6/api/utils/validateInput.js +36 -0
  41. package/src/v6/cli.js +11 -0
  42. package/src/v6/core/impotToTally.js +14 -0
  43. package/src/v6/core/sendToTally.js +21 -0
  44. package/src/v6/index.js +1 -0
  45. package/src/v6/utils/readJson.js +6 -0
@@ -0,0 +1,85 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import { fileURLToPath } from "url";
5
+
6
+ // Prepares single inventory entry
7
+ const startFunc = ({ inItemName, inTaxPer, inUom, inRate, inQty }) => {
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
12
+ const filePath = path.join(__dirname, "../../Import/Templates/inventory.json");
13
+
14
+ let template = fs.readFileSync(filePath, "utf8");
15
+
16
+ let data = JSON.parse(template);
17
+
18
+ const LocalItemName = inItemName;
19
+ const LocalUom = inUom;
20
+ const LocalQty = inQty;
21
+ const LocalRate = inRate;
22
+
23
+ const LocalRateWithTax = LocalRate * (1 + (inTaxPer / 100));
24
+ const LocalAmount = LocalRate * LocalQty;
25
+
26
+ data.hsnitemsource = LocalItemName;
27
+ data.gstitemsource = LocalItemName;
28
+ data.stockitemname = LocalItemName;
29
+
30
+ data.mrprate = `${LocalRateWithTax}.00/${LocalUom}`;
31
+ data.inclvatrate = `${LocalRateWithTax}.00/${LocalUom}`;
32
+
33
+
34
+ // --------------------------------------------------
35
+ // Quantity & Amount
36
+ // --------------------------------------------------
37
+
38
+ data.amount = `${LocalAmount}.00`;
39
+ data.rate = `${LocalRate}.00/${LocalUom}`;
40
+ data.actualqty = `${LocalQty}.00 ${LocalUom}`;
41
+ data.billedqty = `${LocalQty}.00 ${LocalUom}`;
42
+
43
+
44
+ // --------------------------------------------------
45
+ // Batch Allocation
46
+ // --------------------------------------------------
47
+
48
+ data.batchallocations[0].amount = LocalRate * LocalQty;
49
+ data.batchallocations[0].actualqty = `${LocalQty}.00 ${LocalUom}`;
50
+ data.batchallocations[0].billedqty = `${LocalQty}.00 ${LocalUom}`;
51
+
52
+
53
+ // --------------------------------------------------
54
+ // Accounting Allocation
55
+ // --------------------------------------------------
56
+
57
+ data.accountingallocations[0].classrate = `${LocalRate}.00`;
58
+ data.accountingallocations[0].amount = `${LocalAmount}.00`;
59
+
60
+ updateRateDetails(data.ratedetails, inTaxPer);
61
+
62
+ return data;
63
+ };
64
+
65
+ // Update GST ratedetails safely
66
+ const updateRateDetails = (ratedetails, taxPer) => {
67
+ const half = (taxPer / 2).toFixed(2);
68
+ const full = Number(taxPer).toFixed(2);
69
+
70
+ ratedetails.forEach(row => {
71
+ switch (row.gstratedutyhead) {
72
+ case "CGST":
73
+ row.gstrate = half;
74
+ break;
75
+ case "SGST/UTGST":
76
+ row.gstrate = half;
77
+ break;
78
+ case "IGST":
79
+ row.gstrate = full;
80
+ break;
81
+ }
82
+ });
83
+ };
84
+
85
+ export { startFunc };
@@ -0,0 +1,46 @@
1
+ import path from "path";
2
+ import { fileURLToPath } from "url";
3
+ import { startFunc as prepareLedger } from "./prepareLedger.js";
4
+ import prepareGstLedgers from "./prepareGstLedgers.js";
5
+ // Creates ledger entries for voucher
6
+ const startFunc = ({ inItemsJsonAsArray, inLedgerDetails }) => {
7
+ let LocalArray = [];
8
+
9
+ const LocalInItemsJsonAsArray = inItemsJsonAsArray;
10
+
11
+ const LocalAmount = LocalInItemsJsonAsArray.map(element => {
12
+ return element.Rate * element.Qty * (1 + (element.TaxPer / 100));
13
+ });
14
+
15
+ const LocalOnlyAmount = LocalInItemsJsonAsArray.map(element => {
16
+ return element.Rate * element.Qty;
17
+ });
18
+
19
+ const amountSum = LocalAmount.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
20
+ const onlyAmountSum = LocalOnlyAmount.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
21
+
22
+ const LocalLedgerEntry = prepareLedger({
23
+ inLedgerName: inLedgerDetails.LedgerName,
24
+ inAmount: `-${amountSum}.00`
25
+ });
26
+
27
+ LocalArray.push(LocalLedgerEntry);
28
+
29
+ const LocalCGST = prepareGstLedgers({
30
+ inLedgerName: "CGST Output",
31
+ inAmount: `${(amountSum - onlyAmountSum) / 2}.00`
32
+ });
33
+
34
+ LocalArray.push(LocalCGST);
35
+
36
+ const LocalSGST = prepareGstLedgers({
37
+ inLedgerName: "SGST Output",
38
+ inAmount: `${(amountSum - onlyAmountSum) / 2}.00`
39
+ });
40
+
41
+ LocalArray.push(LocalSGST);
42
+
43
+ return LocalArray;
44
+ };
45
+
46
+ export { startFunc };
@@ -0,0 +1,25 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import { fileURLToPath } from "url";
5
+
6
+ // Prepares single ledger entry
7
+ const startFunc = ({ inLedgerName, inAmount }) => {
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
12
+ const filePath = path.join(__dirname, "../../Import/Templates/ledgers.json");
13
+
14
+ let template = fs.readFileSync(filePath, "utf8");
15
+
16
+ let data = JSON.parse(template);
17
+
18
+ data.ledgername = inLedgerName;
19
+ data.amount = inAmount;
20
+ data.vatexpamount = inAmount;
21
+
22
+ return data;
23
+ };
24
+
25
+ export default startFunc;
@@ -0,0 +1,25 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import { fileURLToPath } from "url";
5
+
6
+ // Prepares single ledger entry
7
+ const startFunc = ({ inLedgerName, inAmount }) => {
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
12
+ const filePath = path.join(__dirname, "../../Import/Templates/ledgers.json");
13
+
14
+ let template = fs.readFileSync(filePath, "utf8");
15
+
16
+ let data = JSON.parse(template);
17
+
18
+ data.ledgername = inLedgerName;
19
+ data.amount = inAmount;
20
+ data.isdeemedpositive = true;
21
+
22
+ return data;
23
+ };
24
+
25
+ export { startFunc };
@@ -0,0 +1,20 @@
1
+ import { startFunc as prepareClientData } from "./prepareClientData.js";
2
+ import { startFunc as prepareTallyJson } from "./prepareTallyJson/entryFile.js";
3
+
4
+ const startFunc = ({ inClientData }) => {
5
+ try {
6
+ let data = prepareTallyJson();
7
+
8
+ const fromClientData = prepareClientData({
9
+ inTallyJson: data,
10
+ inClientData
11
+ });
12
+
13
+ return fromClientData;
14
+ } catch (err) {
15
+ console.error("Import Failed");
16
+ console.log(err.response?.data || err.message);
17
+ };
18
+ };
19
+
20
+ export { startFunc };
@@ -0,0 +1,58 @@
1
+ import { startFunc as ForLedger } from "./ForLedger/entryFile.js";
2
+ import { startFunc as ForInventory } from "./ForInventory/entryFile.js";
3
+ import changeCustomerDetails from "./ChangeCustomerDetails/index.js";
4
+
5
+ const startFunc = ({ inTallyJson, inClientData }) => {
6
+ try {
7
+ let data = inTallyJson;
8
+
9
+ const LocalClientData = inClientData;
10
+
11
+ const LocalInventoryItem = ForInventory({ inItemsJsonAsArray: LocalClientData.allinventoryentries });
12
+
13
+ const LocalLedgerItem = ForLedger({
14
+ inItemsJsonAsArray: LocalClientData.allinventoryentries,
15
+ inLedgerDetails: LocalClientData.customerDetails
16
+ });
17
+
18
+ changeCustomerDetails({
19
+ inTallyJson, inClientData
20
+ });
21
+
22
+ // changeVoucherDate({
23
+ // inData: data,
24
+ // inDate: LocalClientData.customerDetails.InvoiceDate
25
+ // });
26
+
27
+ data.tallymessage[0].allinventoryentries = LocalInventoryItem;
28
+ data.tallymessage[0].ledgerentries = LocalLedgerItem;
29
+
30
+ return data;
31
+ } catch (err) {
32
+ console.error("Import Failed");
33
+ console.log(err.response?.data || err.message);
34
+ };
35
+ };
36
+
37
+ const changeCustomerDetails1 = ({ inLedgerName, inData }) => {
38
+ const CommonLedgerName = inLedgerName;
39
+
40
+ inData.tallymessage[0].partyname = CommonLedgerName;
41
+ inData.tallymessage[0].basicbuyername = CommonLedgerName;
42
+ inData.tallymessage[0].partyledgername = CommonLedgerName;
43
+ inData.tallymessage[0].consigneemailingname = CommonLedgerName;
44
+ inData.tallymessage[0].partymailingname = CommonLedgerName;
45
+ inData.tallymessage[0].basicbasepartyname = CommonLedgerName;
46
+ inData.tallymessage[0].gstregistrationtype = "Regular";
47
+ inData.tallymessage[0].partygstin = "37BEVPS3045F1Z1";
48
+ };
49
+
50
+ const changeVoucherDate = ({ inData, inDate }) => {
51
+ const localDate = inDate;
52
+
53
+ inData.tallymessage[0].date = localDate;
54
+ inData.tallymessage[0].vchstatusdate = localDate;
55
+ inData.tallymessage[0].effectivedate = localDate;
56
+ };
57
+
58
+ export { startFunc };
@@ -0,0 +1,25 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import { fileURLToPath } from "url";
5
+
6
+ const startFunc = () => {
7
+ try {
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
12
+ const filePath = path.join(__dirname, "../../Import/Templates/template.json");
13
+
14
+ let template = fs.readFileSync(filePath, "utf8");
15
+
16
+ let data = JSON.parse(template);
17
+
18
+ return data;
19
+ } catch (err) {
20
+ console.error("Import Failed");
21
+ console.log(err.response?.data || err.message);
22
+ };
23
+ };
24
+
25
+ export { startFunc };
@@ -0,0 +1,16 @@
1
+ import { sendToTally } from "../core/impotToTally.js";
2
+ import { startFunc as PrepareDataObject } from "./PrepareDataObject/entryFile.js";
3
+
4
+ import { validateImportVoucherInput } from "./utils/validateInput.js";
5
+
6
+ const importVoucher = async (inClientData) => {
7
+ validateImportVoucherInput(inClientData); // 🔥 early fail
8
+
9
+ const bodyToSend = PrepareDataObject({ inClientData });
10
+
11
+ return await sendToTally(bodyToSend);
12
+
13
+ return await true;
14
+ };
15
+
16
+ export { importVoucher };
@@ -0,0 +1,5 @@
1
+ // src/v1/api/index.js
2
+ export { ledger } from "./ledger.js";
3
+ export { stockItems } from "./stockitems.js";
4
+
5
+ export { importVoucher } from "./importVoucher.js";
@@ -0,0 +1,6 @@
1
+ // src/v1/api/stockItems.js
2
+ import { sendToTally } from "../core/sendToTally.js";
3
+
4
+ export function ledger() {
5
+ return sendToTally("KeshavLedgers");
6
+ };
@@ -0,0 +1,6 @@
1
+ // src/v1/api/stockItems.js
2
+ import { sendToTally } from "../core/sendToTally.js";
3
+
4
+ export function stockItems() {
5
+ return sendToTally("KeshavStockItems");
6
+ };
@@ -0,0 +1,36 @@
1
+ // utils/validateInput.js
2
+ const validateImportVoucherInput = (data) => {
3
+ if (!data || typeof data !== "object") {
4
+ throw new Error("Input must be an object");
5
+ }
6
+
7
+ // 🔹 allinventoryentries
8
+ if (!Array.isArray(data.allinventoryentries)) {
9
+ throw new Error("allinventoryentries must be an array");
10
+ }
11
+
12
+ if (data.allinventoryentries.length === 0) {
13
+ throw new Error("allinventoryentries cannot be empty");
14
+ }
15
+
16
+ // optional: validate one item structure
17
+ const item = data.allinventoryentries[0];
18
+ if (!item.ItemName || !item.Qty) {
19
+ throw new Error("Invalid inventory item structure");
20
+ }
21
+
22
+ // 🔹 customerDetails
23
+ if (!data.customerDetails || typeof data.customerDetails !== "object") {
24
+ throw new Error("customerDetails must be an object");
25
+ }
26
+
27
+ if (!data.customerDetails.LedgerName) {
28
+ throw new Error("LedgerName is required in customerDetails");
29
+ }
30
+
31
+ if (!data.customerDetails.InvoiceDate) {
32
+ throw new Error("InvoiceDate is required in customerDetails");
33
+ }
34
+ };
35
+
36
+ export { validateImportVoucherInput };
package/src/v6/cli.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+
3
+ console.log("kschema CLI running 🚀");
4
+
5
+ const args = process.argv.slice(2);
6
+
7
+ console.log("Args:", args);
8
+
9
+ if (args[0] === "init") {
10
+ console.log("Init command triggered");
11
+ };
@@ -0,0 +1,14 @@
1
+ export async function sendToTally(data, url = "http://localhost:9000") {
2
+ const res = await fetch(url, {
3
+ method: "POST",
4
+ headers: {
5
+ "Content-Type": "application/json",
6
+ "TallyRequest": "Import",
7
+ "Type": "Data",
8
+ "Id": "Vouchers"
9
+ },
10
+ body: JSON.stringify(data)
11
+ });
12
+
13
+ return res.json();
14
+ };
@@ -0,0 +1,21 @@
1
+ // src/v1/core/sendToTally.js
2
+ const BODY = {
3
+ static_variables: [
4
+ { name: "svExportFormat", value: "jsonex" }
5
+ ]
6
+ };
7
+
8
+ export async function sendToTally(Id, url = "http://localhost:9000") {
9
+ const res = await fetch(url, {
10
+ method: "POST",
11
+ headers: {
12
+ "Content-Type": "application/json",
13
+ "TallyRequest": "Export",
14
+ "Type": "Collection",
15
+ "Id": Id
16
+ },
17
+ body: JSON.stringify(BODY)
18
+ });
19
+
20
+ return res.json();
21
+ };
@@ -0,0 +1 @@
1
+ export * from "./api/index.js";
@@ -0,0 +1,6 @@
1
+ // utils/readJson.js
2
+ import fs from "fs/promises";
3
+
4
+ export async function readJson(filePath) {
5
+ return JSON.parse(await fs.readFile(filePath, "utf8"));
6
+ };