/// <summary> /// Save to Project /// </summary> /// <param name="C_Project_ID">id</param> /// <returns>true if saved</returns> private bool Cmd_SaveProject(Ctx ctx, int C_Project_ID) { Decimal qty = 0; log.Config("C_Project_ID=" + C_Project_ID); MProject project = new MProject(ctx, C_Project_ID, null); if (project.Get_ID() == 0) { log.Log(Level.SEVERE, "Not found - C_Project_ID=" + C_Project_ID); } int lineCount = 0; bool chk = false; // for all bom lines if (_selectionList != null) { bool isQtySet = false; for (int i = 0; i < _selectionList.Count; i++) { if (_selectionList[i].IsSelected) { int M_Product_ID = Util.GetValueOfInt(_selectionList[i].ProductID);//.intValue(); // Create Line MProjectLine pl = new MProjectLine(project); pl.SetM_Product_ID(Util.GetValueOfInt(_selectionList[i].ProductID)); pl.SetPlannedQty(Util.GetValueOfInt(_selectionList[i].BOMQty)); if (pl.Save()) { lineCount++; } else { log.Log(Level.SEVERE, "Line not saved"); } } // line selected } // for all bom lines log.Config("#" + lineCount); } return(true); }
/** * Create PO from Planned Amt/Qty * @param projectLine project line */ private void CreatePO(MProject project, MProjectLine projectLine) { if (projectLine.GetM_Product_ID() == 0) { AddLog(projectLine.GetLine(), null, null, "Line has no Product"); return; } if (projectLine.GetC_OrderPO_ID() != 0) { AddLog(projectLine.GetLine(), null, null, "Line was ordered previously"); return; } // PO Record MProductPO[] pos = MProductPO.GetOfProduct(GetCtx(), projectLine.GetM_Product_ID(), Get_TrxName()); if (pos == null || pos.Length == 0) { AddLog(projectLine.GetLine(), null, null, "Product has no PO record"); return; } // Create to Order MOrder order = null; // try to find PO to C_BPartner for (int i = 0; i < m_pos.Count; i++) { MOrder test = m_pos[i]; if (test.GetC_BPartner_ID() == pos[0].GetC_BPartner_ID()) { order = test; break; } } if (order == null) // create new Order { // Vendor MBPartner bp = new MBPartner(GetCtx(), pos[0].GetC_BPartner_ID(), Get_TrxName()); // New Order order = new MOrder(project, false, null); int AD_Org_ID = projectLine.GetAD_Org_ID(); if (AD_Org_ID == 0) { log.Warning("createPOfromProjectLine - AD_Org_ID=0"); AD_Org_ID = GetCtx().GetAD_Org_ID(); if (AD_Org_ID != 0) { projectLine.SetAD_Org_ID(AD_Org_ID); } } order.SetClientOrg(projectLine.GetAD_Client_ID(), AD_Org_ID); order.SetBPartner(bp); order.SetC_Project_ID(project.Get_ID()); order.Save(); // optionally save for consolidation if (m_ConsolidateDocument) { m_pos.Add(order); } } // Create Line MOrderLine orderLine = new MOrderLine(order); orderLine.SetM_Product_ID(projectLine.GetM_Product_ID(), true); orderLine.SetQty(projectLine.GetPlannedQty()); orderLine.SetDescription(projectLine.GetDescription()); // (Vendor) PriceList Price orderLine.SetPrice(); if (Env.Signum(orderLine.GetPriceActual()) == 0) { // Try to find purchase price Decimal poPrice = pos[0].GetPricePO(); int C_Currency_ID = pos[0].GetC_Currency_ID(); // if (Env.Signum(poPrice) == 0) { poPrice = pos[0].GetPriceLastPO(); } if (Env.Signum(poPrice) == 0) { poPrice = pos[0].GetPriceList(); } // We have a price if (Env.Signum(poPrice) != 0) { if (order.GetC_Currency_ID() != C_Currency_ID) { poPrice = VAdvantage.Model.MConversionRate.Convert(GetCtx(), poPrice, C_Currency_ID, order.GetC_Currency_ID(), order.GetDateAcct(), order.GetC_ConversionType_ID(), order.GetAD_Client_ID(), order.GetAD_Org_ID()); } orderLine.SetPrice(poPrice); } } orderLine.SetTax(); orderLine.Save(); // touch order to recalculate tax and totals order.SetIsActive(order.IsActive()); order.Save(); // update ProjectLine projectLine.SetC_OrderPO_ID(order.GetC_Order_ID()); projectLine.Save(); AddLog(projectLine.GetLine(), null, projectLine.GetPlannedQty(), order.GetDocumentNo()); }