Exemple #1
0
        public virtual List <ErrorInfo> GetErrorInfo()
        {
            List <ErrorInfo> errorList = new List <ErrorInfo>();
            ErrorInfo        errorInfo;

            foreach (APTran apTranRow in Base.Transactions.Select())
            {
                string errorMessage = SharedFunctions.CheckCacheState(Base.Transactions.Cache, apTranRow, true, true, true);

                if (string.IsNullOrEmpty(errorMessage) == false)
                {
                    FSxAPTran fsxAPTRanRow = Base.Transactions.Cache.GetExtension <FSxAPTran>(apTranRow);

                    errorInfo = new ErrorInfo()
                    {
                        SOID          = fsxAPTRanRow.SOID,
                        AppointmentID = fsxAPTRanRow.AppointmentID,
                        ErrorMessage  = errorMessage + Environment.NewLine
                    };

                    errorList.Add(errorInfo);
                }
            }

            return(errorList);
        }
Exemple #2
0
        public virtual void CreateInvoice(PXGraph graphProcess, List <DocLineExt> docLines, List <DocLineExt> docLinesGrouped, short invtMult, DateTime?invoiceDate, string invoiceFinPeriodID, OnDocumentHeaderInsertedDelegate onDocumentHeaderInserted, OnTransactionInsertedDelegate onTransactionInserted, PXQuickProcess.ActionFlow quickProcessFlow)
        {
            if (docLinesGrouped.Count == 0)
            {
                return;
            }

            bool?initialHold = false;

            FSServiceOrder fsServiceOrderRow = docLinesGrouped[0].fsServiceOrder;
            FSSrvOrdType   fsSrvOrdTypeRow   = docLinesGrouped[0].fsSrvOrdType;
            FSPostDoc      fsPostDocRow      = docLinesGrouped[0].fsPostDoc;
            FSAppointment  fsAppointmentRow  = docLinesGrouped[0].fsAppointment;

            Vendor vendorRow = SharedFunctions.GetVendorRow(graphProcess, fsServiceOrderRow.BillCustomerID);

            if (vendorRow == null)
            {
                throw new PXException(TX.Error.AP_POSTING_VENDOR_NOT_FOUND);
            }

            Base.FieldDefaulting.AddHandler <APInvoice.branchID>((sender, e) =>
            {
                e.NewValue = fsServiceOrderRow.BranchID;
                e.Cancel   = true;
            });

            APInvoice apInvoiceRow = new APInvoice();

            if (invtMult >= 0)
            {
                apInvoiceRow.DocType = APDocType.DebitAdj;
                AutoNumberHelper.CheckAutoNumbering(Base, Base.APSetup.SelectSingle().DebitAdjNumberingID);
            }
            else
            {
                apInvoiceRow.DocType = APDocType.Invoice;
                AutoNumberHelper.CheckAutoNumbering(Base, Base.APSetup.SelectSingle().InvoiceNumberingID);
            }

            apInvoiceRow.DocDate     = invoiceDate;
            apInvoiceRow.FinPeriodID = invoiceFinPeriodID;
            apInvoiceRow             = PXCache <APInvoice> .CreateCopy(Base.Document.Insert(apInvoiceRow));

            initialHold         = apInvoiceRow.Hold;
            apInvoiceRow.NoteID = null;
            PXNoteAttribute.GetNoteIDNow(Base.Document.Cache, apInvoiceRow);
            apInvoiceRow.VendorID         = fsServiceOrderRow.BillCustomerID;
            apInvoiceRow.VendorLocationID = fsServiceOrderRow.BillLocationID;
            apInvoiceRow.CuryID           = fsServiceOrderRow.CuryID;
            apInvoiceRow.TaxZoneID        = fsAppointmentRow != null ? fsAppointmentRow.TaxZoneID : fsServiceOrderRow.TaxZoneID;
            apInvoiceRow.TaxCalcMode      = fsAppointmentRow != null ? fsAppointmentRow.TaxCalcMode : fsServiceOrderRow.TaxCalcMode;

            apInvoiceRow.SuppliedByVendorLocationID = fsServiceOrderRow.BillLocationID;

            string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, null, fsServiceOrderRow.BillCustomerID);

            if (termsID == null)
            {
                termsID = fsSrvOrdTypeRow.DfltTermIDAP;
            }

            apInvoiceRow.FinPeriodID = invoiceFinPeriodID;
            apInvoiceRow.TermsID     = termsID;
            apInvoiceRow.DocDesc     = fsServiceOrderRow.DocDesc;
            apInvoiceRow.Hold        = true;
            apInvoiceRow             = Base.Document.Update(apInvoiceRow);
            apInvoiceRow.TaxCalcMode = PX.Objects.TX.TaxCalculationMode.TaxSetting;
            apInvoiceRow             = Base.Document.Update(apInvoiceRow);

            InvoicingFunctions.SetContactAndAddress(Base, fsServiceOrderRow);

            if (onDocumentHeaderInserted != null)
            {
                onDocumentHeaderInserted(Base, apInvoiceRow);
            }

            IDocLine  docLine      = null;
            APTran    apTranRow    = null;
            FSxAPTran fsxAPTranRow = null;
            PMTask    pmTaskRow    = null;

            foreach (DocLineExt docLineExt in docLinesGrouped)
            {
                docLine           = docLineExt.docLine;
                fsPostDocRow      = docLineExt.fsPostDoc;
                fsServiceOrderRow = docLineExt.fsServiceOrder;
                fsSrvOrdTypeRow   = docLineExt.fsSrvOrdType;
                fsAppointmentRow  = docLineExt.fsAppointment;

                apTranRow = new APTran();
                apTranRow = Base.Transactions.Insert(apTranRow);

                Base.Transactions.Cache.SetValueExtIfDifferent <APTran.branchID>(apTranRow, docLine.BranchID);
                Base.Transactions.Cache.SetValueExtIfDifferent <APTran.inventoryID>(apTranRow, docLine.InventoryID);
                Base.Transactions.Cache.SetValueExtIfDifferent <APTran.uOM>(apTranRow, docLine.UOM);

                pmTaskRow = docLineExt.pmTask;

                if (pmTaskRow != null && pmTaskRow.Status == ProjectTaskStatus.Completed)
                {
                    throw new PXException(TX.Error.POSTING_PMTASK_ALREADY_COMPLETED, fsServiceOrderRow.RefNbr, docLine.LineRef, pmTaskRow.TaskCD);
                }

                if (docLine.AcctID != null)
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <APTran.accountID>(apTranRow, docLine.AcctID);
                }

                if (docLine.SubID != null)
                {
                    try
                    {
                        Base.Transactions.Cache.SetValueExtIfDifferent <APTran.subID>(apTranRow, docLine.SubID);
                    }
                    catch (PXException)
                    {
                        apTranRow.SubID = null;
                    }
                }
                else
                {
                    InvoicingFunctions.SetCombinedSubID(graphProcess,
                                                        Base.Transactions.Cache,
                                                        null,
                                                        apTranRow,
                                                        null,
                                                        fsSrvOrdTypeRow,
                                                        apTranRow.BranchID,
                                                        apTranRow.InventoryID,
                                                        apInvoiceRow.VendorLocationID,
                                                        fsServiceOrderRow.BranchLocationID,
                                                        fsServiceOrderRow.SalesPersonID,
                                                        docLine.IsService);
                }

                if (docLine.ProjectID != null && docLine.ProjectTaskID != null)
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <APTran.taskID>(apTranRow, docLine.ProjectTaskID);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <APTran.qty>(apTranRow, docLine.GetQty(FieldType.BillableField));
                Base.Transactions.Cache.SetValueExtIfDifferent <APTran.tranDesc>(apTranRow, docLine.TranDesc);

                apTranRow = Base.Transactions.Update(apTranRow);
                Base.Transactions.Cache.SetValueExtIfDifferent <APTran.curyUnitCost>(apTranRow, docLine.CuryUnitPrice * invtMult);

                if (docLine.ProjectID != null)
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <APTran.projectID>(apTranRow, docLine.ProjectID);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <APTran.taxCategoryID>(apTranRow, docLine.TaxCategoryID);
                Base.Transactions.Cache.SetValueExtIfDifferent <APTran.costCodeID>(apTranRow, docLine.CostCodeID);

                if (docLine.IsBillable == false)
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <APTran.manualDisc>(apTranRow, true);
                    Base.Transactions.Cache.SetValueExtIfDifferent <APTran.curyDiscAmt>(apTranRow, docLine.GetQty(FieldType.BillableField) * docLine.CuryUnitPrice * invtMult);
                }
                else
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <APTran.discPct>(apTranRow, docLine.DiscPct);
                }

                fsxAPTranRow = Base.Transactions.Cache.GetExtension <FSxAPTran>(apTranRow);

                fsxAPTranRow.Source           = docLine.BillingBy;
                fsxAPTranRow.SOID             = fsServiceOrderRow.SOID;
                fsxAPTranRow.ServiceOrderDate = fsServiceOrderRow.OrderDate;

                fsxAPTranRow.BillCustomerID     = fsServiceOrderRow.CustomerID;
                fsxAPTranRow.CustomerLocationID = fsServiceOrderRow.LocationID;

                fsxAPTranRow.SODetID         = docLine.PostSODetID;
                fsxAPTranRow.AppointmentID   = docLine.PostAppointmentID;
                fsxAPTranRow.AppointmentDate = fsAppointmentRow?.ExecutionDate;
                fsxAPTranRow.AppDetID        = docLine.PostAppDetID;

                if (docLine.BillingBy == ID.Billing_By.APPOINTMENT)
                {
                    //// TODO AC-142850
                    ////fsxAPTranRow.AppointmentDate = new DateTime(
                    ////                                fsAppointmentRow.ActualDateTimeBegin.Value.Year,
                    ////                                fsAppointmentRow.ActualDateTimeBegin.Value.Month,
                    ////                                fsAppointmentRow.ActualDateTimeBegin.Value.Day,
                    ////                                0,
                    ////                                0,
                    ////                                0);
                }

                fsxAPTranRow.Mem_PreviousPostID = docLine.PostID;
                fsxAPTranRow.Mem_TableSource    = docLine.SourceTable;

                SharedFunctions.CopyNotesAndFiles(Base.Transactions.Cache, apTranRow, docLine, fsSrvOrdTypeRow);
                fsPostDocRow.DocLineRef = apTranRow = Base.Transactions.Update(apTranRow);

                if (onTransactionInserted != null)
                {
                    onTransactionInserted(Base, apTranRow);
                }
            }

            apInvoiceRow = Base.Document.Update(apInvoiceRow);

            if (Base.APSetup.Current.RequireControlTotal == true)
            {
                Base.Document.Cache.SetValueExtIfDifferent <APInvoice.curyOrigDocAmt>(apInvoiceRow, apInvoiceRow.CuryDocBal);
            }

            if (initialHold != true)
            {
                Base.Document.Cache.SetValueExtIfDifferent <APInvoice.hold>(apInvoiceRow, false);
            }

            apInvoiceRow = Base.Document.Update(apInvoiceRow);
        }
        protected int?GetSOIDRelated(APTran line)
        {
            FSxAPTran row = PXCache <APTran> .GetExtension <FSxAPTran>(line);

            return(row?.SOID);
        }