Ejemplo n.º 1
0
        public InvoiceModel CreateInvoice(NewInvoiceModel invoice, int locationId)
        {
            Data.Graph.Invoice inv = new Data.Graph.Invoice();

            var account = AccountRepository.GetAccount(invoice.AccountId);

            if (account == null)
            {
                account             = new Data.Graph.Account();
                account.Name        = invoice.AccountName;
                account.AccountType = AccountTypeRepository.GetAccountType(invoice.AccountTypeId);
                AccountRepository.SaveAccount(account);
            }

            inv.Account     = account;
            inv.Color       = invoice.Color;
            inv.Location    = new Data.Graph.Location(locationId);
            inv.Make        = invoice.Make;
            inv.Model       = invoice.Model;
            inv.ReceiveDate = DateTime.Now;
            inv.StockNumber = invoice.StockNumber;
            inv.Year        = invoice.Year;
            inv.TaxRate     = (decimal)account.AccountType.TaxRate;

            InvoiceRepository.SaveInvoice(inv);
            Logger.InfoFormat("Created new invoice {0} for {1} at location id {2}", inv.Id, inv.Account.Name, locationId);

            return(Mapper.Map <Data.Graph.Invoice, InvoiceModel>(inv));
        }
Ejemplo n.º 2
0
        public void AddLaborToAccountType(int accountTypeId, int accountTypeServiceId, int laborTypeId)
        {
            var accountType = AccountTypeRepository.GetAccountType(accountTypeId);

            if (accountType == null)
            {
                throw new ArgumentException("accountTypeId");
            }

            var service = accountType.ServiceTypeList.Where(s => s.Id == accountTypeServiceId).FirstOrDefault();

            if (service == null)
            {
                throw new ArgumentException("accountTypeServiceId");
            }

            var laborType = AccountTypeRepository.GetLaborType(laborTypeId);

            if (laborType == null)
            {
                throw new ArgumentException("laborTypeId");
            }

            var newLabor = new AccountTypeLabor();

            newLabor.DefaultRate     = 0;
            newLabor.DefaultRateType = "F";
            newLabor.LaborType       = laborType;
            service.AddLabor(newLabor);

            AccountTypeRepository.SaveAccountType(accountType);
        }
Ejemplo n.º 3
0
        public void RemoveLaborFromAccountType(int accountTypeId, int accountTypeServiceId, int accountTypeLaborId)
        {
            var accountType = AccountTypeRepository.GetAccountType(accountTypeId);

            if (accountType == null)
            {
                throw new ArgumentException("accountTypeId");
            }

            var service = accountType.ServiceTypeList.Where(s => s.Id == accountTypeServiceId).FirstOrDefault();

            if (service == null)
            {
                throw new ArgumentException("accountTypeServiceId");
            }

            var labor = service.LaborTypeList.Where(l => l.Id == accountTypeLaborId).FirstOrDefault();

            if (labor == null)
            {
                throw new ArgumentException("accountTypeLaborId");
            }

            service.LaborTypeList.Remove(labor);

            AccountTypeRepository.SaveAccountType(accountType);
        }
Ejemplo n.º 4
0
        public void AddServiceToAccountType(int accountTypeId, int serviceTypeId)
        {
            var accountType = AccountTypeRepository.GetAccountType(accountTypeId);

            if (accountType == null)
            {
                throw new ArgumentException("accountTypeId");
            }

            var serviceType = AccountTypeRepository.GetServiceType(serviceTypeId);

            if (serviceType == null)
            {
                throw new ArgumentException("serviceTypeId");
            }

            var newService = new Data.Graph.AccountTypeService();

            newService.ServiceType          = serviceType;
            newService.DefaultEstimatedTime = 0;
            newService.DefaultRate          = 0;
            newService.IsActive             = true;
            accountType.AddService(newService);

            AccountTypeRepository.SaveAccountType(accountType);
        }
Ejemplo n.º 5
0
        public AccountModel CreateAccount(AccountModel account)
        {
            var graph = new Data.Graph.Account();

            graph.AccountType  = AccountTypeRepository.GetAccountType(account.AccountTypeId);
            graph.AddressLine1 = account.AddressLine1;
            graph.AddressLine2 = account.AddressLine2;
            graph.City         = account.City;
            graph.Name         = account.Name;
            graph.Notes        = account.Notes;
            graph.PostalCode   = account.PostalCode;
            graph.StateCode    = account.StateCode;

            AccountRepository.SaveAccount(graph);

            return(Mapper.Map <Data.Graph.Account, AccountModel>(graph));
        }