public void Update(Doc document) { if (document == null) { return; } RUTROT rutrot = Rutrots.Current ?? Rutrots.SelectSingle(); DocExt documentRR = PXCache <Doc> .GetExtension <DocExt>(document); Branch branch = PXSelect <Branch, Where <Branch.branchID, Equal <Required <Branch.branchID> > > > .Select(Base, documentRR.GetDocumentBranchID()); BranchRUTROT branchRR = RUTROTHelper.GetExtensionNullable <Branch, BranchRUTROT>(branch); PXErrorLevel errorLevel = documentRR.GetDocumentHold() != true ? PXErrorLevel.Error : PXErrorLevel.Warning; bool enableEdit = documentRR.GetRUTROTCompleted() != true && RUTROTHelper.CurrenciesMatch(branchRR, documentRR); bool showSection = documentRR.IsRUTROTDeductible == true; bool showROTSection = showSection && rutrot?.RUTROTType == RUTROTTypes.ROT; bool isAutoDistribution = rutrot?.AutoDistribution == true; UpdateRUTROTCheckbox(enableEdit, RUTROTHelper.IsRUTROTAllowed(branchRR, documentRR)); UpdateRUTROTSection(showSection, enableEdit, showROTSection); UpdateDistributionControls(showSection, enableEdit, isAutoDistribution); SetPersistingChecks(documentRR, rutrot); WarnOnDeductionExceedsAllowance(documentRR, rutrot, errorLevel); WarnUndistributedAmount(documentRR, rutrot, errorLevel, currencyinfo.Current ?? currencyinfo.SelectSingle()); }
private static void ValidateBranchRUTROTSettings(BranchRUTROT branch) { if (branch.TaxAgencyAccountID == null) { throw new PXException(RUTROTMessages.TaxAgencyAccountWasNotFoundForThisBranch); } }
protected virtual void HiddenInventoryItem_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { var item = (HiddenInventoryItem)e.Row; if (item == null) { return; } HiddenInventoryItemRUTROT itemRR = PXCache <HiddenInventoryItem> .GetExtension <HiddenInventoryItemRUTROT>(item); Branch branch = PXSelect <GL.Branch, Where <GL.Branch.branchID, Equal <Required <GL.Branch.branchID> > > > .Select(Base, PXAccess.GetBranchID()); BranchRUTROT branchRR = RUTROTHelper.GetExtensionNullable <Branch, BranchRUTROT>(branch); bool allowRUTROT = branchRR?.AllowsRUTROT == true; bool isOtherCostOrNull = itemRR.RUTROTItemType == null || itemRR.RUTROTItemType == RUTROTItemTypes.OtherCost; PXUIFieldAttribute.SetVisible <HiddenInventoryItemRUTROT.rUTROTItemType>(Base.Item.Cache, item, allowRUTROT); PXUIFieldAttribute.SetVisible <HiddenInventoryItemRUTROT.rUTROTType>(Base.Item.Cache, item, allowRUTROT); PXUIFieldAttribute.SetVisible <HiddenInventoryItemRUTROT.rUTROTWorkTypeID>(Base.Item.Cache, item, allowRUTROT); PXUIFieldAttribute.SetEnabled <HiddenInventoryItemRUTROT.rUTROTWorkTypeID>(sender, item, !isOtherCostOrNull); PXUIFieldAttribute.SetEnabled <HiddenInventoryItemRUTROT.rUTROTItemType>(sender, item, true); PXUIFieldAttribute.SetEnabled <HiddenInventoryItemRUTROT.rUTROTType>(sender, item, true); if (!isOtherCostOrNull && !RUTROTHelper.IsUpToDateWorkType(itemRR.RUTROTWorkTypeID, this.Base.Accessinfo.BusinessDate ?? DateTime.Now, this.Base)) { sender.RaiseExceptionHandling <HiddenInventoryItemRUTROT.rUTROTWorkTypeID>(item, itemRR.RUTROTWorkTypeID, new PXSetPropertyException(RUTROTMessages.ObsoleteWorkTypeWarning, PXErrorLevel.Warning)); } else { sender.RaiseExceptionHandling <HiddenInventoryItemRUTROT.rUTROTWorkTypeID>(item, itemRR.RUTROTWorkTypeID, null); } }
protected virtual void InventoryItem_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { InventoryItem item = e.Row as InventoryItem; if (item == null) { return; } InventoryItemRUTROT itemRR = PXCache <InventoryItem> .GetExtension <InventoryItemRUTROT>(item); Branch branch = Base.CurrentBranch.SelectSingle(PXAccess.GetBranchID()); BranchRUTROT branchRR = RUTROTHelper.GetExtensionNullable <Branch, BranchRUTROT>(branch); bool allowRUTROT = branchRR?.AllowsRUTROT == true; bool isOtherCostOrNull = itemRR.RUTROTItemType == null || itemRR.RUTROTItemType == RUTROTItemTypes.OtherCost; PXUIFieldAttribute.SetVisible <InventoryItemRUTROT.isRUTROTDeductible>(sender, item, allowRUTROT); PXUIFieldAttribute.SetVisible <InventoryItemRUTROT.isRUTROTDeductible>(Base.Item.Cache, item, allowRUTROT); PXUIFieldAttribute.SetVisible <InventoryItemRUTROT.rUTROTItemType>(Base.Item.Cache, item, allowRUTROT); PXUIFieldAttribute.SetVisible <InventoryItemRUTROT.rUTROTType>(Base.Item.Cache, item, allowRUTROT); PXUIFieldAttribute.SetVisible <InventoryItemRUTROT.rUTROTWorkTypeID>(Base.Item.Cache, item, allowRUTROT); PXUIFieldAttribute.SetEnabled <InventoryItemRUTROT.rUTROTWorkTypeID>(sender, item, !isOtherCostOrNull && itemRR.IsRUTROTDeductible == true); PXUIFieldAttribute.SetEnabled <InventoryItemRUTROT.rUTROTItemType>(sender, item, itemRR.IsRUTROTDeductible == true); PXUIFieldAttribute.SetEnabled <InventoryItemRUTROT.rUTROTType>(sender, item, itemRR.IsRUTROTDeductible == true); if (!isOtherCostOrNull && !RUTROTHelper.IsUpToDateWorkType(itemRR.RUTROTWorkTypeID, this.Base.Accessinfo.BusinessDate ?? DateTime.Now, this.Base)) { sender.RaiseExceptionHandling <InventoryItemRUTROT.rUTROTWorkTypeID>(item, itemRR.RUTROTWorkTypeID, new PXSetPropertyException(RUTROTMessages.ObsoleteWorkTypeWarning, PXErrorLevel.Warning)); } else { sender.RaiseExceptionHandling <InventoryItemRUTROT.rUTROTWorkTypeID>(item, itemRR.RUTROTWorkTypeID, null); } }
public static bool IsNeedBalancing(ClaimRUTROTProcess graph, string balanceOn) { if (!PXAccess.FeatureInstalled <FeaturesSet.rutRotDeduction>()) { return(false); } BranchRUTROT branchRUTROT = GetBranchRUTROT(graph); ValidateBranchRUTROTSettings(branchRUTROT); return(branchRUTROT?.BalanceOnProcess == balanceOn); }
public void UncheckRUTROTIfProhibited(IRUTROTable document, Branch branch) { if (branch == null || document == null) { return; } BranchRUTROT branchRR = PXCache <Branch> .GetExtension <BranchRUTROT>(branch); if (RUTROTHelper.IsRUTROTAllowed(branchRR, document) == false && document.IsRUTROTDeductible == true) { document.IsRUTROTDeductible = false; Document.Cache.Update(document.GetBaseDocument()); } }
public static bool IsNeedBalancing(ARInvoiceEntry graph, ARInvoice invoice, string balanceOn) { if (!PXAccess.FeatureInstalled <FeaturesSet.rutRotDeduction>()) { return(false); } BranchRUTROT branchRUTROT = GetBranchRUTROT(graph); if (invoice == null) { return(branchRUTROT?.BalanceOnProcess == balanceOn); } ARInvoiceRUTROT invoiceRUTROT = RUTROTHelper.GetExtensionNullable <ARInvoice, ARInvoiceRUTROT>(invoice); return(invoice.DocType == ARDocType.Invoice && invoiceRUTROT?.IsRUTROTDeductible == true && branchRUTROT?.BalanceOnProcess == balanceOn); }
public static bool IsRUTROTAllowed(BranchRUTROT branchRR, IRUTROTable document) { return(branchRR?.AllowsRUTROT == true && IsRUTROTcompatibleType(document?.GetDocumentType()) && CurrenciesMatch(branchRR, document)); }
public static bool CurrenciesMatch(BranchRUTROT branchRR, IRUTROTable document) { return(branchRR?.RUTROTCuryID == document?.GetDocumentCuryID()); }
private static void CreateMemo(ARInvoiceEntry graph, ARRegister doc, RUTROT rutrot, string docType, bool OnRelease = false) { DuplicateFilter filter = PXCache <DuplicateFilter> .CreateCopy(graph.duplicatefilter.Current); foreach (PXResult <ARInvoice, CurrencyInfo, Terms, Customer> res in ARInvoice_CurrencyInfo_Terms_Customer.Select(graph, (object)doc.DocType, doc.RefNbr, doc.CustomerID)) { CurrencyInfo info = PXCache <CurrencyInfo> .CreateCopy((CurrencyInfo)res); info.CuryInfoID = null; info.IsReadOnly = false; info = PXCache <CurrencyInfo> .CreateCopy(graph.currencyinfo.Insert(info)); ARInvoice invoice = (ARInvoice)graph.Document.Cache.CreateInstance(); if (docType == ARDocType.CreditMemo) { invoice.DueDate = null; invoice.DiscDate = null; invoice.CustomerID = doc.CustomerID; invoice.ARAccountID = doc.ARAccountID; invoice.ARSubID = doc.ARSubID; } if (docType == ARInvoiceType.DebitMemo) { invoice.DueDate = ((ARInvoice)res).DueDate; invoice.DiscDate = ((ARInvoice)res).DiscDate; BranchRUTROT branchRUTROT = GetBranchRUTROT(graph); invoice.CustomerID = branchRUTROT.TaxAgencyAccountID; invoice.ARAccountID = null; invoice.ARSubID = null; } ARInvoiceRUTROT invoiceRUTROT = RUTROTHelper.GetExtensionNullable <ARInvoice, ARInvoiceRUTROT>(invoice); invoiceRUTROT.IsRUTROTDeductible = false; invoice.CuryInfoID = info.CuryInfoID; invoice.DocType = docType; invoice.OrigModule = GL.BatchModule.AR; invoice.RefNbr = null; invoice.OrigModule = GL.BatchModule.AR; invoice.DocDesc = PXLocalizer.LocalizeFormat(RUTROTMessages.MemoDescription, doc.RefNbr); invoice.OpenDoc = true; invoice.Released = false; invoice.Hold = false; invoice.Printed = false; invoice.Emailed = false; invoice.BatchNbr = null; invoice.ScheduleID = null; invoice.Scheduled = false; invoice.NoteID = null; invoice.RefNoteID = null; invoice.TermsID = null; invoice.InstallmentCntr = null; invoice.InstallmentNbr = null; invoice.CuryOrigDiscAmt = 0m; invoice.FinPeriodID = doc.FinPeriodID; invoice.OrigDocDate = invoice.DocDate; invoice.CuryLineTotal = 0m; invoice.IsTaxPosted = false; invoice.IsTaxValid = false; invoice.CuryVatTaxableTotal = 0m; invoice.CuryVatExemptTotal = 0m; invoice.StatementDate = null; invoice.PendingPPD = false; invoice.CustomerLocationID = null; if (!string.IsNullOrEmpty(invoice.PaymentMethodID)) { CA.PaymentMethod pm = null; if (invoice.CashAccountID.HasValue) { CA.PaymentMethodAccount pmAccount = null; PXResult <CA.PaymentMethod, CA.PaymentMethodAccount> pmResult = (PXResult <CA.PaymentMethod, CA.PaymentMethodAccount>) PXSelectJoin <CA.PaymentMethod, LeftJoin < CA.PaymentMethodAccount, On <CA.PaymentMethod.paymentMethodID, Equal <CA.PaymentMethodAccount.paymentMethodID> > >, Where < CA.PaymentMethod.paymentMethodID, Equal <Required <CA.PaymentMethod.paymentMethodID> >, And <CA.PaymentMethodAccount.cashAccountID, Equal <Required <CA.PaymentMethodAccount.cashAccountID> > > > > . Select(graph, invoice.PaymentMethodID, invoice.CashAccountID); pm = pmResult; pmAccount = pmResult; if (pm == null || pm.UseForAR == false || pm.IsActive == false) { invoice.PaymentMethodID = null; invoice.CashAccountID = null; } else if (pmAccount == null || pmAccount.CashAccountID == null || pmAccount.UseForAR != true) { invoice.CashAccountID = null; } } else { pm = PXSelect <CA.PaymentMethod, Where <CA.PaymentMethod.paymentMethodID, Equal <Required <CA.PaymentMethod.paymentMethodID> > > > .Select(graph, invoice.PaymentMethodID); if (pm == null || pm.UseForAR == false || pm.IsActive == false) { invoice.PaymentMethodID = null; invoice.CashAccountID = null; invoice.PMInstanceID = null; } } if (invoice.PMInstanceID.HasValue) { CustomerPaymentMethod cpm = PXSelect <CustomerPaymentMethod, Where <CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > . Select(graph, invoice.PMInstanceID); if (string.IsNullOrEmpty(invoice.PaymentMethodID) || cpm == null || cpm.IsActive == false || cpm.PaymentMethodID != invoice.PaymentMethodID) { invoice.PMInstanceID = null; } } } else { invoice.CashAccountID = null; invoice.PMInstanceID = null; } SalesPerson sp = (SalesPerson)PXSelectorAttribute.Select <ARInvoice.salesPersonID>(graph.Document.Cache, invoice); if (sp == null || sp.IsActive == false) { invoice.SalesPersonID = null; } invoice = graph.Document.Insert(invoice); } TX.TaxAttribute.SetTaxCalc <ARTran.taxCategoryID>(graph.Transactions.Cache, null, TX.TaxCalc.ManualCalc); graph.FieldDefaulting.AddHandler <ARTran.salesPersonID>((sender, e) => { e.NewValue = null; e.Cancel = true; }); decimal roundedTotalDistributedLinesAmt = 0m; foreach (ARTran srcTran in PXSelect <ARTran, Where <ARTran.tranType, Equal <Required <ARTran.tranType> >, And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > > .Select(graph, doc.DocType, doc.RefNbr)) { ARTran tran = PXCache <ARTran> .CreateCopy(srcTran); ARTranRUTROT tranRR = RUTROTHelper.GetExtensionNullable <ARTran, ARTranRUTROT>(tran); if (tranRR.IsRUTROTDeductible != true) { continue; } tran.TranType = graph.Document.Current.DocType; tran.RefNbr = graph.Document.Current.RefNbr; string origDrCr = tran.DrCr; tran.DrCr = null; tran.Released = null; tran.CuryInfoID = null; tran.SOOrderNbr = null; tran.SOShipmentNbr = null; tran.OrigInvoiceDate = tran.TranDate; tran.NoteID = null; tran.ManualPrice = true; tran.CuryTranAmt = Math.Floor(tranRR.CuryRUTROTAvailableAmt ?? 0m); roundedTotalDistributedLinesAmt += tran.CuryTranAmt ?? 0m; tranRR.IsRUTROTDeductible = false; if (!string.IsNullOrEmpty(tran.DeferredCode)) { DRSchedule schedule = PXSelect <DRSchedule, Where <DRSchedule.module, Equal <BQLConstants.moduleAR>, And <DRSchedule.docType, Equal <Required <DRSchedule.docType> >, And <DRSchedule.refNbr, Equal <Required <DRSchedule.refNbr> >, And <DRSchedule.lineNbr, Equal <Required <DRSchedule.lineNbr> > > > > > > . Select(graph, doc.DocType, doc.RefNbr, tran.LineNbr); if (schedule != null) { tran.DefScheduleID = schedule.ScheduleID; } } SalesPerson sp = (SalesPerson)PXSelectorAttribute.Select <ARTran.salesPersonID>(graph.Transactions.Cache, tran); if (sp == null || sp.IsActive == false) { tran.SalesPersonID = null; } ARTran insertedTran = graph.Transactions.Insert(tran); PXNoteAttribute.CopyNoteAndFiles(graph.Transactions.Cache, srcTran, graph.Transactions.Cache, insertedTran); insertedTran.ManualDisc = true; insertedTran.TaxCategoryID = null; graph.Transactions.Update(insertedTran); } decimal distributedFee = (rutrot.CuryDistributedAmt ?? 0m) - roundedTotalDistributedLinesAmt; if (distributedFee != 0m) { foreach (ARTran artran in graph.Transactions.Cache.Inserted) { if (Math.Round(distributedFee) == 0m) { break; } if (artran.CuryTranAmt != 0m) { artran.CuryTranAmt += Math.Sign(distributedFee); distributedFee -= Math.Sign(distributedFee); } graph.Transactions.Update(artran); } } graph.Document.Current.CuryOrigDocAmt = graph.Document.Current.CuryDocBal; graph.Document.Cache.Update(graph.Document.Current); graph.RowInserting.AddHandler <ARSalesPerTran>((sender, e) => { e.Cancel = true; }); foreach (ARSalesPerTran salespertran in PXSelect <ARSalesPerTran, Where <ARSalesPerTran.docType, Equal <Required <ARSalesPerTran.docType> >, And <ARSalesPerTran.refNbr, Equal <Required <ARSalesPerTran.refNbr> > > > > .Select(graph, doc.DocType, doc.RefNbr)) { ARSalesPerTran newtran = PXCache <ARSalesPerTran> .CreateCopy(salespertran); newtran.DocType = graph.Document.Current.DocType; newtran.RefNbr = graph.Document.Current.RefNbr; newtran.Released = false; newtran.CuryInfoID = null; newtran.CuryCommnblAmt *= -1m; newtran.CuryCommnAmt *= -1m; SalesPerson sp = (SalesPerson)PXSelectorAttribute.Select <ARSalesPerTran.salespersonID>(graph.salesPerTrans.Cache, newtran); if (!(sp == null || sp.IsActive == false)) { graph.salesPerTrans.Update(newtran); } } var discountDetailsSet = PXSelect <ARInvoiceDiscountDetail, Where <ARInvoiceDiscountDetail.docType, Equal <Required <ARInvoice.docType> >, And <ARInvoiceDiscountDetail.refNbr, Equal <Required <ARInvoice.refNbr> > > >, OrderBy <Asc <ARInvoiceDiscountDetail.docType, Asc <ARInvoiceDiscountDetail.refNbr> > > > .Select(graph, doc.DocType, doc.RefNbr); foreach (ARInvoiceDiscountDetail discountDetail in discountDetailsSet) { ARInvoiceDiscountDetail newDiscountDetail = PXCache <ARInvoiceDiscountDetail> .CreateCopy(discountDetail); newDiscountDetail.DocType = graph.Document.Current.DocType; newDiscountDetail.RefNbr = graph.Document.Current.RefNbr; newDiscountDetail.IsManual = true; DiscountEngineProvider.GetEngineFor <ARTran, ARInvoiceDiscountDetail>().UpdateDiscountDetail(graph.ARDiscountDetails.Cache, graph.ARDiscountDetails, newDiscountDetail); } graph.Save.Press(); if (docType == ARDocType.CreditMemo && !OnRelease) { CreateAdjustment(graph, doc, graph.Document.Current); } }