Integration with Restaurant Invoice Monitoring System (RIMS) as imposed by Pakistan Tax Authorities

Hi All,
Tax Authorities in Pakistan have asked all the restaurants to integrate their softwares with Restaurant Invoice Monitoring System (RIMS). And provided sample codes for different languages like C#, Java, JavaScript, Php etc.

It is basically a REST API where our software needs to send details of every sale.

The Documentation Link is : http://rims.punjab.gov.pk/Documentation/index.html

The C# code sample is give below:

string URI = “http://rims.punjab.gov.pk/api/databaseupdate/formdata”;

string myParameters = “key=”+ lbl_key.Text +"&data={“pntn”:“25251490”,“branchcode”:“BR25251490496”,“invoice_number”:“431-01”,“invoice_date”: “2015-08-04”,“invoice_time”: “02:41”,“discount_percent”: “2”,“service_charges_percent”: “5”,“tax_percent”:“16”,“table_no”: “1”,“phone”: “042456456”,“customer_name”:“Sani”,“detail”:[{“item_code”:“34”,“item”:“Piza”, “quantity”:“1”,“unit_price”:“725”}]}";

using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = “application/x-www-form-urlencoded”;
string HtmlResult = wc.UploadString(URI, myParameters);
txt_postData.Text = HtmlResult;
}

Similarly javascript sample code is also provided.

Is it possible to integrate SambaPos5 with such an API. If so then please guide me to some tutorials or other similar stuff to get started.

Yes, the Scripting Engine in SambaPOS is JScript. You can use that.

And here is how to hook the .NET WebClient Class inside SambaPOS Script …

Reference: https://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx

Sample Code:

function sendWebCli() {
  var lib = host.lib("System");
  var wc = new lib.System.Net.WebClient();

  var URI = "http://rims.punjab.gov.pk/api/databaseupdate/formdata";

  var myParameters = "whatever (your data looks like JSON)";

  wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
  //         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not sure about this part

  var HtmlResult = wc.UploadString(URI, myParameters);
}
2 Likes

Thanks a lot QMcKay.

1 Like

You can also achieve the FBR request via the database following methods:

First of all we need to create a new table in your database. Datatype of Column BillNo should match the data type of the column you are using to store billNo/InvoiceNO.

USE POS

CREATE TABLE [dbo].[FBR_Table] (

            [ID] [int] IDENTITY (1, 1) NOT NULL ,

            [BillNo] [nvarchar] (100) ,

            [Transmitted] [bit] default(0),

            [Entry_Date] DATETIME DEFAULT GETDATE()

) ON [PRIMARY]

GO


Secondly we need to create a trigger on your invoice table in which you are storing details of invoice mainly total amount, GST , Invoice number and invoice date. This trigger will send your invoice details in my table.
CREATE TRIGGER [dbo].[trgFBR_InvoiceUpd]

ON [dbo].[yourtablename]

AFTER INSERT AS

DECLARE @BillNo nvarchar (100)

SELECT @BillNo= yourInvoiceColumn FROM INSERTED;

IF NOT EXISTS  (SELECT BillNo FROM FBR_Table WHERE  billno=@BillNo)

    INSERT INTO FBR_Table (BillNo, Transmitted) VALUES (@BillNo,0);

GO


Thirdly we need to create a user for our work and allow access to that user.
USE [master]

                                    exec sp_addlogin 'FBR', 'FBR'

                                       USE   POS  

                                    exec sp_adduser  'FBR', 'FBR'

USE POS

Grant select on [checks] to ‘FBR’

Grant select,insert,update on FBR_Table to ‘FBR’