<?php 
error_reporting(E_ERROR | E_PARSE);
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Uploadproduct extends CI_Controller {
    
    public function __construct() {
        parent::__construct();
         if (! $this->session->userdata ( 'user_logged_in' ) || !company_url($this->session->userdata ('company_slag'))) {
            redirect ( 'login', 'refresh' );
        }
        $this->load->vars ( array (
                'global' => 'Available to all views',
                'header' => 'common/header',
                'left' => 'common/left',
                'footer' => 'common/footer' 
        ) );
        $this->load->model('Bank_model');
        $this->load->model('Invoice_model');
        $this->load->model('Product_model');
    }

    /*public function index(){
        $data['bank_list'] = $this->Bank_model->get_bank_list();		
		$bank_deposit_list = $this->Bank_model->get_bank_deposit_details();
        $data['bank_deposit_list'] = array();
        if (count($bank_deposit_list) > 0) {
            foreach ($bank_deposit_list as $key => $value) {
                $data['bank_deposit_list'][$value->account_id]['debit'] = $value->debit;
                $data['bank_deposit_list'][$value->account_id]['credit'] = $value->credit;
            }
        }		
        $this->load->view('bank_list',$data);		
    }*/
    
    
    
    public function index(){
        $data['vendor_list'] = $this->Product_model->get_vendor();		
		
       /* echo "<pre>";
        print_r($data);
        exit(); */		
		
        $this->load->view('upload_product',$data);		
    }
    

    public function newbank(){
        $data['bank_id'] = !empty($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        if ($data['bank_id'] > 0) {
            $data['bank_data'] = $this->Bank_model->get_bank_details($data['bank_id']);
        }
        $this->load->view('new_bank',$data);
    }

    public function updatedesignsolid(){ 

        $activesuryasku = $this->Bank_model->updatedesignsolid();

    }

    public function renameproducts(){  
        
        $all_pro = $this->Bank_model->mr_product_rename(); // 5499 total surya
        $ii = 0;

        foreach($all_pro as $pro){
            $ii++;

            // Surya Modern Loom

            $name = str_replace("Chandra","Modern Loom",$pro['name']);
           
            $key = $pro['keyword_additions'];
            $key = $key." ".$name." ".$pro['name'];

            $product_update_data = array(
                'name' => $name,
                'name_backup' => $pro['name'],
                'keyword_additions' => $key
            );

            $photo_id = $pro['photo_id'];           
            // $this->Bank_model->import_product($product_data);
            $this->Bank_model->update_product($product_update_data,$photo_id);

            // exit();

            if($ii >= 520) break;
        }

        echo "total =".$ii;

    }

    public function rsproductsimage(){  
        
        $all_pro = $this->Bank_model->rsproductsimagelist(); // 5499 total surya
        $ii = 0;

        foreach($all_pro as $pro){
            $ii++;

            // Surya Modern Loom

            $name = "/rug_images/extra_images/".$pro['filename'];

            $product_update_data = array(
                'room_pic' => $name
            );

            $photo_id = $pro['photo_id'];           
            // $this->Bank_model->import_product($product_data);
            $this->Bank_model->update_product($product_update_data,$photo_id);

            // exit();

            // if($ii >= 520) break;
        }

        echo "total =".$ii;

    }

    public function updatecomprosector(){  
        
        $all_pro = $this->Bank_model->comm_product_active();
        $ii = 0;

        foreach($all_pro as $pro){

           $sector = strtolower($pro['sector']);  
           $key = $pro['keyword_additions'];
           
           if($sector == "luxury suite rugs")
           {
                $key = $key." Boutique Rugs";
                
                $product_update_data = array(
                    'sector' => "Boutique Rugs",
                    'keyword_additions' => $key
                );

                $photo_id = $pro['photo_id'];
                $ii++;
                
                // $this->Bank_model->import_product($product_data);
                $this->Bank_model->update_product($product_update_data,$photo_id);

           }elseif($sector == "ready to ship rugs")
           {
                $key = $key." In Stock";

                $product_update_data = array(
                    'sector' => "In Stock",
                    'keyword_additions' => $key
                );

                $photo_id = $pro['photo_id'];
                $ii++;
                
                // $this->Bank_model->import_product($product_data);
                $this->Bank_model->update_product($product_update_data,$photo_id);
            }

        }

        echo "total =".$ii;
        

    }

    public function updateprooffer(){  
        
        $all_pro = $this->Bank_model->comm_product_active();
 
        $ii = 0;
        
        foreach($all_pro as $pro){
         
              $arr_variation = json_decode($pro['variations']);   
 
             foreach($arr_variation as $key=>$variation){
 
                         $arr_variation[$key]->oldPrice = $variation->price;
                         $arr_variation[$key]->price = (int)(round($variation->price * .75));                      
                    
             }
 
             // print_r($f_attr);   
 
             $f_attr = json_encode($arr_variation);
 
              // echo $f_attr;             
             
             $product_update_data = array(
                 'variations' => $f_attr,
                 'promo' => 0,
                 'sale' => "25%",
                 'couponDiscount' => ''
             );
 
             $photo_id = $pro['photo_id'];
             $ii++;
             //exit();
             
             // $this->Bank_model->import_product($product_data);
              $this->Bank_model->update_product($product_update_data,$photo_id);
             //exit();
        }
 
        echo "total =".$ii;
     
     }
    
    public function updatecompro(){  
        
       $all_pro = $this->Bank_model->comm_product_active();

       $ii = 0;
       
       foreach($all_pro as $pro){
        
            // print_r($pro);
            // echo $pro['attributes'];
             echo "<pre>";
             $attr_arr = json_decode($pro['attributes'],1);                     

            // print_r($attr_arr);
            $f_attr = array();

            //{"value":"tibetan","group":"type","name":"tibetan"} {"name":"silk","value":"silk","group":"material"}

            

            foreach($attr_arr as $attr)
            {
                if($attr['name'] == "silk" && $attr['group'] == "design")
                {
                    $f_attr[] = $attr;
                    continue;
                }
                
                /* 
                if($attr['name'] == "commercial" && $attr['group'] == "type")
                {
                    continue;
                }

                if($attr['name'] == "tibetan" && $attr['group'] == "type")
                {
                    $attr['name'] = "hand knotted";
                    $attr['value'] = "hand knotted";
                }
                
                if($attr['name'] == "oddshaped" && $attr['group'] == "type")
                {
                    $attr['name'] = "odd-shape";
                    $attr['value'] = "odd-shape";
                }

                if($attr['name'] == "hilo" && $attr['group'] == "design")
                {
                    $attr['name'] = "texture";
                    $attr['value'] = "texture";
                }

                if($attr['name'] == "solid" && $attr['group'] == "design")
                {
                    $attr['name'] = "solid colored";
                    $attr['value'] = "solid colored";
                }*/
                
                if($attr['name'] == "silk" && $attr['group'] == "material")
                {
                    $f_attr[]=array("group"=>"design","name"=>"silk","value"=>"silk");
                }

                $f_attr[] = $attr;
            } 

            $f_attr[]=array("group"=>"type","name"=>"commercial","value"=>"commercial");

            // print_r($f_attr);   

            $f_attr = json_encode($f_attr);

            // echo $f_attr;
            
            $product_update_data = array(
                'attributes' => $f_attr
            );

            $photo_id = $pro['photo_id'];
            $ii++;
            
            // $this->Bank_model->import_product($product_data);
             $this->Bank_model->update_product($product_update_data,$photo_id);
            //exit();
       }

       echo "total =".$ii;
    
    }

    public function updatesuryamap(){     
        
        // $updates_file = './MAP_and_MSRP_December_2021.csv'; // "./".$importdata->file;      
        $updates_file = './Modern_Rugs_2022_Pricing_1_20_22.csv';

        // $updates_file = './test_20_1_22.csv';
        $target_file = $updates_file;

        $activesuryasku = $this->Bank_model->getactivesuryasku();

        //echo "echo";
        //print_r($activesuryasku);

        $activeskuarray = array();
        foreach($activesuryasku as $acsku)
        {
            $narr = explode("_",$acsku['vendor_sku']);
            $activeskuarray[] = $narr[0];
        }        
        
        $row = array();
        $updates_handle = fopen($target_file, 'r');
        
        if ($updates_handle) {
            $count = 0;
            $allcount = 0;
            $activecount = 0;
            while ($row = fgetcsv($updates_handle, 500000, ",")) {
                $category_id = NULL;
                if ($count != 0) {
                    $sizesku = trim($row[0]);                   
                    $vendorsku = trim($row[1]); 
                    $upc = trim($row[2]);
                    $cost = trim($row[3]);
                    $map = trim($row[4]);
                    $msrp = trim($row[5]);

                    if(in_array($vendorsku,$activeskuarray))
                    {
                        //echo $map."<br>";
                        //$map = round($map - ($map * .10));
                        
                        // echo $vendorsku."<br>";
                        if($map != "")
                        {
                            $this->Bank_model->updatemap($sizesku,$vendorsku,$map,$msrp,$upc);
                            $activecount++;
                        }                        
                    }
                    $allcount++;
                }else{
                    $count++;
                }
            }
            echo "Successfull total - ".$allcount;
            echo "Successfull total Active - ".$activecount;
        }

    }


    public function updatesuryastock(){     
        
        // $updates_file = './MAP_and_MSRP_December_2021.csv'; // "./".$importdata->file;      
        $updates_file = './inventory_20220928.csv';

        // $updates_file = './test_20_1_22.csv';
        $target_file = $updates_file;

        $activesuryasku = $this->Bank_model->getallsuryasku();

        //echo "echo";
        //print_r($activesuryasku);

        $activeskuarray = array();
        foreach($activesuryasku as $acsku)
        {
            $narr = explode("_",$acsku['vendor_sku']);
            $activeskuarray[] = $narr[0];
        }        
        
        $row = array();
        $updates_handle = fopen($target_file, 'r');
        
        if ($updates_handle) {
            $count = 0;
            $allcount = 0;
            $activecount = 0;
            $vskuold = "";
            $vskunew = "";
            $sizeactive = 0;
            $designactive = 0;
            while ($row = fgetcsv($updates_handle, 500000, ",")) {
                $category_id = NULL;
                if ($count != 0) {   
                    
                    $sizeactive = 0;

                    $sizesku = trim($row[0]); 
                    //echo "<br>";                  
                    $vendorsku = trim($row[2]);
                    //echo "<br>"; 
                    $upc = trim($row[1]);
                    //echo "<br>";
                    $stock = trim($row[3]); 

                    if(in_array($vendorsku,$activeskuarray))
                    {                           
                        if($count == 1)
                        {
                            $vskunew = $vendorsku;
                            $vskuold = $vendorsku;
                            $count++;
                        }else{
                            $vskunew = $vendorsku;
                        }

                        if($vskunew != $vskuold)
                        {
                            if($designactive == 0)
                            {
                                $status_pro = 2;
                                $this->Bank_model->updatevsku($vskuold,$status_pro);
                                echo "status = 2 -- ".$vskuold."<br>";
                            }else{
                                $status_pro = 0;
                                $this->Bank_model->updatevsku($vskuold,$status_pro);
                                $designactive = 0;
                                echo "status = 0 -- ".$vskuold."<br>";
                            }                            
                        }

                        if($stock > 0)
                        {   
                            $designactive = 1;
                            $sizeactive = 1;
                        }

                        $this->Bank_model->updatestock($sizesku,$vendorsku,$sizeactive,$upc);
                        $vskuold = $vendorsku;
                        $activecount++;
                                        
                    } 
                    $allcount++;
                }else{
                    $count++;
                }
            }
            echo "Successfull total - ".$allcount;
            echo "Successfull total Active - ".$activecount;
        }

    }


    public function disablesuryalist(){     
        
        // $updates_file = './MAP_and_MSRP_December_2021.csv'; // "./".$importdata->file;      
        $updates_file = './skulist.csv';

        // $updates_file = './test_20_1_22.csv';
        $target_file = $updates_file;

        $activesuryasku = $this->Bank_model->getactivesuryasku();

        //echo "echo";
        //print_r($activesuryasku);

        $activeskuarray = array();
        foreach($activesuryasku as $acsku)
        {
            $narr = explode("_",$acsku['vendor_sku']);
            $activeskuarray[] = $narr[0];
        } 
        
       // echo "<pre>";
       // print_r($activeskuarray);
        
        $row = array();
        $updates_handle = fopen($target_file, 'r');
        
        if ($updates_handle) {
            $count = 0;
            $allcount = 0;
            $activecount = 0;
            while ($row = fgetcsv($updates_handle, 500000, ",")) {
               // $category_id = NULL;
                if ($count != 0) {
                    if(trim($row[0]) == "") continue;
                    $sizesku[] = trim($row[0]);                   
                    /* $vendorsku = trim($row[1]); 
                    $upc = trim($row[2]);
                    $cost = trim($row[3]);
                    $map = trim($row[4]);
                    $msrp = trim($row[5]); */

                  /*  if(in_array($vendorsku,$activeskuarray))
                    {
                        //echo $map."<br>";
                        //$map = round($map - ($map * .10));
                        
                        // echo $vendorsku."<br>";
                        if($map != "")
                        {
                            $this->Bank_model->updatemap($sizesku,$vendorsku,$map,$msrp,$upc);
                            $activecount++;
                        }                        
                    } */
                    $allcount++;
                }else{
                    $count++;
                }
            }
           // echo "Successfull total - ".$allcount;
           // echo "Successfull total Active - ".$activecount;
           // echo "<pre>";
           // print_r($sizesku);
        }
        echo "================";
        $ijk = 0;
        foreach($activeskuarray as $acps)
        {   
            if(!in_array($acps,$sizesku)) 
            {   
                $ijk++;
                //echo $acps."<br>"; 
                $vendor_sku = $acps;

                $product_update_data = array(
                    'new_arrival' => 2
                );

                $this->Bank_model->update_product_ven($product_update_data,$vendor_sku);

            }
        }

        echo $ijk;

    }


    public function importnewcom(){ 

        // $updates_file = './commercial-patterned-fareeds-021522.csv';
        // $updates_file = './fareed-nuuk-collection-041522.csv';
        $updates_file = './fareed-arts-and-crafts-rugs-052422.csv';
        $target_file = $updates_file;

        $row = array();
        $updates_handle = fopen($target_file, 'r');
        $countProduct = 0;

        if ($updates_handle) {
            $count = 0;
            while ($row = fgetcsv($updates_handle, 500000, ",")) {
                $category_id = NULL;
                if ($count != 0) {                       
                        $photo_id = $row[0]; 
                        $nphoto_id = $row[0]; 
                        $vendor_sku = $row[0];                             
                        $name =  $row[1];
                        //$name_arr = explode(" ",$name);
                        //$name = $name_arr[0]." ".$name_arr[1];

                        $orig_name = $row[2];      
                       /* $description = "<p>Fareed's rekindled fascination with patterns stands at the forefront of this collection of handmade luxury rugs, opting to revive a language that has long been ignored by him and yet surrounded him in music, nature, mathematics, and other graphic structures; all these are now finding their way back into his rugs. Fareed's work has never been inhibited by geometric shapes, lines, and rhythm, but now his current passion is somewhat of a \"tamed abstract,\" celebrating the beauty of architecture.<p>
                        <p>The simple compositions of these hand knotted patterned rugs woven in ancient traditions with Fareed's signature color combinations in the finest wools and silks will inspire and touch people's souls.</p>"; // "The ".$name_arr[0]." is made up of ".$row[17] ;  */
                       $description = "The Verandah Collection of outdoor rugs features classic patterns like goose-eye and lush textures like boucle all made using materials durable enough to be placed inside or outside. Perfect for patios, poolside, and living spaces.  All rugs are hand woven using weather resisit materials like Polyester and Polypropylene.";
                       
                       
                        $category = $row[3];   
                        $_category = $row[4];  
                        $collection = $row[7];  
                        $_collection = $row[8];  
                        $vendor = $row[11]; 
                        $_vendor = $row[12]; 
                        $designer = $row[13]; 
                        $_designer = $row[14]; 
                        $made_in = $row[15]; 
                        $color = $row[16]; 
                        $colors = $row[16].",".$row[17]; 
                        
                        $colors_arr = explode(",",$colors);
                        $colors_arr = array_map('trim', $colors_arr);
                        $colors = json_encode($colors_arr);

                        $material = $row[18]; 
                        // $backing = $row[1]; 
                        $quality = $row[19];     
                        $new_arrival = 0; 
                        $attribute_set = "Rugs"; 
                        $isResidential = 0; 
                        $isCommercial = 1; 
                        $isFurniture = 0; 
                        $sector = $row[20]; 

                        $img_arr = explode(".",$row[27]);

                        $image = $row[26]; 
                        $thumb_pic = '/rug_images/'.$img_arr[0].'.'.$img_arr[1]; 
                        $picture = '/rug_images/'.$img_arr[0].'.'.$img_arr[1]; 
                        $large_pic =  '/rug_images/'.$img_arr[0].'.'.$img_arr[1]; 

                        $search_suggestion = '{"search_suggestions":["'.$category.'","'.$vendor.'","'.$designer.'","'.$color.'","'.$quality.'","'.$material.'"]}';
                        $attributes = '[{"group":"type","value":"designer","name":"designer"},{"group":"type","name":"outdoor","value":"outdoor"},{"group":"type","name":"commercial","value":"commercial"},{"group":"design","value":"Synthetic","name":"Synthetic"},{"group":"design","value":"Flatweave","name":"Flatweave"},{"group":"material","value":"Polypropylene","name":"Polypropylene"}]'; 
                        $variations = '[]'; 
                        $qualities = '["Hand Knotted Hospitality","Hand Tufted Ultra-Dense","Printed Commercial","Computer Yarn Placement Commercial","Axminster Commercial"]'; 
                        $today = date("Y-m-d");

                        //$variation = $this->Bank_model->getvariation('100% New Zealand Wool','Hand Tufted');
                        //$variationval = $variation->variations;
                        $variationval = "";

                        $product_data = array(
                            'photo_id' => $photo_id, 
                            'vendor_sku' => $vendor_sku,
                            'name' => $name,  
                            'orig_name' => $orig_name,        
                            'description' => $description,
                            'category' => $category,    
                            '_category' => $_category,  
                            'collection' => $collection,    
                            '_collection' => $_collection, 
                            'comm_category' => $category,    
                            'comm__category' => $category_id, 
                            'comm_collection' => $collection,    
                            'comm__collection' => $_collection, 
                            'vendor' => $vendor,
                            '_vendor' => $_vendor,
                            'designer' => $designer,
                            '_designer' => $_designer,
                            'made_in' => $made_in,
                            'color' => $color,
                            'colors' => $colors,
                            'material' => $material,
                            'quality' => $quality,     
                            'new_arrival' => $new_arrival,
                            'attribute_set' => $attribute_set,
                            'isResidential' => $isResidential,
                            'isCommercial' => $isCommercial,
                            'isFurniture' => $isFurniture,
                            'sector' => $sector,
                            'search_suggestion' => $search_suggestion,
                            'image' => $image,
                            'thumb_pic' => $thumb_pic,
                            'picture' => $picture,
                            'large_pic' => $large_pic,
                            'attributes' => $attributes,
                            'variations' => $variationval,
                            'qualities' => $qualities,
                            'publish_date' => $today,
                            'sort_random' => "",
                            'date_added' => $today,
                            'keywords' => "",
                            'keyword_additions' => "Outdoor Rug"
                        );

                        // $variation = $this->Bank_model->getvariation($material,$quality);
                        
                        // print_r($variation);
                        //echo $photo_id;
                        //echo $variationval = $variation->variations;
                        //echo "<br><br>";

                        // exit();

                        // $add_key = "palazzo patterned";
                        
                        $product_update_data = array(
                            'image' => $image,
                            'thumb_pic' => $thumb_pic,
                            'picture' => $picture,
                            'large_pic' => $large_pic,
                            'attributes' => $attributes
                        );  
                        
                        /* $product_update_data = array(
                            'isResidential' => 1,
                            'orig_name' => $orig_name,      
                            'variations' => $variationval
                        ); */
                        
                       // $this->Bank_model->import_product($product_data);
                        $this->Bank_model->update_product($product_update_data,$photo_id);
                       // exit();                            
                }else{
                    $count++;
                }
            }
            echo "done";
        }

}


    public function importcustomprice(){ 


        $updates_file = './primo_shag_skus.csv';
        $target_file = $updates_file;

        $row = array();
        $updates_handle = fopen($target_file, 'r');
        $countProduct = 0;

        if ($updates_handle) {
            $count = 0;
            while ($row = fgetcsv($updates_handle, 500000, ",")) {
                $category_id = NULL;
                if ($count != 0) {                       
                       echo $photo_id = $row[0]; 
                       echo "<br>";
                       /* $vendor_sku = $row[0];                             
                        $name =  $row[1];
                        $name_arr = explode("_",$name);
                        $name = $name_arr[0]." ".$name_arr[1];

                        $orig_name = $name_arr[0];      
                        $description = "<p>Fareed's rekindled fascination with patterns stands at the forefront of this collection of handmade luxury rugs, opting to revive a language that has long been ignored by him and yet surrounded him in music, nature, mathematics, and other graphic structures; all these are now finding their way back into his rugs. Fareed's work has never been inhibited by geometric shapes, lines, and rhythm, but now his current passion is somewhat of a \"tamed abstract,\" celebrating the beauty of architecture.<p>
                        <p>The simple compositions of these hand knotted patterned rugs woven in ancient traditions with Fareed's signature color combinations in the finest wools and silks will inspire and touch people's souls.</p>"; // "The ".$name_arr[0]." is made up of ".$row[17] ; 
                        $category = $row[3];   
                        $_category = $row[4];  
                        $collection = $row[7];  
                        $_collection = $row[8];  
                        $vendor = $row[11]; 
                        $_vendor = $row[12]; 
                        $designer = $row[13]; 
                        $_designer = $row[14]; 
                        $made_in = $row[15]; 
                        $color = $row[16]; 
                        // $colors = $row[1]; 
                        $material = $row[17]; 
                        // $backing = $row[1]; 
                        $quality = $row[18];     
                        $new_arrival = 0; 
                        $attribute_set = "Rugs"; 
                        $isResidential = 0; 
                        $isCommercial = 1; 
                        $isFurniture = 0; 
                        $sector = $row[19]; 

                        $img_arr = explode(".",$row[26]);

                        $image = $row[26]; 
                        $thumb_pic = '/rug_images/'.$img_arr[0].'_large_medium.'.$img_arr[1]; 
                        $picture = '/rug_images/'.$img_arr[0].'_large_medium.'.$img_arr[1]; 
                        $large_pic =  '/rug_images/'.$img_arr[0].'.'.$img_arr[1]; 

                        $search_suggestion = '{"search_suggestions":["'.$category.'","'.$vendor.'","'.$designer.'","'.$color.'","'.$quality.'","'.$material.'"]}';
                        $attributes = '[{"group":"type","value":"designer","name":"designer"},{"group":"design","value":"luxury","name":"luxury"},{"group":"design","value":"palazzo","name":"palazzo"},{"name":"patterned","value":"patterned","group":"design"},{"group":"design","value":"tibetan","name":"tibetan"},{"group":"material","value":"wool","name":"wool"},{"group":"material","value":"silk","name":"silk"}]'; 
                        $variations = '[]'; 
                        $qualities = '["Hand Knotted Hospitality","Hand Tufted Ultra-Dense","Printed Commercial","Computer Yarn Placement Commercial","Axminster Commercial"]'; 
                        $today = date("Y-m-d");

                        $product_data = array(
                            'photo_id' => $photo_id, 
                            'vendor_sku' => $vendor_sku,
                            'name' => $name,  
                            'orig_name' => $orig_name,        
                            'description' => $description,
                            'category' => $category,    
                            '_category' => $_category,  
                            'collection' => $collection,    
                            '_collection' => $_collection, 
                            'comm_category' => $category,    
                            'comm__category' => $category_id, 
                            'comm_collection' => $collection,    
                            'comm__collection' => $_collection, 
                            'vendor' => $vendor,
                            '_vendor' => $_vendor,
                            'designer' => $designer,
                            '_designer' => $_designer,
                            'made_in' => $made_in,
                            'color' => $color,
                            'material' => $material,
                            'quality' => $quality,     
                            'new_arrival' => $new_arrival,
                            'attribute_set' => $attribute_set,
                            'isResidential' => $isResidential,
                            'isCommercial' => $isCommercial,
                            'isFurniture' => $isFurniture,
                            'sector' => $sector,
                            'search_suggestion' => $search_suggestion,
                            'image' => $image,
                            'thumb_pic' => $thumb_pic,
                            'picture' => $picture,
                            'large_pic' => $large_pic,
                            'attributes' => $attributes,
                            'variations' => $variations,
                            'qualities' => $qualities,
                            'publish_date' => $today,
                            'sort_random' => "",
                            'date_added' => $today,
                            'keywords' => "",
                            'keyword_additions' => ""
                        );

                        $variation = $this->Bank_model->getvariation($material,$quality);
                        
                        // print_r($variation);
                        $variationval = $variation->variations;
                        // echo "<br><br>";

                        $add_key = "palazzo patterned";
                        
                        $product_update_data = array(
                            'description' => $description,
                            'attributes' => $attributes,
                            'keyword_additions' => $add_key
                        ); */

                        $variation = '[
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 1,
                                "price": 2700,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "6\' round",
                                "searchSizeFloor": null,
                                "aliasSize": "6\' round",
                                "size": "6\' round",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 2,
                                "price": 2700,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "6\' square",
                                "searchSizeFloor": null,
                                "aliasSize": "6\' square",
                                "size": "6\' square",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 3,
                                "price": 3000,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "5 x 8",
                                "searchSizeFloor": null,
                                "aliasSize": "5 x 8",
                                "size": "5\' x 8\'",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 4,
                                "price": 4050,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "6 x 9",
                                "searchSizeFloor": null,
                                "aliasSize": "6 x 9",
                                "size": "6\' x 9\'",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 5,
                                "price": 4800,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "8\' round",
                                "searchSizeFloor": null,
                                "aliasSize": "8\' round",
                                "size": "8\' round",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 6,
                                "price": 4800,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "8\' square",
                                "searchSizeFloor": null,
                                "aliasSize": "8\' square",
                                "size": "8\' square",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 7,
                                "price": 6000,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "8 x 10",
                                "searchSizeFloor": null,
                                "aliasSize": "8 x 10",
                                "size": "8\' x 10\'",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 8,
                                "price": 7500,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "10\' round",
                                "searchSizeFloor": null,
                                "aliasSize": "10\' round",
                                "size": "10\' round",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 9,
                                "price": 7500,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "10\' square",
                                "searchSizeFloor": null,
                                "aliasSize": "10\' square",
                                "size": "10\' square",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 10,
                                "price": 8100,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "9 x 12",
                                "searchSizeFloor": null,
                                "aliasSize": "9 x 12",
                                "size": "9\' x 12\'",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 11,
                                "price": 10500,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "10 x 14",
                                "searchSizeFloor": null,
                                "aliasSize": "10 x 14",
                                "size": "10\' x 14\'",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 12,
                                "price": 10800,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "12\' round",
                                "searchSizeFloor": null,
                                "aliasSize": "12\' round",
                                "size": "12\' round",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 13,
                                "price": 10800,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "12\' square",
                                "searchSizeFloor": null,
                                "aliasSize": "12\' square",
                                "size": "12\' square",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            },
                            {
                                "GS1": null,
                                "MSRP": 0,
                                "origMap": 0,
                                "length": 0,
                                "width": 0,
                                "height": 0,
                                "oldPrice": 0,
                                "option": 14,
                                "price": 13500,
                                "psf": 0,
                                "sale": null,
                                "searchSize": "12 x 15",
                                "searchSizeFloor": null,
                                "aliasSize": "12 x 15",
                                "size": "12\' x 15\'",
                                "shape": null,
                                "sizeWeight": 0,
                                "shippingHeight": 0,
                                "shippingLength": 0,
                                "shippingWidth": 0,
                                "shippingWeight": 0,
                                "shippingType": null,
                                "sizeSku": null,
                                "active": 1,
                                "stock": 0,
                                "stock30days": 0,
                                "stock60days": 0,
                                "stockover60days": 0,
                                "wholesale": 0
                            }
                        ]';

                        $variation = stripcslashes($variation);
                        
                         $product_update_data = array(
                            'variations' => $variation
                        ); 
                        
                        // $this->Bank_model->import_product($product_data);
                        $this->Bank_model->update_product($product_update_data,$photo_id);
                        //exit();                            
                }else{
                    $count++;
                }
            }
            echo "done";
        }

}

    public function importnew(){      

       // $token=$this->input->post('token');
       // $importdata = $this->Bank_model->getimportdata($token);       

        
                // $vendor_name = $importdata->vendor_name;
                $vendor_name = "Surya";
                // $vendor_id = $importdata->id;
                $vendor_id = 55;
                // $vendor_prefix_code = $importdata->prefix_code;
                $vendor_prefix_code = 1510;
                $design_prev = '';
                $color_prev = '';
                $today = date("Y-m-d");

                $attributes_json = array();
                $variations_json = array();
                $search_suggestion = array();

                // $updates_file = "./loloi_update.csv";
                $updates_file = "./nani_2_6_22.csv";
                $target_file = $updates_file;
                $row = array();
                $updates_handle = fopen($target_file, 'r');



                /*======*/
                
                $photo_id = ""; 
                $vendor_sku = "";
                $name = "";  
                $orig_name = "";        
                $description = "";
                $category = "";    
                $_category = "";  
                $vendor = "";
                $_vendor = "";
                $designer = "";
                $_designer = "";
                $made_in = "";
                $color = "";
                $colors = "";
                $material = "";
                $backing = "";
                $quality = "";     
                $new_arrival = "";
                $attribute_set = "";
                $isResidential = "";
                $isCommercial = "";
                $isFurniture = "";
                $sector = "";
                $image = "";
                $thumb_pic = "";
                $picture = "";
                $large_pic = "";
                $attributes = "";
                $variations = "";
                $qualities = "";
                $today = "";
                $today = "";


               // $photo_id = "";    
                $vendor_sku = "";
                $design = "";      
                $description = "";
                $category = "";               
                $made_in = "";
                $color = "";
                $colors = "";
                $material = "";
                $backing = "";
                $quality = "";

                $gs1 = "";
                $msrp = 0;
                $origmap = "";
                $length = "";
                $width = "";
                $height = "";
                $oldprice = "";
                $option_val = "";
                $price = "";
                $psf = "";
                $sale = "";
                $searchSize = "";
                $aliasSize = "";
                $size = "";
                $shape = "";
                $shippingheight = "";
                $shippinglength = "";
                $shippingwidth = "";
                $shippingweight = "";
                $shippingtype = "";
                $sizesku = "";
                $cost = 0;
                
                /*====== */

                if ($updates_handle) {
                    $count = 0;
                    $count2 = 0;
                    
                    while ($row = fgetcsv($updates_handle, 500000, ",")) {
                        if($count == 0) $header = $row;
                        if ($count != 0) {

                            $iii = 0;                            

                            while(count($row) > $iii)
                            {   
                                $header_text = trim(strtolower($header[$iii]));

                                switch ($header_text) {
                                    case "design":
                                      $design = $row[$iii];
                                      break;
                                    case "aliassku":
                                      $gs1 = $row[$iii];
                                      break;
                                    case "msrp":
                                       $msrp = $row[$iii];
                                      break;
                                    case "cost":
                                        $cost = $row[$iii];
                                        break;
                                    case "origmap":
                                      $origmap = $row[$iii];
                                      break;
                                    case "length":
                                      $length = $row[$iii];
                                      break;
                                    case "width":
                                      $width = $row[$iii];
                                      break;
                                    case "height":
                                      $height = $row[$iii];
                                      break;
                                    case "oldprice":
                                      $oldprice = $row[$iii];
                                      break;
                                    case "option":
                                      $option = $row[$iii];
                                      break;
                                    case "price":
                                        $price = $row[$iii];
                                        break;
                                    case "psf":
                                        $psf = $row[$iii];
                                        break;
                                    case "sale":
                                        $sale = $row[$iii];
                                        break;
                                    case "searchsize":
                                        $searchsize = $row[$iii];
                                        break;
                                    case "searchsizefloor":
                                        $searchsizefloor = $row[$iii];
                                        break;
                                    case "aliassize":
                                        $aliassize = $row[$iii];
                                        break;
                                    case "size":
                                        $size = $row[$iii];
                                        break;
                                    case "shape":
                                        $shape = $row[$iii];
                                        break;
                                    case "sizeweight":
                                        $sizeweight = $row[$iii];
                                        break;
                                    case "shippingheight":
                                        $shippingheight = $row[$iii];
                                        break;
                                    case "shippinglength":
                                        $shippinglength = $row[$iii];
                                        break;
                                    case "shippingwidth":
                                        $shippingwidth = $row[$iii];
                                        break;
                                    case "shippingweight":
                                        $shippingweight = $row[$iii];
                                        break;
                                    case "shippingtype":
                                        $shippingtype = $row[$iii];
                                        break;
                                    case "sizesku":
                                        $sizesku = $row[$iii];
                                        break;
                                    case "active":
                                        $active = $row[$iii];
                                        break;
                                    case "stock":
                                        $stock = $row[$iii];
                                        break;
                                    case "stock30days":
                                        $stock30days = $row[$iii];
                                        break;
                                    case "stock60days":
                                        $stock60days = $row[$iii];
                                        break;
                                    case "stockover60days":
                                        $stockover60days = $row[$iii];
                                        break;
                                    case "wholesale":
                                        $wholesale = $row[$iii];
                                        break;                                    
                                    case "vendor_sku":
                                        $vendor_sku = $row[$iii];
                                        break;
                                    case "name":
                                        $name = $row[$iii];
                                        break;
                                    case "orig_name":
                                        $orig_name = $row[$iii];
                                        break;
                                    case "description":
                                        $description = $row[$iii];
                                        break;
                                    case "category":
                                        $category = $row[$iii];
                                        break;
                                    case "category_id":
                                        $category_id = $row[$iii];
                                        break;
                                    case "made_in":
                                        $made_in = $row[$iii];
                                        break;
                                    case "color":
                                        $color = $row[$iii];
                                        break;
                                    case "color1":
                                        $color1 = $row[$iii];
                                        break;
                                    case "material":
                                        $material = $row[$iii];
                                        break;
                                    case "backing":
                                        $backing = $row[$iii];
                                        break;
                                    case "quality":
                                        $quality = $row[$iii];
                                        break;
                                    case "new_arrival":
                                        $new_arrival = $row[$iii];
                                        break;
                                    case "attribute_set":
                                        $attribute_set = $row[$iii];
                                        break;
                                    case "isresidential":
                                        $isresidential = $row[$iii];
                                        break;
                                    case "iscommercial":
                                        $iscommercial = $row[$iii];
                                        break;
                                    case "isfurniture":
                                        $isfurniture = $row[$iii];
                                        break;
                                    case "sector":
                                        $sector = $row[$iii];
                                        break;                                            
                                    case "image":
                                        $image = $row[$iii];
                                        break;
                                    case "roomscene":
                                        $roomscene = $row[$iii];
                                        break;
                                    case "thumb_pic":
                                        $thumb_pic = $row[$iii];
                                        break;
                                    case "picture":
                                        $picture = $row[$iii];
                                        break;
                                    case "large_pic":
                                        $large_pic = $row[$iii];
                                        break;
                                    case "qualities":
                                        $qualities = $row[$iii];
                                        break;                                            
                                                    
                                  }

                                  $iii++;

                            } 
                    
                                
                            // if($design_prev == $design && $color_prev == $color)
                            if($design_prev == $design)
                            {   
                                $fl1++;   
                                $option_val = strval($fl1+1); 

                                $size_arr = explode(" ",$size);
                                $shapen = end($size_arr);
                                
                               $searchsizenew = $this->getsearchsize($width,$height,$shapen);

                                    $variations_json[$fl1]['GS1'] = $gs1;
                                    $variations_json[$fl1]['MSRP'] = $msrp;
                                    $variations_json[$fl1]['origMap'] = $origmap;
                                    $variations_json[$fl1]['length'] = $length;
                                    $variations_json[$fl1]['width'] = $width;
                                    $variations_json[$fl1]['height'] = $height;
                                    $variations_json[$fl1]['oldPrice'] = $msrp;
                                    $variations_json[$fl1]['option'] = $option_val;
                                    $variations_json[$fl1]['price'] = $price;
                                    $variations_json[$fl1]['cost'] = $cost;
                                    $variations_json[$fl1]['psf'] = $psf;
                                    $variations_json[$fl1]['sale'] = $sale;
                                    $variations_json[$fl1]['searchSize'] = $searchsizenew;
                                    $variations_json[$fl1]['searchSizeFloor'] = "";
                                    $variations_json[$fl1]['aliasSize'] = str_replace("'","",$aliasSize);
                                    $variations_json[$fl1]['size'] = $size;
                                    $variations_json[$fl1]['shape'] = $shape;
                                    $variations_json[$fl1]['sizeWeight'] = "";
                                    $variations_json[$fl1]['shippingHeight'] = $shippingheight;
                                    $variations_json[$fl1]['shippingLength'] = $shippinglength;
                                    $variations_json[$fl1]['shippingWidth'] = $shippingwidth;
                                    $variations_json[$fl1]['shippingWeight'] = $shippingweight;
                                    $variations_json[$fl1]['shippingType'] = $shippingtype;
                                    $variations_json[$fl1]['sizeSku'] = $sizesku;
                                    $variations_json[$fl1]['active'] = 1;
                                    $variations_json[$fl1]['stock'] = 5;
                                    $variations_json[$fl1]['stock30days'] = 0;
                                    $variations_json[$fl1]['stock60days'] = 0;
                                    $variations_json[$fl1]['stockover60days'] = 0;
                                    $variations_json[$fl1]['wholesale'] = 0;
                                

                            }else{
                                    
                                if($count2 != 0)
                                {
                                    $color_arr = array();
                                    $color_arr[] = $color;
                                    if($color1!="" && $color1!="N/A")
                                    {
                                        $color_arr[] = $color1;
                                    }                                    
                                    $colors = json_encode($color_arr); 

                                    $variations = json_encode($variations_json);  
                                    
                                    $roomscene_arr = explode("/",$roomscene);
                                    $roomscene = end($roomscene_arr);

                                    if($roomscene != "")
                                    { $roomscene = "/rug_images/extra_images/".$roomscene; }

                                    $product_data = array(
                                        'photo_id' => $photo_id, 
                                        'vendor_sku' => $vendor_sku,
                                        'name' => $name,  
                                        'orig_name' => $orig_name,        
                                        'description' => $description,
                                        'category' => $category,    
                                        '_category' => $category_id,  
                                        'collection' => $category,    
                                        '_collection' => $category_id, 
                                        'comm_category' => $category,    
                                        'comm__category' => $category_id, 
                                        'comm_collection' => $category,    
                                        'comm__collection' => $category_id, 
                                        'vendor' => $vendor,
                                        '_vendor' => $_vendor,
                                        'designer' => $designer,
                                        '_designer' => $_designer,
                                        'made_in' => $made_in,
                                        'color' => $color,
                                        'colors' => $colors,
                                        'material' => $material,
                                        'backing' => $backing,
                                        'quality' => $quality,     
                                        'new_arrival' => $new_arrival,
                                        'attribute_set' => $attribute_set,
                                        'isResidential' => $isResidential,
                                        'isCommercial' => $isCommercial,
                                        'isFurniture' => $isFurniture,
                                        'sector' => $sector,
                                        'search_suggestion' => $search_suggestion,
                                        'image' => $image,
                                        'room_pic' => $roomscene,
                                        'thumb_pic' => $thumb_pic,
                                        'picture' => $picture,
                                        'large_pic' => $large_pic,
                                        'attributes' => $attributes,
                                        'variations' => $variations,
                                        'qualities' => $qualities,
                                        'publish_date' => $today,
                                        'sort_random' => "",
                                        'date_added' => $today,
                                        'keywords' => "",
                                        'keyword_additions' => ""
                                    );

                                    $product_update_data = array( 
                                        'variations' => $variations
                                    );

                                     echo "<pre>";
                                     print_r($product_data);
                                    // $this->Bank_model->import_product($product_data);
                                    echo $photo_id."<br>";
                                   // $this->Bank_model->update_product_surya($product_update_data,$photo_id,"Surya");
                                    // exit();

                                    $attributes_json = array();
                                    $variations_json = array();
                                    $search_suggestion = array();

                                } 
                                
                                $fl1 = 0;
                                $option_val = strval($fl1+1);

                                $size_arr = explode(" ",$size);
                                $shapen = end($size_arr);
                                
                                $searchsizenew = $this->getsearchsize($width,$height,$shapen);
                                

                                    $photo_id = $vendor_prefix_code."_".str_replace(" ", "", $design);    
                                    $vendor_sku = $design;
                                    $name = $row[6]." ".$design;      
                                    $orig_name = "";
                                    $description = $description;
                                    $category  = $category;
                                    $_category = ""; 
                                    $collection = $category;
                                    $_collection = "";
                                    $comm_category = $category;
                                    $comm__category = "";
                                    $comm_collection = $category;
                                    $comm__collection = "";
                                    $vendor = "Surya";
                                    $_vendor = "55";
                                    $designer = "";
                                    $_designer = "";
                                    $made_in = $made_in;
                                    $color = $color;
                                    $colors = $colors;
                                    $material = $material;
                                    $backing = $backing;
                                    $quality = $quality;
                                    $new_arrival = 1;
                                    $attribute_set = "Rugs";
                                    $isResidential = "1";
                                    $isCommercial = "";
                                    $isFurniture = "";
                                    $sector = "";
                                    // $search_suggestion =json();
                                    $image = $photo_id.".jpg";
                                    $thumb_pic = "/rug_images/".$photo_id."_small.jpg";
                                    $picture = "/rug_images/".$photo_id."_medium.jpg";
                                    $large_pic = "/rug_images/".$photo_id."_large.jpg";
                                    // $attributes = json();
                                    // $variations = json();
                                    $qualities = "";
                                    $design_prev = $design;
                                    $color_prev = $color;


                                    $search_suggestion['search_suggestions'][0] = "";
                                    $search_suggestion['search_suggestions'][1] = "";
                                    $search_suggestion['search_suggestions'][2] = "";
                                    $search_suggestion['search_suggestions'][3] = "";
                                    $search_suggestion['search_suggestions'][4] = "";


                                    $attributes_json[0]['name'] = $material;
                                    $attributes_json[0]['value'] = $material;
                                    $attributes_json[0]['group'] = "material";

                                    $attributes_json[1]['name'] = $quality;
                                    $attributes_json[1]['value'] = $quality;
                                    $attributes_json[1]['group'] = "Style";

                                   /* $attributes_json[2]['name'] = $row[34];
                                    $attributes_json[2]['value'] = $row[34];
                                    $attributes_json[2]['group'] = "Construction"; */

                                // {"GS1":"764262973877","MSRP":130,"origMap":90,"length":36,"width":24,"height":0,"oldPrice":127000,"option":1,"price":90000,"psf":13.3333333333333,"sale":"0.3","searchSize":"2 x 3","searchSizeFloor":null,"aliasSize":"2 x 3","size":"2' x 3'","shape":"Rectangle","sizeWeight":0,"shippingHeight":4,"shippingLength":24,"shippingWidth":4,"shippingWeight":0,"shippingType":"Small Parcel","sizeSku":"COS8818-23","active":1,"stock":0,"stock30days":0,"stock60days":0,"stockover60days":0,"wholesale":41}

                                   /* $variations_json[$fl1]['GS1'] = $row[3];
                                    $variations_json[$fl1]['MSRP'] = $row[13];
                                    $variations_json[$fl1]['origMap'] = "";
                                    $variations_json[$fl1]['length'] = $row[21];
                                    $variations_json[$fl1]['width'] = $row[22];
                                    $variations_json[$fl1]['height'] = $row[23];
                                    $variations_json[$fl1]['oldPrice'] = "";
                                    $variations_json[$fl1]['option'] = $option_val;
                                    $variations_json[$fl1]['price'] = $row[12];
                                    $variations_json[$fl1]['psf'] = "";
                                    $variations_json[$fl1]['sale'] = "";
                                    $variations_json[$fl1]['searchSize'] = str_replace("'","",$row[19]);
                                    $variations_json[$fl1]['searchSizeFloor'] = "";
                                    $variations_json[$fl1]['aliasSize'] = str_replace("'","",$row[19]);
                                    $variations_json[$fl1]['size'] = $row[19];
                                    $variations_json[$fl1]['shape'] = $row[18];
                                    $variations_json[$fl1]['sizeWeight'] = "";
                                    $variations_json[$fl1]['shippingHeight'] = $row[28];
                                    $variations_json[$fl1]['shippingLength'] = $row[26];
                                    $variations_json[$fl1]['shippingWidth'] = $row[27];
                                    $variations_json[$fl1]['shippingWeight'] = $row[25];
                                    $variations_json[$fl1]['shippingType'] = $row[30];
                                    $variations_json[$fl1]['sizeSku'] = $row[1];
                                    $variations_json[$fl1]['active'] = 1;
                                    $variations_json[$fl1]['stock'] = 5;
                                    $variations_json[$fl1]['stock30days'] = 0;
                                    $variations_json[$fl1]['stock60days'] = 0;
                                    $variations_json[$fl1]['stockover60days'] = 0;
                                    $variations_json[$fl1]['wholesale'] = 0; */

                                    $variations_json[$fl1]['GS1'] = $gs1;
                                    $variations_json[$fl1]['MSRP'] = $msrp;
                                    $variations_json[$fl1]['origMap'] = $origmap;
                                    $variations_json[$fl1]['length'] = $length;
                                    $variations_json[$fl1]['width'] = $width;
                                    $variations_json[$fl1]['height'] = $height;
                                    $variations_json[$fl1]['oldPrice'] = $msrp;
                                    $variations_json[$fl1]['option'] = $option_val;
                                    $variations_json[$fl1]['price'] = $price;
                                    $variations_json[$fl1]['cost'] = $cost;
                                    $variations_json[$fl1]['psf'] = $psf;
                                    $variations_json[$fl1]['sale'] = $sale;
                                    $variations_json[$fl1]['searchSize'] = $searchsizenew;
                                    $variations_json[$fl1]['searchSizeFloor'] = "";
                                    $variations_json[$fl1]['aliasSize'] = str_replace("'","",$aliasSize);
                                    $variations_json[$fl1]['size'] = $size;
                                    $variations_json[$fl1]['shape'] = $shape;
                                    $variations_json[$fl1]['sizeWeight'] = "";
                                    $variations_json[$fl1]['shippingHeight'] = $shippingheight;
                                    $variations_json[$fl1]['shippingLength'] = $shippinglength;
                                    $variations_json[$fl1]['shippingWidth'] = $shippingwidth;
                                    $variations_json[$fl1]['shippingWeight'] = $shippingweight;
                                    $variations_json[$fl1]['shippingType'] = $shippingtype;
                                    $variations_json[$fl1]['sizeSku'] = $sizesku;
                                    $variations_json[$fl1]['active'] = 1;
                                    $variations_json[$fl1]['stock'] = 5;
                                    $variations_json[$fl1]['stock30days'] = 0;
                                    $variations_json[$fl1]['stock60days'] = 0;
                                    $variations_json[$fl1]['stockover60days'] = 0;
                                    $variations_json[$fl1]['wholesale'] = 0;


                                    $search_suggestion = json_encode($search_suggestion);
                                    $attributes = json_encode($attributes_json);
                                    // $variations = json();


                            }

                            
                            $count2++;
                            //exit();
                                
                                
                        } 
                        
                        
                        $count++;
                        
                    }



                    $variations = json_encode($variations_json);            

                                    $product_data = array(
                                        'photo_id' => $photo_id,  
                                        'vendor_sku' => $vendor_sku,
                                        'name' => $name,  
                                        'orig_name' => $orig_name,        
                                        'description' => $description,
                                        'category' => $category,    
                                        '_category' => $_category,  
                                        'vendor' => $vendor,
                                        '_vendor' => $_vendor,
                                        'designer' => $designer,
                                        '_designer' => $_designer,
                                        'made_in' => $made_in,
                                        'color' => $color,
                                        'colors' => $colors,
                                        'material' => $material,
                                        'backing' => $backing,
                                        'quality' => $quality,     
                                        'new_arrival' => $new_arrival,
                                        'attribute_set' => $attribute_set,
                                        'isResidential' => $isResidential,
                                        'isCommercial' => $isCommercial,
                                        'isFurniture' => $isFurniture,
                                        'sector' => $sector,
                                        'search_suggestion' => $search_suggestion,
                                        'image' => $image,
                                        'thumb_pic' => $thumb_pic,
                                        'room_pic' => $roomscene,
                                        'picture' => $picture,
                                        'large_pic' => $large_pic,
                                        'attributes' => $attributes,
                                        'variations' => $variations,
                                        'qualities' => $qualities,
                                        'publish_date' => $today,
                                        'sort_random' => "",
                                        'date_added' => $today,
                                        'keywords' => "",
                                        'keyword_additions' => ""
                                    );

                                    //echo "<pre>";
                                    //print_r($product_data);
                                    
                                    // $this->Bank_model->import_product($product_data);
                                   //exit();

                                $product_update_data = array(  
                                    'variations' => $variations
                                );

                                //echo "<pre>";
                                //print_r($product_data);
                                // $this->Bank_model->import_product($product_data);
                                echo $photo_id."<br>";
                                //$this->Bank_model->update_product_surya($product_update_data,$photo_id,"Surya");


                }

                // $this->Bank_model->updateimportdata($token);

        echo "successfully updated";   
    }

   public function getsearchsize($width,$height,$shape)
{  
    $searchsize = "";  

    $width = round(($width/12),1);
    $height = round(($height/12),1);

    if($shape == "square" && $width == $height)
    {
        if($width <= 4.4){
            $searchsize = "3' - 4' Square";
        }elseif($width >= 4.5 && $width <= 7.4){
            $searchsize = "5' - 7' Square";
        }elseif($width >= 7.5 && $width <= 8.4){
            $searchsize = "8' Square";
        }elseif($width >= 8.5 && $width <= 11){
            $searchsize = "9' - 10' Square";
        }elseif($width >= 11.1){
            $searchsize = "12' Square";
        }
    }elseif($shape == "round" && $width == $height)
    {
        if($width <= 6.4){
            $searchsize = "3' - 6' Round";
        }elseif($width >= 6.5 && $width <= 8.4){
            $searchsize = "7' - 8' Round";
        }elseif($width >= 8.5 && $width <= 11){
            $searchsize = "9' - 10' Round";
        }elseif($width >= 11.1 && $width <= 13){
            $searchsize = "12' Round";
        }elseif($width >= 13.1){
            $searchsize = "14' Round";
        }
    }elseif($shape == "oval" && $width == $height)
    {
        if($width <= 6.4){
            $searchsize = "4' - 6' Oval";
        }elseif($width >= 6.5 && $width <= 11){
            $searchsize = "7' - 10' Oval";
        }elseif($width >= 11.1){
            $searchsize = "12' Oval";
        }
    }elseif($shape == "runner")
    {
        if($height <= 7){
            $searchsize = "4' - 6' Runner";
        }elseif($height >= 7.1 && $height <= 9){
            $searchsize = "8' Runner";
        }elseif($height >= 9.1 && $height <= 11){
            $searchsize = "10' Runner";
        }elseif($height >= 11.1 && $height <= 16){
            $searchsize = "12' - 15' Runner";
        }elseif($height >= 16.1){
            $searchsize = "Oversize Runner";
        }
    }else{

        if($width <= 2.4){
            $searchsize = "2' x 3'";
        }elseif($width >= 2.5 && $width <= 3.4){
            $searchsize = "3' x 5'";
        }elseif($width >= 3.5 && $width <= 4.4){
            $searchsize = "4' x 6'";
        }elseif($width >= 4.5 && $width <= 5.4){
            $searchsize = "5' x 8'";
        }elseif($width >= 5.5 && $width <= 6.4){
            $searchsize = "6' x 9'";
        }elseif($width >= 6.5 && $width <= 7.4){
            $searchsize = "7' x 10'";
        }elseif($width >= 7.5 && $width <= 8.4){
            $searchsize = "8' x 11'";
        }elseif($width >= 8.5 && $width <= 9.4){
            $searchsize = "9' x 12'";
        }elseif($width >= 9.5 && $width <= 11){
            $searchsize = "10' x 14'";
        }elseif($width >= 11.1 && $width <= 13){
            $searchsize = "12' x 15'";
        }elseif($width >= 13.1){
            $searchsize = "Oversize";
        }

    }  

    return $searchsize;

}
	
	public function deposit(){
        $data['bank_id'] = !empty($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $where_bank = array('status' => 1);
        $data['accounts'] = $this->Invoice_model->get_from_table('bank_accounts','*',$where_bank);
        $this->load->view('new_bank_deposit',$data);
    }

    public function deposit_amount(){
        $deposit_arr['to_acc_id'] = $this->input->post('bank_id'); 
        $deposit_arr['from_acc_id'] = $this->input->post('from_acc_id'); 
        $deposit_arr['receive_via'] = $this->input->post('receive_via'); 
        $deposit_arr['reference'] = $this->input->post('reference'); 
        $deposit_arr['amount'] = $this->input->post('amount'); 
        $deposit_arr['notes'] = $this->input->post('notes'); 
        $t_date = $this->input->post('tran_date');
        $arr1 = explode("/",$t_date);
        $deposit_arr['tran_date'] = $arr1[2]."-".$arr1[1]."-".$arr1[0];
        $deposit_arr['date_added'] = $arr1[2]."-".$arr1[1]."-".$arr1[0];
        $this->Bank_model->insert_bank_deposit($deposit_arr);
        echo 1;
    }
	
}
?>