From: Kilian Saffran Date: Thu, 29 Jul 2021 14:27:38 +0000 (+0200) Subject: v29290729 X-Git-Url: http://cloud.dks.lu/git/?a=commitdiff_plain;h=e663b54462e45fcd05f6287445fa4b0b64823337;p=qube.git v29290729 --- diff --git a/.gitignore b/.gitignore index f6a4c12..35ced3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ public_html/old/* public_html/downloads/* +public_html/qubeshop/media/* +public_html/qubeshop/img/article_groups/* public_html/api/composer/vendor/* **/*.bak public_html/data/* @@ -30,3 +32,4 @@ api/data/art_fiche/* api/data/art_groups/* api/data/art_image/* + diff --git a/.vscode/sftp.json b/.vscode/sftp.json index 371c0f0..ad153b4 100644 --- a/.vscode/sftp.json +++ b/.vscode/sftp.json @@ -4,7 +4,7 @@ "protocol": "ftp", "port": 21, "secure": true, - "context": "/", + "context": "/Users/ksaff/Workspace/qube/", "host": "dedi1781.your-server.de", "username": "qubewv", "password": "cKo7O3b0", diff --git a/api/bin/getapidata.pl b/api/bin/getapidata.pl index 5869547..8ebdd7f 100644 --- a/api/bin/getapidata.pl +++ b/api/bin/getapidata.pl @@ -16,7 +16,9 @@ my $steps = ""; my $type = "full"; #full or upd my $dryrun = 0; my $live = 0; -GetOptions("steps|s=s" => \$steps,"type|t=s" => \$type,"dryrun|dr"=> \$dryrun,"live|l" => \$live); +my $onlycopy = 0; +my $onlyget = 0; +GetOptions("steps|s=s" => \$steps,"type|t=s" => \$type,"dryrun|dr"=> \$dryrun,"live|l" => \$live, "onlycopy|c" => \$onlycopy, "onlyget|g" => \$onlyget); my $runcmd = 'ps ax | grep '.basename($0).' | grep -v \'grep\' | head -n1 | awk \'{print $1}\''; my $run = `$runcmd`; @@ -25,7 +27,8 @@ if (($run ne "") && ($run ne $$)){ print "process already running on PID: $run $$\n"; exit(1); } - +my $starttime = POSIX::strftime('%F %T',localtime); +print "Started at".$starttime."\n"; my $cfg = (); my $datapath=dirname($RealBin).'/data'; my $config = config->new(); @@ -52,6 +55,7 @@ if (! -d $cfg->{sqlpath}){ mkdir($cfg->{sqlpath}); } $cfg->{cdate} = POSIX::strftime('%Y%m%d',localtime); +print "Config:\n".Dumper($cfg); my $db = mysql->new($cfg); $cfg->{dbh} = $db; my $clients = (); @@ -62,430 +66,588 @@ $api->writelog("type:".$type); $api->writelog("Config:".Dumper($cfg)); # get clients # first getall needed data from api -if (($steps eq "") || ($steps =~ /clients,/)){ - if ($type eq 'full'){ - $clients->{0}->{'date_update'} = ['>','2012-01-01 00:00:00']; - } elsif ($type eq 'upd') { - my $res = $db->querysorted("select CONCAT(max(date(date_update)),' 00:00:00') as date_update from wiges_s_client;"); - my @c = (); - print "RES:".Dumper($res)."\n"; - my $updx = $res->{0}->{"date_update"}.""; - push(@c,'>'); - push(@c,$updx); - print "Array:".Dumper(@c); - $clients->{0}->{'date_update'} = \@c; - } - $api->getData('s_client',$clients); -} -if (($steps eq "") || ($steps =~ /contacts,/)){ - $clients = $db->querysorted("select client from wiges_s_client;"); - $api->getData('s_contact_client',$clients); -} -# get articles -if (($steps eq "") || ($steps =~ /articles,/)){ - if ($type eq 'full'){ - $articles->{0}->{'date_creation'} = ['>','2015-01-01']; - } elsif ($type eq 'upd') { - $articles = $db->querysorted("select max(date_update) as date_update from wiges_s_article;"); +if ($onlycopy == 0){ + + # get articles + if (($steps =~ /articles,/)){ + my $tmpart = (); + if ($type eq 'full'){ + for (my $i=1;$i<24000;$i++){ + $tmpart->{$i}->{'id'} = "$i"; + } + } elsif ($type eq 'upd') { + #$articles = $db->querysorted("select max(date_update) as date_update from wiges_s_article;"); + my $res = $db->querysorted("select date(max(date_update)) as date_update from wiges_s_article;"); + my @c = (); + my $updx = "2021-07-24 00:00:00"; + push(@c,'>'); + push(@c,$updx); + $tmpart->{0}->{'date_update'} = \@c; + } + $articles = $api->getData('s_article',$tmpart,'article'); + } - $api->getData('s_article',$articles); + if (($steps =~ /translation,/) || ($steps =~ /articles,/)){ + if ($type eq 'full'){ + $articles = $db->querysorted("select article from wiges_s_article;"); + } + $api->getData('l_article',$articles,undef); -} -if (($steps eq "") || ($steps =~ /article_groups,/)){ + } + if (($steps =~ /article_groups,/) || ($steps =~ /articles,/)){ + my $tmpref = (); + if ($type eq 'full'){ + $tmpref = $db->querysorted("select article as article_lie from wiges_s_article;"); + } elsif ($type eq 'upd') { + foreach my $a (keys(%{$articles})){ + $tmpref->{$a}->{article_lie} = $articles->{$a}->{article}; + } + } + $api->getData('private_catalogue',$tmpref,undef); + } + if (($steps =~ /files,/) || ($steps =~ /articles,/)){ + if ($type eq 'full'){ + $articles = $db->querysorted("select article from wiges_s_article;"); + } + $api->getFiles('ole_article',$articles); - # $articles = $db->querysorted("select article as article_generique from wiges_s_article;"); - # &getData('private_catalogue',$articles); - $articles = $db->querysorted("select article as article_lie from wiges_s_article;"); - $api->getData('private_catalogue',$articles); -} -if (($steps eq "") || ($steps =~ /article_files,/)){ - # if ($type eq 'full'){ - $articles = $db->querysorted("select article from wiges_s_article;"); - # } - $api->getFiles('ole_article',$articles); + } + + # get prix_vente + if (($steps =~ /prix_vente,/) || ($steps =~ /articles,/)){ + if ($type eq 'full'){ + $articles = $db->querysorted("select article from wiges_s_article;"); + } + $api->getData('v_prix_vente',$articles); + } + # get stock + if (($steps =~ /stock,/) || ($steps =~ /articles,/)){ + if ($type eq 'full'){ + $articles = $db->querysorted("select article from wiges_s_article;"); + } + $api->getData('v_stock',$articles); + } + # get familles + if (($steps =~ /famille,/) || ($steps =~ /articles,/)){ + my $tmpsel = (); + if ($type eq 'full'){ + $tmpsel = $db->querysorted("select famille_art from wiges_s_article group by famille_art;"); + } else { + my @xarts = (); + foreach my $a (keys(%{$articles})){ + push(@xarts,"'".$articles->{$a}->{article}."'"); + } + $tmpsel = $db->querysorted("select famille_art from wiges_s_article where article in (".join(",",@xarts).") group by famille_art;"); + } + + $api->getData('s_famille_article',$tmpsel); + } + + # get groups + if (($steps =~ /groups,/) || ($steps =~ /articles,/)){ + my $tmpsel = (); + if ($type eq 'full'){ + $articles = $db->querysorted("select gp_art from wiges_s_article group by gp_art;"); + } else { + my @xarts = (); + foreach my $a (keys(%{$articles})){ + push(@xarts,"'".$articles->{$a}->{article}."'"); + } + $tmpsel = $db->querysorted("select gp_art from wiges_s_article where article in (".join(",",@xarts).") group by gp_art;"); + } + $api->getData('s_groupe_article',$tmpsel); + } -} -# get ventes -if (($steps eq "") || ($steps =~ /ventes,/)){ - if ($type eq 'full'){ + if (($steps =~ /clients,/)){ + if ($type eq 'full'){ + $clients->{0}->{'date_update'} = ['>','2012-01-01 00:00:00']; + } elsif ($type eq 'upd') { + my $res = $db->querysorted("select CONCAT(max(date(date_update)),' 00:00:00') as date_update from wiges_s_client;"); + my @c = (); + my $updx = $res->{0}->{"date_update"}.""; + push(@c,'>'); + push(@c,$updx); + $clients->{0}->{'date_update'} = \@c; + } + $api->getData('s_client',$clients,undef); + } + if (($steps =~ /contacts,/)){ $clients = $db->querysorted("select client from wiges_s_client;"); - } elsif ($type eq 'upd') { - my $res = $db->query("select max(dateheure_modif) as dateheure_modif from wiges_w_ventes;"); - $clients->{0}->{'dateheure_modif'} = ['>',$res->{dateheure_modif}]; + $api->getData('s_contact_client',$clients,undef); } - $api->getData('w_ventes',$clients); -} -# get ventes_pos -if (($steps eq "") || ($steps =~ /ventes_pos,/)){ - if ($type eq 'full'){ - $articles = $db->querysorted("select article from wiges_s_article;"); - } elsif ($type eq 'upd') { - my $res = $db->query("select max(dateheure_modif) as dateheure_modif from wiges_s_article;"); - $articles->{0}->{'dateheure_modif'} = ['>',$res->{dateheure_modif}]; + # get ventes + if (($steps =~ /ventes,/)){ + if ($type eq 'full'){ + $clients = $db->querysorted("select client from wiges_s_client;"); + } elsif ($type eq 'upd') { + my $res = $db->query("select max(dateheure_modif) as dateheure_modif from wiges_w_ventes;"); + $clients->{0}->{'dateheure_modif'} = ['>',$res->{dateheure_modif}]; + } + $api->getData('w_ventes',$clients); + } + # get ventes_pos + if (($steps =~ /ventes_pos,/)){ + if ($type eq 'full'){ + $articles = $db->querysorted("select article from wiges_s_article;"); + } elsif ($type eq 'upd') { + my $res = $db->query("select max(dateheure_modif) as dateheure_modif from wiges_s_article;"); + $articles->{0}->{'dateheure_modif'} = ['>',$res->{dateheure_modif}]; + } + $api->getData('w_ventes_pos',$articles); } - $api->getData('w_ventes_pos',$articles); -} -# get prix_vente -if (($steps eq "") || ($steps =~ /prix_vente,/)){ - $articles = $db->querysorted("select article from wiges_s_article;"); - $api->getData('v_prix_vente',$articles); -} -# get stock -if (($steps eq "") || ($steps =~ /stock,/)){ - $articles = $db->querysorted("select article from wiges_s_article;"); - $api->getData('v_stock',$articles); -} -# get familles -if (($steps eq "") || ($steps =~ /famille,/)){ - $articles = $db->querysorted("select famille_art from wiges_s_article group by famille_art;"); - $api->getData('s_famille_article',$articles); -} -# get groups -if (($steps eq "") || ($steps =~ /groups,/)){ - $articles = $db->querysorted("select gp_art from wiges_s_article group by gp_art;"); - $api->getData('s_groupe_article',$articles); } - - -#sync apidata to shopdata -if ($steps =~ /famille,/){ - #wiges_s_famille_article => prod_cat - my $data = $db->queryarray("select * from wiges_s_famille_article"); - foreach my $r (@{$data}){ - #print Dumper($r); - my $nd = { - 'code_famille' => $r->{'famille_art'}, - 'main_cat_link' => $r->{'firme'}, - 'prod_cat_link' => $r->{'designation'}, - 'prod_cat_fr' => $r->{'designation'}, - 'modified' => POSIX::strftime('%F %T', localtime) - }; +if ($onlyget == 0){ + #sync apidata to shopdata + if (($steps =~ /famille,/) || ($steps =~ /articles,/)){ + #wiges_s_famille_article => prod_cat + my $data = $db->queryarray("select * from wiges_s_famille_article"); + foreach my $r (@{$data}){ + #print Dumper($r); + my $nd = { + 'code_famille' => $r->{'famille_art'}, + 'main_cat_link' => $r->{'firme'}, + 'prod_cat_link' => $r->{'designation'}, + 'prod_cat_fr' => $r->{'designation'}, + 'modified' => POSIX::strftime('%F %T', localtime) + }; + + $nd->{'prod_cat_link'} = $config->toAscii($nd->{'prod_cat_link'}); + #$nd->{'prod_cat_link'} =~ s/^[A-Za-z0-9]/_/g; + #print Dumper($nd); + my $sql = $db->createReplaceDDL('prod_cat',$nd,undef); + if ($cfg->{dryrun} == 1){ + print $sql."\n"; + } else { + $api->writesql('prod_cat',$sql); + $db->exec($sql); + } + + } + } + if ($steps =~ /groups,/ || ($steps =~ /articles,/)){ + #wiges_s_groupe_article => prod_group + my $data = $db->queryarray("select * from wiges_s_groupe_article;"); + foreach my $r (@{$data}){ + my ($fr,$de,$qb); + if ($r->{'designation'} =~ /.*-.*\|.*/){ + print "FR|DE|QUBE\n"; + ($fr,$de,$qb) = $r->{'designation'} =~ m/^(.*)\s-\s(.*)\s\|\s(.*)$/; + } elsif ($r->{'designation'} =~ /.*-.*/){ + print "FR|DE\n"; + ($fr,$de) = $r->{'designation'} =~ m/^(.*)\s-\s(.*)$/; + }elsif ($r->{'designation'} =~ /.*\|.*/){ + print "FR|QUBE\n"; + ($fr,$qb) = $r->{'designation'} =~ m/^(.*)\s\|\s(.*)$/; + }else { + print "Only FR\n"; + ($fr) = $r->{'designation'}; + } + + my $nd = { + 'group_code' => $r->{'gp_art'}, + # 'main_cat_link' => $r->{'firme'}, + 'prod_cat' => $r->{'famille_art'}, + 'qube_name' => $qb, + 'prod_name_de' => $de.(($qb)?' | '.$qb:''), + 'prod_name_fr' => $fr.(($qb)?' | '.$qb:'') + }; + my $sql = $db->createReplaceDDL('prod_group',$nd,undef); + if ($cfg->{dryrun} == 1){ + print $sql."\n"; + } else { + $api->writesql('prod_group',$sql); + $db->exec($sql); + } + + + } + } + if ($steps =~ /clients,/){ + #wiges_s_groupe_article => prod_group + my $data = $db->queryarray("SELECT * FROM wiges_s_client;"); + foreach my $r (@{$data}){ - $nd->{'prod_cat_link'} = $config->toAscii($nd->{'prod_cat_link'}); - #$nd->{'prod_cat_link'} =~ s/^[A-Za-z0-9]/_/g; - #print Dumper($nd); - my $sql = $db->createReplaceDDL('prod_cat',$nd,undef); - if ($cfg->{dryrun} == 1){ - print $sql."\n"; - } else { - $db->exec($sql); + my ($lang); + if ($r->{'langue'} eq "D"){ + $lang = 'de'; + } elsif ($r->{'langue'} eq "F"){ + $lang = 'FR'; + }else { + $lang = $r->{'langue'}; + } + + my $nd = { + 'id' => $r->{'id'}, + 'client' => $r->{'client'}, + 'nom_1' => $r->{'nom_1'}, + 'nom_2' => $r->{'nom_2'}, + 'rue' => $r->{'rue'}, + 'code_postal' => $r->{'code_postal'}, + 'boite_postale' => $r->{'boite_postale'}, + 'localite' => $r->{'localite'}, + 'telephone_1' => $r->{'telephone_1'}, + 'telephone_2' => $r->{'telephone_2'}, + 'fax' => $r->{'fax'}, + 'interlocuteur' => $r->{'interlocuteur'}, + 'division' => $r->{'division'}, + 'departement' => $r->{'departement'}, + 'tva_client' => $r->{'tva_client'}, + 'no_tva' => $r->{'no_tva'}, + 'no_accises' => $r->{'no_accises'}, + 'cond_paiement' => $r->{'cond_paiement'}, + 'pays' => $r->{'pays'}, + 'langue' => $r->{'langue'}, + 'devise' => $r->{'devise'}, + 'on_actif' => $r->{'on_actif'}, + 'raison_sociale' => $r->{'raison_sociale'}, + 'adresse_email' => $r->{'adresse_email'}, + 'adresse_url' => $r->{'adresse_url'}, + 'adresse_client' => $r->{'adresse_client'} + }; + my $sql = $db->createReplaceDDL('clients',$nd,undef); + #print $sql."\n"; + if ($cfg->{dryrun} == 1){ + print $sql."\n"; + } else { + $api->writesql('clients',$sql); + $db->exec($sql); + } } - } -} -if ($steps =~ /groups,/){ - #wiges_s_groupe_article => prod_group - my $data = $db->queryarray("select * from wiges_s_groupe_article;"); - foreach my $r (@{$data}){ - my ($fr,$de,$qb); - if ($r->{'designation'} =~ /.*-.*\|.*/){ - print "FR|DE|QUBE\n"; - ($fr,$de,$qb) = $r->{'designation'} =~ m/^(.*)\s-\s(.*)\s\|\s(.*)$/; - } elsif ($r->{'designation'} =~ /.*-.*/){ - print "FR|DE\n"; - ($fr,$de) = $r->{'designation'} =~ m/^(.*)\s-\s(.*)$/; - }elsif ($r->{'designation'} =~ /.*\|.*/){ - print "FR|QUBE\n"; - ($fr,$qb) = $r->{'designation'} =~ m/^(.*)\s\|\s(.*)$/; - }else { - print "Only FR\n"; - ($fr) = $r->{'designation'}; - } - + + if ($steps =~ /contacts,/){ + my $data = $db->queryarray("select id as id_wiges,client as id_client, personne as id_personne, nom, adresse_email as useremail from wiges_s_contact_client where adresse_email is not null;"); + foreach my $r (@{$data}){ my $nd = { - 'group_code' => $r->{'gp_art'}, - # 'main_cat_link' => $r->{'firme'}, - 'prod_cat' => $r->{'famille_art'}, - 'qube_name' => $qb, - 'prod_name_de' => $de.(($qb)?' | '.$qb:''), - 'prod_name_fr' => $fr.(($qb)?' | '.$qb:'') + 'id_wiges' => $r->{id_wiges}, + 'id_client' => $r->{id_client}, + 'id_personne' => $r->{id_personne}, + 'nom' => $r->{nom}, + 'useremail' => $r->{useremail} }; - my $sql = $db->createReplaceDDL('prod_group',$nd,undef); + my $ids = 'id_wiges,id_client,id_personne'; + my $sql = $db->createUpsertDDL('users',$nd,undef,$ids); if ($cfg->{dryrun} == 1){ print $sql."\n"; } else { + $api->writesql('users',$sql); $db->exec($sql); } - + } } -} -if ($steps =~ /clients,/){ - #wiges_s_groupe_article => prod_group - my $data = $db->queryarray("SELECT * FROM wiges_s_client;"); - foreach my $r (@{$data}){ + + if (($steps =~ /article_groups,/) || ($steps =~ /articles,/)){ + my $agdata = $db->queryarray("select wsa.id, + wsa.article, + wsa.gp_art, + wsa.famille_art, + wsa.designation as titre, + wpc.c01 as c01_label, + wpc.c02 as c02_label, + wpc.c03 as c03_label, + wpc.c04 as c04_label, + wpc.c05 as c05_label, + wpc.c06 as c06_label, + wpc.c07 as c07_label, + wpc.c08 as c08_label, + wpc.c09 as c09_label, + wpc.c10 as c10_label, + wsa.on_actif + from wiges_s_article wsa + left join wiges_private_catalogue wpc on (wsa.article=wpc.article_generique) + where wpc.type_ligne = '1' group by article;"); + foreach my $r (@{$agdata}){ + my ($fr,$de,$sup); + $r->{titre} =~ s/“/"/g; + $r->{titre} =~ s/”/"/g; + if ($r->{'titre'} =~ /.*-.*\".*\"/){ + #print "FR|DE|SUP\n"; + ($fr,$de,$sup) = $r->{'titre'} =~ m/^(.*)\s-\s(.*)\"(.*)\".*$/; + } elsif ($r->{'titre'} =~ /.*-.*/){ + #print "FR|DE\n"; + ($fr,$de) = $r->{'titre'} =~ m/^(.*)\s-\s(.*)$/; + }else { + #print "Only FR\n"; + ($fr) = $r->{'titre'}; + } + #print $r->{'titre'}." => $fr == $de == $sup\n"; + my $nd = { + 'id' => $r->{'id'}, + 'article' => $r->{'article'}, + 'gp_art' => $r->{'gp_art'}, + 'famille_art' => $r->{'famille_art'}, + 'titre_fr' => $fr.(($sup)?' | '.$sup:''), + 'titre_de' => $de.(($sup)?' | '.$sup:''), + 'c01_label' => $r->{'c01_label'}, + 'c02_label' => $r->{'c02_label'}, + 'c03_label' => $r->{'c03_label'}, + 'c04_label' => $r->{'c04_label'}, + 'c05_label' => $r->{'c05_label'}, + 'c06_label' => $r->{'c06_label'}, + 'c07_label' => $r->{'c07_label'}, + 'c08_label' => $r->{'c08_label'}, + 'c09_label' => $r->{'c09_label'}, + 'c10_label' => $r->{'c10_label'}, + 'isactive' => $r->{'on_actif'} + }; + my $sql = $db->createReplaceDDL('article_groups',$nd,undef); + if ($cfg->{dryrun} == 1){ + print $sql."\n"; + } else { + $api->writesql('article_groups',$sql); + $db->exec($sql); + } - my ($lang); - if ($r->{'langue'} eq "D"){ - $lang = 'de'; - } elsif ($r->{'langue'} eq "F"){ - $lang = 'FR'; - }else { - $lang = $r->{'langue'}; + } + #group descriptions + my $agtrans = $db->queryarray("select ag.id,ag.article,wla.langue,wla.designation from wiges_l_article wla join article_groups ag on (wla.article=ag.article) where wla.langue in ('D','F') ;"); + foreach my $r (@{$agtrans}){ + my $sql =""; + if ($r->{langue} eq "D"){ + $sql= "UPDATE article_groups set description_de='".$db->securetext($r->{designation})."' where id='".$r->{id}."' and article='".$r->{article}."';"; + } elsif ($r->{langue} eq "F"){ + $sql= "UPDATE article_groups set description_fr='".$db->securetext($r->{designation})."' where id='".$r->{id}."' and article='".$r->{article}."';"; + } + #print "sql: $sql\n"; + if ($sql =~ /^UPDATE/){ + if ($cfg->{dryrun} == 1){ + print $sql."\n"; + } else { + $api->writesql('article_groups',$sql); + $db->exec($sql); + } } - + } + #group images + my $agimg = $db->queryarray("select ag.article,woa.nom_fichier from wiges_ole_article woa join article_groups ag on (woa.article=ag.article) where woa.code_document ='art_image' and woa.nom_fichier is not null;"); + foreach my $r (@{$agimg}){ + if (-e $cfg->{datapath}.'/'.$r->{nom_fichier}){ + my $newfname = basename($r->{nom_fichier}); + #$newfname =~ s/\s/_/g; + my $cmd = 'cp "'.$cfg->{datapath}.'/'.$r->{nom_fichier}.'" "'.$cfg->{imgpath}.'article_groups/'.$newfname.'"'; + print $cmd."\n"; + system($cmd); + + my $sql = "UPDATE article_groups set image='article_groups/".$newfname."' where article='".$r->{article}."';"; + #system($cmd); + if ($cfg->{dryrun} == 1){ + print $sql."\n"; + } else { + $api->writesql('article_groups',$sql); + $db->exec($sql); + } + } else { + #print "File ".dirname($RealBin).'/data/'.$r->{nom_fichier}." does not exist!\n"; + } + } + + my $sqlcleanft = "UPDATE article_groups set fichetechnique=null;"; + $db->exec($sqlcleanft); + my $agfiche = $db->queryarray("select ag.article,woa.nom_fichier from wiges_ole_article woa join article_groups ag on (woa.article=ag.article) where woa.code_document ='art_fiche' and woa.nom_fichier is not null;"); + foreach my $r (@{$agfiche}){ + if (-e $cfg->{datapath}.'/'.$r->{nom_fichier}){ + my $newfname = basename($r->{nom_fichier}); + #$newfname =~ s/\s/_/g; + my $cmd = 'cp "'.$cfg->{datapath}.'/'.$r->{nom_fichier}.'" "'.$cfg->{mediapath}.'fiche/'.$newfname.'"'; + print $cmd."\n"; + system($cmd); + + my $sql = "UPDATE article_groups set fichetechnique='fiche/".$newfname."' where article='".$r->{article}."';"; + #system($cmd); + if ($cfg->{dryrun} == 1){ + print $sql."\n"; + } else { + $api->writesql('article_groups',$sql); + $db->exec($sql); + } + } else { + #print "File ".dirname($RealBin).'/data/'.$r->{nom_fichier}." does not exist!\n"; + } + } + my $sqlcleanbro = "UPDATE article_groups set brochure=null;"; + $db->exec($sqlcleanbro); + my $agbrochure = $db->queryarray("select ag.article,woa.nom_fichier from wiges_ole_article woa join article_groups ag on (woa.article=ag.article) where woa.code_document ='art_fiche' and woa.nom_fichier is not null;"); + foreach my $r (@{$agbrochure}){ + if (-e $cfg->{datapath}.'/'.$r->{nom_fichier}){ + my $newfname = basename($r->{nom_fichier}); + #$newfname =~ s/\s/_/g; + my $cmd = 'cp "'.$cfg->{datapath}.'/'.$r->{nom_fichier}.'" "'.$cfg->{mediapath}.'brochure/'.$newfname.'"'; + print $cmd."\n"; + system($cmd); + + my $sql = "UPDATE article_groups set brochure='brochure/".$newfname."' where article='".$r->{article}."';"; + #system($cmd); + if ($cfg->{dryrun} == 1){ + print $sql."\n"; + } else { + $api->writesql('article_groups',$sql); + $db->exec($sql); + } + } else { + #print "File ".dirname($RealBin).'/data/'.$r->{nom_fichier}." does not exist!\n"; + } + } + } + if ($steps =~ /articles,/){ + my $xarticles = $db->queryarray("select wsa.id, + wpc.article_generique as article_group, + wsa.article, + wsa.gp_art, + wsa.famille_art, + wpc.c01 as c01, + wpc.c02 as c02, + wpc.c03 as c03, + wpc.c04 as c04, + wpc.c05 as c05, + wpc.c06 as c06, + wpc.c07 as c07, + wpc.c08 as c08, + wpc.c09 as c09, + wpc.c10 as c10, + wsa.on_actif, + wsa.unite_quantite + from wiges_s_article wsa + left join wiges_private_catalogue wpc on (wsa.article=wpc.article_lie) + where wpc.type_ligne = '2' group by article;"); + foreach my $r (@{$xarticles}){ my $nd = { - 'id' => $r->{'id'}, - 'client' => $r->{'client'}, - 'nom_1' => $r->{'nom_1'}, - 'nom_2' => $r->{'nom_2'}, - 'rue' => $r->{'rue'}, - 'code_postal' => $r->{'code_postal'}, - 'boite_postale' => $r->{'boite_postale'}, - 'localite' => $r->{'localite'}, - 'telephone_1' => $r->{'telephone_1'}, - 'telephone_2' => $r->{'telephone_2'}, - 'fax' => $r->{'fax'}, - 'interlocuteur' => $r->{'interlocuteur'}, - 'division' => $r->{'division'}, - 'departement' => $r->{'departement'}, - 'tva_client' => $r->{'tva_client'}, - 'no_tva' => $r->{'no_tva'}, - 'no_accises' => $r->{'no_accises'}, - 'cond_paiement' => $r->{'cond_paiement'}, - 'pays' => $r->{'pays'}, - 'langue' => $r->{'langue'}, - 'devise' => $r->{'devise'}, - 'on_actif' => $r->{'on_actif'}, - 'raison_sociale' => $r->{'raison_sociale'}, - 'adresse_email' => $r->{'adresse_email'}, - 'adresse_url' => $r->{'adresse_url'}, - 'adresse_client' => $r->{'adresse_client'} + 'id' => $r->{'id'}, + 'article_group' => $r->{'article_group'}, + 'article' => $r->{'article'}, + 'gp_art' => $r->{'gp_art'}, + 'famille_art' => $r->{'famille_art'}, + 'c01' => $r->{'c01'}, + 'c02' => $r->{'c02'}, + 'c03' => $r->{'c03'}, + 'c04' => $r->{'c04'}, + 'c05' => $r->{'c05'}, + 'c06' => $r->{'c06'}, + 'c07' => $r->{'c07'}, + 'c08' => $r->{'c08'}, + 'c09' => $r->{'c09'}, + 'c10' => $r->{'c10'}, + 'unite_quantite' => $r->{'unite_quantite'}, + 'isactive' => $r->{'on_actif'} }; - my $sql = $db->createReplaceDDL('clients',$nd,undef); + my $sql = $db->createReplaceDDL('articles',$nd,undef); #print $sql."\n"; if ($cfg->{dryrun} == 1){ print $sql."\n"; } else { + $api->writesql('articles',$sql); $db->exec($sql); } - } -} - -if (($steps =~ /article_groups,/) || ($steps =~ /articles,/)){ - my $agdata = $db->queryarray("select wsa.id, - wsa.article, - wsa.gp_art, - wsa.famille_art, - wsa.designation as titre, - wpc.c01 as c01_label, - wpc.c02 as c02_label, - wpc.c03 as c03_label, - wpc.c04 as c04_label, - wpc.c05 as c05_label, - wpc.c06 as c06_label, - wpc.c07 as c07_label, - wpc.c08 as c08_label, - wpc.c09 as c09_label, - wpc.c10 as c10_label - from wiges_s_article wsa - left join wiges_private_catalogue wpc on (wsa.article=wpc.article_generique) - where wpc.type_ligne = '1' group by article ;"); - foreach my $r (@{$agdata}){ - my ($fr,$de,$sup); - $r->{titre} =~ s/“/"/g; - $r->{titre} =~ s/”/"/g; - if ($r->{'titre'} =~ /.*-.*\".*\"/){ - #print "FR|DE|SUP\n"; - ($fr,$de,$sup) = $r->{'titre'} =~ m/^(.*)\s-\s(.*)\"(.*)\".*$/; - } elsif ($r->{'titre'} =~ /.*-.*/){ - #print "FR|DE\n"; - ($fr,$de) = $r->{'titre'} =~ m/^(.*)\s-\s(.*)$/; - }else { - #print "Only FR\n"; - ($fr) = $r->{'titre'}; - } - #print $r->{'titre'}." => $fr == $de == $sup\n"; - my $nd = { - 'id' => $r->{'id'}, - 'article' => $r->{'article'}, - 'gp_art' => $r->{'gp_art'}, - 'famille_art' => $r->{'famille_art'}, - 'titre_fr' => $fr.(($sup)?' | '.$sup:''), - 'titre_de' => $de.(($sup)?' | '.$sup:''), - 'c01_label' => $r->{'c01_label'}, - 'c02_label' => $r->{'c02_label'}, - 'c03_label' => $r->{'c03_label'}, - 'c04_label' => $r->{'c04_label'}, - 'c05_label' => $r->{'c05_label'}, - 'c06_label' => $r->{'c06_label'}, - 'c07_label' => $r->{'c07_label'}, - 'c08_label' => $r->{'c08_label'}, - 'c09_label' => $r->{'c09_label'}, - 'c10_label' => $r->{'c10_label'}, - }; - my $sql = $db->createReplaceDDL('article_groups',$nd,undef); - if ($cfg->{dryrun} == 1){ - print $sql."\n"; - } else { - $db->exec($sql); } - } - #group descriptions - my $agtrans = $db->queryarray("select ag.id,ag.article,wla.langue,wla.designation from wiges_l_article wla join article_groups ag on (wla.article=ag.article) where wla.langue in ('D','F') ;"); - foreach my $r (@{$agtrans}){ - my $sql =""; - if ($r->{langue} eq "D"){ - $sql= "UPDATE article_groups set description_de='".$db->securetext($r->{designation})."' where id='".$r->{id}."' and article='".$r->{article}."';"; - } elsif ($r->{langue} eq "F"){ - $sql= "UPDATE article_groups set description_fr='".$db->securetext($r->{designation})."' where id='".$r->{id}."' and article='".$r->{article}."';"; + + my $sqlcleanft = "UPDATE articles set doc_ft=null;"; + $db->exec($sqlcleanft); + my $agfiche = $db->queryarray("select ag.article,woa.nom_fichier from wiges_ole_article woa join articles ag on (woa.article=ag.article) where woa.code_document ='art_fiche' and woa.nom_fichier is not null;"); + foreach my $r (@{$agfiche}){ + if (-e $cfg->{datapath}.'/'.$r->{nom_fichier}){ + my $newfname = basename($r->{nom_fichier}); + #$newfname =~ s/\s/_/g; + my $cmd = 'cp "'.$cfg->{datapath}.'/'.$r->{nom_fichier}.'" "'.$cfg->{mediapath}.'fiche/'.$newfname.'"'; + print $cmd."\n"; + system($cmd); + + my $sql = "UPDATE articles set doc_ft='fiche/".$newfname."' where article='".$r->{article}."';"; + #system($cmd); + if ($cfg->{dryrun} == 1){ + print $sql."\n"; + } else { + $api->writesql('articles',$sql); + $db->exec($sql); + } + } else { + #print "File ".dirname($RealBin).'/data/'.$r->{nom_fichier}." does not exist!\n"; + } } - #print "sql: $sql\n"; - if ($sql =~ /^UPDATE/){ + #article_prices + # my $arprice = $db->queryarray("select date_debut,0 as cc_client,article,pu_vente as prix_net from wiges_v_prix_vente wsa where prix_vente=1;"); + # foreach my $r (@{$arprice}){ + # my $nd = { + # 'date_debut' => $r->{'date_debut'}, + # 'cc_client' => $r->{'cc_client'}, + # 'article' => $r->{'article'}, + # 'prix_net' => $r->{'prix_net'} + # }; + # my $sql = $db->createReplaceDDL('article_prices',$nd,undef); + # #print $sql."\n"; + # $db->exec($sql); + + # } + + } + if (($steps =~ /prices,/) || ($steps =~ /articles,/)){ + my $arprice = $db->queryarray("select wvpw2.article,wvpw2.date_debut,wvpw2.pu_vente,(wvpw2.pu_vente * 0.17) + wvpw2.pu_vente as prix_brut from wiges_v_prix_vente wvpw2 join (select article,max(date_debut) as maxdate from wiges_v_prix_vente group by article) wvpv1 on (wvpw2.article=wvpv1.article and wvpw2.date_debut=wvpv1.maxdate);"); + foreach my $r (@{$arprice}){ + my $nd = { + 'date_debut' => $r->{'date_debut'}, + 'cc_client' => 0, + 'article' => $r->{'article'}, + 'prix_net' => $r->{'pu_vente'}, + 'prix_brut' => $r->{'prix_brut'} + }; + my $sql = $db->createReplaceDDL('article_prices',$nd,undef); + #print $sql."\n"; if ($cfg->{dryrun} == 1){ print $sql."\n"; } else { + $api->writesql('article_prices',$sql); $db->exec($sql); } + } - } - #group images - my $agimg = $db->queryarray("select ag.article,woa.nom_fichier from wiges_ole_article woa join article_groups ag on (woa.article=ag.article) where woa.code_document ='art_image' and woa.nom_fichier is not null;"); - foreach my $r (@{$agimg}){ - if (-e $cfg->{datapath}.'/'.$r->{nom_fichier}){ - my $newfname = basename($r->{nom_fichier}); - $newfname =~ s/\s/_/g; - my $cmd = 'cp "'.$cfg->{datapath}.'/'.$r->{nom_fichier}.'" "'.$cfg->{imgpath}.'article_groups/'.$newfname.'"'; - print $cmd."\n"; - system($cmd); - - my $sql = "UPDATE article_groups set image='article_groups/".$newfname."' where article='".$r->{article}."';"; - #system($cmd); + # #contrat cadre client + $arprice = $db->queryarray("select null as date_debut,wwv.client as cc_client,wwvp.article,wwvp.pu_net as prix_net,(wwvp.pu_net * 0.17) + wwvp.pu_net as prix_brut from wiges_w_ventes wwv join wiges_w_ventes_pos wwvp on (wwv.no_document=wwvp.no_document and wwv.document='CCC' and wwvp.document='CCC') where wwvp.document='CCC';"); + foreach my $r (@{$arprice}){ + my $nd = { + 'date_debut' => $r->{'date_debut'}, + 'cc_client' => $r->{'cc_client'}, + 'article' => $r->{'article'}, + 'prix_net' => $r->{'prix_net'}, + 'prix_brut' => $r->{'prix_brut'} + }; + my $sql = $db->createReplaceDDL('article_prices',$nd,undef); + #print $sql."\n"; if ($cfg->{dryrun} == 1){ print $sql."\n"; } else { + $api->writesql('article_prices',$sql); $db->exec($sql); } - } else { - #print "File ".dirname($RealBin).'/data/'.$r->{nom_fichier}." does not exist!\n"; - } - } -} -if ($steps =~ /articles,/){ - my $articles = $db->queryarray("select wsa.id, - wpc.article_generique as article_group, - wsa.article, - wsa.gp_art, - wsa.famille_art, - wpc.c01 as c01, - wpc.c02 as c02, - wpc.c03 as c03, - wpc.c04 as c04, - wpc.c05 as c05, - wpc.c06 as c06, - wpc.c07 as c07, - wpc.c08 as c08, - wpc.c09 as c09, - wpc.c10 as c10, - wsa.unite_quantite - from wiges_s_article wsa - left join wiges_private_catalogue wpc on (wsa.article=wpc.article_lie) - where wpc.type_ligne = '2' group by article;"); - foreach my $r (@{$articles}){ - my $nd = { - 'id' => $r->{'id'}, - 'article_group' => $r->{'article_group'}, - 'article' => $r->{'article'}, - 'gp_art' => $r->{'gp_art'}, - 'famille_art' => $r->{'famille_art'}, - 'c01' => $r->{'c01'}, - 'c02' => $r->{'c02'}, - 'c03' => $r->{'c03'}, - 'c04' => $r->{'c04'}, - 'c05' => $r->{'c05'}, - 'c06' => $r->{'c06'}, - 'c07' => $r->{'c07'}, - 'c08' => $r->{'c08'}, - 'c09' => $r->{'c09'}, - 'c10' => $r->{'c10'}, - 'unite_quantite' => $r->{'unite_quantite'} - }; - my $sql = $db->createReplaceDDL('articles',$nd,undef); - #print $sql."\n"; - if ($cfg->{dryrun} == 1){ - print $sql."\n"; - } else { - $db->exec($sql); - } - } - - #article_prices - # my $arprice = $db->queryarray("select date_debut,0 as cc_client,article,pu_vente as prix_net from wiges_v_prix_vente wsa where prix_vente=1;"); - # foreach my $r (@{$arprice}){ - # my $nd = { - # 'date_debut' => $r->{'date_debut'}, - # 'cc_client' => $r->{'cc_client'}, - # 'article' => $r->{'article'}, - # 'prix_net' => $r->{'prix_net'} - # }; - # my $sql = $db->createReplaceDDL('article_prices',$nd,undef); - # #print $sql."\n"; - # $db->exec($sql); - - # } - -} -if (($steps =~ /prices,/) || ($steps =~ /articles,/)){ - my $arprice = $db->queryarray("select wvpw2.article,wvpw2.date_debut,wvpw2.pu_vente,(wvpw2.pu_vente * 0.17) + wvpw2.pu_vente as prix_brut from wiges_v_prix_vente wvpw2 join (select article,max(date_debut) as maxdate from wiges_v_prix_vente group by article) wvpv1 on (wvpw2.article=wvpv1.article and wvpw2.date_debut=wvpv1.maxdate);"); - foreach my $r (@{$arprice}){ - my $nd = { - 'date_debut' => $r->{'date_debut'}, - 'cc_client' => 0, - 'article' => $r->{'article'}, - 'prix_net' => $r->{'pu_vente'}, - 'prix_brut' => $r->{'prix_brut'} - }; - my $sql = $db->createReplaceDDL('article_prices',$nd,undef); - #print $sql."\n"; - if ($cfg->{dryrun} == 1){ - print $sql."\n"; - } else { - $db->exec($sql); } - } - # #contrat cadre client - $arprice = $db->queryarray("select null as date_debut,wwv.client as cc_client,wwvp.article,wwvp.pu_net as prix_net,(wwvp.pu_net * 0.17) + wwvp.pu_net as prix_brut from wiges_w_ventes wwv join wiges_w_ventes_pos wwvp on (wwv.no_document=wwvp.no_document and wwv.document='CCC' and wwvp.document='CCC') where wwvp.document='CCC';"); - foreach my $r (@{$arprice}){ - my $nd = { - 'date_debut' => $r->{'date_debut'}, - 'cc_client' => $r->{'cc_client'}, - 'article' => $r->{'article'}, - 'prix_net' => $r->{'prix_net'}, - 'prix_brut' => $r->{'prix_brut'} - }; - my $sql = $db->createReplaceDDL('article_prices',$nd,undef); - #print $sql."\n"; - if ($cfg->{dryrun} == 1){ - print $sql."\n"; - } else { - $db->exec($sql); - } - } -} -if ($steps =~ /stock,/){ - my $stockar = $db->queryarray("select wvs.article,wvs.qte_stock ,wvs.qte_commandee - wvs.qte_reservee as qte_commandee from articles a join wiges_v_stock wvs on (a.article=wvs.article);"); - foreach my $r (@{$stockar}){ - my $nd = { - 'qte_stock' => $r->{'qte_stock'}, - 'qte_commandee' => $r->{'qte_commandee'}, - }; - my $idents = { - 'article' => $r->{'article'} - }; - my $sql = $db->createUpdateDDL('articles',$nd,$idents,undef); - #print $sql."\n"; - if ($cfg->{dryrun} == 1){ - print $sql."\n"; - } else { - $db->exec($sql); + if ($steps =~ /stock,/ || ($steps =~ /articles,/)){ + my $stockar = $db->queryarray("select wvs.article,wvs.qte_stock ,wvs.qte_commandee - wvs.qte_reservee as qte_commandee from articles a join wiges_v_stock wvs on (a.article=wvs.article);"); + foreach my $r (@{$stockar}){ + my $nd = { + 'qte_stock' => $r->{'qte_stock'}, + 'qte_commandee' => $r->{'qte_commandee'}, + }; + my $idents = { + 'article' => $r->{'article'} + }; + my $sql = $db->createUpdateDDL('articles',$nd,$idents,undef); + #print $sql."\n"; + if ($cfg->{dryrun} == 1){ + print $sql."\n"; + } else { + $api->writesql('articles',$sql); + $db->exec($sql); + } } } } - - +my $endtime = POSIX::strftime('%F %T',localtime); +print "Started at: ".$starttime."\n"; +print "Normal End at: ".$endtime."\n"; +if ($type eq 'upd'){ + print "Total Articles updated: ".keys(%{$articles})."\n"; +} diff --git a/api/bin/lib/api.pm b/api/bin/lib/api.pm index 44d1224..5e859d4 100644 --- a/api/bin/lib/api.pm +++ b/api/bin/lib/api.pm @@ -3,6 +3,8 @@ package api; use strict; use JSON::PP; use Data::Dumper; +use MIME::Base64; +use POSIX 'strftime'; sub new { my $class = shift; @@ -31,8 +33,18 @@ sub sendcurl(){ $cmd .= 'https://'.$self->{url}.'/api/'.$table.'/search'; $self->writelog("CURL: $cmd"); $strres= `$cmd`; - - return $json->decode($strres); + if (($strres !~ /^\[/) && ($strres !~ /^\{/)){ + $self->writelog("NO JSON return!\n=====\n".$strres."\n======\n"); + return []; + } else { + my $ret = $json->decode($strres); + if (!defined($ret)){ + $self->writelog("Error on json-decode!\n=====\n".$strres."\n======\n"); + return []; + } + return $ret; + } + return []; } @@ -52,10 +64,69 @@ sub writelog(){ } } +sub writesql(){ + my $self = shift; + my $tbl = shift; + my $msg = shift; + $msg =~ s/\r//g; + $msg =~ s/\n//g; + $msg =~ s/\s+/ /g; + my $cdatetime = POSIX::strftime('%F %T',localtime); + if ($self->{dryrun} == 0){ + open(SLOG,">>".$self->{sqlpath}."/".$self->{cdate}.$tbl.".sql"); + print SLOG $cdatetime.';'.$msg."\n"; + close(SLOG); + } else { + print $cdatetime.';'.$msg."\n"; + } +} + sub getData($$){ my $self = shift; my $wtable = shift; my $def = shift; + my $retfield = shift; + my $ret = (); + my $retcnt=0; + open(FF,">".$self->{sqlpath}."/".$self->{cdate}."_wiges_".$wtable.".sql"); + close(FF); + foreach my $a (keys(%{$def})){ + $self->writelog($wtable.": ".Dumper($def->{$a})); + my $curlres = $self->sendcurl($wtable,$def->{$a}); + if (ref($curlres) eq "ARRAY"){ + $self->writelog("Length: ".scalar(@{$curlres})." IS ARRAY!"); + if (scalar(@{$curlres}) > 0){ + $self->writelog("Create SQL..."); + foreach my $r (@{$curlres}){ + if (defined($retfield) && $r->{$retfield}){ + $ret->{$retcnt}->{$retfield} = $r->{$retfield}; + $retcnt++; + } + my $sql = $self->{dbh}->createReplaceDDL('wiges_'.$wtable,$r,undef); + if ($self->{dryrun} == 0){ + open(FF,">>".$self->{sqlpath}."/".$self->{cdate}."_wiges_".$wtable.".sql"); + print FF $sql."\n"; + close(FF); + $self->{dbh}->exec($sql); + }else { + print $sql."\n"; + } + + } + } + }else { + $self->writelog("noArray:=>".Dumper($def->{$a})); + } + sleep(0.5); + } + return $ret; +} + +sub getUpdatedList($$){ + my $self = shift; + my $wtable = shift; + my $fields = shift; + my $def = shift; open(FF,">".$self->{sqlpath}."/".$self->{cdate}."_wiges_".$wtable.".sql"); close(FF); foreach my $a (keys(%{$def})){ @@ -85,10 +156,13 @@ sub getData($$){ } } + sub getFiles(){ my $self = shift; my $wtable = shift; my $def = shift; + #my $excl = shift; + #$excl .= $excl.","; open(FF,">".$self->{sqlpath}."/".$self->{cdate}."_wiges_".$wtable.".sql"); close(FF); foreach my $a (keys(%{$def})){ @@ -102,10 +176,16 @@ sub getFiles(){ my $suffix = $r->{nom_fichier}; my $newarticle = $r->{article}; $newarticle =~ s/\//_/g; - $newarticle =~ s/\\/_/g; + $newarticle =~ s/\\/_/g; + $newarticle =~ s/\$/_/g; + $newarticle =~ s/\&/_/g; + $newarticle =~ s/\s+/_/g; + $newarticle =~ s/\./_/g; #$r->{article} = $articles->{$a}->{article}; $suffix =~ s/^\@file\@//; + my $folder= $r->{code_document}; + #if ($excl =~ /$folder,/){ next; } # $folder =~ s/art_//; if ($self->{dryrun} == 0){ if (! -d $self->{datapath}.'/'.$folder){ diff --git a/api/bin/lib/config.pm b/api/bin/lib/config.pm index 628d57a..b6a1cf3 100644 --- a/api/bin/lib/config.pm +++ b/api/bin/lib/config.pm @@ -14,7 +14,7 @@ sub readcfg() { my $file = shift; my $retcfg = (); #print "read CFG ".$self->{cfgfile}."\n"; - open(CFG,$self->{cfgfile}); + open(CFG,$file); while (my $l = ){ chomp($l); $l =~ s/^\s+//; diff --git a/public_html/qubeshop/.htaccess b/public_html/qubeshop/.htaccess index f6025ff..fdb1c13 100644 --- a/public_html/qubeshop/.htaccess +++ b/public_html/qubeshop/.htaccess @@ -1,9 +1,9 @@ #FcgidWrapper "/home/httpd/cgi-bin/php74-fcgi-starter.fcgi" .php RewriteEngine on DirectoryIndex index.php index.html -php_flag display_startup_errors on -php_flag display_errors on -php_flag html_errors on +php_flag display_startup_errors off +php_flag display_errors off +php_flag html_errors off php_value post_max_size 128M php_value upload_max_filesize 128M RewriteCond %{REQUEST_FILENAME} !-f diff --git a/public_html/qubeshop/css/theme.css b/public_html/qubeshop/css/theme.css index c0a1b55..dbb7c8c 100644 --- a/public_html/qubeshop/css/theme.css +++ b/public_html/qubeshop/css/theme.css @@ -162,7 +162,7 @@ hr{border:0;border-top:1px solid #eee;margin:20px 0} .indigo,.hover-indigo:hover{color:#fff!important;background-color:#3f51b5!important} .khaki,.hover-khaki:hover{color:#000!important;background-color:#f0e68c!important} .lime,.hover-lime:hover{color:#000!important;background-color:#cddc39!important} -.orange,.hover-orange:hover{color:#000!important;background-color:#ff9800!important} +.orange,.hover-orange:hover{color:#fff!important;background-color:#ff9800!important} .deep-orange,.hover-deep-orange:hover{color:#fff!important;background-color:#ff5722!important} .pink,.hover-pink:hover{color:#fff!important;background-color:#e91e63!important} .purple,.hover-purple:hover{color:#fff!important;background-color:#9c27b0!important} @@ -773,7 +773,7 @@ label { } input[class*="quantity"]{ - width: 110px!important; + width: 90px!important; text-align: right; } @@ -956,3 +956,14 @@ footer h4 { background-color: #2f54a2; } +button.orange { + color:#fff!important;background-color:#ff9800!important; +} + +button.green { + color:#fff!important;background-color:#4CAF50!important; +} + +button.blue-grey { + color:#fff!important;background-color:#607d8b!important; +} diff --git a/public_html/qubeshop/lib/config.php b/public_html/qubeshop/lib/config.php index aa6721d..d4f89c8 100644 --- a/public_html/qubeshop/lib/config.php +++ b/public_html/qubeshop/lib/config.php @@ -2,13 +2,21 @@ $cfg = array( "cookie" => "qubeshop", "lang" => "fr", - "debug" => 0, + "debug" => 1, + // "db"=> array( + // "type" => "mysql", + // "host" => "dedi1781.your-server.de", + // "dbname" => "qubewv_db3", + // "user" => "qubewv_3", + // "password" => "rhNpYMtXch1Lx6RQ", + // "prefix" => "wiges", + // ), "db"=> array( "type" => "mysql", "host" => "dedi1781.your-server.de", - "dbname" => "qubewv_db3", - "user" => "qubewv_3", - "password" => "rhNpYMtXch1Lx6RQ", + "dbname" => "qube_db4", + "user" => "qube_user4", + "password" => "xevt4b99cNRHPEjF", "prefix" => "wiges", ), "api" => array( @@ -17,7 +25,7 @@ "password" => "poco941", "api-app-key" => "l9345y3e-4b56-3fb4-91ca-404f62d52jfs", "api-device-key" => "webdev", - "url" => "https://qube-test.wiges.lu/api/%%TABLE%%/search" + "url" => "https://pointcomm.api.qube.wiges.lu/api/%%TABLE%%/search" ), "datapath" => "data/", "templatepath" => "tmpl/", diff --git a/public_html/qubeshop/lib/database.php b/public_html/qubeshop/lib/database.php index b7bd7a4..756c81a 100644 --- a/public_html/qubeshop/lib/database.php +++ b/public_html/qubeshop/lib/database.php @@ -54,8 +54,9 @@ class database { public function querybykey($key,$sql){ $result = null; $kresult = array(); + if ($this->debug == 1){ - //error_log("QUERYbykey: ".$sql); + // file_put_contents("sql.log",$sql,FILE_APPEND); } try { if ($this->conn){ diff --git a/public_html/qubeshop/lib/lang/fr.php b/public_html/qubeshop/lib/lang/fr.php index 0909b3b..e42f43d 100644 --- a/public_html/qubeshop/lib/lang/fr.php +++ b/public_html/qubeshop/lib/lang/fr.php @@ -28,6 +28,8 @@ "prefereddeliverydate" => "Date de livraison préférée", "askpricetype" => "Demande de prix pour ...", "message" => "message supplémentaire", - "clientaddress" => "Addresse client" + "clientaddress" => "Addresse client", + "numbondecommande" => "No. bon de commande", + "fichierbondecommande" => "Fichier Bon de commande" ); ?> \ No newline at end of file diff --git a/public_html/qubeshop/lib/modules/Articles.php b/public_html/qubeshop/lib/modules/Articles.php index 9eee7b6..18d7843 100644 --- a/public_html/qubeshop/lib/modules/Articles.php +++ b/public_html/qubeshop/lib/modules/Articles.php @@ -15,13 +15,15 @@ class Articles{ public function getArticleGroups($famillycode,$groupcode,$lang){ if (!$lang){ $lang=$this->cfg["lang"];} - return $this->dbh->queryarray("select id,article,gp_art,famille_art,coalesce(titre_".$lang.",titre_".$this->cfg["lang"].") as titre,coalesce(description_".$lang.",description_".$this->cfg["lang"].") as description,c01_label,c02_label,c03_label,c03_label,c04_label,c05_label,replace(image,' ','%20') as image from article_groups where gp_art='".$groupcode."' and famille_art='".$famillycode."' order by titre,article;"); + return $this->dbh->queryarray("select id,article,gp_art,famille_art,coalesce(titre_".$lang.",titre_".$this->cfg["lang"].") as titre,coalesce(description_".$lang.",description_".$this->cfg["lang"].") as description,c01_label,c02_label,c03_label,c03_label,c04_label,c05_label,replace(image,' ','%20') as image,fichetechnique,brochure,noticemontage from article_groups where gp_art='".$groupcode."' and famille_art='".$famillycode."' order by titre,article;"); } public function getByFamillyAndGroups($famillycode,$groupcode,$lang){ if (!$lang){ $lang=$this->cfg["lang"];} - return $this->dbh->querybykey('article_group',"select ar.id,UPPER(ar.article_group) as article_group,ar.article,ar.gp_art,ar.famille_art,ar.c01,ar.c02,ar.c03,ar.c04,ar.c05,ap.prix_net,ap.prix_brut,ar.unite_quantite,qte_stock,qte_commandee from articles ar join article_prices ap on (ar.article=ap.article) -where ar.famille_art='".$famillycode."' and ar.gp_art='".$groupcode."' group by id,article_group,article order by article_group,article;"); + return $this->dbh->querybykey('article_group',"select ar.id,UPPER(ar.article_group) as article_group,ar.article,ar.gp_art,ar.famille_art,ar.c01,ar.c02,ar.c03,ar.c04,ar.c05,ap.prix_net,ap.prix_brut,ar.unite_quantite,qte_stock,qte_commandee,ar.doc_ft,ar.doc_mo,ar.doc_fs from articles ar join article_prices ap on (ar.article=ap.article) +where article_group in(select article from article_groups where famille_art='".$famillycode."' and gp_art='".$groupcode."') group by id,article_group,article order by article_group,article;"); } + + } ?> \ No newline at end of file diff --git a/public_html/qubeshop/lib/modules/ContratCadre.php b/public_html/qubeshop/lib/modules/ContratCadre.php index 5245d7f..73baf29 100644 --- a/public_html/qubeshop/lib/modules/ContratCadre.php +++ b/public_html/qubeshop/lib/modules/ContratCadre.php @@ -14,13 +14,13 @@ class ContratCadre{ public function getArticleGroups($idclient,$lang){ if (!$lang){ $lang=$this->cfg["lang"];} - return $this->dbh->queryarray("select id,article,gp_art,famille_art,coalesce(titre_".$lang.",titre_".$this->cfg["lang"].") as titre,coalesce(description_".$lang.",description_".$this->cfg["lang"].") as description,c01_label,c02_label,c03_label,c03_label,c04_label,c05_label,replace(image,' ','%20') as image from article_groups where article in ( + return $this->dbh->queryarray("select id,article,gp_art,famille_art,coalesce(titre_".$lang.",titre_".$this->cfg["lang"].") as titre,coalesce(description_".$lang.",description_".$this->cfg["lang"].") as description,c01_label,c02_label,c03_label,c03_label,c04_label,c05_label,replace(image,' ','%20') as image,fichetechnique,brochure,noticemontage from article_groups where article in ( select article_group from article_prices ap join articles a on (a.article=ap.article) where ap.cc_client=".$this->dbh->value($idclient).");"); } public function getArticles($idclient,$lang){ if (!$lang){ $lang=$this->cfg["lang"];} - return $this->dbh->querybykey('article_group',"select ar.id,ar.article_group,ar.article,ar.gp_art,ar.famille_art,ar.c01,ar.c02,ar.c03,ar.c04,ar.c05, null as prix_net,ar.unite_quantite,ar.qte_stock,ar.qte_commandee from article_prices ap join articles ar on (ar.article=ap.article) where ap.cc_client=".$this->dbh->value($idclient).";"); + return $this->dbh->querybykey('article_group',"select ar.id,ar.article_group,ar.article,ar.gp_art,ar.famille_art,ar.c01,ar.c02,ar.c03,ar.c04,ar.c05, null as prix_net,ar.unite_quantite,ar.qte_stock,ar.qte_commandee,ar.doc_ft,ar.doc_mo,ar.doc_fs from article_prices ap join articles ar on (ar.article=ap.article) where ap.cc_client=".$this->dbh->value($idclient).";"); } public function getClients(){ diff --git a/public_html/qubeshop/lib/session.php b/public_html/qubeshop/lib/session.php index a87b1d1..dff3c65 100644 --- a/public_html/qubeshop/lib/session.php +++ b/public_html/qubeshop/lib/session.php @@ -30,7 +30,7 @@ class session { $login = strtolower($login); $login=trim($login); - $sql = "select id from users where lower(useremail)=lower('".$this->dbh->securetext($login)."') and userpassword = '".$pwd."' and isenabled='1';"; + $sql = "select id from users where lower(useremail)=lower('".$this->dbh->securetext($login)."') and userpassword = '".$pwd."' and userpassword is not null and userpassword != '' and isenabled='1';"; $uid = $this->dbh->query($sql); //file_put_contents("session.log",print_r($uid,true)."\n".$sql,FILE_APPEND); diff --git a/public_html/qubeshop/tmpl/elements/shoptoolbar.html b/public_html/qubeshop/tmpl/elements/shoptoolbar.html index 5c01bce..c366995 100644 --- a/public_html/qubeshop/tmpl/elements/shoptoolbar.html +++ b/public_html/qubeshop/tmpl/elements/shoptoolbar.html @@ -2,12 +2,12 @@ - - + + - + {% if (session.usertype == 'admin') %} {# ' + '
'+ '
'+ - ''+ - ''+ - ''+ + ((agrps.data[g].brochure != null)?'':'')+ + ((agrps.data[g].fichetechnique != null)?'':'')+ + ((agrps.data[g].noticemontage != null)?'':'')+ '
'+ '
'+ ''; @@ -95,9 +95,9 @@ let contratcadre ={ ''; agrp += ''+ - ''+ - ''+ - ''+ + ''+((arts.data[agrps.data[g]['article']][x].doc_ft != null)?'':' ')+''+ + ''+((arts.data[agrps.data[g]['article']][x].doc_mo != null)?'':' ')+''+ + ''+((arts.data[agrps.data[g]['article']][x].doc_fs != null)?'':' ')+''+ ''; } } else { diff --git a/public_html/qubeshop/tmpl/js/shop.js b/public_html/qubeshop/tmpl/js/shop.js index 8a050ff..277278c 100644 --- a/public_html/qubeshop/tmpl/js/shop.js +++ b/public_html/qubeshop/tmpl/js/shop.js @@ -12,6 +12,7 @@ let shop= { tblgroups: null, basket:[], askprice:[], + favorites:[], selects: {}, init: function(){ flatpickr("#basket_prefereddeliverydate",{altInput: true, @@ -67,16 +68,16 @@ let shop= { loadProducts(){ let sel = shop.tblgroups.getSelectedData(); if (sel[0]){ - console.log("fam group sel",sel[0]); + //console.log("fam group sel",sel[0]); //console.log("selected",sel[0]); document.getElementById("articlehead").innerHTML=sel[0].catname+' - '+sel[0].groupname; postData({"cl":"Articles","fn":"getArticleGroups","groupcode":sel[0].group_code,"famillycode":sel[0].code_famille,"lang":"{{lang}}"}).then(agrps => { shop.article_groups = agrps.data; - console.log("Article Groups",agrps); + //console.log("Article Groups",agrps); document.getElementById("lst_articlegroups").innerHTML=''; postData({"cl":"Articles","fn":"getByFamillyAndGroups","famillycode":sel[0].code_famille,"groupcode":sel[0].group_code,"lang":"{{lang}}"}).then(arts => { - console.log("articles",arts); + //console.log("articles",arts); shop.articles = arts.data; for (var g=0;g< agrps.data.length;g++){ let agrp = '
'+ @@ -87,9 +88,9 @@ let shop= { '
' + '
'+ '
'+ - ''+ - ''+ - ''+ + ((agrps.data[g].brochure != null)?'':'')+ + ((agrps.data[g].fichetechnique != null)?'':'')+ + ((agrps.data[g].noticemontage != null)?'':'')+ '
'+ '
'+ ''; @@ -103,7 +104,7 @@ let shop= { if (/^Carton/.test(agrps.data[g]["c0"+i+"_label"])){ stf="c0"+i}; if (/^Longueur/.test(agrps.data[g]["c0"+i+"_label"])){ stf="c0"+i}; } - console.log("Step",stf); + //console.log("Step",stf); agrp += '
'+ ''+ ''+ @@ -114,13 +115,13 @@ let shop= { ''+ ''+ ''+ - ''+ + ''+ ''+ ''; - console.log("Article",agrps.data[g]['article']); + //console.log("Article",agrps.data[g]['article']); console.log("Groups articles",arts.data[agrps.data[g]['article']]); if (arts.data[agrps.data[g]['article']]){ - console.log("Article","Publi List"); + //console.log("Article","Publi List"); for (var x in arts.data[agrps.data[g]['article']]){ //console.log("xx",x); @@ -141,12 +142,13 @@ let shop= { ''+ '
'+ ((arts.data[agrps.data[g]['article']][x].unite_quantite)?arts.data[agrps.data[g]['article']][x].unite_quantite:' ')+'
'+ ''+ - ''+''; + '' + + ''+''; agrp += ''+ ''+ - ''+ - ''+ - ''+ + ''+ + ''+ + ''+ ''; } } else { @@ -276,6 +278,126 @@ let shop= { //document.getElementById("totalnet").innerHTML=ptotal.toFixed(2).replace(/\./,',') + " €"; return false; }, + articletofavorites: function(artidx,grpidx){ + console.log("grpidx",grpidx); + console.log("artidx",artidx); + let grparticle = shop.article_groups[grpidx].article; + let article = shop.articles[grparticle][artidx].article; + let artid = shop.articles[grparticle][artidx].id; + //console.log("Article",shop.articles[grparticle][artidx]); + //console.log("artidx",artidx); + + // let grpid = shop.article_groups[grpidx].id; + // let artid = shop.articles[artidx].id; + if (!shop.favorites[grparticle]){ + shop.favorites[grparticle] = shop.article_groups[grpidx]; + shop.favorites[grparticle]["articles"] = {}; + } + if (!shop.favorites[grparticle]["articles"][article]){ + shop.favorites[grparticle]["articles"][article] = shop.articles[grparticle][artidx]; + //shop.askprice[grparticle]["articles"][article]["quantity"] = 0; + } + // let qtoadd = parseInt(document.getElementById("art_" + artid).value); + // shop.askprice[grparticle]["articles"][article]["quantity"] = shop.basket[grparticle]["articles"][article]["quantity"] + qtoadd; + //console.log("shop basket",shop.basket); + console.log("price-list",shop.favorites); + shop.setFavorites(); + }, + setFavorites: function(){ + let bs = document.getElementById("lst_favorites"); + bs.innerHTML =''; + console.log("set Favorites"); + //let ptotal = 0; + //shop.askpriceitems = 0; + let bsr=''; + for (var g in shop.favorites){ + //console.log("basket article group",shop.basket[g]); + + bsr += '
'+ + '
'+ + '
image
'+ + '

'+ ((shop.favorites[g].titre)?shop.favorites[g].titre:' ')+'

'+ + '
' +((shop.favorites[g].description)?shop.favorites[g].description:' ') +'
'+ + '
' + + '
'+ + '
'+ + ''+ + ''+ + ''+ + '
'+ + '
'+ + '
'; + + + let stf=null; + for (var i=1;i<=5;i++){ + if (/^Sac/.test(shop.favorites[g]["c0"+i+"_label"])){ stf="c0"+i}; + if (/^Botte/.test(shop.favorites[g]["c0"+i+"_label"])){ stf="c0"+i}; + if (/^Roul/.test(shop.favorites[g]["c0"+i+"_label"])){ stf="c0"+i}; + if (/^Carton/.test(shop.favorites[g]["c0"+i+"_label"])){ stf="c0"+i}; + if (/^Longueur/.test(shop.favorites[g]["c0"+i+"_label"])){ stf="c0"+i}; + } + //console.log("Step",stf); + bsr += '
'+ + '
'+((agrps.data[g].c04_label != null)?agrps.data[g].c04_label:' ')+''+((agrps.data[g].c05_label != null)?agrps.data[g].c05_label:' ')+'StockQuantitéPrix unit.
(hTVA)
FTMOFSQuantitéPrix unit.
(hTVA)
FTMOFS
'+ ((arts.data[agrps.data[g]['article']][x].prix_brut)?arts.data[agrps.data[g]['article']][x].prix_net.replace(/\./,',')+ ' €':' ')+''+((arts.data[agrps.data[g]['article']][x].doc_ft != null)?'':' ')+''+((arts.data[agrps.data[g]['article']][x].doc_mo != null)?'':' ')+''+((arts.data[agrps.data[g]['article']][x].doc_fs != null)?'':' ')+'
'+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''; + //console.log("Article",shop.favorites[g]['article']); + //console.log("Groups articles",arts.data[shop.favorites[g]['article']]); + //shop.favorites[g] + //console.log("fav a",shop.favorites[g]["articles"]); + + //console.log("Article","Publi List"); + + for (var a in shop.favorites[g]['articles']){ + console.log("xx",a); + + + bsr += ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''; + } + + bsr += ''+ + '
 '+((shop.favorites[g].c01_label != null)?shop.favorites[g].c01_label:' ')+''+((shop.favorites[g].c02_label != null)?shop.favorites[g].c02_label:' ')+''+((shop.favorites[g].c03_label != null)?shop.favorites[g].c03_label:' ')+''+((shop.favorites[g].c04_label != null)?shop.favorites[g].c04_label:' ')+''+((shop.favorites[g].c05_label != null)?shop.favorites[g].c05_label:' ')+'StockQuantitéPrix unit.
(hTVA)
FTMOFS
'+ shop.favorites[g]['articles'][a].article +'
'+ ((shop.favorites[g]['articles'][a].c01)?shop.favorites[g]['articles'][a].c01:' ')+'
'+ ((shop.favorites[g]['articles'][a].c02)?shop.favorites[g]['articles'][a].c02:' ')+'
'+ ((shop.favorites[g]['articles'][a].c03)?shop.favorites[g]['articles'][a].c03:' ')+'
'+ ((shop.favorites[g]['articles'][a].c04)?shop.favorites[g]['articles'][a].c04:' ')+'
'+ ((shop.favorites[g]['articles'][a].c05)?shop.favorites[g]['articles'][a].c05:' ')+'
'+((shop.favorites[g]['articles'][a].qte_stock > 0)?'':'')+''; + + bsr+='
'+ + ''+ + '' + + ''+ + '
'+ ((shop.favorites[g]['articles'][a].unite_quantite)?shop.favorites[g]['articles'][a].unite_quantite:' ')+'
'+ + ''+ + '' + + ''+'
'; + bsr += '
'+ ((shop.favorites[g]['articles'][a].prix_net)?shop.favorites[g]['articles'][a].prix_net.replace(/\./,',')+ ' €':' ')+'
'+ + '
'+ + ''; + } + bs.insertAdjacentHTML('beforeend',bsr); + //document.getElementById("askpriceitems").innerHTML = shop.askpriceitems; + //document.getElementById("totalnet").innerHTML=ptotal.toFixed(2).replace(/\./,',') + " €"; + return false; + }, setBasket: function(){ let bs = document.getElementById("tblbody_basket"); bs.innerHTML =''; @@ -382,6 +504,19 @@ let shop= { shop.setAskPrice(); return false; }, + favoritesRemoveArticle: function(grpid,artid){ + delete(shop.favorites[grpid]["articles"][artid]); + //console.log("shop aricles",); + if (Object.keys(shop.favorites[grpid]["articles"]).length == 0){ + // let grelement2 = document.getElementById("basket_grouprow2_"+grpid); + // grelement2.parentNode.removeChild(grelement2); + // let grelement1 = document.getElementById("basket_grouprow_"+grpid); + // grelement1.parentNode.removeChild(grelement1); + delete(shop.favorites[grpid]); + } + shop.setFavorites(); + return false; + }, basketRecalcTotals: function(){ //let ptotal = 0; shop.basketitems = 0; @@ -436,7 +571,7 @@ let shop= { openpdf: function(pdfname){ var windowReference = window.open(); //postData("report.php",{"generate":repname,"data":data}).then (data => { - windowReference.location = 'img/Test_PDF.pdf'; + windowReference.location = 'media/'+ pdfname; //window.open(api + "file.php?open=" + encodeURIComponent(data.result.file)); //closedataloaddlg(); diff --git a/public_html/qubeshop/tmpl/module/index.html b/public_html/qubeshop/tmpl/module/index.html index fc5bc26..f0cbcef 100644 --- a/public_html/qubeshop/tmpl/module/index.html +++ b/public_html/qubeshop/tmpl/module/index.html @@ -33,4 +33,7 @@ + {{ include("elements/footer.html") }} \ No newline at end of file diff --git a/public_html/qubeshop/tmpl/panels/pnl_basket.html b/public_html/qubeshop/tmpl/panels/pnl_basket.html index 0343134..bd3f2f0 100644 --- a/public_html/qubeshop/tmpl/panels/pnl_basket.html +++ b/public_html/qubeshop/tmpl/panels/pnl_basket.html @@ -26,15 +26,23 @@
- - + +
-
+
+
+ + +
+
+ + +
diff --git a/public_html/qubeshop/tmpl/panels/pnl_favorites.html b/public_html/qubeshop/tmpl/panels/pnl_favorites.html new file mode 100644 index 0000000..9ec95db --- /dev/null +++ b/public_html/qubeshop/tmpl/panels/pnl_favorites.html @@ -0,0 +1,9 @@ +
+
+

Favorites

+
+
+ +
+ +
\ No newline at end of file