private double AddAdvancePayments() { double remainder = total - payments.Sum(p => p.Quantity); List <Payment> displayedAdvancePayments = new List <Payment> (); foreach (Payment advance in advances) { // Find an already used advance with the same payment type Payment payment = displayedAdvancePayments.Find(p => p.TypeId == advance.TypeId); if (payment == null) { payment = (Payment)advance.Clone(); payment.OperationId = operation.Id; payment.LocationId = operation.LocationId; payment.ParentOperation = operation; payment.Quantity = 0; displayedAdvancePayments.Add(payment); } // Record the usage of the advance payment with the similar payment type if (!usedAdvances.ContainsKey(payment)) { usedAdvances [payment] = new List <long> (); } usedAdvances [payment].Add(advance.Id); double sum = Math.Min(remainder, advance.Quantity); payment.Quantity += sum; remainder -= sum; if (remainder.IsZero()) { break; } } foreach (Payment advancePayment in displayedAdvancePayments) { advancePayment.PropertyChanged += payment_PropertyChanged; } payments.AddRange(displayedAdvancePayments); return(remainder); }
public void RecalculatePrices() { BindList <ComplexRecipeDetail> products = detailsProd; double totalMat = detailsMat.Sum(t => t.Total); double totalProd = products.Sum(t => t.Quantity * t.PriceOut); bool allPriceOutAreZero = false; if (totalProd.IsZero() && products.Count > 0) { allPriceOutAreZero = products.All(t => t.PriceOut <= 0); if (allPriceOutAreZero) { totalProd += products.Sum(t => t.Quantity); } } foreach (ComplexRecipeDetail detail in products.Where(p => p.Quantity != 0)) { detail.OriginalPriceInEvaluate(totalProd.IsZero() ? 0 : (allPriceOutAreZero ? 1 : detail.PriceOut) * totalMat / totalProd); detail.TotalEvaluate(); } }
public double GetTotal() { return(list.Sum(container => container.Total)); }
protected override void InitializeForm() { XML form = FormHelper.LoadGladeXML("Dialogs.EditNewPayment.glade", "dlgEditNewPayment"); form.Autoconnect(this); dlgEditNewPayment.Icon = FormHelper.LoadImage("Icons.TradePoint32.png").Pixbuf; btnOK.SetChildImage(FormHelper.LoadImage("Icons.Ok24.png")); btnCancel.SetChildImage(FormHelper.LoadImage("Icons.Cancel24.png")); txtDueDate.Text = BusinessDomain.GetFormattedDate(GetDueDate()); base.InitializeForm(); InitializeFormStrings(); paymentWidget.RefreshGrid(); chkUseAdvances.Visible = operation.UseAdvancePayments && operation.Id < 0; if (!chkUseAdvances.Visible) { return; } advances.AddRange(Payment.GetAdvances(operation.PartnerId)); foreach (Payment payment in advances) { payment.Type.BaseType = BasePaymentType.Advance; } if (advances.Count == 0) { chkUseAdvances.Visible = false; } else { chkUseAdvances.Label = string.Format("{0} {1}", Translator.GetString("Use Advance Payments"), string.Format(Translator.GetString("(total: {0})"), Currency.ToString(advances.Sum(p => p.Quantity), operation.TotalsPriceType))); } }