-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathappState.json
More file actions
1 lines (1 loc) · 52.3 KB
/
appState.json
File metadata and controls
1 lines (1 loc) · 52.3 KB
1
{"EDITOR_STATE":{"allProjectFiles":{"261bafd6-e58c-475d-9415-c1a9385d5243":{"id":"261bafd6-e58c-475d-9415-c1a9385d5243","parent":null,"name":"slappbooks","type":"DIRECTORY","isDirectory":true,"children":["6ce22331-3d5d-4d2e-a5ff-a2f2b38257dd","0cafcfb9-14f8-4cdc-861f-299678af0759","10af9bcd-ac92-434b-9eb0-ca8ff233ec9b","1f616325-bebd-4cb6-9a59-efae98b7760d","d5e8f837-33f8-4736-ba1b-eb1f3aface18","02bc79d4-d52f-4002-b502-992569e9d409","d5925ac9-5dfa-4cc8-9963-15dd6fb40204","0fddcfbb-9df4-458a-a743-9f28159227fc","0b73f184-a777-475d-9741-bf94b7a4629a","8585b721-aeb2-4a48-978d-ddfca08566d1","65abaa92-243f-4c9a-988b-4aed7faac7a2","3e289213-2e08-453c-a6c3-139ee447fd70"],"isRemovable":false,"filePath":"slappbooks"},"6ce22331-3d5d-4d2e-a5ff-a2f2b38257dd":{"id":"6ce22331-3d5d-4d2e-a5ff-a2f2b38257dd","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"add-transaction.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/add-transaction.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n/**\n * Lambda function handles transaction inserts. Events are submitted through the application as transaction objects. \n * An RDS instance is used for transaction inserts. Transactional behaviour is guaranteed for the insert.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n\ttransactions = event.slice();\n\ttransactions.forEach((transaction, index) => {\n\t\tif ((transaction.amount).toString().startsWith(\"(\") && transaction.amount.toString().endsWith(\")\")) {\n\t\t\ttransaction.amount = transaction.amount.slice(1, transaction.amount.length - 1);\n\t\t}\n\t\ttransaction.isCredit = transaction.isCredit ? 1 : 0;\n\t});\n\tlet entity_id;\n\n\trds.beginTransaction({\n\t\tinstanceIdentifier: 'slappbooksdb'\n\t}, function (error, connection) {\n\t\tif (error) { throw err; }\n\t\tlet sql = 'INSERT INTO transaction (transaction_id, set_id, date, entity_id, is_credit, cheque_no, voucher_no, amount, notes, reconcile)' +\n\t\t\t' VALUES (?,?,?,?,?, ?, ?, ?, ?, ?);'\n\n\t\ttransactions.forEach((transaction, index) => {\n\t\t\tlet entityArray = [transaction.entityName];\n\t\t\trds.query({\n\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\tquery: 'SELECT id FROM entity WHERE name = ?',\n\t\t\t\tinserts: entityArray\n\t\t\t}, function (error, results, connection) {\n\t\t\t\tif (error) {\n\t\t\t\t\tconsole.log(\"Error occurred while retreiving the entity id from the database\", error);\n\t\t\t\t\tconnection.rollback();\n\t\t\t\t\tthrow error;\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(\"Successfully retrieved the entity id\")\n\t\t\t\t\tentity_id = results[0].id;\n\t\t\t\t\tconsole.log(transaction.trId);\n\n\t\t\t\t\tlet transactionInsertArray = [transaction.trId, transaction.setId, transaction.date, entity_id, transaction.isCredit, transaction.checkNo,\n\t\t\t\t\ttransaction.voucherNo, transaction.amount, transaction.notes, transaction.reconcile];\n\t\t\t\t\trds.query({\n\t\t\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\t\t\tquery: sql,\n\t\t\t\t\t\tinserts: transactionInsertArray\n\t\t\t\t\t}, function (error, results, connection) {\n\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\tconnection.rollback();\n\t\t\t\t\t\t\tconsole.log(\"Error occurred while inserting the transaction\", error);\n\t\t\t\t\t\t\tcallback(error, JSON.stringify(event));\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconsole.log(\"Successfully inserted the transaction\")\n\t\t\t\t\t\t\tconsole.log(results);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (index === transactions.length - 1) {\n\t\t\t\t\t\t\tconsole.log(\"ending connection\", index);\n\t\t\t\t\t\t\tconnection.end();\n\t\t\t\t\t\t\tcallback(error, JSON.stringify(event));\n\t\t\t\t\t\t}\n\t\t\t\t\t}, connection);\n\t\t\t\t}\n\t\t\t}, connection);\n\t\t\tconnection.commit();\n\t\t});\n\t});\n}","triggers":[{"resourceName":"apigusEast1slappbooksapiaddTransactionpost","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"addTransaction","resourcePath":"/addTransaction","restMethod":"POST","stageMode":0,"stageName":"Prod"}}]},"0cafcfb9-14f8-4cdc-861f-299678af0759":{"id":"0cafcfb9-14f8-4cdc-861f-299678af0759","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"retrieve-transactions.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/retrieve-transactions.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n/**\n * Lambda function retrieves transactions while supporting pagination. Events are submitted through the application as an identifier. \n * An RDS instance is used for transaction retrieval.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n\tconsole.log(event);\n\tlet postObject = event;\n\tlet entityName = postObject.entity;\n\tlet pageNo = postObject.page;\n\tlet pageSize = postObject.pageSize;\n\tlet sorted = postObject.sorted;\n\tlet filtered = postObject.filtered;\n\tlet startIndex = +pageNo * +pageSize;\n\tlet endIndex = startIndex + pageSize;\n\tlet pageNumber = 1;\n\n\t// Retrieve all transactions limited by the start index and page size\n\tlet sql = 'SELECT * FROM transaction T INNER JOIN entity E ON T.entity_id = E.id WHERE E.name = ? LIMIT ?,?';\n\n\trds.query({\n\t\tinstanceIdentifier: 'slappbooksdb',\n\t\tquery: 'SELECT count(*) as count FROM transaction;'\n\t}, function (error, results, connection) {\n\t\tif (error) {\n\t\t\tconsole.log(\"Error occurred while retrieving count\", error);\n\t\t\tthrow error;\n\t\t} else {\n\t\t\tconsole.log(\"Successfully obtained database count\");\n\t\t\tconsole.log(results[0].count);\n\t\t\tpageNumber = Math.ceil(parseFloat(results[0].count) / parseFloat(pageSize));\n\n\t\t\tlet queryArray = [entityName, startIndex, pageSize];\n\t\t\trds.query({\n\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\tquery: sql,\n\t\t\t\tinserts: queryArray\n\t\t\t}, function (error, results, connection) {\n\t\t\t\tif (error) {\n\t\t\t\t\tconsole.log(\"Error occurred while retreiving transactions\", error);\n\t\t\t\t\tthrow error;\n\t\t\t\t} else {\n\t\t\t\t\tlet transactions = [];\n\t\t\t\t\tconsole.log(\"Successfully retreived transactions\");\n\t\t\t\t\tresults.forEach(result => {\n\t\t\t\t\t\ttransactions.push({\n\t\t\t\t\t\t\ttrId: result.transaction_id,\n\t\t\t\t\t\t\tdate: result.date,\n\t\t\t\t\t\t\tcheckNo: result.cheque_no,\n\t\t\t\t\t\t\tvoucherNo: result.voucher_no,\n\t\t\t\t\t\t\tisCredit: result.is_credit,\n\t\t\t\t\t\t\tamount: result.amount,\n\t\t\t\t\t\t\tnotes: result.notes,\n\t\t\t\t\t\t\treconcile: result.reconcile,\n\t\t\t\t\t\t\tsetId: result.set_id,\n\t\t\t\t\t\t\tentityName: entityName\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tlet finalResult = { rows: transactions, pages: pageNumber }\n\t\t\t\t\tconsole.log(finalResult);\n\t\t\t\t\tconnection.end();\n\t\t\t\t\tcallback(error, finalResult);\n\t\t\t\t}\n\t\t\t}, connection);\n\t\t}\n\t});\n}","triggers":[{"resourceName":"apigusEast1slappbooksapigetTransactionListpost","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"getTransactionList","resourcePath":"/getTransactionList","restMethod":"POST","proxyIntegration":false,"stageMode":0,"stageName":"Prod"}}]},"10af9bcd-ac92-434b-9eb0-ca8ff233ec9b":{"id":"10af9bcd-ac92-434b-9eb0-ca8ff233ec9b","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"create-entity.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/create-entity.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n/**\n * Lambda function handles entity creation. Events are submitted through the application as entity objects \n * An RDS instance is used for entity creation.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n\tlet entity = event;\n\n\tlet sql = 'INSERT INTO entity (name, currency, type) values (?, ?, ?)';\n\tlet entityArray = [entity.entity, entity.currency, entity.entityType];\n\n\t// Insert entity value to the database\n\trds.query({\n\t\tinstanceIdentifier: 'slappbooksdb',\n\t\tquery: sql,\n\t\tinserts: entityArray\n\t}, function (error, results, connection) {\n\t\tif (error) {\n\t\t\tconsole.log(\"Error occurred while inserting the entity\", error);\n\t\t\tconnection.end();\n\t\t\tcallback(error, JSON.stringify({ error: \"Error occurred while inserting the entity\" }));\n\t\t\tthrow error;\n\t\t} else {\n\t\t\tconsole.log(\"Successfully inserted the entity\");\n\t\t\tconnection.end();\n\t\t\tcallback(error, JSON.stringify({ success: \"successfully created the entity\" }));\n\t\t}\n\t});\n}","triggers":[{"resourceName":"apigusEast1slappbooksapicreateEntitypost","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"createEntity","resourcePath":"/createEntity","restMethod":"POST","proxyIntegration":false,"stageMode":0,"stageName":"Prod"}}]},"1f616325-bebd-4cb6-9a59-efae98b7760d":{"id":"1f616325-bebd-4cb6-9a59-efae98b7760d","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"get-transaction.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/get-transaction.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n/**\n * Lambda function retrieves a transaction. Events are submitted through the application as an identifier. \n * An RDS instance is used for transaction retrieval.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n let transactionId = event.queryStringParameters.id;\n\n let sql = 'SELECT T.transaction_id, T.set_id, T.date, T.cheque_no, T.is_credit, T.amount, T.notes, T.reconcile, E.name FROM ' +\n 'transaction T INNER JOIN entity E on T.entity_id=E.id where T.set_id=?;';\n let transactionIdArray = [transactionId];\n\n rds.query({\n instanceIdentifier: 'slappbooksdb',\n query: sql,\n inserts: transactionIdArray\n }, function (error, results, connection) {\n if (error) {\n console.log(\"Error occurred while retrieving the transaction with set_id\", transactionId, error);\n throw error;\n } else {\n console.log(\"Successfully retrieved the transaction\")\n let transactions = [];\n results.forEach(result => {\n transactions.push({\n trId: result.transaction_id,\n setId: result.setId,\n date: result.date,\n checkNo: result.cheque_no,\n voucherNo: result.voucher_no,\n isCredit: result.is_credit,\n amount: result.amount,\n notes: result.notes,\n reconcile: result.reconcile,\n entityName: result.name\n });\n });\n console.log(transactions);\n connection.end();\n callback(null, {\n \"statusCode\": 200,\n \"headers\": {\n \"app_header\": \"slappbooks\",\n \"Access-Control-Allow-Origin\": \"*\"\n },\n \"body\": JSON.stringify(transactions),\n \"isBase64Encoded\": false\n });\n }\n });\n}","triggers":[{"resourceName":"apigusEast1slappbooksapigetTransactionByIdget","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"getTransactionById","resourcePath":"/getTransactionById","restMethod":"GET","proxyIntegration":true,"stageMode":0,"stageName":"Prod"}}]},"d5e8f837-33f8-4736-ba1b-eb1f3aface18":{"id":"d5e8f837-33f8-4736-ba1b-eb1f3aface18","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"get-entity-list.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/get-entity-list.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n/**\n * Lambda function handles entity retrieval.\n * An RDS instance is used for entity retrieval.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n\tlet sql = 'SELECT * FROM entity;'\n\n\t// Retrieve the entity objects \n\trds.query({\n\t\tinstanceIdentifier: 'slappbooksdb',\n\t\tquery: sql\n\t}, function (error, results, connection) {\n\t\tif (error) {\n\t\t\tconsole.log(\"Error occurred while retrieving entities\", error);\n\t\t\tthrow error;\n\t\t} else {\n\t\t\tconsole.log(\"Successfully retrieved entities\")\n\t\t\tconsole.log(results);\n\t\t\tlet entities = [];\n\t\t\tresults.forEach(result => {\n\t\t\t\tentities.push({\n\t\t\t\t\tentityName: result.name,\n\t\t\t\t\tentityType: result.type,\n\t\t\t\t\tdefaultCurrency: result.currency\n\t\t\t\t});\n\t\t\t});\n\t\t\tconsole.log(entities);\n\t\t\tconnection.end();\n\t\t\tcallback(error, {\n\t\t\t\t\"statusCode\": 200,\n\t\t\t\t\"headers\": {\n\t\t\t\t\t\"app_header\": \"slappbooks\",\n\t\t\t\t\t\"Access-Control-Allow-Origin\": \"*\"\n\t\t\t\t},\n\t\t\t\t\"body\": JSON.stringify(entities),\n\t\t\t\t\"isBase64Encoded\": false\n\t\t\t});\n\t\t}\n\t});\n}","triggers":[{"resourceName":"apigusEast1slappbooksapigetEntityListget","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"getEntityList","resourcePath":"/getEntityList","restMethod":"GET","proxyIntegration":true,"stageMode":0,"stageName":"Prod"}}]},"65abaa92-243f-4c9a-988b-4aed7faac7a2":{"id":"65abaa92-243f-4c9a-988b-4aed7faac7a2","parent":null,"name":"ConnectionManager.js","type":"JS_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/ConnectionManager.js","code":"module.exports = function () {\n this.dbConnections = [];\n this.dbConnections[\"slappbooksdb\"] = {\n host: process.env.EndPoint_rdsSlappbooksdb,\n port: process.env.Port_rdsSlappbooksdb,\n user: process.env.User_rdsSlappbooksdb,\n password: process.env.Password_rdsSlappbooksdb,\n database: \"slappbooksdb\"\n };\n};","triggers":[]},"02bc79d4-d52f-4002-b502-992569e9d409":{"id":"02bc79d4-d52f-4002-b502-992569e9d409","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"insert-transaction-with-currency.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/insert-transaction-with-currency.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n\n/**\n * Lambda function handles transaction inserts. Events are submitted through the application as transaction objects. \n * An RDS instance is used for transaction inserts. Currency differences are also handled through this lambda function as opposed to a usual \n * transaction insert.Transactional behaviour is guaranteed for the insert.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n\tpostObject = event;\n\ttransactions = postObject.transactions;\n\tconversions = postObject.conversionDetails;\n\tconsole.log(conversions);\n\n\ttransactions.forEach((transaction, index) => {\n\t\tif ((transaction.amount).toString().startsWith(\"(\") && transaction.amount.toString().endsWith(\")\")) {\n\t\t\ttransaction.amount = transaction.amount.slice(1, transaction.amount.length - 1);\n\t\t}\n\t\ttransaction.isCredit = transaction.isCredit ? 1 : 0;\n\t});\n\tlet entity_id;\n\n\trds.beginTransaction({\n\t\tinstanceIdentifier: 'slappbooksdb'\n\t}, function (error, connection) {\n\t\tif (error) { throw err; }\n\n\t\tlet sql = 'INSERT INTO transaction (transaction_id, set_id, date, entity_id, is_credit, cheque_no, voucher_no, amount, notes,' +\n\t\t\t' reconcile) VALUES (?,?,?,?,?, ?, ?, ?, ?, ?);';\n\t\tlet entityArray = [transaction.entityName];\n\t\ttransactions.forEach((transaction, index) => {\n\t\t\trds.query({\n\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\tquery: 'SELECT id FROM entity WHERE name = ?',\n\t\t\t\tinserts: entityArray\n\t\t\t}, function (error, results, connection) {\n\t\t\t\tif (error) {\n\t\t\t\t\tconsole.log(\"Error occurred while retreiving the entity id from the database\", error);\n\t\t\t\t\tconnection.rollback();\n\t\t\t\t\tconnection.end();\n\t\t\t\t\tthrow error;\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(\"Successfully retrieved the entity id\")\n\t\t\t\t\tentity_id = results[0].id;\n\t\t\t\t\tconsole.log(transaction.trId);\n\n\t\t\t\t\tlet transactionInsertArray = [transaction.trId, transaction.setId, transaction.date, entity_id, transaction.isCredit, transaction.checkNo, transaction.voucherNo, transaction.amount, transaction.notes, transaction.reconcile];\n\t\t\t\t\trds.query({\n\t\t\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\t\t\tquery: sql,\n\t\t\t\t\t\tinserts: transactionInsertArray\n\t\t\t\t\t}, function (error, results, connection) {\n\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\tconnection.rollback();\n\t\t\t\t\t\t\tconnection.end();\n\t\t\t\t\t\t\tconsole.log(\"Error occurred while inserting the transaction\", error);\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconsole.log(\"Successfully inserted the transaction\")\n\t\t\t\t\t\t\tconsole.log(results);\n\t\t\t\t\t\t\tsql = 'INSERT INTO conversion (transaction_id, to_currency, from_currency, rate) VALUES (?,?,?,?)';\n\t\t\t\t\t\t\tlet conversionInsertArray = [transaction.trId, conversions[index]._toCurrency, conversions[index]._fromCurrency, conversions[index]._conversionRate];\n\t\t\t\t\t\t\trds.query({\n\t\t\t\t\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\t\t\t\t\tquery: sql,\n\t\t\t\t\t\t\t\tinserts: conversionInsertArray\n\t\t\t\t\t\t\t}, function (error, results, connection) {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconnection.rollback();\n\t\t\t\t\t\t\t\t\tconnection.end();\n\t\t\t\t\t\t\t\t\tconsole.log(\"Error occurred while inserting conversions\");\n\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconsole.log(\"Successfully inserted a conversion object\");\n\t\t\t\t\t\t\t\t\tconsole.log(results);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}, connection);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (index === transactions.length - 1) {\n\t\t\t\t\t\t\tconnection.commit();\n\t\t\t\t\t\t\tconnection.end();\n\t\t\t\t\t\t\tcallback(error, JSON.stringify(event));\n\t\t\t\t\t\t}\n\t\t\t\t\t}, connection);\n\t\t\t\t}\n\t\t\t}, connection);\n\t\t});\n\t});\n}","triggers":[{"resourceName":"apigusEast1slappbooksapicreateTransactionWithCurrencyDifferencepost","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"createTransactionWithCurrencyDifference","resourcePath":"/createTransactionWithCurrencyDifference","restMethod":"POST","proxyIntegration":false,"stageMode":0,"stageName":"Prod"}}]},"d5925ac9-5dfa-4cc8-9963-15dd6fb40204":{"id":"d5925ac9-5dfa-4cc8-9963-15dd6fb40204","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"update-transaction.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/update-transaction.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n/**\n * Lambda function handles transaction updates. Events are submitted through the application as transaction objects. \n * An RDS instance is used for transaction updates. Transactional behaviour is guaranteed for the update.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n\tlet transactions = event.slice();\n\ttransactions.forEach(transaction => {\n\t\tif ((transaction.amount).toString().startsWith(\"(\") && transaction.amount.toString().endsWith(\")\")) {\n\t\t\ttransaction.amount = transaction.amount.slice(1, transaction.amount.length - 1);\n\t\t}\n\t\ttransaction.isCredit = transaction.isCredit ? 1 : 0;\n\t});\n\n\trds.beginTransaction({\n\t\tinstanceIdentifier: 'slappbooksdb'\n\t}, function (error, connection) {\n\t\tif (error) { connection.rollback(); throw error; }\n\n\t\t// Insert transactions to the database \n\t\ttransactions.forEach((transaction, index) => {\n\t\t\tlet entityArray = [transaction.entityName];\n\n\t\t\trds.query({\n\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\tquery: 'SELECT id FROM entity WHERE name = ?',\n\t\t\t\tinserts: entityArray\n\t\t\t}, function (error, results, connection) {\n\t\t\t\tif (error) {\n\t\t\t\t\tconsole.log(\"Error occurred while retreiving the entity id from the database\", error);\n\t\t\t\t\tconnection.rollback();\n\t\t\t\t\tthrow error;\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(\"Successfully retrieved the entity id\")\n\t\t\t\t\tlet entity_id = results[0].id;\n\t\t\t\t\tconsole.log(transaction.trId);\n\n\t\t\t\t\tlet sql = 'UPDATE transaction SET transaction_id=?, set_id=?, date=?, entity_id=?, is_credit=?, cheque_no=?, voucher_no=?, amount=?, notes=?, reconcile=? WHERE transaction_id=?';\n\t\t\t\t\tlet updateArray = [transaction.trId, transaction.setId, transaction.date, entity_id, transaction.isCredit, transaction.checkNo, transaction.voucherNo, transaction.amount, transaction.notes, transaction.reconcile, transaction.trId];\n\t\t\t\t\trds.query({\n\t\t\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\t\t\tquery: sql,\n\t\t\t\t\t\tinserts: updateArray\n\t\t\t\t\t}, function (error, results, connection) {\n\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\tconnection.rollback();\n\t\t\t\t\t\t\tconsole.log(\"Error occurred while updating the transaction\", error);\n\t\t\t\t\t\t\tcallback(error, JSON.stringify(event));\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconsole.log(\"Successfully updated the transaction\");\n\t\t\t\t\t\t\tconnection.commit();\n\t\t\t\t\t\t\tconnection.end();\n\t\t\t\t\t\t\tcallback(error, JSON.stringify(event));\n\t\t\t\t\t\t}\n\t\t\t\t\t}, connection);\n\t\t\t\t}\n\t\t\t}, connection);\n\t\t});\n\t});\n}","triggers":[{"resourceName":"apigusEast1slappbooksapiupdateTransactionpost","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"updateTransaction","resourcePath":"/updateTransaction","restMethod":"POST","proxyIntegration":false,"stageMode":0,"stageName":"Prod"}}]},"0fddcfbb-9df4-458a-a743-9f28159227fc":{"id":"0fddcfbb-9df4-458a-a743-9f28159227fc","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"delete-transaction.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/delete-transaction.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n/**\n * Lambda function handles deleting a transaction. Events are submitted through the application as a transaction identifier. \n * An RDS instance is used for transaction deletion. Transactional behaviour is guaranteed for a delete.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n\tlet setId = event.setId;\n\n\trds.beginTransaction({\n\t\tinstanceIdentifier: 'slappbooksdb'\n\t}, function (error, connection) {\n\t\tif (error) { throw err; }\n\n\t\tlet sql = 'DELETE FROM transaction WHERE set_id=?';\n\t\tlet setIdArray = [setId];\n\t\t// Delete a transaction from the database\n\t\trds.query({\n\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\tquery: sql,\n\t\t\tinserts: setIdArray\n\t\t}, function (error, results, connection) {\n\t\t\tif (error) {\n\t\t\t\tconnection.rollback();\n\t\t\t\tconnection.end();\n\t\t\t\tconsole.log(\"Error occurred while deleting the transaction with set id\", setId, error);\n\t\t\t\tcallback(error, JSON.stringify(event));\n\t\t\t\tthrow error;\n\t\t\t} else {\n\t\t\t\tconnection.commit();\n\t\t\t\tconnection.end();\n\t\t\t\tconsole.log(\"Successfully deleted the transaction with set id\", setId);\n\t\t\t\tcallback(null, JSON.stringify(event));\n\t\t\t}\n\t\t}, connection);\n\n\t});\n}","triggers":[{"resourceName":"apigusEast1slappbooksapideleteTransactionpost","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"deleteTransaction","resourcePath":"/deleteTransaction","restMethod":"POST","proxyIntegration":false,"stageMode":0,"stageName":"Prod"}}]},"0b73f184-a777-475d-9741-bf94b7a4629a":{"id":"0b73f184-a777-475d-9741-bf94b7a4629a","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"get-monthly-transactions.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/get-monthly-transactions.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n/**\n * Lambda function retrieves transactions month wise while supporting pagination. Events are submitted through the application as an identifier. \n * An RDS instance is used for transaction retrieval.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n\tlet postObject = event;\n\tlet entityName = postObject.entity;\n\tlet pageNo = postObject.page;\n\tlet pageSize = postObject.pageSize;\n\tlet sorted = postObject.sorted;\n\tlet filtered = postObject.filtered;\n\tlet startIndex = +pageNo * +pageSize;\n\tlet endIndex = startIndex + pageSize;\n\tlet pageNumber = 1;\n\tlet year = postObject.year;\n\tlet month = postObject.month;\n\n\t// retrieve transactions between the selected time frame\n\tlet sql = 'SELECT * FROM transaction T INNER JOIN entity E ON T.entity_id = E.id WHERE E.name =? AND date BETWEEN ? AND ? LIMIT ?,?';\n\tlet entityArray = [entityName, year.concat(\"-\").concat(month).concat(\"-01\"), year.concat(\"-\").concat(month).concat(\"-31\")];\n\n\trds.query({\n\t\tinstanceIdentifier: 'slappbooksdb',\n\t\tquery: 'SELECT count(*) as count FROM transaction T INNER JOIN entity E ON T.entity_id = E.id WHERE E.name=? AND date BETWEEN ? AND ?',\n\t\tinserts: entityArray\n\t}, function (error, results, connection) {\n\t\tif (error) {\n\t\t\tconsole.log(\"Error occurred while retrieving count\");\n\t\t\tthrow error;\n\t\t} else {\n\t\t\tconsole.log(\"Successfully obtained database count\");\n\t\t\tconsole.log(results[0].count);\n\t\t\tpageNumber = Math.ceil(parseFloat(results[0].count) / parseFloat(pageSize));\n\n\t\t\tlet transactionQueryArray = [entityName, year.concat(\"-\").concat(month).concat(\"-01\"), year.concat(\"-\").concat(month).concat(\"-31\"), startIndex, pageSize];\n\t\t\t// retrieve transactions between a given time frame\n\t\t\trds.query({\n\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\tquery: sql,\n\t\t\t\tinserts: transactionQueryArray\n\t\t\t}, function (error, results, connection) {\n\t\t\t\tif (error) {\n\t\t\t\t\tconsole.log(\"Error occurred while retreiving transactions\", error);\n\t\t\t\t\tthrow error;\n\t\t\t\t} else {\n\t\t\t\t\tlet transactions = [];\n\t\t\t\t\ttransactionResult = results;\n\t\t\t\t\tconsole.log(transactionResult);\n\t\t\t\t\tconsole.log(\"Successfully retreived transactions\");\n\t\t\t\t\tif (startIndex == 0) {\n\n\t\t\t\t\t\tlet amountSql = 'SELECT SUM( IF (T.is_credit = 1, -1 * amount, amount) ) as amount FROM transaction T INNER JOIN entity E ON T.entity_id = E.id WHERE E.name = ? AND date < ?;';\n\t\t\t\t\t\tlet amountQueryArray = [entityName, year.concat(\"-\").concat(month).concat(\"-01\")];\n\t\t\t\t\t\t// Generate the required credit and debit balances to formulate the balance brought forward query\n\t\t\t\t\t\trds.query({\n\t\t\t\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\t\t\t\tquery: amountSql,\n\t\t\t\t\t\t\tinserts: amountQueryArray\n\t\t\t\t\t\t}, function (error, resultAmount, connection) {\n\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\tconsole.log(\"Error occurred while retrieving the amount as balance brought forward\", error);\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tconsole.log(\"Successfully retreived the amount as balance brought forward\");\n\t\t\t\t\t\t\t\tconsole.log(resultAmount);\n\t\t\t\t\t\t\t\tlet amount = resultAmount[0].amount;\n\t\t\t\t\t\t\t\tamount = amount === null ? 0 : amount;\n\n\t\t\t\t\t\t\t\ttransactions.push({\n\t\t\t\t\t\t\t\t\ttrId: '00000000000000000',\n\t\t\t\t\t\t\t\t\tnotes: 'Balance Brought Forward',\n\t\t\t\t\t\t\t\t\tdate: year.concat(\"-\").concat(month).concat(\"-01\"),\n\t\t\t\t\t\t\t\t\tisCredit: amount < 0 ? 1 : 0,\n\t\t\t\t\t\t\t\t\tamount: Math.abs(amount),\n\t\t\t\t\t\t\t\t\tentityName: entityName\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tconsole.log(transactionResult);\n\t\t\t\t\t\t\t\ttransactionResult.forEach(result => {\n\t\t\t\t\t\t\t\t\ttransactions.push({\n\t\t\t\t\t\t\t\t\t\ttrId: result.transaction_id,\n\t\t\t\t\t\t\t\t\t\tdate: result.date,\n\t\t\t\t\t\t\t\t\t\tcheckNo: result.cheque_no,\n\t\t\t\t\t\t\t\t\t\tvoucherNo: result.voucher_no,\n\t\t\t\t\t\t\t\t\t\tisCredit: result.is_credit,\n\t\t\t\t\t\t\t\t\t\tamount: result.amount,\n\t\t\t\t\t\t\t\t\t\tnotes: result.notes,\n\t\t\t\t\t\t\t\t\t\treconcile: result.reconcile,\n\t\t\t\t\t\t\t\t\t\tsetId: result.set_id,\n\t\t\t\t\t\t\t\t\t\tentityName: entityName\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tlet finalResult = { rows: transactions, pages: pageNumber }\n\t\t\t\t\t\t\t\tconsole.log(finalResult);\n\t\t\t\t\t\t\t\tconnection.end();\n\t\t\t\t\t\t\t\tcallback(null, finalResult);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, connection);\n\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresults.forEach(result => {\n\t\t\t\t\t\t\ttransactions.push({\n\t\t\t\t\t\t\t\ttrId: result.transaction_id,\n\t\t\t\t\t\t\t\tdate: result.date,\n\t\t\t\t\t\t\t\tcheckNo: result.cheque_no,\n\t\t\t\t\t\t\t\tvoucherNo: result.voucher_no,\n\t\t\t\t\t\t\t\tisCredit: result.is_credit,\n\t\t\t\t\t\t\t\tamount: result.amount,\n\t\t\t\t\t\t\t\tnotes: result.notes,\n\t\t\t\t\t\t\t\treconcile: result.reconcile,\n\t\t\t\t\t\t\t\tsetId: result.set_id,\n\t\t\t\t\t\t\t\tentityName: entityName\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t\tlet finalResult = { rows: transactions, pages: pageNumber }\n\t\t\t\t\t\tconsole.log(finalResult);\n\t\t\t\t\t\tconnection.end();\n\t\t\t\t\t\tcallback(error, finalResult);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, connection);\n\t\t}\n\t});\n}","triggers":[{"resourceName":"apigusEast1slappbooksapigetMonthlyTransactionListpost","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"getMonthlyTransactionList","resourcePath":"/getMonthlyTransactionList","restMethod":"POST","proxyIntegration":false,"stageMode":0,"stageName":"Prod"}}]},"8585b721-aeb2-4a48-978d-ddfca08566d1":{"id":"8585b721-aeb2-4a48-978d-ddfca08566d1","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"delete-entity.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/delete-entity.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n/**\n * Lambda function handles entity deletion. Events are submitted through the application as entity objects \n * An RDS instance is used for entity deletion.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n\tlet entityName = event.entityName;\n\n\trds.beginTransaction({\n\t\tinstanceIdentifier: 'slappbooksdb'\n\t}, function (error, connection) {\n\t\tif (error) { throw err; }\n\t\tlet entityArray = [entityName];\n\t\trds.query({\n\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\tquery: 'DELETE t2 FROM transaction t1 INNER JOIN entity e ON t1.entity_id=e.id INNER JOIN transaction t2 ON t1.set_id=t2.set_id WHERE e.name=?',\n\t\t\tinserts: entityArray\n\t\t}, function (error, results, connection) {\n\t\t\tif (error) {\n\t\t\t\tconnection.rollback();\n\t\t\t\tconsole.log(\"Error occurred while deleting transactions from transaction table\");\n\t\t\t\tthrow error;\n\t\t\t} else {\n\t\t\t\tconsole.log(\"Successfully deleted the transactions\");\n\t\t\t\tconsole.log(results);\n\n\t\t\t\trds.query({\n\t\t\t\t\tinstanceIdentifier: 'slappbooksdb',\n\t\t\t\t\tquery: 'DELETE FROM entity WHERE name=?',\n\t\t\t\t\tinserts: entityArray\n\t\t\t\t}, function (error, results, connection) {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tconnection.rollback();\n\t\t\t\t\t\tconsole.log(\"Error occurred while deleting the entity \", entityName);\n\t\t\t\t\t\tcallback(error, JSON.stringify(event));\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconnection.commit();\n\t\t\t\t\t\tconsole.log(\"Successfully deleted the entity \", entityName);\n\t\t\t\t\t\tconnection.end();\n\t\t\t\t\t\tcallback(error, JSON.stringify(event));\n\t\t\t\t\t}\n\n\t\t\t\t}, connection);\n\t\t\t}\n\t\t}, connection);\n\n\t});\n}","triggers":[{"resourceName":"apigusEast1slappbooksapideleteEntitypost","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"deleteEntity","resourcePath":"/deleteEntity","restMethod":"POST","proxyIntegration":false,"stageMode":0,"stageName":"Prod"}}]},"3e289213-2e08-453c-a6c3-139ee447fd70":{"id":"3e289213-2e08-453c-a6c3-139ee447fd70","parent":"261bafd6-e58c-475d-9415-c1a9385d5243","name":"trial-balance.js","type":"LAMBDA_FILE","isDirectory":false,"children":[],"isRemovable":true,"filePath":"slappbooks/trial-balance.js","code":"/*\n * Copyright (c) 2018 SLAppForge Lanka (Private) Limited. All Rights Reserved.\n * https://www.slappforge.com\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License. \n */\n\nlet AWS = require('aws-sdk');\nlet connectionManager = require('./ConnectionManager');\nlet SL_AWS = require('slappforge-sdk-aws');\nconst rds = new SL_AWS.RDS(connectionManager);\n\n/**\n * Lambda function retrieves transactions in a report format. Events are submitted through the application as an identifier. \n * An RDS instance is used for transaction retrieval. The lambda function prepares a Trial Balance using the data retrieved.\n *\n * @author Malith Jayaweera\n */\nexports.handler = function (event, context, callback) {\n\n\tlet spotRate = event.spotRate;\n\tlet defaultCurrency = event.defaultCurrency;\n\tlet entries = [];\n\tlet sql = \"SELECT E.name AS name, SUM( IF(T.is_credit='1', -1*(IF(E.currency!=?, T.amount*?, T.amount)), \" +\n\t\t\"IF(E.currency!=?, T.amount*?, T.amount))) AS value FROM transaction T INNER JOIN entity E on\" +\n\t\t\" T.entity_id=E.id LEFT JOIN conversion C on T.transaction_id=C.transaction_id GROUP BY E.id;\";\n\tlet currencyArray = [defaultCurrency, spotRate, defaultCurrency, spotRate];\n\n\trds.query({\n\t\tinstanceIdentifier: 'slappbooksdb',\n\t\tquery: sql,\n\t\tinserts: currencyArray\n\t}, function (error, results, connection) {\n\t\tif (error) {\n\t\t\tconsole.log(\"Error occurred while preparing the trial balance\", error);\n\t\t\tthrow error;\n\t\t} else {\n\t\t\tconsole.log(\"Successfully prepared the trial balance\")\n\t\t\tconsole.log(results);\n\t\t\tresults.forEach(result => {\n\t\t\t\tlet entry = {\n\t\t\t\t\tname: result.name,\n\t\t\t\t\tisCredit: result.value < 0 ? true : false,\n\t\t\t\t\tvalue: Math.abs(result.value)\n\t\t\t\t}\n\t\t\t\tentries.push(entry);\n\t\t\t});\n\t\t}\n\t\tconnection.end();\n\t\tcallback(error, entries);\n\t});\n}","triggers":[{"resourceName":"apigusEast1slappbooksapigetTrialBalancepost","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"getTrialBalance","resourcePath":"/getTrialBalance","restMethod":"POST","proxyIntegration":false,"stageMode":0,"stageName":"Prod"}}]}},"rootNode":"261bafd6-e58c-475d-9415-c1a9385d5243","openFiles":["6ce22331-3d5d-4d2e-a5ff-a2f2b38257dd"],"currentFileId":"6ce22331-3d5d-4d2e-a5ff-a2f2b38257dd","resources":{"rds-slappbooksdb":{"name":"rds-slappbooksdb","type":"RDS","config":{"operation":0,"editMode":true,"rdsInstance":{"rdsEngineType":"mysql","rdsEdition":"","rdsInstanceSpec":{"dbInstanceClass":"db.t2.micro","dbLicenseModel":"general-public-license","dbEngineVersion":"5.7.19","undefined":"5.7.19"},"rdsSetting":{"instanceIdentifier":"slappbooksdb","masterUsername":"slappbooksuser","masterPassword":"12345678"},"rdsDBOptions":{"dbName":"slappbooksdb","dbPort":"3306"},"rdsInstanceArn":"","Host":"process.env.EndPoint_slappbooksdb","doesExist":false,"initializationQuery":"CREATE TABLE entity (\n\tid INT AUTO_INCREMENT,\n\tname VARCHAR(255),\n\tcurrency VARCHAR(10),\n\ttype VARCHAR(255),\n\tPRIMARY KEY (id)\n);\nCREATE TABLE transaction (\n\tid INT AUTO_INCREMENT,\n\ttransaction_id VARCHAR(255) UNIQUE,\n\tset_id VARCHAR(255),\n\tdate DATE,\n\tentity_id INT NOT NULL,\n\tcheque_no VARCHAR(50),\n\tvoucher_no VARCHAR(50),\n\tis_credit INT,\n\tamount DOUBLE,\n\tnotes VARCHAR(255),\n\treconcile INT,\n\tPRIMARY KEY (id),\n\tFOREIGN KEY (entity_id) REFERENCES entity (id) ON DELETE CASCADE\n);\n\n\n\n\nCREATE TABLE conversion (\n\tid INT AUTO_INCREMENT,\n\ttransaction_id VARCHAR(255) NOT NULL,\n\tto_currency VARCHAR(10),\n\tfrom_currency VARCHAR(10),\n\trate DOUBLE,\n\tPRIMARY KEY (id),\n\tFOREIGN KEY (transaction_id) REFERENCES transaction (transaction_id) ON DELETE CASCADE\n);\n\ninsert into entity (id, name, currency, type) values (1, \"Cash\", \"LKR\", \"ASSETS\");\ninsert into entity (id, name, currency, type) values (2, \"Bank\", \"LKR\", \"ASSETS\");\ninsert into entity (id, name, currency, type) values (3, \"Sales\", \"LKR\", \"INCOME\");"},"rdsInstanceResources":[],"mode":0,"projectRegion":"us-east-1","additionalFiles":[{"content":"module.exports = function () {\n this.dbConnections = [];\n this.dbConnections[\"slappbooksdb\"] = {\n host: process.env.EndPoint_rdsSlappbooksdb,\n port: process.env.Port_rdsSlappbooksdb,\n user: process.env.User_rdsSlappbooksdb,\n password: process.env.Password_rdsSlappbooksdb,\n database: \"slappbooksdb\"\n };\n};","filePath":"slappbooks/ConnectionManager.js","fileName":"ConnectionManager.js","showFileOnSideBar":true}],"params":{"query":"SELECT id FROM entity WHERE name = ?","inserts":"entityArray"},"isGlobalEditMode":false,"enableInject":true,"isNewFromGlobal":false},"globallyEditable":true},"apigusEast1slappbooksapigetEntityListget":{"name":"apigusEast1slappbooksapigetEntityListget","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"getEntityList","resourcePath":"/getEntityList","restMethod":"GET","proxyIntegration":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true},"apigusEast1slappbooksapigetTransactionByIdget":{"name":"apigusEast1slappbooksapigetTransactionByIdget","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"getTransactionById","resourcePath":"/getTransactionById","restMethod":"GET","proxyIntegration":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true},"apigusEast1slappbooksapiaddTransactionpost":{"name":"apigusEast1slappbooksapiaddTransactionpost","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"addTransaction","resourcePath":"/addTransaction","restMethod":"POST","enableCORS":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true},"apigusEast1slappbooksapicreateEntitypost":{"name":"apigusEast1slappbooksapicreateEntitypost","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"createEntity","resourcePath":"/createEntity","restMethod":"POST","proxyIntegration":false,"enableCORS":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true},"apigusEast1slappbooksapideleteEntitypost":{"name":"apigusEast1slappbooksapideleteEntitypost","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"deleteEntity","resourcePath":"/deleteEntity","restMethod":"POST","proxyIntegration":false,"enableCORS":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true},"apigusEast1slappbooksapideleteTransactionpost":{"name":"apigusEast1slappbooksapideleteTransactionpost","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"deleteTransaction","resourcePath":"/deleteTransaction","restMethod":"POST","proxyIntegration":false,"enableCORS":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true},"apigusEast1slappbooksapigetMonthlyTransactionListpost":{"name":"apigusEast1slappbooksapigetMonthlyTransactionListpost","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"getMonthlyTransactionList","resourcePath":"/getMonthlyTransactionList","restMethod":"POST","proxyIntegration":false,"enableCORS":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true},"apigusEast1slappbooksapicreateTransactionWithCurrencyDifferencepost":{"name":"apigusEast1slappbooksapicreateTransactionWithCurrencyDifferencepost","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"createTransactionWithCurrencyDifference","resourcePath":"/createTransactionWithCurrencyDifference","restMethod":"POST","proxyIntegration":false,"enableCORS":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true},"apigusEast1slappbooksapigetTransactionListpost":{"name":"apigusEast1slappbooksapigetTransactionListpost","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"getTransactionList","resourcePath":"/getTransactionList","restMethod":"POST","proxyIntegration":false,"enableCORS":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true},"apigusEast1slappbooksapigetTrialBalancepost":{"name":"apigusEast1slappbooksapigetTrialBalancepost","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"getTrialBalance","resourcePath":"/getTrialBalance","restMethod":"POST","proxyIntegration":false,"enableCORS":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true},"apigusEast1slappbooksapiupdateTransactionpost":{"name":"apigusEast1slappbooksapiupdateTransactionpost","type":"API_GATEWAY","config":{"selectedRegion":"us-east-1","apiMode":0,"apiName":"slappbooksapi","endpointType":"EDGE","resourceMode":0,"resourceName":"updateTransaction","resourcePath":"/updateTransaction","restMethod":"POST","proxyIntegration":false,"enableCORS":true,"stageMode":0,"stageName":"Prod"},"globallyEditable":true}},"triggers":{"apigusEast1slappbooksapiaddTransactionpost":{"6ce22331-3d5d-4d2e-a5ff-a2f2b38257dd":{}},"apigusEast1slappbooksapigetTransactionListpost":{"0cafcfb9-14f8-4cdc-861f-299678af0759":{}},"apigusEast1slappbooksapicreateEntitypost":{"10af9bcd-ac92-434b-9eb0-ca8ff233ec9b":{}},"apigusEast1slappbooksapigetTransactionByIdget":{"1f616325-bebd-4cb6-9a59-efae98b7760d":{}},"apigusEast1slappbooksapigetEntityListget":{"d5e8f837-33f8-4736-ba1b-eb1f3aface18":{}},"apigusEast1slappbooksapicreateTransactionWithCurrencyDifferencepost":{"02bc79d4-d52f-4002-b502-992569e9d409":{}},"apigusEast1slappbooksapiupdateTransactionpost":{"d5925ac9-5dfa-4cc8-9963-15dd6fb40204":{}},"apigusEast1slappbooksapideleteTransactionpost":{"0fddcfbb-9df4-458a-a743-9f28159227fc":{}},"apigusEast1slappbooksapigetMonthlyTransactionListpost":{"0b73f184-a777-475d-9741-bf94b7a4629a":{}}},"packageJSON":{"dependencies":{"aws-sdk":{"name":"aws-sdk","version":"2.176.0","notRemovable":true},"slappforge-sdk-aws":{"name":"slappforge-sdk-aws","version":"0.0.5","notRemovable":false}}},"additionalFiles":[{"content":"module.exports = function () {\n this.dbConnections = [];\n this.dbConnections[\"slappbooksdb\"] = {\n host: process.env.EndPoint_rdsSlappbooksdb,\n port: process.env.Port_rdsSlappbooksdb,\n user: process.env.User_rdsSlappbooksdb,\n password: process.env.Password_rdsSlappbooksdb,\n database: \"slappbooksdb\"\n };\n};","filePath":"slappbooks/ConnectionManager.js","fileName":"ConnectionManager.js","showFileOnSideBar":true}],"lambdaId":"6ce22331-3d5d-4d2e-a5ff-a2f2b38257dd","envVariables":[{"lambdaId":"all","varKey":"SIGMA_AWS_ACC_ID","varValue":null,"editable":false,"isEditable":false,"shouldPersist":false,"displayOnly":false}]},"PROJECT_META":{"projectName":"slappbooks","projectDescription":"slappbooks","projectVersion":"1.0.0","projectRegion":"us-east-1","lastSave":1536562346161},"VCS_STATE":{"provider":"GitHub","repo":{"name":"slappbooks","url":"https://github.com/slappforge/slappbooks"}}}