public override IDictionary <int, double> GetCashBookBalances <T> (DataQuery dataQuery)
        {
            LazyListModel <T> model = ExecuteDataQuery <T> (dataQuery,
                                                            string.Format(@"SELECT cashbook.Sign AS {0}, SUM(cashbook.Profit) AS {1} FROM cashbook GROUP BY cashbook.Sign",
                                                                          fieldsTable.GetFieldAlias(DataField.CashEntryDirection),
                                                                          fieldsTable.GetFieldAlias(DataField.CashEntryAmount)));
            Dictionary <int, double> balances = new Dictionary <int, double> ();

            switch (model.Count)
            {
            case 0:
                balances.Add(-1, 0);
                balances.Add(1, 0);
                break;

            case 1:
                int existingSign = (int)model [0, "PaymentDirection"];
                balances.Add(-existingSign, 0);
                balances.Add(existingSign, (double)model [0, "Amount"]);
                break;

            default:
                balances.Add((int)model [0, "PaymentDirection"], (double)model [0, "Amount"]);
                balances.Add((int)model [1, "PaymentDirection"], (double)model [1, "Amount"]);
                break;
            }
            return(balances);
        }
        private void InitializeUsersGrid()
        {
            users     = User.GetAll(BusinessDomain.LoggedUser.UserLevel);
            gridUsers = new ListView();

            scwUsers.Add(gridUsers);
            gridUsers.Show();

            ColumnController cc = new ColumnController();

            Column col = new Column(Translator.GetString("User"), "Name", 0.2, "Name");

            col.MinWidth            = 70;
            col.ListCell.IsEditable = false;
            cc.Add(col);

            gridUsers.ColumnController    = cc;
            gridUsers.Model               = users;
            gridUsers.AllowMultipleSelect = false;
            gridUsers.CellsFucusable      = true;
            gridUsers.RulesHint           = true;
            gridUsers.SortColumnsHint     = true;
            gridUsers.Realized           += grid_Realized;
            gridUsers.Selection.Changed  += gridUsers_SelectionChanged;
        }
        public static LazyListModel <RestaurantOrder> Get(long?locationId, long?customerId, long?userId, DateTime?from = null, DateTime?to = null)
        {
            LazyListModel <RestaurantOrder> orders = BusinessDomain.DataAccessProvider.GetRestaurantOrders <RestaurantOrder> (locationId, customerId, userId, @from, to);

            foreach (RestaurantOrder order in orders)
            {
                order.LoadDetails();
            }

            return(orders);
        }
        public override void DeleteECRReceipts(DataQuery dataQuery)
        {
            LazyListModel <int> model = ExecuteDataQuery <int> (
                dataQuery, string.Format("SELECT ID AS {0} FROM ecrreceipts", fieldsTable.GetFieldAlias(DataField.ECRReceiptID)));

            if (model.Count > 0)
            {
                ExecuteNonQuery(string.Format(
                                    "DELETE FROM ecrreceipts WHERE ID IN ({0})",
                                    string.Join(", ", model.Select(i => i.ToString(CultureInfo.InvariantCulture)))));
            }
        }
Esempio n. 5
0
        public override T GetCashReport <T> (DataQuery dataQuery)
        {
            string query = string.Format(@"
                SELECT SUM(payments.Qtty) AS {0}
                FROM (payments INNER JOIN paymenttypes ON payments.Type = paymenttypes.ID) 
                  LEFT JOIN documents ON payments.Acct = documents.Acct AND payments.OperType = documents.OperType
                WHERE payments.OperType IN (2, 16) AND payments.Mode = 1 AND paymenttypes.PaymentMethod = 1
                  AND documents.InvoiceNumber IS NULL",
                                         fieldsTable.GetFieldAlias(DataField.OperationTotal));

            LazyListModel <T> model = ExecuteDataQuery <T> (dataQuery, query);

            return(model.Count > 0 ? model [0] : null);
        }
Esempio n. 6
0
        private void ReInitializeForm(long?transferId)
        {
            if (transferId != null)
            {
                operation = Transfer.GetById(transferId.Value);

                txtSrcLocation.Text = operation.SourceLocation;
                txtDstLocation.Text = operation.TargetLocation;
                txtUser.Text        = operation.UserName;
                SetDate(operation.Date);
                SetNote(operation.Details);

                SrcLocationSensitive = false;
                SetOperationTotalAndEditMode();
            }
            else
            {
                operation = new Transfer();

                operation.AddNewDetail();
                operation.LoggedUserId = BusinessDomain.LoggedUser.Id;

                if (srcLocation == null)
                {
                    LazyListModel <Location> allLocations = Location.GetAll();
                    if (allLocations.Count == 1)
                    {
                        SetSourceLocation(allLocations [0]);
                    }
                    else
                    {
                        txtSrcLocation.Text = string.Empty;
                    }
                }
                else
                {
                    SetSourceLocation(srcLocation);
                }
                txtDstLocation.Text = string.Empty;
                SetUser(BusinessDomain.LoggedUser);
                SetDate(BusinessDomain.Today);
                SetNote(operation.Details);

                SetOperationTotalAndNewMode();
            }

            InitializeGrid();
            BindGrid();
        }
Esempio n. 7
0
        public static bool TryGetLocked(ref Location location)
        {
            if (BusinessDomain.LoggedUser.LockedLocationId > 0)
            {
                location = GetById(BusinessDomain.LoggedUser.LockedLocationId);
                return(true);
            }

            LazyListModel <Location> allLocations = GetAll();

            if (allLocations.Count == 1)
            {
                location = allLocations [0];
            }

            return(false);
        }
Esempio n. 8
0
        public static bool TryGetLocked(out Partner partner)
        {
            if (BusinessDomain.LoggedUser.LockedPartnerId > 0)
            {
                partner = GetById(BusinessDomain.LoggedUser.LockedPartnerId);
                return(true);
            }

            if (BusinessDomain.LoggedUser.DefaultPartnerId > 0)
            {
                partner = GetById(BusinessDomain.LoggedUser.DefaultPartnerId);
                return(false);
            }

            LazyListModel <Partner> all = GetAll();

            partner = all.Count == 1 ? all [0] : null;

            return(false);
        }
Esempio n. 9
0
        protected virtual void InitializeEntries()
        {
            LazyListModel <User> allUsers             = User.GetAll();
            List <KeyValuePair <int, string> > levels = new List <KeyValuePair <int, string> > (User.GetAllAccessLevels());

            if (user == null)
            {
                user = new User {
                    Password = string.Empty
                };
                // If we are creating the first user after the default user then he can only be owner
                if (allUsers.Count <= 1)
                {
                    ClearAllButOwner(levels);
                }
                else
                {
                    ClearUnavailableAccessLevels(levels);
                }

                cboAccessLevel.Load(levels, "Key", "Value", (int)UserAccessLevel.Operator);

                if (defaultGroupId.HasValue)
                {
                    gEditPanel.SelectGroupId((int)defaultGroupId);
                }

                if (BusinessDomain.AppConfiguration.AutoGenerateUserCodes)
                {
                    user.AutoGenerateCode();
                }
            }
            else
            {
                // If we are editing the first user after the default user then he can only be owner
                if (allUsers.Count <= 2)
                {
                    ClearAllButOwner(levels);
                }
                else
                {
                    ClearUnavailableAccessLevels(levels);
                }

                cboAccessLevel.Load(levels, "Key", "Value", (int)user.UserLevel);
                gEditPanel.SelectGroupId(user.GroupId);
            }

            txtName.Text        = user.Name;
            txtDisplayName.Text = user.Name2;
            txtPassword1.Text   = "******";
            txtPassword2.Text   = "******";
            txtCardNo.Text      = user.CardNo;
            txtCode.Text        = user.Code;

            if (user.LockedLocationId > 0)
            {
                lockedLocation = Location.GetById(user.LockedLocationId);
                if (lockedLocation != null)
                {
                    txtLocation.Text = lockedLocation.Name;
                }
            }

            if (user.LockedPartnerId > 0)
            {
                lockedPartner = Partner.GetById(user.LockedPartnerId);
                if (lockedPartner != null)
                {
                    txtPartner.Text = lockedPartner.Name;
                }
            }

            if (user.DefaultPartnerId > 0)
            {
                defaultPartner = Partner.GetById(user.DefaultPartnerId);
                if (defaultPartner != null)
                {
                    txtDefaultPartner.Text = defaultPartner.Name;
                }
            }

            if (user.DefaultCompanyId > 0)
            {
                defaultCompany = CompanyRecord.GetById(user.DefaultCompanyId);
                if (defaultCompany != null)
                {
                    txtCompany.Text = defaultCompany.Name;
                }
            }

            chkShowItemsPurchasePrice.Active = !user.HideItemsPurchasePrice;
            chkShowItemsAvailability.Active  = !user.HideItemsAvailability;
            chkAllowZeroPrices.Active        = user.AllowZeroPrices;
        }
Esempio n. 10
0
        private void InitializeEntries()
        {
            LazyListModel <MesUnit> units = MesUnit.GetAll();

            if (item == null)
            {
                item = new Item();

                if (defaultGroupId.HasValue)
                {
                    gEditPanel.SelectGroupId((int)defaultGroupId);
                }

                if (BusinessDomain.AppConfiguration.AutoGenerateItemCodes)
                {
                    item.AutoGenerateCode();
                }
            }
            else
            {
                gEditPanel.SelectGroupId(item.GroupId);
            }

            txtCode.Text               = item.Code;
            txtName.Text               = item.Name;
            txtDisplayName.Text        = item.Name2;
            txtCatalogNumber1.Text     = item.Catalog;
            txtCatalogNumber2.Text     = item.Catalog2;
            txtCatalogNumber3.Text     = item.Catalog3;
            txvDescription.Buffer.Text = item.Description;

            txtBarCode1.Text = item.BarCode;
            txtBarCode2.Text = item.BarCode2;

            barcodes.Clear();
            if (!string.IsNullOrWhiteSpace(item.BarCode3))
            {
                foreach (string barcode in item.BarCode3.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    barcodes.Add(barcode);
                }
            }

            if (barcodes.Count == 0)
            {
                barcodes.Add(string.Empty);
            }

            List <KeyValuePair <object, string> > barCodeTypes = Enum.GetValues(typeof(GeneratedBarcodeType))
                                                                 .Cast <object> ()
                                                                 .Select(value => new KeyValuePair <object, string> (value, value.ToString()))
                                                                 .OrderBy(p => p.Value).ToList();

            cboBarcodeType.Load(barCodeTypes, "Key", "Value", BusinessDomain.AppConfiguration.CustomGeneratedBarcodeType);
            txtBarcodeFormat.Text = BusinessDomain.AppConfiguration.CustomGeneratedBarcodeFormat;

            List <MesUnit> validUnits = units.Where(u => !string.IsNullOrWhiteSpace(u.Name)).ToList();

            cbeMesUnit.Load(validUnits, "Name", "Name");
            if (!string.IsNullOrWhiteSpace(item.MUnit))
            {
                cbeMesUnit.Entry.Text = item.MUnit;
            }
            txtMesRatio.Text = Number.ToEditString(item.MUnitRatio);
            cbeMesUnit2.Load(validUnits, "Name", "Name");
            if (!string.IsNullOrWhiteSpace(item.MUnit))
            {
                cbeMesUnit2.Entry.Text = item.MUnit2;
            }
            txtMinimalQty.Text = Quantity.ToEditString(item.MinimalQuantity);
            txtNominalQty.Text = Quantity.ToEditString(item.NominalQuantity);

            LazyListModel <VATGroup>            allGroups = VATGroup.GetAll();
            List <KeyValuePair <long, string> > vatList   = new List <KeyValuePair <long, string> > (allGroups
                                                                                                     .Select(vatGroup => new KeyValuePair <long, string> (vatGroup.Id,
                                                                                                                                                          string.Format("{0} ({1})", vatGroup.Name, Percent.ToString(vatGroup.VatValue)))));

            cboVATGroup.Load(vatList, "Key", "Value", item.VatGroupId);

            SetPrices(item);
        }
Esempio n. 11
0
        public static IManageableListModel <PriceRule> GetAll()
        {
            LazyListModel <PriceRule> allPriceRules = BusinessDomain.DataAccessProvider.GetAllPriceRules <PriceRule> ();

            return(new BindingListModel <PriceRule> (allPriceRules.Where(p => p.ParseFormula())));
        }
        private void InitializeLocationsGrid()
        {
            gridLocations = new ListView
            {
                Name                = "gridLocations",
                WidthRequest        = 250,
                HeightRequest       = 400,
                AllowMultipleSelect = false
            };
            gridLocations.Selection.Changed += Selection_Changed;

            gridLocations.ColumnController = new ColumnController
            {
                new Column(Translator.GetString("Location"), "Name", 1, "Name")
            };

            scwLocations.Add(gridLocations);
            gridLocations.Show();

            allLocations = Location.GetAll();

            bool recreated = false;
            bool retry;

            do
            {
                retry           = false;
                allStartNumbers = OperationNumberingInfo.Get();
                if (allStartNumbers.Length == 0)
                {
                    OperationNumberingInfo.Create();
                    recreated       = true;
                    allStartNumbers = OperationNumberingInfo.Get();
                }
                allStartNumbersPerLocation.Clear();

                foreach (Location location in allLocations)
                {
                    Location l = location;
                    List <OperationNumberingInfo> operations = allStartNumbers.Where(o => o.LocationId == l.Id).ToList();
                    if (operations.Count == 0 && !recreated)
                    {
                        OperationNumberingInfo.Create();
                        retry     = true;
                        recreated = true;
                        break;
                    }

                    foreach (var info in operations)
                    {
                        info.UsageDescription = Translator.GetString("Calculating...");
                    }

                    allStartNumbersPerLocation.Add(new KeyValuePair <long, BindingListModel <OperationNumberingInfo> > (location.Id,
                                                                                                                        new BindingListModel <OperationNumberingInfo> (operations)));
                }
            } while (retry);

            DataHelper.FireAndForget(() =>
            {
                numbersUsagePerLocation = OperationNumbersUsage.Get();
                numbersUsageStarts      = OperationNumbersUsage.GetUsagesStarts();
                Timeout.Add(0, () =>
                {
                    try {
                        UpdateDocumentsUsage();
                    } catch (ArgumentOutOfRangeException) { }
                    return(false);
                });
            });

            allStartNumbersPerLocation = allStartNumbersPerLocation.OrderBy(p => p.Value.Min(o => o.StartNumber)).ToList();
            // Use a model with natural order by the operation number intervals
            gridLocations.Model = new BindingListModel <Location> (allStartNumbersPerLocation.Select(d => allLocations.Find(p => p.Id == d.Key)));
            lblCurrentLocationsValue.SetText(allLocations.Count.ToString("N", formatBigNumber));

            if (gridLocations.Model.Count <= 0)
            {
                return;
            }

            gridLocations.FocusRow(0);
            gridLocations.Selection.Select(0);
            gridLocations.ScrollToV(0);
        }