Ejemplo n.º 1
0
 /**
  *	Fonction qui insere la cotisation dans la base de donnees
  *	et eventuellement liens dans banques, mailman, etc...
  *	@param	    date        	Date d'effet de la cotisation
  *	@param	    montant     	Montant cotisation (accepte 0 pour les adherents non soumis e cotisation)
  *	@param		account_id		Id compte bancaire
  *	@param		operation		Type operation (si Id compte bancaire fourni)
  *	@param		label			Label operation (si Id compte bancaire fourni)
  *	@param		num_chq			Numero cheque (si Id compte bancaire fourni)
  *	@param		emetteur_nom	Nom emetteur cheque
  *	@param		emetteur_banque	Nom banque emetteur cheque
  *	@param		datesubend		Date fin adhesion
  *	@return     int         	rowid de l'entree ajoutee, <0 si erreur
  */
 function cotisation($date, $montant, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0)
 {
     global $conf, $langs, $user;
     // Clean parameters
     if (!$montant) {
         $montant = 0;
     }
     $this->db->begin();
     if ($datesubend) {
         $datefin = $datesubend;
     } else {
         // If no end date, end date = date + 1 year - 1 day
         $datefin = dol_time_plus_duree($date, 1, 'y');
         $datefin = dol_time_plus_duree($datefin, -1, 'd');
     }
     // Create subscription
     $cotisation = new Cotisation($this->db);
     $cotisation->fk_adherent = $this->id;
     $cotisation->dateh = $date;
     // Date of new subscription
     $cotisation->datef = $datefin;
     // End data of new subscription
     $cotisation->amount = $montant;
     $cotisation->note = $label;
     $rowid = $cotisation->create($user);
     if ($rowid > 0) {
         // Update denormalized subscription end date (read database subscription to find values)
         // This will also update this->datefin
         $result = $this->update_end_date($user);
         if ($result > 0) {
             // Change properties of object (used by triggers)
             $this->last_subscription_date = $dateop;
             $this->last_subscription_amount = $montant;
             $this->last_subscription_date_start = $date;
             $this->last_subscription_date_end = $datefin;
             $this->use_webcal = $conf->global->PHPWEBCALENDAR_MEMBERSTATUS == 'always' ? 1 : 0;
             // Appel des triggers
             include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
             $interface = new Interfaces($this->db);
             $result = $interface->run_triggers('MEMBER_SUBSCRIPTION', $this, $user, $langs, $conf);
             if ($result < 0) {
                 $error++;
                 $this->errors = $interface->errors;
             }
             // Fin appel triggers
             $this->db->commit();
             return $rowid;
         } else {
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->error = $cotisation->error;
         $this->db->rollback();
         return -1;
     }
 }
Ejemplo n.º 2
0
 /**
  *	Insert subscription into database and eventually add links to banks, mailman, etc...
  *
  *	@param	int	        $date        		Date of effect of subscription
  *	@param	double		$montant     		Amount of subscription (0 accepted for some members)
  *	@param	int			$accountid			Id bank account
  *	@param	string		$operation			Type operation (if Id bank account provided)
  *	@param	string		$label				Label operation (if Id bank account provided)
  *	@param	string		$num_chq			Numero cheque (if Id bank account provided)
  *	@param	string		$emetteur_nom		Name of cheque writer
  *	@param	string		$emetteur_banque	Name of bank of cheque
  *	@param	int     	$datesubend			Date end subscription
  *	@return int         					rowid of record added, <0 if KO
  */
 function cotisation($date, $montant, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0)
 {
     global $conf, $langs, $user;
     require_once DOL_DOCUMENT_ROOT . '/adherents/class/cotisation.class.php';
     $error = 0;
     // Clean parameters
     if (!$montant) {
         $montant = 0;
     }
     $this->db->begin();
     if ($datesubend) {
         $datefin = $datesubend;
     } else {
         // If no end date, end date = date + 1 year - 1 day
         $datefin = dol_time_plus_duree($date, 1, 'y');
         $datefin = dol_time_plus_duree($datefin, -1, 'd');
     }
     // Create subscription
     $cotisation = new Cotisation($this->db);
     $cotisation->fk_adherent = $this->id;
     $cotisation->dateh = $date;
     // Date of new subscription
     $cotisation->datef = $datefin;
     // End data of new subscription
     $cotisation->amount = $montant;
     $cotisation->note = $label;
     $rowid = $cotisation->create($user);
     if ($rowid > 0) {
         // Update denormalized subscription end date (read database subscription to find values)
         // This will also update this->datefin
         $result = $this->update_end_date($user);
         if ($result > 0) {
             // Change properties of object (used by triggers)
             $this->last_subscription_date = dol_now();
             $this->last_subscription_amount = $montant;
             $this->last_subscription_date_start = $date;
             $this->last_subscription_date_end = $datefin;
             // Call trigger
             $result = $this->call_trigger('MEMBER_SUBSCRIPTION', $user);
             if ($result < 0) {
                 $error++;
             }
             // End call triggers
         }
         if (!$error) {
             $this->db->commit();
             return $rowid;
         } else {
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->error = $cotisation->error;
         $this->db->rollback();
         return -1;
     }
 }