示例#1
0
 public void SetPayer(Payer payer)
 {
     Recipient      = payer.Recipient;
     Payer          = payer;
     SendToEmail    = Payer.InvoiceSettings.EmailInvoice;
     SendToMinimail = Payer.InvoiceSettings.SendToMinimail;
     PayerName      = payer.JuridicalName;
     Customer       = payer.Customer;
 }
        private void Reset(Payer payer, decimal sum)
        {
            if (payer == null)
            {
                return;
            }

            payer.Balance -= sum;
        }
        private void Apply(Payer payer, decimal sum)
        {
            if (payer == null)
            {
                return;
            }

            payer.Balance += sum;
        }
示例#4
0
        public BalanceSummary(DateTime begin, DateTime end, Payer payer)
        {
            var invoices   = Invoice.Queryable.Where(p => p.Payer == payer).ToList();
            var payments   = Payment.Queryable.Where(p => p.Payer == payer).ToList();
            var acts       = Act.Queryable.Where(p => p.Payer == payer).ToList();
            var operations = ActiveRecordLinqBase <BalanceOperation> .Queryable.Where(d => d.Payer == payer).ToList();

            var refunds = operations.Where(d => d.Type == OperationType.Refund);
            var reliefs = operations.Where(d => d.Type == OperationType.DebtRelief);
            var items   = invoices
                          .Select(i => new { i.Id, i.Date, i.Sum, IsInvoice = true, IsAct = false, IsPayment = false, IsOperation = false, Object = (object)i, Comment = "" })
                          .Union(payments.Select(p => new { p.Id, Date = p.PayedOn, p.Sum, IsInvoice = false, IsAct = false, IsPayment = true, IsOperation = false, Object = (object)p, Comment = "" }))
                          .Union(acts.Select(a => new { a.Id, Date = a.Date, a.Sum, IsInvoice = false, IsAct = true, IsPayment = false, IsOperation = false, Object = (object)a, Comment = "" }))
                          .Union(refunds.Select(d => new {
                d.Id, d.Date, Sum = Decimal.Negate(d.Sum),
                IsInvoice         = true,
                IsAct             = false,
                IsPayment         = false,
                IsOperation       = true,
                Object            = (object)d,
                Comment           = BindingHelper.GetDescription(d.Type)
            }))
                          .Union(reliefs.Select(d => new {
                d.Id, d.Date, Sum = Decimal.Negate(d.Sum),
                IsInvoice         = false,
                IsAct             = true,
                IsPayment         = false,
                IsOperation       = true,
                Object            = (object)d,
                Comment           = BindingHelper.GetDescription(d.Type)
            }))
                          .ToList();

            var befores = items.Where(i => i.Date < begin);

            Before = befores
                     .Select(i => i.Object)
                     .OfType <IBalanceUpdater>()
                     .Sum(i => i.BalanceAmount);
            if (payer.BeginBalanceDate.HasValue)
            {
                Before += payer.BeginBalance;
            }

            items  = items.Where(i => i.Date >= begin && i.Date <= end).ToList();
            Total  = items.Select(i => i.Object).OfType <IBalanceUpdater>().Sum(i => i.BalanceAmount);
            Total += Before;

            Items = items.OrderBy(i => i.Date).ToList();

            TotalAct     = items.Where(i => i.IsAct).Sum(i => i.Sum);
            TotalInvoice = items.Where(i => i.IsInvoice).Sum(i => i.Sum);
            TotalPayment = items.Where(i => i.IsPayment).Sum(i => i.Sum);
        }
示例#5
0
        public Invoice(Payer payer, DateTime date)
            : this()
        {
            Parts     = new List <InvoicePart>();
            CreatedOn = DateTime.Now;
            Author    = SecurityContext.Administrator.Name;

            SetPayer(payer);
            Date   = Payer.GetDocumentDate(date);
            Period = Date.ToPeriod();
        }
示例#6
0
 public Invoice(Payer payer, Period period, DateTime invoiceDate, IEnumerable <InvoicePart> parts)
     : this(payer, invoiceDate)
 {
     Period = period;
     foreach (var part in parts)
     {
         part.Invoice = this;
     }
     Parts = parts.ToList();
     CalculateSum();
 }
        public PayerAuditRecord(Payer payer, Account accounting, string comment = null)
        {
            Payer         = payer;
            Administrator = SecurityContext.Administrator;
            UserName      = Administrator.UserName;
            WriteTime     = DateTime.Now;

            ObjectId   = accounting.ObjectId;
            ObjectType = accounting.ObjectType;
            Name       = accounting.Name;
            Comment    = comment;
        }
        public PayerAuditRecord(Payer payer, string message, string comment = null)
        {
            Payer         = payer;
            Administrator = SecurityContext.Administrator;
            UserName      = Administrator.UserName;
            WriteTime     = DateTime.Now;

            ObjectId   = Payer.Id;
            ObjectType = LogObjectType.Payer;
            Name       = Payer.Name;
            Message    = message;
            Comment    = comment;
        }
示例#9
0
        public void UpdateInn()
        {
            if (!UpdatePayerInn)
            {
                return;
            }

            if (Payer != null &&
                PayerClient != null &&
                !String.IsNullOrEmpty(PayerClient.Inn))
            {
                Payer.INN = PayerClient.Inn;
                Payer.Save();
            }
        }
        private void UpdateBalance()
        {
            var oldPayer = this.OldValue(p => p.Payer);
            var oldSum   = this.OldValue(p => p.BalanceAmount);

            if (this.IsChanged(p => p.Payer) || this.IsChanged(p => p.BalanceAmount))
            {
                Reset(oldPayer, oldSum);
                Apply(Payer, BalanceAmount);

                if (oldPayer != null)
                {
                    oldPayer.Save();
                }
                if (Payer != null)
                {
                    Payer.Save();
                }
            }
        }
示例#11
0
        public List <InvoicePart> BuildParts(int invoiceGroup)
        {
            var result = new List <InvoicePart>();

            foreach (var ad in Payer.Ads.Where(a => a.Invoice == null))
            {
                result.Add(PartForAd(ad));
            }

            var accounts = Payer.GetAccounts().Where(a => a.InvoiceGroup == invoiceGroup);

            if (Period.GetInvoicePeriod() == InvoicePeriod.Quarter)
            {
                result.AddRange(Period.Months().SelectMany(p => GetPartsForPeriod(p, accounts, GetPeriodDate(p))));
            }
            else
            {
                result.AddRange(GetPartsForPeriod(Period, accounts, Date));
            }
            return(result);
        }
示例#12
0
        public Act(DateTime actDate, params Invoice[] invoices)
            : this()
        {
            Period    = invoices.Select(i => i.Period).Distinct().Single();
            Payer     = invoices.Select(i => i.Payer).Distinct().Single();
            Recipient = invoices.Select(i => i.Recipient).Distinct().Single();
            PayerName = invoices.Select(i => i.PayerName).Distinct().Single();
            Customer  = invoices.Select(i => i.Customer).Distinct().Single();

            Date = Payer.GetDocumentDate(actDate);
            var invoiceParts = invoices.SelectMany(i => i.Parts);

            if (Payer.InvoiceSettings.DoNotGroupParts)
            {
                Parts = invoiceParts
                        .Select(p => new ActPart(p.Name, p.Count, p.Cost))
                        .ToList();
            }
            else
            {
                Parts = invoiceParts
                        .GroupBy(p => new { p.Name, p.Cost })
                        .Select(g => new ActPart(g.Key.Name, g.Sum(i => i.Count), g.Key.Cost))
                        .ToList();
            }
            CalculateSum();

            foreach (var part in invoiceParts.Where(p => p.Ad != null))
            {
                part.Ad.Act = this;
            }

            foreach (var invoice in invoices)
            {
                invoice.Act = this;
            }
        }
示例#13
0
 public BalanceOperation(Payer payer)
 {
     Payer = payer;
     Date  = DateTime.Now;
 }
示例#14
0
 public Payment(Payer payer)
     : this()
 {
     Payer     = payer;
     Recipient = payer.Recipient;
 }
示例#15
0
 public LegalEntity(Payer payer)
     : this(payer.Name, payer.JuridicalName, payer)
 {
 }
示例#16
0
 public LegalEntity(string name, string fullName, Payer payer)
 {
     Name     = name;
     FullName = fullName;
     Payer    = payer;
 }
示例#17
0
 public Invoice(Payer payer)
     : this(payer, DateTime.Now)
 {
 }
示例#18
0
 public LegalEntity(string name, Payer payer)
     : this(name, name, payer)
 {
 }
示例#19
0
 public Payment(Payer payer, DateTime payedOn, decimal sum) : this(payer)
 {
     Sum     = sum;
     PayedOn = payedOn;
 }
 public Advertising(Payer payer, decimal cost)
 {
     Payer = payer;
     Cost  = cost;
 }
 public Advertising(Payer payer)
 {
     Payer = payer;
 }
        public RevisionAct(Payer payer, DateTime begin, DateTime end,
                           IEnumerable <Act> acts,
                           IEnumerable <Payment> payments,
                           IEnumerable <BalanceOperation> operations)
        {
            if (payer.Recipient == null)
            {
                throw new Exception("У плательщика не указан получатель платежей, выберете получателя платежей.");
            }

            Payer     = payer;
            BeginDate = begin;
            EndDate   = end;

            var parts = acts.Select(i => new RevisionActPart(i))
                        .Union(payments.Select(p => new RevisionActPart(p)))
                        .Union(operations.Select(d => new RevisionActPart(d)))
                        .ToList();

            var beginDebit  = parts.Where(i => i.Date < begin).Sum(i => i.Debit);
            var beginCredit = parts.Where(p => p.Date < begin).Sum(p => p.Credit);

            var beginBalance = beginCredit - beginDebit;

            beginBalance += payer.BeginBalance;

            if (beginBalance > 0)
            {
                BeginCredit = beginBalance;
            }
            else
            {
                BeginDebit = Math.Abs(beginBalance);
            }

            var movements = parts.Where(p => p.Date >= begin && p.Date <= end)
                            .OrderBy(m => m.Date)
                            .ToList();

            DebitSum  = movements.Sum(m => m.Debit);
            CreditSum = movements.Sum(m => m.Credit);

            Balance = BeginDebit + DebitSum - (BeginCredit + CreditSum);
            if (Balance > 0)
            {
                EndDebit = Balance;
            }
            else
            {
                EndCredit = Math.Abs(Balance);
            }

            Balance = Math.Abs(Balance);

            movements.Insert(0,
                             new RevisionActPart(String.Format("Сальдо на {0}", BeginDate.ToShortDateString()),
                                                 BeginDebit,
                                                 BeginCredit,
                                                 BeginDate));

            movements.Add(
                new RevisionActPart("Обороты за период",
                                    DebitSum,
                                    CreditSum,
                                    EndDate));

            movements.Add(
                new RevisionActPart(String.Format("Сальдо на {0}", EndDate.ToShortDateString()),
                                    EndDebit,
                                    EndCredit,
                                    EndDate));

            Movements = movements;
        }