├── .gitignore ├── .vscode ├── launch.json └── settings.json ├── LICENSE ├── README.md ├── config.json ├── database-structure-incremental.sql ├── database-structure.sql ├── dist ├── database.mjs ├── definition.mjs ├── index.mjs ├── logger.mjs ├── server.mjs ├── tally.mjs └── utility.mjs ├── docs ├── commandline-options.md ├── data-structure.md ├── faq.md ├── google-bigquery.md ├── incremental-sync.md └── release-history.md ├── gui.html ├── package-lock.json ├── package.json ├── platform ├── google-bigquery │ └── database-structure.sql ├── mysql │ ├── database-structure-incremental.sql │ └── database-structure.sql ├── postgresql │ ├── database-structure-incremental.sql │ └── database-structure.sql └── powershell │ ├── list-open-companies.ps1 │ └── sync-multiple-company.ps1 ├── reports ├── bigquery │ ├── account-ledger.sql │ ├── accounting-voucher-view.sql │ ├── bill-payable.sql │ ├── bills-receivable.sql │ ├── daily-cash-movement.sql │ ├── profit-loss.sql │ ├── purchase-daily.sql │ ├── purchase-monthly.sql │ ├── purchase-register.sql │ ├── sales-daily.sql │ ├── sales-monthly.sql │ ├── sales-register.sql │ ├── stock-voucher-view.sql │ └── trial-balance.sql └── mssql │ ├── account-ledger.sql │ ├── accounting-voucher-view.sql │ ├── bills-payable.sql │ ├── bills-receivable.sql │ ├── daily-cash-movement.sql │ ├── group-tree-children-parent.sql │ ├── group-tree-parent-child.sql │ ├── profit-loss.sql │ ├── purchase-daily.sql │ ├── purchase-monthly.sql │ ├── purchase-register.sql │ ├── sales-daily.sql │ ├── sales-monthly.sql │ ├── sales-register.sql │ ├── stock-summary.sql │ ├── stock-voucher-view.sql │ └── trial-balance.sql ├── run-gui.bat ├── run.bat ├── src ├── database.mts ├── definition.mts ├── index.mts ├── logger.mts ├── server.mts ├── tally.mts ├── tsconfig.json └── utility.mts ├── tally-export-config-incremental.yaml └── tally-export-config.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | private/ 3 | csv/ 4 | ssl/ 5 | sync/ 6 | dist/*.mjs.map 7 | import-log.txt 8 | error-log.txt 9 | *.zip 10 | *.exe 11 | bigquery-credentials.json 12 | adls-config.json -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "skipFiles": [ 12 | "/**" 13 | ], 14 | "preLaunchTask": "tsc: build - src/tsconfig.json", 15 | "cwd": "${workspaceFolder}", 16 | "program": "${cwd}\\dist\\index.mjs", 17 | "args": [] 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "dist/*.mjs.map": true 4 | } 5 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Dhananjay Gokhale 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tally to Database Server: Data Loader Utility 2 | ![logo](https://excelkida.com/image/github/tally-database-loader.png) 3 | 4 | 5 | 6 | 7 | Commandline utility to load data into Database Server from Tally software, intended for further use by 8 | * MS Excel / Google Sheet (for tabular reports) 9 | * Power BI / Tableau / Google Data Studio (for dashboards) 10 | 11 | ## Index 12 | * [Version](version) 13 | * [Download](#download) 14 | * [Requirements](#requirements) 15 | * [Graphical User Interface](#graphical-user-interface) 16 | * [Tally XML Server](#tally-xml-server) 17 | * [Database Creation](#database-creation) 18 | * [Utility Installation](#utility-installation) 19 | * [Configuration Setup](#configuration-setup) 20 | * Database Connection 21 | * Tally Options 22 | * [Steps](#steps) 23 | * [Tutorial](#tutorial) 24 | * [Understanding Database Structure](docs/data-structure.md) 25 | * [Incremental / Full Sync](docs/incremental-sync.md) 26 | * [Tally Export Config](#tally-export-config) 27 | * [Commandline Options](docs/commandline-options.md) 28 | * [Logs](#logs) 29 | * [Reports](#reports) 30 | * [Google BigQuery](docs/google-bigquery.md) 31 | * [Develop Further](#develop-further) 32 | * [License](#license) 33 | * [Contact](#contact) 34 | * [Credits](#credits) 35 | * [Known Issues](#known-issues) 36 | * [Frequently Asked Questions](docs/faq.md) 37 | * [Release History](docs/release-history.md) 38 | 39 |

40 | 41 | ## Version 42 | Latest Version: **1.0.36**
43 | Updated on: **26-Mar-2025** 44 | 45 | Note: 46 | 1. I keep on fixing utility and adding fields into database. So you are requested to re-create existing databases and re-download utility folder 47 | 2. Incremental sync now works for SQL Server / MySQL / PostgreSQL. Going forward two separate version of **database-structure** and **tally-export-config** will be maintained. Files with suffix **incremental** are to be used for **incremental** sync & other are for **full** sync. 48 | 3. Structure of config.json file is changed. Ensure to download fresh version of utility 49 | 50 | 51 |

52 | 53 | ## Download 54 | 55 | Database Loader Utility is portable, and does not have a setup wizard like we find for software installation. Zip archive of utility can be downloaded from below link. Kindly use open-source & free software [7-zip file archiver](https://www.7-zip.org/download.html) to un-compress utility archive. 56 | 57 | [Download Database Loader Utility](https://excelkida.com/resource/tally-database-loader-utility-1.0.36.7z) 58 | 59 | Also, it is a command-line utility having no window interface (to keep it minimal and faster) 60 | 61 |

62 | 63 | ## Requirements 64 | Utility requires installation of following as a pre-requisite (along with download link) 65 | * Windows 10 66 | * [Tally Prime](https://tallysolutions.com/download/) 67 | * [Node JS](https://nodejs.org/en/) 68 | * Database Server (supports any of below) 69 | * [Microsoft SQL Server](https://www.microsoft.com/en-ie/sql-server/sql-server-downloads/) 70 | * [PostgreSQL](https://www.postgresql.org/download/) 71 | * [MySQL](https://dev.mysql.com/downloads/mysql/) 72 | * [MariaDB](https://mariadb.org/download/) 73 | * [Google BigQuery](https://cloud.google.com/bigquery/) 74 | 75 | Free version of all the above Database Servers are available for download. Also all of them are available on popular cloud like Microsoft Azure / Google Cloud Platform / Amazon Web Services 76 | 77 | Preferred versions: 78 | * SQL Server - version 2019 79 | * MySQL - version 8.x 80 | * PostgreSQL - 11.x or above 81 | 82 | **Note:** *Utility and SQL Queries for reports are deviced considering latest version of the above Database Server. Running it in lower version might hamper few of the functionalities, as some SQL syntax were introduced in latest version* 83 | 84 |

85 | 86 | ## Graphical User Interface 87 | Utility is available in 2 types of interfaces 88 | 1. Command-line based which can be invoked using **run.bat** file 89 | 1. Browser-based interface which can be invoked using **run-gui.bat** file 90 | 91 | Both use the same back-end. File **run-gui.bat** uses browser-based interface which offers following features: 92 | * Ease of editing config.json values (without requiring Notepad) 93 | * Automatic default value setting based on dropdown to minimize invalid configuration values 94 | * Option to send configuration to utility without requiring it to save (suggested when user do no wish to save & reveal password in config.json file) 95 | 96 | **Note:** *Please do not close the command-line window which acts as temporary webserver to interact with browser. Close it only after you close the browser tab of the utility.* 97 | 98 |

99 | 100 | ## Tally XML Server 101 | Tally has in-built XML Server capability, which can import/export data in/out of Tally. This utility sends export command to Tally along with report specification written in TDL (Tally Developer Language) in XML format. In response, Tally returns back the requested data (in XML format), which is then imported into Database Server. 102 | 103 | * Help (F1) > Settings > Connectivity 104 | * Client/Server configuration 105 | * Set TallyPrime is acting as **Both** 106 | 107 |
108 | 109 | **Note: Support for Tally.ERP 9 has been removed, to keep database aligned to Tally Prime. Kindly upgrade to Tally Prime.** 110 | 111 |

112 | 113 | 114 | 115 | ## Database Creation 116 | Database first needs to be created and then Tables needs to be created in which data from Tally will be loaded, before running utility. File **database-structure.sql** contains SQL for creating tables of database. Just ensure to create database using any of GUI Database Manager. That database name should be updated in **schema** property of *config.json*. Open-source database editor available freely are 117 | * [SQL Server Management Studio (SQL Server)](https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms) 118 | * [Azure Data Studio (SQL Server)](https://docs.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio) 119 | * [pgAdmin (PostgreSQL Server)](https://www.pgadmin.org/download/) 120 | * [MySQL Workbench (MySQL Server)](https://dev.mysql.com/downloads/workbench/) 121 | * [Heidi SQL (SQL Server / MySQL / MariaDB / PostgreSQL)](https://www.heidisql.com/download.php/) 122 | 123 | Note: Database structure creation SQL script for PostgreSQL is avilable inside **platform/postgresql** folder of project. In future, database technology-wise separate SQL Script will be available for individual technologies. 124 | 125 | Utility support import into database server installed and hosted on 126 | * Same PC where Tally is 127 | * On any machine on LAN 128 | * Virtual Private Server 129 | * Cloud Database [ Microsoft Azure / Amazon Web Services (AWS) / Google Cloud Platform / Oracle Cloud ] 130 | 131 |

132 | 133 | ## Configuration Setup 134 | Utility contains a file **config.json** containing database connection and tally related settings. 135 | 136 |
137 | 138 | ### Database Connection 139 | Database Connection credentials needs to be set in the file in **database** section of *config.json*. A sample configuration file 140 | 141 | **SQL Server** 142 | ```json 143 | "database": { 144 | "technology": "mssql", 145 | "server": "localhost", 146 | "port": 1433, 147 | "ssl": false, 148 | "schema": "", 149 | "username": "sa", 150 | "password": "", 151 | "loadmethod": "insert" 152 | } 153 | ``` 154 |
155 | 156 | **MySQL / MariaDB Server** 157 | ```json 158 | "database": { 159 | "technology": "mysql", 160 | "server": "localhost", 161 | "port": 3306, 162 | "ssl": false, 163 | "schema": "", 164 | "username": "root", 165 | "password": "", 166 | "loadmethod": "insert" 167 | } 168 | ``` 169 | 170 | **PostgreSQL Server** 171 | ```json 172 | "database": { 173 | "technology": "postgres", 174 | "server": "localhost", 175 | "port": 5432, 176 | "ssl": false, 177 | "schema": "", 178 | "username": "postgres", 179 | "password": "", 180 | "loadmethod": "insert" 181 | } 182 | ``` 183 | 184 |
185 | 186 | | Settings | Value | 187 | | --- | --- | 188 | | technology | **mssql**: Microsoft SQL Server
**mysql**: MySQL Server or MariaDB Server
**postgres**: PostgreSQL Server
**bigquery**: Google BigQuery
**adls**:Azure Data Lake storage
**json**: JSON file
**csv**: Generate CSV dump for further import (below parameters of database connection are dummy when CSV setting is applied) | 189 | | server | IP Address of PC on which Database Server is hosted (**localhost** = same machine) | 190 | | port | Port number on which Database Server is listening
**mssql**: Default port is **1433**
**mysql**: Default port is **3306**
**postgres**: Default port is **5432** | 191 | | ssl | **true**: Secured (to be used only if Database Server is on Cloud)
**false**: Unsecured [*default*] (to be used when Database Server is on same machine / within LAN / within VPN)
Supported for mssql / postgres only | 192 | | schema | Database name in which to insert data | 193 | | username | Username
**mssql**: Default user is **sa**
**mysql**: Default user is **root**
**postgres**: Default user is **postgres** | 194 | | password | Password for corresponding user. It is set during installation of Database Server.
*Note: Trusted Login (password-less) of SQL Server not supported by this utility* | 195 | | loadmethod | **insert**: loads rows in database tables using SQL query with multiple rows. This is most compatible method which works everywhere (Compatibility: **High** / Performance: **Slow** )
**file**: loads rows in database table using file based loading method. This method works only when database server and utility is running on same machine. So this method is not compatible with Cloud databases (Compatibility: **Low** / Performance: **Fast** ) | 196 | 197 | Kindly override configurations, as per respective Database Server setup 198 | 199 | **Note**: *Utility supports SQL Server connection via TCP/IP port only. This option is disabled by default, which needs to be enabled. Kindly refer FAQ where it has been elaborated in detail along with screenshots* 200 | (applicable for Microsoft SQL Server only) 201 | 202 |
203 | 204 | ### Tally Options 205 | Few of the options of Tally may need modification, if default settings of Tally are specifically over-ridden (due to port clashes). A sample configuration of tally is demonstrated as below 206 | 207 | ## Full sync 208 | 209 | ```json 210 | "tally": { 211 | "definition": "tally-export-config.yaml", 212 | "server": "localhost", 213 | "port": 9000, 214 | "fromdate" : "20230401", 215 | "todate" : "20240331", 216 | "sync": "full", 217 | "frequency": 0, 218 | "company": "" 219 | } 220 | ``` 221 | 222 | ## Incremental sync 223 | 224 | ```json 225 | "tally": { 226 | "definition": "tally-export-config-incremental.yaml", 227 | "server": "localhost", 228 | "port": 9000, 229 | "fromdate" : "auto", 230 | "todate" : "auto", 231 | "sync": "incremental", 232 | "frequency": 5, 233 | "company": "" 234 | } 235 | ``` 236 | 237 | | Setting | Value | 238 | | --- | --- | 239 | | definition | Name of export config file in the utility folder. This setting is to be used for easy switching between incremental and full sync, as both the files contains different structure | 240 | | server | IP Address or Computer Name on which Tally XML Server is running (**localhost** is default value equivalent of IP Address 127.0.0.1). Change this if you need to capture data from a Tally running on different PC on your LAN | 241 | | port | By default Tally runs XML Server on port number **9000**. Modify this if you have assigned different port number in Tally XML Server settings (typically done when you want run Tally.ERP 9 and Tally Prime both at a same time parallely, where you will be changing this port number) | 242 | | master / transaction | **true** = Export master/transaction data from Tally (*default*)
**false** = Skip master/transaction data | 243 | | fromdate / todate | **YYYYMMDD** = Period from/to for export of transaction and opening balance (in 8 digit format)
**auto** = This will export complete transactions (irrespective of selected Financial Year) from Tally by auto-detection of First & Last date of transaction | 244 | | sync | **full** = Sync complete data from Tally to Database Server (*default*)
**incremental** = Sync only that data which was added/modified/delete from last sync | 245 | | frequency | ping frequency in minutes to Tally to monitor changes in data and trigger sync (0 = off i.e. just run sync once and close it) | 246 | | company | Name of the company from which to export data or leave it blank to export from Active company of Tally (this parameter is intended for use when user needs to export data from specific company irrespective of it is active or not. Setup a powershell script to run a loop when multiple companies needs to be targeted one-by-one) | 247 | 248 |

249 | 250 | ## Steps 251 | 1. Create database in Database Server along with tables inside it (use **database-structure.sql** to create tables) [ignore if already created] 252 | 1. Ensure options are properly set in **config.json** 253 | 1. Ensure Tally is running and target company from which to export data is Active 254 | 1. Run the file **run.bat** 255 | 1. Commandline window will open, attempt to import data and will get closed after import/error 256 | 1. Check for import status in **import-log.txt** file and errors (if any) in **error-log.txt** file 257 | 258 |

259 | 260 | ## Tutorial 261 | 262 | YouTube tutorial video are availabe (link below) 263 | 264 | **SQL Server** 265 |
266 | 267 | [![YouTube tutorial SQL Server](https://img.youtube.com/vi/Am0uspXtTzM/0.jpg)](https://www.youtube.com/watch?v=Am0uspXtTzM) 268 | 269 |
270 | 271 | **MySQL Server** 272 |
273 | 274 | [![YouTube tutorial MySQL Server](https://img.youtube.com/vi/_bXc54bKTlI/0.jpg)](https://www.youtube.com/watch?v=_bXc54bKTlI) 275 | 276 |

277 | 278 | ## Tally Export Config 279 | Certain times we may require to add or remove any of the fields from export (to add user defined fields created by TDL Developer in Tally customisations). So this export specification is defined in **tally-export-config.yaml** file in YAML format. This file is divided into Master and Transaction, containing multiple tables in it. To understand structure and nomenclature, an example of this is given below 280 | 281 | ```yaml 282 | master: 283 | - name: mst_group 284 | collection: Group 285 | fields: 286 | - name: guid 287 | field: Guid 288 | type: text 289 | ``` 290 | 291 | name: mst_group (**Database Table name**)
292 | collection: Group (**Tally Collection name**)
293 | name: guid (**Database Column name**)
294 | field: Guid (**Tally field name**)
295 | type: **text / logical / date / number / amount / quantity / rate / custom** 296 | 297 | **amount:** Credit = positive / Debit = negative
298 | **quantity:** In Quantity = positive / Out Quantity = negative
299 | **rate:** Rate type of data (is always positive)
300 | **custom:** Any custom expression in TDL format 301 | 302 | 303 |

304 | 305 | ## Logs 306 | Utility creates log of import specifying how many rows in each tables were loaded. This log can be found in **import-log.txt** file. If any error occurs, then details of error(s) are logged in **error-log.txt** file 307 | 308 |

309 | 310 | ## Reports 311 | Project hosts library of SQL Queries to generate some popularly used reports, required for preparing Dashboards in Microsoft Power BI and Google Data Studio. Due to minor difference in SQL syntax & functions of SQL Server and MySQL, SQL for same report is provided for both of these Server platforms. 312 | 313 | Author actively supports **Google BigQuery** (fully cloud-based solution of Google), and even shared equivalent SQL query for BiQuery. BigQuery acts as a input for Google Data Studio Dashboards and also supports easy export of tabular output to Google Sheets. Interested users can sign-up for a free [Google Cloud account](https://cloud.google.com) and use BigQuery with free daily limits 314 | 315 |

316 | 317 | 318 | ## Develop Further 319 | If you intend to develop and modify this utility further to next level for your use-case, then you can clone this project from Git and run the project as below 320 | 1. Clone the project repository 321 | 1. Install Visual Studio and open the project repository folder 322 | 1. Install required npm packages by following command **npm install** 323 | 1. Install global instance of typescript compiler available on Node Package Manager by following command **npm install typescript -g** 324 | 1. Run the project in Visual Studio code (**launch.json** file already provided in **.vscode** folder to run it with required settings) 325 | 326 |

327 | 328 | ## License 329 | This project is under MIT license. You are free to use this utility for commercial & educational purpose. 330 | 331 |

332 | 333 | ## Contact 334 | Project developed & maintained by: **Dhananjay Gokhale** 335 | 336 | For any query email to **info@excelkida.com** or Whatsapp on **(+91) 90284-63366** 337 | 338 |

339 | 340 | ## Credits 341 | Bug fixes or enhancements from various contributors 342 | 343 | * [CA Venugopal Gella](https://github.com/gellavenugopal) - Fixing of Tally Prime 2.0.1 export issue 344 | 345 | ## Known Issues 346 | * When multiple companies are selected in Tally & specific company name is specified in config.json, it has been observed that in a rare case (especially on Windows Server), Tally fails to fetch data from that target company & internally produces an error that specified company is not loaded. 347 | * It has been observed that sometimes when Tally remain running for several days on PC then in a rare case Tally fails to return back updated / latest data (especially on Windows Server) & you may have to restart Tally. 348 | * If you have configured automatic sync of data via Windows Task Schedular, then make sure you don't log-off, but just disconnect as Tally is graphical based software. 349 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "database": { 3 | "technology": "mssql", 4 | "server": "localhost", 5 | "port": 0, 6 | "ssl": false, 7 | "schema": "tallydb", 8 | "username": "sa", 9 | "password": "admin", 10 | "loadmethod": "file" 11 | }, 12 | "tally": { 13 | "definition": "tally-export-config.yaml", 14 | "server": "localhost", 15 | "port": 9000, 16 | "fromdate": "2024-04-01", 17 | "todate": "2025-03-31", 18 | "sync": "full", 19 | "frequency": 0, 20 | "company": "" 21 | } 22 | } -------------------------------------------------------------------------------- /database-structure-incremental.sql: -------------------------------------------------------------------------------- 1 | create table _diff 2 | ( 3 | guid varchar(64) not null, 4 | alterid int not null 5 | ); 6 | 7 | create table _delete 8 | ( 9 | guid varchar(64) not null 10 | ); 11 | 12 | create table _vchnumber 13 | ( 14 | guid varchar(64) not null, 15 | voucher_number varchar(256) not null 16 | ); 17 | 18 | create table config 19 | ( 20 | name nvarchar(64) not null primary key, 21 | value nvarchar(1024) 22 | ); 23 | 24 | create table mst_group 25 | ( 26 | guid varchar(64) not null primary key, 27 | alterid int not null default 0, 28 | name nvarchar(1024) not null default '', 29 | parent nvarchar(1024) not null default '', 30 | _parent varchar(64) not null default '', 31 | primary_group nvarchar(1024) not null default '', 32 | is_revenue tinyint, 33 | is_deemedpositive tinyint, 34 | is_reserved tinyint, 35 | affects_gross_profit tinyint, 36 | sort_position int 37 | ); 38 | 39 | create table mst_ledger 40 | ( 41 | guid varchar(64) not null primary key, 42 | alterid int not null default 0, 43 | name nvarchar(1024) not null default '', 44 | parent nvarchar(1024) not null default '', 45 | _parent varchar(64) not null default '', 46 | alias nvarchar(256) not null default '', 47 | description nvarchar(64) not null default '', 48 | notes nvarchar(64) not null default '', 49 | is_revenue tinyint, 50 | is_deemedpositive tinyint, 51 | opening_balance decimal(17,2) default 0, 52 | closing_balance decimal(17,2) default 0, 53 | mailing_name nvarchar(256) not null default '', 54 | mailing_address nvarchar(1024) not null default '', 55 | mailing_state nvarchar(256) not null default '', 56 | mailing_country nvarchar(256) not null default '', 57 | mailing_pincode nvarchar(64) not null default '', 58 | email nvarchar(256) not null default '', 59 | it_pan nvarchar(64) not null default '', 60 | gstn nvarchar(64) not null default '', 61 | gst_registration_type nvarchar(64) not null default '', 62 | gst_supply_type nvarchar(64) not null default '', 63 | gst_duty_head nvarchar(16) not null default '', 64 | tax_rate decimal(9,4) default 0, 65 | bank_account_holder nvarchar(256) not null default '', 66 | bank_account_number nvarchar(64) not null default '', 67 | bank_ifsc nvarchar(64) not null default '', 68 | bank_swift nvarchar(64) not null default '', 69 | bank_name nvarchar(64) not null default '', 70 | bank_branch nvarchar(64) not null default '', 71 | bill_credit_period int not null default 0 72 | ); 73 | 74 | create table mst_vouchertype 75 | ( 76 | guid varchar(64) not null primary key, 77 | alterid int not null default 0, 78 | name nvarchar(1024) not null default '', 79 | parent nvarchar(1024) not null default '', 80 | _parent varchar(64) not null default '', 81 | numbering_method nvarchar(64) not null default '', 82 | is_deemedpositive tinyint, 83 | affects_stock tinyint 84 | ); 85 | 86 | create table mst_uom 87 | ( 88 | guid varchar(64) not null primary key, 89 | alterid int not null default 0, 90 | name nvarchar(1024) not null default '', 91 | formalname nvarchar(256) not null default '', 92 | is_simple_unit tinyint not null, 93 | base_units nvarchar(1024) not null, 94 | additional_units nvarchar(1024) not null, 95 | conversion int not null 96 | ); 97 | 98 | create table mst_godown 99 | ( 100 | guid varchar(64) not null primary key, 101 | alterid int not null default 0, 102 | name nvarchar(1024) not null default '', 103 | parent nvarchar(1024) not null default '', 104 | _parent varchar(64) not null default '', 105 | address nvarchar(1024) not null default '' 106 | ); 107 | 108 | create table mst_stock_group 109 | ( 110 | guid varchar(64) not null primary key, 111 | alterid int not null default 0, 112 | name nvarchar(1024) not null default '', 113 | parent nvarchar(1024) not null default '', 114 | _parent varchar(64) not null default '' 115 | ); 116 | 117 | create table mst_stock_item 118 | ( 119 | guid varchar(64) not null primary key, 120 | alterid int not null default 0, 121 | name nvarchar(1024) not null default '', 122 | parent nvarchar(1024) not null default '', 123 | _parent varchar(64) not null default '', 124 | alias nvarchar(256) not null default '', 125 | description nvarchar(64) not null default '', 126 | notes nvarchar(64) not null default '', 127 | part_number nvarchar(256) not null default '', 128 | uom nvarchar(32) not null default '', 129 | _uom varchar(64) not null default '', 130 | alternate_uom nvarchar(32) not null default '', 131 | _alternate_uom varchar(64) not null default '', 132 | conversion int not null default 0, 133 | opening_balance decimal(15,4) default 0, 134 | opening_rate decimal(15,4) default 0, 135 | opening_value decimal(17,2) default 0, 136 | closing_balance decimal(15,4) default 0, 137 | closing_rate decimal(15,4) default 0, 138 | closing_value decimal(17,2) default 0, 139 | costing_method nvarchar(32) not null default '', 140 | gst_type_of_supply nvarchar(32) default '', 141 | gst_hsn_code nvarchar(64) default '', 142 | gst_hsn_description nvarchar(256) default '', 143 | gst_rate decimal(9,4) default 0, 144 | gst_taxability nvarchar(32) default '' 145 | ); 146 | 147 | create table mst_cost_category 148 | ( 149 | guid varchar(64) not null primary key, 150 | alterid int not null default 0, 151 | name nvarchar(1024) not null default '', 152 | allocate_revenue tinyint, 153 | allocate_non_revenue tinyint 154 | ); 155 | 156 | create table mst_cost_centre 157 | ( 158 | guid varchar(64) not null primary key, 159 | alterid int not null default 0, 160 | name nvarchar(1024) not null default '', 161 | parent nvarchar(1024) not null default '', 162 | _parent varchar(64) not null default '', 163 | category nvarchar(1024) not null default '' 164 | ); 165 | 166 | create table mst_attendance_type 167 | ( 168 | guid varchar(64) not null primary key, 169 | alterid int not null default 0, 170 | name nvarchar(1024) not null default '', 171 | parent nvarchar(1024) not null default '', 172 | _parent varchar(64) not null default '', 173 | uom nvarchar(32) not null default '', 174 | _uom varchar(64) not null default '', 175 | attendance_type nvarchar(64) not null default '', 176 | attendance_period nvarchar(64) not null default '' 177 | ); 178 | 179 | create table mst_employee 180 | ( 181 | guid varchar(64) not null primary key, 182 | alterid int not null default 0, 183 | name nvarchar(1024) not null default '', 184 | parent nvarchar(1024) not null default '', 185 | _parent varchar(64) not null default '', 186 | id_number nvarchar(256) not null default '', 187 | date_of_joining date, 188 | date_of_release date, 189 | designation nvarchar(64) not null default '', 190 | function_role nvarchar(64) not null default '', 191 | location nvarchar(256) not null default '', 192 | gender nvarchar(32) not null default '', 193 | date_of_birth date, 194 | blood_group nvarchar(32) not null default '', 195 | father_mother_name nvarchar(256) not null default '', 196 | spouse_name nvarchar(256) not null default '', 197 | address nvarchar(256) not null default '', 198 | mobile nvarchar(32) not null default '', 199 | email nvarchar(64) not null default '', 200 | pan nvarchar(32) not null default '', 201 | aadhar nvarchar(32) not null default '', 202 | uan nvarchar(32) not null default '', 203 | pf_number nvarchar(32) not null default '', 204 | pf_joining_date date, 205 | pf_relieving_date date, 206 | pr_account_number nvarchar(32) not null default '' 207 | ); 208 | 209 | create table mst_payhead 210 | ( 211 | guid varchar(64) not null primary key, 212 | alterid int not null default 0, 213 | name nvarchar(1024) not null default '', 214 | parent nvarchar(1024) not null default '', 215 | _parent varchar(64) not null default '', 216 | payslip_name nvarchar(1024) not null default '', 217 | pay_type nvarchar(64) not null default '', 218 | income_type nvarchar(64) not null default '', 219 | calculation_type nvarchar(32) not null default '', 220 | leave_type nvarchar(64) not null default '', 221 | calculation_period nvarchar(32) not null default '' 222 | ); 223 | 224 | create table mst_gst_effective_rate 225 | ( 226 | item nvarchar(1024) not null default '', 227 | _item varchar(64) not null default '', 228 | applicable_from date, 229 | hsn_description nvarchar(256) not null default '', 230 | hsn_code nvarchar(64) not null default '', 231 | rate decimal(9,4) default 0, 232 | is_rcm_applicable tinyint, 233 | nature_of_transaction nvarchar(64) not null default '', 234 | nature_of_goods nvarchar(64) not null default '', 235 | supply_type nvarchar(64) not null default '', 236 | taxability nvarchar(64) not null default '' 237 | ); 238 | 239 | create table mst_opening_batch_allocation 240 | ( 241 | name nvarchar(1024) not null default '', 242 | item nvarchar(1024) not null default '', 243 | _item varchar(64) not null default '', 244 | opening_balance decimal(15,4) default 0, 245 | opening_rate decimal(15,4) default 0, 246 | opening_value decimal(17,2) default 0, 247 | godown nvarchar(1024) not null default '', 248 | _godown varchar(64) not null default '', 249 | manufactured_on date 250 | ); 251 | 252 | create table mst_opening_bill_allocation 253 | ( 254 | ledger nvarchar(1024) not null default '', 255 | _ledger varchar(64) not null default '', 256 | opening_balance decimal(17,4) default 0, 257 | bill_date date, 258 | name nvarchar(1024) not null default '', 259 | bill_credit_period int not null default 0, 260 | is_advance tinyint 261 | ); 262 | 263 | create table trn_closingstock_ledger 264 | ( 265 | ledger nvarchar(1024) not null default '', 266 | _ledger varchar(64) not null default '', 267 | stock_date date, 268 | stock_value decimal(17,2) not null default 0 269 | ); 270 | 271 | create table mst_stockitem_standard_cost 272 | ( 273 | item nvarchar(1024) not null default '', 274 | _item varchar(64) not null default '', 275 | date date, 276 | rate decimal(15,4) default 0 277 | ); 278 | 279 | create table mst_stockitem_standard_price 280 | ( 281 | item nvarchar(1024) not null default '', 282 | _item varchar(64) not null default '', 283 | date date, 284 | rate decimal(15,4) default 0 285 | ); 286 | 287 | create table trn_voucher 288 | ( 289 | guid varchar(64) not null primary key, 290 | alterid int not null default 0, 291 | date date not null, 292 | voucher_type nvarchar(1024) not null, 293 | _voucher_type varchar(64) not null default '', 294 | voucher_number nvarchar(64) not null default '', 295 | reference_number nvarchar(64) not null default '', 296 | reference_date date, 297 | narration nvarchar(4000) not null default '', 298 | party_name nvarchar(256) not null, 299 | _party_name varchar(64) not null default '', 300 | place_of_supply nvarchar(256) not null, 301 | is_invoice tinyint, 302 | is_accounting_voucher tinyint, 303 | is_inventory_voucher tinyint, 304 | is_order_voucher tinyint 305 | ); 306 | 307 | create table trn_accounting 308 | ( 309 | guid varchar(64) not null default '', 310 | ledger nvarchar(1024) not null default '', 311 | _ledger varchar(64) not null default '', 312 | amount decimal(17,2) not null default 0, 313 | amount_forex decimal(17,2) not null default 0, 314 | currency nvarchar(16) not null default '' 315 | ); 316 | 317 | create table trn_inventory 318 | ( 319 | guid varchar(64) not null default '', 320 | item nvarchar(1024) not null default '', 321 | _item varchar(64) not null default '', 322 | quantity decimal(15,4) not null default 0, 323 | rate decimal(15,4) not null default 0, 324 | amount decimal(17,2) not null default 0, 325 | additional_amount decimal(17,2) not null default 0, 326 | discount_amount decimal(17,2) not null default 0, 327 | godown nvarchar(1024), 328 | _godown varchar(64) not null default '', 329 | tracking_number nvarchar(256), 330 | order_number nvarchar(256), 331 | order_duedate date 332 | ); 333 | 334 | create table trn_cost_centre 335 | ( 336 | guid varchar(64) not null default '', 337 | ledger nvarchar(1024) not null default '', 338 | _ledger varchar(64) not null default '', 339 | costcentre nvarchar(1024) not null default '', 340 | _costcentre varchar(64) not null default '', 341 | amount decimal(17,2) not null default 0 342 | ); 343 | 344 | create table trn_cost_category_centre 345 | ( 346 | guid varchar(64) not null default '', 347 | ledger nvarchar(1024) not null default '', 348 | _ledger varchar(64) not null default '', 349 | costcategory nvarchar(1024) not null default '', 350 | _costcategory varchar(64) not null default '', 351 | costcentre nvarchar(1024) not null default '', 352 | _costcentre varchar(64) not null default '', 353 | amount decimal(17,2) not null default 0 354 | ); 355 | 356 | create table trn_cost_inventory_category_centre 357 | ( 358 | guid varchar(64) not null default '', 359 | ledger nvarchar(1024) not null default '', 360 | _ledger varchar(64) not null default '', 361 | item nvarchar(1024) not null default '', 362 | _item varchar(64) not null default '', 363 | costcategory nvarchar(1024) not null default '', 364 | _costcategory varchar(64) not null default '', 365 | costcentre nvarchar(1024) not null default '', 366 | _costcentre varchar(64) not null default '', 367 | amount decimal(17,2) not null default 0 368 | ); 369 | 370 | create table trn_bill 371 | ( 372 | guid varchar(64) not null default '', 373 | ledger nvarchar(1024) not null default '', 374 | _ledger varchar(64) not null default '', 375 | name nvarchar(1024) not null default '', 376 | amount decimal(17,2) not null default 0, 377 | billtype nvarchar(256) not null default '', 378 | bill_credit_period int not null default 0 379 | ); 380 | 381 | create table trn_bank 382 | ( 383 | guid varchar(64) not null default '', 384 | ledger nvarchar(1024) not null default '', 385 | _ledger varchar(64) not null default '', 386 | transaction_type nvarchar(32) not null default '', 387 | instrument_date date, 388 | instrument_number nvarchar(1024) not null default '', 389 | bank_name nvarchar(64) not null default '', 390 | amount decimal(17,2) not null default 0, 391 | bankers_date date 392 | ); 393 | 394 | create table trn_batch 395 | ( 396 | guid varchar(64) not null default '', 397 | item nvarchar(1024) not null default '', 398 | _item varchar(64) not null default '', 399 | name nvarchar(1024) not null default '', 400 | quantity decimal(15,4) not null default 0, 401 | amount decimal(17,2) not null default 0, 402 | godown nvarchar(1024), 403 | _godown varchar(64) not null default '', 404 | destination_godown nvarchar(1024), 405 | _destination_godown varchar(64) not null default '', 406 | tracking_number nvarchar(1024) 407 | ); 408 | 409 | create table trn_inventory_accounting 410 | ( 411 | guid varchar(64) not null default '', 412 | ledger nvarchar(1024) not null default '', 413 | _ledger varchar(64) not null default '', 414 | amount decimal(17,2) not null default 0, 415 | additional_allocation_type nvarchar(32) not null default '' 416 | ); 417 | 418 | create table trn_employee 419 | ( 420 | guid varchar(64) not null default '', 421 | category nvarchar(1024) not null default '', 422 | _category varchar(64) not null default '', 423 | employee_name nvarchar(1024) not null default '', 424 | _employee_name varchar(64) not null default '', 425 | amount decimal(17,2) not null default 0, 426 | employee_sort_order int not null default 0 427 | ); 428 | 429 | create table trn_payhead 430 | ( 431 | guid varchar(64) not null default '', 432 | category nvarchar(1024) not null default '', 433 | _category varchar(64) not null default '', 434 | employee_name nvarchar(1024) not null default '', 435 | _employee_name varchar(64) not null default '', 436 | employee_sort_order int not null default 0, 437 | payhead_name nvarchar(1024) not null default '', 438 | _payhead_name varchar(64) not null default '', 439 | payhead_sort_order int not null default 0, 440 | amount decimal(17,2) not null default 0 441 | ); 442 | 443 | create table trn_attendance 444 | ( 445 | guid varchar(64) not null default '', 446 | employee_name nvarchar(1024) not null default '', 447 | _employee_name varchar(64) not null default '', 448 | attendancetype_name nvarchar(1024) not null default '', 449 | _attendancetype_name varchar(64) not null default '', 450 | time_value decimal(17,2) not null default 0, 451 | type_value decimal(17,2) not null default 0 452 | ); -------------------------------------------------------------------------------- /database-structure.sql: -------------------------------------------------------------------------------- 1 | create table config 2 | ( 3 | name nvarchar(64) not null primary key, 4 | value nvarchar(1024) 5 | ); 6 | 7 | create table mst_group 8 | ( 9 | guid varchar(64) not null primary key, 10 | name nvarchar(1024) not null default '', 11 | parent nvarchar(1024) not null default '', 12 | primary_group nvarchar(1024) not null default '', 13 | is_revenue tinyint, 14 | is_deemedpositive tinyint, 15 | is_reserved tinyint, 16 | affects_gross_profit tinyint, 17 | sort_position int 18 | ); 19 | 20 | create table mst_ledger 21 | ( 22 | guid varchar(64) not null primary key, 23 | name nvarchar(1024) not null default '', 24 | parent nvarchar(1024) not null default '', 25 | alias nvarchar(256) not null default '', 26 | description nvarchar(64) not null default '', 27 | notes nvarchar(64) not null default '', 28 | is_revenue tinyint, 29 | is_deemedpositive tinyint, 30 | opening_balance decimal(17,2) default 0, 31 | closing_balance decimal(17,2) default 0, 32 | mailing_name nvarchar(256) not null default '', 33 | mailing_address nvarchar(1024) not null default '', 34 | mailing_state nvarchar(256) not null default '', 35 | mailing_country nvarchar(256) not null default '', 36 | mailing_pincode nvarchar(64) not null default '', 37 | email nvarchar(256) not null default '', 38 | it_pan nvarchar(64) not null default '', 39 | gstn nvarchar(64) not null default '', 40 | gst_registration_type nvarchar(64) not null default '', 41 | gst_supply_type nvarchar(64) not null default '', 42 | gst_duty_head nvarchar(16) not null default '', 43 | tax_rate decimal(9,4) default 0, 44 | bank_account_holder nvarchar(256) not null default '', 45 | bank_account_number nvarchar(64) not null default '', 46 | bank_ifsc nvarchar(64) not null default '', 47 | bank_swift nvarchar(64) not null default '', 48 | bank_name nvarchar(64) not null default '', 49 | bank_branch nvarchar(64) not null default '', 50 | bill_credit_period int not null default 0 51 | ); 52 | 53 | create table mst_vouchertype 54 | ( 55 | guid varchar(64) not null primary key, 56 | name nvarchar(1024) not null default '', 57 | parent nvarchar(1024) not null default '', 58 | numbering_method nvarchar(64) not null default '', 59 | is_deemedpositive tinyint, 60 | affects_stock tinyint 61 | ); 62 | 63 | create table mst_uom 64 | ( 65 | guid varchar(64) not null primary key, 66 | name nvarchar(1024) not null default '', 67 | formalname nvarchar(256) not null default '', 68 | is_simple_unit tinyint not null, 69 | base_units nvarchar(1024) not null, 70 | additional_units nvarchar(1024) not null, 71 | conversion int not null 72 | ); 73 | 74 | create table mst_godown 75 | ( 76 | guid varchar(64) not null primary key, 77 | name nvarchar(1024) not null default '', 78 | parent nvarchar(1024) not null default '', 79 | address nvarchar(1024) not null default '' 80 | ); 81 | 82 | create table mst_stock_group 83 | ( 84 | guid varchar(64) not null primary key, 85 | name nvarchar(1024) not null default '', 86 | parent nvarchar(1024) not null default '' 87 | ); 88 | 89 | create table mst_stock_item 90 | ( 91 | guid varchar(64) not null primary key, 92 | name nvarchar(1024) not null default '', 93 | parent nvarchar(1024) not null default '', 94 | alias nvarchar(256) not null default '', 95 | description nvarchar(64) not null default '', 96 | notes nvarchar(64) not null default '', 97 | part_number nvarchar(256) not null default '', 98 | uom nvarchar(32) not null default '', 99 | alternate_uom nvarchar(32) not null default '', 100 | conversion int not null default 0, 101 | opening_balance decimal(15,4) default 0, 102 | opening_rate decimal(15,4) default 0, 103 | opening_value decimal(17,2) default 0, 104 | closing_balance decimal(15,4) default 0, 105 | closing_rate decimal(15,4) default 0, 106 | closing_value decimal(17,2) default 0, 107 | costing_method nvarchar(32) not null default '', 108 | gst_type_of_supply nvarchar(32) default '', 109 | gst_hsn_code nvarchar(64) default '', 110 | gst_hsn_description nvarchar(256) default '', 111 | gst_rate decimal(9,4) default 0, 112 | gst_taxability nvarchar(32) default '' 113 | ); 114 | 115 | create table mst_cost_category 116 | ( 117 | guid varchar(64) not null primary key, 118 | name nvarchar(1024) not null default '', 119 | allocate_revenue tinyint, 120 | allocate_non_revenue tinyint 121 | ); 122 | 123 | create table mst_cost_centre 124 | ( 125 | guid varchar(64) not null primary key, 126 | name nvarchar(1024) not null default '', 127 | parent nvarchar(1024) not null default '', 128 | category nvarchar(1024) not null default '' 129 | ); 130 | 131 | create table mst_attendance_type 132 | ( 133 | guid varchar(64) not null primary key, 134 | name nvarchar(1024) not null default '', 135 | parent nvarchar(1024) not null default '', 136 | uom nvarchar(32) not null default '', 137 | attendance_type nvarchar(64) not null default '', 138 | attendance_period nvarchar(64) not null default '' 139 | ); 140 | 141 | create table mst_employee 142 | ( 143 | guid varchar(64) not null primary key, 144 | name nvarchar(1024) not null default '', 145 | parent nvarchar(1024) not null default '', 146 | id_number nvarchar(256) not null default '', 147 | date_of_joining date, 148 | date_of_release date, 149 | designation nvarchar(64) not null default '', 150 | function_role nvarchar(64) not null default '', 151 | location nvarchar(256) not null default '', 152 | gender nvarchar(32) not null default '', 153 | date_of_birth date, 154 | blood_group nvarchar(32) not null default '', 155 | father_mother_name nvarchar(256) not null default '', 156 | spouse_name nvarchar(256) not null default '', 157 | address nvarchar(256) not null default '', 158 | mobile nvarchar(32) not null default '', 159 | email nvarchar(64) not null default '', 160 | pan nvarchar(32) not null default '', 161 | aadhar nvarchar(32) not null default '', 162 | uan nvarchar(32) not null default '', 163 | pf_number nvarchar(32) not null default '', 164 | pf_joining_date date, 165 | pf_relieving_date date, 166 | pr_account_number nvarchar(32) not null default '' 167 | ); 168 | 169 | create table mst_payhead 170 | ( 171 | guid varchar(64) not null primary key, 172 | name nvarchar(1024) not null default '', 173 | parent nvarchar(1024) not null default '', 174 | payslip_name nvarchar(1024) not null default '', 175 | pay_type nvarchar(64) not null default '', 176 | income_type nvarchar(64) not null default '', 177 | calculation_type nvarchar(32) not null default '', 178 | leave_type nvarchar(64) not null default '', 179 | calculation_period nvarchar(32) not null default '' 180 | ); 181 | 182 | create table mst_gst_effective_rate 183 | ( 184 | item nvarchar(1024) not null default '', 185 | applicable_from date, 186 | hsn_description nvarchar(256) not null default '', 187 | hsn_code nvarchar(64) not null default '', 188 | rate decimal(9,4) default 0, 189 | is_rcm_applicable tinyint, 190 | nature_of_transaction nvarchar(64) not null default '', 191 | nature_of_goods nvarchar(64) not null default '', 192 | supply_type nvarchar(64) not null default '', 193 | taxability nvarchar(64) not null default '' 194 | ); 195 | 196 | create table mst_opening_batch_allocation 197 | ( 198 | name nvarchar(1024) not null default '', 199 | item nvarchar(1024) not null default '', 200 | opening_balance decimal(15,4) default 0, 201 | opening_rate decimal(15,4) default 0, 202 | opening_value decimal(17,2) default 0, 203 | godown nvarchar(1024) not null default '', 204 | manufactured_on date 205 | ); 206 | 207 | create table mst_opening_bill_allocation 208 | ( 209 | ledger nvarchar(1024) not null default '', 210 | opening_balance decimal(17,4) default 0, 211 | bill_date date, 212 | name nvarchar(1024) not null default '', 213 | bill_credit_period int not null default 0, 214 | is_advance tinyint 215 | ); 216 | 217 | create table trn_closingstock_ledger 218 | ( 219 | ledger nvarchar(1024) not null default '', 220 | stock_date date, 221 | stock_value decimal(17,2) not null default 0 222 | ); 223 | 224 | create table mst_stockitem_standard_cost 225 | ( 226 | item nvarchar(1024) not null default '', 227 | date date, 228 | rate decimal(15,4) default 0 229 | ); 230 | 231 | create table mst_stockitem_standard_price 232 | ( 233 | item nvarchar(1024) not null default '', 234 | date date, 235 | rate decimal(15,4) default 0 236 | ); 237 | 238 | create table trn_voucher 239 | ( 240 | guid varchar(64) not null primary key, 241 | date date not null, 242 | voucher_type nvarchar(1024) not null, 243 | voucher_number nvarchar(64) not null default '', 244 | reference_number nvarchar(64) not null default '', 245 | reference_date date, 246 | narration nvarchar(4000) not null default '', 247 | party_name nvarchar(256) not null, 248 | place_of_supply nvarchar(256) not null, 249 | is_invoice tinyint, 250 | is_accounting_voucher tinyint, 251 | is_inventory_voucher tinyint, 252 | is_order_voucher tinyint 253 | ); 254 | 255 | create table trn_accounting 256 | ( 257 | guid varchar(64) not null default '', 258 | ledger nvarchar(1024) not null default '', 259 | amount decimal(17,2) not null default 0, 260 | amount_forex decimal(17,2) not null default 0, 261 | currency nvarchar(16) not null default '' 262 | ); 263 | 264 | create table trn_inventory 265 | ( 266 | guid varchar(64) not null default '', 267 | item nvarchar(1024) not null default '', 268 | quantity decimal(15,4) not null default 0, 269 | rate decimal(15,4) not null default 0, 270 | amount decimal(17,2) not null default 0, 271 | additional_amount decimal(17,2) not null default 0, 272 | discount_amount decimal(17,2) not null default 0, 273 | godown nvarchar(1024), 274 | tracking_number nvarchar(256), 275 | order_number nvarchar(256), 276 | order_duedate date 277 | ); 278 | 279 | create table trn_cost_centre 280 | ( 281 | guid varchar(64) not null default '', 282 | ledger nvarchar(1024) not null default '', 283 | costcentre nvarchar(1024) not null default '', 284 | amount decimal(17,2) not null default 0 285 | ); 286 | 287 | create table trn_cost_category_centre 288 | ( 289 | guid varchar(64) not null default '', 290 | ledger nvarchar(1024) not null default '', 291 | costcategory nvarchar(1024) not null default '', 292 | costcentre nvarchar(1024) not null default '', 293 | amount decimal(17,2) not null default 0 294 | ); 295 | 296 | create table trn_cost_inventory_category_centre 297 | ( 298 | guid varchar(64) not null default '', 299 | ledger nvarchar(1024) not null default '', 300 | item nvarchar(1024) not null default '', 301 | costcategory nvarchar(1024) not null default '', 302 | costcentre nvarchar(1024) not null default '', 303 | amount decimal(17,2) not null default 0 304 | ); 305 | 306 | create table trn_bill 307 | ( 308 | guid varchar(64) not null default '', 309 | ledger nvarchar(1024) not null default '', 310 | name nvarchar(1024) not null default '', 311 | amount decimal(17,2) not null default 0, 312 | billtype nvarchar(256) not null default '', 313 | bill_credit_period int not null default 0 314 | ); 315 | 316 | create table trn_bank 317 | ( 318 | guid varchar(64) not null default '', 319 | ledger nvarchar(1024) not null default '', 320 | transaction_type nvarchar(32) not null default '', 321 | instrument_date date, 322 | instrument_number nvarchar(1024) not null default '', 323 | bank_name nvarchar(64) not null default '', 324 | amount decimal(17,2) not null default 0, 325 | bankers_date date 326 | ); 327 | 328 | create table trn_batch 329 | ( 330 | guid varchar(64) not null default '', 331 | item nvarchar(1024) not null default '', 332 | name nvarchar(1024) not null default '', 333 | quantity decimal(15,4) not null default 0, 334 | amount decimal(17,2) not null default 0, 335 | godown nvarchar(1024), 336 | destination_godown nvarchar(1024), 337 | tracking_number nvarchar(1024) 338 | ); 339 | 340 | create table trn_inventory_accounting 341 | ( 342 | guid varchar(64) not null default '', 343 | ledger nvarchar(1024) not null default '', 344 | amount decimal(17,2) not null default 0, 345 | additional_allocation_type nvarchar(32) not null default '' 346 | ); 347 | 348 | create table trn_employee 349 | ( 350 | guid varchar(64) not null default '', 351 | category nvarchar(1024) not null default '', 352 | employee_name nvarchar(1024) not null default '', 353 | amount decimal(17,2) not null default 0, 354 | employee_sort_order int not null default 0 355 | ); 356 | 357 | create table trn_payhead 358 | ( 359 | guid varchar(64) not null default '', 360 | category nvarchar(1024) not null default '', 361 | employee_name nvarchar(1024) not null default '', 362 | employee_sort_order int not null default 0, 363 | payhead_name nvarchar(1024) not null default '', 364 | payhead_sort_order int not null default 0, 365 | amount decimal(17,2) not null default 0 366 | ); 367 | 368 | create table trn_attendance 369 | ( 370 | guid varchar(64) not null default '', 371 | employee_name nvarchar(1024) not null default '', 372 | attendancetype_name nvarchar(1024) not null default '', 373 | time_value decimal(17,2) not null default 0, 374 | type_value decimal(17,2) not null default 0 375 | ); -------------------------------------------------------------------------------- /dist/definition.mjs: -------------------------------------------------------------------------------- 1 | export {}; 2 | //# sourceMappingURL=definition.mjs.map -------------------------------------------------------------------------------- /dist/index.mjs: -------------------------------------------------------------------------------- 1 | import process from 'process'; 2 | import { tally } from './tally.mjs'; 3 | import { database } from './database.mjs'; 4 | import { logger } from './logger.mjs'; 5 | let isSyncRunning = false; 6 | let lastMasterAlterId = 0; 7 | let lastTransactionAlterId = 0; 8 | function parseCommandlineOptions() { 9 | let retval = new Map(); 10 | try { 11 | let lstArgs = process.argv; 12 | if (lstArgs.length > 2 && lstArgs.length % 2 == 0) 13 | for (let i = 2; i < lstArgs.length; i += 2) { 14 | let argName = lstArgs[i]; 15 | let argValue = lstArgs[i + 1]; 16 | if (/^--\w+-\w+$/g.test(argName)) 17 | retval.set(argName.substr(2), argValue); 18 | } 19 | } 20 | catch (err) { 21 | logger.logError('index.substituteTDLParameters()', err); 22 | } 23 | return retval; 24 | } 25 | function invokeImport() { 26 | return new Promise(async (resolve) => { 27 | try { 28 | isSyncRunning = true; 29 | await tally.importData(); 30 | logger.logMessage('Import completed successfully [%s]', new Date().toLocaleString()); 31 | } 32 | catch (err) { 33 | logger.logMessage('Error in importing data\r\nPlease check error-log.txt file for detailed errors [%s]', new Date().toLocaleString()); 34 | } 35 | finally { 36 | isSyncRunning = false; 37 | resolve(); 38 | } 39 | }); 40 | } 41 | //Update commandline overrides to configuration options 42 | let cmdConfig = parseCommandlineOptions(); 43 | database.updateCommandlineConfig(cmdConfig); 44 | tally.updateCommandlineConfig(cmdConfig); 45 | if (tally.config.frequency <= 0) { // on-demand sync 46 | await invokeImport(); 47 | logger.closeStreams(); 48 | } 49 | else { // continuous sync 50 | const triggerImport = async () => { 51 | try { 52 | // skip if sync is already running (wait for next trigger) 53 | if (!isSyncRunning) { 54 | await tally.updateLastAlterId(); 55 | let isDataChanged = !(lastMasterAlterId == tally.lastAlterIdMaster && lastTransactionAlterId == tally.lastAlterIdTransaction); 56 | if (isDataChanged) { // process only if data is changed 57 | //update local variable copy of last alter ID 58 | lastMasterAlterId = tally.lastAlterIdMaster; 59 | lastTransactionAlterId = tally.lastAlterIdTransaction; 60 | await invokeImport(); 61 | } 62 | else { 63 | logger.logMessage('No change in Tally data found [%s]', new Date().toLocaleString()); 64 | } 65 | } 66 | } 67 | catch (err) { 68 | if (typeof err == 'string' && err.endsWith('is closed in Tally')) { 69 | logger.logMessage(err + ' [%s]', new Date().toLocaleString()); 70 | } 71 | else { 72 | throw err; 73 | } 74 | } 75 | }; 76 | if (!tally.config.company) { // do not process continuous sync for blank company 77 | logger.logMessage('Continuous sync requires Tally company name to be specified in config.json'); 78 | } 79 | else { // go ahead with continuous sync 80 | setInterval(async () => await triggerImport(), tally.config.frequency * 60000); 81 | await triggerImport(); 82 | } 83 | } 84 | //# sourceMappingURL=index.mjs.map -------------------------------------------------------------------------------- /dist/logger.mjs: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import util from 'util'; 3 | import process from 'process'; 4 | import { utility } from './utility.mjs'; 5 | class _logger { 6 | streamMessage; 7 | streamError; 8 | flgErrorLogged = false; 9 | constructor() { 10 | if (fs.existsSync('./import-log.txt')) 11 | fs.rmSync('./import-log.txt'); 12 | if (fs.existsSync('./error-log.txt')) 13 | fs.rmSync('./error-log.txt'); 14 | this.streamMessage = fs.createWriteStream('./import-log.txt', { encoding: 'utf-8' }); 15 | this.streamError = fs.createWriteStream('./error-log.txt', { encoding: 'utf-8' }); 16 | } 17 | logMessage(message, ...params) { 18 | console.log(message, ...params); //graphical console 19 | this.streamMessage.write(util.format(message, ...params) + '\r\n'); 20 | if (process.send) { // GUI thread based invoke 21 | process.send(util.format(message, ...params) + '\r\n'); 22 | } 23 | } 24 | logError(fnInfo, err) { 25 | if (!this.flgErrorLogged) { 26 | this.flgErrorLogged = true; 27 | let errorLog = ''; 28 | if (!fnInfo.endsWith(')')) 29 | fnInfo += '()'; 30 | errorLog += `Error from ${fnInfo} at ${utility.Date.format(new Date(), 'yyyy-MM-dd HH:mm:ss')}\r\n`; 31 | if (typeof err == 'string') 32 | errorLog += err + '\r\n'; 33 | else { 34 | let props = Object.getOwnPropertyNames(err); 35 | for (let i = 0; i < props.length; i++) { 36 | let propName = props[i]; 37 | let propValue = err[propName]; 38 | if (typeof propValue == 'string') 39 | errorLog += propValue + '\r\n'; 40 | } 41 | } 42 | errorLog += '-'.repeat(80) + '\r\n\r\n\r\n'; 43 | console.error(errorLog); //graphical console 44 | this.streamError.write(errorLog); 45 | } 46 | } 47 | closeStreams() { 48 | this.streamMessage.close(); 49 | this.streamError.close(); 50 | } 51 | } 52 | let logger = new _logger(); 53 | export { logger }; 54 | //# sourceMappingURL=logger.mjs.map -------------------------------------------------------------------------------- /dist/server.mjs: -------------------------------------------------------------------------------- 1 | import http from 'http'; 2 | import fs from 'fs'; 3 | import child_process from 'child_process'; 4 | import { WebSocketServer } from 'ws'; 5 | const httpPort = 8997; 6 | const wsPort = 8998; 7 | let isSyncRunning = false; 8 | let syncProcess = undefined; 9 | const wsServer = new WebSocketServer({ 10 | port: wsPort 11 | }); 12 | function configObjectToCommandLineArr(obj) { 13 | let retval = []; 14 | let databaseObj = obj['database']; 15 | let tallyObj = obj['tally']; 16 | for (const [key, val] of Object.entries(databaseObj)) { 17 | retval.push('--database-' + key); 18 | retval.push(val); 19 | } 20 | for (const [key, val] of Object.entries(tallyObj)) { 21 | retval.push('--tally-' + key); 22 | retval.push(val); 23 | } 24 | return retval; 25 | } 26 | function runSyncProcess(configObj) { 27 | let cmdArgs = configObjectToCommandLineArr(configObj); 28 | syncProcess = child_process.fork('./dist/index.mjs', cmdArgs); 29 | syncProcess.on('message', (msg) => wsServer.clients.forEach((wsClient) => wsClient.send(msg.toString()))); 30 | syncProcess.on('close', () => { 31 | isSyncRunning = false; 32 | wsServer.clients.forEach((wsClient) => wsClient.send('~')); 33 | }); 34 | } 35 | function postTallyXML(tallyServer, tallyPort, payload) { 36 | return new Promise((resolve, reject) => { 37 | try { 38 | let req = http.request({ 39 | hostname: tallyServer, 40 | port: tallyPort, 41 | path: '', 42 | method: 'POST', 43 | headers: { 44 | 'Content-Length': Buffer.byteLength(payload, 'utf16le'), 45 | 'Content-Type': 'text/xml;charset=utf-16' 46 | } 47 | }, (res) => { 48 | let data = ''; 49 | res 50 | .setEncoding('utf16le') 51 | .on('data', (chunk) => { 52 | let result = chunk.toString() || ''; 53 | data += result; 54 | }) 55 | .on('end', () => { 56 | resolve(data); 57 | }) 58 | .on('error', (httpErr) => { 59 | reject(httpErr); 60 | }); 61 | }); 62 | req.on('error', (reqError) => { 63 | reject(reqError); 64 | }); 65 | req.write(payload, 'utf16le'); 66 | req.end(); 67 | } 68 | catch (err) { 69 | reject(err); 70 | } 71 | }); 72 | } 73 | ; 74 | const httpServer = http.createServer((req, res) => { 75 | let reqContent = ''; 76 | req.on('data', (chunk) => reqContent += chunk); 77 | req.on('end', async () => { 78 | let contentResp = ''; 79 | if (req.url == '/') { 80 | let fileContent = fs.readFileSync('./gui.html', 'utf8'); 81 | contentResp = fileContent; 82 | res.statusCode = 200; 83 | res.setHeader('Content-Type', 'text/html'); 84 | res.end(contentResp); 85 | return; 86 | } 87 | else if (req.url == '/loadconfig') { 88 | let fileContent = fs.readFileSync('./config.json', 'utf8'); 89 | contentResp = fileContent; 90 | res.setHeader('Content-Type', 'application/json'); 91 | } 92 | else if (req.url == '/saveconfig') { 93 | fs.writeFileSync('./config.json', reqContent, { encoding: 'utf8' }); 94 | contentResp = 'Config saved'; 95 | res.setHeader('Content-Type', 'text/plain'); 96 | } 97 | else if (req.url == '/sync') { 98 | let objConfig = JSON.parse(reqContent); 99 | if (isSyncRunning) { 100 | contentResp = 'Sync is already running'; 101 | } 102 | else { 103 | isSyncRunning = true; 104 | runSyncProcess(objConfig); 105 | contentResp = 'Sync started'; 106 | } 107 | res.setHeader('Content-Type', 'text/plain'); 108 | } 109 | else if (req.url == '/abort') { 110 | if (syncProcess) { 111 | syncProcess.kill(); 112 | contentResp = 'Process killed'; 113 | } 114 | else { 115 | contentResp = 'Could not kill process'; 116 | } 117 | res.setHeader('Content-Type', 'text/plain'); 118 | } 119 | else if (req.url == '/list-company') { 120 | const reqPayload = '
1ExportDataMyReportLedgerTable
$$SysName:XMLMyForm
MyPart01DATA
MyLine01MyLine01 : MyCollectionVerticalFld$NameROWCompany
'; 121 | let objConfig = JSON.parse(reqContent); 122 | let result = ''; 123 | try { 124 | result = await postTallyXML(objConfig['server'], objConfig['port'], reqPayload); 125 | } 126 | catch { 127 | result = ''; 128 | } 129 | contentResp = result; 130 | res.setHeader('Content-Type', 'text/xml'); 131 | } 132 | else if (req.url == '/tally-status') { 133 | let objConfig = JSON.parse(reqContent); 134 | try { 135 | let result = await postTallyXML(objConfig['server'], objConfig['port'], ''); 136 | contentResp = result; 137 | } 138 | catch { 139 | contentResp = ''; 140 | } 141 | res.setHeader('Content-Type', 'text/plain'); 142 | } 143 | else { 144 | res.writeHead(404); 145 | res.end(); 146 | return; 147 | } 148 | res.statusCode = 200; 149 | res.end(contentResp); 150 | }); 151 | }); 152 | httpServer.listen(httpPort, 'localhost', () => { 153 | console.log(`Server started on http://localhost:${httpPort}`); 154 | console.log('Launching utility GUI page on default browser...'); 155 | child_process.exec(`start http://localhost:${httpPort}`); 156 | setInterval(() => { 157 | if (wsServer.clients.size == 0 && !isSyncRunning) { 158 | console.log('No webpage connected. Closing utility...'); 159 | process.exit(0); //shutdown utility 160 | } 161 | }, 5000); 162 | }); 163 | //# sourceMappingURL=server.mjs.map -------------------------------------------------------------------------------- /docs/commandline-options.md: -------------------------------------------------------------------------------- 1 | ## Commandline Options 2 | Utility is completely driven by configuration specified in **config.json** file. In case if specific configuration(s) needs to be overriden without changing it in config file, it can be done using commandline switches as follows: 3 | 4 | ```bat 5 | node ./dist/index.mjs [[--option 01] [value 01] [--option 02] [value 02] ...] 6 | ``` 7 | 8 | **option**: Syntax for option is **--parent-child** , *parent* is the main config name followed by *child* is the sub-config name in **config.json** . (Refer example for further explanation) 9 | 10 | **value**: Value of config for corresponsing option 11 | 12 | ### Examples: 13 | 14 | **Scenario 01:** We need to set from & to date dynamically (without changing config file), lets say **FY 2019-20 Q3**, then below is the command for that 15 | ```bat 16 | node ./dist/index.mjs --tally-fromdate 20191001 --tally-todate 20191231 17 | ``` 18 | 19 | **Scenario 02:** You have a tally company named *Reliance Industries*, created database of it by name *client_reliance* and want to export **FY 2019-20** Then below is the command for that 20 | ```bat 21 | node ./dist/index.mjs --tally-fromdate 20191001 --tally-todate 20191231 --tally-company "Reliance Industries" --database-schema client_reliance 22 | ``` 23 | 24 | **Scenario 03:** We need to sync data for multiple companies of Tally. So, this requires creation of separate database for each company. And then sync of all the companies in one go can be done like this 25 | ```bat 26 | node ./dist/index.mjs --database-schema tallydb_airtel --tally-company "Bharti Airtel" 27 | node ./dist/index.mjs --database-schema tallydb_voda_idea --tally-company "Vodafone Idea Ltd FY 2021-22" --tally-fromdate 20210401 --tally-todate 20220331 28 | node ./dist/index.mjs --database-schema tallydb_jio --tally-company "Reliance Jio from (01-Apr-2022)" 29 | ``` 30 | 31 | 32 | **Scenario 04:** Your have a single Tally company with 3 years of data FY 2017-18, FY 2018-19 and FY 2019-20 in it. Full sync for 3 years in single go by setting from-to dates is taking long time with Tally using up large amount of RAM. This can be setup as below with first line of syncing both master and transactions for first year, and then subsequent sync only pushing transactions of that year 33 | ```bat 34 | node ./dist/index.mjs --tally-fromdate 20170401 --tally-todate 20180331 35 | node ./dist/index.mjs --tally-fromdate 20180401 --tally-todate 20190331 --tally-master false --tally-truncate false 36 | node ./dist/index.mjs --tally-fromdate 20190401 --tally-todate 20200331 --tally-master false --tally-truncate false 37 | ``` 38 | 39 | The first line instructions sync to run with normal behaviour (with default mode of clear database and sync). 40 | For next 2 years, commandline instructs utility to exclude master from sync (as they were pushed already in previous step), and suppress database clearing, since we are simply pushing (or adding) current year transactions to existing database. -------------------------------------------------------------------------------- /docs/faq.md: -------------------------------------------------------------------------------- 1 | ## Frequently Asked Question 2 | 3 | **Ques:** How to enable SQL Server connectivity via TCP/IP port for Microsoft SQL Server ? 4 | 5 | **Ans:** Utility supports connection to MS SQL Server via TCP/IP port only. It does not support connecting through named instance like *PC-NAME\\SQLEXPRESS*. This setting can be enabled using below steps: 6 | 7 | 1. Launch **Computer Management** (just type it in Windows Search bar) 8 | 1. Open: Services and Applications > SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for MSSQLSERVER > TCP/IP 9 | ![SQL Server Configuration Manager network settings](https://excelkida.com/image/github/sql-server-configuration-manager-setting.png) 10 | 1. Right Click and **Enable** it 11 | 1. Double Click (or right click and open Properties) to open TCP/IP Properties window 12 | 1. Goto IP Addresses tab > IPAll > and set 13 | * TCP Dynamic Ports = (blank) erase value from it 14 | * TCP Port = 1433
15 | ![SQL Server Configuration Manager IP Address settings](https://excelkida.com/image/github/sql-server-configuration-manager-ipaddress-port-config.png) 16 | 1. Restart SQL Server: Task Manager > Services > MSSQLSERVER > right click > Restart
17 | ![SQL Server Service restart](https://excelkida.com/image/github/task-manager-sql-server-service-restart.png) 18 | 19 | **Ques:** I am getting an error as below, how can I resolve it 20 | ``` 21 | Error from database() at 22 | SyntaxError: Bad control character in string literal in JSON at position xx 23 | ``` 24 | 25 | **Ans:** This error occurs when **config.json** file JSON structure breaks while modifying values in it. In such scenario, overwrite existing *config.json* file by re-extracting it from utility project zip file. 26 | 27 | **Ques:** MySQL gives error *Loading local data is disabled; this must be enabled on both the client and server sides* 28 | 29 | **Ans:** MySQL by default disables loading of local files. To enable it run below command 30 | ```sql 31 | SET GLOBAL local_infile=1; 32 | ``` 33 | If running after this query you end up with message as below 34 | 35 | *1227 (42000): Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation* 36 | 37 | then only option left is to change **loadmethod** to **insert** as your database administrator does not allow you to enable local_infile due to security concerns. 38 | 39 | 40 | 41 | **Ques:** I am getting error as below. How to resolve it ? 42 | ``` 43 | Error from tally.postTallyXML() at 44 | AggregateError [ECONNREFUSED]: 45 | at internalConnectMultiple (node:net:1117:18) 46 | at afterConnectMultiple (node:net:1684:7) 47 | at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) 48 | ECONNREFUSED 49 | ``` 50 | 51 | **Ques:** I cannot see utility command-line (black colour) window pop-up upon running utility 52 | 53 | **Ans:** Please ensure below things which can cause this 54 | 55 | 1. Ensure you have Node.JS installed 56 | 1. In the utility folder check if a folder named **node_modules** exists. If it does not shows up for you, then you should again download utility properly from project GitHub page via **7z** file link provided. 57 | 58 | 59 | **Ans:** This error occurs when utility is unable to communicate with Tally. Ensure below things: 60 | * Tally must be running 61 | * Ensure XML port of Tally is enabled and is properly set in config.json > tally > port 62 | 63 | **Ques:** I am getting error as below. How to resolve it ? 64 | ``` 65 | Error from tally.importData() at 66 | Cannot detect First/Last voucher date from company 67 | ``` 68 | 69 | **Ans:** This error occurs when no company in Tally is selected or active. 70 | It even occurs when you specify incorrect company name in config.json > tally > company 71 | 72 | 73 | **Ques:** I get following error for PostgreSQL connection. What could be the issue 74 | ``` 75 | Error from database.executePostgres() at 76 | error: no pg_hba.conf entry for host "0.0.0.0", user "postgres", database "tallydb", no encryption 77 | ``` 78 | 79 | **Ans:** 80 | You need to set **ssl** to **true** in config.json > database. Also ensure, that your user and database is added in hostssl line in **pg_hba.conf** 81 | 82 | 83 | **Ques:** I get an error like "Received an invalid column length from the bcp client for colid" 84 | 85 | **Ans:** This error is generated by SQL Server bulk load driver. All the textual columns have max length set in **database-structure** file. When any rows has textual data where this length of the text exceeds, this this error is triggered. Generally error will specify column number in front of colid which can be identified by going through the column named in database structure or CSV file. Unfortunately culprit row is not displayed, which one has to manually identify by importing data into Excel via Power Query. -------------------------------------------------------------------------------- /docs/google-bigquery.md: -------------------------------------------------------------------------------- 1 | # Tally to Database: Google BigQuery 2 | 3 | ## Background 4 | Google BigQuery is a cloud-based Data Warehouse supporting SQL Query syntax for data analytics. It is available for free (Database Size: 10 GB / Query Processing: 1000 GB per month). It requires simple signup to Google Cloud using Gmail account. Google Sheet supports easy integration with Google BigQuery, using which SQL Queries can be fired to to BigQuery and tabular output is return back directly into Google Sheet. Utility supports pushing of Tally data directly into Google BigQuery. 5 | 6 | ## BigQuery Database Setup 7 | 1. Sign-up for a Google BigQuery Free Tier account [Video Tutorial](https://www.youtube.com/watch?v=JLXLCv5nUCE) 8 | 1. Create a dataset by name **tallydb** under the default project
9 | ![Big Query Create Dataset](https://excelkida.com/image/github/bigquery-create-dataset.png)
10 | ![Big Query Create Dataset Options](https://excelkida.com/image/github/bigquery-create-dataset-options.png) 11 | 1. Grab databate schema using file under the folder of project [platform/google-bigquery/database-structure.sql](../platform/google-bigquery/database-structure.sql) , dump it to the SQL Query editor window and run it
12 | ![Big Query Create Schema SQL](https://excelkida.com/image/github/bigquery-create-schema-sql.png)
13 | ![Big Query Dataset Table listing](https://excelkida.com/image/github/bigquery-dataset-table-listing.png) 14 | 1. Create service account for connectivity and secured authentication
15 | ![Big Query Service Account Menu](https://excelkida.com/image/github/bigquery-create-service-account-menu.png)
16 | ![Big Query Service Account Menu](https://excelkida.com/image/github/bigquery-service-account-01.png)
17 | ![Big Query Service Account Menu](https://excelkida.com/image/github/bigquery-service-account-02.png) 18 | 1. Create and download JSON based key
19 | ![Big Query Service Account Menu](https://excelkida.com/image/github/bigquery-service-account-keys-01.png)
20 | ![Big Query Service Account Menu](https://excelkida.com/image/github/bigquery-service-account-keys-02.png)
21 | ![Big Query Service Account Menu](https://excelkida.com/image/github/bigquery-service-account-keys-03.png)
22 | ![Big Query Service Account Menu](https://excelkida.com/image/github/bigquery-service-account-keys-04.png) 23 | 1. Copy this JSON based key file into utility folder and rename it to **bigquery-credentials.json** 24 | 25 |

26 | 27 | ## Utility configuration 28 | Ensure that in config.json following values are set properly 29 | ```json 30 | "technology": "bigquery" 31 | "schema": "tallydb" 32 | ``` 33 | *Note: Do not delete remaining settings (as it may break utility), just keep them unchanged* -------------------------------------------------------------------------------- /docs/incremental-sync.md: -------------------------------------------------------------------------------- 1 | # Sync Options 2 | 3 | ## Background 4 | Time to sync is dependent on the volumn of data in the Tally. In few scenario where data is huge, sync time can be very long. 5 | Utility supports 2 types of sync 6 | 7 | **full**: Complete data is sync to database freshly 8 | 9 | **incremental**: Only that portion of data is sync which got added / modified / deleted from the last sync point 10 | 11 | ## Steps for incremental sync 12 | 1. Delete and re-create database using file **database-structure-incremental.sql** 13 | 1. In the **config.json** file, set **sync** setting value to **incremental** , **frequency** to any value greater than zero (i.e. no of minutes utility need to reach out Tally again to check for changes in data) and **definition** to **tally-export-config-incremental.yaml** . From/To date is ignored and set to auto internally. 14 | 1. Carefully set name of the target company of Tally in *company* setting, as it is not advisable to keep company name blank which picks data from active company which could cause mess if it points to incorrect database 15 | 1. Run the **run.bat** file 16 | 17 | ## Compatibility 18 | Incremental sync option is compatible only for RDBMS types of database i.e. 19 | 1. SQL Server 20 | 1. MySQL Server 21 | 1. PostgreSQL Server 22 | 23 | Incremental sync for Google BigQuery is currently not introduced, as UPDATE query of SQL in Google BigQuery incurs high cost beyond free usage limit. 24 | 25 | ## Incremental Sync - Known Limitations 26 | * Date From/To parameter of config.json is disabled during incremental sync (it is set to *auto* as a default), as utility cannot track if changes to data outside period were made or not. It is recommended to run incremental sync on single Financial Year data. 27 | * During prelimnary Full sync required for subsequent incremental sync, period should be kept as *auto* & frequency as zero 28 | * Existing data should not be deleted from database manually using DELETE / TRUNCATE SQL command when using incremental sync, as it may break sync and cause data ingegrity issues 29 | * Setting incorrect database name in subsequency incremental sync will cause data integrity issues. 30 | * **incremental** sync option needs to be used judiciously when it is bare necessity. Prefer **full** sync which is safe compared to incremental sync. 31 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tally-database-loader", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.mjs", 6 | "type": "module", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "overrides": { 13 | "whatwg-url": "^14.0.0" 14 | }, 15 | "dependencies": { 16 | "@azure/storage-file-datalake": "^12.24.0", 17 | "@google-cloud/bigquery": "^7.9.0", 18 | "js-yaml": "^4.1.0", 19 | "mysql2": "^3.11.3", 20 | "pg": "^8.13.0", 21 | "pg-copy-streams": "^6.0.6", 22 | "tedious": "^18.6.1", 23 | "ws": "^8.18.0" 24 | }, 25 | "devDependencies": { 26 | "@types/js-yaml": "^4.0.1", 27 | "@types/node": "^22.5.0", 28 | "@types/pg": "^8.11.10", 29 | "@types/pg-copy-streams": "^1.2.5", 30 | "@types/ws": "^8.5.12" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /platform/google-bigquery/database-structure.sql: -------------------------------------------------------------------------------- 1 | create table tallydb.config 2 | ( 3 | name string(64) not null, 4 | value string(1024) 5 | ); 6 | 7 | create table tallydb.mst_group 8 | ( 9 | guid string(64) not null, 10 | name string(1024) not null, 11 | parent string(1024) not null, 12 | primary_group string(1024) not null, 13 | is_revenue tinyint, 14 | is_deemedpositive tinyint, 15 | is_reserved tinyint, 16 | affects_gross_profit tinyint, 17 | sort_position int 18 | ); 19 | 20 | create table tallydb.mst_ledger 21 | ( 22 | guid string(64) not null, 23 | name string(1024) not null, 24 | parent string(1024) not null, 25 | alias string(256) not null, 26 | description string(64) not null, 27 | notes string(64) not null, 28 | is_revenue tinyint, 29 | is_deemedpositive tinyint, 30 | opening_balance decimal(17,2), 31 | closing_balance decimal(17,2), 32 | mailing_name string(256) not null, 33 | mailing_address string(1024) not null, 34 | mailing_state string(256) not null, 35 | mailing_country string(256) not null, 36 | mailing_pincode string(64) not null, 37 | email string(256) not null, 38 | it_pan string(64) not null, 39 | gstn string(64) not null, 40 | gst_registration_type string(64) not null, 41 | gst_supply_type string(64) not null, 42 | gst_duty_head string(16) not null, 43 | tax_rate decimal(9,4), 44 | bank_account_holder string(256) not null, 45 | bank_account_number string(64) not null, 46 | bank_ifsc string(64) not null, 47 | bank_swift string(64) not null, 48 | bank_name string(64) not null, 49 | bank_branch string(64) not null, 50 | bill_credit_period int not null 51 | ); 52 | 53 | create table tallydb.mst_vouchertype 54 | ( 55 | guid string(64) not null, 56 | name string(1024) not null, 57 | parent string(1024) not null, 58 | numbering_method string(64) not null, 59 | is_deemedpositive tinyint, 60 | affects_stock tinyint 61 | ); 62 | 63 | create table tallydb.mst_uom 64 | ( 65 | guid string(64) not null, 66 | name string(1024) not null, 67 | formalname string(256) not null, 68 | is_simple_unit tinyint not null, 69 | base_units string(1024) not null, 70 | additional_units string(1024) not null, 71 | conversion int not null 72 | ); 73 | 74 | create table tallydb.mst_godown 75 | ( 76 | guid string(64) not null, 77 | name string(1024) not null, 78 | parent string(1024) not null, 79 | address string(1024) not null 80 | ); 81 | 82 | create table tallydb.mst_stock_group 83 | ( 84 | guid string(64) not null, 85 | name string(1024) not null, 86 | parent string(1024) not null 87 | ); 88 | 89 | create table tallydb.mst_stock_item 90 | ( 91 | guid string(64) not null, 92 | name string(1024) not null, 93 | parent string(1024) not null, 94 | alias string(256) not null, 95 | description string(64) not null, 96 | notes string(64) not null, 97 | part_number string(256) not null, 98 | uom string(32) not null, 99 | alternate_uom string(32) not null, 100 | conversion int not null, 101 | opening_balance decimal(15,4), 102 | opening_rate decimal(15,4), 103 | opening_value decimal(17,2), 104 | closing_balance decimal(15,4), 105 | closing_rate decimal(15,4), 106 | closing_value decimal(17,2), 107 | costing_method string(32) not null, 108 | gst_type_of_supply string(32), 109 | gst_hsn_code string(64), 110 | gst_hsn_description string(256), 111 | gst_rate decimal(9,4), 112 | gst_taxability string(32) 113 | ); 114 | 115 | create table tallydb.mst_cost_category 116 | ( 117 | guid string(64) not null, 118 | name string(1024) not null, 119 | allocate_revenue tinyint, 120 | allocate_non_revenue tinyint 121 | ); 122 | 123 | create table tallydb.mst_cost_centre 124 | ( 125 | guid string(64) not null, 126 | name string(1024) not null, 127 | parent string(1024) not null, 128 | category string(1024) not null 129 | ); 130 | 131 | create table tallydb.mst_attendance_type 132 | ( 133 | guid string(64) not null, 134 | name string(1024) not null, 135 | parent string(1024) not null, 136 | uom string(32) not null, 137 | attendance_type string(64) not null, 138 | attendance_period string(64) not null 139 | ); 140 | 141 | create table tallydb.mst_employee 142 | ( 143 | guid string(64) not null, 144 | name string(1024) not null, 145 | parent string(1024) not null, 146 | id_number string(256) not null, 147 | date_of_joining date, 148 | date_of_release date, 149 | designation string(64) not null, 150 | function_role string(64) not null, 151 | location string(256) not null, 152 | gender string(32) not null, 153 | date_of_birth date, 154 | blood_group string(32) not null, 155 | father_mother_name string(256) not null, 156 | spouse_name string(256) not null, 157 | address string(256) not null, 158 | mobile string(32) not null, 159 | email string(64) not null, 160 | pan string(32) not null, 161 | aadhar string(32) not null, 162 | uan string(32) not null, 163 | pf_number string(32) not null, 164 | pf_joining_date date, 165 | pf_relieving_date date, 166 | pr_account_number string(32) not null 167 | ); 168 | 169 | create table tallydb.mst_payhead 170 | ( 171 | guid string(64) not null, 172 | name string(1024) not null, 173 | parent string(1024) not null, 174 | payslip_name string(1024) not null, 175 | pay_type string(64) not null, 176 | income_type string(64) not null, 177 | calculation_type string(32) not null, 178 | leave_type string(64) not null, 179 | calculation_period string(32) not null 180 | ); 181 | 182 | create table tallydb.mst_gst_effective_rate 183 | ( 184 | item string(1024) not null, 185 | applicable_from date, 186 | hsn_description string(256) not null, 187 | hsn_code string(64) not null, 188 | rate decimal(9,4) not null, 189 | is_rcm_applicable tinyint, 190 | nature_of_transaction string(64) not null, 191 | nature_of_goods string(64) not null, 192 | supply_type string(64) not null, 193 | taxability string(64) not null 194 | ); 195 | 196 | create table tallydb.mst_opening_batch_allocation 197 | ( 198 | name string(1024) not null, 199 | item string(1024) not null, 200 | opening_balance decimal(15,4), 201 | opening_rate decimal(15,4), 202 | opening_value decimal(17,2), 203 | godown string(1024) not null, 204 | manufactured_on date 205 | ); 206 | 207 | create table tallydb.mst_opening_bill_allocation 208 | ( 209 | ledger string(1024) not null, 210 | opening_balance decimal(17,4), 211 | bill_date date, 212 | name string(1024) not null, 213 | bill_credit_period int not null, 214 | is_advance tinyint 215 | ); 216 | 217 | create table tallydb.trn_closingstock_ledger 218 | ( 219 | ledger string(1024) not null, 220 | stock_date date, 221 | stock_value decimal(17,2) not null 222 | ); 223 | 224 | create table tallydb.mst_stockitem_standard_cost 225 | ( 226 | item string(1024) not null, 227 | date date, 228 | rate decimal(15,4) 229 | ); 230 | 231 | create table tallydb.mst_stockitem_standard_price 232 | ( 233 | item string(1024) not null, 234 | date date, 235 | rate decimal(15,4) 236 | ); 237 | 238 | create table tallydb.trn_voucher 239 | ( 240 | guid string(64) not null, 241 | date date not null, 242 | voucher_type string(1024) not null, 243 | voucher_number string(64) not null, 244 | reference_number string(64) not null, 245 | reference_date date, 246 | narration string(4000) not null, 247 | party_name string(256) not null, 248 | place_of_supply string(256) not null, 249 | is_invoice tinyint, 250 | is_accounting_voucher tinyint, 251 | is_inventory_voucher tinyint, 252 | is_order_voucher tinyint 253 | ); 254 | 255 | create table tallydb.trn_accounting 256 | ( 257 | guid string(64) not null, 258 | ledger string(1024) not null, 259 | amount decimal(17,2) not null, 260 | amount_forex decimal(17,2) not null, 261 | currency string(16) not null 262 | ); 263 | 264 | create table tallydb.trn_inventory 265 | ( 266 | guid string(64) not null, 267 | item string(1024) not null, 268 | quantity decimal(15,4) not null, 269 | rate decimal(15,4) not null, 270 | amount decimal(17,2) not null, 271 | additional_amount decimal(17,2) not null, 272 | discount_amount decimal(17,2) not null, 273 | godown string(1024), 274 | tracking_number string(256), 275 | order_number string(256), 276 | order_duedate date 277 | ); 278 | 279 | create table tallydb.trn_cost_centre 280 | ( 281 | guid string(64) not null, 282 | ledger string(1024) not null, 283 | costcentre string(1024) not null, 284 | amount decimal(17,2) not null 285 | ); 286 | 287 | create table tallydb.trn_cost_category_centre 288 | ( 289 | guid string(64) not null, 290 | ledger string(1024) not null, 291 | costcategory string(1024) not null, 292 | costcentre string(1024) not null, 293 | amount decimal(17,2) not null 294 | ); 295 | 296 | create table tallydb.trn_cost_inventory_category_centre 297 | ( 298 | guid string(64) not null, 299 | ledger string(1024) not null, 300 | item string(1024) not null, 301 | costcategory string(1024) not null, 302 | costcentre string(1024) not null, 303 | amount decimal(17,2) not null 304 | ); 305 | 306 | create table tallydb.trn_bill 307 | ( 308 | guid string(64) not null, 309 | ledger string(1024) not null, 310 | name string(1024) not null, 311 | amount decimal(17,2) not null, 312 | billtype string(256) not null, 313 | bill_credit_period int not null 314 | ); 315 | 316 | create table tallydb.trn_bank 317 | ( 318 | guid string(64) not null, 319 | ledger string(1024) not null, 320 | transaction_type string(32) not null, 321 | instrument_date date, 322 | instrument_number string(1024) not null, 323 | bank_name string(64) not null, 324 | amount decimal(17,2) not null, 325 | bankers_date date 326 | ); 327 | 328 | create table tallydb.trn_batch 329 | ( 330 | guid string(64) not null, 331 | item string(1024) not null, 332 | name string(1024) not null, 333 | quantity decimal(15,4) not null, 334 | amount decimal(17,2) not null, 335 | godown string(1024), 336 | destination_godown string(1024), 337 | tracking_number string(1024) 338 | ); 339 | 340 | create table tallydb.trn_inventory_accounting 341 | ( 342 | guid string(64) not null, 343 | ledger string(1024) not null, 344 | amount decimal(17,2) not null, 345 | additional_allocation_type string(32) not null 346 | ); 347 | 348 | create table tallydb.trn_employee 349 | ( 350 | guid string(64) not null, 351 | category string(1024) not null, 352 | employee_name string(1024) not null, 353 | amount decimal(17,2) not null, 354 | employee_sort_order int not null 355 | ); 356 | 357 | create table tallydb.trn_payhead 358 | ( 359 | guid string(64) not null, 360 | category string(1024) not null, 361 | employee_name string(1024) not null, 362 | employee_sort_order int not null, 363 | payhead_name string(1024) not null, 364 | payhead_sort_order int not null, 365 | amount decimal(17,2) not null 366 | ); 367 | 368 | create table tallydb.trn_attendance 369 | ( 370 | guid string(64) not null, 371 | employee_name string(1024) not null, 372 | attendancetype_name string(1024) not null, 373 | time_value decimal(17,2) not null, 374 | type_value decimal(17,2) not null 375 | ); -------------------------------------------------------------------------------- /platform/mysql/database-structure-incremental.sql: -------------------------------------------------------------------------------- 1 | create table _diff 2 | ( 3 | guid varchar(64) not null, 4 | alterid int not null 5 | ); 6 | 7 | create table _delete 8 | ( 9 | guid varchar(64) not null 10 | ); 11 | 12 | create table _vchnumber 13 | ( 14 | guid varchar(64) not null, 15 | voucher_number varchar(256) not null 16 | ); 17 | 18 | create table config 19 | ( 20 | name varchar(64) not null primary key, 21 | value varchar(1024) 22 | ); 23 | 24 | create table mst_group 25 | ( 26 | guid varchar(64) not null primary key, 27 | alterid int not null default 0, 28 | name varchar(1024) not null default '', 29 | parent varchar(1024) not null default '', 30 | _parent varchar(64) not null default '', 31 | primary_group varchar(1024) not null default '', 32 | is_revenue tinyint, 33 | is_deemedpositive tinyint, 34 | is_reserved tinyint, 35 | affects_gross_profit tinyint, 36 | sort_position int 37 | ); 38 | 39 | create table mst_ledger 40 | ( 41 | guid varchar(64) not null primary key, 42 | alterid int not null default 0, 43 | name varchar(1024) not null default '', 44 | parent varchar(1024) not null default '', 45 | _parent varchar(64) not null default '', 46 | alias varchar(256) not null default '', 47 | description varchar(64) not null default '', 48 | notes varchar(64) not null default '', 49 | is_revenue tinyint, 50 | is_deemedpositive tinyint, 51 | opening_balance decimal(17,2) default 0, 52 | closing_balance decimal(17,2) default 0, 53 | mailing_name varchar(256) not null default '', 54 | mailing_address varchar(1024) not null default '', 55 | mailing_state varchar(256) not null default '', 56 | mailing_country varchar(256) not null default '', 57 | mailing_pincode varchar(64) not null default '', 58 | email varchar(256) not null default '', 59 | it_pan varchar(64) not null default '', 60 | gstn varchar(64) not null default '', 61 | gst_registration_type varchar(64) not null default '', 62 | gst_supply_type varchar(64) not null default '', 63 | gst_duty_head varchar(16) not null default '', 64 | tax_rate decimal(9,4) default 0, 65 | bank_account_holder varchar(256) not null default '', 66 | bank_account_number varchar(64) not null default '', 67 | bank_ifsc varchar(64) not null default '', 68 | bank_swift varchar(64) not null default '', 69 | bank_name varchar(64) not null default '', 70 | bank_branch varchar(64) not null default '', 71 | bill_credit_period int not null default 0 72 | ); 73 | 74 | create table mst_vouchertype 75 | ( 76 | guid varchar(64) not null primary key, 77 | alterid int not null default 0, 78 | name varchar(1024) not null default '', 79 | parent varchar(1024) not null default '', 80 | _parent varchar(64) not null default '', 81 | numbering_method varchar(64) not null default '', 82 | is_deemedpositive tinyint, 83 | affects_stock tinyint 84 | ); 85 | 86 | create table mst_uom 87 | ( 88 | guid varchar(64) not null primary key, 89 | alterid int not null default 0, 90 | name varchar(1024) not null default '', 91 | formalname varchar(256) not null default '', 92 | is_simple_unit tinyint not null, 93 | base_units varchar(1024) not null, 94 | additional_units varchar(1024) not null, 95 | conversion int not null 96 | ); 97 | 98 | create table mst_godown 99 | ( 100 | guid varchar(64) not null primary key, 101 | alterid int not null default 0, 102 | name varchar(1024) not null default '', 103 | parent varchar(1024) not null default '', 104 | _parent varchar(64) not null default '', 105 | address varchar(1024) not null default '' 106 | ); 107 | 108 | create table mst_stock_group 109 | ( 110 | guid varchar(64) not null primary key, 111 | alterid int not null default 0, 112 | name varchar(1024) not null default '', 113 | parent varchar(1024) not null default '', 114 | _parent varchar(64) not null default '' 115 | ); 116 | 117 | create table mst_stock_item 118 | ( 119 | guid varchar(64) not null primary key, 120 | alterid int not null default 0, 121 | name varchar(1024) not null default '', 122 | parent varchar(1024) not null default '', 123 | _parent varchar(64) not null default '', 124 | alias varchar(256) not null default '', 125 | description varchar(64) not null default '', 126 | notes varchar(64) not null default '', 127 | part_number varchar(256) not null default '', 128 | uom varchar(32) not null default '', 129 | _uom varchar(64) not null default '', 130 | alternate_uom varchar(32) not null default '', 131 | _alternate_uom varchar(64) not null default '', 132 | conversion int not null default 0, 133 | opening_balance decimal(15,4) default 0, 134 | opening_rate decimal(15,4) default 0, 135 | opening_value decimal(17,2) default 0, 136 | closing_balance decimal(15,4) default 0, 137 | closing_rate decimal(15,4) default 0, 138 | closing_value decimal(17,2) default 0, 139 | costing_method varchar(32) not null default '', 140 | gst_type_of_supply varchar(32) default '', 141 | gst_hsn_code varchar(64) default '', 142 | gst_hsn_description varchar(256) default '', 143 | gst_rate decimal(9,4) default 0, 144 | gst_taxability varchar(32) default '' 145 | ); 146 | 147 | create table mst_cost_category 148 | ( 149 | guid varchar(64) not null primary key, 150 | alterid int not null default 0, 151 | name varchar(1024) not null default '', 152 | allocate_revenue tinyint, 153 | allocate_non_revenue tinyint 154 | ); 155 | 156 | create table mst_cost_centre 157 | ( 158 | guid varchar(64) not null primary key, 159 | alterid int not null default 0, 160 | name varchar(1024) not null default '', 161 | parent varchar(1024) not null default '', 162 | _parent varchar(64) not null default '', 163 | category varchar(1024) not null default '' 164 | ); 165 | 166 | create table mst_attendance_type 167 | ( 168 | guid varchar(64) not null primary key, 169 | alterid int not null default 0, 170 | name varchar(1024) not null default '', 171 | parent varchar(1024) not null default '', 172 | _parent varchar(64) not null default '', 173 | uom varchar(32) not null default '', 174 | _uom varchar(64) not null default '', 175 | attendance_type varchar(64) not null default '', 176 | attendance_period varchar(64) not null default '' 177 | ); 178 | 179 | create table mst_employee 180 | ( 181 | guid varchar(64) not null primary key, 182 | alterid int not null default 0, 183 | name varchar(1024) not null default '', 184 | parent varchar(1024) not null default '', 185 | _parent varchar(64) not null default '', 186 | id_number varchar(256) not null default '', 187 | date_of_joining date, 188 | date_of_release date, 189 | designation varchar(64) not null default '', 190 | function_role varchar(64) not null default '', 191 | location varchar(256) not null default '', 192 | gender varchar(32) not null default '', 193 | date_of_birth date, 194 | blood_group varchar(32) not null default '', 195 | father_mother_name varchar(256) not null default '', 196 | spouse_name varchar(256) not null default '', 197 | address varchar(256) not null default '', 198 | mobile varchar(32) not null default '', 199 | email varchar(64) not null default '', 200 | pan varchar(32) not null default '', 201 | aadhar varchar(32) not null default '', 202 | uan varchar(32) not null default '', 203 | pf_number varchar(32) not null default '', 204 | pf_joining_date date, 205 | pf_relieving_date date, 206 | pr_account_number varchar(32) not null default '' 207 | ); 208 | 209 | create table mst_payhead 210 | ( 211 | guid varchar(64) not null primary key, 212 | alterid int not null default 0, 213 | name varchar(1024) not null default '', 214 | parent varchar(1024) not null default '', 215 | _parent varchar(64) not null default '', 216 | payslip_name varchar(1024) not null default '', 217 | pay_type varchar(64) not null default '', 218 | income_type varchar(64) not null default '', 219 | calculation_type varchar(32) not null default '', 220 | leave_type varchar(64) not null default '', 221 | calculation_period varchar(32) not null default '' 222 | ); 223 | 224 | create table mst_gst_effective_rate 225 | ( 226 | item varchar(1024) not null default '', 227 | _item varchar(64) not null default '', 228 | applicable_from date, 229 | hsn_description varchar(256) not null default '', 230 | hsn_code varchar(64) not null default '', 231 | rate decimal(9,4) default 0, 232 | is_rcm_applicable tinyint, 233 | nature_of_transaction varchar(64) not null default '', 234 | nature_of_goods varchar(64) not null default '', 235 | supply_type varchar(64) not null default '', 236 | taxability varchar(64) not null default '' 237 | ); 238 | 239 | create table mst_opening_batch_allocation 240 | ( 241 | name varchar(1024) not null default '', 242 | item varchar(1024) not null default '', 243 | _item varchar(64) not null default '', 244 | opening_balance decimal(15,4) default 0, 245 | opening_rate decimal(15,4) default 0, 246 | opening_value decimal(17,2) default 0, 247 | godown varchar(1024) not null default '', 248 | _godown varchar(64) not null default '', 249 | manufactured_on date 250 | ); 251 | 252 | create table mst_opening_bill_allocation 253 | ( 254 | ledger varchar(1024) not null default '', 255 | _ledger varchar(64) not null default '', 256 | opening_balance decimal(17,4) default 0, 257 | bill_date date, 258 | name varchar(1024) not null default '', 259 | bill_credit_period int not null default 0, 260 | is_advance tinyint 261 | ); 262 | 263 | create table trn_closingstock_ledger 264 | ( 265 | ledger varchar(1024) not null default '', 266 | _ledger varchar(64) not null default '', 267 | stock_date date, 268 | stock_value decimal(17,2) not null default 0 269 | ); 270 | 271 | create table mst_stockitem_standard_cost 272 | ( 273 | item varchar(1024) not null default '', 274 | _item varchar(64) not null default '', 275 | date date, 276 | rate decimal(15,4) default 0 277 | ); 278 | 279 | create table mst_stockitem_standard_price 280 | ( 281 | item varchar(1024) not null default '', 282 | _item varchar(64) not null default '', 283 | date date, 284 | rate decimal(15,4) default 0 285 | ); 286 | 287 | create table trn_voucher 288 | ( 289 | guid varchar(64) not null primary key, 290 | alterid int not null default 0, 291 | date date not null, 292 | voucher_type varchar(1024) not null, 293 | _voucher_type varchar(64) not null default '', 294 | voucher_number varchar(64) not null default '', 295 | reference_number varchar(64) not null default '', 296 | reference_date date, 297 | narration varchar(4000) not null default '', 298 | party_name varchar(256) not null, 299 | _party_name varchar(64) not null default '', 300 | place_of_supply varchar(256) not null, 301 | is_invoice tinyint, 302 | is_accounting_voucher tinyint, 303 | is_inventory_voucher tinyint, 304 | is_order_voucher tinyint 305 | ); 306 | 307 | create table trn_accounting 308 | ( 309 | guid varchar(64) not null default '', 310 | ledger varchar(1024) not null default '', 311 | _ledger varchar(64) not null default '', 312 | amount decimal(17,2) not null default 0, 313 | amount_forex decimal(17,2) not null default 0, 314 | currency varchar(16) not null default '' 315 | ); 316 | 317 | create table trn_inventory 318 | ( 319 | guid varchar(64) not null default '', 320 | item varchar(1024) not null default '', 321 | _item varchar(64) not null default '', 322 | quantity decimal(15,4) not null default 0, 323 | rate decimal(15,4) not null default 0, 324 | amount decimal(17,2) not null default 0, 325 | additional_amount decimal(17,2) not null default 0, 326 | discount_amount decimal(17,2) not null default 0, 327 | godown varchar(1024), 328 | _godown varchar(64) not null default '', 329 | tracking_number varchar(256), 330 | order_number varchar(256), 331 | order_duedate date 332 | ); 333 | 334 | create table trn_cost_centre 335 | ( 336 | guid varchar(64) not null default '', 337 | ledger varchar(1024) not null default '', 338 | _ledger varchar(64) not null default '', 339 | costcentre varchar(1024) not null default '', 340 | _costcentre varchar(64) not null default '', 341 | amount decimal(17,2) not null default 0 342 | ); 343 | 344 | create table trn_cost_category_centre 345 | ( 346 | guid varchar(64) not null default '', 347 | ledger varchar(1024) not null default '', 348 | _ledger varchar(64) not null default '', 349 | costcategory varchar(1024) not null default '', 350 | _costcategory varchar(64) not null default '', 351 | costcentre varchar(1024) not null default '', 352 | _costcentre varchar(64) not null default '', 353 | amount decimal(17,2) not null default 0 354 | ); 355 | 356 | create table trn_cost_inventory_category_centre 357 | ( 358 | guid varchar(64) not null default '', 359 | ledger varchar(1024) not null default '', 360 | _ledger varchar(64) not null default '', 361 | item varchar(1024) not null default '', 362 | _item varchar(64) not null default '', 363 | costcategory varchar(1024) not null default '', 364 | _costcategory varchar(64) not null default '', 365 | costcentre varchar(1024) not null default '', 366 | _costcentre varchar(64) not null default '', 367 | amount decimal(17,2) not null default 0 368 | ); 369 | 370 | create table trn_bill 371 | ( 372 | guid varchar(64) not null default '', 373 | ledger varchar(1024) not null default '', 374 | _ledger varchar(64) not null default '', 375 | name varchar(1024) not null default '', 376 | amount decimal(17,2) not null default 0, 377 | billtype varchar(256) not null default '', 378 | bill_credit_period int not null default 0 379 | ); 380 | 381 | create table trn_bank 382 | ( 383 | guid varchar(64) not null default '', 384 | ledger varchar(1024) not null default '', 385 | _ledger varchar(64) not null default '', 386 | transaction_type varchar(32) not null default '', 387 | instrument_date date, 388 | instrument_number varchar(1024) not null default '', 389 | bank_name varchar(64) not null default '', 390 | amount decimal(17,2) not null default 0, 391 | bankers_date date 392 | ); 393 | 394 | create table trn_batch 395 | ( 396 | guid varchar(64) not null default '', 397 | item varchar(1024) not null default '', 398 | _item varchar(64) not null default '', 399 | name varchar(1024) not null default '', 400 | quantity decimal(15,4) not null default 0, 401 | amount decimal(17,2) not null default 0, 402 | godown varchar(1024), 403 | _godown varchar(64) not null default '', 404 | destination_godown varchar(1024), 405 | _destination_godown varchar(64) not null default '', 406 | tracking_number varchar(1024) 407 | ); 408 | 409 | create table trn_inventory_accounting 410 | ( 411 | guid varchar(64) not null default '', 412 | ledger varchar(1024) not null default '', 413 | _ledger varchar(64) not null default '', 414 | amount decimal(17,2) not null default 0, 415 | additional_allocation_type varchar(32) not null default '' 416 | ); 417 | 418 | create table trn_employee 419 | ( 420 | guid varchar(64) not null default '', 421 | category varchar(1024) not null default '', 422 | _category varchar(64) not null default '', 423 | employee_name varchar(1024) not null default '', 424 | _employee_name varchar(64) not null default '', 425 | amount decimal(17,2) not null default 0, 426 | employee_sort_order int not null default 0 427 | ); 428 | 429 | create table trn_payhead 430 | ( 431 | guid varchar(64) not null default '', 432 | category varchar(1024) not null default '', 433 | _category varchar(64) not null default '', 434 | employee_name varchar(1024) not null default '', 435 | _employee_name varchar(64) not null default '', 436 | employee_sort_order int not null default 0, 437 | payhead_name varchar(1024) not null default '', 438 | _payhead_name varchar(64) not null default '', 439 | payhead_sort_order int not null default 0, 440 | amount decimal(17,2) not null default 0 441 | ); 442 | 443 | create table trn_attendance 444 | ( 445 | guid varchar(64) not null default '', 446 | employee_name varchar(1024) not null default '', 447 | _employee_name varchar(64) not null default '', 448 | attendancetype_name varchar(1024) not null default '', 449 | _attendancetype_name varchar(64) not null default '', 450 | time_value decimal(17,2) not null default 0, 451 | type_value decimal(17,2) not null default 0 452 | ); -------------------------------------------------------------------------------- /platform/mysql/database-structure.sql: -------------------------------------------------------------------------------- 1 | create table config 2 | ( 3 | name varchar(64) not null primary key, 4 | value varchar(1024) 5 | ); 6 | 7 | create table mst_group 8 | ( 9 | guid varchar(64) not null primary key, 10 | name varchar(1024) not null default '', 11 | parent varchar(1024) not null default '', 12 | primary_group varchar(1024) not null default '', 13 | is_revenue tinyint, 14 | is_deemedpositive tinyint, 15 | is_reserved tinyint, 16 | affects_gross_profit tinyint, 17 | sort_position int 18 | ); 19 | 20 | create table mst_ledger 21 | ( 22 | guid varchar(64) not null primary key, 23 | name varchar(1024) not null default '', 24 | parent varchar(1024) not null default '', 25 | alias varchar(256) not null default '', 26 | description varchar(64) not null default '', 27 | notes varchar(64) not null default '', 28 | is_revenue tinyint, 29 | is_deemedpositive tinyint, 30 | opening_balance decimal(17,2) default 0, 31 | closing_balance decimal(17,2) default 0, 32 | mailing_name varchar(256) not null default '', 33 | mailing_address varchar(1024) not null default '', 34 | mailing_state varchar(256) not null default '', 35 | mailing_country varchar(256) not null default '', 36 | mailing_pincode varchar(64) not null default '', 37 | email varchar(256) not null default '', 38 | it_pan varchar(64) not null default '', 39 | gstn varchar(64) not null default '', 40 | gst_registration_type varchar(64) not null default '', 41 | gst_supply_type varchar(64) not null default '', 42 | gst_duty_head varchar(16) not null default '', 43 | tax_rate decimal(9,4) default 0, 44 | bank_account_holder varchar(256) not null default '', 45 | bank_account_number varchar(64) not null default '', 46 | bank_ifsc varchar(64) not null default '', 47 | bank_swift varchar(64) not null default '', 48 | bank_name varchar(64) not null default '', 49 | bank_branch varchar(64) not null default '', 50 | bill_credit_period int not null default 0 51 | ); 52 | 53 | create table mst_vouchertype 54 | ( 55 | guid varchar(64) not null primary key, 56 | name varchar(1024) not null default '', 57 | parent varchar(1024) not null default '', 58 | numbering_method varchar(64) not null default '', 59 | is_deemedpositive tinyint, 60 | affects_stock tinyint 61 | ); 62 | 63 | create table mst_uom 64 | ( 65 | guid varchar(64) not null primary key, 66 | name varchar(1024) not null default '', 67 | formalname varchar(256) not null default '', 68 | is_simple_unit tinyint not null, 69 | base_units varchar(1024) not null, 70 | additional_units varchar(1024) not null, 71 | conversion int not null 72 | ); 73 | 74 | create table mst_godown 75 | ( 76 | guid varchar(64) not null primary key, 77 | name varchar(1024) not null default '', 78 | parent varchar(1024) not null default '', 79 | address varchar(1024) not null default '' 80 | ); 81 | 82 | create table mst_stock_group 83 | ( 84 | guid varchar(64) not null primary key, 85 | name varchar(1024) not null default '', 86 | parent varchar(1024) not null default '' 87 | ); 88 | 89 | create table mst_stock_item 90 | ( 91 | guid varchar(64) not null primary key, 92 | name varchar(1024) not null default '', 93 | parent varchar(1024) not null default '', 94 | alias varchar(256) not null default '', 95 | description varchar(64) not null default '', 96 | notes varchar(64) not null default '', 97 | part_number varchar(256) not null default '', 98 | uom varchar(32) not null default '', 99 | alternate_uom varchar(32) not null default '', 100 | conversion int not null default 0, 101 | opening_balance decimal(15,4) default 0, 102 | opening_rate decimal(15,4) default 0, 103 | opening_value decimal(17,2) default 0, 104 | closing_balance decimal(15,4) default 0, 105 | closing_rate decimal(15,4) default 0, 106 | closing_value decimal(17,2) default 0, 107 | costing_method varchar(32) not null default '', 108 | gst_type_of_supply varchar(32) default '', 109 | gst_hsn_code varchar(64) default '', 110 | gst_hsn_description varchar(256) default '', 111 | gst_rate decimal(9,4) default 0, 112 | gst_taxability varchar(32) default '' 113 | ); 114 | 115 | create table mst_cost_category 116 | ( 117 | guid varchar(64) not null primary key, 118 | name varchar(1024) not null default '', 119 | allocate_revenue tinyint, 120 | allocate_non_revenue tinyint 121 | ); 122 | 123 | create table mst_cost_centre 124 | ( 125 | guid varchar(64) not null primary key, 126 | name varchar(1024) not null default '', 127 | parent varchar(1024) not null default '', 128 | category varchar(1024) not null default '' 129 | ); 130 | 131 | create table mst_attendance_type 132 | ( 133 | guid varchar(64) not null primary key, 134 | name varchar(1024) not null default '', 135 | parent varchar(1024) not null default '', 136 | uom varchar(32) not null default '', 137 | attendance_type varchar(64) not null default '', 138 | attendance_period varchar(64) not null default '' 139 | ); 140 | 141 | create table mst_employee 142 | ( 143 | guid varchar(64) not null primary key, 144 | name varchar(1024) not null default '', 145 | parent varchar(1024) not null default '', 146 | id_number varchar(256) not null default '', 147 | date_of_joining date, 148 | date_of_release date, 149 | designation varchar(64) not null default '', 150 | function_role varchar(64) not null default '', 151 | location varchar(256) not null default '', 152 | gender varchar(32) not null default '', 153 | date_of_birth date, 154 | blood_group varchar(32) not null default '', 155 | father_mother_name varchar(256) not null default '', 156 | spouse_name varchar(256) not null default '', 157 | address varchar(256) not null default '', 158 | mobile varchar(32) not null default '', 159 | email varchar(64) not null default '', 160 | pan varchar(32) not null default '', 161 | aadhar varchar(32) not null default '', 162 | uan varchar(32) not null default '', 163 | pf_number varchar(32) not null default '', 164 | pf_joining_date date, 165 | pf_relieving_date date, 166 | pr_account_number varchar(32) not null default '' 167 | ); 168 | 169 | create table mst_payhead 170 | ( 171 | guid varchar(64) not null primary key, 172 | name varchar(1024) not null default '', 173 | parent varchar(1024) not null default '', 174 | payslip_name varchar(1024) not null default '', 175 | pay_type varchar(64) not null default '', 176 | income_type varchar(64) not null default '', 177 | calculation_type varchar(32) not null default '', 178 | leave_type varchar(64) not null default '', 179 | calculation_period varchar(32) not null default '' 180 | ); 181 | 182 | create table mst_gst_effective_rate 183 | ( 184 | item varchar(1024) not null default '', 185 | applicable_from date, 186 | hsn_description varchar(256) not null default '', 187 | hsn_code varchar(64) not null default '', 188 | rate decimal(9,4) default 0, 189 | is_rcm_applicable tinyint, 190 | nature_of_transaction varchar(64) not null default '', 191 | nature_of_goods varchar(64) not null default '', 192 | supply_type varchar(64) not null default '', 193 | taxability varchar(64) not null default '' 194 | ); 195 | 196 | create table mst_opening_batch_allocation 197 | ( 198 | name varchar(1024) not null default '', 199 | item varchar(1024) not null default '', 200 | opening_balance decimal(15,4) default 0, 201 | opening_rate decimal(15,4) default 0, 202 | opening_value decimal(17,2) default 0, 203 | godown varchar(1024) not null default '', 204 | manufactured_on date 205 | ); 206 | 207 | create table mst_opening_bill_allocation 208 | ( 209 | ledger varchar(1024) not null default '', 210 | opening_balance decimal(17,4) default 0, 211 | bill_date date, 212 | name varchar(1024) not null, 213 | bill_credit_period int not null default 0, 214 | is_advance tinyint 215 | ); 216 | 217 | create table trn_closingstock_ledger 218 | ( 219 | ledger varchar(1024) not null default '', 220 | stock_date date, 221 | stock_value decimal(17,2) not null default 0 222 | ); 223 | 224 | create table mst_stockitem_standard_cost 225 | ( 226 | item varchar(1024) not null default '', 227 | date date, 228 | rate decimal(15,4) default 0 229 | ); 230 | 231 | create table mst_stockitem_standard_price 232 | ( 233 | item varchar(1024) not null default '', 234 | date date, 235 | rate decimal(15,4) default 0 236 | ); 237 | 238 | create table trn_voucher 239 | ( 240 | guid varchar(64) not null primary key, 241 | date date not null, 242 | voucher_type varchar(1024) not null, 243 | voucher_number varchar(64) not null default '', 244 | reference_number varchar(64) not null default '', 245 | reference_date date, 246 | narration varchar(4000) not null default '', 247 | party_name varchar(256) not null, 248 | place_of_supply varchar(256) not null, 249 | is_invoice tinyint, 250 | is_accounting_voucher tinyint, 251 | is_inventory_voucher tinyint, 252 | is_order_voucher tinyint 253 | ); 254 | 255 | create table trn_accounting 256 | ( 257 | guid varchar(64) not null default '', 258 | ledger varchar(1024) not null default '', 259 | amount decimal(17,2) not null default 0, 260 | amount_forex decimal(17,2) not null default 0, 261 | currency varchar(16) not null default '' 262 | ); 263 | 264 | create table trn_inventory 265 | ( 266 | guid varchar(64) not null default '', 267 | item varchar(1024) not null default '', 268 | quantity decimal(15,4) not null default 0, 269 | rate decimal(15,4) not null default 0, 270 | amount decimal(17,2) not null default 0, 271 | additional_amount decimal(17,2) not null default 0, 272 | discount_amount decimal(17,2) not null default 0, 273 | godown varchar(1024), 274 | tracking_number varchar(256), 275 | order_number varchar(256), 276 | order_duedate date 277 | ); 278 | 279 | create table trn_cost_centre 280 | ( 281 | guid varchar(64) not null default '', 282 | ledger varchar(1024) not null default '', 283 | costcentre varchar(1024) not null default '', 284 | amount decimal(17,2) not null default 0 285 | ); 286 | 287 | create table trn_cost_category_centre 288 | ( 289 | guid varchar(64) not null default '', 290 | ledger varchar(1024) not null default '', 291 | costcategory varchar(1024) not null default '', 292 | costcentre varchar(1024) not null default '', 293 | amount decimal(17,2) not null default 0 294 | ); 295 | 296 | create table trn_cost_inventory_category_centre 297 | ( 298 | guid varchar(64) not null default '', 299 | ledger varchar(1024) not null default '', 300 | item varchar(1024) not null default '', 301 | costcategory varchar(1024) not null default '', 302 | costcentre varchar(1024) not null default '', 303 | amount decimal(17,2) not null default 0 304 | ); 305 | 306 | create table trn_bill 307 | ( 308 | guid varchar(64) not null default '', 309 | ledger varchar(1024) not null default '', 310 | name varchar(1024) not null default '', 311 | amount decimal(17,2) not null default 0, 312 | billtype varchar(256) not null default '', 313 | bill_credit_period int not null default 0 314 | ); 315 | 316 | create table trn_bank 317 | ( 318 | guid varchar(64) not null default '', 319 | ledger varchar(1024) not null default '', 320 | transaction_type varchar(32) not null default '', 321 | instrument_date date, 322 | instrument_number varchar(1024) not null default '', 323 | bank_name varchar(64) not null default '', 324 | amount decimal(17,2) not null default 0, 325 | bankers_date date 326 | ); 327 | 328 | create table trn_batch 329 | ( 330 | guid varchar(64) not null default '', 331 | item varchar(1024) not null default '', 332 | name varchar(1024) not null default '', 333 | quantity decimal(15,4) not null default 0, 334 | amount decimal(17,2) not null default 0, 335 | godown varchar(1024), 336 | destination_godown varchar(1024), 337 | tracking_number varchar(1024) 338 | ); 339 | 340 | create table trn_inventory_accounting 341 | ( 342 | guid varchar(64) not null default '', 343 | ledger varchar(1024) not null default '', 344 | amount decimal(17,2) not null default 0, 345 | additional_allocation_type varchar(32) not null default '' 346 | ); 347 | 348 | create table trn_employee 349 | ( 350 | guid varchar(64) not null default '', 351 | category varchar(1024) not null default '', 352 | employee_name varchar(1024) not null default '', 353 | amount decimal(17,2) not null default 0, 354 | employee_sort_order int not null default 0 355 | ); 356 | 357 | create table trn_payhead 358 | ( 359 | guid varchar(64) not null default '', 360 | category varchar(1024) not null default '', 361 | employee_name varchar(1024) not null default '', 362 | employee_sort_order int not null default 0, 363 | payhead_name varchar(1024) not null default '', 364 | payhead_sort_order int not null default 0, 365 | amount decimal(17,2) not null default 0 366 | ); 367 | 368 | create table trn_attendance 369 | ( 370 | guid varchar(64) not null default '', 371 | employee_name varchar(1024) not null default '', 372 | attendancetype_name varchar(1024) not null default '', 373 | time_value decimal(17,2) not null default 0, 374 | type_value decimal(17,2) not null default 0 375 | ); -------------------------------------------------------------------------------- /platform/postgresql/database-structure-incremental.sql: -------------------------------------------------------------------------------- 1 | create table _diff 2 | ( 3 | guid varchar(64) not null, 4 | alterid int not null 5 | ); 6 | 7 | create table _delete 8 | ( 9 | guid varchar(64) not null 10 | ); 11 | 12 | create table _vchnumber 13 | ( 14 | guid varchar(64) not null, 15 | voucher_number varchar(256) not null 16 | ); 17 | 18 | create table config 19 | ( 20 | name varchar(64) not null primary key, 21 | value varchar(1024) 22 | ); 23 | 24 | create table mst_group 25 | ( 26 | guid varchar(64) not null primary key, 27 | alterid int not null default 0, 28 | name varchar(1024) not null default '', 29 | parent varchar(1024) not null default '', 30 | _parent varchar(64) not null default '', 31 | primary_group varchar(1024) not null default '', 32 | is_revenue smallint, 33 | is_deemedpositive smallint, 34 | is_reserved smallint, 35 | affects_gross_profit smallint, 36 | sort_position int 37 | ); 38 | 39 | create table mst_ledger 40 | ( 41 | guid varchar(64) not null primary key, 42 | alterid int not null default 0, 43 | name varchar(1024) not null default '', 44 | parent varchar(1024) not null default '', 45 | _parent varchar(64) not null default '', 46 | alias varchar(256) not null default '', 47 | description varchar(64) not null default '', 48 | notes varchar(64) not null default '', 49 | is_revenue smallint, 50 | is_deemedpositive smallint, 51 | opening_balance decimal(17,2) default 0, 52 | closing_balance decimal(17,2) default 0, 53 | mailing_name varchar(256) not null default '', 54 | mailing_address varchar(1024) not null default '', 55 | mailing_state varchar(256) not null default '', 56 | mailing_country varchar(256) not null default '', 57 | mailing_pincode varchar(64) not null default '', 58 | email varchar(256) not null default '', 59 | it_pan varchar(64) not null default '', 60 | gstn varchar(64) not null default '', 61 | gst_registration_type varchar(64) not null default '', 62 | gst_supply_type varchar(64) not null default '', 63 | gst_duty_head varchar(16) not null default '', 64 | tax_rate decimal(9,4) default 0, 65 | bank_account_holder varchar(256) not null default '', 66 | bank_account_number varchar(64) not null default '', 67 | bank_ifsc varchar(64) not null default '', 68 | bank_swift varchar(64) not null default '', 69 | bank_name varchar(64) not null default '', 70 | bank_branch varchar(64) not null default '', 71 | bill_credit_period int not null default 0 72 | ); 73 | 74 | create table mst_vouchertype 75 | ( 76 | guid varchar(64) not null primary key, 77 | alterid int not null default 0, 78 | name varchar(1024) not null default '', 79 | parent varchar(1024) not null default '', 80 | _parent varchar(64) not null default '', 81 | numbering_method varchar(64) not null default '', 82 | is_deemedpositive smallint, 83 | affects_stock smallint 84 | ); 85 | 86 | create table mst_uom 87 | ( 88 | guid varchar(64) not null primary key, 89 | alterid int not null default 0, 90 | name varchar(1024) not null default '', 91 | formalname varchar(256) not null default '', 92 | is_simple_unit smallint not null, 93 | base_units varchar(1024) not null, 94 | additional_units varchar(1024) not null, 95 | conversion int not null 96 | ); 97 | 98 | create table mst_godown 99 | ( 100 | guid varchar(64) not null primary key, 101 | alterid int not null default 0, 102 | name varchar(1024) not null default '', 103 | parent varchar(1024) not null default '', 104 | _parent varchar(64) not null default '', 105 | address varchar(1024) not null default '' 106 | ); 107 | 108 | create table mst_stock_group 109 | ( 110 | guid varchar(64) not null primary key, 111 | alterid int not null default 0, 112 | name varchar(1024) not null default '', 113 | parent varchar(1024) not null default '', 114 | _parent varchar(64) not null default '' 115 | ); 116 | 117 | create table mst_stock_item 118 | ( 119 | guid varchar(64) not null primary key, 120 | alterid int not null default 0, 121 | name varchar(1024) not null default '', 122 | parent varchar(1024) not null default '', 123 | _parent varchar(64) not null default '', 124 | alias varchar(256) not null default '', 125 | description varchar(64) not null default '', 126 | notes varchar(64) not null default '', 127 | part_number varchar(256) not null default '', 128 | uom varchar(32) not null default '', 129 | _uom varchar(64) not null default '', 130 | alternate_uom varchar(32) not null default '', 131 | _alternate_uom varchar(64) not null default '', 132 | conversion int not null default 0, 133 | opening_balance decimal(15,4) default 0, 134 | opening_rate decimal(15,4) default 0, 135 | opening_value decimal(17,2) default 0, 136 | closing_balance decimal(15,4) default 0, 137 | closing_rate decimal(15,4) default 0, 138 | closing_value decimal(17,2) default 0, 139 | costing_method varchar(32) not null default '', 140 | gst_type_of_supply varchar(32) default '', 141 | gst_hsn_code varchar(64) default '', 142 | gst_hsn_description varchar(256) default '', 143 | gst_rate int default 0, 144 | gst_taxability varchar(32) default '' 145 | ); 146 | 147 | create table mst_cost_category 148 | ( 149 | guid varchar(64) not null primary key, 150 | alterid int not null default 0, 151 | name varchar(1024) not null default '', 152 | allocate_revenue smallint, 153 | allocate_non_revenue smallint 154 | ); 155 | 156 | create table mst_cost_centre 157 | ( 158 | guid varchar(64) not null primary key, 159 | alterid int not null default 0, 160 | name varchar(1024) not null default '', 161 | parent varchar(1024) not null default '', 162 | _parent varchar(64) not null default '', 163 | category varchar(1024) not null default '' 164 | ); 165 | 166 | create table mst_attendance_type 167 | ( 168 | guid varchar(64) not null primary key, 169 | alterid int not null default 0, 170 | name varchar(1024) not null default '', 171 | parent varchar(1024) not null default '', 172 | _parent varchar(64) not null default '', 173 | uom varchar(32) not null default '', 174 | _uom varchar(64) not null default '', 175 | attendance_type varchar(64) not null default '', 176 | attendance_period varchar(64) not null default '' 177 | ); 178 | 179 | create table mst_employee 180 | ( 181 | guid varchar(64) not null primary key, 182 | alterid int not null default 0, 183 | name varchar(1024) not null default '', 184 | parent varchar(1024) not null default '', 185 | _parent varchar(64) not null default '', 186 | id_number varchar(256) not null default '', 187 | date_of_joining date, 188 | date_of_release date, 189 | designation varchar(64) not null default '', 190 | function_role varchar(64) not null default '', 191 | location varchar(256) not null default '', 192 | gender varchar(32) not null default '', 193 | date_of_birth date, 194 | blood_group varchar(32) not null default '', 195 | father_mother_name varchar(256) not null default '', 196 | spouse_name varchar(256) not null default '', 197 | address varchar(256) not null default '', 198 | mobile varchar(32) not null default '', 199 | email varchar(64) not null default '', 200 | pan varchar(32) not null default '', 201 | aadhar varchar(32) not null default '', 202 | uan varchar(32) not null default '', 203 | pf_number varchar(32) not null default '', 204 | pf_joining_date date, 205 | pf_relieving_date date, 206 | pr_account_number varchar(32) not null default '' 207 | ); 208 | 209 | create table mst_payhead 210 | ( 211 | guid varchar(64) not null primary key, 212 | alterid int not null default 0, 213 | name varchar(1024) not null default '', 214 | parent varchar(1024) not null default '', 215 | _parent varchar(64) not null default '', 216 | payslip_name varchar(1024) not null default '', 217 | pay_type varchar(64) not null default '', 218 | income_type varchar(64) not null default '', 219 | calculation_type varchar(32) not null default '', 220 | leave_type varchar(64) not null default '', 221 | calculation_period varchar(32) not null default '' 222 | ); 223 | 224 | create table mst_gst_effective_rate 225 | ( 226 | item varchar(1024) not null default '', 227 | _item varchar(64) not null default '', 228 | applicable_from date, 229 | hsn_description varchar(256) not null default '', 230 | hsn_code varchar(64) not null default '', 231 | rate decimal(9,4) default 0, 232 | is_rcm_applicable smallint, 233 | nature_of_transaction varchar(64) not null default '', 234 | nature_of_goods varchar(64) not null default '', 235 | supply_type varchar(64) not null default '', 236 | taxability varchar(64) not null default '' 237 | ); 238 | 239 | create table mst_opening_batch_allocation 240 | ( 241 | name varchar(1024) not null default '', 242 | item varchar(1024) not null default '', 243 | _item varchar(64) not null default '', 244 | opening_balance decimal(15,4) default 0, 245 | opening_rate decimal(15,4) default 0, 246 | opening_value decimal(17,2) default 0, 247 | godown varchar(1024) not null default '', 248 | _godown varchar(64) not null default '', 249 | manufactured_on date 250 | ); 251 | 252 | create table mst_opening_bill_allocation 253 | ( 254 | ledger varchar(1024) not null default '', 255 | _ledger varchar(64) not null default '', 256 | opening_balance decimal(17,4) default 0, 257 | bill_date date, 258 | name varchar(1024) not null default '', 259 | bill_credit_period int not null default 0, 260 | is_advance smallint 261 | ); 262 | 263 | create table trn_closingstock_ledger 264 | ( 265 | ledger varchar(1024) not null default '', 266 | _ledger varchar(64) not null default '', 267 | stock_date date, 268 | stock_value decimal(17,2) not null default 0 269 | ); 270 | 271 | create table mst_stockitem_standard_cost 272 | ( 273 | item varchar(1024) not null default '', 274 | _item varchar(64) not null default '', 275 | date date, 276 | rate decimal(15,4) default 0 277 | ); 278 | 279 | create table mst_stockitem_standard_price 280 | ( 281 | item varchar(1024) not null default '', 282 | _item varchar(64) not null default '', 283 | date date, 284 | rate decimal(15,4) default 0 285 | ); 286 | 287 | create table trn_voucher 288 | ( 289 | guid varchar(64) not null primary key, 290 | alterid int not null default 0, 291 | date date not null, 292 | voucher_type varchar(1024) not null, 293 | _voucher_type varchar(64) not null default '', 294 | voucher_number varchar(64) not null default '', 295 | reference_number varchar(64) not null default '', 296 | reference_date date, 297 | narration varchar(4000) not null default '', 298 | party_name varchar(256) not null, 299 | _party_name varchar(64) not null default '', 300 | place_of_supply varchar(256) not null, 301 | is_invoice smallint, 302 | is_accounting_voucher smallint, 303 | is_inventory_voucher smallint, 304 | is_order_voucher smallint 305 | ); 306 | 307 | create table trn_accounting 308 | ( 309 | guid varchar(64) not null default '', 310 | ledger varchar(1024) not null default '', 311 | _ledger varchar(64) not null default '', 312 | amount decimal(17,2) not null default 0, 313 | amount_forex decimal(17,2) not null default 0, 314 | currency varchar(16) not null default '' 315 | ); 316 | 317 | create table trn_inventory 318 | ( 319 | guid varchar(64) not null default '', 320 | item varchar(1024) not null default '', 321 | _item varchar(64) not null default '', 322 | quantity decimal(15,4) not null default 0, 323 | rate decimal(15,4) not null default 0, 324 | amount decimal(17,2) not null default 0, 325 | additional_amount decimal(17,2) not null default 0, 326 | discount_amount decimal(17,2) not null default 0, 327 | godown varchar(1024), 328 | _godown varchar(64) not null default '', 329 | tracking_number varchar(256), 330 | order_number varchar(256), 331 | order_duedate date 332 | ); 333 | 334 | create table trn_cost_centre 335 | ( 336 | guid varchar(64) not null default '', 337 | ledger varchar(1024) not null default '', 338 | _ledger varchar(64) not null default '', 339 | costcentre varchar(1024) not null default '', 340 | _costcentre varchar(64) not null default '', 341 | amount decimal(17,2) not null default 0 342 | ); 343 | 344 | create table trn_cost_category_centre 345 | ( 346 | guid varchar(64) not null default '', 347 | ledger varchar(1024) not null default '', 348 | _ledger varchar(64) not null default '', 349 | costcategory varchar(1024) not null default '', 350 | _costcategory varchar(64) not null default '', 351 | costcentre varchar(1024) not null default '', 352 | _costcentre varchar(64) not null default '', 353 | amount decimal(17,2) not null default 0 354 | ); 355 | 356 | create table trn_cost_inventory_category_centre 357 | ( 358 | guid varchar(64) not null default '', 359 | ledger varchar(1024) not null default '', 360 | _ledger varchar(64) not null default '', 361 | item varchar(1024) not null default '', 362 | _item varchar(64) not null default '', 363 | costcategory varchar(1024) not null default '', 364 | _costcategory varchar(64) not null default '', 365 | costcentre varchar(1024) not null default '', 366 | _costcentre varchar(64) not null default '', 367 | amount decimal(17,2) not null default 0 368 | ); 369 | 370 | create table trn_bill 371 | ( 372 | guid varchar(64) not null default '', 373 | ledger varchar(1024) not null default '', 374 | _ledger varchar(64) not null default '', 375 | name varchar(1024) not null default '', 376 | amount decimal(17,2) not null default 0, 377 | billtype varchar(256) not null default '', 378 | bill_credit_period int not null default 0 379 | ); 380 | 381 | create table trn_bank 382 | ( 383 | guid varchar(64) not null default '', 384 | ledger varchar(1024) not null default '', 385 | _ledger varchar(64) not null default '', 386 | transaction_type varchar(32) not null default '', 387 | instrument_date date, 388 | instrument_number varchar(1024) not null default '', 389 | bank_name varchar(64) not null default '', 390 | amount decimal(17,2) not null default 0, 391 | bankers_date date 392 | ); 393 | 394 | create table trn_batch 395 | ( 396 | guid varchar(64) not null default '', 397 | item varchar(1024) not null default '', 398 | _item varchar(64) not null default '', 399 | name varchar(1024) not null default '', 400 | quantity decimal(15,4) not null default 0, 401 | amount decimal(17,2) not null default 0, 402 | godown varchar(1024), 403 | _godown varchar(64) not null default '', 404 | destination_godown varchar(1024), 405 | _destination_godown varchar(64) not null default '', 406 | tracking_number varchar(1024) 407 | ); 408 | 409 | create table trn_inventory_accounting 410 | ( 411 | guid varchar(64) not null default '', 412 | ledger varchar(1024) not null default '', 413 | _ledger varchar(64) not null default '', 414 | amount decimal(17,2) not null default 0, 415 | additional_allocation_type varchar(32) not null default '' 416 | ); 417 | 418 | create table trn_employee 419 | ( 420 | guid varchar(64) not null default '', 421 | category varchar(1024) not null default '', 422 | _category varchar(64) not null default '', 423 | employee_name varchar(1024) not null default '', 424 | _employee_name varchar(64) not null default '', 425 | amount decimal(17,2) not null default 0, 426 | employee_sort_order int not null default 0 427 | ); 428 | 429 | create table trn_payhead 430 | ( 431 | guid varchar(64) not null default '', 432 | category varchar(1024) not null default '', 433 | _category varchar(64) not null default '', 434 | employee_name varchar(1024) not null default '', 435 | _employee_name varchar(64) not null default '', 436 | employee_sort_order int not null default 0, 437 | payhead_name varchar(1024) not null default '', 438 | _payhead_name varchar(64) not null default '', 439 | payhead_sort_order int not null default 0, 440 | amount decimal(17,2) not null default 0 441 | ); 442 | 443 | create table trn_attendance 444 | ( 445 | guid varchar(64) not null default '', 446 | employee_name varchar(1024) not null default '', 447 | _employee_name varchar(64) not null default '', 448 | attendancetype_name varchar(1024) not null default '', 449 | _attendancetype_name varchar(64) not null default '', 450 | time_value decimal(17,2) not null default 0, 451 | type_value decimal(17,2) not null default 0 452 | ); -------------------------------------------------------------------------------- /platform/postgresql/database-structure.sql: -------------------------------------------------------------------------------- 1 | create table config 2 | ( 3 | name varchar(64) not null primary key, 4 | value varchar(1024) 5 | ); 6 | 7 | create table mst_group 8 | ( 9 | guid varchar(64) not null primary key, 10 | name varchar(1024) not null default '', 11 | parent varchar(1024) not null default '', 12 | primary_group varchar(1024) not null default '', 13 | is_revenue smallint, 14 | is_deemedpositive smallint, 15 | is_reserved smallint, 16 | affects_gross_profit smallint, 17 | sort_position int 18 | ); 19 | 20 | create table mst_ledger 21 | ( 22 | guid varchar(64) not null primary key, 23 | name varchar(1024) not null default '', 24 | parent varchar(1024) not null default '', 25 | alias varchar(256) not null default '', 26 | description varchar(64) not null default '', 27 | notes varchar(64) not null default '', 28 | is_revenue smallint, 29 | is_deemedpositive smallint, 30 | opening_balance decimal(17,2) default 0, 31 | closing_balance decimal(17,2) default 0, 32 | mailing_name varchar(256) not null default '', 33 | mailing_address varchar(1024) not null default '', 34 | mailing_state varchar(256) not null default '', 35 | mailing_country varchar(256) not null default '', 36 | mailing_pincode varchar(64) not null default '', 37 | email varchar(256) not null default '', 38 | it_pan varchar(64) not null default '', 39 | gstn varchar(64) not null default '', 40 | gst_registration_type varchar(64) not null default '', 41 | gst_supply_type varchar(64) not null default '', 42 | gst_duty_head varchar(16) not null default '', 43 | tax_rate decimal(9,4) default 0, 44 | bank_account_holder varchar(256) not null default '', 45 | bank_account_number varchar(64) not null default '', 46 | bank_ifsc varchar(64) not null default '', 47 | bank_swift varchar(64) not null default '', 48 | bank_name varchar(64) not null default '', 49 | bank_branch varchar(64) not null default '', 50 | bill_credit_period int not null default 0 51 | ); 52 | 53 | create table mst_vouchertype 54 | ( 55 | guid varchar(64) not null primary key, 56 | name varchar(1024) not null default '', 57 | parent varchar(1024) not null default '', 58 | numbering_method varchar(64) not null default '', 59 | is_deemedpositive smallint, 60 | affects_stock smallint 61 | ); 62 | 63 | create table mst_uom 64 | ( 65 | guid varchar(64) not null primary key, 66 | name varchar(1024) not null default '', 67 | formalname varchar(256) not null default '', 68 | is_simple_unit smallint not null, 69 | base_units varchar(1024) not null, 70 | additional_units varchar(1024) not null, 71 | conversion int not null 72 | ); 73 | 74 | create table mst_godown 75 | ( 76 | guid varchar(64) not null primary key, 77 | name varchar(1024) not null default '', 78 | parent varchar(1024) not null default '', 79 | address varchar(1024) not null default '' 80 | ); 81 | 82 | create table mst_stock_group 83 | ( 84 | guid varchar(64) not null primary key, 85 | name varchar(1024) not null default '', 86 | parent varchar(1024) not null default '' 87 | ); 88 | 89 | create table mst_stock_item 90 | ( 91 | guid varchar(64) not null primary key, 92 | name varchar(1024) not null default '', 93 | parent varchar(1024) not null default '', 94 | alias varchar(256) not null default '', 95 | description varchar(64) not null default '', 96 | notes varchar(64) not null default '', 97 | part_number varchar(256) not null default '', 98 | uom varchar(32) not null default '', 99 | alternate_uom varchar(32) not null default '', 100 | conversion int not null default 0, 101 | opening_balance decimal(15,4) default 0, 102 | opening_rate decimal(15,4) default 0, 103 | opening_value decimal(17,2) default 0, 104 | closing_balance decimal(15,4) default 0, 105 | closing_rate decimal(15,4) default 0, 106 | closing_value decimal(17,2) default 0, 107 | costing_method varchar(32) not null default '', 108 | gst_type_of_supply varchar(32) default '', 109 | gst_hsn_code varchar(64) default '', 110 | gst_hsn_description varchar(256) default '', 111 | gst_rate decimal(9,4) default 0, 112 | gst_taxability varchar(32) default '' 113 | ); 114 | 115 | create table mst_cost_category 116 | ( 117 | guid varchar(64) not null primary key, 118 | name varchar(1024) not null default '', 119 | allocate_revenue smallint, 120 | allocate_non_revenue smallint 121 | ); 122 | 123 | create table mst_cost_centre 124 | ( 125 | guid varchar(64) not null primary key, 126 | name varchar(1024) not null default '', 127 | parent varchar(1024) not null default '', 128 | category varchar(1024) not null default '' 129 | ); 130 | 131 | create table mst_attendance_type 132 | ( 133 | guid varchar(64) not null primary key, 134 | name varchar(1024) not null default '', 135 | parent varchar(1024) not null default '', 136 | uom varchar(32) not null default '', 137 | attendance_type varchar(64) not null default '', 138 | attendance_period varchar(64) not null default '' 139 | ); 140 | 141 | create table mst_employee 142 | ( 143 | guid varchar(64) not null primary key, 144 | name varchar(1024) not null default '', 145 | parent varchar(1024) not null default '', 146 | id_number varchar(256) not null default '', 147 | date_of_joining date, 148 | date_of_release date, 149 | designation varchar(64) not null default '', 150 | function_role varchar(64) not null default '', 151 | location varchar(256) not null default '', 152 | gender varchar(32) not null default '', 153 | date_of_birth date, 154 | blood_group varchar(32) not null default '', 155 | father_mother_name varchar(256) not null default '', 156 | spouse_name varchar(256) not null default '', 157 | address varchar(256) not null default '', 158 | mobile varchar(32) not null default '', 159 | email varchar(64) not null default '', 160 | pan varchar(32) not null default '', 161 | aadhar varchar(32) not null default '', 162 | uan varchar(32) not null default '', 163 | pf_number varchar(32) not null default '', 164 | pf_joining_date date, 165 | pf_relieving_date date, 166 | pr_account_number varchar(32) not null default '' 167 | ); 168 | 169 | create table mst_payhead 170 | ( 171 | guid varchar(64) not null primary key, 172 | name varchar(1024) not null default '', 173 | parent varchar(1024) not null default '', 174 | payslip_name varchar(1024) not null default '', 175 | pay_type varchar(64) not null default '', 176 | income_type varchar(64) not null default '', 177 | calculation_type varchar(32) not null default '', 178 | leave_type varchar(64) not null default '', 179 | calculation_period varchar(32) not null default '' 180 | ); 181 | 182 | create table mst_gst_effective_rate 183 | ( 184 | item varchar(1024) not null default '', 185 | applicable_from date, 186 | hsn_description varchar(256) not null default '', 187 | hsn_code varchar(64) not null default '', 188 | rate decimal(9,4) default 0, 189 | is_rcm_applicable smallint, 190 | nature_of_transaction varchar(64) not null default '', 191 | nature_of_goods varchar(64) not null default '', 192 | supply_type varchar(64) not null default '', 193 | taxability varchar(64) not null default '' 194 | ); 195 | 196 | create table mst_opening_batch_allocation 197 | ( 198 | name varchar(1024) not null default '', 199 | item varchar(1024) not null default '', 200 | opening_balance decimal(15,4) default 0, 201 | opening_rate decimal(15,4) default 0, 202 | opening_value decimal(17,2) default 0, 203 | godown varchar(1024) not null default '', 204 | manufactured_on date 205 | ); 206 | 207 | create table mst_opening_bill_allocation 208 | ( 209 | ledger varchar(1024) not null default '', 210 | opening_balance decimal(17,4) default 0, 211 | bill_date date, 212 | name varchar(1024) not null default '', 213 | bill_credit_period int not null default 0, 214 | is_advance smallint 215 | ); 216 | 217 | create table trn_closingstock_ledger 218 | ( 219 | ledger varchar(1024) not null default '', 220 | stock_date date, 221 | stock_value decimal(17,2) not null default 0 222 | ); 223 | 224 | create table mst_stockitem_standard_cost 225 | ( 226 | item varchar(1024) not null default '', 227 | date date, 228 | rate decimal(15,4) default 0 229 | ); 230 | 231 | create table mst_stockitem_standard_price 232 | ( 233 | item varchar(1024) not null default '', 234 | date date, 235 | rate decimal(15,4) default 0 236 | ); 237 | 238 | create table trn_voucher 239 | ( 240 | guid varchar(64) not null primary key, 241 | date date not null, 242 | voucher_type varchar(1024) not null, 243 | voucher_number varchar(64) not null default '', 244 | reference_number varchar(64) not null default '', 245 | reference_date date, 246 | narration varchar(4000) not null default '', 247 | party_name varchar(256) not null, 248 | place_of_supply varchar(256) not null, 249 | is_invoice smallint, 250 | is_accounting_voucher smallint, 251 | is_inventory_voucher smallint, 252 | is_order_voucher smallint 253 | ); 254 | 255 | create table trn_accounting 256 | ( 257 | guid varchar(64) not null default '', 258 | ledger varchar(1024) not null default '', 259 | amount decimal(17,2) not null default 0, 260 | amount_forex decimal(17,2) not null default 0, 261 | currency varchar(16) not null default '' 262 | ); 263 | 264 | create table trn_inventory 265 | ( 266 | guid varchar(64) not null default '', 267 | item varchar(1024) not null default '', 268 | quantity decimal(15,4) not null default 0, 269 | rate decimal(15,4) not null default 0, 270 | amount decimal(17,2) not null default 0, 271 | additional_amount decimal(17,2) not null default 0, 272 | discount_amount decimal(17,2) not null default 0, 273 | godown varchar(1024), 274 | tracking_number varchar(256), 275 | order_number varchar(256), 276 | order_duedate date 277 | ); 278 | 279 | create table trn_cost_centre 280 | ( 281 | guid varchar(64) not null default '', 282 | ledger varchar(1024) not null default '', 283 | costcentre varchar(1024) not null default '', 284 | amount decimal(17,2) not null default 0 285 | ); 286 | 287 | create table trn_cost_category_centre 288 | ( 289 | guid varchar(64) not null default '', 290 | ledger varchar(1024) not null default '', 291 | costcategory varchar(1024) not null default '', 292 | costcentre varchar(1024) not null default '', 293 | amount decimal(17,2) not null default 0 294 | ); 295 | 296 | create table trn_cost_inventory_category_centre 297 | ( 298 | guid varchar(64) not null default '', 299 | ledger varchar(1024) not null default '', 300 | item varchar(1024) not null default '', 301 | costcategory varchar(1024) not null default '', 302 | costcentre varchar(1024) not null default '', 303 | amount decimal(17,2) not null default 0 304 | ); 305 | 306 | create table trn_bill 307 | ( 308 | guid varchar(64) not null default '', 309 | ledger varchar(1024) not null default '', 310 | name varchar(1024) not null default '', 311 | amount decimal(17,2) not null default 0, 312 | billtype varchar(256) not null default '', 313 | bill_credit_period int not null default 0 314 | ); 315 | 316 | create table trn_bank 317 | ( 318 | guid varchar(64) not null default '', 319 | ledger varchar(1024) not null default '', 320 | transaction_type varchar(32) not null default '', 321 | instrument_date date, 322 | instrument_number varchar(1024) not null default '', 323 | bank_name varchar(64) not null default '', 324 | amount decimal(17,2) not null default 0, 325 | bankers_date date 326 | ); 327 | 328 | create table trn_batch 329 | ( 330 | guid varchar(64) not null default '', 331 | item varchar(1024) not null default '', 332 | name varchar(1024) not null default '', 333 | quantity decimal(15,4) not null default 0, 334 | amount decimal(17,2) not null default 0, 335 | godown varchar(1024), 336 | destination_godown varchar(1024), 337 | tracking_number varchar(1024) 338 | ); 339 | 340 | create table trn_inventory_accounting 341 | ( 342 | guid varchar(64) not null default '', 343 | ledger varchar(1024) not null default '', 344 | amount decimal(17,2) not null default 0, 345 | additional_allocation_type varchar(32) not null default '' 346 | ); 347 | 348 | create table trn_employee 349 | ( 350 | guid varchar(64) not null default '', 351 | category varchar(1024) not null default '', 352 | employee_name varchar(1024) not null default '', 353 | amount decimal(17,2) not null default 0, 354 | employee_sort_order int not null default 0 355 | ); 356 | 357 | create table trn_payhead 358 | ( 359 | guid varchar(64) not null default '', 360 | category varchar(1024) not null default '', 361 | employee_name varchar(1024) not null default '', 362 | employee_sort_order int not null default 0, 363 | payhead_name varchar(1024) not null default '', 364 | payhead_sort_order int not null default 0, 365 | amount decimal(17,2) not null default 0 366 | ); 367 | 368 | create table trn_attendance 369 | ( 370 | guid varchar(64) not null default '', 371 | employee_name varchar(1024) not null default '', 372 | attendancetype_name varchar(1024) not null default '', 373 | time_value decimal(17,2) not null default 0, 374 | type_value decimal(17,2) not null default 0 375 | ); -------------------------------------------------------------------------------- /platform/powershell/list-open-companies.ps1: -------------------------------------------------------------------------------- 1 | $resp = Invoke-WebRequest -Uri http://localhost:9000 -Method POST -Body "
1ExportDataMyReport
ASCII (Comma Delimited)MyForm
MyPart
MyLineMyLine : MyCollectionVerticalFldName`$`$StringFindAndReplace:`$Name:'`"':'`"`"'Company
" 2 | $resp.Content -------------------------------------------------------------------------------- /platform/powershell/sync-multiple-company.ps1: -------------------------------------------------------------------------------- 1 | $src = Import-Csv -Path .\config.csv 2 | foreach ($item in $src) 3 | { 4 | Start-Process -FilePath node.exe -WorkingDirectory .\ -ArgumentList ".\dist\index.mjs --database-schema $($item.schema) --tally-company ""$($item.company)""" -Wait 5 | 6 | } -------------------------------------------------------------------------------- /reports/bigquery/account-ledger.sql: -------------------------------------------------------------------------------- 1 | /* Account Statement */ 2 | with tblLedger as 3 | ( 4 | select v.guid, v.date, v.voucher_number, v.voucher_type, v.narration, 5 | (case when a.amount < 0 then -a.amount else 0 end) debit, 6 | (case when a.amount > 0 then a.amount else 0 end) credit 7 | from tallydb.trn_accounting a 8 | join tallydb.trn_voucher v on v.guid = a.guid 9 | where (a.ledger = 'Cash') and (v.is_order_voucher = 0 and v.is_inventory_voucher = 0) and (v.date between parse_date('%d-%m-%Y', '01-04-2020') and parse_date('%d-%m-%Y', '31-03-2021')) 10 | order by v.date 11 | ), 12 | tblEntry as 13 | ( 14 | select v.guid, string_agg(distinct a.ledger) ledgers 15 | from tallydb.trn_voucher v 16 | join tallydb.trn_accounting a on (a.guid = v.guid and a.ledger <> 'Cash') 17 | where (v.guid in (select guid from tblLedger)) and (v.is_order_voucher = 0 and v.is_inventory_voucher = 0) 18 | group by v.guid 19 | ) 20 | select l.date, l.date, l.voucher_type, l.voucher_number, c.ledgers ledgers 21 | from tblLedger l 22 | join tblEntry c on c.guid = l.guid 23 | order by l.date 24 | ; -------------------------------------------------------------------------------- /reports/bigquery/accounting-voucher-view.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | DATE(2000,1,1) as date, 3 | 'Opening Balance' as voucher_type, 4 | '' as voucher_number, 5 | l.name as ledger, 6 | l.opening_balance as amount, 7 | '' as party_name, 8 | g.primary_group as primary_group, 9 | 'Opening Balance' as voucher_category 10 | FROM `tallydb.mst_ledger` as l 11 | INNER JOIN `tallydb.mst_group` AS g ON l.parent = g.name 12 | WHERE l.opening_balance <> 0 13 | UNION ALL 14 | SELECT 15 | v.date, 16 | v.voucher_type, 17 | v.voucher_number, 18 | a.ledger, 19 | a.amount, 20 | v.party_name, 21 | g.primary_group, 22 | t.parent AS voucher_category 23 | FROM `tallydb.trn_accounting` AS a 24 | INNER JOIN `tallydb.trn_voucher` AS v ON a.guid = v.guid 25 | INNER JOIN `tallydb.mst_vouchertype` AS t ON v.voucher_type = t.name 26 | INNER JOIN `tallydb.mst_ledger` AS l ON a.ledger = l.name 27 | INNER JOIN `tallydb.mst_group` AS g ON l.parent = g.name 28 | WHERE 29 | v.is_order_voucher = 0 30 | AND v.is_inventory_voucher = 0 -------------------------------------------------------------------------------- /reports/bigquery/bill-payable.sql: -------------------------------------------------------------------------------- 1 | with bill_combined as 2 | ( 3 | select bill_date as date, ledger, name, opening_balance as amount, 'New Ref' as billtype, bill_credit_period 4 | from `tallydb.mst_opening_bill_allocation` 5 | union all 6 | select v.date, b.ledger, b.name, b.amount, b.billtype, bill_credit_period 7 | from `tallydb.trn_bill` as b 8 | join `tallydb.trn_voucher` as v on v.guid = b.guid 9 | ), 10 | tbl_newref as 11 | ( 12 | select * 13 | from bill_combined 14 | where bill_combined.billtype in ('New Ref', 'Advance') 15 | ), 16 | tbl_agstref as 17 | ( 18 | select * 19 | from bill_combined 20 | where bill_combined.billtype in ('Agst Ref') 21 | ), 22 | tbl_outstanding as 23 | ( 24 | select 25 | nr.ledger, 26 | nr.name, 27 | coalesce(max(nr.amount), 0) as billed_amount, 28 | coalesce(sum(ar.amount), 0) as adjusted_amount, 29 | (coalesce(max(nr.amount), 0) + coalesce(sum(ar.amount), 0)) as outstanding_amount, 30 | (date_diff(current_date(),max(nr.date), day) - max(nr.bill_credit_period)) as overdue_days, 31 | date_add(max(nr.date),interval max(nr.bill_credit_period) day) as overdue_date, 32 | date_diff(current_date(),max(nr.date), day) as oustanding_days, 33 | max(nr.date) bill_date, 34 | max(nr.bill_credit_period) as bill_credit_period 35 | from tbl_newref as nr 36 | left join tbl_agstref as ar on (nr.ledger = ar.ledger and nr.name = ar.name) 37 | group by nr.ledger, nr.name 38 | ) 39 | select 40 | bill_date as date, 41 | name as ref_number, 42 | ledger as party_name, 43 | outstanding_amount as pending_amount, 44 | overdue_date as due_on, 45 | overdue_days as overdue_by_days 46 | from tbl_outstanding 47 | where outstanding_amount > 0 48 | order by overdue_days desc -------------------------------------------------------------------------------- /reports/bigquery/bills-receivable.sql: -------------------------------------------------------------------------------- 1 | with bill_combined as 2 | ( 3 | select bill_date as date, ledger, name, opening_balance as amount, 'New Ref' as billtype, bill_credit_period 4 | from `tallydb.mst_opening_bill_allocation` 5 | union all 6 | select v.date, b.ledger, b.name, b.amount, b.billtype, bill_credit_period 7 | from `tallydb.trn_bill` as b 8 | join `tallydb.trn_voucher` as v on v.guid = b.guid 9 | ), 10 | tbl_newref as 11 | ( 12 | select * 13 | from bill_combined 14 | where bill_combined.billtype in ('New Ref', 'Advance') 15 | ), 16 | tbl_agstref as 17 | ( 18 | select * 19 | from bill_combined 20 | where bill_combined.billtype in ('Agst Ref') 21 | ), 22 | tbl_outstanding as 23 | ( 24 | select 25 | nr.ledger, 26 | nr.name, 27 | coalesce(max(nr.amount), 0) as billed_amount, 28 | coalesce(sum(ar.amount), 0) as adjusted_amount, 29 | (coalesce(max(nr.amount), 0) + coalesce(sum(ar.amount), 0)) as outstanding_amount, 30 | (date_diff(current_date(),max(nr.date), day) - max(nr.bill_credit_period)) as overdue_days, 31 | date_add(max(nr.date),interval max(nr.bill_credit_period) day) as overdue_date, 32 | date_diff(current_date(),max(nr.date), day) as oustanding_days, 33 | max(nr.date) bill_date, 34 | max(nr.bill_credit_period) as bill_credit_period 35 | from tbl_newref as nr 36 | left join tbl_agstref as ar on (nr.ledger = ar.ledger and nr.name = ar.name) 37 | group by nr.ledger, nr.name 38 | ) 39 | select 40 | bill_date as date, 41 | name as ref_number, 42 | ledger as party_name, 43 | -outstanding_amount as pending_amount, 44 | overdue_date as due_on, 45 | overdue_days as overdue_by_days 46 | from tbl_outstanding 47 | where outstanding_amount < 0 48 | order by overdue_days desc -------------------------------------------------------------------------------- /reports/bigquery/daily-cash-movement.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Daily Receipt and Payment (incl Contra) 3 | */ 4 | with tblCashMovement as 5 | ( 6 | select v.date, 7 | sum(case when a.amount < 0 then -a.amount else 0 end) receipt, 8 | sum(case when a.amount > 0 then a.amount else 0 end) payment 9 | from tallydb.trn_accounting a 10 | join tallydb.trn_voucher v on v.guid = a.guid 11 | join tallydb.mst_ledger l on l.name = a.ledger 12 | join tallydb.mst_group g on g.name = l.parent 13 | join tallydb.mst_vouchertype t on t.name = v.voucher_type 14 | where 15 | (v.is_order_voucher = 0 and v.is_inventory_voucher = 0) 16 | and lower(g.primary_group) = 'cash-in-hand' 17 | and lower(t.parent) in ('receipt', 'payment', 'contra') 18 | and (v.date between parse_date('%d-%m-%Y', '01-04-2020') and parse_date('%d-%m-%Y', '31-03-2021')) 19 | group by v.date 20 | ) 21 | select d.dt date, ifnull(c.receipt, 0) receipt, ifnull(c.payment, 0) payment 22 | from (select * from unnest(generate_date_array(parse_date('%d-%m-%Y', '01-04-2020'), parse_date('%d-%m-%Y', '31-03-2021'), interval 1 day)) dt) d 23 | left join tblCashMovement c on d.dt = c.date 24 | order by d.dt 25 | ; -------------------------------------------------------------------------------- /reports/bigquery/profit-loss.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Calculates balances of all Income Expenditure type ledgers 3 | 4 | Fields: 5 | group = Primary Group for the ledger (not to be confused with parent) 6 | ledger = Ledger name 7 | nature = [expense / income] 8 | affects_gross_profit = [Y/N] indicates if the ledger affects calculation of gross profit or not 9 | */ 10 | with tblOpeningStock as 11 | ( 12 | select 13 | 'Opening Stock' as `group`, 14 | 'Opening Stock' as `ledger`, 15 | 'expense' as `nature`, 16 | 'Y' as `affects_gross_profit`, 17 | coalesce(sum(opening_balance),0) as `balance` 18 | from tallydb.mst_ledger l 19 | join tallydb.mst_group g on g.name = l.parent 20 | where g.primary_group = 'Stock-in-hand' 21 | ), 22 | tblClosingStock as 23 | ( 24 | select 25 | 'Closing Stock' as `group`, 26 | 'Closing Stock' as `ledger`, 27 | 'income' as `nature`, 28 | 'Y' as `affects_gross_profit`, 29 | coalesce(-sum(t.stock_value),0) as `balance` 30 | from 31 | ( 32 | select ledger, stock_value, row_number() over(partition by ledger order by stock_date desc) ctr 33 | from tallydb.trn_closingstock_ledger 34 | ) as t 35 | where t.ctr = 1 36 | ), 37 | tblGroupBalance as 38 | ( 39 | select 40 | g.primary_group as `group`, 41 | l.name as `ledger`, 42 | (case when max(g.is_deemedpositive) = 1 then 'expense' else 'income' end) as `nature`, 43 | (case when max(g.affects_gross_profit) = 1 then 'Y' else 'N' end) as `affects_gross_profit`, 44 | sum(a.amount) `balance` 45 | from tallydb.trn_accounting a 46 | join tallydb.trn_voucher v on v.guid = a.guid 47 | join tallydb.mst_vouchertype t on v.voucher_type = t.name 48 | join tallydb.mst_ledger l on a.ledger = l.name 49 | join tallydb.mst_group g on g.name = l.parent 50 | where g.is_revenue = 1 and v.is_order_voucher = 0 and t.affects_stock = 0 51 | group by g.primary_group, l.name 52 | ) 53 | select * from tblGroupBalance 54 | union all 55 | select * from tblOpeningStock 56 | union all 57 | select * from tblClosingStock -------------------------------------------------------------------------------- /reports/bigquery/purchase-daily.sql: -------------------------------------------------------------------------------- 1 | with tblDailySales as 2 | ( 3 | select v.date, 4 | sum(a.amount) amount 5 | from tallydb.trn_accounting a 6 | join tallydb.trn_voucher v on v.guid = a.guid 7 | join tallydb.mst_ledger l on l.name = a.ledger 8 | join tallydb.mst_group g on g.name = l.parent 9 | where g.primary_group = 'Purchase Accounts' and v.date >= parse_date('%d-%m-%Y', '01-04-2020') and v.date <= parse_date('%d-%m-%Y', '31-03-2021') 10 | group by v.date 11 | ) 12 | select d.dt date, ifnull(-c.amount, 0) amount 13 | from (select * from unnest(generate_date_array(parse_date('%d-%m-%Y', '01-04-2020'), parse_date('%d-%m-%Y', '31-03-2021'), interval 1 day)) dt) d 14 | left join tblDailySales c on d.dt = c.date 15 | order by d.dt 16 | ; -------------------------------------------------------------------------------- /reports/bigquery/purchase-monthly.sql: -------------------------------------------------------------------------------- 1 | with tblYearMonthList as 2 | ( 3 | select extract(year from dt) year, extract(month from dt) month 4 | from (select * from unnest(generate_date_array(parse_date('%d-%m-%Y', '01-04-2020'), parse_date('%d-%m-%Y', '31-03-2021'), interval 1 month)) dt) 5 | ), 6 | tblMonthlySales as 7 | ( 8 | select extract(year from v.date) year, extract(month from v.date) month, 9 | sum(a.amount) amount 10 | from tallydb.trn_accounting a 11 | join tallydb.trn_voucher v on v.guid = a.guid 12 | join tallydb.mst_ledger l on l.name = a.ledger 13 | join tallydb.mst_group g on g.name = l.parent 14 | where g.primary_group = 'Purchase Accounts' and v.date >= parse_date('%d-%m-%Y', '01-04-2020') and v.date <= parse_date('%d-%m-%Y', '31-03-2021') 15 | group by extract(year from v.date), extract(month from v.date) 16 | ) 17 | select l.year year, l.month month, ifnull(-s.amount, 0) amount 18 | from tblYearMonthList l 19 | left join tblMonthlySales s on (l.year = s.year and l.month = s.month) 20 | order by l.year, l.month 21 | ; -------------------------------------------------------------------------------- /reports/bigquery/purchase-register.sql: -------------------------------------------------------------------------------- 1 | /* Purchase Register (input for PIVOT table) */ 2 | 3 | select 4 | v.date, 5 | v.voucher_number, 6 | v.voucher_type, 7 | v.party_name, 8 | z.gstn, 9 | a.ledger, 10 | -a.amount amount 11 | from tallydb.trn_accounting a 12 | join tallydb.trn_voucher v on v.guid = a.guid 13 | join tallydb.mst_vouchertype t on v.voucher_type = t.name 14 | join tallydb.mst_ledger l on a.ledger = l.name 15 | join tallydb.mst_ledger z on v.party_name = z.name 16 | where t.parent in ('Purchase') and a.ledger <> v.party_name 17 | order by v.date, v.guid, a.amount -------------------------------------------------------------------------------- /reports/bigquery/sales-daily.sql: -------------------------------------------------------------------------------- 1 | with tblDailySales as 2 | ( 3 | select v.date, 4 | sum(a.amount) amount 5 | from tallydb.trn_accounting a 6 | join tallydb.trn_voucher v on v.guid = a.guid 7 | join tallydb.mst_ledger l on l.name = a.ledger 8 | join tallydb.mst_group g on g.name = l.parent 9 | where g.primary_group = 'Sales Accounts' and v.date >= parse_date('%d-%m-%Y', '01-04-2020') and v.date <= parse_date('%d-%m-%Y', '31-03-2021') 10 | group by v.date 11 | ) 12 | select d.dt date, ifnull(c.amount, 0) amount 13 | from (select * from unnest(generate_date_array(parse_date('%d-%m-%Y', '01-04-2020'), parse_date('%d-%m-%Y', '31-03-2021'), interval 1 day)) dt) d 14 | left join tblDailySales c on d.dt = c.date 15 | order by d.dt 16 | ; -------------------------------------------------------------------------------- /reports/bigquery/sales-monthly.sql: -------------------------------------------------------------------------------- 1 | with tblYearMonthList as 2 | ( 3 | select extract(year from dt) year, extract(month from dt) month 4 | from (select * from unnest(generate_date_array(parse_date('%d-%m-%Y', '01-04-2020'), parse_date('%d-%m-%Y', '31-03-2021'), interval 1 month)) dt) 5 | ), 6 | tblMonthlySales as 7 | ( 8 | select extract(year from v.date) year, extract(month from v.date) month, 9 | sum(a.amount) amount 10 | from tallydb.trn_accounting a 11 | join tallydb.trn_voucher v on v.guid = a.guid 12 | join tallydb.mst_ledger l on l.name = a.ledger 13 | join tallydb.mst_group g on g.name = l.parent 14 | where g.primary_group = 'Sales Accounts' and v.date >= parse_date('%d-%m-%Y', '01-04-2020') and v.date <= parse_date('%d-%m-%Y', '31-03-2021') 15 | group by extract(year from v.date), extract(month from v.date) 16 | ) 17 | select l.year year, l.month month, ifnull(s.amount, 0) amount 18 | from tblYearMonthList l 19 | left join tblMonthlySales s on (l.year = s.year and l.month = s.month) 20 | order by l.year, l.month 21 | ; -------------------------------------------------------------------------------- /reports/bigquery/sales-register.sql: -------------------------------------------------------------------------------- 1 | /* Sales Register (input for PIVOT table) */ 2 | 3 | select 4 | v.date, 5 | v.voucher_number, 6 | v.voucher_type, 7 | v.party_name, 8 | z.gstn, 9 | a.ledger, 10 | a.amount 11 | from tallydb.trn_accounting a 12 | join tallydb.trn_voucher v on v.guid = a.guid 13 | join tallydb.mst_vouchertype t on v.voucher_type = t.name 14 | join tallydb.mst_ledger l on a.ledger = l.name 15 | join tallydb.mst_ledger z on v.party_name = z.name 16 | where t.parent in ('Sales') and a.ledger <> v.party_name 17 | order by v.date, v.guid, a.amount desc -------------------------------------------------------------------------------- /reports/bigquery/stock-voucher-view.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | DATE(2000,1,1) AS date, 3 | '' as voucher_number, 4 | 'Opening Balance' as voucher_type, 5 | b.item, 6 | b.opening_balance as quantity, 7 | b.opening_value as amount, 8 | b.godown as godown 9 | FROM `tallydb.mst_opening_batch_allocation` as b 10 | UNION ALL 11 | SELECT * EXCEPT (repetition) 12 | FROM 13 | ( 14 | SELECT 15 | v.date, v.voucher_number, v.voucher_type, i.item, i.quantity, i.amount, i.godown, 16 | (CASE WHEN i.tracking_number = '' THEN 1 ELSE ROW_NUMBER() OVER(PARTITION BY i.tracking_number, i.item ORDER BY v.date) END) AS repetition 17 | FROM `tallydb.trn_inventory` as i 18 | JOIN `tallydb.trn_voucher` as v on (v.guid = i.guid) 19 | WHERE v.is_order_voucher = 0 20 | ) AS t 21 | WHERE t.repetition = 1 -------------------------------------------------------------------------------- /reports/bigquery/trial-balance.sql: -------------------------------------------------------------------------------- 1 | with tblop as 2 | ( 3 | select a.ledger ledger, sum(a.amount) amount 4 | from tallydb.trn_accounting a 5 | join tallydb.trn_voucher v on v.guid = a.guid 6 | where v.is_order_voucher = 0 and v.is_inventory_voucher = 0 and v.date < parse_date('%d-%m-%Y', '01-04-2020') 7 | group by a.ledger 8 | ), 9 | tblcurr as 10 | ( 11 | select a.ledger ledger, 12 | sum(case when a.amount < 0 then abs(a.amount) else 0 end) debit, 13 | sum(case when a.amount > 0 then a.amount else 0 end) credit 14 | from tallydb.trn_accounting a 15 | join tallydb.trn_voucher v on v.guid = a.guid 16 | where v.is_order_voucher = 0 and v.is_inventory_voucher = 0 and v.date between parse_date('%d-%m-%Y', '01-04-2020') and parse_date('%d-%m-%Y', '31-03-2021') 17 | group by a.ledger 18 | ) 19 | select l.name, 20 | if(l.is_revenue is true, (l.opening_balance + ifnull(op.amount,0)), 0) opening, 21 | ifnull(curr.debit,0) debit, 22 | ifnull(curr.credit,0) credit, 23 | if(l.is_revenue is true, (l.opening_balance + ifnull(op.amount,0)) + ifnull(curr.credit,0) - ifnull(curr.debit,0) ,ifnull(curr.credit,0) - ifnull(curr.debit,0)) closing 24 | from tallydb.mst_ledger l 25 | left join tblop op on op.ledger = l.name 26 | left join tblcurr curr on curr.ledger = l.name 27 | order by l.name 28 | ; -------------------------------------------------------------------------------- /reports/mssql/account-ledger.sql: -------------------------------------------------------------------------------- 1 | /* Account Statement */ 2 | declare 3 | @ledger nvarchar(1024) = 'Cash', 4 | @fromDate date = '2020-04-01', 5 | @toDate date = '2021-03-31'; 6 | with tblLedger as 7 | ( 8 | select v.guid, v.date, v.voucher_number, v.voucher_type, v.narration, 9 | (case when a.amount < 0 then -a.amount else 0 end) 'debit', 10 | (case when a.amount > 0 then a.amount else 0 end) 'credit' 11 | from trn_accounting a 12 | join trn_voucher v on v.guid = a.guid 13 | where a.ledger = @ledger and v.is_accounting_voucher = 1 and (v.date between @fromDate and @toDate) 14 | ), 15 | tblEntry as 16 | ( 17 | select v.guid, string_agg(a.ledger, ',') ledgers 18 | from trn_voucher v 19 | join trn_accounting a on (a.guid = v.guid and a.ledger <> @ledger) 20 | where v.guid in (select distinct guid from tblLedger) and v.is_order_voucher = 0 and v.is_inventory_voucher = 0 21 | group by v.guid 22 | ) 23 | select l.date, l.voucher_number, l.voucher_type, c.ledgers ledgers, l.debit, l.credit, l.narration 24 | from tblLedger l 25 | join tblEntry c on c.guid = l.guid 26 | order by l.date 27 | ; -------------------------------------------------------------------------------- /reports/mssql/accounting-voucher-view.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | DATEFROMPARTS(2000,1,1) as date, 3 | /* MAKEDATE(2000,1,1) as date --MySQL */ 4 | /* DATE '2000-01-01' as date --PostgreSQL */ 5 | 'Opening Balance' as voucher_type, 6 | '' as voucher_number, 7 | l.name as ledger, 8 | l.opening_balance as amount, 9 | '' as party_name, 10 | g.primary_group as primary_group, 11 | 'Opening Balance' as voucher_category 12 | FROM mst_ledger as l 13 | INNER JOIN mst_group AS g ON l.parent = g.name 14 | WHERE l.opening_balance <> 0 15 | UNION ALL 16 | SELECT 17 | v.date, 18 | v.voucher_type, 19 | v.voucher_number, 20 | a.ledger, 21 | a.amount, 22 | v.party_name, 23 | g.primary_group, 24 | t.parent AS voucher_category 25 | FROM trn_accounting AS a 26 | INNER JOIN trn_voucher AS v ON a.guid = v.guid 27 | INNER JOIN mst_vouchertype AS t ON v.voucher_type = t.name 28 | INNER JOIN mst_ledger AS l ON a.ledger = l.name 29 | INNER JOIN mst_group AS g ON l.parent = g.name 30 | WHERE 31 | v.is_order_voucher = 0 32 | AND v.is_inventory_voucher = 0 -------------------------------------------------------------------------------- /reports/mssql/bills-payable.sql: -------------------------------------------------------------------------------- 1 | with bill_combined as 2 | ( 3 | select bill_date as date, ledger, name, opening_balance as amount, 'New Ref' as billtype, bill_credit_period 4 | from mst_opening_bill_allocation 5 | union all 6 | select v.date, b.ledger, b.name, b.amount, b.billtype, bill_credit_period 7 | from trn_bill as b 8 | join trn_voucher as v on v.guid = b.guid 9 | ), 10 | tbl_newref as 11 | ( 12 | select * 13 | from bill_combined 14 | where bill_combined.billtype in ('New Ref', 'Advance') 15 | ), 16 | tbl_agstref as 17 | ( 18 | select * 19 | from bill_combined 20 | where bill_combined.billtype in ('Agst Ref') 21 | ), 22 | tbl_outstanding as 23 | ( 24 | select 25 | nr.ledger, 26 | nr.name, 27 | coalesce(max(nr.amount), 0) as billed_amount, 28 | coalesce(sum(ar.amount), 0) as adjusted_amount, 29 | (coalesce(max(nr.amount), 0) + coalesce(sum(ar.amount), 0)) as outstanding_amount, 30 | /* (CURRENT_DATE - MAX(nr.date))::INTEGER - MAX(nr.bill_credit_period) AS overdue_days, --PostgreSQL */ 31 | /* (DATEDIFF(CURDATE(), MAX(nr.date)) - MAX(nr.bill_credit_period)) AS overdue_days, --MySQL */ 32 | (datediff(day, max(nr.date), getdate()) - max(nr.bill_credit_period)) as overdue_days, 33 | /* MAX(nr.date) + (MAX(nr.bill_credit_period) || ' days')::INTERVAL AS overdue_date, --PostgreSQL */ 34 | /* DATE_ADD(MAX(nr.date), INTERVAL MAX(nr.bill_credit_period) DAY) AS overdue_date, --MySQL */ 35 | dateadd(day, max(nr.bill_credit_period), max(nr.date)) as overdue_date, 36 | /* (CURRENT_DATE - MAX(nr.date))::INTEGER AS oustanding_days, --PostgreSQL */ 37 | /* DATEDIFF(CURDATE(), MAX(nr.date)) AS oustanding_days, --MySQL */ 38 | datediff(day, max(nr.date), getdate()) as oustanding_days, 39 | max(nr.date) bill_date, 40 | max(nr.bill_credit_period) as bill_credit_period 41 | from tbl_newref as nr 42 | left join tbl_agstref as ar on (nr.ledger = ar.ledger and nr.name = ar.name) 43 | group by nr.ledger, nr.name 44 | ) 45 | select 46 | bill_date as date, 47 | name as ref_number, 48 | ledger as party_name, 49 | outstanding_amount as pending_amount, 50 | overdue_date as due_on, 51 | overdue_days as overdue_by_days 52 | from tbl_outstanding 53 | where outstanding_amount > 0 54 | order by overdue_days desc -------------------------------------------------------------------------------- /reports/mssql/bills-receivable.sql: -------------------------------------------------------------------------------- 1 | with bill_combined as 2 | ( 3 | select bill_date as date, ledger, name, opening_balance as amount, 'New Ref' as billtype, bill_credit_period 4 | from mst_opening_bill_allocation 5 | union all 6 | select v.date, b.ledger, b.name, b.amount, b.billtype, bill_credit_period 7 | from trn_bill as b 8 | join trn_voucher as v on v.guid = b.guid 9 | ), 10 | tbl_newref as 11 | ( 12 | select * 13 | from bill_combined 14 | where bill_combined.billtype in ('New Ref', 'Advance') 15 | ), 16 | tbl_agstref as 17 | ( 18 | select * 19 | from bill_combined 20 | where bill_combined.billtype in ('Agst Ref') 21 | ), 22 | tbl_outstanding as 23 | ( 24 | select 25 | nr.ledger, 26 | nr.name, 27 | coalesce(max(nr.amount), 0) as billed_amount, 28 | coalesce(sum(ar.amount), 0) as adjusted_amount, 29 | (coalesce(max(nr.amount), 0) + coalesce(sum(ar.amount), 0)) as outstanding_amount, 30 | /* (CURRENT_DATE - MAX(nr.date))::INTEGER - MAX(nr.bill_credit_period) AS overdue_days, --PostgreSQL */ 31 | /* (DATEDIFF(CURDATE(), MAX(nr.date)) - MAX(nr.bill_credit_period)) AS overdue_days, --MySQL */ 32 | (datediff(day, max(nr.date), getdate()) - max(nr.bill_credit_period)) as overdue_days, 33 | /* MAX(nr.date) + (MAX(nr.bill_credit_period) || ' days')::INTERVAL AS overdue_date, --PostgreSQL */ 34 | /* DATE_ADD(MAX(nr.date), INTERVAL MAX(nr.bill_credit_period) DAY) AS overdue_date, --MySQL */ 35 | dateadd(day, max(nr.bill_credit_period), max(nr.date)) as overdue_date, 36 | /* (CURRENT_DATE - MAX(nr.date))::INTEGER AS oustanding_days, --PostgreSQL */ 37 | /* DATEDIFF(CURDATE(), MAX(nr.date)) AS oustanding_days, --MySQL */ 38 | datediff(day, max(nr.date), getdate()) as oustanding_days, 39 | max(nr.date) bill_date, 40 | max(nr.bill_credit_period) as bill_credit_period 41 | from tbl_newref as nr 42 | left join tbl_agstref as ar on (nr.ledger = ar.ledger and nr.name = ar.name) 43 | group by nr.ledger, nr.name 44 | ) 45 | select 46 | bill_date as date, 47 | name as ref_number, 48 | ledger as party_name, 49 | -outstanding_amount as pending_amount, 50 | overdue_date as due_on, 51 | overdue_days as overdue_by_days 52 | from tbl_outstanding 53 | where outstanding_amount < 0 54 | order by overdue_days desc -------------------------------------------------------------------------------- /reports/mssql/daily-cash-movement.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Daily Receipt and Payment (incl Contra) 3 | */ 4 | 5 | declare 6 | @fromDate date = '2020-04-01', 7 | @toDate date = '2021-03-31'; 8 | with tblDateList as 9 | ( 10 | select @fromDate value 11 | union all 12 | select dateadd(day, 1, value) from tblDateList where value < @toDate 13 | ), 14 | tblCashMovement as 15 | ( 16 | select v.date, 17 | sum(case when a.amount < 0 then -a.amount else 0 end) receipt, 18 | sum(case when a.amount > 0 then a.amount else 0 end) payment 19 | from trn_accounting a 20 | join trn_voucher v on v.guid = a.guid 21 | join mst_ledger l on l.name = a.ledger 22 | join mst_group g on g.name = l.parent 23 | join mst_vouchertype t on t.name = v.voucher_type 24 | where g.primary_group = 'cash-in-hand' and t.parent in ('receipt', 'payment', 'contra') 25 | group by v.date 26 | ) 27 | select d.value date, isnull(c.receipt, 0) receipt, isnull(c.payment, 0) payment 28 | from tblDateList d 29 | left join tblCashMovement c on d.value = c.date 30 | option (maxrecursion 500) 31 | ; 32 | -------------------------------------------------------------------------------- /reports/mssql/group-tree-children-parent.sql: -------------------------------------------------------------------------------- 1 | /* groups: CHILD --> PARENT traversal */ 2 | declare 3 | @group nvarchar(1024) = 'Loans & Advances (Asset)'; 4 | with cte as 5 | ( 6 | select name, parent from mst_group where name = @group 7 | union all 8 | select e.name, e.parent from mst_group e inner join cte on cte.parent = e.name 9 | ) 10 | select * from cte; -------------------------------------------------------------------------------- /reports/mssql/group-tree-parent-child.sql: -------------------------------------------------------------------------------- 1 | /* groups: PARENT --> CHILD traversal */ 2 | declare 3 | @group nvarchar(1024) = 'Loans & Advances (Asset)'; 4 | with cte as 5 | ( 6 | select name, parent from mst_group where name = @group 7 | union all 8 | select e.name, e.parent from mst_group e inner join cte on cte.name = e.parent 9 | ) 10 | select * from cte; -------------------------------------------------------------------------------- /reports/mssql/profit-loss.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Calculates balances of all Income Expenditure type ledgers 3 | 4 | Fields: 5 | group = Primary Group for the ledger (not to be confused with parent) 6 | ledger = Ledger name 7 | nature = [expense / income] 8 | affects_gross_profit = [Y/N] indicates if the ledger affects calculation of gross profit or not 9 | */ 10 | with tblOpeningStock as 11 | ( 12 | select 13 | 'Opening Stock' as 'group', 14 | 'Opening Stock' as 'ledger', 15 | 'expense' as 'nature', 16 | 'Y' as 'affects_gross_profit', 17 | sum(opening_balance) as 'balance' 18 | from mst_ledger l 19 | join mst_group g on g.name = l.parent 20 | where g.primary_group = 'Stock-in-hand' 21 | ), 22 | tblClosingStock as 23 | ( 24 | select 25 | 'Closing Stock' as 'group', 26 | 'Closing Stock' as 'ledger', 27 | 'income' as 'nature', 28 | 'Y' as 'affects_gross_profit', 29 | -sum(t.stock_value) as 'balance' 30 | from 31 | ( 32 | select ledger, stock_value, row_number() over(partition by ledger order by stock_date desc) ctr 33 | from trn_closingstock_ledger 34 | ) as t 35 | where t.ctr = 1 36 | ), 37 | tblGroupBalance as 38 | ( 39 | select 40 | g.primary_group as 'group', 41 | l.name as 'ledger', 42 | (case when max(g.is_deemedpositive) = 1 then 'expense' else 'income' end) as 'nature', 43 | (case when max(g.affects_gross_profit) = 1 then 'Y' else 'N' end) as 'affects_gross_profit', 44 | sum(a.amount) 'balance' 45 | from trn_accounting a 46 | join trn_voucher v on v.guid = a.guid 47 | join mst_vouchertype t on v.voucher_type = t.name 48 | join mst_ledger l on a.ledger = l.name 49 | join mst_group g on g.name = l.parent 50 | where g.is_revenue = 1 and v.is_order_voucher = 0 and v.is_inventory_voucher = 0 and t.affects_stock = 0 51 | group by g.primary_group, l.name 52 | ) 53 | select * from tblGroupBalance 54 | union all 55 | select * from tblOpeningStock 56 | union all 57 | select * from tblClosingStock -------------------------------------------------------------------------------- /reports/mssql/purchase-daily.sql: -------------------------------------------------------------------------------- 1 | declare 2 | @fromDate date = '2020-04-01', 3 | @toDate date = '2021-03-31'; 4 | with tblDateList as 5 | ( 6 | select @fromDate value 7 | union all 8 | select dateadd(day, 1, value) from tblDateList where value < @toDate 9 | ), 10 | tblDailySales as 11 | ( 12 | select v.date, 13 | sum(a.amount) amount 14 | from trn_accounting a 15 | join trn_voucher v on v.guid = a.guid 16 | join mst_ledger l on l.name = a.ledger 17 | join mst_group g on g.name = l.parent 18 | where g.primary_group = 'Purchase Accounts' and v.is_order_voucher = 0 and v.is_inventory_voucher = 0 and v.date >= @fromDate and v.date <= @toDate 19 | group by v.date 20 | ) 21 | select d.value date, isnull(-c.amount, 0) amount 22 | from tblDateList d 23 | left join tblDailySales c on d.value = c.date 24 | option (maxrecursion 500) 25 | ; -------------------------------------------------------------------------------- /reports/mssql/purchase-monthly.sql: -------------------------------------------------------------------------------- 1 | declare 2 | @fromDate date = '2020-04-01', 3 | @toDate date = '2021-03-31'; 4 | with tblDateList as 5 | ( 6 | select @fromDate value 7 | union all 8 | select dateadd(day, 1, value) from tblDateList where value < @toDate 9 | ), 10 | tblYearMonthList as 11 | ( 12 | select year(l.value) year, month(l.value) month 13 | from tblDateList l 14 | group by year(l.value), month(l.value) 15 | ), 16 | tblDailySales as 17 | ( 18 | select year(v.date) year, month(v.date) month, 19 | sum(a.amount) amount 20 | from trn_accounting a 21 | join trn_voucher v on v.guid = a.guid 22 | join mst_ledger l on l.name = a.ledger 23 | join mst_group g on g.name = l.parent 24 | where g.primary_group = 'Purchase Accounts' and v.is_order_voucher = 0 and v.is_inventory_voucher = 0 and v.date >= @fromDate and v.date <= @toDate 25 | group by year(v.date), month(v.date) 26 | ) 27 | select l.year year, l.month month, isnull(-s.amount, 0) amount 28 | from tblYearMonthList l 29 | left join tblDailySales s on (l.year = s.year and l.month = s.month) 30 | order by l.year, l.month 31 | option (maxrecursion 500) 32 | ; -------------------------------------------------------------------------------- /reports/mssql/purchase-register.sql: -------------------------------------------------------------------------------- 1 | /* Purchase Register (input for PIVOT table) */ 2 | 3 | select 4 | v.date, 5 | v.voucher_number, 6 | v.voucher_type, 7 | v.party_name, 8 | z.gstn, 9 | a.ledger, 10 | -a.amount amount 11 | from trn_accounting a 12 | join trn_voucher v on v.guid = a.guid 13 | join mst_vouchertype t on v.voucher_type = t.name 14 | join mst_ledger l on a.ledger = l.name 15 | join mst_ledger z on v.party_name = z.name 16 | where t.parent in ('Purchase') and a.ledger <> v.party_name 17 | order by v.date, v.guid, a.amount -------------------------------------------------------------------------------- /reports/mssql/sales-daily.sql: -------------------------------------------------------------------------------- 1 | declare 2 | @fromDate date = '2020-04-01', 3 | @toDate date = '2021-03-31'; 4 | with tblDateList as 5 | ( 6 | select @fromDate value 7 | union all 8 | select dateadd(day, 1, value) from tblDateList where value < @toDate 9 | ), 10 | tblDailySales as 11 | ( 12 | select v.date, 13 | sum(a.amount) amount 14 | from trn_accounting a 15 | join trn_voucher v on v.guid = a.guid 16 | join mst_ledger l on l.name = a.ledger 17 | join mst_group g on g.name = l.parent 18 | where g.primary_group = 'Sales Accounts' and v.date >= @fromDate and v.date <= @toDate 19 | group by v.date 20 | ) 21 | select d.value date, isnull(c.amount, 0) amount 22 | from tblDateList d 23 | left join tblDailySales c on d.value = c.date 24 | option (maxrecursion 500) 25 | ; -------------------------------------------------------------------------------- /reports/mssql/sales-monthly.sql: -------------------------------------------------------------------------------- 1 | declare 2 | @fromDate date = '2020-04-01', 3 | @toDate date = '2021-03-31'; 4 | with tblDateList as 5 | ( 6 | select @fromDate value 7 | union all 8 | select dateadd(day, 1, value) from tblDateList where value < @toDate 9 | ), 10 | tblYearMonthList as 11 | ( 12 | select year(l.value) year, month(l.value) month 13 | from tblDateList l 14 | group by year(l.value), month(l.value) 15 | ), 16 | tblDailySales as 17 | ( 18 | select year(v.date) year, month(v.date) month, 19 | sum(a.amount) amount 20 | from trn_accounting a 21 | join trn_voucher v on v.guid = a.guid 22 | join mst_ledger l on l.name = a.ledger 23 | join mst_group g on g.name = l.parent 24 | where g.primary_group = 'Sales Accounts' and v.date >= @fromDate and v.date <= @toDate 25 | group by year(v.date), month(v.date) 26 | ) 27 | select l.year year, l.month month, isnull(s.amount, 0) amount 28 | from tblYearMonthList l 29 | left join tblDailySales s on (l.year = s.year and l.month = s.month) 30 | order by l.year, l.month 31 | option (maxrecursion 500) 32 | ; -------------------------------------------------------------------------------- /reports/mssql/sales-register.sql: -------------------------------------------------------------------------------- 1 | /* Sales Register (input for PIVOT table) */ 2 | 3 | select 4 | v.date, 5 | v.voucher_number, 6 | v.voucher_type, 7 | v.party_name, 8 | z.gstn, 9 | a.ledger, 10 | a.amount 11 | from trn_accounting a 12 | join trn_voucher v on v.guid = a.guid 13 | join mst_vouchertype t on v.voucher_type = t.name 14 | join mst_ledger l on a.ledger = l.name 15 | join mst_ledger z on v.party_name = z.name 16 | where t.parent in ('Sales') and a.ledger <> v.party_name 17 | order by v.date, v.guid, a.amount desc -------------------------------------------------------------------------------- /reports/mssql/stock-summary.sql: -------------------------------------------------------------------------------- 1 | with tblTrackingReco as 2 | ( 3 | select i.item, i.tracking_number, 4 | sum(case when t.parent in ('Receipt Note', 'Delivery Note') then abs(i.quantity) else 0 end) note, 5 | sum(case when t.parent not in ('Receipt Note', 'Delivery Note') then abs(i.quantity) else 0 end) invoice 6 | from trn_inventory i 7 | join trn_voucher v on v.guid = i.guid 8 | join mst_vouchertype t on v.voucher_type = t.name 9 | where i.tracking_number is not null 10 | group by i.item, i.tracking_number 11 | ), 12 | tblEffects as 13 | ( 14 | select 15 | i.item, 16 | sum(case when i.quantity > 0 then i.quantity else 0 end) in_qty, 17 | sum(case when i.quantity < 0 then -i.quantity else 0 end) out_qty 18 | from trn_inventory i 19 | join trn_voucher v on v.guid = i.guid 20 | join mst_vouchertype t on v.voucher_type = t.name 21 | left join tblTrackingReco r on (i.item = r.item and i.tracking_number = r.tracking_number) 22 | where 23 | v.is_order_voucher = 0 and (i.tracking_number is null or (t.parent not in ('Receipt Note', 'Delivery Note') and (r.note = r.invoice)) or (t.parent in ('Receipt Note', 'Delivery Note') and (r.note > r.invoice))) 24 | group by i.item 25 | ) 26 | select 27 | s.name, s.parent, s.uom, 28 | s.opening_balance op_qty, 29 | coalesce(e.in_qty, 0) in_qty, 30 | coalesce(e.out_qty, 0) out_qty, 31 | (s.opening_balance + coalesce(e.in_qty, 0) - coalesce(e.out_qty, 0)) clo_bal 32 | from mst_stock_item s 33 | left join tblEffects e on s.name = e.item -------------------------------------------------------------------------------- /reports/mssql/stock-voucher-view.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | DATEFROMPARTS(2000,1,1) AS date, 3 | '' as voucher_number, 4 | 'Opening Balance' as voucher_type, 5 | b.item, 6 | b.opening_balance as quantity, 7 | b.opening_value as amount, 8 | b.godown as godown 9 | FROM mst_opening_batch_allocation as b 10 | UNION ALL 11 | SELECT t.date, t.voucher_number, t.voucher_type, t.item, t.quantity, t.amount, t.godown 12 | FROM 13 | ( 14 | SELECT 15 | v.date, v.voucher_number, v.voucher_type, i.item, i.quantity, i.amount, i.godown, 16 | (CASE WHEN i.tracking_number = '' THEN 1 ELSE ROW_NUMBER() OVER(PARTITION BY i.tracking_number, i.item ORDER BY v.date) END) AS repetition 17 | FROM trn_inventory as i 18 | JOIN trn_voucher as v on (v.guid = i.guid) 19 | WHERE v.is_order_voucher = 0 20 | ) AS t 21 | WHERE t.repetition = 1 -------------------------------------------------------------------------------- /reports/mssql/trial-balance.sql: -------------------------------------------------------------------------------- 1 | declare 2 | @fromDate date = '2020-04-01', 3 | @toDate date = '2021-03-31'; 4 | with tblop as 5 | ( 6 | select a.ledger 'ledger', sum(a.amount) 'amount' 7 | from trn_accounting a 8 | join trn_voucher v on v.guid = a.guid 9 | where v.is_order_voucher = 0 and v.is_inventory_voucher = 0 and v.date < @fromDate 10 | group by a.ledger 11 | ), 12 | tblcurr as 13 | ( 14 | select a.ledger 'ledger', 15 | sum(case when a.amount < 0 then abs(a.amount) else 0 end) 'debit', 16 | sum(case when a.amount > 0 then a.amount else 0 end) 'credit' 17 | from trn_accounting a 18 | join trn_voucher v on v.guid = a.guid 19 | where v.is_order_voucher = 0 and v.is_inventory_voucher = 0 and v.date between @fromDate and @toDate 20 | group by a.ledger 21 | ) 22 | select l.name, 23 | (case when l.is_revenue = 0 then (l.opening_balance + isnull(op.amount,0)) else 0 end) 'opening', 24 | isnull(curr.debit,0) 'debit', 25 | isnull(curr.credit,0) 'credit', 26 | (case when l.is_revenue = 0 then (l.opening_balance + isnull(op.amount,0)) + isnull(curr.credit,0) - isnull(curr.debit,0) else isnull(curr.credit,0) - isnull(curr.debit,0) end) 'closing' 27 | from mst_ledger l 28 | left join tblop op on op.ledger = l.name 29 | left join tblcurr curr on curr.ledger = l.name 30 | order by l.name 31 | ; -------------------------------------------------------------------------------- /run-gui.bat: -------------------------------------------------------------------------------- 1 | node ./dist/server.mjs -------------------------------------------------------------------------------- /run.bat: -------------------------------------------------------------------------------- 1 | node ./dist/index.mjs -------------------------------------------------------------------------------- /src/definition.mts: -------------------------------------------------------------------------------- 1 | interface connectionConfig { 2 | technology: string; 3 | server: string; 4 | port: number; 5 | schema: string; 6 | ssl: boolean; 7 | username: string; 8 | password: string; 9 | loadmethod: string; 10 | } 11 | 12 | interface queryResult { 13 | rowCount: number; 14 | data: any[]; 15 | } 16 | 17 | interface tallyConfig { 18 | definition: string; 19 | server: string; 20 | port: number; 21 | fromdate: string; // [ YYYYMMDD / auto ] 22 | todate: string; // [ YYYYMMDD / auto ] 23 | sync: string; // [ full / incremental ] 24 | frequency: number; // in minutes 25 | company: string; 26 | } 27 | 28 | interface fieldConfigYAML { 29 | name: string; 30 | field: string; 31 | type: string; 32 | } 33 | 34 | interface tableFieldYAML { 35 | table: string; 36 | field: string; 37 | } 38 | 39 | interface tableConfigYAML { 40 | name: string; 41 | collection: string; 42 | nature: string; 43 | fields: fieldConfigYAML[]; 44 | filters?: string[]; 45 | fetch?: string[]; 46 | cascade_update?: tableFieldYAML[]; 47 | cascade_delete?: tableFieldYAML[]; 48 | } 49 | 50 | interface databaseFieldInfo { 51 | fieldName: string; 52 | dataType: string; 53 | isNullable: boolean; 54 | length?: number; 55 | precision?: number; 56 | scale?: number; 57 | } 58 | 59 | interface cdmFileFormatSetting { 60 | $type: string; 61 | columnHeaders: boolean; 62 | } 63 | 64 | interface cdmAttribute { 65 | name: string; 66 | dataType: string; 67 | } 68 | 69 | interface cdmPartition { 70 | name: string; 71 | location: string; 72 | fileFormatSettings: cdmFileFormatSetting; 73 | } 74 | 75 | interface cdmEntity { 76 | $type: string; 77 | name: string; 78 | attributes: cdmAttribute[]; 79 | partitions: cdmPartition[]; 80 | } 81 | 82 | interface cdmModel { 83 | name: string; 84 | version: string; 85 | entities: cdmEntity[]; 86 | } 87 | 88 | export { connectionConfig, queryResult, tallyConfig, fieldConfigYAML, tableFieldYAML, tableConfigYAML, databaseFieldInfo, cdmModel, cdmEntity, cdmPartition, cdmAttribute, cdmFileFormatSetting }; -------------------------------------------------------------------------------- /src/index.mts: -------------------------------------------------------------------------------- 1 | import process from 'process'; 2 | import { tally } from './tally.mjs'; 3 | import { database } from './database.mjs'; 4 | import { logger } from './logger.mjs' 5 | 6 | let isSyncRunning = false; 7 | let lastMasterAlterId = 0; 8 | let lastTransactionAlterId = 0; 9 | 10 | function parseCommandlineOptions(): Map { 11 | let retval = new Map(); 12 | try { 13 | let lstArgs = process.argv; 14 | 15 | if (lstArgs.length > 2 && lstArgs.length % 2 == 0) 16 | for (let i = 2; i < lstArgs.length; i += 2) { 17 | let argName = lstArgs[i]; 18 | let argValue = lstArgs[i + 1]; 19 | if (/^--\w+-\w+$/g.test(argName)) 20 | retval.set(argName.substr(2), argValue); 21 | } 22 | } catch (err) { 23 | logger.logError('index.substituteTDLParameters()', err); 24 | } 25 | return retval; 26 | } 27 | 28 | function invokeImport(): Promise { 29 | return new Promise(async (resolve) => { 30 | try { 31 | isSyncRunning = true; 32 | await tally.importData(); 33 | logger.logMessage('Import completed successfully [%s]', new Date().toLocaleString()); 34 | } 35 | catch (err) { 36 | logger.logMessage('Error in importing data\r\nPlease check error-log.txt file for detailed errors [%s]', new Date().toLocaleString()); 37 | } 38 | finally { 39 | isSyncRunning = false; 40 | resolve(); 41 | } 42 | }); 43 | } 44 | 45 | //Update commandline overrides to configuration options 46 | let cmdConfig = parseCommandlineOptions(); 47 | database.updateCommandlineConfig(cmdConfig); 48 | tally.updateCommandlineConfig(cmdConfig); 49 | 50 | 51 | if(tally.config.frequency <= 0) { // on-demand sync 52 | await invokeImport(); 53 | logger.closeStreams(); 54 | } 55 | else { // continuous sync 56 | const triggerImport = async () => { 57 | try { 58 | // skip if sync is already running (wait for next trigger) 59 | if(!isSyncRunning) { 60 | await tally.updateLastAlterId(); 61 | 62 | let isDataChanged = !(lastMasterAlterId == tally.lastAlterIdMaster && lastTransactionAlterId == tally.lastAlterIdTransaction); 63 | if(isDataChanged) { // process only if data is changed 64 | //update local variable copy of last alter ID 65 | lastMasterAlterId = tally.lastAlterIdMaster; 66 | lastTransactionAlterId = tally.lastAlterIdTransaction; 67 | await invokeImport(); 68 | } 69 | else { 70 | logger.logMessage('No change in Tally data found [%s]', new Date().toLocaleString()); 71 | } 72 | } 73 | } catch (err) { 74 | if(typeof err == 'string' && err.endsWith('is closed in Tally')) { 75 | logger.logMessage(err + ' [%s]', new Date().toLocaleString()); 76 | } 77 | else { 78 | throw err; 79 | } 80 | } 81 | } 82 | 83 | if(!tally.config.company) { // do not process continuous sync for blank company 84 | logger.logMessage('Continuous sync requires Tally company name to be specified in config.json'); 85 | } 86 | else { // go ahead with continuous sync 87 | setInterval(async () => await triggerImport(), tally.config.frequency * 60000); 88 | await triggerImport(); 89 | } 90 | } -------------------------------------------------------------------------------- /src/logger.mts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import util from 'util' 3 | import process from 'process'; 4 | import { utility } from './utility.mjs'; 5 | 6 | class _logger { 7 | 8 | private streamMessage: fs.WriteStream; 9 | private streamError: fs.WriteStream; 10 | private flgErrorLogged = false; 11 | 12 | constructor() { 13 | if (fs.existsSync('./import-log.txt')) 14 | fs.rmSync('./import-log.txt'); 15 | if (fs.existsSync('./error-log.txt')) 16 | fs.rmSync('./error-log.txt'); 17 | 18 | this.streamMessage = fs.createWriteStream('./import-log.txt', { encoding: 'utf-8' }); 19 | this.streamError = fs.createWriteStream('./error-log.txt', { encoding: 'utf-8' }); 20 | } 21 | 22 | logMessage(message: string, ...params: any[]): void { 23 | console.log(message, ...params); //graphical console 24 | this.streamMessage.write(util.format(message, ...params) + '\r\n'); 25 | 26 | if(process.send) { // GUI thread based invoke 27 | process.send(util.format(message, ...params) + '\r\n'); 28 | } 29 | } 30 | 31 | logError(fnInfo: string, err: any): void { 32 | if (!this.flgErrorLogged) { 33 | this.flgErrorLogged = true; 34 | let errorLog = ''; 35 | if (!fnInfo.endsWith(')')) 36 | fnInfo += '()'; 37 | errorLog += `Error from ${fnInfo} at ${utility.Date.format(new Date(), 'yyyy-MM-dd HH:mm:ss')}\r\n`; 38 | if (typeof err == 'string') 39 | errorLog += err + '\r\n'; 40 | else { 41 | let props = Object.getOwnPropertyNames(err); 42 | for (let i = 0; i < props.length; i++) { 43 | let propName = props[i]; 44 | let propValue = err[propName]; 45 | if (typeof propValue == 'string') 46 | errorLog += propValue + '\r\n'; 47 | } 48 | } 49 | errorLog += '-'.repeat(80) + '\r\n\r\n\r\n'; 50 | console.error(errorLog); //graphical console 51 | this.streamError.write(errorLog); 52 | } 53 | } 54 | 55 | closeStreams() { 56 | this.streamMessage.close(); 57 | this.streamError.close(); 58 | } 59 | } 60 | let logger = new _logger(); 61 | 62 | export { logger }; -------------------------------------------------------------------------------- /src/server.mts: -------------------------------------------------------------------------------- 1 | import http from 'http'; 2 | import fs from 'fs'; 3 | import child_process from 'child_process'; 4 | import { WebSocketServer } from 'ws'; 5 | import { connectionConfig, tallyConfig } from './definition.mjs'; 6 | 7 | const httpPort = 8997; 8 | const wsPort = 8998; 9 | 10 | let isSyncRunning = false; 11 | let syncProcess: child_process.ChildProcess | undefined = undefined 12 | 13 | const wsServer = new WebSocketServer({ 14 | port: wsPort 15 | }); 16 | 17 | function configObjectToCommandLineArr(obj: any): string[] { 18 | let retval = []; 19 | let databaseObj: connectionConfig = obj['database']; 20 | let tallyObj: tallyConfig = obj['tally']; 21 | for(const [key, val] of Object.entries(databaseObj)) { 22 | retval.push('--database-' + key); 23 | retval.push(val); 24 | } 25 | for(const [key, val] of Object.entries(tallyObj)) { 26 | retval.push('--tally-' + key); 27 | retval.push(val); 28 | } 29 | return retval; 30 | } 31 | 32 | function runSyncProcess(configObj: any) { 33 | let cmdArgs = configObjectToCommandLineArr(configObj); 34 | syncProcess = child_process.fork('./dist/index.mjs', cmdArgs); 35 | syncProcess.on('message', (msg) => wsServer.clients.forEach((wsClient) => wsClient.send(msg.toString()))); 36 | syncProcess.on('close', () => { 37 | isSyncRunning = false; 38 | wsServer.clients.forEach((wsClient) => wsClient.send('~')); 39 | }); 40 | } 41 | 42 | function postTallyXML(tallyServer: string, tallyPort: number, payload: string): Promise { 43 | return new Promise((resolve, reject) => { 44 | try { 45 | let req = http.request({ 46 | hostname: tallyServer, 47 | port: tallyPort, 48 | path: '', 49 | method: 'POST', 50 | headers: { 51 | 'Content-Length': Buffer.byteLength(payload, 'utf16le'), 52 | 'Content-Type': 'text/xml;charset=utf-16' 53 | } 54 | }, 55 | (res) => { 56 | let data = ''; 57 | res 58 | .setEncoding('utf16le') 59 | .on('data', (chunk) => { 60 | let result = chunk.toString() || ''; 61 | data += result; 62 | }) 63 | .on('end', () => { 64 | resolve(data); 65 | }) 66 | .on('error', (httpErr) => { 67 | reject(httpErr); 68 | }); 69 | }); 70 | req.on('error', (reqError) => { 71 | reject(reqError); 72 | }); 73 | req.write(payload, 'utf16le'); 74 | req.end(); 75 | } catch (err) { 76 | reject(err); 77 | } 78 | }); 79 | }; 80 | 81 | const httpServer = http.createServer((req, res) => { 82 | 83 | let reqContent = ''; 84 | 85 | req.on('data', (chunk) => reqContent += chunk); 86 | 87 | req.on('end', async () => { 88 | 89 | let contentResp = ''; 90 | if (req.url == '/') { 91 | let fileContent = fs.readFileSync('./gui.html', 'utf8'); 92 | contentResp = fileContent; 93 | res.statusCode = 200; 94 | res.setHeader('Content-Type', 'text/html'); 95 | res.end(contentResp); 96 | return; 97 | } 98 | else if (req.url == '/loadconfig') { 99 | let fileContent = fs.readFileSync('./config.json', 'utf8'); 100 | contentResp = fileContent; 101 | res.setHeader('Content-Type', 'application/json'); 102 | } 103 | else if (req.url == '/saveconfig') { 104 | fs.writeFileSync('./config.json', reqContent, { encoding: 'utf8' }); 105 | contentResp = 'Config saved'; 106 | res.setHeader('Content-Type', 'text/plain'); 107 | } 108 | else if (req.url == '/sync') { 109 | let objConfig = JSON.parse(reqContent); 110 | if(isSyncRunning) { 111 | contentResp = 'Sync is already running'; 112 | } 113 | else { 114 | isSyncRunning = true; 115 | runSyncProcess(objConfig); 116 | contentResp = 'Sync started'; 117 | } 118 | res.setHeader('Content-Type', 'text/plain'); 119 | } 120 | else if (req.url == '/abort') { 121 | if(syncProcess) { 122 | syncProcess.kill(); 123 | contentResp = 'Process killed'; 124 | } 125 | else { 126 | contentResp = 'Could not kill process'; 127 | } 128 | res.setHeader('Content-Type', 'text/plain'); 129 | } 130 | else if (req.url == '/list-company') { 131 | const reqPayload = '
1ExportDataMyReportLedgerTable
$$SysName:XMLMyForm
MyPart01DATA
MyLine01MyLine01 : MyCollectionVerticalFld$NameROWCompany
'; 132 | let objConfig = JSON.parse(reqContent); 133 | let result = ''; 134 | try { 135 | result = await postTallyXML(objConfig['server'], objConfig['port'], reqPayload); 136 | } 137 | catch { 138 | result = ''; 139 | } 140 | contentResp = result; 141 | res.setHeader('Content-Type', 'text/xml'); 142 | } 143 | else if (req.url == '/tally-status') { 144 | let objConfig = JSON.parse(reqContent); 145 | try { 146 | let result = await postTallyXML(objConfig['server'], objConfig['port'], ''); 147 | contentResp = result; 148 | } 149 | catch { 150 | contentResp = ''; 151 | } 152 | res.setHeader('Content-Type', 'text/plain'); 153 | } 154 | else { 155 | res.writeHead(404); 156 | res.end(); 157 | return; 158 | } 159 | 160 | res.statusCode = 200; 161 | res.end(contentResp); 162 | }); 163 | }); 164 | 165 | httpServer.listen(httpPort, 'localhost', () => { 166 | console.log(`Server started on http://localhost:${httpPort}`); 167 | console.log('Launching utility GUI page on default browser...'); 168 | child_process.exec(`start http://localhost:${httpPort}`); 169 | setInterval(() => { //set timer to detect if webpage is open/closed via monitoring websocket clients 170 | if(wsServer.clients.size == 0 && !isSyncRunning) { 171 | console.log('No webpage connected. Closing utility...'); 172 | process.exit(0); //shutdown utility 173 | } 174 | }, 5000); 175 | }); 176 | 177 | 178 | -------------------------------------------------------------------------------- /src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "moduleResolution": "NodeNext", 5 | "target": "ES2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ 6 | "module": "NodeNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 7 | "outDir": "../dist", 8 | "rootDir": "./", 9 | "strict": true, 10 | "sourceMap": true /* Generates corresponding '.map' file. */ 11 | } 12 | } -------------------------------------------------------------------------------- /src/utility.mts: -------------------------------------------------------------------------------- 1 | //Utility (Javascript core functionality extension) 2 | 3 | const dateExpression = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/; 4 | const monthsShort: string[] = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 5 | const monthsLong: string[] = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 6 | const weeksShort: string[] = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; 7 | const weeksLong: string[] = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; 8 | const regexMonthsShort = 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec'; 9 | const regexMonthsLong = 'January|February|March|April|May|June|July|August|September|October|November|December'; 10 | const regexWeeksLong = 'Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday'; 11 | const regexWeeksShort = 'Sun|Mon|Tue|Wed|Thu|Fri|Sat'; 12 | 13 | class _utility { 14 | String = { 15 | 16 | /** 17 | * Strips last character from string 18 | */ 19 | strip(val: string, count = 1): string { 20 | return val.substr(0, val.length - count); 21 | }, 22 | 23 | insertAt(value: string, index: number, expr: string): string { 24 | if (index > value.length) index = value.length; 25 | var leftPart = value.substr(0, index); 26 | var rightPart = value.substr(index); 27 | var retval = leftPart + expr + rightPart; 28 | return retval; 29 | }, 30 | 31 | /** 32 | * Splits string on specific 33 | */ 34 | split(value: string, separator: string, removeEmpty = false): string[] { 35 | let e = value.replace(new RegExp(`${separator}{2}`, 'g'), '\x07'); //Replace double separator instances with special character 36 | let retval = e.split(separator); //split on the basis of separator 37 | for (let i = 0; i < retval.length; i++) //Substitute special character with single separator instance 38 | retval[i] = retval[i].replace(/\x07/g, separator); 39 | 40 | if (removeEmpty) //Remove empty splits (if asked for) 41 | for (let i = retval.length - 1; i >= 0; i--) 42 | if (!retval[i]) 43 | retval.splice(i, 1); 44 | 45 | return retval; 46 | }, 47 | 48 | escapeHTML(unsafe: string): string { 49 | return unsafe 50 | .replace(/&/g, "&") 51 | .replace(//g, ">") 53 | .replace(/"/g, """) 54 | .replace(/'/g, "'"); 55 | } 56 | } 57 | 58 | Number = { 59 | 60 | format(value: number, mask: string): string { 61 | 62 | 63 | function formatNumber(mask: string, value: number): string { 64 | let retval = ''; //Return value 65 | let i, j; 66 | let indexDecimalPoint = mask.indexOf('.'); //dot position (if any) 67 | let mskInteger = indexDecimalPoint === -1 ? mask : mask.substr(0, indexDecimalPoint); //Extract integer part of mask 68 | let mskFraction = indexDecimalPoint === -1 ? '' : mask.substr(indexDecimalPoint + 1, mask.length - indexDecimalPoint); //Extract fraction part of mask 69 | let flgZero = false, flgHash = false, flgComma = false, flgDecimal = false; 70 | for (i = 0; i < mskInteger.length; i++) { //Validate mask 71 | let c = mskInteger.charAt(i); 72 | if (c === '.') { //decimal 73 | if (flgDecimal) return ''; //There cannot be two decimal places 74 | if (flgComma) return ''; //Comma cannot preceed decimal 75 | flgDecimal = true; //flag that decimal point has been detected 76 | } 77 | else if (c === ',') { //comma 78 | if (flgComma) return ''; //There cannot be two consecutive commas 79 | if (flgDecimal) return ''; //Fraction portion cannot contain comma 80 | flgComma = true; 81 | } 82 | else if (c === '#') { //hash 83 | if (flgDecimal) return ''; //Fraction portion cannot have hash 84 | if (flgZero) return ''; //Hash cannot appear after Zeros 85 | flgHash = true; //flag that has has been detected 86 | flgComma = false; //reset comma detection 87 | } 88 | else { //zero 89 | flgZero = true; //flag that zero has been detected 90 | flgComma = true; //reset comma detection 91 | } 92 | } 93 | 94 | let numSign = Math.sign(value); 95 | let val = Math.abs(value); //Remove number sign for formatting 96 | let numInteger = Math.trunc(val); //Extract integer portion of number 97 | let numFraction = val - numInteger; //Extract fraction portion of number 98 | let numIntegerFixedCount = mskInteger.replace(/[#,]+/g, '').length; //number of fixed digits to show on integer part 99 | let numIntegerTotalCount = mskInteger.replace(/[,]+/g, '').length; //total number of formatted digits to show on integer part 100 | let numIntegerDigitCount = Math.floor(Math.log10(numInteger)) + 1; //total number of unformatted digits to show on integer part 101 | if (!Number.isFinite(numIntegerDigitCount)) numIntegerDigitCount = 1; //Zero to be handled as single digit 102 | retval = numInteger.toString(); //First convert integer part to string 103 | if (numIntegerDigitCount > numIntegerTotalCount) //Pad extra has to the left (if mask falls short) 104 | mskInteger = '#'.repeat(numIntegerDigitCount - numIntegerTotalCount) + mskInteger; 105 | if (numIntegerDigitCount < numIntegerTotalCount) //Pad extra zeros to the left (if required) 106 | retval = '0'.repeat(numIntegerTotalCount - numIntegerDigitCount) + retval; 107 | 108 | 109 | //Format integer part with comma mask 110 | for (i = 0; i < mskInteger.length; i++) 111 | if (mskInteger.charAt(i) === ',') 112 | retval = utility.String.insertAt(retval, i, ','); 113 | 114 | //Remove extra zeros from left as per mask 115 | let stripCount = 0; 116 | for (i = 0; i < mskInteger.length; i++) { 117 | let cInteger = retval.charCodeAt(i); //ASCII value of number index 118 | let chMask = mskInteger[i]; //Character at mask index 119 | if (chMask === '0' || (chMask === '#' && cInteger > 48)) 120 | break; 121 | else 122 | stripCount++; 123 | } 124 | 125 | retval = retval.substr(stripCount, retval.length - stripCount); 126 | if (mskFraction.length) retval += '.' + numFraction.toFixed(mskFraction.length).substr(2); 127 | return retval; 128 | }; 129 | 130 | 131 | 132 | 133 | let sign = Math.sign(value); 134 | value = Math.abs(value); 135 | if (mask.includes(';')) { //Handle positive-negative-neutral 136 | let parts = mask.split(';'); 137 | if (sign == 1) mask = parts[0]; 138 | else if (sign == -1) mask = parts[1]; 139 | else mask = parts.length == 3 ? parts[2] : parts[0]; 140 | } 141 | 142 | //Extract prefix-suffix-mask 143 | let prefix = '', suffix = ''; 144 | let maskParts = /([#,0\.]+)/g.exec(mask); 145 | if (maskParts) { 146 | prefix = mask.substr(0, maskParts.index) || ''; 147 | suffix = mask.substr(maskParts.index + maskParts[1].length) || ''; 148 | mask = maskParts[1]; 149 | } 150 | 151 | 152 | let replacedValue = formatNumber(mask, value); 153 | let retval = prefix + replacedValue + suffix; 154 | 155 | return retval; 156 | }, 157 | 158 | round(value: number, precision: number = 0): number { 159 | if (!value) return 0; 160 | let _value = value * Math.pow(10, precision); 161 | if (_value - Math.trunc(_value) > 0.5) 162 | _value = Math.trunc(_value) + 1; 163 | else 164 | _value = Math.trunc(_value); 165 | return _value / Math.pow(10, precision); 166 | } 167 | } 168 | 169 | Date = { 170 | 171 | /** 172 | * Returns today's date without time value 173 | */ 174 | today(): Date { 175 | let today = new Date(); //Calculate milliseconds elapsed till this moment 176 | return new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0, 0); 177 | }, 178 | 179 | /** 180 | * Calculates date with desired difference (in milli-senconds) 181 | * @param dt Target date to add/subtract difference 182 | * @param ms Milli-seconds to add/substract 183 | */ 184 | diff(dt: Date, ms: number): Date { 185 | let retval = dt.valueOf(); //Calculate milliseconds elapsed till this moment 186 | retval += ms; //Add(-Subtract) milliseconds 187 | return new Date(retval); 188 | }, 189 | 190 | dateReviver(key: any, value: any): any { 191 | if (typeof value === 'string' && dateExpression.test(value)) 192 | return new Date(value); 193 | return value; 194 | }, 195 | 196 | format(value: Date, mask: string): string { 197 | let vDay = value.getDate(); 198 | let vMonth = value.getMonth(); 199 | let vYear = value.getFullYear(); 200 | let vWeek = value.getDay(); 201 | let vHour = value.getHours(); 202 | let vMinute = value.getMinutes(); 203 | let vSecond = value.getSeconds(); 204 | 205 | //Year replacement 206 | if (/yyyy/.test(mask)) mask = mask.replace('yyyy', vYear.toString()); 207 | else if (/yy/.test(mask)) mask = mask.replace('yy', vYear.toString().substr(2, 3)); 208 | else; 209 | 210 | //Month replacement 211 | if (/MMMM/.test(mask)) mask = mask.replace('MMMM', monthsLong[vMonth]); 212 | else if (/MMM/.test(mask)) mask = mask.replace('MMM', monthsShort[vMonth]); 213 | else if (/MM/.test(mask)) mask = mask.replace('MM', (vMonth + 1).toString().padStart(2, '0')); 214 | else if (/M/.test(mask)) mask = mask.replace('M', (vMonth + 1).toString()); 215 | else; 216 | 217 | //Day replacement 218 | if (/dddd/.test(mask)) mask = mask.replace('dddd', weeksLong[vWeek]); 219 | else if (/ddd/.test(mask)) mask = mask.replace('ddd', weeksShort[vWeek]); 220 | else if (/dd/.test(mask)) mask = mask.replace('dd', vDay.toString().padStart(2, '0')); 221 | else if (/d/.test(mask)) mask = mask.replace('d', vDay.toString()); 222 | else; 223 | 224 | //Hour replacement 225 | if (/HH/.test(mask)) mask = mask.replace('HH', vHour.toString().padStart(2, '0')); 226 | else if (/H/.test(mask)) mask = mask.replace('H', vHour.toString()); 227 | else if (/hh/.test(mask)) mask = mask.replace('hh', (vHour % 12 ? 0 : vHour % 12).toString().padStart(2, '0')); 228 | else if (/h/.test(mask)) mask = mask.replace('h', (vHour % 12 ? 0 : vHour % 12).toString()); 229 | else; 230 | 231 | //Minute replacement 232 | if (/mm/.test(mask)) mask = mask.replace('mm', vMinute.toString().padStart(2, '0')); 233 | else if (/m/.test(mask)) mask = mask.replace('m', vMinute.toString()); 234 | else; 235 | 236 | //Second replacement 237 | if (/ss/.test(mask)) mask = mask.replace('ss', vSecond.toString().padStart(2, '0')); 238 | else if (/s/.test(mask)) mask = mask.replace('s', vSecond.toString()); 239 | else; 240 | 241 | //AM-PM replacement 242 | if (/tt/.test(mask)) mask = mask.replace('tt', Math.floor(vHour / 12) ? 'PM' : 'AM'); 243 | else; 244 | 245 | return mask; 246 | }, 247 | 248 | parse(value: string, format: string): Date | null { 249 | let vYear = 0, vMonth = 0, vDay = 0, vHour = 0, vMinute = 0, vSecond = 0; 250 | let parts: string[] = []; 251 | 252 | //Strip out format separators (if found) 253 | if (/[\:|\/|\.|\s|-]/.test(format)) { //Format separator found 254 | //Remove separator from values 255 | format = format.replace(/[\:|\/|\.|\s|-]/g, ''); 256 | value = value.replace(/[\:|\/|\.|\s|-]/g, ''); 257 | } 258 | 259 | //Extract date format parts 260 | parts = format.split(/(dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|HH|H|hh|h|mm|m|ss|s|tt|t)/g); 261 | for (let i = parts.length - 1; i >= 0; i--) //Remove empty parts 262 | if (!parts[i]) 263 | parts.splice(i, 1); 264 | 265 | //Construct regex expression to separate parts from value 266 | let regexValue = '^'; 267 | for (let i = 0; i < parts.length; i++) { 268 | let capExpr = parts[i]; 269 | if (capExpr == 'd') capExpr = '[1-9]|[1-2][0-9]|3[0-1]'; 270 | else if (capExpr == 'dd') capExpr = '0[1-9]|[1-2][0-9]|3[0-1]'; 271 | else if (capExpr == 'ddd') capExpr = regexWeeksShort; 272 | else if (capExpr == 'dddd') capExpr = regexWeeksLong; 273 | else if (capExpr == 'M') capExpr = '1[0-2]|[1-9]'; 274 | else if (capExpr == 'MM') capExpr = '0[1-9]|1[0-2]'; 275 | else if (capExpr == 'MMM') capExpr = regexMonthsShort; 276 | else if (capExpr == 'MMMM') capExpr = regexMonthsLong; 277 | else if (capExpr == 'yy') capExpr = '\\d{2}'; 278 | else if (capExpr == 'yyyy') capExpr = '\\d{4}'; 279 | else if (capExpr == 'H') capExpr = '[1-9]|1[0-9]|2[0-3]'; 280 | else if (capExpr == 'HH') capExpr = '0[0-9]|1[0-9]|2[0-3]'; 281 | else if (capExpr == 'h') capExpr = '[1-9]|1[0-2]'; 282 | else if (capExpr == 'hh') capExpr = '0[1-9]|1[0-2]'; 283 | else if (capExpr == 'm') capExpr = '[1-9]|[1-5][0-9]'; 284 | else if (capExpr == 'mm') capExpr = '[0-5][0-9]'; 285 | else if (capExpr == 's') capExpr = '[1-9]|[1-5][0-9]'; 286 | else if (capExpr == 'ss') capExpr = '[0-5][0-9]'; 287 | else if (capExpr == 'tt') capExpr = 'a\\.?m\\.?|A\\.?M\\.?'; 288 | else; 289 | regexValue += `(${capExpr})`; 290 | } 291 | regexValue += '$'; 292 | 293 | let partResult = new RegExp(regexValue, 'g').exec(value); 294 | if (!partResult) return null; 295 | if (partResult.length !== parts.length + 1) return null; //Regex group match gives original value as extra (so ignored) 296 | for (let i = 0; i < parts.length; i++) { 297 | let partFormat = parts[i]; 298 | let partValue = partResult[i + 1]; 299 | let val = parseInt(partValue); 300 | if (partFormat == 'd' || partFormat == 'dd') vDay = val; 301 | //else if (partFormat == 'ddd') vMonth = weeksShort.indexOf(partValue); 302 | //else if (partFormat == 'dddd') vMonth = weeksLong.indexOf(partValue); 303 | else if (partFormat == 'M' || partFormat == 'MM') vMonth = --val; 304 | else if (partFormat == 'MMM') vMonth = monthsShort.indexOf(partValue); 305 | else if (partFormat == 'MMMM') vMonth = monthsLong.indexOf(partValue); 306 | else if (partFormat == 'yy' || partFormat == 'yyyy') vYear = val; 307 | else if (partFormat == 'H' || partFormat == 'HH') vHour = val; 308 | //else if (partFormat == 'h' || partFormat == 'hh') vHour = val; //am-pm handling to be impleamented 309 | else if (partFormat == 'm' || partFormat == 'mm') vMinute = val; 310 | else if (partFormat == 's' || partFormat == 'ss') vSecond = val; 311 | else; 312 | } 313 | 314 | //2 digit year handling 315 | if (vYear < 100) 316 | vYear += vYear > 71 ? 1900 : 2000; //upto 70 in 1900 centurary 317 | 318 | return new Date(vYear, vMonth, vDay, vHour, vMinute, vSecond); 319 | } 320 | } 321 | 322 | Object = { 323 | copyPropertyValues(source: any, target: any): void { 324 | let lstProp = Object.getOwnPropertyNames(source); 325 | for (let i = 0; i < lstProp.length; i++) 326 | target[lstProp[i]] = source[lstProp[i]]; 327 | } 328 | } 329 | 330 | Array = { 331 | distinct(source: any[], field: string): any[] { 332 | let retval: any[] = []; 333 | for (let i = 0; i < source.length; i++) 334 | if (!retval.includes(source[i][field])) 335 | retval.push(source[i][field]); 336 | 337 | return retval; 338 | }, 339 | unique(arr: T[], prop: K): T[] { 340 | let retval: T[] = []; 341 | for (let i = 0; i < arr.length; i++) 342 | if (retval.findIndex(p => p[prop] === arr[i][prop]) == -1) 343 | retval.push(arr[i]); 344 | return retval; 345 | } 346 | } 347 | } 348 | let utility = new _utility(); //Create singleton instance of class 349 | 350 | export { utility }; //Export singleton instance of class --------------------------------------------------------------------------------