public static int InsertEvent(Guid OrgID, int DeptId, int CreatedByUserId, NotificationRules.TicketEvent tktEvent, string ObjectStateNew, string ObjectStateOld, FileItem[] EventFiles, int ScheduledTicketId, DateTime RunTime)
 {
     SqlParameter _pId=new SqlParameter("@Id", SqlDbType.Int);
     _pId.Direction=ParameterDirection.InputOutput;
     _pId.Value=DBNull.Value;
     SqlParameter _pObjectStateNew = new SqlParameter("@ObjectStateNew", SqlDbType.NText);
     if (ObjectStateNew.Length > 0) _pObjectStateNew.Value = ObjectStateNew;
     else _pObjectStateNew.Value = DBNull.Value;
     SqlParameter _pObjectStateOld = new SqlParameter("@ObjectStateOld", SqlDbType.NText);
     if (ObjectStateOld.Length > 0) _pObjectStateOld.Value = ObjectStateOld;
     else _pObjectStateOld.Value = DBNull.Value;
     SqlParameter _pScheduledTicketId = new SqlParameter("@ScheduledTicketId", SqlDbType.Int);
     if (ScheduledTicketId != 0) _pScheduledTicketId.Value = ScheduledTicketId;
     else _pScheduledTicketId.Value = DBNull.Value;
     SqlParameter _pRunTime = new SqlParameter("@RunTime", SqlDbType.SmallDateTime);
     if (RunTime == DateTime.MinValue) _pRunTime.Value = DBNull.Value;
     else _pRunTime.Value = RunTime;
     UpdateData("sp_UpdateNotificationEventsQueue", new SqlParameter[] { _pId, new SqlParameter("@DId", DeptId), new SqlParameter("@CreatedByUserId", CreatedByUserId), new SqlParameter("@EventType", (int)tktEvent), _pObjectStateNew, _pObjectStateOld, _pScheduledTicketId, _pRunTime}, OrgID);
     int _id = (int)_pId.Value;
     if (EventFiles == null) return _id;
     foreach (FileItem _file in EventFiles) InsertFile(OrgID, DeptId, _id, _file);
     return _id;
 }
Exemple #2
0
 public static void UpdateFiles(Guid OrgID, int DeptID, int TicketId, System.IO.FileInfo[] files, FileItem[] savedfiles)
 {
     FileItem[] _fArr = Tickets.SelectFilesToArray(DeptID, TicketId);
     foreach (FileItem _f1 in _fArr)
     {
         bool _toDelete = true;
         foreach (FileItem _f2 in savedfiles)
         {
             if (_f1.Name == _f2.Name)
             {
                 _toDelete = false;
                 break;
             }
         }
         if (!_toDelete) continue;
         Tickets.DeleteFile(OrgID, DeptID, TicketId, _f1.ID);
     }
     foreach (System.IO.FileInfo _file in files)
     {
         System.IO.FileStream _fstream = _file.OpenRead();
         byte[] _data = new byte[Convert.ToInt32(_fstream.Length)];
         _fstream.Read(_data, 0, _data.Length);
         Tickets.InsertFile(DeptID, TicketId, _file.Name, Convert.ToInt32(_file.Length), _data);
         _fstream.Close();
     }
 }
 public static int InsertFile(Guid OrgID, int DeptId, int NotificationEventsQueueId, FileItem EventFile)
 {
     SqlParameter _pId = new SqlParameter("@Id", SqlDbType.Int);
     _pId.Direction = ParameterDirection.InputOutput;
     _pId.Value = DBNull.Value;
     SqlParameter _pFileData = new SqlParameter("@FileData", SqlDbType.Image);
     _pFileData.Value = EventFile.Data;
     UpdateData("sp_UpdateNotificationEventsQueueFile", new SqlParameter[] { _pId, new SqlParameter("@DId", DeptId), new SqlParameter("@NotificationEventsQueueId", NotificationEventsQueueId), new SqlParameter("@FileName", EventFile.Name), new SqlParameter("@FileSize", EventFile.Size), _pFileData }, OrgID);
     return (int)_pId.Value;
 }
 public static int InsertFile(int DeptId, int NotificationEventsQueueId, FileItem EventFile)
 {
     return InsertFile(Guid.Empty, DeptId, NotificationEventsQueueId, EventFile);
 }
 public static int InsertEvent(Guid OrgID, int DeptId, int CreatedByUserId, NotificationRules.TicketEvent tktEvent, string ObjectState, FileItem[] EventFiles)
 {
     return InsertEvent(OrgID, DeptId, CreatedByUserId, tktEvent, ObjectState, string.Empty, EventFiles, 0, DateTime.MinValue);
 }
 public static FileItem[] SelectNotificationEventFilesToArray(Guid orgID, int DeptID, int ScheduledTicketId)
 {
     DataTable _dt = SelectNotificationEventFiles(orgID, DeptID, ScheduledTicketId);
     FileItem[] _arr = new FileItem[_dt.Rows.Count];
     for (int i = 0; i < _dt.Rows.Count; i++) _arr[i] = new FileItem((int)_dt.Rows[i]["Id"], _dt.Rows[i]["FileName"].ToString(), (int)_dt.Rows[i]["FileSize"], (DateTime)_dt.Rows[i]["dtUpdated"], !_dt.Rows[i].IsNull("FileData") ? (byte[])_dt.Rows[i]["FileData"] : null);
     return _arr;
 }
 public static int InsertEvent(int DeptId, int CreatedByUserId, NotificationRules.TicketEvent tktEvent, string ObjectState, FileItem[] EventFiles)
 {
     return InsertEvent(Guid.Empty, DeptId, CreatedByUserId, tktEvent, ObjectState, EventFiles);
 }
 public static int RaiseNotificationEvent(int DeptID, int UserId, int ScheduledTicketId, DateTime RunTime, FileItem[] tktFiles)
 {
     NotificationEventsQueue.DeleteEvents(Guid.Empty, DeptID, ScheduledTicketId);
     return RaiseNotificationEvent(Guid.Empty, DeptID, UserId, TicketEvent.NewTicket, null, null, ScheduledTicketId, RunTime, tktFiles);
 }
 public static int RaiseNotificationEvent(Guid OrgID, int DeptID, int UserId, TicketEvent tktEvent, Ticket tkt, Ticket oldTkt, int ScheduledTicketId, DateTime RunTime, FileItem[] tktFiles)
 {
     XmlSerializer _serializer = new XmlSerializer(typeof(Ticket));
     string _objStateNew = string.Empty;
     if (tkt != null)
     {
         TextWriter _stream = new StringWriter();
         _serializer.Serialize(_stream, tkt);
         _objStateNew = _stream.ToString();
         _stream.Close();
     }
     string _objStateOld = string.Empty;
     if (oldTkt != null)
     {
         TextWriter _stream = new StringWriter();
         _serializer.Serialize(_stream, oldTkt);
         _objStateOld = _stream.ToString();
         _stream.Close();
     }
     return NotificationEventsQueue.InsertEvent(OrgID, DeptID, UserId, tktEvent, _objStateNew, _objStateOld, tktFiles, ScheduledTicketId, RunTime);
 }
 public static int RaiseNotificationEvent(Guid OrgId, int DeptID, int UserId, TicketEvent tktEvent, Ticket tkt, Ticket oldTkt, FileItem[] tktFiles)
 {
     return RaiseNotificationEvent(OrgId, DeptID, UserId, tktEvent, tkt, oldTkt, 0, DateTime.MinValue, tktFiles);
 }
 public static int RaiseNotificationEvent(int DeptID, int UserId, TicketEvent tktEvent, Ticket tkt, Ticket oldTkt, FileItem[] tktFiles)
 {
     return RaiseNotificationEvent(Guid.Empty, DeptID, UserId, tktEvent, tkt, oldTkt, tktFiles);
 }
Exemple #12
0
        internal static object SendInvoice(ApiUser hdUser, string invoice_id, string recipients, bool isPDFOnly = false)
        {
            Guid   organizationId = hdUser.OrganizationId;
            int    departmentId   = hdUser.DepartmentId;
            int    userId         = hdUser.UserId;
            string Email          = hdUser.LoginEmail;
            string userName       = hdUser.FullName;
            string department     = hdUser.DepartmentName;

            Models.Invoice invoice    = GetInvoice(organizationId, departmentId, invoice_id, false);
            int            AccountId  = invoice.AccountId;
            List <int>     intUserIds = new List <int>();

            string[] emails = recipients.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();
            recipients         = "";
            invoice.recipients = AccountUsers.GetAccountUsers(organizationId, departmentId, invoice.AccountId);
            foreach (string email in emails)
            {
                if (!Utils.IsValidEmail(email))
                {
                    continue;
                }

                bool        isAccountingContact = true;
                int         userID    = 0;
                string      new_email = "";
                AccountUser user      = invoice.recipients.Find(r => r.Email.ToLower() == email.ToLower());
                if (user != null)
                {
                    isAccountingContact = user.AccountingContact;
                    userID    = user.Id;
                    new_email = user.Email;
                }
                else
                {
                    userId              = bigWebApps.bigWebDesk.Data.Accounts.InsertUserIntoAccount(hdUser.OrganizationId, hdUser.DepartmentId, AccountId, email, 0, false);
                    new_email           = email;
                    isAccountingContact = false;
                }
                if (!isAccountingContact)
                {
                    bigWebApps.bigWebDesk.Data.Accounts.UpdateAccountContact(hdUser.OrganizationId, hdUser.DepartmentId, AccountId, userID, true);
                }
                recipients += new_email + ";";
            }

            int    ProjectId = invoice.ProjectId;
            int    invoiceID = invoice.Id.Value;
            string subject   = invoice.Customer + " | Invoice #" + invoiceID;
            string from      = "\"" + userName + " - " + department + "\"<" + Email + ">";

            if (!string.IsNullOrWhiteSpace(recipients))
            {
                Instance_Config instanceConfig = new Models.Instance_Config(hdUser);
                string          currency       = string.IsNullOrWhiteSpace(instanceConfig.Currency) ? "$" : instanceConfig.Currency;
                try
                {
                    string filename     = "Invoice-" + invoiceID.ToString() + ".pdf";
                    string logoURL      = string.Empty;
                    string logoImageUrl = Files.GetOrganizationLargeLogoUrl(organizationId);
                    if (!String.IsNullOrEmpty(logoImageUrl))
                    {
                        logoURL = logoImageUrl;
                    }
                    logoImageUrl = Files.GetInstanceLargeLogoUrl(hdUser.InstanceId);
                    if (!String.IsNullOrEmpty(logoImageUrl))
                    {
                        logoURL = logoImageUrl;
                    }
                    byte[] pdfBytes = null;
                    string body     = "";
                    try
                    {
                        pdfBytes = bigWebApps.bigWebDesk.Data.Invoice.ExportPDF(organizationId, hdUser.InstanceId, departmentId, userId, invoiceID, "https://app.sherpadesk.com", currency,
                                                                                instanceConfig.Names.tech.a, instanceConfig.Names.ticket.a, instanceConfig.ProjectTracking, instanceConfig.Names.user.a, instanceConfig.QBUseQBInvoiceNumber, logoURL);
                        if (isPDFOnly)
                        {
                            var sfile = new System.IO.MemoryStream(pdfBytes);
                            return(new BWA.bigWebDesk.Api.Services.FilesService.FileResult(sfile, "application/pdf", filename));
                        }
                        body = bigWebApps.bigWebDesk.Data.Invoice.ExportHtml(organizationId, hdUser.InstanceId, departmentId, userId, invoiceID, "https://app.sherpadesk.com", currency, instanceConfig.Names.tech.a,
                                                                             instanceConfig.Names.ticket.a, instanceConfig.ProjectTracking, instanceConfig.Names.user.a, instanceConfig.QBUseQBInvoiceNumber);
                    }
                    catch
                    {
                        throw new HttpError(HttpStatusCode.NotFound, "Cannot create invoice with provided data.");
                    }
                    MailNotification _mail_notification = new MailNotification(organizationId, departmentId, userId, from, recipients, subject, body);
                    if (pdfBytes != null)
                    {
                        bigWebApps.bigWebDesk.Data.FileItem[] _files = new bigWebApps.bigWebDesk.Data.FileItem[1];
                        _files[0] = new bigWebApps.bigWebDesk.Data.FileItem(0, filename, pdfBytes.Length, DateTime.Now, string.Empty, pdfBytes);
                        _mail_notification.AttachedFiles = _files;
                    }
                    string _return_string = _mail_notification.Commit(true);
                }
                catch
                {
                    throw new HttpError(HttpStatusCode.NotFound, "Email error.");
                }
            }
            else
            {
                throw new HttpError(HttpStatusCode.NotFound, "No recepients selected.");
            }
            return(invoice);
        }