Skip to main content

Document Triggers

The Document Triggers function allows you to recieve input from a third party service during the proccess of issuing documents.
The document data is sent to a predefined third party URL address that can, in response, influence the issuing process.

tip

You can find instructions for adding an address, verifying the data and converting from base64 to JSON here.

Document Trigger Example

The example below shows the data that's sent to the predefined URL address when issuing a document:

{
"data": "W3siQWNjb3ViRHVtaS...",//stock data in Base64
"table": "documents",//table
"db_name": "wizdb...",//database name
"company_info": { "private_company": "5656563",
"company_vatnum": "123456789"},//company information
"date_time": "Sun, 20 Mar 2022 15:37:04 GMT",//Sending time
"signature": "3904cadb8a19e800ec1518087faf45" //signature
}

Trigger fields

data stock data in a base64 format
table“documents”
db_nameThe DB from which the stock is produced
company_info:
private_companyThe company's identification (ח.פ חברה)
company_vatnum Licensed dealer number (מספר עוסק מורשה)
date_timeDate and time the trigger was sent
signatureData signature

Document data

Below is a list of the fields that the data parameter can return if their data has been changed:

id, DocNumber, DocumentID, ValueDate, DueDate, Osek874, AccountKey, Address, Phone, AccMail, Warehouse, Agent, Currency, Rate, DiscountPrc, TFtal moves: StockID, ItemKey, ItemName, Quantity, Price, DiscountPrc, CurrencyCode, Rate, TFtal, Warehouse, Agent

Click here for descriptions of Document fields

Example of a document data after converting from base64

{
"id":1,
"DocNumber": 1,
"DocumentID": 1,
"ValueDate": "2021-11-11",
"DueDate": "2021-11-11",
"Osek874": 123456789,
"AccountKey": "30005",
"Address": "מנחם בגין 169",
"Phone": "0525554434",
"AccMail": "@...",
"Warehouse": 2,
"Agent": 20,
"Currency": "$",
"Rate": 1,
"DiscountPrc": 0,
"TFtal": 40,
"moves": [
{
"StockID": "1",
"ItemKey": "1004",
"ItemName": "עציץ",
"Quantity": 1,
"Price": 40,
"DiscountPrc": 0,
"CurrencyCode": "שח",
"Rate": 1,
"Tftal": 40 ,
"Warehouse": 2,
"Agent": 20
}
]
}

Responses

There are 3 possible response types to a trigger:

  1. Block or Approve
  2. Return Errors and/or Messages
  3. Make changes
NameTypeDescription
DoIssue
Required
0 = blocking issue
1 = continued issue
Issue the document
StockID
Required
Integer numberID from Stock table
MessagesString (max 249)Array of messages and error
ItemsArraycannot be sent together with TotalDocumentArray of offers and adding items
TotalDocumentFloat numbercannot be sent together with itemsNew total to the document
textString (max 249)cannot be sent together with itemsTotal change reason

1. Block or Approve

{
"DoIssue": 1,
"StockID":stock.StockID
}

2. Receive Errors and/or Messages

The following parameters should be included in a messages

NameTypeDescription
status
Required
1 = message , 2 = errorType of message
text
Required
String (max 249)The message / error that will be displayed to the user
{
"DoIssue": 0,
"StockID":stock.StockID ,
"Messages": [{"text": "לא ניתן למכור כרגע ללקוח זה" , "status": "2"},
"text": "ניתן למכור מהתאריך 01.01.2022" , "status": "1"}]
{
Important

The messages and errors are only displayed to the user, they won't be saved in the database.

3. Make changes

NameTypeDescription
status
Required
0 = question,
1 = message
whether the item be add automatically
0 = question, the offer will be shown to the user on the screen who will decide whether to add or not
1 = message, the item will be added to the document and a message will be displayed to the user
text
Required
String (max 249)The message text
item
itemKey
Required
String (max 20)Item Key
quantity
Required
Float numberquantity
DiscountPrcFloat numberDiscountPrc
priceFloat numberprice
CurrencyCodeString (max 5)
values
CurrencyCode
warehouseInteger numberwarehouse
agentInteger numberagent

An example for adding or suggesting adding items

{
"DoIssue": 0,
"StockID":stock.StockID ,
"Items": [{"status":0,
"text": "מטר 1+1 מתנה" ,
"item": { "itemKey": "מטר", "quantity": 2 ,
"DiscountPrc": 50 ,"price":15 ,
"CurrencyCode":"$" , "warehouse":1 ,"agent":12 },
{"status":1 ,
"text":"מתנה בקנייה מעל 1000" ,
"item": { "itemKey": "מתנה", "quantity": 1 ,
"DiscountPrc": 0 ,"price":0 ,
"CurrencyCode":"$" , "warehouse":3 ,"agent":4 }
}]
}

An Example of updating the total

{
"DoIssue":1,
"StockID":stock.StockID ,
"TotalDocument":stock.TFtal * 0.8;
"text":"20% הנחה על קניית 3 פריטים ומעלה"
}

Full Server example

const express = require("express");
const router = express.Router();

const bodyParser = require("body-parser");
router.use(bodyParser.urlencoded({ extended: true }));
router.use(bodyParser.json());

const md5 = require("md5");


router.post("/Deals", async (req, res) => {

//Converting to JSON
const stock = JSON.parse(Buffer.from(req.body.data,'base64').toString('utf-8'));

//Data Verification
let token = `1ea80b1ea80b1ea80b1ea80b1ea80b...`;
let signature = md5(`${req.body.data}${token}`);

let badSignature = {
DoIssue: 0,
StockID:stock.id,
Messages: [{ text: 'חתימה הנתונים שגויה', status: "2" }],
};

if(req.body.signature != signature)
res.json(badSignature);

//Responses
if(stock.Agent == 7 && !stock.moves.find(move => move.ItemKey == "70004")){
let giftItem = {
DoIssue: 1,
StockID: stock.id,
Items: [{status: 1, text: "עט מתנה ללקוחות סוכן חדש", item:{itemKey: "70004", quantity: 1, agent:7},}],
};
res.json(giftItem);
}else if(stock.moves.length == 3){
let offerItems = {
DoIssue: 1,
StockID:stock.id,
Items:[{status: 0,text: "עכבר מחשב ב 50% הנחה",item: { itemKey: "100004", quantity: 1 , price:40 , DiscountPrc:50 }},
{status: 0,text: "דפדפת 1+1 מתנה",item: { itemKey: "100233", quantity: 2 , price:7 , DiscountPrc:50 }}],
};
res.json(offerItems);
}else if(stock.moves.find(move => move.ItemKey == '989')){
let notSale = {
DoIssue: 0,
StockID:stock.id,
Messages: [{ text: 'לא ניתן למכור אוגדנית', status: "2" },
{ text: 'למכירה מתאריך 05.01.2025', status: "1" }],
};
res.json(notSale);
}else if(stock.TFtal > 3000 && stock.DiscountPrc == 0){
let discountTFtal = {
DoIssue: 1,
StockID: stock.id,
TotalDocument: stock.TFtal*0.8,
text: "20% הנחה , בקניה מעל 3000"
};
res.json(discountTFtal);
}else{
let baseRes = {
DoIssue: 1,
StockID:stock.id,
};
res.json(baseRes);
};

});

module.exports = router;