Exemple #1
0
        public string GetReportHTML(DateTime from, DateTime to)
        {
            var reportLocationIds = LocationIds;
            var locations         = Db.FindLocation(new LocationDiscriminator()
            {
                Filter = x => reportLocationIds.Contains(x.LocationId)
            }, null, null);
            var reportAddresses = locations.Select(l => l.Location.AddressId).ToArray();
            var addresses       = Db.FindAddress(new AddressDiscriminator()
            {
                Filter = x => reportAddresses.Contains(x.AddressId)
            });
            var trns = Db.FindCreditTransaction(new CreditTransactionDiscriminator()
            {
                Filter = x => reportLocationIds.Contains(x.LocationId) && x.TransactionTime >= from && x.TransactionTime < to
            });
            var productIds    = trns.Select(x => x.CreditTransaction.ProductId).Distinct().ToArray();
            var productFilter = new ProductDiscriminator()
            {
                Filter = x => productIds.Contains(x.ProductId)
            };
            var products = Db.FindProduct(productFilter, null, null, default(int));
            var prices   = Db.FindProductPriceHistory(productFilter, true);
            var userIds  = trns.Select(t => t.CreditTransaction.UserId).Distinct().ToArray();
            var users    = SecrityDB.FindUserProfile(new UserProfileDiscriminator()
            {
                Filter = x => userIds.Contains(x.UserId)
            });

            var trnTemplate = new LocationTransactions();

            trnTemplate.Locations          = locations.Select(l => l.Location);
            trnTemplate.Addresses          = addresses.Select(a => a.Address);
            trnTemplate.From               = from;
            trnTemplate.To                 = to;
            trnTemplate.CreditTransactions = trns.Select(x => x.CreditTransaction);
            trnTemplate.Products           = products.Select(x => x.Product);
            trnTemplate.Prices             = prices.Select(x => x.ProductPriceHistory);
            trnTemplate.Users              = users.Select(u => u.UserProfile);
            return(trnTemplate.TransformText());
        }
Exemple #2
0
        public string GetReportHTML(DateTime from, DateTime to)
        {
            var reportLocationIds = LocationIds;
            var locations         = Db.FindLocation(new LocationDiscriminator()
            {
                Filter = x => reportLocationIds.Contains(x.LocationId)
            }, null, null);
            var reportAddresses = locations.Select(l => l.Location.AddressId).ToArray();
            var addresses       = Db.FindAddress(new AddressDiscriminator()
            {
                Filter = x => reportAddresses.Contains(x.AddressId)
            });
            var locationUsers = Db.FindUserProfile(null, new UserProfileVsLocationDiscriminator()
            {
            }, null);
            var userIds = locationUsers.Select(u => u.UserProfile2.UserId).ToArray();
            var credits = Db.FindProfileCredit(new ProfileCreditDiscriminator()
            {
                Filter = x => x.HasBallance.HasValue && x.HasBallance.Value && userIds.Contains(x.UserId)
            });

            switch (mode)
            {
            case ModeOptions.ARREARS:
                var arrearsTemplate = new CustomerArrearsByLocation();
                arrearsTemplate.Locations      = locations.Select(l => l.Location);
                arrearsTemplate.Addresses      = addresses.Select(a => a.Address);
                arrearsTemplate.ProfileCredits = credits;
                arrearsTemplate.Users          = locationUsers.Select(u => u.UserProfile2);
                return(arrearsTemplate.TransformText());

            default:
                var balanceTemplate = new CustomerBalancesByLocation();
                balanceTemplate.Locations      = locations.Select(l => l.Location);
                balanceTemplate.Addresses      = addresses.Select(a => a.Address);
                balanceTemplate.ProfileCredits = credits;
                balanceTemplate.Users          = locationUsers.Select(u => u.UserProfile2);
                return(balanceTemplate.TransformText());
            }
        }
        public string GetReportHTML()
        {
            var      reportLocationIds = LocationIds;
            IAddress address           = null;

            if (SessionGlobal.CurrentLocation != null && SessionGlobal.CurrentLocation.AddressId.HasValue)
            {
                long curAddressId = SessionGlobal.CurrentLocation.AddressId.Value;
                var  addressC     = Db.FindAddress(new AddressDiscriminator()
                {
                    Filter = x => x.AddressId == curAddressId
                }).FirstOrDefault();
                if (addressC != null)
                {
                    address = addressC.Address;
                }
            }
            var user = Db.FindUserProfile(new UserProfile2Discriminator()
            {
                Filter = x => x.UserId == UserId
            }, null, null).First();
            var userCredits = Db.FindProfileCredit(new ProfileCreditDiscriminator()
            {
                Filter = x => x.HasBallance.HasValue && x.HasBallance.Value && x.UserId == UserId && reportLocationIds.Contains(x.LocationId)
            });
            var locations = Db.FindLocation(new LocationDiscriminator()
            {
                Filter = x => reportLocationIds.Contains(x.LocationId)
            }, null, null);
            var invoiceTemplate = new Invoice();

            invoiceTemplate.User            = user.UserProfile2;
            invoiceTemplate.Locations       = locations.Select(l => l.Location);
            invoiceTemplate.Credits         = userCredits;
            invoiceTemplate.LocationAddress = address;
            return(invoiceTemplate.TransformText());
        }
        public string GetReportHTML()
        {
            var      reportLocationIds = LocationIds;
            IAddress address           = null;

            if (SessionGlobal.CurrentLocation != null && SessionGlobal.CurrentLocation.AddressId.HasValue)
            {
                long curAddressId = SessionGlobal.CurrentLocation.AddressId.Value;
                var  addressC     = Db.FindAddress(new AddressDiscriminator()
                {
                    Filter = x => x.AddressId == curAddressId
                }).FirstOrDefault();
                if (addressC != null)
                {
                    address = addressC.Address;
                }
            }
            var user = Db.FindUserProfile(new UserProfile2Discriminator()
            {
                Filter = x => x.UserId == UserId
            }, null, null).First();
            var locations = Db.FindLocation(new LocationDiscriminator()
            {
                Filter = x => reportLocationIds.Contains(x.LocationId)
            }, null, null);
            var lastTransaction = Db.FindCreditTransaction(new CreditTransactionDiscriminator()
            {
                Filter = x => x.UserId == UserId && reportLocationIds.Contains(x.LocationId), Take = 1, OrderBy = new SortByFld[] { new SortByFld()
                                                                                                                                    {
                                                                                                                                        FieldName = "Id", IsDescending = true
                                                                                                                                    } }
            }).FirstOrDefault();

            if (lastTransaction != null)
            {
                DateTime lastTrnTime        = lastTransaction.CreditTransaction.TransactionTime.AddMinutes(-1);
                var      reportLocationIds2 = LocationIds;
                var      lastTransactions   = Db.FindCreditTransaction(new CreditTransactionDiscriminator()
                {
                    Filter = x => x.UserId == UserId && reportLocationIds2.Contains(x.LocationId) && x.TransactionTime >= lastTrnTime
                });
                var productIds    = lastTransactions.Select(x => x.CreditTransaction.ProductId).Distinct().ToArray();
                var productFilter = new ProductDiscriminator()
                {
                    Filter = x => productIds.Contains(x.ProductId)
                };
                var products        = Db.FindProduct(productFilter, null, null, default(int));
                var prices          = Db.FindProductPriceHistory(productFilter, true);
                var receiptTemplate = new Receipt();
                receiptTemplate.User               = user.UserProfile2;
                receiptTemplate.Locations          = locations.Select(l => l.Location);
                receiptTemplate.CreditTransactions = lastTransactions.Select(x => x.CreditTransaction);
                receiptTemplate.Products           = products.Select(x => x.Product);
                receiptTemplate.Prices             = prices.Select(x => x.ProductPriceHistory);
                receiptTemplate.LocationAddress    = address;
                return(receiptTemplate.TransformText());
            }
            else
            {
                return(null);
            }
        }