public void PostSale(IPosTransaction posTransaction) { Debug.WriteLine("PostSale"); RetailTransaction retailTransaction = posTransaction as RetailTransaction; if (retailTransaction != null) { // We are a retail transaction // The Sale Item may not alway be the last item. // If the last has alredy been added, then it is a qty change so consder // handling later... SaleLineItem saleLineItem = retailTransaction.SaleItems.Last.Value; if (saleLineItem != null) { if (!(saleLineItem is IncomeExpenseItem)) { // Note: Depending upon requriments, we may want to skip fiscal receipt coupons for certain // types of saleLineItems such as Income or Expense account FiscalPrinterSingleton fiscalCore = FiscalPrinterSingleton.Instance; IFiscalOperations fiscalPrinter = fiscalCore.FiscalPrinter; if (fiscalPrinter.OperatingState != FiscalPrinterState.FiscalReceipt) { FiscalPrinterSingleton.Instance.SalesLineItemData.Clear(); string customerAccountNumber = UserMessages.RequestCustomerTaxId(string.Empty); fiscalPrinter.BeginReceipt(customerAccountNumber); } if (!fiscalCore.SalesLineItemData.ContainsKey(saleLineItem.LineId)) { // We found at leat one new item (not just a quantity change) fiscalCore.UpdateFiscalCouponSalesItemsQty(retailTransaction); } } } } }
public void PreEndTransaction(IPreTriggerResult preTriggerResult, IPosTransaction posTransaction) { if (preTriggerResult == null) { throw new ArgumentNullException("preTriggerResult"); } if (posTransaction == null) { throw new ArgumentNullException("posTransaction"); } Debug.WriteLine("PreEndTransaction"); bool abortTransaction = false; FiscalPrinterSingleton fiscalCore = FiscalPrinterSingleton.Instance; IFiscalOperations fiscalPrinter = fiscalCore.FiscalPrinter; PersistentPrinterData printerData = fiscalCore.PrinterData; RetailTransaction retailTransaction = posTransaction as RetailTransaction; LinkedList <TenderLineItem> tenderLines = null; LinkedList <SaleLineItem> salesLines = null; ComputePosExeMD5Text(); // Note: Other transaction types (CustomerPaymentTransaction) may also apply. if (retailTransaction != null) { // We are a retail transaction // Add all payments to the fiscal printer // Alternative option is to do this as ar result of IPaymentTriggers tenderLines = retailTransaction.TenderLines; salesLines = retailTransaction.SaleItems; if (fiscalPrinter.OperatingState == FiscalPrinterState.FiscalReceipt) { Decimal totalDiscountAmount = 0m; Decimal totalDiscountPercent = 0m; // Post any quantity changes to the printer fiscalCore.UpdateFiscalCouponSalesItemsQty(retailTransaction); UpdateFiscalPrinterTransactionData(fiscalCore, fiscalPrinter, salesLines, ref totalDiscountAmount, ref totalDiscountPercent); // Start payment, apply total/transaction discount or surcharge // Note: we are not implementing a surcharge if (totalDiscountPercent != 0) { // Transaction level % discount fiscalPrinter.StartTotalPaymentWithDiscount((int)(totalDiscountPercent * 100)); } else if (totalDiscountAmount != 0) { // Transaction level amount discount fiscalPrinter.StartTotalPaymentWithDiscount(totalDiscountAmount); } else { // No transaction level discounts or surcharge fiscalPrinter.StartTotalPayment(); } // Process Payments... Decimal posPaymentTotal = 0m; foreach (TenderLineItem tenderLine in tenderLines) { if (!tenderLine.Voided) { string paymentMethod = fiscalCore.MapTenderTypeIdToPaymentMethod(tenderLine.TenderTypeId); decimal paymentAmount = tenderLine.Amount; if (paymentAmount > 0m) { // only process positive payments with the fiscal printer // Cash-back should is ignored fiscalPrinter.MakePayment(paymentMethod, paymentAmount); posPaymentTotal += paymentAmount; } } } string couponNumber = fiscalPrinter.GetCouponNumber(); posTransaction.FiscalDocumentId = couponNumber; string serialNumber = fiscalPrinter.GetSerialNumber(); posTransaction.FiscalSerialId = serialNumber; Debug.WriteLine("Balance due: " + fiscalPrinter.GetBalanceDue()); Debug.WriteLine("Subtotal " + fiscalPrinter.GetSubtotal()); Debug.WriteLine("Pos Payment total " + posPaymentTotal); Debug.Assert(fiscalPrinter.GetBalanceDue() == 0m, "Not enough payment was made as expected by the fiscal printer"); if (fiscalPrinter.GetBalanceDue() > 0m) { // user will need to void transaction or fix the shortage to proceed. preTriggerResult.ContinueOperation = false; preTriggerResult.MessageId = 4042; // The action is not valid for this type of transaction. } else { // End and finalize the Fiscal Coupon fiscalPrinter.EndReceipt(string.Format(CultureInfo.CurrentCulture, "Thank you! MD5:{0}", _posExeMd5Text)); printerData.SetGrandTotal(fiscalPrinter.GetGrandTotal()); PrintTenderManagementReports(tenderLines); } } else { // Check to see if there are sales items on this transaction if (ContainsItemsRequiringFiscalPrinter(retailTransaction)) { // A Fiscal Coupon has not been created - Abort this operation. preTriggerResult.ContinueOperation = false; preTriggerResult.MessageId = 4042; // The action is not valid for this type of transaction. } } if (abortTransaction) { // Abort the transaction fiscalPrinter.CancelReceipt(); preTriggerResult.ContinueOperation = false; preTriggerResult.MessageId = 4042; // The action is not valid for this type of transaction. } } }