//=============================================================================================================

        /// <summary>
        /// Add Attribute Set Value
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public string AddAttributeSet(VA005_AddAttributeSet values)
        {
            MAttributeSet ctrl = new MAttributeSet(_ctx, values.ID, null);

            ctrl.SetName(values.name);
            ctrl.SetDescription(values.description);
            ctrl.SetMandatoryType(values.mandatorytype);
            ctrl.SetIsGuaranteeDate(values.IsGuaranteeDate);
            ctrl.SetIsGuaranteeDateMandatory(values.IsGuaranteeDateMandatory);
            ctrl.SetIsLot(values.islotcheck);
            ctrl.SetIsSerNo(values.isserialcheck);
            if (!String.IsNullOrEmpty(values.lotvalue))
            {
                ctrl.SetM_LotCtl_ID(Convert.ToInt32(values.lotvalue));
            }
            else
            {
                ctrl.SetM_LotCtl_ID(0);
            }

            if (!String.IsNullOrEmpty(values.serialvalue))
            {
                ctrl.SetM_SerNoCtl_ID(Convert.ToInt32(values.serialvalue));
            }
            else
            {
                ctrl.SetM_SerNoCtl_ID(0);
            }

            if (ctrl.Save())
            {
                return(ctrl.GetM_AttributeSet_ID().ToString());
            }
            return(Msg.GetMsg(_ctx, "VA005_UnableToAddAttributeSet"));
        }
Esempio n. 2
0
 /*  Get Attribute Set
  *	@return set or null
  */
 public MAttributeSet GetAttributeSet()
 {
     if (GetM_AttributeSet_ID() != 0)
     {
         return(MAttributeSet.Get(GetCtx(), GetM_AttributeSet_ID()));
     }
     return(null);
 }
Esempio n. 3
0
        /*	Has the Product Instance Attribute
         *	@return true if instance attributes
         */
        public bool IsInstanceAttribute()
        {
            if (GetM_AttributeSet_ID() == 0)
            {
                return(false);
            }
            MAttributeSet mas = MAttributeSet.Get(GetCtx(), GetM_AttributeSet_ID());

            return(mas.IsInstanceAttribute());
        }
        public string DeleteAttributeSetValue(VA005_DeleteAttributeSetValue value)
        {
            //MAttributeValue obj = new MAttributeValue(_ctx, value.attributesetdelID, null);
            MAttributeSet obj      = new MAttributeSet(_ctx, value.attributesetdelID, null);
            int           attvalid = obj.GetM_AttributeSet_ID();
            string        _result  = "";

            if (!obj.Delete(true))
            {
                ValueNamePair pp = VLogger.RetrieveError();
                _result = pp.ToString();
            }

            return(_result);
        }
        public AttributeInstance SaveAttribute(int windowNoParent, string strLotStringC, string strSerNoC, string dtGuaranteeDateC, string strAttrCodeC,
                                               bool productWindow, int mAttributeSetInstanceId, int mProductId, int windowNo, List <KeyNamePair> values, Ctx ctx)
        {
            var editors = values;
            AttributeInstance obj = new AttributeInstance();
            String            strLotString = "", strSerNo = "", strAttrCode = "";
            int           attributeID = 0, prdAttributes = 0, pAttribute_ID = 0, product_id = 0;
            StringBuilder sql             = new StringBuilder();
            string        qry             = "";
            StringBuilder qryAttr         = null;
            DataSet       ds              = null;
            DateTime?     dtGuaranteeDate = null;
            bool          _changed        = false;

            if (!productWindow && strLotStringC != null)
            {
                strLotString = strLotStringC;
            }   //	L

            if (!productWindow && strSerNoC != null)
            {
                log.Fine("SerNo=" + strSerNoC);
                strSerNo = strSerNoC;
            }

            if (!productWindow && dtGuaranteeDateC != null)
            {
                dtGuaranteeDate = Convert.ToDateTime(dtGuaranteeDateC);
            }   //	Gua

            if (!productWindow && strAttrCodeC != null)
            {
                strAttrCode = strAttrCodeC;
            }
            if (String.IsNullOrEmpty(strAttrCode))
            {
                ctx.SetContext(windowNoParent, "AttrCode", "");
            }
            else
            {
                ctx.SetContext(windowNoParent, "AttrCode", strAttrCode);
            }

            MAttributeSet aset = null;

            MAttribute[] attributes = null;
            String       mandatory  = "";
            var          _masi      = MAttributeSetInstance.Get(ctx, 0, mProductId);

            aset = _masi.GetMAttributeSet();
            if (aset == null)
            {
                return(null);
            }

            if (!productWindow && strAttrCode != "")
            {
                qryAttr = new StringBuilder();
                qryAttr.Append(@"SELECT count(*) FROM M_Product prd LEFT JOIN M_ProductAttributes patr on (prd.M_Product_ID=patr.M_Product_ID) " +
                               " LEFT JOIN M_Manufacturer muf on (prd.M_Product_ID=muf.M_Product_ID) WHERE (patr.UPC = '" + strAttrCode + "' OR prd.UPC = '" + strAttrCode + "' OR muf.UPC = '" + strAttrCode + "')");
                //"AND (patr.M_Product_ID = " + _M_Product_ID + " OR prd.M_Product_ID = " + _M_Product_ID + " OR muf.M_Product_ID = " + _M_Product_ID + ")";
                prdAttributes = Util.GetValueOfInt(DB.ExecuteScalar(qryAttr.ToString()));
                if (prdAttributes != 0)
                {
                    //qryAttr.Clear();
                    //qryAttr.Append("SELECT M_AttributeSetInstance_ID FROM M_ProductAttributes WHERE UPC = '" + strAttrCode + "' AND M_Product_ID = " + _M_Product_ID);
                    //attributeID = Util.GetValueOfInt(DB.ExecuteScalar(qryAttr.ToString()));
                    //if (attributeID == 0)
                    //{
                    qryAttr.Clear();
                    qryAttr.Append("SELECT M_ProductAttributes_ID FROM M_ProductAttributes WHERE UPC = '" + strAttrCode + "'");
                    pAttribute_ID = Util.GetValueOfInt(DB.ExecuteScalar(qryAttr.ToString()));
                    if (pAttribute_ID != 0)
                    {
                        MProductAttributes patr = new MProductAttributes(ctx, pAttribute_ID, null);
                        attributeID = patr.GetM_AttributeSetInstance_ID();
                        product_id  = patr.GetM_Product_ID();
                    }
                    //}
                }
                _changed = true;
            }   //	Attribute Code

            if (!productWindow && aset.IsLot())
            {
                log.Fine("Lot=" + strLotString);
                String text = strLotString;
                _masi.SetLot(text);
                sql.Append("UPPER(ats.Lot) = '" + text.ToUpper() + "'");
                if (aset.IsLotMandatory() && (text == null || text.Length == 0))
                {
                    mandatory += " - " + Msg.Translate(ctx, "Lot");
                }
                _changed = true;
            }   //	Lot
            if (!productWindow && aset.IsSerNo())
            {
                log.Fine("SerNo=" + strSerNo);
                String text = strSerNo;
                _masi.SetSerNo(text);
                _masi.SetSerNo(text);
                if (sql.Length > 0)
                {
                    sql.Append(" and UPPER(ats.SerNo) = '" + text.ToUpper() + "'");
                }
                else
                {
                    sql.Append(" UPPER(ats.SerNo) = '" + text.ToUpper() + "'");
                }
                if (aset.IsSerNoMandatory() && (text == null || text.Length == 0))
                {
                    mandatory += " - " + Msg.Translate(ctx, "SerNo");
                }
                _changed = true;
            }
            if (!productWindow && aset.IsGuaranteeDate())
            {
                log.Fine("GuaranteeDate=" + dtGuaranteeDate);
                DateTime?ts = dtGuaranteeDate;
                _masi.SetGuaranteeDate(ts);
                if (sql.Length > 0)
                {
                    sql.Append(" AND ats.GuaranteeDate = " + GlobalVariable.TO_DATE(dtGuaranteeDate, true));
                }
                else
                {
                    sql.Append(" ats.GuaranteeDate = " + GlobalVariable.TO_DATE(dtGuaranteeDate, true));
                }
                if (aset.IsGuaranteeDateMandatory() && ts == null)
                {
                    mandatory += " - " + Msg.Translate(ctx, "GuaranteeDate");
                }
                _changed = true;
            }   //	GuaranteeDate

            if (sql.Length > 0)
            {
                sql.Insert(0, " where ");
            }
            sql.Append(" order by ats.m_attributesetinstance_id");

            //	***	Save Attributes ***
            //	New Instance
            if (_changed || _masi.GetM_AttributeSetInstance_ID() == 0)
            {
                //_masi.Save();
                //obj.M_AttributeSetInstance_ID = _masi.GetM_AttributeSetInstance_ID();
                //mAttributeSetInstanceId = _masi.GetM_AttributeSetInstance_ID();
                //obj.M_AttributeSetInstanceName = _masi.GetDescription();
            }
            //	Save Instance Attributes
            attributes = aset.GetMAttributes(!productWindow);

            if (attributes.Length > 0)
            {
                qry = @"SELECT ats.M_AttributeSetInstance_ID, av.M_AttributeValue_ID,ats.M_AttributeSet_ID,au.Value,att.AttributeValueType FROM M_AttributeSetInstance ats 
                        INNER JOIN M_AttributeInstance au ON ats.M_AttributeSetInstance_ID=au.M_AttributeSetInstance_ID LEFT JOIN M_Attribute att 
                        ON au.M_Attribute_ID=att.M_Attribute_ID LEFT JOIN M_AttributeValue av ON au.M_AttributeValue_ID=av.M_AttributeValue_ID";
            }
            else
            {
                qry = @"SELECT ats.M_AttributeSetInstance_ID FROM M_AttributeSetInstance ats ";
            }

            if (sql.Length > 0)
            {
                qry += sql;
            }
            if (attributes.Length > 0)
            {
                qry += ",au.M_Attribute_ID";
            }

            ds = DB.ExecuteDataset(qry, null, null);
            Dictionary <MAttribute, object> lst = new Dictionary <MAttribute, object>();

            for (int i = 0; i < attributes.Length; i++)
            {
                if (MAttribute.ATTRIBUTEVALUETYPE_List.Equals(attributes[i].GetAttributeValueType()))
                {
                    object          editor = editors[i];
                    MAttributeValue value  = null;
                    if (Convert.ToInt32(editors[i].Key) > 0)
                    {
                        value = new MAttributeValue(ctx, Convert.ToInt32(editors[i].Key), null);
                        value.SetName(editors[i].Name);
                    }
                    log.Fine(attributes[i].GetName() + "=" + value);
                    if (attributes[i].IsMandatory() && value == null)
                    {
                        mandatory += " - " + attributes[i].GetName();
                    }
                    lst[attributes[i]] = value;
                    //attributes[i].SetMAttributeInstance(mAttributeSetInstanceId, value);
                }
                else if (MAttribute.ATTRIBUTEVALUETYPE_Number.Equals(attributes[i].GetAttributeValueType()))
                {
                    object  editor = editors[i].Name;
                    decimal value  = Convert.ToDecimal(editor);
                    log.Fine(attributes[i].GetName() + "=" + value);
                    if (attributes[i].IsMandatory())
                    {
                        mandatory += " - " + attributes[i].GetName();
                    }
                    lst[attributes[i]] = value;
                    //attributes[i].SetMAttributeInstance(mAttributeSetInstanceId, value);
                }
                else
                {
                    object editor = editors[i].Name;
                    String value  = Convert.ToString(editor);
                    log.Fine(attributes[i].GetName() + "=" + value);
                    if (attributes[i].IsMandatory() && (value == null || value.Length == 0))
                    {
                        mandatory += " - " + attributes[i].GetName();
                    }
                    lst[attributes[i]] = value;
                    //attributes[i].SetMAttributeInstance(mAttributeSetInstanceId, value);
                }
                _changed = true;
            }

            if (_changed)
            {
                if (mandatory.Length > 0)
                {
                    obj.Error = Msg.GetMsg(ctx, "FillMandatory") + mandatory;
                    return(obj);
                }
                if (attributes.Length > 0)
                {
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            int attCount = 0;
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                int    attSetID  = Util.GetValueOfInt(ds.Tables[0].Rows[i]["M_AttributeSet_ID"]);
                                string valueType = Util.GetValueOfString(ds.Tables[0].Rows[i]["AttributeValueType"]);
                                int    attributesetinstance_iD = Util.GetValueOfInt(ds.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]);
                                if (i > 0 && attributesetinstance_iD != Util.GetValueOfInt(ds.Tables[0].Rows[i - 1]["M_AttributeSetInstance_ID"]))
                                {
                                    attCount = 0;
                                }
                                for (int j = 0; j < attributes.Length; j++)
                                {
                                    if (MAttribute.ATTRIBUTEVALUETYPE_List.Equals(attributes[j].GetAttributeValueType()) && MAttribute.ATTRIBUTEVALUETYPE_List.Equals(valueType))
                                    {
                                        int             attID = Util.GetValueOfInt(ds.Tables[0].Rows[i]["M_AttributeValue_ID"]);
                                        MAttributeValue atr   = new MAttributeValue(ctx, attID, null);

                                        if (Util.GetValueOfString(atr.GetName()) == Util.GetValueOfString(lst[attributes[j]]) && attSetID == aset.GetM_AttributeSet_ID())
                                        {
                                            attCount += 1;
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                    else if (MAttribute.ATTRIBUTEVALUETYPE_Number.Equals(attributes[j].GetAttributeValueType()) && MAttribute.ATTRIBUTEVALUETYPE_Number.Equals(valueType))
                                    {
                                        decimal?attVal = Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["Value"]);
                                        if (attVal == Util.GetValueOfDecimal(lst[attributes[j]]) && attSetID == aset.GetM_AttributeSet_ID())
                                        {
                                            attCount += 1;
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                    else if (MAttribute.ATTRIBUTEVALUETYPE_StringMax40.Equals(attributes[j].GetAttributeValueType()) && MAttribute.ATTRIBUTEVALUETYPE_StringMax40.Equals(valueType))
                                    {
                                        string attVal = Util.GetValueOfString(ds.Tables[0].Rows[i]["Value"]);
                                        if (attVal == Util.GetValueOfString(lst[attributes[j]]) && attSetID == aset.GetM_AttributeSet_ID())
                                        {
                                            attCount += 1;
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                }

                                if (attCount == attributes.Length)
                                {
                                    mAttributeSetInstanceId = Util.GetValueOfInt(ds.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]);
                                    break;
                                }
                            }
                            if (attCount != attributes.Length)
                            {
                                mAttributeSetInstanceId = 0;
                            }
                        }
                        else
                        {
                            mAttributeSetInstanceId = 0;
                        }
                    }
                    else
                    {
                        mAttributeSetInstanceId = 0;
                    }
                    ds.Dispose();
                }
                else
                {
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                mAttributeSetInstanceId = Util.GetValueOfInt(ds.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]);
                                break;
                            }
                        }
                        else
                        {
                            mAttributeSetInstanceId = 0;
                        }
                    }
                    else
                    {
                        mAttributeSetInstanceId = 0;
                    }
                    ds.Dispose();
                }

                if (mAttributeSetInstanceId == 0)
                {
                    _masi.Save();

                    mAttributeSetInstanceId        = _masi.GetM_AttributeSetInstance_ID();
                    obj.M_AttributeSetInstance_ID  = _masi.GetM_AttributeSetInstance_ID();
                    obj.M_AttributeSetInstanceName = _masi.GetDescription();
                }

                else
                {
                    _masi = new MAttributeSetInstance(ctx, mAttributeSetInstanceId, null);
                }

                for (int i = 0; i < attributes.Length; i++)
                {
                    if (MAttribute.ATTRIBUTEVALUETYPE_List.Equals(attributes[i].GetAttributeValueType()))
                    {
                        MAttributeValue value = lst[attributes[i]] != null ? lst[attributes[i]] as MAttributeValue : null;
                        attributes[i].SetMAttributeInstance(mAttributeSetInstanceId, value);
                    }
                    else if (MAttribute.ATTRIBUTEVALUETYPE_Number.Equals(attributes[i].GetAttributeValueType()))
                    {
                        attributes[i].SetMAttributeInstance(mAttributeSetInstanceId, (decimal?)lst[attributes[i]]);
                    }
                    else
                    {
                        attributes[i].SetMAttributeInstance(mAttributeSetInstanceId, (String)lst[attributes[i]]);
                    }
                }

                if (attributeID == 0 && strAttrCode != "")
                {
                    MProductAttributes pAttr = new MProductAttributes(ctx, 0, null);
                    pAttr.SetUPC(strAttrCode);
                    pAttr.SetM_Product_ID(mProductId);
                    pAttr.SetM_AttributeSetInstance_ID(mAttributeSetInstanceId);
                    pAttr.Save();
                }
                _masi.SetDescription();
                _masi.Save();

                mAttributeSetInstanceId        = _masi.GetM_AttributeSetInstance_ID();
                obj.M_AttributeSetInstance_ID  = _masi.GetM_AttributeSetInstance_ID();
                obj.M_AttributeSetInstanceName = _masi.GetDescription();
                //
                if (attributeID != 0 && (attributeID != mAttributeSetInstanceId || product_id != mProductId))
                {
                    obj.Error = Msg.GetMsg(ctx, "AttributeCodeExists");
                }
            }
            else
            {
                obj.M_AttributeSetInstance_ID  = _masi.GetM_AttributeSetInstance_ID();
                obj.M_AttributeSetInstanceName = _masi.GetDescription();
            }
            return(obj);
        }
        //Dictionary<MAttribute, KeyValuePair<MAttributeInstance, MAttributeValue[]>> attributesList = new Dictionary<MAttribute, KeyValuePair<MAttributeInstance, MAttributeValue[]>>(4);

        public AttributesObjects LoadInit(int _M_AttributeSetInstance_ID, int _M_Product_ID, bool _productWindow, int windowNo, Ctx ctx, int AD_Column_ID, int window_ID, bool IsSOTrx, string IsInternalUse)
        {
            AttributesObjects obj = new AttributesObjects();

            MAttributeSet aset = null;

            MAttribute[] attributes = null;
            //	Get Model
            MAttributeSetInstance _masi = MAttributeSetInstance.Get(ctx, _M_AttributeSetInstance_ID, _M_Product_ID);
            MProduct _prd = new MProduct(ctx, _M_Product_ID, null);

            if (_masi == null)
            {
                obj.IsReturnNull = true;
                obj.Error        = "No Model for M_AttributeSetInstance_ID=" + _M_AttributeSetInstance_ID + ", M_Product_ID=" + _M_Product_ID;
                return(obj);
            }

            //	Get Attribute Set
            aset = _masi.GetMAttributeSet();
            //	Product has no Attribute Set
            if (aset == null)
            {
                obj.IsReturnNull = true;
                obj.Error        = "PAttributeNoAttributeSet";
                return(obj);
            }

            obj.MAttributeSetID = aset.Get_ID();

            //	Product has no Instance Attributes
            if (!_productWindow && !aset.IsInstanceAttribute())
            {
                obj.Error = "NPAttributeNoInstanceAttribute=";
                return(obj);
            }

            if (_productWindow)
            {
                attributes = aset.GetMAttributes(false);
            }
            else
            {
                attributes = aset.GetMAttributes(true);
            }

            //Row 0
            obj.tableStucture = "<table style='width: 100%;'><tr>";
            if (_productWindow)
            {
                for (int i = 0; i < attributes.Length; i++)
                {
                    obj.tableStucture = AddAttributeLine(attributes[i], _M_AttributeSetInstance_ID, true, false, windowNo, obj, i);
                }
            }
            else
            {
                var newEditContent = VAdvantage.Utility.Util.CleanMnemonic(Msg.GetMsg(ctx, "NewRecord"));
                if (_M_AttributeSetInstance_ID > 0)
                {
                    newEditContent = VAdvantage.Utility.Util.CleanMnemonic(Msg.GetMsg(ctx, "EditRecord"));
                }
                //column 1
                obj.tableStucture += "<td style = 'visibility: hidden;'>";
                obj.tableStucture += "<input type='checkbox' id='chkNewEdit_" + windowNo + "' ><label  class='VIS_Pref_Label_Font'>" + newEditContent + "</label>";
                obj.tableStucture += "</td>";

                //column 2
                obj.tableStucture += "<td>";
                obj.tableStucture += "<button type='button' style='margin-bottom: 10px;' id='btnSelect_" + windowNo + "' role='button' aria-disabled='false'><img style='float: left;' src='~/Areas/VIS/Images/base/Delete24.PNG' /><span style='float: left;margin-left: 5px;margin-right: 5px;' >" + VAdvantage.Utility.Util.CleanMnemonic(Msg.GetMsg(ctx, "SelectExisting")) + "</span></button>";
                obj.tableStucture += "</td>";
                obj.tableStucture += "</tr>";

                //Change 20-May-2015 Bharat
                var label = Msg.Translate(ctx, "AttrCode");
                obj.tableStucture += "<tr>";
                obj.tableStucture += "<td>";
                obj.tableStucture += "<label style='padding-bottom: 10px; padding-right: 5px;' id=lot_" + windowNo + "' class='VIS_Pref_Label_Font'>" + label + "</label>";
                obj.tableStucture += "</td>";
                //column 2
                obj.tableStucture += "<td>";
                obj.tableStucture += "<input  style='width: 100%;' id='txtAttrCode_" + windowNo + "' value='' class='VIS_Pref_pass' type='text'>";
                obj.tableStucture += "</td>";

                obj.tableStucture += "</tr>";

                //Row 1
                obj.tableStucture += "<tr>";
                //	All Attributes
                for (int i = 0; i < attributes.Length; i++)
                {
                    obj.tableStucture = AddAttributeLine(attributes[i], _M_AttributeSetInstance_ID, true, false, windowNo, obj, i);
                }
            }

            //	Lot
            if (!_productWindow && aset.IsLot())
            {
                //column 1
                var label = Msg.Translate(ctx, "Lot");
                obj.tableStucture += "<td>";
                obj.tableStucture += "<label style='padding-bottom: 10px; padding-right: 5px;' id=lot_" + windowNo + "' class='VIS_Pref_Label_Font'>" + label + "</label>";
                obj.tableStucture += "</td>";
                //column 2
                obj.tableStucture += "<td>";
                obj.tableStucture += "<input  style='width: 100%;' id='txtLotString_" + windowNo + "' value='" + _masi.GetLot() + "' class='VIS_Pref_pass' type='text'>";
                obj.tableStucture += "</td>";

                obj.tableStucture += "</tr>";

                //Row 1
                if (!IsSOTrx || IsInternalUse == "N" || window_ID == 191 || window_ID == 140)
                {
                    obj.tableStucture += "<tr>";
                    //column 1
                    label              = Msg.Translate(ctx, "M_Lot_ID");
                    obj.tableStucture += "<td>";
                    obj.tableStucture += "<label style='padding-bottom: 10px; padding-right: 5px;' id=M_Lot_ID_" + windowNo + "' class='VIS_Pref_Label_Font'>" + label + "</label>";
                    obj.tableStucture += "</td>";


                    String sql = "SELECT M_Lot_ID, Name "
                                 + "FROM M_Lot l "
                                 + "WHERE EXISTS (SELECT M_Product_ID FROM M_Product p "
                                 + "WHERE p.M_AttributeSet_ID=" + _masi.GetM_AttributeSet_ID()
                                 + " AND p.M_Product_ID=l.M_Product_ID)";

                    KeyNamePair[] data = DB.GetKeyNamePairs(sql, true);
                    //column 2
                    obj.tableStucture += "<td>";
                    obj.tableStucture += "<select style='width: 100%;margin-bottom: 10px;' id='cmbLot_" + windowNo + "'>";
                    obj.tableStucture += " <option selected value='" + 0 + "' > </option>";
                    for (int i = 1; i < data.Length; i++)
                    {
                        if (Convert.ToInt32(data[i].Key) == _masi.GetM_Lot_ID())
                        {
                            obj.tableStucture += " <option selected value='" + data[i].Key + "' >" + data[i].Name + "</option>";
                        }
                        else
                        {
                            obj.tableStucture += " <option value='" + data[i].Key + "' >" + data[i].Name + "</option>";
                        }
                    }

                    obj.tableStucture += "</select>";
                    obj.tableStucture += "</td>";
                    obj.tableStucture += "</tr>";


                    //Row 2
                    obj.tableStucture += "<tr>";

                    //	New Lot Button
                    if (_masi.GetMAttributeSet().GetM_LotCtl_ID() != 0)
                    {
                        if (MRole.GetDefault(ctx).IsTableAccess(MLot.Table_ID, false) && MRole.GetDefault(ctx).IsTableAccess(MLotCtl.Table_ID, false))
                        {
                            if (!_masi.IsExcludeLot(AD_Column_ID, IsSOTrx))//_windowNoParent
                            {
                                //column 1
                                obj.tableStucture += "<td></td>";
                                //column 2
                                obj.tableStucture += "<td>";
                                obj.tableStucture += "<button type='button' style='margin-bottom: 10px;' id='btnLot_" + windowNo + "' role='button' aria-disabled='false'><span >" + VAdvantage.Utility.Util.CleanMnemonic(Msg.GetMsg(ctx, "New")) + "</span></button>";
                                obj.tableStucture += "</td>";

                                obj.tableStucture += "</tr>";
                                //Row 3
                                obj.tableStucture += "<tr>";
                            }
                        }
                    }
                }
                //mZoom = new System.Windows.Forms.ToolStripMenuItem(Msg.GetMsg(Env.GetContext(), "Zoom"), Env.GetImageIcon("Zoom16.gif"));
                //mZoom.Click += new EventHandler(mZoom_Click);
                //ctxStrip.Items.Add(mZoom);
            }

            //	SerNo
            if (!_productWindow && aset.IsSerNo())
            {
                //column 1
                var label = Msg.Translate(ctx, "SerNo");
                obj.tableStucture += "<td>";
                obj.tableStucture += "<label style='padding-bottom: 10px; padding-right: 5px;' id=SerNo_" + windowNo + "' class='VIS_Pref_Label_Font'>" + label + "</label>";
                obj.tableStucture += "</td>";

                //column 2
                // txtSerNo.Text = _masi.GetSerNo();
                obj.tableStucture += "<td>";
                obj.tableStucture += "<input style='width: 100%;'  id='txtSerNo_" + windowNo + "' value='" + _masi.GetSerNo() + "' class='VIS_Pref_pass' type='text'>";
                obj.tableStucture += "</td>";

                obj.tableStucture += "</tr>";

                //Row 1
                obj.tableStucture += "<tr>";

                //	New SerNo Button
                if (_masi.GetMAttributeSet().GetM_SerNoCtl_ID() != 0)
                {
                    if (MRole.GetDefault(ctx).IsTableAccess(MSerNoCtl.Table_ID, false))
                    {
                        if (!_masi.IsExcludeSerNo(AD_Column_ID, IsSOTrx))//_windowNoParent
                        {
                            //column 1
                            obj.tableStucture += "<td></td>";
                            obj.tableStucture += "<td>";
                            obj.tableStucture += "<button type='button' style='margin-bottom: 10px;' id='btnSerNo_" + windowNo + "' role='button' aria-disabled='false'><span >" + VAdvantage.Utility.Util.CleanMnemonic(Msg.GetMsg(ctx, "New")) + "</span></button>";
                            obj.tableStucture += "</td>";
                        }

                        obj.tableStucture += "</tr>";
                        //Row 2
                        obj.tableStucture += "<tr>";
                    }
                }
            }   //	SerNo

            ////	GuaranteeDate
            if (!_productWindow && aset.IsGuaranteeDate())
            {
                var dtpicGuaranteeDate = TimeUtil.AddDays(DateTime.Now, _prd.GetGuaranteeDays());
                if (_M_AttributeSetInstance_ID > 0)
                {
                    dtpicGuaranteeDate = (DateTime)(_masi.GetGuaranteeDate());
                }
                var label = Msg.Translate(ctx, "GuaranteeDate");
                //Column 1
                obj.tableStucture += "<td>";
                obj.tableStucture += "<label style='padding-bottom: 10px; padding-right: 5px;' id='guaranteeDate_" + windowNo + "' class='VIS_Pref_Label_Font'>" + label + "</label>";
                obj.tableStucture += "</td>";
                //Column 2
                obj.tableStucture += "<td>";
                //obj.tableStucture += "<input style='width: 100%;' value='" + String.Format("{0:yyyy-MM-dd}", dtpicGuaranteeDate) + "' type='date'  id='dtpicGuaranteeDate_" + windowNo + "' class='VIS_Pref_pass'/>";
                obj.tableStucture += "<input style='width: 100%;' value='" + String.Format("{0:yyyy-MM-dd}", dtpicGuaranteeDate) + "' type='date'  id='dtpicGuaranteeDate_" + windowNo + "' class='VIS_Pref_pass'/>";
                obj.tableStucture += "</td>";

                obj.tableStucture += "</tr>";
                //Row 2
                obj.tableStucture += "<tr>";
            }

            //string[] sep = new string[1];
            //sep[0] = "<tr>";
            //sep = obj.tableStucture.Split(sep, StringSplitOptions.RemoveEmptyEntries);
            //if (sep.Length <= 3)
            //{
            //    obj.Error = "PAttributeNoInfo";
            //    obj.IsReturnNull = true;
            //    return null;
            //}

            //	New/Edit Window
            if (!_productWindow)
            {
                //chkNewEdit.IsChecked = _M_AttributeSetInstance_ID == 0;
            }

            //	Attrribute Set Instance Description
            //Column 1
            var label1 = Msg.Translate(ctx, "Description");

            obj.tableStucture += "<td>";
            obj.tableStucture += "<label style='padding-bottom: 10px; padding-right: 5px;' id='description_" + windowNo + "' class='VIS_Pref_Label_Font'>" + label1 + "</label>";
            obj.tableStucture += "</td>";
            //Column 2
            obj.tableStucture += "<td>";
            obj.tableStucture += "<input style='width: 100%;' readonly  id='txtDescription_" + windowNo + "' value='" + _masi.GetDescription() + "' class='VIS_Pref_pass vis-gc-vpanel-table-readOnly' type='text'>";
            obj.tableStucture += "</td>";

            obj.tableStucture += "</tr>";


            //Add Ok and Cancel button
            //Last row
            obj.tableStucture += "<tr>";

            obj.tableStucture += "<td style='text-align:right'  colspan='2'>";
            obj.tableStucture += "<button style='margin-bottom:0px;margin-top:0px; float:right' type='button' class='VIS_Pref_btn-2' style='float: right;'  id='btnCancel_" + windowNo + "' role='button' aria-disabled='false'>" + VAdvantage.Utility.Util.CleanMnemonic(Msg.GetMsg(ctx, "Cancel")) + "</button>";
            obj.tableStucture += "<button style='margin-bottom:0px;margin-top:0px; float:right; margin-right: 10px;' type='button' class='VIS_Pref_btn-2' style='float: right; margin-right: 10px;' id='btnOk_" + windowNo + "' role='button' aria-disabled='false'>" + VAdvantage.Utility.Util.CleanMnemonic(Msg.GetMsg(ctx, "OK")) + "</button>";
            obj.tableStucture += "</td>";
            obj.tableStucture += "</tr>";

            obj.tableStucture += "</table>";
            if (obj.ControlList != null)
            {
                if (obj.ControlList.Length > 1)
                {
                    obj.ControlList = obj.ControlList.Substring(0, obj.ControlList.Length - 1);
                }
                ;
            }
            return(obj);
        }
        public List <String> GetAttributeInstance(int _M_AttributeSetInstance_ID, int _M_Product_ID, bool _productWindow, int windowNo, Ctx ctx, int AD_Column_ID, int attrcode)
        {
            List <String> attrValues = new List <String>();

            int           attr_ID = 0;
            StringBuilder sql     = new StringBuilder();
            MAttributeSet aset    = null;

            MAttribute[]          attributes = null;
            MAttributeSetInstance _masi      = MAttributeSetInstance.Get(ctx, _M_AttributeSetInstance_ID, _M_Product_ID);

            //	Get Attribute Set
            aset = _masi.GetMAttributeSet();
            //	Product has no Attribute Set
            if (aset == null)
            {
                Msg.GetMsg("PAttributeNoAttributeSet", null);
                return(null);;
            }
            string attrsetQry   = @"SELECT ats.M_AttributeSet_ID FROM M_ProductAttributes patr LEFT JOIN  M_AttributeSetInstance ats 
                        ON (patr.M_AttributeSetInstance_ID=ats.M_AttributeSetInstance_ID) where patr.UPC='" + attrcode + "'";
            int    attributeSet = Util.GetValueOfInt(DB.ExecuteScalar(attrsetQry));

            if (attributeSet != aset.Get_ID())
            {
                return(null);
            }
            if (!_productWindow && aset.IsLot())
            {
                sql.Append("SELECT ats.Lot,ats.SerNo,ats.GuaranteeDate ");
            }   //	Lot
            //if (!_productWindow && aset.IsSerNo())
            //{
            //    sql.Append(" SELECT ats.SerNo");
            //}
            //if (!_productWindow && aset.IsGuaranteeDate())
            //{
            //    if (sql.Length > 0)
            //    {
            //        sql.Append(",ats.GuaranteeDate");
            //    }
            //    else
            //    {
            //        sql.Append("SELECT ats.GuaranteeDate");
            //    }
            //}	//	GuaranteeDate
            if (sql.Length > 0)
            {
                sql.Append(@" FROM M_ProductAttributes patr INNER JOIN M_AttributeSetInstance ats ON (patr.m_attributesetinstance_id=ats.m_attributesetinstance_id) WHERE patr.UPC='" + attrcode + "'");
                DataSet ds1 = null;
                try
                {
                    ds1 = DB.ExecuteDataset(sql.ToString(), null, null);

                    if (ds1 != null)
                    {
                        if (ds1.Tables[0].Rows.Count > 0)
                        {
                            if (!_productWindow && aset.IsLot())
                            {
                                attrValues.Add(Util.GetValueOfString(ds1.Tables[0].Rows[0]["Lot"]));
                            }   //	Lot
                            else
                            {
                                attrValues.Add("");
                            }
                            if (!_productWindow && aset.IsSerNo())
                            {
                                attrValues.Add(Util.GetValueOfString(ds1.Tables[0].Rows[0]["SerNo"]));
                            }
                            else
                            {
                                attrValues.Add("");
                            }
                            if (!_productWindow && aset.IsGuaranteeDate())
                            {
                                attrValues.Add(Util.GetValueOfString(ds1.Tables[0].Rows[0]["GuaranteeDate"]));
                            }   //	GuaranteeDate
                            else
                            {
                                attrValues.Add("");
                            }
                            ds1.Dispose();
                        }
                        else
                        {
                            ds1.Dispose();
                        }
                    }
                    else
                    {
                        ds1.Dispose();
                    }
                }
                catch
                {
                    attrValues.Clear();
                }
                finally
                {
                    ds1.Dispose();
                }
            }
            if (attrValues.Count == 0)
            {
                attrValues.Add("");
                attrValues.Add("");
                attrValues.Add("");
            }
            return(attrValues);
        }
        public List <String> GetAttribute(int _M_AttributeSetInstance_ID, int _M_Product_ID, bool _productWindow, int windowNo, Ctx ctx, int AD_Column_ID, int attrcode)
        {
            List <String> attrValues = new List <String>();

            int           attr_ID = 0;
            StringBuilder sql     = new StringBuilder();
            MAttributeSet aset    = null;

            MAttribute[]          attributes = null;
            MAttributeSetInstance _masi      = MAttributeSetInstance.Get(ctx, _M_AttributeSetInstance_ID, _M_Product_ID);

            //	Get Attribute Set
            aset = _masi.GetMAttributeSet();
            //	Product has no Attribute Set
            if (aset == null)
            {
                Msg.GetMsg("PAttributeNoAttributeSet", null);
                return(null);;
            }
            string attrsetQry   = @"SELECT ats.M_AttributeSet_ID FROM M_ProductAttributes patr LEFT JOIN  M_AttributeSetInstance ats 
                        ON (patr.M_AttributeSetInstance_ID=ats.M_AttributeSetInstance_ID) where patr.UPC='" + attrcode + "'";
            int    attributeSet = Util.GetValueOfInt(DB.ExecuteScalar(attrsetQry));

            if (attributeSet != aset.Get_ID())
            {
                return(null);
            }

            ////	Product has no Instance Attributes
            //if (!_productWindow && !aset.IsInstanceAttribute())
            //{
            //    Dispatcher.BeginInvoke(() => Classes.ShowMessage.Error("PAttributeNoInstanceAttribute", null));
            //    //ADialog.error(m_WindowNo, this, "PAttributeNoInstanceAttribute");
            //    return;
            //}
            if (_productWindow)
            {
                attributes = aset.GetMAttributes(false);
                log.Fine("Product Attributes=" + attributes.Length);
            }
            else
            {
                attributes = aset.GetMAttributes(true);
            }

            if (attributes.Length > 0)
            {
                string  attrQry = @"SELECT ats.M_Attribute_ID,ats.M_AttributeValue_ID,ats.Value,att.attributevaluetype FROM M_ProductAttributes patr LEFT JOIN  M_AttributeInstance ats 
                    ON (patr.M_AttributeSetInstance_ID=ats.M_AttributeSetInstance_ID) inner join M_attributesetinstance ast ON (patr.M_AttributeSetInstance_ID=ast.M_AttributeSetInstance_ID)
                    LEFT JOIN M_Attribute att ON ats.M_Attribute_ID=att.M_Attribute_ID
                    where patr.UPC='" + attrcode + "' AND ast.M_AttributeSet_ID = " + _masi.GetM_AttributeSet_ID() + " Order By ats.M_Attribute_ID";
                DataSet ds      = null;
                try
                {
                    ds = DB.ExecuteDataset(attrQry, null, null);
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                if (Util.GetValueOfString(ds.Tables[0].Rows[i]["AttributeValueType"]) == "L")
                                {
                                    attrValues.Add(Util.GetValueOfString(ds.Tables[0].Rows[i]["M_AttributeValue_ID"]));
                                }
                                else
                                {
                                    attrValues.Add(Util.GetValueOfString(ds.Tables[0].Rows[i]["Value"]));
                                }
                            }
                            ds.Dispose();
                        }
                        else
                        {
                            ds.Dispose();
                        }
                    }
                    else
                    {
                        ds.Dispose();
                    }
                }
                catch
                {
                }
                finally
                {
                    ds.Dispose();
                }
            }
            if (attrValues.Count == 0)
            {
                attrValues.Add("");
            }
            return(attrValues);
        }
Esempio n. 9
0
        /// <summary>
        /// Create/Add to Inventory Line
        /// </summary>
        /// <param name="M_Locator_ID">locator</param>
        /// <param name="M_Product_ID">product</param>
        /// <param name="M_AttributeSetInstance_ID">asi</param>
        /// <param name="qtyOnHand">quantity</param>
        /// <param name="M_AttributeSet_ID">attribute set</param>
        /// <returns>lines added</returns>
        private int CreateInventoryLine(int M_Locator_ID, int M_Product_ID,
                                        int M_AttributeSetInstance_ID, Decimal qtyOnHand, Decimal currentQty, int M_AttributeSet_ID)
        {
            Boolean oneLinePerASI = false;

            if (M_AttributeSet_ID != 0)
            {
                MAttributeSet mas = MAttributeSet.Get(GetCtx(), M_AttributeSet_ID);
                oneLinePerASI = mas.IsInstanceAttribute();
            }
            if (oneLinePerASI)
            {
                MInventoryLine line = new MInventoryLine(_inventory, M_Locator_ID,
                                                         M_Product_ID, M_AttributeSetInstance_ID,
                                                         qtyOnHand, qtyOnHand); //	book/count
                line.SetOpeningStock(currentQty);
                if (line.Save())
                {
                    return(1);
                }
                return(0);
            }

            if (Env.Signum(qtyOnHand) == 0)
            {
                M_AttributeSetInstance_ID = 0;
            }

            if (_line != null &&
                _line.GetM_Locator_ID() == M_Locator_ID &&
                _line.GetM_Product_ID() == M_Product_ID)
            {
                if (Env.Signum(qtyOnHand) == 0)
                {
                    return(0);
                }
                //	Same ASI (usually 0)
                if (_line.GetM_AttributeSetInstance_ID() == M_AttributeSetInstance_ID)
                {
                    _line.SetQtyBook(Decimal.Add(_line.GetQtyBook(), qtyOnHand));
                    _line.SetQtyCount(Decimal.Add(_line.GetQtyCount(), qtyOnHand));
                    _line.SetOpeningStock((Decimal.Add(_line.GetOpeningStock(), currentQty)));
                    _line.Save();
                    return(0);
                }
                //	Save Old Line info
                else if (_line.GetM_AttributeSetInstance_ID() != 0)
                {
                    MInventoryLineMA ma = new MInventoryLineMA(_line,
                                                               _line.GetM_AttributeSetInstance_ID(), _line.GetQtyBook());
                    if (!ma.Save())
                    {
                        ;
                    }
                }
                _line.SetM_AttributeSetInstance_ID(0);
                _line.SetQtyBook(Decimal.Add(_line.GetQtyBook(), qtyOnHand));
                _line.SetQtyCount(Decimal.Add(_line.GetQtyCount(), qtyOnHand));
                _line.SetOpeningStock((Decimal.Add(_line.GetOpeningStock(), currentQty)));
                _line.Save();
                //
                MInventoryLineMA ma1 = new MInventoryLineMA(_line, M_AttributeSetInstance_ID, qtyOnHand);
                if (!ma1.Save())
                {
                    ;
                }
                return(0);
            }
            //	new line
            _line = new MInventoryLine(_inventory, M_Locator_ID, M_Product_ID,
                                       M_AttributeSetInstance_ID, qtyOnHand, qtyOnHand); //	book/count
            _line.SetOpeningStock(currentQty);
            if (_line.Save())
            {
                return(1);
            }
            return(0);
        }
Esempio n. 10
0
        /// <summary>
        /// Create/Add to Inventory Line
        /// </summary>
        /// <param name="M_Locator_ID">locator</param>
        /// <param name="M_Product_ID">product</param>
        /// <param name="M_AttributeSetInstance_ID">asi</param>
        /// <param name="qtyOnHand">quantity</param>
        /// <param name="M_AttributeSet_ID">attribute set</param>
        /// <returns>lines added</returns>
        private int CreateInventoryLine(int M_Locator_ID, int M_Product_ID,
                                        int M_AttributeSetInstance_ID, Decimal qtyOnHand, Decimal currentQty, int M_AttributeSet_ID)
        {
            Boolean oneLinePerASI = false;

            if (M_AttributeSet_ID != 0)
            {
                MAttributeSet mas = MAttributeSet.Get(GetCtx(), M_AttributeSet_ID);
                oneLinePerASI = mas.IsInstanceAttribute();
            }
            if (oneLinePerASI)
            {
                MInventoryLine line = new MInventoryLine(_inventory, M_Locator_ID,
                                                         M_Product_ID, M_AttributeSetInstance_ID,
                                                         qtyOnHand, qtyOnHand); //	book/count
                line.SetOpeningStock(currentQty);
                line.SetAsOnDateCount(line.GetQtyCount());

                // JID_0903: On creating the lines from physical inventory count system is not updating the UOM and Qty on physical inventory line.
                if (line.Get_ColumnIndex("QtyEntered") > 0)
                {
                    line.Set_Value("QtyEntered", line.GetQtyCount());
                }
                if (line.Get_ColumnIndex("C_UOM_ID") > 0)
                {
                    MProduct prd = new MProduct(GetCtx(), M_Product_ID, Get_Trx());
                    line.Set_Value("C_UOM_ID", prd.GetC_UOM_ID());
                }

                if (line.Get_ColumnIndex("IsFromProcess") >= 0)
                {
                    line.SetIsFromProcess(true);
                }
                if (line.Save())
                {
                    return(1);
                }
                return(0);
            }

            if (Env.Signum(qtyOnHand) == 0)
            {
                M_AttributeSetInstance_ID = 0;
            }

            if (_line != null &&
                _line.GetM_Locator_ID() == M_Locator_ID &&
                _line.GetM_Product_ID() == M_Product_ID)
            {
                if (Env.Signum(qtyOnHand) == 0)
                {
                    return(0);
                }
                //	Same ASI (usually 0)
                if (_line.GetM_AttributeSetInstance_ID() == M_AttributeSetInstance_ID)
                {
                    _line.SetQtyBook(Decimal.Add(_line.GetQtyBook(), qtyOnHand));
                    _line.SetQtyCount(Decimal.Add(_line.GetQtyCount(), qtyOnHand));
                    _line.SetOpeningStock((Decimal.Add(_line.GetOpeningStock(), currentQty)));
                    _line.SetAsOnDateCount(_line.GetQtyCount());

                    // JID_0903: On creating the lines from physical inventory count system is not updating the UOM and Qty on physical inventory line.
                    if (_line.Get_ColumnIndex("QtyEntered") > 0)
                    {
                        _line.Set_Value("QtyEntered", _line.GetQtyCount());
                    }
                    if (_line.Get_ColumnIndex("C_UOM_ID") > 0)
                    {
                        MProduct prd = new MProduct(GetCtx(), M_Product_ID, Get_Trx());
                        _line.Set_Value("C_UOM_ID", prd.GetC_UOM_ID());
                    }

                    if (_line.Get_ColumnIndex("IsFromProcess") >= 0)
                    {
                        _line.SetIsFromProcess(true);
                    }
                    _line.Save();
                    return(0);
                }
                //	Save Old Line info
                else if (_line.GetM_AttributeSetInstance_ID() != 0)
                {
                    MInventoryLineMA ma = new MInventoryLineMA(_line,
                                                               _line.GetM_AttributeSetInstance_ID(), _line.GetQtyBook());
                    if (!ma.Save())
                    {
                        ;
                    }
                }
                _line.SetM_AttributeSetInstance_ID(0);
                _line.SetQtyBook(Decimal.Add(_line.GetQtyBook(), qtyOnHand));
                _line.SetQtyCount(Decimal.Add(_line.GetQtyCount(), qtyOnHand));
                _line.SetOpeningStock((Decimal.Add(_line.GetOpeningStock(), currentQty)));
                _line.SetAsOnDateCount(_line.GetQtyCount());

                // JID_0903: On creating the lines from physical inventory count system is not updating the UOM and Qty on physical inventory line.
                if (_line.Get_ColumnIndex("QtyEntered") > 0)
                {
                    _line.Set_Value("QtyEntered", _line.GetQtyCount());
                }
                if (_line.Get_ColumnIndex("C_UOM_ID") > 0)
                {
                    MProduct prd = new MProduct(GetCtx(), M_Product_ID, Get_Trx());
                    _line.Set_Value("C_UOM_ID", prd.GetC_UOM_ID());
                }

                if (_line.Get_ColumnIndex("IsFromProcess") >= 0)
                {
                    _line.SetIsFromProcess(true);
                }
                _line.Save();
                //
                MInventoryLineMA ma1 = new MInventoryLineMA(_line, M_AttributeSetInstance_ID, qtyOnHand);
                if (!ma1.Save())
                {
                    ;
                }
                return(0);
            }
            //	new line
            _line = new MInventoryLine(_inventory, M_Locator_ID, M_Product_ID,
                                       M_AttributeSetInstance_ID, qtyOnHand, qtyOnHand); //	book/count
            _line.SetOpeningStock(currentQty);
            _line.SetAsOnDateCount(_line.GetQtyCount());

            // JID_0903: On creating the lines from physical inventory count system is not updating the UOM and Qty on physical inventory line.
            if (_line.Get_ColumnIndex("QtyEntered") > 0)
            {
                _line.Set_Value("QtyEntered", _line.GetQtyCount());
            }
            if (_line.Get_ColumnIndex("C_UOM_ID") > 0)
            {
                MProduct prd = new MProduct(GetCtx(), M_Product_ID, Get_Trx());
                _line.Set_Value("C_UOM_ID", prd.GetC_UOM_ID());
            }

            if (_line.Get_ColumnIndex("IsFromProcess") >= 0)
            {
                _line.SetIsFromProcess(true);
            }
            if (_line.Save())
            {
                return(1);
            }
            return(0);
        }
Esempio n. 11
0
        /// <summary>
        /// Create Line
        /// </summary>
        /// <param name="order">order</param>
        /// <param name="orderLine">line</param>
        /// <param name="qty">Quantity</param>
        /// <param name="storages">storage info</param>
        /// <param name="force">force delivery</param>
        private void CreateLine(MOrder order, MOrderLine orderLine, Decimal qty,
                                MStorage[] storages, bool force)
        {
            //	Complete last Shipment - can have multiple shipments
            if (_lastC_BPartner_Location_ID != orderLine.GetC_BPartner_Location_ID())
            {
                CompleteShipment();
            }
            _lastC_BPartner_Location_ID = orderLine.GetC_BPartner_Location_ID();
            //	Create New Shipment
            if (_shipment == null)
            {
                _shipment = new MInOut(order, 0, _movementDate);
                _shipment.SetM_Warehouse_ID(orderLine.GetM_Warehouse_ID());     //	sets Org too
                if (order.GetC_BPartner_ID() != orderLine.GetC_BPartner_ID())
                {
                    _shipment.SetC_BPartner_ID(orderLine.GetC_BPartner_ID());
                }
                if (order.GetC_BPartner_Location_ID() != orderLine.GetC_BPartner_Location_ID())
                {
                    _shipment.SetC_BPartner_Location_ID(orderLine.GetC_BPartner_Location_ID());
                }
                if (!_shipment.Save())
                {
                    throw new Exception("Could not create Shipment");
                }
            }
            //	Non Inventory Lines
            if (storages == null)
            {
                MInOutLine line = new MInOutLine(_shipment);
                line.SetOrderLine(orderLine, 0, Env.ZERO);
                line.SetQty(qty);       //	Correct UOM
                if (orderLine.GetQtyEntered().CompareTo(orderLine.GetQtyOrdered()) != 0)
                {
                    line.SetQtyEntered(Decimal.Round(Decimal.Divide(Decimal.Multiply(qty,
                                                                                     orderLine.GetQtyEntered()), orderLine.GetQtyOrdered()),
                                                     12, MidpointRounding.AwayFromZero));
                }
                line.SetLine(_line + orderLine.GetLine());
                //Amit 27-jan-2014
                if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'")) > 0)
                {
                    line.SetDTD001_IsAttributeNo(true);
                }
                if (!line.Save())
                {
                    throw new Exception("Could not create Shipment Line");
                }
                log.Fine(line.ToString());
                return;
            }

            //	Product
            MProduct product    = orderLine.GetProduct();
            bool     linePerASI = false;

            if (product.GetM_AttributeSet_ID() != 0)
            {
                MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                linePerASI = mas.IsInstanceAttribute();
            }

            //	Inventory Lines
            List <MInOutLine> list      = new List <MInOutLine>();
            Decimal           toDeliver = qty;

            for (int i = 0; i < storages.Length; i++)
            {
                MStorage storage = storages[i];
                Decimal  deliver = toDeliver;
                //	Not enough On Hand
                if (deliver.CompareTo(storage.GetQtyOnHand()) > 0 &&
                    Env.Signum(storage.GetQtyOnHand()) >= 0)            //	positive storage
                {
                    if (!force || //	Adjust to OnHand Qty
                        (i + 1 != storages.Length))     //	if force don't adjust last location
                    {
                        deliver = storage.GetQtyOnHand();
                    }
                }
                if (Env.Signum(deliver) == 0)   //	zero deliver
                {
                    continue;
                }
                int M_Locator_ID = storage.GetM_Locator_ID();
                //
                MInOutLine line = null;
                if (!linePerASI)        //	find line with Locator
                {
                    for (int n = 0; n < list.Count; n++)
                    {
                        MInOutLine test = (MInOutLine)list[n];
                        if (test.GetM_Locator_ID() == M_Locator_ID)
                        {
                            line = test;
                            break;
                        }
                    }
                }
                if (line == null)       //	new line
                {
                    line = new MInOutLine(_shipment);
                    line.SetOrderLine(orderLine, M_Locator_ID, order.IsSOTrx() ? deliver : Env.ZERO);
                    line.SetQty(deliver);
                    list.Add(line);
                }
                else
                {
                    //	existing line
                    line.SetQty(Decimal.Add(line.GetMovementQty(), deliver));
                }
                if (orderLine.GetQtyEntered().CompareTo(orderLine.GetQtyOrdered()) != 0)
                {
                    line.SetQtyEntered(Decimal.Round(Decimal.Divide(Decimal.Multiply(line.GetMovementQty(), orderLine.GetQtyEntered()),
                                                                    orderLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero));
                }

                line.SetLine(_line + orderLine.GetLine());
                if (linePerASI)
                {
                    line.SetM_AttributeSetInstance_ID(storage.GetM_AttributeSetInstance_ID());
                }

                //Amit 27-jan-2014
                if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'")) > 0)
                {
                    line.SetDTD001_IsAttributeNo(true);
                }

                if (!line.Save())
                {
                    throw new Exception("Could not create Shipment Line");
                }
                log.Fine("ToDeliver=" + qty + "/" + deliver + " - " + line);
                toDeliver = Decimal.Subtract(toDeliver, deliver);
                //	Temp adjustment
                storage.SetQtyOnHand(Decimal.Subtract(storage.GetQtyOnHand(), deliver));
                //
                if (Env.Signum(toDeliver) == 0)
                {
                    break;
                }
            }
            if (Env.Signum(toDeliver) != 0)
            {
                throw new Exception("Not All Delivered - Remainder=" + toDeliver);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true if can be saved</returns>
        protected override bool BeforeSave(bool newRecord)
        {
            Decimal    VA024_ProvisionPrice = 0;
            MInventory inventory            = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx());
            MProduct   product = MProduct.Get(GetCtx(), GetM_Product_ID());

            if (newRecord && _isManualEntry)
            {
                //	Product requires ASI
                if (GetM_AttributeSetInstance_ID() == 0)
                {
                    if (product.GetM_AttributeSet_ID() != 0)
                    {
                        MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                        //uncomment by Amit on behalf of Mandeep 7-3-2016
                        //if (mas.IsInstanceAttribute()
                        //    && (mas.IsMandatory() || mas.IsMandatoryAlways()))
                        if (mas.IsMandatory() || mas.IsMandatoryAlways())
                        {
                            log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstance_ID"));
                            return(false);
                        }
                    }
                } //	No ASI
            }     //	new or manual

            // not to create Internal use Inventory with -ve qty -- but during reversal system will create record with -ve qty
            // duing reversal -- ReversalDoc_ID contain refernce o  orignal record id
            if (IsInternalUse() && Get_ColumnIndex("ReversalDoc_ID") > 0 && GetReversalDoc_ID() == 0 && GetQtyInternalUse() < 0)
            {
                log.SaveError("", Msg.GetMsg(GetCtx(), "VIS_CantbeNegative"));
                return(false);
            }

            //	Set Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_InventoryLine WHERE M_Inventory_ID=" + GetM_Inventory_ID();
                int    ii  = DB.GetSQLValue(Get_TrxName(), sql);
                SetLine(ii);
            }

            // SI_0644.1 : Enforce UOM Precision - Rounding Quantities
            if (newRecord || Is_ValueChanged("QtyInternalUse"))
            {
                SetQtyInternalUse(GetQtyInternalUse());
            }

            // change to set Converted Quantity in Internal Use Qty and AsonDateQty and difference qty if there is differnce in UOM of Base Product and UOM Selected on line
            if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID"))
            {
                Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered"));
                if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID")))
                {
                    qty = MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered")));
                    if (IsInternalUse())
                    {
                        SetQtyInternalUse(qty);
                    }
                    else
                    {
                        SetAsOnDateCount(qty);
                        SetDifferenceQty(qty);
                    }
                }
            }

            // SI_0644 - As on date and difference should be according to the precision of UOM attached.
            if (newRecord || Is_ValueChanged("AsOnDateCount"))
            {
                if (product != null)
                {
                    int precision = product.GetUOMPrecision();
                    SetAsOnDateCount(Decimal.Round(GetAsOnDateCount(), precision, MidpointRounding.AwayFromZero));
                }
            }

            // SI_0644 - As on date and difference should be according to the precision of UOM attached.
            if (newRecord || Is_ValueChanged("DifferenceQty"))
            {
                if (product != null)
                {
                    int precision = product.GetUOMPrecision();
                    SetDifferenceQty(Decimal.Round(GetDifferenceQty(), precision, MidpointRounding.AwayFromZero));
                }
            }

            // SI_0682_1 Need to update the reserved qty on requisition line by internal use line save aslo and should work as work in inventory move.
            if (Env.IsModuleInstalled("DTD001_") && IsInternalUse())
            {
                qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("QtyInternalUse"));
            }

            int    M_Warehouse_ID = 0; MWarehouse wh = null;
            string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID();

            M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry, null, Get_TrxName()));

            wh  = MWarehouse.Get(GetCtx(), M_Warehouse_ID);
            qry = "SELECT QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();
            if (GetM_AttributeSetInstance_ID() != 0)
            {
                qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
            }
            OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry, null, Get_TrxName()));
            // when record is in completed & closed stage - then no need to check qty availablity in warehouse
            if (wh.IsDisallowNegativeInv() == true &&
                (!(inventory.GetDocStatus() == "CO" || inventory.GetDocStatus() == "CL" ||
                   inventory.GetDocStatus() == "RE" || inventory.GetDocStatus() == "VO" || inventory.GetDocStatus() == "IP")))
            {
                #region DisallowNegativeInv = True
                if (!IsInternalUse() && GetDifferenceQty() > 0)
                {
                    if ((OnHandQty - GetDifferenceQty()) < 0)
                    {
                        log.SaveError("Info", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                        return(false);
                    }
                }
                else if (IsInternalUse())
                {
                    if ((OnHandQty - GetQtyInternalUse()) < 0)
                    {
                        log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                        return(false);
                    }
                }
                #endregion
            }
            //	Enforce Qty UOM
            if (newRecord || Is_ValueChanged("QtyCount"))
            {
                SetQtyCount(GetQtyCount());
            }

            //	InternalUse Inventory
            if (IsInternalUse() && Env.Signum(GetQtyInternalUse()) == 0)
            {
                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "QtyInternalUse"));
                return(false);
            }
            if (Env.Signum(GetQtyInternalUse()) != 0)
            {
                if (!INVENTORYTYPE_ChargeAccount.Equals(GetInventoryType()))
                {
                    SetInventoryType(INVENTORYTYPE_ChargeAccount);
                }
                //
                if (GetC_Charge_ID() == 0)
                {
                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "InternalUseNeedsCharge"));
                    return(false);
                }
            }
            else if (INVENTORYTYPE_ChargeAccount.Equals(GetInventoryType()))
            {
                if (GetC_Charge_ID() == 0)
                {
                    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "C_Charge_ID"));
                    return(false);
                }
            }
            else if (GetC_Charge_ID() != 0)
            {
                SetC_Charge_ID(0);
            }

            //	Set AD_Org to parent if not charge
            if (GetC_Charge_ID() == 0)
            {
                SetAD_Org_ID(GetParent().GetAD_Org_ID());
            }

            // By Amit for Obsolete Inventory - 25-May-2016
            if (Env.IsModuleInstalled("VA024_"))
            {
                //MInventory inventory = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx());
                //shipment and Return to vendor
                if (inventory.IsInternalUse() || (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0))
                {
                    try
                    {
                        string qry1 = @"SELECT  SUM(o.VA024_UnitPrice)   FROM VA024_t_ObsoleteInventory o 
                                  WHERE o.IsActive = 'Y' AND  o.M_Product_ID = " + GetM_Product_ID() + @" and 
                                  ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" +
                                      " AND o.AD_Org_ID = " + GetAD_Org_ID();
                        //+" AND M_Warehouse_ID = " + inventory.GetM_Warehouse_ID();
                        VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx()));
                        if (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0)
                        {
                            SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * (GetQtyBook() - GetQtyCount())));
                        }
                        else
                        {
                            SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetQtyInternalUse()));
                        }

                        if (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0)
                        {
                            qry1 = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + (GetQtyBook() - GetQtyCount());
                        }
                        else
                        {
                            qry1 = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + GetQtyInternalUse();
                        }
                        qry1 += @" FROM m_product p  INNER JOIN va024_t_obsoleteinventory oi ON p.m_product_id = oi.M_product_ID
                                 INNER JOIN m_product_category pc ON pc.m_product_category_ID = p.m_product_category_ID
                                 INNER JOIN AD_client c ON c.AD_Client_ID = p.Ad_Client_ID   INNER JOIN AD_ClientInfo ci  ON c.AD_Client_ID = ci.Ad_Client_ID
                                 INNER JOIN m_cost ct ON ( p.M_Product_ID     = ct.M_Product_ID  AND ci.C_AcctSchema1_ID = ct.C_AcctSchema_ID )
                                 INNER JOIN c_acctschema asch  ON (asch.C_AcctSchema_ID = ci.C_AcctSchema1_ID)
                                 INNER JOIN va024_obsoleteinvline oil ON oil.va024_obsoleteinvline_ID = oi.va024_obsoleteinvline_ID ";
                        qry1 += @"    WHERE ct.AD_Org_ID =  
                          CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" 
                               WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel  = 'C' OR pc.costinglevel = 'B')) THEN 0 
                               WHEN (pc.costinglevel IS NULL AND asch.costinglevel  = 'O') THEN " + GetAD_Org_ID() + @" 
                               WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel  = 'C' OR asch.costinglevel   = 'B')) THEN 0  END
                          AND ct.m_costelement_id =  
                          CASE WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod  != 'C') THEN  (SELECT MIN(m_costelement_id)  FROM m_costelement  
                                     WHERE m_costelement.costingmethod =pc.costingmethod  AND m_costelement.Ad_Client_ID  = oi.ad_client_id  ) 
                                WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod = 'C' ) THEN  pc.m_costelement_id 
                                WHEN ( pc.costingmethod IS NULL AND asch.costingmethod  != 'C') THEN  (SELECT MIN(m_costelement_id)  FROM m_costelement 
                                     WHERE m_costelement.costingmethod = asch.costingmethod  AND m_costelement.Ad_Client_ID  = oi.ad_client_id  )
                                WHEN ( pc.costingmethod IS NULL AND asch.costingmethod  = 'C') THEN asch.m_costelement_id  END 
                         AND NVL(ct.M_Attributesetinstance_ID , 0) =  
                         CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" 
                              WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel  = 'C' OR pc.costinglevel = 'O')) THEN 0 
                              WHEN ( pc.costinglevel IS NULL AND asch.costinglevel  = 'B') THEN " + GetM_AttributeSetInstance_ID() + @"
                              WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel  = 'C' OR asch.costinglevel   = 'O')) THEN 0  END 
                         AND p.M_Product_ID = " + GetM_Product_ID();
                        SetVA024_CostPrice(Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx())));
                    }
                    catch { }
                }
            }

            return(true);
        }
Esempio n. 13
0
        }       //	prepare

        /// <summary>
        /// Perrform Process.
        /// </summary>
        /// <returns>Info</returns>
        protected override String DoIt()
        {
            log.Info("M_Locator_ID=" + _M_Locator_ID + ",MovementDate=" + _MovementDate);
            //
            StringBuilder sql         = null;
            int           no          = 0;
            String        clientCheck = " AND AD_Client_ID=" + _AD_Client_ID;

            //	****	Prepare	****

            //	Delete Old Imported
            if (_DeleteOldImported)
            {
                sql = new StringBuilder("DELETE FROM I_Inventory "
                                        + "WHERE I_IsImported='Y'").Append(clientCheck);
                no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
                log.Fine("Delete Old Impored =" + no);
            }

            //	Set Client, Org, Location, IsActive, Created/Updated
            sql = new StringBuilder("UPDATE I_Inventory "
                                    + "SET AD_Client_ID = COALESCE (AD_Client_ID,").Append(_AD_Client_ID).Append("),"
                                                                                                                 + " AD_Org_ID = COALESCE (AD_Org_ID,").Append(_AD_Org_ID).Append("),");
            if (_MovementDate != null)
            {
                sql.Append(" MovementDate = COALESCE (MovementDate,").Append(DataBase.DB.TO_DATE(_MovementDate)).Append("),");
            }
            sql.Append(" IsActive = COALESCE (IsActive, 'Y'),"
                       + " Created = COALESCE (Created, SysDate),"
                       + " CreatedBy = COALESCE (CreatedBy, 0),"
                       + " Updated = COALESCE (Updated, SysDate),"
                       + " UpdatedBy = COALESCE (UpdatedBy, 0),"
                       + " I_ErrorMsg = NULL,"
                       + " M_Warehouse_ID = NULL," //	reset
                       + " I_IsImported = 'N' "
                       + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Info("Reset=" + no);

            String ts = DataBase.DB.IsPostgreSQL() ? "COALESCE(I_ErrorMsg,'')" : "I_ErrorMsg";  //java bug, it could not be used directly

            sql = new StringBuilder("UPDATE I_Inventory o "
                                    + "SET I_IsImported='E', I_ErrorMsg=" + ts + "||'ERR=Invalid Org, '"
                                    + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0"
                                    + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            if (no != 0)
            {
                log.Warning("Invalid Org=" + no);
            }

            // gwu: bug 1703137
            // if Warehouse key provided, get Warehouse ID
            sql = new StringBuilder("UPDATE I_Inventory i "
                                    + "SET M_Warehouse_ID=(SELECT MAX(M_Warehouse_ID) FROM M_Warehouse w"
                                    + " WHERE i.WarehouseValue=w.Value AND i.AD_Client_ID=w.AD_Client_ID) "
                                    + "WHERE M_Warehouse_ID IS NULL AND WarehouseValue IS NOT NULL"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Set Warehouse from Value =" + no);

            //	Location
            sql = new StringBuilder("UPDATE I_Inventory i "
                                    + "SET M_Locator_ID=(SELECT MAX(M_Locator_ID) FROM M_Locator l"
                                    + " WHERE i.LocatorValue=l.Value AND COALESCE (i.M_Warehouse_ID, l.M_Warehouse_ID)=l.M_Warehouse_ID AND i.AD_Client_ID=l.AD_Client_ID) "
                                    + "WHERE M_Locator_ID IS NULL AND LocatorValue IS NOT NULL"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Set Locator from Value =" + no);
            sql = new StringBuilder("UPDATE I_Inventory i "
                                    + "SET M_Locator_ID=(SELECT MAX(M_Locator_ID) FROM M_Locator l"
                                    + " WHERE i.X=l.X AND i.Y=l.Y AND i.Z=l.Z AND COALESCE (i.M_Warehouse_ID, l.M_Warehouse_ID)=l.M_Warehouse_ID AND i.AD_Client_ID=l.AD_Client_ID) "
                                    + "WHERE M_Locator_ID IS NULL AND X IS NOT NULL AND Y IS NOT NULL AND Z IS NOT NULL"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Set Locator from X,Y,Z =" + no);
            if (_M_Locator_ID != 0)
            {
                sql = new StringBuilder("UPDATE I_Inventory "
                                        + "SET M_Locator_ID = ").Append(_M_Locator_ID).Append(
                    " WHERE M_Locator_ID IS NULL"
                    + " AND I_IsImported<>'Y'").Append(clientCheck);
                no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
                log.Fine("Set Locator from Parameter=" + no);
            }
            sql = new StringBuilder("UPDATE I_Inventory "
                                    + "SET I_IsImported='E', I_ErrorMsg=" + ts + "||'ERR=No Location, ' "
                                    + "WHERE M_Locator_ID IS NULL"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            if (no != 0)
            {
                log.Warning("No Location=" + no);
            }


            //	Set M_Warehouse_ID
            sql = new StringBuilder("UPDATE I_Inventory i "
                                    + "SET M_Warehouse_ID=(SELECT M_Warehouse_ID FROM M_Locator l WHERE i.M_Locator_ID=l.M_Locator_ID) "
                                    + "WHERE M_Locator_ID IS NOT NULL"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Set Warehouse from Locator =" + no);
            sql = new StringBuilder("UPDATE I_Inventory "
                                    + "SET I_IsImported='E', I_ErrorMsg=" + ts + "||'ERR=No Warehouse, ' "
                                    + "WHERE M_Warehouse_ID IS NULL"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            if (no != 0)
            {
                log.Warning("No Warehouse=" + no);
            }


            //	Product
            sql = new StringBuilder("UPDATE I_Inventory i "
                                    + "SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p"
                                    + " WHERE i.Value=p.Value AND i.AD_Client_ID=p.AD_Client_ID) "
                                    + "WHERE M_Product_ID IS NULL AND Value IS NOT NULL"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Set Product from Value=" + no);
            sql = new StringBuilder("UPDATE I_Inventory i "
                                    + "SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p"
                                    + " WHERE i.UPC=p.UPC AND i.AD_Client_ID=p.AD_Client_ID) "
                                    + "WHERE M_Product_ID IS NULL AND UPC IS NOT NULL"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Set Product from UPC=" + no);
            sql = new StringBuilder("UPDATE I_Inventory "
                                    + "SET I_IsImported='E', I_ErrorMsg=" + ts + "||'ERR=No Product, ' "
                                    + "WHERE M_Product_ID IS NULL"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            if (no != 0)
            {
                log.Warning("No Product=" + no);
            }

            //	No QtyCount
            sql = new StringBuilder("UPDATE I_Inventory "
                                    + "SET I_IsImported='E', I_ErrorMsg=" + ts + "||'ERR=No Qty Count, ' "
                                    + "WHERE QtyCount IS NULL"
                                    + " AND I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            if (no != 0)
            {
                log.Warning("No QtyCount=" + no);
            }

            Commit();

            /*********************************************************************/

            MInventory inventory = null;

            int noInsert     = 0;
            int noInsertLine = 0;

            //	Go through Inventory Records
            sql = new StringBuilder("SELECT * FROM I_Inventory "
                                    + "WHERE I_IsImported='N'").Append(clientCheck)
                  .Append(" ORDER BY M_Warehouse_ID, TRUNC(MovementDate,'DD'), I_Inventory_ID");
            IDataReader idr = null;

            try
            {
                //PreparedStatement pstmt = DataBase.prepareStatement (sql.ToString (), Get_TrxName());
                //ResultSet rs = pstmt.executeQuery ();
                idr = DataBase.DB.ExecuteReader(sql.ToString(), null, Get_TrxName());
                //
                int      x_M_Warehouse_ID = -1;
                DateTime?x_MovementDate   = null;
                while (idr.Read())
                {
                    X_I_Inventory imp          = new X_I_Inventory(GetCtx(), idr, Get_TrxName());
                    DateTime?     MovementDate = TimeUtil.GetDay(imp.GetMovementDate());

                    if (inventory == null ||
                        imp.GetM_Warehouse_ID() != x_M_Warehouse_ID ||
                        !MovementDate.Equals(x_MovementDate))
                    {
                        inventory = new MInventory(GetCtx(), 0, Get_TrxName());
                        inventory.SetClientOrg(imp.GetAD_Client_ID(), imp.GetAD_Org_ID());
                        inventory.SetDescription("I " + imp.GetM_Warehouse_ID() + " " + MovementDate);
                        inventory.SetM_Warehouse_ID(imp.GetM_Warehouse_ID());
                        inventory.SetMovementDate(MovementDate);
                        //
                        if (!inventory.Save())
                        {
                            log.Log(Level.SEVERE, "Inventory not saved");
                            break;
                        }
                        x_M_Warehouse_ID = imp.GetM_Warehouse_ID();
                        x_MovementDate   = MovementDate;
                        noInsert++;
                    }

                    //	Line
                    int M_AttributeSetInstance_ID = 0;
                    if (imp.GetLot() != null || imp.GetSerNo() != null)
                    {
                        MProduct product = MProduct.Get(GetCtx(), imp.GetM_Product_ID());
                        if (product.IsInstanceAttribute())
                        {
                            MAttributeSet         mas  = product.GetAttributeSet();
                            MAttributeSetInstance masi = new MAttributeSetInstance(GetCtx(), 0, mas.GetM_AttributeSet_ID(), Get_TrxName());
                            if (mas.IsLot() && imp.GetLot() != null)
                            {
                                masi.SetLot(imp.GetLot(), imp.GetM_Product_ID());
                            }
                            if (mas.IsSerNo() && imp.GetSerNo() != null)
                            {
                                masi.SetSerNo(imp.GetSerNo());
                            }
                            masi.SetDescription();
                            masi.Save();
                            M_AttributeSetInstance_ID = masi.GetM_AttributeSetInstance_ID();
                        }
                    }
                    MInventoryLine line = new MInventoryLine(inventory,
                                                             imp.GetM_Locator_ID(), imp.GetM_Product_ID(), M_AttributeSetInstance_ID,
                                                             imp.GetQtyBook(), imp.GetQtyCount());
                    if (line.Save())
                    {
                        imp.SetI_IsImported(X_I_Inventory.I_ISIMPORTED_Yes);
                        imp.SetM_Inventory_ID(line.GetM_Inventory_ID());
                        imp.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID());
                        imp.SetProcessed(true);
                        if (imp.Save())
                        {
                            noInsertLine++;
                        }
                    }
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql.ToString(), e);
            }

            //	Set Error to indicator to not imported
            sql = new StringBuilder("UPDATE I_Inventory "
                                    + "SET I_IsImported='N', Updated=SysDate "
                                    + "WHERE I_IsImported<>'Y'").Append(clientCheck);
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            AddLog(0, null, Utility.Util.GetValueOfDecimal(no), "@Errors@");
            //
            AddLog(0, null, Utility.Util.GetValueOfDecimal(noInsert), "@M_Inventory_ID@: @Inserted@");
            AddLog(0, null, Utility.Util.GetValueOfDecimal(noInsertLine), "@M_InventoryLine_ID@: @Inserted@");
            return("");
        }       //	doIt