private static List <PriceComponent> GetPriceComponents(this WorkEffort @this, Part part) { var priceComponents = new List <PriceComponent>(); var extent = new PriceComponents(@this.Strategy.Session).Extent(); foreach (PriceComponent priceComponent in extent) { if (priceComponent.ExistPart && priceComponent.Part.Equals(part) && priceComponent.FromDate <= @this.ActualStart && (!priceComponent.ExistThroughDate || priceComponent.ThroughDate >= @this.ActualStart)) { priceComponents.Add(priceComponent); } } // Discounts and surcharges can be specified without product or product feature, these need te be added to collection of pricecomponents extent = new PriceComponents(@this.Strategy.Session).Extent(); foreach (PriceComponent priceComponent in extent) { if (!priceComponent.ExistProduct && !priceComponent.ExistPart && !priceComponent.ExistProductFeature && priceComponent.FromDate <= @this.ActualStart && (!priceComponent.ExistThroughDate || priceComponent.ThroughDate >= @this.ActualStart)) { priceComponents.Add(priceComponent); } } return(priceComponents); }
public virtual ActionResult viewWorkEffort(int id) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { Authentication newAuth = new Authentication(); if (newAuth.isManager(this)) { ViewBag.managerFlag = true; } WorkEffort workeffort = WorkEffortDB.WorkEffortList.Find(id); if (workeffort == null) { return(HttpNotFound()); } ViewBag.pcaList = getWePcaCodesSelectList(workeffort); ViewBag.WorkEffortID = workeffort.ID; return(View(workeffort)); } else { return(View("notLoggedOn")); } }
[HttpPost, ActionName("deleteWorkEffort")] //This action MUST match the above delete function. public virtual ActionResult confirmedDeleteWorkEffort(int id) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { //make sure that there aren't any hours billed to the work effort if (checkWeForBilledHours(id) == true) { TempData["failedDelete"] = true; return(RedirectToAction("weManagement")); } else { WorkEffort workeffort = WorkEffortDB.WorkEffortList.Find(id); //change the active status to FALSE for all PCA_WE entries for the work effort deactivateAllPcaWeForWorkEffort(id); //delete the work effort WorkEffortDB.WorkEffortList.Remove(workeffort); WorkEffortDB.SaveChanges(); return(RedirectToAction("weManagement")); } } else { return(View("error")); } }
// /* Retrieves Work Effort object with specified ID, and changes "hidden" to TRUE * if the end date was at least one day ago. (note: Hidden Work Efforts don't * show up for employee's when they are adding a Work Effort to their timesheet, * but they do still show up in Manager/weManagement where they can be edited and * un-hidden) */ public virtual ActionResult hideWorkEffort(int id) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { WorkEffort we = WorkEffortDB.WorkEffortList.Find(id); if (we.endDate < DateTime.Today) { we.hidden = true; WorkEffortDB.Entry(we).State = System.Data.EntityState.Modified; WorkEffortDB.SaveChanges(); return(RedirectToAction("WeManagement")); } else { TempData["failedHide"] = true; return(RedirectToAction("WeManagement")); } } else { return(View("error")); } }
private static void DeriveActualHoursAndDates(this WorkEffort @this) { @this.ActualHours = 0M; foreach (ServiceEntry serviceEntry in @this.ServiceEntriesWhereWorkEffort) { if (serviceEntry is TimeEntry timeEntry) { @this.ActualHours += timeEntry.ActualHours; if ([email protected]) { @this.ActualStart = timeEntry.FromDate; } else if (timeEntry.FromDate < @this.ActualStart) { @this.ActualStart = timeEntry.FromDate; } if ([email protected]) { @this.ActualCompletion = timeEntry.ThroughDate; } else if (timeEntry.ThroughDate > @this.ActualCompletion) { @this.ActualCompletion = timeEntry.ThroughDate; } } } }
public static void AppsOnBuild(this WorkEffort @this, ObjectOnBuild method) { if ([email protected]) { @this.WorkEffortState = new WorkEffortStates(@this.Strategy.Session).Created; } }
public static void BaseOnPostDerive(this WorkEffort @this, ObjectOnPostDerive method) { if ([email protected]) { @this.AddDeniedPermission(new Permissions(@this.Strategy.Session).Get((Class)@this.Strategy.Class, MetaWorkEffort.Instance.Invoice, Operations.Execute)); } else { @this.RemoveDeniedPermission(new Permissions(@this.Strategy.Session).Get((Class)@this.Strategy.Class, MetaWorkEffort.Instance.Invoice, Operations.Execute)); } var completePermission = new Permissions(@this.Strategy.Session).Get((Class)@this.Strategy.Class, MetaWorkEffort.Instance.Complete, Operations.Execute); if (@this.ServiceEntriesWhereWorkEffort.Any(v => !v.ExistThroughDate)) { @this.AddDeniedPermission(new Permissions(@this.Strategy.Session).Get((Class)@this.Strategy.Class, MetaWorkEffort.Instance.Complete, Operations.Execute)); } else { if (@this.WorkEffortState.IsInProgress) { @this.RemoveDeniedPermission(new Permissions(@this.Strategy.Session).Get((Class)@this.Strategy.Class, MetaWorkEffort.Instance.Complete, Operations.Execute)); } } if (@this.WorkEffortState.IsFinished) { if (@this.ExecutedBy.Equals(@this.Customer)) { @this.RemoveDeniedPermission(new Permissions(@this.Strategy.Session).Get((Class)@this.Strategy.Class, MetaWorkEffort.Instance.Revise, Operations.Execute)); } } }
public static void BaseOnDerive(this WorkEffort @this, ObjectOnDerive method) { var derivation = method.Derivation; var internalOrganisations = new Organisations(@this.Strategy.Session).Extent().Where(v => Equals(v.IsInternalOrganisation, true)).ToArray(); if ([email protected] && internalOrganisations.Count() == 1) { @this.TakenBy = internalOrganisations.First(); } if ([email protected] && @this.ExistTakenBy) { @this.DerivedRoles.WorkEffortNumber = @this.TakenBy.NextWorkEffortNumber(); } if ([email protected] && @this.ExistTakenBy) { @this.ExecutedBy = @this.TakenBy; } @this.VerifyWorkEffortPartyAssignments(derivation); @this.DeriveActualHoursAndDates(); @this.DeriveCanInvoice(); if (@this.ExistActualStart && @this.WorkEffortState.IsCreated) { @this.WorkEffortState = new WorkEffortStates(@this.Strategy.Session).InProgress; } }
// /* Retrieves Work Effort object with specified ID and returns it's time * boundaries as a string (note: it's called from addHours View) */ public string getWeTimeBoundsString(int id) { WorkEffort we = WorkEffortDB.WorkEffortList.Find(id); string bounds = we.startDate + " - " + we.endDate; return(bounds); }
public virtual bool addHours(Hours newhours) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { WorkEffort tmpWe = WorkEffortDB.WorkEffortList.Find(newhours.workEffortID); //make sure that the new hours are within the work effort's time bounds if ((newhours.timestamp < tmpWe.startDate) || (newhours.timestamp > tmpWe.endDate)) { return(false); } //make sure that a timesheet exists for the period hours are being added to checkForTimesheet(newhours.creator, newhours.timestamp); //add and save new hours HoursDB.HoursList.Add(newhours); HoursDB.SaveChanges(); return(true); } else { return(false); } }
public static void BaseOnDerive(this WorkEffort @this, ObjectOnDerive method) { var derivation = method.Derivation; if ([email protected]) { @this.DerivationTrigger = Guid.NewGuid(); } var internalOrganisations = new Organisations(@this.Strategy.Session).Extent().Where(v => Equals(v.IsInternalOrganisation, true)).ToArray(); if ([email protected] && internalOrganisations.Count() == 1) { @this.TakenBy = internalOrganisations.First(); } if ([email protected] && @this.ExistTakenBy) { var year = @this.CreationDate.Value.Year; @this.DerivedRoles.WorkEffortNumber = @this.TakenBy.NextWorkEffortNumber(year); var fiscalYearInternalOrganisationSequenceNumbers = @this.TakenBy.FiscalYearsInternalOrganisationSequenceNumbers.FirstOrDefault(v => v.FiscalYear == year); var prefix = @this.TakenBy.WorkEffortSequence.IsEnforcedSequence ? @this.TakenBy.WorkEffortNumberPrefix : fiscalYearInternalOrganisationSequenceNumbers.WorkEffortNumberPrefix; @this.DerivedRoles.SortableWorkEffortNumber = @this.Session().GetSingleton().SortableNumber(prefix, @this.WorkEffortNumber, year.ToString()); } if ([email protected] && @this.ExistTakenBy) { @this.ExecutedBy = @this.TakenBy; } @this.VerifyWorkEffortPartyAssignments(derivation); @this.DeriveActualHoursAndDates(); if (@this.ExistActualStart && @this.WorkEffortState.IsCreated) { @this.WorkEffortState = new WorkEffortStates(@this.Strategy.Session).InProgress; } @this.DeriveCanInvoice(); if (@this.WorkEffortState.IsFinished && @this.CanInvoice) { @this.WorkEffortState = new WorkEffortStates(@this.Strategy.Session).Completed; } foreach (WorkEffortInventoryAssignment inventoryAssignment in @this.WorkEffortInventoryAssignmentsWhereAssignment) { foreach (InventoryTransactionReason createReason in @this.WorkEffortState.InventoryTransactionReasonsToCreate) { inventoryAssignment.SyncInventoryTransactions(derivation, inventoryAssignment.InventoryItem, inventoryAssignment.Quantity, createReason, false); } foreach (InventoryTransactionReason cancelReason in @this.WorkEffortState.InventoryTransactionReasonsToCancel) { inventoryAssignment.SyncInventoryTransactions(derivation, inventoryAssignment.InventoryItem, inventoryAssignment.Quantity, cancelReason, true); } } }
public static void AppsInvoice(this WorkEffort @this, WorkEffortInvoice method) { if (@this.CanInvoice) { @this.WorkEffortState = new WorkEffortStates(@this.Strategy.Session).Finished; @this.InvoiceThis(); } }
public static TimeEntry CreateTimeEntry(this WorkEffort @this, DateTime fromDate, DateTime throughDate, TimeFrequency frequency, RateType rateType) => new TimeEntryBuilder(@this.Session()) .WithRateType(rateType) .WithFromDate(fromDate) .WithThroughDate(throughDate) .WithTimeFrequency(frequency) .WithWorkEffort(@this) .Build();
public static void BaseComplete(this WorkEffort @this, WorkEffortComplete method) { if (!method.Result.HasValue) { @this.WorkEffortState = new WorkEffortStates(@this.Strategy.Session).Completed; method.Result = true; } }
// // Returns TRUE if the date is within the start and end dates of the the Work Effort public bool isWithinWeTimeBounds(int weID, DateTime hrsDate) { WorkEffort tmpWe = WorkEffortDB.WorkEffortList.Find(weID); if ((hrsDate >= tmpWe.startDate) && (hrsDate <= tmpWe.endDate)) { return(true); } return(false); }
public virtual ActionResult addWorkEffort(WorkEffort workeffort) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { if (ModelState.IsValid) { //make sure there is an end date if (workeffort.endDate == null) { workeffort.endDate = DateTime.MaxValue; } //make sure the start date is before the end date if (workeffort.startDate > workeffort.endDate) { ViewBag.divisionList = getDivisionSelectList(); ViewBag.endBeforeStartFlag = true; return(View(workeffort)); } //make sure it falls within it's associated PCA code's time boundaries if (verifyWeTimeBounds(workeffort, workeffort.pcaCode) == true) { //update WorkEffort table in database WorkEffortDB.WorkEffortList.Add(workeffort); WorkEffortDB.SaveChanges(); //add the PCA_WE association to PCA_WE table PCA_WE tmpPcaWe = new PCA_WE(); tmpPcaWe.WE = workeffort.ID; tmpPcaWe.PCA = getPcaIdFromCode(workeffort.pcaCode); tmpPcaWe.associationStartDate = DateTime.Now; tmpPcaWe.associationEndDate = DateTime.MaxValue; tmpPcaWe.active = true; PCA_WEDB.PCA_WEList.Add(tmpPcaWe); PCA_WEDB.SaveChanges(); return(RedirectToAction("weManagement")); } else { ViewBag.divisionList = getDivisionSelectList(); ViewBag.notWithinTimeBounds = true; return(View(workeffort)); } } return(View("error")); } else { return(View("error")); } }
public static void BaseRevise(this WorkEffort @this, WorkEffortRevise method) { if (@this.ExistActualStart) { @this.WorkEffortState = new WorkEffortStates(@this.Strategy.Session).InProgress; } else { @this.WorkEffortState = new WorkEffortStates(@this.Strategy.Session).Created; } }
public static void AppsOnPostDerive(this WorkEffort @this, ObjectOnPostDerive method) { if ([email protected]) { @this.AddDeniedPermission(new Permissions(@this.Strategy.Session).Get(@this.Strategy.Class, MetaWorkEffort.Instance.Invoice, Operations.Execute)); } else { @this.RemoveDeniedPermission(new Permissions(@this.Strategy.Session).Get(@this.Strategy.Class, MetaWorkEffort.Instance.Invoice, Operations.Execute)); } }
public static void AppsOnPreDerive(this WorkEffort @this, ObjectOnPreDerive method) { var derivation = method.Derivation; if (derivation.ChangeSet.Associations.Contains(@this.Id)) { foreach (WorkEffortInventoryAssignment inventoryAssignment in @this.WorkEffortInventoryAssignmentsWhereAssignment) { derivation.AddDependency(inventoryAssignment, @this); } } }
public static void BaseOnBuild(this WorkEffort @this, ObjectOnBuild method) { if ([email protected]) { @this.WorkEffortState = new WorkEffortStates(@this.Strategy.Session).Created; } if ([email protected] && @this.Strategy.Session.GetUser() is Person owner) { @this.Owner = owner; } }
public void CreateTask_Simplest_SuccessTest() { #region define parties var petya = new Person() { Id = "Петя" }; var simenceKnowlage = new SkillType() { Id = "1", DisplayName = "Знание Сименс контроллеров" }; var knowSimence = new PartySkill() { Party = petya, Raiting = 3, SkillType = simenceKnowlage, YearsEcpirience = 1 }; var vasya = new Person() { Id = "Вася" }; var samsungKnowlage = new SkillType() { Id = "1", DisplayName = "Знание Самсунг контроллеров" }; var knowSamsung = new PartySkill() { Party = vasya, Raiting = 2, SkillType = samsungKnowlage, YearsEcpirience = 3 }; var dychenko = new Person() { Id = "Дыченко" }; List <Party> people = new List <Party>(); people.Add(petya); people.Add(vasya); people.Add(dychenko); #endregion #region assigmen WorkOrder to a party var assigmenPetayToWork = new WorkEffortPartyAssignment(); var person = people.OfType <Person>().SingleOrDefault(x => x.Id.Id == "Петя"); assigmenPetayToWork.AllocatedParty = person; #endregion #region calculate work effort var workEffort = new WorkEffort(); #endregion }
public static void BaseOnPreDerive(this WorkEffort @this, ObjectOnPreDerive method) { var(iteration, changeSet, derivedObjects) = method; if (iteration.ChangeSet.Associations.Contains(@this.Id)) { foreach (WorkEffortInventoryAssignment inventoryAssignment in @this.WorkEffortInventoryAssignmentsWhereAssignment) { iteration.AddDependency(inventoryAssignment, @this); iteration.Mark(inventoryAssignment); } } }
public static void BaseInvoice(this WorkEffort @this, WorkEffortInvoice method) { if (!method.Result.HasValue) { if (@this.CanInvoice) { @this.WorkEffortState = new WorkEffortStates(@this.Strategy.Session).Finished; @this.InvoiceThis(); } method.Result = true; } }
private static void CreateInvoiceItems(this WorkEffort @this, SalesInvoice salesInvoice) { var session = @this.Strategy.Session; var timeEntriesByBillingRate = @this.ServiceEntriesWhereWorkEffort.OfType <TimeEntry>() .Where(v => (v.IsBillable && !v.BillableAmountOfTime.HasValue && v.AmountOfTime.HasValue) || v.BillableAmountOfTime.HasValue) .GroupBy(v => v.BillingRate) .Select(v => v) .ToArray(); foreach (var rateGroup in timeEntriesByBillingRate) { var timeEntries = rateGroup.ToArray(); var invoiceItem = new SalesInvoiceItemBuilder(session) .WithInvoiceItemType(new InvoiceItemTypes(session).Time) .WithAssignedUnitPrice(rateGroup.Key) .WithQuantity(timeEntries.Sum(v => v.BillableAmountOfTime ?? v.AmountOfTime ?? 0.0m)) .Build(); salesInvoice.AddSalesInvoiceItem(invoiceItem); foreach (var billableEntry in timeEntries) { new TimeEntryBillingBuilder(session) .WithTimeEntry(billableEntry) .WithInvoiceItem(invoiceItem) .Build(); } } foreach (WorkEffortInventoryAssignment workEffortInventoryAssignment in @this.WorkEffortInventoryAssignmentsWhereAssignment) { var part = workEffortInventoryAssignment.InventoryItem.Part; var invoiceItem = new SalesInvoiceItemBuilder(session) .WithInvoiceItemType(new InvoiceItemTypes(session).PartItem) .WithPart(part) .WithAssignedUnitPrice(workEffortInventoryAssignment.UnitSellingPrice) .WithQuantity(workEffortInventoryAssignment.DerivedBillableQuantity) .WithCostOfGoodsSold(workEffortInventoryAssignment.CostOfGoodsSold) .Build(); salesInvoice.AddSalesInvoiceItem(invoiceItem); new WorkEffortBillingBuilder(session) .WithWorkEffort(@this) .WithInvoiceItem(invoiceItem) .Build(); } }
private WorkEffortInventoryAssignment CreateInventoryAssignment(WorkEffort workOrder, Part part, int quantity) { new InventoryItemTransactionBuilder(this.Session) .WithPart(part) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(quantity) .Build(); return(new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workOrder) .WithInventoryItem(part.InventoryItemsWherePart.First) .WithQuantity(quantity) .Build()); }
public virtual ActionResult deleteWorkEffort(int id) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { WorkEffort workeffort = WorkEffortDB.WorkEffortList.Find(id); ViewBag.pcaList = getWePcaCodesSelectList(workeffort); return(View(workeffort)); } else { return(View("error")); } }
// /* Checks to see if the work effort falls within the specified PCA code's time boundaries. * If so, it returns TRUE. */ public bool verifyWeTimeBounds(WorkEffort effort, int pca) { var searchPCA = from m in PcaCodeDB.PcaCodeList where (m.code.CompareTo(pca) == 0) select m; foreach (var item in searchPCA) { if ((item.startDate <= effort.startDate) && (item.endDate >= effort.endDate)) { return(true); } } return(false); }
private static void BaseCalculateTotalRevenue(this WorkEffort @this, WorkEffortCalculateTotalRevenue method) { if (!method.Result.HasValue) { ((WorkEffortDerivedRoles)@this).TotalLabourRevenue = Rounder.RoundDecimal(@this.BillableTimeEntries().Sum(v => v.BillingAmount), 2); ((WorkEffortDerivedRoles)@this).TotalMaterialRevenue = Rounder.RoundDecimal(@this.WorkEffortInventoryAssignmentsWhereAssignment.Where(v => v.DerivedBillableQuantity > 0).Sum(v => v.DerivedBillableQuantity * v.UnitSellingPrice), 2); ((WorkEffortDerivedRoles)@this).TotalSubContractedRevenue = Rounder.RoundDecimal(@this.WorkEffortPurchaseOrderItemAssignmentsWhereAssignment.Sum(v => v.Quantity * v.UnitSellingPrice), 2); var totalRevenue = Rounder.RoundDecimal(@this.TotalLabourRevenue + @this.TotalMaterialRevenue + @this.TotalSubContractedRevenue, 2); method.Result = true; ((WorkEffortDerivedRoles)@this).GrandTotal = totalRevenue; ((WorkEffortDerivedRoles)@this).TotalRevenue = @this.Customer.Equals(@this.ExecutedBy) ? 0M : totalRevenue; } }
public virtual ActionResult deletePCA_WE(PCA_WE pca_we) { Authentication auth = new Authentication(); if (auth.isAdmin(this) || Authentication.DEBUG_bypassAuth) { //The view actually passed the PCA code instead of the ID, so set the ID to the correct value pca_we.PCA = getPcaIdFromCode(pca_we.PCA); int count = 0; PCA_WE tmpPcaWe = new PCA_WE(); var searchPcaWe = from p in PCA_WEDB.PCA_WEList where p.WE == pca_we.WE where p.active == true select p; foreach (var item in searchPcaWe) { //This if-statement will only be true once if (item.PCA == pca_we.PCA) { tmpPcaWe = PCA_WEDB.PCA_WEList.Find(item.ID); } count++; } if (count > 1) { //deactivate and set the end date for the PCA_WE entry tmpPcaWe.active = false; tmpPcaWe.associationEndDate = DateTime.Now; // save changes in database PCA_WEDB.Entry(tmpPcaWe).State = System.Data.EntityState.Modified; PCA_WEDB.SaveChanges(); return(RedirectToAction("weManagement", "Manager")); } ViewBag.lastPcaFlag = true; WorkEffort we = WorkEffortDB.WorkEffortList.Find(pca_we.WE); ViewBag.workEffortDescription = we.description; ViewBag.workEffortId = we.ID; ViewBag.pcaList = getWePcaCodesSelectList(we); return(View()); } else { return(View("error")); } }
public virtual ActionResult editWorkEffort(WorkEffort workeffort) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { if (ModelState.IsValid) { //make sure the start date is before the end date if (workeffort.startDate > workeffort.endDate) { ViewBag.endBeforeStartFlag = true; ViewBag.pcaList = getWePcaCodesSelectList(workeffort); Authentication newAuth = new Authentication(); if (newAuth.isAdmin(this)) { ViewBag.adminFlag = true; } return(View(workeffort)); } //make sure it falls within it's associated PCA code's time boundaries if (verifyWeTimeBounds(workeffort, workeffort.pcaCode) == true) { WorkEffortDB.WorkEffortList.Add(workeffort); WorkEffortDB.Entry(workeffort).State = System.Data.EntityState.Modified; WorkEffortDB.SaveChanges(); return(RedirectToAction("weManagement")); } else { ViewBag.notWithinTimeBounds = true; ViewBag.pcaList = getWePcaCodesSelectList(workeffort); Authentication newAuth = new Authentication(); if (newAuth.isAdmin(this)) { ViewBag.adminFlag = true; } return(View(workeffort)); } } return(View(workeffort)); } else { return(View("error")); } }