示例#1
0
        protected virtual IEnumerable filter()
        {
            ApproveBillsFilter filter = Filter.Current;

            if (filter != null && filter.SelectionDate != null && filter.PendingRefresh == true)
            {
                DateTime PayInLessThan             = ((DateTime)filter.SelectionDate).AddDays(filter.PayInLessThan.GetValueOrDefault());
                DateTime DueInLessThan             = ((DateTime)filter.SelectionDate).AddDays(filter.DueInLessThan.GetValueOrDefault());
                DateTime DiscountExpiresInLessThan = ((DateTime)filter.SelectionDate).AddDays(filter.DiscountExpiresInLessThan.GetValueOrDefault());

                decimal approvedTotal = 0m;
                decimal docsTotal     = 0m;

                PXView view = new PXView(this, true, BqlCommand.CreateInstance(getAPDocumentSelect(true)));

                foreach (PXResult <APInvoice> temp in view.SelectMulti(PayInLessThan, DueInLessThan, DiscountExpiresInLessThan))
                {
                    APInvoice res = temp;
                    approvedTotal += res.PaySel == true ? (Accessinfo.CuryViewState ? (res.DocBal ?? 0m) : (res.CuryDocBal ?? 0m)) : 0m;
                    docsTotal     += Accessinfo.CuryViewState ? (res.DocBal ?? 0m) : (res.CuryDocBal ?? 0m);
                }

                Filter.Current.CuryApprovedTotal = approvedTotal;
                Filter.Current.CuryDocsTotal     = docsTotal;
                Filter.Current.PendingRefresh    = false;
            }

            yield return(Filter.Current);

            Filter.Cache.IsDirty = false;
        }
示例#2
0
        public static void ReleaseRetainage(APInvoiceEntry graph, APInvoiceExt invoice, APRetainageFilter filter, bool isAutoRelease)
        {
            graph.Clear(PXClearOption.ClearAll);
            PXUIFieldAttribute.SetError(graph.Document.Cache, null, null, null);

            RetainageOptions retainageOptions = new RetainageOptions();

            retainageOptions.DocDate          = filter.DocDate;
            retainageOptions.FinPeriodID      = filter.FinPeriodID;
            retainageOptions.CuryRetainageAmt = invoice.CuryRetainageReleasedAmt;
            retainageOptions.InvoiceNbr       = invoice.RetainageVendorRef;

            APInvoiceEntryRetainage retainageExt = graph.GetExtension <APInvoiceEntryRetainage>();

            APInvoice retainageInvoice = retainageExt.ReleaseRetainageProc(invoice, retainageOptions, isAutoRelease);

            graph.Save.Press();

            if (isAutoRelease && retainageInvoice.Hold != true)
            {
                List <APRegister> toRelease = new List <APRegister>()
                {
                    retainageInvoice
                };
                using (new PXTimeStampScope(null))
                {
                    APDocumentRelease.ReleaseDoc(toRelease, true);
                }
            }
        }
示例#3
0
        protected virtual void APInvoice_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            APInvoice doc = (APInvoice)e.Row;

            if (doc.PaySel == true && doc.PayDate == null)
            {
                sender.RaiseExceptionHandling <APInvoice.payDate>(doc, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(APInvoice.payDate).Name));
            }

            if (doc.PaySel == true && doc.DocDate != null && doc.PayDate != null &&
                ((DateTime)doc.DocDate).CompareTo((DateTime)doc.PayDate) > 0)
            {
                sender.RaiseExceptionHandling <APInvoice.payDate>(e.Row, doc.PayDate, new PXSetPropertyException(Messages.ApplDate_Less_DocDate, PXErrorLevel.RowError, typeof(APInvoice.payDate).Name));
            }

            if (doc.PaySel == true && doc.PayLocationID == null)
            {
                sender.RaiseExceptionHandling <APInvoice.payLocationID>(doc, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(APInvoice.payLocationID).Name));
            }

            if (doc.PaySel == true && doc.PayAccountID == null)
            {
                sender.RaiseExceptionHandling <APInvoice.payAccountID>(doc, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(APInvoice.payAccountID).Name));
            }

            if (doc.PaySel == true && doc.PayTypeID == null)
            {
                sender.RaiseExceptionHandling <APInvoice.payTypeID>(doc, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(APInvoice.payTypeID).Name));
            }
        }
示例#4
0
        public static bool Ensure(PXCache cache, APInvoice bill)
        {
            bool?  result = null;
            object value  = null;

            new IsPOLinkedAPBill().Verify(cache, bill, new List <object>(), ref result, ref value);
            return(result == true);
        }
        protected virtual void APInvoice_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected bs)
        {
            if (bs != null)
            {
                bs(sender, e);
            }
            APInvoice row = e.Row as APInvoice;

            if (row == null)
            {
                return;
            }
            bool           isWithinContext = Base.IsWithinContext;
            GLVoucher      voucher         = this.Voucher.Select();
            GLVoucherBatch voucherBatch    = this.VoucherBatch.Select();
            PXCache        voucherCache    = this.Voucher.Cache;
            bool           isDetached      = (voucher == null);

            PXUIFieldAttribute.SetEnabled <GLVoucher.refNbr>(voucherCache, voucher, false);
            PXUIFieldAttribute.SetVisible <GLVoucher.refNbr>(voucherCache, voucher, !isDetached);
            PXUIFieldAttribute.SetEnabled <APInvoice.refNbr>(sender, e.Row, !isWithinContext);
            this.SaveAndAdd.SetVisible(!isDetached && isWithinContext);
            this.SaveAndAdd.SetEnabled(!isDetached && isWithinContext);
            if (isWithinContext)
            {
                Base.release.SetVisible(false);
                Base.release.SetEnabled(false);
                Base.voidInvoice.SetVisible(false);
                Base.voidInvoice.SetEnabled(false);
                Base.voidDocument.SetVisible(false);
                Base.voidDocument.SetEnabled(false);
                Base.voidCheck.SetVisible(false);
                Base.voidCheck.SetEnabled(false);
                Base.reverseInvoice.SetEnabled(false);
                try
                {
                    Base.action.SetEnabled("Reverse", false);
                }
                catch { }
            }
            if (!isDetached)
            {
                try
                {
                    Base.action.SetEnabled("Add to Schedule", false);
                }
                catch { }
                Base.createSchedule.SetEnabled(false);
            }
            PXUIFieldAttribute.SetVisible <GLVoucher.voucherBatchNbr>(Voucher.Cache, null, !isDetached && !isWithinContext);
            PXUIFieldAttribute.SetVisible <GLVoucher.workBookID>(Voucher.Cache, null, !isDetached && !isWithinContext);
            if (isWithinContext && !isDetached)
            {
                sender.AllowInsert = !(voucherBatch != null && voucherBatch.Released == true);
            }
        }
        protected virtual void APInvoiceDiscountDetail_RowInserting(PXCache sender, PXRowInsertingEventArgs e)
        {
            APInvoice invoice = Base.Document.Current;

            if (invoice?.RetainageApply == true ||
                invoice?.IsRetainageDocument == true)
            {
                e.Cancel = true;
            }
        }
        public static APInvoice Process(APInvoice doc)
        {
            List <APInvoice> list = new List <APInvoice>();

            list.Add(doc);

            List <APInvoice> listWithTax = Process(list, false);

            return(listWithTax[0]);
        }
        public virtual APInvoice CommitExternalTax(APInvoice doc)
        {
            if (doc != null && doc.IsTaxValid == true && doc.NonTaxable == false && IsExternalTax(doc.TaxZoneID) && doc.InstallmentNbr == null)
            {
                if (TaxPluginMaint.IsActive(Base, doc.TaxZoneID))
                {
                    var service = TaxProviderFactory(Base, doc.TaxZoneID);

                    CommitTaxRequest request = new CommitTaxRequest();
                    request.CompanyCode = ExternalTax.CompanyCodeFromBranch(Base, doc.TaxZoneID, doc.BranchID);
                    request.DocCode     = $"AP.{doc.DocType}.{doc.RefNbr}";

                    if (doc.DocType == APDocType.Refund)
                    {
                        request.DocType = TaxDocumentType.ReturnInvoice;
                    }
                    else
                    {
                        request.DocType = TaxDocumentType.PurchaseInvoice;
                    }


                    CommitTaxResult result = service.CommitTax(request);
                    if (result.IsSuccess)
                    {
                        doc.IsTaxPosted = true;
                    }
                    else
                    {
                        //External Tax Provider retuned an error - The given document is already marked as posted on the avalara side.
                        if (!result.IsSuccess && result.Messages.Any(t => t.Contains("Expected Posted")))
                        {
                            //ignore this error - everything is cool
                        }
                        else
                        {
                            //show as warning.
                            StringBuilder sb = new StringBuilder();
                            foreach (var msg in result.Messages)
                            {
                                sb.AppendLine(msg);
                            }

                            if (sb.Length > 0)
                            {
                                doc.WarningMessage = PXMessages.LocalizeFormatNoPrefixNLA(AR.Messages.PostingToExternalTaxProviderFailed, sb.ToString());
                            }
                        }
                    }
                }
            }

            return(doc);
        }
        public void AddDiscount(
            PXCache sender,
            APInvoice row,
            AddDiscountDelegate baseMethod)
        {
            bool isRetainage =
                row.RetainageApply == true ||
                row.IsRetainageDocument == true;

            if (!isRetainage)
            {
                baseMethod(sender, row);
            }
        }
示例#10
0
        public virtual TaxDocumentType GetTaxDocumentType(APInvoice invoice)
        {
            switch (invoice.DrCr)
            {
            case DrCr.Debit:
                return(TaxDocumentType.PurchaseInvoice);

            case DrCr.Credit:
                return(TaxDocumentType.ReturnInvoice);

            default:
                throw new PXException(Messages.DocTypeNotSupported);
            }
        }
        protected virtual void APInvoice_RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
        {
            APInvoice document = e.Row as APInvoice;

            if (document == null)
            {
                return;
            }

            if (document.RetainageApply == true &&
                document.Released == true)
            {
                using (new PXConnectionScope())
                {
                    APRetainageInvoice dummyInvoice = new APRetainageInvoice();
                    dummyInvoice.CuryRetainageUnpaidTotal = 0m;
                    dummyInvoice.CuryRetainagePaidTotal   = 0m;

                    foreach (APRetainageInvoice childRetainageBill in RetainageDocuments
                             .Select(document.DocType, document.RefNbr)
                             .RowCast <APRetainageInvoice>()
                             .Where(res => res.Released == true))
                    {
                        dummyInvoice.DocType        = childRetainageBill.DocType;
                        dummyInvoice.RefNbr         = childRetainageBill.RefNbr;
                        dummyInvoice.CuryOrigDocAmt = childRetainageBill.CuryOrigDocAmt;
                        dummyInvoice.CuryDocBal     = childRetainageBill.CuryOrigDocAmt;

                        foreach (APAdjust application in PXSelect <APAdjust,
                                                                   Where <APAdjust.adjdDocType, Equal <Required <APAdjust.adjdDocType> >,
                                                                          And <APAdjust.adjdRefNbr, Equal <Required <APAdjust.adjdRefNbr> >,
                                                                               And <APAdjust.released, Equal <True>,
                                                                                    And <APAdjust.voided, NotEqual <True>,
                                                                                         And <APAdjust.adjgDocType, NotEqual <APDocType.debitAdj> > > > > > >
                                 .Select(Base, childRetainageBill.DocType, childRetainageBill.RefNbr))
                        {
                            dummyInvoice.AdjustBalance(application);
                        }

                        dummyInvoice.CuryRetainageUnpaidTotal += childRetainageBill.DocBal * childRetainageBill.SignAmount;
                        dummyInvoice.CuryRetainagePaidTotal   += (dummyInvoice.CuryOrigDocAmt - dummyInvoice.CuryDocBal) * dummyInvoice.SignAmount;
                    }

                    document.CuryRetainageUnpaidTotal = document.CuryRetainageUnreleasedAmt + dummyInvoice.CuryRetainageUnpaidTotal;
                    document.CuryRetainagePaidTotal   = dummyInvoice.CuryRetainagePaidTotal;
                }
            }
        }
        protected virtual void APInvoice_RetainageApply_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            APInvoice document = (APInvoice)e.Row;
            bool?     newValue = (bool?)e.NewValue;

            if (document == null)
            {
                return;
            }

            if (document.RetainageApply == true && newValue == false)
            {
                IEnumerable <APTran> trans = Base.Transactions.Select().Where(tran => ((APTran)tran).CuryRetainageAmt != 0 || ((APTran)tran).RetainagePct != 0).RowCast <APTran>();

                if (!trans.Any())
                {
                    return;
                }

                WebDialogResult wdr =
                    Base.Document.Ask(
                        Messages.Warning,
                        Messages.UncheckApplyRetainage,
                        MessageButtons.YesNo,
                        MessageIcon.Warning);

                if (wdr == WebDialogResult.Yes)
                {
                    foreach (APTran tran in trans)
                    {
                        tran.CuryRetainageAmt = 0m;
                        tran.RetainagePct     = 0m;
                        Base.Transactions.Update(tran);
                    }
                }
                else
                {
                    e.Cancel   = true;
                    e.NewValue = true;
                }
            }
            else if (document.RetainageApply != true && newValue == true)
            {
                ClearCurrentDocumentDiscountDetails();
            }
        }
 public virtual IEnumerable viewDocument(PXAdapter adapter)
 {
     if (this.documents.Current != null)
     {
         APInvoiceEntry graph = PXGraph.CreateInstance <APInvoiceEntry>();
         APInvoice      poDoc = graph.Document.Search <APInvoice.refNbr>(this.documents.Current.RefNbr, this.documents.Current.DocType);
         if (poDoc != null)
         {
             graph.Document.Current = poDoc;
             throw new PXRedirectRequiredException(graph, true, "Document")
                   {
                       Mode = PXBaseRedirectException.WindowMode.NewWindow
                   };
         }
     }
     return(adapter.Get());
 }
示例#14
0
        protected virtual IEnumerable apdocumentlist()
        {
            ApproveBillsFilter filter = Filter.Current;

            if (filter != null && filter.SelectionDate != null)
            {
                DateTime PayInLessThan             = ((DateTime)filter.SelectionDate).AddDays(filter.PayInLessThan.GetValueOrDefault());
                DateTime DueInLessThan             = ((DateTime)filter.SelectionDate).AddDays(filter.DueInLessThan.GetValueOrDefault());
                DateTime DiscountExpiresInLessThan = ((DateTime)filter.SelectionDate).AddDays(filter.DiscountExpiresInLessThan.GetValueOrDefault());

                PXView view = new PXView(this, false, BqlCommand.CreateInstance(getAPDocumentSelect(false)));

                foreach (PXResult <APInvoice> res in
                         view.Graph.QuickSelect(view.BqlSelect, new object[] { PayInLessThan, DueInLessThan, DiscountExpiresInLessThan }, null, false))
                {
                    APInvoice apdoc = res;

                    if (string.IsNullOrEmpty(apdoc.PayTypeID))
                    {
                        try
                        {
                            APDocumentList.Cache.SetDefaultExt <APInvoice.payTypeID>(apdoc);
                        }
                        catch (PXSetPropertyException e)
                        {
                            APDocumentList.Cache.RaiseExceptionHandling <APInvoice.payTypeID>(apdoc, apdoc.PayTypeID, e);
                        }
                    }

                    if (apdoc.PayAccountID == null)
                    {
                        try
                        {
                            APDocumentList.Cache.SetDefaultExt <APInvoice.payAccountID>(apdoc);
                        }
                        catch (PXSetPropertyException e)
                        {
                            APDocumentList.Cache.RaiseExceptionHandling <APInvoice.payAccountID>(apdoc, apdoc.PayAccountID, e);
                        }
                    }

                    yield return(apdoc);
                }
            }
        }
        public virtual IEnumerable ViewInvoice(PXAdapter adapter)
        {
            PendingPPDDebitAdjApp adj = Applications.Current;

            if (adj != null)
            {
                APInvoice invoice = PXSelect <APInvoice, Where <APInvoice.refNbr, Equal <Current <PendingPPDDebitAdjApp.invRefNbr> >,
                                                                And <APInvoice.docType, Equal <Current <PendingPPDDebitAdjApp.invDocType> > > > >
                                    .Select(this).First();

                if (invoice != null)
                {
                    PXGraph graph = PXGraph.CreateInstance <APInvoiceEntry>();
                    PXRedirectHelper.TryRedirect(graph, invoice, PXRedirectHelper.WindowMode.NewWindow);
                }
            }
            return(adapter.Get());
        }
        private void SetNumbering(PXCache sender, APInvoice row)
        {
            if (row == null)
            {
                return;
            }
            if (Base.IsWithinContext)
            {
                Numbering numbering = PXSelectJoin <Numbering,
                                                    InnerJoin <GLWorkBook, On <GLWorkBook.voucherNumberingID, Equal <Numbering.numberingID> > >,
                                                    Where <GLWorkBook.workBookID, Equal <Required <GLWorkBook.workBookID> > > > .Select(this.Base, Base.GetContextValue <GLVoucherBatch.workBookID>());

                AutoNumberAttribute.SetNumberingId <APInvoice.refNbr>(sender, row.DocType, numbering.NumberingID);
                if (numbering.UserNumbering == true)
                {
                    sender.RaiseExceptionHandling <APInvoice.refNbr>(row, row.RefNbr, new PXException(GL.Messages.ManualNumberingDisabled));
                }
            }
        }
        protected virtual void APInvoice_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            APInvoice doc = (APInvoice)e.Row;

            Terms terms = (Terms)PXSelectorAttribute.Select <APInvoice.termsID>(Base.Document.Cache, doc);

            if (terms != null && doc.RetainageApply == true && terms.InstallmentType == CS.TermsInstallmentType.Multiple)
            {
                sender.RaiseExceptionHandling <APInvoice.termsID>(doc, doc.TermsID, new PXSetPropertyException(Messages.RetainageWithMultipleCreditTerms));
            }

            bool disablePersistingCheckForRetainageAccountAndSub = doc.RetainageApply != true;

            PXDefaultAttribute.SetPersistingCheck <APRegister.retainageAcctID>(sender, doc, disablePersistingCheckForRetainageAccountAndSub
                                ? PXPersistingCheck.Nothing
                                : PXPersistingCheck.NullOrBlank);
            PXDefaultAttribute.SetPersistingCheck <APInvoice.retainageSubID>(sender, doc, disablePersistingCheckForRetainageAccountAndSub
                                ? PXPersistingCheck.Nothing
                                : PXPersistingCheck.NullOrBlank);
        }
        /// <summary>
        /// Removes all application records associated with the specified
        /// document. This is required in order to prevent stuck application
        /// records after a document becomes scheduled.
        /// </summary>
        private void RemoveApplications(DocumentSelection document)
        {
            APInvoiceEntry invoiceEntry = PXGraph.CreateInstance <APInvoiceEntry>();

            APInvoice documentAsInvoice = PXSelect <
                APInvoice,
                Where <
                    APInvoice.docType, Equal <Required <APInvoice.docType> >,
                    And <APInvoice.refNbr, Equal <Required <APInvoice.refNbr> > > > >
                                          .Select(invoiceEntry, document.DocType, document.RefNbr);

            invoiceEntry.Document.Current = documentAsInvoice;

            invoiceEntry.Adjustments
            .Select()
            .RowCast <APInvoiceEntry.APAdjust>()
            .Where(application => application.Released != true)
            .ForEach(application => invoiceEntry.Adjustments.Delete(application));

            invoiceEntry.Save.Press();
        }
示例#19
0
        public IEnumerable Adjustments()
        {
            var newAdjustments = SelectFrom <APAdjust> .
                                 LeftJoin <APInvoice> .On <APInvoice.docType.IsEqual <APAdjust.adjdDocType> .And <APInvoice.refNbr.IsEqual <APAdjust.adjdRefNbr> > > .
                                 LeftJoin <APTran> .On <APInvoice.paymentsByLinesAllowed.IsEqual <True> .And <APTran.tranType.IsEqual <APAdjust.adjdDocType> .And <APTran.refNbr.IsEqual <APAdjust.adjdRefNbr> .And <APTran.lineNbr.IsEqual <APAdjust.adjdLineNbr> > > > > .
                                 Where <APAdjust.adjgDocType.IsEqual <APPayment.docType.FromCurrent> .And <APAdjust.adjgRefNbr.IsEqual <APPayment.refNbr.FromCurrent> .And <APAdjust.released.IsNotEqual <True> > > > .
                                 View.Select(Base);

            var row = Base.Document.Current;

            if (row == null)
            {
                return(newAdjustments);
            }

            var aPPaymentVendorCrossRateAttr = SelectFrom <CSAnswers> .
                                               LeftJoin <BAccountR> .On <CSAnswers.refNoteID.IsEqual <BAccountR.noteID> > .
                                               LeftJoin <APPayment> .On <BAccountR.bAccountID.IsEqual <APPayment.vendorID> > .
                                               Where <APPayment.refNbr.IsEqual <@P.AsString> .And <APPayment.docType.IsEqual <@P.AsString> > .And <CSAnswers.attributeID.IsEqual <VendorCrossRateAttr> > > .
                                               View.Select(Base, row.RefNbr, row.DocType).TopFirst?.Value;

            foreach (PXResult <APAdjust, APInvoice, APTran> adjustment in newAdjustments)
            {
                APAdjust  aPAdjust  = adjustment;
                APInvoice aPInvoice = adjustment;

                if (row.CuryID != aPInvoice.CuryID && aPPaymentVendorCrossRateAttr == "1" && Convert.ToDecimal(aPAdjust.AdjdCuryRate) != 1.00m && aPInvoice.CuryInfoID != null)
                {
                    var curyInfo = SelectFrom <CurrencyInfo> .Where <CurrencyInfo.curyInfoID.IsEqual <@P.AsInt> > .View.Select(Base, aPInvoice.CuryInfoID).TopFirst;

                    var curyInfoCuryRate = curyInfo?.CuryMultDiv == "M" ? curyInfo?.CuryRate : curyInfo?.RecipRate;
                    aPAdjust.AdjdCuryRate = curyInfoCuryRate == null ? aPAdjust.AdjdCuryRate : curyInfoCuryRate;
                }
            }
            return(newAdjustments);
        }
        protected virtual void APInvoice_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            APInvoice document = e.Row as APInvoice;

            if (document == null)
            {
                return;
            }

            bool isDocumentReleasedOrPrebooked = document.Released == true || document.Prebooked == true;
            bool isDocumentVoided  = document.Voided == true;
            bool isDocumentInvoice = document.DocType == APDocType.Invoice;
            bool retainageApply    = document.RetainageApply == true;

            releaseRetainage.SetEnabled(false);

            if (isDocumentReleasedOrPrebooked || isDocumentVoided)
            {
                releaseRetainage.SetEnabled(isDocumentInvoice &&
                                            document.Released == true &&
                                            retainageApply &&
                                            document.CuryRetainageUnreleasedAmt > 0m);
            }
        }
        public virtual IEnumerable ReleaseRetainage(PXAdapter adapter)
        {
            APInvoice doc = Base.Document.Current;

            if (doc != null &&
                doc.DocType == APDocType.Invoice &&
                doc.RetainageApply == true &&
                doc.CuryRetainageUnreleasedAmt > 0m)
            {
                APRetainageInvoice retainageDoc = RetainageDocuments
                                                  .Select()
                                                  .RowCast <APRetainageInvoice>()
                                                  .FirstOrDefault(row => row.Released != true);

                if (retainageDoc != null)
                {
                    throw new PXException(
                              Messages.ReleaseRetainageNotReleasedDocument,
                              PXMessages.LocalizeNoPrefix(APDocTypeDict[retainageDoc.DocType]),
                              retainageDoc.RefNbr,
                              PXMessages.LocalizeNoPrefix(APDocTypeDict[doc.DocType]));
                }

                APRegister reversingDoc;
                if (Base.CheckReversingRetainageDocumentAlreadyExists(Base.Document.Current, out reversingDoc))
                {
                    throw new PXException(
                              Messages.ReleaseRetainageReversingDocumentExists,
                              PXMessages.LocalizeNoPrefix(APDocTypeDict[doc.DocType]),
                              PXMessages.LocalizeNoPrefix(APDocTypeDict[reversingDoc.DocType]),
                              reversingDoc.RefNbr);
                }

                Base.Save.Press();

                RetainageOptions retainageOpts = ReleaseRetainageOptions.Current;

                WebDialogResult wdr = ReleaseRetainageOptions.AskExt(
                    (graph, view) =>
                {
                    retainageOpts.CuryRetainageTotal         = doc.CuryRetainageUnreleasedAmt;
                    retainageOpts.RetainagePct               = 100m;
                    retainageOpts.CuryRetainageAmt           = doc.CuryRetainageUnreleasedAmt;
                    retainageOpts.CuryRetainageUnreleasedAmt = retainageOpts.CuryRetainageTotal - retainageOpts.CuryRetainageAmt;
                },
                    true);

                if (wdr == WebDialogResult.OK)
                {
                    APInvoice invoice = PXCache <APInvoice> .CreateCopy(doc);

                    try
                    {
                        ReleaseRetainageProc(invoice, retainageOpts);
                        return(new List <APInvoice> {
                            Base.Document.Current
                        });
                    }
                    catch (PXException)
                    {
                        Base.Clear(PXClearOption.PreserveTimeStamp);
                        Base.Document.Current = doc;
                        throw;
                    }
                }
            }

            return(adapter.Get());
        }
示例#22
0
        protected virtual IEnumerable apdocumentlist()
        {
            ApproveBillsFilter filter = Filter.Current;

            if (filter != null && filter.SelectionDate != null)
            {
                DateTime PayInLessThan             = ((DateTime)filter.SelectionDate).AddDays(filter.PayInLessThan.GetValueOrDefault());
                DateTime DueInLessThan             = ((DateTime)filter.SelectionDate).AddDays(filter.DueInLessThan.GetValueOrDefault());
                DateTime DiscountExpiresInLessThan = ((DateTime)filter.SelectionDate).AddDays(filter.DiscountExpiresInLessThan.GetValueOrDefault());

                foreach (PXResult <APInvoice, Vendor, APAdjust> res in PXSelectJoin <APInvoice,
                                                                                     InnerJoin <Vendor, On <Vendor.bAccountID, Equal <APInvoice.vendorID> >,
                                                                                                LeftJoin <APAdjust, On <APAdjust.adjdDocType, Equal <APInvoice.docType>,
                                                                                                                        And <APAdjust.adjdRefNbr, Equal <APInvoice.refNbr>,
                                                                                                                             And <APAdjust.released, Equal <False> > > >,
                                                                                                          LeftJoin <APPayment, On <APPayment.docType, Equal <APInvoice.docType>,
                                                                                                                                   And <APPayment.refNbr, Equal <APInvoice.refNbr>,
                                                                                                                                        And <Where <APPayment.docType, Equal <APDocType.prepayment>, Or <APPayment.docType, Equal <APDocType.debitAdj> > > > > > > > >,
                                                                                     Where <APInvoice.openDoc, Equal <True>,
                                                                                            And2 <Where <APInvoice.released, Equal <True>, Or <APInvoice.prebooked, Equal <True> > >,
                                                                                                  And <APAdjust.adjgRefNbr, IsNull,
                                                                                                       And <APPayment.refNbr, IsNull,
                                                                                                            And2 <Match <Vendor, Current <AccessInfo.userName> >,
                                                                                                                  And2 <Where <APInvoice.curyID, Equal <Current <ApproveBillsFilter.curyID> >,
                                                                                                                               Or <Current <ApproveBillsFilter.curyID>, IsNull> >,
                                                                                                                        And2 <Where2 <Where <Current <ApproveBillsFilter.showApprovedForPayment>, Equal <True>,
                                                                                                                                             And <APInvoice.paySel, Equal <True> > >,
                                                                                                                                      Or <Where <Current <ApproveBillsFilter.showNotApprovedForPayment>, Equal <True>,
                                                                                                                                                 And <APInvoice.paySel, Equal <False> > > > >,
                                                                                                                              And2 <Where <Vendor.bAccountID, Equal <Current <ApproveBillsFilter.vendorID> >,
                                                                                                                                           Or <Current <ApproveBillsFilter.vendorID>, IsNull> >,
                                                                                                                                    And2 <Where <Vendor.vendorClassID, Equal <Current <ApproveBillsFilter.vendorClassID> >,
                                                                                                                                                 Or <Current <ApproveBillsFilter.vendorClassID>, IsNull> >,
                                                                                                                                          And <Where2 <Where2 <Where <Current <ApproveBillsFilter.showPayInLessThan>, Equal <True>, And <APInvoice.payDate, LessEqual <Required <APInvoice.payDate> > > >,
                                                                                                                                                               Or2 <Where <Current <ApproveBillsFilter.showDueInLessThan>, Equal <True>,
                                                                                                                                                                           And <APInvoice.dueDate, LessEqual <Required <APInvoice.dueDate> > > >,
                                                                                                                                                                    Or <Where <Current <ApproveBillsFilter.showDiscountExpiresInLessThan>, Equal <True>,
                                                                                                                                                                               And <APInvoice.discDate, LessEqual <Required <APInvoice.discDate> > > > > > >,
                                                                                                                                                       Or <Where <Current <ApproveBillsFilter.showPayInLessThan>, Equal <False>,
                                                                                                                                                                  And <Current <ApproveBillsFilter.showDueInLessThan>, Equal <False>,
                                                                                                                                                                       And <Current <ApproveBillsFilter.showDiscountExpiresInLessThan>, Equal <False> > > > > > > > > > > > > > > > >
                         .Select(this, PayInLessThan, DueInLessThan, DiscountExpiresInLessThan))
                {
                    APInvoice apdoc = res;

                    if (string.IsNullOrEmpty(apdoc.PayTypeID))
                    {
                        try
                        {
                            APDocumentList.Cache.SetDefaultExt <APInvoice.payTypeID>(apdoc);
                        }
                        catch (PXSetPropertyException e)
                        {
                            APDocumentList.Cache.RaiseExceptionHandling <APInvoice.payTypeID>(apdoc, apdoc.PayTypeID, e);
                        }
                    }

                    if (apdoc.PayAccountID == null)
                    {
                        try
                        {
                            APDocumentList.Cache.SetDefaultExt <APInvoice.payAccountID>(apdoc);
                        }
                        catch (PXSetPropertyException e)
                        {
                            APDocumentList.Cache.RaiseExceptionHandling <APInvoice.payAccountID>(apdoc, apdoc.PayAccountID, e);
                        }
                    }

                    yield return(apdoc);
                }
            }
        }
        public virtual void GenerateProc(Schedule s, short Times, DateTime runDate)
        {
            List <ScheduleDet> sd = GL.ScheduleProcess.MakeSchedule(this, s, Times, runDate);

            APInvoiceEntry docgraph = CreateGraph();

            foreach (ScheduleDet sdet in sd)
            {
                foreach (PXResult <APInvoice, Vendor, CurrencyInfo> res in PXSelectJoin <APInvoice, InnerJoin <Vendor, On <Vendor.bAccountID, Equal <APInvoice.vendorID> >, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <APInvoice.curyInfoID> > > >, Where <APInvoice.scheduleID, Equal <Required <APInvoice.scheduleID> >, And <APInvoice.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID))
                {
                    docgraph.Clear();
                    docgraph.vendor.Current = (Vendor)res;
                    APInvoice    apdoc = (APInvoice)res;
                    CurrencyInfo info  = (CurrencyInfo)res;

                    CurrencyInfo new_info = PXCache <CurrencyInfo> .CreateCopy(info);

                    new_info.CuryInfoID = null;
                    new_info            = docgraph.currencyinfo.Insert(new_info);

                    APInvoice new_apdoc = PXCache <APInvoice> .CreateCopy(apdoc);

                    new_apdoc.CuryInfoID          = new_info.CuryInfoID;
                    new_apdoc.DocDate             = sdet.ScheduledDate;
                    new_apdoc.FinPeriodID         = sdet.ScheduledPeriod;
                    new_apdoc.TranPeriodID        = null;
                    new_apdoc.DueDate             = null;
                    new_apdoc.DiscDate            = null;
                    new_apdoc.PayDate             = null;
                    new_apdoc.CuryOrigDiscAmt     = null;
                    new_apdoc.OrigDiscAmt         = null;
                    new_apdoc.RefNbr              = null;
                    new_apdoc.Scheduled           = false;
                    new_apdoc.CuryLineTotal       = 0m;
                    new_apdoc.CuryVatTaxableTotal = 0m;
                    new_apdoc.CuryVatExemptTotal  = 0m;
                    new_apdoc.NoteID              = null;
                    new_apdoc = docgraph.Document.Insert(new_apdoc);

                    TaxAttribute.SetTaxCalc <APTran.taxCategoryID, APTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc);
                    PXNoteAttribute.SetNote(docgraph.Document.Cache, new_apdoc, PXNoteAttribute.GetNote(Caches[typeof(APInvoice)], apdoc));
                    PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, new_apdoc, PXNoteAttribute.GetFileNotes(Caches[typeof(APInvoice)], apdoc));

                    foreach (APTran aptran in PXSelect <APTran, Where <APTran.tranType, Equal <Required <APTran.tranType> >, And <APTran.refNbr, Equal <Required <APTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr))
                    {
                        APTran new_aptran = PXCache <APTran> .CreateCopy(aptran);

                        new_aptran.RefNbr     = null;
                        new_aptran.CuryInfoID = null;
                        docgraph.Transactions.Insert(new_aptran);
                    }

                    foreach (APTaxTran tax in PXSelect <APTaxTran, Where <APTaxTran.tranType, Equal <Required <APTaxTran.tranType> >, And <APTaxTran.refNbr, Equal <Required <APTaxTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr))
                    {
                        APTaxTran new_aptax = new APTaxTran();
                        new_aptax.TaxID = tax.TaxID;

                        new_aptax = docgraph.Taxes.Insert(new_aptax);

                        if (new_aptax != null)
                        {
                            new_aptax = PXCache <APTaxTran> .CreateCopy(new_aptax);

                            new_aptax.TaxRate        = tax.TaxRate;
                            new_aptax.CuryTaxableAmt = tax.CuryTaxableAmt;
                            new_aptax.CuryTaxAmt     = tax.CuryTaxAmt;
                            new_aptax = docgraph.Taxes.Update(new_aptax);
                        }
                    }
                    docgraph.Save.Press();
                }
                s.LastRunDate = sdet.ScheduledDate;
                Running_Schedule.Cache.Update(s);
            }

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                Running_Schedule.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }
            Running_Schedule.Cache.Persisted(false);
        }
示例#24
0
        protected virtual IEnumerable apdocumentlist()
        {
            ApproveBillsFilter filter = (ApproveBillsFilter)Filter.Current;
            PXResultset<APInvoice> ret = new PXResultset<APInvoice>();

            if (filter != null && filter.SelectionDate!=null)
            {
                                DateTime PayInLessThan = ((DateTime)filter.SelectionDate).AddDays(filter.PayInLessThan.GetValueOrDefault());
                                DateTime DueInLessThan = ((DateTime)filter.SelectionDate).AddDays(filter.DueInLessThan.GetValueOrDefault());
                                DateTime DiscountExpiresInLessThan = ((DateTime)filter.SelectionDate).AddDays(filter.DiscountExpiresInLessThan.GetValueOrDefault());

                foreach (PXResult<APInvoice, Vendor, APAdjust> res in PXSelectJoin<APInvoice,
                        InnerJoin<Vendor,
                            On<Vendor.bAccountID, Equal<APInvoice.vendorID>>,
                        LeftJoin<APAdjust,
                            On<APAdjust.adjdDocType, Equal<APInvoice.docType>,
                             And<APAdjust.adjdRefNbr, Equal<APInvoice.refNbr>,
                             And<APAdjust.released, Equal<boolFalse>>>>,
                        LeftJoin<APPayment,
                            On<APPayment.docType, Equal<APInvoice.docType>,
                            And<APPayment.refNbr, Equal<APInvoice.refNbr>,
                            And<Where<APPayment.docType, Equal<APDocType.prepayment>, Or<APPayment.docType, Equal<APDocType.debitAdj>>>>>>>>>,
                    Where<APInvoice.openDoc, Equal<boolTrue>,
                        And2<Where<APInvoice.released, Equal<boolTrue>, Or<APInvoice.prebooked, Equal<boolTrue>>>,
                        And<APAdjust.adjgRefNbr, IsNull,
                        And<APPayment.refNbr, IsNull,
                        And2<Where<APInvoice.curyID, Equal<Current<ApproveBillsFilter.curyID>>,
                               Or<Current<ApproveBillsFilter.curyID>, IsNull>>,
                        And2<Where2<Where<Current<ApproveBillsFilter.showApprovedForPayment>, Equal<boolTrue>,
                                        And<APInvoice.paySel, Equal<boolTrue>>>,
                                 Or<Where<Current<ApproveBillsFilter.showNotApprovedForPayment>, Equal<boolTrue>,
                                        And<APInvoice.paySel, Equal<boolFalse>>>>>,
                        And2<Where<Vendor.bAccountID, Equal<Current<ApproveBillsFilter.vendorID>>,
                                 Or<Current<ApproveBillsFilter.vendorID>, IsNull>>,
                        And2<Where<Vendor.vendorClassID, Equal<Current<ApproveBillsFilter.vendorClassID>>,
                                 Or<Current<ApproveBillsFilter.vendorClassID>, IsNull>>,
                                                And<Where2<Where2<Where<Current<ApproveBillsFilter.showPayInLessThan>, Equal<boolTrue>,
                                                                                                And<APInvoice.payDate, LessEqual<Required<APInvoice.payDate>>
                                                                                                >>,
                                        Or2<Where<Current<ApproveBillsFilter.showDueInLessThan>, Equal<boolTrue>,
                                                And<APInvoice.dueDate, LessEqual<Required<APInvoice.dueDate>>
                                                >>,
                                        Or<Where<Current<ApproveBillsFilter.showDiscountExpiresInLessThan>, Equal<boolTrue>,
                                                And<APInvoice.discDate, LessEqual<Required<APInvoice.discDate>>
                                                >>>>>,
                                                                Or<Where<Current<ApproveBillsFilter.showPayInLessThan>, Equal<boolFalse>,
                                       And<Current<ApproveBillsFilter.showDueInLessThan>, Equal<boolFalse>,
                                       And<Current<ApproveBillsFilter.showDiscountExpiresInLessThan>, Equal<boolFalse>>>>>
                                   >>>>>>>>>>>.Select(this,
                                                                                    PayInLessThan,
                                          DueInLessThan,
                                          DiscountExpiresInLessThan))
                {
                    APInvoice apdoc = (APInvoice)res;
                    Vendor vend = (Vendor)res;

                    if (string.IsNullOrEmpty(apdoc.PayTypeID))
                    {
                        APDocumentList.Cache.SetDefaultExt<APInvoice.payTypeID>(apdoc);
                    }

                    if (apdoc.PayAccountID == null)
                    {
                        APDocumentList.Cache.SetDefaultExt<APInvoice.payAccountID>(apdoc);
                    }

                    ret.Add(new PXResult<APInvoice>(apdoc));
                }
            }
            return ret;
        }
        public static void CreatePPDDebitAdjs(PXCache cache, APPPDDebitAdjParameters filter, APSetup setup, List <PendingPPDDebitAdjApp> docs)
        {
            int            i      = 0;
            bool           failed = false;
            APInvoiceEntry ie     = PXGraph.CreateInstance <APInvoiceEntry>();

            ie.APSetup.Current = setup;

            if (filter.GenerateOnePerVendor == true)
            {
                if (filter.DebitAdjDate == null)
                {
                    throw new PXSetPropertyException(CR.Messages.EmptyValueErrorFormat,
                                                     PXUIFieldAttribute.GetDisplayName <APPPDDebitAdjParameters.debitAdjDate>(cache));
                }

                if (filter.FinPeriodID == null)
                {
                    throw new PXSetPropertyException(CR.Messages.EmptyValueErrorFormat,
                                                     PXUIFieldAttribute.GetDisplayName <APPPDDebitAdjParameters.finPeriodID>(cache));
                }

                Dictionary <PPDApplicationKey, List <PendingPPDDebitAdjApp> > dict = new Dictionary <PPDApplicationKey, List <PendingPPDDebitAdjApp> >();
                foreach (PendingPPDDebitAdjApp pendingPPDDebitAdjApp in docs)
                {
                    CurrencyInfo info = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(ie, pendingPPDDebitAdjApp.InvCuryInfoID);

                    PPDApplicationKey key = new PPDApplicationKey();
                    pendingPPDDebitAdjApp.Index = i++;
                    key.BranchID   = pendingPPDDebitAdjApp.AdjdBranchID;
                    key.BAccountID = pendingPPDDebitAdjApp.VendorID;
                    key.LocationID = pendingPPDDebitAdjApp.InvVendorLocationID;
                    key.CuryID     = info.CuryID;
                    key.CuryRate   = info.CuryRate;
                    key.AccountID  = pendingPPDDebitAdjApp.AdjdAPAcct;
                    key.SubID      = pendingPPDDebitAdjApp.AdjdAPSub;
                    key.TaxZoneID  = pendingPPDDebitAdjApp.InvTaxZoneID;

                    List <PendingPPDDebitAdjApp> list;
                    if (!dict.TryGetValue(key, out list))
                    {
                        dict[key] = list = new List <PendingPPDDebitAdjApp>();
                    }

                    list.Add(pendingPPDDebitAdjApp);
                }

                foreach (List <PendingPPDDebitAdjApp> list in dict.Values)
                {
                    APInvoice invoice = CreateAndReleasePPDDebitAdj(ie, filter, list, AutoReleaseDebitAdjustments);

                    if (invoice == null)
                    {
                        failed = true;
                    }
                }
            }
            else
            {
                foreach (PendingPPDDebitAdjApp pendingPPDDebitAdjApp in docs)
                {
                    List <PendingPPDDebitAdjApp> list = new List <PendingPPDDebitAdjApp>(1);
                    pendingPPDDebitAdjApp.Index = i++;
                    list.Add(pendingPPDDebitAdjApp);

                    APInvoice invoice = CreateAndReleasePPDDebitAdj(ie, filter, list, AutoReleaseDebitAdjustments);

                    if (invoice == null)
                    {
                        failed = true;
                    }
                }
            }

            if (failed)
            {
                throw new PXException(GL.Messages.DocumentsNotReleased);
            }
        }
        public virtual void GenerateProc(Schedule schedule, short times, DateTime runDate)
        {
            IEnumerable <ScheduleDet> occurrences = new Scheduler(this).MakeSchedule(schedule, times, runDate);

            APInvoiceEntry invoiceEntry = CreateGraph();

            using (PXTransactionScope transactionScope = new PXTransactionScope())
            {
                foreach (ScheduleDet occurrence in occurrences)
                {
                    foreach (PXResult <APInvoice, Vendor, CurrencyInfo> scheduledInvoiceResult in PXSelectJoin <
                                 APInvoice,
                                 InnerJoin <Vendor, On <Vendor.bAccountID, Equal <APInvoice.vendorID> >,
                                            InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <APInvoice.curyInfoID> > > >,
                                 Where <
                                     APInvoice.scheduleID, Equal <Required <APInvoice.scheduleID> >,
                                     And <APInvoice.scheduled, Equal <boolTrue> > > >
                             .Select(this, schedule.ScheduleID))
                    {
                        invoiceEntry.Clear();

                        invoiceEntry.vendor.Current = (Vendor)scheduledInvoiceResult;
                        APInvoice    scheduledInvoice             = (APInvoice)scheduledInvoiceResult;
                        CurrencyInfo scheduledInvoiceCurrencyInfo = (CurrencyInfo)scheduledInvoiceResult;

                        if (scheduledInvoice.Released == true)
                        {
                            throw new PXException(AR.Messages.ScheduledDocumentAlreadyReleased);
                        }

                        // Cloning currency info is required because we want to preserve
                        // (and not default) the currency rate type of the template document.
                        // -
                        CurrencyInfo newCurrencyInfo = PXCache <CurrencyInfo> .CreateCopy(scheduledInvoiceCurrencyInfo);

                        newCurrencyInfo.CuryInfoID  = null;
                        newCurrencyInfo.CuryRate    = null;
                        newCurrencyInfo.CuryEffDate = occurrence.ScheduledDate;

                        newCurrencyInfo = invoiceEntry.currencyinfo.Insert(newCurrencyInfo);

                        APInvoice newInvoice = PXCache <APInvoice> .CreateCopy(scheduledInvoice);

                        newInvoice.CuryInfoID          = newCurrencyInfo.CuryInfoID;
                        newInvoice.DocDate             = occurrence.ScheduledDate;
                        newInvoice.FinPeriodID         = occurrence.ScheduledPeriod;
                        newInvoice.TranPeriodID        = null;
                        newInvoice.DueDate             = null;
                        newInvoice.DiscDate            = null;
                        newInvoice.PayDate             = null;
                        newInvoice.CuryOrigDiscAmt     = null;
                        newInvoice.OrigDiscAmt         = null;
                        newInvoice.RefNbr              = null;
                        newInvoice.Scheduled           = false;
                        newInvoice.CuryLineTotal       = 0m;
                        newInvoice.CuryVatTaxableTotal = 0m;
                        newInvoice.CuryVatExemptTotal  = 0m;
                        newInvoice.NoteID              = null;
                        newInvoice.PaySel              = false;
                        newInvoice.IsTaxValid          = false;
                        newInvoice.IsTaxPosted         = false;
                        newInvoice.IsTaxSaved          = false;
                        newInvoice.OrigDocType         = scheduledInvoice.DocType;
                        newInvoice.OrigRefNbr          = scheduledInvoice.RefNbr;

                        newInvoice = invoiceEntry.Document.Insert(newInvoice);                         //we insert an item here because we need DontApprove field to be set in RowSelected
                        if (newInvoice.DontApprove != true)
                        {
                            // We always generate documents on hold
                            // if approval process is enabled in AP.
                            // -
                            newInvoice.Hold = true;
                        }

                        newInvoice = invoiceEntry.Document.Update(newInvoice);

                        CurrencyInfoAttribute.SetEffectiveDate <APInvoice.docDate>(
                            invoiceEntry.Document.Cache,
                            new PXFieldUpdatedEventArgs(newInvoice, null, false));

                        PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(APInvoice)], scheduledInvoice, invoiceEntry.Document.Cache, newInvoice);

                        foreach (APTran originalLine in PXSelect <
                                     APTran,
                                     Where <
                                         APTran.tranType, Equal <Required <APTran.tranType> >,
                                         And <APTran.refNbr, Equal <Required <APTran.refNbr> >,
                                              And <Where <
                                                       APTran.lineType, IsNull,
                                                       Or <APTran.lineType, NotEqual <SOLineType.discount> > > > > > >
                                 .Select(invoiceEntry, scheduledInvoice.DocType, scheduledInvoice.RefNbr))
                        {
                            APTran newLine = PXCache <APTran> .CreateCopy(originalLine);

                            newLine.RefNbr      = null;
                            newLine.CuryInfoID  = null;
                            newLine.ManualPrice = true;
                            newLine.ManualDisc  = true;
                            newLine.NoteID      = null;
                            newLine             = invoiceEntry.Transactions.Insert(newLine);

                            PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(APTran)], originalLine, invoiceEntry.Transactions.Cache, newLine);
                        }

                        foreach (APInvoiceDiscountDetail originalDiscountDetail in PXSelect <
                                     APInvoiceDiscountDetail,
                                     Where <
                                         APInvoiceDiscountDetail.docType, Equal <Required <APInvoiceDiscountDetail.docType> >,
                                         And <APInvoiceDiscountDetail.refNbr, Equal <Required <APInvoiceDiscountDetail.refNbr> > > > >
                                 .Select(invoiceEntry, scheduledInvoice.DocType, scheduledInvoice.RefNbr))
                        {
                            APInvoiceDiscountDetail newDiscountDetail =
                                PXCache <APInvoiceDiscountDetail> .CreateCopy(originalDiscountDetail);

                            newDiscountDetail.RefNbr     = null;
                            newDiscountDetail.CuryInfoID = null;
                            newDiscountDetail.IsManual   = true;

                            DiscountEngineProvider.GetEngineFor <APTran, APInvoiceDiscountDetail>().InsertDiscountDetail(invoiceEntry.DiscountDetails.Cache, invoiceEntry.DiscountDetails, newDiscountDetail);
                        }

                        BalanceCalculation.ForceDocumentControlTotals(invoiceEntry, newInvoice);

                        try
                        {
                            invoiceEntry.Save.Press();
                        }
                        catch
                        {
                            if (invoiceEntry.Document.Cache.IsInsertedUpdatedDeleted)
                            {
                                throw;
                            }
                        }
                    }

                    schedule.LastRunDate = occurrence.ScheduledDate;
                    Running_Schedule.Cache.Update(schedule);
                }

                transactionScope.Complete(this);
            }

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                Running_Schedule.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }

            Running_Schedule.Cache.Persisted(false);
        }
示例#27
0
        public virtual IEnumerable documents()
        {
            PendingInvoiceFilter filter = Filter.Current;
            Dictionary <CashAcctKey, PendingPaymentSummary> result = new Dictionary <CashAcctKey, PendingPaymentSummary>();

            if (filter == null && !filter.PayDate.HasValue)
            {
                return(result.Values);
            }
            PXSelectBase <APInvoice> sel = new PXSelectJoin <APInvoice,
                                                             InnerJoin <CashAccount, On <CashAccount.cashAccountID, Equal <APInvoice.payAccountID> >,
                                                                        LeftJoin <APAdjust, On <APInvoice.docType, Equal <APAdjust.adjdDocType>,
                                                                                                And <APInvoice.refNbr, Equal <APAdjust.adjdRefNbr>, And <APAdjust.released, Equal <BitOff> > > > > >,
                                                             Where <APInvoice.paySel, Equal <BitOn>,
                                                                    And2 <Where <APInvoice.released, Equal <True>, Or <APInvoice.prebooked, Equal <True> > >,
                                                                          And <APInvoice.openDoc, Equal <BitOn> > > >,
                                                             OrderBy <
                                                                 Asc <APInvoice.docType,
                                                                      Asc <APInvoice.refNbr> > >
                                                             >(this);

            /*if(filter.CuryID != null)
             * {
             *      sel.WhereAnd<Where<APInvoice.curyID, Equal<Current<PendingInvoiceFilter.curyID>>>>();
             * }*/
            if (filter.PayDate != null)
            {
                sel.WhereAnd <Where <APInvoice.payDate, LessEqual <Current <PendingInvoiceFilter.payDate> > > >();
            }

            if (filter.PayAccountID != null)
            {
                sel.WhereAnd <Where <APInvoice.payAccountID, Equal <Current <PendingInvoiceFilter.payAccountID> > > >();
            }

            if (filter.PayTypeID != null)
            {
                sel.WhereAnd <Where <APInvoice.payTypeID, Equal <Current <PendingInvoiceFilter.payTypeID> > > >();
            }

            APInvoiceKey lastInvoice = null;

            foreach (PXResult <APInvoice, CashAccount, APAdjust> it in sel.Select())
            {
                APInvoice   inv    = (APInvoice)it;
                CashAccount acct   = (CashAccount)it;
                APAdjust    adjust = (APAdjust)it;
                if (adjust.AdjdDocType != null)
                {
                    continue;                                     //Skip invoices, having unreleased payments
                }
                APInvoiceKey invNbr = new APInvoiceKey(inv.DocType, inv.RefNbr);
                if (lastInvoice != null && lastInvoice.CompareTo(invNbr) == 0)
                {
                    continue;                     //Skip multiple entries for invoice
                }
                //inv.DocCount = it.RowCount;
                lastInvoice = invNbr;
                CashAcctKey           key = new CashAcctKey(inv.PayAccountID.Value, inv.PayTypeID);
                PendingPaymentSummary res = null;
                if (!result.ContainsKey(key))
                {
                    res = new PendingPaymentSummary();
                    res.PayAccountID = inv.PayAccountID;
                    res.PayTypeID    = inv.PayTypeID;
                    res.CuryID       = acct.CuryID;
                    result[key]      = res;
                    //Assign new CyrrencyInfo - to do conersion correctly. RateTypeID must be taken from the Cash Account
                    CurrencyInfo new_info = new CurrencyInfo();
                    new_info.CuryID         = res.CuryID;
                    new_info.CuryRateTypeID = acct.CuryRateTypeID;
                    new_info.CuryEffDate    = filter.PayDate;
                    new_info       = this.CurrencyInfo_CuryInfoID.Insert(new_info);
                    res.CuryInfoID = new_info.CuryInfoID;
                }
                else
                {
                    res = result[key];
                }

                APAdjust adj = new APAdjust();
                adj.VendorID    = inv.VendorID;
                adj.AdjdDocType = inv.DocType;
                adj.AdjdRefNbr  = inv.RefNbr;
                adj.AdjgDocType = APDocType.Check;
                adj.AdjgRefNbr  = " <NEW>";
                try
                {
                    PaymentEntry.CalcBalances <APInvoice, APAdjust>(this.CurrencyInfo_CuryInfoID, res.CuryInfoID, filter.PayDate, inv, adj);
                }
                catch (PXRateIsNotDefinedForThisDateException ex)
                {
                    Documents.Cache.RaiseExceptionHandling <PendingPaymentSummary.curyID>(res, res.CuryID, new PXSetPropertyException(ex.Message, PXErrorLevel.RowError));
                }
                Aggregate(res, new PXResult <APAdjust, APInvoice> (adj, inv), filter.PayDate);
            }
            return(result.Values);
        }
        public virtual APInvoice ReleaseRetainageProc(APInvoice doc, RetainageOptions retainageOpts, bool isAutoRelease = false)
        {
            Base.Clear(PXClearOption.PreserveTimeStamp);

            if (retainageOpts.CuryRetainageAmt <= 0 || retainageOpts.CuryRetainageAmt > doc.CuryRetainageUnreleasedAmt)
            {
                throw new PXException(Messages.IncorrectRetainageAmount);
            }

            // Magic. We need to prevent rewriting of CurrencyInfo.IsReadOnly
            // by true in CurrencyInfoView
            //
            Base.CurrentDocument.Cache.AllowUpdate = true;

            PXResult <APInvoice, CurrencyInfo, Terms, Vendor> resultDoc =
                APInvoice_CurrencyInfo_Terms_Vendor
                .SelectSingleBound(Base, null, doc.DocType, doc.RefNbr, doc.VendorID)
                .Cast <PXResult <APInvoice, CurrencyInfo, Terms, Vendor> >()
                .First();

            CurrencyInfo info        = resultDoc;
            APInvoice    origInvoice = resultDoc;
            Vendor       vendor      = resultDoc;

            CurrencyInfo new_info = PXCache <CurrencyInfo> .CreateCopy(info);

            new_info.CuryInfoID = null;
            new_info.IsReadOnly = false;
            new_info            = PXCache <CurrencyInfo> .CreateCopy(Base.currencyinfo.Insert(new_info));

            APInvoice invoice = PXCache <APInvoice> .CreateCopy(origInvoice);

            invoice.CuryInfoID = new_info.CuryInfoID;
            invoice.DocType    = APDocType.Invoice;
            invoice.RefNbr     = null;
            invoice.LineCntr   = null;
            invoice.InvoiceNbr = retainageOpts.InvoiceNbr;

            // Must be set for _RowSelected event handler
            //
            invoice.OpenDoc  = true;
            invoice.Released = false;

            Base.Document.Cache.SetDefaultExt <APInvoice.isMigratedRecord>(invoice);
            invoice.BatchNbr        = null;
            invoice.PrebookBatchNbr = null;
            invoice.Prebooked       = false;
            invoice.ScheduleID      = null;
            invoice.Scheduled       = false;
            invoice.NoteID          = null;

            invoice.DueDate         = null;
            invoice.DiscDate        = null;
            invoice.CuryOrigDiscAmt = 0m;
            invoice.OrigDocType     = origInvoice.DocType;
            invoice.OrigRefNbr      = origInvoice.RefNbr;
            invoice.OrigDocDate     = origInvoice.DocDate;

            invoice.PaySel              = false;
            invoice.CuryLineTotal       = 0m;
            invoice.IsTaxPosted         = false;
            invoice.IsTaxValid          = false;
            invoice.CuryVatTaxableTotal = 0m;
            invoice.CuryVatExemptTotal  = 0m;

            invoice.CuryDocBal     = 0m;
            invoice.CuryOrigDocAmt = retainageOpts.CuryRetainageAmt;
            invoice.Hold           = !isAutoRelease && Base.apsetup.Current.HoldEntry == true || Base.IsApprovalRequired(invoice, Base.Document.Cache);

            invoice.DocDate     = retainageOpts.DocDate;
            invoice.FinPeriodID = retainageOpts.FinPeriodID;

            Base.ClearRetainageSummary(invoice);
            invoice.RetainageApply      = false;
            invoice.IsRetainageDocument = true;

            invoice = Base.Document.Insert(invoice);

            if (new_info != null)
            {
                CurrencyInfo b_info = (CurrencyInfo)PXSelect <CurrencyInfo,
                                                              Where <CurrencyInfo.curyInfoID, Equal <Current <APInvoice.curyInfoID> > > > .Select(Base);

                b_info.CuryID         = new_info.CuryID;
                b_info.CuryEffDate    = new_info.CuryEffDate;
                b_info.CuryRateTypeID = new_info.CuryRateTypeID;
                b_info.CuryRate       = new_info.CuryRate;
                b_info.RecipRate      = new_info.RecipRate;
                b_info.CuryMultDiv    = new_info.CuryMultDiv;
                Base.currencyinfo.Update(b_info);
            }

            decimal retainagePercent = (decimal)(retainageOpts.CuryRetainageAmt / doc.CuryRetainageTotal);

            PXResultset <APTran> details = PXSelectGroupBy <APTran,
                                                            Where <APTran.tranType, Equal <Required <APTran.tranType> >,
                                                                   And <APTran.refNbr, Equal <Required <APTran.refNbr> >,
                                                                        And <APTran.curyRetainageAmt, NotEqual <decimal0> > > >,
                                                            Aggregate <
                                                                GroupBy <APTran.taxCategoryID,
                                                                         Sum <APTran.curyRetainageAmt> > > >
                                           .Select(Base, doc.DocType, doc.RefNbr);

            APTran  tranNew       = null;
            decimal prevCuryTotal = 0m;

            TaxCalc oldTaxCalc = TaxBaseAttribute.GetTaxCalc <APTran.taxCategoryID>(Base.Transactions.Cache, null);

            TaxBaseAttribute.SetTaxCalc <APTran.taxCategoryID>(Base.Transactions.Cache, null, TaxCalc.ManualCalc);

            foreach (APTran detail in details)
            {
                // Create APTran record for chosen retainage amount,
                // clear all required fields to prevent tax calculation,
                // discount calculation and retainage calculation.
                // CuryUnitCost = 0m and CuryLineAmt = 0m here to prevent their
                // FieldDefaulting events, because in our case default value
                // should be equal to zero.
                //
                tranNew = Base.Transactions.Insert(new APTran
                {
                    CuryUnitCost = 0m,
                    CuryLineAmt  = 0m
                });

                tranNew.BranchID      = origInvoice.BranchID;
                tranNew.TaxCategoryID = detail.TaxCategoryID;
                tranNew.AccountID     = origInvoice.RetainageAcctID;
                tranNew.SubID         = origInvoice.RetainageSubID;
                tranNew.ProjectID     = ProjectDefaultAttribute.NonProject();

                tranNew.Qty                  = 0m;
                tranNew.CuryUnitCost         = 0m;
                tranNew.ManualDisc           = true;
                tranNew.DiscPct              = 0m;
                tranNew.CuryDiscAmt          = 0m;
                tranNew.RetainagePct         = 0m;
                tranNew.CuryRetainageAmt     = 0m;
                tranNew.CuryTaxableAmt       = 0m;
                tranNew.CuryTaxAmt           = 0;
                tranNew.CuryExpenseAmt       = 0m;
                tranNew.GroupDiscountRate    = 1m;
                tranNew.DocumentDiscountRate = 1m;

                using (new PXLocaleScope(vendor.LocaleName))
                {
                    tranNew.TranDesc = PXMessages.LocalizeFormatNoPrefix(
                        Messages.RetainageForTransactionDescription,
                        APDocTypeDict[origInvoice.DocType],
                        origInvoice.RefNbr);
                }

                prevCuryTotal       = (retainageOpts.CuryRetainageAmt ?? 0m) - (invoice.CuryDocBal ?? 0m);
                tranNew.CuryLineAmt = PXCurrencyAttribute.RoundCury(Base.Transactions.Cache, tranNew, (detail.CuryRetainageAmt ?? 0m) * retainagePercent);
                tranNew             = Base.Transactions.Update(tranNew);
            }

            ClearCurrentDocumentDiscountDetails();

            // We should copy all taxes from the original document
            // because it is possible to add or delete them.
            //
            foreach (APTaxTran aptaxtran in PXSelect <APTaxTran,
                                                      Where <APTaxTran.module, Equal <BatchModule.moduleAP>,
                                                             And <APTaxTran.tranType, Equal <Required <APTaxTran.tranType> >,
                                                                  And <APTaxTran.refNbr, Equal <Required <APTaxTran.refNbr> > > > > >
                     .Select(Base, origInvoice.DocType, origInvoice.RefNbr)
                     .RowCast <APTaxTran>()
                     .Where(row => row.CuryRetainedTaxAmt != 0m))
            {
                APTaxTran new_aptaxtran = Base.Taxes.Insert(new APTaxTran
                {
                    TaxID = aptaxtran.TaxID
                });

                if (new_aptaxtran != null)
                {
                    new_aptaxtran = PXCache <APTaxTran> .CreateCopy(new_aptaxtran);

                    new_aptaxtran.TaxRate = aptaxtran.TaxRate;
                    new_aptaxtran         = Base.Taxes.Update(new_aptaxtran);
                }
            }

            TaxBaseAttribute.SetTaxCalc <APTran.taxCategoryID>(Base.Transactions.Cache, null, oldTaxCalc);
            decimal diff = (retainageOpts.CuryRetainageAmt ?? 0m) - (invoice.CuryDocBal ?? 0m);

            if (tranNew != null && diff != 0m)
            {
                HashSet <string> taxList = PXSelectJoin <APTax,
                                                         InnerJoin <Tax, On <Tax.taxID, Equal <APTax.taxID> > >,
                                                         Where <APTax.tranType, Equal <Required <APTax.tranType> >,
                                                                And <APTax.refNbr, Equal <Required <APTax.refNbr> >,
                                                                     And <APTax.lineNbr, Equal <Required <APTax.lineNbr> >,
                                                                          And <Tax.taxType, NotEqual <CSTaxType.use> > > > > >
                                           .Select(Base, tranNew.TranType, tranNew.RefNbr, tranNew.LineNbr)
                                           .RowCast <APTax>()
                                           .Select(row => row.TaxID)
                                           .ToHashSet();

                // To guarantee correct document total amount
                // we should calculate last line total,
                // including its taxes.
                //
                TaxAttribute.CalcTaxable calcClass = new TaxAttribute.CalcTaxable(false, TaxAttribute.TaxCalcLevelEnforcing.None);
                decimal curyLineAmt = calcClass.CalcTaxableFromTotalAmount(
                    Base.Transactions.Cache,
                    tranNew,
                    taxList,
                    invoice.DocDate.Value,
                    prevCuryTotal);

                tranNew.CuryLineAmt = curyLineAmt;
                tranNew             = Base.Transactions.Update(tranNew);
            }

            APVendorRefNbrAttribute aPVendorRefNbrAttribute = Base.Document.Cache.GetAttributesReadonly <APInvoice.invoiceNbr>()
                                                              .OfType <APVendorRefNbrAttribute>().FirstOrDefault();

            if (aPVendorRefNbrAttribute != null)
            {
                var args = new PXFieldVerifyingEventArgs(invoice, invoice.InvoiceNbr, true);
                aPVendorRefNbrAttribute.FieldVerifying(Base.Document.Cache, args);
            }

            return(invoice);
        }
 public virtual bool IsAttached(APInvoice aRow, out GLVoucherBatch aVoucherBatch, out GLVoucher aVoucher)
 {
     return(IsAttached(Base, aRow.NoteID, out aVoucherBatch, out aVoucher));
 }