Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- //3.14 и 3.36
- header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
- header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
- header("Cache-Control: no-cache, must-revalidate");
- header("Pragma: no-cache");
- header('Content-type: text/html; charset=utf-8');
- $koef=3.14;
- $host = 'localhost';
- $db = 'db';
- $user = 'users';
- $pass = 'pasw';
- $charset = 'utf8';
- $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
- $opt = [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_BOTH,
- PDO::ATTR_EMULATE_PREPARES => false,
- ];
- $db = new PDO($dsn, $user, $pass, $opt);
- require_once 'Classes/PHPExcel.php';
- try{
- if (isset($_FILES['up_xls'])){
- $excel = PHPExcel_IOFactory::load($uploadfile);
- }else
- $excel = PHPExcel_IOFactory::load('parser.xls');
- } catch(Exception $e){
- print_r($e);
- }
- Foreach($excel ->getWorksheetIterator() as $worksheet) {
- $lists[] = $worksheet->toArray();
- }
- $i=0;
- $j=0;
- foreach($lists as $list){
- //echo '<table border="1">';
- // Перебор строк
- foreach($list as $row){
- // echo '<tr>';
- // Перебор столбцов
- $i=0;
- $search_index=0;
- //**************************Поиск нужных нам столбцов*************************************
- foreach ($row as $col){
- if (strpos($col,"CUSTOMER NO.")!==false){
- $mas_pars['art']=$search_index;
- }
- if (strpos($col,"FINISHING")!==false){
- $mas_pars['color']=$search_index;
- }
- if (strpos($col,"UNIT PRICE")!==false){
- $mas_pars['cena']=$search_index;
- }
- if (strpos($col,"SIZE OF THE CARTON")!==false){
- $mas_pars['size_w']=$search_index;
- $mas_pars['size_h']=$search_index+2;
- $mas_pars['size_l']=$search_index+4;
- }
- if (strpos($col,"TOTAL QTY")!==false){
- $mas_pars['count']=$search_index;
- }
- $search_index++;
- }
- //*****************************************************************************************
- $index=0;
- foreach($row as $col){
- if (($index==$mas_pars['art'])||($index==$mas_pars['color'])||($index==$mas_pars['cena'])||($index==$mas_pars['size_w'])||($index==$mas_pars['size_h'])||($index==$mas_pars['size_l'])||($index==$mas_pars['count'])){
- //echo '<td>'.$col.'</td>';
- if ($col==''){
- break;
- }
- $mas[$j][$i]=$col;
- $i++;
- }
- $index++;
- }
- if (count($mas[$j])<3){
- unset($mas[$j]);
- sort($mas);
- }
- if (strpos($mas[$j][0],' ')!==false){
- $mas[$j][0]=preg_replace("/\s+/", "", $mas[$j][0]);
- }
- if (strpos($mas[$j][1],' ')!==false){
- $mas[$j][1]=preg_replace("/\s+/", "", $mas[$j][1]);
- }
- if (strpos($mas[$j][6],' ')!==false){
- $mas[$j][6]=preg_replace("/\s+/", "", $mas[$j][6]);
- }
- if (strpos($mas[$j][0],'AD')===false){
- unset($mas[$j]);
- sort($mas);
- }else{
- $mas[$j][0]=str_replace("AD", "AD-", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'--')==true){
- $mas[$j][0]=str_replace("--", "-", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'CHROME')==true){
- $mas[$j][0]=str_replace("CHROME", "CR", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'WHITE')==true){
- $mas[$j][0]=str_replace("WHITE", "WH", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'BRONZE')==true){
- $mas[$j][0]=str_replace("BRONZE", "BR", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'GOLD')==true){
- $mas[$j][0]=str_replace("GOLD", "GO", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'BLACK')==true){
- $mas[$j][0]=str_replace("BLACK", "BK", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'GREY')==true){
- $mas[$j][0]=str_replace("GREY", "GR", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'WH')==true){
- $mas[$j][0]=str_replace("WH", " WH", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'GO')==true){
- $mas[$j][0]=str_replace("GO", " GO", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'BK')==true){
- $mas[$j][0]=str_replace("BK", " BK", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'GR')==true){
- $mas[$j][0]=str_replace("GR", " GR", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'BR')==true){
- $mas[$j][0]=str_replace("BR", " BR", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'BN')==true){
- $mas[$j][0]=str_replace("BN", " BN", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'CR')==true){
- $mas[$j][0]=str_replace("CR", " CR", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'+')==true){
- $mas[$j][0]=str_replace("+", " +", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'- ')==true){
- $mas[$j][0]=str_replace("- ", " + ", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],' + ')==true){
- $mas[$j][0]=str_replace(" + ", "+", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'BK+CR')==true){
- $mas[$j][0]=str_replace("BK+CR", "BK", $mas[$j][0]);
- }
- if (strpos($mas[$j][0],'CR+WH')==true){
- $mas[$j][0]=str_replace("CR+WH", "WH+CR", $mas[$j][0]);
- }
- if (strpos($mas[$j][1],',')==true){
- $mas[$j][1]=preg_replace('/^([^,]*).*$/', '$1', $mas[$j][1]);
- }
- if (strpos($mas[$j][1],'CHROME')!==false){
- $mas[$j][1]=str_replace("CHROME", "CR", $mas[$j][1]);
- }
- if (strpos($mas[$j][1],'WHITE')!==false){
- $mas[$j][1]=str_replace("WHITE", "WH", $mas[$j][1]);
- }
- if (strpos($mas[$j][1],'BRONZE')!==false){
- $mas[$j][1]=str_replace("BRONZE", "BR", $mas[$j][1]);
- }
- if (strpos($mas[$j][1],'GOLD')!==false){
- $mas[$j][1]=str_replace("GOLD", "GO", $mas[$j][1]);
- }
- if (strpos($mas[$j][1],'BLACK')!==false){
- $mas[$j][1]=str_replace("BLACK", "BK", $mas[$j][1]);
- }
- if (strpos($mas[$j][1],'GREY')!==false){
- $mas[$j][1]=str_replace("GREY", "GR", $mas[$j][1]);
- }
- if (strpos($mas[$j][6],'$')!==false){
- $mas[$j][6]=str_replace("$", "", $mas[$j][6]);
- }
- if (trim($mas[$j][6])!=''){
- $mas[$j][6]=round((trim($mas[$j][6])*$koef),2);
- }
- error_reporting(E_ALL);
- $cena=$mas[$j][6];
- $g=explode(".",$cena);
- if (strlen($g[1])>2){
- if ($g[1][3]>5){
- $cenaa=substr($g[1],0,2);
- $cenaa++;
- }else{
- $cenaa=substr($g[1],0,2);
- }
- $cenaa=$g[0].".".$cenaa;
- }else $cenaa=$mas[$j][6];
- if (strlen($g[1])<2){
- $cenaa=$cenaa."0";
- }
- $size_t=str_replace(",","",trim($mas[$j][2]))."х".str_replace(",","",trim($mas[$j][3]))."х".str_replace(",","",trim($mas[$j][4]));
- $size_t=str_replace(".","",trim($mas[$j][2]))."х".str_replace(".","",trim($mas[$j][3]))."х".str_replace(".","",trim($mas[$j][4]));
- $kolvo=$mas[$j][5];
- //echo '</tr>';
- if (trim($mas[$j][0])!=''){
- try{
- //*************************************************************************************************************************************************
- $art=substr(($db->quote(trim($mas[$j][0])."%")),1,strlen($db->quote(trim($mas[$j][0])."%"))-2);
- $r=$db->prepare("select id, cena, art from tovar_test where art LIKE :art");
- $update=$db->prepare("update tovar_test set cena = :cena where id= :id;");
- $insert=$db->prepare("insert into prixod(id_t, art, cena, data, kolvo) values(:id_t, :art, :cena, now(), :kolvo);");
- $insert_t=$db->prepare("insert into tovar_test(id_typ, id_kol, art, naz, cena, visibl, foto, foto1) values('7', '21', :art, 'new', :cena, '0', 'images/no-image.png', 'images/no-image.png');");
- $r->execute([':art'=>$art]);
- //*************************************Одно сопадение*************************************************************
- if ($r->rowCount()==1){
- $art=substr(($db->quote(trim($mas[$j][0]))),1,strlen($db->quote(trim($mas[$j][0])))-2);
- $r->execute([':art'=>$art]);
- if ($r->rowCount()!=0){
- $message.= "<br><br><font color=\"green\"><b>".$j.". '".$art."' - Найден в первом проходе!</b></font><br>";
- foreach ($r as $res){
- if (trim($res['cena'])!=$cenaa){
- $message.= "<font color=\"red\">Неверная цена(".$res['cena']." € <> ".$cenaa." €)</font><br>";
- if ($update->execute([':cena'=>$cenaa, ':id'=>$res['id']])){$message.= "<font color=\"green\">Цена успешно изменена</font><br>";}else $message.= "<font color=\"red\">Произошла ошибка при изменении цены</font><br>";
- }else $message.= "Цена верна(".$res['cena']." € = ".$cenaa." €)<br>";
- if ($insert->execute([':id_t'=>$res['id'], ':art'=>$res['art'], ':cena'=>$cenaa, ':kolvo'=>$kolvo])){$message.= "В таблицу приход запись добавлена<br>";}else $message.= "<font color=\"red\">Произошла ошибка при добавлении записи в таблицу приход</font><br>";
- }
- }else{
- $art=substr(($db->quote(trim($mas[$j][0]." ".$mas[$j][1]))),1,strlen($db->quote(trim($mas[$j][0]." ".$mas[$j][1])))-2);
- $r->execute([':art'=>$art]);
- if ($r->rowCount()!=0){
- $message.= "<br><br><font color=\"green\"><b>".$j.". '".$art."' - Найден во втором проходе!</b></font><br>";
- foreach ($r as $res){
- if (trim($res['cena'])!=$cenaa){
- $message.= "<font color=\"red\">Неверная цена(".$res['cena']." € <> ".$cenaa." €)</font><br>";
- if ($update->execute([':cena'=>$cenaa, ':id'=>$res['id']])){$message.= "<font color=\"green\">Цена успешно изменена</font><br>";}else $message.= "<font color=\"red\">Произошла ошибка при изменении цены</font><br>";
- }else $message.= "Цена верна(".$res['cena']." € = ".$cenaa." €)<br>";
- if ($insert->execute([':id_t'=>$res['id'], ':art'=>$res['art'], ':cena'=>$cenaa, ':kolvo'=>$kolvo])){$message.= "В таблицу приход запись добавлена<br>";}else $message.= "<font color=\"red\">Произошла ошибка при добавлении записи в таблицу приход</font><br>";
- }
- }else $message.= "<br><br><font color=\"red\"><b>".$j.". '".$art."' - Не найден во втором проходе!</b></font><br>";
- }
- }
- //**********************************Несколько совпадений**********************************************************
- if ($r->rowCount()>1){
- $art=substr(($db->quote(trim($mas[$j][0]." ".$mas[$j][1]))),1,strlen($db->quote(trim($mas[$j][0]." ".$mas[$j][1])))-2);
- $r->execute([':art'=>$art]);
- if ($r->rowCount()!=0){
- $message.= "<br><br><font color=\"green\"><b>".$j.". '".$art."' - Найден при множественном выборе!</b></font><br>";
- foreach ($r as $res){
- if (trim($res['cena'])!=$cenaa){
- $message.= "<font color=\"red\">Неверная цена(".$res['cena']." € <> ".$cenaa." €)</font><br>";
- if ($update->execute([':cena'=>$cenaa, ':id'=>$res['id']])){$message.= "<font color=\"green\">Цена успешно изменена</font><br>";}else $message.= "<font color=\"red\">Произошла ошибка при изменении цены</font><br>";
- }else $message.= "Цена верна(".$res['cena']." € = ".$cenaa." €)<br>";
- if ($insert->execute([':id_t'=>$res['id'], ':art'=>$res['art'], ':cena'=>$cenaa, ':kolvo'=>$kolvo])){$message.= "В таблицу приход запись добавлена<br>";}else $message.= "<font color=\"red\">Произошла ошибка при добавлении записи в таблицу приход</font><br>";
- }
- }else $message.= "<br><br><font color=\"red\"><b>".$j.". '".$art."' - Не найден при множественном выборе!</b></font><br>";
- }
- //*************************************Нет совпадений*************************************************************
- if ($r->rowCount()==0){
- $message.= "<br><br><font color=\"red\"><b>".$j.". '".$art."' - Не найден вообще!</b></font><br>";
- $art=substr(($db->quote(trim($mas[$j][0]))),1,strlen($db->quote(trim($mas[$j][0])))-2);
- if ($insert_t->execute([':art'=>$art, ':cena'=>$cenaa])){
- $message.= "Товар успешно добавлен в таблицу товар<br>";
- $r->execute([':art'=>$art]);
- foreach ($r as $res){
- if ($insert->execute([':id_t'=>$res['id'], ':art'=>$res['art'], ':cena'=>$cenaa, ':kolvo'=>$kolvo])){$message.= "В таблицу приход запись добавлена<br>";}else print "<font color=\"red\">Произошла ошибка при добавлении записи в таблицу приход</font><br>";
- }
- }else $message.= "<font color=\"red\">Произошла ошибка при добавлении в таблицу товар</font><br>";
- }
- //****************************************************************************************************************************************************
- } catch(Exception $e){
- print_r($e);
- }
- $message.= "Цена: ".$cenaa." €<br>";
- $message.= "Размер коробки: ".$size_t."<br>";
- $message.= "Количество: ".$kolvo."<br>";
- }
- $j++;
- }
- //echo '</table>';
- }
- if (!isset($_REQUEST['page']) && isset($message)){
- print $message;
- print "<pre>";
- print_r($mas);
- print "</pre>";
- print "<pre>";
- print_r($mas_pars);
- print "</pre>";
- }
- /* */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement