<commit_before><?php

class exportSocieteTask extends sfBaseTask
{
  protected function configure()
  {
    // // add your own arguments here
    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'declaration'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'default'),
      // add your own options here
    ));

    $this->namespace        = 'export';
    $this->name             = 'societe';
    $this->briefDescription = '';
    $this->detailedDescription = <<<EOF
The [testFacture|INFO] task does things.
Call it with:

    [php symfony export:societe|INFO]
EOF;
  }

  const ISCLIENT = 1;
  const ISFOURNISSEUR = 2;

  private function printSociete($societe, $compte, $isclient = 1) {
    print $compte.";";
    print $societe->raison_sociale.";";
    if ($isclient == self::ISCLIENT) {
      print "CLIENT;";
    }else{
      print "FOURNISSEUR;";
    }
    print $societe->raison_sociale_abregee.";";
    print preg_replace('/;.*/', '', $societe->getSiegeAdresses()).";";
    if (preg_match('/;/', $societe->getSiegeAdresses())) {
        print str_replace(';', '-', preg_replace('/.*;/', '', $societe->getSiegeAdresses()));
    }
    print ";";
    print $societe->siege->code_postal.";";
    print $societe->siege->commune.";";
    print "France;";
    print ";"; //NAF
    print $societe->no_tva_intracommunautaire.";";
    print $societe->siret.";";
    print $societe->statut.";";
    print $societe->date_modification.";";
    print preg_replace('/[^\+0-9]/i', '', $societe->telephone).";"; 
    print preg_replace('/[^\+0-9]/i', '', $societe->fax).";"; 
    print $societe->email.";";
    print $this->routing->generate('societe_visualisation', $societe, true).';';
#    print "http://10.0.2.195/societe/".$societe->identifiant."/visualisation;";
    try {
      if ($isclient == self::ISCLIENT) {
	print $societe->getRegionViticole(false);
      }
    }catch(sfException $e) {
      print "INCONNUE";
    }
    print ";\n";
  }

  protected function execute($arguments = array(), $options = array())
  {
    // initialize the database connection
    $databaseManager = new sfDatabaseManager($this->configuration);
    $connection = $databaseManager->getDatabase($options['connection'])->getConnection();

    $this->routing = clone ProjectConfiguration::getAppRouting();

    echo "numéro de compte;intitulé;type (client/fournisseur);abrégé;adresse;address complément;code postal;ville;pays;code NAF;n° identifiant;n° siret;mise en sommeil;date de création;téléphone;fax;email;site;Région viticole;\n";

    foreach(SocieteAllView::getInstance()->findByInterpro('INTERPRO-declaration') as $socdata) {
      $soc = SocieteClient::getInstance()->find($socdata->id);
      if (!$soc->code_comptable_client && ! $soc->code_comptable_fournisseur) 
	continue;
      if ($soc->code_comptable_client) {
	$this->printSociete($soc, $soc->code_comptable_client, self::ISCLIENT);<commit_msg>Export des seules sociétés actives par défaut<commit_after><?php

class exportSocieteTask extends sfBaseTask
{
  protected function configure()
  {
    // // add your own arguments here
    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'declaration'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'default'),
      new sfCommandOption('all', null, sfCommandOption::PARAMETER_OPTIONAL, 'Display all societé (suspendu included)', ''),
      // add your own options here
    ));

    $this->namespace        = 'export';
    $this->name             = 'societe';
    $this->briefDescription = '';
    $this->detailedDescription = <<<EOF
The [testFacture|INFO] task does things.
Call it with:

    [php symfony export:societe|INFO]
EOF;
  }

  const ISCLIENT = 1;
  const ISFOURNISSEUR = 2;

  private function printSociete($societe, $compte, $isclient = 1) {
    if (!$this->includeSuspendu && !$societe->isActif()) {
	return ;
    }
    print $compte.";";
    print $societe->raison_sociale.";";
    if ($isclient == self::ISCLIENT) {
      print "CLIENT;";
    }else{
      print "FOURNISSEUR;";
    }
    print $societe->raison_sociale_abregee.";";
    print preg_replace('/;.*/', '', $societe->getSiegeAdresses()).";";
    if (preg_match('/;/', $societe->getSiegeAdresses())) {
        print str_replace(';', '-', preg_replace('/.*;/', '', $societe->getSiegeAdresses()));
    }
    print ";";
    print $societe->siege->code_postal.";";
    print $societe->siege->commune.";";
    print "France;";
    print ";"; //NAF
    print $societe->no_tva_intracommunautaire.";";
    print $societe->siret.";";
    print $societe->statut.";";
    print $societe->date_modification.";";
    print preg_replace('/[^\+0-9]/i', '', $societe->telephone).";"; 
    print preg_replace('/[^\+0-9]/i', '', $societe->fax).";"; 
    print $societe->email.";";
    print $this->routing->generate('societe_visualisation', $societe, true).';';
    try {
      if ($isclient == self::ISCLIENT) {
	print $societe->getRegionViticole(false).';';
      }
    }catch(sfException $e) {
      print "INCONNUE;";
    }
    print $societe->isActif().';';
    print "\n";
  }

  protected function execute($arguments = array(), $options = array())
  {
    // initialize the database connection
    $databaseManager = new sfDatabaseManager($this->configuration);
    $connection = $databaseManager->getDatabase($options['connection'])->getConnection();

    $this->includeSuspendu = false;
    if (isset($options['all']) && $options['all']) {
	$this->includeSuspendu = true;
    }

    $this->routing = clone ProjectConfiguration::getAppRouting();

    echo "numéro de compte;intitulé;type (client/fournisseur);abrégé;adresse;address complément;code postal;ville;pays;code NAF;n° identifiant;n° siret;mise en sommeil;date de création;téléphone;fax;email;site;Région viticole;Actif;\n";

    foreach(SocieteAllView::getInstance()->findByInterpro('INTERPRO-declaration') as $socdata) {
      $soc = SocieteClient::getInstance()->find($socdata->id);
      if (!$soc->code_comptable_client && ! $soc->code_comptable_fournisseur) 
	continue;
      if ($soc->code_comptable_client) {
	$this->printSociete($soc, $soc->code_comptable_client, self::ISCLIENT);
{'fraction_non_alphanumeric': 0.1777441332323997, 'fraction_numerical': 0.0031794095382286147, 'mean_word_length': 4.058192955589586, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7591423', 'n_tokens_mistral': 2229, 'n_tokens_neox': 2220, 'n_words': 399}