<?php 
namespace OfficeBrain\Bundle\ProductBundle\Manager\Service;
use Symfony\Component\HttpFoundation\Request;
use OfficeBrain\Bundle\ProductBundle\Helper\PluginDataHelper;
use OfficeBrain\Bundle\ObSolrOperationBundle\Form\Data\OperationData;
use Doctrine\ORM\EntityManager as EntityManager;
use OfficeBrain\Bundle\CoreBundle\Constant\Constant;
//use OfficeBrain\Bundle\ProductBundle\ApiClient\ProductApiClient;

/**
 * @author Employee Id: 4808
 *
 * Description : This Class Used For Distributor Admin Functionality 
 *
 **/
class DistributorAdminManager
{
	/**
	 * @author Employee Id: 5190
	 *
	 * Description : This function used for Set and intilize variables and request array
	 *
	 **/
	public function __construct(Request $request, $service_container, EntityManager $em, $productApi)
	{
		$this->request=$request;
		$this->productApi=$productApi;		
		$this->serviceContainer = $service_container;
		$this->PluginDataHelper = new PluginDataHelper($this->serviceContainer);
		$this->translator = $this->serviceContainer->get('translator');
		//$this->productCategoryMappingRepository = $productCategoryMappingRepository;
		$this->projectSetting = $this->request->get('project_setting');
		
		$this->em = $em;
		$this->productMasterRepository = $this->em->getRepository('OfficeBrainProductBundle:ProductMaster');
		//CountryProduct
		$this->countryRepository = $this->em->getRepository('OfficeBrainCoreBundle:Country');
		$this->countryProductRepo = $this->em->getRepository('OfficeBrainProductBundle:CountryProduct');
		$this->productCultureRepository = $this->em->getRepository('OfficeBrainProductBundle:CultureProducts');
		$this->productPriceRepository = $this->em->getRepository('OfficeBrainProductBundle:ProductPrice');
		$this->searchKeywordRepository = $this->em->getRepository('OfficeBrainProductBundle:SearchKeyword');
		$this->featureDetailsRepository  = $this->em->getRepository('OfficeBrainProductBundle:FeatureDetails');
		$this->customProductCategoryMappingRepository = $this->em->getRepository('OfficeBrainProductBundle:CustomProductCategoryMapping');
		//$this->brandRepository = $this->em->getRepository('OfficeBrainBrandBundle:CultureBrand');
	}
	
	
	/**
	 * @author Employee Id: 5190
	 *
	 * Description: This Function Used For Add Distributor New Product
	 *
	 * @param array $requestParams
	 *
	 * @return array
	 */
	public function add($params){
		// Is Set For Return Data
		//$dataForReturn = array();
		$supplier_id = $params['supplier_id'];
		
		//Available Language
		$cultureArray = array_keys($params['product_name']);
		
		// TODO: Need to pass Country with id and by code dynamically
		// we have to modified the country array
		
		$countryArray=array();
		foreach($params['country'] as $key=>$country){
	    	$countryArr=explode("_",$country);
	        $countryArray[$countryArr[0]]=$countryArr[1];
		}
		$params['country']=$countryArray;
		$params['sku'] = trim($params['sku']);
		
		if(isset($params['distributor_product_id']) && $params['distributor_product_id'] >0){
			//TODO : Code For When Product Uncheck from any country then it delete from the country
			$countryProductObj = $this->countryProductRepo->getProductCountryForAdd($params['distributor_product_id']);
			$deletedProductCountries = array();
			foreach($countryProductObj as $deletedValues){
				$deletedProductCountries[] = $deletedValues['id'];
			}
			// For Deleted at to Null
			$sameValues = array_intersect(array_keys($params['country']),$deletedProductCountries);
			if(!empty($sameValues)){
				foreach($sameValues as $deletedCountry){
					$this->countryProductRepo->setDeletedAtNull($params['distributor_product_id'],$deletedCountry);
				}
			}
			 
			// For Delete Entry
			$countryForDelete = array_diff($deletedProductCountries,array_keys($params['country']));
			if(!empty($countryForDelete)){
				foreach($countryForDelete as $deleteCountry){
					$this->countryProductRepo->delete($params['distributor_product_id'],$deleteCountry);
				}
			}
			$isDuplicate = $this->productMasterRepository->checkDuplicateSku($params['sku'],$supplier_id,$params['distributor_product_id']);
		} else{
			$isDuplicate = $this->productMasterRepository->checkDuplicateSku($params['sku'],$supplier_id);
		} 
		
		if($isDuplicate){
			$returnData = array('status' => 'error','message' => 'duplicate_sku');
			return $returnData;
		}
		
		$brandObj = null;
		/* $brandObj = null;
		if(isset($params['brand'])) {
			$culBrand = $this->brandRepository->findOneBy(array('brand' => $params['brand'])); //CultureBrand
			if ($culBrand) $brandObj = $culBrand->getBrand();
		} */
		
		if(isset($params['distributor_product_id']) && isset($params['master_product_id']) && $params['distributor_product_id']>0 && $params['master_product_id']>0){
			$productMaster = $this->productMasterRepository->update($params['distributor_product_id'],$params['sku'],$brandObj,$supplier_id,$params);
		}else{
			$sku = $params['sku'];
			$productMaster = $this->productMasterRepository->addNew($sku,$brandObj,$params, $supplier_id);
		}
		
		//For country related data
		foreach($params['country'] as $country_key => $country_values) {
			$countryObj = $this->countryRepository->findOneBy(array('countryCode'=>strtoupper($country_values)));
			if (!$countryObj) continue;
			
			//Insert category Data in Product_Category Mapping Table Country Wise
			if(isset($params['category']['country_'.$country_values])) {
				$oldProductCatId = $this->customProductCategoryMappingRepository->getCategory($productMaster->getId(), $countryObj->getId());
				if(!empty($oldProductCatId)){
					$oldSelectedCatId =  array();
					foreach ($oldProductCatId as $oldCategoryId){
						$oldSelectedCatId[] = $oldCategoryId['categoryId'];
					}
					$this->customProductCategoryMappingRepository->PMRemoveCategory($productMaster->getId(), $oldSelectedCatId ,$countryObj->getId());
				}
				
				foreach($params['category']['country_'.$country_values] as $category) {
					$setReturnData = array();
					//$categoryMaster = $this->categoryMasterRepository->findOneBy(array('id'=>$category, 'deletedAt' => null));
					$mappingData =$this->customProductCategoryMappingRepository->add($category,$productMaster->getId(), $countryObj->getId());
			
					// For Mapping Product Category on Local
					$setReturnData['cat_id'] = $category;
					$setReturnData['country_id'] = $countryObj->getId();
					$setReturnData['product_id'] = $productMaster->getId();
					$dataForReturn['category_data'][$countryObj->getId()][] = $setReturnData;
				}
			}
			
			//Product Status
			$status = isset($params['status']) ? $params['status']: 0;
			$productCountryObject = $this->countryProductRepo->pMEdit($productMaster->getId(), $countryObj->getId(), $status, $params['currency_array'][$country_values]);
		}
		//For culture vise create
		$cultureDetails = $this->serviceContainer->getParameter('language');
		$productCultureObjArr = array();
		foreach($cultureArray as $index=>$cultureName) {
			$culture = $cultureDetails[$cultureName]['id'];
			if (!$culture) continue;
		
			if(trim($params['product_name'][$cultureName]) == '') continue;
		
			// here we have to check that if particular sku have already exist
			$isDuplicate = '';
		
			$description = (isset($params['product_description'][$cultureName])) ? $params['product_description'][$cultureName]:'';
			$productName = (isset($params['product_name'][$cultureName])?$params['product_name'][$cultureName]:'');
			$validUpto = $params['valid_up_to'];
			//General Information
			$generalInformation = (isset($params['general_information'][$cultureName]) && $params['general_information'][$cultureName] != '') ? $params['general_information'][$cultureName]:'';
		
			$cultureProductData = array('description'=>$description,'product_name'=>$productName, 'validUpto'=>$validUpto, 'general_information' => $generalInformation);
			$productCultureObject = $this->productCultureRepository->PMEdit($cultureProductData,$productMaster,$culture);
			$productCultureObjArr[$index] = $productCultureObject;
			// Strore ProductCultureObject values in array
			
			
			// Now we have to insert in feature_details
			if(isset($params['feature_detail'][$cultureName])) {
				$featureDetailsArray=$params['feature_detail'][$cultureName];
				if(count($featureDetailsArray)>0){
					$productFeatureDetails = $this->featureDetailsRepository->removeFeatures($productCultureObject);
					foreach ($featureDetailsArray as $featureKey=>$featureDetails) {
						$featureLabel = !empty($params['feature_detail_label']) ? $params['feature_detail_label'][$cultureName][$featureKey] : '';
						$featureValue = $featureDetails;
						if (trim($featureLabel) == '' && trim($featureValue) == '') continue;
						$productFeatureDetails = $this->featureDetailsRepository->add($featureValue,$productCultureObject,$productMaster,$culture,$featureLabel);
					}
				}
			}
			
			//Keyword
			if ($params['keyword'][$cultureName] && $params['keyword'][$cultureName] != '') {
				$keyword = explode(",",$params['keyword'][$cultureName]);
				$this->searchKeywordRepository->removeProductKeywords($culture,$productCultureObject,$keyword);
				foreach($keyword as $_keyword){
					$this->searchKeywordRepository->addProductKeyword($culture,$productCultureObject,trim($_keyword));
				}
			}
		}
		
		// Pricing Values Except Variation Price
		/* if(isset($params['country']) && isset($params['Pricing'])) {
			// Insert Country Wise
			$PricingType = isset($params['PricingType'])?$params['PricingType']:'';
			//$PricingType = $params['PricingType'];
			$priceUnit = $params['Pricing']['price_unit'];
			// check that if Pricing is set
			if($params['Pricing'] && count($params['Pricing']) > 0 && $PricingType!= trim('variation')){
				foreach($params['Pricing'] as $key => $pricingArray){
					if($key != $PricingType){
						$this->productPriceRepository->removePrice($productMaster,$key,null,null,"decorative");
						continue;
					}
					foreach($pricingArray as $cnt_key=>$pricing) {
						if(is_array($pricing)) {
							// loop for values
							$country = str_replace("country_","",$cnt_key);
							$currency = $params['currency_array'][$country];
							$countryObj = $this->countryRepository->findOneBy(array('countryCode'=>$country));
							$this->productPriceRepository->removePrice($productMaster->getId(),$PricingType,$countryObj,null,"decorative");
							$productPriceObject = $this->productPriceRepository->addPrice($countryObj->getId(),$productMaster->getId(),$currency,$pricing,$PricingType,$priceUnit);
						}
					}
				}
			}
		
			$BlankPricingType = isset($params['BlankPricingType'])?$params['BlankPricingType']:'';
			$priceUnit = $params['BlankPricing']['price_unit'];
			// check that if Pricing is set
			if($params['BlankPricing'] && count($params['BlankPricing']) > 0 && $BlankPricingType!= trim('variation')){
				foreach($params['BlankPricing'] as $key => $pricingArray){
					if($key != $BlankPricingType){
						$this->productPriceRepository->removePrice($productMaster,$key,null,null,"blank");
						continue;
					}
					foreach($pricingArray as $cnt_key=>$pricing) {
						if(is_array($pricing)) {
							// loop for values
							$country = str_replace("country_","",$cnt_key);
							$currency = $params['currency_array'][$country];
							$countryObj = $this->countryRepository->findOneBy(array('countryCode'=>$country));
							$this->productPriceRepository->removePrice($productMaster->getId(),$BlankPricingType,$countryObj,null,"blank");
							$productPriceObject = $this->productPriceRepository->addPrice($countryObj->getId(),$productMaster->getId(),$currency,$pricing,$BlankPricingType,$priceUnit);
						}
					}
				}
			}
		} */
		
		if(isset($params['country']) && isset($params['Pricing'])) {
			// Insert Country Wise
			$PricingType = isset($params['PricingType'])?$params['PricingType']:'';
			//$PricingType = $params['PricingType'];
			$priceUnit = $params['Pricing']['price_unit'];
			// check that if Pricing is set
			if($params['Pricing'] && count($params['Pricing']) > 0 && $PricingType!= trim('variation')){
            	foreach($params['Pricing'] as $key => $pricingArray){
            		if($key != $PricingType){
            			$this->productPriceRepository->removePrice($productMaster,$key,null,null);
            			continue;
            		}
	            	foreach($pricingArray as $cnt_key=>$pricing) {
	                    if(is_array($pricing)) {
	                        // loop for values
	                        $country = str_replace("country_","",$cnt_key);
	                        $currency = $params['currency_array'][$country];
	                        $countryObj = $this->countryRepository->findOneBy(array('countryCode'=>$country));
	                        $this->productPriceRepository->removePrice($productMaster->getId(),$PricingType,$countryObj,null);
	                        $this->productPriceRepository->addPrice($countryObj->getId(),$productMaster->getId(),$currency,$pricing,$PricingType,$priceUnit);
	                    }
	                }
                }
            }
            
           /*  $BlankPricingType = isset($params['BlankPricingType'])?$params['BlankPricingType']:'';
            $priceUnit = $params['BlankPricing']['price_unit'];
            // check that if Pricing is set
            if($params['BlankPricing'] && count($params['BlankPricing']) > 0 && $BlankPricingType!= trim('variation')){
            	foreach($params['BlankPricing'] as $key => $pricingArray){
            		if($key != $BlankPricingType){
            			$this->productPriceRepository->removePrice($productMaster,$key,null,null,"blank");
            			continue;
            		}
            		foreach($pricingArray as $cnt_key=>$pricing) {
            			if(is_array($pricing)) {
            				// loop for values
            				$country = str_replace("country_","",$cnt_key);
            				$currency = $params['currency_array'][$country];
            				$countryObj = $this->countryRepository->findOneBy(array('countryCode'=>$country));
            				$this->productPriceRepository->removePrice($productMaster->getId(),$BlankPricingType,$countryObj,null,"blank");
            				$this->productPriceRepository->addPrice($countryObj->getId(),$productMaster->getId(),$currency,$pricing,$BlankPricingType,$priceUnit);
            			}
            		}
            	}
            } */
		}
		// End of Pricing Data
        
		$returnData = array('status' =>'success','message' => 'product_add_edit.product_updated_successfully', 'master_product_id'=>$productMaster->getPmsId());
		return $returnData;
		
        /* if(!empty($productMaster) && !empty($productCultureObject) && !empty($productCountryObject) && !empty($productPriceObject) ){
        	return array('status'=>'success','message'=>'product_add_edit.product_updated_successfully', 'master_product_id'=>$productMaster->getId());
        }
        else{
        	return array('status'=>'error', 'message'=>'product_add_edit.NO_DATA_FOUND');
        } */
	}
	
	/**
	 * Emp ID - 5190
	 *
	 * @param integer $product_id
	 * @param array $languages
	 * @param array $countries
	 *
	 * return product information based on product langage and country
	 */
	public function editViewDistributorProduct($productApiData,$productId, $languages, $countries, $default_culture){
		$explode_seperator = Constant::$DATA_SEP;
		$data_to_return = (isset($productApiData['product_id']) && $productApiData['product_id']>0) ? $productApiData : array();
		
		$serializer = $this->serviceContainer->get('serializer');
		$cultureDetails = $this->serviceContainer->getParameter('language');
		$default_culture_id = $cultureDetails[$default_culture]['id'];
		
		$countryProductObj = $this->em->getRepository('OfficeBrainProductBundle:CountryProduct')->getProductCountry($productId);
		$country_and_code = array_change_key_case(array_combine(array_column($countryProductObj,'code'), array_column($countryProductObj,'id')));
		
		$data_to_return['product_id'] = $productId;
		
		$productObj = $this->productMasterRepository->findOneBy(array('id'=>$productId));
		$product_master_data = json_decode($serializer->serialize($productObj, 'json'),true);
		$data_to_return['supplier_id'] = $product_master_data['supplier_id'];
		
		foreach($languages as $language){
			//$culture = $this->cultureRepository->findOneBy(array("name"=>$language));
			//if (!$culture) continue;
			$language_id = $cultureDetails[$language]['id'];
			$product = $this->productCultureRepository->findOneBy(array('productId'=>$productId,'culture'=>$language_id));
			
			if (!$product) continue;
			$finalData = json_decode($serializer->serialize($product, "json"),true);
			if(!count($finalData)){ $data_to_return[$language] = array();continue; }
			$cultureProductId =  $finalData['id'];
		
			//BASIC INFO
			//$data_to_return[$language]['basic_information'] = array();
			//$data_to_return[$language]['basic_information']['culture_product_id'] = $cultureProductId;
			$data_to_return[$language]['basic_information']['masked_sku'] = $product_master_data['masked_s_k_u'];
			$data_to_return[$language]['basic_information']['sku_number'] = $product_master_data['masked_s_k_u'];
			$data_to_return[$language]['basic_information']['title'] = $finalData['title'];
			if(!empty($finalData['description'])){
				$data_to_return[$language]['basic_information']['description'] = $finalData['description'];
			}
			$data_to_return[$language]['basic_information']['slug'] = $finalData['slug'];
			
			if(isset($product_master_data['valid_up_to']) && $product_master_data['valid_up_to']!=null){
				$data_to_return[$language]['basic_information']['valid_up_to'] = $product_master_data['valid_up_to'];
				$valid_up_to_array = explode("-",$data_to_return[$language]['basic_information']['valid_up_to']);
				$mktime = mktime(0,0,0,$valid_up_to_array[2],$valid_up_to_array[1],$valid_up_to_array[0]);
				$data_to_return[$language]['basic_information']['valid_up_to'] = date('m-d-Y',$mktime);
			}
			
			//Feature details
			$featureLabelValue =  array();
			$featureDetails = $this->featureDetailsRepository->getFeatureDetails($cultureProductId, $language_id);
			if(!empty($featureDetails)){
				foreach($featureDetails as $ind=>$featureDetail){
					$featureLabelValue[$ind]['label'] = $featureDetail['featureLabel'];
					$featureLabelValue[$ind]['value'] = $featureDetail['feature'];
				}
				$data_to_return[$language]['feature_details'] = $featureLabelValue;
			}
			unset($featureDetails);
			
			//Keyword
			$keywordInfo = $this->searchKeywordRepository->getKeyword($cultureProductId);
			if(!empty($keywordInfo[0]['keyword'])){
				$data_to_return[$language]['keyword'] =  implode(",",explode($explode_seperator,$keywordInfo[0]['keyword']));
			}
			unset($keywordInfo);
		}
		
		$availableCountries = $this->countryProductRepo->findBy(array("productId"=>$productObj));
		$product_country = array();
		foreach($availableCountries as $availableCountry){
			$product_country[] = array_search($availableCountry->getCountryId(),$country_and_code);
		}
		if(!empty($product_country)){
			$product_country = array_unique($product_country);
			$data_to_return['available_country']= $product_country;
		}
		$productPrice = $this->productPriceRepository->getProductWisePrice($productId);
		if($productPrice){
			$data_to_return['regular_variations_type'] = '';
			foreach($country_and_code as $countryName=>$country){
				 // Get country wise category information.
				$categoryInfo = $this->customProductCategoryMappingRepository->getCategory($productId, $country);
				if(!empty($categoryInfo)){
					$selectedCatId =  array();
					foreach ($categoryInfo as $categoryId){
						$selectedCatId[] = $categoryId['categoryId'];
					}
					$data_to_return['category'][$countryName] = $selectedCatId;
				}
				unset($categoryInfo);
				
				//Regular Price
				$regular_charges = $this->productPriceRepository->getProductWisePrice($productId,$country);
				$data_to_return['regular_variations_charges'][$countryName] = array();
				$regularCharges = array();
				if(count($regular_charges)){
					$priceRangeKeyArray=array();
					foreach($regular_charges as $_regular_charges){
						$key = '';
						if(in_array($_regular_charges->getPricingType(),array('regular','piece_wise','call_for_price'))){
							$from = $_regular_charges->getFromQty();
							$to = ($_regular_charges->getToQty() ? $_regular_charges->getToQty() : '');
							$type = $_regular_charges->getType();
				
							if($_regular_charges->getPricingType()=='call_for_price'){
								if(!in_array($type."_".$from."_".$to,$priceRangeKeyArray))
									$priceRangeKeyArray[]=$type."_".$from."_".$to;
				
									$key= array_search($type."_".$from."_".$to,$priceRangeKeyArray);
							}else{
								if(!in_array($from."_".$to,$priceRangeKeyArray))
									$priceRangeKeyArray[]=$from."_".$to;
									$key= array_search($from."_".$to,$priceRangeKeyArray);
							}
				
							$regularCharges[$key]['from']=$_regular_charges->getFromQty();
							$regularCharges[$key]['to']  =($_regular_charges->getToQty() ? $_regular_charges->getToQty() : '');
							$regularCharges[$key]['type']= $_regular_charges->getType();
							if($type == 'blank'){
								//$regularCharges[$key]['blank_rate']=number_format($_regular_charges->getRate(),3);
								$regularCharges[$key]['blank_rate']= $_regular_charges->getRate() ? $_regular_charges->getRate() : "";
								$regularCharges[$key]['blank_code']=$_regular_charges->getCode();
							}else{
								//$regularCharges[$key]['rate']=number_format($_regular_charges->getRate(),3);
								$regularCharges[$key]['rate']= $_regular_charges->getRate() ? $_regular_charges->getRate() : "";
								$regularCharges[$key]['code']=$_regular_charges->getCode();
							}
				
							$currency = $_regular_charges->getCurrencyId();
						}
					}
					$data_to_return['regular_price_unit'] = $_regular_charges->getPriceUnit();
					$data_to_return['regular_variations_type'] = $_regular_charges->getPricingType();
					$data_to_return['regular_variations_charges'][$countryName] = $regularCharges;
				}
				
				//Below Code for New decorative and blank Split Pricing
				/* $priceTypes = $this->serviceContainer->getParameter('pricing_types'); // "Decorative,Blank"
				foreach($priceTypes as $type){
					//Regular Price
					$regular_charges = $this->productPriceRepository->getProductWisePrice($productObj,$country,null,$type);
					$data_to_return['regular_variations_charges'][$type][$countryName] = array();
					$regularCharges = array();
					if(count($regular_charges)){
					    $priceRangeKeyArray=array();
						foreach($regular_charges as $_regular_charges){
						    $key = '';
							if(in_array($_regular_charges->getPricingType(),array('regular','piece_wise','call_for_price'))){
								$from = $_regular_charges->getFromQty();
								$to = ($_regular_charges->getToQty() ? $_regular_charges->getToQty() : '');
								$type = $_regular_charges->getType();
								
								if($_regular_charges->getPricingType()=='call_for_price'){
									if(!in_array($type."_".$from."_".$to,$priceRangeKeyArray))
									    $priceRangeKeyArray[]=$type."_".$from."_".$to;
									
									$key= array_search($type."_".$from."_".$to,$priceRangeKeyArray);
								}else{
									if(!in_array($from."_".$to,$priceRangeKeyArray))
										$priceRangeKeyArray[]=$from."_".$to;
										
									$key= array_search($from."_".$to,$priceRangeKeyArray);
								}
								
								$regularCharges[$key]['from']=$_regular_charges->getFromQty();
								$regularCharges[$key]['to']  =($_regular_charges->getToQty() ? $_regular_charges->getToQty() : '');
								$regularCharges[$key]['type']= $_regular_charges->getType();
								if($type == 'blank'){
									//$regularCharges[$key]['blank_rate']=number_format($_regular_charges->getRate(),3);
									$regularCharges[$key]['blank_rate']= $_regular_charges->getRate() ? $_regular_charges->getRate() : "";
									$regularCharges[$key]['blank_code']=$_regular_charges->getCode();
								}else{
									//$regularCharges[$key]['rate']=number_format($_regular_charges->getRate(),3);							
									$regularCharges[$key]['rate']= $_regular_charges->getRate() ? $_regular_charges->getRate() : "";
									$regularCharges[$key]['code']=$_regular_charges->getCode();
								}
								
								$currency = $_regular_charges->getCurrencyId();
							}
						}
						$data_to_return['regular_price_unit'][$type] = $_regular_charges->getPriceUnit();
						$data_to_return['regular_variations_type'][$type] = $_regular_charges->getPricingType();
						$data_to_return['regular_variations_charges'][$type][$countryName] = $regularCharges;
					}
					unset($regular_charges);
				} */
					
				//Status
				$countryProd = $this->countryProductRepo->findOneBy(array('productId' => $productObj->getId(), 'countryId' => $country));
				$data_to_return['status'][$countryName] = ($countryProd) ? $countryProd->getStatus() : '';
			}
		}
		return $data_to_return;
	}
	
    public function existsDistributorProduct($masterProductId){
    	if(isset($masterProductId)) {
    		$productObj = $this->productMasterRepository->findOneBy(array('pmsId'=>$masterProductId));
    		if ($productObj) return $productObj;
    	}
    }
    
    public function checkDistributorProductDuplicateSKU($sku,$supplierId,$productId){
    	if($productId){
    		$isDuplicate = $this->productMasterRepository->checkDuplicateSku($sku,$supplierId,$productId);
    	}else{
    		$isDuplicate = $this->productMasterRepository->checkDuplicateSku($sku,$supplierId);
    	}
    	if($isDuplicate){
    		$returnData = array('status' => 'error','message' => 'duplicate_sku');
    	}else{
    		$returnData = array('status' => 'success','message' => 'SKU_doesnot_exist');
    	}

    	return $returnData;
    }
    
    /**
     * @author Employee Id: 5190
     *
     * Description: This Function Used For Listing of Distributor Product Data
     *
     * @param unknown $searchStatus
     * @param string $searchParam
     * @param string $searchQuery
     * @param string $sortType
     * @param string $sortBy
     * @param string $cultureid
     * @param string $supplier_id
     * @param number $records_per_page
     * @param number $page
     * @return multitype:
     */
    public function listDistributorProduct($status,$searchParam='', $searchQuery='', $sortBy='updatedAt', $sortType='DESC',$culture_name="", $country_code = "", $supplier_id="",$projectSuppiers="", $recordsPerPage="",$page="",$projectId="",$brandIds="",$catIds=""){
    	//$projectSuppiers = $this->productApiManager->getSupplierNameList($projectId);
    	$projectSuppiersIds = array_column($projectSuppiers,'supplier_id');
    	$request = $this->serviceContainer->get('request');
    	$country = $this->countryRepository->findOneBy(array("countryCode"=>$country_code));
    	if(is_object($country)){
    		$cultureDetails = $this->serviceContainer->getParameter('language');
    		$cultureId = $cultureDetails[$culture_name]['id'];
    		if($cultureId>0){
    			$firstResult = 0;
    			if($page>1){
    				$firstResult = (($page - 1) * $recordsPerPage);
    			}
    			$maxResult = $recordsPerPage;
    			$country_id = $country->getId();
    			//$imageurl= ($this->request->isSecure()? "https://":"http://").$this->request->getHttpHost().$this->request->getBasePath();
    			//$product_image_path = $this->container->getParameter('_default_product_image_url_path');
    			list($count,$data)=$this->productCultureRepository->productList($status,$searchParam,$searchQuery, $sortBy,$sortType,$cultureId,$country_id,$supplier_id,$firstResult,$maxResult,$projectSuppiersIds,$brandIds,$catIds);
    			
    			foreach ($data as $key=>$value){
    				$productCaptionCulture=$this->productCultureRepository->getProductNameCulture($value['product_master_id'],$cultureId);
    				$data[$key]['productcaption']=$productCaptionCulture;
    			}
    	
    			if($data){
    				$returnData = array();
    				$returnData['count']=$count;
    				$returnData['data']=$data;
    			}else{
    				$returnData=array();
    				$returnData['count']=$count;
    				$returnData['data']=array();
    			}
    		}else{
    			$returnData=array("status" => "error", "error_message"=>'Culture does not exist');
    		}
    	}else{
    		$returnData=array("status" => "error","error_message"=>'Country does not exist');
    	}

    	return $returnData;
    }
    
    /**
     * @author Employee Id: 5190
     *
     * Description: This Function Used For View Distributor Product
     *
     * @param array $requestParams
     *
     * @return array|multitype:string |multitype:string NULL
     */
    public function distributorView($productMasterData){
		$returnData = array();
		$dataToReturn = array();
		$request = $this->serviceContainer->get('request');
		$serializer = $this->serviceContainer->get('serializer');
    	$isDistributor = $this->serviceContainer->getParameter('default_main_instance_type');
		
    	if(strtolower($isDistributor) !== 'distributor'){
    		return $productMasterData;
    	}
    	
		if(array_key_exists('product_id',$productMasterData)){ //called using SLUG
	    	$culture = strtolower($productMasterData['culture']);
	    	list($language,$country) = explode("_",$culture);

	    	$cultureDetails = $this->serviceContainer->getParameter('language');
	    	$languageId = $cultureDetails[$language]['id'];
	    	$countryId = $this->countryRepository->getCountryIdFromCountryCode($country);
	    	$productId = $productMasterData['product_id'];
			$returnData = $this->distributorProductInfo($serializer, null, $productId, $languageId,$countryId,false,$culture);
			if(!isset($returnData['error_message'])){
				$finalData = $this->userFriendlyVersion($productMasterData, $returnData['data'], $language,$country,false,$culture,$isDistributor);
				$dataToReturn = $finalData;
			}else{
				$dataToReturn = $productMasterData;
			}
		}else{
			foreach($productMasterData as $productId=>$productData){ 
                $culture = strtolower($productData['culture']);
                list($language,$country) = explode("_",$culture);
    
                $cultureDetails = $this->serviceContainer->getParameter('language');
                $languageId = $cultureDetails[$language]['id'];
                $countryId = $this->countryRepository->getCountryIdFromCountryCode($country);
                
                if(count($productData)){
                    $returnData = $this->distributorProductInfo($serializer, null, $productId, $languageId,$countryId,false,$culture);
                    if(!isset($returnData['error_message'])){
                        $finalData = $this->userFriendlyVersion($productData, $returnData['data'], $language,$country,false,$culture,$isDistributor);
                        $dataToReturn[$productId] = $finalData;
                    }else{
                        $dataToReturn[$productId] = $productData;
                    }
                }
                else{
                    $dataToReturn[$productId] = $productData;
				}
            }
        }
                    
        return $dataToReturn;
	}
    
    /**
     * @author Employee Id: 5190
     *
     * Description: This Function Used For View Product
     *
     * @param array $requestParams
     *
     * @return array|multitype:string |multitype:string NULL
     */
    public function distViewAPI($product_ids,$product_culture,$is_for_admin=false)
    {
    	//Add product API request
    	$this->productApi->init('view_dist_product_admin');
    	$this->productApi->setCulture($product_culture);
    	$this->productApi->setCallParameters(array('product_ids' => $product_ids));
    	$this->productApi->doProcess();
    
    	$return = false;
    	if ($this->productApi->isSuccess()) {
    		$data = $this->productApi->getResultArray();
    		//$data = $this->distributorView($data); // comment this line when you call this distributor manager distributorView method from distributor controller and uncomment code and comment above 5-6 lines code. 
    		$status = "success";
    		return array("status"=>$status,"data"=> $data);
    	} else {
    		return array('status'=>'error', 'message'=>$this->productApi->getErorDescription());
    	}
    }
    
    protected function userFriendlyVersion($apiProductData,$productInfo,$language,$country,$request_from_virtual,$culture){
    	$data_to_return = !empty($apiProductData) ? $apiProductData : array();
    	$explode_seperator = Constant::$DATA_SEP;
    	//$data_to_return['instance_type'] = "distributor";
    	$data_to_return['product_id'] = isset($productInfo['product_id']) ? $productInfo['product_id'] : $productInfo['local_product_id'];
    	$data_to_return['local_product_id'] = $productInfo['local_product_id'];
        $data_to_return['culture_product_local_id'] = $productInfo['cultureProductId'];
    	$data_to_return['culture'] = $culture;
    
    	$data_to_return['is_deleted'] = ($productInfo['is_deleted'] ? true: false);
    	$cultureId = $productInfo['culture'];
    
    	//BASIC INFO
    	$data_to_return['basic_information']['sku_number'] = $productInfo['masked_s_k_u'];
    
    	if(!empty($productInfo['title']))
    		$data_to_return['basic_information']['title'] = $productInfo['title'];
    
    		if(!empty($productInfo['description'])){
    			$description = str_replace(array("\n","\r","\n\r"), "", $productInfo['description']);
    			$description = preg_replace('/class=".[^"]*"/', ' ', $description);
    			$description = preg_replace("/class='.[^']*'/", ' ', $description);
    			$data_to_return['basic_information']['description'] = $description;
    		}
    
    		if(isset($productInfo['active']))
    			$data_to_return['basic_information']['active'] = $productInfo['active'];
    
			if(!empty($productInfo['slug']))
    			$data_to_return['basic_information']['slug'] = $productInfo['slug'];
    
			if(!empty($productInfo['general_information']) && trim($productInfo['general_information']) !="" )
    			$data_to_return['basic_information']['general_information']  = $productInfo['general_information'];
    
			if(!empty($productInfo['valid_up_to']) && trim($productInfo['valid_up_to']) !="" )
    			$data_to_return['basic_information']['valid_up_to'] = $productInfo['valid_up_to'];
    							
			//Feature details
			if(!empty($productInfo['feature_details']) && $productInfo['feature_details'] !="" )
    			$data_to_return['feature_details'] = $productInfo['feature_details'];

			//KEYWORD
    		if(!empty($productInfo['keyword'])){
    			$keyword = $productInfo['keyword'];
    			$keyword = explode($explode_seperator,$keyword);
    			$data_to_return['keyword'] = implode(",",$keyword);
			}
    								
			$data_to_return['decorative_pricing'] = false;
    		$data_to_return['blank_pricing'] = false;
    
    		//REGULAR PRICING
    		 if(!$request_from_virtual){
    			if(!empty( $productInfo['price_type'])){
    				$data_to_return['price_type'] = $productInfo['price_type'];
				}
    			if(!empty( $productInfo['pricing'])){
    				$data_to_return['pricing'] = $productInfo['pricing'];
				}
    
    			$unit_price = $regular_price = $min_qty =  0;
    			$code = $min_qty_range = "";
    									
    		//	if(!$request_from_virtual){
    			if(!empty($data_to_return['pricing'])){
    				if(array_key_exists('decorative', $data_to_return['pricing'])){
    					$lastRec = end($data_to_return['pricing']['decorative']);
    					$firstRec = $data_to_return['pricing']['decorative'][0];
					}else{
    					$lastRec = end($data_to_return['pricing']['blank']);
    					$firstRec = $data_to_return['pricing']['blank'][0];
					}
    										
					if(!empty( $productInfo['decorative_pricing'])){
    					$data_to_return['decorative_pricing'] = $productInfo['decorative_pricing'];
    				}
    				if(!empty( $productInfo['blank_pricing'])){
    					$data_to_return['blank_pricing'] = $productInfo['blank_pricing'];
					}
    
					$data_to_return['unit_price'] = number_format((float)$firstRec['rate'],3);//$unit_price;
    				$data_to_return['regular_price'] = number_format((float)$firstRec['rate'],3);//$regular_price;
    				$data_to_return['minimum_quantity'] = $firstRec['from'];//$min_qty;
    				$data_to_return['minimum_quantity_range'] = ''.$firstRec['from']."-".$firstRec['to'];//$min_qty_range;
    				//TODO
    				$data_to_return['min_price'] = $lastRec['rate'];//$lastRec['rate'];
    				$data_to_return['code'] = $lastRec['code'];//$code;
				}
				if(!empty( $productInfo['price_unit'])){
    				$data_to_return['price_unit'] = $productInfo['price_unit'];
    			}
			} 
    
			// TODO : Pricing Section After Split Pricing Blank , Decorative
    			/*if(!$request_from_virtual){
    				$priceTypes = $this->serviceContainer->getParameter('pricing_types'); // "Decorative,Blank"
    									
					if(!empty( $productInfo['price_type'])){
    					$data_to_return['new_pricing'] = $productInfo['price_type'];
					}
    				if(!empty( $productInfo['pricing'])){
    					$data_to_return['new_pricing'] = $productInfo['pricing'];
					}
    									
					foreach($priceTypes as $priceType){
    					$data_to_return['new_pricing'][$priceType]['price_unit'] = $productInfo['new_pricing'][$priceType]['price_unit'];
    					$data_to_return['new_pricing'][$priceType]['price_type'] = $productInfo['new_pricing'][$priceType]['price_type'];
    					$data_to_return['new_pricing'][$priceType]['pricing'] = $productInfo['new_pricing'][$priceType]['pricing'];
    
    					$unit_price = $regular_price = $min_qty =  0;
    					$code = $min_qty_range = "";
    									 
    					if(!$request_from_virtual){
    						$lastRec = end($productInfo['new_pricing'][$priceType]['pricing']);
    						$firstRec = $productInfo['new_pricing'][$priceType]['pricing'][0];
    
    						$data_to_return['decorative_pricing'] = $productInfo['decorative_pricing'];
    						$data_to_return['blank_pricing'] = $productInfo['blank_pricing'];
    
    						$data_to_return['unit_price'] = number_format((float)$firstRec['rate'],3);//$unit_price;
    						$data_to_return['regular_price'] = number_format((float)$firstRec['rate'],3);//$regular_price;
    						$data_to_return['minimum_quantity'] = $firstRec['from'];//$min_qty;
    						$data_to_return['minimum_quantity_range'] = ''.$firstRec['from']."-".$firstRec['to'];//$min_qty_range;
    						//TODO
    						$data_to_return['min_price'] = $lastRec['rate'];//$lastRec['rate'];
    						$data_to_return['code'] = $lastRec['code'];//$code;
						}
					}
				}*/
			return $data_to_return;
    	}
    
    
    /**
     * @author Employee Id: 5190
     *
     * Description: This Function Used For compare Supplier and Distributor Product View
     *
     * @param array $requestParams
     *
     * @return array|multitype:string |multitype:string NULL
     */
    public function compareProductView($productId,$culture){
    	$returnData = array();
    	$dataToReturn = array();
    	
    	$request = $this->serviceContainer->get('request');
    	$serializer = $this->serviceContainer->get('serializer');
    
    	//$culture = $this->request->get('product_culture',$this->request->get('_locale',null));
    	list($language,$country) = explode("_",strtolower($culture));
    
    	$cultureDetails = $this->serviceContainer->getParameter('language');
    	$languageId = $cultureDetails[$language]['id'];
    	$countryId = $this->countryRepository->getCountryIdFromCountryCode($country);
    
    	$returnData = $this->distributorProductInfo($serializer, null, $productId, $languageId,$countryId,false,$culture);
    	if(!isset($returnData['error_message'])){
    		// Edit 4246 For Slug
    		$finalData = $returnData['data'];
    		$finalData = $this->userFriendlyVersion(null, $finalData, $language,$country,false,$culture);
    		$dataToReturn[$productId] = $finalData;
    		$dataToReturn = array('status'=>'success','data'=>$dataToReturn);
    	}else{
    		$dataToReturn = $returnData;
    	}

    	return $dataToReturn;
    }
    
    
    /**
     * Emp ID - 5190
     *
     * @param Serializer $serializer
     * @param string $productSlug
     * @param integer $productId
     * @param string $language
     *
     * return product information based on product slug/ product id(s)
     */
    public function distributorProductInfo($serializer, $productSlug, $pmsProductId, $language,$country,$request_from_virtual=false,$culture=''){
    	if ($productSlug !=null || $pmsProductId!=null) {

    		$distProductObj = $this->productMasterRepository->findOneBy(array('pmsId'=>$pmsProductId));
    		if (!$distProductObj) {
    			$returnData = array('status'=>'error', 'error_message'=>'INVALID_PRODUCT_SLUG_OR_ID');
    		} else {
    			$productId = $distProductObj->getId();
    			if ($productId!=null) {
    				$product = $this->productCultureRepository->findOneBy(array('productId'=>$productId,'culture'=>(int)$language));
    				$countryProd = $this->countryProductRepo->findProductById($productId,$country);
    			}
    			
    			if(!$product || !$countryProd){
    				$returnData = array('status'=>'error', 'error_message'=>'INVALID_PRODUCT_SLUG_OR_ID');
    			}
    			else{
    				$productMasterObj = $this->productMasterRepository->getProductInfoById($productId);
    				$productMasterObj = $productMasterObj[0];
    				$supplierId = $productMasterObj->getSupplierId();
    				$cultureProductId = $product->getId();
    				
    				$finalData = array_merge((array) json_decode($serializer->serialize($product, "json")), (array) json_decode($serializer->serialize($productMasterObj, 'json')));
    				$finalData['local_product_id'] = $productId;
    				$finalData['product_id'] = $productMasterObj->getPmsId();
    				$finalData['cultureProductId'] = $cultureProductId;
    				$finalData['valid_up_to'] = (isset($finalData['valid_up_to']) && $finalData['valid_up_to']!=null) ? $finalData['valid_up_to'] : "";
    				 
    				//DO NOT CHECK DELETED_AT IN THIS QUERY AS WE NEED TO ADD FLAG FOR DELETED PRODUCT.
    				//$countryProd = $this->countryProductRepo->findProductById($productId,$country);
    				$countryProd = $countryProd[0];
    				 
    				$finalData['is_deleted'] = (($productMasterObj->getDeletedAt()) || ($countryProd->getDeletedAt())) ? true : false;
    				$finalData['supplier_id'] = $finalData['supplier_id'];
    				$finalData['currency'] = ($countryProd) ? $countryProd->getCurrency() : '';
    				 
    				$finalData['active'] = ($countryProd) ? $countryProd->getStatus() : '';
    				 
    				$finalData['description'] = (isset($finalData['description']) && $finalData['description']!=null) ? $finalData['description'] : "";
    				$descArr = explode("|",$finalData['description']);
    				$descArr = array_unique($descArr);
    				$finalData['description'] = implode("|",$descArr);
    				unset($descArr);
    				 
    				//Category
    				//Revised country wise data
    				/* $categoryInfo = $this->customProductCategoryMappingRepository->getCategory($productId, $country);
    				 $finalData['category'] = $categoryInfo[0]['product_category'];
    				 unset($categoryInfo); */
    				 
    				//Keyword
    				$keywordInfo = $this->searchKeywordRepository->getKeyword($cultureProductId);
    				$finalData['keyword'] = $keywordInfo[0]['keyword'];
    				unset($keywordInfo);
    				 
    				//Feature details
    				$featureLabelValue =  array();
    				$featureDetails = $this->featureDetailsRepository->getFeatureDetails($cultureProductId, $language);
    				foreach($featureDetails as $ind=>$featureDetail){
    					$featureLabelValue[$ind]['label'] = $featureDetail['featureLabel'];
    					$featureLabelValue[$ind]['value'] = $featureDetail['feature'];
    				}
    				$finalData['feature_details'] = $featureLabelValue;
    				unset($featureDetails);
    				 
    				$finalData['decorative_pricing'] = false;
    				$finalData['blank_pricing'] = false;
    				//Regular Price
    				$finalData['price_type'] = '';
    				$finalData['price_type_label'] = '';
    				$finalData['price_unit'] = '';
    				$finalData['pricing'] = array();
    				$finalData = $this->getProductPricing($productId,$country,$finalData);
    				$finalData = $this->getNewProductPricing($productId,$country,$finalData);
    					
    				//return $finalData;
    				$returnData =  array('status'=>'success','data'=>$finalData);
    			}
    		}
    	}

    	return $returnData;
    }
    
    private function getProductPricing($productId,$country,$finalData){
    	$regular_charges = $this->productPriceRepository->getProductWisePrice($productId,$country);
    	$regularCharges = array();
    	if(count($regular_charges)) {
    		foreach($regular_charges as $ind => $_regular_charges) {
    			if(in_array($_regular_charges->getPricingType(),array('regular','piece_wise','call_for_price'))) {
    				$type = $_regular_charges->getType();
    				$regularCharges[$type][$ind]['from']=$_regular_charges->getFromQty();
    				$regularCharges[$type][$ind]['to']  =($_regular_charges->getToQty() ? $_regular_charges->getToQty() : '');
    				//$regularCharges[$type][$ind]['type']= $_regular_charges->getType();
    				$regularCharges[$type][$ind]['rate']=number_format($_regular_charges->getRate(),3);
    				$regularCharges[$type][$ind]['code']=$_regular_charges->getCode();
    					
    				$currency = $_regular_charges->getCurrencyId();
    				$regularCharges[$type] = array_values($regularCharges[$type]);
    					
    				if($type=='decorative'){
    					$finalData['decorative_pricing'] = true;
    				}
    					
    				if($type=='blank'){
    					$finalData['blank_pricing'] = true;
    				}
    			}
    		}
    
    		$finalData['price_type'] = $_regular_charges->getPricingType();
			$finalData['price_unit'] = $_regular_charges->getPriceUnit();
			$finalData['pricing'] = $regularCharges;
    			
    		unset($regularCharges);
    	} 
    	return $finalData;
    }
    
    /** TODO : New ProductPricing After Split Pricing **/
    private function getNewProductPricing($productId,$country,$finalData){
    	$priceTypes = $this->serviceContainer->getParameter('pricing_types'); // "Decorative,Blank"
    	foreach($priceTypes as $priceType){
    		$regular_charges = $this->productPriceRepository->getProductWisePrice($productId,$country,null,$priceType);
    		$regularCharges = array();
    		if(count($regular_charges)) {
    			foreach($regular_charges as $ind => $_regular_charges) {
    				if(in_array($_regular_charges->getPricingType(),array('regular','piece_wise','call_for_price'))) {
    					$type = $_regular_charges->getType();
    					$regularCharges[$ind]['from']=$_regular_charges->getFromQty();
    					$regularCharges[$ind]['to']  =($_regular_charges->getToQty() ? $_regular_charges->getToQty() : '');
    					//$regularCharges[$type][$ind]['type']= $_regular_charges->getType();
    					$regularCharges[$ind]['rate']=number_format($_regular_charges->getRate(),3);
    					$regularCharges[$ind]['code']=$_regular_charges->getCode();
    						
    					$currency = $_regular_charges->getCurrencyId();
    					$regularCharges = array_values($regularCharges);
    					if($type=='decorative'){
    						$finalData['decorative_pricing'] = true;
    					}
    						
    					if($type=='blank'){
    						$finalData['blank_pricing'] = true;
    					}
    				}
    			}
    			$finalData['new_pricing'][$priceType]['price_type'] = $_regular_charges->getPricingType();
    			$finalData['new_pricing'][$priceType]['price_unit'] = $_regular_charges->getPriceUnit();
    			$finalData['new_pricing'][$priceType]['pricing'] = $regularCharges;
    			unset($regularCharges);
    		} 
    	}
    	return $finalData;
    }
    
    /**
     * Emp Id : 4246
     * Description : Add Data from Solr Search
     * @param unknown $productData
     */
    public function addFromSolr($productData,$culture,$languageId){
    	$countryDetails = $this->serviceContainer->getParameter('country');
    	@list($language,$country) = explode('_',$culture);
    	$currencyId = 0;
    	$countryId = 0;
    	if(isset($countryDetails[$country])){
    		$currencyId = $countryDetails[$country]['currency']['id'];
    		$countryId = $countryDetails[$country]['id'];
    	}
    	$productMasterObj = $this->productMasterRepository->addFromSolr($productData);
    	$cultureProductObj = $this->productCultureRepository->addCultureDataFromSolr($productData,$productMasterObj->getId(),$languageId);
    	$countryProductObj = $this->countryProductRepo->addCountryDataFromSolr($productMasterObj->getId(),$countryId,$currencyId);
    	return $productMasterObj;
    }
    
    /**
     * Emp Id: 5190
     * Description : This Function is Set Product Status According To Send Status Active / Inactive
     *
     * @param unknown $productId
     * @param unknown $country
     * @param unknown $setStatus
     */
    public function changeProductStatus($productId='',$country='',$setStatus=''){
    	$productIds = json_decode($productId, true);
    	$countryObj= $this->countryRepository->findOneBy(array("countryCode"=>$country));
    	if(is_object($countryObj)){
    		$countryId = $countryObj->getId();
    		$changeStatus = $this->countryProductRepo->changeProductStatus($productIds,$countryId,$setStatus);
    		if(is_array($changeStatus)){
    			if($setStatus){
    				$message = "PRODUCT_ACTIVATED";
    			}else{
    				$message = "PRODUCT_DEACTIVATED";
    			}
    			$returnData = array('status'=>'success','message'=>$message,'data' => $changeStatus);
    		}else{
    			$returnData = array('status' => 'error','message'=>'DATA_NOT_FOUND');
    		}
    	}else{
    		$returnData = array('status' => 'error','message'=>'COUNTRY_NOT_FOUND');
    	}
    	return $returnData;
    }
    
    /**
     * Emp Id : 5190
     * Description : For Delete product from master Tables
     *
     * @param Integer $productMasterId
     */
    public function deleteProduct($productMasterId,$distributorProductId,$productCountry){
    	$countryObj= $this->countryRepository->findOneBy(array("countryCode"=>$productCountry));
    	$removeData = $this->countryProductRepo->delete($distributorProductId,$countryObj->getId());
    
    	$productCountryObj = $this->countryProductRepo->findBy(array('productId' => $distributorProductId, 'deletedAt' => null));
    	if (count($productCountryObj) == 0) {
    		$this->productMasterRepository->deleteProduct($productMasterId,$distributorProductId);
    	}
    
    	if($removeData){
    		$returnData = array('status'=>'success','message'=>'PRODUCT_DELETED_SUCCESSFULLY');
    	}else{
    		$returnData = array('status' => 'error','message'=>'not_found');
    	}
    	
    	return $returnData;
    }
    
}
?>