Пример #1
0
        public virtual void InvoiceContractPeriodFilter_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            InvoiceContractPeriodFilter createInvoiceFilterRow = (InvoiceContractPeriodFilter)e.Row;

            string errorMessage         = PXUIFieldAttribute.GetErrorOnly <InvoiceContractPeriodFilter.invoiceFinPeriodID>(cache, createInvoiceFilterRow);
            bool   enableProcessButtons = string.IsNullOrEmpty(errorMessage) == true;

            Contracts.SetProcessAllEnabled(enableProcessButtons);
            Contracts.SetProcessEnabled(enableProcessButtons);
        }
Пример #2
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++;
                }
            });
        }