private void Calculate(double total, double cost, PaymentMethods paymentMethod, JobPricing jobPricing) { //gross calc if (paymentMethod == PaymentMethods.Cash) { _gross = total; } else if (paymentMethod == PaymentMethods.Check) { _gross = total - (total * Globals.checkFee); } else { _gross = total - (total * Globals.creditCardFee); } //techCut calc if (jobPricing == JobPricing.Day) { _techCut = (_gross - cost) * 0.2; } else if (jobPricing == JobPricing.Night) { _techCut = (_gross - cost) * 0.35; } else { _techCut = (_gross - cost) * 0.5; } _grossMinusCost = _gross - cost; _techPayout = cost + _techCut; _company = _grossMinusCost * 0.5; _businessNet = _gross - _techPayout - _company; _sumCash = _company + _businessNet; }
private Dictionary <Type, List <EntityInfo> > BeforeSaveEntities(Dictionary <Type, List <EntityInfo> > saveMap) { #region JobPricing List <EntityInfo> entityInfos = saveMap.Where(e => e.Key == typeof(JobPricing)).Select(e => e.Value).FirstOrDefault(); if (entityInfos != null) { foreach (EntityInfo entityInfo in entityInfos) { JobPricing jobPricing = (JobPricing)(entityInfo.Entity); // single query without lazy loading var temp = (from p in Session.Query <JobTranslation>() where p.Id == jobPricing.JobId select new { JobTranslation = p, p.SourceMaterial.Request }).FirstOrDefault(); if (temp != null) { if (!CheckForObjectTypeInSaveMap(temp.JobTranslation, saveMap)) { temp.JobTranslation.UpdateDate = DateTime.UtcNow; saveMap.AddCustomEntity(temp.JobTranslation, this); } if (!saveMap.Any(e => e.Key == typeof(Request))) { temp.Request.UpdateDate = DateTime.UtcNow; saveMap.AddCustomEntity(temp.Request, this); } } } } #endregion #region JobMaterial entityInfos = saveMap.Where(e => e.Key == typeof(JobMaterial)).Select(e => e.Value).FirstOrDefault(); if (entityInfos != null) { foreach (EntityInfo entityInfo in entityInfos) { JobMaterial jobMaterial = (JobMaterial)(entityInfo.Entity); if (!saveMap.Any(e => e.Key.IsSubclassOf(typeof(Job)) && e.Value.Any(f => ((Job)f.Entity).Id == jobMaterial.JobId))) { // single query without lazy loading var temp = (from p in Session.Query <Job>() where p.Id == jobMaterial.JobId select new { Job = p, Request = p.SourceMaterial.Request }).FirstOrDefault(); if (temp != null) { temp.Job.UpdateDate = DateTime.UtcNow; saveMap.AddCustomEntity(temp.Job, this); if (!saveMap.Any(e => e.Key == typeof(Request))) { temp.Request.UpdateDate = DateTime.UtcNow; saveMap.AddCustomEntity(temp.Request, this); } } } } } #endregion #region Reference entityInfos = saveMap.Where(e => e.Key == typeof(Reference)).Select(e => e.Value).FirstOrDefault(); if (entityInfos != null) { foreach (EntityInfo entityInfo in entityInfos) { Reference reference = (Reference)(entityInfo.Entity); Request request = saveMap.Where(e => e.Key == typeof(Request)).SelectMany(e => e.Value).Select(c => (Request)c.Entity).FirstOrDefault(); if (request != null) { request.UpdateDate = DateTime.UtcNow; } else { // single query without lazy loading request = (from p in Session.Query <Request>() where p.ReferenceSet.Id == reference.ReferenceSetId select p).FirstOrDefault(); if (request != null) { request.UpdateDate = DateTime.UtcNow; saveMap.AddCustomEntity(request, this); } } } } #endregion #region JobComment entityInfos = saveMap.Where(e => e.Key == typeof(JobComment)).Select(e => e.Value).FirstOrDefault(); if (entityInfos != null) { foreach (EntityInfo entityInfo in entityInfos) { JobComment jobComment = (JobComment)(entityInfo.Entity); // single query without lazy loading var temp = (from p in Session.Query <Job>() where p.Id == jobComment.JobId select new { Job = p, Request = p.SourceMaterial.Request }).First(); temp.Job.UpdateDate = DateTime.UtcNow; saveMap.AddCustomEntity(temp.Job, this); if (!saveMap.Any(e => e.Key == typeof(Request))) { temp.Request.UpdateDate = DateTime.UtcNow; saveMap.AddCustomEntity(temp.Request, this); } } } #endregion #region Job entityInfos = saveMap.Where(e => e.Key.IsSubclassOf(typeof(Job))).Select(e => e.Value).FirstOrDefault(); if (entityInfos != null) { foreach (EntityInfo entityInfo in entityInfos) { if (!saveMap.Any(e => e.Key == typeof(Request))) { Request request = GetQuery <SourceMaterial>().Where(e => e.Id == ((Job)entityInfo.Entity).SourceMaterialId).Select(e => e.Request).FirstOrDefault(); if (request == null) { Guid?requestId = saveMap.Where(e => e.Key == typeof(SourceMaterial)) .SelectMany(e => e.Value) .Select(x => (SourceMaterial)x.Entity) .Where(x => x.Id == ((Job)entityInfo.Entity).SourceMaterialId) .Select(x => x.RequestId) .SingleOrDefault(); if (requestId.HasValue) { request = GetQuery <Request>().FirstOrDefault(e => e.Id == requestId); } } saveMap.AddCustomEntity(request, this); } } } #endregion #region Material entityInfos = saveMap.Where(e => e.Key == typeof(Material) || e.Key.IsSubclassOf(typeof(Material))).Select(e => e.Value).FirstOrDefault(); if (entityInfos != null) { // Update 'UploadedBy' field only for new entities foreach (EntityInfo entityInfo in entityInfos.Where(e => e.EntityState == EntityState.Added)) { Material material = (Material)entityInfo.Entity; if (string.IsNullOrEmpty(material.UploadedBy)) { material.UploadedBy = material.CreatedBy; } if (!material.UploaderType.HasValue) { material.UploaderType = UploaderType.Other; } } } #endregion var tmp = saveMap.Where(p => p.Key.IsSubclassOf(typeof(Job))) .Select(p => p.Value.Where(x => x.EntityState == EntityState.Deleted).ToList()) .FirstOrDefault(); var jobs = tmp == null ? null : tmp.Select(x => (Job)x.Entity).ToList(); var requestToChange = saveMap .Where(p => p.Key.IsAssignableFrom(typeof(Request))) .Select(p => p.Value) .FirstOrDefault(); var smToChange = saveMap .Where(p => p.Key.IsAssignableFrom(typeof(SourceMaterial))) .Select(p => p.Value.Where(x => x.EntityState == EntityState.Added).ToList()) .FirstOrDefault(); if (requestToChange != null) { var rq = ((Request)requestToChange.First().Entity); List <SourceMaterial> sms = new List <SourceMaterial>(); sms = Session.Query <SourceMaterial>().Where(x => x.RequestId == rq.Id).Where(x => !x.Jobs.Any()).Distinct().ToList(); if (jobs != null) { foreach (var job in jobs) { sms.AddRange(Session.Query <SourceMaterial>().Where(x => x.RequestId == rq.Id).Where(v => v.Jobs.Contains(job)).Distinct().ToList()); } } if (rq.RequestTemplateId != null) { foreach (var sm in sms) { if (!CheckForObjectTypeInSaveMap(sm, saveMap)) { sm.UpdateDate = DateTime.UtcNow; saveMap.AddCustomEntity <SourceMaterial>(sm, this); } } } } Session.Clear(); return(saveMap); }
public NewJobCalculator(double total, double cost, PaymentMethods paymentMethod, JobPricing jobPricing) { Calculate(total, cost, paymentMethod, jobPricing); }