Пример #1
0
        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;
                }
            }
        }
Пример #2
0
        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();
        }