public static void ReverseAllocatedTran(PMTran tran)
        {
            RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>();

            pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });

            PMRegister reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert();

            reversalDoc.OrigDocType  = PMOrigDocType.AllocationReversal;
            reversalDoc.OrigDocNbr   = tran.RefNbr;
            reversalDoc.Description  = "Allocation Reversal to Non-Billable";
            pmEntry.Document.Current = reversalDoc;

            PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>();

            foreach (PMTran reverse in engine.ReverseTran(tran))
            {
                reverse.Reversed = true;
                pmEntry.Transactions.Insert(reverse);
            }

            tran.Reversed = true;
            pmEntry.Transactions.Update(tran);

            pmEntry.Save.Press();

            PMSetup setup = PXSelect <PMSetup> .Select(pmEntry);

            if (setup.AutoReleaseAllocation == true)
            {
                RegisterRelease.Release(reversalDoc);
            }
        }
Exemplo n.º 2
0
        protected virtual void BillingFilter_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            BillingFilter filter = Filter.Current;

            Items.SetProcessDelegate(
                delegate(ProjectsList item)
            {
                PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>();
                if (!engine.Bill(item.ProjectID, filter.InvoiceDate))
                {
                    throw new PXSetPropertyException(Warnings.NothingToBill, PXErrorLevel.RowWarning);
                }
            });
        }
        public static void ReverseAllocatedTran(PMTran tran)
        {
            RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>();

            pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });

            PMRegister reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert();

            reversalDoc.OrigDocType  = PMOrigDocType.AllocationReversal;
            reversalDoc.OrigDocNbr   = tran.RefNbr;
            reversalDoc.Description  = PXMessages.LocalizeNoPrefix(Messages.AllocationReversalNonBilling);
            pmEntry.Document.Current = reversalDoc;

            PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>();

            foreach (PMTran reverse in engine.ReverseTran(tran))
            {
                reverse.Reversed     = true;
                reverse.Date         = null;
                reverse.FinPeriodID  = null;
                reverse.TranDate     = null;
                reverse.TranPeriodID = null;

                pmEntry.Transactions.Insert(reverse);
            }

            tran.Reversed = true;
            PM.RegisterReleaseProcess.SubtractFromUnbilledSummary(pmEntry, tran);
            pmEntry.Transactions.Update(tran);

            pmEntry.Save.Press();

            PMSetup setup = PXSelect <PMSetup> .Select(pmEntry);

            if (setup.AutoReleaseAllocation == true)
            {
                RegisterRelease.Release(reversalDoc);
            }
        }
Exemplo n.º 4
0
        public static void ReverseAllocatedTran(PMTran tran)
        {
            RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>();

            pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });

            PMRegister origDoc = PXSelectReadonly <PMRegister, Where <PMRegister.refNbr, Equal <Required <PMRegister.refNbr> > > > .Select(pmEntry, tran.RefNbr);

            PMRegister reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert();

            reversalDoc.OrigDocType  = PMOrigDocType.Reversal;
            reversalDoc.OrigNoteID   = origDoc.NoteID;
            reversalDoc.Description  = PXMessages.LocalizeNoPrefix(Messages.AllocationReversal);
            pmEntry.Document.Current = reversalDoc;

            PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>();

            foreach (PMTran reverse in engine.ReverseTran(tran))
            {
                pmEntry.Transactions.Insert(reverse);
            }
            tran.ExcludedFromBilling       = true;
            tran.ExcludedFromBillingReason = PXMessages.LocalizeNoPrefix(Messages.ExcludedFromBillingAsReversed);
            PM.RegisterReleaseProcess.SubtractFromUnbilledSummary(pmEntry, tran);
            pmEntry.Transactions.Update(tran);

            pmEntry.Save.Press();

            PMSetup setup = PXSelect <PMSetup> .Select(pmEntry);

            if (setup.AutoReleaseAllocation == true)
            {
                RegisterRelease.Release(reversalDoc);
            }
        }
Exemplo n.º 5
0
        public virtual List <Balance> Run(PMTask task)
        {
            if (task.BillingID == null)
            {
                throw new PXException(Messages.BillingIDIsNotDefined);
            }

            Dictionary <string, Balance> balances = new Dictionary <string, Balance>();

            DateTime?     lastDate;
            List <PMTran> expenseTrans   = CreateExpenseTransactions(task, out lastDate);
            List <long>   expenseTranIds = new List <long>();

            Debug.Print("Created Expense Transactions:");
            Debug.Indent();
            foreach (PMTran tran in expenseTrans)
            {
                expenseTranIds.Add(tran.TranID.Value);
                Debug.Print("TranID:{0} AccountGroup:{1}, InventoryID={2}, Qty={3}, Amt={4}, Allocated={5}, Released={6}, Billed={7}, Date={8}", tran.TranID, AccountGroupFromID(tran.AccountGroupID), InventoryFromID(tran.InventoryID), tran.Qty, tran.Amount, tran.Allocated, tran.Released, tran.Billed, tran.Date);
            }
            Debug.Unindent();

            if (expenseTrans.Count == 0)
            {
                PXTrace.WriteError(Messages.FailedToEmulateExpenses, task.TaskCD);
                return(new List <Balance>());
            }

            PMAllocator ae = PXGraph.CreateInstance <PMAllocator>();

            ae.SourceTransactions = expenseTrans;
            foreach (PMTran tran in expenseTrans)
            {
                ae.Transactions.Insert(tran);
            }
            ae.OverrideAllocationDate = lastDate;
            ae.Execute(task);
            Debug.Print("After Allocation:");
            Debug.Indent();
            foreach (PMTran tran in ae.Transactions.Cache.Inserted)
            {
                tran.Released = true;
                Transactions.Cache.Update(tran);

                if (expenseTranIds.Contains(tran.TranID.Value))
                {
                    continue;
                }

                int    inventoryID = tran.InventoryID ?? PMInventorySelectorAttribute.EmptyInventoryID;
                string key         = string.Format("{0}.{1}", tran.AccountGroupID, inventoryID);

                if (!balances.ContainsKey(key))
                {
                    Balance b = new Balance();
                    b.AccountGroupID = tran.AccountGroupID.Value;
                    b.InventoryID    = inventoryID;

                    balances.Add(key, b);
                }

                Debug.Print("TranID:{0} AccountGroup:{1}, InventoryID={2}, Qty={3}, Amt={4}, Allocated={5}, Released={6}, Billed={7}, Date={8}", tran.TranID, AccountGroupFromID(tran.AccountGroupID), InventoryFromID(tran.InventoryID), tran.Qty, tran.Amount, tran.Allocated, tran.Released, tran.Billed, tran.Date);
            }
            Debug.Unindent();

            DateTime billingDate = lastDate.Value.AddDays(1);

            //Get ARTrans for Bill:
            Debug.Print("Bill using the following Billing date={0}", billingDate);

            PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>();

            engine.IsEmulation = true;
            engine.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            engine.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            Debug.Print("Transactions passed to BillTask:");
            Debug.Indent();
            foreach (PMTran tran in Transactions.Cache.Cached)
            {
                if (expenseTranIds.Contains(tran.TranID.Value))
                {
                    continue;
                }
                engine.Transactions.Insert(tran);
                Debug.Print("TranID:{0} AccountGroup:{1}, InventoryID={2}, Qty={3}, Amt={4}, Allocated={5}, Released={6}, Billed={7}, Date={8}", tran.TranID, AccountGroupFromID(tran.AccountGroupID), InventoryFromID(tran.InventoryID), tran.Qty, tran.Amount, tran.Allocated, tran.Released, tran.Billed, tran.Date);
            }
            Debug.Unindent();

            List <PMBillEngine.BillingData> arTrans = engine.BillTask(task, billingDate);

            //Create ARInvoice to DEFAULT Accounts and SubAccounts.
            ARInvoiceEntry invoiceEntry = PXGraph.CreateInstance <ARInvoiceEntry>();

            //Project and Task is in Planning State - thus suppress verification:
            invoiceEntry.FieldVerifying.AddHandler <ARInvoice.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            invoiceEntry.FieldVerifying.AddHandler <ARTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            invoiceEntry.FieldVerifying.AddHandler <ARTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            ARInvoice invoice = new ARInvoice();

            invoice.DocType = ARDocType.Invoice;

            invoice = PXCache <ARInvoice> .CreateCopy(invoiceEntry.Document.Insert(invoice));

            invoice.DocDate            = billingDate;
            invoice.CustomerID         = task.CustomerID;
            invoice.CustomerLocationID = task.LocationID;
            invoice.ProjectID          = task.ProjectID;
            invoice = (ARInvoice)invoiceEntry.Document.Update(invoice);

            CurrencyInfo curyinfo = (CurrencyInfo)invoiceEntry.Caches[typeof(CurrencyInfo)].Current;

            foreach (PMBillEngine.BillingData data in arTrans)
            {
                decimal curyamount;
                PXDBCurrencyAttribute.CuryConvCury(invoiceEntry.Caches[typeof(CurrencyInfo)], curyinfo, (data.Tran.UnitPrice ?? 0), out curyamount);
                data.Tran.CuryUnitPrice = curyamount;
                PXDBCurrencyAttribute.CuryConvCury(invoiceEntry.Caches[typeof(CurrencyInfo)], curyinfo, (data.Tran.ExtPrice ?? 0), out curyamount);
                data.Tran.CuryExtPrice     = curyamount;
                data.Tran.CuryTranAmt      = data.Tran.CuryExtPrice;
                data.Tran.FreezeManualDisc = true;
                ARTran newTran = (ARTran)invoiceEntry.Caches[typeof(ARTran)].Insert(data.Tran);
            }

            ARInvoice oldInvoice = (ARInvoice)invoiceEntry.Caches[typeof(ARInvoice)].CreateCopy(invoice);

            invoice.CuryOrigDocAmt = invoice.CuryDocBal;
            invoiceEntry.Caches[typeof(ARInvoice)].RaiseRowUpdated(invoice, oldInvoice);

            Debug.Print("AR Trans:");
            Debug.Indent();

            foreach (ARTran tran in invoiceEntry.Transactions.Select())
            {
                if (tran.TaskID == task.TaskID)
                {
                    Debug.Print("InventoryID={0}, Qty={1}, Amt={2}", InventoryFromID(tran.InventoryID), tran.Qty, tran.TranAmt);

                    Account acct = PXSelect <Account, Where <Account.accountID, Equal <Required <Account.accountID> > > > .Select(invoiceEntry, tran.AccountID);

                    if (acct.AccountGroupID == null)
                    {
                        throw new PXException("Failed to emulate billing. The Sales Account in the Invoice is not mapped to any Account Group.");
                    }

                    string key = string.Format("{0}.{1}", acct.AccountGroupID, tran.InventoryID ?? PMInventorySelectorAttribute.EmptyInventoryID);

                    if (balances.ContainsKey(key))
                    {
                        balances[key].Amount   += tran.TranAmt ?? 0;
                        balances[key].Quantity += tran.Qty ?? 0;
                    }
                    else
                    {
                        Balance b = new Balance();
                        b.AccountGroupID = acct.AccountGroupID.Value;
                        b.InventoryID    = tran.InventoryID ?? PMInventorySelectorAttribute.EmptyInventoryID;
                        b.Amount         = tran.TranAmt ?? 0;
                        b.Quantity       = tran.Qty ?? 0;

                        balances.Add(key, b);
                    }
                }
            }

            return(new List <Balance>(balances.Values));
        }