Exemple #1
0
        //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        //Terminals

        //Duplicate method from logicpos.Utils

        public static pos_configurationplaceterminal GetTerminal()
        {
            pos_configurationplaceterminal configurationPlaceTerminal = null;

            //Debug Directive disabled by Mario, if enabled we cant force Hardware id in Release, if we want to ignore appHardwareId from config we just delete it
            //If assigned in Config use it, else does nothing and use default ####-####-####-####-####-####
            if (SettingsApp.AppHardwareId != null && SettingsApp.AppHardwareId != String.Empty)
            {
                GlobalFramework.LicenceHardwareId = SettingsApp.AppHardwareId;
            }

            try
            {
                //Try TerminalID from Database
                configurationPlaceTerminal = (pos_configurationplaceterminal)FrameworkUtils.GetXPGuidObjectFromField(typeof(pos_configurationplaceterminal), "HardwareId", GlobalFramework.LicenceHardwareId);
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
            }

            //Create a new db terminal
            if (configurationPlaceTerminal == null)
            {
                try
                {
                    //Persist Terminal in DB
                    configurationPlaceTerminal = new pos_configurationplaceterminal(GlobalFramework.SessionXpo)
                    {
                        Ord         = FrameworkUtils.GetNextTableFieldID("pos_configurationplaceterminal", "Ord"),
                        Code        = FrameworkUtils.GetNextTableFieldID("pos_configurationplaceterminal", "Code"),
                        Designation = "Terminal #" + FrameworkUtils.GetNextTableFieldID("pos_configurationplaceterminal", "Code"),
                        HardwareId  = GlobalFramework.LicenceHardwareId
                                      //Fqdn = GetFQDN()
                    };
                    configurationPlaceTerminal.Save();
                }
                catch (Exception ex)
                {
                    _log.Error(string.Format("Error! Cant Register a new TerminalId [{0}] with HardwareId: [{1}], Error: [2]", configurationPlaceTerminal.Oid, configurationPlaceTerminal.HardwareId, ex.Message), ex);
                    Environment.Exit(0);
                }
            }
            return(configurationPlaceTerminal);
        }
Exemple #2
0
        public static bool PersistWorkSessionTotals(POS_WorkSessionPeriod pWorkSessionPeriod)
        {
            try
            {
                //Start UnitOfWork
                using (UnitOfWork uowSession = new UnitOfWork())
                {
                    uint                           paymentMethodOrd   = 0;
                    string                         paymentMethodToken = String.Empty;
                    MovementTypeTotal              movementTypeTotal  = MovementTypeTotal.None;
                    POS_WorkSessionPeriod          workSessionPeriod;
                    FIN_ConfigurationPaymentMethod configurationPaymentMethod;
                    POS_WorkSessionPeriodTotal     workSessionPeriodTotal;
                    //Can filter by Day or Terminal type
                    string wherePeriodField = (pWorkSessionPeriod.PeriodType == WorkSessionPeriodType.Terminal) ? "wspPeriod" : "wspPeriodParent";

                    string sql = string.Format(@"
                        SELECT 
                              DISTINCT(cpmPaymentMethodToken) as Token,
                              cpmPaymentMethodOrd as Ord
                        FROM 
                            view_worksessionmovement 
                        WHERE 
                            cpmPaymentMethodToken IS NOT NULL AND {0} = '{1}'
                        ORDER 
                            BY cpmPaymentMethodOrd
                        ;"
                                               , wherePeriodField
                                               , pWorkSessionPeriod.Oid
                                               );

                    XPSelectData xPSelectData = FrameworkUtils.GetSelectedDataFromQuery(uowSession, sql);
                    foreach (SelectStatementResultRow row in xPSelectData.Data)
                    {
                        paymentMethodOrd   = Convert.ToUInt16(row.Values[xPSelectData.GetFieldIndex("Ord")]);
                        paymentMethodToken = row.Values[xPSelectData.GetFieldIndex("Token")].ToString();

                        switch (paymentMethodToken)
                        {
                        case "MONEY":
                            movementTypeTotal = MovementTypeTotal.Money;
                            break;

                        case "BANK_CHECK":
                            movementTypeTotal = MovementTypeTotal.BankCheck;
                            break;

                        case "CASH_MACHINE":
                            movementTypeTotal = MovementTypeTotal.CashMachine;
                            break;

                        case "CREDIT_CARD":
                            movementTypeTotal = MovementTypeTotal.Credit;
                            break;

                        case "VISA":
                            movementTypeTotal = MovementTypeTotal.Visa;
                            break;

                        case "CURRENT_ACCOUNT":
                            movementTypeTotal = MovementTypeTotal.CurrentAccount;
                            break;
                        }

                        if (movementTypeTotal != MovementTypeTotal.None)
                        {
                            //Get XPObjects
                            workSessionPeriod          = uowSession.GetObjectByKey <POS_WorkSessionPeriod>(pWorkSessionPeriod.Oid);
                            configurationPaymentMethod = (FIN_ConfigurationPaymentMethod)FrameworkUtils.GetXPGuidObjectFromField(uowSession, typeof(FIN_ConfigurationPaymentMethod), "Token", paymentMethodToken);

                            //Persist WorkSessionPeriodTotal
                            workSessionPeriodTotal = new POS_WorkSessionPeriodTotal(uowSession)
                            {
                                Ord           = paymentMethodOrd,
                                PaymentMethod = configurationPaymentMethod,
                                Total         = GetSessionPeriodMovementTotal(workSessionPeriod, movementTypeTotal),
                                Period        = workSessionPeriod
                            };
                        }
                    }
                    ;

                    try
                    {
                        //Commit UOW Changes
                        uowSession.CommitChanges();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        //Rollback
                        uowSession.RollbackTransaction();
                        _log.Error(ex.Message, ex);
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                return(false);
            }
        }