Пример #1
0
        public HttpResponseMessage InitializeSale(int tillNumber, int registerNumber)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,SaleController,InitializeSale,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            ErrorMessage        message;
            string              userCode;
            HttpResponseMessage httpResponseMessage;

            if (GetUserCode(out userCode, out httpResponseMessage))
            {
                return(httpResponseMessage);
            }
            var sale = _saleManager.InitializeSale(tillNumber, registerNumber, userCode, out message);

            if (message?.MessageStyle?.Message != null)
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict, message));
            }
            if (sale != null)
            {
                var editLines       = _saleManager.CheckEditOptions(sale.Sale_Lines, userCode);
                var enableButton    = _saleManager.EnableCashButton(sale, userCode);
                var userCanWriteOff = _saleManager.EnableWriteOffButton(userCode);
                var saleModel       = SaleMapper.CreateSaleModel(sale, editLines, enableButton, userCanWriteOff);
                _performancelog.Debug($"End,SaleController,InitializeSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(Request.CreateResponse(HttpStatusCode.OK, saleModel));
            }


            return(null);
        }
Пример #2
0
        /// <summary>
        /// Suspend Sale
        /// </summary>
        /// <param name="tillNumber">Till number</param>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="userCode">User code</param>
        /// <param name="errorMessage">Error</param>
        /// <returns>Sale</returns>
        public Sale SuspendSale(int tillNumber, int saleNumber, string userCode, out ErrorMessage errorMessage)
        {
            var dateStart = DateTime.Now;

            Performancelog.Debug($"Start,SuspendedSaleManager,SuspendSale,{string.Empty},{dateStart:hh.mm.ss.ffffff}");
            if (!CanUserSuspendSale(userCode, out errorMessage))
            {
                return(new Sale());
            }
            var sale   = _saleManager.GetCurrentSale(saleNumber, tillNumber, 0, userCode, out errorMessage);
            var offSet = _policyManager.LoadStoreInfo().OffSet;

            if (!string.IsNullOrEmpty(errorMessage.MessageStyle.Message))
            {
                return(null);
            }

            //Added for checking delete prepay crash recovery
            if (sale.DeletePrepay)
            {
                //Please complete delete prepay first!~Comlete current transaction.
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 50, null),
                    StatusCode   = HttpStatusCode.PreconditionFailed
                };
                return(null);
            }

            if (sale.Sale_Lines.Count == 0 && !_policyManager.SUSPEND_MT)
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 80, null, MessageType.OkOnly),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }
            //Added checking not allowing suspend sale with prepay
            if (_prepayManager.PrepayItemId(ref sale) > 0)
            {
                //MsgBox ("Cannot suspend sale with prepay, Please remove the prepay sale before suspend!~Suspend a Sale.")
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 57, null, CriticalOkMessageType),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }
            var sharePolicy = _policyManager.SHARE_SUSP;

            _suspendedSaleService.SuspendSale("SUSPEND", sharePolicy, sale, userCode);
            CacheManager.DeleteCurrentSaleForTill(sale.TillNumber, sale.Sale_Num);
            sale = _saleManager.InitializeSale(tillNumber, sale.Register, userCode, out errorMessage);
            //Update Sale object in Cache
            CacheManager.AddCurrentSaleForTill(sale.TillNumber, sale.Sale_Num, sale);
            Performancelog.Debug($"End,SuspendedSaleManager,SuspendSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(sale);
        }
Пример #3
0
        /// <summary>
        /// Save Bottle return
        /// </summary>
        /// <param name="brPayment">Br payment</param>
        /// <param name="userCode">User code</param>
        /// <param name="error">Error message</param>
        /// <param name="bottleReport">Report</param>
        /// <param name="openDrawer">Open drawer or not</param>
        public Sale SaveBottleReturn(BR_Payment brPayment,
                                     out ErrorMessage error, out Report bottleReport, out bool openDrawer)
        {
            bottleReport = null;
            openDrawer   = false;
            var dateStart = DateTime.Now;

            Performancelog.Debug($"Start,BottleManager,SaveBottleReturn,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            error = new ErrorMessage();
            var offSet       = _policyManager.LoadStoreInfo().OffSet;
            var userCode     = UserCode;
            var user         = _loginManager.GetExistingUser(userCode);
            var existingSale = _saleService.GetSaleByTillNumber(brPayment.TillNumber);

            if (existingSale != null && existingSale.Sale_Lines.Count > 0)
            {
                error.MessageStyle = new MessageStyle
                {
                    Message     = "Please finish current sale before bottle return.~Bottle Return",
                    MessageType = ExclamationOkMessageType
                };
                error.StatusCode = HttpStatusCode.Conflict;
                return(null);
            }
            if (!_policyManager.GetPol("U_BOTTLERTN", user))
            {
                error.MessageStyle = _resourceManager.CreateMessage(offSet, 38, 57, null, ExclamationOkMessageType);
                error.StatusCode   = HttpStatusCode.Forbidden;
                return(null);
            }

            if (brPayment.Amount != 0)
            {
                if (string.IsNullOrEmpty(Convert.ToString(_policyManager.GetPol("BASECURR", null))))
                {
                    error.MessageStyle = _resourceManager.CreateMessage(offSet, 18, 61, null, CriticalOkMessageType);
                    error.StatusCode   = HttpStatusCode.NotFound;
                    return(null);
                }

                if (brPayment.Amount > (decimal)Math.Abs(_policyManager.GetPol("U_BR_LIMIT", user)))
                {
                    // Exceed the bottle return limit, Please get an authorized user!
                    error.MessageStyle = _resourceManager.CreateMessage(offSet, 18, 62, null, CriticalOkMessageType);
                    error.StatusCode   = HttpStatusCode.Forbidden;
                    return(null);
                }

                if (_policyManager.OPEN_DRAWER == "Every Sale")
                {
                    openDrawer = true;
                }
                var sale = new Sale
                {
                    Sale_Totals = { Net = Convert.ToDecimal(brPayment.Amount) }
                };
                var saleTotals = sale.Sale_Totals;
                _saleManager.SetGross(ref saleTotals, sale.Sale_Totals.Net);
                sale.Sale_Totals.Gross        = saleTotals.Gross;
                sale.Sale_Totals.TotalLabel   = saleTotals.TotalLabel;
                sale.Sale_Totals.SummaryLabel = saleTotals.SummaryLabel;
                sale.Register    = brPayment.RegisterNumber;
                sale.Sale_Change = 0;

                sale.TillNumber  = Convert.ToByte(brPayment.TillNumber);
                sale.Sale_Date   = DateTime.Now;
                sale.Sale_Tender = 0;
                sale.Sale_Change = 0;
                sale.Sale_Amount = 0;
                if (_policyManager.GetPol("Penny_Adj", null) && brPayment.Amount != 0)
                {
                    sale.Sale_Totals.Penny_Adj = Helper.Calculate_Penny_Adj(Convert.ToDecimal(brPayment.Amount));
                }
                else
                {
                    sale.Sale_Totals.Penny_Adj = 0;
                }

                brPayment.Penny_Adj = sale.Sale_Totals.Penny_Adj;
                if (existingSale == null)
                {
                    brPayment.Sale_Num = _saleManager.GetCurrentSaleNo(brPayment.TillNumber, userCode, out error);
                }
                var tendBr = new Tenders();
                var tender = tendBr.Add(Convert.ToString(_policyManager.GetPol("BASECURR", null)),
                                        "Cash", 1, true, true, false, (short)1,
                                        Convert.ToString(_policyManager.GetPol("BASECURR", null)),
                                        false, 0, 0, 0.01, true, Convert.ToDouble(-brPayment.Amount),
                                        (short)1, true, false, "", "");
                _tenderManager.Set_Amount_Entered(ref tendBr, ref sale, tender, -brPayment.Amount);

                sale.Sale_Num  = Convert.ToInt32(brPayment.Sale_Num);
                sale.Sale_Type = "BTL RTN";
                var shiftNumber = _tillService.GetTill(brPayment.TillNumber).Shift;
                bottleReport = _receiptManager.Print_BottleReturn(brPayment, user.Name, DateTime.Today,
                                                                  DateTime.Now, sale.Register, (short)brPayment.TillNumber, shiftNumber);
                bottleReport.Copies = _policyManager.BottleReturnReceiptCopies;
                _bottleReturnService.SaveBottleReturnsToDbTrans(brPayment);
                _saleManager.SaveSale(sale, userCode, ref tendBr, null);
                CacheManager.DeleteCurrentSaleForTill(sale.TillNumber, sale.Sale_Num);
                //_saleManager.Clear_Sale(sale.Sale_Num,sale.TillNumber, userCode, "", null, true, false, false, out msg);
                sale = _saleManager.InitializeSale(brPayment.TillNumber, brPayment.RegisterNumber, userCode, out error);
                //Update Sale object in Cache
                CacheManager.AddCurrentSaleForTill(sale.TillNumber, sale.Sale_Num, sale);
                Performancelog.Debug($"End,BottleManager,SaveBottleReturn,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                return(sale);
            }
            return(null);
        }
        public HttpResponseMessage CompletePayout([FromBody] PayoutModel payoutModel)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,PayoutController,CompletePayout,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            string userCode;
            HttpResponseMessage httpResponseMessage;

            if (GetUserCode(out userCode, out httpResponseMessage))
            {
                return(httpResponseMessage);
            }
            if (payoutModel == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse
                {
                    Error = new MessageStyle
                    {
                        Message = Resource.InvalidInformation,
                        MessageType = MessageType.OkOnly
                    }
                }));
            }
            var po = new Payout
            {
                Sale_Num      = payoutModel.SaleNumber,
                Gross         = payoutModel.Amount,
                Return_Reason = new Return_Reason {
                    Reason = payoutModel.ReasonCode
                },
                Vendor = new Vendor {
                    Code = payoutModel.VendorCode
                },
            };
            ErrorMessage error;
            bool         openDrawer;
            var          fs = _payoutManager.SaveVendorPayout(po, payoutModel.TillNumber, userCode,
                                                              payoutModel.RegisterNumber, payoutModel.Taxes, out openDrawer, out error);

            _performancelog.Debug($"End,PayoutController,CompletePayout,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            if (!string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound,
                                              new ErrorResponse
                {
                    Error = error.MessageStyle,
                }));
            }
            var newSale = _saleManager.InitializeSale(payoutModel.TillNumber, payoutModel.RegisterNumber, userCode, out error);
            var completePaymentResponseModel = new CompletePaymentResponseModel
            {
                NewSale = new NewSale
                {
                    SaleNumber = newSale.Sale_Num,
                    TillNumber = newSale.TillNumber,
                    Customer   = newSale.Customer.Name
                },
                OpenCashDrawer   = openDrawer,
                CustomerDisplays = new List <CustomerDisplay> {
                    newSale.CustomerDisplay
                }
            };

            try
            {
                completePaymentResponseModel.PaymentReceipt = new ReportModel
                {
                    ReportName    = fs.ReportName,
                    ReportContent = fs.ReportContent,
                    Copies        = fs.Copies
                };
                _performancelog.Debug($"End,PayoutController,CompletePayout,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                return(Request.CreateResponse(HttpStatusCode.OK, completePaymentResponseModel));
            }
            catch
            {
                _performancelog.Debug($"End,PayoutController,CompletePayout,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(Request.CreateResponse(HttpStatusCode.NotFound, new ErrorResponse
                {
                    Error = new MessageStyle {
                        Message = Resource.Error, MessageType = 0
                    }
                }));
            }
        }
        public HttpResponseMessage CompletePayment([FromBody] CompletePaymentInputModel model)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,PaymentController,CompletePayment,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            ErrorMessage        errorMessage;
            string              userCode;
            HttpResponseMessage httpResponseMessage;

            if (GetUserCode(out userCode, out httpResponseMessage))
            {
                return(httpResponseMessage);
            }
            if (model == null)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.BadRequest,
                           new ErrorResponse
                {
                    Error = new MessageStyle {
                        Message = Constants.InvalidRequest, MessageType = 0
                    }
                }));
            }

            bool            openCashDrawer;
            bool            isRefund;
            string          changeDue;
            CustomerDisplay lcdMsg;
            var             receipts = _paymentManager.CompletePayment(model.SaleNumber, model.TillNumber,
                                                                       model.TransactionType, userCode, model.IssueStoreCredit, out errorMessage, out openCashDrawer,
                                                                       out changeDue, out isRefund, out lcdMsg);

            var kickbackCommunicationMsg = _paymentManager.KickbackCommunicationError();

            if (!string.IsNullOrEmpty(errorMessage?.MessageStyle?.Message))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse
                {
                    Error = errorMessage.MessageStyle
                }));
            }

            var newSale                      = _saleManager.InitializeSale(model.TillNumber, model.RegisterNumber, userCode, out errorMessage);
            var tillLimitExeceeded           = _paymentManager.CheckTillLimit(model.TillNumber);
            var completePaymentResponseModel = new FinishPaymentResponseModel
            {
                NewSale = new NewSale
                {
                    SaleNumber = newSale.Sale_Num,
                    TillNumber = newSale.TillNumber,
                    Customer   = newSale.Customer.Name
                },
                OpenCashDrawer     = openCashDrawer,
                LimitExceedMessage = tillLimitExeceeded,
                ChangeDue          = changeDue,
                CustomerDisplays   = new List <CustomerDisplay> {
                    lcdMsg, newSale.CustomerDisplay
                },
                Receipts            = receipts,
                kickabckServerError = kickbackCommunicationMsg
            };

            KickBackManager.ExchangeRate = 0;
            return(Request.CreateResponse(HttpStatusCode.OK, completePaymentResponseModel));
        }
        /// <summary>
        /// Return Sale
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="tillNumber">Till number</param>
        /// <param name="saleTillNumber"></param>
        /// <param name="correction">Correction sale or not</param>
        /// <param name="reasonCode">Reason code</param>
        /// <param name="message">Error</param>
        /// <param name="reasonType">Reason type</param>
        /// <param name="saleLineMessages">Sale line messages</param>
        /// <param name="report"></param>
        /// <param name="fileName"></param>
        /// <returns>Sale</returns>
        public Sale ReturnSale(User user, int saleNumber, int tillNumber, int saleTillNumber, bool correction,
                               string reasonType, string reasonCode, out ErrorMessage message, out List <ErrorMessage>
                               saleLineMessages, out Report report, out string fileName)
        {
            Sale     sale     = new Sale();
            DateTime saleDate = DateTime.Now.AddDays(-Convert.ToInt16(_policyManager.GetPol("RES_DAYS", null)));

            saleLineMessages = new List <ErrorMessage>();
            report           = null;
            fileName         = string.Empty;
            if (!IsUserAbleToReturn(user, out message))
            {
                return(sale);
            }

            Sale_Line sl;
            var       blnRecReason = false;
            bool      isReturnable;
            bool      isSaleFound;

            sale = _returnSaleService.GetSaleBySaleNumber(saleNumber, saleTillNumber, saleDate, _policyManager.TE_Type, _policyManager.TE_GETNAME, _policyManager.TAX_EXEMPT_GA, _policyManager.DefaultCust, _policyManager.DEF_CUST_CODE, out isSaleFound, out isReturnable);
            var offSet = _policyManager.LoadStoreInfo().OffSet;

            if (!isSaleFound)
            {
                message = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 40, 98, null)
                };
                return(sale);
            }

            if (!isReturnable)
            {
                message = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 40, 95, saleDate)
                };
                return(sale);
            }
            var sal = _saleService.GetSaleByTillNumber(tillNumber);// _saleService.GetSalesFromDbTemp(tillNumber);

            sale.Sale_Num   = sal?.Sale_Num ?? _saleManager.GetCurrentSaleNo(tillNumber, user.Code, out message);
            sale.TillNumber = (byte)tillNumber;
            _saleHeadManager.SetSalePolicies(ref sale);
            var saleLines = _returnSaleService.GetSaleLineBySaleNumber(saleNumber, saleTillNumber, saleDate, sale.Customer.DiscountType, _policyManager.TE_Type, _policyManager.TAX_EXEMPT);

            //_suspendedSaleService.RemovePreviousTransactionFromDbTemp(tillNumber);

            foreach (var saleLine in saleLines)
            {
                saleLine.PRICE_DEC = CommonUtility.GetShortValue(_policyManager.GetPol("PRICE_DEC", saleLine));
                saleLine.QUANT_DEC = CommonUtility.GetShortValue(_policyManager.GetPol("QUANT_DEC", saleLine));
                if (_policyManager.GetPol("ACCEPT_RET", saleLine) && saleLine.GiftType != "GiveX")
                {
                    var newSaleLine = saleLine;
                    newSaleLine.Till_Num = sale.TillNumber;
                    var          quantity     = saleLine.Quantity;
                    var          price        = saleLine.price;
                    var          amount       = saleLine.Amount;
                    var          discountRate = saleLine.Discount_Rate;
                    var          discountType = saleLine.Discount_Type;
                    ErrorMessage error;
                    _saleLineManager.SetPluCode(ref sale, ref newSaleLine, newSaleLine.PLU_Code, out error);

                    if (newSaleLine.ProductIsFuel && !newSaleLine.IsPropane)
                    {
                        newSaleLine.Regular_Price = Convert.ToDouble(newSaleLine.price);
                    }

                    if (newSaleLine.Gift_Certificate && newSaleLine.GiftType == "LocalGift")
                    {
                        newSaleLine.Description = _resourceManager.GetResString(offSet, 8124) + newSaleLine.Gift_Num;
                    }
                    _saleManager.Add_a_Line(ref sale, newSaleLine, user.Code, sale.TillNumber, out message, adjust: false, tableAdjust: false,
                                            forRefund: true);

                    newSaleLine.No_Loading = false;
                    if (newSaleLine.ScalableItem)
                    {
                        newSaleLine.Regular_Price = newSaleLine.price;
                    }

                    _saleLineManager.SetPrice(ref newSaleLine, price);
                    _saleLineManager.SetQuantity(ref newSaleLine, quantity);
                    _saleLineManager.SetAmount(ref newSaleLine, amount);
                    saleLine.Discount_Type = discountType;
                    _saleLineManager.SetDiscountRate(ref newSaleLine, discountRate);
                    newSaleLine.No_Loading = false; // It has to be set back to false, otherwise if the user changes the qty or price in the POS screen after unsuspend, the amount will not be right
                }
                else
                {
                    saleLineMessages.Add(new ErrorMessage
                    {
                        MessageStyle = _resourceManager.CreateMessage(offSet, 0, 8109, saleLine.Stock_Code + " " + saleLine.Description,
                                                                      CriticalOkMessageType)
                    });
                }
            }

            _saleManager.Sale_Discount(ref sale, Convert.ToDecimal(sale.Sale_Totals.Invoice_Discount),
                                       Convert.ToString(sale.Sale_Totals.Invoice_Discount_Type), false);
            sale.ForCorrection = correction; // 06/24/05 Nancy added ForCorrection
                                             //    CL = "" ' code
                                             //SaleMain.Default.lblCustName.Text = sale.Customer.Name;
            foreach (var tempLoopVarSl in saleLines)
            {
                sl            = tempLoopVarSl;
                sl.No_Loading = false;
            }
            sale.LoadingTemp = false;

            foreach (var tempLoopVarSl in saleLines)
            {
                sl = tempLoopVarSl;
                if (!_policyManager.GetPol("RET_REASON", sl))
                {
                    continue;
                }
                blnRecReason = true;
                break;
            }

            if (blnRecReason)
            {
                ReasonType rType;
                Enum.TryParse(reasonType, true, out rType);
                var returnReason = (char)rType != '\0' ? _reasonService.GetReturnReason(reasonCode, (char)rType) : new Return_Reason {
                    RType = "R"
                };
                foreach (var tempLoopVarSl in saleLines)
                {
                    sl = tempLoopVarSl;
                    _saleManager.Line_Reason(ref sale, ref sl, returnReason);
                }
            }
            _saleManager.SaveTemp(ref sale, tillNumber);
            //Update Sale object in Cache
            sale.ReverseRunaway  = sale.Sale_Type == "RUNAWAY" && sale.Sale_Amount > 0;  //
            sale.ReversePumpTest = sale.Sale_Type == "PUMPTEST" && sale.Sale_Amount > 0; //
            if (sale.ReverseRunaway)
            {
                var newLineMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 25, null)
                };
                saleLineMessages.Add(newLineMessage);
                Tenders nullTenders = null;
                fileName = Constants.RunAwayFile;
                var    file    = "Runaway";
                var    rePrint = false;
                Stream signature;
                sale.Sale_Type = "RUNAWAY";
                report         = _receiptManager.Print_Receipt(tillNumber, null, ref sale, ref nullTenders, true, ref file,
                                                               ref rePrint, out signature, user.Code);
                _saleManager.Clear_Sale(sale, sale.Sale_Num, sale.TillNumber, user.Code, "RUNAWAY", null, false, true, false, out message);

                ErrorMessage error;
                sale = _saleManager.InitializeSale(tillNumber, sale.Register, user.Code, out error);
            }
            if (sale.ReversePumpTest)
            {
                var newLineMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 27, null)
                };
                saleLineMessages.Add(newLineMessage);
                Tenders nullTenders = null;
                fileName = Constants.PumpTestFile;
                var    file    = "PumpTest";
                var    rePrint = false;
                Stream signature;
                sale.Sale_Type = "PUMPTEST";
                report         = _receiptManager.Print_Receipt(tillNumber, null, ref sale, ref nullTenders, true, ref file, ref rePrint, out signature, user.Code);
                _saleManager.Clear_Sale(sale, sale.Sale_Num, sale.TillNumber, user.Code, "PUMPTEST", null, false, true, false, out message);
                ErrorMessage error;
                sale = _saleManager.InitializeSale(tillNumber, sale.Register, user.Code, out error);
            }
            CacheManager.AddCurrentSaleForTill(sale.TillNumber, sale.Sale_Num, sale);
            return(sale);
        }