} // prepare /// <summary> /// Perrform Process. /// </summary> /// <returns>Message (translated text)</returns> protected override String DoIt() { MProject project = new MProject(GetCtx(), m_C_Project_ID, Get_TrxName()); log.Info("doIt - " + project); MProjectLine[] projectLines = project.GetLines(); if (MProject.PROJECTCATEGORY_WorkOrderJob.Equals(project.GetProjectCategory()) || MProject.PROJECTCATEGORY_AssetProject.Equals(project.GetProjectCategory())) { /** @todo Check if we should close it */ } // Close lines for (int line = 0; line < projectLines.Length; line++) { projectLines[line].SetProcessed(true); projectLines[line].Save(); } project.SetProcessed(true); project.Save(); return(""); } // doIt
protected override String DoIt() { log.Info("doIt - C_Project_ID=" + m_C_Project_ID + " - C_ProjectLine_ID=" + m_C_ProjectLine_ID + " - Consolidate=" + m_ConsolidateDocument); if (m_C_ProjectLine_ID != 0) { MProjectLine projectLine = new MProjectLine(GetCtx(), m_C_ProjectLine_ID, Get_TrxName()); MProject project = new MProject(GetCtx(), projectLine.GetC_Project_ID(), Get_TrxName()); CreatePO(project, projectLine); } else { MProject project = new MProject(GetCtx(), m_C_Project_ID, Get_TrxName()); MProjectLine[] lines = project.GetLines(); //for (MProjectLine element : lines) for (int i = 0; i < lines.Length; i++) { MProjectLine element = lines[i]; CreatePO(project, element); } } return(""); }
/// <summary> /// Generate Quotation /// </summary> /// <returns>Process Message</returns> protected override string DoIt() { // Int32 value = 0; string msg = ""; ValueNamePair vp = null; MBPartner bp = null; MOrderLine ol = null; log.Info("C_Project_ID=" + _C_Project_ID); if (_C_Project_ID == 0) { throw new ArgumentException("C_Project_ID == 0"); } MProject fromProject = new MProject(GetCtx(), _C_Project_ID, Get_TrxName()); if (fromProject.GetGenerate_Quotation() == null) { throw new ArgumentException("No Generate Quotation found on Project."); } if (fromProject.GetGenerate_Quotation().Trim() == "Y") { throw new ArgumentException("Sales Quotation already generated"); } // if Business Partner or Prospect is not selected then gives error if (fromProject.GetC_BPartner_ID() == 0 && fromProject.GetC_BPartnerSR_ID() == 0) { return(Msg.GetMsg(GetCtx(), "SelectBP/Prospect")); } //JID_1200: if Business Partner/Prospect Location is not selected then gives error if (fromProject.GetC_BPartner_Location_ID() == 0) { return(Msg.GetMsg(GetCtx(), "SelectBPLocation")); } MOrder order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetAD_Client_ID(fromProject.GetAD_Client_ID()); order.SetAD_Org_ID(fromProject.GetAD_Org_ID()); C_Bpartner_id = fromProject.GetC_BPartner_ID(); C_Bpartner_Location_id = fromProject.GetC_BPartner_Location_ID(); C_BPartnerSR_ID = fromProject.GetC_BPartnerSR_ID(); MBPartnerLocation bpartnerloc = new MBPartnerLocation(GetCtx(), C_Bpartner_Location_id, Get_TrxName()); //String currentdate = DateTime.Now.ToString(); String sqlprjln = "SELECT COUNT(C_ProjectLine_ID) FROM C_ProjectLine WHERE C_Project_ID=" + _C_Project_ID; C_ProjectLine_ID = Util.GetValueOfInt(DB.ExecuteScalar(sqlprjln, null, Get_TrxName())); if (C_ProjectLine_ID != 0) { order.SetDateOrdered(DateTime.Now.ToLocalTime()); order.SetDatePromised(DateTime.Now.ToLocalTime()); if (C_Bpartner_id != 0) { order.SetC_BPartner_ID(fromProject.GetC_BPartner_ID()); if (bpartnerloc.IsShipTo() == true) { order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetAD_User_ID(fromProject.GetAD_User_ID()); } if (bpartnerloc.IsBillTo() == true) { order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetBill_User_ID(fromProject.GetAD_User_ID()); } } if (C_BPartnerSR_ID != 0) { order.SetC_BPartner_ID(fromProject.GetC_BPartnerSR_ID()); if (bpartnerloc.IsShipTo() == true) { order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetAD_User_ID(fromProject.GetAD_User_ID()); } if (bpartnerloc.IsBillTo() == true) { order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetBill_User_ID(fromProject.GetAD_User_ID()); } } String sql = "SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType = 'SOO' AND DocSubTypeSO = 'ON' AND IsReturnTrx = 'N' AND IsActive = 'Y' AND AD_Client_ID = " + GetCtx().GetAD_Client_ID() + " AND AD_Org_ID IN (0, " + GetAD_Org_ID() + ") ORDER BY AD_Org_ID DESC"; int Doctype_id = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_TrxName())); int MPriceList_id = fromProject.GetM_PriceList_ID(); order.SetM_PriceList_ID(MPriceList_id); order.SetC_Project_ID(GetRecord_ID()); if (fromProject.GetSalesRep_ID() > 0) { order.SetSalesRep_ID(fromProject.GetSalesRep_ID()); } order.SetC_Currency_ID(fromProject.GetC_Currency_ID()); if (C_Bpartner_id != 0) { bp = new MBPartner(GetCtx(), C_Bpartner_id, Get_TrxName()); if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } //bp.SetAD_Client_ID(fromProject.GetAD_Client_ID()); //bp.SetAD_Org_ID(fromProject.GetAD_Org_ID()); if (bp.GetC_PaymentTerm_ID() != 0) { order.SetPaymentMethod(bp.GetPaymentRule()); order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); order.SetVA009_PaymentMethod_ID(bp.GetVA009_PaymentMethod_ID()); } if (!bp.Save()) { log.SaveError("BPartnerNotSaved", ""); return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } } else { bp = new MBPartner(GetCtx(), C_BPartnerSR_ID, Get_TrxName()); if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } //bp.SetAD_Client_ID(fromProject.GetAD_Client_ID()); //bp.SetAD_Org_ID(fromProject.GetAD_Org_ID()); if (bp.GetC_PaymentTerm_ID() != 0) { order.SetPaymentMethod(bp.GetPaymentRule()); order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); order.SetVA009_PaymentMethod_ID(bp.GetVA009_PaymentMethod_ID()); } if (!bp.Save()) { log.SaveError("BPartnerNotSaved", ""); return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } } order.SetFreightCostRule("I"); if (order.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { order.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } order.SetDocStatus("IP"); order.SetC_DocType_ID(Doctype_id); order.SetC_DocTypeTarget_ID(Doctype_id); order.SetIsSOTrx(true); order.Set_Value("IsSalesQuotation", true); //Set VA077 values on header level if (Env.IsModuleInstalled("VA077_")) { //Get the org count of legal entity org sql = @"SELECT Count(AD_Org_ID) FROM AD_Org WHERE IsActive='Y' AND (IsProfitCenter ='Y' OR IsCostCenter ='Y') AND AD_Client_Id=" + fromProject.GetAD_Client_ID() + @" AND LegalEntityOrg = " + fromProject.GetAD_Org_ID(); int result = Util.GetValueOfInt(DB.ExecuteScalar(sql)); if (result > 0) { order.SetVA077_IsLegalEntity(true); } order.SetVA077_SalesCoWorker(fromProject.GetVA077_SalesCoWorker()); order.SetVA077_SalesCoWorkerPer(fromProject.GetVA077_SalesCoWorkerPer()); order.Set_Value("VA077_TotalMarginAmt", fromProject.Get_Value("VA077_TotalMarginAmt")); order.Set_Value("VA077_TotalPurchaseAmt", fromProject.Get_Value("VA077_TotalPurchaseAmt")); order.Set_Value("VA077_TotalSalesAmt", fromProject.Get_Value("VA077_TotalSalesAmt")); order.Set_Value("VA077_MarginPercent", fromProject.Get_Value("VA077_MarginPercent")); } if (!order.Save()) { Get_TrxName().Rollback(); vp = VLogger.RetrieveError(); if (vp != null) { msg = vp.GetName(); } else { msg = Msg.GetMsg(GetCtx(), "QuotationNotSaved"); } log.SaveError("QuotationNotSaved", ""); return(msg); } //Order Lines int count = 0; MProjectLine[] lines = fromProject.GetLines(); for (int i = 0; i < lines.Length; i++) { ol = new MOrderLine(order); ol.SetLine(lines[i].GetLine()); ol.SetDescription(lines[i].GetDescription()); ol.SetM_Product_ID(lines[i].GetM_Product_ID(), true); ol.SetQtyEntered(lines[i].GetPlannedQty()); ol.SetQtyOrdered(lines[i].GetPlannedQty()); ol.SetPriceEntered(lines[i].GetPlannedPrice()); ol.SetPriceActual(lines[i].GetPlannedPrice()); ol.SetPriceList(lines[i].GetPriceList()); //Set VA077 values on line level if (Env.IsModuleInstalled("VA077_")) { ol.Set_Value("VA077_MarginPercent", lines[i].Get_Value("VA077_MarginPercent")); ol.Set_Value("VA077_MarginAmt", lines[i].Get_Value("VA077_MarginAmt")); ol.Set_Value("VA077_PurchasePrice", lines[i].Get_Value("VA077_PurchasePrice")); } if (ol.Save()) { count++; } else { Get_TrxName().Rollback(); vp = VLogger.RetrieveError(); if (vp != null) { msg = vp.GetName(); } else { msg = Msg.GetMsg(GetCtx(), "QuoteLineNotSaved"); } log.SaveError("QuoteLineNotSaved", ""); return(msg); } } fromProject.SetRef_Order_ID(order.GetC_Order_ID()); fromProject.SetGenerate_Quotation("Y"); if (!fromProject.Save()) { Get_TrxName().Rollback(); log.SaveError("ProjectNotSaved", ""); return(Msg.GetMsg(GetCtx(), "ProjectNotSaved")); } msg = Msg.GetMsg(GetCtx(), "QuotationGenerated"); } else { msg = Msg.GetMsg(GetCtx(), "NoLines"); } return(msg); }
} // prepare /// <summary> /// Perrform Process. /// </summary> /// <returns>Message (clear text)</returns> protected override String DoIt() { log.Info("C_Project_ID=" + _C_Project_ID); if (_C_Project_ID == 0) { throw new ArgumentException("C_Project_ID == 0"); } MProject fromProject = GetProject(GetCtx(), _C_Project_ID, Get_TrxName()); GetCtx().SetIsSOTrx(true); // Set SO context /** @todo duplicate invoice prevention */ MOrder order = new MOrder(fromProject, true, MOrder.DocSubTypeSO_OnCredit); if (!order.Save()) { throw new Exception("Could not create Order"); } // *** Lines *** int count = 0; // Service Project if (MProject.PROJECTCATEGORY_ServiceChargeProject.Equals(fromProject.GetProjectCategory())) { /** @todo service project invoicing */ throw new Exception("Service Charge Projects are on the TODO List"); } // Service Lines else // Order Lines { MProjectLine[] lines = fromProject.GetLines(); for (int i = 0; i < lines.Length; i++) { MOrderLine ol = new MOrderLine(order); ol.SetLine(lines[i].GetLine()); ol.SetDescription(lines[i].GetDescription()); // ol.SetM_Product_ID(lines[i].GetM_Product_ID(), true); //ol.SetQty(lines[i].GetPlannedQty().subtract(lines[i].GetInvoicedQty())); ol.SetQty(Decimal.Subtract(lines[i].GetPlannedQty(), lines[i].GetInvoicedQty())); ol.SetPrice(); if (lines[i].GetPlannedPrice().CompareTo(Env.ZERO) != 0) { ol.SetPrice(lines[i].GetPlannedPrice()); } ol.SetDiscount(); ol.SetTax(); if (ol.Save()) { count++; } } // for all lines if (lines.Length != count) { log.Log(Level.SEVERE, "Lines difference - ProjectLines=" + lines.Length + " <> Saved=" + count); } } // Order Lines return("@C_Order_ID@ " + order.GetDocumentNo() + " (" + count + ")"); } // doIt
} // prepare /// <summary> /// Perrform Process. /// </summary> /// <returns>Message (clear text)</returns> protected override String DoIt() { log.Info("C_Project_ID=" + _C_Project_ID); if (_C_Project_ID == 0) { throw new ArgumentException("C_Project_ID == 0"); } MProject fromProject = GetProject(GetCtx(), _C_Project_ID, Get_TrxName()); GetCtx().SetIsSOTrx(true); // Set SO context /** @todo duplicate invoice prevention */ //Added by Vivek for Credit Limit on 24/08/2016 if (fromProject.GetC_BPartner_ID() != 0) { VAdvantage.Model.MBPartner bp = new VAdvantage.Model.MBPartner(GetCtx(), fromProject.GetC_BPartner_ID(), Get_TrxName()); if (bp.GetCreditStatusSettingOn() == "CH") { if (bp.GetCreditValidation() == "A" || bp.GetCreditValidation() == "D" || bp.GetCreditValidation() == "E") { log.SaveError("StopOrder", ""); return(Msg.GetMsg(GetCtx(), "StopOrder")); } else if (bp.GetCreditValidation() == "G" || bp.GetCreditValidation() == "J" || bp.GetCreditValidation() == "K") { if (_msg != null) { _msg.Clear(); } log.SaveError("WarningOrder", ""); _msg.Append(Msg.GetMsg(GetCtx(), "WarningOrder")); } } else { VAdvantage.Model.MBPartnerLocation loc = new VAdvantage.Model.MBPartnerLocation(GetCtx(), fromProject.GetC_BPartner_Location_ID(), Get_TrxName()); if (loc.GetCreditValidation() == "A" || loc.GetCreditValidation() == "D" || loc.GetCreditValidation() == "E") { log.SaveError("StopOrder", ""); return(Msg.GetMsg(GetCtx(), "StopOrder")); } else if (loc.GetCreditValidation() == "G" || loc.GetCreditValidation() == "J" || loc.GetCreditValidation() == "K") { if (_msg != null) { _msg.Clear(); } log.SaveError("WarningOrder", ""); _msg.Append(Msg.GetMsg(GetCtx(), "WarningOrder")); } } } //Credit Limit MOrder order = new MOrder(fromProject, true, MOrder.DocSubTypeSO_OnCredit); if (!order.Save()) { throw new Exception("Could not create Order"); } // *** Lines *** int count = 0; // Service Project if (MProject.PROJECTCATEGORY_ServiceChargeProject.Equals(fromProject.GetProjectCategory())) { /** @todo service project invoicing */ throw new Exception("Service Charge Projects are on the TODO List"); } // Service Lines else // Order Lines { MProjectLine[] lines = fromProject.GetLines(); for (int i = 0; i < lines.Length; i++) { MOrderLine ol = new MOrderLine(order); ol.SetLine(lines[i].GetLine()); ol.SetDescription(lines[i].GetDescription()); // ol.SetM_Product_ID(lines[i].GetM_Product_ID(), true); //ol.SetQty(lines[i].GetPlannedQty().subtract(lines[i].GetInvoicedQty())); ol.SetQty(Decimal.Subtract(lines[i].GetPlannedQty(), lines[i].GetInvoicedQty())); ol.SetPrice(); if (lines[i].GetPlannedPrice().CompareTo(Env.ZERO) != 0) { ol.SetPrice(lines[i].GetPlannedPrice()); } ol.SetDiscount(); ol.SetTax(); if (ol.Save()) { count++; } } // for all lines if (lines.Length != count) { log.Log(Level.SEVERE, "Lines difference - ProjectLines=" + lines.Length + " <> Saved=" + count); } } // Order Lines if (_msg != null) { return("@C_Order_ID@ " + order.GetDocumentNo() + " (" + count + ")" + " " + _msg); } else { return("@C_Order_ID@ " + order.GetDocumentNo() + " (" + count + ")"); } } // doIt
} // prepare /// <summary> /// Generate Sales Order /// </summary> /// <returns>Process Message</returns> protected override String DoIt() { Int32 value = 0; string msg = ""; ValueNamePair vp = null; MBPartner bp = null; MOrderLine ol = null; log.Info("C_Project_ID=" + _C_Project_ID); if (_C_Project_ID == 0) { throw new ArgumentException("C_Project_ID == 0"); } MProject fromProject = new MProject(GetCtx(), _C_Project_ID, Get_TrxName()); if (fromProject.GetGenerate_Order().Trim() == "Y") { throw new ArgumentException("Sales Order already generated"); } // if Business Partner or Prospect is not selected then gives error if (fromProject.GetC_BPartner_ID() == 0 && fromProject.GetC_BPartnerSR_ID() == 0) { return(Msg.GetMsg(GetCtx(), "SelectBP/Prospect")); } // if Business Partner/Prospect Location is not selected then gives error if (fromProject.GetC_BPartner_Location_ID() == 0) { return(Msg.GetMsg(GetCtx(), "SelectBPLocation")); } MOrder order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetAD_Client_ID(fromProject.GetAD_Client_ID()); order.SetAD_Org_ID(fromProject.GetAD_Org_ID()); C_Bpartner_id = fromProject.GetC_BPartner_ID(); C_Bpartner_Location_id = fromProject.GetC_BPartner_Location_ID(); C_BPartnerSR_ID = fromProject.GetC_BPartnerSR_ID(); MBPartnerLocation bpartnerloc = new MBPartnerLocation(GetCtx(), C_Bpartner_Location_id, Get_TrxName()); //String currentdate = DateTime.Now.ToString(); String sqlprjln = "SELECT COUNT(C_ProjectLine_ID) FROM C_ProjectLine WHERE C_Project_ID=" + _C_Project_ID; C_ProjectLine_ID = Util.GetValueOfInt(DB.ExecuteScalar(sqlprjln, null, Get_TrxName())); if (C_ProjectLine_ID != 0) { order.SetDateOrdered(DateTime.Now.ToLocalTime()); order.SetDatePromised(DateTime.Now.ToLocalTime()); if (C_Bpartner_id != 0) { order.SetC_BPartner_ID(fromProject.GetC_BPartner_ID()); if (bpartnerloc.IsShipTo() == true) { order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetAD_User_ID(fromProject.GetAD_User_ID()); } if (bpartnerloc.IsBillTo() == true) { order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetBill_User_ID(fromProject.GetAD_User_ID()); } } if (C_BPartnerSR_ID != 0) { String sqlcust = "UPDATE C_BPartner SET IsCustomer='Y', IsProspect='N' WHERE C_BPartner_ID=" + C_BPartnerSR_ID; value = DB.ExecuteQuery(sqlcust, null, Get_TrxName()); if (value == -1) { return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } order.SetC_BPartner_ID(fromProject.GetC_BPartnerSR_ID()); if (bpartnerloc.IsShipTo() == true) { order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetAD_User_ID(fromProject.GetAD_User_ID()); } if (bpartnerloc.IsBillTo() == true) { order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetBill_User_ID(fromProject.GetAD_User_ID()); } } String sql = "SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType = 'SOO' AND DocSubTypeSO = 'SO' AND IsReturnTrx = 'N' AND IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID() + " AND AD_Org_ID IN (0, " + GetAD_Org_ID() + ") ORDER BY AD_Org_ID DESC"; int Doctype_id = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_TrxName())); order.SetM_PriceList_ID(fromProject.GetM_PriceList_ID()); order.SetC_Project_ID(GetRecord_ID()); if (fromProject.GetSalesRep_ID() > 0) { order.SetSalesRep_ID(fromProject.GetSalesRep_ID()); } order.SetC_Currency_ID(fromProject.GetC_Currency_ID()); if (C_Bpartner_id != 0) { bp = new MBPartner(GetCtx(), C_Bpartner_id, Get_TrxName()); if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } //bp.SetAD_Client_ID(fromProject.GetAD_Client_ID()); //bp.SetAD_Org_ID(fromProject.GetAD_Org_ID()); if (bp.GetC_PaymentTerm_ID() != 0) { order.SetPaymentMethod(bp.GetPaymentRule()); order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); } if (!bp.Save()) { log.SaveError("BPartnerNotSaved", ""); return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } } else { bp = new MBPartner(GetCtx(), C_BPartnerSR_ID, Get_TrxName()); if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } //bp.SetAD_Client_ID(fromProject.GetAD_Client_ID()); //bp.SetAD_Org_ID(fromProject.GetAD_Org_ID()); if (bp.GetC_PaymentTerm_ID() != 0) { order.SetPaymentMethod(bp.GetPaymentRule()); order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); } if (!bp.Save()) { log.SaveError("BPartnerNotSaved", ""); return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } } order.SetFreightCostRule("I"); if (order.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { order.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } order.SetDocStatus("IP"); order.SetC_DocType_ID(Doctype_id); order.SetIsSOTrx(true); order.SetC_DocTypeTarget_ID(Doctype_id); order.SetPriorityRule("5"); order.SetFreightCostRule("I"); if (!order.Save()) { Get_TrxName().Rollback(); vp = VLogger.RetrieveError(); if (vp != null) { msg = vp.GetName(); } else { msg = Msg.GetMsg(GetCtx(), "SaleOrderNotSaved"); } log.SaveError("SaleOrderNotSaved", ""); return(msg); } //Order Lines int count = 0; MProjectLine[] lines = fromProject.GetLines(); for (int i = 0; i < lines.Length; i++) { ol = new MOrderLine(order); ol.SetLine(lines[i].GetLine()); ol.SetDescription(lines[i].GetDescription()); ol.SetM_Product_ID(lines[i].GetM_Product_ID(), true); ol.SetQtyEntered(lines[i].GetPlannedQty()); ol.SetQtyOrdered(lines[i].GetPlannedQty()); ol.SetPriceEntered(lines[i].GetPlannedPrice()); ol.SetPriceActual(lines[i].GetPlannedPrice()); ol.SetPriceList(lines[i].GetPriceList()); if (ol.Save()) { count++; } else { Get_TrxName().Rollback(); vp = VLogger.RetrieveError(); if (vp != null) { msg = vp.GetName(); } else { msg = Msg.GetMsg(GetCtx(), "OrderLineNotSaved"); } log.SaveError("OrderLineNotSaved", ""); return(msg); } } fromProject.SetC_Order_ID(order.GetC_Order_ID()); fromProject.SetC_BPartner_ID(fromProject.GetC_BPartnerSR_ID()); fromProject.SetC_BPartnerSR_ID(0); fromProject.SetGenerate_Order("Y"); if (!fromProject.Save()) { Get_TrxName().Rollback(); log.SaveError("ProjectNotSaved", ""); return(Msg.GetMsg(GetCtx(), "ProjectNotSaved")); } return(Msg.GetMsg(GetCtx(), "OrderGenerationDone")); } else { msg = Msg.GetMsg(GetCtx(), "NoLines"); } return(msg); }
/** * 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