Пример #1
0
        public object Post(POST_Time_Logs request)
        {
            ApiUser hdUser        = request.ApiUser;
            bool    is_billable   = request.is_billable ?? true;
            bool    is_local_time = request.is_local_time ?? false;
            int     techID        = (request.tech_id > 0 && hdUser.IsTechAdmin) ? request.tech_id : hdUser.UserId;

            bigWebApps.bigWebDesk.Data.Ticket _tktNew = null;
            DateTime?start_date = request.start_date;
            DateTime?stop_date  = request.stop_date;

            if (is_local_time)
            {
                if (request.start_date.HasValue && request.start_date > DateTime.MinValue)
                {
                    start_date = request.start_date.Value.AddHours(-1 * hdUser.TimeZoneOffset);
                }
                if (request.stop_date.HasValue && request.stop_date > DateTime.MinValue)
                {
                    stop_date = request.stop_date.Value.AddHours(-1 * hdUser.TimeZoneOffset);
                }
            }
            string key      = request.ticket_key;
            string response = "";

            if (!string.IsNullOrEmpty(key) && key != "0" && request.project_time_id <= 0)
            {
                Ticket.InputTime(hdUser, Ticket.GetId(hdUser.OrganizationId, hdUser.DepartmentId, key), request.task_type_id, start_date,
                                 stop_date, request.hours, hdUser.TimeZoneOffset, HttpUtility.HtmlDecode(request.note_text), is_billable, request.date, request.ticket_time_id,
                                 techID, ref _tktNew, request.complete, request.remain_hours, request.prepaid_pack_id, string.Empty);
            }
            else
            {
                int accountID = request.account_id != 0 ? request.account_id : -1;
                int projectID = request.project_id > 0 ? request.project_id : -1;
                response = Models.Projects.PostProjectTime(hdUser, accountID, projectID, techID, request.task_type_id, start_date, stop_date, request.hours, hdUser.TimeZoneOffset,
                                                           HttpUtility.HtmlDecode(request.note_text), is_billable, request.date, request.project_time_id, request.prepaid_pack_id, string.Empty, key);
            }
            if (_tktNew != null)
            {
                return(TicketLogRecords.TicketLog(hdUser.OrganizationId, hdUser.DepartmentId, _tktNew.ID, _tktNew.PseudoID));
            }
            return(new HttpResult(response, HttpStatusCode.OK));
        }
Пример #2
0
        public object Post(Posts request)
        {
            ApiUser hdUser = request.ApiUser;
            //v1
            string ticket_key = request.key;

            //v2
            if (!string.IsNullOrEmpty(request.ticket))
            {
                ticket_key = request.ticket;
            }
            request.note_text = request.note_text ?? "";
            int ticketId = Ticket.GetId(hdUser.OrganizationId, hdUser.DepartmentId, ticket_key);

            bigWebApps.bigWebDesk.Data.Ticket _tktNew = null;
            Ticket.Response(hdUser, ticketId, request.note_text, request.is_waiting_on_response, ref _tktNew, request.files, request.user_id);
            if (_tktNew != null)
            {
                return(TicketLogRecords.TicketLog(hdUser.OrganizationId, hdUser.DepartmentId, _tktNew.ID, _tktNew.PseudoID));
            }
            return(new HttpResult("", HttpStatusCode.OK));
        }
Пример #3
0
        public object Post(Ticket_Actions request)
        {
            ApiUser hdUser = request.ApiUser;

            bigWebApps.bigWebDesk.Data.Ticket _tktNew = null;
            if (request.action == "response" || !string.IsNullOrEmpty(request.note_text))
            {
                Ticket.Response(hdUser, Ticket.GetId(hdUser.OrganizationId, hdUser.DepartmentId, request.key), request.note_text, request.is_waiting_on_response, ref _tktNew, request.files, request.user_id);
                //return new HttpResult("", HttpStatusCode.OK);
            }
            else if (request.action == "workpad")
            {
                string workpad = HttpUtility.HtmlDecode(request.workpad + "");
                Ticket.UpdateTicketWorkpad(hdUser.OrganizationId, Ticket.GetId(hdUser.OrganizationId, hdUser.DepartmentId, request.key), workpad);
                //return new HttpResult("", HttpStatusCode.OK);
            }
            else if (request.action == "note" && hdUser.IsTechAdmin)
            {
                string note = request.note + "";
                Ticket.UpdateTechNote(hdUser.OrganizationId, Ticket.GetId(hdUser.OrganizationId, hdUser.DepartmentId, request.key), note);
                //return new HttpResult("", HttpStatusCode.OK);
            }
            else if (request.action == "add_tech" || request.tech_id > 0)
            {
                Ticket.AttachAlternateTechnician(hdUser, Ticket.GetId(hdUser.OrganizationId, hdUser.DepartmentId, request.key), request.tech_id);
            }
            else if (request.action == "add_user" || request.user_id > 0)
            {
                Ticket.AttachAlternateUser(hdUser, Ticket.GetId(hdUser.OrganizationId, hdUser.DepartmentId, request.key), request.user_id);
            }

            if (_tktNew != null)
            {
                return(TicketLogRecords.TicketLog(hdUser.OrganizationId, hdUser.DepartmentId, _tktNew.ID, _tktNew.PseudoID));
            }
            return(new HttpResult("", HttpStatusCode.OK));
        }
Пример #4
0
        public object Post(POST_TodoItem request)
        {
            ApiUser hdUser = request.ApiUser;

            CheckToDos(hdUser);
            Guid todoItemId = Guid.Empty;
            Guid todoListId = Guid.Empty;

            if (!string.IsNullOrEmpty(request.task_id) && !Guid.TryParse(request.task_id, out todoItemId))
            {
                return(new HttpResult("", HttpStatusCode.NotFound));
            }
            DataRow plRow = null;

            if (!string.IsNullOrEmpty(request.task_id))
            {
                plRow = bigWebApps.bigWebDesk.Data.ToDo.SelectToDoItem(hdUser.OrganizationId, hdUser.DepartmentId, todoItemId.ToString());
                if (plRow == null)
                {
                    throw new HttpError(HttpStatusCode.NotFound, "Wrong ToDo Task Id");
                }
                todoListId = Guid.Parse(plRow["ToDoListId"].ToString());
            }
            string   text             = (request.text != null ? request.text : "");
            DateTime due_date         = request.due_date ?? DateTime.MinValue;
            decimal  estimated_remain = request.estimated_remain ?? 0;
            int      assigned_id      = request.assigned_id ?? 0;

            if (!string.IsNullOrEmpty(request.task_id))
            {
                bigWebApps.bigWebDesk.Data.ToDo.UpdateToDoItem(hdUser.OrganizationId, todoItemId.ToString(), hdUser.DepartmentId, text, hdUser.UserId, assigned_id,
                                                               estimated_remain, due_date, true, request.title, request.notify ?? true);
                if (request.time_hours.HasValue)
                {
                    Instance_Config instanceConfig = new Instance_Config(hdUser);
                    if (!instanceConfig.TimeTracking)
                    {
                        throw new HttpError("Time Tracking is not enabled for this instance.");
                    }
                    if (!plRow.IsNull("TimeInvoiceId"))
                    {
                        throw new HttpError("Time log associated with this ToDo Item has been invoiced and can not be edited.");
                    }
                    if (!plRow.IsNull("TimeBillId"))
                    {
                        throw new HttpError("Time log associated with this ToDo Item has been paid and can not be edited.");
                    }
                    decimal time_hours        = request.time_hours.Value;
                    bool    time_is_billable  = request.time_is_billable ?? true;
                    int     time_task_type_id = request.time_task_type_id ?? 0;
                    if (!plRow.IsNull("TimeId"))
                    {
                        if (time_hours < 0)
                        {
                            bigWebApps.bigWebDesk.Data.ToDo.UnlinkToDoTime(hdUser.OrganizationId, hdUser.DepartmentId, int.Parse(plRow["TimeId"].ToString()), !plRow.IsNull("ProjectId"));
                        }
                        else if (time_hours == 0)
                        {
                            if (!plRow.IsNull("ProjectId"))
                            {
                                Models.Projects.DeleteProjectTime(hdUser, int.Parse(plRow["TimeId"].ToString()));
                            }
                            else
                            {
                                Models.Ticket.DeleteTicketTime(hdUser, int.Parse(plRow["TimeId"].ToString()));
                            }
                        }
                        else
                        {
                            if (!plRow.IsNull("ProjectId"))
                            {
                                DataRow rowProjectTime = bigWebApps.bigWebDesk.Data.Project.SelectProjectTimeByID(hdUser.OrganizationId, hdUser.DepartmentId, int.Parse(plRow["TimeId"].ToString()));
                                if (rowProjectTime == null)
                                {
                                    throw new HttpError(System.Net.HttpStatusCode.NotFound, "Project Time Id Not Found");
                                }
                                int techID = 0;
                                if (!rowProjectTime.IsNull("UserId"))
                                {
                                    techID = int.Parse(rowProjectTime["UserId"].ToString());
                                }
                                DateTime?start_date = null;
                                if (!rowProjectTime.IsNull("StartTimeUTC"))
                                {
                                    start_date = (DateTime)rowProjectTime["StartTimeUTC"];
                                }
                                DateTime?stop_date = null;
                                if (!rowProjectTime.IsNull("StopTimeUTC"))
                                {
                                    stop_date = (DateTime)rowProjectTime["StopTimeUTC"];
                                }
                                Models.Projects.EditProjectTime(hdUser, -1, int.Parse(plRow["ProjectId"].ToString()), techID, time_task_type_id, start_date, stop_date,
                                                                time_hours, hdUser.TimeZoneOffset, rowProjectTime["Note"].ToString(), time_is_billable, (DateTime)rowProjectTime["Date"], int.Parse(plRow["TimeId"].ToString()),
                                                                int.Parse(rowProjectTime["ContractID"].ToString()));
                            }
                            else
                            {
                                DataRow tlRow = bigWebApps.bigWebDesk.Data.Tickets.SelectTicketTimeByID(hdUser.OrganizationId, hdUser.DepartmentId, int.Parse(plRow["TimeId"].ToString()));
                                if (tlRow == null)
                                {
                                    throw new HttpError(HttpStatusCode.NotFound, "No data found");
                                }
                                DateTime?start_date = null;
                                if (!tlRow.IsNull("StartTime"))
                                {
                                    start_date = (DateTime)tlRow["StartTime"];
                                }
                                DateTime?stop_date = null;
                                if (!tlRow.IsNull("StopTime"))
                                {
                                    stop_date = (DateTime)tlRow["StopTime"];
                                }
                                decimal?remainHours = null;
                                if (!tlRow.IsNull("HoursRemaining"))
                                {
                                    remainHours = decimal.Parse(tlRow["HoursRemaining"].ToString());
                                }
                                int contract_id = 0;
                                if (!tlRow.IsNull("ContractID"))
                                {
                                    contract_id = int.Parse(tlRow["ContractID"].ToString());
                                }
                                Ticket.EditTime(hdUser, int.Parse(plRow["TimeId"].ToString()), start_date, stop_date, time_is_billable, (DateTime)tlRow["Date"], time_hours, time_task_type_id,
                                                tlRow["Note"].ToString(), remainHours, int.Parse(tlRow["Complete"].ToString()), contract_id, tlRow["ContractName"].ToString());
                            }
                        }
                    }
                    else
                    {
                        int techID = (request.assigned_id.HasValue && request.assigned_id.Value > 0 && hdUser.IsAdmin) ? request.assigned_id.Value : hdUser.UserId;
                        if (!plRow.IsNull("ProjectId"))
                        {
                            Models.Projects.PostProjectTime(hdUser, -1, int.Parse(plRow["ProjectId"].ToString()), techID, time_task_type_id, null, null, time_hours, hdUser.TimeZoneOffset,
                                                            string.Empty, time_is_billable, DateTime.UtcNow, 0, 0, todoItemId.ToString(), string.Empty);
                        }
                        else
                        {
                            bigWebApps.bigWebDesk.Data.Ticket _tktNew = null;
                            Ticket.InputTime(hdUser, int.Parse(plRow["ListTicketId"].ToString()), time_task_type_id, null, null, time_hours, hdUser.TimeZoneOffset, string.Empty,
                                             time_is_billable, DateTime.UtcNow, 0, techID, ref _tktNew, 0, 0, 0, todoItemId.ToString());
                        }
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(request.list_id) && !Guid.TryParse(request.list_id, out todoListId))
                {
                    throw new HttpError(HttpStatusCode.NotFound, "Wrong ToDo List Id");
                }
                if (!string.IsNullOrEmpty(request.list_id))
                {
                    CheckToDoList(hdUser, todoListId);
                }
                else
                {
                    int ticketID  = CheckAddToDoListConditions(hdUser, request.ticket_key, request.project_id);
                    int projectID = (request.project_id ?? 0);

                    string name   = "Main";
                    string filter = string.Empty;

                    if (ticketID > 0)
                    {
                        filter = "TicketId = " + ticketID.ToString();
                    }
                    else if (projectID > 0)
                    {
                        filter = "ProjectId = " + projectID.ToString();
                    }
                    else
                    {
                        name = "My ToDo's";

                        filter = "ProjectId IS NULL AND TicketId IS NULL";
                    }

                    DataTable table = bigWebApps.bigWebDesk.Data.ToDo.SelectToDoListsByUser(hdUser.OrganizationId, hdUser.DepartmentId, assigned_id);

                    foreach (DataRow row in table.Select(filter))
                    {
                        string toDoListName = (string)row["ToDoListName"];
                        if (string.Compare(name, toDoListName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            todoListId = (Guid)row["ToDoListId"];
                            break;
                        }
                    }

                    if (todoListId == Guid.Empty)
                    {
                        todoListId = Guid.NewGuid();

                        bigWebApps.bigWebDesk.Data.ToDo.InsertToDoList(hdUser.OrganizationId, todoListId.ToString(), hdUser.DepartmentId, name, string.Empty, ticketID, projectID);
                    }
                }
                bigWebApps.bigWebDesk.Data.ToDo.InsertToDoItem(hdUser.OrganizationId, hdUser.DepartmentId, text, todoListId.ToString(), hdUser.UserId, assigned_id,
                                                               estimated_remain, due_date, true, request.title, request.notify ?? true);
            }
            if (request.notify ?? false)
            {
                string userName = string.Empty;
                if (!string.IsNullOrEmpty(hdUser.FirstName) && !string.IsNullOrEmpty(hdUser.LastName))
                {
                    userName = hdUser.FirstName + " " + hdUser.LastName;
                }
                bigWebApps.bigWebDesk.Data.ToDo.SendToDoEmail(hdUser.OrganizationId, hdUser.InstanceId, hdUser.UserId, userName, hdUser.LoginEmail, todoListId.ToString(), text,
                                                              due_date, estimated_remain, assigned_id, request.title);
            }
            return(new HttpResult("", HttpStatusCode.OK));
        }
Пример #5
0
        public static string PostProjectTime(ApiUser User, int AccountId, int ProjectId, int TechId, int TaskTypeId, DateTime?start_date, DateTime?stop_date,
                                             decimal Hours, int HoursOffset, string NoteText, bool is_billable, DateTime?date, int projectTimeID, int?contract_id, string toDoItemId, string ticket_key)
        {
            string response = "";

            if (ProjectId > 0 && bigWebApps.bigWebDesk.Data.Project.SelectDetail(User.OrganizationId, User.DepartmentId, ProjectId) == null)
            {
                throw new HttpError(System.Net.HttpStatusCode.NotFound, "Wrong Project Id");
            }
            DateTime dateTimeLog = DateTime.UtcNow;

            if (date.HasValue && date > DateTime.MinValue)
            {
                dateTimeLog = (DateTime)date;
            }
            string  contractName  = Contracts.CheckAccountContract(User, AccountId, contract_id ?? 0, dateTimeLog, 0, projectTimeID, ProjectId);
            string  _taskTypeName = string.Empty;
            DataRow _rowTaskType  = bigWebApps.bigWebDesk.Data.TaskType.SelectTaskType(User.OrganizationId, User.DepartmentId, TaskTypeId);

            if (_rowTaskType == null)
            {
                throw new HttpError(System.Net.HttpStatusCode.NotFound, "No Task Types found for TaskTypeId=" + TaskTypeId.ToString() + ".");
            }
            _taskTypeName = _rowTaskType["TaskTypeName"].ToString();
            if ((Hours > 999) || (Hours < -999))
            {
                throw new HttpError("Hours value should be between -999 and 999.");
            }
            DateTime startDate = DateTime.MinValue;
            DateTime stopDate  = DateTime.MinValue;

            if (start_date.HasValue && start_date > DateTime.MinValue)
            {
                startDate = start_date.Value;//.AddHours(HoursOffset);
            }
            if (stop_date.HasValue && stop_date > DateTime.MinValue)
            {
                stopDate = stop_date.Value;//.AddHours(HoursOffset);
            }
            else if (startDate != DateTime.MinValue)
            {
                stopDate = startDate.AddHours((double)Hours);
            }
            if (Hours == 0 && startDate > DateTime.MinValue && stopDate > DateTime.MinValue)
            {
                Hours = Convert.ToDecimal((stopDate - startDate).TotalHours);
            }
            if (projectTimeID > 0)
            {
                EditProjectTime(User, AccountId, ProjectId, TechId, TaskTypeId, start_date, stop_date, Hours, HoursOffset, NoteText + "", is_billable, date, projectTimeID, contract_id);
                if (!string.IsNullOrEmpty(ticket_key) && ticket_key != "0")
                {
                    int tktId = Ticket.GetId(User.OrganizationId, User.DepartmentId, ticket_key);
                    if (tktId > 0)
                    {
                        int _timeLogId = bigWebApps.bigWebDesk.Data.Project.MoveProjectTimeToTicket(User.OrganizationId, User.DepartmentId, projectTimeID, tktId);
                        response = _timeLogId.ToString();
                        string _hoursFull = "";
                        if (Hours >= 1)
                        {
                            _hoursFull = ((int)Hours).ToString();
                            if ((int)Hours == 1)
                            {
                                _hoursFull += " hour ";
                            }
                            else
                            {
                                _hoursFull += " hours ";
                            }
                        }

                        string _minutes = string.Format("{0:00}", Hours * 60 % 60).TrimStart('0');

                        if (!string.IsNullOrEmpty(_minutes))
                        {
                            _hoursFull += _minutes;
                            if (_minutes == "1")
                            {
                                _hoursFull += " minute";
                            }
                            else
                            {
                                _hoursFull += " minutes";
                            }
                        }

                        if (!string.IsNullOrEmpty(_hoursFull))
                        {
                            _hoursFull = "(" + _hoursFull.Trim() + ")";
                        }
                        string sysGeneratedText = User.FullName + " logged " + Hours.ToString("0.00") + " hours " + _hoursFull + " as " + _taskTypeName + " task type";
                        if (contract_id > 0)
                        {
                            sysGeneratedText += " on " + contractName + " contract";
                        }
                        sysGeneratedText += ".";
                        CustomNames _cNames = CustomNames.GetCustomNames(User.OrganizationId, User.DepartmentId);
                        bigWebApps.bigWebDesk.Data.Ticket _tkt = new bigWebApps.bigWebDesk.Data.Ticket(User.OrganizationId, User.DepartmentId, tktId, true);
                        bigWebApps.bigWebDesk.Data.Ticket.InsertLogMessage(User.OrganizationId, User.DepartmentId, tktId, TechId, "Log Entry", NoteText, sysGeneratedText, string.Empty, string.Empty, string.Empty, _timeLogId);
                        if (NoteText.Length > 0)
                        {
                            sysGeneratedText = NoteText + "<br><br>" + sysGeneratedText;
                        }
                        _tkt.TicketLogs.Insert(0, new bigWebApps.bigWebDesk.Data.Ticket.LogEntry(TechId, User.LoginEmail, User.FirstName, User.LastName, DateTime.UtcNow, _cNames.Technician.FullSingular + " Costs", sysGeneratedText));
                        foreach (bigWebApps.bigWebDesk.Data.Ticket.TicketAssignee ta in _tkt.Technicians)
                        {
                            ta.SendResponse = true;
                        }
                        foreach (bigWebApps.bigWebDesk.Data.Ticket.TicketAssignee ta in _tkt.Users)
                        {
                            ta.SendResponse = true;
                        }
                        bigWebApps.bigWebDesk.Data.NotificationRules.RaiseNotificationEvent(User.OrganizationId, User.DepartmentId, TechId,
                                                                                            bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.EnterLaborCosts, _tkt, null, null);
                    }
                }
                return(response);
            }
            bigWebApps.bigWebDesk.Data.Project.InsertTimeRecord(User.OrganizationId, User.DepartmentId, ProjectId, TechId,
                                                                TaskTypeId, dateTimeLog, Hours, NoteText + "",
                                                                startDate,
                                                                stopDate,
                                                                DateTime.UtcNow,
                                                                TechId, HoursOffset, bigWebApps.bigWebDesk.Data.Logins.SelectTechHourlyRate(User.OrganizationId, User.DepartmentId, TechId, TaskTypeId),
                                                                ProjectId == -1 ? AccountId : -1, is_billable, contract_id ?? 0, toDoItemId);
            return(response);
        }
Пример #6
0
        public object Put(Ticket_Actions request)
        {
            ApiUser hdUser = request.ApiUser;

            request.note_text = request.note_text ?? "";
            request.status    = request.status ?? "";
            request.status    = request.status.Replace("_", "");
            int ticket_id = Ticket.GetId(hdUser.OrganizationId, hdUser.DepartmentId, request.key);

            var _tktOld = new bigWebApps.bigWebDesk.Data.Ticket(hdUser.OrganizationId, hdUser.DepartmentId, ticket_id, true);

            bigWebApps.bigWebDesk.Data.Ticket _tktNew = null;
            Ticket.Status status;

            if (Enum.TryParse <Ticket.Status>(request.status, true, out status))
            {
                if (_tktOld.TicketStatus != status)
                {
                    switch (status)
                    {
                    case Ticket.Status.OnHold:
                        Ticket.OnHold(hdUser, ticket_id, request.note_text, ref _tktNew);
                        break;

                    case Ticket.Status.PartsOnOrder:
                        throw new HttpError(HttpStatusCode.NotFound, "Incorrect status");

                    case Ticket.Status.Closed:
                        Ticket.Close(hdUser, ticket_id, request.note_text, request.is_send_notifications, request.resolved, request.resolution_id, request.confirmed, request.confirm_note, ref _tktNew);
                        break;

                    case Ticket.Status.Open:
                        Ticket.ReOpen(hdUser, ticket_id, request.note_text, ref _tktNew);
                        break;
                    }
                }
            }

            bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent tktEvent = bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.TicketResponse;

            if (request.action == "transfer" || (request.user_id > 0 && _tktOld.UserId != request.user_id))
            {
                Ticket.TransferToUser(hdUser, ticket_id, request.user_id, request.note_text, ref _tktNew);
                tktEvent = bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.ChangeEndUser;
            }

            if (request.action == "transfer" || (request.tech_id > 0 && _tktOld.TechnicianId != request.tech_id))
            {
                Ticket.TransferToTech(hdUser, ticket_id, request.tech_id, request.note_text, request.keep_attached, ref _tktNew);
                if (_tktNew.TechnicianId == hdUser.UserId)
                {
                    bigWebApps.bigWebDesk.Data.Ticket.UpdateNewPostIcon(hdUser.OrganizationId, hdUser.DepartmentId, ticket_id, hdUser.UserId, false);
                }
                else if (_tktNew.TechnicianId != hdUser.UserId)
                {
                    bigWebApps.bigWebDesk.Data.Ticket.UpdateNewPostIcon(hdUser.OrganizationId, hdUser.DepartmentId, ticket_id, hdUser.UserId, true);
                }
                tktEvent = bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.TransferTicket;
            }

            if (request.priority_id > 0 && _tktOld.PriorityId != request.priority_id)
            {
                Ticket.UpdatePriority(hdUser.OrganizationId, hdUser.DepartmentId, ticket_id, request.priority_id);
                tktEvent = bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.ChangePriority;
            }

            /** not implemented
             *  need to add parameters LocationId, Transfermode, is_transfer_user_to_account
             *  look page https://support.sherpadesk.com/home/accts/assignticket.aspx
             *  Transfermode:
             *                          0 - This ticket only (default)
             *                          1 - Only unassigned tickets for this user
             *                          2 - All tickets for this user
             */
            if (request.account_id != 0 && _tktOld.AccountId != request.account_id)
            {
                Ticket.UpdateAccount(hdUser.OrganizationId, hdUser.DepartmentId, ticket_id, request.account_id, request.account_location_id, 0, request.is_transfer_user_to_account);
                tktEvent = bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.ChangeAccount;
            }
            if (request.location_id != 0 && _tktOld.LocationId != request.location_id)
            {
                Ticket.UpdateLocation(hdUser.OrganizationId, hdUser.DepartmentId, ticket_id, request.location_id);
                tktEvent = bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.ChangeLocation;
            }
            if (request.project_id != 0 && _tktOld.ProjectId != request.project_id)
            {
                Ticket.UpdateProject(hdUser.OrganizationId, hdUser.DepartmentId, ticket_id, request.project_id);
                tktEvent = bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.ChangeProject;
            }
            if (request.level_id > 0 && _tktOld.Level != request.level_id)
            {
                Ticket.UpdateLevel(hdUser.OrganizationId, hdUser.DepartmentId, ticket_id, request.level_id, hdUser.UserId, request.note_text);
                tktEvent = bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.ChangeLevel;
            }
            if (request.class_id > 0 && _tktOld.ClassId != request.class_id)
            {
                Ticket.UpdateClass(hdUser.OrganizationId, hdUser.DepartmentId, ticket_id, request.class_id);
                tktEvent = bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.ChangeClass;
            }

            if (tktEvent != bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.TicketResponse)
            {
                _tktNew = _tktNew ?? new bigWebApps.bigWebDesk.Data.Ticket(hdUser.OrganizationId, hdUser.DepartmentId, ticket_id, true);
                bigWebApps.bigWebDesk.Data.NotificationRules.RaiseNotificationEvent(hdUser.OrganizationId, hdUser.DepartmentId, hdUser.UserId, tktEvent, _tktNew);
            }

            if (!string.IsNullOrEmpty(request.action))
            {
                switch (request.action.ToLower())
                {
                case "pickup": Ticket.PickUp(hdUser, ticket_id, request.note_text, ref _tktNew);
                    break;

                case "confirm": Ticket.Confirm(hdUser, ticket_id, request.note_text, ref _tktNew);
                    break;

                case "escalate":
                    Ticket.EscalateTicketByLevel(hdUser, ticket_id, true);
                    return(getTicket(hdUser, request.key, false));

                    break;

                case "deescalate":
                    Ticket.EscalateTicketByLevel(hdUser, ticket_id, false);
                    return(getTicket(hdUser, request.key, false));

                    break;
                }
            }
            if (_tktNew != null)
            {
                return(TicketLogRecords.TicketLog(hdUser.OrganizationId, hdUser.DepartmentId, _tktNew.ID, _tktNew.PseudoID));
            }
            return(new HttpResult("", HttpStatusCode.OK));
        }
Пример #7
0
        public object Post(POST_Expense request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            if (!instanceConfig.MiscCosts)
            {
                throw new HttpError("Expenses is not enabled for this instance.");
            }
            if (!string.IsNullOrEmpty(request.expense_id))
            {
                DataRow plRow = bigWebApps.bigWebDesk.Data.Expense.SelectExpense(hdUser.OrganizationId, hdUser.DepartmentId, request.expense_id);
                if (plRow == null)
                {
                    throw new HttpError(HttpStatusCode.NotFound, "Wrong Expense Id");
                }
            }
            bool is_billable           = request.is_billable ?? true;
            bool is_technician_payment = request.is_technician_payment ?? true;
            int  techID = request.tech_id > 0 ? request.tech_id : hdUser.UserId;

            bigWebApps.bigWebDesk.CustomNames _cNames = bigWebApps.bigWebDesk.CustomNames.GetCustomNames(hdUser.OrganizationId, hdUser.DepartmentId);
            int ticketID = 0;

            if (!string.IsNullOrEmpty(request.ticket_key))
            {
                ticketID = Ticket.GetId(hdUser.OrganizationId, hdUser.DepartmentId, request.ticket_key);
                if (ticketID == 0)
                {
                    throw new HttpError("Incorrect " + _cNames.Ticket.abbreviatedSingular + " key.");
                }
            }
            string categoryName = string.Empty;

            if (!string.IsNullOrEmpty(request.category_id))
            {
                DataRow ecRow = bigWebApps.bigWebDesk.Data.Expense.SelectExpenseCategory(hdUser.OrganizationId, hdUser.DepartmentId, request.category_id);
                if (ecRow == null)
                {
                    throw new HttpError(HttpStatusCode.NotFound, "Wrong Category Id");
                }
                else
                {
                    if (!(bool)ecRow["Active"])
                    {
                        throw new HttpError(HttpStatusCode.NotFound, "Category Is Inactive");
                    }
                    categoryName = ecRow["Name"].ToString();
                }
            }
            string logNote        = "";
            string additionalNote = "";
            string note           = "";
            string note_internal  = "";

            if (!string.IsNullOrEmpty(request.note))
            {
                note = request.note;
            }
            if (!string.IsNullOrEmpty(request.note_internal))
            {
                note_internal = request.note_internal;
            }
            if (ticketID > 0)
            {
                logNote = "Misc Cost ";
                if (!string.IsNullOrEmpty(request.expense_id))
                {
                    logNote += "edited";
                }
                else
                {
                    logNote += "added";
                }
                logNote += " " + instanceConfig.Currency + request.amount.ToString("0.00") + (note.Length > 0 ? " - "
                                                                                              + note : string.Empty);
                if (!string.IsNullOrEmpty(categoryName))
                {
                    logNote += "<br>Category: " + categoryName + ".";
                }
                if (!string.IsNullOrEmpty(request.vendor))
                {
                    logNote += "<br>Vendor: " + request.vendor + ".";
                }
                logNote += " Billable: " + is_billable.ToString() + ".";
                logNote += " " + _cNames.Technician.FullSingular + " Payment: " + is_technician_payment.ToString() + ".";
                if (request.markup > 0)
                {
                    logNote += "<br>Markup: " + request.markup + "%.";
                }
                logNote += "<br>The Misc Cost was ";
                if (!string.IsNullOrEmpty(request.expense_id))
                {
                    logNote += "edited";
                }
                else
                {
                    logNote += "added";
                }
                logNote += " by " + hdUser.FirstName + " " + hdUser.LastName + ".";
            }
            else
            {
                if (techID != hdUser.UserId)
                {
                    additionalNote = " The expense was ";
                    if (!string.IsNullOrEmpty(request.expense_id))
                    {
                        additionalNote += "edited";
                    }
                    else
                    {
                        additionalNote += "input";
                    }
                    additionalNote += " by " + hdUser.FirstName + " " + hdUser.LastName + ".";
                }
            }
            string   vendor = (request.vendor != null ? request.vendor : "");
            DateTime date   = DateTime.UtcNow;

            if (request.date.HasValue && request.date > DateTime.MinValue)
            {
                date = (DateTime)request.date;
            }
            if (!string.IsNullOrEmpty(request.expense_id))
            {
                bigWebApps.bigWebDesk.Data.Expense.UpdateExpense(hdUser.OrganizationId, hdUser.DepartmentId, request.expense_id, ticketID, request.account_id,
                                                                 request.project_id, techID, request.amount, HttpUtility.HtmlDecode(note), HttpUtility.HtmlDecode(note_internal) + additionalNote, vendor, is_billable,
                                                                 request.markup, request.category_id, request.qb_account_id, date, is_technician_payment);
            }
            else
            {
                bigWebApps.bigWebDesk.Data.Expense.InsertExpense(hdUser.OrganizationId, hdUser.DepartmentId, ticketID, request.account_id,
                                                                 request.project_id, techID, request.amount, HttpUtility.HtmlDecode(note), HttpUtility.HtmlDecode(note_internal) + additionalNote, vendor, is_billable,
                                                                 request.markup, request.category_id, request.qb_account_id, date, is_technician_payment);
            }
            if (ticketID > 0)
            {
                bigWebApps.bigWebDesk.Data.Ticket _tkt = new bigWebApps.bigWebDesk.Data.Ticket(hdUser.OrganizationId, hdUser.DepartmentId, ticketID, true);
                _tkt.TicketLogs.Insert(0, new bigWebApps.bigWebDesk.Data.Ticket.LogEntry(hdUser.UserId, hdUser.LoginEmail, hdUser.FirstName, hdUser.LastName, DateTime.UtcNow, "Misc Costs", logNote));
                bigWebApps.bigWebDesk.Data.NotificationRules.RaiseNotificationEvent(hdUser.OrganizationId, hdUser.DepartmentId, hdUser.UserId,
                                                                                    bigWebApps.bigWebDesk.Data.NotificationRules.TicketEvent.EnterMiscCosts, _tkt);
            }
            return(new HttpResult("", HttpStatusCode.OK));
        }