public virtual void OnOrganizationBranchSync(BranchMaint branchMaint, Organization organization, BranchMaint.BranchBAccount branchBaccountCopy, Action <BranchMaint, Organization, BranchMaint.BranchBAccount> baseMethod) { baseMethod(branchMaint, organization, branchBaccountCopy); if (!PXAccess.FeatureInstalled <FeaturesSet.rutRotDeduction>()) { return; } OrganizationRUTROT organizationRutRot = Base.OrganizationView.Cache.GetExtension <OrganizationRUTROT>(organization); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.allowsRUTROT>(branchBaccountCopy, organizationRutRot.AllowsRUTROT); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.rUTROTCuryID>(branchBaccountCopy, organizationRutRot.RUTROTCuryID); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.balanceOnProcess>(branchBaccountCopy, organizationRutRot.BalanceOnProcess); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.defaultRUTROTType>(branchBaccountCopy, organizationRutRot.DefaultRUTROTType); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.rOTDeductionPct>(branchBaccountCopy, organizationRutRot.ROTDeductionPct); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.rOTExtraAllowanceLimit>(branchBaccountCopy, organizationRutRot.ROTExtraAllowanceLimit); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.rOTPersonalAllowanceLimit>(branchBaccountCopy, organizationRutRot.ROTPersonalAllowanceLimit); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.rUTDeductionPct>(branchBaccountCopy, organizationRutRot.RUTDeductionPct); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.rUTExtraAllowanceLimit>(branchBaccountCopy, organizationRutRot.RUTExtraAllowanceLimit); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.rUTPersonalAllowanceLimit>(branchBaccountCopy, organizationRutRot.RUTPersonalAllowanceLimit); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.rUTROTClaimNextRefNbr>(branchBaccountCopy, organizationRutRot.RUTROTClaimNextRefNbr); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.rUTROTOrgNbrValidRegEx>(branchBaccountCopy, organizationRutRot.RUTROTOrgNbrValidRegEx); branchMaint.BAccount.Cache.SetValue <BranchBAccountRUTROT.taxAgencyAccountID>(branchBaccountCopy, organizationRutRot.TaxAgencyAccountID); }
public virtual IEnumerable Generate(PXAdapter adapter) { var gafPeriod = GAFPeriodView.Current; Branch branch = BranchMaint.FindBranchByID(this, gafPeriod.BranchID); var taxPeriod = TaxYearMaint.FindTaxPeriodByKey(this, branch.ParentBranchID, gafPeriod.TaxAgencyID, gafPeriod.TaxPeriodID); if (taxPeriod == null) { return(adapter.Get()); } var chekingResult = _gafValidator.CheckGAFGenerationRequirements(gafPeriod.BranchID, taxPeriod); if (!chekingResult.IsSuccess) { throw new PXException(chekingResult.GetGeneralMessage()); } if (chekingResult.HasWarning) { if (GAFPeriodView.Ask(chekingResult.GetGeneralMessage(), MessageButtons.OKCancel) != WebDialogResult.OK) { return(adapter.Get()); } } PXLongOperation.StartOperation(this, () => GenerateProc(gafPeriod)); return(adapter.Get()); }
protected virtual void GAFPeriod_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { var gafPeriod = (GAFPeriod)e.Row; if (gafPeriod == null) { return; } if (gafPeriod.TaxPeriodID != null) { Branch branch = BranchMaint.FindBranchByID(this, gafPeriod.BranchID); var taxPeriod = TaxYearMaint.FindTaxPeriodByKey(this, branch.ParentBranchID, gafPeriod.TaxAgencyID, gafPeriod.TaxPeriodID); if (taxPeriod == null) { return; } gafPeriod.StartDate = taxPeriod.StartDate; gafPeriod.EndDateUI = taxPeriod.EndDateUI; } else { gafPeriod.StartDate = null; gafPeriod.EndDateUI = null; } }
protected virtual void UpdateBranchesParents(Ledger ledger) { IEnumerable <Branch> ledgerBranches = BranchMaint.GetBranchesWithLedgerID(this, ledger.LedgerID); foreach (Branch branch in ledgerBranches) { BranchMaint.SetBranchParentID(branch, ledger.DefBranchID); BranchView.Update(branch); } }
protected virtual void Branch_LedgerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e) { Branch branch = e.Row as Branch; if (branch == null) { return; } Ledger ledger = GeneralLedgerMaint.FindLedgerByID(this, branch.LedgerID); BranchMaint.SetBranchParentID(branch, ledger?.DefBranchID); }
protected virtual void AP1099Year_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { AP1099Year year1099 = (AP1099Year)e.Row; if (year1099 == null) { return; } close1099Year.SetEnabled(!string.IsNullOrEmpty(year1099.FinYear) && year1099.Status == AP1099Year.status.Open); int?[] childBranches = BranchMaint.GetChildBranches(this, Year_Header.Current.BranchID) .Select(branch => branch.BranchID) .ToArray(); if (childBranches.Length == 0) { return; } bool hasUnappliedPrepayments = PXSelectJoin <APRegister, InnerJoin <Vendor, On <APRegister.vendorID, Equal <Vendor.bAccountID> >, InnerJoin <FinPeriod, On <APRegister.finPeriodID, Equal <FinPeriod.finPeriodID> > > >, Where <Vendor.vendor1099, Equal <True>, And <APRegister.docType, Equal <APDocType.prepayment>, And <APRegister.status, NotEqual <APDocStatus.closed>, And <FinPeriod.finYear, Equal <Current <AP1099Year.finYear> >, And <APRegister.branchID, In <Required <APRegister.branchID> > > > > > > > .SelectWindowed(this, 0, 1, childBranches) .Any(); PXSetPropertyException finYearExeption = hasUnappliedPrepayments ? new PXSetPropertyException(Messages.ExistsUnappliedPayments, PXErrorLevel.Warning, year1099.FinYear) : null; sender.RaiseExceptionHandling <AP1099Year.finYear>( year1099, year1099.FinYear, finYearExeption); }
public static void UpdateTaxHistorySums(PXGraph graph, RoundingManager rmanager, string taxPeriodId, int?revisionId, int?branchID, Func <TaxReportLine, bool> ShowTaxReportLine = null) { if (!rmanager.IsRequireRounding) { return; } PXCache cache = graph.Caches[typeof(TaxHistory)]; using (new PXReadBranchRestrictedScope(branchID)) { PXResultset <TaxHistory> lines = GetTaxHistoryLines(graph, rmanager.CurrentVendor.BAccountID, taxPeriodId, revisionId); if (lines.Count == 0) { return; } Branch branch = BranchMaint.FindBranchByID(graph, branchID); TaxPeriod period = TaxYearMaint.GetTaxPeriodByKey(graph, branch.ParentBranchID, rmanager.CurrentVendor.BAccountID, taxPeriodId); Company company = PXSelect <Company> .Select(graph); PXResult <Currency, CurrencyRateByDate> curyWithRateSet = GetCurrencyAndRateByDate(graph, rmanager.CurrentVendor, company, period); Currency currency = curyWithRateSet; CurrencyRateByDate rateByDate = currency.CuryID != company.BaseCuryID ? curyWithRateSet : null; TaxBucketsCalculation taxBucketsAggregatesCalc = new TaxBucketsCalculation(TaxReportLineType.TaxAmount, graph, rmanager, currency, rateByDate, ShowTaxReportLine); TaxBucketsCalculation taxableBucketsAggregatesCalc = new TaxBucketsCalculation(TaxReportLineType.TaxableAmount, graph, rmanager, currency, rateByDate, ShowTaxReportLine); taxBucketsAggregatesCalc.CalculateTaxBuckets(lines); taxableBucketsAggregatesCalc.CalculateTaxBuckets(lines); } cache.Persist(PXDBOperation.Insert); cache.Persisted(isAborted: false); }
public virtual IEnumerable Close1099Year(PXAdapter adapter) { int?[] childBranches = BranchMaint.GetChildBranches(this, Year_Header.Current.BranchID) .Select(branch => branch.BranchID) .ToArray(); PXCache cache = Year_Header.Cache; List <AP1099Year> list = adapter.Get().Cast <AP1099Year>().ToList(); foreach (AP1099Year year in list .Where(year => !string.IsNullOrEmpty(year.FinYear) && year.Status == AP1099Year.status.Open && childBranches.Contains(year.BranchID))) { year.Status = AP1099Year.status.Closed; cache.Update(year); } if (cache.IsInsertedUpdatedDeleted) { Actions.PressSave(); PXLongOperation.StartOperation(this, delegate {}); } return(list); }
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); } } } } }