├── .env.example ├── .eslintrc.json ├── .github ├── dependabot.yml └── workflows │ └── auto-merge.yml ├── .gitignore ├── LICENSE ├── README.md ├── database └── db.sql ├── package-lock.json ├── package.json ├── public ├── css │ ├── style.css │ └── styles.css ├── images │ └── logo.png ├── js │ ├── datatables.js │ ├── html5-qrcode.js │ ├── printQR.js │ └── select2.js └── uploads │ ├── 1674063981511.png │ ├── 1674064027186.png │ ├── 1674064184226.jpeg │ ├── 1674064230911.jpg │ ├── 1674064267657.jpg │ ├── 1674078883777.png │ ├── 1674078966925.jpg │ ├── ACDB1452.png │ ├── ACVE3142.png │ ├── ADDE1324.png │ ├── ALCM3917.png │ ├── RLMXP8042.png │ ├── VWEE2311.png │ └── VWVE1425.png ├── scripts └── setup-db.js └── src ├── app.js ├── config └── database.js ├── controllers ├── accountController.js ├── authController.js ├── barangController.js ├── barangKeluarController.js ├── barangMasukController.js ├── dashboardController.js ├── logController.js └── usersController.js ├── queries ├── barangKeluarQuery.js ├── barangMasukQuery.js ├── logQuery.js ├── stockBarangQuery.js └── usersQuery.js ├── routes ├── accountRoutes.js ├── authRoutes.js ├── barangKeluarRoutes.js ├── barangMasukRoutes.js ├── barangRoutes.js ├── dashboardRoutes.js ├── logRoutes.js └── usersRoutes.js ├── server.js └── views ├── 401.ejs ├── 404.ejs ├── account.ejs ├── barang.ejs ├── barangDetail.ejs ├── barangKeluar.ejs ├── barangMasuk.ejs ├── index.ejs ├── log.ejs ├── login.ejs ├── partials ├── footer.ejs ├── header.ejs └── nav.ejs └── users.ejs /.env.example: -------------------------------------------------------------------------------- 1 | # Server configuration 2 | HOSTNAME=localhost 3 | PORT=3000 4 | 5 | # Postgres connection 6 | PGUSER=postgres 7 | PGPASSWORD=root 8 | PGDATABASE=siib # 'setup-db' script will create the database 9 | PGHOST=localhost 10 | PGPORT=5432 -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "commonjs": true, 4 | "es2021": true, 5 | "node": true 6 | }, 7 | "extends": [ 8 | "airbnb-base" 9 | ], 10 | "parserOptions": { 11 | "ecmaVersion": 12 12 | }, 13 | "rules": { 14 | "no-console": "off" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | schedule: 11 | interval: "weekly" 12 | target-branch: "dev" 13 | - package-ecosystem: "npm" # See documentation for possible values 14 | directory: "/" # Location of package manifests 15 | schedule: 16 | interval: "daily" 17 | target-branch: "dev" 18 | -------------------------------------------------------------------------------- /.github/workflows/auto-merge.yml: -------------------------------------------------------------------------------- 1 | name: auto-merge 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | auto-merge: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - uses: ahmadnassri/action-dependabot-auto-merge@v2.6.6 12 | with: 13 | target: minor 14 | github-token: ${{ secrets.mytoken }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | # dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sistem Informasi Inventaris Barang 2 | 3 | An inventory management application. This is my final project for WGS Bootcamp Batch 4. 4 | 5 | ## Table of Contents 6 | 7 | - [First Time Setup](#first-time-setup) 8 | - [Prerequisite](#prerequisite) 9 | - [Installation](#installation) 10 | - [Running Locally](#running-locally) 11 | - [Main Features](#main-features) 12 | - [Screenshots](#screenshots) 13 | - [Dashboard](#dashboard) 14 | - [Table](#table) 15 | - [Print QR Code](#print-qr-code) 16 | - [Scan QR Code](#scan-qr-code) 17 | - [Dark Mode](#dark-mode) 18 | - [License](#license) 19 | 20 | ## First Time Setup 21 | 22 | ### Prerequisite 23 | 24 | - [Git](https://git-scm.com/downloads) 25 | - [Node](https://nodejs.org/en/download/current) 26 | - [PostgreSQL](https://www.postgresql.org/download/) 27 | 28 | Make sure your system PATH includes Postgres tools. For Windows, [see instructions here](https://www.commandprompt.com/education/how-to-set-windows-path-for-postgres-tools/). 29 | 30 | ### Installation 31 | 32 | 1. Clone the repository: 33 | 34 | ```bash 35 | git clone https://github.com/savareyhano/Sistem-Informasi-Inventaris-Barang.git 36 | ``` 37 | 38 | 2. Navigate to the project directory: 39 | 40 | ```bash 41 | cd Sistem-Informasi-Inventaris-Barang 42 | ``` 43 | 44 | 3. Create a `.env` file (further configuration needed to match your Postgres database settings): 45 | 46 | ```bash 47 | cp .env.example .env 48 | ``` 49 | 50 | 4. Install the dependencies: 51 | 52 | ```bash 53 | npm install 54 | ``` 55 | 56 | 5. Create the database: 57 | 58 | ```bash 59 | npm run setup-db 60 | ``` 61 | 62 | ## Running Locally 63 | 64 | 1. Start the project: 65 | 66 | ```bash 67 | npm start 68 | ``` 69 | 70 | 2. Visit [http://localhost:3000](http://localhost:3000) (this may vary depending on the `HOSTNAME` and `PORT` values you set in the `.env` file). 71 | 72 | 3. Login with the following credentials: 73 | 74 | | email | password | role | 75 | |---|---|---| 76 | | superadmin@email.com | superadmin123 | superadmin | 77 | | admin@email.com | admin123 | superadmin | 78 | | user@email.com | password | user | 79 | | usr@email.com | password | user | 80 | 81 | ## Main Features 82 | 83 | - **Integrated Bulk QR Code Generator**: Enables the creation of QR codes in bulk for selected items, complete with customization options for resizing and printing. 84 | - **Versatile QR Code Scanner**: Offers the ability to scan QR codes using webcam devices or by uploading images. 85 | 86 | ## Screenshots 87 | 88 | ### Dashboard 89 | 90 | ![Dashboard](https://user-images.githubusercontent.com/32730327/273454645-93f713e4-ae39-46f9-8557-5403794b8104.png) 91 | 92 | ### Table 93 | 94 | ![Table](https://user-images.githubusercontent.com/32730327/273454711-420e7794-6de7-4a96-bd93-51c745c4e983.png) 95 | 96 | ### Print QR Code 97 | 98 | ![Print QR](https://user-images.githubusercontent.com/32730327/279402658-b86975e8-857c-46ee-9fa6-0501d59afde6.png) 99 | 100 | ### Scan QR Code 101 | 102 | ![Scan QR1](https://user-images.githubusercontent.com/32730327/273454801-d9c2f9e0-5ee1-4708-8283-656e787ce9f2.png) 103 | ![Scan QR2](https://user-images.githubusercontent.com/32730327/273454805-ca0edc90-de09-4def-a2fa-9fa7cfe7dfb0.png) 104 | 105 | ### Dark Mode 106 | 107 | ![Dark Mode](https://user-images.githubusercontent.com/32730327/273454814-4f1d843c-59bf-4469-bb28-92ebf73f9caa.png) 108 | 109 | ## License 110 | 111 | This project is licensed under the [GNU General Public License v3.0](https://github.com/savareyhano/Sistem-Informasi-Inventaris-Barang/blob/main/LICENSE). 112 | -------------------------------------------------------------------------------- /database/db.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/database/db.sql -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sistem-informasi-inventaris-barang", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node src/server.js", 8 | "start:dev": "nodemon src/server.js", 9 | "lint": "eslint ./src", 10 | "lint:fix": "eslint ./src --fix", 11 | "setup-db": "node scripts/setup-db.js" 12 | }, 13 | "keywords": [], 14 | "author": "Sava Reyhano", 15 | "license": "ISC", 16 | "dependencies": { 17 | "admin-lte": "3.2", 18 | "bcrypt": "^5.1.0", 19 | "canvas": "^2.11.0", 20 | "cookie-session": "^2.0.0", 21 | "dotenv": "^16.3.1", 22 | "ejs": "^3.1.10", 23 | "express": "^4.18.2", 24 | "express-validator": "^7.0.1", 25 | "html5-qrcode": "^2.3.4", 26 | "jsbarcode": "^3.11.5", 27 | "method-override": "^3.0.0", 28 | "moment": "^2.29.4", 29 | "morgan": "^1.10.0", 30 | "multer": "^1.4.5-lts.1", 31 | "pg": "^8.8.0", 32 | "pgtools": "^1.0.1", 33 | "qrcode": "^1.5.1" 34 | }, 35 | "devDependencies": { 36 | "eslint": "^8.57.0", 37 | "eslint-config-airbnb-base": "^15.0.0", 38 | "eslint-plugin-import": "^2.29.1", 39 | "nodemon": "^3.0.1" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /public/css/style.css: -------------------------------------------------------------------------------- 1 | .zoomable { 2 | width: 100%; 3 | max-width: 100px; 4 | max-height: 100px; 5 | } 6 | 7 | .zoomable:hover { 8 | transform: scale(2.5); 9 | transition: 0.32s ease; 10 | } 11 | 12 | .img-detail { 13 | width: 100%; 14 | max-width: 250px; 15 | max-height: 250px; 16 | } 17 | 18 | select:required:invalid { 19 | color: gray; 20 | } 21 | option[value=""][disabled] { 22 | display: none; 23 | } 24 | option { 25 | color: black; 26 | } -------------------------------------------------------------------------------- /public/css/styles.css: -------------------------------------------------------------------------------- 1 | *{ 2 | transition: all 0.6s; 3 | } 4 | 5 | html { 6 | height: 100%; 7 | } 8 | 9 | body{ 10 | font-family: 'Lato', sans-serif; 11 | color: #888; 12 | margin: 0; 13 | } 14 | 15 | #main{ 16 | display: table; 17 | width: 100%; 18 | height: 100vh; 19 | text-align: center; 20 | } 21 | 22 | .fof{ 23 | display: table-cell; 24 | vertical-align: middle; 25 | } 26 | 27 | .fof h1{ 28 | font-size: 50px; 29 | display: inline-block; 30 | padding-right: 12px; 31 | animation: type .5s alternate infinite; 32 | } 33 | 34 | @keyframes type{ 35 | from{box-shadow: inset -3px 0px 0px #888;} 36 | to{box-shadow: inset -3px 0px 0px transparent;} 37 | } -------------------------------------------------------------------------------- /public/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/images/logo.png -------------------------------------------------------------------------------- /public/js/datatables.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | $(() => { 3 | $('#stokbarang') 4 | .DataTable({ 5 | responsive: true, 6 | // "lengthChange": false, 7 | autoWidth: false, 8 | dom: 9 | "B<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>>" 10 | + "<'row'<'col-sm-12'tr>>" 11 | + "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", 12 | buttons: [ 13 | // "copy", 14 | // "csv", 15 | // "excel", 16 | // "pdf", 17 | { 18 | extend: 'print', 19 | customize: (win) => { 20 | $(win.document.body).css('height', 'auto').css('min-height', '0'); 21 | }, 22 | exportOptions: { 23 | stripHtml: false, 24 | columns: [0, 1, 2, 3, 4, 5, 6], 25 | }, 26 | }, 27 | // "colvis" 28 | ], 29 | initComplete() { 30 | $('.buttons-print').html(' Cetak '); 31 | }, 32 | }) 33 | .buttons() 34 | .container() 35 | .appendTo('#bt'); 36 | $('#barangmasuk') 37 | .DataTable({ 38 | responsive: true, 39 | // "lengthChange": false, 40 | autoWidth: false, 41 | dom: 42 | "B<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>>" 43 | + "<'row'<'col-sm-12'tr>>" 44 | + "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", 45 | buttons: [ 46 | // "copy", 47 | // "csv", 48 | // "excel", 49 | // "pdf", 50 | { 51 | extend: 'print', 52 | customize: (win) => { 53 | $(win.document.body).css('height', 'auto').css('min-height', '0'); 54 | }, 55 | exportOptions: { 56 | stripHtml: false, 57 | columns: [0, 1, 2, 3, 4, 5, 6], 58 | }, 59 | }, 60 | // "colvis" 61 | ], 62 | initComplete() { 63 | $('.buttons-print').html(' Cetak '); 64 | }, 65 | }) 66 | .buttons() 67 | .container() 68 | .appendTo('#bt'); 69 | $('#barangkeluar') 70 | .DataTable({ 71 | responsive: true, 72 | // "lengthChange": false, 73 | autoWidth: false, 74 | dom: 75 | "B<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>>" 76 | + "<'row'<'col-sm-12'tr>>" 77 | + "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", 78 | buttons: [ 79 | // "copy", 80 | // "csv", 81 | // "excel", 82 | // "pdf", 83 | { 84 | extend: 'print', 85 | customize: (win) => { 86 | $(win.document.body).css('height', 'auto').css('min-height', '0'); 87 | }, 88 | exportOptions: { 89 | stripHtml: false, 90 | columns: [0, 1, 2, 3, 4, 5, 6], 91 | }, 92 | }, 93 | // "colvis" 94 | ], 95 | initComplete() { 96 | $('.buttons-print').html(' Cetak '); 97 | }, 98 | }) 99 | .buttons() 100 | .container() 101 | .appendTo('#bt'); 102 | $('#user').DataTable({ 103 | responsive: true, 104 | // "lengthChange": false, 105 | autoWidth: false, 106 | }); 107 | $('#log').DataTable({ 108 | responsive: true, 109 | // "lengthChange": false, 110 | autoWidth: false, 111 | }); 112 | $('#detailbarangmasuk').DataTable({ 113 | paging: true, 114 | lengthChange: false, 115 | searching: false, 116 | ordering: true, 117 | info: true, 118 | autoWidth: false, 119 | responsive: true, 120 | }); 121 | $('#detailbarangkeluar').DataTable({ 122 | paging: true, 123 | lengthChange: false, 124 | searching: false, 125 | ordering: true, 126 | info: true, 127 | autoWidth: false, 128 | responsive: true, 129 | }); 130 | }); 131 | -------------------------------------------------------------------------------- /public/js/html5-qrcode.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | /* eslint-disable no-undef */ 3 | function select2Search($el, term) { 4 | $el.select2('open'); 5 | 6 | // Get the search box within the dropdown or the selection 7 | // Dropdown = single, Selection = multiple 8 | const $search = $el.data('select2').dropdown.$search 9 | || $el.data('select2').selection.$search; 10 | // This is undocumented and may change in the future 11 | 12 | $search.val(term); 13 | $search.trigger('input'); 14 | } 15 | 16 | function onScanSuccess(decodedText) { 17 | // handle the scanned code as you like, for example: 18 | // console.log(`Code matched = ${decodedText}`, decodedResult); 19 | if (document.getElementById('html5-qrcode-button-camera-stop')) { 20 | document.getElementById('html5-qrcode-button-camera-stop').click(); 21 | } 22 | const $select = $($('#barang')); 23 | select2Search($select, decodedText); 24 | } 25 | 26 | function onScanFailure(error) { 27 | // handle scan failure, usually better to ignore and keep scanning. 28 | // for example: 29 | console.warn(`Code scan error = ${error}`); 30 | } 31 | 32 | const html5QrcodeScanner = new Html5QrcodeScanner( 33 | 'reader', 34 | { 35 | fps: 10, 36 | qrbox: { width: 250, height: 250 }, 37 | rememberLastUsedCamera: false, 38 | }, 39 | /* verbose= */ false, 40 | ); 41 | html5QrcodeScanner.render(onScanSuccess, onScanFailure); 42 | 43 | function stopScan() { 44 | if (document.getElementById('html5-qrcode-button-camera-stop')) { 45 | document.getElementById('html5-qrcode-button-camera-stop').click(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /public/js/printQR.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | /* eslint-disable no-unused-vars */ 3 | function checkSizeValue(input) { 4 | const inputValue = input; 5 | if (inputValue.value <= inputValue.min) { 6 | inputValue.value = inputValue.min; 7 | } 8 | } 9 | 10 | function checkQtyValue(input) { 11 | const inputValue = input; 12 | if (inputValue.value <= inputValue.min) { 13 | inputValue.value = inputValue.min; 14 | } 15 | } 16 | 17 | function ImagetoPrint(source, title) { 18 | return ( 19 | `${title}\n${ 23 | source 24 | }` 25 | ); 26 | } 27 | 28 | function PrintImage(source, id, title) { 29 | const pagelink = 'about:blank'; 30 | const qty = $(`#qrQty${id}`).val(); 31 | const pixelToCentimeter = 37.7952755906; 32 | const width = $(`#qrWidth${id}`).val() * pixelToCentimeter; 33 | const height = $(`#qrHeight${id}`).val() * pixelToCentimeter; 34 | const pwa = window.open(pagelink, '_new'); 35 | let img = ''; 36 | for (let i = 1; i <= qty; i += 1) { 37 | img += ``; 38 | } 39 | pwa.document.open(); 40 | pwa.document.write(ImagetoPrint(img, title)); 41 | pwa.document.close(); 42 | } 43 | -------------------------------------------------------------------------------- /public/js/select2.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | $('.select2bs4').select2({ 3 | theme: 'bootstrap4', 4 | }); 5 | -------------------------------------------------------------------------------- /public/uploads/1674063981511.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/1674063981511.png -------------------------------------------------------------------------------- /public/uploads/1674064027186.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/1674064027186.png -------------------------------------------------------------------------------- /public/uploads/1674064184226.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/1674064184226.jpeg -------------------------------------------------------------------------------- /public/uploads/1674064230911.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/1674064230911.jpg -------------------------------------------------------------------------------- /public/uploads/1674064267657.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/1674064267657.jpg -------------------------------------------------------------------------------- /public/uploads/1674078883777.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/1674078883777.png -------------------------------------------------------------------------------- /public/uploads/1674078966925.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/1674078966925.jpg -------------------------------------------------------------------------------- /public/uploads/ACDB1452.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/ACDB1452.png -------------------------------------------------------------------------------- /public/uploads/ACVE3142.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/ACVE3142.png -------------------------------------------------------------------------------- /public/uploads/ADDE1324.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/ADDE1324.png -------------------------------------------------------------------------------- /public/uploads/ALCM3917.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/ALCM3917.png -------------------------------------------------------------------------------- /public/uploads/RLMXP8042.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/RLMXP8042.png -------------------------------------------------------------------------------- /public/uploads/VWEE2311.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/VWEE2311.png -------------------------------------------------------------------------------- /public/uploads/VWVE1425.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savareyhano/sistem-informasi-inventaris-barang/ceb48b6284827e8e68f3b1fb212beaef6d35dccf/public/uploads/VWVE1425.png -------------------------------------------------------------------------------- /scripts/setup-db.js: -------------------------------------------------------------------------------- 1 | const { createdb, dropdb } = require('pgtools'); 2 | const { exec } = require('child_process'); 3 | require('dotenv').config(); 4 | const readline = require('readline').createInterface({ 5 | input: process.stdin, 6 | output: process.stdout, 7 | }); 8 | 9 | const config = { 10 | user: process.env.PGUSER, 11 | password: process.env.PGPASSWORD, 12 | host: process.env.PGHOST, 13 | port: process.env.PGPORT, 14 | }; 15 | 16 | const databaseName = process.env.PGDATABASE; 17 | const dumpFilePath = './database/db.sql'; 18 | 19 | class DatabaseError extends Error { 20 | constructor(message) { 21 | super(message); 22 | this.name = this.constructor.name; 23 | } 24 | } 25 | 26 | async function createDatabase() { 27 | try { 28 | await createdb(config, databaseName); 29 | } catch (error) { 30 | throw new DatabaseError(`Error creating database: ${error}`); 31 | } 32 | } 33 | 34 | async function restoreDatabase() { 35 | return new Promise((resolve, reject) => { 36 | const restoreCommand = `pg_restore -U ${config.user} -d ${databaseName} -v ${dumpFilePath}`; 37 | 38 | exec( 39 | restoreCommand, 40 | { env: { PGPASSWORD: config.password } }, 41 | (error) => { 42 | if (error) { 43 | reject(new DatabaseError(`Error restoring database: ${error}`)); 44 | } else { 45 | console.log('Database restored successfully'); 46 | resolve(); 47 | } 48 | }, 49 | ); 50 | }); 51 | } 52 | 53 | async function dropDatabase() { 54 | try { 55 | await dropdb(config, databaseName); 56 | } catch (error) { 57 | throw new DatabaseError(`Error dropping database: ${error}`); 58 | } 59 | } 60 | 61 | async function setupDatabase() { 62 | try { 63 | await createDatabase(); 64 | await restoreDatabase(); 65 | process.exit(0); 66 | } catch (error) { 67 | if ( 68 | error instanceof DatabaseError 69 | && error.message.includes('duplicate_database') 70 | ) { 71 | readline.question( 72 | `Database ${process.env.PGDATABASE} already exists. Proceed with restoration? Existing data will be replaced. (Y/N) `, 73 | async (answer) => { 74 | if (answer.toLowerCase() === 'y') { 75 | try { 76 | await dropDatabase(); 77 | await createDatabase(); 78 | await restoreDatabase(); 79 | } catch (err) { 80 | console.error('Error setting up database:', err); 81 | } 82 | } else { 83 | console.log('Operation cancelled.'); 84 | } 85 | readline.close(); 86 | }, 87 | ); 88 | } else { 89 | console.error('Error setting up database:', error); 90 | process.exit(1); 91 | } 92 | } 93 | } 94 | 95 | setupDatabase(); 96 | -------------------------------------------------------------------------------- /src/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const methodOverride = require('method-override'); 3 | const cookieSession = require('cookie-session'); 4 | const crypto = require('crypto'); 5 | const path = require('path'); 6 | const morgan = require('morgan'); 7 | 8 | const log = require('./queries/logQuery'); 9 | 10 | const authRoutes = require('./routes/authRoutes'); 11 | const dashboardRoutes = require('./routes/dashboardRoutes'); 12 | const usersRoutes = require('./routes/usersRoutes'); 13 | const accountRoutes = require('./routes/accountRoutes'); 14 | const barangRoutes = require('./routes/barangRoutes'); 15 | const barangMasukRoutes = require('./routes/barangMasukRoutes'); 16 | const barangKeluarRoutes = require('./routes/barangKeluarRoutes'); 17 | const logRoutes = require('./routes/logRoutes'); 18 | 19 | const app = express(); 20 | 21 | app.set('view engine', 'ejs'); 22 | app.set('views', path.join(__dirname, 'views')); 23 | 24 | app.use(express.urlencoded({ extended: true })); 25 | app.use(methodOverride('_method')); 26 | app.use( 27 | cookieSession({ 28 | name: 'session', 29 | keys: [crypto.randomBytes(16).toString('hex')], 30 | maxAge: 24 * 60 * 60 * 1000, // 24 hours 31 | }), 32 | ); 33 | 34 | // Static files 35 | app.use('/css', express.static(path.join(__dirname, '../public/css'))); 36 | app.use('/js', express.static(path.join(__dirname, '../public/js'))); 37 | app.use('/uploads', express.static(path.join(__dirname, '../public/uploads'))); 38 | app.use('/images', express.static(path.join(__dirname, '../public/images'))); 39 | app.use('/plugins', express.static(path.join(__dirname, '../node_modules/admin-lte/plugins'))); 40 | app.use('/dist', express.static(path.join(__dirname, '../node_modules/admin-lte/dist'))); 41 | app.use('/node_modules', express.static(path.join(__dirname, '../node_modules'))); 42 | 43 | // Custom logger 44 | const custom = (tokens, req, res) => { 45 | if (req.session && req.session.user) { 46 | const user = req.session.user.email; 47 | const method = tokens.method(req, res); 48 | const endpoint = tokens.url(req, res); 49 | const statusCode = tokens.status(req, res); 50 | 51 | log.addLog(user, method, endpoint, statusCode); 52 | } 53 | return [ 54 | tokens.method(req, res), 55 | tokens.url(req, res), 56 | tokens.status(req, res), 57 | tokens.res(req, res, 'content-length'), 58 | '-', 59 | tokens['response-time'](req, res), 60 | 'ms', 61 | ].join(' '); 62 | }; 63 | 64 | app.use(morgan(custom)); 65 | 66 | app.use(authRoutes); 67 | app.use(dashboardRoutes); 68 | app.use(usersRoutes); 69 | app.use(accountRoutes); 70 | app.use(barangRoutes); 71 | app.use(barangMasukRoutes); 72 | app.use(barangKeluarRoutes); 73 | app.use(logRoutes); 74 | 75 | app.get('*', (req, res) => { 76 | res.status(404).render('404', { title: '404 Error' }); 77 | }); 78 | 79 | module.exports = app; 80 | -------------------------------------------------------------------------------- /src/config/database.js: -------------------------------------------------------------------------------- 1 | const { Pool } = require('pg'); 2 | require('dotenv').config(); 3 | 4 | const pool = new Pool({ 5 | user: process.env.PGUSER, 6 | password: process.env.PGPASSWORD, 7 | database: process.env.PGDATABASE, 8 | host: process.env.PGHOST, 9 | port: process.env.PGPORT, 10 | }); 11 | 12 | module.exports = pool; 13 | -------------------------------------------------------------------------------- /src/controllers/accountController.js: -------------------------------------------------------------------------------- 1 | const bcrypt = require('bcrypt'); 2 | const { body, validationResult } = require('express-validator'); 3 | const user = require('../queries/usersQuery'); 4 | 5 | const getAccount = async (req, res) => { 6 | if (req.session.user && req.session.user.role === 'superadmin') { 7 | const users = await user.checkProfile(req.session.user.email); 8 | res.render('account', { 9 | usr: users, 10 | user: req.session.user.email, 11 | title: 'Edit Akun', 12 | }); 13 | } else if (req.session.user && req.session.user.role === 'user') { 14 | const users = await user.checkProfile(req.session.user.email); 15 | res.render('account', { 16 | usr: users, 17 | us: req.session.user.email, 18 | title: 'Edit Akun', 19 | }); 20 | } else { 21 | res.status(401); 22 | res.render('401', { title: '401 Error' }); 23 | } 24 | }; 25 | 26 | const changeEmail = [ 27 | body('email').custom(async (value, { req }) => { 28 | const duplicate = await user.checkDuplicate(value.toLowerCase()); 29 | if (value === req.body.oldEmail) { 30 | throw new Error( 31 | 'Ganti email gagal: email baru tidak boleh sama dengan email sekarang.', 32 | ); 33 | } 34 | if (duplicate) { 35 | throw new Error('Ganti email gagal: email sudah ada.'); 36 | } 37 | return true; 38 | }), 39 | body('password').custom(async (value, { req }) => { 40 | const checkPass = await bcrypt.compare(value, req.body.matchPass); 41 | if (!checkPass) { 42 | throw new Error('Ganti email gagal: kata sandi salah.'); 43 | } 44 | return true; 45 | }), 46 | async (req, res) => { 47 | if (req.session.user && req.session.user.email !== 'superadmin@email.com') { 48 | const errors = validationResult(req); 49 | if (!errors.isEmpty()) { 50 | res.render('account', { 51 | title: 'Akun', 52 | errors: errors.array(), 53 | usr: req.body, 54 | user: req.session.user.email, 55 | }); 56 | } else { 57 | await user.updateEmail(req.body); 58 | req.session = null; 59 | res.render('login', { 60 | title: 'Login', 61 | logout: 'Ganti email berhasil, silahkan masuk kembali.', 62 | }); 63 | } 64 | } else { 65 | res.status(401); 66 | res.render('401', { title: '401 Error' }); 67 | } 68 | }, 69 | ]; 70 | 71 | const changePassword = [ 72 | body('oldPassword').custom(async (value, { req }) => { 73 | const checkPass = await bcrypt.compare(value, req.body.matchPass); 74 | if (!checkPass) { 75 | throw new Error('Ganti kata sandi gagal: kata sandi lama salah.'); 76 | } 77 | return true; 78 | }), 79 | body('password').custom(async (value, { req }) => { 80 | const checkPass = await bcrypt.compare(value, req.body.matchPass); 81 | if (checkPass) { 82 | throw new Error( 83 | 'Ganti kata sandi gagal: kata sandi baru tidak boleh sama dengan kata sandi lama.', 84 | ); 85 | } 86 | return true; 87 | }), 88 | body('confirmPassword').custom(async (value, { req }) => { 89 | if (value !== req.body.password) { 90 | throw new Error( 91 | 'Ganti kata sandi gagal: kata sandi baru dan konfirmasi kata sandi baru tidak cocok.', 92 | ); 93 | } 94 | return true; 95 | }), 96 | async (req, res) => { 97 | if (req.session.user && req.session.user.role === 'superadmin') { 98 | const errors = validationResult(req); 99 | if (!errors.isEmpty()) { 100 | res.render('account', { 101 | title: 'Akun', 102 | errors: errors.array(), 103 | usr: req.body, 104 | user: req.session.user.email, 105 | }); 106 | } else { 107 | const password = await bcrypt.hash(req.body.password, 10); 108 | const { id } = req.body; 109 | 110 | await user.updatePassword(password, id); 111 | req.session = null; 112 | res.render('login', { 113 | title: 'Login', 114 | logout: 'Ganti kata sandi berhasil, silahkan masuk kembali.', 115 | }); 116 | } 117 | } else if (req.session.user && req.session.user.role === 'user') { 118 | const errors = validationResult(req); 119 | if (!errors.isEmpty()) { 120 | res.render('account', { 121 | title: 'Akun', 122 | errors: errors.array(), 123 | usr: req.body, 124 | us: req.session.user.email, 125 | }); 126 | } else { 127 | const password = await bcrypt.hash(req.body.password, 10); 128 | const { id } = req.body; 129 | 130 | await user.updatePassword(password, id); 131 | req.session = null; 132 | res.render('login', { 133 | title: 'Login', 134 | logout: 'Ganti kata sandi berhasil, silahkan masuk kembali.', 135 | }); 136 | } 137 | } else { 138 | res.status(401); 139 | res.render('401', { title: '401 Error' }); 140 | } 141 | }, 142 | ]; 143 | 144 | const changeRole = [ 145 | body('password').custom(async (value, { req }) => { 146 | const checkPass = await bcrypt.compare(value, req.body.matchPass); 147 | if (!checkPass) { 148 | throw new Error('Ganti role gagal: kata sandi salah.'); 149 | } 150 | return true; 151 | }), 152 | async (req, res) => { 153 | if (req.session.user && req.session.user.email !== 'superadmin@email.com') { 154 | const errors = validationResult(req); 155 | if (!errors.isEmpty()) { 156 | res.render('account', { 157 | title: 'Akun', 158 | errors: errors.array(), 159 | usr: req.body, 160 | user: req.session.user.email, 161 | }); 162 | } else { 163 | await user.updateRole(req.body); 164 | req.session = null; 165 | res.render('login', { 166 | title: 'Login', 167 | logout: 'Ganti role berhasil, silahkan masuk kembali.', 168 | }); 169 | } 170 | } else { 171 | res.status(401); 172 | res.render('401', { title: '401 Error' }); 173 | } 174 | }, 175 | ]; 176 | 177 | module.exports = { 178 | getAccount, 179 | changeEmail, 180 | changePassword, 181 | changeRole, 182 | }; 183 | -------------------------------------------------------------------------------- /src/controllers/authController.js: -------------------------------------------------------------------------------- 1 | const bcrypt = require('bcrypt'); 2 | const user = require('../queries/usersQuery'); 3 | 4 | const login = async (req, res) => { 5 | const { email } = req.body; 6 | const { password } = req.body; 7 | 8 | const checkPass = await bcrypt.compare( 9 | password, 10 | await user.checkPassword(email), 11 | ); 12 | 13 | if ( 14 | email === (await user.email(email)) 15 | && checkPass 16 | && (await user.checkRole(email)) === 'superadmin' 17 | ) { 18 | req.session.user = { 19 | email, 20 | role: 'superadmin', 21 | }; 22 | res.redirect('/'); 23 | } else if ( 24 | email === (await user.email(email)) 25 | && checkPass 26 | && (await user.checkRole(email)) === 'user' 27 | ) { 28 | req.session.user = { 29 | email, 30 | role: 'user', 31 | }; 32 | res.redirect('/'); 33 | } else { 34 | res.render('login', { 35 | title: 'Login', 36 | loginFail: 'Email atau kata sandi salah.', 37 | }); 38 | } 39 | }; 40 | 41 | const logout = (req, res) => { 42 | req.session = null; 43 | res.render('login', { title: 'Login', logout: 'Keluar berhasil.' }); 44 | }; 45 | 46 | module.exports = { 47 | login, 48 | logout, 49 | }; 50 | -------------------------------------------------------------------------------- /src/controllers/barangController.js: -------------------------------------------------------------------------------- 1 | const { promisify } = require('util'); 2 | const fs = require('fs'); 3 | const { body, validationResult } = require('express-validator'); 4 | const moment = require('moment'); 5 | const QRCode = require('qrcode'); 6 | const multer = require('multer'); 7 | const path = require('path'); 8 | // const { createCanvas } = require("canvas"); 9 | // const JsBarcode = require("jsbarcode"); 10 | const stok = require('../queries/stockBarangQuery'); 11 | const bmasuk = require('../queries/barangMasukQuery'); 12 | const bkeluar = require('../queries/barangKeluarQuery'); 13 | 14 | // Multer 15 | const storage = multer.diskStorage({ 16 | destination: (req, file, cb) => { 17 | cb(null, './public/uploads'); 18 | }, 19 | filename: (req, file, cb) => { 20 | cb(null, Date.now() + path.extname(file.originalname)); 21 | }, 22 | }); 23 | 24 | const upload = multer({ storage }); 25 | 26 | // Delete File 27 | const unlinkAsync = promisify(fs.unlink); 28 | 29 | // Canvas 30 | // const canvas = createCanvas(); 31 | 32 | const getBarang = async (req, res) => { 33 | if (req.session.user && req.session.user.role === 'superadmin') { 34 | const barang = await stok.getBarang(); 35 | res.render('barang', { 36 | user: req.session.user.email, 37 | title: 'Stok Barang', 38 | brg: barang, 39 | }); 40 | } else if (req.session.user && req.session.user.role === 'user') { 41 | const barang = await stok.getBarang(); 42 | res.render('barang', { 43 | us: req.session.user.email, 44 | title: 'Stok Barang', 45 | brg: barang, 46 | }); 47 | } else { 48 | res.status(401); 49 | res.render('401', { title: '401 Error' }); 50 | } 51 | }; 52 | 53 | const getBarangDetail = async (req, res) => { 54 | if (req.session.user && req.session.user.role === 'superadmin') { 55 | const barang = await stok.getDetail(req.params.id); 56 | const barangMasuk = await bmasuk.getDetailBarang(req.params.id); 57 | const barangKeluar = await bkeluar.getDetailBarang(req.params.id); 58 | 59 | res.render('barangDetail', { 60 | brg: barang, 61 | user: req.session.user.email, 62 | title: 'Detail Barang', 63 | brgm: barangMasuk, 64 | brgk: barangKeluar, 65 | moment, 66 | }); 67 | } else if (req.session.user && req.session.user.role === 'user') { 68 | const barang = await stok.getDetail(req.params.id); 69 | const barangMasuk = await bmasuk.getDetailBarang(req.params.id); 70 | const barangKeluar = await bkeluar.getDetailBarang(req.params.id); 71 | 72 | res.render('barangDetail', { 73 | brg: barang, 74 | us: req.session.user.email, 75 | title: 'Detail Barang', 76 | brgm: barangMasuk, 77 | brgk: barangKeluar, 78 | moment, 79 | }); 80 | } else { 81 | res.status(401); 82 | res.render('401', { title: '401 Error' }); 83 | } 84 | }; 85 | 86 | const addBarang = [ 87 | upload.single('image'), 88 | body('kodebarang').custom(async (value) => { 89 | const dup = await stok.cekKode(value.toLowerCase()); 90 | if (dup) { 91 | throw new Error('Tambah barang gagal: kode barang sudah ada.'); 92 | } 93 | return true; 94 | }), 95 | body('namabarang').custom(async (value) => { 96 | const duplicate = await stok.cekBarang(value.toLowerCase()); 97 | if (duplicate) { 98 | throw new Error('Tambah barang gagal: nama barang sudah ada.'); 99 | } 100 | return true; 101 | }), 102 | body('image').custom(async (value, { req }) => { 103 | const maxSize = 1048576; 104 | if (req.file.size > maxSize) { 105 | throw new Error('Tambah barang gagal: ukuran file melebihi batas 1MB.'); 106 | } 107 | return true; 108 | }), 109 | async (req, res) => { 110 | if (req.session.user && req.session.user.role === 'superadmin') { 111 | const errors = validationResult(req); 112 | if (!errors.isEmpty()) { 113 | const img = req.file.filename; 114 | 115 | const imgPath = `./public/uploads/${img}`; 116 | if (fs.existsSync(imgPath)) { 117 | await unlinkAsync(imgPath); 118 | } 119 | 120 | const barang = await stok.getBarang(); 121 | 122 | res.render('barang', { 123 | title: 'Stok Barang', 124 | errors: errors.array(), 125 | user: req.session.user.email, 126 | brg: barang, 127 | }); 128 | } else { 129 | const { namabarang } = req.body; 130 | const { deskripsi } = req.body; 131 | const { stock } = req.body; 132 | const image = req.file.filename; 133 | const penginput = req.session.user.email; 134 | const { kodebarang } = req.body; 135 | 136 | await stok.addBarang( 137 | namabarang, 138 | deskripsi, 139 | stock, 140 | image, 141 | penginput, 142 | kodebarang, 143 | ); 144 | 145 | // JsBarcode(canvas, kodebarang); 146 | // const buffer = canvas.toBuffer("image/png"); 147 | const writeImgPath = `./public/uploads/${kodebarang}.png`; 148 | // fs.writeFileSync(writeImgPath, buffer); 149 | QRCode.toFile(writeImgPath, kodebarang, (err) => { 150 | if (err) { 151 | console.err(err); 152 | return false; 153 | } 154 | return true; 155 | }); 156 | 157 | res.redirect('/barang'); 158 | } 159 | } else if (req.session.user && req.session.user.role === 'user') { 160 | const errors = validationResult(req); 161 | if (!errors.isEmpty()) { 162 | const img = req.file.filename; 163 | 164 | const imgPath = `./public/uploads/${img}`; 165 | if (fs.existsSync(imgPath)) { 166 | await unlinkAsync(imgPath); 167 | } 168 | 169 | const barang = await stok.getBarang(); 170 | 171 | res.render('barang', { 172 | title: 'Stok Barang', 173 | errors: errors.array(), 174 | us: req.session.user.email, 175 | brg: barang, 176 | }); 177 | } else { 178 | const { namabarang } = req.body; 179 | const { deskripsi } = req.body; 180 | const { stock } = req.body; 181 | const image = req.file.filename; 182 | const penginput = req.session.user.email; 183 | const { kodebarang } = req.body; 184 | 185 | await stok.addBarang( 186 | namabarang, 187 | deskripsi, 188 | stock, 189 | image, 190 | penginput, 191 | kodebarang, 192 | ); 193 | 194 | // JsBarcode(canvas, kodebarang); 195 | // const buffer = canvas.toBuffer("image/png"); 196 | const writeImgPath = `./public/uploads/${kodebarang}.png`; 197 | // fs.writeFileSync(writeImgPath, buffer); 198 | QRCode.toFile(writeImgPath, kodebarang, (err) => { 199 | if (err) { 200 | console.err(err); 201 | return false; 202 | } 203 | return true; 204 | }); 205 | 206 | res.redirect('/barang'); 207 | } 208 | } else { 209 | res.status(401); 210 | res.render('401', { title: '401 Error' }); 211 | } 212 | }, 213 | ]; 214 | 215 | const updateBarang = [ 216 | upload.single('image'), 217 | body('kodebarang').custom(async (value, { req }) => { 218 | const dup = await stok.checkKodeDuplicate(value.toLowerCase()); 219 | if (value !== req.body.oldKode && dup) { 220 | throw new Error('Edit barang gagal: kode barang sudah ada.'); 221 | } 222 | return true; 223 | }), 224 | body('namabarang').custom(async (value, { req }) => { 225 | const duplicate = await stok.checkDuplicate(value.toLowerCase()); 226 | if (value !== req.body.oldNama && duplicate) { 227 | throw new Error('Edit barang gagal: nama barang sudah ada.'); 228 | } 229 | return true; 230 | }), 231 | body('image').custom(async (value, { req }) => { 232 | const maxSize = 1048576; 233 | if (req.file) { 234 | if (req.file.size > maxSize) { 235 | throw new Error('Edit barang gagal: ukuran file melebihi batas 1MB.'); 236 | } 237 | } 238 | return true; 239 | }), 240 | async (req, res) => { 241 | if (req.session.user && req.session.user.role === 'superadmin') { 242 | const errors = validationResult(req); 243 | if (!errors.isEmpty()) { 244 | if (req.file && req.file.filename) { 245 | const img = req.file.filename; 246 | 247 | const imgPath = `./public/uploads/${img}`; 248 | if (fs.existsSync(imgPath)) { 249 | await unlinkAsync(imgPath); 250 | } 251 | } 252 | const barang = await stok.getBarang(); 253 | 254 | res.render('barang', { 255 | title: 'Stok Barang', 256 | errors: errors.array(), 257 | brg: barang, 258 | user: req.session.user.email, 259 | }); 260 | } else if (req.file && req.file.filename) { 261 | const { namabarang } = req.body; 262 | const { deskripsi } = req.body; 263 | const { stock } = req.body; 264 | const image = req.file.filename; 265 | const { kodebarang } = req.body; 266 | const { oldKode } = req.body; 267 | const { idbarang } = req.body; 268 | const img = req.body.image; 269 | 270 | await stok.updateBarang( 271 | namabarang, 272 | deskripsi, 273 | stock, 274 | image, 275 | kodebarang, 276 | idbarang, 277 | ); 278 | 279 | const imgPath = `./public/uploads/${img}`; 280 | if (fs.existsSync(imgPath)) { 281 | await unlinkAsync(imgPath); 282 | } 283 | 284 | if (kodebarang !== oldKode) { 285 | const oldImgPath = `./public/uploads/${oldKode}.png`; 286 | if (fs.existsSync(oldImgPath)) { 287 | await unlinkAsync(oldImgPath); 288 | } 289 | 290 | // JsBarcode(canvas, kodebarang); 291 | // const buffer = canvas.toBuffer("image/png"); 292 | const writeImgPath = `./public/uploads/${kodebarang}.png`; 293 | // fs.writeFileSync(writeImgPath, buffer); 294 | QRCode.toFile(writeImgPath, kodebarang, (err) => { 295 | if (err) { 296 | console.err(err); 297 | return false; 298 | } 299 | return true; 300 | }); 301 | } 302 | 303 | res.redirect('/barang'); 304 | } else { 305 | const { namabarang } = req.body; 306 | const { deskripsi } = req.body; 307 | const { stock } = req.body; 308 | const { image } = req.body; 309 | const { kodebarang } = req.body; 310 | const { oldKode } = req.body; 311 | const { idbarang } = req.body; 312 | 313 | await stok.updateBarang( 314 | namabarang, 315 | deskripsi, 316 | stock, 317 | image, 318 | kodebarang, 319 | idbarang, 320 | ); 321 | 322 | if (kodebarang !== oldKode) { 323 | const oldImgPath = `./public/uploads/${oldKode}.png`; 324 | if (fs.existsSync(oldImgPath)) { 325 | await unlinkAsync(oldImgPath); 326 | } 327 | 328 | // JsBarcode(canvas, kodebarang); 329 | // const buffer = canvas.toBuffer("image/png"); 330 | const writeImgPath = `./public/uploads/${kodebarang}.png`; 331 | // fs.writeFileSync(writeImgPath, buffer); 332 | QRCode.toFile(writeImgPath, kodebarang, (err) => { 333 | if (err) { 334 | console.err(err); 335 | return false; 336 | } 337 | return true; 338 | }); 339 | } 340 | 341 | res.redirect('/barang'); 342 | } 343 | } else { 344 | res.status(401); 345 | res.render('401', { title: '401 Error' }); 346 | } 347 | }, 348 | ]; 349 | 350 | const deleteBarang = async (req, res) => { 351 | if (req.session.user && req.session.user.role === 'superadmin') { 352 | const image = await stok.getImage(req.params.id); 353 | const kode = await stok.getKode(req.params.id); 354 | await stok.delBarang(req.params.id); 355 | // await bmasuk.delBarangMasukId(req.params.id); 356 | // await bkeluar.delBarangKeluarId(req.params.id); 357 | const imgPath = `./public/uploads/${image}`; 358 | if (fs.existsSync(imgPath)) { 359 | await unlinkAsync(imgPath); 360 | } 361 | const writeImgPath = `./public/uploads/${kode}.png`; 362 | if (fs.existsSync(writeImgPath)) { 363 | await unlinkAsync(writeImgPath); 364 | } 365 | res.redirect('/barang'); 366 | } else { 367 | res.status(401); 368 | res.render('401', { title: '401 Error' }); 369 | } 370 | }; 371 | 372 | module.exports = { 373 | getBarang, 374 | getBarangDetail, 375 | addBarang, 376 | updateBarang, 377 | deleteBarang, 378 | }; 379 | -------------------------------------------------------------------------------- /src/controllers/barangKeluarController.js: -------------------------------------------------------------------------------- 1 | const moment = require('moment'); 2 | const stok = require('../queries/stockBarangQuery'); 3 | const bkeluar = require('../queries/barangKeluarQuery'); 4 | 5 | const getBarangKeluar = async (req, res) => { 6 | if (req.session.user && req.session.user.role === 'superadmin') { 7 | const barangKeluar = await bkeluar.getBarangK(); 8 | const barang = await stok.getBarang(); 9 | res.render('barangKeluar', { 10 | user: req.session.user.email, 11 | title: 'Barang Keluar', 12 | brgk: barangKeluar, 13 | moment, 14 | brg: barang, 15 | }); 16 | } else if (req.session.user && req.session.user.role === 'user') { 17 | const barangKeluar = await bkeluar.getBarangK(); 18 | const barang = await stok.getBarang(); 19 | res.render('barangKeluar', { 20 | us: req.session.user.email, 21 | title: 'Barang Keluar', 22 | brgk: barangKeluar, 23 | moment, 24 | brg: barang, 25 | }); 26 | } else { 27 | res.status(401); 28 | res.render('401', { title: '401 Error' }); 29 | } 30 | }; 31 | 32 | const addBarangKeluar = async (req, res) => { 33 | if (req.session.user && req.session.user.role === 'superadmin') { 34 | const idbarang = req.body.barang; 35 | const { penerima } = req.body; 36 | const { qty } = req.body; 37 | const namabarangKeluar = await stok.getNama(idbarang); 38 | const penginput = req.session.user.email; 39 | const kodebarangKeluar = await stok.getKode(idbarang); 40 | 41 | const stock = await stok.getStock(idbarang); 42 | const newStock = parseInt(stock, 10) - parseInt(qty, 10); 43 | 44 | if (newStock < 0) { 45 | const barangKeluar = await bkeluar.getBarangK(); 46 | const barang = await stok.getBarang(); 47 | res.render('barangKeluar', { 48 | user: req.session.user.email, 49 | title: 'Barang Keluar', 50 | brgk: barangKeluar, 51 | moment, 52 | error: 'Tambah barang keluar gagal: stok barang tidak mencukupi.', 53 | brg: barang, 54 | }); 55 | } else { 56 | await stok.updateStock(newStock, idbarang); 57 | await bkeluar.addBarangKeluar( 58 | idbarang, 59 | penerima, 60 | qty, 61 | namabarangKeluar, 62 | penginput, 63 | kodebarangKeluar, 64 | ); 65 | 66 | res.redirect('/barangkeluar'); 67 | } 68 | } else if (req.session.user && req.session.user.role === 'user') { 69 | const idbarang = req.body.barang; 70 | const { penerima } = req.body; 71 | const { qty } = req.body; 72 | const namabarangKeluar = await stok.getNama(idbarang); 73 | const penginput = req.session.user.email; 74 | const kodebarangKeluar = await stok.getKode(idbarang); 75 | 76 | const stock = await stok.getStock(idbarang); 77 | const newStock = parseInt(stock, 10) - parseInt(qty, 10); 78 | 79 | if (newStock < 0) { 80 | const barangKeluar = await bkeluar.getBarangK(); 81 | const barang = await stok.getBarang(); 82 | res.render('barangKeluar', { 83 | us: req.session.user.email, 84 | title: 'Barang Keluar', 85 | brgk: barangKeluar, 86 | moment, 87 | error: 'Tambah barang keluar gagal: stok barang tidak mencukupi.', 88 | brg: barang, 89 | }); 90 | } else { 91 | await stok.updateStock(newStock, idbarang); 92 | await bkeluar.addBarangKeluar( 93 | idbarang, 94 | penerima, 95 | qty, 96 | namabarangKeluar, 97 | penginput, 98 | kodebarangKeluar, 99 | ); 100 | 101 | res.redirect('/barangkeluar'); 102 | } 103 | } else { 104 | res.status(401); 105 | res.render('401', { title: '401 Error' }); 106 | } 107 | }; 108 | 109 | const updateBarangKeluar = async (req, res) => { 110 | if (req.session.user && req.session.user.role === 'superadmin') { 111 | const { idbarang } = req.body; 112 | const { penerima } = req.body; 113 | const { qty } = req.body; 114 | const { idkeluar } = req.body; 115 | 116 | const stockk = await stok.getStock(idbarang); 117 | if (stockk !== 'undefined') { 118 | const currentQtyy = await bkeluar.getQty(idkeluar); 119 | 120 | const qtyy = parseInt(qty, 10); 121 | const currentQty = parseInt(currentQtyy, 10); 122 | 123 | if (qtyy > currentQty) { 124 | const selisih = qtyy - currentQty; 125 | const kurangin = stockk - selisih; 126 | if (kurangin < 0) { 127 | const barangKeluar = await bkeluar.getBarangK(); 128 | const barang = await stok.getBarang(); 129 | res.render('barangKeluar', { 130 | user: req.session.user.email, 131 | title: 'Barang Keluar', 132 | brgk: barangKeluar, 133 | moment, 134 | error: 135 | 'Edit barang keluar gagal: menambah jumlah keluar barang ini akan mengakibatkan nilai stok barang menjadi negatif.', 136 | brg: barang, 137 | }); 138 | } else { 139 | await stok.updateStock(kurangin, idbarang); 140 | await bkeluar.updateBarangKeluar(penerima, qty, idkeluar); 141 | res.redirect('/barangkeluar'); 142 | } 143 | } else { 144 | const selisih = currentQty - qtyy; 145 | const tambahin = stockk + selisih; 146 | await stok.updateStock(tambahin, idbarang); 147 | await bkeluar.updateBarangKeluar(penerima, qty, idkeluar); 148 | res.redirect('/barangkeluar'); 149 | } 150 | } else { 151 | await bkeluar.updateBarangKeluar(penerima, qty, idkeluar); 152 | res.redirect('/barangkeluar'); 153 | } 154 | } else { 155 | res.status(401); 156 | res.render('401', { title: '401 Error' }); 157 | } 158 | }; 159 | 160 | const deleteBarangKeluar = async (req, res) => { 161 | if (req.session.user && req.session.user.role === 'superadmin') { 162 | const { idbarang } = req.body; 163 | const { qty } = req.body; 164 | const { idkeluar } = req.body; 165 | 166 | const stockk = await stok.getStock(idbarang); 167 | if (stockk !== 'undefined') { 168 | const qtyy = parseInt(qty, 10); 169 | const stock = parseInt(stockk, 10); 170 | 171 | const selisih = stock + qtyy; 172 | 173 | await stok.updateStock(selisih, idbarang); 174 | await bkeluar.delBarangKeluar(idkeluar); 175 | 176 | res.redirect('/barangkeluar'); 177 | } else { 178 | await bkeluar.delBarangKeluar(idkeluar); 179 | 180 | res.redirect('/barangkeluar'); 181 | } 182 | } else { 183 | res.status(401); 184 | res.render('401', { title: '401 Error' }); 185 | } 186 | }; 187 | 188 | module.exports = { 189 | getBarangKeluar, 190 | addBarangKeluar, 191 | updateBarangKeluar, 192 | deleteBarangKeluar, 193 | }; 194 | -------------------------------------------------------------------------------- /src/controllers/barangMasukController.js: -------------------------------------------------------------------------------- 1 | const moment = require('moment'); 2 | const stok = require('../queries/stockBarangQuery'); 3 | const bmasuk = require('../queries/barangMasukQuery'); 4 | 5 | const getBarangMasuk = async (req, res) => { 6 | if (req.session.user && req.session.user.role === 'superadmin') { 7 | const barangMasuk = await bmasuk.getBarangM(); 8 | const barang = await stok.getBarang(); 9 | res.render('barangMasuk', { 10 | user: req.session.user.email, 11 | title: 'Barang Masuk', 12 | brgm: barangMasuk, 13 | moment, 14 | brg: barang, 15 | }); 16 | } else if (req.session.user && req.session.user.role === 'user') { 17 | const barangMasuk = await bmasuk.getBarangM(); 18 | const barang = await stok.getBarang(); 19 | res.render('barangMasuk', { 20 | us: req.session.user.email, 21 | title: 'Barang Masuk', 22 | brgm: barangMasuk, 23 | moment, 24 | brg: barang, 25 | }); 26 | } else { 27 | res.status(401); 28 | res.render('401', { title: '401 Error' }); 29 | } 30 | }; 31 | 32 | const addBarangMasuk = async (req, res) => { 33 | if (req.session.user && req.session.user.role === 'superadmin') { 34 | const idbarang = req.body.barang; 35 | const { keterangan } = req.body; 36 | const { qty } = req.body; 37 | const namabarangMasuk = await stok.getNama(idbarang); 38 | const penginput = req.session.user.email; 39 | const kodebarangMasuk = await stok.getKode(idbarang); 40 | 41 | const stock = await stok.getStock(idbarang); 42 | const newStock = parseInt(stock, 10) + parseInt(qty, 10); 43 | 44 | await stok.updateStock(newStock, idbarang); 45 | await bmasuk.addBarangMasuk( 46 | idbarang, 47 | keterangan, 48 | qty, 49 | namabarangMasuk, 50 | penginput, 51 | kodebarangMasuk, 52 | ); 53 | 54 | res.redirect('/barangmasuk'); 55 | } else if (req.session.user && req.session.user.role === 'user') { 56 | const idbarang = req.body.barang; 57 | const { keterangan } = req.body; 58 | const { qty } = req.body; 59 | const namabarangMasuk = await stok.getNama(idbarang); 60 | const penginput = req.session.user.email; 61 | const kodebarangMasuk = await stok.getKode(idbarang); 62 | 63 | const stock = await stok.getStock(idbarang); 64 | const newStock = parseInt(stock, 10) + parseInt(qty, 10); 65 | 66 | await stok.updateStock(newStock, idbarang); 67 | await bmasuk.addBarangMasuk( 68 | idbarang, 69 | keterangan, 70 | qty, 71 | namabarangMasuk, 72 | penginput, 73 | kodebarangMasuk, 74 | ); 75 | 76 | res.redirect('/barangmasuk'); 77 | } else { 78 | res.status(401); 79 | res.render('401', { title: '401 Error' }); 80 | } 81 | }; 82 | 83 | const updateBarangMasuk = async (req, res) => { 84 | if (req.session.user && req.session.user.role === 'superadmin') { 85 | const { idbarang } = req.body; 86 | const { keterangan } = req.body; 87 | const { qty } = req.body; 88 | const { idmasuk } = req.body; 89 | 90 | const stockk = await stok.getStock(idbarang); 91 | if (stockk !== 'undefined') { 92 | const currentQtyy = await bmasuk.getQty(idmasuk); 93 | 94 | const qtyy = parseInt(qty, 10); 95 | const currentQty = parseInt(currentQtyy, 10); 96 | 97 | if (qtyy > currentQty) { 98 | const selisih = qtyy - currentQty; 99 | const tambahin = stockk + selisih; 100 | await stok.updateStock(tambahin, idbarang); 101 | await bmasuk.updateBarangMasuk(keterangan, qty, idmasuk); 102 | res.redirect('/barangmasuk'); 103 | } else { 104 | const selisih = currentQty - qtyy; 105 | const kurangin = stockk - selisih; 106 | if (kurangin < 0) { 107 | const barangMasuk = await bmasuk.getBarangM(); 108 | const barang = await stok.getBarang(); 109 | res.render('barangMasuk', { 110 | user: req.session.user.email, 111 | title: 'Barang Masuk', 112 | brgm: barangMasuk, 113 | moment, 114 | deleteFail: 115 | 'Edit barang masuk gagal: mengurangi jumlah masuk barang ini akan mengakibatkan nilai stok barang menjadi negatif.', 116 | brg: barang, 117 | }); 118 | } else { 119 | await stok.updateStock(kurangin, idbarang); 120 | await bmasuk.updateBarangMasuk(keterangan, qty, idmasuk); 121 | res.redirect('/barangmasuk'); 122 | } 123 | } 124 | } else { 125 | await bmasuk.updateBarangMasuk(keterangan, qty, idmasuk); 126 | res.redirect('/barangmasuk'); 127 | } 128 | } else { 129 | res.status(401); 130 | res.render('401', { title: '401 Error' }); 131 | } 132 | }; 133 | 134 | const deleteBarangMasuk = async (req, res) => { 135 | if (req.session.user && req.session.user.role === 'superadmin') { 136 | const { idbarang } = req.body; 137 | const { qty } = req.body; 138 | const { idmasuk } = req.body; 139 | 140 | const stockk = await stok.getStock(idbarang); 141 | if (stockk !== 'undefined') { 142 | const qtyy = parseInt(qty, 10); 143 | const stock = parseInt(stockk, 10); 144 | 145 | const selisih = stock - qtyy; 146 | 147 | if (selisih < 0) { 148 | const barangMasuk = await bmasuk.getBarangM(); 149 | const barang = await stok.getBarang(); 150 | res.render('barangMasuk', { 151 | user: req.session.user.email, 152 | title: 'Barang Masuk', 153 | brgm: barangMasuk, 154 | moment, 155 | deleteFail: 156 | 'Hapus barang masuk gagal: menghapus barang masuk ini akan mengakibatkan nilai stok barang menjadi negatif.', 157 | brg: barang, 158 | }); 159 | } else { 160 | await stok.updateStock(selisih, idbarang); 161 | await bmasuk.delBarangMasuk(idmasuk); 162 | 163 | res.redirect('/barangmasuk'); 164 | } 165 | } else { 166 | await bmasuk.delBarangMasuk(idmasuk); 167 | 168 | res.redirect('/barangmasuk'); 169 | } 170 | } else { 171 | res.status(401); 172 | res.render('401', { title: '401 Error' }); 173 | } 174 | }; 175 | 176 | module.exports = { 177 | getBarangMasuk, 178 | addBarangMasuk, 179 | updateBarangMasuk, 180 | deleteBarangMasuk, 181 | }; 182 | -------------------------------------------------------------------------------- /src/controllers/dashboardController.js: -------------------------------------------------------------------------------- 1 | const user = require('../queries/usersQuery'); 2 | const stok = require('../queries/stockBarangQuery'); 3 | const bmasuk = require('../queries/barangMasukQuery'); 4 | const bkeluar = require('../queries/barangKeluarQuery'); 5 | 6 | const getIndex = async (req, res) => { 7 | if (req.session.user && req.session.user.role === 'superadmin') { 8 | const totalStock = await stok.totalStock(); 9 | const totalQtyBM = await bmasuk.totalQty(); 10 | const totalQtyBK = await bkeluar.totalQty(); 11 | const totalUsers = await user.totalUsers(); 12 | res.render('index', { 13 | user: req.session.user.email, 14 | title: 'Dasbor', 15 | totalStock, 16 | totalQtyBM, 17 | totalQtyBK, 18 | totalUsers, 19 | }); 20 | } else if (req.session.user && req.session.user.role === 'user') { 21 | const totalStock = await stok.totalStock(); 22 | const totalQtyBM = await bmasuk.totalQty(); 23 | const totalQtyBK = await bkeluar.totalQty(); 24 | const totalUsers = await user.totalUsers(); 25 | res.render('index', { 26 | us: req.session.user.email, 27 | title: 'Dasbor', 28 | totalStock, 29 | totalQtyBM, 30 | totalQtyBK, 31 | totalUsers, 32 | }); 33 | } else { 34 | res.render('login', { title: 'Login' }); 35 | } 36 | }; 37 | 38 | module.exports = getIndex; 39 | -------------------------------------------------------------------------------- /src/controllers/logController.js: -------------------------------------------------------------------------------- 1 | const moment = require('moment'); 2 | const log = require('../queries/logQuery'); 3 | 4 | const getLog = async (req, res) => { 5 | if (req.session.user && req.session.user.role === 'superadmin') { 6 | const logs = await log.getLog(); 7 | res.render('log', { 8 | log: logs, 9 | user: req.session.user.email, 10 | title: 'Log Aplikasi', 11 | moment, 12 | }); 13 | } else { 14 | res.status(401); 15 | res.render('401', { title: '401 Error' }); 16 | } 17 | }; 18 | 19 | module.exports = getLog; 20 | -------------------------------------------------------------------------------- /src/controllers/usersController.js: -------------------------------------------------------------------------------- 1 | const bcrypt = require('bcrypt'); 2 | const { body, validationResult } = require('express-validator'); 3 | const user = require('../queries/usersQuery'); 4 | 5 | const getUsers = async (req, res) => { 6 | if (req.session.user && req.session.user.role === 'superadmin') { 7 | const users = await user.getUsers(); 8 | res.render('users', { 9 | usr: users, 10 | user: req.session.user.email, 11 | title: 'Kelola Pengguna', 12 | }); 13 | } else { 14 | res.status(401); 15 | res.render('401', { title: '401 Error' }); 16 | } 17 | }; 18 | 19 | const addUser = [ 20 | body('email').custom(async (value) => { 21 | const duplicate = await user.email2(value.toLowerCase()); 22 | if (duplicate) { 23 | throw new Error('Tambah pengguna gagal: email sudah ada.'); 24 | } 25 | return true; 26 | }), 27 | async (req, res) => { 28 | if (req.session.user && req.session.user.role === 'superadmin') { 29 | const errors = validationResult(req); 30 | if (!errors.isEmpty()) { 31 | const users = await user.getUsers(); 32 | res.render('users', { 33 | title: 'Kelola Pengguna', 34 | errors: errors.array(), 35 | usr: users, 36 | user: req.session.user.email, 37 | }); 38 | } else { 39 | const { email } = req.body; 40 | const password = await bcrypt.hash(req.body.password, 10); 41 | const { role } = req.body; 42 | 43 | await user.addUser(email, password, role); 44 | 45 | res.redirect('/users'); 46 | } 47 | } else { 48 | res.status(401); 49 | res.render('401', { title: '401 Error' }); 50 | } 51 | }, 52 | ]; 53 | 54 | const updateUser = [ 55 | body('email').custom(async (value, { req }) => { 56 | const duplicate = await user.checkDuplicate(value.toLowerCase()); 57 | if (value !== req.body.oldEmail && duplicate) { 58 | throw new Error('Edit pengguna gagal: email sudah ada.'); 59 | } 60 | return true; 61 | }), 62 | async (req, res) => { 63 | if (req.session.user && req.session.user.role === 'superadmin') { 64 | const errors = validationResult(req); 65 | if (!errors.isEmpty()) { 66 | const users = await user.getUsers(); 67 | res.render('users', { 68 | title: 'Kelola Pengguna', 69 | errors: errors.array(), 70 | usr: users, 71 | user: req.session.user.email, 72 | }); 73 | } else { 74 | await user.updateUser(req.body); 75 | res.redirect('/users'); 76 | } 77 | } else { 78 | res.status(401); 79 | res.render('401', { title: '401 Error' }); 80 | } 81 | }, 82 | ]; 83 | 84 | const deleteUser = async (req, res) => { 85 | if (req.session.user && req.session.user.role === 'superadmin') { 86 | await user.delUser(req.params.id); 87 | res.redirect('/users'); 88 | } else { 89 | res.status(401); 90 | res.render('401', { title: '401 Error' }); 91 | } 92 | }; 93 | 94 | const resetPassword = async (req, res) => { 95 | if (req.session.user && req.session.user.role === 'superadmin') { 96 | const password = await bcrypt.hash('password', 10); 97 | await user.updatePassword(password, req.params.id); 98 | const users = await user.getUsers(); 99 | res.render('users', { 100 | usr: users, 101 | user: req.session.user.email, 102 | title: 'Kelola Pengguna', 103 | resetSuccess: 'Reset kata sandi berhasil.', 104 | }); 105 | } else { 106 | res.status(401); 107 | res.render('401', { title: '401 Error' }); 108 | } 109 | }; 110 | 111 | module.exports = { 112 | getUsers, 113 | addUser, 114 | updateUser, 115 | deleteUser, 116 | resetPassword, 117 | }; 118 | -------------------------------------------------------------------------------- /src/queries/barangKeluarQuery.js: -------------------------------------------------------------------------------- 1 | const pool = require('../config/database'); 2 | 3 | const getDetail = async (id) => { 4 | const query = { 5 | text: 'SELECT * FROM public.keluar WHERE idkeluar = $1', 6 | values: [id], 7 | }; 8 | 9 | const result = await pool.query(query); 10 | return result.rows[0]; 11 | }; 12 | 13 | const getQty = async (id) => { 14 | const query = { 15 | text: 'SELECT * FROM public.keluar WHERE idkeluar = $1', 16 | values: [id], 17 | }; 18 | 19 | const result = await pool.query(query); 20 | return result.rows[0].qty; 21 | }; 22 | 23 | const addBarangKeluar = async ( 24 | idbarang, 25 | penerima, 26 | qty, 27 | namabarangKeluar, 28 | penginput, 29 | kodebarangKeluar, 30 | ) => { 31 | const query = { 32 | text: 'INSERT INTO public.keluar(idbarang, penerima, qty, namabarang_k, penginput, kodebarang_k) VALUES ($1, $2, $3, $4, $5, $6)', 33 | values: [idbarang, penerima, qty, namabarangKeluar, penginput, kodebarangKeluar], 34 | }; 35 | 36 | await pool.query(query); 37 | }; 38 | 39 | const updateBarangKeluar = async (penerima, qty, idkeluar) => { 40 | const query = { 41 | text: 'UPDATE public.keluar SET penerima= $1, qty = $2 WHERE idkeluar = $3', 42 | values: [penerima, qty, idkeluar], 43 | }; 44 | 45 | await pool.query(query); 46 | }; 47 | 48 | const delBarangKeluarId = async (id) => { 49 | const query = { 50 | text: 'DELETE FROM public.keluar WHERE idbarang = $1', 51 | values: [id], 52 | }; 53 | 54 | await pool.query(query); 55 | }; 56 | 57 | const delBarangKeluar = async (idkeluar) => { 58 | const query = { 59 | text: 'DELETE FROM public.keluar WHERE idkeluar = $1', 60 | values: [idkeluar], 61 | }; 62 | 63 | await pool.query(query); 64 | }; 65 | 66 | const getBarangK = async () => { 67 | const query = { 68 | text: 'SELECT * FROM public.keluar ORDER BY idkeluar DESC', 69 | values: [], 70 | }; 71 | 72 | const result = await pool.query(query); 73 | return result.rows; 74 | }; 75 | 76 | const getDetailBarang = async (id) => { 77 | const query = { 78 | text: 'SELECT * FROM public.keluar WHERE idbarang = $1', 79 | values: [id], 80 | }; 81 | 82 | const result = await pool.query(query); 83 | return result.rows; 84 | }; 85 | 86 | const totalQty = async () => { 87 | const query = { 88 | text: 'SELECT SUM(qty) FROM keluar', 89 | values: [], 90 | }; 91 | 92 | const result = await pool.query(query); 93 | return result.rows[0].sum; 94 | }; 95 | 96 | module.exports = { 97 | getDetail, 98 | getQty, 99 | updateBarangKeluar, 100 | addBarangKeluar, 101 | delBarangKeluarId, 102 | delBarangKeluar, 103 | getBarangK, 104 | getDetailBarang, 105 | totalQty, 106 | }; 107 | -------------------------------------------------------------------------------- /src/queries/barangMasukQuery.js: -------------------------------------------------------------------------------- 1 | const pool = require('../config/database'); 2 | 3 | const getDetail = async (id) => { 4 | const query = { 5 | text: 'SELECT * FROM public.masuk WHERE idmasuk = $1', 6 | values: [id], 7 | }; 8 | 9 | const result = await pool.query(query); 10 | return result.rows[0]; 11 | }; 12 | 13 | const getQty = async (id) => { 14 | const query = { 15 | text: 'SELECT * FROM public.masuk WHERE idmasuk = $1', 16 | values: [id], 17 | }; 18 | 19 | const result = await pool.query(query); 20 | return result.rows[0].qty; 21 | }; 22 | 23 | const addBarangMasuk = async ( 24 | idbarang, 25 | keterangan, 26 | qty, 27 | namabarangMasuk, 28 | penginput, 29 | kodebarangMasuk, 30 | ) => { 31 | const query = { 32 | text: 'INSERT INTO public.masuk(idbarang, keterangan, qty, namabarang_m, penginput, kodebarang_m) VALUES ($1, $2, $3, $4, $5, $6)', 33 | values: [idbarang, keterangan, qty, namabarangMasuk, penginput, kodebarangMasuk], 34 | }; 35 | 36 | await pool.query(query); 37 | }; 38 | 39 | const updateBarangMasuk = async (keterangan, qty, idmasuk) => { 40 | const query = { 41 | text: 'UPDATE public.masuk SET keterangan = $1, qty = $2 WHERE idmasuk = $3', 42 | values: [keterangan, qty, idmasuk], 43 | }; 44 | 45 | await pool.query(query); 46 | }; 47 | 48 | const delBarangMasukId = async (id) => { 49 | const query = { 50 | text: 'DELETE FROM public.masuk WHERE idbarang = $1', 51 | values: [id], 52 | }; 53 | 54 | await pool.query(query); 55 | }; 56 | 57 | const delBarangMasuk = async (idmasuk) => { 58 | const query = { 59 | text: 'DELETE FROM public.masuk WHERE idmasuk = $1', 60 | values: [idmasuk], 61 | }; 62 | 63 | await pool.query(query); 64 | }; 65 | 66 | const getBarangM = async () => { 67 | const query = { 68 | text: 'SELECT * FROM public.masuk ORDER by idmasuk DESC', 69 | values: [], 70 | }; 71 | 72 | const result = await pool.query(query); 73 | return result.rows; 74 | }; 75 | 76 | const getDetailBarang = async (id) => { 77 | const query = { 78 | text: 'SELECT * FROM public.masuk WHERE idbarang = $1', 79 | values: [id], 80 | }; 81 | 82 | const result = await pool.query(query); 83 | return result.rows; 84 | }; 85 | 86 | const totalQty = async () => { 87 | const query = { 88 | text: 'SELECT SUM(qty) FROM masuk', 89 | values: [], 90 | }; 91 | 92 | const result = await pool.query(query); 93 | return result.rows[0].sum; 94 | }; 95 | 96 | module.exports = { 97 | getDetail, 98 | getQty, 99 | addBarangMasuk, 100 | updateBarangMasuk, 101 | delBarangMasukId, 102 | delBarangMasuk, 103 | getBarangM, 104 | getDetailBarang, 105 | totalQty, 106 | }; 107 | -------------------------------------------------------------------------------- /src/queries/logQuery.js: -------------------------------------------------------------------------------- 1 | const pool = require('../config/database'); 2 | 3 | const getLog = async () => { 4 | const query = { 5 | text: 'SELECT * FROM public.log ORDER BY idlog DESC', 6 | values: [], 7 | }; 8 | 9 | const result = await pool.query(query); 10 | return result.rows; 11 | }; 12 | 13 | const addLog = async (usr, method, endpoint, statusCode) => { 14 | const query = { 15 | text: 'INSERT INTO public.log(usr, method, endpoint, status_code) VALUES ($1, $2, $3, $4)', 16 | values: [usr, method, endpoint, statusCode], 17 | }; 18 | 19 | await pool.query(query); 20 | }; 21 | 22 | module.exports = { 23 | getLog, 24 | addLog, 25 | }; 26 | -------------------------------------------------------------------------------- /src/queries/stockBarangQuery.js: -------------------------------------------------------------------------------- 1 | const pool = require('../config/database'); 2 | 3 | const getBarang = async () => { 4 | const query = { 5 | text: 'SELECT * FROM public.stock ORDER BY idbarang', 6 | values: [], 7 | }; 8 | 9 | const result = await pool.query(query); 10 | return result.rows; 11 | }; 12 | 13 | const cekKode = async (kodebarang) => { 14 | const query = { 15 | text: 'SELECT kodebarang FROM public.stock WHERE LOWER(kodebarang) = $1', 16 | values: [kodebarang], 17 | }; 18 | 19 | const result = await pool.query(query); 20 | 21 | if (!result.rowCount) { 22 | return undefined; 23 | } 24 | 25 | return result.rows[0].kodebarang; 26 | }; 27 | 28 | const cekBarang = async (namabarang) => { 29 | const query = { 30 | text: 'SELECT namabarang FROM public.stock WHERE LOWER(namabarang) = $1', 31 | values: [namabarang], 32 | }; 33 | 34 | const result = await pool.query(query); 35 | 36 | if (!result.rowCount) { 37 | return undefined; 38 | } 39 | 40 | return result.rows[0].namabarang; 41 | }; 42 | 43 | const addBarang = async ( 44 | namabarang, 45 | deskripsi, 46 | stock, 47 | image, 48 | penginput, 49 | kodebarang, 50 | ) => { 51 | const query = { 52 | text: 'INSERT INTO public.stock(namabarang, deskripsi, stock, image, penginput, kodebarang) VALUES ($1, $2, $3, $4, $5, $6)', 53 | values: [namabarang, deskripsi, stock, image, penginput, kodebarang], 54 | }; 55 | 56 | await pool.query(query); 57 | }; 58 | 59 | const getImage = async (id) => { 60 | const query = { 61 | text: 'SELECT image FROM public.stock WHERE idbarang = $1', 62 | values: [id], 63 | }; 64 | 65 | const result = await pool.query(query); 66 | return result.rows[0].image; 67 | }; 68 | 69 | const delBarang = async (id) => { 70 | const query = { 71 | text: 'DELETE FROM public.stock WHERE idbarang = $1', 72 | values: [id], 73 | }; 74 | 75 | await pool.query(query); 76 | }; 77 | 78 | const getDetail = async (id) => { 79 | const query = { 80 | text: 'SELECT * FROM public.stock WHERE idbarang = $1', 81 | values: [id], 82 | }; 83 | 84 | const result = await pool.query(query); 85 | return result.rows[0]; 86 | }; 87 | 88 | const updateBarang = async ( 89 | namabarang, 90 | deskripsi, 91 | stock, 92 | image, 93 | kodebarang, 94 | idbarang, 95 | ) => { 96 | const query = { 97 | text: 'UPDATE public.stock SET namabarang = $1, deskripsi = $2, stock = $3, image = $4, kodebarang = $5 WHERE idbarang = $6', 98 | values: [namabarang, deskripsi, stock, image, kodebarang, idbarang], 99 | }; 100 | 101 | await pool.query(query); 102 | }; 103 | 104 | const getStock = async (id) => { 105 | const query = { 106 | text: 'SELECT * FROM public.stock WHERE idbarang = $1', 107 | values: [id], 108 | }; 109 | 110 | const result = await pool.query(query); 111 | 112 | if (!result.rowCount) { 113 | return 'undefined'; 114 | } 115 | 116 | return result.rows[0].stock; 117 | }; 118 | 119 | const updateStock = async (newStock, idbarang) => { 120 | const query = { 121 | text: 'UPDATE public.stock SET stock = $1 WHERE idbarang = $2', 122 | values: [newStock, idbarang], 123 | }; 124 | 125 | await pool.query(query); 126 | }; 127 | 128 | const checkKodeDuplicate = async (kodebarang) => { 129 | const query = { 130 | text: 'SELECT * FROM public.stock WHERE LOWER(kodebarang) = $1', 131 | values: [kodebarang], 132 | }; 133 | 134 | const result = await pool.query(query); 135 | return result.rows[0]; 136 | }; 137 | 138 | const checkDuplicate = async (namabarang) => { 139 | const query = { 140 | text: 'SELECT * FROM public.stock WHERE LOWER(namabarang) = $1', 141 | values: [namabarang], 142 | }; 143 | 144 | const result = await pool.query(query); 145 | return result.rows[0]; 146 | }; 147 | 148 | const getKode = async (id) => { 149 | const query = { 150 | text: 'SELECT kodebarang FROM public.stock WHERE idbarang = $1', 151 | values: [id], 152 | }; 153 | 154 | const result = await pool.query(query); 155 | return result.rows[0].kodebarang; 156 | }; 157 | 158 | const getNama = async (id) => { 159 | const query = { 160 | text: 'SELECT namabarang FROM public.stock WHERE idbarang = $1', 161 | values: [id], 162 | }; 163 | 164 | const result = await pool.query(query); 165 | return result.rows[0].namabarang; 166 | }; 167 | 168 | const totalStock = async () => { 169 | const query = { 170 | text: 'SELECT SUM(stock) FROM stock', 171 | values: [], 172 | }; 173 | 174 | const result = await pool.query(query); 175 | return result.rows[0].sum; 176 | }; 177 | 178 | module.exports = { 179 | getBarang, 180 | cekKode, 181 | cekBarang, 182 | addBarang, 183 | getImage, 184 | delBarang, 185 | getDetail, 186 | updateBarang, 187 | getStock, 188 | updateStock, 189 | checkKodeDuplicate, 190 | checkDuplicate, 191 | getKode, 192 | getNama, 193 | totalStock, 194 | }; 195 | -------------------------------------------------------------------------------- /src/queries/usersQuery.js: -------------------------------------------------------------------------------- 1 | const pool = require('../config/database'); 2 | 3 | const email = async (userEmail) => { 4 | const query = { 5 | text: 'SELECT email FROM public.users WHERE email = $1', 6 | values: [userEmail], 7 | }; 8 | 9 | const result = await pool.query(query); 10 | 11 | if (!result.rowCount) { 12 | return 'undefined'; 13 | } 14 | 15 | return result.rows[0].email; 16 | }; 17 | 18 | const email2 = async (userEmail) => { 19 | const query = { 20 | text: 'SELECT email FROM public.users WHERE LOWER(email) = $1', 21 | values: [userEmail], 22 | }; 23 | 24 | const result = await pool.query(query); 25 | 26 | if (!result.rowCount) { 27 | return undefined; 28 | } 29 | 30 | return result.rows[0].email; 31 | }; 32 | 33 | const password = async (userPassword) => { 34 | const query = { 35 | text: 'SELECT password FROM public.users WHERE password = $1', 36 | values: [userPassword], 37 | }; 38 | 39 | const result = await pool.query(query); 40 | 41 | if (!result.rowCount) { 42 | return 'undefined'; 43 | } 44 | 45 | return result.rows[0].password; 46 | }; 47 | 48 | const role = async (userEmail, userPassword) => { 49 | const query = { 50 | text: 'SELECT role FROM public.users WHERE email = $1 AND password = $2', 51 | values: [userEmail, userPassword], 52 | }; 53 | 54 | const result = await pool.query(query); 55 | 56 | if (!result.rowCount) { 57 | return 'undefined'; 58 | } 59 | 60 | return result.rows[0].role; 61 | }; 62 | 63 | const getUsers = async () => { 64 | const query = { 65 | text: 'SELECT * FROM public.users ORDER BY id', 66 | values: [], 67 | }; 68 | 69 | const result = await pool.query(query); 70 | return result.rows; 71 | }; 72 | 73 | const delUser = async (id) => { 74 | const query = { 75 | text: 'DELETE FROM public.users WHERE id = $1', 76 | values: [id], 77 | }; 78 | 79 | await pool.query(query); 80 | }; 81 | 82 | const addUser = async (userEmail, userPassword, userRole) => { 83 | const query = { 84 | text: 'INSERT INTO public.users(email, password, role) VALUES ($1, $2, $3)', 85 | values: [userEmail, userPassword, userRole], 86 | }; 87 | 88 | await pool.query(query); 89 | }; 90 | 91 | const getDetail = async (id) => { 92 | const query = { 93 | text: 'SELECT * FROM public.users WHERE id = $1', 94 | values: [id], 95 | }; 96 | 97 | const result = await pool.query(query); 98 | return result.rows[0]; 99 | }; 100 | 101 | const checkDuplicate = async (userEmail) => { 102 | const query = { 103 | text: 'SELECT * FROM public.users WHERE LOWER(email) = $1', 104 | values: [userEmail], 105 | }; 106 | 107 | const result = await pool.query(query); 108 | return result.rows[0]; 109 | }; 110 | 111 | const updateUser = async (newUser) => { 112 | const { 113 | email: newEmail, password: newPassword, role: newRole, id, 114 | } = newUser; 115 | const query = { 116 | text: 'UPDATE public.users SET email = $1, password = $2, role = $3 WHERE id = $4', 117 | values: [newEmail, newPassword, newRole, id], 118 | }; 119 | 120 | await pool.query(query); 121 | }; 122 | 123 | const checkProfile = async (userEmail) => { 124 | const query = { 125 | text: 'SELECT * FROM public.users WHERE email = $1', 126 | values: [userEmail], 127 | }; 128 | 129 | const result = await pool.query(query); 130 | return result.rows[0]; 131 | }; 132 | 133 | const updateEmail = async (newUser) => { 134 | const { email: newEmail, id: newId } = newUser; 135 | const query = { 136 | text: 'UPDATE public.users SET email = $1 WHERE id = $2', 137 | values: [newEmail, newId], 138 | }; 139 | 140 | await pool.query(query); 141 | }; 142 | 143 | const updatePassword = async (newPassword, id) => { 144 | const query = { 145 | text: 'UPDATE public.users SET password = $1 WHERE id = $2', 146 | values: [newPassword, id], 147 | }; 148 | 149 | await pool.query(query); 150 | }; 151 | 152 | const updateRole = async (newUser) => { 153 | const { role: newRole, id } = newUser; 154 | const query = { 155 | text: 'UPDATE public.users SET role = $1 WHERE id = $2', 156 | values: [newRole, id], 157 | }; 158 | 159 | await pool.query(query); 160 | }; 161 | 162 | const checkPassword = async (userEmail) => { 163 | const query = { 164 | text: 'SELECT password FROM public.users WHERE email = $1', 165 | values: [userEmail], 166 | }; 167 | 168 | const result = await pool.query(query); 169 | 170 | if (!result.rowCount) { 171 | return 'undefined'; 172 | } 173 | 174 | return result.rows[0].password; 175 | }; 176 | 177 | const checkRole = async (userEmail) => { 178 | const query = { 179 | text: 'SELECT role FROM public.users WHERE email = $1', 180 | values: [userEmail], 181 | }; 182 | 183 | const result = await pool.query(query); 184 | 185 | if (!result.rowCount) { 186 | return 'undefined'; 187 | } 188 | 189 | return result.rows[0].role; 190 | }; 191 | 192 | const totalUsers = async () => { 193 | const query = { 194 | text: 'SELECT COUNT(id) FROM users', 195 | values: [], 196 | }; 197 | 198 | const result = await pool.query(query); 199 | 200 | return result.rows[0].count; 201 | }; 202 | 203 | module.exports = { 204 | email, 205 | email2, 206 | password, 207 | role, 208 | getUsers, 209 | delUser, 210 | addUser, 211 | getDetail, 212 | checkDuplicate, 213 | updateUser, 214 | checkProfile, 215 | updateEmail, 216 | updatePassword, 217 | updateRole, 218 | checkPassword, 219 | checkRole, 220 | totalUsers, 221 | }; 222 | -------------------------------------------------------------------------------- /src/routes/accountRoutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const router = express.Router(); 4 | const { 5 | getAccount, changeEmail, changePassword, changeRole, 6 | } = require('../controllers/accountController'); 7 | 8 | router.get('/account', getAccount); 9 | router.put('/account/changeemail', changeEmail); 10 | router.put('/account/changepassword', changePassword); 11 | router.put('/account/changerole', changeRole); 12 | 13 | module.exports = router; 14 | -------------------------------------------------------------------------------- /src/routes/authRoutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const router = express.Router(); 4 | const { login, logout } = require('../controllers/authController'); 5 | 6 | router.post('/login', login); 7 | router.get('/logout', logout); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /src/routes/barangKeluarRoutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const router = express.Router(); 4 | const { 5 | getBarangKeluar, addBarangKeluar, updateBarangKeluar, deleteBarangKeluar, 6 | } = require('../controllers/barangKeluarController'); 7 | 8 | router.get('/barangkeluar', getBarangKeluar); 9 | router.post('/barangkeluar', addBarangKeluar); 10 | router.put('/barangkeluar/:id', updateBarangKeluar); 11 | router.post( 12 | '/barangkeluar/delete/:id', 13 | deleteBarangKeluar, 14 | ); 15 | 16 | module.exports = router; 17 | -------------------------------------------------------------------------------- /src/routes/barangMasukRoutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const router = express.Router(); 4 | const { 5 | getBarangMasuk, addBarangMasuk, updateBarangMasuk, deleteBarangMasuk, 6 | } = require('../controllers/barangMasukController'); 7 | 8 | router.get('/barangmasuk', getBarangMasuk); 9 | router.post('/barangmasuk', addBarangMasuk); 10 | router.put('/barangmasuk/:id', updateBarangMasuk); 11 | router.post('/barangmasuk/delete/:id', deleteBarangMasuk); 12 | 13 | module.exports = router; 14 | -------------------------------------------------------------------------------- /src/routes/barangRoutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const router = express.Router(); 4 | const { 5 | getBarang, getBarangDetail, addBarang, updateBarang, deleteBarang, 6 | } = require('../controllers/barangController'); 7 | 8 | router.get('/barang', getBarang); 9 | router.get('/barang/:id', getBarangDetail); 10 | router.post('/barang', addBarang); 11 | router.put('/barang/:id', updateBarang); 12 | router.post('/barang/delete/:id', deleteBarang); 13 | 14 | module.exports = router; 15 | -------------------------------------------------------------------------------- /src/routes/dashboardRoutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const router = express.Router(); 4 | const getIndex = require('../controllers/dashboardController'); 5 | 6 | router.get('/', getIndex); 7 | 8 | module.exports = router; 9 | -------------------------------------------------------------------------------- /src/routes/logRoutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const router = express.Router(); 4 | const getLog = require('../controllers/logController'); 5 | 6 | router.get('/log', getLog); 7 | 8 | module.exports = router; 9 | -------------------------------------------------------------------------------- /src/routes/usersRoutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const router = express.Router(); 4 | const { 5 | getUsers, addUser, updateUser, deleteUser, resetPassword, 6 | } = require('../controllers/usersController'); 7 | 8 | router.get('/users', getUsers); 9 | router.post('/users', addUser); 10 | router.put('/users/:id', updateUser); 11 | router.post('/users/delete/:id', deleteUser); 12 | router.post('/users/resetpassword/:id', resetPassword); 13 | 14 | module.exports = router; 15 | -------------------------------------------------------------------------------- /src/server.js: -------------------------------------------------------------------------------- 1 | const app = require('./app'); 2 | require('dotenv').config(); 3 | 4 | const host = process.env.HOSTNAME; 5 | const port = process.env.PORT; 6 | 7 | app.listen(port, () => { 8 | console.log(`Listening to the server on http://${host}:${port}`); 9 | }); 10 | -------------------------------------------------------------------------------- /src/views/401.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | <%= title %> 10 | 11 | 12 | 13 |
14 |
15 |

Error 401 - Unauthorized

16 |
17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /src/views/404.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | <%= title %> 10 | 11 | 12 | 13 |
14 |
15 |

Error 404 - Page Not Found

16 |
17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /src/views/account.ejs: -------------------------------------------------------------------------------- 1 | <%- include('./partials/header') %> 2 | <%- include('./partials/nav') %> 3 |
4 |

Edit Akun

5 |
6 | 7 | 8 | 9 | 10 |
11 |
12 | <% if(typeof errors != 'undefined') { %> 13 | <% errors.forEach(error => { %> 14 |
15 | 16 | <%= error.msg %> 17 |
18 | <% }) %> 19 | <% } %> 20 | <% if(typeof locals.user != 'undefined' && locals.user != 'superadmin@email.com') { %> 21 | 22 |
23 |
24 |

Ganti Email

25 |
26 | 27 | 28 |
29 |
30 | 31 | 32 | 33 |
34 | 35 | <%= usr.oldEmail || usr.email %> 36 |
37 |
38 | 39 | 40 |
41 |
42 | 43 | 44 |
45 |
46 | 47 | 48 | 51 |
52 |
53 | 54 | <% } %> 55 | 56 | 57 |
58 |
59 |

Ganti Kata Sandi

60 |
61 | 62 | 63 |
64 |
65 | 66 | 67 |
68 | 69 | 70 |
71 |
72 | 73 | 74 |
75 |
76 | 77 | 78 |
79 |
80 | 81 | 82 | 85 |
86 |
87 | 88 | 89 | <% if(typeof locals.user != 'undefined' && locals.user != 'superadmin@email.com') { %> 90 | 91 |
92 |
93 |

Ganti Role

94 |
95 | 96 | 97 |
98 |
99 | 100 | 101 | 102 | 103 |
104 | 105 | <%= usr.oldRole || usr.role %> 106 |
107 |
108 | 109 | user 110 |
111 |
112 | 113 | 114 |
115 |
116 | 117 | 118 | 121 |
122 |
123 | 124 | <% } %> 125 | 126 |
127 | 128 |
129 | <%- include('./partials/footer') %> -------------------------------------------------------------------------------- /src/views/barang.ejs: -------------------------------------------------------------------------------- 1 | <%- include('./partials/header') %> 2 | <%- include('./partials/nav') %> 3 |
4 |

Stok Barang

5 |
6 |
7 |
8 |
9 | 13 |
14 |
15 |
16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 |
24 |
25 | <% if(typeof errors != 'undefined') { %> 26 | <% errors.forEach(error => { %> 27 |
28 | 29 | <%= error.msg %> 30 |
31 | <% }) %> 32 | <% } %> 33 |
34 |
35 |

Tabel Stok Barang

36 |
37 | 38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | <% brg.forEach((element, index)=> { %> 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 76 | 77 | 78 | 79 | 124 | 125 | 126 | 147 | 148 | 149 | 187 | 188 | <% }) %> 189 | 190 |
NoKode BarangGambarNama BarangDeskripsiStokPenginputAksi
<%= index+1%><%= element.kodebarang %><%= element.namabarang %><%= element.deskripsi %><%= element.stock %><%= element.penginput %> 63 | 64 | <% if(typeof locals.user != 'undefined') { %> 65 | 68 | 71 | <% } %> 72 | 75 |
191 |
192 | 193 |
194 | 195 |
196 | 197 |
198 | 199 |
200 | 201 |
202 | 203 | 204 | 245 | 246 | <%- include('./partials/footer') %> -------------------------------------------------------------------------------- /src/views/barangDetail.ejs: -------------------------------------------------------------------------------- 1 | <%- include('./partials/header') %> 2 | <%- include('./partials/nav') %> 3 |
4 |

Detail Barang

5 |
6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 |
14 |

<%= brg.namabarang %>

15 | 16 | 17 |
18 |
19 |
20 |
Kode Barang
21 |
: <%= brg.kodebarang %>
22 |
23 |
24 |
Deskripsi
25 |
: <%= brg.deskripsi %>
26 |
27 |
28 |
Stok
29 |
: <%= brg.stock %>
30 |
31 |
32 |
Penginput
33 |
: <%= brg.penginput %>
34 |
35 | 36 |


37 | 38 |

Barang Masuk

39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | <% brgm.forEach((element, index)=> { %> 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | <% }) %> 63 | 64 |
NoTanggal & WaktuKode BarangNama BarangJumlahKeteranganPenginput
<%= index+1%><%= moment(element.tanggal).locale('id').format('DD-MM-YYYY HH:mm:ss') %><%= element.kodebarang_m %><%= element.namabarang_m %><%= element.qty %><%= element.keterangan %><%= element.penginput %>
65 | 66 |

67 | 68 |

Barang Keluar

69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | <% brgk.forEach((element, index)=> { %> 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | <% }) %> 93 | 94 |
NoTanggal & WaktuKode BarangNama BarangJumlahPenerimaPenginput
<%= index+1%><%= moment(element.tanggal).locale('id').format('DD-MM-YYYY HH:mm:ss') %><%= element.kodebarang_k %><%= element.namabarang_k %><%= element.qty %><%= element.penerima %><%= element.penginput %>
95 |
96 |
97 |
98 | 99 |
100 | <%- include('./partials/footer') %> -------------------------------------------------------------------------------- /src/views/barangKeluar.ejs: -------------------------------------------------------------------------------- 1 | <%- include('./partials/header') %> 2 | <%- include('./partials/nav') %> 3 |
4 |

Barang Keluar

5 |
6 |
7 |
8 |
9 | 13 |
14 |
15 |
16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 |
24 |
25 | <% if(typeof error != 'undefined'){ %> 26 |
27 | 28 | <%= error %> 29 |
30 | <% } %> 31 |
32 |
33 |

Tabel Barang Keluar

34 |
35 | 36 |
37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | <% if(typeof locals.user != 'undefined') { %> 48 | 49 | <% } %> 50 | 51 | 52 | 53 | <% brgk.forEach((element, index)=> { %> 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | <% if(typeof locals.user != 'undefined') { %> 63 | 71 | <% } %> 72 | 73 | 74 | 75 | 105 | 106 | 107 | 131 | 132 | <% }) %> 133 | 134 |
NoTanggal & WaktuKode BarangNama BarangJumlahPenerimaPenginputAksi
<%= index+1%><%= moment(element.tanggal).locale('id').format('DD-MM-YYYY HH:mm:ss') %><%= element.kodebarang_k %><%= element.namabarang_k %><%= element.qty %><%= element.penerima %><%= element.penginput %> 64 | 67 | 70 |
135 |
136 | 137 |
138 | 139 |
140 | 141 |
142 | 143 |
144 | 145 |
146 | 147 | 148 | 192 | 193 | <%- include('./partials/footer') %> -------------------------------------------------------------------------------- /src/views/barangMasuk.ejs: -------------------------------------------------------------------------------- 1 | <%- include('./partials/header') %> 2 | <%- include('./partials/nav') %> 3 |
4 |

Barang Masuk

5 |
6 |
7 |
8 |
9 | 13 |
14 |
15 |
16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 |
24 |
25 | <% if(locals.deleteFail){ %> 26 |
27 | 28 | <%= deleteFail %> 29 |
30 | <% } %> 31 |
32 |
33 |

Tabel Barang Masuk

34 |
35 | 36 |
37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | <% if(typeof locals.user != 'undefined') { %> 48 | 49 | <% } %> 50 | 51 | 52 | 53 | <% brgm.forEach((element, index)=> { %> 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | <% if(typeof locals.user != 'undefined') { %> 63 | 71 | <% } %> 72 | 73 | 74 | 75 | 105 | 106 | 107 | 131 | 132 | <% }) %> 133 | 134 |
NoTanggal & WaktuKode BarangNama BarangJumlahKeteranganPenginputAksi
<%= index+1%><%= moment(element.tanggal).locale('id').format('DD-MM-YYYY HH:mm:ss') %><%= element.kodebarang_m %><%= element.namabarang_m %><%= element.qty %><%= element.keterangan %><%= element.penginput %> 64 | 67 | 70 |
135 |
136 | 137 |
138 | 139 |
140 | 141 |
142 | 143 |
144 | 145 |
146 | 147 | 148 | 188 | 189 | <%- include('./partials/footer') %> -------------------------------------------------------------------------------- /src/views/index.ejs: -------------------------------------------------------------------------------- 1 | <%- include('./partials/header') %> 2 | <%- include('./partials/nav') %> 3 |
4 |

Dasbor

5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 | 15 |
16 |
17 | 18 |
19 |
20 | <% if(totalStock>0) { %> 21 |

<%= totalStock %>

22 | <% }else{ %> 23 |

0

24 | <% } %> 25 | 26 |

Stok Barang

27 |
28 |
29 | 30 |
31 | Selengkapnya 32 |
33 |
34 | 35 |
36 | 37 |
38 |
39 | <% if(totalQtyBM>0) { %> 40 |

<%= totalQtyBM %>

41 | <% }else{ %> 42 |

0

43 | <% } %> 44 | 45 |

Barang Masuk

46 |
47 |
48 | 49 |
50 | Selengkapnya 51 |
52 |
53 | 54 |
55 | 56 |
57 |
58 | <% if(totalQtyBK>0) { %> 59 |

<%= totalQtyBK %>

60 | <% }else{ %> 61 |

0

62 | <% } %> 63 | 64 |

Barang Keluar

65 |
66 |
67 | 68 |
69 | Selengkapnya 70 |
71 |
72 | 73 | <% if(typeof locals.user != 'undefined') { %> 74 |
75 | 76 |
77 |
78 | <% if(totalUsers>0) { %> 79 |

<%= totalUsers %>

80 | <% }else{ %> 81 |

0

82 | <% } %> 83 | 84 |

Pengguna

85 |
86 |
87 | 88 |
89 | Selengkapnya 90 |
91 |
92 | 93 | <% } %> 94 |
95 | 96 |
97 |
98 | <%- include('./partials/footer') %> -------------------------------------------------------------------------------- /src/views/log.ejs: -------------------------------------------------------------------------------- 1 | <%- include('./partials/header') %> 2 | <%- include('./partials/nav') %> 3 |
4 |

Log Aplikasi

5 |
6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 |

Tabel Log Aplikasi

18 |
19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | <% log.forEach((element, index)=> { %> 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <% }) %> 43 | 44 |
NoTanggal & WaktuPenggunaMethodEndpointStatus Code
<%= index+1%><%= moment(element.date).locale('id').format('DD-MM-YYYY HH:mm:ss') %><%= element.usr %><%= element.method %><%= element.endpoint %><%= element.status_code %>
45 |
46 | 47 |
48 | 49 |
50 | 51 |
52 | 53 |
54 | 55 |
56 | 57 | 58 | 79 | 80 | <%- include('./partials/footer') %> -------------------------------------------------------------------------------- /src/views/login.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= locals.title ? title : "Login" %> 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/views/partials/footer.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | Copyright © 2023 Sava Reyhano. All rights reserved. 6 |
7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /src/views/partials/header.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= locals.title ? title : "Stock Barang" %> 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/views/partials/nav.ejs: -------------------------------------------------------------------------------- 1 |
2 | 3 | 37 | 38 | 39 | 40 | 150 | 151 | 152 |
153 | 154 |
155 |
156 |
-------------------------------------------------------------------------------- /src/views/users.ejs: -------------------------------------------------------------------------------- 1 | <%- include('./partials/header') %> 2 | <%- include('./partials/nav') %> 3 |
4 |

Kelola Pengguna

5 |
6 |
7 |
8 |
9 | 13 |
14 |
15 |
16 |
17 |
18 |
19 | 20 | 21 |
22 |
23 |
24 |
25 |
26 | 27 | Info: kata sandi untuk pengguna baru dan reset kata sandi adalah "password" 28 |
29 | <% if(typeof errors != 'undefined') { %> 30 | <% errors.forEach(error => { %> 31 |
32 | 33 | <%= error.msg %> 34 |
35 | <% }) %> 36 | <% } %> 37 | <% if(locals.resetSuccess){ %> 38 |
39 | 40 | <%= resetSuccess %> 41 |
42 | <% } %> 43 |
44 |
45 |

Tabel Kelola Pengguna

46 |
47 | 48 |
49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | <% usr.forEach((element, index)=> { %> 60 | 61 | 62 | 63 | 64 | 77 | 78 | 79 | 80 | 114 | 115 | 116 | 137 | 138 | 139 | 160 | 161 | <% }) %> 162 | 163 |
NoEmailRoleAksi
<%= index+1%><%= element.email %><%= element.role %> 65 | <% if(element.role != 'superadmin') { %> 66 | 69 | 72 | 75 | <% } %> 76 |
164 |
165 | 166 |
167 | 168 |
169 | 170 |
171 | 172 |
173 | 174 |
175 | 176 | 177 | 209 | 210 | <%- include('./partials/footer') %> --------------------------------------------------------------------------------