Beispiel #1
0
        public object Post(FB_Tasks_Create request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            try
            {
                return(FBTasks.CreateTask(hdUser, instanceConfig, request.task_type_id, request.fb_project_id));
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #2
0
        public object Post(FB_Category_Create request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            try
            {
                return(FBCategories.CreateCategory(hdUser, instanceConfig, request.category_id));
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #3
0
        public object Post(QB_Vendor_Create request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckQBOnlineIntegration(instanceConfig);
            try
            {
                return(QBVendors.CreateVendor(hdUser, instanceConfig, request.user_id));
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #4
0
        public object Delete(FB_Staff_Delete request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            try
            {
                FBStaffs.UnlinkFreshBooksStaff(hdUser, request.key);
                return(new HttpResult("", HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #5
0
        public object Post(FB_Projects_Create request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            try
            {
                return(FBProjects.CreateProject(hdUser, instanceConfig, request.project_id, request.fb_staff_id,
                                                request.fb_client_id, request.account_id));
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #6
0
        public object Get(FB_Tasks request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            if (request.project.HasValue)
            {
                return(request.FilteredResult <bigWebApps.bigWebDesk.Data.FBTask>(FBTasks.GetFBTasks(instanceConfig, request.page, request.limit, request.project.Value)));
            }
            else if (!string.IsNullOrEmpty(request.name))
            {
                return(FBTasks.FindFBTask(instanceConfig, request.name));
            }
            throw new HttpError(HttpStatusCode.NotFound, "incorrect id or name");
        }
Beispiel #7
0
        public object Put(FB_Expense_Update request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);
            string          notes          = "";
            int             projectID      = 0;
            int             clientID       = 0;
            string          vendor         = "";
            DateTime        date           = DateTime.MinValue;

            if (request.notes != null)
            {
                notes = request.notes;
            }
            if (request.fb_project_id.HasValue)
            {
                projectID = request.fb_project_id.Value;
            }
            if (request.fb_client_id.HasValue)
            {
                clientID = request.fb_client_id.Value;
            }
            if (request.date.HasValue)
            {
                date = request.date.Value;
            }
            if (request.vendor != null)
            {
                vendor = request.vendor;
            }
            try
            {
                string result = FBExpenses.CreateExpense(hdUser, instanceConfig, request.fb_staff_id, projectID, request.fb_category_id,
                                                         clientID, request.amount, vendor, notes, date, "", request.key);
                if (result == "ok")
                {
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                else
                {
                    throw new HttpError(Utils.ClearString(result));
                }
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #8
0
        public object Delete(Xero_Contact_Unlink request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckXeroIntegration(instanceConfig);
            try
            {
                Xero.UnlinkXeroContact(hdUser.OrganizationId, hdUser.DepartmentId, request.key);
                return(new HttpResult("", HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #9
0
        public object Delete(QB_Expense_Delete request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckQBOnlineIntegration(instanceConfig);
            bool is_travel = request.is_travel ?? false;

            if (request.is_unlink)
            {
                try
                {
                    if (is_travel)
                    {
                        QBExpenses.UnlinkQuickBooksTravel(hdUser, int.Parse(request.key));
                    }
                    else
                    {
                        QBExpenses.UnlinkQuickBooksExpense(hdUser, request.key);
                    }
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                catch (Exception ex)
                {
                    throw new HttpError(Utils.ClearString(ex.Message));
                }
            }
            else
            {
                try
                {
                    if (is_travel)
                    {
                        QBExpenses.DeleteQuickBooksTravel(hdUser, instanceConfig, int.Parse(request.key));
                    }
                    else
                    {
                        QBExpenses.DeleteQuickBooksExpense(hdUser, instanceConfig, request.key);
                    }
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                catch (Exception ex)
                {
                    throw new HttpError(Utils.ClearString(ex.Message));
                }
            }
        }
Beispiel #10
0
        public object Post(FB_Time request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);
            bool            isProjectLog   = false;
            string          notes          = "";
            int             staffID        = 0;
            DateTime        date           = DateTime.MinValue;

            if (request.is_project_log.HasValue)
            {
                isProjectLog = request.is_project_log.Value;
            }
            if (request.notes != null)
            {
                notes = request.notes;
            }
            if (request.fb_staff_id.HasValue)
            {
                staffID = request.fb_staff_id.Value;
            }
            if (request.date.HasValue)
            {
                date = request.date.Value;
            }
            try
            {
                string result = FBTimeEntries.CreateTimeEntry(hdUser, instanceConfig, staffID, request.fb_project_id, request.fb_task_type_id,
                                                              request.hours, notes, date, request.time_id, isProjectLog, 0);
                if (result == "ok")
                {
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                else
                {
                    throw new HttpError(Utils.ClearString(result));
                }
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #11
0
        public object Get(FB_Projects request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            int clientID = 0;

            if (!int.TryParse(request.client, out clientID))
            {
                throw new HttpError(HttpStatusCode.NotFound, "incorrect client id");
            }
            int staffID = 0;

            if (!int.TryParse(request.staff, out staffID))
            {
                throw new HttpError(HttpStatusCode.NotFound, "incorrect staff id");
            }

            return(request.FilteredResult <bigWebApps.bigWebDesk.Data.FBProject>(FBProjects.GetFBProjects(instanceConfig, request.page, request.limit, clientID, staffID)));
        }
Beispiel #12
0
        public object Post(Xero_Invoice_Create request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckXeroIntegration(instanceConfig);
            try
            {
                XeroInvoice xeroInvoice;
                string      result = Xero.CreateInvoice(hdUser.OrganizationId, hdUser.DepartmentId, instanceConfig, instanceConfig.XeroAuthConsumerKey, request.invoice_id, out xeroInvoice,
                                                        instanceConfig.XeroRSAPrivateKey);
                if (result != "ok")
                {
                    throw new HttpError(HttpStatusCode.NotFound, Utils.ClearString(result));
                }
                return(xeroInvoice);
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #13
0
        public object Post(Xero_Bill_Create request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckXeroIntegration(instanceConfig);
            try
            {
                string result = Xero.CreateBill(hdUser.OrganizationId, hdUser.DepartmentId, instanceConfig, instanceConfig.XeroAuthConsumerKey, request.bill_id, instanceConfig.XeroRSAPrivateKey);
                if (result == "ok")
                {
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                else
                {
                    throw new HttpError(Utils.ClearString(result));
                }
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #14
0
        public object Delete(QB_Time_Delete request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckQBOnlineIntegration(instanceConfig);
            bool isProjectLog = false;

            if (request.is_project_log.HasValue)
            {
                isProjectLog = request.is_project_log.Value;
            }
            if (request.is_unlink)
            {
                try
                {
                    QBTimeActivities.UnlinkQuickBooksTimeActivity(hdUser, request.key, isProjectLog);
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                catch (Exception ex)
                {
                    throw new HttpError(Utils.ClearString(ex.Message));
                }
            }
            else
            {
                try
                {
                    QBTimeActivities.DeleteQuickBooksTimeActivity(hdUser, instanceConfig, request.key, isProjectLog);
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                catch (Exception ex)
                {
                    throw new HttpError(Utils.ClearString(ex.Message));
                }
            }
        }
Beispiel #15
0
        public object Post(QB_Bill_Create request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckQBOnlineIntegration(instanceConfig);
            PaymentsService.CheckPaymentEnable(instanceConfig);
            try
            {
                string result = QBBills.CreateBill(hdUser, instanceConfig, request.bill_id);
                if (result == "ok")
                {
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                else
                {
                    throw new HttpError(Utils.ClearString(result));
                }
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #16
0
        public object Post(Xero_Contact_Create request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckXeroIntegration(instanceConfig);
            int user_id    = 0;
            int account_id = 0;

            if (request.user_id.HasValue)
            {
                user_id = request.user_id.Value;
            }
            if (request.account_id.HasValue)
            {
                account_id = request.account_id.Value;
            }
            try
            {
                XeroContact xeroContact;
                string      result = Xero.CreateContact(hdUser.OrganizationId, hdUser.DepartmentId, instanceConfig, instanceConfig.XeroAuthConsumerKey, user_id, account_id, out xeroContact,
                                                        instanceConfig.XeroRSAPrivateKey);
                if (result == "ok")
                {
                    return(xeroContact);
                }
                else
                {
                    throw new HttpError(HttpStatusCode.NotFound, Utils.ClearString(result));
                }
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #17
0
        public object Put(QB_Expense_Update request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckQBOnlineIntegration(instanceConfig);
            int travel_id = 0;

            if (request.travel_id.HasValue)
            {
                travel_id = request.travel_id.Value;
            }
            CheckExpenseAndUpdateQBAccount(hdUser, request.expense_id, request.qb_account_id, travel_id);
            string   notes             = "";
            string   note_internal     = "";
            int      qb_employee_id    = 0;
            int      qb_vendor_id      = 0;
            int      markup            = 0;
            DateTime date              = DateTime.Now;
            bool     overwrite_changes = false;

            if (request.overwrite_changes.HasValue)
            {
                overwrite_changes = request.overwrite_changes.Value;
            }
            if (request.notes != null)
            {
                notes = request.notes;
            }
            if (request.note_internal != null)
            {
                note_internal = request.note_internal;
            }
            if (request.qb_employee_id.HasValue)
            {
                qb_employee_id = request.qb_employee_id.Value;
            }
            if (request.qb_vendor_id.HasValue)
            {
                qb_vendor_id = request.qb_vendor_id.Value;
            }
            if (request.date.HasValue)
            {
                date = request.date.Value;
            }
            if (request.markup.HasValue)
            {
                markup = request.markup.Value;
            }
            bool qb_is_employee = request.qb_is_employee ?? false;
            bool is_billable    = request.is_billable ?? true;

            try
            {
                string result = QBExpenses.CreateExpense(hdUser, instanceConfig, qb_employee_id, request.qb_customer_id, request.qb_service_id, request.qb_account_id,
                                                         qb_is_employee, request.amount, notes, note_internal, date, is_billable, markup, request.expense_id, request.key, request.qb_sync_token, overwrite_changes, qb_vendor_id, travel_id);
                if (result == "ok")
                {
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                else
                {
                    throw new HttpError(Utils.ClearString(result));
                }
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #18
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));
        }
Beispiel #19
0
        public object Put(PutAsset request)
        {
            if (request.id < 1)
            {
                throw new HttpError(HttpStatusCode.NotFound, "Asset not found. Please check Id");
            }

            var req            = base.Request;
            int formKeysCount  = req.FormData.Count;
            int queryKeysCount = req.QueryString.Count;

            if (req.QueryString.GetValues("format") != null)
            {
                queryKeysCount--;
            }

            if (formKeysCount == 0 && queryKeysCount == 0)
            {
                throw new HttpError(HttpStatusCode.NotAcceptable, "No parameters provided to Asset");
            }

            ApiUser         hdUser       = request.ApiUser;
            Instance_Config config       = CheckAssets(hdUser);
            DateTime?       entered_date = null;

            if (request.entered_date.HasValue && request.entered_date > DateTime.MinValue)
            {
                entered_date = request.entered_date.Value.AddHours(-1 * hdUser.TimeZoneOffset);
            }
            System.Data.DataRow drasset = Models.Assets.GetAssetRow(request.ApiUser, request.id);

            if (request.location_id.HasValue && request.location_id.Value > 0 && config.LocationTracking && config.AccountManager)
            {
                int    account_id   = request.account_id ?? hdUser.AccountId;
                string account_name = Models.Account_Details.GetAccountDetails(hdUser, account_id, false).Name;

                var location = Models.Location.GetLocation(hdUser.OrganizationId, hdUser.DepartmentId, request.location_id.Value);
                if (account_id == -1)
                {
                    account_id = 0;
                }
                if (location.AccountId != account_id)
                {
                    throw new HttpError($"Cannot move Asset to LocationId = {request.location_id}! This location don't exists in Account: {account_name} with Account Id: {account_id}.");
                }
            }

            Models.Assets.UpdateAsset(hdUser, request.id, drasset, request.checkout_id, request.owner_id, request.account_id, request.serial_number,
                                      request.category_id,
                                      request.type_id,
                                      request.make_id,
                                      request.model_id,
                                      request.unique1_value,
                                      request.unique2_value,
                                      request.unique3_value,
                                      request.unique4_value,
                                      request.unique5_value,
                                      request.unique6_value,
                                      request.unique7_value,
                                      request.unique_motherboard,
                                      request.unique_bios,
                                      request.name,
                                      request.description,
                                      request.note,
                                      request.location_id,
                                      request.is_bulk,
                                      request.is_force_dublicate,
                                      request.is_active,
                                      request.status_id,
                                      entered_date);
            return(new HttpResult("", HttpStatusCode.OK));
        }
Beispiel #20
0
        public object Put(QB_Time_Update request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckQBOnlineIntegration(instanceConfig);
            bool     isProjectLog      = false;
            bool     overwrite_changes = false;
            string   notes             = "";
            int      qb_employee_id    = 0;
            int      qb_vendor_id      = 0;
            DateTime date = DateTime.Now;

            if (request.is_project_log.HasValue)
            {
                isProjectLog = request.is_project_log.Value;
            }
            if (request.qb_employee_id.HasValue)
            {
                qb_employee_id = request.qb_employee_id.Value;
            }
            if (request.qb_vendor_id.HasValue)
            {
                qb_vendor_id = request.qb_vendor_id.Value;
            }
            if (request.overwrite_changes.HasValue)
            {
                overwrite_changes = request.overwrite_changes.Value;
            }
            if (request.notes != null)
            {
                notes = request.notes;
            }
            if (request.date.HasValue)
            {
                date = request.date.Value;
            }
            decimal time_offset = hdUser.TimeZoneOffset;

            if (request.time_offset.HasValue)
            {
                time_offset = request.time_offset.Value;
            }
            bool is_billable   = request.is_billable ?? true;
            bool is_rate_fixed = request.is_rate_fixed ?? false;

            try
            {
                string result = QBTimeActivities.CreateTimeActivity(hdUser, instanceConfig, qb_employee_id, request.qb_customer_id, request.qb_service_id,
                                                                    request.hours, request.hourly_rate, notes, date, request.time_id, isProjectLog, is_billable, request.start_time, request.stop_time, time_offset, request.key,
                                                                    request.qb_sync_token, overwrite_changes, qb_vendor_id, is_rate_fixed);
                if (result == "ok")
                {
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                else
                {
                    throw new HttpError(Utils.ClearString(result));
                }
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }
Beispiel #21
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));
        }