private void btnCalculateOutstanding_Click(object sender, EventArgs e) { if (Validation.ValidateCombo(ref cmbClients)) { Client current = (Client)bind1.Current; List <Contract> contracts = new Contract().GetAllContracts(current.ClientIdentifier); if (contracts.Count > 0) { foreach (Contract item in contracts) { if (item.DateOfIssue.AddMonths(item.TermDuration) > DateTime.UtcNow) { ServiceLevel sl = new ServiceLevel().GetServiceLevels(item.SLevel.Level)[0]; List <ContractProducts> cp = new ContractProducts(item, new Product()).GetContractProducts(); List <ContractConfigurations> cc = new ContractConfigurations(item).GetContractConfigurations(); List <Billing> b = new Billing(current, DateTime.UtcNow, 0, 0).GetClientBilling(); int monthsLeft = DateDifference.GetMonthDifference(item.DateOfIssue, item.DateOfIssue.AddMonths(item.TermDuration)); if (monthsLeft > 0) { chcDiffPaid.Visible = true; int monthsPaid = DateDifference.GetMonthDifference(item.DateOfIssue, DateTime.UtcNow); double serviceFeePaid = monthsPaid * sl.MonthlyCost; double sumProductCost = (from cProd in cp select cProd.ContractProducts_Product.BasePrice).Sum(); double sumAddCosts = (from cConf in cc select cConf.ContractConfigurations_Configuration.AddCost).Sum(); double sumProductCostPaid = (from bProd in b select bProd.AmountPaid).Sum() - serviceFeePaid; outstandingAmount = (sumProductCost + sumAddCosts) - sumProductCostPaid; } else { chcDiffPaid.Visible = false; } txtOutstanding.Text = "R" + outstandingAmount.ToString(); txtOutstanding.Visible = true; lblOutstanding.Visible = true; btnCalculateOutstanding.Visible = false; break; } } } else { MessageBoxShower.ShowInfo("This client does not have any active contracts.", "Cannot Cancel contract"); txtOutstanding.Visible = false; lblOutstanding.Visible = false; chcDiffPaid.Visible = false; } } }
private void btnPrintContract_Click(object sender, EventArgs e) { Client client = (Client)clientBind.Current; List <Contract> contracts = new Contract().GetAllContracts(client.ClientIdentifier); foreach (Contract item in contracts) { List <Product> products = new List <Product>(); List <SystemComponents> comps = new List <SystemComponents>(); List <Configurations> confs = new List <Configurations>(); List <ContractProducts> cp = new ContractProducts(item, new Product()).GetContractProducts(); foreach (ContractProducts cproduct in cp) { products.Add(cproduct.ContractProducts_Product); } foreach (Product p in products) { List <SystemComponents> comp = new SystemComponents(p).GetSystemComponents(); foreach (SystemComponents c in comp) { comps.Add(c); } } List <ContractConfigurations> cc = new ContractConfigurations(item).GetContractConfigurations(); foreach (ContractConfigurations configuration in cc) { confs.Add(configuration.ContractConfigurations_Configuration); } PdfWriter.CreateClientContractPdf(client, item, products, comps, confs); } }
private void btnFinish_Click(object sender, EventArgs e) { if (contract.InsertContract() && SubmitAllProducts() && SubmitAllConfigs()) { MessageBoxShower.ShowInfo("The Contract has been recorded successfully.", "Success!"); Client current = client; double outstandingAmount = 0; List <Contract> contracts = new Contract().GetAllContracts(current.ClientIdentifier); if (contracts.Count > 0) { foreach (Contract item in contracts) { if (item.DateOfIssue.AddMonths(item.TermDuration) > DateTime.UtcNow) { ServiceLevel sl = new ServiceLevel().GetServiceLevels(item.SLevel.Level)[0]; List <ContractProducts> cp = new ContractProducts(item, new Product()).GetContractProducts(); List <ContractConfigurations> cc = new ContractConfigurations(item).GetContractConfigurations(); List <Billing> b = new Billing(current, DateTime.UtcNow, 0, 0).GetClientBilling(); int monthsLeft = DateDifference.GetMonthDifference(item.DateOfIssue, item.DateOfIssue.AddMonths(item.TermDuration)); if (monthsLeft > 0) { int monthsPaid = DateDifference.GetMonthDifference(item.DateOfIssue, DateTime.UtcNow); double serviceFeePaid = monthsPaid * sl.MonthlyCost; double sumProductCost = (from cProd in cp select cProd.ContractProducts_Product.BasePrice).Sum(); double sumAddCosts = (from cConf in cc select cConf.ContractConfigurations_Configuration.AddCost).Sum(); double sumProductCostPaid = (from bProd in b select bProd.AmountPaid).Sum() - serviceFeePaid; outstandingAmount = (sumProductCost + sumAddCosts) - sumProductCostPaid; } Billing bill = new Billing(client, DateTime.UtcNow, outstandingAmount, 0); bill.InsertBilling(); } } } } this.Close(); }