} // sendAlert private int sendAlertToResponsible(MWFResponsible responsible, List <int> list, MWFProcess process, String subject, String message, FileInfo pdf) { int counter = 0; if (responsible.IsInvoker()) { ; } // Human else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Human.Equals(responsible.GetResponsibleType()) && responsible.GetAD_User_ID() != 0 && !list.Contains(responsible.GetAD_User_ID())) { if (m_client.SendEMail(responsible.GetAD_User_ID(), subject, message, pdf)) { counter++; } list.Add(responsible.GetAD_User_ID()); } // Org of the Document else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Organization.Equals(responsible.GetResponsibleType())) { PO document = process.GetPO(); if (document != null) { MOrgInfo org = MOrgInfo.Get(GetCtx(), document.GetAD_Org_ID(), null); if (org.GetSupervisor_ID() != 0 && !list.Contains(org.GetSupervisor_ID())) { if (m_client.SendEMail(org.GetSupervisor_ID(), subject, message, pdf)) { counter++; } list.Add(org.GetSupervisor_ID()); } } } // Role else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Role.Equals(responsible.GetResponsibleType()) && responsible.GetAD_Role_ID() != 0) { MUserRoles[] userRoles = MUserRoles.GetOfRole(GetCtx(), responsible.GetAD_Role_ID()); for (int i = 0; i < userRoles.Length; i++) { MUserRoles roles = userRoles[i]; if (!roles.IsActive()) { continue; } int AD_User_ID = roles.GetAD_User_ID(); if (!list.Contains(AD_User_ID)) { if (m_client.SendEMail(AD_User_ID, subject, message, pdf)) { counter++; } list.Add(AD_User_ID); } } } return(counter); } // sendAlertToResponsible
/// <summary> /// Create Orders /// </summary> /// <returns>true if created</returns> private bool CreateOrders() { // Get Counter Org/BP int runAD_Org_ID = _run.GetAD_Org_ID(); if (runAD_Org_ID == 0) { runAD_Org_ID = GetCtx().GetAD_Org_ID(); } MOrg runOrg = MOrg.Get(GetCtx(), runAD_Org_ID); int runC_BPartner_ID = runOrg.GetLinkedC_BPartner_ID(); bool counter = !_run.IsCreateSingleOrder() && // no single Order runC_BPartner_ID > 0 && // Org linked to BP !_docType.IsSOTrx(); // PO MBPartner runBPartner = counter ? new MBPartner(GetCtx(), runC_BPartner_ID, Get_TrxName()) : null; if (!counter || runBPartner == null || runBPartner.Get_ID() != runC_BPartner_ID) { counter = false; } if (counter) { log.Info("RunBP=" + runBPartner + " - " + _docType); } log.Info("Single=" + _run.IsCreateSingleOrder() + " - " + _docType + ",SO=" + _docType.IsSOTrx()); log.Fine("Counter=" + counter + ",C_BPartner_ID=" + runC_BPartner_ID + "," + runBPartner); // MBPartner bp = null; MOrder singleOrder = null; MProduct product = null; // Consolidated Order if (_run.IsCreateSingleOrder()) { bp = new MBPartner(GetCtx(), _run.GetC_BPartner_ID(), Get_TrxName()); if (bp.Get_ID() == 0) { throw new ArgumentException("Business Partner not found - C_BPartner_ID=" + _run.GetC_BPartner_ID()); } // if (!_IsTest) { singleOrder = new MOrder(GetCtx(), 0, Get_TrxName()); singleOrder.SetC_DocTypeTarget_ID(_docType.GetC_DocType_ID()); singleOrder.SetC_DocType_ID(_docType.GetC_DocType_ID()); singleOrder.SetIsReturnTrx(_docType.IsReturnTrx()); singleOrder.SetIsSOTrx(_docType.IsSOTrx()); singleOrder.SetBPartner(bp); if (_run.GetC_BPartner_Location_ID() != 0) { singleOrder.SetC_BPartner_Location_ID(_run.GetC_BPartner_Location_ID()); } singleOrder.SetDateOrdered(_DateOrdered); singleOrder.SetDatePromised(_DatePromised); if (!singleOrder.Save()) { log.Log(Level.SEVERE, "Order not saved"); return(false); } _counter++; } } int lastC_BPartner_ID = 0; int lastC_BPartner_Location_ID = 0; MOrder order = null; // For all lines for (int i = 0; i < _details.Length; i++) { MDistributionRunDetail detail = _details[i]; // Create Order Header if (_run.IsCreateSingleOrder()) { order = singleOrder; } // New Business Partner else if (lastC_BPartner_ID != detail.GetC_BPartner_ID() || lastC_BPartner_Location_ID != detail.GetC_BPartner_Location_ID()) { // finish order order = null; } lastC_BPartner_ID = detail.GetC_BPartner_ID(); lastC_BPartner_Location_ID = detail.GetC_BPartner_Location_ID(); // New Order if (order == null) { bp = new MBPartner(GetCtx(), detail.GetC_BPartner_ID(), Get_TrxName()); if (!_IsTest) { order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetC_DocTypeTarget_ID(_docType.GetC_DocType_ID()); order.SetIsReturnTrx(_docType.IsReturnTrx()); order.SetC_DocType_ID(_docType.GetC_DocType_ID()); order.SetIsSOTrx(_docType.IsSOTrx()); // Counter Doc if (counter && bp.GetAD_OrgBP_ID_Int() > 0) { log.Fine("Counter - From_BPOrg=" + bp.GetAD_OrgBP_ID_Int() + "-" + bp + ", To_BP=" + runBPartner); order.SetAD_Org_ID(bp.GetAD_OrgBP_ID_Int()); MOrgInfo oi = MOrgInfo.Get(GetCtx(), bp.GetAD_OrgBP_ID_Int(), null); if (oi.GetM_Warehouse_ID() > 0) { order.SetM_Warehouse_ID(oi.GetM_Warehouse_ID()); } order.SetBPartner(runBPartner); } else // normal { log.Fine("From_Org=" + runAD_Org_ID + ", To_BP=" + bp); order.SetAD_Org_ID(runAD_Org_ID); order.SetBPartner(bp); if (detail.GetC_BPartner_Location_ID() != 0) { order.SetC_BPartner_Location_ID(detail.GetC_BPartner_Location_ID()); } } order.SetDateOrdered(_DateOrdered); order.SetDatePromised(_DatePromised); if (!order.Save()) { log.Log(Level.SEVERE, "Order not saved"); return(false); } } } // Line if (product == null || product.GetM_Product_ID() != detail.GetM_Product_ID()) { product = MProduct.Get(GetCtx(), detail.GetM_Product_ID()); } if (_IsTest) { AddLog(0, null, detail.GetActualAllocation(), bp.GetName() + " - " + product.GetName()); continue; } // Create Order Line MOrderLine line = new MOrderLine(order); if (counter && bp.GetAD_OrgBP_ID_Int() > 0) { ; // don't overwrite counter doc } else // normal - optionally overwrite { line.SetC_BPartner_ID(detail.GetC_BPartner_ID()); if (detail.GetC_BPartner_Location_ID() != 0) { line.SetC_BPartner_Location_ID(detail.GetC_BPartner_Location_ID()); } } // line.SetProduct(product); line.SetQty(detail.GetActualAllocation()); line.SetPrice(); if (!line.Save()) { log.Log(Level.SEVERE, "OrderLine not saved"); return(false); } AddLog(0, null, detail.GetActualAllocation(), order.GetDocumentNo() + ": " + bp.GetName() + " - " + product.GetName()); } // finish order order = null; return(true); }