Ejemplo n.º 1
0
 /// <summary>
 /// Parent Constructor
 /// </summary>
 /// <param name="rfq">rfq</param>
 /// <param name="partner">web response</param>
 public MRfQResponse(MRfQ rfq, MBPartner partner)
     : this(rfq, null,
            partner.GetC_BPartner_ID(),
            partner.GetPrimaryC_BPartner_Location_ID(),
            partner.GetPrimaryAD_User_ID())
 {
 }
        /// <summary>
        /// Set Credit Status
        /// </summary>
        public void SetSOCreditStatus()
        {
            MBPartner bp          = new MBPartner(GetCtx(), GetC_BPartner_ID(), Get_TrxName());
            Decimal   creditLimit = GetSO_CreditLimit();

            //	Nothing to do
            if (SOCREDITSTATUS_NoCreditCheck.Equals(GetSOCreditStatus()) ||
                SOCREDITSTATUS_CreditStop.Equals(GetSOCreditStatus()) ||
                Env.ZERO.CompareTo(creditLimit) == 0)
            {
                return;
            }

            //	Above Credit Limit
            // changed this function for fetching open balance because in case of void it calculates again and fetches wrong value of open balance // Lokesh Chauhan
            //if (creditLimit.CompareTo(GetTotalOpenBalance(!_TotalOpenBalanceSet)) < 0)
            if (creditLimit.CompareTo(GetTotalOpenBalance()) <= 0)
            {
                SetSOCreditStatus(SOCREDITSTATUS_CreditHold);
            }
            else
            {
                //	Above Watch Limit
                Decimal watchAmt = Decimal.Multiply(creditLimit, bp.GetCreditWatchRatio());
                if (watchAmt.CompareTo(GetTotalOpenBalance()) < 0)
                {
                    SetSOCreditStatus(SOCREDITSTATUS_CreditWatch);
                }
                else    //	is OK
                {
                    SetSOCreditStatus(SOCREDITSTATUS_CreditOK);
                }
            }
            log.Fine("SOCreditStatus=" + GetSOCreditStatus());
        }
Ejemplo n.º 3
0
        /**
         *  Set Value Name Description
         *	@param Invoice
         *	@param line line
         *	@param deliveryCount
         */
        public void SetValueNameDescription(MInvoice invoice, MInvoiceLine line, int deliveryCount)
        {
            MProduct  product = line.GetProduct();
            MBPartner partner = new MBPartner(GetCtx(), invoice.GetC_BPartner_ID(), null);

            SetValueNameDescription(invoice, deliveryCount, product, partner);
        }
Ejemplo n.º 4
0
        /**
         *  Set Value Name Description
         *	@param shipment shipment
         *	@param line line
         *	@param deliveryCount
         */
        public void SetValueNameDescription(MInOut shipment, MInOutLine line, int deliveryCount)
        {
            MProduct  product = line.GetProduct();
            MBPartner partner = shipment.GetBPartner();

            SetValueNameDescription(shipment, deliveryCount, product, partner);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get/Create Entry for BPartner
        /// </summary>
        /// <param name="C_BPartner_ID">business partner</param>
        /// <param name="C_Currency_ID">currency</param>
        /// <param name="SalesRep_ID">sales rep</param>
        /// <returns>entry</returns>
        public MDunningRunEntry GetEntry(int C_BPartner_ID, int C_Currency_ID, int SalesRep_ID)
        {
            // TODO: Related BP
            int C_BPartnerRelated_ID = C_BPartner_ID;

            //
            GetEntries(false);
            for (int i = 0; i < _entries.Length; i++)
            {
                MDunningRunEntry entry = _entries[i];
                if (entry.GetC_BPartner_ID() == C_BPartnerRelated_ID)
                {
                    return(entry);
                }
            }
            //	New Entry
            MDunningRunEntry entry1 = new MDunningRunEntry(this);
            MBPartner        bp     = new MBPartner(GetCtx(), C_BPartnerRelated_ID, Get_TrxName());

            entry1.SetBPartner(bp, true);       //	AR hardcoded

            // Change by mohit -1st Priority given to the sales rep selected in process parameter and 2nd given to the sales rep on customer master..- 1 May 2019.
            if (SalesRep_ID > 0)
            {
                entry1.SetSalesRep_ID(SalesRep_ID);
            }
            entry1.SetC_Currency_ID(C_Currency_ID);
            //
            _entries = null;
            return(entry1);
        }
Ejemplo n.º 6
0
        /**
         *  Set Value, Name, Description
         *	@param invoice
         *	@param deliveryCount count
         *	@param product product
         *	@param partner partner
         */
        public void SetValueNameDescription(MInvoice invoice,
                                            int deliveryCount, MProduct product, MBPartner partner)
        {
            String documentNo = "_" + invoice.GetDocumentNo();

            if (deliveryCount > 1)
            {
                documentNo += "_" + deliveryCount;
            }
            //	Value
            String value = partner.GetValue() + "_" + product.GetValue();

            if (value.Length > 40 - documentNo.Length)
            {
                value = value.Substring(0, 40 - documentNo.Length) + documentNo;
            }
            // Change to set Value from Document Sequence
            // SetValue(value);

            // Change to set only name of product as value in Asset
            //	Name		MProduct.afterSave
            // String name = partner.GetName() + " - " + product.GetName();

            String name = product.GetName();

            if (name.Length > 60)
            {
                name = name.Substring(0, 60);
            }
            SetName(name);
            //	Description
            String description = product.GetDescription();

            SetDescription(description);
        }
Ejemplo n.º 7
0
 /**
  *  BP Parent Constructor
  *  @param bp partner
  */
 public MBPartnerLocation(MBPartner bp)
     : this(bp.GetCtx(), 0, bp.Get_TrxName())
 {
     SetClientOrg(bp);
     //	may (still) be 0
     Set_ValueNoCheck("C_BPartner_ID", (int)(bp.GetC_BPartner_ID()));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Get Cash Trx Business Partner
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="AD_Client_ID">client</param>
        /// <returns>Cash Trx Business Partner or null</returns>
        public static MBPartner GetBPartnerCashTrx(Ctx ctx, int AD_Client_ID)
        {
            MBPartner retValue = null;
            String    sql      = "SELECT * FROM C_BPartner "
                                 + " WHERE C_BPartner_ID IN (SELECT C_BPartnerCashTrx_ID FROM AD_ClientInfo" +
                                 " WHERE AD_Client_ID=" + AD_Client_ID + ")";
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    retValue = new MBPartner(ctx, dr, null);
                }
                if (dt == null)
                {
                    _log.Log(Level.SEVERE, "Not found for AD_Client_ID=" + AD_Client_ID);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally { dt = null; }
            return(retValue);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get Empty Template Business Partner
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="AD_Client_ID">client</param>
        /// <returns>Template Business Partner or null</returns>
        public static MBPartner GetTemplate(Ctx ctx, int AD_Client_ID)
        {
            MBPartner template = GetBPartnerCashTrx(ctx, AD_Client_ID);

            if (template == null)
            {
                template = new MBPartner(ctx, 0, null);
            }
            //	Reset
            if (template != null)
            {
                template.Set_ValueNoCheck("C_BPartner_ID", 0);
                template.SetValue("");
                template.SetName("");
                template.SetName2(null);
                template.SetDUNS("");
                template.SetFirstSale(null);
                //
                template.SetSO_CreditLimit(Env.ZERO);
                template.SetSO_CreditUsed(Env.ZERO);
                template.SetTotalOpenBalance(Env.ZERO);
                //	s_template.setRating(null);
                //
                template.SetActualLifeTimeValue(Env.ZERO);
                template.SetPotentialLifeTimeValue(Env.ZERO);
                template.SetAcqusitionCost(Env.ZERO);
                template.SetShareOfCustomer(0);
                template.SetSalesVolume(0);
            }
            return(template);
        }
        /// <summary>
        /// Get/Create Entry for BPartner
        /// </summary>
        /// <param name="C_BPartner_ID">business partner</param>
        /// <param name="C_Currency_ID">currency</param>
        /// <param name="SalesRep_ID">sales rep</param>
        /// <returns>entry</returns>
        public MDunningRunEntry GetEntry(int C_BPartner_ID, int C_Currency_ID, int SalesRep_ID)
        {
            // TODO: Related BP
            int C_BPartnerRelated_ID = C_BPartner_ID;

            //
            GetEntries(false);
            for (int i = 0; i < _entries.Length; i++)
            {
                MDunningRunEntry entry = _entries[i];
                if (entry.GetC_BPartner_ID() == C_BPartnerRelated_ID)
                {
                    return(entry);
                }
            }
            //	New Entry
            MDunningRunEntry entry1 = new MDunningRunEntry(this);
            MBPartner        bp     = new MBPartner(GetCtx(), C_BPartnerRelated_ID, Get_TrxName());

            entry1.SetBPartner(bp, true);       //	AR hardcoded
            //
            //if (entry1.GetSalesRep_ID() == 0)
            // Change done bu mohit to set sales rep selected.- 1 May 2019.
            if (SalesRep_ID > 0)
            {
                entry1.SetSalesRep_ID(SalesRep_ID);
            }
            entry1.SetC_Currency_ID(C_Currency_ID);
            //
            _entries = null;
            return(entry1);
        }
Ejemplo n.º 11
0
        /**
         *  After Save
         *	@param newRecord
         *	@param success
         *	@return success
         */
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }

            if (!UpdateCbAndLine())
            {
                return(false);
            }

            if (GetVSS_PAYMENTTYPE() == X_C_CashLine.VSS_PAYMENTTYPE_Payment && GetC_BPartner_ID() > 0)
            {
                MCash   csh = new MCash(GetCtx(), GetC_Cash_ID(), Get_TrxName());
                Decimal amt = MConversionRate.ConvertBase(GetCtx(), GetAmount(),        //	CM adjusted
                                                          GetC_Currency_ID(), csh.GetDateAcct(), 0, GetAD_Client_ID(), GetAD_Org_ID());

                MBPartner bp     = new MBPartner(GetCtx(), GetC_BPartner_ID(), Get_Trx());
                string    retMsg = "";
                bool      crdAll = bp.IsCreditAllowed(GetC_BPartner_Location_ID(), Decimal.Subtract(0, amt), out retMsg);
                if (!crdAll)
                {
                    log.SaveWarning("Warning", retMsg);
                }
                else if (bp.IsCreditWatch(GetC_BPartner_Location_ID()))
                {
                    log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "VIS_BPCreditWatch"));
                }
            }

            return(true);
        }
Ejemplo n.º 12
0
        public static bool GetIsEmployee(Ctx ctx, int AD_USER_ID)
        {
            MUser     user = MUser.Get(ctx, AD_USER_ID);
            MBPartner bp   = MBPartner.Get(ctx, user.GetC_BPartner_ID());

            user = null;
            if (bp == null)
            {
                return(false);
            }
            return(bp.IsEmployee());
        }
Ejemplo n.º 13
0
 /**
  *  Get BPartner
  *	@return bp or null
  */
 public MBPartner GetBPartner()
 {
     if (GetC_BPartner_ID() == 0)
     {
         _bp = null;
     }
     else if (_bp == null ||
              _bp.GetC_BPartner_ID() != GetC_BPartner_ID())
     {
         _bp = new MBPartner(GetCtx(), GetC_BPartner_ID(), Get_TrxName());
     }
     return(_bp);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Set Credit Status
        /// </summary>
        public void SetSOCreditStatus()
        {
            MBPartner bp          = new MBPartner(GetCtx(), GetC_BPartner_ID(), Get_TrxName());
            Decimal   creditLimit = GetSO_CreditLimit();

            //	Nothing to do
            if (SOCREDITSTATUS_NoCreditCheck.Equals(GetSOCreditStatus()) ||
                SOCREDITSTATUS_CreditStop.Equals(GetSOCreditStatus()) ||
                Env.ZERO.CompareTo(creditLimit) == 0)
            {
                return;
            }

            //	Above Credit Limit
            // changed this function for fetching open balance because in case of void it calculates again and fetches wrong value of open balance // Lokesh Chauhan
            //if (creditLimit.CompareTo(GetTotalOpenBalance(!_TotalOpenBalanceSet)) < 0)
            if (creditLimit.CompareTo(GetTotalOpenBalance()) <= 0)
            {
                SetSOCreditStatus(SOCREDITSTATUS_CreditHold);
            }
            else
            {
                //	Above Watch Limit
                //Peference check if credit watch per is zero on header then gets the value from bpgroup
                Decimal watchAmt;
                if (bp.Get_ColumnIndex("CreditWatchPercent") > 0)
                {
                    if (bp.GetCreditWatchPercent() == 0)
                    {
                        watchAmt = Decimal.Multiply(creditLimit, bp.GetCreditWatchRatio());
                    }
                    else
                    {
                        watchAmt = Decimal.Multiply(creditLimit, bp.GetCustomerCreditWatch());
                    }
                }
                else
                {
                    watchAmt = Decimal.Multiply(creditLimit, bp.GetCreditWatchRatio());
                }
                if (watchAmt.CompareTo(GetTotalOpenBalance()) < 0)
                {
                    SetSOCreditStatus(SOCREDITSTATUS_CreditWatch);
                }
                else    //	is OK
                {
                    SetSOCreditStatus(SOCREDITSTATUS_CreditOK);
                }
            }
            log.Fine("SOCreditStatus=" + GetSOCreditStatus());
        }
 /**
  *  Constructor
  *	@param ctx context
  *  @param bp BP
  *	@param bpc BP Contact
  *  @param location Location
  */
 public MBPBankAccount(Ctx ctx, MBPartner bp, MUser bpc, MLocation location)
     : this(ctx, 0, bp.Get_TrxName())
 {
     SetIsACH(false);
     //
     SetC_BPartner_ID(bp.GetC_BPartner_ID());
     //
     SetA_Name(bpc.GetName());
     SetA_EMail(bpc.GetEMail());
     //
     SetA_Street(location.GetAddress1());
     SetA_City(location.GetCity());
     SetA_Zip(location.GetPostal());
     SetA_State(location.GetRegionName(true));
     SetA_Country(location.GetCountryName());
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Get BPartner with Value
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="Value">value</param>
        /// <returns>BPartner or null</returns>
        public static MBPartner Get(Ctx ctx, String Value)
        {
            if (Value == null || Value.Length == 0)
            {
                return(null);
            }
            MBPartner retValue     = null;
            int       AD_Client_ID = ctx.GetAD_Client_ID();
            String    sql          = "SELECT * FROM C_BPartner WHERE Value=@Value"
                                     + " AND AD_Client_ID=" + AD_Client_ID;
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@Value", Value);
                idr      = DataBase.DB.ExecuteReader(sql, param, null);
                dt       = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    retValue = new MBPartner(ctx, dr, null);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                dt = null;
            }
            return(retValue);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Update Open Balance of BP's
        /// </summary>
        /// <param name="bps">list of business partners</param>
        private void UpdateBP(HashSet <int> bps)
        {
            log.Info("#" + bps.Count);
            IEnumerator <int> it = bps.GetEnumerator();

            it.Reset();
            while (it.MoveNext())
            {
                int       C_BPartner_ID = it.Current;
                MBPartner bp            = new MBPartner(GetCtx(), C_BPartner_ID, Get_TrxName());
                bp.SetTotalOpenBalance();               //	recalculates from scratch
                //	bp.setSOCreditStatus();			//	called automatically
                if (bp.Save())
                {
                    log.Fine(bp.ToString());
                }
                else
                {
                    log.Log(Level.SEVERE, "BP not updated - " + bp);
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Get BPartner with Value
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="C_BPartner_ID">id</param>
        /// <returns>BPartner or null</returns>
        public static MBPartner Get(Ctx ctx, int C_BPartner_ID)
        {
            MBPartner retValue     = null;
            int       AD_Client_ID = ctx.GetAD_Client_ID();
            String    sql          = "SELECT * FROM C_BPartner WHERE C_BPartner_ID=" + C_BPartner_ID
                                     + " AND  AD_Client_ID=" + AD_Client_ID;
            DataSet ds = new DataSet();

            try
            {
                ds = DataBase.DB.ExecuteDataset(sql, null, null);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    retValue = new MBPartner(ctx, dr, null);
                }
                ds = null;
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            return(retValue);
        }
Ejemplo n.º 19
0
        /**
         *  Create Trial Asset
         *	@param ctx context
         *	@param user user
         *	@param entityType entity type
         *	@return asset or null if no product found
         */
        public static MAsset GetTrial(Ctx ctx, MUser user, String entityType)
        {
            if (user == null)
            {
                _log.Warning("Cannot create Trial - No User");
                return(null);
            }
            if (Utility.Util.IsEmpty(entityType))
            {
                _log.Warning("Cannot create Trial - No Entity Type");
                return(null);
            }
            MProduct product = MProduct.GetTrial(ctx, entityType);

            if (product == null)
            {
                _log.Warning("No Trial for Entity Type=" + entityType);
                return(null);
            }
            //
            DateTime now = Convert.ToDateTime(CommonFunctions.CurrentTimeMillis());
            //
            MAsset asset = new MAsset(ctx, 0, null);

            asset.SetClientOrg(user);
            asset.SetAssetServiceDate(now);
            asset.SetIsOwned(false);
            asset.SetIsTrialPhase(true);
            //
            MBPartner partner    = new MBPartner(ctx, user.GetC_BPartner_ID(), null);
            String    documentNo = "Trial";
            //	Value
            String value = partner.GetValue() + "_" + product.GetValue();

            if (value.Length > 40 - documentNo.Length)
            {
                value = value.Substring(0, 40 - documentNo.Length) + documentNo;
            }
            asset.SetValue(value);
            //	Name		MProduct.afterSave
            String name = "Trial " + partner.GetName() + " - " + product.GetName();

            if (name.Length > 60)
            {
                name = name.Substring(0, 60);
            }
            asset.SetName(name);
            //	Description
            String description = product.GetDescription();

            asset.SetDescription(description);

            //	User
            asset.SetAD_User_ID(user.GetAD_User_ID());
            asset.SetC_BPartner_ID(user.GetC_BPartner_ID());
            //	Product
            asset.SetM_Product_ID(product.GetM_Product_ID());
            asset.SetA_Asset_Group_ID(product.GetA_Asset_Group_ID());
            asset.SetQty(new Decimal(product.GetSupportUnits()));
            //	Guarantee & Version
            asset.SetGuaranteeDate(TimeUtil.AddDays(now, product.GetTrialPhaseDays()));
            asset.SetVersionNo(product.GetVersionNo());
            //
            return(asset);
        }
Ejemplo n.º 20
0
        }       //	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
Ejemplo n.º 21
0
        /**
         *  Create BP, Contact, Location from Lead
         *	@return error message
         */
        public String CreateBP()
        {
            if (GetC_BPartner_ID() != 0 && GetAD_User_ID() != 0 && GetC_BPartner_Location_ID() == 0)
            {
                return("@AlreadyExists@: @C_BPartner_ID@ (ID=" + GetC_BPartner_ID() + ")");
            }

            //	BPartner
            if (GetC_BPartner_ID() == 0 &&
                (GetBPName() != null && GetBPName().Length > 0))
            {
                //	Existing User
                _user = GetUser();
                if (_user != null)
                {
                    if (_user.GetC_BPartner_ID() != 0)
                    {
                        SetRef_BPartner_ID(_user.GetC_BPartner_ID());
                        log.Info("Set to BPartner of User - " + _user);
                        return(CreateBPLocation());
                    }
                }
                //
                _bp = new MBPartner(GetCtx(), Get_TrxName());   //	Template
                _bp.SetAD_Org_ID(GetAD_Org_ID());
                //_bp.SetValue(GetBPName());
                _bp.SetName(GetBPName());
                _bp.SetIsCustomer(false);
                _bp.SetIsProspect(true);
                _bp.SetSOCreditStatus("O");
                // Check Removed as per Surya Sir's Decision BY Lokesh

                //_bp.SetC_Campaign_ID(GetC_Campaign_ID());
                //
                if (GetC_BP_Group_ID() == 0)
                {
                    // ShowMessage.Info("First Select Customer Group Then process again", true, null, null);
                    return(null);
                }
                else
                {
                    _bp.SetC_BP_Group_ID(GetC_BP_Group_ID());
                }
                MBPGroup gp = new MBPGroup(GetCtx(), GetC_BP_Group_ID(), Get_TrxName());
                _bp.SetM_PriceList_ID(gp.GetM_PriceList_ID());
                if (GetC_BP_Size_ID() != 0)
                {
                    _bp.SetC_BP_Size_ID(GetC_BP_Size_ID());
                }
                if (GetURL() != null)
                {
                    _bp.SetURL(GetURL());
                }
                if (GetC_BP_Status_ID() != 0)
                {
                    _bp.SetC_BP_Status_ID(GetC_BP_Status_ID());
                }
                if (GetC_IndustryCode_ID() != 0)
                {
                    _bp.SetC_IndustryCode_ID(GetC_IndustryCode_ID());
                }
                if (GetNAICS() != null)
                {
                    _bp.SetNAICS(GetNAICS());
                }
                if (GetDUNS() != null)
                {
                    _bp.SetDUNS(GetDUNS());
                }
                if (GetNumberEmployees() != 0)
                {
                    _bp.SetNumberEmployees(GetNumberEmployees());
                }
                if (GetSalesVolume() != 0)
                {
                    _bp.SetSalesVolume(GetSalesVolume());
                }
                if (GetSalesRep_ID() != 0)
                {
                    _bp.SetSalesRep_ID(GetSalesRep_ID());
                }
                if (GetC_Campaign_ID() != 0)
                {
                    _bp.SetC_Campaign_ID(GetC_Campaign_ID());
                }
                if (!_bp.Save())
                {
                    return("@SaveError@");
                }
                //	Update User
                if (_user != null && _user.GetC_BPartner_ID() == 0)
                {
                    _user.SetC_BPartner_ID(_bp.GetC_BPartner_ID());
                    _user.Save();
                }
                //	Save BP
                SetRef_BPartner_ID(_bp.GetC_BPartner_ID());
            }

            String error = CreateBPContact();

            if (error != null && error.Length > 0)
            {
                return(error);
            }
            CreateBPLocation();

            try
            {
                int    id    = _bp.GetC_BPartner_ID();
                string qry   = "Update c_bpartner set Description='' where c_bpartner_id=" + id;
                int    check = DB.ExecuteQuery(qry, null, Get_TrxName());
                string val   = _bp.GetValue();
                qry   = "Update c_bpartner set Value='" + val + GetBPName() + "' where c_bpartner_id=" + id;
                check = DB.ExecuteQuery(qry, null, Get_TrxName());

                if (GetR_InterestArea_ID() != 0)
                {
                    string      sql = "Select R_InterestArea_ID from vss_lead_interestarea where C_Lead_ID=" + GetC_Lead_ID();
                    IDataReader dr  = DB.ExecuteReader(sql, null, Get_TrxName());
                    while (dr.Read())
                    {
                        X_R_ContactInterest Prospect = new X_R_ContactInterest(GetCtx(), 0, Get_TrxName());
                        Prospect.SetR_InterestArea_ID(Util.GetValueOfInt(dr[0]));
                        Prospect.SetC_BPartner_ID(GetRef_BPartner_ID());
                        String query  = "Select ad_user_id from ad_user where c_bpartner_id= " + GetRef_BPartner_ID();
                        int    UserId = Util.GetValueOfInt(DB.ExecuteScalar(query, null, Get_TrxName()));
                        Prospect.SetAD_User_ID(UserId);
                        query = "Select C_BPartner_Location_id from C_BPartner_Location where c_bpartner_id= " + GetRef_BPartner_ID();

                        int Id = Util.GetValueOfInt(DB.ExecuteScalar(query, null, Get_TrxName()));
                        X_C_BPartner_Location loc = new X_C_BPartner_Location(GetCtx(), Id, Get_TrxName());
                        Prospect.SetC_BPartner_Location_ID(Id);
                        Prospect.SetPhone(loc.GetPhone());
                        Prospect.SetFax(loc.GetFax());

                        X_AD_User us = new X_AD_User(GetCtx(), UserId, Get_TrxName());
                        Prospect.SetC_Job_ID(us.GetC_Job_ID());
                        Prospect.SetSubscribeDate(DateTime.Today);
                        query = "Select Email from ad_user where ad_user_id= " + UserId;
                        String mail = Util.GetValueOfString(DB.ExecuteScalar(query, null, Get_TrxName()));
                        Prospect.SetEMail(mail);
                        if (Prospect.Save())
                        {
                        }
                    }
                    dr.Close();
                }
            }
            catch
            {
            }

            return(null);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Set BPartner
        /// </summary>
        /// <param name="bp">partner</param>
        /// <param name="isSOTrx">SO</param>
        public void SetBPartner(MBPartner bp, bool isSOTrx)
        {
            SetC_BPartner_ID(bp.GetC_BPartner_ID());
            MBPartnerLocation[] locations = bp.GetLocations(false);
            //	Location
            if (locations.Length == 1)
            {
                SetC_BPartner_Location_ID(locations[0].GetC_BPartner_Location_ID());
            }
            else
            {
                for (int i = 0; i < locations.Length; i++)
                {
                    MBPartnerLocation location = locations[i];
                    if (!location.IsActive())
                    {
                        continue;
                    }
                    if ((location.IsPayFrom() && isSOTrx) ||
                        (location.IsRemitTo() && !isSOTrx))
                    {
                        SetC_BPartner_Location_ID(location.GetC_BPartner_Location_ID());
                        break;
                    }
                }
            }
            if (GetC_BPartner_Location_ID() == 0)
            {
                String msg = "@C_BPartner_ID@ " + bp.GetName();
                if (isSOTrx)
                {
                    msg += " @No@ @IsPayFrom@";
                }
                else
                {
                    msg += " @No@ @IsRemitTo@";
                }
                throw new ArgumentException(msg);
            }
            //	User with location
            MUser[] users = MUser.GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID());
            if (users.Length == 1)
            {
                SetAD_User_ID(users[0].GetAD_User_ID());
            }
            else
            {
                for (int i = 0; i < users.Length; i++)
                {
                    MUser user = users[i];
                    if (user.GetC_BPartner_Location_ID() == GetC_BPartner_Location_ID())
                    {
                        SetAD_User_ID(users[i].GetAD_User_ID());
                        break;
                    }
                }
            }
            //
            int SalesRep_ID = bp.GetSalesRep_ID();

            if (SalesRep_ID != 0)
            {
                SetSalesRep_ID(SalesRep_ID);
            }
        }
Ejemplo n.º 23
0
 public void SetBPartner(int C_BPartner_ID)
 {
     _bpartner = new MBPartner(GetCtx(), C_BPartner_ID, Get_TrxName());
 }
Ejemplo n.º 24
0
        /**
         *  Complete Document
         *  @return new status (Complete, In Progress, Invalid, Waiting ..)
         */
        public String CompleteIt()
        {
            //	Re-Check
            if (!_justPrepared)
            {
                String status = PrepareIt();
                if (!DocActionVariables.STATUS_INPROGRESS.Equals(status))
                {
                    return(status);
                }
            }
            //	Implicit Approval
            if (!IsApproved())
            {
                ApproveIt();
            }
            //
            log.Info(ToString());

            //	Allocation Header
            MAllocationHdr alloc = new MAllocationHdr(GetCtx(), false,
                                                      GetDateAcct(), GetC_Currency_ID(),
                                                      Msg.Translate(GetCtx(), "C_Cash_ID") + ": " + GetName(), Get_TrxName());

            alloc.SetAD_Org_ID(GetAD_Org_ID());
            if (!alloc.Save())
            {
                _processMsg = "Could not create Allocation Hdr";
                return(DocActionVariables.STATUS_INVALID);
            }
            //
            MCashLine[] lines = GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MCashLine line = lines[i];

                if (Util.GetValueOfInt(line.GetC_InvoicePaySchedule_ID()) != 0)
                {
                    MInvoicePaySchedule paySch = new MInvoicePaySchedule(GetCtx(), Util.GetValueOfInt(line.GetC_InvoicePaySchedule_ID()), Get_TrxName());
                    paySch.SetC_CashLine_ID(line.GetC_CashLine_ID());
                    paySch.Save();
                }
                else
                {
                    int[] InvoicePaySchedule_ID = MInvoicePaySchedule.GetAllIDs("C_InvoicePaySchedule", "C_Invoice_ID = " + line.GetC_Invoice_ID() + @" AND C_InvoicePaySchedule_ID NOT IN 
                    (SELECT NVL(C_InvoicePaySchedule_ID,0) FROM C_InvoicePaySchedule WHERE C_Payment_ID IN (SELECT NVL(C_Payment_ID,0) FROM C_InvoicePaySchedule) UNION 
                    SELECT NVL(C_InvoicePaySchedule_ID,0) FROM C_InvoicePaySchedule  WHERE C_Cashline_ID IN (SELECT NVL(C_Cashline_ID,0) FROM C_InvoicePaySchedule))", Get_TrxName());

                    foreach (int invocePay in InvoicePaySchedule_ID)
                    {
                        MInvoicePaySchedule paySch = new MInvoicePaySchedule(GetCtx(), invocePay, Get_TrxName());
                        paySch.SetC_CashLine_ID(line.GetC_CashLine_ID());
                        paySch.Save();
                    }
                }

                if (MCashLine.CASHTYPE_Invoice.Equals(line.GetCashType()))
                {
                    bool           differentCurrency = GetC_Currency_ID() != line.GetC_Currency_ID();
                    MAllocationHdr hdr = alloc;
                    if (differentCurrency)
                    {
                        hdr = new MAllocationHdr(GetCtx(), false,
                                                 GetDateAcct(), line.GetC_Currency_ID(),
                                                 Msg.Translate(GetCtx(), "C_Cash_ID") + ": " + GetName(), Get_TrxName());
                        hdr.SetAD_Org_ID(GetAD_Org_ID());
                        if (!hdr.Save())
                        {
                            _processMsg = "Could not create Allocation Hdr";
                            return(DocActionVariables.STATUS_INVALID);
                        }
                    }
                    //	Allocation Line
                    MAllocationLine aLine = new MAllocationLine(hdr, line.GetAmount(),
                                                                line.GetDiscountAmt(), line.GetWriteOffAmt(), line.GetOverUnderAmt());
                    aLine.SetC_Invoice_ID(line.GetC_Invoice_ID());
                    aLine.SetC_CashLine_ID(line.GetC_CashLine_ID());
                    if (!aLine.Save())
                    {
                        _processMsg = "Could not create Allocation Line";
                        return(DocActionVariables.STATUS_INVALID);
                    }
                    if (differentCurrency)
                    {
                        //	Should start WF
                        hdr.ProcessIt(DocActionVariables.ACTION_COMPLETE);
                        hdr.Save();
                    }
                }
                else if (MCashLine.CASHTYPE_BankAccountTransfer.Equals(line.GetCashType()))
                {
                    //	Payment just as intermediate info
                    MPayment pay = new MPayment(GetCtx(), 0, Get_TrxName());
                    pay.SetAD_Org_ID(GetAD_Org_ID());
                    String documentNo = GetName();
                    pay.SetDocumentNo(documentNo);
                    pay.SetR_PnRef(documentNo);
                    pay.Set_Value("TrxType", "X");              //	Transfer
                    pay.Set_Value("TenderType", "X");
                    //
                    pay.SetC_BankAccount_ID(line.GetC_BankAccount_ID());
                    pay.SetC_DocType_ID(true);  //	Receipt
                    pay.SetDateTrx(GetStatementDate());
                    pay.SetDateAcct(GetDateAcct());
                    pay.SetAmount(line.GetC_Currency_ID(), Decimal.Negate(line.GetAmount()));   //	Transfer
                    pay.SetDescription(line.GetDescription());
                    pay.SetDocStatus(MPayment.DOCSTATUS_Closed);
                    pay.SetDocAction(MPayment.DOCACTION_None);
                    pay.SetPosted(true);
                    pay.SetIsAllocated(true);   //	Has No Allocation!
                    pay.SetProcessed(true);
                    if (!pay.Save())
                    {
                        _processMsg = "Could not create Payment";
                        return(DocActionVariables.STATUS_INVALID);
                    }
                }
                // Added to Update Open Balance of Business Partner
                else if (MCashLine.CASHTYPE_BusinessPartner.Equals(line.GetCashType()))
                {
                    if (line.GetC_BPartner_ID() != 0)
                    {
                        Decimal?  UpdatedBal = 0;
                        MBPartner bp         = new MBPartner(GetCtx(), line.GetC_BPartner_ID(), Get_TrxName());

                        Decimal?cashAmt = VAdvantage.Model.MConversionRate.ConvertBase(GetCtx(), Decimal.Add(Decimal.Add(line.GetAmount(), line.GetDiscountAmt()), line.GetWriteOffAmt()),
                                                                                       GetC_Currency_ID(), GetDateAcct(), 0, GetAD_Client_ID(), GetAD_Org_ID());
                        if (cashAmt > 0)
                        {
                            UpdatedBal = Decimal.Subtract((Decimal)bp.GetTotalOpenBalance(), (Decimal)cashAmt);

                            Decimal?newCreditAmt = bp.GetSO_CreditUsed();
                            if (newCreditAmt == null)
                            {
                                newCreditAmt = Decimal.Negate((Decimal)cashAmt);
                            }
                            else
                            {
                                newCreditAmt = Decimal.Subtract((Decimal)newCreditAmt, (Decimal)cashAmt);
                            }
                            //
                            log.Fine("TotalOpenBalance=" + bp.GetTotalOpenBalance(false) + "(" + cashAmt
                                     + ", Credit=" + bp.GetSO_CreditUsed() + "->" + newCreditAmt
                                     + ", Balance=" + bp.GetTotalOpenBalance(false) + " -> " + UpdatedBal);
                            bp.SetSO_CreditUsed((Decimal)newCreditAmt);
                        }
                        else
                        {
                            UpdatedBal = Decimal.Subtract((Decimal)bp.GetTotalOpenBalance(), (Decimal)cashAmt);
                            log.Fine("Payment Amount =" + line.GetAmount() + "(" + cashAmt
                                     + ") Balance=" + bp.GetTotalOpenBalance(false) + " -> " + UpdatedBal);
                        }
                        bp.SetTotalOpenBalance(Convert.ToDecimal(UpdatedBal));
                        bp.SetSOCreditStatus();
                        if (!bp.Save(Get_TrxName()))
                        {
                            _processMsg = "Could not update Business Partner";
                            return(DocActionVariables.STATUS_INVALID);
                        }
                    }
                }
            }
            //	Should start WF
            alloc.ProcessIt(DocActionVariables.ACTION_COMPLETE);
            alloc.Save();

            //	User Validation
            String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE);

            if (valid != null)
            {
                _processMsg = valid;
                return(DocActionVariables.STATUS_INVALID);
            }
            //
            SetProcessed(true);
            SetDocAction(DOCACTION_Close);
            if (!UpdateCompletedBalance())
            {
                _processMsg = "Could not update Header";
                return(VAdvantage.Process.DocActionVariables.STATUS_INVALID);
            }

            return(VAdvantage.Process.DocActionVariables.STATUS_COMPLETED);
        }
Ejemplo n.º 25
0
 public void SetBPartner(MBPartner bpartner)
 {
     _bpartner = bpartner;
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Set BPartner
        /// </summary>
        /// <param name="bp">partner</param>
        /// <param name="isSOTrx">SO</param>
        public void SetBPartner(MBPartner bp, bool isSOTrx)
        {
            SetC_BPartner_ID(bp.GetC_BPartner_ID());
            MBPartnerLocation[] locations = GetLocations();
            //	Location

            for (int i = 0; i < locations.Length; i++)
            {
                MBPartnerLocation location = locations[i];
                if (!location.IsActive())
                {
                    continue;
                }
                if ((location.IsPayFrom() && isSOTrx) ||
                    (location.IsRemitTo() && !isSOTrx))
                {
                    SetC_BPartner_Location_ID(location.GetC_BPartner_Location_ID());
                    break;
                }
            }
            //}
            if (GetC_BPartner_Location_ID() == 0)
            {
                String msg = "@C_BPartner_ID@ " + bp.GetName();
                if (isSOTrx)
                {
                    msg += " @No@ @IsPayFrom@";
                }
                else
                {
                    msg += " @No@ @IsRemitTo@";
                }
                //throw new ArgumentException(msg);
                log.SaveInfo("", msg);
                return;
            }

            //	User with location
            // Change done by mohit to pick users sorted by date updated. 7 May 2019.
            MUser[] users = GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID());
            if (users.Length == 1)
            {
                if (users[0].IsEmail() || users[0].GetNotificationType() == MUser.NOTIFICATIONTYPE_EMail ||
                    users[0].GetNotificationType() == MUser.NOTIFICATIONTYPE_EMailPlusNotice || users[0].GetNotificationType() == MUser.NOTIFICATIONTYPE_EMailPlusFaxEMail)
                {
                    SetAD_User_ID(users[0].GetAD_User_ID());
                }
            }
            else
            {
                for (int i = 0; i < users.Length; i++)
                {
                    MUser user = users[i];
                    if (user.GetC_BPartner_Location_ID() == GetC_BPartner_Location_ID() && (user.IsEmail() || user.GetNotificationType() == MUser.NOTIFICATIONTYPE_EMail ||
                                                                                            user.GetNotificationType() == MUser.NOTIFICATIONTYPE_EMailPlusNotice || user.GetNotificationType() == MUser.NOTIFICATIONTYPE_EMailPlusFaxEMail))
                    {
                        SetAD_User_ID(users[i].GetAD_User_ID());
                        break;
                    }
                }
            }
            //
            int SalesRep_ID = bp.GetSalesRep_ID();

            if (SalesRep_ID != 0)
            {
                SetSalesRep_ID(SalesRep_ID);
            }
        }