public function postUploadimport() { set_time_limit(0); date_default_timezone_set('Asia/Jakarta'); $file = Input::file('inputfile'); $headindex = Input::get('headindex'); $firstdata = Input::get('firstdata'); $importkey = !is_null($this->importkey) ? Input::get('importkey') : $this->importkey; $aux_form_data = $this->processImportAuxForm(); //$importkey = $this->importkey; $rstring = str_random(15); $destinationPath = realpath('storage/upload') . '/' . $rstring; $filename = $file->getClientOriginalName(); $filemime = $file->getMimeType(); $filesize = $file->getSize(); $extension = $file->getClientOriginalExtension(); //if you need extension of the file $filename = str_replace(Config::get('kickstart.invalidchars'), '-', $filename); $uploadSuccess = $file->move($destinationPath, $filename); $fileitems = array(); if ($uploadSuccess) { $xlsfile = realpath('storage/upload') . '/' . $rstring . '/' . $filename; //$imp = Excel::load($xlsfile)->toArray(); $imp = array(); Excel::load($xlsfile, function ($reader) use(&$imp) { //$reader->formatDates(true, 'Y-m-d H:i:s'); $reader->formatDates(true); $imp = $reader->toArray(); })->get(); $headrow = $imp[$headindex - 1]; for ($h = 0; $h < count($headrow); $h++) { $headrow[$h] = strtolower($headrow[$h]); } //print_r($headrow); $firstdata = $firstdata - 1; $imported = array(); $sessobj = new Importsession(); $sessobj->heads = array_values($headrow); $sessobj->isHead = 1; $sessobj->sessId = $rstring; $sessobj->save(); for ($i = $firstdata; $i < count($imp); $i++) { $check = ''; $rowitem = $imp[$i]; $imported[] = $rowitem; $sessobj = new Importsession(); $rowtemp = array(); foreach ($rowitem as $k => $v) { $hkey = strtolower($headrow[$k]); $v = trim($v); $sessobj->{$hkey} = $this->prepImportItem($headrow[$k], $v, $rowitem); $rowtemp[$hkey] = $v; $check .= $v; } if (count($aux_form_data) > 0) { foreach ($aux_form_data as $ak => $av) { $sessobj->{$ak} = $this->prepImportItem($ak, $av); $rowtemp[$ak] = $av; } } $rowitem = $rowtemp; $sessobj->sessId = $rstring; $sessobj->isHead = 0; if (trim($check) == '') { } else { $sessobj->save(); } } } if (is_null($this->import_commit_url)) { $this->backlink = strtolower($this->controller_name); $commit_url = $this->backlink . '/commit/' . $rstring; } else { $commit_url = $this->import_commit_url . '/' . $rstring; } return Redirect::to($commit_url); }
public function postUploadimport() { $file = Input::file('inputfile'); $headindex = Input::get('headindex'); $firstdata = Input::get('firstdata'); $importkey = !is_null($this->importkey) ? Input::get('importkey') : $this->importkey; //$importkey = $this->importkey; $rstring = str_random(15); $destinationPath = realpath('storage/upload') . '/' . $rstring; $filename = $file->getClientOriginalName(); $filemime = $file->getMimeType(); $filesize = $file->getSize(); $extension = $file->getClientOriginalExtension(); //if you need extension of the file $filename = str_replace(Config::get('kickstart.invalidchars'), '-', $filename); $uploadSuccess = $file->move($destinationPath, $filename); $fileitems = array(); if ($uploadSuccess) { $xlsfile = realpath('storage/upload') . '/' . $rstring . '/' . $filename; //$imp = Excel::load($xlsfile)->toArray(); $imp = array(); Excel::load($xlsfile, function ($reader) use(&$imp) { $imp = $reader->toArray(); })->get(); $headrow = $imp[$headindex - 1]; //print_r($headrow); $firstdata = $firstdata - 1; $imported = array(); $sessobj = new Importsession(); $sessobj->heads = array_values($headrow); $sessobj->isHead = 1; $sessobj->sessId = $rstring; $sessobj->save(); for ($i = $firstdata; $i < count($imp); $i++) { $rowitem = $imp[$i]; $imported[] = $rowitem; $sessobj = new Importsession(); $rowtemp = array(); foreach ($rowitem as $k => $v) { $sessobj->{$headrow[$k]} = $v; $rowtemp[$headrow[$k]] = $v; } $rowitem = $rowtemp; $sessobj->sessId = $rstring; $sessobj->isHead = 0; $sessobj->save(); } } $this->backlink = strtolower($this->controller_name); $commit_url = $this->backlink . '/commit/' . $rstring; return Redirect::to($commit_url); }
public function postUploadimport() { $locationId = Input::get('locationId'); $locationName = $this->locationName($locationId); $file = Input::file('inputfile'); $headindex = Input::get('headindex'); $firstdata = Input::get('firstdata'); $importkey = !is_null($this->importkey) ? Input::get('importkey') : $this->importkey; //$importkey = $this->importkey; $rstring = str_random(15); $destinationPath = realpath('storage/upload') . '/' . $rstring; $filename = $file->getClientOriginalName(); $filemime = $file->getMimeType(); $filesize = $file->getSize(); $extension = $file->getClientOriginalExtension(); //if you need extension of the file $filename = str_replace(Config::get('kickstart.invalidchars'), '-', $filename); $uploadSuccess = $file->move($destinationPath, $filename); $fileitems = array(); if ($uploadSuccess) { $xlsfile = realpath('storage/upload') . '/' . $rstring . '/' . $filename; //$imp = Excel::load($xlsfile)->toArray(); $imp = array(); Excel::load($xlsfile, function ($reader) use(&$imp) { $imp = $reader->get(); })->get(); $imported = array(); foreach ($imp as $sheet) { $rackName = trim($sheet->getTitle()); $rackId = $this->rackId($rackName, $locationId, $locationName); print $rackId . ' - ' . $rackName . ' - ' . $locationId . ' - ' . $locationName . "\r\n"; $i = 0; $heads = array(); foreach ($sheet as $rows) { if ($i == $headindex) { $heads = array(); foreach ($rows as $r) { $heads[] = $r; } } if ($i >= $firstdata) { $row = array(); $y = 0; foreach ($rows as $r) { $row[$heads[$y]] = $r; $y++; } $add = array(); $add['locationName'] = $locationName; $add['locationId'] = $locationId; $add['rackId'] = $rackId; if (isset($row['SKU']) && $row['SKU'] == '') { $row['SKU'] = strtoupper(str_random(8)); } $row = array_merge($add, $row); $imported[] = $row; } $i++; } } $hadd = array('locationName', 'locationId', 'rackId'); $heads = array_merge($hadd, $heads); //print_r($heads); //print_r($imported); //die(); $sessobj = new Importsession(); $sessobj->heads = $heads; $sessobj->isHead = 1; $sessobj->sessId = $rstring; $sessobj->save(); foreach ($imported as $import) { $import['isHead'] = 0; $import['sessId'] = $rstring; Importsession::insert($import); } } $this->backlink = strtolower($this->controller_name); $commit_url = $this->backlink . '/commit/' . $rstring; return Redirect::to($commit_url); }