/// <summary>
        /// Check the ManageRooms value on Setup to check/hide the Rooms Values options.
        /// </summary>
        private void HideRooms()
        {
            bool isRoomManagementActive = ServiceManagementSetup.IsRoomManagementActive(this, SetupRecord?.Current);

            FSServiceOrder fsServiceOrderRow = ServiceOrderRelated.SelectSingle();

            PXUIFieldAttribute.SetVisible <FSServiceOrder.roomID>(this.ServiceOrderRelated.Cache, fsServiceOrderRow, isRoomManagementActive);
        }
コード例 #2
0
        /// <summary>
        /// Sets the Customer Billing Cycle from its Customer Class.
        /// </summary>
        public virtual void SetBillingCycleFromCustomerClass(PXCache cache, Customer customerRow)
        {
            if (customerRow.CustomerClassID == null)
            {
                return;
            }

            FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(Base);

            if (fsSetupRow != null &&
                fsSetupRow.CustomerMultipleBillingOptions == true)
            {
                foreach (FSCustomerBillingSetup fsCustomerBillingSetupRow in this.CustomerBillingCycles.Select())
                {
                    this.CustomerBillingCycles.Delete(fsCustomerBillingSetupRow);
                }

                var customerClsBillingSetupRows = PXSelect <FSCustomerClassBillingSetup,
                                                            Where <
                                                                FSCustomerClassBillingSetup.customerClassID, Equal <Required <FSCustomerClassBillingSetup.customerClassID> > > >
                                                  .Select(Base, customerRow.CustomerClassID);

                foreach (FSCustomerClassBillingSetup fsCustomerClassBillingSetupRow in customerClsBillingSetupRows)
                {
                    FSCustomerBillingSetup fsCustomerBillingSetupRow = new FSCustomerBillingSetup();
                    fsCustomerBillingSetupRow.SrvOrdType         = fsCustomerClassBillingSetupRow.SrvOrdType;
                    fsCustomerBillingSetupRow.BillingCycleID     = fsCustomerClassBillingSetupRow.BillingCycleID;
                    fsCustomerBillingSetupRow.SendInvoicesTo     = fsCustomerClassBillingSetupRow.SendInvoicesTo;
                    fsCustomerBillingSetupRow.BillShipmentSource = fsCustomerClassBillingSetupRow.BillShipmentSource;
                    fsCustomerBillingSetupRow.FrequencyType      = fsCustomerClassBillingSetupRow.FrequencyType;

                    this.CustomerBillingCycles.Insert(fsCustomerBillingSetupRow);
                }

                return;
            }

            SetSingleBillingSettings(cache, customerRow);
        }
コード例 #3
0
        public virtual FSContractPostDoc CreateInvoiceByContract(PXGraph graphProcess, DateTime?invoiceDate, string invoiceFinPeriodID, FSContractPostBatch fsContractPostBatchRow, FSServiceContract fsServiceContractRow, FSContractPeriod fsContractPeriodRow, List <ContractInvoiceLine> docLines)
        {
            if (docLines.Count == 0)
            {
                return(null);
            }

            FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(graphProcess);

            ARInvoice arInvoiceRow = new ARInvoice();

            arInvoiceRow.DocType = ARInvoiceType.Invoice;

            arInvoiceRow.DocDate     = invoiceDate;
            arInvoiceRow.FinPeriodID = invoiceFinPeriodID;
            arInvoiceRow.Hold        = true;
            arInvoiceRow             = Base.Document.Insert(arInvoiceRow);

            Base.Document.Cache.SetValueExt <ARInvoice.customerID>(arInvoiceRow, fsServiceContractRow.BillCustomerID);
            Base.Document.Cache.SetValueExt <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceContractRow.BillLocationID);
            Base.Document.Cache.SetValueExt <ARInvoice.branchID>(arInvoiceRow, fsServiceContractRow.BranchID);
            Base.Document.Cache.SetValueExt <ARInvoice.docDesc>(arInvoiceRow, "Contract Standardized Billing: " + fsServiceContractRow.RefNbr + " " + fsServiceContractRow.DocDesc);

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

            if (termsID != null)
            {
                Base.Document.Cache.SetValueExt <ARInvoice.termsID>(arInvoiceRow, termsID);
            }
            else
            {
                Base.Document.Cache.SetValueExt <ARInvoice.termsID>(arInvoiceRow, fsSetupRow.DfltContractTermIDARSO);
            }

            ARTran    arTranRow    = null;
            FSxARTran fsxARTranRow = null;
            int?      acctID;

            foreach (ContractInvoiceLine docLine in docLines)
            {
                arTranRow = new ARTran();
                arTranRow = Base.Transactions.Insert(arTranRow);

                Base.Transactions.Cache.SetValueExt <ARTran.inventoryID>(arTranRow, docLine.InventoryID);
                Base.Transactions.Cache.SetValueExt <ARTran.uOM>(arTranRow, docLine.UOM);
                Base.Transactions.Cache.SetValueExt <ARTran.salesPersonID>(arTranRow, docLine.SalesPersonID);

                arTranRow = Base.Transactions.Update(arTranRow);

                if (docLine.AcctID != null)
                {
                    acctID = docLine.AcctID;
                }
                else
                {
                    acctID = (int?)ServiceOrderCore.Get_INItemAcctID_DefaultValue(
                        graphProcess,
                        fsSetupRow.ContractSalesAcctSource,
                        docLine.InventoryID,
                        fsServiceContractRow);
                }

                Base.Transactions.Cache.SetValueExt <ARTran.accountID>(arTranRow, acctID);

                if (docLine.SubID != null)
                {
                    try
                    {
                        Base.Transactions.Cache.SetValueExt <ARTran.subID>(arTranRow, docLine.SubID);
                    }
                    catch (PXException)
                    {
                        arTranRow.SubID = null;
                    }
                }
                else
                {
                    InvoicingFunctions.SetCombinedSubID(
                        graphProcess,
                        Base.Transactions.Cache,
                        arTranRow,
                        null,
                        null,
                        fsSetupRow,
                        arTranRow.BranchID,
                        arTranRow.InventoryID,
                        arInvoiceRow.CustomerLocationID,
                        fsServiceContractRow.BranchLocationID);
                }

                Base.Transactions.Cache.SetValueExt <ARTran.qty>(arTranRow, docLine.Qty);

                Base.Transactions.Cache.SetValueExt <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice);

                Base.Transactions.Cache.SetValueExt <ARTran.tranDesc>(arTranRow, docLine.TranDescPrefix + arTranRow.TranDesc);

                arTranRow = Base.Transactions.Update(arTranRow);

                Base.Transactions.Cache.SetValueExt <ARTran.commissionable>(arTranRow, docLine.Commissionable ?? false);

                fsxARTranRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow);

                fsxARTranRow.Source             = ID.Billing_By.CONTRACT;
                fsxARTranRow.ServiceContractID  = fsServiceContractRow.ServiceContractID;
                fsxARTranRow.ContractPeriodID   = fsContractPeriodRow.ContractPeriodID;
                fsxARTranRow.BillCustomerID     = fsServiceContractRow.BillCustomerID;
                fsxARTranRow.CustomerLocationID = fsServiceContractRow.BillLocationID;

                arTranRow = Base.Transactions.Update(arTranRow);
            }

            if (Base.ARSetup.Current.RequireControlTotal == true)
            {
                Base.Document.Cache.SetValueExt <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal);
            }

            Base.Document.Cache.SetValueExt <ARInvoice.hold>(arInvoiceRow, false);

            Exception newException = null;

            try
            {
                Base.Save.Press();
            }
            catch (Exception e)
            {
                List <ErrorInfo> errorList = this.GetErrorInfo();

                var exceptionWithContextMessage = ExceptionHelper.GetExceptionWithContextMessage(
                    PXMessages.Localize(TX.Messages.ERROR_CREATING_INVOICE_IN_POSTING_BATCH),
                    e);

                newException = InvoicingFunctions.GetErrorInfoInLines(errorList, exceptionWithContextMessage);
            }

            if (newException != null)
            {
                throw newException;
            }

            arInvoiceRow = Base.Document.Current;

            FSContractPostDoc fsContractCreatedDocRow = new FSContractPostDoc()
            {
                ContractPeriodID    = fsContractPeriodRow.ContractPeriodID,
                ContractPostBatchID = fsContractPostBatchRow.ContractPostBatchID,
                PostDocType         = arInvoiceRow.DocType,
                PostedTO            = ID.Batch_PostTo.AR,
                PostRefNbr          = arInvoiceRow.RefNbr,
                ServiceContractID   = fsServiceContractRow.ServiceContractID
            };

            return(fsContractCreatedDocRow);
        }
        private void EnableDisableFields(PXCache cache, FSSrvOrdType fsSrvOrdTypeRow)
        {
            bool enabledPostToOption = SrvOrdAppointmentsPosted.Current != null && SrvOrdAppointmentsPosted.Current.AppointmentID != null;
            bool postToIsNone        = fsSrvOrdTypeRow.PostTo != ID.SrvOrdType_PostTo.NONE;

            fsSrvOrdTypeRow.BAccountRequired = fsSrvOrdTypeRow.Behavior != ID.Behavior_SrvOrderType.INTERNAL_APPOINTMENT;
            fsSrvOrdTypeRow.RequireRoute     = fsSrvOrdTypeRow.Behavior == ID.Behavior_SrvOrderType.ROUTE_APPOINTMENT;

            if (fsSrvOrdTypeRow.BAccountRequired == false)
            {
                fsSrvOrdTypeRow.RequireContact = false;
            }

            bool isRoomManagementActive = ServiceManagementSetup.IsRoomManagementActive(cache.Graph, SetupRecord?.Current);

            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.requireRoom>(cache, fsSrvOrdTypeRow, isRoomManagementActive);
            PXUIFieldAttribute.SetVisible <FSSrvOrdType.requireRoom>(cache, fsSrvOrdTypeRow, isRoomManagementActive);

            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.salesAcctSource>(cache, fsSrvOrdTypeRow, postToIsNone);
            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.combineSubFrom>(cache, fsSrvOrdTypeRow, postToIsNone);
            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.dfltTermIDARSO>(cache, fsSrvOrdTypeRow, postToIsNone);
            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.postOrderType>(cache, fsSrvOrdTypeRow, postToIsNone);
            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.dfltTermIDAP>(cache, fsSrvOrdTypeRow, postToIsNone && fsSrvOrdTypeRow.PostNegBalanceToAP == true);
            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.postOrderTypeNegativeBalance>(cache, fsSrvOrdTypeRow, postToIsNone);
            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.subID>(cache, fsSrvOrdTypeRow, postToIsNone);
            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.allowInvoiceOnlyClosedAppointment>(cache, fsSrvOrdTypeRow, postToIsNone);

            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.postNegBalanceToAP>(cache, fsSrvOrdTypeRow, fsSrvOrdTypeRow.PostTo == ID.SrvOrdType_PostTo.ACCOUNTS_RECEIVABLE_MODULE);
            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.enableINPosting>(
                cache,
                fsSrvOrdTypeRow,
                postToIsNone &&
                PXAccess.FeatureInstalled <FeaturesSet.distributionModule>() &&
                fsSrvOrdTypeRow.Behavior == ID.Behavior_SrvOrderType.ROUTE_APPOINTMENT);
            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.requireContact>(cache, fsSrvOrdTypeRow, fsSrvOrdTypeRow.BAccountRequired == true);
            PXUIFieldAttribute.SetEnabled <FSSrvOrdType.postTo>(cache, fsSrvOrdTypeRow, !enabledPostToOption);

            EnableDisableEmployeeTimeCardIntegrationFields(cache, fsSrvOrdTypeRow);

            switch (fsSrvOrdTypeRow.Behavior)
            {
            case ID.Behavior_SrvOrderType.INTERNAL_APPOINTMENT:
                fsSrvOrdTypeRow.AppAddressSource = ID.Source_Info.BRANCH_LOCATION;
                PXUIFieldAttribute.SetEnabled <FSSrvOrdType.appAddressSource>(cache, fsSrvOrdTypeRow, false);
                PXUIFieldAttribute.SetEnabled <FSSrvOrdType.requireCustomerSignature>(cache, fsSrvOrdTypeRow, true);
                SetPostingSettingVisibility(cache, fsSrvOrdTypeRow, false);
                break;

            case ID.Behavior_SrvOrderType.ROUTE_APPOINTMENT:
                PXUIFieldAttribute.SetEnabled <FSSrvOrdType.appAddressSource>(cache, fsSrvOrdTypeRow, true);
                PXUIFieldAttribute.SetEnabled <FSSrvOrdType.requireCustomerSignature>(cache, fsSrvOrdTypeRow, true);
                SetPostingSettingVisibility(cache, fsSrvOrdTypeRow, true);
                break;

            case ID.Behavior_SrvOrderType.QUOTE:
            default:

                if (fsSrvOrdTypeRow.Behavior == ID.Behavior_SrvOrderType.REGULAR_APPOINTMENT)
                {
                    PXUIFieldAttribute.SetEnabled <FSSrvOrdType.requireCustomerSignature>(cache, fsSrvOrdTypeRow, true);
                }
                else
                {
                    PXUIFieldAttribute.SetEnabled <FSSrvOrdType.requireCustomerSignature>(cache, fsSrvOrdTypeRow, false);
                }

                PXUIFieldAttribute.SetEnabled <FSSrvOrdType.appAddressSource>(cache, fsSrvOrdTypeRow, true);

                if (fsSrvOrdTypeRow.RequireContact == false &&
                    fsSrvOrdTypeRow.AppAddressSource == ID.Source_Info.CUSTOMER_CONTACT)
                {
                    fsSrvOrdTypeRow.AppAddressSource = ID.Source_Info.BUSINESS_ACCOUNT;
                }

                SetPostingSettingVisibility(cache, fsSrvOrdTypeRow, fsSrvOrdTypeRow.Behavior != ID.Behavior_SrvOrderType.QUOTE);
                break;
            }
        }
コード例 #5
0
        /// <summary>
        /// Checks if the Employee Time Cards Integration is enabled in the Service Management Setup.
        /// </summary>
        public static bool IsTheTimeCardIntegrationEnabled(PXGraph graph)
        {
            FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(graph);

            return(fsSetupRow != null && fsSetupRow.EnableEmpTimeCardIntegration == true);
        }
コード例 #6
0
        public CreateInvoiceByContractPost()
        {
            CreateInvoiceByContractPost graphCreateInvoiceByServiceOrderPost = null;

            Contracts.SetProcessDelegate(
                delegate(List <ContractPeriodToPost> contractPeriodToPostRows)
            {
                graphCreateInvoiceByServiceOrderPost = PXGraph.CreateInstance <CreateInvoiceByContractPost>();

                int rowIndex = 0;
                InvoiceContractPeriodFilter filter = Filter.Current;
                FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(graphCreateInvoiceByServiceOrderPost);

                ContractPostBatchEntry contractPostBatchGraph   = PXGraph.CreateInstance <ContractPostBatchEntry>();
                ContractPostPeriodEntry contractPostPeriodGraph = PXGraph.CreateInstance <ContractPostPeriodEntry>();

                FSContractPostDoc fsContractPostDocRow     = null;
                FSContractPostBatch fsContractPostBatchRow = null;

                List <ContractInvoiceLine> invoiceDet              = new List <ContractInvoiceLine>();
                List <ContractInvoiceLine> contractPeriodLines     = null;
                List <ContractInvoiceLine> contractInvoiceDetList  = null;
                List <ContractInvoiceLine> equipmentInvoiceDetList = null;

                FSServiceContract fsServiceContractRow = null;
                FSContractPeriod fsContractPeriodRow   = null;

                IInvoiceContractGraph invoiceGraph = GetInvoiceGraph(fsSetupRow);

                foreach (ContractPeriodToPost contractPeriodToPostRow in contractPeriodToPostRows)
                {
                    fsContractPostDocRow = null;
                    GetContractAndPeriod(contractPeriodToPostRow.ServiceContractID, contractPeriodToPostRow.ContractPeriodID, out fsServiceContractRow, out fsContractPeriodRow);
                    contractPeriodLines = GetContractPeriodLines(contractPeriodToPostRow);

                    if (contractPeriodLines.Count > 0 && fsServiceContractRow != null && fsContractPeriodRow != null)
                    {
                        contractInvoiceDetList = GetContractInvoiceLines(contractPeriodToPostRow);
                        invoiceDet.AddRange(contractInvoiceDetList);

                        if (fsSetupRow.ContractPostTo == ID.Contract_PostTo.SALES_ORDER_MODULE)
                        {
                            equipmentInvoiceDetList = GetEquipmentInvoiceLines(contractPeriodToPostRow);
                        }

                        List <ContractInvoiceLine> contractInvoiceLines = GetInvoiceLines(invoiceDet, contractPeriodLines, contractInvoiceDetList, fsSetupRow.ContractPostTo);

                        if (equipmentInvoiceDetList != null && equipmentInvoiceDetList.Count > 0)
                        {
                            contractInvoiceLines.AddRange(equipmentInvoiceDetList);
                            invoiceDet.AddRange(equipmentInvoiceDetList);
                        }

                        try
                        {
                            using (var ts = new PXTransactionScope())
                            {
                                if (fsContractPostBatchRow == null)
                                {
                                    fsContractPostBatchRow = contractPostBatchGraph.CreatePostingBatch(filter.UpToDate, filter.InvoiceDate, filter.InvoiceFinPeriodID, SetupRecord.Current.ContractPostTo);
                                }

                                fsContractPostDocRow = invoiceGraph.CreateInvoiceByContract(graphCreateInvoiceByServiceOrderPost, filter.InvoiceDate, filter.InvoiceFinPeriodID, fsContractPostBatchRow, fsServiceContractRow, fsContractPeriodRow, contractInvoiceLines);

                                fsContractPostDocRow = CreateContractPostDoc(contractPostPeriodGraph, fsContractPostDocRow);

                                CreateContractPostDet(contractPostPeriodGraph, fsContractPostDocRow, invoiceDet);

                                UpdateSourcePostDoc(fsSetupRow, fsContractPostDocRow, fsServiceContractRow);

                                CreateContractPostRegister(this, fsContractPostDocRow);

                                contractPeriodToPostRow.ContractPostBatchID = fsContractPostBatchRow.ContractPostBatchID;

                                ts.Complete();
                            }

                            PXProcessing <ContractPeriodToPost> .SetInfo(rowIndex, TX.Messages.RECORD_PROCESSED_SUCCESSFULLY);
                        }
                        catch (Exception e)
                        {
                            PXProcessing <ContractPeriodToPost> .SetError(rowIndex, e.Message);
                        }
                    }
                    else
                    {
                        PXProcessing <ContractPeriodToPost> .SetError(rowIndex, TX.Error.PERIOD_WITHOUT_DETAILS);
                    }

                    rowIndex++;
                }
            });
        }
コード例 #7
0
        public virtual FSContractPostDoc CreateInvoiceByContract(PXGraph graphProcess, DateTime?invoiceDate, string invoiceFinPeriodID, FSContractPostBatch fsContractPostBatchRow, FSServiceContract fsServiceContractRow, FSContractPeriod fsContractPeriodRow, List <ContractInvoiceLine> docLines)
        {
            if (docLines.Count == 0)
            {
                return(null);
            }

            FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(graphProcess);

            ARInvoice arInvoiceRow = new ARInvoice();

            arInvoiceRow.DocType = ARInvoiceType.Invoice;
            AutoNumberHelper.CheckAutoNumbering(Base, Base.ARSetup.SelectSingle().InvoiceNumberingID);

            arInvoiceRow.DocDate     = invoiceDate;
            arInvoiceRow.FinPeriodID = invoiceFinPeriodID;
            arInvoiceRow.Hold        = true;
            arInvoiceRow             = Base.Document.Insert(arInvoiceRow);

            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerID>(arInvoiceRow, fsServiceContractRow.BillCustomerID);
            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceContractRow.BillLocationID);
            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.branchID>(arInvoiceRow, fsServiceContractRow.BranchID);
            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.docDesc>(arInvoiceRow, (PXMessages.LocalizeFormatNoPrefix(TX.Messages.CONTRACT_WITH_STANDARDIZED_BILLING, fsServiceContractRow.RefNbr, (string.IsNullOrEmpty(fsServiceContractRow.DocDesc) ? string.Empty : fsServiceContractRow.DocDesc))));

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

            if (termsID != null)
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, termsID);
            }
            else
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, fsSetupRow.DfltContractTermIDARSO);
            }

            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.projectID>(arInvoiceRow, fsServiceContractRow.ProjectID);

            ARTran    arTranRow    = null;
            FSxARTran fsxARTranRow = null;
            int?      acctID;

            foreach (ContractInvoiceLine docLine in docLines)
            {
                arTranRow = new ARTran();
                arTranRow = Base.Transactions.Insert(arTranRow);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.inventoryID>(arTranRow, docLine.InventoryID);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.uOM>(arTranRow, docLine.UOM);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.salesPersonID>(arTranRow, docLine.SalesPersonID);

                arTranRow = Base.Transactions.Update(arTranRow);

                if (docLine.AcctID != null)
                {
                    acctID = docLine.AcctID;
                }
                else
                {
                    acctID = (int?)ServiceOrderCore.Get_INItemAcctID_DefaultValue(graphProcess,
                                                                                  fsSetupRow.ContractSalesAcctSource,
                                                                                  docLine.InventoryID,
                                                                                  fsServiceContractRow);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.accountID>(arTranRow, acctID);

                if (docLine.SubID != null)
                {
                    try
                    {
                        Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.subID>(arTranRow, docLine.SubID);
                    }
                    catch (PXException)
                    {
                        arTranRow.SubID = null;
                    }
                }
                else
                {
                    InvoicingFunctions.SetCombinedSubID(graphProcess,
                                                        Base.Transactions.Cache,
                                                        arTranRow,
                                                        null,
                                                        null,
                                                        fsSetupRow,
                                                        arTranRow.BranchID,
                                                        arTranRow.InventoryID,
                                                        arInvoiceRow.CustomerLocationID,
                                                        fsServiceContractRow.BranchLocationID);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.qty>(arTranRow, docLine.Qty);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice);

                if (docLine.ServiceContractID != null &&
                    docLine.ContractRelated == false &&
                    (docLine.SODetID != null || docLine.AppDetID != null))
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyExtPrice>(arTranRow, docLine.CuryBillableExtPrice);
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.discPct>(arTranRow, docLine.DiscPct);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.tranDesc>(arTranRow, docLine.TranDescPrefix + arTranRow.TranDesc);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.taskID>(arTranRow, docLine.ProjectTaskID);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.costCodeID>(arTranRow, docLine.CostCodeID);

                arTranRow = Base.Transactions.Update(arTranRow);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.commissionable>(arTranRow, docLine.Commissionable ?? false);

                fsxARTranRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow);

                fsxARTranRow.Source            = ID.DocumentSource.INVOICE_FROM_SERVICECONTRACT;
                fsxARTranRow.ServiceContractID = fsServiceContractRow.ServiceContractID;
                fsxARTranRow.ContractPeriodID  = fsContractPeriodRow.ContractPeriodID;

                fsxARTranRow.BillCustomerID     = fsServiceContractRow.CustomerID;
                fsxARTranRow.CustomerLocationID = fsServiceContractRow.CustomerLocationID;

                arTranRow = Base.Transactions.Update(arTranRow);
            }

            if (Base.ARSetup.Current.RequireControlTotal == true)
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal);
            }

            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.hold>(arInvoiceRow, false);

            Exception newException = null;

            try
            {
                Base.Save.Press();
            }
            catch (Exception e)
            {
                List <ErrorInfo> errorList = this.GetErrorInfo();
                newException = InvoicingFunctions.GetErrorInfoInLines(errorList, e);
            }

            if (newException != null)
            {
                throw newException;
            }

            arInvoiceRow = Base.Document.Current;

            FSContractPostDoc fsContractCreatedDocRow = new FSContractPostDoc()
            {
                ContractPeriodID    = fsContractPeriodRow.ContractPeriodID,
                ContractPostBatchID = fsContractPostBatchRow.ContractPostBatchID,
                PostDocType         = arInvoiceRow.DocType,
                PostedTO            = ID.Batch_PostTo.AR,
                PostRefNbr          = arInvoiceRow.RefNbr,
                ServiceContractID   = fsServiceContractRow.ServiceContractID
            };

            return(fsContractCreatedDocRow);
        }