Exemplo n.º 1
0
        /// <summary>
        /// Method to add cash draw
        /// </summary>
        /// <param name="cashDraw">Cash draw</param>
        public void AddCashDraw(CashDraw cashDraw)
        {
            _connection = new SqlConnection(GetConnectionString(DataSource.CSCTills));
            if (_connection.State == ConnectionState.Closed)
            {
                _connection.Open();
            }
            _dataTable = new DataTable();
            _adapter   = new SqlDataAdapter("select * from CashDraw where TILL=" + cashDraw.TillNumber, _connection);
            _adapter.Fill(_dataTable);
            var fields = _dataTable.NewRow();

            fields["Draw_Date"] = cashDraw.DrawDate;
            fields["User"]      = cashDraw.User;
            fields["Till"]      = cashDraw.TillNumber;
            fields["Amount"]    = cashDraw.TotalValue;
            fields["Reason"]    = cashDraw.Reason;
            _dataTable.Rows.Add(fields);
            SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);

            _adapter.InsertCommand = builder.GetInsertCommand();
            _adapter.Update(_dataTable);
            _connection.Close();
            _adapter?.Dispose();
        }
Exemplo n.º 2
0
        // code moved to cash bonus controller
        ///// <summary>
        ///// Method to get cash draw buttons
        ///// </summary>
        ///// <returns>Cash draw buttons</returns>
        //public CashDrawButton GetCashBonusDrawButtons(string userCode, out ErrorMessage error)
        //{
        //    var dateStart = DateTime.Now;
        //    _performancelog.Debug($"Start,CashManager,GetCashDrawButtons,{string.Empty},{dateStart:hh.mm.ss.ffffff}");
        //    var offSet = _policyManager.LoadStoreInfo().OffSet;
        //    error = new ErrorMessage();
        //    var user = _loginManager.GetExistingUser(userCode);
        //    if (!Convert.ToBoolean(_policyManager.GetPol("U_TILLDRAW", user)))
        //    {
        //        MessageType temp_VbStyle3 = (int)MessageType.Exclamation + MessageType.OkOnly;
        //        error.MessageStyle = _resourceManager.CreateMessage(offSet, 38, 56, null, temp_VbStyle3);
        //        error.StatusCode = System.Net.HttpStatusCode.Forbidden;
        //        _performancelog.Debug($"End,CashManager,GetCashDrawButtons,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
        //        return null;
        //    }

        //    var cashDrawButton = new CashDrawButton
        //    {
        //        Coins = _cashService.GetCoins(),
        //        Bills = _cashService.GetBills()
        //    };
        //    _performancelog.Debug($"End,CashManager,GetCashDrawButtons,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

        //    return cashDrawButton;
        //}


        /// <summary>
        /// Print cash draw
        /// </summary>
        /// <param name="cashDraw">Cash draw</param>
        /// <param name="userCode"></param>
        /// <param name="copies">Copies</param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public FileStream CompleteCashDraw(CashDrawButton cashDraw, string userCode, out int copies,
                                           out ErrorMessage errorMessage)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,CashManager,GetCashDrawButtons,{string.Empty},{dateStart:hh.mm.ss.ffffff}");
            copies       = _policyManager.CashDrawReceiptCopies;
            errorMessage = new ErrorMessage();
            var message = string.Empty;
            var till    = _tillService.GetTill(cashDraw.TillNumber);

            if (till == null)
            {
                message = "Till does not exists";
            }

            if (cashDraw.Amount <= 0)
            {
                message = "Invalid Cash Drop Amount";
            }

            if (!string.IsNullOrEmpty(message))
            {
                errorMessage.MessageStyle = new MessageStyle
                {
                    Message = message
                };
                errorMessage.StatusCode = System.Net.HttpStatusCode.BadRequest;
                _performancelog.Debug($"End,CashManager,GetCashDrawButtons,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(null);
            }
            var isInvalidCash     = false;
            var isInvalidQuantity = false;

            var cashDrawButtons = GetCashDrawButtons(userCode, out errorMessage);

            if (!string.IsNullOrEmpty(errorMessage.MessageStyle.Message))
            {
                _performancelog.Debug($"End,CashManager,GetCashDrawButtons,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                return(null);
            }

            ValidateCoins(cashDraw, ref isInvalidCash, ref isInvalidQuantity, cashDrawButtons);
            ValidateBills(cashDraw, ref isInvalidCash, ref isInvalidQuantity, cashDrawButtons);

            if (isInvalidCash)
            {
                message = "Invalid Cash or Bill";
            }

            if (isInvalidQuantity)
            {
                message = "Invalid Cash or Bill Quantity";
            }

            if (!string.IsNullOrEmpty(message))
            {
                errorMessage.MessageStyle = new MessageStyle
                {
                    Message = message
                };
                errorMessage.StatusCode = System.Net.HttpStatusCode.BadRequest;
                _performancelog.Debug($"End,CashManager,GetCashDrawButtons,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                return(null);
            }

            //print receipt
            var reasonType = ReasonType.CashDraw;
            var reason     = _reasonService.GetReturnReason(cashDraw.DrawReason, (char)reasonType);

            if (_policyManager.DRAW_REASON && reason == null)
            {
                errorMessage.MessageStyle = new MessageStyle
                {
                    Message = "Invalid Reason"
                };
                errorMessage.StatusCode = System.Net.HttpStatusCode.BadRequest;
                _performancelog.Debug($"End,CashManager,GetCashDrawButtons,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                return(null);
            }

            var draw = new CashDraw
            {
                TillNumber = cashDraw.TillNumber,
                DrawDate   = DateTime.Now,
                TotalValue = (float)cashDraw.Amount,
                User       = userCode.ToUpper(),
                Reason     = cashDraw.DrawReason
            };

            // add values to cash draw
            _cashService.AddCashDraw(draw);

            //update till
            if (till != null)
            {
                till.Cash = till.Cash + cashDraw.Amount;
                _tillService.UpdateTill(till);
                _performancelog.Debug($"End,CashManager,GetCashDrawButtons,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                return(_receiptManager.Print_Draw(till, cashDraw.RegisterNumber, userCode, cashDraw.Coins,
                                                  cashDraw.Bills, reason, cashDraw.Amount));
            }
            return(null);
        }