[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/telephonie/script/tools/ -> update-contrat-contact.php (source)

   1  <?PHP
   2  /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   *
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   *
  18   * $Id: update-contrat-contact.php,v 1.1 2005/07/26 08:31:09 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/tools/update-contrat-contact.php,v $
  20   *
  21   * Mise à jours des contacts des contrats à partir des contacts des lignes
  22   * Script de migration de la nouvelle structure de la base
  23   *
  24   */
  25  
  26  require  ("../../master.inc.php");
  27  
  28  $contrats = array();
  29  
  30  $sql = "SELECT c.rowid, cc.rowid FROM llx_telephonie_contrat as c LEFT JOIN llx_telephonie_contrat_contact_facture as cc ON cc.fk_contrat = c.rowid WHERE cc.fk_contact is null";
  31  
  32  if ($db->query($sql))
  33  {
  34    $i = 0;
  35    $num = $db->num_rows();
  36  
  37    while ($i < $num)
  38      {
  39        $row = $db->fetch_row();
  40        $contrats[$i] = $row[0];
  41        $i++;
  42      }
  43  
  44    $db->free();
  45  }
  46  else
  47  {
  48    print "Errir";
  49  }
  50  
  51  dolibarr_syslog("Update contrats ".sizeof($contrats));
  52  
  53  for ($i = 0 ; $i < sizeof($contrats) ; $i++)
  54  {  
  55    $numc = 0;
  56  
  57    $sql = "SELECT distinct(c.fk_contact) FROM llx_telephonie_contact_facture as c, llx_telephonie_societe_ligne as l";
  58    $sql .= " WHERE l.rowid = c.fk_ligne";
  59    $sql .= " AND l.fk_contrat = ".$contrats[$i];
  60  
  61  
  62    if ($db->query($sql))
  63      {      
  64        $numc = $db->num_rows();
  65        
  66        if ($numc == 1)
  67      {
  68        $obc = $db->fetch_object();      
  69        $idcon = $obc->fk_contact;
  70      }
  71        $db->free();
  72      }
  73    else
  74      {
  75        print "Erreur";
  76      }
  77  
  78    if ($numc == 1)
  79      {
  80        $sql = "INSERT INTO llx_telephonie_contrat_contact_facture";
  81        $sql .= " (fk_contrat, fk_contact) ";
  82        $sql .= " VALUES (".$contrats[$i].",".$idcon.")";
  83        
  84        if (!$db->query($sql))
  85      {
  86        dolibarr_syslog("Erreur ");
  87      }
  88        else
  89      {
  90        dolibarr_syslog("Update contrat ".$contrats[$i]);
  91      }
  92      }
  93    else
  94      {
  95  
  96        if ($numc > 0)
  97      {
  98        print "$contrats[$i] $numc\n";
  99        print $sql."\n" ;
 100      }
 101      }
 102  }
 103  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics