Exemple #1
0
        public virtual IEnumerable createAP(PXAdapter adapter)
        {
            UploadFileRevision file = PXSelectJoin <UploadFileRevision,
                                                    InnerJoin <UploadFile,
                                                               On <UploadFileRevision.fileID, Equal <UploadFile.fileID>,
                                                                   And <UploadFileRevision.fileRevisionID, Equal <UploadFile.lastRevisionID> > >,
                                                               InnerJoin <NoteDoc,
                                                                          On <NoteDoc.fileID, Equal <UploadFile.fileID> > > >,
                                                    Where <NoteDoc.noteID, Equal <Required <CRSMEmail.noteID> >,
                                                           And <UploadFile.name, Like <pdfExtension> > >,
                                                    OrderBy <Desc <UploadFileRevision.createdDateTime> > > .Select(Base, Base.Emails.Current.NoteID);

            string url = null;

            if (file != null)
            {
                string rooturl;

                if (HttpContext.Current == null)
                {
                    rooturl = string.Empty;
                }

                var applicationpath = string.IsNullOrEmpty(HttpContext.Current.Request.ApplicationPath)
                                        ? string.Empty
                                        : HttpContext.Current.Request.ApplicationPath + "/";
                rooturl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + applicationpath;

                url = string.Concat(rooturl != null ? rooturl : string.Empty, HandlerURL, file.FileID.GetValueOrDefault(Guid.Empty).ToString("D"));

                CRSMEmail email = Base.Emails.Current;

                APInvoiceEntryPXInhExt graph = PXGraph.CreateInstance <APInvoiceEntryPXInhExt>();
                graph.Clear();
                APInvoice doc = (APInvoice)graph.Document.Cache.CreateInstance();
                doc.GetExtension <APInvoiceExt>().UsrFileURL = url;
                doc.LineCntr = 0;
                TryFillValuesFromPDF(graph.Document.Cache, doc, Base.Emails.Cache, email);
                doc = graph.Document.Insert(doc);

                (email).Selected = false;
                CRSMEmail copy = PXCache <CRSMEmail> .CreateCopy(email);

                CRActivity newActivity = (CRActivity)graph.Caches[typeof(CRActivity)].Insert();

                copy.BAccountID = newActivity.BAccountID;
                copy.ContactID  = newActivity.ContactID;
                copy.RefNoteID  = newActivity.RefNoteID;
                copy.MPStatus   = MailStatusListAttribute.Processed;
                copy.Exception  = null;
                PXRefNoteSelectorAttribute.EnsureNotePersistence(Base, Base.entityFilter.Current.Type, Base.entityFilter.Current.RefNoteID);
                copy = Base.Emails.Update(copy);
                Base.Save.Press();

                PXNoteAttribute.CopyNoteAndFiles(Base.Emails.Cache, Base.Emails.Current, graph.Document.Cache, doc);
                PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);
            }
            return(adapter.Get());
        }
        public virtual IEnumerable relate(PXAdapter adapter)
        {
            bool lint = entityFilter.AskExt() == WebDialogResult.OK && entityFilter.VerifyRequired();

            if (lint)
            {
                PXCache       cache            = this.Caches <CRSMEmail>();
                RelatedEntity relatedEntity    = entityFilter.Current;
                EntityHelper  helper           = new EntityHelper(this);
                Type          entityType       = PXBuildManager.GetType(relatedEntity.Type, false);
                object        row              = helper.GetEntityRow(entityType, relatedEntity.RefNoteID);
                Type          graphType        = helper.GetPrimaryGraphType(row, false);
                Type          actualEntityType = PXSubstManager.Substitute(entityType, graphType);
                object        actualRow        = helper.GetEntityRow(actualEntityType, relatedEntity.RefNoteID);
                PXGraph       graph            = PXGraph.CreateInstance(graphType);
                graph.Caches[actualEntityType].Current = actualRow;
                foreach (PXResult <CRSMEmail, EMailAccount, EPView> email in SelectedList())
                {
                    ((CRSMEmail)email).Selected = false;
                    CRSMEmail copy = PXCache <CRSMEmail> .CreateCopy(email);

                    CRActivity newActivity = (CRActivity)graph.Caches[typeof(CRActivity)].Insert();

                    copy.BAccountID = newActivity.BAccountID;
                    copy.ContactID  = newActivity.ContactID;
                    copy.RefNoteID  = newActivity.RefNoteID;
                    copy.MPStatus   = MailStatusListAttribute.Processed;
                    copy.Exception  = null;
                    PXRefNoteSelectorAttribute.EnsureNotePersistence(this, entityFilter.Current.Type, entityFilter.Current.RefNoteID);
                    copy = (CRSMEmail)cache.Update(copy);
                }
                Save.Press();
            }
            else
            {
                entityFilter.Ask(Messages.Warning, Messages.SelectRecord, MessageButtons.OK);
            }

            Emails.Cache.IsDirty = false;
            Emails.Cache.Clear();
            Emails.Cache.ClearQueryCacheObsolete();
            Emails.View.RequestRefresh();
            return(adapter.Get());
        }