Imports Williams.Lea.Symphony.Web.Domain.Models
Imports Williams.Lea.Symphony.Web.Domain.Validation
Imports Williams.Lea.Symphony.Web.UIObjects
Imports Williams.Lea.Symphony.Web.Domain.Helpers
Imports Williams.Lea.Symphony.Web.Crosscutting
Imports Williams.Lea.Symphony.Web.Domain
Imports Williams.Lea.Symphony.Web.Domain.Interfaces
Public Class JT_Completed
Inherits JobTicket
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.ORIGINATING Then
LogAction("Unauthorized complete attempt", ActionType.Read, False)
ShowError(Domain.Localization.Resources.Resources.AccessDenied)
End If
Page.Title = String.Format("Complete request {0}", Me.JOBNUMBER)
LoadGrid("FINAL")
If Not Me.IsPostBack Then
Dim reasons = _settingsService.GetReasonCodes(Me.SELECTEDSITENAME, "JOBLATE", Nothing)
If Not reasons Is Nothing Then
For Each reason In reasons
ddLateReason.Items.Add(New ListItem(reason.REASON, reason.REASON_CODE))
Next
End If
ddLateReason.Items.Insert(0, New ListItem("Make a selection", ""))
If Not Me.ATTACHMENTS_MODE.Equals(AttachmentMode.Off.Value, StringComparison.OrdinalIgnoreCase) Then
rgFileCompleted.Visible = True
txtNotes.Height = New Unit(225, UnitType.Pixel)
Else
rgFileCompleted.Visible = False
txtNotes.Height = New Unit(375, UnitType.Pixel)
End If
End If
End Sub
Private Sub LoadGrid(ByVal type As String)
Dim data = _service.GetJobTicketAttachments(Me.JOBNUMBER, Me.ATTACHMENTS_MODE, type, True)
If Not data Is Nothing Then
rgFileCompleted.DataSource = data.ToTimeAdjustedList()
End If
End Sub
Protected Sub btnComplete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click, btnComplete.Click
Dim job = _service.GetRoute(Me.SELECTEDSITENAME, Me.JOBNUMBER)
If job Is Nothing Then
Me.ErrorMessage(Domain.Localization.Resources.Resources.ItemNotFound)
Return
End If
'Check if already completed
If job.STATUS.ToUpper = StatusTypes.Completed.Value Or job.STATUS.ToUpper = StatusTypes.Cancelled.Value Then
Me.ErrorMessage(Domain.Localization.Resources.Resources.CompletedReload)
Return
End If
ExecuteJobComplete()
End Sub
Private Sub ExecuteJobComplete()
Me.Validate("vgSave")
If Not Me.IsValid Then
Me.ErrorMessage(GetValidatorErrors(Me.Validators))
Return
End If
Try
_service.ValidateMandatoryTasks(Me.SELECTEDSITENAME, Me.JOBNUMBER)
Dim route = _service.GetRoute(Me.SELECTEDSITENAME, Me.JOBNUMBER)
If route Is Nothing Then
ErrorMessage(Domain.Localization.Resources.Resources.ItemNotFound)
Return
End If
Dim lateReason = String.Empty
If route.DUE_DATE < TimeProvider.Current.UtcNow Then
If ddLateReason.SelectedValue.Trim.Length = 0 Then
Dim Script As String = "function f(){$find('" + mpeLate.ClientID + "').show(); Sys.Application.remove_load(f);} Sys.Application.add_load(f);"
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", Script, True)
Return
Else
lateReason = String.Format("Reason request was late: [{0}]: {1}", ddLateReason.SelectedValue, ddLateReason.SelectedItem.Text)
End If
End If
_service.UpdateRouteStatus(New JobTicketRoutesDTO() With {
.SITE = Me.SELECTEDSITENAME,
.JOB_NO = Me.JOBNUMBER,
.STATUS = StatusTypes.Completed.Value
})
_service.CreateJobMessage(New JobMessageDTO() With {
.JOB_NO = Me.JOBNUMBER,
.MESSAGE = String.Format("Request has been completed:
{0}", txtNotes.Content.Sanitize()),
.IS_READ = False,
.PORTAL = False,
.MESSAGE_TYPE = MessageTypes.Completed.Value
})
_service.CreateJobNote(New JobNotesDTO() With {
.COMMENTS = String.Format("Request has been completed{0}", If(lateReason.Trim.Length > 0, String.Format(". {0}", lateReason), "")),
.JOB_NO = Me.JOBNUMBER,
.SYSTEM = True,
.SITE = Me.SELECTEDSITENAME
})
If _service.AddNotificationForJob(Me.JOBNUMBER, NotificationTypes.Completed.Value) Then
LogAction(String.Format("Sending completed email for request {0}", Me.JOBNUMBER), ActionType.Create, True)
End If
_intakeAiService.HandleJobFinish(Me.JOBNUMBER)
LogAction(String.Format("Request #{0} has been completed", Me.JOBNUMBER), ActionType.Update, True)
CloseRadWindowSelf()
ReloadAll("full")
Catch ex As ValidationException
Me.ErrorMessage(GetValidationExceptionErrors(ex))
Return
Catch ex As Exception
Me.ErrorMessage(Domain.Localization.Resources.Resources.ErrorUpdatingRecord)
LogError(ex.ToString(), ActionType.Update, False)
Return
End Try
End Sub
Protected Sub btnLateOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLateOK.Click
Dim job = _service.GetRoute(Me.SELECTEDSITENAME, Me.JOBNUMBER)
If job Is Nothing Then
Me.ErrorMessage(Domain.Localization.Resources.Resources.ItemNotFound)
Return
End If
'Check if already completed
If job.STATUS.ToUpper = StatusTypes.Completed.Value Or job.STATUS.ToUpper = StatusTypes.Cancelled.Value Then
Me.ErrorMessage(Domain.Localization.Resources.Resources.CompletedReload)
Return
End If
ExecuteJobComplete()
End Sub
End Class