Beispiel #1
0
        private bool CreateTransaction()
        {
            if (total > 0)
            {
                // Are you sure you want to save these amounts....
                DialogResult result = DialogResult.None;
                using (frmMessage dialog = new frmMessage(LSRetailPosis.ApplicationLocalizer.Language.Translate(1953), System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question))
                {
                    LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog);
                    result = dialog.DialogResult;
                }

                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    TenderLineItem tenderLine;
                    int            i = 0; //counter variable for the int Array

                    // Did we count cash?
                    if (cashCounted)
                    {
                        TenderViewModel cashViewTender = gridSource.First(tender => tender.TenderOperationType == PosisOperations.PayCash);
                        string          cashTenderId   = cashViewTender.TenderTypeId;
                        string          cashTenderDesc = cashViewTender.TenderName;
                        string          cashTenderCode = ApplicationSettings.Terminal.StoreCurrency;

                        decimal totalCashAmount = gridSource.Sum(tender => tender.TenderOperationType == PosisOperations.PayCash ? tender.Total : 0m);

                        //This allows the operator to recount a given number of times.
                        if (transaction is TenderDeclarationTransaction)
                        {
                            int rowHandle = gridSource.IndexOf(cashViewTender);

                            if (NeedForRecount(cashTenderId, totalCashAmount, cashTenderDesc, ref i))
                            {
                                // Select the cash row
                                if (rowHandle != -1)
                                {
                                    gvTenders.SelectRow(rowHandle);
                                }

                                return(false);
                            }
                            else
                            {
                                // Disable the cash tender row
                                cashViewTender.Enabled = false;
                                gvTenders.InvalidateRow(rowHandle);

                                i++; //proceed to the next counter that belongs to the next tendertype.
                            }
                        }

                        //Adding a Tenderline (or not)
                        if (totalCashAmount > 0)
                        {
                            tenderLine                       = (TenderLineItem)Dialog.InternalApplication.BusinessLogic.Utility.CreateTenderLineItem();
                            tenderLine.Amount                = totalCashAmount;
                            tenderLine.TenderTypeId          = cashTenderId;
                            tenderLine.Description           = cashTenderDesc;
                            tenderLine.ExchrateMST           = Dialog.InternalApplication.Services.Currency.ExchangeRate(transaction.StoreCurrencyCode) * 100;
                            tenderLine.CompanyCurrencyAmount = Dialog.InternalApplication.Services.Currency.CurrencyToCurrency(transaction.StoreCurrencyCode, ApplicationSettings.Terminal.CompanyCurrency, totalCashAmount);
                            tenderLine.CurrencyCode          = transaction.StoreCurrencyCode;
                            transaction.Add(tenderLine);
                        }
                    }

                    // Did we count other tenders?
                    if (otherTendersCounted)
                    {
                        List <TenderViewModel> otherTenders = gridSource.FindAll(
                            tender => tender.TenderOperationType != PosisOperations.PayCash && tender.TenderOperationType != PosisOperations.PayCurrency);

                        foreach (TenderViewModel otherCount in otherTenders)
                        {
                            if (transaction is TenderDeclarationTransaction)
                            {
                                int rowHandle = gridSource.IndexOf(otherCount);

                                if (NeedForRecount(otherCount.TenderTypeId, otherCount.Total, otherCount.TenderName, ref i))
                                {
                                    // Select the row
                                    if (rowHandle != -1)
                                    {
                                        gvTenders.SelectRow(rowHandle);
                                    }

                                    return(false);
                                }
                                else
                                {
                                    // Disable the row
                                    otherCount.Enabled = false;
                                    gvTenders.InvalidateRow(rowHandle);
                                    i++;
                                }
                            }

                            if (otherCount.Total > 0)
                            {
                                tenderLine                       = (TenderLineItem)Dialog.InternalApplication.BusinessLogic.Utility.CreateTenderLineItem();
                                tenderLine.Amount                = otherCount.Total;
                                tenderLine.TenderTypeId          = otherCount.TenderTypeId;
                                tenderLine.Description           = otherCount.TenderName;
                                tenderLine.ExchrateMST           = Dialog.InternalApplication.Services.Currency.ExchangeRate(transaction.StoreCurrencyCode) * 100;
                                tenderLine.CompanyCurrencyAmount = Dialog.InternalApplication.Services.Currency.CurrencyToCurrency(transaction.StoreCurrencyCode, ApplicationSettings.Terminal.CompanyCurrency, otherCount.Total);
                                tenderLine.CurrencyCode          = transaction.StoreCurrencyCode;
                                transaction.Add(tenderLine);
                            }
                        }
                    }

                    // Did we count foreign currency?
                    if (foreignCurrencyCounted)
                    {
                        List <TenderViewModel> currencyTenders = gridSource.FindAll(tender => tender.TenderOperationType == PosisOperations.PayCurrency);

                        foreach (TenderViewModel currencyCount in currencyTenders)
                        {
                            //Convert to StoreCurrency...
                            decimal currAmountInStoreCurr = Dialog.InternalApplication.Services.Currency.CurrencyToCurrency(
                                currencyCount.Currency, ApplicationSettings.Terminal.StoreCurrency, currencyCount.Total);

                            if (transaction is TenderDeclarationTransaction)
                            {
                                int rowHandle = gridSource.IndexOf(currencyCount);

                                if (NeedForRecount(currencyCount.TenderTypeId, currAmountInStoreCurr, currencyCount.Currency, ref i))
                                {
                                    // Select the row
                                    if (rowHandle != -1)
                                    {
                                        gvTenders.SelectRow(rowHandle);
                                    }

                                    return(false);
                                }
                                else
                                {
                                    // Disable the row
                                    currencyCount.Enabled = false;
                                    gvTenders.InvalidateRow(rowHandle);

                                    i++;
                                }
                            }

                            if (currencyCount.Total > 0)
                            {
                                tenderLine        = (TenderLineItem)Dialog.InternalApplication.BusinessLogic.Utility.CreateTenderLineItem();
                                tenderLine.Amount = currencyCount.Total;
                                tenderLine.ForeignCurrencyAmount = currAmountInStoreCurr;
                                tenderLine.CompanyCurrencyAmount = Dialog.InternalApplication.Services.Currency.CurrencyToCurrency(currencyCount.Currency, ApplicationSettings.Terminal.CompanyCurrency, currencyCount.Total);
                                tenderLine.ExchangeRate          = ((Dialog.InternalApplication.Services.Currency.ExchangeRate(currencyCount.Currency)) / (Dialog.InternalApplication.Services.Currency.ExchangeRate(ApplicationSettings.Terminal.StoreCurrency))) * 100;
                                tenderLine.ExchrateMST           = Dialog.InternalApplication.Services.Currency.ExchangeRate(currencyCount.Currency) * 100;
                                tenderLine.TenderTypeId          = currencyCount.TenderTypeId;
                                tenderLine.Description           = currencyCount.TenderName;
                                tenderLine.CurrencyCode          = currencyCount.Currency;
                                transaction.Add(tenderLine);
                            }
                        }
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            // No amount has been entered yet
            using (frmMessage frm = new frmMessage(LSRetailPosis.ApplicationLocalizer.Language.Translate(1959), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand))
            {
                LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(frm);
            }

            return(false);
        }
Beispiel #2
0
        protected override void OnLoad(EventArgs e)
        {
            if (!this.DesignMode)
            {
                LogMessage("Loading frmTenderCount",
                           LSRetailPosis.LogTraceLevel.Trace,
                           this.ToString());

                TranslateLabels();


                // Check which amounts the POS will expect per tendertype
                // Start by checking which tender types to count....
                TenderData tenderData = new TenderData(
                    ApplicationSettings.Database.LocalConnection,
                    ApplicationSettings.Database.DATAAREAID);

                LoadFromTenderData(tenderData);

                LogMessage("Counting " + tendersToCount.Rows.Count + " tenders",
                           LSRetailPosis.LogTraceLevel.Trace,
                           this.ToString());

                gridSource = new System.Collections.Generic.List <TenderViewModel>();
                denominationDataSources = new Dictionary <int, List <DenominationViewModel> >();

                foreach (DataRow row in tendersToCount.Rows)
                {
                    ITender tmpTender = Dialog.InternalApplication.BusinessLogic.Utility.CreateTender();
                    tmpTender.TenderID       = row["TENDERTYPEID"].ToString();
                    tmpTender.TenderName     = row["NAME"].ToString();
                    tmpTender.PosisOperation = (PosisOperations)(row["POSOPERATION"]);

                    LSRetailPosis.ApplicationLog.Log(this.ToString(), "Counting: " + tmpTender.TenderID
                                                     + " " + tmpTender.TenderName + " "
                                                     + tmpTender.PosisOperation.ToString(),
                                                     LSRetailPosis.LogTraceLevel.Trace);

                    switch (tmpTender.PosisOperation)
                    {
                    case PosisOperations.PayCash:
                        cashCounted = true;

                        TenderViewModel cashRow = new TenderViewModel()
                        {
                            TenderTypeId        = tmpTender.TenderID,
                            TenderOperationType = tmpTender.PosisOperation,
                            TenderName          = tmpTender.TenderName,
                            DisplayName         = ApplicationLocalizer.Language.Translate(STRING_ID_TENDER_NAME, ApplicationSettings.Terminal.StoreCurrency),
                            Currency            = ApplicationSettings.Terminal.StoreCurrency
                        };

                        gridSource.Insert(0, cashRow);
                        break;

                    case PosisOperations.PayCurrency:
                        foreignCurrencyCounted = true;

                        ExchangeRateDataManager exchangeRateData = new ExchangeRateDataManager(ApplicationSettings.Database.LocalConnection, ApplicationSettings.Database.DATAAREAID);
                        //Initialize with all number of currencies avialable
                        foreach (string currency in exchangeRateData.GetCurrencyPair(
                                     ApplicationSettings.Terminal.StoreCurrency,
                                     ApplicationSettings.Terminal.ExchangeRateType,
                                     ApplicationSettings.Terminal.StorePrimaryId))
                        {
                            TenderViewModel currencyRow = new TenderViewModel()
                            {
                                TenderTypeId        = tmpTender.TenderID,
                                TenderOperationType = tmpTender.PosisOperation,
                                TenderName          = tmpTender.TenderName,
                                DisplayName         = ApplicationLocalizer.Language.Translate(STRING_ID_TENDER_NAME, currency),
                                Currency            = currency
                            };

                            gridSource.Insert(gridSource.Count > 0 ? 1 : 0, currencyRow);
                        }
                        break;

                    default:
                        otherTendersCounted = true;
                        TenderViewModel otherRow = new TenderViewModel()
                        {
                            TenderTypeId        = tmpTender.TenderID,
                            TenderOperationType = tmpTender.PosisOperation,
                            TenderName          = tmpTender.TenderName,
                            DisplayName         = tmpTender.TenderName
                        };

                        gridSource.Add(otherRow);
                        break;
                    }
                }

                this.gridTenders.DataSource = gridSource;

                this.Text = lblHeader.Text = formHeadingText;
                this.gvTenders.Appearance.HeaderPanel.ForeColor = this.ForeColor;
                this.gvTenders.Appearance.Row.ForeColor         = this.ForeColor;

                UpdateTotalAmount();
            }

            base.OnLoad(e);
        }