public void AddPart() { Part part = new Part(); part.Number = "VOD-13-33P"; chargeSlip.Add(part); Assert.AreEqual(chargeSlip.PartCount, 1, "PartCount is wrong."); }
public void Close() { if (invoice == null) { throw(new InvalidInvoiceException()); } // add invoice charges to po charges foreach (Charge c in invoice.Charges) { Add(c); } // Collect all the different work orders the parts go to. // For each work order, create a charge slip Hashtable woList = new Hashtable(); int n = 1; // we always start with charge slip #000001 string nStr = "000000"; double totalPartCost = 0; foreach (DictionaryEntry item in parts) { if (!woList.Contains(item.Value)) { ChargeSlip cs = new ChargeSlip(); string s = n.ToString(); cs.Number = nStr.Substring(0, 6 - s.Length) + s; woList[item.Value] = cs; // add the new charge slip to the work order (item.Value as WorkOrder).Add(cs); } // For each charge slip, add the part to // the charge slip. ChargeSlip cs2 = woList[item.Value] as ChargeSlip; cs2.Add(item.Key as Part); totalPartCost += (item.Key as Part).VendorCost; } // For each work order, get the total parts amount on // its corresponding charge slip. foreach (DictionaryEntry item in woList) { ChargeSlip cs = item.Value as ChargeSlip; double csPartCost = 0; for (int i = 0; i < cs.PartCount; i++) { csPartCost += cs.Parts[i].VendorCost; } // The charge amount added to the charge slip = // csPartCost * chargeAmt / totalPartCost for (int i = 0; i < charges.Count; i++) { Charge charge = new Charge(); charge.Amount = csPartCost * charges[i].Amount / totalPartCost; charge.Description = charges[i].Description; cs.Add(charge); } } }