/// <summary> /// Перезагрузка плановых платежей с сохранением информации о преждних платежах. /// </summary> public void ReloadPaymentsPlannedLight() { //если плановых платежей еще нет, либо был удален совершенный платеж. if (!PaymentsPlanned.Any() || SumRest.Sum > PaymentsPlanned.Sum(x => x.SumAndVat.Sum)) { ReloadPaymentsPlannedFull(); return; } var paymentsToRemove = new List <PaymentPlanWrapper>(PaymentsPlanned); var sumRest = SumRest.Sum; while (sumRest > 0 && paymentsToRemove.Any()) { var payment = paymentsToRemove.Last(); if (sumRest < payment.SumAndVat.Sum) { payment.SumAndVat.Sum = sumRest; paymentsToRemove.Remove(payment); break; } sumRest -= payment.SumAndVat.Sum; paymentsToRemove.Remove(payment); } foreach (var paymentWrapper in paymentsToRemove) { PaymentsPlanned.Remove(paymentWrapper); } }
/// <summary> /// Полная перезагрузка плановых платежей /// </summary> public void ReloadPaymentsPlannedFull() { PaymentsPlanned.Clear(); foreach (var condition in PaymentConditionsToDone) { var payment = new PaymentPlan { SumAndVat = new SumAndVat { Sum = CostSingle.Sum * condition.PartInPercent / 100, Vat = CostSingle.Vat } }; //дата платежа if (condition.PaymentConditionPoint == PaymentConditionPoint.ProductionStart) { payment.Date = ProductionUnit.ProductionStartDateCalculated.AddDays(condition.DaysToPoint); } if (condition.PaymentConditionPoint == PaymentConditionPoint.ProductionEnd) { payment.Date = ProductionUnit.ProductionEndDateCalculated.AddDays(condition.DaysToPoint); } if (condition.PaymentConditionPoint == PaymentConditionPoint.Shipment) { payment.Date = ShipmentUnit.ShipmentDateCalculated.AddDays(condition.DaysToPoint); } if (condition.PaymentConditionPoint == PaymentConditionPoint.Delivery) { payment.Date = ShipmentUnit.DeliveryDateCalculated.AddDays(condition.DaysToPoint); } var paymentWrapper = new PaymentPlanWrapper(payment); PaymentsPlanned.Add(paymentWrapper); } }