Fieldpine Logo Documentation Home  

Price All Sale Event


Goto: Talk To Fieldpine Home Page Talk To Fieldpine Events Overview

This event is generated when the POS has mostly completed a modification to the sale and allows you to change any pricing on any saleline you wish.

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_PRICE_ALL_SALE) {
				// This is a global pricing event request.  Lets do it
				FieldpinePacket pReply = MyPricingEngine(pPacket);
				if (pReply) {
					Fdl.ReplyTo_InOut(pPacket, pReply);
					Fdl.FreePacket(pReply);
				}
			}
		}

		Fdl.FreePacket(pPacket);
	}
}

Extracting and Processing the Sale Details

This event includes a SALE object that describes the sales current state. Your code should convert the API packet to a format that it can easily work with and then process the packet. In C++ we provide a number of helper classes to do this conversion for you.

FieldpinePacket MyPricingEngine(FieldpinePacket pRequest) {
/* ***********************************************************
  This is the main logic to price a complete sale.
  Pricing a complete sale is not often done, but does allow you to get around some tight 
  requirements and implement pretty much any pricing structure you wish
  ***********************************************************
*/

	// Create a sale from the input packet
	// This converts the calling structure to something C++ can handle easier

	// Find the SALE packet
	FieldpinePacket pSale = theApp.Fdl.GetSubPacket(pRequest, "SALE", 0);
	if (pSale == NULL) return NULL;

	Sale inSale(pSale);
	theApp.Fdl.FreePacket(pSale);


	CTypedPtrArray<CPtrArray, Line*> InterestingLines;

	// Loop over all lines and see if anything we are interested in
	int i=0;
	for (i=0; i < inSale.GetLineCount(); i++) {
		Line* pLine = inSale.m_Lines.GetAt(i);

		if (pLine->m_Pid == 44) InterestingLines.Add(pLine);	// Replace with your requirements

	}


	if (InterestingLines.GetSize() == 0) return NULL;	// Nothing of interest, quit

	// Create a command to send back to the POS
	FieldpinePacket pReply = theApp.Fdl.NewPacket("CMDE");

	....


	return pReply;
}