id_acte = $id_acte+0; if ($this->id_acte) { $this->load(); } else { $this->date_acte = today(); } } // charge une acte à partir de la base. public function load(){ $q = "select * from actes where id_acte = '".$this->id_acte."' "; $r = pmb_mysql_query($q) ; if(pmb_mysql_num_rows($r)) { $obj = pmb_mysql_fetch_object($r); $this->date_acte = $obj->date_acte; $this->numero = $obj->numero; $this->nom_acte = $obj->nom_acte; $this->type_acte = $obj->type_acte; $this->statut = $obj->statut; $this->date_paiement = $obj->date_paiement; $this->num_paiement = $obj->num_paiement; $this->num_entite = $obj->num_entite; $this->num_fournisseur = $obj->num_fournisseur; $this->num_contact_livr = $obj->num_contact_livr; $this->num_contact_fact = $obj->num_contact_fact; //TODO Voir suppression num_exercice $this->num_exercice = $obj->num_exercice; $this->commentaires = $obj->commentaires; $this->reference = $obj->reference; $this->commentaires_i = $obj->commentaires_i; $this->devise = $obj->devise; $this->date_ech = $obj->date_ech; $this->date_valid = $obj->date_valid; } } // enregistre un acte en base. public function save(){ global $num_cde,$num_dev; if ( !$this->num_entite || !$this->num_fournisseur ) die("Erreur de création actes"); //récupération du libelle fournisseur $q = "select raison_sociale from entites where id_entite = '".$this->num_fournisseur."' "; $r = pmb_mysql_query($q); $fou = pmb_mysql_result($r, 0, 0); $num = ''; if($this->type_acte == TYP_ACT_CDE) $num = trim($num_cde); else if($this->type_acte == TYP_ACT_DEV) $num = trim($num_dev); if ($this->id_acte) { if ($num!='') { $this->numero=$num; } else { $this->numero=addslashes($this->numero); } $q = "update actes set "; $q.= "numero = '".$this->numero."', "; $q.= "nom_acte = '".$this->nom_acte."', "; $q.= "statut = '".$this->statut."', "; $q.= "date_paiement = '".$this->date_paiement."', "; $q.= "num_paiement = '".$this->num_paiement."', "; $q.= "num_fournisseur = '".$this->num_fournisseur."', "; $q.= "num_contact_livr = '".$this->num_contact_livr."', "; $q.= "num_contact_fact = '".$this->num_contact_fact."', "; //TODO Voir suppression num_exercice $q.= "num_exercice = '".$this->num_exercice."', "; $q.= "commentaires = '".$this->commentaires."', "; $q.= "reference = '".$this->reference."', "; $q.= "commentaires_i = '".$this->commentaires_i."', "; $q.= "devise = '".$this->devise."', "; $q.= "date_ech = '".$this->date_ech."', "; $q.= "date_valid = '".$this->date_valid."', "; $q.= "index_acte = ' ".$this->numero." ".strip_empty_words($fou)." ".strip_empty_words($this->commentaires)." ".strip_empty_words($this->reference)." ".strip_empty_words($this->nom_acte)." ' "; $q.= "where id_acte = '".$this->id_acte."' "; $r = pmb_mysql_query($q); audit::insert_modif(AUDIT_ACQUIS, $this->id_acte); } else { if ($num!='') { $this->numero=$num; } else { $this->calc(); } $q = "insert into actes set type_acte = '".$this->type_acte."', "; $q.= "date_acte = '".today()."', "; $q.= "numero = '".$this->numero."', "; $q.= "nom_acte = '".$this->nom_acte."', "; $q.= "statut = '".$this->statut."', "; $q.= "date_paiement = '".$this->date_paiement."', "; $q.= "num_paiement = '".$this->num_paiement."', "; $q.= "num_entite = '".$this->num_entite."', "; $q.= "num_fournisseur = '".$this->num_fournisseur."', "; $q.= "num_contact_livr = '".$this->num_contact_livr."', "; $q.= "num_contact_fact = '".$this->num_contact_fact."', "; //TODO Voir suppression num_exercice $q.= "num_exercice = '".$this->num_exercice."', "; $q.= "commentaires = '".$this->commentaires."' , "; $q.= "reference = '".$this->reference."', "; $q.= "commentaires_i = '".$this->commentaires_i."', "; $q.= "devise = '".$this->devise."', "; $q.= "date_ech = '".$this->date_ech."', "; $q.= "date_valid = '".$this->date_valid."', "; $q.= "index_acte = ' ".strip_empty_words($this->numero)." ".strip_empty_words($fou)." ".strip_empty_words($this->commentaires)." ".strip_empty_words($this->reference)." ".strip_empty_words($this->nom_acte)." ' "; $r = pmb_mysql_query($q); $this->id_acte = pmb_mysql_insert_id(); audit::insert_creation(AUDIT_ACQUIS, $this->id_acte); } } //supprime un acte de la base public function delete($id_acte= 0) { if(!$id_acte) $id_acte = $this->id_acte; actes::deleteLignes($id_acte); liens_actes::delete($id_acte); $q = "delete from actes where id_acte = '".$id_acte."' "; pmb_mysql_query($q); audit::delete_audit(AUDIT_ACQUIS, $id_acte); } //supprime les lignes d'un acte public static function deleteLignes($id_acte) { $query = "delete from lignes_actes_applicants where ligne_acte_num in (select id_ligne from lignes_actes where num_acte=".$id_acte.") "; pmb_mysql_query($query); $q = "delete from lignes_actes where num_acte = '".$id_acte."' "; pmb_mysql_query($q); } //supprime les lignes de l'acte non comprises dans le tableau de lignes public function cleanLignes($id_acte = 0, $tab_lig=array()) { if(!$id_acte) $id_acte=$this->id_acte; if(count($tab_lig)==0) return; $list_lig=implode("','", $tab_lig); $q = "delete from lignes_actes where num_acte='".$id_acte."' and id_ligne not in ('".$list_lig."')"; pmb_mysql_query($q); } //Recherche la prochaine echeance d'une commande en cours public static function getNextLivr($id_acte) { $q = "select min((date_format(date_ech, '%Y%m%d'))) from lignes_actes where num_acte = '".$id_acte."' and (('2' & statut) = '0') "; $r = pmb_mysql_query($q); if (pmb_mysql_num_rows($r)) { $res = pmb_mysql_result($r,0,0); $res = substr($res,0,4).'-'.substr($res,4,2).'-'.substr($res,6,2); } else $res = '0'; return $res; } // calcule le numéro d'un acte en base. // Il faut d'abord avoir renseigné le numéro d'entité et le type d'acte public function calc(){ $this->numero = calcNumero($this->num_entite, $this->type_acte); } // Retourne les lignes d'un acte public static function getLignes($id_acte=0, $param=0){ //if(!$id_acte) $id_acte = $this->id_acte; $q = "select * from lignes_actes where num_acte = '".$id_acte."' "; if($param) $q.="and ".$param." "; $r = pmb_mysql_query($q); return $r; } //TODO Voir suppression num_exercice //Retourne la liste des actes appartenant à l'exercice passé en paramètres public static function listByExercice($num_exercice){ $q = "select id_acte from actes where num_exercice = '".$num_exercice."' "; $r = pmb_mysql_query($q); return $r; } //Retourne un tableau de la liste des etats possibles pour un acte en fonction de son type (valeur, libelle) public static function getStatelist($type_acte, $all=TRUE) { global $msg; $t=array(); switch($type_acte) { case TYP_ACT_DEV : if ($all) { $t[-1]=$msg['acquisition_dev_tous']; } $t[2]=$msg['acquisition_dev_enc']; $t[4]=$msg['acquisition_dev_rec']; $t[32]=$msg['acquisition_dev_arc']; break; case TYP_ACT_CDE : if ($all) { $t[-1]=$msg['acquisition_cde_tous']; } $t[1]=$msg['acquisition_cde_aval']; $t[2]=$msg['acquisition_cde_enc']; $t[4]=$msg['acquisition_cde_liv']; $t[32]=$msg['acquisition_cde_arc']; break; case TYP_ACT_LIV : if ($all) { $t[-1]=$msg['acquisition_liv_tous']; } $t[4]=$msg['acquisition_liv_rec']; $t[32]=$msg['acquisition_liv_arc']; break; case TYP_ACT_FAC : if ($all) { $t[-1]=$msg['acquisition_fac_tous']; } $t[4]=$msg['acquisition_fac_rec']; $t[16]=$msg['acquisition_fac_pay']; $t[32]=$msg['acquisition_fac_arc']; break; } return $t; } public function update_statut($id_acte=0) { if(!$id_acte) $id_acte = $this->id_acte; $q = "update actes set statut='".$this->statut."' where id_acte='".$id_acte."' "; pmb_mysql_query($q); } //optimization de la table actes public function optimize() { $opt = pmb_mysql_query('OPTIMIZE TABLE actes'); return $opt; } } ?>