/** * Issue Receipt * @return Message (clear text) */ private String IssueReceipt() { MInOut inOut = new MInOut(GetCtx(), m_M_InOut_ID, null); if (inOut.IsSOTrx() || !inOut.IsProcessed() || !(MInOut.DOCSTATUS_Completed.Equals(inOut.GetDocStatus()) || MInOut.DOCSTATUS_Closed.Equals(inOut.GetDocStatus()))) { throw new ArgumentException("Receipt not valid - " + inOut); } log.Info(inOut.ToString()); // Set Project of Receipt if (inOut.GetC_Project_ID() == 0) { inOut.SetC_Project_ID(m_project.GetC_Project_ID()); inOut.Save(); } else if (inOut.GetC_Project_ID() != m_project.GetC_Project_ID()) { throw new ArgumentException("Receipt for other Project (" + inOut.GetC_Project_ID() + ")"); } MInOutLine[] inOutLines = inOut.GetLines(false); int counter = 0; for (int i = 0; i < inOutLines.Length; i++) { // Need to have a Product if (inOutLines[i].GetM_Product_ID() == 0) { continue; } // Need to have Quantity if (Env.Signum(inOutLines[i].GetMovementQty()) == 0) { continue; } // not issued yet if (ProjectIssueHasReceipt(inOutLines[i].GetM_InOutLine_ID())) { continue; } // Create Issue MProjectIssue pi = new MProjectIssue(m_project); pi.SetMandatory(inOutLines[i].GetM_Locator_ID(), inOutLines[i].GetM_Product_ID(), inOutLines[i].GetMovementQty()); if (m_MovementDate != null) // default today { pi.SetMovementDate(m_MovementDate); } if (m_Description != null && m_Description.Length > 0) { pi.SetDescription(m_Description); } else if (inOutLines[i].GetDescription() != null) { pi.SetDescription(inOutLines[i].GetDescription()); } else if (inOut.GetDescription() != null) { pi.SetDescription(inOut.GetDescription()); } pi.SetM_InOutLine_ID(inOutLines[i].GetM_InOutLine_ID()); pi.Process(); // Find/Create Project Line MProjectLine pl = null; MProjectLine[] pls = m_project.GetLines(); for (int ii = 0; ii < pls.Length; ii++) { // The Order we generated is the same as the Order of the receipt if (pls[ii].GetC_OrderPO_ID() == inOut.GetC_Order_ID() && pls[ii].GetM_Product_ID() == inOutLines[i].GetM_Product_ID() && pls[ii].GetC_ProjectIssue_ID() == 0) // not issued { pl = pls[ii]; break; } } if (pl == null) { pl = new MProjectLine(m_project); } pl.SetMProjectIssue(pi); // setIssue pl.Save(); AddLog(pi.GetLine(), pi.GetMovementDate(), pi.GetMovementQty(), null); counter++; } // all InOutLines return("@Created@ " + counter); } // issueReceipt