public static void Run()
        {
            Organizations economyEnabledOrgs = Organizations.EconomyEnabled;

            foreach (Organization organization in economyEnabledOrgs)
            {
                FinancialTransactions unbalancedTransactions = FinancialTransactions.GetUnbalanced(organization);
                PaymentGroups         groups = PaymentGroups.ForOrganization(organization);
                FinancialAccount      assetsOutboundInvoices = organization.FinancialAccounts.AssetsOutboundInvoices;

                // This is an N^2 search. Don't care. It runs background.

                foreach (PaymentGroup group in groups)
                {
                    foreach (FinancialTransaction tx in unbalancedTransactions)
                    {
                        if (group.Open && tx.Description.EndsWith(group.Tag.Substring(4)) && tx.DateTime.Date == group.DateTime.Date && tx.Rows.AmountCentsTotal == group.AmountCents)
                        {
                            // Match!

                            tx.Dependency = group;
                            tx.AddRow(assetsOutboundInvoices, -group.AmountCents, null);
                            group.Open = false;
                        }
                    }
                }
            }
        }
Beispiel #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.PageAccessRequired = new Access(this.CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Write);

        this.PageTitle = "Debug Ledgers";
        this.PageIcon  = "iconshock-tester";

        // Initialize by mapping all

        // TODO: If this O(n^2) matching becomes teh suckage, optimize using hashtables over amounts

        Payouts.AutomatchAgainstUnbalancedTransactions(this.CurrentOrganization);

        // Iterate over all open payment groups and try to map them to unbalanced transactions

        FinancialTransactions unbalancedTransactions = FinancialTransactions.GetUnbalanced(this.CurrentOrganization); // TODO: this fn should move to Organization
        PaymentGroups         openGroups             = PaymentGroups.ForOrganization(this.CurrentOrganization, false);

        foreach (PaymentGroup openGroup in openGroups)
        {
            openGroup.MapTransaction(unbalancedTransactions);
        }
    }
 protected void PopulatePaymentGroups(int organizationId)
 {
     this.GridPaymentGroups.DataSource = PaymentGroups.ForOrganization(Organization.FromIdentity(organizationId));
 }
        public void DataCatalogsFill()
        {
            try
            {
                _logger.Debug("DataCatalogsFill start");

                //OperationResultValue<UpdateResult> res = DBProvider.Client.GetUpdatesForSession("");
                //var res2 = res.Result.UpdatedData[0] as OrderToGo;

                OnDataCatalogMessage("Загружаю список операторов");
                //managerOperator = DBDataExtractor<User>.GetDataList(DBProvider.Client.GetUserList) == null ? new FullyObservableCollection<User>() : new FullyObservableCollection<User>(DBDataExtractor<User>.GetDataList(DBProvider.Client.GetUserList));
                managerOperator = DBDataExtractor <User> .GetDataList(DBProvider.Client.GetUserList);

                OnDataCatalogMessage("Загружаю контакты");
                ContactPerson = DBDataExtractor <ContactPerson> .GetDataList(DBProvider.Client.GetContactPersonList);

                /*
                 * ToGoCustomers = DBDataExtractor<OrderCustomer>.GetDataList(DBProvider.Client.GetOrderCustomerList);
                 * ToGoCustomersAddresses = new FullyObservableCollection<OrderCustomerAddress>();
                 * foreach (var cust in ToGoCustomers)
                 * {
                 *  foreach (var addr in cust.Addresses)
                 *  {
                 *      ToGoCustomersAddresses.Add(addr);
                 *  }
                 * }
                 */
                OnDataCatalogMessage("Загружаю наклейки");
                //ItemLabelsInfo = DBDataExtractor<ItemLabelInfo>.GetDataList(DBProvider.Client.GetItemLabelInfoList) == null ? new FullyObservableCollection<ItemLabelInfo>() : new FullyObservableCollection<ItemLabelInfo>(DBDataExtractor<ItemLabelInfo>.GetDataList(DBProvider.Client.GetItemLabelInfoList));
                ItemLabelsInfo = DBDataExtractor <ItemLabelInfo> .GetDataList(DBProvider.Client.GetItemLabelInfoList);

                DishLogicGroup = DBDataExtractor <DishLogicGroup> .GetDataList(DBProvider.Client.GetDishLogicGroupsList);

                DishKitchenGroup = DBDataExtractor <DishKitchenGroup> .GetDataList(DBProvider.Client.GetDishKitсhenGroupsList);

                OnDataCatalogMessage("Загружаю авиакомпании");
                PaymentGroups = DBDataExtractor <PaymentGroup> .GetDataList(DBProvider.Client.GetPaymentGroupList);

                Payments = DBDataExtractor <Payment> .GetDataList(DBProvider.Client.GetPaymentList);

                foreach (var a in Payments)
                {
                    if (a.PaymentGroupId != 0)
                    {
                        a.PaymentGroup = PaymentGroups.SingleOrDefault(b => b.Id == a.PaymentGroupId);
                    }

                    PaymentsSourceCache.AddOrUpdate(a);
                }
                Discounts = DBDataExtractor <Discount> .GetDataList(DBProvider.Client.GetDiscountList);

                AllAirCompanies = new FullyObservableCollection <AirCompany>(DBDataExtractor <AirCompany>
                                                                             .GetDataList(DBProvider.Client.GetAirCompanyList)
                                                                             //.Where(a => !DBProvider.SharAirs.Contains(a.Id) || ((Authorization.CurentUser != null) && ((Authorization.CurentUser.UserName == "sh.user") || (Authorization.IsDirector))))
                                                                             .OrderBy(a => a.Name));



                foreach (var a in AllAirCompanies)
                {
                    if (a.PaymentId != null)
                    {
                        a.PaymentType = Payments.SingleOrDefault(b => b.Id == a.PaymentId);
                    }
                    if (a.DiscountId != null)
                    {
                        a.DiscountType = Discounts.SingleOrDefault(b => b.Id == a.DiscountId);
                    }
                }
                AirCompanies = new FullyObservableCollection <AirCompany>(AllAirCompanies.Where(a => a.IsActive && (!DBProvider.SharAirs.Contains(a.Id) || ((Authorization.CurentUser != null) && ((Authorization.CurentUser.UserName == "sh.user") || (Authorization.IsDirector))))));
                //AirCompanies = DBDataExtractor<AirCompany>.GetDataList(DBProvider.Client.GetAirCompanyList);
                //DeliveryPlaces = DBDataExtractor<DeliveryPlace>.GetDataList(DBProvider.Client.GetDeliveryPlaceList) == null ? new FullyObservableCollection<DeliveryPlace>() : new FullyObservableCollection<DeliveryPlace>(DBDataExtractor<DeliveryPlace>.GetDataList(DBProvider.Client.GetDeliveryPlaceList));

                DeliveryPlaces = DBDataExtractor <DeliveryPlace> .GetDataList(DBProvider.Client.GetDeliveryPlaceList);

                Drivers = DBDataExtractor <Driver> .GetDataList(DBProvider.Client.GetDriverList) == null ? new FullyObservableCollection <Driver>() : new FullyObservableCollection <Driver>(DBDataExtractor <Driver> .GetDataList(DBProvider.Client.GetDriverList));

                mDiscounts = DBDataExtractor <Discount> .GetDataList(DBProvider.Client.GetDiscountList) == null ? new FullyObservableCollection <Discount>() : new FullyObservableCollection <Discount>(DBDataExtractor <Discount> .GetDataList(DBProvider.Client.GetDiscountList));

                OnDataCatalogMessage("Загружаю блюда");
                Dishes = DBDataExtractor <Dish> .GetDataList(DBProvider.Client.GetDishList);

                foreach (var d in Dishes)
                {
                    if (d.DishKitсhenGroupId > 0)
                    {
                        try { d.DishKitсhenGroup = DishKitchenGroup.Single(a => a.Id == d.DishKitсhenGroupId); } catch { }
                    }
                    if (d.DishLogicGroupId > 0)
                    {
                        try { d.DishLogicGroup = DishLogicGroup.Single(a => a.Id == d.DishLogicGroupId); } catch { }
                    }
                    d.LabelsCount = ItemLabelsInfo.Where(a => a.ParenItemId == d.Id).Count();
                }

                OnDataCatalogMessage("Загружаю cписок клиентов");

                marketingChannels = DBDataExtractor <MarketingChannel> .GetDataList(DBProvider.Client.GetMarketingChannelList);


                ItemLabelsInfo.ItemPropertyChanged += ItemLabelsInfo_ItemPropertyChanged;

                RefreshDynamicData();

                _logger.Debug("DataCatalogsFill end");
            }
            catch (Exception e)
            {
                _logger.Debug($"DataCatalogsFill error {e.Message}");
                MainClass.SetNeedExit("Ошибка загрузки справочников " + e.Message);
            }

            /*
             * foreach (var d in DBDataExtractor<Dish>.GetDataList(DBProvider.Client.GetDishList) == null ? new FullyObservableCollection<Dish>() : new FullyObservableCollection<Dish>(DBDataExtractor<Dish>.GetDataList(DBProvider.Client.GetDishList)))
             * {
             *  dishes.Add(d);
             * }
             */
        }