示例#1
0
        }       //	issueReceipt

        /**
         *	Issue Expense Report
         *	@return Message (clear text)
         */
        private String IssueExpense()
        {
            //	Get Expense Report
            MTimeExpense expense = new MTimeExpense(GetCtx(), m_S_TimeExpense_ID, Get_TrxName());

            if (!expense.IsProcessed())
            {
                throw new ArgumentException("Time+Expense not processed - " + expense);
            }

            //	for all expense lines
            MTimeExpenseLine[] expenseLines = expense.GetLines(false);
            int counter = 0;

            for (int i = 0; i < expenseLines.Length; i++)
            {
                //	Need to have a Product
                if (expenseLines[i].GetM_Product_ID() == 0)
                {
                    continue;
                }
                //	Need to have Quantity
                if (Env.Signum(expenseLines[i].GetQty()) == 0)
                {
                    continue;
                }
                //	Need to the same project
                if (expenseLines[i].GetC_Project_ID() != m_project.GetC_Project_ID())
                {
                    continue;
                }
                //	not issued yet
                if (ProjectIssueHasExpense(expenseLines[i].GetS_TimeExpenseLine_ID()))
                {
                    continue;
                }

                //	Find Location
                int M_Locator_ID = 0;
                //	MProduct product = new MProduct (getCtx(), expenseLines[i].getM_Product_ID());
                //	if (product.isStocked())
                M_Locator_ID = MStorage.GetM_Locator_ID(expense.GetM_Warehouse_ID(),
                                                        expenseLines[i].GetM_Product_ID(), 0, //	no ASI
                                                        expenseLines[i].GetQty(), null);
                if (M_Locator_ID == 0)                                                        //	Service/Expense - get default (and fallback)
                {
                    M_Locator_ID = expense.GetM_Locator_ID();
                }

                //	Create Issue
                MProjectIssue pi = new MProjectIssue(m_project);
                pi.SetMandatory(M_Locator_ID, expenseLines[i].GetM_Product_ID(), expenseLines[i].GetQty());
                if (m_MovementDate != null)             //	default today
                {
                    pi.SetMovementDate(m_MovementDate);
                }
                if (m_Description != null && m_Description.Length > 0)
                {
                    pi.SetDescription(m_Description);
                }
                else if (expenseLines[i].GetDescription() != null)
                {
                    pi.SetDescription(expenseLines[i].GetDescription());
                }
                pi.SetS_TimeExpenseLine_ID(expenseLines[i].GetS_TimeExpenseLine_ID());
                pi.Process();
                //	Find/Create Project Line
                MProjectLine pl = new MProjectLine(m_project);
                pl.SetMProjectIssue(pi);                //	setIssue
                pl.Save();
                AddLog(pi.GetLine(), pi.GetMovementDate(), pi.GetMovementQty(), null);
                counter++;
            }   //	allExpenseLines

            return("@Created@ " + counter);
        }       //	issueExpense