<commit_before><?php

class DRevProduit extends BaseDRevProduit
{
	public function getConfig()
	{
		return $this->getCouchdbDocument()->getConfiguration()->get($this->getProduitHash());
	}

	public function getLibelle() {
		if(!$this->_get('libelle')) {
			$this->libelle = $this->getConfig()->getLibelleComplet();
			if($this->denomination_complementaire) {
				$this->libelle .= ' '.$this->denomination_complementaire;
			}
		}

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

	public function getLibelleComplet()
	{

		return $this->getLibelle();
	}

	public function getChildrenNode()
    {
        return $this->getCepages();
    }

    public function getProduitHash() {
			return $this->getParent()->getHash();
    }

    public function getTotalTotalSuperficie()
    {

		return $this->superficie_revendique + (($this->canHaveVtsgn()) ? $this->superficie_revendique_vtsgn : 0);
    }

    public function getTotalVolumeRevendique()
    {

		return $this->volume_revendique_total + (($this->canHaveVtsgn()) ? $this->volume_revendique_vtsgn : 0);
    }

	public function getTotalVciUtilise() {

		return $this->vci->complement + $this->vci->substitution + $this->vci->rafraichi + $this->vci->destruction;
	}

	public function getPlafondStockVci() {

		return $this->recolte->superficie_total * $this->getConfig()->rendement_vci_total;
	}

	public function canHaveVtsgn() {

		return false;
	}

	public function hasVci($saisie = false) {
		if ($saisie) {
			return ($this->vci->stock_precedent || $this->vci->destruction || $this->vci->complement || $this->vci->substitution || $this->vci->rafraichi || $this->vci->constitue  || $this->vci->ajustement);
		}
		return ($this->vci->stock_precedent !== null || $this->vci->destruction !== null || $this->vci->complement !== null || $this->vci->substitution !== null || $this->vci->rafraichi !== null || $this->vci->constitue !== null || $this->vci->ajustement !== null);
	}

	public function hasVciDetruit() {
		return ($this->vci->destruction && $this->vci->destruction > 0)? true : false;
	}

    public function isActive()
    {

		return true;
    }

    public function isCleanable() {

        if(!$this->isActive()) {

            return true;
        }
		if ($this->recolte->superficie_total === null && $this->recolte->volume_total === null && $this->superficie_revendique === null && $this->volume_revendique_total === null ) {
			return true;
		}

        return false;
    }

	public function update($params = array()) {
		$this->vci->stock_final = null;
		$this->volume_revendique_issu_vci = null;
		if($this->hasVci()) {
			$this->volume_revendique_issu_vci = ((float) $this->vci->complement) + ((float) $this->vci->substitution) + ((float) $this->vci->rafraichi);
			$this->vci->stock_final = ((float) $this->vci->rafraichi) + ((float) $this->vci->constitue) + ((float) $this->vci->ajustement);
		}
		$this->volume_revendique_total = ((float) $this->volume_revendique_issu_recolte) + ((float) $this->volume_revendique_issu_vci);
	}

	public function isHabilite() {
		$date = date('Y-m-d');
		if($this->document->isValidee()){
			$date = $this->document->validation;
		}
		$hab = HabilitationClient::getInstance()->findPreviousByIdentifiantAndDate($this->document->identifiant, $date);
		if (!$hab) {
			return false;
		}
		return $hab->isHabiliteFor($this->getProduitHash(), HabilitationClient::ACTIVITE_VINIFICATEUR);
	}

	public function getCodeCouleur()
	{
		if (preg_match('/\/rouge\//', $this->getHash())) {
			return 1;
		}
		if (preg_match('/\/rose\//', $this->getHash())) {
			return 2;
		}
		if (preg_match('/\/blanc\//', $this->getHash())) {
			return 3;
		}
		return null;
	}

	public function canCalculTheoriticalVolumeRevendiqueIssuRecolte() {

		if($this->recolte->volume_total == $this->recolte->volume_sur_place) {

			return true;
		}

		if($this->recolte->volume_sur_place == ($this->recolte->recolte_nette + $this->recolte->usages_industriels_total)) {

			return true;
		}

		return false;
	}

	public function getTheoriticalVolumeRevendiqueIssuRecole() {
		if($this->recolte->recolte_nette)
			return $this->recolte->recolte_nette - $this->vci->rafraichi - $this->vci->substitution;
		else
			return $this->recolte->recolte_nette;
	}

	public function getRendementVci(){
		if(!$this->superficie_revendique) {

			return null;
		}
		if(!$this->exist('vci') || !$this->vci->exist('constitue')) {

			return null;
		}

		return $this->vci->constitue / $this->superficie_revendique;
	}
	public function getRendementVciTotal(){
		if(!$this->superficie_revendique) {

			return null;
		}
		if(!$this->exist('vci') || !$this->vci->exist('stock_final')) {

			return null;
		}

		return $this->vci->stock_final / $this->superficie_revendique;
	}


	public function getRendementEffectif(){
		if(!$this->superficie_revendique) {

			return null;
		}

		return $this->volume_revendique_total / $this->superficie_revendique;
	}

	public function getRendementDR(){
		if(!$this->exist('recolte') || !$this->recolte->exist('volume_total') || !$this->recolte->exist('superficie_total')) {

			return null;
		}

		return $this->recolte->volume_total / $this->recolte->superficie_total;
	}

	public function validateOdg($date = null){
		if(is_null($date)) {
				$date = date('Y-m-d');
		}
		$this->add('validation_odg',$date);
	}

	public function isValidateOdg(){
		return ($this->exist('validation_odg') && $this->validation_odg);
	}

}<commit_msg>Evite division par zéro<commit_after><?php

class DRevProduit extends BaseDRevProduit
{
	public function getConfig()
	{
		return $this->getCouchdbDocument()->getConfiguration()->get($this->getProduitHash());
	}

	public function getLibelle() {
		if(!$this->_get('libelle')) {
			$this->libelle = $this->getConfig()->getLibelleComplet();
			if($this->denomination_complementaire) {
				$this->libelle .= ' '.$this->denomination_complementaire;
			}
		}

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

	public function getLibelleComplet()
	{

		return $this->getLibelle();
	}

	public function getChildrenNode()
    {
        return $this->getCepages();
    }

    public function getProduitHash() {
			return $this->getParent()->getHash();
    }

    public function getTotalTotalSuperficie()
    {

		return $this->superficie_revendique + (($this->canHaveVtsgn()) ? $this->superficie_revendique_vtsgn : 0);
    }

    public function getTotalVolumeRevendique()
    {

		return $this->volume_revendique_total + (($this->canHaveVtsgn()) ? $this->volume_revendique_vtsgn : 0);
    }

	public function getTotalVciUtilise() {

		return $this->vci->complement + $this->vci->substitution + $this->vci->rafraichi + $this->vci->destruction;
	}

	public function getPlafondStockVci() {

		return $this->recolte->superficie_total * $this->getConfig()->rendement_vci_total;
	}

	public function canHaveVtsgn() {

		return false;
	}

	public function hasVci($saisie = false) {
		if ($saisie) {
			return ($this->vci->stock_precedent || $this->vci->destruction || $this->vci->complement || $this->vci->substitution || $this->vci->rafraichi || $this->vci->constitue  || $this->vci->ajustement);
		}
		return ($this->vci->stock_precedent !== null || $this->vci->destruction !== null || $this->vci->complement !== null || $this->vci->substitution !== null || $this->vci->rafraichi !== null || $this->vci->constitue !== null || $this->vci->ajustement !== null);
	}

	public function hasVciDetruit() {
		return ($this->vci->destruction && $this->vci->destruction > 0)? true : false;
	}

    public function isActive()
    {

		return true;
    }

    public function isCleanable() {

        if(!$this->isActive()) {

            return true;
        }
		if ($this->recolte->superficie_total === null && $this->recolte->volume_total === null && $this->superficie_revendique === null && $this->volume_revendique_total === null ) {
			return true;
		}

        return false;
    }

	public function update($params = array()) {
		$this->vci->stock_final = null;
		$this->volume_revendique_issu_vci = null;
		if($this->hasVci()) {
			$this->volume_revendique_issu_vci = ((float) $this->vci->complement) + ((float) $this->vci->substitution) + ((float) $this->vci->rafraichi);
			$this->vci->stock_final = ((float) $this->vci->rafraichi) + ((float) $this->vci->constitue) + ((float) $this->vci->ajustement);
		}
		$this->volume_revendique_total = ((float) $this->volume_revendique_issu_recolte) + ((float) $this->volume_revendique_issu_vci);
	}

	public function isHabilite() {
		$date = date('Y-m-d');
		if($this->document->isValidee()){
			$date = $this->document->validation;
		}
		$hab = HabilitationClient::getInstance()->findPreviousByIdentifiantAndDate($this->document->identifiant, $date);
		if (!$hab) {
			return false;
		}
		return $hab->isHabiliteFor($this->getProduitHash(), HabilitationClient::ACTIVITE_VINIFICATEUR);
	}

	public function getCodeCouleur()
	{
		if (preg_match('/\/rouge\//', $this->getHash())) {
			return 1;
		}
		if (preg_match('/\/rose\//', $this->getHash())) {
			return 2;
		}
		if (preg_match('/\/blanc\//', $this->getHash())) {
			return 3;
		}
		return null;
	}

	public function canCalculTheoriticalVolumeRevendiqueIssuRecolte() {

		if($this->recolte->volume_total == $this->recolte->volume_sur_place) {

			return true;
		}

		if($this->recolte->volume_sur_place == ($this->recolte->recolte_nette + $this->recolte->usages_industriels_total)) {

			return true;
		}

		return false;
	}

	public function getTheoriticalVolumeRevendiqueIssuRecole() {
		if($this->recolte->recolte_nette)
			return $this->recolte->recolte_nette - $this->vci->rafraichi - $this->vci->substitution;
		else
			return $this->recolte->recolte_nette;
	}

	public function getRendementVci(){
		if(!$this->superficie_revendique) {

			return null;
		}
		if(!$this->exist('vci') || !$this->vci->exist('constitue')) {

			return null;
		}

		return $this->vci->constitue / $this->superficie_revendique;
	}
	public function getRendementVciTotal(){
		if(!$this->superficie_revendique) {

			return null;
		}
		if(!$this->exist('vci') || !$this->vci->exist('stock_final')) {

			return null;
		}

		return $this->vci->stock_final / $this->superficie_revendique;
	}


	public function getRendementEffectif(){
		if(!$this->superficie_revendique) {

			return null;
		}

		return $this->volume_revendique_total / $this->superficie_revendique;
	}

	public function getRendementDR(){
		if(!$this->exist('recolte') || !$this->recolte->exist('volume_total') || !$this->recolte->exist('superficie_total')) {

			return null;
		}
		if ($this->recolte->superficie_total) {
			return $this->recolte->volume_total / $this->recolte->superficie_total;
		}
		return 0;
	}

	public function validateOdg($date = null){
		if(is_null($date)) {
				$date = date('Y-m-d');
		}
		$this->add('validation_odg',$date);
	}

	public function isValidateOdg(){
		return ($this->exist('validation_odg') && $this->validation_odg);
	}

}
{'fraction_non_alphanumeric': 0.1833547675914018, 'fraction_numerical': 0.0011941943781003123, 'mean_word_length': 4.239172281039461, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 319, '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': '2770111', 'n_tokens_mistral': 4262, 'n_tokens_neox': 3971, 'n_words': 575}