2018-06-23 05:31:09 +00:00
|
|
|
package connectwise
|
|
|
|
|
|
|
|
import (
|
2018-06-23 05:35:42 +00:00
|
|
|
"encoding/json"
|
2018-06-23 05:31:09 +00:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2018-07-07 00:26:11 +00:00
|
|
|
//TimeEntry is a struct to hold the unmarshaled JSON data when making a call to the Time API
|
2018-06-23 05:35:42 +00:00
|
|
|
type TimeEntry struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Company struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Identifier string `json:"identifier"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Info struct {
|
|
|
|
CompanyHref string `json:"company_href"`
|
|
|
|
MobileGUID string `json:"mobileGuid"`
|
|
|
|
} `json:"_info"`
|
|
|
|
} `json:"company"`
|
|
|
|
ChargeToID int `json:"chargeToId"`
|
|
|
|
ChargeToType string `json:"chargeToType"`
|
|
|
|
Member struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Identifier string `json:"identifier"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Info struct {
|
|
|
|
MemberHref string `json:"member_href"`
|
|
|
|
ImageHref string `json:"image_href"`
|
|
|
|
} `json:"_info"`
|
|
|
|
} `json:"member"`
|
|
|
|
LocationID int `json:"locationId"`
|
|
|
|
BusinessUnitID int `json:"businessUnitId"`
|
|
|
|
WorkType struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Info struct {
|
|
|
|
WorkTypeHref string `json:"workType_href"`
|
|
|
|
} `json:"_info"`
|
|
|
|
} `json:"workType"`
|
|
|
|
WorkRole struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Info struct {
|
|
|
|
WorkRoleHref string `json:"workRole_href"`
|
|
|
|
} `json:"_info"`
|
|
|
|
} `json:"workRole"`
|
|
|
|
TimeStart string `json:"timeStart"`
|
|
|
|
TimeEnd string `json:"timeEnd"`
|
|
|
|
HoursDeduct float64 `json:"hoursDeduct"`
|
|
|
|
ActualHours float64 `json:"actualHours"`
|
|
|
|
BillableOption string `json:"billableOption"`
|
|
|
|
Notes string `json:"notes"`
|
|
|
|
AddToDetailDescriptionFlag bool `json:"addToDetailDescriptionFlag"`
|
|
|
|
AddToInternalAnalysisFlag bool `json:"addToInternalAnalysisFlag"`
|
|
|
|
AddToResolutionFlag bool `json:"addToResolutionFlag"`
|
|
|
|
EmailResourceFlag bool `json:"emailResourceFlag"`
|
|
|
|
EmailContactFlag bool `json:"emailContactFlag"`
|
|
|
|
EmailCcFlag bool `json:"emailCcFlag"`
|
|
|
|
HoursBilled float64 `json:"hoursBilled"`
|
|
|
|
EnteredBy string `json:"enteredBy"`
|
|
|
|
DateEntered string `json:"dateEntered"`
|
|
|
|
MobileGUID string `json:"mobileGuid"`
|
|
|
|
HourlyRate float64 `json:"hourlyRate"`
|
|
|
|
TimeSheet struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Info struct {
|
|
|
|
TimeSheetHref string `json:"timeSheet_href"`
|
|
|
|
} `json:"_info"`
|
|
|
|
} `json:"timeSheet"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
Info struct {
|
|
|
|
LastUpdated string `json:"lastUpdated"`
|
|
|
|
UpdatedBy string `json:"updatedBy"`
|
|
|
|
ChargeToMobileGUID string `json:"chargeToMobileGuid"`
|
|
|
|
} `json:"_info"`
|
2018-06-25 18:54:10 +00:00
|
|
|
CustomFields []struct {
|
2018-06-23 05:39:02 +00:00
|
|
|
ID int
|
|
|
|
Caption string
|
|
|
|
Type string
|
|
|
|
EntryMethod string
|
|
|
|
NumberOfDecimals int
|
|
|
|
Value string
|
|
|
|
}
|
2018-06-23 05:35:42 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 00:26:11 +00:00
|
|
|
//GetTimeEntryByID expects a time entry ID and will return a pointer to a TimeEntry struct
|
2018-07-07 00:29:53 +00:00
|
|
|
func (cw *Site) GetTimeEntryByID(timeEntryID int) (*TimeEntry, error) {
|
2018-07-08 21:16:59 +00:00
|
|
|
req := cw.NewRequest(fmt.Sprintf("/time/entries/%d", timeEntryID), "GET", nil)
|
2018-07-07 23:18:59 +00:00
|
|
|
err := req.Do()
|
2018-07-06 03:20:52 +00:00
|
|
|
if err != nil {
|
2018-07-07 23:18:59 +00:00
|
|
|
return nil, fmt.Errorf("request failed for %s: %s", req.RestAction, err)
|
2018-07-06 03:20:52 +00:00
|
|
|
}
|
2018-06-23 05:31:09 +00:00
|
|
|
|
2018-07-07 23:18:59 +00:00
|
|
|
timeEntry := &TimeEntry{}
|
|
|
|
err = json.Unmarshal(req.Body, timeEntry)
|
2018-07-06 03:20:52 +00:00
|
|
|
if err != nil {
|
2018-07-06 14:37:53 +00:00
|
|
|
return nil, fmt.Errorf("failed to unmarshal body into struct: %s", err)
|
2018-07-06 03:20:52 +00:00
|
|
|
}
|
2018-06-23 05:31:09 +00:00
|
|
|
|
2018-07-07 23:18:59 +00:00
|
|
|
return timeEntry, nil
|
2018-06-23 05:31:09 +00:00
|
|
|
}
|