示例#1
0
        public IEnumerable records()
        {
            this.Caches <MISC1099EFileProcessingInfoRaw>().ClearQueryCache();

            if (Filter.Current?.MasterBranchID == null)
            {
                yield break;
            }

            using (new PXReadBranchRestrictedScope(MarkedBranches))
            {
                // TODO: Workaround awaiting AC-64107
                // -
                IEnumerable <MISC1099EFileProcessingInfo> list = PXSelect <
                    MISC1099EFileProcessingInfoRaw,
                    Where <
                        MISC1099EFileProcessingInfoRaw.finYear, Equal <Current <MISC1099EFileFilter.finYear> >,
                        And <Current <MISC1099EFileFilter.masterBranchID>, IsNotNull> > >
                                                                 .Select(this)
                                                                 .RowCast <MISC1099EFileProcessingInfoRaw>()
                                                                 .GroupBy(rawInfo => new { rawInfo.PayerBranchID, rawInfo.VendorID })
                                                                 .Select(group => new MISC1099EFileProcessingInfo
                {
                    BranchID           = group.First().BranchID,
                    PayerBranchID      = group.Key.PayerBranchID,
                    BoxNbr             = group.First().BoxNbr,
                    FinYear            = group.First().FinYear,
                    VendorID           = group.Key.VendorID,
                    VAcctCD            = group.First().VAcctCD,
                    VAcctName          = group.First().VAcctName,
                    LTaxRegistrationID = group.First().LTaxRegistrationID,
                    HistAmt            = group.Sum(h => h.HistAmt)
                })
                                                                 .ToArray();

                foreach (MISC1099EFileProcessingInfo record in list)
                {
                    MISC1099EFileProcessingInfo located = Records.Cache.Locate(record) as MISC1099EFileProcessingInfo;
                    yield return(located ?? Records.Cache.Insert(record));
                }
                //There is "masterBranch is not null" here because select parameters must be changed after changing masterBranch.
                //If select parametrs is unchanged since last use this select will not be executed and return previous result.
            }
        }
示例#2
0
        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);
        }