<commit_before><?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

use \Carbon\Carbon;
use \PHPExcel;
use \PHPExcel_IOFactory as IO_Factory;
use \PHPExcel_Cell as Cell;
use \PHPExcel_Cell_DataType as DataType;

class MebelImportCommand extends Command {

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'mebel:import';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Import products from excel to database.';

	/**
	 * Create a new command instance.
	 *
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function fire()
	{
		$path = $this->option('path');
		$file = $this->option('file');
		$sheet = $this->option('sheet');
		if (null == $file) 
			die('ERROR: Hayo lo.. File nggak diinput!!!');

		$objPHPExcel = IO_Factory::load( $path . $file);
		$worksheets = $objPHPExcel->getWorksheetIterator();
		//dd($worksheets);
		//$worksheet = $worksheets[(int) $sheet];
		foreach ($worksheets as $worksheet) {
			$worksheetTitle     = $worksheet->getTitle();
			$highestRow         = $worksheet->getHighestRow(); // e.g. 10
			$highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
			$highestColumnIndex = Cell::columnIndexFromString($highestColumn);

			// Import mulai dari baris nomor 3, heading tidak masuk
			for ($row = 3; $row <= $highestRow; $row++) { 

				$data = array(
					'name_id'				=> $worksheet->getCellByColumnAndRow(1-1, $row),
					'description_id' 		=> $worksheet->getCellByColumnAndRow(2-1, $row),
					'meta_title_id' 		=> $worksheet->getCellByColumnAndRow(3-1, $row),
					'meta_description_id' 	=> $worksheet->getCellByColumnAndRow(4-1, $row),
					'meta_keyword_id' 		=> $worksheet->getCellByColumnAndRow(5-1, $row),
					'tag_id' 				=> $worksheet->getCellByColumnAndRow(6-1, $row),
					'name_en' 				=> $worksheet->getCellByColumnAndRow(7-1, $row),
					'description_en' 		=> $worksheet->getCellByColumnAndRow(8-1, $row),
					'meta_title_en' 		=> $worksheet->getCellByColumnAndRow(9-1, $row),
					'meta_description_en' 	=> $worksheet->getCellByColumnAndRow(10-1, $row),
					'meta_keyword_en' 		=> $worksheet->getCellByColumnAndRow(11-1, $row),
					'tag_en' 				=> $worksheet->getCellByColumnAndRow(12-1, $row),
					'image' 				=> $worksheet->getCellByColumnAndRow(13-1, $row),
					'model'					=> $worksheet->getCellByColumnAndRow(14-1, $row),
					'sku' 					=> $worksheet->getCellByColumnAndRow(15-1, $row),
					/*'upc' 			=> $worksheet->getCellByColumnAndRow(16-1, $row),
					'ean' 				=> $worksheet->getCellByColumnAndRow(17-1, $row),
					'jan' 				=> $worksheet->getCellByColumnAndRow(18-1, $row),
					'isbn' 				=> $worksheet->getCellByColumnAndRow(19-1, $row),
					'mpn' 				=> $worksheet->getCellByColumnAndRow(20-1, $row),*/
					'location'			=> $worksheet->getCellByColumnAndRow(21-1, $row),
					'price' 			=> $worksheet->getCellByColumnAndRow(22-1, $row),
					'tax_class_id' 		=> $worksheet->getCellByColumnAndRow(23-1, $row),
					'quantity' 			=> $worksheet->getCellByColumnAndRow(24-1, $row),
					'minimum'			=> $worksheet->getCellByColumnAndRow(25-1, $row),
					'substract'			=> $worksheet->getCellByColumnAndRow(26-1, $row),
					'stock_status_id'	=> $worksheet->getCellByColumnAndRow(27-1, $row),
					'shipping'			=> $worksheet->getCellByColumnAndRow(28-1, $row),
					'url_slug' 			=> $worksheet->getCellByColumnAndRow(29-1, $row), 
					'length'			=> $worksheet->getCellByColumnAndRow(31-1, $row),
					'width' 			=> $worksheet->getCellByColumnAndRow(32-1, $row),
					'height'			=> $worksheet->getCellByColumnAndRow(33-1, $row),
					'length_class_id' 	=> $worksheet->getCellByColumnAndRow(34-1, $row),
					'weight'			=> $worksheet->getCellByColumnAndRow(35-1, $row),
					'weight_class_id'	=> $worksheet->getCellByColumnAndRow(36-1, $row),
					'status'			=> $worksheet->getCellByColumnAndRow(37-1, $row),
					'sort_order'		=> $worksheet->getCellByColumnAndRow(38-1, $row)
				);
	
				$this->insert($data);
			}
		}
	}

	/**
	 * Get the console command arguments.
	 *
	 * @return array
	 */
	protected function getArguments()
	{
		return array(
		//	array('argumen', InputArgument::REQUIRED, 'An example argument.'),
		);
	}

	/**
	 * Get the console command options.
	 *
	 * @return array
	 */
	protected function getOptions()
	{
		return array(
			array('file', null, InputOption::VALUE_REQUIRED, 'File yang mau di import', null),
			array('path', null, InputOption::VALUE_OPTIONAL, 'Lokasi file', 'storage/xls/'),
			array('sheet', null, InputOption::VALUE_OPTIONAL, 'Sheet number', 1)
		);
	}

	protected function insert(array $data)
	{
		$product = new Product;
		$product->model 			= $data['model'];
		$product->sku 				= $data['sku'];
		$product->location 			= $data['location'];<commit_msg>category import product<commit_after><?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

use \Carbon\Carbon;
use \PHPExcel;
use \PHPExcel_IOFactory as IO_Factory;
use \PHPExcel_Cell as Cell;
use \PHPExcel_Cell_DataType as DataType;

class MebelImportCommand extends Command {

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'mebel:import';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Import products from excel to database.';

	/**
	 * Create a new command instance.
	 *
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function fire()
	{
		$path = $this->option('path');
		$file = $this->option('file');
		$sheet = $this->option('sheet');
		if (null == $file) 
			die('ERROR: Hayo lo.. File nggak diinput!!!');

		$objPHPExcel = IO_Factory::load( $path . $file);
		$worksheets = $objPHPExcel->getWorksheetIterator();
		//dd($worksheets);
		//$worksheet = $worksheets[(int) $sheet];
		foreach ($worksheets as $worksheet) {
			$worksheetTitle     = $worksheet->getTitle();
			$highestRow         = $worksheet->getHighestRow(); // e.g. 10
			$highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
			$highestColumnIndex = Cell::columnIndexFromString($highestColumn);

			// Import mulai dari baris nomor 3, heading tidak masuk
			for ($row = 3; $row <= $highestRow; $row++) { 

				$data = array(
					'name_id'				=> $worksheet->getCellByColumnAndRow(1-1, $row),
					'description_id' 		=> $worksheet->getCellByColumnAndRow(2-1, $row),
					'meta_title_id' 		=> $worksheet->getCellByColumnAndRow(3-1, $row),
					'meta_description_id' 	=> $worksheet->getCellByColumnAndRow(4-1, $row),
					'meta_keyword_id' 		=> $worksheet->getCellByColumnAndRow(5-1, $row),
					'tag_id' 				=> $worksheet->getCellByColumnAndRow(6-1, $row),
					'name_en' 				=> $worksheet->getCellByColumnAndRow(7-1, $row),
					'description_en' 		=> $worksheet->getCellByColumnAndRow(8-1, $row),
					'meta_title_en' 		=> $worksheet->getCellByColumnAndRow(9-1, $row),
					'meta_description_en' 	=> $worksheet->getCellByColumnAndRow(10-1, $row),
					'meta_keyword_en' 		=> $worksheet->getCellByColumnAndRow(11-1, $row),
					'tag_en' 				=> $worksheet->getCellByColumnAndRow(12-1, $row),
					'image' 				=> $worksheet->getCellByColumnAndRow(13-1, $row),
					'model'					=> $worksheet->getCellByColumnAndRow(14-1, $row),
					'sku' 					=> $worksheet->getCellByColumnAndRow(15-1, $row),
					/*'upc' 			=> $worksheet->getCellByColumnAndRow(16-1, $row),
					'ean' 				=> $worksheet->getCellByColumnAndRow(17-1, $row),
					'jan' 				=> $worksheet->getCellByColumnAndRow(18-1, $row),
					'isbn' 				=> $worksheet->getCellByColumnAndRow(19-1, $row),
					'mpn' 				=> $worksheet->getCellByColumnAndRow(20-1, $row),*/
					'location'			=> $worksheet->getCellByColumnAndRow(21-1, $row),
					'price' 			=> $worksheet->getCellByColumnAndRow(22-1, $row),
					'tax_class_id' 		=> $worksheet->getCellByColumnAndRow(23-1, $row),
					'quantity' 			=> $worksheet->getCellByColumnAndRow(24-1, $row),
					'minimum'			=> $worksheet->getCellByColumnAndRow(25-1, $row),
					'substract'			=> $worksheet->getCellByColumnAndRow(26-1, $row),
					'stock_status_id'	=> $worksheet->getCellByColumnAndRow(27-1, $row),
					'shipping'			=> $worksheet->getCellByColumnAndRow(28-1, $row),
					'url_slug' 			=> $worksheet->getCellByColumnAndRow(29-1, $row), 
					'length'			=> $worksheet->getCellByColumnAndRow(31-1, $row),
					'width' 			=> $worksheet->getCellByColumnAndRow(32-1, $row),
					'height'			=> $worksheet->getCellByColumnAndRow(33-1, $row),
					'length_class_id' 	=> $worksheet->getCellByColumnAndRow(34-1, $row),
					'weight'			=> $worksheet->getCellByColumnAndRow(35-1, $row),
					'weight_class_id'	=> $worksheet->getCellByColumnAndRow(36-1, $row),
					'status'			=> $worksheet->getCellByColumnAndRow(37-1, $row),
					'sort_order'		=> $worksheet->getCellByColumnAndRow(38-1, $row)
				);
	
				$this->insert($data, $worksheetTitle);
			}
		}
	}

	/**
	 * Get the console command arguments.
	 *
	 * @return array
	 */
	protected function getArguments()
	{
		return array(
		//	array('argumen', InputArgument::REQUIRED, 'An example argument.'),
		);
	}

	/**
	 * Get the console command options.
	 *
	 * @return array
	 */
	protected function getOptions()
	{
		return array(
			array('file', null, InputOption::VALUE_REQUIRED, 'File yang mau di import', null),
			array('path', null, InputOption::VALUE_OPTIONAL, 'Lokasi file', 'storage/xls/'),
			array('sheet', null, InputOption::VALUE_OPTIONAL, 'Sheet number', 1)
		);
	}

	protected function insert(array $data, $worksheetTitle)
	{
		switch ($worksheetTitle) {
			case 'kursi-tamu':
				$categoryId = 59;
				break;
			case 'tempat-tidur':
				$categoryId = 59;
				break;
			case 'lemari':
				$categoryId = 59;
				break;
			case 'kursi-makan':
				$categoryId = 59;
				break;
			case 'tolet':
				$categoryId = 59;
				break;
			case 'kursi-sofa':
				$categoryId = 59;
				break;
			case 'meje-telpon':
				$categoryId = 59;
				break;
			case 'bufet':
				$categoryId = 59;
				break;
			case 'meja':
				$categoryId = 59;
				break;
			case 'kursi':
				$categoryId = 59;
				break;
			case 'sketsel':
				$categoryId = 59;
				break;
			case 'jam-hias':
				$categoryId = 59;
				break;
			case 'mimbar':
				$categoryId = 59;
				break;
			case 'nakas':
				$categoryId = 59;
				break;
			case 'gebyok':
				$categoryId = 59;
				break;
			case 'kaligrafi':
				$categoryId = 59;
				break;
			
		}

		$product = new Product;
		$product->model 			= $data['model'];
		$product->sku 				= $data['sku'];
		$product->location 			= $data['location'];
{'fraction_non_alphanumeric': 0.17144177449168208, 'fraction_numerical': 0.022735674676524955, 'mean_word_length': 3.5851694915254235, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 173, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1679958', 'n_tokens_mistral': 4830, 'n_tokens_neox': 3999, 'n_words': 691}