예제 #1
0
 /// <summary>
 /// Save contract details
 /// </summary>
 /// <param name="contract">The contract value object</param>
 public void SaveContract(ContractVO contract)
 {
     if (contract != null)
     {
         contractDAL.SaveContract(contract);
     }
 }
        public ActionResult ContractSave(MODEL.Contract contract)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //Valiate the currency
                    ValidateCurrency(contract);

                    //to check whether EarlyTerminationDate is entered when AtRisk is Yes
                    if ((contract.AtRisk == 0) || ((contract.AtRisk == 1) && (contract.EarlyTerminationDate != null)))
                    {
                        //Get user id
                        int?            userId          = Session.GetUserId();
                        ContractService contractService = new ContractService();
                        //ContractVO contractVO = new ContractVO(contract, userId);

                        ContractVO contractVO = contract.Transpose(userId);

                        contractService.SaveContract(contractVO);

                        //Get customer comment for the selected customer and company
                        contract.CustomerComment = GetCustomerComment(contractVO.CompanyId, contractVO.InvoiceCustomerId);
                        //Set the flag to identify if to reload the page.
                        //If true means creating  new contract and reload the page.
                        //Else only update the contract header related details and remain on same page.
                        bool isNewRecord = contract.ID <= 0 ? true : false;
                        //return Json(new List<object>() { contractVO.CompanyId, contractVO.ID, isNewRecord });
                        return(Json(new List <object>()
                        {
                            contractVO.CompanyId, contractVO.ID, isNewRecord, contractVO.InvoiceCustomerId, contract.CustomerComment
                        }));
                    }
                    else
                    {
                        return(new HttpStatusCodeAndErrorResult(500, String.Format(Constants.CANNOT_SAVE, Constants.CONTRACT)));
                    }
                }
                else
                {
                    foreach (var item in ModelState)
                    {
                        if (item.Key == "EarlyTerminationDate" && item.Value.Errors.Count > 0)
                        {
                            return(new HttpStatusCodeAndErrorResult(500, String.Format("Early Termination Date should be in dd/MM/yyyy format")));
                        }
                    }
                    return(new HttpStatusCodeAndErrorResult(500, String.Format(Constants.CANNOT_SAVE, Constants.CONTRACT)));
                }
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeAndErrorResult(500, e.Message));
            }
        }
예제 #3
0
        /// <summary>
        /// Get contract details by Id
        /// </summary>
        /// <param name="contractId">contract Id</param>
        /// <returns>IndexId Details</returns>
        public ContractVO GetContractById(int contractId)
        {
            Contract   contract   = mdbDataContext.Contracts.SingleOrDefault(c => c.ID == contractId);
            ContractVO contractVO = null;

            if (contract != null)
            {
                contractVO = new ContractVO(contract);
            }
            return(contractVO);
        }
예제 #4
0
        /// <summary>
        /// Gets the list of Contracts
        /// </summary>
        /// <param name="companyId">company id</param>
        /// <param name="invoiceCustomerId">invoicecustomer id</param>
        /// <returns>List of contracts</returns>
        public List <ContractVO> GetContractList(int companyId, int?invoiceCustomerId)
        {
            List <Contract> contracts = null;

            if (invoiceCustomerId != -1)
            {
                contracts = mdbDataContext.Contracts.Where(c => c.CompanyID == companyId && c.InvoiceCustomerID == invoiceCustomerId && c.IsDeleted == false).ToList();
            }
            else
            {
                contracts = mdbDataContext.Contracts.Where(c => c.CompanyID == companyId && c.IsDeleted == false).ToList();
            }

            List <ContractVO> contractVOList = new List <ContractVO>();

            List <EndUser> endUsers =
                mdbDataContext.EndUsers.Where(e => e.IsDeleted == false && e.BusinessPartner.CompanyID == companyId)
                .ToList();

            //Get all invoice customers associated with company
            List <OACustomer> invoiceCustomerList = mdbDataContext.OACustomers.Where(x => x.CompanyID == companyId).ToList();
            int        enduserId = 0;
            OACustomer customer  = null;

            foreach (var item in contracts)
            {
                ContractVO contractVO = new ContractVO(item);

                //If enduser is not invoice customer
                if (contractVO.EndUserId.StartsWith("E"))
                {
                    EndUser endUser = endUsers.FirstOrDefault(c => c.EndUserTextID == contractVO.EndUserId);
                    if (endUser != null)
                    {
                        contractVO.EndUserName = endUser.EndUserName;
                    }
                }
                else
                {
                    //If enduser is invoice customer
                    if (contractVO.EndUserId != contractVO.InvoiceCustomerId.ToString())
                    {
                        enduserId = Convert.ToInt32(contractVO.EndUserId);
                        customer  = invoiceCustomerList.FirstOrDefault(x => x.ID == enduserId);
                        contractVO.EndUserName = (customer != null) ? customer.CustomerName : contractVO.EndUserName;
                    }
                }

                contractVOList.Add(contractVO);
            }

            return(contractVOList);
        }
예제 #5
0
        /// <summary>
        /// Save contact details
        /// </summary>
        /// <param name="contractVO">Value Object Contract</param>
        public void SaveContract(ContractVO contractVO)
        {
            if (contractVO != null)
            {
                Contract contract = null;
                if (contractVO.ID <= 0)
                {
                    //Add new contract
                    contract = new Contract();

                    contract.ContractNumber       = contractVO.ContractNumber;
                    contract.CompanyID            = contractVO.CompanyId;
                    contract.DivisionID           = contractVO.DivisionId;
                    contract.CurrencyID           = contractVO.CurrencyId;
                    contract.EndUserID            = contractVO.EndUserId;
                    contract.InvoiceCustomerID    = contractVO.InvoiceCustomerId;
                    contract.POReferenceNo        = contractVO.POReferenceNumber;
                    contract.AtRisk               = contractVO.AtRisk;
                    contract.EarlyTerminationDate = contractVO.EarlyTerminationDate;
                    contract.CreationDate         = DateTime.Now;
                    contract.CreatedBy            = contractVO.CreatedByUserId;

                    mdbDataContext.Contracts.InsertOnSubmit(contract);
                    mdbDataContext.SubmitChanges();

                    //Set newly added contract id
                    if (contractVO.ID == 0)
                    {
                        contractVO.ID = contract.ID;
                    }
                }
                else
                {
                    //Update contract details
                    contract = mdbDataContext.Contracts.Where(c => c.ID == contractVO.ID && c.IsDeleted == false).SingleOrDefault();
                    contract.ContractNumber       = contractVO.ContractNumber;
                    contract.CompanyID            = contractVO.CompanyId;
                    contract.DivisionID           = contractVO.DivisionId;
                    contract.CurrencyID           = contractVO.CurrencyId;
                    contract.EndUserID            = contractVO.EndUserId;
                    contract.POReferenceNo        = contractVO.POReferenceNumber;
                    contract.AtRisk               = contractVO.AtRisk;
                    contract.EarlyTerminationDate = contractVO.EarlyTerminationDate;
                    contract.LastUpdatedDate      = DateTime.Now;
                    contract.LastUpdatedBy        = contractVO.LastUpdatedByUserId;
                    contract.InvoiceCustomerID    = contractVO.InvoiceCustomerId;

                    mdbDataContext.SubmitChanges();
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Save the copied contract
        /// </summary>
        /// <param name="contractId">contract Id</param>
        /// <param name="userId">login userId</param>
        public void SaveCopyContract(ContractVO contractVO, int?userId)
        {
            //ContractVO contractVO = GetContractById(contractId);
            Contract              copyContract       = new Contract();
            ContractLineDAL       contractlineDAL    = new ContractLineDAL();
            List <ContractLineVO> contractLineVOList = contractlineDAL.GetContractLineByContractId(contractVO.ID);

            if (contractVO != null)
            {
                string contractNumber = contractVO.ContractNumber;
                if (contractNumber.Length > 20)
                {
                    contractNumber = contractNumber.Substring(0, 20) + "-Copy";
                }
                else
                {
                    contractNumber = contractNumber + "-Copy";
                }

                copyContract.ContractNumber       = contractNumber;
                copyContract.CompanyID            = contractVO.CompanyId;
                copyContract.DivisionID           = contractVO.DivisionId;
                copyContract.CurrencyID           = contractVO.CurrencyId;
                copyContract.EndUserID            = contractVO.EndUserId;
                copyContract.InvoiceCustomerID    = contractVO.InvoiceCustomerId;
                copyContract.POReferenceNo        = contractVO.POReferenceNumber;
                copyContract.AtRisk               = contractVO.AtRisk;
                copyContract.EarlyTerminationDate = contractVO.EarlyTerminationDate;
                copyContract.CreationDate         = DateTime.Now;
                copyContract.CreatedBy            = userId;

                mdbDataContext.Contracts.InsertOnSubmit(copyContract);
                mdbDataContext.SubmitChanges();

                //If contractLine list is not empty
                if (contractLineVOList != null)
                {
                    //Set newly added contract id
                    int contractId = copyContract.ID;

                    contractlineDAL.SaveCopyContractLine(contractLineVOList, contractId, userId);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// to get contract maintenance billing lines based on contract id
        /// </summary>
        /// <param name="contractId"></param>
        /// <returns>List of contractVO</returns>
        public List <ContractVO> GetContractMaintenanceDetailsBasedOnContractId(int contractId)
        {
            ContractMaintenanceDAL contractMaintenanceDAL = new ContractMaintenanceDAL();
            ContractVO             contractVO             = new ContractVO();
            List <ContractVO>      contractVOList         = new List <ContractVO>();

            //to get all maintenance  billing lines based on contract id
            List <ContractMaintenanceVO> contractMaintenanceVOList = contractMaintenanceDAL.GetContractMaintenanceDetails(contractId);

            //to get all billing lines of a contract
            foreach (ContractMaintenanceVO contractMaintenanceVO in contractMaintenanceVOList)
            {
                //to get billing line tags of a particular billing line
                foreach (MaintenanceBillingLineVO maintenanceBillingLine in contractMaintenanceVO.MaintenanceBillingLineVos)
                {
                    contractVO.MaintenanceBillingLineVOList.Add(maintenanceBillingLine);
                }
                contractVO.ContractMaintenanceVOList.Add(contractMaintenanceVO);
            }
            contractVOList.Add(contractVO);

            return(contractVOList);
        }
예제 #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="contractVO"></param>
 public Contract(ContractVO contractVO, string visibleOrHidden = "visible") : this()
 {
     ID                                   = contractVO.ID;
     ContractNumber                       = contractVO.ContractNumber;
     CurrencyId                           = contractVO.CurrencyId;
     DivisionId                           = contractVO.DivisionId;
     EndUserId                            = contractVO.EndUserId;
     InvoiceCustomerId                    = contractVO.InvoiceCustomerId;
     CompanyId                            = contractVO.CompanyId;
     CompanyName                          = contractVO.CompanyName;
     EndUser                              = contractVO.EndUserName;
     InvoiceCustomer                      = contractVO.InvoiceCustomerName;
     CustomerNameAndShortName             = contractVO.InvoiceCustomerName + " - " + contractVO.ShortName;
     CustomerNameCustomerCodeAndShortName = contractVO.InvoiceCustomerName + " - " + contractVO.CustomerCode +
                                            " - " + contractVO.ShortName;
     DivisionName         = contractVO.DivisionName;
     Currency             = contractVO.Currency;
     AtRisk               = contractVO.AtRisk;
     EarlyTerminationDate = contractVO.EarlyTerminationDate;
     IsDeleted            = contractVO.IsDeleted;
     POReferenceNumber    = contractVO.POReferenceNumber;
     Visible              = visibleOrHidden;
 }
예제 #9
0
        /// <summary>
        /// Transpose model object to value object
        /// </summary>
        /// <param name="contract">The contract model</param>
        /// <param name="userId">The user id</param>
        public ContractVO Transpose(int?userId)
        {
            ContractVO contractVO = new ContractVO();

            contractVO.ID                   = this.ID;
            contractVO.ContractNumber       = this.ContractNumber;
            contractVO.CompanyId            = this.CompanyId;
            contractVO.EndUserId            = this.EndUserId;
            contractVO.InvoiceCustomerId    = this.InvoiceCustomerId;
            contractVO.DivisionId           = this.DivisionId;
            contractVO.CurrencyId           = this.CurrencyId;
            contractVO.Currency             = this.Currency;
            contractVO.CompanyName          = this.CompanyName;
            contractVO.DivisionName         = this.DivisionName;
            contractVO.InvoiceCustomerName  = this.InvoiceCustomer;
            contractVO.AtRisk               = this.AtRisk;
            contractVO.EarlyTerminationDate = this.EarlyTerminationDate;
            contractVO.IsDeleted            = this.IsDeleted;
            contractVO.POReferenceNumber    = this.POReferenceNumber;
            contractVO.CreatedByUserId      = userId;
            contractVO.LastUpdatedByUserId  = userId;

            return(contractVO);
        }
예제 #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="contractVO"></param>
 public Contract(ContractVO contractVO)
 {
     ID                                   = contractVO.ID;
     ContractNumber                       = contractVO.ContractNumber;
     CurrencyId                           = contractVO.CurrencyId;
     DivisionId                           = contractVO.DivisionId;
     EndUserId                            = contractVO.EndUserId;
     InvoiceCustomerId                    = contractVO.InvoiceCustomerId;
     CompanyId                            = contractVO.CompanyId;
     CompanyName                          = contractVO.CompanyName;
     EndUser                              = contractVO.EndUserName;
     InvoiceCustomer                      = contractVO.InvoiceCustomerName;
     CustomerNameAndShortName             = contractVO.InvoiceCustomerName + " - " + contractVO.ShortName;
     CustomerNameCustomerCodeAndShortName = contractVO.InvoiceCustomerName + " - " + contractVO.CustomerCode +
                                            " - " + contractVO.ShortName;
     AtRisk = contractVO.AtRisk;
     EarlyTerminationDate         = contractVO.EarlyTerminationDate;
     DivisionName                 = contractVO.DivisionName;
     Currency                     = contractVO.Currency;
     IsDeleted                    = contractVO.IsDeleted;
     POReferenceNumber            = contractVO.POReferenceNumber;
     ContractMaintenanceVOList    = contractVO.ContractMaintenanceVOList;
     MaintenanceBillingLineVOList = contractVO.MaintenanceBillingLineVOList;
 }
        public ActionResult SaveContractCopy(int contractId)
        {
            try
            {
                //Get user id
                int?            userId          = Session.GetUserId();
                ContractService contractService = new ContractService();

                ContractVO contractVO = new ContractVO();
                contractVO = contractService.GetContractById(contractId);
                MODEL.Contract contract = new MODEL.Contract(contractVO);
                contractVO = contract.Transpose(userId);

                contractService.SaveCopyContract(contractVO, userId);
                //Get customer comment for the selected customer and company
                //contract.CustomerComment = GetCustomerComment(contractVO.CompanyId, contractVO.InvoiceCustomerId);

                return(new HttpStatusCodeResult(200));
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeAndErrorResult(500, e.Message));
            }
        }
예제 #12
0
 /// <summary>
 /// Save the copied contract
 /// </summary>
 /// <param name="contractId">contract Id</param>
 /// <param name="userId">login userId</param>
 public void SaveCopyContract(ContractVO contractVO, int?userId)
 {
     contractDAL.SaveCopyContract(contractVO, userId);
 }
        /// <summary>
        /// Create or update contract details
        /// </summary>
        /// <param name="companyId">The company id</param>
        /// <param name="contractId">The contract Id to look for, (null if new contract creation)</param>
        /// <param name="showCodingDetailTab">The flag to identify if to display coding line tab or billing details tab</param>
        /// <returns>The contact details</returns>
        public ActionResult ContractDetails(int companyId, int?contractId, int?invoiceCustomerId, bool showCodingDetailTab = false)
        {
            MODEL.Contract contract = new MODEL.Contract();

            try
            {
                //If editing contract, then get contract details
                if (contractId.HasValue)
                {
                    ContractService contractService = new ContractService();

                    //Get contract details
                    ContractVO contractVO = contractService.GetContractById(contractId.Value);
                    if (contractVO == null)
                    {
                        ModelState.AddModelError("", String.Format(Constants.ITEM_NOT_FOUND, Constants.CONTRACT));
                    }
                    else
                    {
                        contract = new MODEL.Contract(contractVO, Session.AllowUserToEdit());
                    }
                }
                else
                {
                    //for creating new contract AtRisk= No
                    contract.AtRisk    = 0;
                    contract.CompanyId = companyId;
                }

                //Get logged in user associated companies
                contract.OAcompanyList = Session.GetUserAssociatedCompanyList();

                //If new contract line then set company name
                if (!contractId.HasValue)
                {
                    //Set company name
                    var company = contract.OAcompanyList.Find(x => x.ID == companyId);
                    if (company != null)
                    {
                        contract.CompanyName = company.Name;
                    }
                }

                //Get all active divisions associated with the company
                contract.DivisionList = GetDivisionListForContract(companyId);

                //Get all active currency list
                contract.CurrencyList = GetCurrencyList();

                //Get all end users associated with the company
                contract.EndUserList = GetEndUserList(companyId, contract.InvoiceCustomerId);

                //Get all invoice customers associated with the company
                contract.InvoiceCustomerList = GetInvoiceCustomerListForContract(companyId);
                //Get customer comment
                contract.CustomerComment = GetCustomerComment(companyId, contract.InvoiceCustomerId);

                //Set view bag having showCodingDetailTab flag
                ViewBag.showCodingDetailTab = showCodingDetailTab;
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }
            return(View(contract));
        }