Esempio n. 1
0
        /**
         *  Create Request from Lead
         *  @param R_RequestType_ID request type
         *	@return error message
         */
        private String CreateRequest(int R_RequestType_ID)
        {
            if (GetR_Request_ID() != 0)
            {
                return("@AlreadyExists@: @R_Request_ID@ (ID=" + GetR_Request_ID() + ")");
            }
            if (GetC_BPartner_ID() == 0)
            {
                String retValue = CreateBP();
                if (retValue != null)
                {
                    return(retValue);
                }
            }
            _request = new MRequest(GetCtx(), 0, Get_TrxName());
            _request.SetAD_Org_ID(GetAD_Org_ID());
            String summary = GetName();

            if (summary == null)
            {
                summary = GetHelp();
            }
            if (summary == null)
            {
                summary = GetSummary();
            }
            if (summary == null)
            {
                summary = GetDescription();
            }
            _request.SetSummary(summary);
            //
            _request.SetR_RequestType_ID(R_RequestType_ID);
            if (IsR_Status_IDValid(GetR_Status_ID()))
            {
                _request.SetR_Status_ID(GetR_Status_ID());
            }
            else
            {
                _request.SetR_Status_ID();
            }
            //
            _request.SetC_Lead_ID(GetC_Lead_ID());
            //
            _request.SetC_BPartner_ID(GetC_BPartner_ID());
            _request.SetAD_User_ID(GetAD_User_ID());
            _request.SetC_Project_ID(GetC_Project_ID());
            _request.SetC_Campaign_ID(GetC_Campaign_ID());
            _request.SetR_Source_ID(GetR_Source_ID());
            _request.SetC_BPartnerSR_ID(GetC_BPartnerSR_ID());
            _request.SetC_SalesRegion_ID(GetC_SalesRegion_ID());

            _request.SetSalesRep_ID(GetSalesRep_ID());
            if (!_request.Save())
            {
                return("@SaveError@");
            }
            //
            SetR_Request_ID(_request.GetR_Request_ID());
            return(null);
        }
        }   //  processEMail

        private void FindSalesRep()
        {
            int changed  = 0;
            int notFound = 0;
            Ctx ctx      = new Ctx();
            //
            String sql = "SELECT * FROM R_Request "
                         + "WHERE AD_Client_ID=@AD_Client_ID"
                         + " AND SalesRep_ID=0 AND Processed='N'";

            if (m_model.GetR_RequestType_ID() != 0)
            {
                sql += " AND R_RequestType_ID=@R_RequestType_ID";
            }

            try
            {
                SqlParameter[] param = null;

                if (m_model.GetR_RequestType_ID() != 0)
                {
                    param = new SqlParameter[2];
                }
                else
                {
                    param = new SqlParameter[1];
                }

                param[0] = new SqlParameter("@AD_Client_ID", m_model.GetAD_Client_ID());
                if (m_model.GetR_RequestType_ID() != 0)
                {
                    param[1] = new SqlParameter("@AD_Client_ID", m_model.GetR_RequestType_ID());
                }

                DataSet ds = DB.ExecuteDataset(sql, param);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    MRequest request = new MRequest(ctx, dr, null);
                    if (request.GetSalesRep_ID() != 0)
                    {
                        continue;
                    }
                    int SalesRep_ID = FindSalesRep(request);
                    if (SalesRep_ID != 0)
                    {
                        request.SetSalesRep_ID(SalesRep_ID);
                        request.Save();
                        changed++;
                    }
                    else
                    {
                        notFound++;
                    }
                }
            }
            catch (SqlException ex)
            {
                log.Log(Level.SEVERE, sql, ex);
            }
            //
            if ((changed == 0) && (notFound == 0))
            {
                m_summary.Append("No unallocated Requests");
            }
            else
            {
                m_summary.Append("Allocated SalesRep=").Append(changed);
            }
            if (notFound > 0)
            {
                m_summary.Append(",Not=").Append(notFound);
            }
            m_summary.Append(" - ");
        }       //	findSalesRep