<?php



namespace App\Http\Controllers;



use Illuminate\Http\Request;

use Illuminate\Support\Facades\Mail;

use App\Mail\ShortlistMail;


use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Pagination\Paginator;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Support\Facades\Auth;
use Tymon\JWTAuth\Facades\JWTAuth;


use App\Models\User;
use App\Models\Shopify_theme_changes;

use Illuminate\Support\Facades\View;
use App\Models\Diamond;




class MailController extends Controller

{

    /**

     * Send an email with the form data.

     */

    public function sendMail(Request $request)

    {
		$stock_id = $request->stock_number; 
		$retailer_id = 7; 
	  	$dia_type = 'Natural Diamonds';
	  	$pricequery = $this->diamond_price($retailer_id,$dia_type);		
	  	$retailerPermsion = $this->retailer_permsion($retailer_id);
		
		 $diamond_query = "SELECT dm.segomaid , dm.sarineid , vm.external_certificate, vm.external_certificate_path, vm.external_video , vm.external_video_path , vm.external_video_formula , vm.delivery_days , vm.additional_shipping_day , vm.display_invtry_before_login , vm.show_price , vm.external_image , vm.external_image_path , vm.external_image_formula , dm.girdle_thin , dm.girdle_thick , dm.girdle , dm.culet ,dm.diamondid , if(if_display_vendor_stock_no = 1 , dm.vendor_stock_number ,dm.stock_number) as stock_no , dm.stock_number , dm.certificate_company as certificate_company_id , sm.image as shape_image , dm.carat_weight , dm.dm_diamond_type,dm.vendor_path, fco_name, fco_short_name, fci_name, fci_short_name , dm.memo_rap_disc , ( ".$pricequery." /dm.`carat_weight`) as price_per_carat , dm.rap_percentage , ".$pricequery." as price , dlab.dl_name as certificate_company , dm.depth , dm.table_diamond , dm.measurements as measurement , if(availability=0,'No','Yes') as status , if(availability=1,'A',if(availability=2,'M','H')) as availability_status , lm.countries_name as location_name , di.url as video_url , dm.availability , dm.vendor_stock_number , dm.vendorname, dm.is_offer_stone , dm.shape as shape_id ,dm.color as color_id , dm.clarity as clarity_id , dm.cut as cut_id , dm.polish as polish_id , dm.symmetry as symmetry_id , dm.fluorescence as fluorescence_id , dm.delivery_days as dm_delivery_days , dm.measurement_l , dm.measurement_w , dm.measurement_h , dm.shade , dm.locationid ,  dm.image_temp, dm.customer_group , dm.msrp_price , dm.is_matched_pair_separable , dm.matched_pair_stockNumber , dm.certificate_number, dm.is_new_diamond, matchpair_list, dm.length_width_radio , diamond_seo , dm.comments, dm.matched_pair_stockNumber, dm.key_to_symbol,
  dm.additional_field,  dm.certificate_number, dm.certificate_name, dm.base_color, dm.vendor_path, (SELECT count(short_list_id) FROM shop_short_list WHERE ssl_diamond_id = dm.diamondid and ssl_sess_id = '1d5e07323a6c2e3cee609b4312764833' and ssl_customer_id = '0' and ssl_retailer_id = '".$retailer_id."' ) as total_short_list , if(rsm.mapname != '' , rsm.mapname , sm.shortname) as shape_name , if(rsm1.mapname != '' , rsm1.mapname , cm.short_name) as color_name , if(rsm2.mapname != '' , rsm2.mapname , clam.name) as clarity_name , if(rsm3.mapname != '' , rsm3.mapname , cutm.shortname) as cut_name , if(rsm3.mapname != '' , rsm3.mapname , cutm.full_name) as fullcut , if(rsm4.mapname != '' , rsm4.mapname , dpol.short_name) as polish , if(rsm4.mapname != '' , rsm4.mapname , dpol.full_name) as fullpolish , if(rsm5.mapname != '' , rsm5.mapname , dsym.short_name) as symmetry , if(rsm5.mapname != '' , rsm5.mapname , dsym.full_name) as fullsymmetry , if(rsm6.mapname != '' , rsm6.mapname , dflo.short_name) as fluorescence , if(rsm6.mapname != '' , rsm6.mapname , dflo.full_name) as fullfluorescence ,  if(rsm7.mapname != '' , rsm7.mapname , dc.dc_name) as culet, girdle, if(rsm8.mapname != '' , rsm8.mapname , dg1.dg_name) as girdle_thin, if(rsm10.mapname != '' , rsm10.mapname , dg2.dg_name) as girdle_thick, if(rsm9.mapname != '' , rsm9.mapname , dshade.ds_name) as shade, if(rsm.mapname != '' , rsm.mapname , sm.name) as ShapeName , if(rsm1.mapname != '' , rsm1.mapname , cm.name) as ColorName , if(rsm3.mapname != '' , rsm3.mapname , cutm.name) as CutName , if(rsm4.mapname != '' , rsm4.mapname , dpol.name) as PolishName , if(rsm5.mapname != '' , rsm5.mapname , dsym.name) as SymmetryName , if(rsm6.mapname != '' , rsm6.mapname , dflo.name) as FluorescenceName ,if((rsm.mapname = '' || rsm.mapname IS NULL) && (sm.name = '' || sm.name IS NULL) , 99999 , sm.sort_order) as shape_short ,if((rsm1.mapname = '' || rsm1.mapname IS NULL ) && (cm.short_name = '' || cm.short_name IS NULL) , 99999 ,cm.sort_order) as color_short ,if((rsm2.mapname = '' || rsm2.mapname IS NULL ) && (clam.name = '' || clam.name IS NULL) , 99999 , clam.sort_order) as clarity_short ,if((rsm3.mapname = '' || rsm3.mapname IS NULL ) && (cutm.shortname = '' || cutm.shortname IS NULL) , 99999 , cutm.sort_order) as cut_short ,if((rsm4.mapname = '' || rsm4.mapname IS NULL ) && (dpol.short_name = '' || dpol.short_name IS NULL) , 99999 , dpol.sort_order) as polish_short ,if((rsm5.mapname = '' || rsm5.mapname IS NULL ) && (dsym.short_name = '' || dsym.short_name IS NULL) , 99999 , dsym.sort_order) as symmetry_short ,if((rsm6.mapname = '' || rsm6.mapname IS NULL ) && (dflo.short_name = '' || dflo.short_name IS NULL) , 99999 , dflo.sort_order) as fluorescence_short, dlab.cert_url FROM 
  diamond_master as dm 
  left join diamond_shape_master as sm on dm.shape = sm.id 
  left join diamond_color_master as cm on cm.id = dm.color 
  left join diamond_clarity_master as clam on clam.id = dm.clarity 
  left join diamond_cut_master as cutm on cutm.id = dm.cut 
  left join diamond_polish_master as dpol on dpol.id = dm.polish 
  left join diamond_symmetry_master as dsym on dsym.id = dm.symmetry 
  left join diamond_flourescence_master as dflo on dflo.id = dm.fluorescence 
  left join shop_countries as lm on dm.locationid = lm.countries_id 
  left join diamond_images as di on dm.diamondid = di.diamondid 
  and di.type = 'video_link' 
  left join vendor_master vm on vm.vendorid = dm.vendorname 
  left join diamond_lab as dlab on dm.certificate_company = dlab.dl_id 
  left join diamond_fancycolor_intensity_master on fci_id = fancy_color_intensity 
  left join diamond_fancycolor_overtones_master on fco_id = fancy_color_overtone 
  left join retailer_shape_mapping_master as rsm on sm.id = rsm.shapeid 
  and rsm.type = 'shape' 
  and rsm.retailerid = '".$retailer_id."' 
  left join retailer_shape_mapping_master as rsm1 on cm.id = rsm1.shapeid 
  and rsm1.type = 'color' 
  and rsm1.retailerid = '".$retailer_id."' 
  left join retailer_shape_mapping_master as rsm2 on clam.id = rsm2.shapeid 
  and rsm2.type = 'clarity' 
  and rsm2.retailerid = '".$retailer_id."' 
  left join retailer_shape_mapping_master as rsm3 on cutm.id = rsm3.shapeid 
  and rsm3.type = 'cut' 
  and rsm3.retailerid = '".$retailer_id."' 
  left join retailer_shape_mapping_master as rsm4 on dpol.id = rsm4.shapeid 
  and rsm4.type = 'polish' 
  and rsm4.retailerid = '".$retailer_id."' 
  left join retailer_shape_mapping_master as rsm5 on dsym.id = rsm5.shapeid 
  and rsm5.type = 'symmetry' 
  and rsm5.retailerid = '".$retailer_id."' 
  left join retailer_shape_mapping_master as rsm6 on dflo.id = rsm6.shapeid 
  and rsm6.type = 'flourescence' 
  and rsm6.retailerid = '".$retailer_id."' 
  left join client_markup cmark on cmark.retailerid = '".$retailer_id."' 
  left join diamond_culet as dc on dm.culet = dc.dc_id 
  left join retailer_shape_mapping_master as rsm7 on dc.dc_id = rsm7.shapeid 
  and rsm7.type = 'culet' 
  and rsm7.retailerid = '".$retailer_id."'
  left join diamond_girdle as dg1 on dm.girdle_thin = dg1.dg_id 
  left join retailer_shape_mapping_master as rsm8 on dg1.dg_id = rsm8.shapeid 
  and rsm8.type = 'girdle_thin' 
  and rsm8.retailerid = '".$retailer_id."' 
  left join diamond_girdle as dg2 on dm.girdle_thick = dg2.dg_id 
  left join retailer_shape_mapping_master as rsm10 on dg2.dg_id = rsm10.shapeid 
  and rsm10.type = 'girdle_thick' 
  and rsm10.retailerid = '".$retailer_id."'
  left join diamond_shade as dshade on dm.shade = dshade.ds_id 
  left join retailer_shape_mapping_master as rsm9 on dshade.ds_id = rsm9.shapeid 
  and rsm9.type = 'shade' 
  and rsm9.retailerid = '".$retailer_id."' 
  and dm.carat_weight between cmark.price_from 
  and cmark.price_to 
  and cmark.type = '2' 
  left join retailer_markup rmark on rmark.retailerid = '".$retailer_id."' 
  and if(c_markup_type=1, `diamond_price2`+COALESCE(c_markup_value,0), `diamond_price2`+((`diamond_price2`*COALESCE(c_markup_value,0))/100)) between rmark.price_from and rmark.price_to and rmark.type = '1' WHERE quantity = 0 AND status = 1 AND vm.vendor_status=1 AND vm.deleted = 0 and stock_number = '$stock_id'  limit 1";
      
	  $diamond_record = DB::select($diamond_query);
	  
	   foreach($diamond_record as $rec){
			$firstImage = '';
			$rec->diamond_video = '';
			//print_ex($rec);
			//echo $rec->image_temp;
			if(!empty($rec->image_temp)){
				$image = explode(",",$rec->image_temp);
				$firstImage = @$image[0];
				$arrParsedUrl = parse_url($firstImage);
				//print_r($arrParsedUrl);
				if (!empty($arrParsedUrl['path'])) {
					if ($arrParsedUrl['path'] === "http" || $arrParsedUrl['scheme'] === "http" || $arrParsedUrl['path'] === "https" || $arrParsedUrl['scheme'] === "https") {
						
						$rec->diamond_image =  $firstImage;
						//echo $firstImage;
						
					}
				}
				//echo '<br />';
				}else{
						
						$vendorSNimage = 'https://www.amipi.com/'.$rec->vendor_path . '/diamond_images/' . strtolower($rec->vendor_stock_number) . '.jpg';
						$SNimage = 'https://www.amipi.com/'.$rec->vendor_path . '/diamond_images/' . strtolower($rec->stock_number) . '.jpg';
						$vendorSNimage1 = 'https://www.amipi.com/'.$rec->vendor_path . '/diamond_images/' . $rec->vendor_stock_number . '.jpg';
						$SNimage1 = 'https://www.amipi.com/'.$rec->vendor_path . '/diamond_images/' . $rec->stock_number . '.jpg';
						
						if (file_exists($SNimage)) {
							$rec->diamond_image = $SNimage;
						}
						if (file_exists($vendorSNimage)) {
							$rec->diamond_image = $vendorSNimage;
						}
						if (file_exists($SNimage1)) {
							$rec->diamond_image = $SNimage1;
						}
						if (file_exists($vendorSNimage1)) {
							$rec->diamond_image = $vendorSNimage1;
						}

					
					}
			if(empty($rec->diamond_image)){
			//print_r($image);
			//echo '<br />';
			//echo "select type , url from diamond_images where diamondid = '" . $rec->diamondid . "' and type = 'image' order by type desc limit 1";
			$ImagesQuery = "select type , url from diamond_images where diamondid = '" . $rec->diamondid . "' and type = 'image' order by type desc limit 1";
			$imageData = DB::select($ImagesQuery);
			//print_ex($imageData);
			$FirstImageData = @$imageData['0']->url;
				$skfpath1 = $rec->vendor_path . '/diamond_images/';
				$diskimage = $this->getshape($rec->ShapeName, $skfpath1, $FirstImageData, $rec->external_image, $rec->external_image_path, $rec->external_image_formula, $rec->vendor_stock_number, $rec->certificate_number, $rec->diamondid, $rec->vendorname);
				
				
				$rec->diamond_image = 'https://www.amipi.com/'.$diskimage;
			}
			
			//// video /////////
			
			$VideoQuery = "select type , url from diamond_images where diamondid = '" . $rec->diamondid . "' and type = 'video_link' order by type desc limit 1";
			$videoData = DB::select($VideoQuery);
			//print_ex($videoData);
			if(!empty($videoData)){
				$rec->diamond_video =  @$videoData['0']->url;
				}	
				//echo $diskimage;
			 //print_ex($imageData)
			 
			}
			$rec->diamond_cert_link = '';
			//if(!empty($rec->certificate_number)){
				$CertificateLink = $this->getcertificate($rec->external_certificate,$rec->external_certificate_path,$rec->vendor_path,$rec->certificate_number,$rec->certificate_name,$rec->diamondid,$rec->vendor_stock_number,$rec->vendorname,$rec->stock_number);
				
				$FinalCertificateLink = '';
				if($CertificateLink != '')
				{
					$FinalCertificateLink = $CertificateLink;
				}else{
					 
					$CertificateLink1 =	$rec->cert_url.$rec->certificate_number;
					$FinalCertificateLink = $CertificateLink1;
					}
					
					$rec->diamond_cert_link =  $FinalCertificateLink;
          
        // Validate the incoming form data

        $validatedData = $request->validate([

            'your_name' => 'required|string',

            'your_email' => 'required|email',

            'friend_name' => 'required|string',

            'friend_email' => 'required|email',

            'personal_message' => 'nullable|string',

            'stock_number' => 'required|string',

            'current_url' => 'required|url',			
			
        ]);

		//print_r($validatedData); die(' line 51');

        // Send the email to the friend
		
	

       Mail::to($validatedData['friend_email'])->send(new ShortlistMail($validatedData,$diamond_record));
        // Return a JSON response indicating success
        return response()->json(['status' => 'success','request' => $validatedData,'diamond_record' => $diamond_record])
                                    ->header('Access-Control-Allow-Origin', '*')
                                    ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
                                    ->header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
      

    }
	
	
	function diamond_price($retailerid , $DiamondType=null) {
      		
			$retailerid = 7;
			//$DiamondType = '';
			
	  		$price_level = 1;
			$AliasName = '';
			$AliasName1 = '';
			if($DiamondType == '')
			{
				$AliasName = 'cmark.';
				$AliasName1 = 'rmark.';
			}
			
			// echo "SELECT retailer_certified_level_id,retailer_noncertified_level_id,retailer_cvd_level_id,retailer_jewelry_level_id,customer_level,as_certified_diamonds_per , as_certified_diamonds_flat , as_cvd_per , as_cvd_flat , as_jewelry_per , as_jewelry_flat FROM retailer_master rm JOIN shop_customer_level cl ON rm.retailer_certified_level_id=cl.customer_level_id JOIN affiliate_store_setup ass ON rm.retailerrid=ass.as_retailer_id WHERE rm.retailerrid = $retailerid and parent_retailer_id = 0";
			 $query = "SELECT retailer_certified_level_id,retailer_noncertified_level_id,retailer_cvd_level_id,retailer_jewelry_level_id,customer_level,as_certified_diamonds_per , as_certified_diamonds_flat , as_cvd_per , as_cvd_flat , as_jewelry_per , as_jewelry_flat FROM retailer_master rm JOIN shop_customer_level cl ON rm.retailer_certified_level_id=cl.customer_level_id JOIN affiliate_store_setup ass ON rm.retailerrid=ass.as_retailer_id WHERE rm.retailerrid = $retailerid and parent_retailer_id = 0";			 
      		 $records = DB::select($query);
			 
			// print_r($records); die();
			 
			
			
			 $customer_level = $records['0']->customer_level; 
			 $as_certified_diamonds_per = (int)@$records['0']->as_certified_diamonds_per;
			 $as_certified_diamonds_flat = (int)@$records['0']->as_certified_diamonds_flat;
			 $as_cvd_per = (int)@$records['0']->as_cvd_per;
			 $as_cvd_flat = (int)@$records['0']->as_cvd_flat;
	  
			if((int)@$customer_level == 0)
			{	
				return "`diamond_price".$price_level."`";	
				exit;
			}
			
			$price_level = (int)@$customer_level;
			
			 if($DiamondType == 1){
			
			$str="if(".$AliasName."c_markup_type=1,`diamond_price".$price_level."`+COALESCE(".$AliasName."c_markup_value,0),`diamond_price".$price_level."`+((`diamond_price".$price_level."`"."*COALESCE(".$AliasName."c_markup_value,0))/100))";			
				$price=$str;			
				$price1=$price;			
				$str="
				(CEIL((
				CASE
				WHEN ".$AliasName1."markup_type = 1 AND COALESCE(".$AliasName1."markup_value,0) >= ".$as_certified_diamonds_flat." 				
				THEN ".$price." + COALESCE(".$AliasName1."markup_value,0)
				
				WHEN ".$AliasName1."markup_type = 1 AND COALESCE(".$AliasName1."markup_value,0) < ".$as_certified_diamonds_flat." 
				THEN ".$price." + ".$as_certified_diamonds_flat."				
				
				WHEN ".$AliasName1."markup_type = 2 AND COALESCE(".$AliasName1."markup_value,0) >= ".$as_certified_diamonds_per." 
				THEN ".$price." + ((".$price.""." * COALESCE(".$AliasName1."markup_value,0))/100)				
				
				WHEN ".$AliasName1."markup_type = 2 AND COALESCE(".$AliasName1."markup_value,0) < ".$as_certified_diamonds_per." 
				THEN ".$price." + ((".$price.""." * ".$as_certified_diamonds_per.")/100)				
				
				WHEN COALESCE(".$AliasName1."markup_type,0) = 0 AND ".$as_certified_diamonds_per." > 0 
				THEN ".$price." + ((".$price.""." * ".$as_certified_diamonds_per.")/100)				
				
				WHEN COALESCE(".$AliasName1."markup_type,0) = 0 AND ".$as_certified_diamonds_flat." > 0 
				THEN ".$price." + ".$as_certified_diamonds_flat."
				
						
				ELSE ".$price."
				END
				)/10)*10 )
				";
				$price=$str;
			 }else{
				//echo $price; die();
				
				$str="if(".$AliasName."c_markup_type=1,`diamond_price".$price_level."`+COALESCE(".$AliasName."c_markup_value,0),`diamond_price".$price_level."`+((`diamond_price".$price_level."`"."*COALESCE(".$AliasName."c_markup_value,0))/100))";			
				$price=$str;			
				$price1=$price;					
				$str="
				(CEIL((
				CASE
				WHEN ".$AliasName1."markup_type = 1 AND COALESCE(".$AliasName1."markup_value,0) >= ".$as_cvd_flat." 				
				THEN ".$price." + COALESCE(".$AliasName1."markup_value,0)
				
				WHEN ".$AliasName1."markup_type = 1 AND COALESCE(".$AliasName1."markup_value,0) < ".$as_cvd_flat." 

				THEN ".$price." + ".$as_cvd_flat."				
				
				WHEN ".$AliasName1."markup_type = 2 AND COALESCE(".$AliasName1."markup_value,0) >= ".$as_cvd_per." 
				THEN ".$price." + ((".$price.""." * COALESCE(".$AliasName1."markup_value,0))/100)				
				
				WHEN ".$AliasName1."markup_type = 2 AND COALESCE(".$AliasName1."markup_value,0) < ".$as_cvd_per." 
				THEN ".$price." + ((".$price.""." * ".$as_cvd_per.")/100)				
				
				WHEN COALESCE(".$AliasName1."markup_type,0) = 0 AND ".$as_cvd_per." > 0 
				THEN ".$price." + ((".$price.""." * ".$as_cvd_per.")/100)				
				
				WHEN COALESCE(".$AliasName1."markup_type,0) = 0 AND ".$as_cvd_flat." > 0 
				THEN ".$price." + ".$as_cvd_flat."					
						
				ELSE ".$price."
				END
				)/10)*10 )
				";
				$price=$str;
				
			 }
			
			return $price;
  
  
     
      
    }
	
	function retailer_permsion($retailer_id) 
	{
		  $query = "SELECT 
				
			allow_availability , display_jewelry_before_login,display_certified_before_login,display_non_certified_before_login ,(select customer_level from shop_customer_level where customer_level_id = r.retailer_certified_level_id ) as retailer_certified_level_id ,(select customer_level from shop_customer_level where customer_level_id = r.retailer_cvd_level_id ) as retailer_cvd_level_id , (select customer_level from shop_customer_level where customer_level_id = r.retailer_noncertified_level_id ) as retailer_noncertified_level_id , (select customer_level from shop_customer_level where customer_level_id = r.retailer_jewelry_level_id ) as retailer_jewelry_level_id ,  admin_email_address , retailerrid , retailer_companyname , retailer_level_id , rv_level_id , retailer_name ,firstname , lastname , email ,  retailer_logo , retailer_filter , 	client_filter , cvd_client_filter , cvd_retailer_filter , allow_loope , allow_video, filter_diamond_size_from , filter_diamond_size_to , filter_diamond_shape , filter_diamond_color , filter_diamond_clarity , filter_diamond_cut , filter_diamond_polish , filter_diamond_symmetry , filter_diamond_fluorescence , filter_diamond_lab , filter_diamond_vendor , filter_diamond_price_from , filter_diamond_price_to , filter_country_id , allow_milky , allow_black ,display_rap_percentage , filter_country_id , retailer_status , fb_link , twitter_link , insta_link, pin_link, r_is_display_delivery_days, display_price_lab_grown_before_login, home_diamond_superdeal, home_category, home_jewelry_superdeal, home_quick_search,quick_search_mind_dia, quick_search_lab_dia,ticker,full_price_show
				
				, as_image,as_small_image,as_top_image,as_favicon_image,as_loding_image, as_web_flag1 , as_web_flag2 , as_web_flag3 , as_filter_diamond_shape , as_filter_diamond_color , as_filter_diamond_clarity , as_filter_diamond_cut , as_filter_diamond_polish , as_filter_diamond_symmetry , as_filter_diamond_fluorescence , as_filter_diamond_lab , as_filter_diamond_vendors , as_filter_location , as_allow_loope , as_allow_video , as_allow_memo , as_allow_milky , as_allow_black , as_r_is_display_delivery_days , as_display_rap_percentage , as_allow_availability , as_display_certified_before_login , as_display_non_certified_before_login , as_display_diamond_price_before_login , as_display_jewelry_price_before_login ,		
as_filter_diamond_size_from , as_filter_diamond_size_to , as_filter_diamond_price_from , as_filter_diamond_price_to , as_guaranteed_availability , as_display_jewelry_before_login , as_display_cart_icon, as_display_share_with_friend, as_display_print_diamond_detail, as_export_to_excel, as_export_to_pdf, as_diamond_quote_button, as_jewelry_quote_button, as_lab_jewelry_quote_button, as_us_ct, as_display_similar_products, as_filter_metal_type , as_filter_metal_color , as_filter_metal_quality , as_filter_product_diamond_color,as_filter_product_diamond_clarity, as_filter_vendors , as_filter_category , as_filter_sub_category, as_filter_sub_category_group, as_navigation,display_cert_number,is_email_verified,

				as_main_background,
				as_header_background,	
				as_inner_header_background,
				as_footer_background,
				as_body_background,
				as_first_filter_background,
				as_second_filter_background,
				as_heading_color,
				as_sub_heading_color,
				as_filter_shadow_color,
				as_textbox_background_color,
				as_listing_mouse_over_color,
				as_primary_color,
				as_primary_color_link,
				as_primary_color_link_mouseover,
				as_button_color,
				as_button_color_mouseover,
				as_button_background_color,
				as_button_background_color_mouseover,
				as_extra_button_color,
				as_extra_button_color_mouseover,
				as_extra_button_background_color,
				as_extra_button_background_color_mouseover,
				as_top_header_background,
				as_top_header_text_color,
				as_top_header_text_color_hover,
				as_top_header_text_icon,
				as_top_header_text_icon_hover,
				as_diamond_filter_svg,
				as_diamond_filter_svg_hover,
				as_match_diamond_background,
				as_match_diamond_background_hover,
				as_main_header_icon,
				as_main_header_icon_hover,
				as_heading_font_type,
				as_heading_font_size,
				as_sub_heading_font_type,
				as_sub_heading_font_size,
				as_normal_font_type,
				as_normal_font_size,
				as_other_font_size,
				as_button_text_font_type,
				as_button_text_font_size
				, as_store_name , as_contact_name , as_email , as_phone , as_fax , as_address , as_city , as_state , as_zip , as_country
			, as_certified_diamonds_per , as_certified_diamonds_flat , as_cvd_per , as_cvd_flat , as_jewelry_per , as_jewelry_flat
			
			,as_meta_title  , as_meta_keyword  , as_meta_description , as_ga_code , as_otherscript_code , as_chatscript_code , as_menu_type, store_locator,  admin_as_filter_vendors  , as_allow_cvd
			
				from retailer_master as r 
				
				left join admin_master as a on r.representative_id = a.admin_id 
				
				left join retailer_master_other as rmo on r.retailerrid = rmo.retailer_id 
				
				left join affiliate_store_setup as ass on r.retailerrid = ass.as_retailer_id 	
				
				left join affiliate_store_setup_template as ast on ass.as_id = ast.as_id and is_primary = 1  			 	
				
				WHERE 1 and parent_retailer_id = 0 and r.deleted=0 and retailerrid = ".$retailer_id."";	
						 
      		 $records = DB::select($query);
			  
			 
			 
		return $records;
	}
	
	function getcertificate($isexternal,$extpath,$vpath,$certnumber,$certname,$diamondid,$vendorstock,$vendorid,$stocknum=null)
	{
		/*echo $isexternal.'isexternal <br>';
		echo $extpath.'extpath <br>';
		echo $vpath.'vpath <br>';
		echo $certnumber.'certnumber <br>';
		echo $certname.'certname <br>';
		echo $diamondid.'diamondid <br>';
		echo $vendorstock.'vendorstock <br>';
		echo $vendorid.'vendorid <br>';*/
		//if($isexternal==0) //store in database and in our server
		$linknv="";
		{				
			if($certname!="" && file_exists($vpath.'/diamond_certificate/'.$vendorstock))
			{
				$nvcertificate_name = $vendorstock;
				$ext = pathinfo($nvcertificate_name, PATHINFO_EXTENSION);			
				if($ext == 'pdf')
				{
					$linknv=$vpath.'/diamond_certificate/'.$certname;
				}
				else
				{
					$linknv='pdf_image/index.php?id='.$diamondid;
				}
			}
			else if($certnumber != "")
			{
				$nvcertificate_name = $vendorstock.'.pdf';		
				if(file_exists($vpath.'/diamond_certificate/'.$nvcertificate_name))
				{	
					$linknv=$vpath.'/diamond_certificate/'.$nvcertificate_name;
				}
				$nvcertificate_name = $certnumber.'.jpg';		
				if(file_exists($vpath.'/diamond_certificate/'.$nvcertificate_name))
				{	
					$linknv='pdf_image/index.php?id='.$diamondid;
				}
			}
			else if($vendorstock != "")
			{
				//if($linknv == ""){
					$nvcertificate_name = $vendorstock.'.pdf';		
					if(file_exists($vpath.'/diamond_certificate/'.$nvcertificate_name))
					{	
						$linknv=$vpath.'/diamond_certificate/'.$nvcertificate_name;
					}
					$nvcertificate_name = $certnumber.'.jpg';		
					if(file_exists($vpath.'/diamond_certificate/'.$nvcertificate_name))
					{	
						$linknv='pdf_image/index.php?id='.$diamondid;
					}
					//echo $linknv; die;
				//}
			}
			else
			{
				$linknv="";									
			}
		}
		
		return $linknv;
	}
	
	function getshape($shapename,$filepath='',$filename='',$external=0,$extpath='',$extformula='',$vendorstock='',$certno='',$did='',$vendorid='')
	{
		$tempimgpath = "images/tempimage/images/";		
		$cpath = $vendorid.'_'.$vendorstock;
		$extformula = str_replace("%CERTIFICATE.NUMBER%",$certno,$extformula);
		$extformula = str_replace("%VENDORSTOCKNUMBER%",$vendorstock,$extformula);
		$extformula = str_replace("%FILENAME%",$filename,$extformula);
		$shapename = strtolower($shapename);
		$shapepath = '';
		if($shapename != '')
		{
			$shapepath = "images/shape/".$shapename."_big.jpg";	
		}
		//if($external==0)
		{
			if($filename!="" && file_exists($filepath.$filename))
			{
				return $filepath.$filename;			
			}
			else
			{			
				return $shapepath;				
			}
		}
		/*else
		{
			if($extpath=="" || $extformula=="")return $shapepath;
			$allimage=explode(";",$extformula);
			$imagedata="";
			$te=0;
			for($p4=0;$p4<=count($allimage)-1;$p4++)
			{
				$imgnew=explode("/",$allimage[$p4]);		
				$checkimage=$imgnew[count($imgnew)-1];			
				$tempcheckfile=$tempimgpath.$cpath.$p4."_".$checkimage;			
				if(file_exists(HTTP_SERVER.$tempcheckfile))
				{
					$imagedata=$imagedata.$tempcheckfile.";";
					$te++;
					continue;
				}
				$curpath=$extpath.$allimage[$p4];
				$rfdetail=array();
				$rfdetail=url_exists($curpath);
				if($rfdetail['success']==1)		
				{
					if(!file_exists($tempcheckfile))
					{
						generatenewfile($curpath,$tempcheckfile);
					}
					$imagedata=$imagedata.$tempcheckfile.';';
					$te++;							
				}
			}	
			if($te==0)$imagedata=$shapepath;
			return $imagedata;	
		}*/
	}  

}

