public static IState ApplyPointDiscount(Decimal discountAmount) { if (discountAmount == 0) { discountAmount = cr.Document.PointPrices(cr.Document.Customer.Points); } if (discountAmount > cr.Document.TotalAmount) { discountAmount = cr.Document.TotalAmount; } long usingPoint = cr.Document.PriceToPoint(discountAmount * -1); if (Math.Abs(usingPoint) > cr.Document.Customer.Points) { throw new InvalidProgramException("YETERSÝZ PUAN"); } //cr.Document.AddPoint(usingPoint); cr.Document.State = DocumentPaying.Instance(); CreditPaymentInfo cpi = null; List <ICredit> creditList = new List <ICredit>(cr.DataConnector.GetCredits().Values); ICredit crd = creditList.Find(delegate(ICredit c) { return(c.IsPointPayment); }); if (crd != null) { cpi = new CreditPaymentInfo(crd, discountAmount); } else { throw new InvalidPaymentException(); } state.Pay((CreditPaymentInfo)cpi); if (cr.Document.IsEmpty && cr.Document.TotalAmount == Decimal.Zero) { return(States.Start.Instance()); } TempPaymentMethod = new CashPaymentInfo(); input = new Number(); //TODO Tell promoserver that the points are used iff document is closed //return PayAfterPointDiscount(); if (cr.Document.TotalAmount == 0m) { cr.State.Enter(); } return(cr.State); }
public static IState Instance() { if (cr.Printer == null) { Chassis.RestartProgram(false); } if (cr.CurrentCashier == null || cr.CurrentManager == null) { return(Login.Instance()); } if (cr.Document.Status == DocumentStatus.Paying) { return(Payment.Continue()); } if (cr.Document.State == DocumentPaying.Instance()) { return(Payment.Continue()); } if (cr.Document.Adjustments.Length != 0) { decimal total = 0; for (int adj = 0; adj < cr.Document.Adjustments.Length; adj++) { total += cr.Document.Adjustments[adj].NetAmount; } if (total != 0) { return(Payment.Continue()); } } cr.Document.State = DocumentOpen.Instance(); //Turn off satis var led if (cr.Document.IsEmpty) { DisplayAdapter.Cashier.LedOff(Leds.Sale); } //Turn off customer led if (cr.Document.Customer == null) { DisplayAdapter.Cashier.LedOff(Leds.Customer); } //Show main menu to cashier and customer //check name if length bigger-smaller than 14 String name = cr.CurrentCashier.Name; if (name.Length > 14) { name = name.Substring(0, 14); } System.Threading.Thread.Sleep(100); DisplayAdapter.Cashier.Show(cashierMsg, cr.Document.Name, DateTime.Now, name); DisplayAdapter.Customer.Show(PosMessage.WELCOME); cr.Printer.ClearDisplay(); if (cr.Item != null) { cr.Item.Reset(); } if (cr.Item is VoidItem) { cr.Item = new SalesItem(); } Payment.ResetPayment(); #if ORDER if (!cr.Document.IsEmpty && cr.Document.ReturnReason == "WAITING_FOR_PAYMENT") { /*DisplayAdapter.Cashier.Show("ÖDEME BEKLENİYOR.."); * System.Threading.Thread.Sleep(2000); * return Selling.CloseOrder();*/ // Çıkış için document iptal edilebilir, çıkış fonk VoidLastOrder eklenebilir cr.Document.ReturnReason = null; return(States.AlertCashier.Instance(new Confirm(PosMessage.WAITING_PAYMENT, new StateInstance(Selling.CloseOrder)))); } else if (!cr.Document.IsEmpty) { return(Selling.Instance()); } else { return(state); } #else return(cr.Document.IsEmpty ? state : Selling.Instance()); #endif }
public override void Adjust(AdjustmentType method) { if (input.ToString().Length < input.Length || Str.Contains(input.ToString(), ',')) { if (method == AdjustmentType.PercentDiscount) { method = AdjustmentType.Discount; } else if (method == AdjustmentType.PercentFee) { method = AdjustmentType.Fee; } } if (cr.Document.IsEmpty) { cr.State = States.AlertCashier.Instance(new Confirm(PosMessage.NO_SALE_INVALID_ACTION)); return; } /* * //Check whether cashier has authorization or not. * if (input.ToDecimal() == 100) * { * if (method == AdjustmentType.PercentDiscount) * { * input = new Number(cr.Document.State is DocumentOpen ? cr.Document.LastItem.TotalAmount : cr.Document.BalanceDue); * method = AdjustmentType.Discount; * } * if (method == AdjustmentType.PercentFee) * { * input = new Number(cr.Document.State is DocumentOpen ? cr.Document.LastItem.TotalAmount : cr.Document.BalanceDue); * method = AdjustmentType.Fee; * } * } */ if (method == AdjustmentType.PercentDiscount || method == AdjustmentType.Discount) { //check whether cashier has percentDiscount or discount. if (!cr.IsAuthorisedFor(Authorizations.Discount)) { cr.State = States.AlertCashier.Instance(new Confirm(PosMessage.INSUFFICIENT_ACCESS_LEVEL)); return; } } else if (method == AdjustmentType.PercentFee || method == AdjustmentType.Fee) { //check whether cashier has percentFee or fee. if (!cr.IsAuthorisedFor(Authorizations.Fee)) { cr.State = States.AlertCashier.Instance(new Confirm(PosMessage.INSUFFICIENT_ACCESS_LEVEL)); return; } } //Deny if percentFee or percentDiscount is not integer. if (method == AdjustmentType.PercentDiscount || method == AdjustmentType.PercentFee) { if (input.Decimals > 0) { cr.State = AlertCashier.Instance(new Confirm(PosMessage.DNEY_PERCENTDISCOUNT)); return; } if (input.Length > 2) { cr.State = AlertCashier.Instance(new Confirm(PosMessage.DNEY_PERCENT_OVER_AMOUNT)); return; } } Adjustment adjustment = null; try { if (cr.Document.State is DocumentOpen) { if (cr.Document.LastItem.Adjustments.Count > 0 && !cr.Document.LastItem.Adjustments[cr.Document.LastItem.Adjustments.Count - 1].IsCorrection) { cr.State = States.AlertCashier.Instance(new Confirm("DAHA ÖNCE ÜRÜNE\nÝND/ART YAPILMIÞ")); return; } if (cr.Document.LastItem is VoidItem) { cr.State = States.AlertCashier.Instance(new Confirm("ÜRÜN ÝPTALÝNE\nÝND/ART YAPILAMAZ")); return; } if (input.ToDecimal() < 0.01m) { cr.State = States.AlertCashier.Instance(new Confirm("MÝN ÝND/ART TUTARI\n0,01")); return; } adjustment = new Adjustment(cr.Document.LastItem, method, input.ToDecimal()); if (!(cr.CurrentCashier.IsAuthorisedFor(adjustment) && cr.Document.CanAdjust(adjustment))) { cr.State = States.AlertCashier.Instance(new Confirm(String.Format("{0} {1}", adjustment.Label, PosMessage.INSUFFICIENT_LIMIT))); return; } if (method == AdjustmentType.PercentFee && input.ToDecimal() > 99) { adjustment = new Adjustment(cr.Document.LastItem, AdjustmentType.Fee, adjustment.NetAmount); } cr.Printer.Print(adjustment); cr.Document.LastItem.Adjust(adjustment); //TODO - if printerresponse is OK DisplayAdapter.Both.Show(adjustment); cr.State = Selling.Instance(); } else if (cr.Document.State is DocumentSubTotal) { adjustment = new Adjustment(cr.Document, method, input.ToDecimal()); if (!(cr.CurrentCashier.IsAuthorisedFor(adjustment) && cr.Document.CanAdjust(adjustment))) { cr.State = States.AlertCashier.Instance(new Confirm(String.Format("{0} {1}", adjustment.Label, PosMessage.INSUFFICIENT_LIMIT))); return; } cr.Printer.Print(adjustment); cr.Document.Adjust(adjustment); DisplayAdapter.Both.Show(adjustment); cr.State = States.PaymentAfterTotalAdjustment.Instance(adjustment); cr.Document.State = DocumentPaying.Instance(); } } catch (CmdSequenceException) { String adj = (method == AdjustmentType.Discount || method == AdjustmentType.PercentDiscount) ? PosMessage.DISCOUNT : PosMessage.FEE; cr.State = AlertCashier.Instance(new Confirm(String.Format("ARATOPLAM ONCESINE\n{0} GECERSIZ", adj))); } catch (ReceiptLimitExceededException) { //Sales document is a receipt which needs to be //converted to an invoice Invoice invoice = new Invoice(cr.Document); if (adjustment.Target is SalesItem) { invoice.LastItem.Adjust(adjustment); } if (!cr.Printer.CanPrint(invoice)) { throw new ReceiptLimitExceededException(); } MenuList docTypes = new MenuList(); docTypes.Add(new MenuLabel(PosMessage.TRANSFER_DOCUMENT + "\n" + PosMessage.INVOICE, invoice)); cr.State = States.ListDocument.Instance(docTypes, new ProcessSelectedItem <SalesDocument>(cr.ChangeDocumentType)); DisplayAdapter.Cashier.Show(PosMessage.RECEIPT_LIMIT_EXCEEDED_TRANSFER_DOCUMENT); } finally { input.Clear(); } }