Exemple #1
0
        public JsonResult PostImmediate(int AD_Client_ID, int AD_Table_ID, int Record_ID, bool force)
        {
            Ctx    ctx = Session["ctx"] as Ctx;
            string res = "";

            try
            {
                string clientName = ctx.GetAD_Org_Name() + "_" + ctx.GetAD_User_Name();
                string storedPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "");
                storedPath += clientName;
                VLogMgt.Initialize(true, storedPath);


                MAcctSchema[] ass = MAcctSchema.GetClientAcctSchema(ctx, AD_Client_ID);
                res = Doc.PostImmediate(ass, AD_Table_ID, Record_ID, force, null);
                if (res == null || res.Trim().Length > 0)
                {
                    res = "OK";
                }
            }
            catch (Exception ex)
            {
                res += ex.Message;
            }
            return(Json(new { result = res }, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        /// <summary>
        /// Work
        /// </summary>
        protected override void DoWork()
        {
            _summary = new StringBuilder();
            //	Get Schemata
            if (_modelLocal.GetC_AcctSchema_ID() == 0)
            {
                _ass = MAcctSchema.GetClientAcctSchema(GetCtx(), _modelLocal.GetAD_Client_ID());
            }
            else        //	only specific accounting schema
            {
                _ass = new MAcctSchema[] { new MAcctSchema(GetCtx(), _modelLocal.GetC_AcctSchema_ID(), null) };
            }
            //
            PostSession();
            MCost.Create(_clientLocal);
            //
            int no = _modelLocal.DeleteLog();

            _summary.Append("Logs deleted=").Append(no);
            //
            MAcctProcessorLog pLog = new MAcctProcessorLog(_modelLocal, _summary.ToString());

            pLog.SetReference("#" + Utility.Util.GetValueOfString(_runCount) // String.valueOf(p_runCount)
                              + " - " + TimeUtil.FormatElapsed(_startWork)); //new DateTime(_startWork)));
            pLog.Save();
        }
Exemple #3
0
        /// <summary>
        /// Process
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            log.Info("M_Product_Category_ID=" + _M_Product_Category_ID
                     + ", Future=" + _SetFutureCostTo
                     + ", Standard=" + _SetStandardCostTo
                     + "; M_PriceList_Version_ID=" + _M_PriceList_Version_ID);
            if (_SetFutureCostTo == null)
            {
                _SetFutureCostTo = "";
            }
            if (_SetStandardCostTo == null)
            {
                _SetStandardCostTo = "";
            }
            //	Nothing to Do
            if (_SetFutureCostTo.Length == 0 && _SetStandardCostTo.Length == 0)
            {
                return("-");
            }
            //	PLV required
            if (_M_PriceList_Version_ID == 0 &&
                (_SetFutureCostTo.Equals(TO_PriceListLimit) || _SetStandardCostTo.Equals(TO_PriceListLimit)))
            {
                throw new Exception("@FillMandatory@  @M_PriceList_Version_ID@");
            }

            //	Validate Source
            if (!IsValid(_SetFutureCostTo))
            {
                throw new Exception("@NotFound@ @M_CostElement_ID@ (Future) " + _SetFutureCostTo);
            }
            if (!IsValid(_SetStandardCostTo))
            {
                throw new Exception("@NotFound@ @M_CostElement_ID@ (Standard) " + _SetStandardCostTo);
            }

            //	Prepare
            MClient client = MClient.Get(GetCtx());

            _ce = MCostElement.GetMaterialCostElement(client, MAcctSchema.COSTINGMETHOD_StandardCosting);
            if (_ce.Get_ID() == 0)
            {
                throw new Exception("@NotFound@ @M_CostElement_ID@ (StdCost)");
            }
            log.Config(_ce.ToString());
            _ass = MAcctSchema.GetClientAcctSchema(GetCtx(), client.GetAD_Client_ID());
            for (int i = 0; i < _ass.Length; i++)
            {
                CreateNew(_ass[i]);
            }
            Commit();

            //	Update Cost
            int counter = Update();

            return("#" + counter);
        }
        /// <summary>
        /// Post Immediate
        /// @ejb.interface-method view-type="both"
        /// </summary>
        /// <param name="ctx">Client Context</param>
        /// <param name="AD_Client_ID">Client ID of Document</param>
        /// <param name="AD_Table_ID">Table ID of Document</param>
        /// <param name="Record_ID">Record ID of this document</param>
        /// <param name="force">force posting</param>
        /// <param name="trxName">transaction</param>
        /// <returns>null, if success or error message</returns>
        public String PostImmediate(IDictionary <string, string> ctxDic, int AD_Client_ID, int AD_Table_ID, int Record_ID, bool force, Trx trxName)
        {
            //log.Info("[" + _no + "] Table=" + AD_Table_ID + ", Record=" + Record_ID);
            //_postCount++;
            Ctx ctx = new Ctx(ctxDic);

            MAcctSchema[] ass = MAcctSchema.GetClientAcctSchema(ctx, AD_Client_ID);
            return(Doc.PostImmediate(ass, AD_Table_ID, Record_ID, force, trxName));
        }
        /**
         *  Update Balance of Client
         *	@param ctx context
         *	@param deleteFirst delete first
         *  @param dateFrom null for all or first date to delete/calculate
         *  @param trx transaction
         *  @param svrPrc optional server process
         *	@return Info
         */
        public static String UpdateBalanceClient(Ctx ctx,
                                                 DateTime?dateFrom, Trx trx, int Fact_Accumulation_ID, SvrProcess svrPrc)
        {
            int           AD_Client_ID = ctx.GetAD_Client_ID();
            StringBuilder Info         = new StringBuilder();

            MAcctSchema[] ass = MAcctSchema.GetClientAcctSchema(ctx, AD_Client_ID);
            foreach (MAcctSchema as1 in ass)
            {
                if (Info.Length > 0)
                {
                    Info.Append(" - ");
                }
                String msg = UpdateBalance(ctx, as1.GetC_AcctSchema_ID(),
                                           dateFrom, trx, Fact_Accumulation_ID, svrPrc);
                Info.Append(as1.GetName()).Append(":").Append(msg);
            }
            return(Info.ToString());
        }
Exemple #6
0
        /**
         *  After Save
         *	@param newRecord new
         *	@param success success
         *	@return success
         */
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }
            VAdvantage.Model.MProduct current = new VAdvantage.Model.MProduct(GetCtx(), GetM_Product_ID(), Get_Trx());
            StringBuilder             _sql    = new StringBuilder("");

            //_sql.Append("Select count(*) from  ad_table where tablename like 'FRPT_Product_Category_Acct'");
            _sql.Append("SELECT count(*) FROM all_objects WHERE object_type IN ('TABLE') AND (object_name)  = UPPER('FRPT_Product_Category_Acct')  AND OWNER LIKE '" + DB.GetSchema() + "'");
            int count = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));

            if (count > 0)
            {
                PO obj = null;
                //MFRPTProductAcct obj = null;
                int    _MProduct_ID  = GetM_Product_ID();
                int    _PCategory_ID = GetM_Product_Category_ID();
                string sql           = "SELECT L.VALUE FROM AD_REF_LIST L inner join AD_Reference r on R.AD_REFERENCE_ID=L.AD_REFERENCE_ID where   r.name='FRPT_RelatedTo' and l.name='Product'";
                //"select VALUE from AD_Ref_List where name='Product'";
                string _RelatedToProduct = Convert.ToString(DB.ExecuteScalar(sql));
                //string _RelatedToProduct = X_FRPT_AcctDefault.FRPT_RELATEDTO_Product.ToString();

                _sql.Clear();
                _sql.Append("Select Count(*) From FRPT_Product_Acct  where M_Product_ID=" + _MProduct_ID + " AND IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID());
                int value = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));
                if (value < 1)
                {
                    _sql.Clear();
                    _sql.Append("Select  PCA.c_acctschema_id, PCA.c_validcombination_id, PCA.frpt_acctdefault_id From FRPT_product_category_acct PCA inner join frpt_acctdefault ACC ON acc.frpt_acctdefault_id= PCA.frpt_acctdefault_id where PCA.m_product_category_id=" + _PCategory_ID + " and acc.frpt_relatedto=" + _RelatedToProduct + " AND PCA.IsActive = 'Y' AND PCA.AD_Client_ID = " + GetAD_Client_ID());
                    //_sql.Append("Select C_AcctSchema_ID, C_ValidCombination_ID, FRPT_AcctDefault_ID from FRPT_product_category_acct where m_product_category_id =" + _PCategory_ID);

                    DataSet ds = DB.ExecuteDataset(_sql.ToString());
                    if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            //obj = new MFRPTProductAcct(GetCtx(), 0, null);
                            obj = MTable.GetPO(GetCtx(), "FRPT_Product_Acct", 0, null);
                            obj.Set_ValueNoCheck("AD_Org_ID", 0);
                            obj.Set_ValueNoCheck("M_Product_ID", _MProduct_ID);
                            obj.Set_ValueNoCheck("C_AcctSchema_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_AcctSchema_ID"]));
                            obj.Set_ValueNoCheck("C_ValidCombination_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_ValidCombination_ID"]));
                            obj.Set_ValueNoCheck("FRPT_AcctDefault_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["FRPT_AcctDefault_ID"]));
                            if (!obj.Save())
                            {
                            }
                        }
                    }
                }
                // Change by mohit amortization process
                //int _CountVA038 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA038_'  AND IsActive = 'Y'"));
                //if (_CountVA038 > 0)
                //{
                //    if (GetProductType() == "E" || GetProductType() == "S")
                //    {
                //        if (Util.GetValueOfInt(Get_Value("VA038_AmortizationTemplate_ID")) > 0)
                //        {
                //            DataSet _dsAcct = DB.ExecuteDataset("SELECT C_AcctSchema_ID, FRPT_AcctDefault_ID, C_VALIDCOMBINATION_ID, SEQNO FROM VA038_Amortization_Acct "
                //                              + "WHERE IsActive='Y' AND  VA038_AmortizationTemplate_ID=" + Util.GetValueOfInt(Get_Value("VA038_AmortizationTemplate_ID")));
                //            if (_dsAcct != null && _dsAcct.Tables[0].Rows.Count > 0)
                //            {
                //                for (int j = 0; j < _dsAcct.Tables[0].Rows.Count; j++)
                //                {
                //                    obj = MTable.GetPO(GetCtx(), "FRPT_Product_Acct", 0, null);
                //                    obj.Set_ValueNoCheck("AD_Org_ID", 0);
                //                    obj.Set_ValueNoCheck("M_Product_ID", _MProduct_ID);
                //                    obj.Set_ValueNoCheck("C_AcctSchema_ID", Util.GetValueOfInt(_dsAcct.Tables[0].Rows[j]["C_AcctSchema_ID"]));
                //                    obj.Set_ValueNoCheck("C_ValidCombination_ID", Util.GetValueOfInt(_dsAcct.Tables[0].Rows[j]["C_ValidCombination_ID"]));
                //                    obj.Set_ValueNoCheck("FRPT_AcctDefault_ID", Util.GetValueOfInt(_dsAcct.Tables[0].Rows[j]["FRPT_AcctDefault_ID"]));
                //                    if (!obj.Save())
                //                    { }
                //                }
                //            }
                //        }
                //    }
                //}
                // End amortization process
            }
            else
            {
                // By Amit
                //if (!success)
                //    return success;

                //	Value/Name change in Account
                if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name")))
                {
                    MAccount.UpdateValueDescription(GetCtx(), "M_Product_ID=" + GetM_Product_ID(), Get_TrxName());
                }

                //	Name/Description Change in Asset	MAsset.setValueNameDescription
                if (!newRecord && (Is_ValueChanged("Name") || Is_ValueChanged("Description")))
                {
                    String sql = " UPDATE A_Asset a SET Name=(SELECT SUBSTR(bp.Name || ' - ' || p.Name,1,60) FROM M_Product p, C_BPartner bp  WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID)," +
                                 "Description=(SELECT  p.Description FROM M_Product p, C_BPartner bp WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID)" +
                                 "WHERE IsActive='Y'  AND M_Product_ID=" + GetM_Product_ID();

                    int no = 0;
                    try
                    {
                        no = Util.GetValueOfInt(DB.ExecuteQuery(sql, null, Get_TrxName()));
                    }
                    catch { }
                    log.Fine("Asset Description updated #" + no);
                }
                //	New - Acct, Tree, Old Costing
                if (newRecord)
                {
                    if (String.IsNullOrEmpty(GetCtx().GetContext("#DEFAULT_ACCOUNTING_APPLICABLE")) || Util.GetValueOfString(GetCtx().GetContext("#DEFAULT_ACCOUNTING_APPLICABLE")) == "Y")
                    {
                        bool sucs = Insert_Accounting("M_Product_Acct", "M_Product_Category_Acct",
                                                      "p.M_Product_Category_ID=" + GetM_Product_Category_ID());

                        //Karan. work done to show message if data not saved in accounting tab. but will save data in current tab.
                        // Before this, data was being saved but giving message "record not saved".
                        if (!sucs)
                        {
                            log.SaveWarning("AcctNotSaved", "");
                        }
                    }

                    //
                    MAcctSchema[] mass = MAcctSchema.GetClientAcctSchema(GetCtx(), GetAD_Client_ID(), Get_TrxName());
                    for (int i = 0; i < mass.Length; i++)
                    {
                        //	Old
                        MProductCosting pcOld = new MProductCosting(current, mass[i].GetC_AcctSchema_ID());
                        pcOld.Save();
                    }
                }
                //	New Costing
                // by Amit 22-12-2015
                //if (newRecord || Is_ValueChanged("M_Product_Category_ID"))
                //{
                //    MCost.Create(this);
                //}
            }

            //22-12-2015
            //by Amit for creating records ffor product foe all Costing Element whose costing elemnt type is 'Material'
            if (newRecord || Is_ValueChanged("M_Product_Category_ID"))
            {
                MCost.CreateRecords(current);
            }
            //20-12-2016
            //By Vivek Chauhan saving Nutrition value against product...........
            object ModuleId = DB.ExecuteScalar("select ad_moduleinfo_id from ad_moduleinfo where prefix='VA019_' and isactive='Y'");

            if (ModuleId != null && ModuleId != DBNull.Value)
            {
                object objNDBNo = DB.ExecuteScalar("select va019_ndbno from M_Product where m_product_ID=" + GetM_Product_ID() + "");
                if (objNDBNo != null && objNDBNo != DBNull.Value)
                {
                    CallNutritionApi(Convert.ToString(objNDBNo), GetM_Product_ID());
                }
            }

            if (Is_Changed())
            {
                string updatequery = "Update M_Product set GMT01_IsSpoorPosted='N' Where M_Product_ID=" + GetM_Product_ID();
                int    no          = DB.ExecuteQuery(updatequery);
            }

            return(success);
        }
Exemple #7
0
        /// <summary>
        /// Create new Charge based on the parameters passed
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="m_C_AcctSchema_ID"></param>
        /// <param name="m_C_TaxCategory_ID"></param>
        /// <param name="name"></param>
        /// <param name="primaryC_ElementValue_ID"></param>
        /// <param name="expense"></param>
        /// <returns></returns>
        public int CreateCharge(Ctx ctx, int m_C_AcctSchema_ID, int m_C_TaxCategory_ID, String name, int primaryC_ElementValue_ID, Boolean expense)
        {
            MCharge charge = new MCharge(ctx, 0, null);

            charge.SetName(name);
            charge.SetC_TaxCategory_ID(m_C_TaxCategory_ID);
            if (!charge.Save())
            {
                // log.Log(Level.SEVERE, name + " not created");
                Msg = name + " not created";
                ID  = 0;
                return(0);
            }

            MAcctSchema m_acctSchema = null;

            //  Get Primary AcctSchama
            if (m_acctSchema == null)
            {
                m_acctSchema = new MAcctSchema(ctx, m_C_AcctSchema_ID, null);
            }
            if (m_acctSchema == null || m_acctSchema.GetC_AcctSchema_ID() == 0)
            {
                ID = 0;
                return(0);
            }
            MAcctSchemaElement primary_ase = m_acctSchema.GetAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_Account);

            //	Get All
            MAcctSchema[] ass = MAcctSchema.GetClientAcctSchema(ctx, charge.GetAD_Client_ID());
            foreach (MAcctSchema ac in ass)
            {
                //	Target Account
                MAccount defaultAcct = MAccount.GetDefault(ac, true);   //	optional null
                //	Natural Account
                int C_ElementValue_ID  = primaryC_ElementValue_ID;
                MAcctSchemaElement ase = ac.GetAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_Account);
                if (primary_ase.GetC_Element_ID() != ase.GetC_Element_ID())
                {
                    MAcctSchemaDefault defAccts = MAcctSchemaDefault.Get(ctx, ac.GetC_AcctSchema_ID());
                    int C_ValidCombination_ID   = defAccts.GetCh_Expense_Acct();
                    if (!expense)
                    {
                        C_ValidCombination_ID = defAccts.GetCh_Revenue_Acct();
                    }
                    MAccount chargeAcct = MAccount.Get(ctx, C_ValidCombination_ID);
                    C_ElementValue_ID = chargeAcct.GetAccount_ID();
                    //	Fallback
                    if (C_ElementValue_ID == 0)
                    {
                        C_ElementValue_ID = defaultAcct.GetAccount_ID();
                        if (C_ElementValue_ID == 0)
                        {
                            C_ElementValue_ID = ase.GetC_ElementValue_ID();
                        }
                        if (C_ElementValue_ID == 0)
                        {
                            // log.Log(Level.WARNING, "No Default ElementValue for " + ac);
                            Msg = "No Default ElementValue for " + ac;
                            continue;
                        }
                    }
                }

                MAccount acct = MAccount.Get(ctx,
                                             charge.GetAD_Client_ID(), charge.GetAD_Org_ID(),
                                             ac.GetC_AcctSchema_ID(),
                                             C_ElementValue_ID, defaultAcct.GetC_SubAcct_ID(),
                                             defaultAcct.GetM_Product_ID(), defaultAcct.GetC_BPartner_ID(), defaultAcct.GetAD_OrgTrx_ID(),
                                             defaultAcct.GetC_LocFrom_ID(), defaultAcct.GetC_LocTo_ID(), defaultAcct.GetC_SalesRegion_ID(),
                                             defaultAcct.GetC_Project_ID(), defaultAcct.GetC_Campaign_ID(), defaultAcct.GetC_Activity_ID(),
                                             defaultAcct.GetUser1_ID(), defaultAcct.GetUser2_ID(),
                                             defaultAcct.GetUserElement1_ID(), defaultAcct.GetUserElement2_ID());
                if (acct == null)
                {
                    //log.Log(Level.WARNING, "No Default Account for " + ac);
                    Msg = "No Default Account for " + ac;
                    continue;
                }

                //  Update Accounts
                StringBuilder sql = new StringBuilder("UPDATE C_Charge_Acct ");
                sql.Append("SET CH_Expense_Acct=").Append(acct.GetC_ValidCombination_ID());
                sql.Append(", CH_Revenue_Acct=").Append(acct.GetC_ValidCombination_ID());
                sql.Append(" WHERE C_Charge_ID=").Append(charge.GetC_Charge_ID());
                sql.Append(" AND C_AcctSchema_ID=").Append(ac.GetC_AcctSchema_ID());
                //
                int no = VAdvantage.DataBase.DB.ExecuteQuery(sql.ToString(), null, null);
                if (no != 1)
                {
                    //log.Log(Level.WARNING, "Update #" + no + "\n" + sql.ToString());
                    Msg = "Update #" + no + "\n" + sql.ToString();
                }
            }
            ID = charge.GetC_Charge_ID();
            return(charge.GetC_Charge_ID());
        }