public int AddContractHistory(ContractHistory history)
 {
     history.ActionDate = DateTime.UtcNow.ToString("dd/MM/yyyy",
                                                   CultureInfo.InvariantCulture);
     _context.ContractHistories.Add(history);
     _context.SaveChanges();
     return(history.Id);
 }
Beispiel #2
0
        public bool CloseContract(int Id, Contract contract)
        {
            Contract existcontract = GetContractById(Id);

            if (existcontract == null)
            {
                return(false);
            }
            existcontract.ContractStatusId = contract.ContractStatusId;
            _context.Update(existcontract);
            _context.SaveChanges();



            // Adding To Contract History
            ContractHistory history = new ContractHistory
            {
                ContractId       = existcontract.Id,
                CustomerId       = existcontract.CustomerId,
                ForeignAgencyId  = existcontract.ForeignAgencyId,
                EmployeeId       = contract.EmployeeId,
                ActionId         = (int)EnumHelper.ContractAction.Close,
                ContractStatusId = contract.ContractStatusId,
                ActionById       = contract.CreatedById
            };

            history.ActionByName = _context.Users.Where(x => x.Id.Contains(history.ActionById)).SingleOrDefault().UserName;
            var emp = _context.Employees.SingleOrDefault(x => x.Id == history.EmployeeId);

            if (emp != null)
            {
                history.EmployeeName = emp.FirstName + ' ' + emp.Father;
            }
            var cust = _context.Customers.SingleOrDefault(x => x.Id == history.CustomerId);

            if (cust != null)
            {
                history.CustomerName = cust.Name;
            }
            var foreignAgencies = _context.ForeignAgencies.SingleOrDefault(x => x.Id == history.ForeignAgencyId);

            if (foreignAgencies != null)
            {
                history.ForeignAgencyName = foreignAgencies.OfficeName;
            }
            //var Action = _context.ContractAction.SingleOrDefault(x => x.Id == history.ActionId);
            //if (Action != null) { history.ActionName = Action.Name; }


            history.ActionDate = DateTime.UtcNow.ToString("dd/MM/yyyy",
                                                          CultureInfo.InvariantCulture);

            _context.ContractHistories.Add(history);
            _context.SaveChanges();


            return(true);
        }
Beispiel #3
0
        public int AddContractTicket(ContractTicket contractTicket)
        {
            var cont = _context.Contracts.Find(contractTicket.ContractId);

            contractTicket.EmployeeId = cont.EmployeeId;
            _context.ContractTickets.Add(contractTicket);
            _context.SaveChanges();

            // Contract Info

            if (cont != null)
            {
                cont.ContractStatusId = (int)EnumHelper.ContractStatus.Ticket;
                _context.Update(cont);
                _context.SaveChanges();
            }



            // Adding To Contract History
            ContractHistory history = new ContractHistory();

            history.ContractId       = contractTicket.ContractId;
            history.CustomerId       = cont.CustomerId;
            history.ForeignAgencyId  = cont.ForeignAgencyId;
            history.EmployeeId       = cont.EmployeeId;
            history.ActionId         = (int)EnumHelper.ContractAction.Ticket;
            history.ContractStatusId = cont.ContractStatusId;
            var ticket = contractTicket.TicketById;

            history.ActionById   = contractTicket.TicketById;
            history.ActionByName = _context.Users.Where(x => x.Id.Contains(history.ActionById)).SingleOrDefault().UserName;
            var foreignAgencies = _context.ForeignAgencies.SingleOrDefault(x => x.Id == history.ForeignAgencyId);

            if (foreignAgencies != null)
            {
                history.ForeignAgencyName = foreignAgencies.OfficeName;
            }
            var cust = _context.Customers.SingleOrDefault(x => x.Id == history.CustomerId);

            if (cust != null)
            {
                history.CustomerName = cust.Name;
            }
            var emp = _context.Employees.SingleOrDefault(x => x.Id == history.EmployeeId);

            if (emp != null)
            {
                history.EmployeeName = emp.FirstName + ' ' + emp.Father;
            }
            history.ActionDate = DateTime.UtcNow.ToString("dd/MM/yyyy",
                                                          CultureInfo.InvariantCulture);
            _context.ContractHistories.Add(history);
            _context.SaveChanges();

            return(contractTicket.Id);
        }
Beispiel #4
0
        public int AddContract(Contract contract)
        {
            contract.Remainder     = contract.ContractCost;
            contract.Paid          = 0;
            contract.TestDay       = 0;
            contract.OldContractNo = 0;
            var getCurrentFinancialPeriod = _context.FinancialPeriods.Where(x => x.FinancialPeriodStatusId == (int)EnumHelper.FinancPeriodStatus.CURRENT).SingleOrDefault();

            if (getCurrentFinancialPeriod != null)
            {
                contract.FinancialPeriodId = getCurrentFinancialPeriod.Id;
            }

            _context.Contracts.Add(contract);
            _context.SaveChanges();

            // Add Invoice
            Invoice contractInvoice = new Invoice {
                ContractNo    = contract.Id,
                InvoiceDate   = DateTime.UtcNow.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                Amount        = contract.ContractCost - contract.VatCost,
                VatValue      = contract.VatCost,
                Discount      = 0,
                Note          = contract.ContractNote,
                VatPercentage = (contract.VatCost / contract.ContractCost) * 100,
                Total         = contract.ContractCost
            };
            var customerInvoice = _context.Customers.Where(x => x.Id == contract.CustomerId).SingleOrDefault();

            if (customerInvoice != null)
            {
                contractInvoice.Customer = customerInvoice.Name;
            }
            _context.Invoices.Add(contractInvoice);
            _context.SaveChanges();

            // Adding To Contract History
            ContractHistory history = new ContractHistory
            {
                ContractId       = contract.Id,
                CustomerId       = contract.CustomerId,
                ForeignAgencyId  = contract.ForeignAgencyId,
                EmployeeId       = contract.EmployeeId,
                ActionId         = (int)EnumHelper.ContractAction.New,
                ContractStatusId = contract.ContractStatusId,
                ActionById       = contract.CreatedById
            };

            history.ActionByName = _context.Users.Where(x => x.Id.Contains(history.ActionById)).SingleOrDefault().UserName;
            //var emp = _context.Employees.SingleOrDefault(x => x.Id == history.EmployeeId);
            //if (emp != null) { history.EmployeeName = emp.FirstName + ' ' + employee.Father; }
            var cust = _context.Customers.SingleOrDefault(x => x.Id == history.CustomerId);

            if (cust != null)
            {
                history.CustomerName = cust.Name;
            }
            //var foreignAgencies = _context.ForeignAgencies.SingleOrDefault(x => x.Id == history.ForeignAgencyId);
            //if (foreignAgencies != null) { history.ForeignAgencyName = foreignAgencies.OfficeName; }
            //var Action = _context.ContractAction.SingleOrDefault(x => x.Id == history.ActionId);
            //if (Action != null) { history.ActionName = Action.Name; }
            //var contract_s = _context.ContractStatuses.SingleOrDefault(x => x.Id == history.ContractStatusId);
            //if (contractStatus != null) { history.ContractStatusName = contract_s.Name; }

            history.ActionDate = DateTime.UtcNow.ToString("dd/MM/yyyy",
                                                          CultureInfo.InvariantCulture);
            _context.ContractHistories.Add(history);
            _context.SaveChanges();

            return(contract.Id);
        }
Beispiel #5
0
        public bool UpdateContractVisa(int Id, ContractVisa contractVisa)
        {
            ContractVisa existContractVisa = GetContractVisaById(Id);

            if (existContractVisa == null)
            {
                return(false);
            }
            existContractVisa.ContractId = contractVisa.ContractId;
            existContractVisa.EmployeeId = contractVisa.EmployeeId;
            existContractVisa.VisaById   = contractVisa.VisaById;
            //existContractVisa.VisaByName = contractVisa.VisaByName;
            existContractVisa.VisaDate = contractVisa.VisaDate;


            //var employee = _context.Employees.SingleOrDefault(x => x.Id == contractVisa.EmployeeId);
            //if (employee != null) { existContractVisa.EmployeeName = employee.FirstName + ' ' + employee.Father; }

            _context.Update(existContractVisa);
            _context.SaveChanges();


            // Contract Info
            var cont = _context.Contracts.Find(contractVisa.ContractId);

            if (cont != null)
            {
                cont.ContractStatusId = (int)EnumHelper.ContractStatus.Visa;
                //cont.ContractStatusName = _context.ContractStatuses.Find(cont.ContractStatusId).Name;
                if (contractVisa.EmployeeId != null)
                {
                    cont.EmployeeId = contractVisa.EmployeeId;
                    //cont.EmployeeName = contractVisa.EmployeeName;
                }
                _context.Update(cont);
                _context.SaveChanges();
            }



            // Adding To Contract History
            ContractHistory history = new ContractHistory();

            history.ContractId       = contractVisa.ContractId;
            history.CustomerId       = cont.CustomerId;
            history.ForeignAgencyId  = cont.ForeignAgencyId;
            history.EmployeeId       = cont.EmployeeId;
            history.ActionId         = (int)EnumHelper.ContractAction.Visa;
            history.ContractStatusId = cont.ContractStatusId;
            //history.ActionByName = contractVisa.VisaByName;
            history.ActionById   = contractVisa.VisaById;
            history.ActionByName = _context.Users.Where(x => x.Id.Contains(history.ActionById)).SingleOrDefault().UserName;
            var foreignAgencies = _context.ForeignAgencies.SingleOrDefault(x => x.Id == history.ForeignAgencyId);

            if (foreignAgencies != null)
            {
                history.ForeignAgencyName = foreignAgencies.OfficeName;
            }
            var cust = _context.Customers.SingleOrDefault(x => x.Id == history.CustomerId);

            if (cust != null)
            {
                history.CustomerName = cust.Name;
            }
            var emp = _context.Employees.SingleOrDefault(x => x.Id == history.EmployeeId);

            if (emp != null)
            {
                history.EmployeeName = emp.FirstName + ' ' + emp.Father;
            }
            history.ActionDate = DateTime.UtcNow.ToString("dd/MM/yyyy",
                                                          CultureInfo.InvariantCulture);

            _context.ContractHistories.Add(history);
            _context.SaveChanges();

            return(true);
        }
        public int AddContractSelect(ContractSelect contractSelect)
        {
            _context.ContractSelects.Add(contractSelect);
            _context.SaveChanges();

            // Contract Info
            var cont = _context.Contracts.Find(contractSelect.ContractId);

            // Get JoB Salary
            var agency = _context.ForeignAgencyJobs.Where(x => x.ForeignAgencyId == contractSelect.ForeignAgencyId &&
                                                          x.IsActive == true && x.JobTypeId == cont.JobTypeId).SingleOrDefault();


            if (cont != null)
            {
                cont.ContractStatusId = (int)EnumHelper.ContractStatus.Select;
                //cont.ContractStatusName = _context.ContractStatuses.Find(cont.ContractStatusId).Name;
                if (contractSelect.ForeignAgencyId != null)
                {
                    cont.ForeignAgencyId = contractSelect.ForeignAgencyId;
                }
                _context.Update(cont);
                _context.SaveChanges();
            }



            // Adding To Contract History
            ContractHistory history = new ContractHistory();

            history.ContractId       = contractSelect.ContractId;
            history.CustomerId       = cont.CustomerId;
            history.ForeignAgencyId  = cont.ForeignAgencyId;
            history.EmployeeId       = cont.EmployeeId;
            history.ActionId         = (int)EnumHelper.ContractAction.Select;
            history.ContractStatusId = cont.ContractStatusId;
            //history.ActionByName = contractSelect.SelectByName;
            history.ActionById   = contractSelect.SelectById;
            history.ActionByName = _context.Users.Where(x => x.Id.Contains(history.ActionById)).SingleOrDefault().UserName;
            var foreignAgencies = _context.ForeignAgencies.SingleOrDefault(x => x.Id == history.ForeignAgencyId);

            if (foreignAgencies != null)
            {
                history.ForeignAgencyName = foreignAgencies.OfficeName;
            }
            var cust = _context.Customers.SingleOrDefault(x => x.Id == history.CustomerId);

            if (cust != null)
            {
                history.CustomerName = cust.Name;
            }

            history.ActionDate = DateTime.UtcNow.ToString("dd/MM/yyyy",
                                                          CultureInfo.InvariantCulture);

            _context.ContractHistories.Add(history);
            _context.SaveChanges();



            return(contractSelect.Id);
        }
        public bool UpdateContractSelect(int Id, ContractSelect contractSelect)
        {
            ContractSelect existcontractSelect = GetContractSelectById(Id);

            if (existcontractSelect == null)
            {
                return(false);
            }
            existcontractSelect.ContractId      = contractSelect.ContractId;
            existcontractSelect.ForeignAgencyId = contractSelect.ForeignAgencyId;
            existcontractSelect.PolNumer        = contractSelect.PolNumer;
            existcontractSelect.PolNumerDate    = contractSelect.PolNumerDate;
            existcontractSelect.SelectById      = contractSelect.SelectById;;
            //existcontractSelect.SelectByName = contractSelect.SelectByName;
            existcontractSelect.SelectDate = contractSelect.SelectDate;



            _context.Update(existcontractSelect);
            _context.SaveChanges();


            // Contract Info
            var cont = _context.Contracts.Find(contractSelect.ContractId);

            if (cont != null)
            {
                cont.ContractStatusId = (int)EnumHelper.ContractStatus.Select;
                if (contractSelect.ForeignAgencyId != null)
                {
                    cont.ForeignAgencyId = contractSelect.ForeignAgencyId;
                }
                _context.Update(cont);
                _context.SaveChanges();
            }



            // Adding To Contract History
            ContractHistory history = new ContractHistory();

            history.ContractId       = contractSelect.ContractId;
            history.CustomerId       = cont.CustomerId;
            history.ForeignAgencyId  = cont.ForeignAgencyId;
            history.EmployeeId       = cont.EmployeeId;
            history.ActionId         = (int)EnumHelper.ContractAction.Select;
            history.ContractStatusId = cont.ContractStatusId;
            var select = contractSelect.SelectById;

            history.ActionById   = contractSelect.SelectById;
            history.ActionByName = _context.Users.Where(x => x.Id.Contains(history.ActionById)).SingleOrDefault().UserName;
            var foreignAgencies = _context.ForeignAgencies.SingleOrDefault(x => x.Id == history.ForeignAgencyId);

            if (foreignAgencies != null)
            {
                history.ForeignAgencyName = foreignAgencies.OfficeName;
            }
            var cust = _context.Customers.SingleOrDefault(x => x.Id == history.CustomerId);

            if (cust != null)
            {
                history.CustomerName = cust.Name;
            }
            history.ActionDate = DateTime.UtcNow.ToString("dd/MM/yyyy",
                                                          CultureInfo.InvariantCulture);

            _context.ContractHistories.Add(history);
            _context.SaveChanges();


            return(true);
        }
        public int AddContractDelegation(ContractDelegation contractDelegation)
        {
            // Contract Info
            var cont = _context.Contracts.Find(contractDelegation.ContractId);
            // Get JoB Salary
            var agency = _context.ForeignAgencyJobs.Where(x => x.ForeignAgencyId == contractDelegation.ForeignAgencyId &&
                                                          x.IsActive == true && x.JobTypeId == cont.JobTypeId).SingleOrDefault();

            if (agency != null)
            {
                _context.ContractDelegations.Add(contractDelegation);
                _context.SaveChanges();
            }


            if (cont != null && agency != null)
            {
                cont.ContractStatusId = (int)EnumHelper.ContractStatus.Delegate;
                if (contractDelegation.ForeignAgencyId != null)
                {
                    cont.ForeignAgencyId = contractDelegation.ForeignAgencyId;
                }
                //if (agency != null)
                //{
                //    cont.ContractCost = (decimal)agency.Price;
                //    cont.VatCost = (cont.ContractCost) * (5 / 100);
                //    cont.Remainder = cont.ContractCost;
                //}
                _context.Update(cont);
                _context.SaveChanges();
            }

            // Update ForgienAgency
            if (agency != null)
            {
                var forgeignAgency = _context.ForeignAgencies.SingleOrDefault(x => x.Id == contractDelegation.ForeignAgencyId);
                if (forgeignAgency != null)
                {
                    forgeignAgency.DeservedAmount  = (decimal)agency.Price;
                    forgeignAgency.RemainderAmount = forgeignAgency.DeservedAmount;
                    _context.Update(forgeignAgency);
                    _context.SaveChanges();
                }



                // Adding To Contract History
                ContractHistory history = new ContractHistory();
                history.ContractId       = (int)contractDelegation.ContractId;
                history.CustomerId       = cont.CustomerId;
                history.ForeignAgencyId  = cont.ForeignAgencyId;
                history.EmployeeId       = cont.EmployeeId;
                history.ActionId         = (int)EnumHelper.ContractAction.Delegate;
                history.ContractStatusId = cont.ContractStatusId;
                history.ActionById       = contractDelegation.DelegateById;
                history.ActionByName     = _context.Users.Where(x => x.Id.Contains(history.ActionById)).SingleOrDefault().UserName;
                var foreignAgencies = _context.ForeignAgencies.SingleOrDefault(x => x.Id == history.ForeignAgencyId);
                if (foreignAgencies != null)
                {
                    history.ForeignAgencyName = foreignAgencies.OfficeName;
                }
                var cust = _context.Customers.SingleOrDefault(x => x.Id == history.CustomerId);
                if (cust != null)
                {
                    history.CustomerName = cust.Name;
                }
                history.ActionDate = DateTime.UtcNow.ToString("dd/MM/yyyy",
                                                              CultureInfo.InvariantCulture);

                _context.ContractHistories.Add(history);
                _context.SaveChanges();
            }
            return(contractDelegation.Id);
        }
 public bool UpdateContractHistory(int Id, ContractHistory contractHistory)
 {
     throw new NotImplementedException();
 }