/invoice

Chaincode and rest/json based node.js application

Primary LanguageJavaScript

Invoice

Chaincode and rest/json based node.js application

Creating Invoice using Hyperledger Fabric | Mandatory

GO Version: go version go1.11.5 linux/amd64

OS: Ubuntu 18.04 LTS

Installing the prerequisites

Step 1

  1. Download Go Language in this link https://golang.org/doc/install and follow the step by step installation.
  2. Set your gopath by opening the terminal and run echo $GOPATH

Step 2

  1. Clone this repository by running git clone https://github.com/ssvergara/invoice.git
  2. Open the Fabcar folder and copy all the files except the node modules
  3. Create a folder named Fabcar under fabric-samples/ and paste the files we copied earlier.

Output

fabric-samples/
            |-Fabcar
	|- openFabric.sh
	|--enrollAdmin.js
	|---mainregisteruser.js
	|---1stparticipantUser.js
	|---2ndparticipantUser.js
	|--- OEM.js
	|---bankuser.js
	|---appmain.js
	|---app1stparticipant.js
	|---appOEM.js
	|---appBank.js
  1. Create a folder fabcar under fabric-samples/chaincode/
  2. Make a new folder go.
  3. Inside the cloned repository, under chaincode, Copy the go folder and paste it on to fabric-samples/chaincode/

Output

fabric-samples/
	|- chaincode
            |-fabcar
	|--go
	|---scm.go

Step 3.

Open terminal and go to this directory fabric-samples/Fabcar/ Start the fabric ./openFabric.sh

Run npm install to create the modules

Run enrollAdmin.js

Run node mainregisteruser.js

Run node appmain.js

Output

1stuser

Step 4

Test the endpoints using Insomnia REST Client. [Download Insomnia REST Client here: https://insomnia.rest/download/ ]

  1. Choose the function GET and enter the localhost:3000/queryAllinvoice. You must see a data like this:

localhost 3000 get

  1. Create a new tab and choose the function POST and enter the localhost:3000/invoice. Create the parameters and create your own invoices and click Send;

Raise Invoice

Parameters

invoiceNumber

billedTo

invoiceDate

invoiceAmount

itemDescription

gr

isPaid

paidAmount

repaid

repaymentAmount

Note: gr, isPaid, paidAmount, repaid, repaymentAmount, default values are as follows:

gr = N

isPaid = N

paidAmount = 0

repaid = N

repaymentAmount = 0

localhost 3000 post

  1. Create a new tab and choose the function PUT and enter the localhost:3000/invoice. Create the parameters and create your own invoices and click Send;

Goods Received

Parameters

invoiceNumber

gr

localhost 3000 put gr

  1. Create a new tab and choose the function PUT and enter the localhost:3000/invoice. Create the parameters and create your own invoices and click Send;

Bank Payment to Supplier

Parameters

invoiceNumber

paidAmount

Note: Paid Amount must be less than Invoice Amount

localhost 3000 put paidamount

  1. Create a new tab and choose the function PUT and enter the localhost:3000/invoice. Create the parameters and create your own invoices and click Send;

OEM repays to Bank

Parameters

invoiceNumber

repaymentAmount

Note: Repayment Amount must be greater than the value of Paid Amount.

localhost 3000 repayment


Creating Invoice using Hyperledger Fabric | Optional

Step 1 | Raise Invoice (only supplier can create Invoice)

Open a new terminal and open the folder fabric-samples/Fabcar/

Enroll a new user node enrollAdmin.js

Run node 1stparticipantUser.js

Run node app1stparticipant.js

  1. Open the Insomnia REST Client

Choose the function GET and enter the localhost:3001/invoice

localhost 3001 get

  1. Choose the POST function and create the parameters:

invoiceNumber

billedTo

invoiceDate

invoiceAmount

itemDescription

gr

isPaid

paidAmount

repaid

repaymentAmount

localhost 3001 post

Step 2 | Goods received (only OEM can do GR)

Open a new terminal and open the folder fabric-samples/Fabcar/

Enroll a new user node enrollAdmin.js

Run node OEM.js

Run node appOEM.js

Open the Insomnia REST Client

  1. Choose the function GET and enter the localhost:3003/invoice

localhost 3003 get

  1. Choose the PUT function and create the parameters:

invoiceNumber

gr

localhost 3003 put

Step 3 | Goods received (only bank can pay to supplier)

Open a new terminal and open the folder fabric-samples/Fabcar/

Enroll a new user node enrollAdmin.js

Run node bankuser.js

Run node appBank.js

Open the Insomnia REST Client

  1. Choose the function GET and enter the localhost:3007/invoice

localhost 3007 get

  1. Choose the PUT function and create the parameters:

invoiceNumber

paidAmount

localhost 3007 put gr

Step 4 | Transaction Log

Open the Insomnia Rest Client. Choose the function GET and enter the localhost:3000

  1. Click the query tab and type invoice as the name and INV0 as the value to get the transaction Id and timestamp.

localhost 3000 transaction log

Step 5 | Display Invoices

Open the Insomnia Rest Client, choose the function GET and enter the localhost:3000

Display invoices per Supplier

Type the user1 in supplier to get the invoices per supplier

localhost 3000 supplierhistory

Display invoices per OEM

Type the Lenovo in oem to get the invoices per oem

localhost 3000 oemhistory