protected virtual void MISC1099EFileFilter_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { MISC1099EFileFilter oldRow = (MISC1099EFileFilter)e.OldRow; MISC1099EFileFilter newRow = (MISC1099EFileFilter)e.Row; if (oldRow.FinYear != newRow.FinYear || oldRow.MasterBranchID != newRow.MasterBranchID) { Records.Cache.Clear(); } }
public TransmitterTRecord CreateTransmitterRecord(OrganizationBAccount orgBAccount, Organization organization, Contact rowMainContact, Address rowMainAddress, MISC1099EFileFilter filter, int totalPayeeB) { return(new TransmitterTRecord { RecordType = "T", PaymentYear = filter.FinYear, PriorYearDataIndicator = filter.IsPriorYear == true ? "P" : string.Empty, TransmitterTIN = orgBAccount.TaxRegistrationID, TransmitterControlCode = organization.TCC, Blank1 = string.Empty, TestFileIndicator = filter.IsTestMode == true ? "T" : string.Empty, ForeignEntityIndicator = organization.ForeignEntity == true ? "1" : string.Empty, TransmitterName = rowMainContact.FullName.Trim(), CompanyName = rowMainContact.FullName.Trim(), CompanyMailingAddress = string.Concat(rowMainAddress.AddressLine1, rowMainAddress.AddressLine2), CompanyCity = rowMainAddress.City, CompanyState = rowMainAddress.State, CompanyZipCode = rowMainAddress.PostalCode, Blank2 = string.Empty, //Setup at the end - dependent of Payee B records TotalNumberofPayees = totalPayeeB.ToString(), ContactName = organization.ContactName, ContactTelephoneAndExt = organization.CTelNumber, ContactEmailAddress = organization.CEmail, Blank3 = string.Empty, RecordSequenceNumber = (++RecordCounter).ToString(), Blank4 = string.Empty, VendorIndicator = "V", VendorName = TRecordVendorInfo.VendorName, VendorMailingAddress = TRecordVendorInfo.VendorMailingAddress, VendorCity = TRecordVendorInfo.VendorCity, VendorState = TRecordVendorInfo.VendorState, VendorZipCode = TRecordVendorInfo.VendorZipCode, VendorContactName = TRecordVendorInfo.VendorContactName, VendorContactTelephoneAndExt = TRecordVendorInfo.VendorContactTelephoneAndExt, Blank5 = string.Empty, #region Check - Vendor or Branch? VendorForeignEntityIndicator = TRecordVendorInfo.VendorForeignEntityIndicator, #endregion Blank6 = string.Empty, Blank7 = string.Empty, }); }
public PayerRecordA CreatePayerARecord(OrganizationBAccount orgBAccount, Organization organization, Contact rowMainContact, Address rowMainAddress, LocationExtAddress rowShipInfo, Contact rowShipContact, MISC1099EFileFilter filter) { string companyName1 = rowMainContact.FullName.Trim(); string companyName2 = string.Empty; if (companyName1.Length > 40) { companyName2 = companyName1.Substring(40); companyName1 = companyName1.Substring(0, 40); } return(new PayerRecordA { RecordType = "A", PaymentYear = filter.FinYear, CombinedFederalORStateFiler = organization.CFSFiler == true ? "1" : string.Empty, Blank1 = string.Empty, PayerTaxpayerIdentificationNumberTIN = orgBAccount.TaxRegistrationID, PayerNameControl = organization.NameControl, LastFilingIndicator = filter.IsLastFiling == true ? "1" : string.Empty, TypeofReturn = "A", AmountCodes = (filter.ReportingDirectSalesOnly == true) ? "1" : "12345678ABCDE", Blank2 = string.Empty, ForeignEntityIndicator = organization.ForeignEntity == true ? "1" : string.Empty, FirstPayerNameLine = companyName1, SecondPayerNameLine = companyName2, #region Check with Gabriel, we need Transfer Agent or no TransferAgentIndicator = "0", #endregion PayerShippingAddress = string.Concat(rowShipInfo.AddressLine1, rowShipInfo.AddressLine2), PayerCity = rowShipInfo.City, PayerState = rowShipInfo.State, PayerZipCode = rowShipInfo.PostalCode, PayerTelephoneAndExt = rowShipContact.Phone1, Blank3 = string.Empty, RecordSequenceNumber = (++RecordCounter).ToString(), Blank4 = string.Empty, Blank5 = string.Empty }); }
protected virtual void MISC1099EFileFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { MISC1099EFileFilter rowfilter = e.Row as MISC1099EFileFilter; if (rowfilter == null) { return; } Records.SetProcessDelegate( delegate(List <MISC1099EFileProcessingInfo> list) { MISC1099EFileProcessing graph = CreateInstance <MISC1099EFileProcessing>(); graph.Process(list, rowfilter); }); if (rowfilter.Include == MISC1099EFileFilter.include.AllMarkedOrganizations) { string unmarkedOrganizations = PXSelectJoinGroupBy <Organization, InnerJoin <Branch, On <Organization.organizationID, Equal <Branch.organizationID> > >, Where2 <Where <Organization.reporting1099, NotEqual <True>, Or <Organization.reporting1099, IsNull> >, And <MatchWithBranch <Branch.branchID> > >, Aggregate <GroupBy <Organization.organizationID> > > .SelectWindowed(this, 0, 10) .RowCast <Organization>() .Select(organization => organization.OrganizationCD) .JoinToString(", "); sender.RaiseExceptionHandling <MISC1099EFileFilter.include>(rowfilter, rowfilter.Include, !string.IsNullOrEmpty(unmarkedOrganizations) ? new PXSetPropertyException(Messages.Unefiled1099Organizations, PXErrorLevel.Warning, unmarkedOrganizations) : null); } else { sender.RaiseExceptionHandling <MISC1099EFileFilter.include>(rowfilter, rowfilter.Include, null); } }
public PayeeRecordB CreatePayeeBRecord(BranchMaint graph, BranchMaint.BranchBAccount branchRow, MISC1099EFileProcessingInfo Record1099, MISC1099EFileFilter filter) { PayeeRecordB bRecord; graph.Caches <AP1099History>().ClearQueryCache(); using (new PXReadBranchRestrictedScope(Record1099.PayerBranchID)) { VendorR rowVendor = PXSelect <VendorR, Where <VendorR.bAccountID, Equal <Required <VendorR.bAccountID> > > > .Select(graph, Record1099.VendorID); Contact rowVendorContact = PXSelect <Contact, Where <Contact.bAccountID, Equal <Required <BAccount.bAccountID> >, And <Contact.contactID, Equal <Required <BAccount.defContactID> > > > > .Select(graph, rowVendor.BAccountID, rowVendor.DefContactID); Address rowVendorAddress = PXSelect <Address, Where <Address.bAccountID, Equal <Required <BAccount.bAccountID> >, And <Address.addressID, Equal <Required <BAccount.defAddressID> > > > > .Select(graph, rowVendor.BAccountID, rowVendor.DefAddressID); LocationExtAddress rowVendorShipInfo = PXSelect <LocationExtAddress, Where <LocationExtAddress.locationBAccountID, Equal <Required <BAccount.bAccountID> >, And <LocationExtAddress.locationID, Equal <Required <BAccount.defLocationID> > > > > .Select(graph, rowVendor.BAccountID, rowVendor.DefLocationID); List <AP1099History> amtList1099 = PXSelectJoinGroupBy <AP1099History, InnerJoin <AP1099Box, On <AP1099History.boxNbr, Equal <AP1099Box.boxNbr> > >, Where <AP1099History.vendorID, Equal <Required <AP1099History.vendorID> >, And <AP1099History.finYear, Equal <Required <AP1099History.finYear> > > >, Aggregate < GroupBy <AP1099History.boxNbr, Sum <AP1099History.histAmt> > > > .Select(graph, Record1099.VendorID, filter.FinYear) .Where(res => res.GetItem <AP1099History>().HistAmt >= res.GetItem <AP1099Box>().MinReportAmt) .RowCast <AP1099History>() .ToList(); if ((amtList1099.Sum(hist => hist.HistAmt) ?? 0m) == 0m) { return(null); } bRecord = new PayeeRecordB { RecordType = "B", PaymentYear = filter.FinYear, //ALWAYS G since we have one Payee record per file. CorrectedReturnIndicator = filter.IsCorrectionReturn == true ? "G" : string.Empty, NameControl = string.Empty, #region confirmed with Gabriel - ALWAYS Business TypeOfTIN = "1", #endregion PayerTaxpayerIdentificationNumberTIN = rowVendorShipInfo.TaxRegistrationID, PayerAccountNumberForPayee = rowVendor.AcctCD, #region Check with Gabriel, not sure about this PayerOfficeCode = string.Empty, #endregion Blank1 = string.Empty, PaymentAmount1 = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 1)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmount2 = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 2)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmount3 = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 3)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmount4 = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 4)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmount5 = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 5)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmount6 = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 6)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmount7 = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 7)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmount8 = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 8)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), // //Need Box 11??? PaymentAmount9 = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 9)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), // PaymentAmountA = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 10)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmountB = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 13)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmountC = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 14)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), Payment = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 151)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmountE = filter.ReportingDirectSalesOnly == true ? 0m : Math.Round((amtList1099.FirstOrDefault(v => (v != null && v.BoxNbr == 152)) ?? new AP1099Hist { HistAmt = 0m }).HistAmt ?? 0m, 2), PaymentAmountF = 0m, PaymentAmountG = 0m, ForeignCountryIndicator = rowVendor.ForeignEntity == true ? "1" : string.Empty, PayeeNameLine = rowVendorContact.FullName, Blank2 = string.Empty, PayeeMailingAddress = string.Concat(rowVendorAddress.AddressLine1, rowVendorAddress.AddressLine2), Blank3 = string.Empty, PayeeCity = rowVendorAddress.City, PayeeState = rowVendorAddress.State, PayeeZipCode = rowVendorAddress.PostalCode, Blank4 = string.Empty, RecordSequenceNumber = (++RecordCounter).ToString(), Blank5 = string.Empty, #region Confirmed with Gabriel, Skip for now SecondTINNotice = string.Empty, #endregion Blank6 = string.Empty, #region Check - Dependent on Box 9 - check in 3rd party DirectSalesIndicator = GetDirectSaleIndicator(graph, Record1099.VendorID.Value, filter.FinYear), #endregion FATCA = rowVendor.FATCA == true ? "1": string.Empty, Blank7 = string.Empty, #region Confirmed with Gabriel, skip for now SpecialDataEntries = string.Empty, StateIncomeTaxWithheld = string.Empty, LocalIncomeTaxWithheld = string.Empty, #endregion CombineFederalOrStateCode = branchRow.CFSFiler == true?GetCombinedFederalOrStateCode(rowVendorAddress.State) : string.Empty, Blank8 = string.Empty, }; } return(bRecord); }
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); } } } } }