/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     /* $input = array_except(Input::all(), '_method');
     		$file_path = $input['excel_file']; */
     /* $target_dir = public_path()."\uploads\eod_data\\";
     		$target_file = $target_dir . basename($_FILES["excel_file"]["name"]); */
     //$target_file = 'C:\xampp\htdocs\sharemarket_app\uploads\eod_data\Copy (2) of fo28AUG2015bhav.csv';
     $target_file = 'uploads/eod_data/fo28AUG2015bhav - Copy (2).csv';
     //$target_file = 'C:\xampp\htdocs\sharemarket_app\uploads\eod_data\fo28AUG2015bhav - Copy.csv';
     /* if (move_uploaded_file($_FILES["excel_file"]["tmp_name"], $target_file)) {
     			echo "The file ". basename( $_FILES["excel_file"]["name"]). " has been uploaded.";
     		} else {
     			echo "Sorry, there was an error uploading your file.";
     			die;
     		} */
     set_time_limit(6000);
     $data = array();
     \Excel::filter('chunk')->load($target_file)->chunk(250, function ($results) use(&$data) {
         $results_array = $results->toArray();
         //print_r($results_array);
         $i = 1;
         foreach ($results_array as $row) {
             //print_r($row);die;
             $datetime = strtotime($row['expiry_dt']);
             $datetime *= 1000;
             $data[] = "[{$datetime}, {$row['open']}, {$row['high']}, {$row['low']}, {$row['close']}]";
             //print_r($data);die;
         }
         //print_r($data);die;
     });
     //print_r($data);
     //die;
     return View::make('eod.index')->with('data', $data);
 }
Example #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $dir = $_SERVER['DOCUMENT_ROOT'] . "public/toUpload/";
     $doc = $this->argument('table') . '.xlsx';
     try {
         Excel::filter('chunk')->load($dir . $doc)->chunk(250, function ($reader) {
             if ($this->argument('table') == 'extracts') {
                 Extract::insert($this->validate($reader));
             } else {
                 ExcelDaily::insert($this->validate($reader));
             }
         });
         $message = "El archivo " . $doc . " se ha guardado en la base de datos.";
     } catch (Exception $e) {
         $message = "No se ha guardar " . $doc . ". Intenta subirlo de nuevo.";
     }
     /*Mail::send('emails.excel', ['msn' => $message], function ($m) use($message){
     			$m->to('*****@*****.**', 'Creditos Lilipink')->subject('Notificación Lilipink');
     		});*/
     Mail::send('emails.excel', ['msn' => $message], function ($m) use($message) {
         $m->to('*****@*****.**', 'Creditos Lilipink')->subject('Notificación Lilipink');
     });
     unlink($dir . $doc);
     if (!is_dir($dir)) {
         rmdir($dir);
     }
 }
Example #3
0
 public function fire()
 {
     $dir = $_SERVER['DOCUMENT_ROOT'] . "public/toUpload/";
     try {
         Excel::filter('chunk')->load($dir . 'data.xlsx')->chunk(250, function ($reader) {
             foreach ($reader->toArray() as $data) {
                 $user = User::where('identification_card', $data['cedula'])->first();
                 if (!$user) {
                     $user = User::create(['identification_card' => $data['cedula'], 'name' => $data['nombre'], 'user_name' => str_replace(' ', '.', $data['nombre']), 'email' => $data['email'] ? $data['email'] : 'Sin registro', 'address' => $data['direccion'] ? $data['direccion'] : 'Sin registro', 'residency_city' => $data['ciudad'] ? $data['ciudad'] : 'Sin registro', 'phone' => $data['tel1'] ? $data['tel1'] : 'Sin registro', 'mobile_phone' => $data['tel2'] ? $data['tel2'] : 'Sin registro', 'document_type' => 0, 'roles_id' => 4]);
                 }
                 $credit = CreditRequest::where('user_id', intval($user->id))->first();
                 if (!$credit) {
                     $c = new CreditRequest();
                     $c->user_id = intval($user->id);
                     $c->value = intval($data['limitecredito']);
                     $c->state = 1;
                     $c->location = 3;
                     $c->responsible = 18;
                     $c->save();
                 } else {
                     $credit->value = $data['limitecredito'];
                     $credit->save();
                 }
             }
         });
         echo $message = "El archivo  se ha guardado en la base de datos.";
     } catch (Exception $e) {
         echo $message = "No se ha guardar . Intenta subirlo de nuevo.";
     }
     Mail::send('emails.excel', ['msn' => $message], function ($m) use($message) {
         $m->to('*****@*****.**', 'Creditos Lilipink')->subject('Archivos actualizados');
     });
     array_map('unlink', glob($_SERVER['DOCUMENT_ROOT'] . "/toUpload/*"));
 }