/// <summary>
        /// Method to save vendor payout
        /// </summary>
        /// <param name="po">Payout</param>
        /// <param name="tillNumber">Till number</param>
        /// <param name="userCode">User code</param>
        /// <param name="registerNumber">Register number</param>
        /// <param name="taxes">Taxes</param>
        /// <param name="openDrawer">Open cash drawer</param>
        /// <param name="error">Error message</param>
        /// <returns>Report</returns>
        public Report SaveVendorPayout(Payout po, int tillNumber, string userCode, byte registerNumber,
                                       List <Tax> taxes, out bool openDrawer, out ErrorMessage error)
        {
            openDrawer = false;
            var sale   = _saleManager.GetCurrentSale(po.Sale_Num, tillNumber, 0, userCode, out error);
            var offSet = _policyManager.LoadStoreInfo().OffSet;

            if (!string.IsNullOrEmpty(error.MessageStyle.Message))
            {
                return(null);
            }
            if (!_policyManager.DO_PAYOUTS || (sale != null && sale.Sale_Lines.Count > 0))
            {
                MessageType temp_VbStyle8 = (int)MessageType.Exclamation + MessageType.OkOnly;
                error.MessageStyle = _resourceManager.CreateMessage(offSet, 38, 54, null, temp_VbStyle8);
                return(null);
            }
            if (po.Gross > (decimal)214748.3647)
            {
                error = new ErrorMessage
                {
                    MessageStyle = new MessageStyle
                    {
                        Message = "Maximum payout amount is 214748.3647"
                    }
                };
                return(null);
            }
            var salePo = new Sale();
            var tendPo = new Tenders();



            var curr = Convert.ToString(_policyManager.BASECURR);

            if (string.IsNullOrEmpty(curr))
            {
                MessageType temp_VbStyle = (int)MessageType.OkOnly + MessageType.Critical;
                error.MessageStyle = _resourceManager.CreateMessage(offSet, 23, 94, null, temp_VbStyle);
                return(null);
            }
            var   poTaxes  = _taxService.GetAllTaxes();
            float sumTaxes = 0;

            foreach (var tax in taxes)
            {
                if (poTaxes.Any(p => p.TaxName == tax.Code))
                {
                    po.Payout_Taxes.Add(tax.Code, "", tax.Amount, true, tax.Code);
                    salePo.Sale_Totals.Sale_Taxes.Add(tax.Code, "I", 0, 0, 0, tax.Amount, po.Gross, 0, 0, "");
                    sumTaxes = (float)(sumTaxes + Conversion.Val(tax.Amount));
                }
                else
                {
                    MessageType temp_VbStyle8 = (int)MessageType.Exclamation + MessageType.OkOnly;
                    error.MessageStyle = new MessageStyle
                    {
                        Message     = "Invalid tax entered",
                        MessageType = temp_VbStyle8
                    };
                    return(null);
                }
            }
            if (!string.IsNullOrEmpty(po.Vendor.Code))
            {
                po.Vendor = _stockService.GetVendorByCode(po.Vendor.Code);
                if (po.Vendor.Code == null)
                {
                    MessageType temp_VbStyle2 = (int)MessageType.Critical + MessageType.OkOnly;
                    error.MessageStyle = new MessageStyle
                    {
                        Message     = "Invalid vendor code",
                        MessageType = temp_VbStyle2
                    };
                    return(null);
                }
            }
            // Nicoolette changed next line on Nov 13,2007 to allow negative payouts, based on Mr. Gas requirement
            if (po.Gross == 0)
            {
                //    If PO.Gross <= 0 Then
                //You must specify the Payout Amount, vbCritical + vbOKOnly
                MessageType temp_VbStyle2 = (int)MessageType.Critical + MessageType.OkOnly;
                error.MessageStyle = _resourceManager.CreateMessage(offSet, 23, 91, null, temp_VbStyle2);
                return(null);
            }

            if (_policyManager.PO_REASON)
            {
                po.Return_Reason = _reasonService.GetReturnReason(po.Return_Reason.Reason, (char)ReasonType.Payouts);
                if (po.Return_Reason == null)
                {
                    MessageType temp_VbStyle2 = (int)MessageType.Critical + MessageType.OkOnly;
                    error.MessageStyle = _resourceManager.CreateMessage(offSet, 23, 92, null, temp_VbStyle2);
                    return(null);
                }
                salePo.Return_Reason = po.Return_Reason;
            }


            var till = _tillService.GetTill(tillNumber);

            till.Cash = till.Cash - po.Gross;
            _tillService.UpdateTill(till);
            if (_policyManager.OPEN_DRAWER == "Every Sale")
            {
                openDrawer = true;
            }



            tendPo.Add(curr, "Cash", 1, true, true, false, 1, curr, false, 0, 0, 0.01, true, Convert.ToDouble((object)-po.Gross), 1, true, false, "", "");
            _tenderManager.Set_Amount_Entered(ref tendPo, ref salePo, tendPo[1], -po.Gross, -1);
            // payout

            if (_policyManager.PENNY_ADJ && po.Gross != 0)
            {
                salePo.Sale_Totals.Penny_Adj = modGlobalFunctions.Calculate_Penny_Adj(po.Gross);
            }
            else
            {
                salePo.Sale_Totals.Penny_Adj = 0;
            }
            po.Penny_Adj = salePo.Sale_Totals.Penny_Adj;
            //   end

            salePo.Sale_Totals.Net = po.Gross; // - Sum_Taxes   Nicolette commented out,
                                               // once for payout all taxes are included, don't subtract the taxes,
                                               // this will afect Sale_Amt in SaleHead, March 07, 2003

            var saleTotals = salePo.Sale_Totals;

            _saleManager.SetGross(ref saleTotals, salePo.Sale_Totals.Net);
            salePo.Sale_Totals.Gross        = saleTotals.Gross;
            salePo.Sale_Totals.TotalLabel   = saleTotals.TotalLabel;
            salePo.Sale_Totals.SummaryLabel = saleTotals.SummaryLabel;

            salePo.Register    = Convert.ToByte(registerNumber);
            salePo.Sale_Change = 0;

            salePo.TillNumber         = Convert.ToByte(tillNumber);
            salePo.Sale_Date          = DateTime.Now;
            salePo.Sale_Tender        = 0;
            salePo.Sale_Totals.PayOut = po.Gross;
            salePo.Sale_Change        = 0;
            salePo.Sale_Amount        = 0;
            if (po.Sale_Num == 0)
            {
                salePo.Sale_Num = _saleManager.GetSaleNo(tillNumber, userCode, out error);
            }
            else
            {
                salePo.Sale_Num = po.Sale_Num;
            }

            po.Penny_Adj = salePo.Sale_Totals.Penny_Adj; //

            salePo.Sale_Type = "PAYOUT";
            salePo.Vendor    = po.Vendor.Code;
            var user   = _userService.GetUser(userCode);
            var stream = _receiptManager.Print_Payout(po, userCode, user.Name, DateTime.Today,
                                                      salePo.Sale_Date, registerNumber,
                                                      till);

            stream.Copies = _policyManager.PayoutReceiptCopies;
            _saleManager.SaveSale(salePo, userCode, ref tendPo, null);


            _saleManager.Clear_Sale(salePo, po.Sale_Num, salePo.TillNumber, userCode, "", null,
                                    false, false, false, out error);


            return(stream);
        }
示例#2
0
        /// <summary>
        /// Void sale
        /// </summary>
        /// <param name="userCode">User code</param>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="tillNumber">Till number</param>
        /// <param name="voidReason">Void reason</param>
        /// <param name="errorMessage">Error</param>
        /// <param name="fs">Report content</param>
        /// <returns>Sale</returns>
        public Sale VoidSale(string userCode, int saleNumber, int tillNumber, string voidReason,
                             out ErrorMessage errorMessage, out Report fs)
        {
            fs = null;
            var dateStart = DateTime.Now;

            Performancelog.Debug($"Start,SuspendedSaleManager,VoidSale,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            var sale = _saleManager.GetCurrentSale(saleNumber, tillNumber, 0, userCode, out errorMessage);

            if (!string.IsNullOrEmpty(errorMessage.MessageStyle.Message))
            {
                return(null);
            }
            var offSet = _policyManager.LoadStoreInfo().OffSet;

            //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)
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 77, null, MessageType.OkOnly),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }


            if (CountFuelLines(sale) > 1) // if there are more then 1 line with fuel do not allow to void this sale
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 82, null, MessageType.OkOnly),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }

            //Added, not allow to void sale with prepay line

            if (_prepayManager.PrepayItemId(ref sale) > 0)
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 82, null, MessageType.OkOnly),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }

            //crash recovery' if there is partial/ full payment donot allow void
            if (sale.Payment)
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 14, null, MessageType.OkOnly),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }

            //Added to control void GiveX items
            string lineNumber = string.Empty;

            if (modGlobalFunctions.HasGivexSale(sale, ref lineNumber))
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 22, null, CriticalOkMessageType),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }
            if (!CanUserVoidSale(userCode, out errorMessage))
            {
                return(null);
            }


            //added to print receipt for Void sales
            if (_policyManager.PRINT_VOID)
            {
                sale.Sale_Type = "VOID";
                Tenders nullTenders = null;
                var     fileName    = string.Empty;
                var     rePrint     = false;
                Stream  signature;
                fs = _receiptManager.Print_Receipt(sale.TillNumber, null, ref sale, ref nullTenders,
                                                   true, ref fileName, ref rePrint, out signature, userCode);
            }

            var newSale = new Sale
            {
                Sale_Num =
                    _saleManager.Clear_Sale(sale, sale.Sale_Num, sale.TillNumber, userCode, "VOID", null, true, true,
                                            false, out errorMessage)
            };

            CacheManager.DeleteCurrentSaleForTill(sale.TillNumber, sale.Sale_Num);
            newSale.TillNumber = sale.TillNumber;
            newSale.Customer   = _customerManager.LoadCustomer(string.Empty);
            newSale.Register   = sale.Register;
            newSale.SaleHead   = new SaleHead();
            newSale.Payment    = false;
            _saleHeadManager.SetSalePolicies(ref newSale);
            _saleManager.SaveTemp(ref newSale, newSale.TillNumber);
            Register register = null;

            _mainManager.SetRegister(ref register, newSale.Register);
            if (register.Customer_Display)
            {
                newSale.CustomerDisplay = _mainManager.DisplayMsgLcd(register,
                                                                     _mainManager.FormatLcdString(register, _resourceManager.GetResString(offSet, 414) + "#:",
                                                                                                  Conversion.Str(newSale.Sale_Num).Trim()), "");
            }
            CacheManager.AddCurrentSaleForTill(newSale.TillNumber, newSale.Sale_Num, newSale);
            Performancelog.Debug($"End,SuspendedSaleManager,VoidSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            return(newSale);
        }
        /// <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);
        }