[ 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/compta/export/modules/ -> compta.export.poivre.class.php (source)

   1  <?PHP
   2  /* Copyright (C) 2004 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: compta.export.poivre.class.php,v 1.15 2005/07/10 21:00:55 eldy Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/export/modules/compta.export.poivre.class.php,v $
  20   */
  21  
  22  require_once DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_workbook.inc.php";
  23  require_once DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_worksheet.inc.php";
  24  
  25  
  26  
  27  class ComptaExportPoivre extends ComptaExport
  28  {
  29      var $db;
  30      var $user;
  31  
  32  
  33      function ComptaExportPoivre ($DB, $USER)
  34      {
  35          $this->db = $DB;
  36          $this->user = $USER;
  37      }
  38  
  39      /**
  40       * Agrégation des lignes de facture
  41       */
  42      function Agregate($line_in)
  43      {
  44          dolibarr_syslog("ComptaExportPoivre::Agregate");
  45          dolibarr_syslog("ComptaExportPoivre::Agregate " . sizeof($line_in) . " lignes en entrées");
  46          $i = 0;
  47          $j = 0;
  48          $n = sizeof($line_in);
  49  
  50          // On commence par la ligne 0
  51  
  52          $this->line_out[$j] = $line_in[$i];
  53  
  54          //print "$j ".$this->line_out[$j][8] . "<br>";
  55  
  56          for ( $i = 1 ; $i < $n ; $i++)
  57          {
  58              // On agrège les lignes avec le même code comptable
  59  
  60              if ( ($line_in[$i][1] == $line_in[$i-1][1]) && ($line_in[$i][4] == $line_in[$i-1][4]) )
  61              {
  62                  $this->line_out[$j][8] = ($this->line_out[$j][8] + $line_in[$i][8]);
  63              }
  64              else
  65              {
  66                  $j++;
  67                  $this->line_out[$j] = $line_in[$i];
  68              }
  69  
  70              //    print "$j ".$this->line_out[$j][8] . "<br>";
  71  
  72          }
  73  
  74          dolibarr_syslog("ComptaExportPoivre::Agregate " . sizeof($this->line_out) . " lignes en sorties");
  75  
  76          return 0;
  77      }
  78  
  79      /*
  80       *
  81       */
  82      function Export($linec, $linep, $id=0)
  83      {
  84          $error = 0;
  85  
  86          dolibarr_syslog("ComptaExportPoivre::Export");
  87          dolibarr_syslog("ComptaExportPoivre::Export " . sizeof($linec) . " lignes en entrées");
  88  
  89          $this->Agregate($linec);
  90  
  91          $this->db->begin();
  92  
  93          if ($id == 0)
  94          {
  95              $dt = strftime('EC%y%m', time());
  96  
  97              $sql = "SELECT count(ref) FROM ".MAIN_DB_PREFIX."export_compta";
  98              $sql .= " WHERE ref like '$dt%'";
  99  
 100              if ($this->db->query($sql))
 101              {
 102                  $row = $this->db->fetch_row();
 103                  $cc = $row[0];
 104              }
 105              else
 106              {
 107                  $error++;
 108                  dolibarr_syslog("ComptaExportPoivre::Export Erreur Select");
 109              }
 110  
 111  
 112              if (!$error)
 113              {
 114                  $this->ref = $dt . substr("000".$cc, -2);
 115  
 116                  $sql = "INSERT INTO ".MAIN_DB_PREFIX."export_compta (ref, date_export, fk_user)";
 117                  $sql .= " VALUES ('".$this->ref."', now(),".$this->user->id.")";
 118  
 119                  if ($this->db->query($sql))
 120                  {
 121                      $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."export_compta");
 122                  }
 123                  else
 124                  {
 125                      $error++;
 126                      dolibarr_syslog("ComptaExportPoivre::Export Erreur INSERT");
 127                  }
 128              }
 129          }
 130          else
 131          {
 132              $this->id = $id;
 133  
 134              $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."export_compta";
 135              $sql .= " WHERE rowid = ".$this->id;
 136  
 137              $resql = $this->db->query($sql);
 138  
 139              if ($resql)
 140              {
 141                  $row = $this->db->fetch_row($resql);
 142                  $this->ref = $row[0];
 143              }
 144              else
 145              {
 146                  $error++;
 147                  dolibarr_syslog("ComptaExportPoivre::Export Erreur Select");
 148              }
 149          }
 150  
 151  
 152          if (!$error)
 153          {
 154              dolibarr_syslog("ComptaExportPoivre::Export ref : ".$this->ref);
 155  
 156              $fxname = DOL_DATA_ROOT."/compta/export/".$this->ref.".xls";
 157  
 158              $workbook = &new writeexcel_workbook($fxname);
 159  
 160              $page = &$workbook->addworksheet('Export');
 161  
 162              $page->set_column(0,0,8); // A
 163              $page->set_column(1,1,6); // B
 164              $page->set_column(2,2,9); // C
 165              $page->set_column(3,3,14); // D
 166              $page->set_column(4,4,44); // E
 167              $page->set_column(5,5,9); // F Numéro de pièce
 168              $page->set_column(6,6,8); // G
 169  
 170  
 171              // Pour les factures
 172  
 173              //A 0 Date Opération 040604 pour 4 juin 2004
 174              //B 1 VE -> ventilation
 175              //C 2 code Compte général
 176              //D 3 code client
 177              //E 4 Intitul
 178              //F 5 Numéro de pièce
 179              //G 6 Date d'échéance, = à la date d'opération si pas d'échéance
 180              //H 7 Montant
 181              //I 8 Type opération D pour Débit ou C pour Crédit
 182              //J 9 EUR pour Monnaie en Euros
 183  
 184              // Pour les paiements
 185  
 186              $i = 0;
 187              $j = 0;
 188              $n = sizeof($this->line_out);
 189  
 190              $oldfacture = 0;
 191  
 192              for ( $i = 0 ; $i < $n ; $i++)
 193              {
 194                  if ( $oldfacture <> $this->line_out[$i][1])
 195                  {
 196                      // Ligne client
 197                      $page->write_string($j, 0, strftime("%d%m%y",$this->line_out[$i][0]));
 198                      $page->write_string($j, 1,  "VI");
 199                      $page->write_string($j, 2,  "41100000");
 200                      $page->write_string($j, 3, stripslashes($this->line_out[$i][2]));
 201                      $page->write_string($j, 4, stripslashes($this->line_out[$i][3])." Facture");
 202                      $page->write_string($j, 5, $this->line_out[$i][5]); // Numéro de factur
 203                      $page->write($j, 6, ereg_replace(",",".",$this->line_out[$i][7]));
 204                      $page->write_string($j, 7, 'D' ); // D pour débit
 205                      $page->write_string($j, 8, strftime("%d%m%y",$this->line_out[$i][0]));
 206  
 207                      $j++;
 208  
 209                      // Ligne TVA
 210                      $page->write_string($j, 0, strftime("%d%m%y",$this->line_out[$i][0]));
 211                      $page->write_string($j, 1, "VI");
 212                      $page->write_string($j, 2, '4457119');
 213  
 214                      $page->write_string($j, 4, stripslashes($this->line_out[$i][3])." Facture");
 215                      $page->write_string($j, 5, $this->line_out[$i][5]); // Numéro de facture
 216                      $page->write($j, 6, ereg_replace(",",".",$this->line_out[$i][6])); // Montant de TVA
 217                      $page->write_string($j, 7, 'C'); // C pour crédit
 218                      $page->write_string($j, 8, strftime("%d%m%y",$this->line_out[$i][0]));
 219  
 220  
 221                      $oldfacture = $this->line_out[$i][1];
 222                      $j++;
 223                  }
 224  
 225                  $page->write_string($j, 0, strftime("%d%m%y",$this->line_out[$i][0]));
 226                  $page->write_string($j, 1, 'VI');
 227                  $page->write_string($j, 2, $this->line_out[$i][4]); // Code Comptable
 228                  $page->write_string($j, 4, $this->line_out[$i][3]." Facture");
 229                  $page->write_string($j, 5, $this->line_out[$i][5]);
 230                  $page->write($j, 6, ereg_replace(",",".",round($this->line_out[$i][8], 2)));
 231                  $page->write_string($j, 7, 'C');                     // C pour crédit
 232                  $page->write_string($j, 8, strftime("%d%m%y",$this->line_out[$i][0]));
 233  
 234                  $j++;
 235              }
 236  
 237              // Tag des lignes de factures
 238              $n = sizeof($linec);
 239              for ( $i = 0 ; $i < $n ; $i++)
 240              {
 241                  $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet";
 242                  $sql .= " SET fk_export_compta=".$this->id;
 243                  $sql .= " WHERE rowid = ".$linec[$i][10];
 244  
 245                  if (!$this->db->query($sql))
 246                  {
 247                      $error++;
 248                  }
 249              }
 250  
 251              // Pour les paiements
 252  
 253              // Date Opération 040604 pour 4 juin 2004
 254              // CE -> caisse d'epargne
 255              // code Compte général
 256              // code client
 257              // Intitul
 258              // Numéro de pièce
 259              // Montant
 260              // Type opération D pour Débit ou C pour Crédit
 261              // Date d'échéance, = à la date d'opération si pas d'échéance
 262              // EUR pour Monnaie en Euros
 263  
 264              $i = 0;
 265              //$j = 0;
 266              $n = sizeof($linep);
 267  
 268              $oldfacture = 0;
 269  
 270              for ( $i = 0 ; $i < $n ; $i++)
 271              {
 272                  /*
 273                  * En cas de rejet ou paiement en négatif on inverse debit et credit
 274                  *
 275                  *
 276                  */
 277                  if ($linep[$i][5] >= 0)
 278                  {
 279                      $debit = "D";
 280                      $credit = "C";
 281                  }
 282                  else
 283                  {
 284                      $debit = "C";
 285                      $credit = "D";
 286  
 287                      if ($linep[$i][6] == 'Prélèvement')
 288                      {
 289                          $linep[$i][6] = 'Rejet Prelevement';
 290                      }
 291  
 292                  }
 293  
 294                  $page->write_string($j,0, strftime("%d%m%y",$linep[$i][0]));
 295                  $page->write_string($j,1, 'CE');
 296  
 297                  $page->write_string($j,2, '5122000');
 298  
 299                  if ($linep[$i][6] == 'Prélèvement')
 300                  {
 301                      $linep[$i][6] = 'Prelevement';
 302                  }
 303  
 304                  $page->write_string($j,4, stripslashes($linep[$i][3])." ".stripslashes($linep[$i][6])); //
 305                  $page->write_string($j,5, $linep[$i][7]);                  // Numéro de facture
 306  
 307                  $page->write($j,6, ereg_replace(",",".",round(abs($linep[$i][5]), 2)));  // Montant de la ligne
 308                  $page->write_string($j,7,$debit);
 309                  $page->write_string($j,8, strftime("%d%m%y",$linep[$i][0]));
 310  
 311  
 312                  $j++;
 313  
 314                  $page->write_string($j,0, strftime("%d%m%y",$linep[$i][0]));
 315                  $page->write_string($j,1, 'CE');
 316  
 317                  $page->write_string($j,2, '41100000');
 318                  $page->write_string($j,3, $linep[$i][2]);
 319                  $page->write_string($j,4, stripslashes($linep[$i][3])." ".stripslashes($linep[$i][6])); //
 320                  $page->write_string($j,5, $linep[$i][7]);     // Numéro de facture
 321                  $page->write($j,6, ereg_replace(",",".",round(abs($linep[$i][5]), 2)));  // Montant de la ligne
 322                  $page->write_string($j,7, $credit);
 323                  $page->write_string($j,8, strftime("%d%m%y",$linep[$i][0]));
 324  
 325                  $j++;
 326  
 327              }
 328              $workbook->close();
 329  
 330              // Tag des lignes de factures
 331              $n = sizeof($linep);
 332              for ( $i = 0 ; $i < $n ; $i++)
 333  
 334              {
 335                  $sql = "UPDATE ".MAIN_DB_PREFIX."paiement";
 336                  $sql .= " SET fk_export_compta=".$this->id;
 337                  $sql .= " WHERE rowid = ".$linep[$i][1];
 338  
 339                  if (!$this->db->query($sql))
 340                  {
 341                      $error++;
 342                  }
 343              }
 344  
 345          }
 346  
 347          if (!$error)
 348          {
 349              $this->db->commit();
 350              dolibarr_syslog("ComptaExportPoivre::Export COMMIT");
 351          }
 352          else
 353          {
 354              $this->db->rollback();
 355              dolibarr_syslog("ComptaExportPoivre::Export ROLLBACK");
 356          }
 357  
 358          return 0;
 359      }
 360  }


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