<commit_before><?php
/**
 * Model for Vrac
 *
 */

class Vrac extends BaseVrac {

    protected $archivage_document = null;

    public function  __construct() {
        parent::__construct();   
        $this->initDocuments();
    }

    public function __clone() {
        parent::__clone();
        $this->initDocuments();
    }   

    protected function initDocuments() {
        $this->archivage_document = new ArchivageDocument($this);
    }
    
    public function constructId() {
        $this->set('_id', 'VRAC-'.$this->numero_contrat);

        if(!$this->date_signature) {
            $this->date_signature = date('d/m/Y');
        }
        
        if(!$this->date_campagne) {
            $this->date_campagne = date('d/m/Y');
        }
    }

    public function getCampagne() {

        return $this->_get('campagne');
    } 

    public function setNumeroContrat($value) {
        $this->_set('numero_contrat', $value);
    }

    public function setProduit($value) {
        $this->_set('produit', $value);
        $this->produit_libelle = $this->getProduitObject()->getLibelleFormat(array(), "%g% %a% %m% %l% %co% %ce%");
    }
    
    public function setBouteillesContenanceLibelle($c) {
        $this->_set('bouteilles_contenance_libelle', $c);
        if ($c) {
            $this->setBouteillesContenanceVolume(VracClient::$contenance[$c]);
        }
    }

    public function update($params = array()) {
        
        $this->prix_total = null;
        switch ($this->type_transaction)
        {
            case 'raisins' :
            {
                $this->prix_total = $this->raisin_quantite * $this->prix_unitaire;
                $this->bouteilles_contenance_libelle = null;
                $this->bouteilles_contenance_volume = null;
                $this->volume_propose = ( $this->raisin_quantite / $this->getDensite() ) / 100.0;
                break;
            }
            case 'vin_bouteille' :
            {
                $this->prix_total = $this->bouteilles_quantite * $this->prix_unitaire;
                $this->volume_propose = $this->bouteilles_quantite * $this->bouteilles_contenance_volume;
                break;
            }
            
            case 'mouts' :
            case 'vin_vrac' :
            {
                $this->prix_total = $this->jus_quantite * $this->prix_unitaire;              
                $this->bouteilles_contenance_libelle = '';
                $this->bouteilles_contenance_volume = null;
                $this->volume_propose = $this->jus_quantite;
                break;
            }              
        }
        if(isset($this->volume_propose) && $this->volume_propose!=0) $this->prix_hl = $this->prix_total/$this->volume_propose;
    }

    public function setInformations() 
    {        
        $this->setAcheteurInformations();
        $this->setVendeurInformations();
        if($this->mandataire_identifiant!=null && $this->mandataire_exist)
        {
            $this->setMandataireInformations();
            
        }
    }

    private function setAcheteurInformations() 
    {
        $acheteurObj = $this->getAcheteurObject();
        $this->acheteur->nom = $acheteurObj->nom;
        $this->acheteur->cvi = $acheteurObj->cvi;
        $this->acheteur->commune = $acheteurObj->siege->commune;
        $this->acheteur->code_postal = $acheteurObj->siege->code_postal;
    }
    
    private function setMandataireInformations() 
    {
        $mandataireObj = $this->getMandataireObject();
        $this->mandataire->nom = $mandataireObj->nom;
        //TODO : surement à changer
        $this->mandataire->carte_pro = $mandataireObj->identifiant;
        $this->mandataire->adresse = $mandataireObj->siege->commune.'  '.$mandataireObj->siege->code_postal;
    }
    
    private function setVendeurInformations() 
    {
        $vendeurObj = $this->getVendeurObject();
        $this->vendeur->nom = $vendeurObj->nom;
        $this->vendeur->cvi = $vendeurObj->cvi;
        $this->vendeur->commune = $vendeurObj->siege->commune;
        $this->vendeur->code_postal = $vendeurObj->siege->code_postal;       
    }

    public function setDate($attribut, $d) {
        if (preg_match('/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/', $d, $m)) {<commit_msg>Veille à ce que les identifiants des partis ne soit pas précédé de ETABLISSEMENT-<commit_after><?php
/**
 * Model for Vrac
 *
 */

class Vrac extends BaseVrac {

    protected $archivage_document = null;

    public function  __construct() {
        parent::__construct();   
        $this->initDocuments();
    }

    public function __clone() {
        parent::__clone();
        $this->initDocuments();
    }   

    protected function initDocuments() {
        $this->archivage_document = new ArchivageDocument($this);
    }
    
    public function constructId() {
        $this->set('_id', 'VRAC-'.$this->numero_contrat);

        if(!$this->date_signature) {
            $this->date_signature = date('d/m/Y');
        }
        
        if(!$this->date_campagne) {
            $this->date_campagne = date('d/m/Y');
        }
    }

    public function getCampagne() {

        return $this->_get('campagne');
    } 

    public function setNumeroContrat($value) {
        $this->_set('numero_contrat', $value);
    }

    public function setProduit($value) {
        $this->_set('produit', $value);
        $this->produit_libelle = $this->getProduitObject()->getLibelleFormat(array(), "%g% %a% %m% %l% %co% %ce%");
    }
    
    public function setBouteillesContenanceLibelle($c) {
        $this->_set('bouteilles_contenance_libelle', $c);
        if ($c) {
            $this->setBouteillesContenanceVolume(VracClient::$contenance[$c]);
        }
    }

    public function update($params = array()) {
        
        $this->prix_total = null;
        switch ($this->type_transaction)
        {
            case 'raisins' :
            {
                $this->prix_total = $this->raisin_quantite * $this->prix_unitaire;
                $this->bouteilles_contenance_libelle = null;
                $this->bouteilles_contenance_volume = null;
                $this->volume_propose = ( $this->raisin_quantite / $this->getDensite() ) / 100.0;
                break;
            }
            case 'vin_bouteille' :
            {
                $this->prix_total = $this->bouteilles_quantite * $this->prix_unitaire;
                $this->volume_propose = $this->bouteilles_quantite * $this->bouteilles_contenance_volume;
                break;
            }
            
            case 'mouts' :
            case 'vin_vrac' :
            {
                $this->prix_total = $this->jus_quantite * $this->prix_unitaire;              
                $this->bouteilles_contenance_libelle = '';
                $this->bouteilles_contenance_volume = null;
                $this->volume_propose = $this->jus_quantite;
                break;
            }              
        }
        if(isset($this->volume_propose) && $this->volume_propose!=0) $this->prix_hl = $this->prix_total/$this->volume_propose;
    }

    public function setInformations() 
    {        
        $this->setAcheteurInformations();
        $this->setVendeurInformations();
        if($this->mandataire_identifiant!=null && $this->mandataire_exist)
        {
            $this->setMandataireInformations();
            
        }
    }

    public function setVendeurIdentifiant($s) {
	return $this->_set('vendeur_identifiant', str_replace('ETABLISSEMENT-', '', $s));
    }

    public function setAcheteurIdentifiant($s) {
        return $this->_set('acheteur_identifiant', str_replace('ETABLISSEMENT-', '', $s));
    }

    public function setMandataireIdentifiant($s) {
        return $this->_set('mandataire_identifiant', str_replace('ETABLISSEMENT-', '', $s));
    }



    private function setAcheteurInformations() 
    {
        $acheteurObj = $this->getAcheteurObject();
        $this->acheteur->nom = $acheteurObj->nom;
        $this->acheteur->cvi = $acheteurObj->cvi;
        $this->acheteur->commune = $acheteurObj->siege->commune;
        $this->acheteur->code_postal = $acheteurObj->siege->code_postal;
    }
    
    private function setMandataireInformations() 
    {
        $mandataireObj = $this->getMandataireObject();
        $this->mandataire->nom = $mandataireObj->nom;
        //TODO : surement à changer
        $this->mandataire->carte_pro = $mandataireObj->identifiant;
        $this->mandataire->adresse = $mandataireObj->siege->commune.'  '.$mandataireObj->siege->code_postal;
    }
    
    private function setVendeurInformations() 
    {
        $vendeurObj = $this->getVendeurObject();
        $this->vendeur->nom = $vendeurObj->nom;
        $this->vendeur->cvi = $vendeurObj->cvi;
        $this->vendeur->commune = $vendeurObj->siege->commune;
        $this->vendeur->code_postal = $vendeurObj->siege->code_postal;       
    }

    public function setDate($attribut, $d) {
        if (preg_match('/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/', $d, $m)) {
{'fraction_non_alphanumeric': 0.1486366659277322, 'fraction_numerical': 0.0031035247173575703, 'mean_word_length': 2.1715289982425308, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 192, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1438042', 'n_tokens_mistral': 3010, 'n_tokens_neox': 2928, 'n_words': 384}