private void customButtonSubmit_Click(object sender, EventArgs e)
        {
            string selectedBankId = comboBoxBankData.SelectedValue.ToString();

            if (!string.IsNullOrEmpty(selectedBankId) && !string.IsNullOrEmpty(customTextBoxTrAmount.Text) &&
                customTextBoxBagNo.isValid)
            {
                string bankName          = string.Empty;
                string bankRoutingNumber = string.Empty;
                string bankAccountNumber = string.Empty;
                if (selectedBankId.Equals(BNL))
                {
                    selectedBankId    = string.Empty;
                    bankName          = customTextBoxBankName.Text;
                    bankRoutingNumber = customTextBoxRoutingNumber.Text;
                    bankAccountNumber = customTextBoxAcctNumber.Text;
                    if (string.IsNullOrEmpty(bankName) || string.IsNullOrEmpty(bankRoutingNumber) ||
                        string.IsNullOrEmpty(bankAccountNumber))
                    {
                        MessageBox.Show("Enter Bank details and submit");
                        return;
                    }
                }
                string transferAmount = customTextBoxTrAmount.Text;
                if (transferAmount.StartsWith("$"))
                {
                    transferAmount = transferAmount.Substring(1);
                }
                if (Utilities.GetDecimalValue(transferAmount, 0) > 0)
                {
                    GlobalDataAccessor.Instance.beginTransactionBlock();
                    bool retVal = ShopCashProcedures.InsertBankTransfer(selectedBankId, DENOMINATIONCURRENCY,
                                                                        GlobalDataAccessor.Instance.DesktopSession.StoreSafeID,
                                                                        string.Format("{0} {1}", ShopDateTime.Instance.ShopDate.FormatDate(), ShopDateTime.Instance.ShopTime.ToString()),
                                                                        "", GlobalDataAccessor.Instance.DesktopSession.LoggedInUserSecurityProfile.UserID,
                                                                        Utilities.GetDecimalValue(transferAmount).ToString(), CashTransferTypes.SHOPTOBANK.ToString(),
                                                                        GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber, "",
                                                                        customTextBoxBagNo.Text, bankName, bankAccountNumber, bankRoutingNumber, GlobalDataAccessor.Instance.DesktopSession,
                                                                        out transferNumber, out errorCode, out errorText);
                    if (retVal)
                    {
                        MessageBox.Show(@"Bank Transfer data successfully inserted");
                        GlobalDataAccessor.Instance.DesktopSession.endTransactionBlock(EndTransactionType.COMMIT);

                        CashTransferVO bankTransferdata = new CashTransferVO();
                        bankTransferdata.TransferNumber            = transferNumber;
                        bankTransferdata.TransferStatus            = CashTransferStatusCodes.ACCEPTED.ToString();
                        bankTransferdata.TransferAmount            = Utilities.GetDecimalValue(transferAmount, 0);
                        bankTransferdata.BankName                  = comboBoxBankData.Text.ToString();
                        bankTransferdata.DepositBagNo              = customTextBoxBagNo.Text;
                        bankTransferdata.DestinationEmployeeName   = GlobalDataAccessor.Instance.DesktopSession.LoggedInUserSecurityProfile.UserName;
                        bankTransferdata.DestinationEmployeeNumber = GlobalDataAccessor.Instance.DesktopSession.LoggedInUserSecurityProfile.EmployeeNumber;
                        SiteId sourceSite = new SiteId();
                        sourceSite = GlobalDataAccessor.Instance.CurrentSiteId;
                        bankTransferdata.SourceShopInfo = sourceSite;
                        BankAndInternalCashTransfer bankTransferFrm = new BankAndInternalCashTransfer();
                        bankTransferFrm.CashTransferdata = bankTransferdata;
                        bankTransferFrm.TransferToBank   = true;
                        bankTransferFrm.ShowDialog();
                    }
                    else
                    {
                        GlobalDataAccessor.Instance.DesktopSession.endTransactionBlock(EndTransactionType.ROLLBACK);
                        FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Bank Transfer from store failed " + errorText);
                    }
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Transfer amount cannot be 0");
                    return;
                }
            }
            else
            {
                MessageBox.Show(@"Fill in all the required information and submit");
                return;
            }
        }
Beispiel #2
0
        private void customButtonSubmit_Click(object sender, EventArgs e)
        {
            string errorCode;
            string errorText;

            //Validate the user
            if (callLdap(customTextBoxDestUser.Text, customTextBoxDestUserPwd.Text))
            {
                var cashdrawerstatus = string.Empty;
                if ((TransferToSafe && transferUserSafeAccess) || (!TransferToSafe && GlobalDataAccessor.Instance.DesktopSession.IsUserAssignedCashDrawer(customTextBoxDestUser.Text,
                                                                                                                                                          comboBoxCashDrawerData.Text.ToString(), out cashdrawerstatus)))
                {
                    if (cashdrawerstatus != "1")
                    {
                        //Check if the cash drawer was balanced today
                        //If it is we show a message that the cash drawer needs to be rebalanced
                        //else proceed.
                        bool cashdrawerbalanced;
                        ShopCashProcedures.CheckCashDrawerBalanced(comboBoxCashDrawerData.SelectedValue.ToString(),
                                                                   ShopDateTime.Instance.ShopDate.FormatDate(), GlobalDataAccessor.Instance.DesktopSession,
                                                                   out cashdrawerbalanced, out errorCode, out errorText);
                        if (cashdrawerbalanced)
                        {
                            MessageBox.Show(Commons.GetMessageString("WM02RebalanceDrawerRequired") + " " +
                                            comboBoxCashDrawerData.Text);
                        }
                        //Open the cash drawer of the destination user
                        string    errorMsg;
                        string    cdID             = comboBoxCashDrawerData.SelectedValue.ToString();
                        const int cashDrawerStatus = (int)CASHDRAWERSTATUS.OPEN;
                        string    workstationID    = SecurityAccessor.Instance.EncryptConfig.ClientConfig.ClientConfiguration.WorkstationId;

                        if (!ShopCashProcedures.UpdateSafeStatus(cdID, GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber,
                                                                 customTextBoxDestUser.Text.ToString(), ShopDateTime.Instance.ShopDate.FormatDate(), cashDrawerStatus.ToString(),
                                                                 workstationID, GlobalDataAccessor.Instance.DesktopSession,
                                                                 out errorCode, out errorMsg))
                        {
                            FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Error when trying to open the cash drawer" + errorMsg);
                        }
                    }
                    DestinationUserValidated = true;
                }
                else
                {
                    MessageBox.Show(@"The destination user is not authorized to receive transfer to the selected cash drawer or safe");
                    return;
                }
            }
            else
            {
                MessageBox.Show(@"Destination user credentials invalid");
                return;
            }
            string transferAmount = customTextBoxTrAmount.Text;

            if (transferAmount.StartsWith("$"))
            {
                transferAmount = transferAmount.Substring(1);
            }

            if (Utilities.GetDecimalValue(transferAmount, 0) == 0)
            {
                MessageBox.Show("Transfer amount cannot be 0");
                return;
            }
            string sourceCashDrawerId;

            if (TransferFromSafe)
            {
                sourceCashDrawerId = GlobalDataAccessor.Instance.DesktopSession.StoreSafeID;
            }
            else
            {
                sourceCashDrawerId = GlobalDataAccessor.Instance.DesktopSession.CashDrawerId;
            }
            string selectedCashDrawerId = comboBoxCashDrawerData.SelectedValue.ToString();

            if (!string.IsNullOrEmpty(selectedCashDrawerId) && !string.IsNullOrEmpty(customTextBoxTrAmount.Text) &&
                DestinationUserValidated)
            {
                int transferNumber;
                GlobalDataAccessor.Instance.beginTransactionBlock();
                bool retVal = ShopCashProcedures.InsertcashTransfer(sourceCashDrawerId, selectedCashDrawerId,
                                                                    Utilities.GetDecimalValue(transferAmount, 0), DENOMINATIONCURRENCY,
                                                                    ShopDateTime.Instance.ShopDate.FormatDate().ToString() + " " + ShopDateTime.Instance.ShopTime.ToString(), GlobalDataAccessor.Instance.DesktopSession.LoggedInUserSecurityProfile.UserID,
                                                                    customTextBoxDestUser.Text, GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber, GlobalDataAccessor.Instance.DesktopSession,
                                                                    out transferNumber, out errorCode, out errorText);

                if (retVal)
                {
                    GlobalDataAccessor.Instance.endTransactionBlock(EndTransactionType.COMMIT);
                    MessageBox.Show(@"Internal Cash Transfer Created Successfully");
                    string         destinationUser  = customTextBoxDestUser.Text;
                    CashTransferVO cashTransferdata = new CashTransferVO();
                    cashTransferdata.TransferNumber     = transferNumber;
                    cashTransferdata.TransferStatus     = CashTransferStatusCodes.ACCEPTED.ToString();
                    cashTransferdata.TransferAmount     = Utilities.GetDecimalValue(transferAmount, 0);
                    cashTransferdata.SourceEmployeeName = GlobalDataAccessor.Instance.DesktopSession.LoggedInUserSecurityProfile.UserFirstName + " " + GlobalDataAccessor.Instance.DesktopSession.LoggedInUserSecurityProfile.UserLastName;
                    string sourceUserName = GlobalDataAccessor.Instance.DesktopSession.LoggedInUserSecurityProfile.UserName;
                    cashTransferdata.SourceEmployeeNumber = sourceUserName.Substring(sourceUserName.Length - 5, 5);
                    if (TransferFromSafe)
                    {
                        cashTransferdata.SourceDrawerName = GlobalDataAccessor.Instance.DesktopSession.StoreSafeName;
                    }
                    else
                    {
                        cashTransferdata.SourceDrawerName = GlobalDataAccessor.Instance.DesktopSession.CashDrawerName;
                    }
                    cashTransferdata.DestinationDrawerName     = comboBoxCashDrawerData.Text.ToString();
                    cashTransferdata.DestinationEmployeeName   = userDisplayName;
                    cashTransferdata.DestinationEmployeeNumber = destinationUser.Substring(destinationUser.Length - 5, 5);
                    var sourceSite = new SiteId();
                    sourceSite = GlobalDataAccessor.Instance.CurrentSiteId;
                    cashTransferdata.SourceShopInfo = sourceSite;
                    var bankTransferFrm = new BankAndInternalCashTransfer();
                    bankTransferFrm.CashTransferdata = cashTransferdata;
                    bankTransferFrm.TransferToBank   = false;
                    bankTransferFrm.InternalTransfer = true;
                    bankTransferFrm.ShowDialog();
                }
                else
                {
                    FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Internal Cash Transfer from store failed " + errorText);
                    GlobalDataAccessor.Instance.endTransactionBlock(EndTransactionType.ROLLBACK);
                }
                this.Close();
            }
            else
            {
                MessageBox.Show(@"Fill in all the required information and submit");
                return;
            }
        }