예제 #1
0
        public ClassTypeViewModel GetClassTypeAjax(int id)
        {
            var classType = GetClassType(id);

            return(new ClassTypeViewModel()
            {
                ClassTypeName = classType.Name,
                Tax = classType.Tax,
                RatePPH = configurationService.GetValue <decimal>("RatePPH"),
                RatePPN = configurationService.GetValue <decimal>("RatePPN")
            });
        }
        public string AddOrUpdateConfirmationLetter(int id,
                                                    DateTime date,
                                                    int accountManagerID,
                                                    string customerCode,
                                                    List <DateTime> trainingDates,
                                                    string trainingLocation,
                                                    string description,
                                                    int classTypeID,
                                                    int topicID,
                                                    decimal price,
                                                    decimal tax,
                                                    decimal pph,
                                                    decimal discount,
                                                    int bankID,
                                                    DateTime paymentDueDate,
                                                    string refLetterNo,
                                                    int totalParticipants,
                                                    int[] moduleIDs)
        {
            decimal ratePPH   = configurationService.GetValue <decimal>("RatePPH") / 100M;
            decimal ratePPN   = configurationService.GetValue <decimal>("RatePPN") / 100M;
            var     employee  = repository.FindOne <Employee>(emp => emp.ID == accountManagerID);
            var     cl        = id != 0 ? repository.Single <ConfirmationLetter>(letter => letter.ID == id) : new ConfirmationLetter();
            var     classType = repository.Single <ClassType>(ct => ct.ID == classTypeID);
            var     customer  = repository.Single <Customer>(cust => cust.Code == customerCode);
            var     refLetter = String.IsNullOrEmpty(refLetterNo)
                ? null
                : repository.Single <ConfirmationLetter>(letter => letter.LetterNo == refLetterNo);

            if (id == 0)
            {
                cl.LetterNo = runningNumberProvider.GenerateConfirmationLetterNo(employee.ID, date);
            }
            cl.Date             = date;
            cl.AccountManagerID = accountManagerID;
            cl.CustomerID       = customer.ID;
            cl.TrainingLocation = trainingLocation;
            cl.Description      = description;
            cl.ClassTypeID      = classTypeID;
            cl.TopicID          = topicID;
            cl.Price            = price;
            cl.Tax               = classType.Tax ? ratePPN * (price - discount) : 0;
            cl.PPH               = classType.Tax ? ratePPH * (price - discount) : 0;
            cl.Discount          = discount;
            cl.TotalPrice        = cl.Price - cl.Discount + cl.Tax - cl.PPH;
            cl.TransferToBankID  = bankID;
            cl.PaymentDueDate    = paymentDueDate;
            cl.TotalParticipants = totalParticipants;
            if (refLetter != null)
            {
                cl.RefLetterID = refLetter.ID;
            }
            repository.SetAuditFields(id, cl, principal.Identity.Name);

            cl.Modules.Clear();
            foreach (var moduleID in moduleIDs)
            {
                var module = repository.FindOne <Module>(mod => mod.ID == moduleID);
                if (module != null)
                {
                    cl.Modules.Add(module);
                }
            }

            if (customer.CustomerType == "I")
            {
                if (cl.Customers != null)
                {
                    cl.Customers.Clear();
                }

                cl.Customers.Add(customer);
            }

            repository.Delete <ConfirmationLetterSchedule>(schedule => schedule.ConfirmationLetterID == cl.ID);
            foreach (var trainingDate in trainingDates)
            {
                var schedule = new ConfirmationLetterSchedule();
                schedule.ConfirmationLetter = cl;
                schedule.Date = trainingDate;
                cl.ConfirmationLetterSchedules.Add(schedule);
            }

            if (id == 0)
            {
                repository.Add(cl);
            }
            else
            {
                repository.Update(cl);
            }



            repository.UnitOfWork.SaveChanges();

            return(cl.LetterNo);
        }