<?php

include('../../../configuracion.php');




    // Comprobamos si se subió la imagen
            
                
                set_include_path(get_include_path() . PATH_SEPARATOR . 'mago/lib/');
	            include '../../lib/PHPExcel/IOFactory.php';

                $inputFileName = 'documento/upload-stock.xlsx';	
 
                try {
                    $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
                } catch(Exception $e) {
                    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
                }

                $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
                $arrayCount = count($allDataInSheet);
 
                $datos_base = array();
                

                /*
                A = SKU
                B = stock
                
                */

                for($i=1;$i<=$arrayCount;$i++){

                   
                    $codigo	  = trim($allDataInSheet[$i]["A"]);
                    $stock	  = trim($allDataInSheet[$i]["B"]);
                    
                   

                    $producto = $db->row("productos","id","codigo='{$codigo}'");
                            
                    if($producto){
                           
                        

                            $datos = array(
                                'stock' => @$stock+0,
                            );

                            $db->update("productos",$datos,"id='$producto->is'");

    echo "stock".$codigo."<br>";
                    }
}
	       


?>