Example #1
0
 /**
  * Duplication de la facture
  *
  * @return void|string
  **/
 function duplicate()
 {
     /** @var CFacture $new*/
     $new = new $this->_class();
     $new->cloneFrom($this);
     if ($msg = $new->store()) {
         return $msg;
     }
     $liaison = new CFactureLiaison();
     $liaison->facture_id = $this->_id;
     $liaison->facture_class = $this->_class;
     $liaison->loadMatchingObject();
     $new_liaison = new CFactureLiaison();
     $new_liaison->cloneFrom($liaison, $new->_id);
     if ($msg = $new_liaison->store()) {
         return $msg;
     }
     $this->loadRefsReglements();
     foreach ($this->_ref_reglements as $reglement) {
         // Clonage
         $new_reglement = new CReglement();
         foreach ($reglement->getProperties() as $name => $value) {
             $new_reglement->{$name} = $value;
         }
         // Enregistrement
         $new_reglement->_id = null;
         $new_reglement->object_id = $new->_id;
         if ($msg = $new_reglement->store()) {
             return $msg;
         }
     }
     $this->loadRefsRelances();
     foreach ($this->_ref_relances as $relance) {
         // Clonage
         $new_relance = new CRelance();
         foreach ($relance->getProperties() as $name => $value) {
             $new_relance->{$name} = $value;
         }
         // Enregistrement
         $new_relance->_id = null;
         $new_relance->object_id = $new->_id;
         if ($msg = $new_relance->store()) {
             return $msg;
         }
     }
 }