· 8 years ago · Mar 07, 2018, 07:48 AM
1Option Explicit
2
3' ## SUMMARY When pressing "Activate" this sub will be executed. It empties the field "Next action" _
4 and sets the helpdesk status to "Ongoing". The button is only visible if the helpdesk is assigned _
5 to activeuser and there is a value in "Next action"
6Public Sub Activate()
7 On Error GoTo ErrorHandler
8
9 Dim oInspector As Lime.Inspector
10
11 Set oInspector = Application.ActiveInspector
12
13 If Globals.VerifyInspector("helpdesk", oInspector) And ActionPad_Helpdesk.SaveNew() Then
14 Call oInspector.Controls.SetValue("nextactiondate", Null)
15 Call oInspector.Controls.SetValue("statuscolor", Database.Classes("helpdesk").Fields("statuscolor").Options.Lookup("ongoing", lkLookupOptionByKey).value) 'ongoing
16 Call oInspector.Save(True)
17
18 'create history
19 Call CreateHelpdeskHistory(oInspector.Record.ID, Localize.GetText("ActionPad_Helpdesk", "t_errand_activated"), True)
20 End If
21
22Exit Sub
23ErrorHandler:
24 Call UI.ShowError("ActionPad_Helpdesk.Activate")
25End Sub
26
27
28
29
30' ##SUMMARY When pressing "Begin" this sub will be executed. Its checks if there _
31 already is a responsible person for the case. If there is not, you become _
32 responsible. The field "startdate" will be set to current time. If there _
33 already is a responsible coworker for the case a messegebox will be dispayed _
34 and you can decide if you really want to take over the case.
35Public Sub Take()
36 On Error GoTo ErrorHandler
37
38 Dim oInspector As Lime.Inspector
39
40 Set oInspector = Application.ActiveInspector
41
42 If Globals.VerifyInspector("helpdesk", oInspector) And ActionPad_Helpdesk.SaveNew() Then
43 'Reopen
44 If VBA.IsNull(oInspector.Controls.GetValue("enddate")) = False Then
45 If Lime.MessageBox(Localize.GetText("ActionPad_Helpdesk", "q_done_reopen"), vbYesNo) = vbNo Then
46 Exit Sub
47 Else
48 Call ReOpen
49 oInspector.WebBar.Refresh
50 Exit Sub
51 End If
52 End If
53
54 'Just take it
55 If VBA.IsNull(oInspector.Controls.GetValue("startdate")) Then
56 Call oInspector.Controls.SetValue("startdate", VBA.Now())
57 End If
58 Call oInspector.Controls.SetValue("coworker", ActiveUser.Record.ID)
59 Call oInspector.Save(True)
60
61 'create history
62 Call CreateHelpdeskHistory(oInspector.Record.ID, Localize.GetText("ActionPad_Helpdesk", "t_errand_started"), True)
63 End If
64
65 Exit Sub
66ErrorHandler:
67 Call UI.ShowError("ActionPad_Helpdesk.Take")
68End Sub
69
70' ##SUMMARY When reopening a case a check is made to se that there is a date set on the _
71 field "startdate". If there is non startdate the field will be set to current _
72 time. Since the case is reopen the field "enddate" will be set to Null and _
73 the active user will be responsible for the case.
74Public Sub ReOpen()
75 On Error GoTo ErrorHandler
76
77 Dim oInspector As Lime.Inspector
78
79
80 Set oInspector = Application.ActiveInspector
81
82 If Globals.VerifyInspector("helpdesk", oInspector) And ActionPad_Helpdesk.SaveNew() Then
83
84 If VBA.IsNull(oInspector.Controls.GetValue("startdate")) Then
85 Call oInspector.Controls.SetValue("startdate", VBA.Now())
86 End If
87
88 Call oInspector.Controls.SetValue("enddate", Null)
89 Call oInspector.Controls.SetValue("coworker", ActiveUser.Record.ID)
90 Call oInspector.Save(True)
91
92 'create history
93 Call CreateHelpdeskHistory(oInspector.Record.ID, Localize.GetText("ActionPad_Helpdesk", "t_errand_restarted"), True)
94 End If
95
96 Exit Sub
97ErrorHandler:
98 Call UI.ShowError("ActionPad_Helpdesk.ReOpen")
99End Sub
100
101' ##SUMMARY When taking over a case from another coworker the coworker field on the card _
102 changes to active users name. If there is no startdate for the case _
103 the field gets current time as startdate.
104Public Sub TakeOver()
105 On Error GoTo ErrorHandler
106
107 Dim oInspector As Lime.Inspector
108
109 Set oInspector = Application.ActiveInspector
110
111 If Globals.VerifyInspector("helpdesk", oInspector) And ActionPad_Helpdesk.SaveNew() Then
112 If oInspector.Controls.GetValue("coworker", 0) > 0 Then
113 If oInspector.Controls.GetValue("coworker", 0) = ActiveUser.Record.ID Then
114 Call Lime.MessageBox(Localize.GetText("ActionPad_Helpdesk", "i_already_responsible"), VBA.vbInformation Or VBA.vbOKOnly)
115 Exit Sub
116 ElseIf Lime.MessageBox(Localize.GetText("ActionPad_Helpdesk", "q_take_over"), VBA.vbQuestion + VBA.vbYesNo, oInspector.Controls.GetText("coworker")) = VBA.vbNo Then
117 Exit Sub
118 Else
119 If VBA.IsNull(oInspector.Controls.GetValue("startdate")) Then
120 Call oInspector.Controls.SetValue("startdate", VBA.Now())
121 End If
122
123 Call oInspector.Controls.SetValue("coworker", ActiveUser.Record.ID)
124 Call oInspector.Save(True)
125
126 'create history
127 Call CreateHelpdeskHistory(oInspector.Record.ID, Localize.GetText("ActionPad_Helpdesk", "t_errand_overtaken"))
128 End If
129 End If
130 End If
131
132 Exit Sub
133ErrorHandler:
134 Call UI.ShowError("ActionPad_Helpdesk.TakeOver")
135End Sub
136
137' ##SUMMARY When putting back a case the fields startdate and coworker are set to Null.
138Public Sub PutBack()
139 On Error GoTo ErrorHandler
140
141 Dim oInspector As Lime.Inspector
142
143 Set oInspector = Application.ActiveInspector
144 If Globals.VerifyInspector("helpdesk", oInspector) And ActionPad_Helpdesk.SaveNew() Then
145
146 Call oInspector.Controls.SetValue("coworker", Null)
147 Call oInspector.Save(True)
148
149 'create history
150 Call CreateHelpdeskHistory(oInspector.Record.ID, Localize.GetText("ActionPad_Helpdesk", "t_errand_putback"), True)
151 End If
152
153 Exit Sub
154ErrorHandler:
155 Call UI.ShowError("ActionPad_Helpdesk.PutBack")
156End Sub
157
158' ##SUMMARY When closing a case "Set done" the field enddate will be ste to current _
159 time. If there is no startdate that field will also be set to current _
160 time. A check is also made if there is a responsible coworker for the _
161 case, if not the active user will be set as the responsible coworker.
162Public Sub Done()
163 On Error GoTo ErrorHandler
164
165 Dim oInspector As Lime.Inspector
166
167 Set oInspector = Application.ActiveInspector
168
169 If Globals.VerifyInspector("helpdesk", oInspector) And ActionPad_Helpdesk.SaveNew() Then
170 If VBA.IsNull(oInspector.Controls.GetValue("startdate", Null)) Then
171 Call oInspector.Controls.SetValue("startdate", VBA.Now())
172 End If
173 Call oInspector.Controls.SetValue("enddate", VBA.Now())
174 Call oInspector.Controls.SetValue("nextactiondate", Null)
175
176 'Set coworker to active coworker if coworker is not set.
177 If oInspector.Controls.GetValue("coworker", 0) = 0 Then
178 Call oInspector.Controls.SetValue("coworker", ActiveUser.Record.ID)
179 End If
180
181 Call oInspector.Save(True)
182
183 'create history
184 Call CreateHelpdeskHistory(oInspector.Record.ID, Localize.GetText("ActionPad_Helpdesk", "t_errand_done"), True)
185
186 'PATTERN: Unread history
187 'END Unread history
188 End If
189
190 Exit Sub
191ErrorHandler:
192 Call UI.ShowError("ActionPad_Helpdesk.Done")
193End Sub
194
195' ##SUMMARY Parks the case according to hours set in LIME. Calls on the sub called _
196 "AddWorkingHours" that recounts the hours to working hours. The _
197 deadline-field will be set to a date that depends on the parking hours (see _
198 Case statement)
199Public Sub Park(ByVal nHours As Integer, ByVal sNotes As String, Optional bCloseRecord As Boolean = False)
200 On Error GoTo ErrorHandler
201
202 Dim oInspector As Lime.Inspector
203
204 'Get the local text
205 If VBA.Len(VBA.Trim(sNotes)) Then
206 sNotes = Localize.GetText("Actionpad_Helpdesk", sNotes)
207 End If
208
209 Set oInspector = Application.ActiveInspector
210
211 If Globals.VerifyInspector("helpdesk", oInspector) And ActionPad_Helpdesk.SaveNew() Then
212
213 'If the case does not have responsible coworker - take it
214 If oInspector.Controls.GetValue("coworker", 0) = 0 Then
215 Call ActionPad_Helpdesk.Take
216 End If
217
218 Dim oRecord As LDE.Record
219 Dim dtPark As Date
220 Dim bAllOK As Boolean 'might need user poll as parking is designed for working hours, and to avoid parking already done tasks.
221
222 Application.MousePointer = 11
223
224 ' Park
225 dtPark = AddWorkingHours(VBA.Now(), nHours)
226
227 ' Make sure that right now is a working hour
228 If IsWorktime(VBA.Now()) Then
229 bAllOK = True
230 ElseIf Lime.MessageBox(Localize.GetText("ActionPad_Helpdesk", "q_errand_notworkingtime"), vbYesNo Or vbExclamation, VBA.CStr(dtPark)) = vbYes Then
231 bAllOK = True
232 Else
233 bAllOK = False
234 End If
235
236 ' Make sure that we are not parking a done task
237
238 If bAllOK And VBA.IsNull(oInspector.Controls.GetValue("enddate")) = False Then
239 If Lime.MessageBox(Localize.GetText("ActionPad_Helpdesk", "q_reopen_closed"), vbYesNo Or vbExclamation) = vbYes Then
240 Call oInspector.Controls.SetValue("coworker", ActiveUser.Record.ID)
241 Call oInspector.Controls.SetValue("startdate", Now)
242 Call oInspector.Controls.SetValue("enddate", Null)
243 sNotes = Localize.GetText("ActionPad_Helpdesk", "t_errand_restarted") + " " + sNotes
244 Call Lime.MessageBox(Localize.GetText("ActionPad_Helpdesk", "t_reopened_parked"), VBA.vbInformation)
245 bAllOK = True
246 oInspector.WebBar.Refresh
247 Else
248 bAllOK = False
249 End If
250 End If
251
252 If bAllOK Then ' Let's do it
253 Call oInspector.Controls.SetValue("nextactiondate", dtPark)
254 Call oInspector.Save(True)
255
256 'Create history
257 If VBA.Len(VBA.Trim(sNotes)) > 0 Then
258 Call CreateHelpdeskHistory(oInspector.Record.ID, VBA.Trim(sNotes))
259 End If
260
261 If bCloseRecord Then
262 Call oInspector.Close(True)
263 End If
264 End If
265 End If
266
267 Application.MousePointer = 0
268
269 Exit Sub
270ErrorHandler:
271 Call UI.ShowError("ActionPad_Helpdesk.Park")
272End Sub
273
274' ##SUMMARY Checks if current time is working hours.
275Private Function IsWorktime(theDate As Date) As Boolean
276 On Error GoTo ErrorHandler
277
278 Dim theTime As Date
279 Dim bWorkTime As Boolean
280
281 theTime = TimeSerial(VBA.Hour(theDate), VBA.Minute(theDate), 0)
282 bWorkTime = False
283
284 If theTime >= CustomSettings.HELPDESK_WORKDAY_START And theTime < CustomSettings.HELPDESK_WORKDAY_END Then
285 If CustomSettings.HELPDESK_WORK_LUNCH Then
286 bWorkTime = True
287 ElseIf theTime >= CustomSettings.HELPDESK_LUNCH_START And theTime < CustomSettings.HELPDESK_LUNCH_END Then
288 bWorkTime = False
289 Else
290 bWorkTime = True
291 End If
292 End If
293
294 IsWorktime = bWorkTime
295
296 Exit Function
297ErrorHandler:
298 Call UI.ShowError("Actionpad_Helpdesk.IsWorktime")
299End Function
300
301' A great math helper method.
302' ##SUMMARY Recount the "parking hours" to working hours.
303Public Function AddWorkingHours(ByVal dtADate As Date, ByVal iHoursToAdd As Integer)
304 On Error GoTo ErrorHandler
305
306 Dim dtReturnDate As Date
307 Dim lMinutesToAdd As Long
308 dtReturnDate = dtADate
309
310 ' add one hour at a time
311 Dim i As Integer
312 For i = 1 To iHoursToAdd
313 dtReturnDate = DateAdd("h", 1, dtReturnDate)
314 'Is during lunch hour and work during lunch hour
315 If CustomSettings.HELPDESK_WORK_LUNCH = False _
316 And VBA.TimeSerial(VBA.Hour(dtReturnDate), VBA.Minute(dtReturnDate), 0) > VBA.TimeSerial(VBA.Hour(CustomSettings.HELPDESK_LUNCH_START), VBA.Minute(CustomSettings.HELPDESK_LUNCH_START), 0) _
317 And VBA.TimeSerial(VBA.Hour(dtReturnDate), VBA.Minute(dtReturnDate), 0) < VBA.TimeSerial(VBA.Hour(CustomSettings.HELPDESK_LUNCH_END), VBA.Minute(CustomSettings.HELPDESK_LUNCH_END), 0) Then
318 lMinutesToAdd = VBA.DateDiff("n", CustomSettings.HELPDESK_LUNCH_START, CustomSettings.HELPDESK_LUNCH_END)
319 dtReturnDate = DateAdd("n", lMinutesToAdd, dtReturnDate)
320
321 ElseIf VBA.TimeSerial(VBA.Hour(dtReturnDate), VBA.Minute(dtReturnDate), 0) > VBA.TimeSerial(VBA.Hour(CustomSettings.HELPDESK_WORKDAY_END), VBA.Minute(CustomSettings.HELPDESK_WORKDAY_END), 0) Then
322 lMinutesToAdd = 1440 - VBA.DateDiff("n", CustomSettings.HELPDESK_WORKDAY_START, CustomSettings.HELPDESK_WORKDAY_END) ' 1440 minuter per dygn
323 dtReturnDate = DateAdd("n", lMinutesToAdd, dtReturnDate)
324 End If
325
326 If VBA.Weekday(dtReturnDate, vbMonday) > 5 And CustomSettings.HELPDESK_WORK_WEEKENDS = False Then ' if more than fri jump to mon
327 dtReturnDate = DateAdd("d", 8 - VBA.Weekday(dtReturnDate, vbMonday), dtReturnDate)
328 End If
329 Next i
330
331 AddWorkingHours = dtReturnDate
332
333 Exit Function
334ErrorHandler:
335 Call UI.ShowError("ActionPad_Helpdesk.AddWorkingHours")
336End Function
337
338' ##SUMMARY Creates a history note of what has been done in the case. (parking the case, _
339 taking over it,mark it as done and so on)
340Public Sub CreateHelpdeskHistory(ByVal idowner As Long, Optional Text As String, Optional connectCompany As Boolean = False)
341 On Error GoTo ErrorHandler
342
343 Dim oInspector As Lime.Inspector
344 Set oInspector = Application.ActiveInspector
345
346 If Globals.VerifyInspector("helpdesk", oInspector) And ActionPad_Helpdesk.SaveNew() Then
347
348 Dim NewHistory As LDE.Record
349 Set NewHistory = New LDE.Record
350
351 NewHistory.Open Database.Classes("history")
352 NewHistory.value("helpdesk") = idowner
353 NewHistory.value("date") = VBA.Now()
354 NewHistory.value("coworker") = ActiveUser.Record.ID
355 Call NewHistory.SelectOption("type", "comment")
356 NewHistory.value("note") = Text
357
358 If connectCompany Then
359 NewHistory.value("company") = oInspector.Controls.GetValue("company")
360 End If
361
362 NewHistory.Update
363 End If
364
365 Exit Sub
366ErrorHandler:
367 Call UI.ShowError("ActionPad_Helpdesk.CreateHelpdeskHistory")
368End Sub
369' ##SUMMARY When linking a company or/and person this sub gets contact information from _
370 the company or/and person table and place it in the actionpad under the case _
371 number.
372Public Function GetContactInfo() As String
373 On Error GoTo ErrorHandler
374 Dim oRecordPerson As New LDE.Record
375 Dim oRecordCompany As LDE.Record
376 Dim oView As New LDE.View
377 Dim oInspector As Lime.Inspector
378 Dim strHTML As String
379 Dim idcompany As Long
380
381 strHTML = ""
382
383 Set oInspector = Application.ActiveInspector
384
385 If Globals.VerifyInspector("helpdesk", oInspector, False) Then
386 strHTML = "<ul>"
387
388 'If a person is linked
389 If oInspector.Controls.GetValue("person", 0) > 0 Then
390 Call oView.Add("phone")
391 Call oView.Add("mobilephone")
392 Call oView.Add("email")
393 Call oView.Add("company.idcompany")
394 Call oView.Add("company.phone")
395
396 oRecordPerson.Open Database.Classes("person"), oInspector.Controls.GetValue("person"), oView
397
398
399 If VBA.Len(oRecordPerson.value("phone")) > 0 Then
400 strHTML = strHTML + "<li> " + oRecordPerson.value("phone") + " (" + oRecordPerson.field("phone").LocalName + ")<br/></li>"
401 End If
402
403 If VBA.Len(oRecordPerson.value("mobilephone")) > 0 Then
404 strHTML = strHTML + "<li>" + oRecordPerson.value("mobilephone") + " (" + oRecordPerson.field("mobilephone").LocalName + ")<br/></li>"
405 End If
406
407 If VBA.Len(oRecordPerson.value("email")) > 0 Then
408 strHTML = strHTML & "<a href=""#"" title=""" + Localize.GetText("ActionPad_Helpdesk", "t_sendemail") + """ onclick=""javascript:VBA.Run('Actionpad_Helpdesk.EmailContact')"" >" & oRecordPerson.Text("email") & "</a>"
409 End If
410
411
412 'What is the companyid
413 If VBA.IsNull(oRecordPerson.value("company.idcompany")) = False Then
414 idcompany = oRecordPerson.value("company.idcompany")
415 End If
416 End If
417
418 'Company is the same as linked to a person and as set
419 If oInspector.Controls.GetValue("company", 0) = idcompany And oInspector.Controls.GetValue("company", 0) > 0 Then
420 If VBA.Len(oRecordPerson.value("company.phone")) > 0 Then
421 strHTML = strHTML + "<li>" + oRecordPerson.value("company.phone") + " (" + Database.Classes("company").LocalName + ")<br/></li>"
422 End If
423 ElseIf oInspector.Controls.GetValue("company", 0) > 0 Then
424 Set oRecordCompany = New LDE.Record
425 oRecordCompany.Open Database.Classes("company"), oInspector.Controls.GetValue("company", 0), "phone"
426
427 If VBA.Len(oRecordCompany.value("phone")) > 0 Then
428 strHTML = strHTML + "<li> " + oRecordCompany.value("phone") + " (" + Database.Classes("company").LocalName + ")<br/></li>"
429 End If
430 End If
431 strHTML = strHTML + "</ul>"
432 End If
433
434
435 GetContactInfo = strHTML
436
437 Exit Function
438ErrorHandler:
439 Call UI.ShowError("ActionPad_Helpdesk.GetContactOptions")
440 GetContactInfo = ""
441End Function
442
443' ##SUMMARY This sub opens up Outlook and a template when clicking on the email address _
444 in actionpad.
445
446Public Function EmailContact()
447 On Error GoTo ErrorHandler
448
449 Dim oInspector As Lime.Inspector
450 Set oInspector = Application.ActiveInspector
451
452 If Globals.VerifyInspector("helpdesk", oInspector) Then
453
454 Dim docTemplate As LDE.DocumentTemplate
455
456 'Email template with chosen language
457 Select Case Application.Locale
458 Case "sv":
459 Set docTemplate = Database.Templates.Lookup("Ärende-Ta kontakt", lkLookupDocumentTemplateByName)
460 Case "en-us", "en_us":
461 Set docTemplate = Database.Templates.Lookup("Helpdesk contact", lkLookupDocumentTemplateByName)
462 Case "fi":
463 Set docTemplate = Database.Templates.Lookup("Helpdesk contact", lkLookupDocumentTemplateByName)
464 Case "no"
465 Set docTemplate = Database.Templates.Lookup("Bekreft mottatt henvendelse", lkLookupDocumentTemplateByName)
466 Case Else:
467 Set docTemplate = Database.Templates.Lookup("Helpdesk contact", lkLookupDocumentTemplateByName)
468 End Select
469
470 If docTemplate Is Nothing Then
471 Lime.MessageBox (Localize.GetText("Actionpad_Helpdesk", "i_notemplate"))
472 Exit Function
473 End If
474
475 Dim oAddin As Object
476 Dim oMailer As Lime.IMailer
477 For Each oAddin In Application.AddIns
478 If oAddin.ProgId = "LimeOutlookXP.Addin" Then
479 Set oMailer = oAddin.Object
480 End If
481 Next oAddin
482
483 If oMailer Is Nothing Then
484 Call Lime.MessageBox(Localize.GetText("Actionpad_Helpdesk", "i_nooutlook"))
485 Else
486 oMailer.SendTemplate docTemplate, oInspector.Record, oInspector.Class.Fields("person"), Context:=ActiveInspector
487 End If
488 End If
489
490 Exit Function
491ErrorHandler:
492 Call UI.ShowError("ActionPad_Helpdesk.EmailContact")
493End Function
494
495' ##SUMMARY Saves changes made in actionpad.
496Public Function SaveNew() As Boolean
497 On Error GoTo ErrorHandler
498 Dim oInspector As Lime.Inspector
499
500 Set oInspector = Application.ActiveInspector
501
502 On Error GoTo ErrorSave
503 If (oInspector.Record.State And lkRecordStateNew) = lkRecordStateNew Then
504 Call oInspector.Save(True)
505 End If
506 GoTo SaveOK
507ErrorSave:
508 Lime.MessageBox (Err.Description)
509 SaveNew = False
510 Exit Function
511SaveOK:
512 SaveNew = True
513
514 Exit Function
515ErrorHandler:
516 Call UI.ShowError("Actionpad_Helpdesk.TrySave")
517
518 SaveNew = False
519End Function
520
521Public Sub NewHistory(ByVal strType As String)
522 On Error GoTo ErrorHandler
523 Dim oInspector As Lime.Inspector
524
525 If ActionPad_Helpdesk.SaveNew() Then
526 Set oInspector = ActionPadTools.NewInspectorFromInspector("history")
527 Call oInspector.Controls.SelectOption("type", strType)
528 Call oInspector.Controls.SetFocus("note")
529 oInspector.Modified = False
530 End If
531
532 Exit Sub
533ErrorHandler:
534 Call UI.ShowError("Actionpad_Helpdesk.NewHistory")
535End Sub
536
537' ##SUMMARY Hides and shows links on the actionpad depending on the status of the case.
538
539Public Function ShowLinks(link As String) As Boolean
540 On Error GoTo ErrorHandler
541 Dim oInspector As Lime.Inspector
542 Dim bShow As Boolean
543
544 bShow = False
545
546 If ActiveInspector.Class.Name = "helpdesk" Then
547 Set oInspector = Application.ActiveInspector
548 Else
549 If Not ActiveInspector.ParentInspector Is Nothing Then
550 If ActiveInspector.ParentInspector.Class.Name = "helpdesk" Then
551 Set oInspector = ActiveInspector.ParentInspector
552 Else
553 ShowLinks = False
554 Exit Function
555 End If
556 Else
557 ShowLinks = False
558 Exit Function
559 End If
560 End If
561
562 If Globals.VerifyInspector("helpdesk", oInspector, False) Then
563 Select Case link
564
565 'Case "take" modified on 7-12-2015 by /THO in response to solution improvement ticket
566 Case "take"
567 If VBA.IsNull(oInspector.Controls.GetValue("enddate")) Then
568 If VBA.IsNull(oInspector.Controls.GetValue("coworker", Null)) = True Then
569 bShow = True
570 End If
571 End If
572
573 Case "takeover"
574 If VBA.IsNull(oInspector.Controls.GetValue("enddate")) Then
575 If Not ActiveUser.Record Is Nothing Then
576 If oInspector.Controls.GetValue("coworker", 0) > 0 Then
577 If ActiveUser.Record.ID <> oInspector.Controls.GetValue("coworker", 0) Then
578 bShow = True
579 End If
580 End If
581 End If
582 End If
583
584 Case "done"
585 If VBA.IsNull(oInspector.Controls.GetValue("enddate")) Then
586 bShow = True
587 End If
588
589 Case "undo"
590 If Not VBA.IsNull(oInspector.Controls.GetValue("enddate")) Then
591 bShow = True
592 End If
593
594 Case "putback"
595 If VBA.IsNull(oInspector.Controls.GetValue("enddate")) Then
596 If oInspector.Controls.GetValue("coworker", 0) > 0 Then
597 bShow = True
598 End If
599 End If
600
601 ' ## Activate - The button is only visible if the helpdesk is assigned to activeuser and there is a value in "Next action".
602
603 Case "activate"
604 If Not ActiveUser.Record Is Nothing Then
605 If oInspector.Controls.GetValue("coworker", 0) > 0 Then
606 If ActiveUser.Record.ID = oInspector.Controls.GetValue("coworker", 0) Then
607 If VBA.IsNull(oInspector.Controls.GetValue("nextactiondate", Null)) = False Then
608 bShow = True
609 End If
610 End If
611 End If
612 End If
613 End Select
614 End If
615
616 ShowLinks = bShow
617
618 Exit Function
619ErrorHandler:
620 Call UI.ShowError("Actionpad_Helpdesk.ShowLinks")
621 ShowLinks = False
622End Function
623
624' #SUMMARY Creates an email based on a history
625
626Public Sub SendMailIncludingHistory()
627 On Error GoTo ErrorHandler
628
629 Dim oInspector As Lime.Inspector
630 Dim oControls As Lime.Controls
631 Dim oAddin As Object
632 Dim oNewMail As Object
633
634 Dim strBody As String
635 Dim strSubject As String
636
637 Dim oFilter As LDE.Filter
638 Dim oView As LDE.View
639 Dim oRecords As LDE.Records
640 Dim oRecord As LDE.Record
641
642 Set oInspector = Application.ActiveInspector
643
644 If Globals.VerifyInspector("helpdesk", oInspector, True) Then
645 If Globals.TryToSaveInspector(oInspector) = False Then
646 Application.MousePointer = 0
647 Exit Sub
648 End If
649 Set oControls = oInspector.Controls
650
651 'Find Addin
652 Set oAddin = Application.FindAddIn("LimeOutlookXP.Addin")
653
654 If oAddin Is Nothing Then
655 Call Lime.MessageBox(Localize.GetText("addins", "e_mailaddinnotfound"), VBA.vbOKOnly Or VBA.vbError)
656 Exit Sub
657 End If
658
659 'Subject
660 strSubject = "[" + oInspector.Record.Text("helpdeskno") + "] - " + oInspector.Record.Text("title")
661
662 'Body
663 strBody = strBody & "<body><html>"
664 strBody = strBody & "<br><b>" & oControls.GetText("company") & "</b><br>"
665 strBody = strBody & "<b>" & oControls.GetText("person") & ":</b> "
666
667 If oControls.GetValue("person", 0) > 0 Then
668 If VBA.Len(oControls.GetText("person.phone", "")) > 0 Then
669 strBody = strBody & oControls.GetText("person.phone") & ", "
670 End If
671 If VBA.Len(oControls.GetText("person.mobilephone", "")) > 0 Then
672 strBody = strBody & oControls.GetText("person.mobilephone") & ", "
673 End If
674 If VBA.Len(oControls.GetText("person.email", "")) > 0 Then
675 strBody = strBody & "<a href=""mailto:"
676 strBody = strBody & oControls.GetText("person.email") & """>" & oControls.GetText("person.email") & "<br><br>"
677 End If
678
679
680 End If
681
682 strBody = strBody & "<a href=""" & Application.CreateURL(oControls.Record, , lkCreateUrlTypeLink) & """ >" & oControls.GetText("helpdeskno") & "</a>" & "<br><br>"
683
684 'strBody = strBody & "<span style=""font-size:12;font-weight:bold;"">Kommentar:</span><br><br><br>"
685
686 strBody = strBody & "<span style=""font-size:12;font-weight:bold;"">" + Localize.LocalFieldName("helpdesk", "title") + "</span><br>"
687 strBody = strBody & oControls.GetText("title") & "<br><br>"
688
689 strBody = strBody & "<span style=""font-size:12;font-weight:bold;"">" + Localize.LocalFieldName("helpdesk", "description") + "</span><br>"
690 strBody = strBody & VBA.Replace(oControls.GetText("description"), vbLf, "<br>") & "<br><br>"
691
692 'Historynotes
693 Set oFilter = New LDE.Filter
694 Call oFilter.AddCondition("helpdesk", lkOpEqual, oControls.Record.ID)
695 If oFilter.HitCount(Database.Classes("history")) > 0 Then
696 Set oView = New LDE.View
697 Call oView.Add("date", lkSortDescending)
698 Call oView.Add("coworker")
699 Call oView.Add("person")
700 Call oView.Add("type")
701 Call oView.Add("note")
702
703 Set oRecords = New LDE.Records
704 Call oRecords.Open(Database.Classes("history"), oFilter, oView, 20)
705
706 strBody = strBody & "<span style=""font-size:12;font-weight:bold;"">" + Database.Classes("history").LocalName + "</span><br>"
707
708 For Each oRecord In oRecords
709 strBody = strBody & "<div><span style=""font-size:12;font-weight:bold; position:relative;left:20px;width:150px;margin-right:15px;"">" & oRecord.Text("date") & " ["
710 strBody = strBody & oRecord.Text("type") & "] - "
711 strBody = strBody & oRecord.Text("person") & " ("
712 strBody = strBody & oRecord.Text("coworker") & ")</span></div>"
713 strBody = strBody & "<div><span style=""font-size:12;"">" & VBA.Replace(oRecord.Text("note"), vbLf, "<br>") & "</span></div><br>"
714 Next oRecord
715
716 End If
717
718 strBody = strBody & "</body></html>"
719
720
721 ' Create and open email
722 Set oNewMail = CreateObject("LimeOutlookXP.NewMail")
723 oNewMail.Recipients = ""
724 oNewMail.Subject = strSubject
725 oNewMail.htmlbody = strBody
726 oNewMail.Context = oInspector.Record
727 oNewMail.Display
728 End If
729
730 Exit Sub
731ErrorHandler:
732 Call UI.ShowError("Helpdesk.SendMailIncludingHistory")
733End Sub
734
735' ##SUMMARY Opens a dialog with all active coworkers. When choosing the coworker, the coworker is entered in the coworker field
736Public Sub Delegate()
737 On Error GoTo ErrorHandler
738
739 Dim oInspector As Lime.Inspector
740 Set oInspector = ActiveInspector
741
742 If Globals.VerifyInspector("helpdesk", oInspector) And ActionPad_Helpdesk.SaveNew() Then
743 Dim oDialog As New Lime.Dialog
744 Dim oFilter As New LDE.Filter
745
746 Call oFilter.AddCondition("inactive", lkOpEqual, 0)
747 Call oFilter.AddCondition("idcoworker", lkOpNotEqual, oInspector.Controls.GetValue("coworker"))
748 Call oFilter.AddOperator(lkOpAnd)
749 If Not ActiveUser.Record Is Nothing Then
750 Call oFilter.AddCondition("idcoworker", lkOpNotEqual, ActiveUser.Record.ID)
751 Call oFilter.AddOperator(lkOpAnd)
752 End If
753
754 oDialog.Property("class") = Database.Classes("coworker")
755 oDialog.Property("filter") = oFilter
756 oDialog.Property("AutoLoad") = True
757 oDialog.Property("SingleSelect") = True
758 Dim oPool As LDE.Pool
759
760 If oDialog.show(lkDialogSearchRecords) = vbCancel Then
761 Exit Sub
762 Else
763 Set oPool = New LDE.Pool
764 Set oPool = oDialog.Property("Pool")
765
766 Dim oRecord As New LDE.Record
767 Dim sNotes As String
768 Call oRecord.Open(Database.Classes("coworker"), VBA.CLng(oPool.value(0)), "idcoworker")
769 Call oInspector.Controls.SetValue("coworker", oRecord.ID)
770 sNotes = " " & oRecord.Description & "."
771
772 Call oInspector.Save(True)
773
774 'Create history
775 Call CreateHelpdeskHistory(oInspector.Record.ID, Localize.GetText("ActionPad_Helpdesk", "t_errand_delegated") & sNotes, True)
776 End If
777 End If
778
779 Exit Sub
780ErrorHandler:
781 Call UI.ShowError("Actionpad_Helpdesk.Delegate")
782End Sub
783
784' ##SUMMARY Call from app to change next action
785Public Sub ParkWithDatepicker(parkeddate As String, deadlinedate As String)
786 On Error GoTo ErrorHandler
787 Dim oInspector As Lime.Inspector
788
789 Set oInspector = Application.ActiveInspector
790
791 If Globals.VerifyInspector("helpdesk", oInspector) And ActionPad_Helpdesk.SaveNew() Then
792 Call oInspector.Controls.SetValue("nextactiondate", parkeddate)
793 Call oInspector.Save(True)
794
795 Dim sNotes As String
796 sNotes = Lime.FormatString(Localize.GetText("app_AccordionHelpdesk", "i_parkfromdatepicker"), parkeddate)
797
798 If VBA.Len(VBA.Trim(sNotes)) > 0 Then
799 Call CreateHelpdeskHistory(oInspector.Record.ID, VBA.Trim(sNotes))
800 End If
801 End If
802
803 Exit Sub
804ErrorHandler:
805 Call UI.ShowError("ActionPad_Helpdesk.ParkWithDatepicker")
806End Sub
807
808' ##SUMMARY Reply to the selected e-mail document in the document tab or reply to the latest e-mail document
809Public Sub ReplyByEmail()
810 On Error GoTo ErrorHandler
811
812 Dim oInspector As Lime.Inspector
813 Dim oAddin As Object
814 Set oInspector = Application.ActiveInspector
815 Dim oDocumentRecord As LDE.Record
816
817 If Globals.VerifyInspector("helpdesk", oInspector, True) Then
818 If Globals.TryToSaveInspector(oInspector) = False Then
819 Application.MousePointer = 0
820 Exit Sub
821 End If
822
823 Set oDocumentRecord = GetEmailDocumentRecord(oInspector)
824
825 If oDocumentRecord Is Nothing Then
826 If VBA.Len(oInspector.Controls.GetValue("email")) = 0 Then
827 Call Lime.MessageBox(Localize.GetText("Actionpad_Helpdesk", "i_noemail"), vbInformation)
828 Exit Sub
829 Else
830 Call ActionPad_Helpdesk.EmailContact
831 End If
832
833 Exit Sub
834 End If
835
836 'Find Addin
837 Set oAddin = Application.FindAddIn("LimeOutlookXP.Addin")
838
839 If oAddin Is Nothing Then
840 Call Lime.MessageBox(Localize.GetText("addins", "e_mailaddinnotfound"), VBA.vbOKOnly Or VBA.vbError)
841 Exit Sub
842 End If
843
844 Call oAddin.ReplyAllMail(oDocumentRecord)
845 End If
846
847 Exit Sub
848ErrorHandler:
849 Call UI.ShowError("ActionPad_Helpdesk.ReplyByEmail")
850End Sub
851
852' ##SUMMARY Returns the Document record when the user reply an e-mail
853Private Function GetEmailDocumentRecord(ByVal oInspector As Lime.Inspector) As LDE.Record
854 On Error GoTo ErrorHandler
855
856 ' The user has selected an e-mail document
857 If Not oInspector.ActiveExplorer Is Nothing Then
858 If oInspector.ActiveExplorer.Class.Name = "document" Then
859 If oInspector.ActiveExplorer.Selection.Count = 1 Then
860 ' Check if the document field exists in the view
861 If oInspector.ActiveExplorer.ActiveItem.Fields.Exists("document") Then
862 If Not oInspector.ActiveExplorer.Selection.Item(1).Record.Document("document") Is Nothing Then
863 If oInspector.ActiveExplorer.Selection.Item(1).Record.Document("document").Extension = "msg" Then
864 Set GetEmailDocumentRecord = ActiveInspector.ActiveExplorer.ActiveItem.Record
865 Exit Function
866 End If
867 End If
868 Else
869 Dim oRecordDocument As New LDE.Record
870 Call oRecordDocument.Open(Database.Classes("document"), oInspector.ActiveExplorer.Selection.Item(1).ID)
871 Set GetEmailDocumentRecord = oRecordDocument
872 Exit Function
873 End If
874 End If
875 End If
876 End If
877
878 ' Find the latest email
879 Dim oFilter As New LDE.Filter
880 Call oFilter.AddCondition("helpdesk", lkOpEqual, oInspector.Record.ID)
881 Call oFilter.AddCondition("document.fileextension", lkOpEqual, "msg")
882 Call oFilter.AddOperator(lkOpAnd)
883
884 If oFilter.HitCount(Database.Classes("document")) = 0 Then
885 Set GetEmailDocumentRecord = Nothing
886 Exit Function
887 End If
888
889 Dim oView As New LDE.View
890 Call oView.Add("createdtime", lkSortDescending)
891 Call oView.Add("document")
892
893 Dim oRecords As New LDE.Records
894 Call oRecords.Open(Database.Classes("document"), oFilter, oView, 1)
895
896 If oRecords.Count = 1 Then
897 Set GetEmailDocumentRecord = oRecords.Item(1)
898 Else
899 Set GetEmailDocumentRecord = Nothing
900 End If
901
902 Exit Function
903ErrorHandler:
904 Set GetEmailDocumentRecord = Nothing
905 Call UI.ShowError("ActionPad_Helpdesk.GetEmailDocumentRecord")
906End Function
907' ##SUMMARY Creates an e-mail to confirm that the ticket has been received, including the active helpdesk ticket number.
908Public Sub ConfirmReceivedHelpdesk()
909 On Error GoTo ErrorHandler
910
911 Dim oInspector As Lime.Inspector
912
913 Set oInspector = ActiveInspector
914
915 If Globals.VerifyInspector("helpdesk", oInspector, True) Then
916 If Globals.TryToSaveInspector(oInspector) = False Then
917 Application.MousePointer = 0
918 Exit Sub
919 End If
920
921 Dim docTemplate As LDE.DocumentTemplate
922
923 Set docTemplate = Database.Templates.Lookup(Localize.GetText("Actionpad_Helpdesk", "t_template_confirm_received"), lkLookupDocumentTemplateByName)
924
925 If docTemplate Is Nothing Then
926 Lime.MessageBox (Localize.GetText("Actionpad_Helpdesk", "i_notemplate"))
927 Exit Sub
928 End If
929
930 Dim oAddin As Object
931 Dim oMailer As Lime.IMailer
932 For Each oAddin In Application.AddIns
933 If oAddin.ProgId = "LimeOutlookXP.Addin" Then
934 Set oMailer = oAddin.Object
935 End If
936 Next oAddin
937
938 If oMailer Is Nothing Then
939 Call Lime.MessageBox(Localize.GetText("Actionpad_Helpdesk", "i_nooutlook"))
940 Else
941 oMailer.SendTemplate docTemplate, oInspector.Record, oInspector.Class.Fields("person"), Context:=ActiveInspector
942 End If
943 End If
944
945 Exit Sub
946ErrorHandler:
947 Call UI.ShowError("ActionPad_Helpdesk.ConfirmReceivedHelpdesk")
948End Sub