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`;
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();
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 = ();
$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";
+}
tblgroups: null,\r
basket:[],\r
askprice:[],\r
+ favorites:[],\r
selects: {},\r
init: function(){\r
flatpickr("#basket_prefereddeliverydate",{altInput: true,\r
loadProducts(){\r
let sel = shop.tblgroups.getSelectedData();\r
if (sel[0]){\r
- console.log("fam group sel",sel[0]);\r
+ //console.log("fam group sel",sel[0]);\r
//console.log("selected",sel[0]);\r
document.getElementById("articlehead").innerHTML=sel[0].catname+' - '+sel[0].groupname;\r
postData({"cl":"Articles","fn":"getArticleGroups","groupcode":sel[0].group_code,"famillycode":sel[0].code_famille,"lang":"{{lang}}"}).then(agrps => {\r
shop.article_groups = agrps.data;\r
- console.log("Article Groups",agrps);\r
+ //console.log("Article Groups",agrps);\r
document.getElementById("lst_articlegroups").innerHTML='';\r
\r
postData({"cl":"Articles","fn":"getByFamillyAndGroups","famillycode":sel[0].code_famille,"groupcode":sel[0].group_code,"lang":"{{lang}}"}).then(arts => {\r
- console.log("articles",arts);\r
+ //console.log("articles",arts);\r
shop.articles = arts.data;\r
for (var g=0;g< agrps.data.length;g++){\r
let agrp = '<div class="container margin padding border">'+\r
'</div>' +\r
'<div class="rest right">'+\r
'<div class="bar bar-block bg-qube" style="width: 200px;">'+\r
- '<button class="bar-item button text-white" style="text-align: right!important;" onclick="shop.openpdf(\'\');">Brochure pricipale <span class="icon icon-pdf"></span></button>'+\r
- '<button class="bar-item button text-white" style="text-align: right!important;" onclick="shop.openpdf(\'\');">Fiche technique <span class="icon icon-pdf"></span></button>'+\r
- '<button class="bar-item button text-white" style="text-align: right!important;" onclick="shop.openpdf(\'\');">Notice de montage <span class="icon icon-pdf"></span></button>'+\r
+ ((agrps.data[g].brochure != null)?'<button class="bar-item button text-white" style="text-align: right!important;" onclick="shop.openpdf(\''+agrps.data[g].brochure+ '\');">Brochure pricipale <span class="icon icon-pdf"></span></button>':'')+\r
+ ((agrps.data[g].fichetechnique != null)?'<button class="bar-item button text-white" style="text-align: right!important;" onclick="shop.openpdf(\''+agrps.data[g].fichetechnique+ '\');">Fiche technique <span class="icon icon-pdf"></span></button>':'')+\r
+ ((agrps.data[g].noticemontage != null)?'<button class="bar-item button text-white" style="text-align: right!important;" onclick="shop.openpdf(\''+agrps.data[g].noticemontage+ '\');">Notice de montage <span class="icon icon-pdf"></span></button>':'')+\r
'</div>'+\r
'</div>'+\r
'</div>';\r
if (/^Carton/.test(agrps.data[g]["c0"+i+"_label"])){ stf="c0"+i};\r
if (/^Longueur/.test(agrps.data[g]["c0"+i+"_label"])){ stf="c0"+i};\r
}\r
- console.log("Step",stf);\r
+ //console.log("Step",stf);\r
agrp += '<div class="container light-grey">'+\r
'<table style="width: 1400px;">'+\r
'<thead><tr>'+\r
'<th style="width: 105px;">'+((agrps.data[g].c04_label != null)?agrps.data[g].c04_label:' ')+'</th>'+\r
'<th style="width: 105px;">'+((agrps.data[g].c05_label != null)?agrps.data[g].c05_label:' ')+'</th>'+\r
'<th style="width: 50px;">Stock</th>'+\r
- '<th style="width: 380px;min-width: 380px;">Quantité</th><th style="width: 120px;">Prix unit.<br/>(hTVA)</th><th style="width: 46px;">FT</th><th style="width: 46px;">MO</th><th style="width: 46px;">FS</th>'+\r
+ '<th style="width: 400px;min-width: 400px;">Quantité</th><th style="width: 120px;">Prix unit.<br/>(hTVA)</th><th style="width: 46px;">FT</th><th style="width: 46px;">MO</th><th style="width: 46px;">FS</th>'+\r
'</tr></thead>'+\r
'<tbody>';\r
- console.log("Article",agrps.data[g]['article']);\r
+ //console.log("Article",agrps.data[g]['article']);\r
console.log("Groups articles",arts.data[agrps.data[g]['article']]);\r
if (arts.data[agrps.data[g]['article']]){\r
- console.log("Article","Publi List");\r
+ //console.log("Article","Publi List");\r
for (var x in arts.data[agrps.data[g]['article']]){\r
//console.log("xx",x);\r
\r
'<button class="bar-item button border bodybtn" onclick="shop.articlequantityplus(\''+arts.data[agrps.data[g]['article']][x].id+'\',\''+ ((stf)?arts.data[agrps.data[g]['article']][x][stf]:1)+'\');"><span class="icon icon-add"></span></button>'+\r
'<div class="bar-item">'+ ((arts.data[agrps.data[g]['article']][x].unite_quantite)?arts.data[agrps.data[g]['article']][x].unite_quantite:' ')+'</div>'+\r
'<button class="bar-item button bodybtn green" onclick="shop.articletobasket(\''+x+'\',\''+ g +'\');"><span class="icon icon-shop"></span></button>'+\r
- '<button class="bar-item button bodybtn bg-qube text-white" onclick="shop.articletoaskprice(\''+x+'\',\''+ g +'\');"><span class="icon icon-euro-tag"></span></button>'+'</div>';\r
+ '<button class="bar-item button bodybtn blue-grey text-white" onclick="shop.articletoaskprice(\''+x+'\',\''+ g +'\');"><span class="icon icon-euro-tag"></span></button>' +\r
+ '<button class="bar-item button bodybtn orange text-white" onclick="shop.articletofavorites(\''+x+'\',\''+ g +'\');"><span class="icon icon-star"></span></button>'+'</div>';\r
agrp += '</td>'+\r
'<td style="text-align: right;">'+ ((arts.data[agrps.data[g]['article']][x].prix_brut)?arts.data[agrps.data[g]['article']][x].prix_net.replace(/\./,',')+ ' €':' ')+'</td>'+\r
- '<td><button class="button bodybtn padding" onclick="shop.openpdf(\'\');"><span class="icon icon-pdf"></span></button></td>'+\r
- '<td><button class="button bodybtn padding" onclick="shop.openpdf(\'\');"><span class="icon icon-pdf"></span></button></td>'+\r
- '<td><button class="button bodybtn padding" onclick="shop.openpdf(\'\');"><span class="icon icon-pdf"></span></button></td>'+\r
+ '<td>'+((arts.data[agrps.data[g]['article']][x].doc_ft != null)?'<button class="button bodybtn padding" onclick="shop.openpdf(\''+arts.data[agrps.data[g]['article']][x].doc_ft+ '\');"><span class="icon icon-pdf"></span></button>':' ')+'</td>'+\r
+ '<td>'+((arts.data[agrps.data[g]['article']][x].doc_mo != null)?'<button class="button bodybtn padding" onclick="shop.openpdf(\''+arts.data[agrps.data[g]['article']][x].doc_mo+ '\');"><span class="icon icon-pdf"></span></button>':' ')+'</td>'+\r
+ '<td>'+((arts.data[agrps.data[g]['article']][x].doc_fs != null)?'<button class="button bodybtn padding" onclick="shop.openpdf(\''+arts.data[agrps.data[g]['article']][x].doc_fs+ '\');"><span class="icon icon-pdf"></span></button>':' ')+'</td>'+\r
'</tr>';\r
}\r
} else {\r
//document.getElementById("totalnet").innerHTML=ptotal.toFixed(2).replace(/\./,',') + " €";\r
return false;\r
},\r
+ articletofavorites: function(artidx,grpidx){\r
+ console.log("grpidx",grpidx);\r
+ console.log("artidx",artidx);\r
+ let grparticle = shop.article_groups[grpidx].article;\r
+ let article = shop.articles[grparticle][artidx].article;\r
+ let artid = shop.articles[grparticle][artidx].id;\r
+ //console.log("Article",shop.articles[grparticle][artidx]);\r
+ //console.log("artidx",artidx);\r
+ \r
+ // let grpid = shop.article_groups[grpidx].id;\r
+ // let artid = shop.articles[artidx].id;\r
+ if (!shop.favorites[grparticle]){\r
+ shop.favorites[grparticle] = shop.article_groups[grpidx];\r
+ shop.favorites[grparticle]["articles"] = {};\r
+ }\r
+ if (!shop.favorites[grparticle]["articles"][article]){\r
+ shop.favorites[grparticle]["articles"][article] = shop.articles[grparticle][artidx];\r
+ //shop.askprice[grparticle]["articles"][article]["quantity"] = 0; \r
+ }\r
+ // let qtoadd = parseInt(document.getElementById("art_" + artid).value);\r
+ // shop.askprice[grparticle]["articles"][article]["quantity"] = shop.basket[grparticle]["articles"][article]["quantity"] + qtoadd;\r
+ //console.log("shop basket",shop.basket);\r
+ console.log("price-list",shop.favorites);\r
+ shop.setFavorites();\r
+ },\r
+ setFavorites: function(){\r
+ let bs = document.getElementById("lst_favorites");\r
+ bs.innerHTML ='';\r
+ console.log("set Favorites");\r
+ //let ptotal = 0;\r
+ //shop.askpriceitems = 0;\r
+ let bsr='';\r
+ for (var g in shop.favorites){\r
+ //console.log("basket article group",shop.basket[g]);\r
+ \r
+ bsr += '<div class="container margin padding border">'+\r
+ '<div class="cell-row">'+\r
+ '<div class="quarter" style="padding-right: 20px; padding-bottom: 10px;" ><img src="'+ ((shop.favorites[g].image != null)?'img/'+shop.favorites[g].image:'img/qubenoimg.jpg')+ '" style="max-width: 175px;" alt="image"/></div>'+\r
+ '<div class="half"><h4>'+ ((shop.favorites[g].titre)?shop.favorites[g].titre:' ')+'</h4>'+\r
+ '<div style="margin-top: 20px;">' +((shop.favorites[g].description)?shop.favorites[g].description:' ') +'</div>'+\r
+ '</div>' +\r
+ '<div class="rest right">'+\r
+ '<div class="bar bar-block bg-qube" style="width: 200px;">'+\r
+ '<button class="bar-item button text-white" style="text-align: right!important;" onclick="shop.openpdf(\'\');">Brochure pricipale <span class="icon icon-pdf"></span></button>'+\r
+ '<button class="bar-item button text-white" style="text-align: right!important;" onclick="shop.openpdf(\'\');">Fiche technique <span class="icon icon-pdf"></span></button>'+\r
+ '<button class="bar-item button text-white" style="text-align: right!important;" onclick="shop.openpdf(\'\');">Notice de montage <span class="icon icon-pdf"></span></button>'+\r
+ '</div>'+\r
+ '</div>'+\r
+ '</div>';\r
+ \r
+ \r
+ let stf=null;\r
+ for (var i=1;i<=5;i++){\r
+ if (/^Sac/.test(shop.favorites[g]["c0"+i+"_label"])){ stf="c0"+i};\r
+ if (/^Botte/.test(shop.favorites[g]["c0"+i+"_label"])){ stf="c0"+i};\r
+ if (/^Roul/.test(shop.favorites[g]["c0"+i+"_label"])){ stf="c0"+i};\r
+ if (/^Carton/.test(shop.favorites[g]["c0"+i+"_label"])){ stf="c0"+i};\r
+ if (/^Longueur/.test(shop.favorites[g]["c0"+i+"_label"])){ stf="c0"+i};\r
+ }\r
+ //console.log("Step",stf);\r
+ bsr += '<div class="container light-grey">'+\r
+ '<table style="width: 1400px;">'+\r
+ '<thead><tr>'+\r
+ '<th style="width: 150px;"> </th>'+\r
+ '<th style="width: 105px;">'+((shop.favorites[g].c01_label != null)?shop.favorites[g].c01_label:' ')+'</th>'+\r
+ '<th style="width: 105px;">'+((shop.favorites[g].c02_label != null)?shop.favorites[g].c02_label:' ')+'</th>'+\r
+ '<th style="width: 105px;">'+((shop.favorites[g].c03_label != null)?shop.favorites[g].c03_label:' ')+'</th>'+\r
+ '<th style="width: 105px;">'+((shop.favorites[g].c04_label != null)?shop.favorites[g].c04_label:' ')+'</th>'+\r
+ '<th style="width: 105px;">'+((shop.favorites[g].c05_label != null)?shop.favorites[g].c05_label:' ')+'</th>'+\r
+ '<th style="width: 50px;">Stock</th>'+\r
+ '<th style="width: 400px;min-width: 400px;">Quantité</th><th style="width: 120px;">Prix unit.<br/>(hTVA)</th><th style="width: 46px;">FT</th><th style="width: 46px;">MO</th><th style="width: 46px;">FS</th>'+\r
+ '</tr></thead>'+\r
+ '<tbody>';\r
+ //console.log("Article",shop.favorites[g]['article']);\r
+ //console.log("Groups articles",arts.data[shop.favorites[g]['article']]);\r
+ //shop.favorites[g]\r
+ //console.log("fav a",shop.favorites[g]["articles"]);\r
+ \r
+ //console.log("Article","Publi List");\r
+\r
+ for (var a in shop.favorites[g]['articles']){\r
+ console.log("xx",a);\r
+ \r
+ \r
+ bsr += '<tr>'+\r
+ '<td class="articleno" >'+ shop.favorites[g]['articles'][a].article +'</td>'+\r
+ '<td><div class="white border">'+ ((shop.favorites[g]['articles'][a].c01)?shop.favorites[g]['articles'][a].c01:' ')+'</div></td>'+\r
+ '<td><div class="white border">'+ ((shop.favorites[g]['articles'][a].c02)?shop.favorites[g]['articles'][a].c02:' ')+'</div></td>'+\r
+ '<td><div class="white border">'+ ((shop.favorites[g]['articles'][a].c03)?shop.favorites[g]['articles'][a].c03:' ')+'</div></td>'+\r
+ '<td><div class="white border">'+ ((shop.favorites[g]['articles'][a].c04)?shop.favorites[g]['articles'][a].c04:' ')+'</div></td>'+\r
+ '<td><div class="white border">'+ ((shop.favorites[g]['articles'][a].c05)?shop.favorites[g]['articles'][a].c05:' ')+'</div></td>'+\r
+ '<td style="text-align: center;">'+((shop.favorites[g]['articles'][a].qte_stock > 0)?'<span class="icon icon-stock-ok text-green"></span>':'<span class="icon icon-nostock text-red"></span>')+'</td>'+\r
+ '<td>';\r
+ \r
+ bsr+='<div class="bar">'+\r
+ '<button class="bar-item button border bodybtn " onclick="shop.articlequantityminus(\''+shop.favorites[g]['articles'][a].id+'\',\''+ ((stf)?shop.favorites[g]['articles'][a][stf]:1)+'\');"><span class="icon icon-minus"></span></button>'+\r
+ '<input type="text" value="1" id="art_'+shop.favorites[g]['articles'][a].id+'" class="bar-item border quantity" onfocus="shop.setSelected(this);" onblur="shop.checkquantity(this);">' + \r
+ '<button class="bar-item button border bodybtn" onclick="shop.articlequantityplus(\''+shop.favorites[g]['articles'][a].id+'\',\''+ ((stf)?shop.favorites[g]['articles'][a][stf]:1)+'\');"><span class="icon icon-add"></span></button>'+\r
+ '<div class="bar-item">'+ ((shop.favorites[g]['articles'][a].unite_quantite)?shop.favorites[g]['articles'][a].unite_quantite:' ')+'</div>'+\r
+ '<button class="bar-item button bodybtn green" onclick="shop.articletobasket(\''+a+'\',\''+ g +'\');"><span class="icon icon-shop"></span></button>'+\r
+ '<button class="bar-item button bodybtn bg-qube text-white" onclick="shop.articletoaskprice(\''+a+'\',\''+ g +'\');"><span class="icon icon-euro-tag"></span></button>' +\r
+ '<button class="bar-item button bodybtn red" onclick="shop.favoritesRemoveArticle(\''+g+'\',\''+ a +'\');"><span class="icon icon-trash"></span></button>'+'</div>';\r
+ bsr += '</td>'+\r
+ '<td style="text-align: right;">'+ ((shop.favorites[g]['articles'][a].prix_net)?shop.favorites[g]['articles'][a].prix_net.replace(/\./,',')+ ' €':' ')+'</td>'+\r
+ '<td><button class="button bodybtn padding" onclick="shop.openpdf(\'\');"><span class="icon icon-pdf"></span></button></td>'+\r
+ '<td><button class="button bodybtn padding" onclick="shop.openpdf(\'\');"><span class="icon icon-pdf"></span></button></td>'+\r
+ '<td><button class="button bodybtn padding" onclick="shop.openpdf(\'\');"><span class="icon icon-pdf"></span></button></td>'+\r
+ '</tr>';\r
+ }\r
+ \r
+ bsr += '</tbody>'+\r
+ '</table>'+\r
+ '</div>'+\r
+ '</div>';\r
+ }\r
+ bs.insertAdjacentHTML('beforeend',bsr);\r
+ //document.getElementById("askpriceitems").innerHTML = shop.askpriceitems;\r
+ //document.getElementById("totalnet").innerHTML=ptotal.toFixed(2).replace(/\./,',') + " €";\r
+ return false;\r
+ },\r
setBasket: function(){\r
let bs = document.getElementById("tblbody_basket");\r
bs.innerHTML ='';\r
shop.setAskPrice();\r
return false;\r
},\r
+ favoritesRemoveArticle: function(grpid,artid){\r
+ delete(shop.favorites[grpid]["articles"][artid]);\r
+ //console.log("shop aricles",);\r
+ if (Object.keys(shop.favorites[grpid]["articles"]).length == 0){\r
+ // let grelement2 = document.getElementById("basket_grouprow2_"+grpid);\r
+ // grelement2.parentNode.removeChild(grelement2);\r
+ // let grelement1 = document.getElementById("basket_grouprow_"+grpid);\r
+ // grelement1.parentNode.removeChild(grelement1);\r
+ delete(shop.favorites[grpid]);\r
+ }\r
+ shop.setFavorites();\r
+ return false;\r
+ },\r
basketRecalcTotals: function(){\r
//let ptotal = 0;\r
shop.basketitems = 0;\r
openpdf: function(pdfname){\r
var windowReference = window.open();\r
//postData("report.php",{"generate":repname,"data":data}).then (data => {\r
- windowReference.location = 'img/Test_PDF.pdf';\r
+ windowReference.location = 'media/'+ pdfname;\r
//window.open(api + "file.php?open=" + encodeURIComponent(data.result.file));\r
\r
//closedataloaddlg();\r