public virtual void ImportStatement(PX.SM.FileInfo aFileInfo, bool doRedirect)
        {
            bool             isFormatRecognized = false;
            IStatementReader reader             = this.CreateReader();

            if (reader != null && reader.IsValidInput(aFileInfo.BinData))
            {
                reader.Read(aFileInfo.BinData);
                List <CABankTranHeader> imported;
                reader.ExportToNew(aFileInfo, this, out imported);
                if (imported != null && doRedirect)
                {
                    CABankTranHeader last = (imported != null && imported.Count > 0) ? imported[imported.Count - 1] : null;
                    if (this.Header.Current == null || (last != null &&
                                                        (this.Header.Current.CashAccountID != last.CashAccountID || this.Header.Current.RefNbr != last.RefNbr)))
                    {
                        this.Header.Current = this.Header.Search <CABankTranHeader.cashAccountID, CABankTranHeader.refNbr>(last.CashAccountID, last.RefNbr);
                        throw new PXRedirectRequiredException(this, "Navigate to the uploaded record");
                    }
                }
                isFormatRecognized = true;
            }
            if (!isFormatRecognized)
            {
                throw new PXException(Messages.UploadFileHasUnrecognizedBankStatementFormat);
            }
        }
    protected void exportAttachmnts()
    {
        var order = Base.Document.Current;

        PXLongOperation.StartOperation(Base, () =>
        {
            using (MemoryStream stream = new MemoryStream())
            {
                using (PX.Common.ZipArchive archive = PX.Common.ZipArchive.CreateFrom(stream, false))
                {
                    UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();
                    Guid[] uids = PXNoteAttribute.GetFileNotes(Base.Document.Cache, order);
                    foreach (Guid uid in uids)
                    {
                        PX.SM.FileInfo fileInfo = upload.GetFile(uid);
                        archive.AddFile(fileInfo.Name, fileInfo.BinData);
                    }
                }
                PX.SM.FileInfo info = new PX.SM.FileInfo(
                    string.Format("{0}-{1}-Attachmets.zip", order.OrderType, order.OrderNbr),
                    null, stream.ToArray());
                throw new PXRedirectToFileException(info, true);
            }
        });
    }
Пример #3
0
        public virtual IEnumerable trainFaceRecongnition(PXAdapter adapter)
        {
            Save.Press();

            PXLongOperation.StartOperation(this, delegate()
            {
                IFaceClient client = Trainer.Authenticate(MasterView.Current.FaceApiEndpoint, MasterView.Current.FaceApiSubscriptionKey);
                var trainer        = new Trainer(client, MasterView.Current.FaceApiGroupID);
                bool uploaded      = false;
                foreach (EPEmployee emp in PXSelect <EPEmployee> .Select(this))
                {
                    bool deleted  = false;
                    Person person = null;
                    Guid[] files  = PXNoteAttribute.GetFileNotes(this.Caches[typeof(EPEmployee)], emp);

                    foreach (Guid fileID in files)
                    {
                        var fm            = new PX.SM.UploadFileMaintenance();
                        PX.SM.FileInfo fi = fm.GetFile(fileID);
                        string ext        = System.IO.Path.GetExtension(fi.Name).ToLower();
                        PXTrace.WriteWarning(emp.AcctCD.TrimEnd() + " " + ext);
                        if (ext.IsIn(".png", ".jpg", ".bmp"))
                        {
                            if (!deleted)
                            {
                                var utilities = new Utilities(client, MasterView.Current.FaceApiGroupID);
                                utilities.DeleteEmployee(emp.AcctCD.TrimEnd());
                                deleted = true;
                            }

                            if (person == null)
                            {
                                person = trainer.GetEmployee_CreateIfNonExistent(emp.AcctCD.TrimEnd());
                            }


                            using (var stream = new System.IO.MemoryStream(fi.BinData))
                            {
                                PXTrace.WriteWarning(emp.AcctCD.TrimEnd() + " " + fi.Name + " " + stream.Length);
                                trainer.UploadTrainingImageStream(person, stream);
                                Thread.Sleep(1000);
                                uploaded = true;
                            }
                        }
                    }
                }
                if (uploaded)
                {
                    trainer.InvokeTraining();
                }
            });


            return(adapter.Get());
        }
Пример #4
0
        public void exportAsReport()
        {
            var design = Base.Designs.Current;

            if (design == null)
            {
                return;
            }

            string reportName = _nameRegex.Replace(design.Name ?? "", "");

            if (String.IsNullOrEmpty(reportName))
            {
                reportName = "Report1";
            }

            var report = new Report
            {
                Name      = reportName,
                SchemaUrl = PXUrl.SiteUrlWithPath(),
                Items     =
                {
                    new PageHeaderSection()
                    {
                        Name = "pageHeaderSection1"
                    },
                    new DetailSection()
                    {
                        Name = "detailSection1"
                    },
                    new PageFooterSection()
                    {
                        Name = "pageFooterSection1"
                    }
                }
            };

            var tableByAlias = ConvertTables(report);

            ConvertRelations(report, tableByAlias);
            ConvertParameters(report);
            ConvertFilters(report);
            ConvertGroups(report);
            ConvertSorts(report);

            byte[] data     = SerializeReport(report);
            var    fileInfo = new FileInfo(reportName + ".rpx", null, data);

            throw new PXRedirectToFileException(fileInfo, true);
        }
Пример #5
0
 public static byte[] GetFirstFile(PXCache cache, object row)
 {
     Guid[] guids = PXNoteAttribute.GetFileNotes(cache, row);
     if (guids.Length > 0)
     {
         var            fm = new PX.SM.UploadFileMaintenance();
         PX.SM.FileInfo fi = fm.GetFile(guids[0]);
         return(fi.BinData);
     }
     else
     {
         return(null);
     }
 }
Пример #6
0
    private void SetRecognitionResult(APInvoiceRecognitionEntry graph)
    {
        var fileIdEncoded = Request.QueryString[APInvoiceRecognitionEntry.FileIdParameter];

        if (fileIdEncoded == null)
        {
            return;
        }

        var  fileIdString = HttpUtility.UrlDecode(fileIdEncoded);
        Guid fileId;

        if (!Guid.TryParse(fileIdString, out fileId))
        {
            return;
        }

        var file = graph.GetSystemFile(fileId);

        if (file == null)
        {
            return;
        }

        var fileInfoInMemory = new PX.SM.FileInfo(fileId, file.Name, null, file.Data);

        PXContext.SessionTyped <PXSessionStatePXData>().FileInfo[fileInfoInMemory.UID.ToString()] = fileInfoInMemory;

        var uriEncoded = Request.QueryString[APInvoiceRecognitionEntry.RecognitionUriParameter];

        if (uriEncoded == null)
        {
            return;
        }

        var uriString = HttpUtility.UrlDecode(uriEncoded);
        var uri       = new Uri(uriString, UriKind.RelativeOrAbsolute);

        var recognitionTask = Task.Run(() => graph.InvoiceRecognitionClient.GetRecognitionResult(uri));

        recognitionTask.Wait();

        graph.StoreRecognitionResultIntoSession(recognitionTask.Result, fileIdString);
    }
        public virtual IEnumerable UploadFile(PXAdapter adapter)
        {
            bool doImport = true;

            if (CASetup.Current.ImportToSingleAccount == true)
            {
                CABankTranHeader row = Header.Current;
                if (row == null || Header.Current.CashAccountID == null)
                {
                    throw new PXException(Messages.CashAccountMustBeSelectedToImportStatement);
                }
                else
                {
                    CashAccount acct = PXSelect <CashAccount, Where <CashAccount.cashAccountID, Equal <Required <CashAccount.cashAccountID> > > > .Select(this, row.CashAccountID);

                    if (acct != null && string.IsNullOrEmpty(acct.StatementImportTypeName))
                    {
                        throw new PXException(Messages.StatementImportServiceMustBeConfiguredForTheCashAccount);
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(CASetup.Current.StatementImportTypeName))
                {
                    throw new PXException(Messages.StatementImportServiceMustBeConfiguredInTheCASetup);
                }
            }

            if (Header.Current != null && this.IsDirty == true)
            {
                if (CASetup.Current.ImportToSingleAccount != true)
                {
                    if (Header.Ask(Messages.ImportConfirmationTitle, Messages.UnsavedDataInThisScreenWillBeLostConfirmation, MessageButtons.YesNo) != WebDialogResult.Yes)
                    {
                        doImport = false;
                    }
                }
                else
                {
                    doImport = true;
                }
            }

            if (doImport)
            {
                if (this.NewRevisionPanel.AskExt() == WebDialogResult.OK)
                {
                    CABankTranHeader currHeader      = Header.Current;
                    const string     PanelSessionKey = "ImportStatementProtoFile";
                    PX.SM.FileInfo   info            = PXContext.SessionTyped <PXSessionStatePXData>().FileInfo[PanelSessionKey] as PX.SM.FileInfo;
                    System.Web.HttpContext.Current.Session.Remove(PanelSessionKey);
                    ImportStatement(info, true);
                    Save.Press();
                    CABankTranHeader        newRow = this.Header.Current;
                    List <CABankTranHeader> result = new List <CABankTranHeader>();
                    result.Add(newRow);
                    return(result);
                }
            }
            return(adapter.Get());
        }
Пример #8
0
        public void Process(List <MISC1099EFileProcessingInfo> records, MISC1099EFileFilter filter)
        {
            using (new PXReadBranchRestrictedScope(MarkedBranches))
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    using (StreamWriter sw = new StreamWriter(stream, Encoding.Unicode))
                    {
                        BranchMaint graph = CreateInstance <BranchMaint>();

                        foreach (PXResult <Branch, BranchMaint.BranchBAccount, Contact, Address, LocationExtAddress> transmitter in Payer.Select(filter.MasterBranchID))
                        {
                            TransmitterTRecord trecord      = CreateTransmitterRecord(transmitter, transmitter, transmitter, filter, 0);
                            List <object>      data1099Misc = new List <object> {
                                trecord
                            };

                            List <IGrouping <int?, MISC1099EFileProcessingInfo> > groups = records.GroupBy(rec => rec.PayerBranchID).ToList();
                            foreach (IGrouping <int?, MISC1099EFileProcessingInfo> group in groups)
                            {
                                foreach (PXResult <Branch, BranchMaint.BranchBAccount, Contact, Address, LocationExtAddress> payer in Payer.Select(@group.Key))
                                {
                                    Contact rowShipContact = PXSelectJoin <Contact,
                                                                           InnerJoin <Location, On <Contact.bAccountID, Equal <Location.bAccountID>,
                                                                                                    And <Contact.contactID, Equal <Location.defContactID> > > >,
                                                                           Where <Location.bAccountID, Equal <Required <BAccount.bAccountID> >,
                                                                                  And <Location.locationID, Equal <Required <BAccount.defLocationID> > > > >
                                                             .Select(graph, ((BranchMaint.BranchBAccount)payer).BranchBAccountID, ((BranchMaint.BranchBAccount)payer).DefLocationID);

                                    data1099Misc.Add(CreatePayerARecord(payer, payer, payer, payer, rowShipContact, filter));

                                    List <PayeeRecordB> payeeRecs = new List <PayeeRecordB>();
                                    foreach (MISC1099EFileProcessingInfo rec in @group)
                                    {
                                        PXProcessing <AP1099History> .SetCurrentItem(rec);

                                        payeeRecs.Add(CreatePayeeBRecord(graph, payer, rec, filter));
                                        PXProcessing <AP1099History> .SetProcessed();
                                    }
                                    payeeRecs = payeeRecs.WhereNotNull().ToList();
                                    trecord.TotalNumberofPayees = payeeRecs.Count.ToString();
                                    data1099Misc.AddRange(payeeRecs);
                                    data1099Misc.Add(CreateEndOfPayerRecordC(payeeRecs));

                                    //If combined State Filer then only generate K Record.
                                    if (((Branch)payer).CFSFiler == true)
                                    {
                                        data1099Misc.AddRange(payeeRecs
                                                              .Where(x => !string.IsNullOrWhiteSpace(x.PayeeState))
                                                              .GroupBy(x => x.PayeeState.Trim(), StringComparer.CurrentCultureIgnoreCase)
                                                              .Select(y => CreateStateTotalsRecordK(y.ToList()))
                                                              .Where(kRecord => kRecord != null));
                                    }
                                }
                            }

                            data1099Misc.Add(CreateEndOfTransmissionRecordF(groups.Count, records.Count));

                            //Write to file
                            FixedLengthFile flatFile = new FixedLengthFile();

                            flatFile.WriteToFile(data1099Misc, sw);
                            sw.Flush();

                            const string   path = "1099-MISC.txt";
                            PX.SM.FileInfo info = new PX.SM.FileInfo(path, null, stream.ToArray());

                            throw new PXRedirectToFileException(info, true);
                        }
                    }
                }
            }
        }
Пример #9
0
        public void Export(List <TWNGUITrans> tWNGUITrans)
        {
            try
            {
                TWNGenGUIMediaFile genGUIMediaFile = PXGraph.CreateInstance <TWNGenGUIMediaFile>();
                TWNGUIPreferences  gUIPreferences  = gUIPreferSetup.Current;

                int    count = 1;
                string lines = "", fileName = "", ticketType = "X7";

                using (MemoryStream ms = new MemoryStream())
                {
                    using (StreamWriter sw = new StreamWriter(ms, Encoding.ASCII))
                    {
                        fileName = gUIPreferences.OurTaxNbr + ".t02";

                        foreach (TWNGUITrans gUITrans in tWNGUITrans)
                        {
                            // Tax ID
                            lines = gUIPreferences.OurTaxNbr;
                            // Country No
                            lines += gUIPreferences.ZeroTaxTaxCntry;
                            // Tax Registration ID
                            lines += gUIPreferences.TaxRegistrationID;
                            // Tax Filling Date
                            lines += genGUIMediaFile.GetGUILegal(FilterGUITran.Current.ToDate.Value);
                            // GUI Date
                            lines += genGUIMediaFile.GetGUILegal(gUITrans.GUIDate.Value);
                            // GUI Number
                            lines += genGUIMediaFile.GetGUINbr(gUITrans);
                            // Customer Tax ID
                            lines += gUITrans.TaxNbr ?? new string(genGUIMediaFile.space, 8);
                            // Export Method
                            lines += gUITrans.ExportMethods;
                            // Custom Method
                            lines += gUITrans.CustomType;
                            // Ticket Type
                            // Ticket Number
                            if (gUITrans.ExportTicketType == ticketType)
                            {
                                lines += new String(genGUIMediaFile.space, 2);
                                lines += new String(genGUIMediaFile.space, 14);
                            }
                            else
                            {
                                lines += gUITrans.ExportTicketType;
                                lines += gUITrans.ExportTicketNbr;
                            }
                            // Amount
                            lines += genGUIMediaFile.GetNetAmt(gUITrans);
                            // Custom Clearing Date
                            lines += GetTWNDate(gUITrans.ClearingDate.Value);

                            // Only the last line does not need to be broken.
                            if (count < tWNGUITrans.Count)
                            {
                                sw.WriteLine(lines);
                                count++;
                            }
                            else
                            {
                                sw.Write(lines);
                            }
                        }

                        //Write to file
                        //FixedLengthFile flatFile = new FixedLengthFile();
                        //flatFile.WriteToFile(recordList, sw);
                        //sw.Flush();

                        sw.Close();

                        PX.SM.FileInfo info = new PX.SM.FileInfo(fileName, null, ms.ToArray());

                        throw new PXRedirectToFileException(info, true);
                    }
                }
            }
            catch (Exception ex)
            {
                PXProcessing <TWNGUITrans> .SetError(ex);

                throw;
            }
        }