This event is generated when the POS is about to create and add a product to a sale. The saleline does not yet exist. This event can block this product being added to the sale by setting f200=0 in a REEV packet.
Trapping the Event
In your main dispatch loop, detect the event
while (bRun) {
// Read a packet, wait up to 60 seconds then return anyway.
FieldpinePacket pPacket = Fdl.SimpleRead(pBuffer, 10*1000*1000, 60*1000);
// Did we get anything?
if (pPacket) {
// Is this an evnt packet?
if (memcmp(pBuffer, "EVNT", 4) == 0) {
// Extract the Event number from the packet
// Every event packet includes this field to say what it is exactly
long EventNo = 0;
Fdl.GetInt(pPacket, FIELDPINE_EVNT_EVENTNO, &EventNo);
if (EventNo == FIELDPINE_EVENT_SALELINE_PRE_ADD) {
FieldpinePacket pReply = PreSaleline(pPacket);
if (pReply) {
Fdl.ReplyTo_InOut(pPacket, pReply);
Fdl.FreePacket(pReply);
}
}
}
Fdl.FreePacket(pPacket);
}
}
Extracting and Processing New Item
This event includes a ADDI object that describes the item being added. It also includes a complete SALE object that we wish to add too.
FieldpinePacket PreSaleline(FieldpinePacket pRequest) {
// Find the ADDI packet describing what is being added
FieldpinePacket pAdd = theApp.Fdl.GetSubPacket(pRequest, "ADDI", 0);
if (pAdd == NULL) return NULL;
// Extract the Product Pid being added
long Pid = 0;
Fdl.GetInt(pAdd, 110, &Pid);
// Release pAdd
Fdl.FreePacket(pAdd);
if (Pid == 44) {
// Do not allow Pid 44
// Create a command to send back to the POS
FieldpinePacket pReply = theApp.Fdl.NewPacket("REEV");
Fdl.SetInt(pReply, 200, 0); // Command = block
return pReply;
}
// Ok, allow it. Send an allow reply
FieldpinePacket pReply = theApp.Fdl.NewPacket("REEV");
Fdl.SetInt(pReply, 200, 1); // Command = allow
return pReply;
}
