public PartnerErrorResult SaveDCanabalizeMaster(DCanabalizeMaster argDCanabalizeMaster, DCanabalizeDetailsCol argDCanabalizeDetailsCol)
        {
            List <ErrorHandler>           lstErr                  = new List <ErrorHandler>();
            PartnerErrorResult            errorcol                = new PartnerErrorResult();
            PartnerGoodsMovementManager   objPartnerGMManager     = new PartnerGoodsMovementManager();
            PartnerMaterialDocTypeManager objPartnerMatDocTypeMan = new PartnerMaterialDocTypeManager();

            DataAccess da = new DataAccess();

            string strretValue            = "";
            string strProductGoodsMovCode = "";
            string strSpareGoodsMovCode   = "";

            DataSet dsMatDocType = null;

            try
            {
                da.Open_Connection();
                da.BEGIN_TRANSACTION();
                if (blnIsDCanabalizeMasterExists(argDCanabalizeMaster.DCanabalizeDocNo, argDCanabalizeMaster.PartnerCode, argDCanabalizeMaster.ClientCode, da) == false)
                {
                    if (argDCanabalizeMaster.PGoodsMovementCode == "NEW")
                    {
                        if (argDCanabalizeMaster.MaterialDocTypeCode != "")
                        {
                            strProductGoodsMovCode = objPartnerGMManager.GenerateGMCode("NEW", "GM01", argDCanabalizeMaster.PartnerCode, argDCanabalizeMaster.ClientCode, da);
                            argDCanabalizeMaster.PGoodsMovementCode = strProductGoodsMovCode;
                            argDCanabalizeMaster.GMItemNo           = 1;
                        }
                        else
                        {
                            argDCanabalizeMaster.PGoodsMovementCode = "";
                            argDCanabalizeMaster.GMItemNo           = 0;
                        }
                    }


                    strretValue = InsertDCanabalizeMaster(argDCanabalizeMaster, da, lstErr);
                }
                else
                {
                    strretValue = UpdateDCanabalizeMaster(argDCanabalizeMaster, da, lstErr);
                }
                foreach (ErrorHandler objerr in lstErr)
                {
                    if (objerr.Type == "E")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }

                    if (objerr.Type == "A")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }
                }

                if (strretValue != "")
                {
                    //if (argSerializeStockMissingPartsCol.colSerializeStockMissingParts.Count > 0)
                    //{

                    //    foreach (SerializeStockMissingParts objSerializeStockMissingParts in argSerializeStockMissingPartsCol.colSerializeStockMissingParts)
                    //    {
                    //        if (Convert.ToString(objSerializeStockMissingParts.SerialNo).Trim() == Convert.ToString(argDCanabalizeMaster.SerialNo).Trim())
                    //        {
                    //            objSerializeStockMissingPartsManager.SaveSerializeStockMissingParts(objSerializeStockMissingParts, da, lstErr);
                    //        }
                    //    }

                    //}



                    if (argDCanabalizeDetailsCol.colDCanabalizeDetails.Count > 0)
                    {
                        foreach (DCanabalizeDetails objDCanabalizeDetails in argDCanabalizeDetailsCol.colDCanabalizeDetails)
                        {
                            if (objDCanabalizeDetails.IsDeleted == 0)
                            {
                                if (objDCanabalizeDetails.PGoodsMovementCode == "NEW")
                                {
                                    strSpareGoodsMovCode = objPartnerGMManager.GenerateGMCode("NEW", "GM01", argDCanabalizeMaster.PartnerCode, argDCanabalizeMaster.ClientCode, da);
                                    objDCanabalizeDetails.PGoodsMovementCode = strSpareGoodsMovCode;
                                    objDCanabalizeDetails.GMItemNo           = objDCanabalizeDetails.DCanabalizeItemNo;
                                }

                                objDCanabalizeDetails.DCanabalizeDocNo = strretValue;
                                objDCanabalizeDetailsManager.SaveDCanabalizeDetails(objDCanabalizeDetails, da, lstErr);
                            }
                            else
                            {
                                /***************************/

                                /*** Delete Fucntion ***/

                                /***************************/
                            }
                        }

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }

                            if (objerr.Type == "A")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }
                        }
                    }


                    /* Partner Goods Movement Declared for Spares */
                    if (argDCanabalizeDetailsCol.colDCanabalizeDetails.Count > 0)
                    {
                        PartnerGoodsMovement objPartnerSpareGM = new PartnerGoodsMovement();
                        objPartnerSpareGM.PGoodsMovementCode      = strSpareGoodsMovCode;
                        objPartnerSpareGM.PartnerGMDocTypeCode    = "GM01";
                        objPartnerSpareGM.FromPlantCode           = "";
                        objPartnerSpareGM.FromPartnerCode         = Convert.ToString(argDCanabalizeMaster.PartnerCode);
                        objPartnerSpareGM.FromPartnerEmployeeCode = "";
                        objPartnerSpareGM.FromStoreCode           = "";
                        objPartnerSpareGM.ToPartnerCode           = Convert.ToString(argDCanabalizeMaster.PartnerCode);
                        objPartnerSpareGM.ToPlantCode             = "";
                        objPartnerSpareGM.ToStoreCode             = "";
                        objPartnerSpareGM.ToPartnerEmployeeCode   = "";
                        objPartnerSpareGM.ClientCode    = argDCanabalizeMaster.ClientCode;
                        objPartnerSpareGM.CreatedBy     = argDCanabalizeMaster.CreatedBy;
                        objPartnerSpareGM.ModifiedBy    = argDCanabalizeMaster.ModifiedBy;
                        objPartnerSpareGM.TotalQuantity = 0;
                        objPartnerSpareGM.PartnerCode   = Convert.ToString(argDCanabalizeMaster.PartnerCode);
                        objPartnerSpareGM.GoodsMovDate  = Convert.ToDateTime(argDCanabalizeMaster.DCanablizeDate);

                        /*----------------------------------------------------------------------------------------*/
                        /* Partner Goods Movement Detail */
                        PartnerGoodsMovementDetailCol  objPartnerSpareGMCol       = new PartnerGoodsMovementDetailCol();
                        PartnerGoodsMovSerialDetailCol objPartnerSpareGMSerialCol = new PartnerGoodsMovSerialDetailCol();

                        objPartnerSpareGMCol.colPartnerGMDetail             = new List <PartnerGoodsMovementDetail>();
                        objPartnerSpareGMSerialCol.colPartnerGMSerialDetail = new List <PartnerGoodsMovSerialDetail>();
                        bool IsNew     = true;
                        int  iCtr      = 0;
                        int  tmpItemNo = 0;
                        foreach (DCanabalizeDetails objDCanabalizeDetails in argDCanabalizeDetailsCol.colDCanabalizeDetails)
                        {
                            if (objDCanabalizeDetails.IsDeleted == 0)
                            {
                                dsMatDocType = new DataSet();
                                iCtr         = iCtr + 1;
                                tmpItemNo    = iCtr;
                                if (IsNew == true)
                                {
                                    dsMatDocType = objPartnerMatDocTypeMan.GetPartnerMaterialDocType(objDCanabalizeDetails.MaterialDocTypeCode, objDCanabalizeDetails.ClientCode, da);

                                    PartnerGoodsMovementDetail objPartnerGMDetailsnew = new PartnerGoodsMovementDetail();
                                    objPartnerGMDetailsnew.PGoodsMovementCode  = strSpareGoodsMovCode;
                                    objPartnerGMDetailsnew.ItemNo              = tmpItemNo;
                                    objPartnerGMDetailsnew.MaterialCode        = Convert.ToString(objDCanabalizeDetails.MaterialCode);
                                    objPartnerGMDetailsnew.MatGroup1Code       = Convert.ToString(objDCanabalizeDetails.MatGroup1Code);
                                    objPartnerGMDetailsnew.StockIndicator      = Convert.ToString(objDCanabalizeDetails.StockIndicator);
                                    objPartnerGMDetailsnew.ToStockIndicator    = Convert.ToString(objDCanabalizeDetails.ToStockIndicator);
                                    objPartnerGMDetailsnew.Quantity            = Convert.ToInt32(objDCanabalizeDetails.Quantity);
                                    objPartnerGMDetailsnew.UOMCode             = Convert.ToString(objDCanabalizeDetails.UOMCode);
                                    objPartnerGMDetailsnew.ClientCode          = Convert.ToString(objDCanabalizeDetails.ClientCode);
                                    objPartnerGMDetailsnew.CreatedBy           = Convert.ToString(objDCanabalizeDetails.CreatedBy);
                                    objPartnerGMDetailsnew.ModifiedBy          = Convert.ToString(objDCanabalizeDetails.ModifiedBy);
                                    objPartnerGMDetailsnew.TranRefDocCode      = Convert.ToString(strretValue);
                                    objPartnerGMDetailsnew.TranRefDocItemNo    = Convert.ToInt32(objDCanabalizeDetails.DCanabalizeItemNo);
                                    objPartnerGMDetailsnew.MaterialDocTypeCode = Convert.ToString(objDCanabalizeDetails.MaterialDocTypeCode);
                                    objPartnerGMDetailsnew.PartnerCode         = Convert.ToString(objDCanabalizeDetails.PartnerCode);

                                    if (dsMatDocType != null)
                                    {
                                        if (dsMatDocType.Tables[0].Rows.Count > 0)
                                        {
                                            if (dsMatDocType.Tables[0].Rows[0]["FromPlant"].ToString() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.FromPlantCode = "";
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.FromPlantCode = "";
                                            }

                                            if (dsMatDocType.Tables[0].Rows[0]["FromPartner"].ToString() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.FromPartnerCode = Convert.ToString(objDCanabalizeDetails.PartnerCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.FromPartnerCode = "";
                                            }

                                            if (dsMatDocType.Tables[0].Rows[0]["FromStore"].ToString() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.FromStoreCode = Convert.ToString(objDCanabalizeDetails.StoreCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.FromStoreCode = "";
                                            }

                                            if (dsMatDocType.Tables[0].Rows[0]["FromEmployee"].ToString() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.FromPartnerEmployeeCode = Convert.ToString(objDCanabalizeDetails.PartnerEmployeeCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.FromPartnerEmployeeCode = "";
                                            }

                                            if (dsMatDocType.Tables[0].Rows[0]["ToPartner"].ToString() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToPartnerCode = Convert.ToString(objDCanabalizeDetails.PartnerCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToPartnerCode = "";
                                            }

                                            if (dsMatDocType.Tables[0].Rows[0]["ToStore"].ToString() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToStoreCode = Convert.ToString(objDCanabalizeDetails.ToStoreCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToStoreCode = "";
                                            }

                                            if (dsMatDocType.Tables[0].Rows[0]["ToEmployee"].ToString() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToPartnerEmployeeCode = Convert.ToString(objDCanabalizeDetails.ToPartnerEmployeeCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToPartnerEmployeeCode = "";
                                            }

                                            if (dsMatDocType.Tables[0].Rows[0]["ToPlant"].ToString() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToPlantCode = "";
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToPlantCode = "";
                                            }

                                            if (dsMatDocType.Tables[0].Rows[0]["ToMaterialCode"].ToString() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToMaterialCode = Convert.ToString(objDCanabalizeDetails.MaterialCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToMaterialCode = "";
                                            }
                                        }
                                        else
                                        {
                                            objPartnerGMDetailsnew.FromPlantCode           = "";
                                            objPartnerGMDetailsnew.FromPartnerCode         = Convert.ToString(objDCanabalizeDetails.PartnerCode);
                                            objPartnerGMDetailsnew.FromPartnerEmployeeCode = Convert.ToString(objDCanabalizeDetails.PartnerEmployeeCode);
                                            objPartnerGMDetailsnew.FromStoreCode           = Convert.ToString(objDCanabalizeDetails.StoreCode);
                                            objPartnerGMDetailsnew.ToPartnerCode           = Convert.ToString(objDCanabalizeDetails.PartnerCode);
                                            objPartnerGMDetailsnew.ToPartnerEmployeeCode   = Convert.ToString(objDCanabalizeDetails.ToPartnerEmployeeCode);
                                            objPartnerGMDetailsnew.ToPlantCode             = "";
                                            objPartnerGMDetailsnew.ToStoreCode             = Convert.ToString(objDCanabalizeDetails.ToStoreCode);
                                            objPartnerGMDetailsnew.ToMaterialCode          = Convert.ToString(objDCanabalizeDetails.MaterialCode);
                                        }
                                    }

                                    objPartnerSpareGMCol.colPartnerGMDetail.Add(objPartnerGMDetailsnew);
                                    /*Partner Goods Movement Serial Detail*/
                                    if (objDCanabalizeDetails.SerialNo1 != "")
                                    {
                                        /*Partner Goods Movement Serial Detail*/

                                        PartnerGoodsMovSerialDetail objPartnerGoodsMovSerialnew = new PartnerGoodsMovSerialDetail();
                                        objPartnerGoodsMovSerialnew.PGoodsMovementCode = strSpareGoodsMovCode;
                                        objPartnerGoodsMovSerialnew.ItemNo             = tmpItemNo;
                                        objPartnerGoodsMovSerialnew.SerialNo1          = Convert.ToString(objDCanabalizeDetails.SerialNo1);
                                        objPartnerGoodsMovSerialnew.SerialNo2          = Convert.ToString("");
                                        objPartnerGoodsMovSerialnew.MaterialCode       = Convert.ToString(objDCanabalizeDetails.MaterialCode);
                                        objPartnerGoodsMovSerialnew.MatGroup1Code      = Convert.ToString(objDCanabalizeDetails.MatGroup1Code);
                                        objPartnerGoodsMovSerialnew.RefDocCode         = Convert.ToString(objDCanabalizeDetails.RefDocCode);
                                        objPartnerGoodsMovSerialnew.RefDocItemNo       = Convert.ToInt32(objDCanabalizeDetails.RefDocItemNo);
                                        objPartnerGoodsMovSerialnew.RefDocType         = Convert.ToString(objDCanabalizeDetails.RefDocTypeCode);
                                        objPartnerGoodsMovSerialnew.TranRefDocCode     = Convert.ToString(strretValue);
                                        objPartnerGoodsMovSerialnew.TranRefDocItemNo   = Convert.ToInt32(objDCanabalizeDetails.DCanabalizeItemNo);
                                        objPartnerGoodsMovSerialnew.IsDeleted          = 0;
                                        objPartnerGoodsMovSerialnew.ClientCode         = Convert.ToString(objDCanabalizeDetails.ClientCode);
                                        objPartnerGoodsMovSerialnew.CreatedBy          = Convert.ToString(objDCanabalizeDetails.CreatedBy);
                                        objPartnerGoodsMovSerialnew.ModifiedBy         = Convert.ToString(objDCanabalizeDetails.ModifiedBy);
                                        objPartnerGoodsMovSerialnew.StockIndicator     = Convert.ToString(objDCanabalizeDetails.StockIndicator);
                                        objPartnerGoodsMovSerialnew.ToStockIndicator   = Convert.ToString(objDCanabalizeDetails.ToStockIndicator);


                                        if (dsMatDocType != null)
                                        {
                                            if (dsMatDocType.Tables[0].Rows.Count > 0)
                                            {
                                                if (dsMatDocType.Tables[0].Rows[0]["FromPlant"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.PlantCode = "";
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.PlantCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["FromPartner"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.PartnerCode = Convert.ToString(objDCanabalizeDetails.PartnerCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.PartnerCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["FromStore"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.StoreCode = Convert.ToString(objDCanabalizeDetails.StoreCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.StoreCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["FromEmployee"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.PartnerEmployeeCode = Convert.ToString(objDCanabalizeDetails.PartnerEmployeeCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.PartnerEmployeeCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["ToPartner"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPartnerCode = Convert.ToString(objDCanabalizeDetails.PartnerCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPartnerCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["ToStore"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToStoreCode = Convert.ToString(objDCanabalizeDetails.ToStoreCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToStoreCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["ToEmployee"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPartnerEmployeeCode = Convert.ToString(objDCanabalizeDetails.ToPartnerEmployeeCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPartnerEmployeeCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["ToPlant"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPlantCode = "";
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPlantCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["ToMaterialCode"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToMaterialCode = Convert.ToString(objDCanabalizeDetails.MaterialCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToMaterialCode = "";
                                                }
                                            }
                                            else
                                            {
                                            }
                                        }

                                        objPartnerSpareGMSerialCol.colPartnerGMSerialDetail.Add(objPartnerGoodsMovSerialnew);
                                    }
                                }
                            }
                        }
                        /*Partner Spare Goods Movement Save*/
                        if (objPartnerSpareGMCol.colPartnerGMDetail.Count > 0)
                        {
                            objPartnerGMManager.SavePartnerGoodsMovement(objPartnerSpareGM, objPartnerSpareGMCol, objPartnerSpareGMSerialCol, da, lstErr);

                            foreach (ErrorHandler objerr in lstErr)
                            {
                                if (objerr.Type == "E")
                                {
                                    errorcol.colErrorHandler.Add(objerr);
                                    da.ROLLBACK_TRANSACTION();
                                    return(errorcol);
                                }

                                if (objerr.Type == "A")
                                {
                                    errorcol.colErrorHandler.Add(objerr);
                                    da.ROLLBACK_TRANSACTION();
                                    return(errorcol);
                                }
                            }
                        }
                    }
                }



                da.COMMIT_TRANSACTION();
            }
            catch (Exception ex)
            {
                if (da != null)
                {
                    da.ROLLBACK_TRANSACTION();
                }
                objErrorHandler.Type       = ErrorConstant.strAboartType;
                objErrorHandler.MsgId      = 0;
                objErrorHandler.Module     = ErrorConstant.strInsertModule;
                objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
                objErrorHandler.Message    = ex.Message.ToString();
                objErrorHandler.RowNo      = 0;
                objErrorHandler.FieldName  = "";
                objErrorHandler.LogCode    = "";
                lstErr.Add(objErrorHandler);
                errorcol.colErrorHandler.Add(objErrorHandler);
            }
            finally
            {
                if (da != null)
                {
                    da.Close_Connection();
                    da = null;
                }
            }
            return(errorcol);
        }
Пример #2
0
        public PartnerErrorResult SaveAsgTechnicianCallMaster(AsgTechnicianCallMaster argAsgTechnicianCallMaster, AsgTechnicianCallDetailCol argAsgTechCallDetailCol)
        {
            List <ErrorHandler>         lstErr              = new List <ErrorHandler>();
            PartnerErrorResult          errorcol            = new PartnerErrorResult();
            PartnerGoodsMovementManager objPartnerGMManager = new PartnerGoodsMovementManager();

            DataAccess da          = new DataAccess();
            string     strretValue = "";

            try
            {
                da.Open_Connection();
                da.BEGIN_TRANSACTION();

                if (blnIsAsgTechnicianCallMasterExists(argAsgTechnicianCallMaster.AsgTechCallCode, argAsgTechnicianCallMaster.PartnerCode, argAsgTechnicianCallMaster.ClientCode, da) == false)
                {
                    strretValue = InsertAsgTechnicianCallMaster(argAsgTechnicianCallMaster, da, lstErr);
                }
                else
                {
                    strretValue = UpdateAsgTechnicianCallMaster(argAsgTechnicianCallMaster, da, lstErr);
                }

                foreach (ErrorHandler objerr in lstErr)
                {
                    if (objerr.Type == "E")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }

                    if (objerr.Type == "A")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }
                }

                if (strretValue != "")
                {
                    string strGoodsMovementCode = "";
                    if (argAsgTechnicianCallMaster.AssignType.Trim() != "CALL")
                    {
                        strGoodsMovementCode = objPartnerGMManager.GenerateGMCode("NEW", "GM01", argAsgTechnicianCallMaster.PartnerCode, argAsgTechnicianCallMaster.ClientCode, da);
                    }

                    if (argAsgTechCallDetailCol.colAsgTechnicianCallDetail.Count > 0)
                    {
                        foreach (AsgTechnicianCallDetail objAsgTechnicianCallDetail in argAsgTechCallDetailCol.colAsgTechnicianCallDetail)
                        {
                            objAsgTechnicianCallDetail.AsgTechCallCode = strretValue;

                            if (argAsgTechnicianCallMaster.AssignType.Trim() != "CALL")
                            {
                                objAsgTechnicianCallDetail.PGoodsMovementCode = strGoodsMovementCode;
                                objAsgTechnicianCallDetail.GMItemNo           = objAsgTechnicianCallDetail.ItemNo;
                            }

                            if (objAsgTechnicianCallDetail.IsDeleted == 0)
                            {
                                objAsgTechnicianCallDetailMan.SaveAsgTechnicianCallDetail(objAsgTechnicianCallDetail, da, lstErr);
                            }
                            else
                            {
                                /*Delete function*/
                            }
                        }

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }

                            if (objerr.Type == "A")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }
                        }
                    }

                    if (argAsgTechnicianCallMaster.AssignType.Trim().ToUpper() != "CALL")
                    {
                        /* Partner Goods Movement Declared */
                        PartnerGoodsMovement objPartnerGM = new PartnerGoodsMovement();

                        objPartnerGM.PGoodsMovementCode      = strGoodsMovementCode;
                        objPartnerGM.PartnerGMDocTypeCode    = "GM01";
                        objPartnerGM.FromPlantCode           = "";
                        objPartnerGM.FromPartnerCode         = "";
                        objPartnerGM.FromPartnerEmployeeCode = "";
                        objPartnerGM.FromStoreCode           = "";
                        objPartnerGM.ToPartnerCode           = Convert.ToString(argAsgTechnicianCallMaster.PartnerCode);
                        objPartnerGM.ToPlantCode             = "";
                        objPartnerGM.ToStoreCode             = "";
                        objPartnerGM.ToPartnerEmployeeCode   = Convert.ToString(argAsgTechnicianCallMaster.PartnerEmployeeCode);
                        objPartnerGM.GoodsMovDate            = Convert.ToDateTime(argAsgTechnicianCallMaster.AssignDate);
                        objPartnerGM.ClientCode    = argAsgTechnicianCallMaster.ClientCode;
                        objPartnerGM.CreatedBy     = argAsgTechnicianCallMaster.CreatedBy;
                        objPartnerGM.ModifiedBy    = argAsgTechnicianCallMaster.ModifiedBy;
                        objPartnerGM.TotalQuantity = 0;
                        objPartnerGM.PartnerCode   = argAsgTechnicianCallMaster.PartnerCode;


                        /*----------------------------------------------------------------------------------------*/

                        /* Partner Goods Movement Detail */
                        PartnerMaterialDocTypeManager objPartnerMatDocTypeMan = new PartnerMaterialDocTypeManager();

                        PartnerGoodsMovementDetailCol  objPartnerGMCol       = new PartnerGoodsMovementDetailCol();
                        PartnerGoodsMovSerialDetailCol objPartnerGMSerialCol = new PartnerGoodsMovSerialDetailCol();

                        objPartnerGMCol.colPartnerGMDetail             = new List <PartnerGoodsMovementDetail>();
                        objPartnerGMSerialCol.colPartnerGMSerialDetail = new List <PartnerGoodsMovSerialDetail>();

                        DataSet dsMatDocType = null;
                        bool    IsNew        = true;
                        int     iCtr         = 0;
                        int     tmpItemNo    = 0;

                        foreach (AsgTechnicianCallDetail objAsgTechCallDetail in argAsgTechCallDetailCol.colAsgTechnicianCallDetail)
                        {
                            if (objAsgTechCallDetail.IsDeleted == 0)
                            {
                                dsMatDocType = new DataSet();

                                if (IsNew == true)
                                {
                                    iCtr = iCtr + 1;

                                    dsMatDocType = objPartnerMatDocTypeMan.GetPartnerMaterialDocType(objAsgTechCallDetail.MaterialDocTypeCode, objAsgTechCallDetail.ClientCode, da);

                                    PartnerGoodsMovementDetail objPartnerGMDetailsnew = new PartnerGoodsMovementDetail();
                                    objPartnerGMDetailsnew.PGoodsMovementCode = strGoodsMovementCode;
                                    objPartnerGMDetailsnew.ItemNo             = iCtr;
                                    tmpItemNo = iCtr;
                                    objPartnerGMDetailsnew.MaterialCode        = Convert.ToString(objAsgTechCallDetail.MaterialCode);
                                    objPartnerGMDetailsnew.MatGroup1Code       = Convert.ToString(objAsgTechCallDetail.MaterialCode);
                                    objPartnerGMDetailsnew.Quantity            = Convert.ToInt32(objAsgTechCallDetail.Quantity);
                                    objPartnerGMDetailsnew.UOMCode             = Convert.ToString(objAsgTechCallDetail.UOMCode);
                                    objPartnerGMDetailsnew.ClientCode          = Convert.ToString(objAsgTechCallDetail.ClientCode);
                                    objPartnerGMDetailsnew.CreatedBy           = Convert.ToString(objAsgTechCallDetail.CreatedBy);
                                    objPartnerGMDetailsnew.ModifiedBy          = Convert.ToString(objAsgTechCallDetail.ModifiedBy);
                                    objPartnerGMDetailsnew.TranRefDocCode      = Convert.ToString(strretValue);
                                    objPartnerGMDetailsnew.TranRefDocItemNo    = Convert.ToInt32(objAsgTechCallDetail.ItemNo);
                                    objPartnerGMDetailsnew.MaterialDocTypeCode = Convert.ToString(objAsgTechCallDetail.MaterialDocTypeCode);
                                    objPartnerGMDetailsnew.PartnerCode         = Convert.ToString(objAsgTechCallDetail.PartnerCode);
                                    if (dsMatDocType != null)
                                    {
                                        if (dsMatDocType.Tables[0].Rows.Count > 0)
                                        {
                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["AllowedFromStock"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.StockIndicator = Convert.ToString(objAsgTechCallDetail.StockIndicator);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.StockIndicator = "";
                                            }

                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["AllowedToStock"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToStockIndicator = Convert.ToString(objAsgTechCallDetail.ToStockIndicator);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToStockIndicator = "";
                                            }

                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["FromPlant"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.FromPlantCode = "";
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.FromPlantCode = "";
                                            }

                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["FromPartner"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.FromPartnerCode = Convert.ToString(objAsgTechCallDetail.PartnerCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.FromPartnerCode = "";
                                            }

                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["FromStore"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.FromStoreCode = Convert.ToString(objAsgTechCallDetail.StoreCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.FromStoreCode = "";
                                            }

                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["FromEmployee"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.FromPartnerEmployeeCode = Convert.ToString(objAsgTechCallDetail.FromPartnerEmployeeCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.FromPartnerEmployeeCode = "";
                                            }

                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["ToPartner"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToPartnerCode = Convert.ToString(objAsgTechCallDetail.ToPartnerCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToPartnerCode = "";
                                            }

                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["ToStore"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToStoreCode = Convert.ToString(objAsgTechCallDetail.ToStoreCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToStoreCode = "";
                                            }

                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["ToEmployee"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToPartnerEmployeeCode = Convert.ToString(objAsgTechCallDetail.ToPartnerEmployeeCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToPartnerEmployeeCode = "";
                                            }

                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["ToPlant"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToPlantCode = "";
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToPlantCode = "";
                                            }

                                            if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["ToMaterialCode"]).Trim() != "HIDE")
                                            {
                                                objPartnerGMDetailsnew.ToMaterialCode = Convert.ToString(objAsgTechCallDetail.ToMaterialCode);
                                            }
                                            else
                                            {
                                                objPartnerGMDetailsnew.ToMaterialCode = "";
                                            }
                                        }
                                        else
                                        {
                                            objPartnerGMDetailsnew.FromPlantCode           = "";
                                            objPartnerGMDetailsnew.FromPartnerCode         = Convert.ToString(objAsgTechCallDetail.PartnerCode);
                                            objPartnerGMDetailsnew.FromPartnerEmployeeCode = "";
                                            objPartnerGMDetailsnew.FromStoreCode           = Convert.ToString(objAsgTechCallDetail.StoreCode);
                                            objPartnerGMDetailsnew.ToPartnerCode           = Convert.ToString(objAsgTechCallDetail.ToPartnerCode);
                                            objPartnerGMDetailsnew.ToPartnerEmployeeCode   = Convert.ToString(objAsgTechCallDetail.ToPartnerEmployeeCode);
                                            objPartnerGMDetailsnew.ToPlantCode             = "";
                                            objPartnerGMDetailsnew.ToStoreCode             = Convert.ToString(objAsgTechCallDetail.ToStoreCode);
                                            objPartnerGMDetailsnew.ToMaterialCode          = Convert.ToString(objAsgTechCallDetail.ToMaterialCode);
                                        }
                                    }

                                    objPartnerGMCol.colPartnerGMDetail.Add(objPartnerGMDetailsnew);


                                    if (objAsgTechCallDetail.SerialNo1 != "")
                                    {
                                        /*Partner Goods Movement Serial Detail*/

                                        PartnerGoodsMovSerialDetail objPartnerGoodsMovSerialnew = new PartnerGoodsMovSerialDetail();
                                        objPartnerGoodsMovSerialnew.PGoodsMovementCode = strGoodsMovementCode;
                                        objPartnerGoodsMovSerialnew.ItemNo             = tmpItemNo;
                                        objPartnerGoodsMovSerialnew.SerialNo1          = Convert.ToString(objAsgTechCallDetail.SerialNo1);
                                        objPartnerGoodsMovSerialnew.SerialNo2          = Convert.ToString(objAsgTechCallDetail.SerialNo2);
                                        objPartnerGoodsMovSerialnew.MaterialCode       = Convert.ToString(objAsgTechCallDetail.MaterialCode);
                                        objPartnerGoodsMovSerialnew.MatGroup1Code      = Convert.ToString(objAsgTechCallDetail.MatGroup1Code);
                                        objPartnerGoodsMovSerialnew.RefDocCode         = Convert.ToString(objAsgTechCallDetail.RefDocCode);
                                        objPartnerGoodsMovSerialnew.RefDocItemNo       = Convert.ToInt32(objAsgTechCallDetail.RefDocItemNo);
                                        objPartnerGoodsMovSerialnew.RefDocType         = Convert.ToString(objAsgTechCallDetail.RefDocTypeCode);
                                        objPartnerGoodsMovSerialnew.TranRefDocCode     = Convert.ToString(strretValue);
                                        objPartnerGoodsMovSerialnew.TranRefDocItemNo   = Convert.ToInt32(objAsgTechCallDetail.ItemNo);
                                        objPartnerGoodsMovSerialnew.IsDeleted          = 0;
                                        objPartnerGoodsMovSerialnew.ClientCode         = Convert.ToString(objAsgTechCallDetail.ClientCode);
                                        objPartnerGoodsMovSerialnew.CreatedBy          = Convert.ToString(objAsgTechCallDetail.CreatedBy);
                                        objPartnerGoodsMovSerialnew.ModifiedBy         = Convert.ToString(objAsgTechCallDetail.ModifiedBy);


                                        if (dsMatDocType != null)
                                        {
                                            if (dsMatDocType.Tables[0].Rows.Count > 0)
                                            {
                                                if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["AllowedFromStock"]).Trim() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.StockIndicator = Convert.ToString(objAsgTechCallDetail.StockIndicator);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.StockIndicator = "";
                                                }

                                                if (Convert.ToString(dsMatDocType.Tables[0].Rows[0]["AllowedToStock"]).Trim() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToStockIndicator = Convert.ToString(objAsgTechCallDetail.ToStockIndicator);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToStockIndicator = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["FromPlant"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.PlantCode = "";
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.PlantCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["FromPartner"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.PartnerCode = Convert.ToString(objAsgTechCallDetail.PartnerCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.PartnerCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["FromStore"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.StoreCode = Convert.ToString(objAsgTechCallDetail.StoreCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.StoreCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["FromEmployee"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.PartnerEmployeeCode = Convert.ToString(objAsgTechCallDetail.FromPartnerEmployeeCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.PartnerEmployeeCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["ToPartner"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPartnerCode = Convert.ToString(objAsgTechCallDetail.ToPartnerCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPartnerCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["ToStore"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToStoreCode = Convert.ToString(objAsgTechCallDetail.ToStoreCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToStoreCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["ToEmployee"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPartnerEmployeeCode = Convert.ToString(objAsgTechCallDetail.ToPartnerEmployeeCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPartnerEmployeeCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["ToPlant"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPlantCode = "";
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToPlantCode = "";
                                                }

                                                if (dsMatDocType.Tables[0].Rows[0]["ToMaterialCode"].ToString() != "HIDE")
                                                {
                                                    objPartnerGoodsMovSerialnew.ToMaterialCode = Convert.ToString(objAsgTechCallDetail.ToMaterialCode);
                                                }
                                                else
                                                {
                                                    objPartnerGoodsMovSerialnew.ToMaterialCode = "";
                                                }
                                            }
                                            else
                                            {
                                                objPartnerGoodsMovSerialnew.PlantCode             = "";
                                                objPartnerGoodsMovSerialnew.PartnerCode           = Convert.ToString(objAsgTechCallDetail.PartnerCode);
                                                objPartnerGoodsMovSerialnew.PartnerEmployeeCode   = "";
                                                objPartnerGoodsMovSerialnew.StoreCode             = Convert.ToString(objAsgTechCallDetail.StoreCode);
                                                objPartnerGoodsMovSerialnew.ToPartnerCode         = Convert.ToString(objAsgTechCallDetail.ToPartnerCode);
                                                objPartnerGoodsMovSerialnew.ToPartnerEmployeeCode = Convert.ToString(objAsgTechCallDetail.ToPartnerEmployeeCode);
                                                objPartnerGoodsMovSerialnew.ToPlantCode           = "";
                                                objPartnerGoodsMovSerialnew.ToStoreCode           = Convert.ToString(objAsgTechCallDetail.ToStoreCode);
                                                objPartnerGoodsMovSerialnew.ToMaterialCode        = Convert.ToString(objAsgTechCallDetail.ToMaterialCode);
                                            }
                                        }


                                        objPartnerGMSerialCol.colPartnerGMSerialDetail.Add(objPartnerGoodsMovSerialnew);

                                        /*----------------------------------------------------------------------------------------------------------*/
                                    }
                                }
                            }
                            /*-----------------------------------------------------------------------------------------------------------*/
                        }
                        /*Partner Goods Movement Save*/

                        objPartnerGMManager.SavePartnerGoodsMovement(objPartnerGM, objPartnerGMCol, objPartnerGMSerialCol, da, lstErr);

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }

                            if (objerr.Type == "A")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }
                        }
                    }
                }
                da.COMMIT_TRANSACTION();
            }
            catch (Exception ex)
            {
                if (da != null)
                {
                    da.ROLLBACK_TRANSACTION();
                }
                objErrorHandler.Type       = ErrorConstant.strAboartType;
                objErrorHandler.MsgId      = 0;
                objErrorHandler.Module     = ErrorConstant.strInsertModule;
                objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
                objErrorHandler.Message    = ex.Message.ToString();
                objErrorHandler.RowNo      = 0;
                objErrorHandler.FieldName  = "";
                objErrorHandler.LogCode    = "";
                lstErr.Add(objErrorHandler);
                errorcol.colErrorHandler.Add(objErrorHandler);
            }
            finally
            {
                if (da != null)
                {
                    da.Close_Connection();
                    da = null;
                }
            }
            return(errorcol);
        }
        public PartnerErrorResult SavePartnerGoodsMovement(PartnerGoodsMovement argPartnerGoodsMovement, PartnerGoodsMovementDetailCol argPartnerGNDetail, PartnerGoodsMovSerialDetailCol argPartnerGMSerialDetail)
        {
            List <ErrorHandler> lstErr   = new List <ErrorHandler>();
            PartnerErrorResult  errorcol = new PartnerErrorResult();
            PartnerGoodsMovementDetailManager  objPartnerGMDetailManager       = new PartnerGoodsMovementDetailManager();
            PartnerGoodsMovSerialDetailManager objPartnerGNSerialDetailManager = new PartnerGoodsMovSerialDetailManager();
            DataAccess da          = new DataAccess();
            string     strRetValue = "";

            try
            {
                da.Open_Connection();
                da.BEGIN_TRANSACTION();

                if (blnIsPartnerGoodsMovementExists(argPartnerGoodsMovement.PGoodsMovementCode, argPartnerGoodsMovement.ClientCode, da) == false)
                {
                    strRetValue = InsertPartnerGoodsMovement(argPartnerGoodsMovement, da, lstErr);
                }
                else
                {
                    strRetValue = UpdatePartnerGoodsMovement(argPartnerGoodsMovement, da, lstErr);
                }

                foreach (ErrorHandler objerr in lstErr)
                {
                    if (objerr.Type == "E")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }

                    if (objerr.Type == "A")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }
                }

                if (strRetValue != "")
                {
                    if (argPartnerGNDetail.colPartnerGMDetail.Count > 0)
                    {
                        foreach (PartnerGoodsMovementDetail objPartnerGMDetail in argPartnerGNDetail.colPartnerGMDetail)
                        {
                            objPartnerGMDetail.PGoodsMovementCode = strRetValue;

                            if (objPartnerGMDetail.IsDeleted == 0)
                            {
                                objPartnerGMDetailManager.SavePartnerGoodsMovementDetail(objPartnerGMDetail, da, lstErr);
                            }
                            else
                            {
                                /*Delete Function Call*/
                            }
                        }

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }

                            if (objerr.Type == "A")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }
                        }
                    }

                    if (argPartnerGMSerialDetail.colPartnerGMSerialDetail.Count > 0)
                    {
                        foreach (PartnerGoodsMovSerialDetail objPartnerGMSerialDetail in argPartnerGMSerialDetail.colPartnerGMSerialDetail)
                        {
                            objPartnerGMSerialDetail.PGoodsMovementCode = strRetValue;

                            if (objPartnerGMSerialDetail.IsDeleted == 0)
                            {
                                objPartnerGNSerialDetailManager.SavePartnerGoodsMovSerialDetail(objPartnerGMSerialDetail, da, lstErr);
                            }
                            else
                            {
                                /*Call delete function*/
                            }
                        }

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }

                            if (objerr.Type == "A")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }
                        }
                    }

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

                    int IsCreateRepOrder = 0;
                    PartnerGMDocTypeManager objPartnerGMDocTypeMan = new PartnerGMDocTypeManager();
                    DataSet ds = objPartnerGMDocTypeMan.GetPartnerGMDocType(Convert.ToString(argPartnerGoodsMovement.PartnerGMDocTypeCode), Convert.ToString(argPartnerGoodsMovement.ClientCode), da);

                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            if (Convert.ToString(ds.Tables[0].Rows[0]["CreateRepOrder"]) != "")
                            {
                                IsCreateRepOrder = Convert.ToInt32(ds.Tables[0].Rows[0]["CreateRepOrder"]);
                            }
                        }
                    }


                    if (IsCreateRepOrder == 1)
                    {
                        ///* Call Replace Order Save Function */
                        ReplacementOrder objRepalcementOrder = new ReplacementOrder();
                        string           strNewRepOrderCode  = objReplaceOrderManager.GenerateRepOrderCode("NEW", "RO01", argPartnerGoodsMovement.PartnerCode, argPartnerGoodsMovement.ClientCode);

                        objRepalcementOrder.RepOrderCode        = strNewRepOrderCode;
                        objRepalcementOrder.RepOrderDocTypeCode = Convert.ToString("RO01");
                        objRepalcementOrder.RepOrderDate        = Convert.ToDateTime(argPartnerGoodsMovement.GoodsMovDate).ToString("yyyy-MM-dd");
                        objRepalcementOrder.TotalQuantity       = 0;
                        objRepalcementOrder.RepOrderStatus      = "OPEN";
                        objRepalcementOrder.OrderType           = Convert.ToString(argPartnerGoodsMovement.AssignType);
                        objRepalcementOrder.IssueDocCode        = Convert.ToString(argPartnerGoodsMovement.PGoodsMovementCode);
                        objRepalcementOrder.PartnerCode         = Convert.ToString(argPartnerGoodsMovement.PartnerCode);
                        objRepalcementOrder.ToPartnerCode       = Convert.ToString(argPartnerGoodsMovement.ToPartnerCode);
                        objRepalcementOrder.ClientCode          = Convert.ToString(argPartnerGoodsMovement.ClientCode);
                        objRepalcementOrder.CreatedBy           = Convert.ToString(argPartnerGoodsMovement.CreatedBy);
                        objRepalcementOrder.ModifiedBy          = Convert.ToString(argPartnerGoodsMovement.ModifiedBy);

                        ReplacementOrderDetailCol argReplacementOrderDetailCol = new ReplacementOrderDetailCol();
                        ReplacementOrderDetail    objReplacementOrderDetail    = null;

                        ReplacementOrderSerialDetailCol argReplacementOrderSerialDetailCol = new ReplacementOrderSerialDetailCol();
                        ReplacementOrderSerialDetail    objReplacementOrderSerialDetail    = null;

                        int ictr = 0;

                        foreach (PartnerGoodsMovementDetail objPartnerGMDetail in argPartnerGNDetail.colPartnerGMDetail)
                        {
                            ictr = ictr + 1;
                            objReplacementOrderDetail = new ReplacementOrderDetail();
                            objReplacementOrderDetail.RepOrderCode        = strNewRepOrderCode;
                            objReplacementOrderDetail.RepOrderItemNo      = ictr;
                            objReplacementOrderDetail.MaterialCode        = objPartnerGMDetail.MaterialCode;
                            objReplacementOrderDetail.MatGroup1Code       = objPartnerGMDetail.MatGroup1Code;
                            objReplacementOrderDetail.PartnerCode         = objPartnerGMDetail.PartnerCode;
                            objReplacementOrderDetail.PartnerEmployeeCode = objPartnerGMDetail.FromPartnerEmployeeCode;
                            objReplacementOrderDetail.OrderQty            = objPartnerGMDetail.Quantity;
                            objReplacementOrderDetail.UOMCode             = objPartnerGMDetail.UOMCode;
                            objReplacementOrderDetail.ReceivedQty         = 0;
                            objReplacementOrderDetail.RepOrderStatus      = "OPEN";
                            objReplacementOrderDetail.IssueDocCode        = objPartnerGMDetail.PGoodsMovementCode;
                            objReplacementOrderDetail.IssueDocItemNo      = objPartnerGMDetail.ItemNo;
                            objReplacementOrderDetail.ToPartnerCode       = objPartnerGMDetail.ToPartnerCode;
                            objReplacementOrderDetail.ClientCode          = argPartnerGoodsMovement.ClientCode;
                            objReplacementOrderDetail.CreatedBy           = argPartnerGoodsMovement.CreatedBy;
                            objReplacementOrderDetail.ModifiedBy          = argPartnerGoodsMovement.ModifiedBy;
                            objReplacementOrderDetail.IsDeleted           = 0;

                            argReplacementOrderDetailCol.colReplacementOrderDetail.Add(objReplacementOrderDetail);

                            foreach (PartnerGoodsMovSerialDetail objPartnerGMSerialDetail in argPartnerGMSerialDetail.colPartnerGMSerialDetail)
                            {
                                if (objPartnerGMSerialDetail.ItemNo == objPartnerGMDetail.ItemNo)
                                {
                                    objReplacementOrderSerialDetail = new ReplacementOrderSerialDetail();
                                    objReplacementOrderSerialDetail.RepOrderCode        = strNewRepOrderCode;
                                    objReplacementOrderSerialDetail.RepOrderItemNo      = ictr;
                                    objReplacementOrderSerialDetail.SerialNo1           = objPartnerGMSerialDetail.SerialNo1;
                                    objReplacementOrderSerialDetail.SerialNo2           = objPartnerGMSerialDetail.SerialNo2;
                                    objReplacementOrderSerialDetail.MaterialCode        = objPartnerGMSerialDetail.MaterialCode;
                                    objReplacementOrderSerialDetail.MatGroup1Code       = objPartnerGMSerialDetail.MatGroup1Code;
                                    objReplacementOrderSerialDetail.PartnerCode         = objPartnerGMSerialDetail.PartnerCode;
                                    objReplacementOrderSerialDetail.PartnerEmployeeCode = objPartnerGMSerialDetail.PartnerEmployeeCode;
                                    objReplacementOrderSerialDetail.OrderQty            = 1;
                                    objReplacementOrderSerialDetail.UOMCode             = objPartnerGMDetail.UOMCode;
                                    objReplacementOrderSerialDetail.ReceivedQty         = 0;
                                    objReplacementOrderSerialDetail.RepOrderStatus      = "OPEN";
                                    objReplacementOrderSerialDetail.IssueDocCode        = objPartnerGMSerialDetail.PGoodsMovementCode;
                                    objReplacementOrderSerialDetail.IssueDocItemNo      = objPartnerGMSerialDetail.ItemNo;
                                    objReplacementOrderSerialDetail.ToPartnerCode       = objPartnerGMSerialDetail.ToPartnerCode;
                                    objReplacementOrderSerialDetail.ClientCode          = argPartnerGoodsMovement.ClientCode;
                                    objReplacementOrderSerialDetail.CreatedBy           = argPartnerGoodsMovement.CreatedBy;
                                    objReplacementOrderSerialDetail.ModifiedBy          = argPartnerGoodsMovement.ModifiedBy;
                                    objReplacementOrderSerialDetail.IsDeleted           = 0;

                                    argReplacementOrderSerialDetailCol.colReplacementOrderSerialDetail.Add(objReplacementOrderSerialDetail);
                                }
                            }
                        }

                        if (argReplacementOrderDetailCol.colReplacementOrderDetail.Count > 0)
                        {
                            objReplaceOrderManager.SaveReplacementOrder(objRepalcementOrder, argReplacementOrderDetailCol, argReplacementOrderSerialDetailCol, da, lstErr);

                            foreach (ErrorHandler objerr in lstErr)
                            {
                                if (objerr.Type == "E")
                                {
                                    errorcol.colErrorHandler.Add(objerr);
                                    da.ROLLBACK_TRANSACTION();
                                    return(errorcol);
                                }

                                if (objerr.Type == "A")
                                {
                                    errorcol.colErrorHandler.Add(objerr);
                                    da.ROLLBACK_TRANSACTION();
                                    return(errorcol);
                                }
                            }
                        }
                    }

                    /******************************/
                }
                da.COMMIT_TRANSACTION();
            }
            catch (Exception ex)
            {
                if (da != null)
                {
                    da.ROLLBACK_TRANSACTION();
                }
                objErrorHandler.Type       = ErrorConstant.strAboartType;
                objErrorHandler.MsgId      = 0;
                objErrorHandler.Module     = ErrorConstant.strInsertModule;
                objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
                objErrorHandler.Message    = ex.Message.ToString();
                objErrorHandler.RowNo      = 0;
                objErrorHandler.FieldName  = "";
                objErrorHandler.LogCode    = "";
                lstErr.Add(objErrorHandler);
                errorcol.colErrorHandler.Add(objErrorHandler);
            }
            finally
            {
                if (da != null)
                {
                    da.Close_Connection();
                    da = null;
                }
            }
            return(errorcol);
        }
        public void SavePartnerGoodsMovement(PartnerGoodsMovement argPartnerGoodsMovement, PartnerGoodsMovementDetailCol argPartnerGNDetail, PartnerGoodsMovSerialDetailCol argPartnerGMSerialDetail, DataAccess da, List <ErrorHandler> lstErr)
        {
            try
            {
                PartnerGoodsMovementDetailManager  objPartnerGMDetailManager       = new PartnerGoodsMovementDetailManager();
                PartnerGoodsMovSerialDetailManager objPartnerGNSerialDetailManager = new PartnerGoodsMovSerialDetailManager();
                string strRetValue = "";
                if (blnIsPartnerGoodsMovementExists(argPartnerGoodsMovement.PGoodsMovementCode, argPartnerGoodsMovement.ClientCode, da) == false)
                {
                    strRetValue = InsertPartnerGoodsMovement(argPartnerGoodsMovement, da, lstErr);
                }
                else
                {
                    //strRetValue =  UpdatePartnerGoodsMovement(argPartnerGoodsMovement, da, lstErr);
                }

                if (strRetValue != "")
                {
                    if (argPartnerGNDetail.colPartnerGMDetail.Count > 0)
                    {
                        foreach (PartnerGoodsMovementDetail objPartnerGMDetail in argPartnerGNDetail.colPartnerGMDetail)
                        {
                            objPartnerGMDetail.PGoodsMovementCode = strRetValue;

                            if (objPartnerGMDetail.IsDeleted == 0)
                            {
                                objPartnerGMDetailManager.InsertPartnerGoodsMovementDetail(objPartnerGMDetail, da, lstErr);
                            }
                            else
                            {
                                /*Delete Function Call*/
                            }
                        }
                    }

                    if (argPartnerGMSerialDetail.colPartnerGMSerialDetail.Count > 0)
                    {
                        foreach (PartnerGoodsMovSerialDetail objPartnerGMSerialDetail in argPartnerGMSerialDetail.colPartnerGMSerialDetail)
                        {
                            objPartnerGMSerialDetail.PGoodsMovementCode = strRetValue;

                            if (objPartnerGMSerialDetail.IsDeleted == 0)
                            {
                                objPartnerGNSerialDetailManager.InsertPartnerGoodsMovSerialDetail(objPartnerGMSerialDetail, da, lstErr);
                            }
                            else
                            {
                                /*Call delete function*/
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                objErrorHandler.Type       = ErrorConstant.strAboartType;
                objErrorHandler.MsgId      = 0;
                objErrorHandler.Module     = ErrorConstant.strInsertModule;
                objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
                objErrorHandler.Message    = ex.Message.ToString();
                objErrorHandler.RowNo      = 0;
                objErrorHandler.FieldName  = "";
                objErrorHandler.LogCode    = "";
                lstErr.Add(objErrorHandler);
            }
        }
        public PartnerErrorResult SaveCallClosingDetails(CallClosingMaster argCallClosingMaster, CallClosingDetailCol argCallClosingDetailCol, CallBillingDocMaster argCallBillingDocMaster, CallBillingDocCol argCallBillingDocCol, string argPartnerCode, string argClientCode, string argUserName)
        {
            List <ErrorHandler>         lstErr                      = new List <ErrorHandler>();
            PartnerErrorResult          errorcol                    = new PartnerErrorResult();
            PartnerGoodsMovementManager objPartnerGMManager         = new PartnerGoodsMovementManager();
            CallClosingMasterManager    objCallClosingMasterManager = new CallClosingMasterManager();
            DataAccess da          = new DataAccess();
            string     strRetValue = "";

            try
            {
                da.Open_Connection();
                da.BEGIN_TRANSACTION();

                string strGoodsMovementCode = "";
                int    ictr = 0;
                strGoodsMovementCode = objPartnerGMManager.GenerateGMCode("NEW", "GM01", argPartnerCode, argClientCode, da);

                if (argCallClosingMaster != null)
                {
                    objCallClosingMasterManager.SaveCallClosingMaster(argCallClosingMaster, da, lstErr);
                }

                foreach (ErrorHandler objerr in lstErr)
                {
                    if (objerr.Type == "E")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }

                    if (objerr.Type == "A")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }
                }

                foreach (CallClosingDetails argCallClosingDetails in argCallClosingDetailCol.colCallClosingDetail)
                {
                    ictr = ictr + 1;

                    if (blnIsCallClosingDetailsExists(argCallClosingDetails.CallClosingCode, argCallClosingDetails.CallCode, argCallClosingDetails.CallItemNo, argCallClosingDetails.PartnerCode, argCallClosingDetails.ClientCode, da) == false)
                    {
                        argCallClosingDetails.PGoodsMovementCode = strGoodsMovementCode;
                        argCallClosingDetails.GMItemNo           = ictr;

                        InsertCallClosingDetails(argCallClosingDetails, da, lstErr);
                    }
                    else
                    {
                        UpdateCallClosingDetails(argCallClosingDetails, da, lstErr);
                    }
                }

                foreach (ErrorHandler objerr in lstErr)
                {
                    if (objerr.Type == "E")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }

                    if (objerr.Type == "A")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }
                }

                /*--------------------Billing Document---------------------------------------------------------------*/

                if (argCallBillingDocMaster != null)
                {
                    if (argCallBillingDocCol.colCallBillingDoc.Count > 0)
                    {
                        string srtNewCallBillingDocCode = "";
                        srtNewCallBillingDocCode = objCallBillingDocMasterManager.GenerateCallBillingDocCode(argCallBillingDocMaster.CallBillingDocCode, argCallBillingDocMaster.CallBillingDocTypeCode, argCallBillingDocMaster.PartnerCode, argCallBillingDocMaster.ClientCode, da);

                        argCallBillingDocMaster.CallBillingDocCode = srtNewCallBillingDocCode;
                        strRetValue = objCallBillingDocMasterManager.SaveCallBillingDocMaster(argCallBillingDocMaster, da, lstErr);

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }

                            if (objerr.Type == "A")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }
                        }

                        if (strRetValue != "")
                        {
                            foreach (CallBillingDoc objCallBillingDoc in argCallBillingDocCol.colCallBillingDoc)
                            {
                                objCallBillingDoc.CallBillingDocCode = strRetValue;
                                objCallBillingDocManager.SaveCallBillingDoc(objCallBillingDoc, da, lstErr);
                            }

                            foreach (ErrorHandler objerr in lstErr)
                            {
                                if (objerr.Type == "E")
                                {
                                    errorcol.colErrorHandler.Add(objerr);
                                    da.ROLLBACK_TRANSACTION();
                                    return(errorcol);
                                }

                                if (objerr.Type == "A")
                                {
                                    errorcol.colErrorHandler.Add(objerr);
                                    da.ROLLBACK_TRANSACTION();
                                    return(errorcol);
                                }
                            }
                        }
                    }
                }

                /*--------------------------------------------------------------------------------------------*/



                /* Partner Goods Movement Declared */
                PartnerGoodsMovement objPartnerGM = new PartnerGoodsMovement();

                objPartnerGM.PGoodsMovementCode      = strGoodsMovementCode;
                objPartnerGM.PartnerGMDocTypeCode    = "GM01";
                objPartnerGM.FromPlantCode           = "";
                objPartnerGM.FromPartnerCode         = argPartnerCode;
                objPartnerGM.FromPartnerEmployeeCode = "";
                objPartnerGM.FromStoreCode           = "";
                objPartnerGM.ToPartnerCode           = "";
                objPartnerGM.ToPlantCode             = "";
                objPartnerGM.ToStoreCode             = "";
                objPartnerGM.ToPartnerEmployeeCode   = "";
                objPartnerGM.ClientCode    = argClientCode;
                objPartnerGM.CreatedBy     = argUserName;
                objPartnerGM.ModifiedBy    = argUserName;
                objPartnerGM.TotalQuantity = 0;
                objPartnerGM.PartnerCode   = Convert.ToString(argPartnerCode);
                objPartnerGM.GoodsMovDate  = Convert.ToDateTime(DateTime.Now);
                /*----------------------------------------------------------------------------------------*/
                /* Partner Goods Movement Detail */
                PartnerMaterialDocTypeManager objPartnerMatDocTypeMan = new PartnerMaterialDocTypeManager();

                PartnerGoodsMovementDetailCol  objPartnerGMCol       = new PartnerGoodsMovementDetailCol();
                PartnerGoodsMovSerialDetailCol objPartnerGMSerialCol = new PartnerGoodsMovSerialDetailCol();

                objPartnerGMCol.colPartnerGMDetail             = new List <PartnerGoodsMovementDetail>();
                objPartnerGMSerialCol.colPartnerGMSerialDetail = new List <PartnerGoodsMovSerialDetail>();

                DataSet dsMatDocType = null;
                bool    IsNew        = true;
                int     tmpItemNo    = 0;

                ictr = 0;
                foreach (CallClosingDetails argCallClosingDetails in argCallClosingDetailCol.colCallClosingDetail)
                {
                    if (argCallClosingDetails.IsDeleted == 0)
                    {
                        dsMatDocType = new DataSet();
                        if (IsNew == true)
                        {
                            ictr         = ictr + 1;
                            dsMatDocType = objPartnerMatDocTypeMan.GetPartnerMaterialDocType(argCallClosingDetails.MaterialDocTypeCode, argCallClosingDetails.ClientCode, da);

                            PartnerGoodsMovementDetail objPartnerGMDetailsnew = new PartnerGoodsMovementDetail();
                            objPartnerGMDetailsnew.PGoodsMovementCode = strGoodsMovementCode;
                            objPartnerGMDetailsnew.ItemNo             = ictr;
                            tmpItemNo = ictr;
                            objPartnerGMDetailsnew.MaterialCode        = Convert.ToString(argCallClosingDetails.MaterialCode);
                            objPartnerGMDetailsnew.MatGroup1Code       = Convert.ToString(argCallClosingDetails.MatGroup1Code);
                            objPartnerGMDetailsnew.StockIndicator      = Convert.ToString(argCallClosingDetails.StockIndicator);
                            objPartnerGMDetailsnew.ToStockIndicator    = Convert.ToString("");
                            objPartnerGMDetailsnew.Quantity            = Convert.ToInt32(argCallClosingDetails.Quantity);
                            objPartnerGMDetailsnew.UOMCode             = Convert.ToString(argCallClosingDetails.UOMCode);
                            objPartnerGMDetailsnew.ClientCode          = Convert.ToString(argCallClosingDetails.ClientCode);
                            objPartnerGMDetailsnew.CreatedBy           = Convert.ToString(argCallClosingDetails.CreatedBy);
                            objPartnerGMDetailsnew.ModifiedBy          = Convert.ToString(argCallClosingDetails.ModifiedBy);
                            objPartnerGMDetailsnew.TranRefDocCode      = Convert.ToString(argCallClosingDetails.CallClosingCode);
                            objPartnerGMDetailsnew.TranRefDocItemNo    = Convert.ToInt32(ictr);
                            objPartnerGMDetailsnew.MaterialDocTypeCode = Convert.ToString(argCallClosingDetails.MaterialDocTypeCode);
                            objPartnerGMDetailsnew.PartnerCode         = Convert.ToString(argPartnerCode);


                            if (dsMatDocType != null)
                            {
                                if (dsMatDocType.Tables[0].Rows.Count > 0)
                                {
                                    if (dsMatDocType.Tables[0].Rows[0]["FromPlant"].ToString() != "Hide")
                                    {
                                        objPartnerGMDetailsnew.FromPlantCode = "";
                                    }
                                    else
                                    {
                                        objPartnerGMDetailsnew.FromPlantCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["FromPartner"].ToString() != "Hide")
                                    {
                                        objPartnerGMDetailsnew.FromPartnerCode = Convert.ToString(argCallClosingDetails.PartnerCode);
                                    }
                                    else
                                    {
                                        objPartnerGMDetailsnew.FromPartnerCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["FromStore"].ToString() != "Hide")
                                    {
                                        objPartnerGMDetailsnew.FromStoreCode = Convert.ToString(argCallClosingDetails.StoreCode);
                                    }
                                    else
                                    {
                                        objPartnerGMDetailsnew.FromStoreCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["FromEmployee"].ToString() != "Hide")
                                    {
                                        objPartnerGMDetailsnew.FromPartnerEmployeeCode = "";
                                    }
                                    else
                                    {
                                        objPartnerGMDetailsnew.FromPartnerEmployeeCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["ToPartner"].ToString() != "Hide")
                                    {
                                        objPartnerGMDetailsnew.ToPartnerCode = Convert.ToString("");
                                    }
                                    else
                                    {
                                        objPartnerGMDetailsnew.ToPartnerCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["ToStore"].ToString() != "Hide")
                                    {
                                        objPartnerGMDetailsnew.ToStoreCode = Convert.ToString("");
                                    }
                                    else
                                    {
                                        objPartnerGMDetailsnew.ToStoreCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["ToEmployee"].ToString() != "Hide")
                                    {
                                        objPartnerGMDetailsnew.ToPartnerEmployeeCode = Convert.ToString("");
                                    }
                                    else
                                    {
                                        objPartnerGMDetailsnew.ToPartnerEmployeeCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["ToPlant"].ToString() != "Hide")
                                    {
                                        objPartnerGMDetailsnew.ToPlantCode = "";
                                    }
                                    else
                                    {
                                        objPartnerGMDetailsnew.ToPlantCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["ToMaterialCode"].ToString() != "Hide")
                                    {
                                        objPartnerGMDetailsnew.ToMaterialCode = Convert.ToString("");
                                    }
                                    else
                                    {
                                        objPartnerGMDetailsnew.ToMaterialCode = "";
                                    }
                                }
                                else
                                {
                                    objPartnerGMDetailsnew.FromPlantCode           = "";
                                    objPartnerGMDetailsnew.FromPartnerCode         = Convert.ToString(argCallClosingDetails.PartnerCode);
                                    objPartnerGMDetailsnew.FromPartnerEmployeeCode = "";
                                    objPartnerGMDetailsnew.FromStoreCode           = Convert.ToString(argCallClosingDetails.StoreCode);
                                    objPartnerGMDetailsnew.ToPartnerCode           = Convert.ToString("");
                                    objPartnerGMDetailsnew.ToPartnerEmployeeCode   = Convert.ToString("");
                                    objPartnerGMDetailsnew.ToPlantCode             = "";
                                    objPartnerGMDetailsnew.ToStoreCode             = Convert.ToString("");
                                    objPartnerGMDetailsnew.ToMaterialCode          = Convert.ToString("");
                                }
                            }
                            objPartnerGMCol.colPartnerGMDetail.Add(objPartnerGMDetailsnew);

                            /*Partner Goods Movement Serial Detail*/

                            PartnerGoodsMovSerialDetail objPartnerGoodsMovSerialnew = new PartnerGoodsMovSerialDetail();
                            objPartnerGoodsMovSerialnew.PGoodsMovementCode = strGoodsMovementCode;
                            objPartnerGoodsMovSerialnew.ItemNo             = tmpItemNo;
                            objPartnerGoodsMovSerialnew.SerialNo1          = Convert.ToString(argCallClosingDetails.SerialNo1);
                            objPartnerGoodsMovSerialnew.SerialNo2          = Convert.ToString(argCallClosingDetails.SerialNo2);
                            objPartnerGoodsMovSerialnew.MaterialCode       = Convert.ToString(argCallClosingDetails.MaterialCode);
                            objPartnerGoodsMovSerialnew.MatGroup1Code      = Convert.ToString(argCallClosingDetails.MatGroup1Code);
                            objPartnerGoodsMovSerialnew.RefDocCode         = Convert.ToString(argCallClosingDetails.CallCode);
                            objPartnerGoodsMovSerialnew.RefDocItemNo       = Convert.ToInt32(argCallClosingDetails.CallItemNo);
                            objPartnerGoodsMovSerialnew.RefDocType         = Convert.ToString("");
                            objPartnerGoodsMovSerialnew.TranRefDocCode     = Convert.ToString(argCallClosingDetails.CallClosingCode);
                            objPartnerGoodsMovSerialnew.TranRefDocItemNo   = Convert.ToInt32(ictr);
                            objPartnerGoodsMovSerialnew.IsDeleted          = 0;
                            objPartnerGoodsMovSerialnew.ClientCode         = Convert.ToString(argCallClosingDetails.ClientCode);
                            objPartnerGoodsMovSerialnew.CreatedBy          = Convert.ToString(argCallClosingDetails.CreatedBy);
                            objPartnerGoodsMovSerialnew.ModifiedBy         = Convert.ToString(argCallClosingDetails.ModifiedBy);
                            objPartnerGoodsMovSerialnew.StockIndicator     = Convert.ToString(argCallClosingDetails.StockIndicator);
                            objPartnerGoodsMovSerialnew.ToStockIndicator   = Convert.ToString(argCallClosingDetails.StockIndicator);

                            if (dsMatDocType != null)
                            {
                                if (dsMatDocType.Tables[0].Rows.Count > 0)
                                {
                                    if (dsMatDocType.Tables[0].Rows[0]["FromPlant"].ToString() != "Hide")
                                    {
                                        objPartnerGoodsMovSerialnew.PlantCode = "";
                                    }
                                    else
                                    {
                                        objPartnerGoodsMovSerialnew.PlantCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["FromPartner"].ToString() != "Hide")
                                    {
                                        objPartnerGoodsMovSerialnew.PartnerCode = Convert.ToString(argCallClosingDetails.PartnerCode);
                                    }
                                    else
                                    {
                                        objPartnerGoodsMovSerialnew.PartnerCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["FromStore"].ToString() != "Hide")
                                    {
                                        objPartnerGoodsMovSerialnew.StoreCode = Convert.ToString(argCallClosingDetails.StoreCode);
                                    }
                                    else
                                    {
                                        objPartnerGoodsMovSerialnew.StoreCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["FromEmployee"].ToString() != "Hide")
                                    {
                                        objPartnerGoodsMovSerialnew.PartnerEmployeeCode = "";
                                    }
                                    else
                                    {
                                        objPartnerGoodsMovSerialnew.PartnerEmployeeCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["ToPartner"].ToString() != "Hide")
                                    {
                                        objPartnerGoodsMovSerialnew.ToPartnerCode = Convert.ToString("");
                                    }
                                    else
                                    {
                                        objPartnerGoodsMovSerialnew.ToPartnerCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["ToStore"].ToString() != "Hide")
                                    {
                                        objPartnerGoodsMovSerialnew.ToStoreCode = Convert.ToString("");
                                    }
                                    else
                                    {
                                        objPartnerGoodsMovSerialnew.ToStoreCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["ToEmployee"].ToString() != "Hide")
                                    {
                                        objPartnerGoodsMovSerialnew.ToPartnerEmployeeCode = Convert.ToString("");
                                    }
                                    else
                                    {
                                        objPartnerGoodsMovSerialnew.ToPartnerEmployeeCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["ToPlant"].ToString() != "Hide")
                                    {
                                        objPartnerGoodsMovSerialnew.ToPlantCode = "";
                                    }
                                    else
                                    {
                                        objPartnerGoodsMovSerialnew.ToPlantCode = "";
                                    }

                                    if (dsMatDocType.Tables[0].Rows[0]["ToMaterialCode"].ToString() != "Hide")
                                    {
                                        objPartnerGoodsMovSerialnew.ToMaterialCode = Convert.ToString("");
                                    }
                                    else
                                    {
                                        objPartnerGoodsMovSerialnew.ToMaterialCode = "";
                                    }
                                }
                                else
                                {
                                    objPartnerGoodsMovSerialnew.PlantCode             = "";
                                    objPartnerGoodsMovSerialnew.PartnerCode           = Convert.ToString(argCallClosingDetails.PartnerCode);
                                    objPartnerGoodsMovSerialnew.PartnerEmployeeCode   = "";
                                    objPartnerGoodsMovSerialnew.StoreCode             = Convert.ToString(argCallClosingDetails.StoreCode);
                                    objPartnerGoodsMovSerialnew.ToPartnerCode         = Convert.ToString("");
                                    objPartnerGoodsMovSerialnew.ToPartnerEmployeeCode = Convert.ToString("");
                                    objPartnerGoodsMovSerialnew.ToPlantCode           = "";
                                    objPartnerGoodsMovSerialnew.ToStoreCode           = Convert.ToString("");
                                    objPartnerGoodsMovSerialnew.ToMaterialCode        = Convert.ToString("");
                                }
                            }

                            objPartnerGMSerialCol.colPartnerGMSerialDetail.Add(objPartnerGoodsMovSerialnew);

                            /*----------------------------------------------------------------------------------------------------------*/
                        }
                    }
                }
                /*Partner Goods Movement Save*/
                objPartnerGMManager.SavePartnerGoodsMovement(objPartnerGM, objPartnerGMCol, objPartnerGMSerialCol, da, lstErr);

                foreach (ErrorHandler objerr in lstErr)
                {
                    if (objerr.Type == "E")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }

                    if (objerr.Type == "A")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }
                }

                da.COMMIT_TRANSACTION();
            }
            catch (Exception ex)
            {
                if (da != null)
                {
                    da.ROLLBACK_TRANSACTION();
                }
                objErrorHandler.Type       = ErrorConstant.strAboartType;
                objErrorHandler.MsgId      = 0;
                objErrorHandler.Module     = ErrorConstant.strInsertModule;
                objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
                objErrorHandler.Message    = ex.Message.ToString();
                objErrorHandler.RowNo      = 0;
                objErrorHandler.FieldName  = "";
                objErrorHandler.LogCode    = "";
                lstErr.Add(objErrorHandler);
                errorcol.colErrorHandler.Add(objErrorHandler);
            }
            finally
            {
                if (da != null)
                {
                    da.Close_Connection();
                    da = null;
                }
            }
            return(errorcol);
        }
        //public ICollection<PartnerGoodsMovSerialDetail> colGetPartnerGoodsMovSerialDetail(string argPGoodsMovementCode, int argItemNo, string argClientCode)
        //{
        //    List<PartnerGoodsMovSerialDetail> lst = new List<PartnerGoodsMovSerialDetail>();
        //    DataSet DataSetToFill = new DataSet();
        //    PartnerGoodsMovSerialDetail tPartnerGoodsMovSerialDetail = new PartnerGoodsMovSerialDetail();

        //    DataSetToFill = this.GetPartnerGoodsMovSerialDetail(argPGoodsMovementCode, argItemNo, argClientCode);

        //    if (DataSetToFill != null)
        //    {
        //        foreach (DataRow dr in DataSetToFill.Tables[0].Rows)
        //        {
        //            lst.Add(objCreatePartnerGoodsMovSerialDetail(dr));
        //        }
        //    }
        //    goto Finish;

        //Finish:
        //    DataSetToFill = null;


        //    return lst;
        //}

        public void colGetPartnerGoodsMovSerialDetail(string argPGoodsMovementCode, string argClientCode, ref PartnerGoodsMovSerialDetailCol argPartnerGoodsMovSerialDetailCol)
        {
            DataSet DataSetToFill = new DataSet();
            PartnerGoodsMovSerialDetail tPartnerGoodsMovSerialDetail = new PartnerGoodsMovSerialDetail();

            DataSetToFill = this.GetPartnerGoodsMovSerialDetail(argPGoodsMovementCode, argClientCode);

            if (DataSetToFill != null)
            {
                foreach (DataRow dr in DataSetToFill.Tables[0].Rows)
                {
                    argPartnerGoodsMovSerialDetailCol.colPartnerGMSerialDetail.Add(objCreatePartnerGoodsMovSerialDetail(dr));
                }
            }
            goto Finish;

Finish:
            DataSetToFill = null;
        }