-
-
Save jvanhoesen/7c438ef851ef1aac4bfa9af7c9cebf08 to your computer and use it in GitHub Desktop.
Graph for primary Data-Access-Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AATimeRequestEntry : PXGraph<AATimeRequestEntry, NPTimeRequest> | |
{ | |
#region Constructor | |
public AATimeRequestEntry() | |
{ | |
Action.AddMenuAction(Approve); | |
Action.AddMenuAction(Reject); | |
} | |
#endregion | |
#region Views | |
public PXSetup<AATimeRequestSetup> Setup; | |
public PXSetup<AATimeRequestApproval> SetupApproval; | |
public PXSelect<AATimeRequest> Document; | |
[PXViewName("Approval Details")] | |
public EPApprovalAutomation<AATimeRequest, AATimeRequest.approved, AATimeRequest.rejected, AATimeRequest.hold, AATimeRequestApproval> Approval; | |
public PXSelect<AATimeRequestDetail, Where<AATimeRequestDetail.refnbr, Equal<Current<AATimeRequest.refnbr>>>> Details; | |
#endregion | |
#region Buttons | |
#region Action | |
public PXAction<AATimeRequest> Action; | |
[PXButton(MenuAutoOpen = true)] | |
[PXUIField(DisplayName = "Actions", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)] | |
public virtual IEnumerable action(PXAdapter adapter) | |
{ | |
return adapter.Get(); | |
} | |
#endregion | |
#region Approval Buttons | |
#region Approve | |
public PXAction<AATimeRequest> Approve; | |
[PXButton] | |
[PXUIField(DisplayName = "Approve", Visible = false, MapEnableRights = PXCacheRights.Select)] | |
public IEnumerable approve(PXAdapter adapter) | |
{ | |
AATimeRequest timeRequest = Document.Current; | |
if (timeRequest != null) | |
{ | |
timeRequest.Approved = true; | |
timeRequest.Status = AATimeRequestStatus.Approved; | |
Document.Update(timeRequest); | |
Save.Press(); | |
} | |
return adapter.Get(); | |
} | |
#endregion | |
#region Reject | |
public PXAction<AATimeRequest> Reject; | |
[PXButton] | |
[PXUIField(DisplayName = "Reject", MapEnableRights = PXCacheRights.Select)] | |
public IEnumerable reject(PXAdapter adapter) | |
{ | |
AATimeRequest timeRequest = Document.Current; | |
if (timeRequest != null) | |
{ | |
timeRequest.Rejected = true; | |
timeRequest.Status = AATimeRequestStatus.Rejected; | |
Document.Update(timeRequest); | |
Save.Press(); | |
} | |
return adapter.Get(); | |
} | |
#endregion | |
#endregion | |
#endregion | |
#region Events | |
#region AATimeRequest | |
protected virtual void _(Events.RowSelecting<AATimeRequest> e) | |
{ | |
if (e.Row is AATimeRequest row) | |
{ | |
using (new PXConnectionScope()) | |
{ | |
//If Approvals are enabled, check if the current user is the set approver | |
if (Setup.Current.TimeRequestApproval ?? false) | |
{ | |
EPEmployee approver = PXSelectJoin<EPEmployee, | |
InnerJoin<EPRule, On<EPEmployee.userID, Equal<EPRule.ownerID>>, | |
InnerJoin<EPAssignmentMap, On<EPRule.assignmentMapID, Equal<EPAssignmentMap.assignmentMapID>>>>, | |
Where<EPAssignmentMap.assignmentMapID, Equal<Required<EPAssignmentMap.assignmentMapID>>>>.Select(this, SetupApproval.Current.AssignmentMapID); | |
if (approver != null) | |
{ | |
row.IsApprover = (approver.UserID == Accessinfo.UserID); | |
} | |
} | |
} | |
} | |
} | |
/// <summary> | |
/// Enables Approve/Reject buttons when a document goes to 'Pending Approval' | |
/// Disables header fields except for 'Hold' checkbox when doc is off hold | |
/// </summary> | |
protected virtual void _(Events.RowSelected<AATimeRequest> e) | |
{ | |
if (e.Row is AATimeRequest row) | |
{ | |
if (Setup.Current.TimeRequestApproval ?? false) //Approvals are set | |
{ | |
Approve.SetEnabled(row.Status == AATimeRequestStatus.PendingApproval && row.IsApprover == true); | |
Reject.SetEnabled(row.Status == AATimeRequestStatus.PendingApproval && row.IsApprover == true); | |
} | |
else //No approvals | |
{ | |
Approve.SetEnabled(row.Status == AATimeRequestStatus.PendingApproval); | |
Reject.SetEnabled(row.Status == AATimeRequestStatus.PendingApproval); | |
} | |
e.Cache.SetEnabled<AATimeRequest.employeeID>(row, row.Status == AATimeRequestStatus.OnHold); | |
e.Cache.SetEnabled<AATimeRequest.date>(row, row.Status == AATimeRequestStatus.OnHold); | |
e.Cache.SetEnabled<AATimeRequest.description>(row, row.Status == AATimeRequestStatus.OnHold); | |
} | |
} | |
/// <summary> | |
/// Sets a document to pending approval when taken off hold, or resets the other status fields when a document is put back on hold | |
/// </summary> | |
protected virtual void _(Events.FieldUpdated<AATimeRequest, AATimeRequest.hold> e) | |
{ | |
if (e.Row is AATimeRequest row) | |
{ | |
if (!row.Hold ?? false) | |
{ | |
row.Status = AATimeRequestStatus.PendingApproval; | |
} | |
else | |
{ | |
row.Status = AATimeRequestStatus.OnHold; | |
row.Rejected = false; | |
row.Approved = false; | |
} | |
} | |
} | |
#endregion | |
#region AATimeRequestDetail | |
protected virtual void _(Events.RowSelected<AATimeRequestDetail> e) | |
{ | |
if (e.Row is AATimeRequestDetail row) | |
{ | |
//Prevent further changes from being made to a detail row when the document is no longer 'On Hold' | |
Details.Cache.AllowUpdate = Document.Current.Hold ?? false; | |
} | |
} | |
#endregion | |
#region EPApproval | |
/// <summary> | |
/// Set additional information on the approval record for the approver | |
/// </summary> | |
protected virtual void _(Events.RowInserting<EPApproval> e) | |
{ | |
if (e.Row is EPApproval) | |
{ | |
AATimeRequest currentTR = Document.Current; | |
if (currentTR != null) | |
{ | |
e.Cache.SetValue<EPApproval.refNoteID>(e.Row, currentTR.NoteID); | |
EPEmployee employee = PXSelect<EPEmployee, Where<EPEmployee.bAccountID, Equal<Required<EPEmployee.bAccountID>>>>.Select(this, currentTR.EmployeeID); | |
if (employee != null) | |
{ | |
e.Cache.SetValue<EPApproval.documentOwnerID>(e.Row, employee.UserID); | |
e.Cache.SetValue<EPApproval.bAccountID>(e.Row, employee.BAccountID); | |
} | |
e.Cache.SetValue<EPApproval.docDate>(e.Row, currentTR.Date); | |
e.Cache.SetValue<EPApproval.descr>(e.Row, currentTR.Description); | |
string details = ""; | |
foreach(AATimeRequestDetail detail in Details.Select()) | |
{ | |
details += string.Format(AdvancedTimeCardMessages.TRApprovalDetails, detail.Date.Value.ToShortDateString(), detail.StartTime.Value.ToShortTimeString(), detail.EndTime.Value.ToShortTimeString()); | |
} | |
e.Cache.SetValue<EPApproval.details>(e.Row, details); | |
} | |
} | |
} | |
#endregion | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment