Beispiel #1
0
        private int CheckAddToDoListConditions(ApiUser hdUser, string ticket_key, int?project_id)
        {
            int ticketID = 0;

            if (!string.IsNullOrEmpty(ticket_key))
            {
                ticketID = Ticket.GetId(hdUser.OrganizationId, hdUser.DepartmentId, ticket_key);
                if (ticketID == 0)
                {
                    bigWebApps.bigWebDesk.CustomNames _cNames = bigWebApps.bigWebDesk.CustomNames.GetCustomNames(hdUser.OrganizationId, hdUser.DepartmentId);
                    throw new HttpError("Incorrect " + _cNames.Ticket.abbreviatedSingular + " key.");
                }
            }
            if (project_id.HasValue && project_id > 0)
            {
                DataRow rowProjectDetail = bigWebApps.bigWebDesk.Data.Project.SelectDetail(hdUser.OrganizationId, hdUser.DepartmentId, project_id.Value);
                if (rowProjectDetail == null)
                {
                    throw new HttpError(System.Net.HttpStatusCode.NotFound, "Wrong Project Id");
                }
            }
            if (ticketID > 0 && (project_id ?? 0) > 0)
            {
                throw new HttpError("Please set ticket_key or project_id for adding To Do List.");
            }
            return(ticketID);
        }
Beispiel #2
0
        public object Post(POST_Travel request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            if (!instanceConfig.TravelCosts)
            {
                throw new HttpError("Travels is not enabled for this instance.");
            }
            if (request.travel_id > 0)
            {
                DataTable dt = bigWebApps.bigWebDesk.Data.TicketTravelCosts.Select(hdUser.OrganizationId, hdUser.DepartmentId, request.travel_id);
                if (dt == null || dt.Rows.Count == 0)
                {
                    throw new HttpError(HttpStatusCode.NotFound, "Wrong Travel 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;
            int  ticketID = 0;

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

            if (!string.IsNullOrEmpty(request.note))
            {
                note = request.note;
            }

            DateTime date = DateTime.UtcNow;

            if (request.date.HasValue && request.date > DateTime.MinValue)
            {
                date = (DateTime)request.date;
            }
            if (request.travel_id > 0)
            {
                bigWebApps.bigWebDesk.Data.TicketTravelCosts.Update(hdUser.OrganizationId, hdUser.DepartmentId, ticketID, request.account_id, request.start_location ?? string.Empty, request.end_location ?? string.Empty,
                                                                    request.distance, request.distance_rate, date, request.travel_id, HttpUtility.HtmlDecode(note), is_billable, techID, is_technician_payment, request.qb_account_id, request.project_id);
            }
            else
            {
                bigWebApps.bigWebDesk.Data.TicketTravelCosts.Insert(hdUser.OrganizationId, hdUser.DepartmentId, ticketID, request.account_id, request.start_location ?? string.Empty, request.end_location ?? string.Empty,
                                                                    request.distance, request.distance_rate, date, HttpUtility.HtmlDecode(note), is_billable, techID, is_technician_payment, request.qb_account_id, request.project_id);
            }

            return(new HttpResult("", HttpStatusCode.OK));
        }
Beispiel #3
0
        public object Get(GET_Contracts request)
        {
            ApiUser hdUser = request.ApiUser;

            bigWebApps.bigWebDesk.CustomNames _cNames = bigWebApps.bigWebDesk.CustomNames.GetCustomNames(hdUser.OrganizationId, hdUser.DepartmentId);
            int accountID = request.account ?? -1;
            int projectID = request.project ?? 0;

            if (accountID > 0)
            {
                DataRow aRow = bigWebApps.bigWebDesk.Data.Accounts.SelectOne(hdUser.DepartmentId, accountID, hdUser.OrganizationId);
                if (aRow == null)
                {
                    throw new HttpError(HttpStatusCode.NotFound, "Incorrect " + _cNames.Account.FullSingular + " Id.");
                }
                else
                {
                    if (!(bool)aRow["btActive"])
                    {
                        throw new HttpError(HttpStatusCode.NotFound, _cNames.Account.FullSingular + " Is Inactive.");
                    }
                }
            }
            if (projectID > 0)
            {
                DataRow pRow = bigWebApps.bigWebDesk.Data.Project.Select(hdUser.OrganizationId, hdUser.DepartmentId, projectID);
                if (pRow == null)
                {
                    throw new HttpError(HttpStatusCode.NotFound, "Incorrect Project Id.");
                }
                else
                {
                    if (pRow.IsNull("Active") || !(bool)pRow["Active"])
                    {
                        throw new HttpError(HttpStatusCode.NotFound, "Project Is Inactive.");
                    }
                }
            }
            DateTime date = DateTime.UtcNow;

            if (request.date.HasValue && request.date > DateTime.MinValue)
            {
                date = (DateTime)request.date;
            }
            return(request.FilteredResult <Contract>(Contracts.GetContracts(hdUser.OrganizationId, hdUser.DepartmentId, accountID, date, projectID)));
        }
Beispiel #4
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));
        }