diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php index b6107a62f13..1dffdd4c277 100644 --- a/htdocs/comm/addpropal.php +++ b/htdocs/comm/addpropal.php @@ -38,9 +38,10 @@ if (defined("PROPALE_ADDON") && is_readable(DOL_DOCUMENT_ROOT ."/includes/module } $langs->load("propal"); -$langs->load("projects"); +if ($conf->projet->enabled) $langs->load("projects"); $langs->load("companies"); $langs->load("bills"); +$langs->load("orders"); $user->getrights('propale'); $user->getrights('fichinter'); @@ -179,6 +180,8 @@ if ($_GET["action"] == 'create') */ // Date de livraison + // A quoi sert une date de livraison sur une propale ? + // Si il y a date de livraison connue alors ne s'agit-il pas d'une commande plutot ? if ($conf->global->PROPAL_ADD_SHIPPING_DATE) { print ''.$langs->trans("DateDelivery").''; diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index b9247c19130..84cb7c7f2cb 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -157,83 +157,97 @@ if ($_POST['action'] == 'set_ref_client' && $user->rights->propale->creer) */ if ($_POST['action'] == 'add') { - $propal = new Propal($db, $_POST['socidp']); - - // Si on a selectionné une propal à copier, on réalise la copie - if($_POST['createmode']=='copy' && $_POST['copie_propal']) - { - if($propal->load_from($_POST['copie_propal']) == -1) - { - //$msg = '
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; - $msg = '
Impossible de copier la propal Id = ' . $_POST['copie_propal'] . '!
'; - } - $propal->datep = mktime(12, 1, 1, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - $propal->date_livraison = $_POST['liv_year']."-".$_POST['liv_month']."-".$_POST['liv_day']; - $propal->adresse_livraison_id = $_POST['adresse_livraison_id']; - $propal->duree_validite = $_POST['duree_validite']; - $propal->cond_reglement_id = $_POST['cond_reglement_id']; - $propal->mode_reglement_id = $_POST['mode_reglement_id']; - $propal->remise_percent = $_POST['remise_percent']; - $propal->remise_absolue = $_POST['remise_absolue']; - $propal->socidp = $_POST['socidp']; - $propal->contactid = $_POST['contactidp']; - $propal->projetidp = $_POST['projetidp']; - $propal->modelpdf = $_POST['model']; - $propal->author = $user->id; - $propal->note = $_POST['note']; - $propal->ref = $_POST['ref']; - $propal->statut = 0; - - $id = $propal->create_from(); - } - else - { - $propal->datep = mktime(12, 1, 1, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - $propal->date_livraison = $_POST['liv_year']."-".$_POST['liv_month']."-".$_POST['liv_day']; - $propal->adresse_livraison_id = $_POST['adresse_livraison_id']; - $propal->duree_validite = $_POST['duree_validite']; - $propal->cond_reglement_id = $_POST['cond_reglement_id']; - $propal->mode_reglement_id = $_POST['mode_reglement_id']; - - $propal->contactid = $_POST['contactidp']; - $propal->projetidp = $_POST['projetidp']; - $propal->modelpdf = $_POST['model']; - $propal->author = $user->id; - $propal->note = $_POST['note']; - $propal->ref_client = $_POST['ref_client']; - - $propal->ref = $_POST['ref']; - - for ($i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i++) - { + $propal = new Propal($db, $_POST['socidp']); + + $db->begin(); + + // Si on a selectionné une propal à copier, on réalise la copie + if($_POST['createmode']=='copy' && $_POST['copie_propal']) + { + if ($propal->load_from($_POST['copie_propal']) == -1) + { + $msg = '
'.$langs->trans("ErrorFailedToCopyProposal",$_POST['copie_propal']).'
'; + } + $propal->datep = mktime(12, 1, 1, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $propal->date_livraison = $_POST['liv_year']."-".$_POST['liv_month']."-".$_POST['liv_day']; + $propal->adresse_livraison_id = $_POST['adresse_livraison_id']; + $propal->duree_validite = $_POST['duree_validite']; + $propal->cond_reglement_id = $_POST['cond_reglement_id']; + $propal->mode_reglement_id = $_POST['mode_reglement_id']; + $propal->remise_percent = $_POST['remise_percent']; + $propal->remise_absolue = $_POST['remise_absolue']; + $propal->socidp = $_POST['socidp']; + $propal->contactid = $_POST['contactidp']; + $propal->projetidp = $_POST['projetidp']; + $propal->modelpdf = $_POST['model']; + $propal->author = $user->id; + $propal->note = $_POST['note']; + $propal->ref = $_POST['ref']; + $propal->statut = 0; + + $id = $propal->create_from(); + } + else + { + $propal->datep = mktime(12, 1, 1, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $propal->date_livraison = $_POST['liv_year']."-".$_POST['liv_month']."-".$_POST['liv_day']; + $propal->adresse_livraison_id = $_POST['adresse_livraison_id']; + $propal->duree_validite = $_POST['duree_validite']; + $propal->cond_reglement_id = $_POST['cond_reglement_id']; + $propal->mode_reglement_id = $_POST['mode_reglement_id']; + + $propal->contactid = $_POST['contactidp']; + $propal->projetidp = $_POST['projetidp']; + $propal->modelpdf = $_POST['model']; + $propal->author = $user->id; + $propal->note = $_POST['note']; + $propal->ref_client = $_POST['ref_client']; + + $propal->ref = $_POST['ref']; + + for ($i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i++) + { if ($_POST['idprod'.$i]) { - $xid = 'idprod'.$i; - $xqty = 'qty'.$i; - $xremise = 'remise'.$i; - $propal->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]); + $xid = 'idprod'.$i; + $xqty = 'qty'.$i; + $xremise = 'remise'.$i; + $propal->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]); } - } + } + + $id = $propal->create(); + } + + if ($id > 0) + { + // Insertion contact par defaut + $result=$propal->add_contact($_POST["contactidp"],'CUSTOMER','external'); - $id = $propal->create(); - } - /* - * Generation - */ - if ($id > 0) - { - $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs"); - if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']); - propale_pdf_create($db, $id, $_POST['model'], $outputlangs); + if ($result > 0) + { + $db->commit(); - Header ('Location: '.$_SERVER["PHP_SELF"].'?propalid='.$id); - exit; - } - else - { - dolibarr_print_error($db,$propal->error); - exit; - } + // Generation document PDF + $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs"); + if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']); + propale_pdf_create($db, $id, $_POST['model'], $outputlangs); + + Header ('Location: '.$_SERVER["PHP_SELF"].'?propalid='.$id); + exit; + } + else + { + $msg = '
'.$langs->trans("ErrorFailedToAddContact").'
'; + $db->rollback(); + } + } + else + { + dolibarr_print_error($db,$propal->error); + $db->rollback(); + exit; + } } /* diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index a505f4e8ab3..5c61583636e 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -29,6 +29,7 @@ \version $Revision$ */ +require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT ."/contact.class.php"); @@ -37,9 +38,11 @@ require_once(DOL_DOCUMENT_ROOT ."/contact.class.php"); \class Commande \brief Classe de gestion de commande */ -class Commande +class Commande extends CommonObject { var $db ; + var $element='commande'; + var $id ; var $ref; var $socidp; @@ -1561,270 +1564,6 @@ class Commande } } - /** - * \brief Liste les valeurs possibles de type de contacts pour les factures - * \param source 'internal' ou 'external' - * \return array Tableau des types de contacts - */ - function liste_type_contact($source) - { - global $langs; - $element='commande'; - $tab = array(); - - $sql = "SELECT distinct tc.rowid, tc.code, tc.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE element='".$element."'"; - $sql.= " AND source='".$source."'"; - $sql.= " ORDER by tc.code"; - - $resql=$this->db->query($sql); - - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - $transkey="TypeContact_".$element."_".$source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - $tab[$obj->rowid]=$libelle_type; - $i++; - } - - return $tab; - } - else - { - $this->error=$this->db->error(); - return null; - } - } - - - /** - * \brief Récupère les lignes de contact de l'objet - * \param statut Statut des lignes detail à récupérer - * \param source Source du contact external (llx_socpeople) ou internal (llx_user) - * \return array Tableau des rowid des contacts - */ - function liste_contact($statut=-1,$source='external') - { - global $langs; - $element='commande'; - $tab=array(); - - $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,"; - if ($source == 'internal') $sql.=" '-1' as socid,"; - if ($source == 'external') $sql.=" t.fk_soc as socid,"; - if ($source == 'internal') $sql.=" t.name as nom,"; - if ($source == 'external') $sql.=" t.name as nom,"; - $sql.= "tc.source, tc.element, tc.code, tc.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,"; - if ($source == 'internal') $sql.=" ".MAIN_DB_PREFIX."user t,"; - if ($source == 'external') $sql.=" ".MAIN_DB_PREFIX."socpeople t,"; - $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc"; - $sql.= " WHERE element_id =".$this->id; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element='".$element."'"; - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; - if ($source == 'external') $sql.= " AND tc.source = 'external'"; - $sql.= " AND tc.active=1"; - if ($source == 'internal') $sql.= " AND ec.fk_socpeople = t.rowid"; - if ($source == 'external') $sql.= " AND ec.fk_socpeople = t.idp"; - if ($statut >= 0) $sql.= " AND statut = '$statut'"; - $sql.=" ORDER BY t.name ASC"; - - $resql=$this->db->query($sql); - - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,'nom'=>$obj->nom,'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut); - $i++; - } - - return $tab; - } - else - { - $this->error=$this->db->error(); - dolibarr_print_error($this->db); - return -1; - } - } - - - /** - * \brief Ajoute un contact associé une commande - * \param fk_socpeople Id du contact a ajouter. - * \param type_contact Type de contact - * \param source extern=Contact externe (llx_socpeople), intern=Contact interne (llx_user) - * \return int <0 si erreur, >0 si ok - */ - function add_contact($fk_socpeople, $type_contact, $source='extern') - { - dolibarr_syslog("Commande::add_contact $fk_socpeople, $type_contact, $source"); - - if ($fk_socpeople <= 0) return -1; - - // Verifie type_contact - if (! $type_contact || ! is_numeric($type_contact)) - { - $this->error="Valeur pour type_contact incorrect"; - return -3; - } - - $datecreate = time(); - - // Insertion dans la base - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; - $sql.= $this->db->idate($datecreate); - $sql.= ", 4, '". $type_contact . "' "; - $sql.= ")"; - - // Retour - if ( $this->db->query($sql) ) - { - return 1; - } - else - { - $this->error=$this->db->error()." - $sql"; - return -1; - } - } - - - /** - * \brief Supprime une ligne de contact - * \param rowid La reference du contact - * \return statur >0 si ok, <0 si ko - */ - function delete_contact($rowid) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; - $sql.= " WHERE rowid =".$rowid; - - if ($this->db->query($sql)) - { - return 1; - } - else - { - return -1; - } - } - - /** - * \brief Le détail d'un contact - * \param rowid L'identifiant du contact - * \return object L'objet construit par DoliDb.fetch_object - */ - function detail_contact($rowid) - { - $element='commande'; - - $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; - $sql.= " tc.code, tc.libelle, s.fk_soc"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc, "; - $sql.= " ".MAIN_DB_PREFIX."socpeople as s"; - $sql.= " WHERE ec.rowid =".$rowid; - $sql.= " AND ec.fk_socpeople=s.idp"; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element = '".$element."'"; - - $resql=$this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - return $obj; - } - else - { - $this->error=$this->db->error(); - dolibarr_print_error($this->db); - return null; - } - } - - /** - * \brief Mise a jour du contact associé à une commande - * \param rowid La reference du lien commande-contact - * \param statut Le nouveau statut - * \param type_contact_id Description du type de contact - * \return int <0 si erreur, =0 si ok - */ - function update_contact($rowid, $statut, $type_contact_id) - { - // Insertion dans la base - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; - $sql.= " statut = $statut,"; - $sql.= " fk_c_type_contact = '".$type_contact_id ."'"; - $sql.= " where rowid = ".$rowid; - // Retour - if ( $this->db->query($sql) ) - { - return 0; - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } - - /** - * \brief Renvoi tableau des id des contacts d'un type donné - * \param source 'internel' ou 'external' - * \param code Type de contact - * \param array Tableau des id de réponses - */ - function getIdContact($source,$code) - { - $element='commande'; // Contact sur commande - $result=array(); - $i=0; - - $sql = "SELECT ec.fk_socpeople"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE ec.element_id = ".$this->id; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element = '".$element."'"; - $sql.= " AND tc.source = '".$source."'"; - $sql.= " AND tc.code = '".$code."'"; - - $resql=$this->db->query($sql); - - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { - $result[$i]=$obj->fk_socpeople; - $i++; - } - } - else - { - $this->error=$this->db->error(); - return null; - } - - return $result; - } - - /** * Supprime la commande diff --git a/htdocs/compta/dons/liste.php b/htdocs/compta/dons/liste.php index 3edea3d6618..dc3d9d91808 100644 --- a/htdocs/compta/dons/liste.php +++ b/htdocs/compta/dons/liste.php @@ -89,7 +89,8 @@ if ($result) print_liste_field_titre($langs->trans("Name"),"liste.php","d.nom","&page=$page&statut=$statut","","",$sortfield); print_liste_field_titre($langs->trans("Company"),"liste.php","d.societe","&page=$page&statut=$statut","","",$sortfield); print_liste_field_titre($langs->trans("Date"),"liste.php","d.datedon","&page=$page&statut=$statut","",'align="center"',$sortfield); - if ($conf->projet->enabled) { + if ($conf->projet->enabled) + { $langs->load("projects"); print_liste_field_titre($langs->trans("Project"),"liste.php","projet","&page=$page&statut=$statut","","",$sortfield); } diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php index 66816ed01d4..083e39ba1e3 100644 --- a/htdocs/compta/facture/apercu.php +++ b/htdocs/compta/facture/apercu.php @@ -223,8 +223,8 @@ if ($_GET["facid"] > 0) // Projet if ($conf->projet->enabled) { - print ''; $langs->load("projects"); + print ''; print ''.$langs->trans("Project").''; if ($fac->projetid > 0) { diff --git a/htdocs/compta/fiche.php b/htdocs/compta/fiche.php index fdf3fa877cc..51e5f4bb119 100644 --- a/htdocs/compta/fiche.php +++ b/htdocs/compta/fiche.php @@ -35,7 +35,7 @@ require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); $langs->load("companies"); if ($conf->facture->enabled) $langs->load("bills"); -if ($conf->projet->enabled) $langs->load("projects"); +if ($conf->projet->enabled) $langs->load("projects"); $user->getrights("commercial"); diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index f8dffdffee3..1ca23208be4 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -27,6 +27,7 @@ \version $Revision$ */ +require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); @@ -35,9 +36,10 @@ require_once(DOL_DOCUMENT_ROOT."/product.class.php"); \brief Classe permettant la gestion des contrats */ -class Contrat +class Contrat extends CommonObject { var $db; + var $element='contrat'; var $id; var $ref; @@ -1053,290 +1055,7 @@ class Contrat /* gestion des contacts d'un contrat */ - - /** - * \brief Ajoute un contact associé au contrat - * \param fk_socpeople Id du contact a ajouter. - * \param type_contact Type de contact - * \param source extern=Contact externe (llx_socpeople), intern=Contact interne (llx_user) - * \return int <0 si erreur, >0 si ok - */ - function add_contact($fk_socpeople, $type_contact, $source='extern') - { - dolibarr_syslog("Contrat::add_contact $fk_socpeople, $type_contact, $source"); - - if ($fk_socpeople <= 0) return -1; - - // Si type_contact = texte, aller chercher code dans table llx_c_type_contact - if ($type_contact == 'SALESREPSIGN' || $type_contact == 'SALESREPFOLL') - { - $sql.="SELECT rowid from ".MAIN_DB_PREFIX."c_type_contact"; - $sql.=" WHERE element='contrat' AND source='internal'"; - $sql.=" AND code='".$type_contact."'"; - $resql = $this->db->query($sql); - if ( $resql ) - { - $obj = $this->db->fetch_object($resql); - if ($obj) $type_contact=$obj->rowid; - } - else - { - dolibarr_print_error($this->db); - $this->error=$this->db->error()." - $sql"; - return -2; - } - } - - // Verifie type_contact - if (! $type_contact) - { - $this->error="Valeur pour type_contact incorrect"; - return -3; - } - - $datecreate = time(); - - // Insertion dans la base - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; - $sql.= $this->db->idate($datecreate); - $sql.= ", 4, '". $type_contact . "' "; - $sql.= ")"; - - // Retour - if ( $this->db->query($sql) ) - { - return 1; - } - else - { - $this->error=$this->db->error()." - $sql"; - return -1; - } - } - - /** - * \brief Misea jour du contact associé au contrat - * \param rowid La reference du lien contrat-contact - * \param statut Le nouveau statut - * \param nature Description du contact - * \return int <0 si erreur, =0 si ok - */ - function update_contact($rowid, $statut, $type_contact_id) - { - // Insertion dans la base - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set "; - $sql.= " statut = $statut ,"; - $sql.= " fk_c_type_contact = '".$type_contact_id ."'"; - $sql.= " where rowid = ".$rowid; - // Retour - if ( $this->db->query($sql) ) - { - return 0; - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } - - /** - * \brief Supprime une ligne de contact - * \param idligne La reference du contact - * \return statur >0 si ok, <0 si ko - */ - function delete_contact($idligne) - { - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; - $sql.= " WHERE rowid =".$idligne; - if ($this->db->query($sql)) - { - return 1; - } - else - { - return -1; - } - } - /** - * \brief Récupère les lignes de contact de l'objet - * \param statut Statut des lignes detail à récupérer - * \param source Source du contact external (llx_socpeople) ou internal (llx_user) - * \return array Tableau des rowid des contacts - */ - function liste_contact($statut=-1,$source='external') - { - global $langs; - - $element='contrat'; // Contact sur le contrat - - $tab=array(); - - $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,"; - if ($source == 'internal') $sql.=" '-1' as socid,"; - if ($source == 'external') $sql.=" t.fk_soc as socid,"; - if ($source == 'internal') $sql.=" t.name as nom,"; - if ($source == 'external') $sql.=" t.name as nom,"; - $sql.= "tc.source, tc.element, tc.code, tc.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,"; - if ($source == 'internal') $sql.=" ".MAIN_DB_PREFIX."user t,"; - if ($source == 'external') $sql.=" ".MAIN_DB_PREFIX."socpeople t,"; - $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc"; - $sql.= " WHERE element_id =".$this->id; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element='".$element."'"; - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; - if ($source == 'external') $sql.= " AND tc.source = 'external'"; - $sql.= " AND tc.active=1"; - if ($source == 'internal') $sql.= " AND ec.fk_socpeople = t.rowid"; - if ($source == 'external') $sql.= " AND ec.fk_socpeople = t.idp"; - if ($statut >= 0) $sql.= " AND statut = '$statut'"; - $sql.=" ORDER BY t.name ASC"; - - $resql=$this->db->query($sql); - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,'nom'=>$obj->nom, - 'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut); - $i++; - } - return $tab; - } - else - { - $this->error=$this->db->error(); - dolibarr_print_error($this->db); - return -1; - } - } - - /** - * \brief Le détail d'un contact - * \param rowid L'identifiant du contact - * \return object L'objet construit par DoliDb.fetch_object - */ - function detail_contact($rowid) - { - $element='contrat'; // Contact sur le contrat - - $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; - $sql.= " tc.code, tc.libelle, s.fk_soc"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc, "; - $sql.= " ".MAIN_DB_PREFIX."socpeople as s"; - $sql.= " WHERE ec.rowid =".$rowid; - $sql.= " AND ec.fk_socpeople=s.idp"; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element = '".$element."'"; - - $resql=$this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - return $obj; - } - else - { - $this->error=$this->db->error(); - dolibarr_print_error($this->db); - return null; - } - } - - /** - * \brief La liste des valeurs possibles de type de contacts - * \param source internal ou externam - * \return array La liste des natures - */ - function liste_type_contact($source) - { - global $langs; - - $element='contrat'; // Contact sur le contrat - - $tab = array(); - - $sql = "SELECT distinct tc.rowid, tc.code, tc.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE element='".$element."'"; - $sql.= " AND source='".$source."'"; - $sql.= " ORDER by tc.code"; - - $resql=$this->db->query($sql); - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - $transkey="TypeContact_".$element."_".$source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - $tab[$obj->rowid]=$libelle_type; - $i++; - } - return $tab; - } - else - { - $this->error=$this->db->error(); -// dolibarr_print_error($this->db); - return null; - } - } - - /** - * \brief Retourne id des contacts d'une source et d'un type donné - * Exemple: contact client de facturation ('external', 'BILLING') - * Exemple: contact client de livraison ('external', 'SHIPPING') - * Exemple: contact interne suivi paiement ('internal', 'SALESREPFOLL') - * \return array Liste des id contacts - */ - function getIdContact($source,$code) - { - $element='contrat'; // Contact sur le contrat - - $result=array(); - $i=0; - - $sql = "SELECT ec.fk_socpeople"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE ec.element_id = ".$this->id; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element = '".$element."'"; - $sql.= " AND tc.source = '".$source."'"; - $sql.= " AND tc.code = '".$code."'"; - - $resql=$this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { - $result[$i]=$obj->fk_socpeople; - $i++; - } - } - else - { - $this->error=$this->db->error(); - return null; - } - - return $result; - } - /** * \brief Retourne id des contacts clients de facturation * \return array Liste des id contacts facturation diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 8cbcb56c596..20ceb153bdc 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -31,6 +31,7 @@ \version $Revision$ */ +require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT .'/notify.class.php'); require_once(DOL_DOCUMENT_ROOT ."/product.class.php"); require_once(DOL_DOCUMENT_ROOT ."/client.class.php"); @@ -40,9 +41,10 @@ require_once(DOL_DOCUMENT_ROOT ."/client.class.php"); \brief Classe permettant la gestion des factures clients */ -class Facture +class Facture extends CommonObject { var $db; + var $element='facture'; var $id; @@ -2001,267 +2003,7 @@ class Facture } - /** - * \brief Ajoute un contact associé une facture - * \param fk_socpeople Id du contact a ajouter. - * \param type_contact Type de contact - * \param source extern=Contact externe (llx_socpeople), intern=Contact interne (llx_user) - * \return int <0 si erreur, >0 si ok - */ - function add_contact($fk_socpeople, $type_contact, $source='extern') - { - dolibarr_syslog("Facture::add_contact $fk_socpeople, $type_contact, $source"); - - if ($fk_socpeople <= 0) return -1; - - // Verifie type_contact - if (! $type_contact || ! is_numeric($type_contact)) - { - $this->error="Valeur pour type_contact incorrect"; - return -3; - } - - $datecreate = time(); - - // Insertion dans la base - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; - $sql.= $this->db->idate($datecreate); - $sql.= ", 4, '". $type_contact . "' "; - $sql.= ")"; - - // Retour - if ( $this->db->query($sql) ) - { - return 1; - } - else - { - $this->error=$this->db->error()." - $sql"; - return -1; - } - } - - /** - * \brief Mise a jour du contact associé une facture - * \param rowid La reference du lien facture-contact - * \param statut Le nouveau statut - * \param type_contact_id Description du type de contact - * \return int <0 si erreur, =0 si ok - */ - function update_contact($rowid, $statut, $type_contact_id) - { - // Insertion dans la base - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; - $sql.= " statut = $statut,"; - $sql.= " fk_c_type_contact = '".$type_contact_id ."'"; - $sql.= " where rowid = ".$rowid; - // Retour - if ( $this->db->query($sql) ) - { - return 0; - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } - - /** - * \brief Supprime une ligne de contact - * \param rowid La reference du contact - * \return statur >0 si ok, <0 si ko - */ - function delete_contact($rowid) - { - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; - $sql.= " WHERE rowid =".$rowid; - if ($this->db->query($sql)) - { - return 1; - } - else - { - return -1; - } - } - - /** - * \brief Récupère les lignes de contact de l'objet - * \param statut Statut des lignes detail à récupérer - * \param source Source du contact external (llx_socpeople) ou internal (llx_user) - * \return array Tableau des rowid des contacts - */ - function liste_contact($statut=-1,$source='external') - { - global $langs; - - $element='facture'; - - $tab=array(); - - $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,"; - if ($source == 'internal') $sql.=" '-1' as socid,"; - if ($source == 'external') $sql.=" t.fk_soc as socid,"; - if ($source == 'internal') $sql.=" t.name as nom,"; - if ($source == 'external') $sql.=" t.name as nom,"; - $sql.= "tc.source, tc.element, tc.code, tc.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,"; - if ($source == 'internal') $sql.=" ".MAIN_DB_PREFIX."user t,"; - if ($source == 'external') $sql.=" ".MAIN_DB_PREFIX."socpeople t,"; - $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc"; - $sql.= " WHERE element_id =".$this->id; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element='".$element."'"; - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; - if ($source == 'external') $sql.= " AND tc.source = 'external'"; - $sql.= " AND tc.active=1"; - if ($source == 'internal') $sql.= " AND ec.fk_socpeople = t.rowid"; - if ($source == 'external') $sql.= " AND ec.fk_socpeople = t.idp"; - if ($statut >= 0) $sql.= " AND statut = '$statut'"; - $sql.=" ORDER BY t.name ASC"; - - $resql=$this->db->query($sql); - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,'nom'=>$obj->nom, - 'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut); - $i++; - } - return $tab; - } - else - { - $this->error=$this->db->error(); - dolibarr_print_error($this->db); - return -1; - } - } - - /** - * \brief Le détail d'un contact - * \param rowid L'identifiant du contact - * \return object L'objet construit par DoliDb.fetch_object - */ - function detail_contact($rowid) - { - $element='facture'; - - $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; - $sql.= " tc.code, tc.libelle, s.fk_soc"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc, "; - $sql.= " ".MAIN_DB_PREFIX."socpeople as s"; - $sql.= " WHERE ec.rowid =".$rowid; - $sql.= " AND ec.fk_socpeople=s.idp"; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element = '".$element."'"; - - $resql=$this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - return $obj; - } - else - { - $this->error=$this->db->error(); - dolibarr_print_error($this->db); - return null; - } - } - - /** - * \brief Liste les valeurs possibles de type de contacts pour les factures - * \param source 'internal' ou 'external' - * \return array Tableau des types de contacts - */ - function liste_type_contact($source) - { - global $langs; - - $element='facture'; - - $tab = array(); - - $sql = "SELECT distinct tc.rowid, tc.code, tc.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE element='".$element."'"; - $sql.= " AND source='".$source."'"; - $sql.= " ORDER by tc.code"; - - $resql=$this->db->query($sql); - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - $transkey="TypeContact_".$element."_".$source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - $tab[$obj->rowid]=$libelle_type; - $i++; - } - return $tab; - } - else - { - $this->error=$this->db->error(); - return null; - } - } - - /** - * \brief Retourne id des contacts d'une source et d'un type donné - * Exemple: contact client de facturation ('external', 'BILLING') - * Exemple: contact client de livraison ('external', 'SHIPPING') - * Exemple: contact interne suivi paiement ('internal', 'SALESREPFOLL') - * \return array Liste des id contacts - */ - function getIdContact($source,$code) - { - $element='facture'; // Contact sur la facture - - $result=array(); - $i=0; - - $sql = "SELECT ec.fk_socpeople"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE ec.element_id = ".$this->id; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element = '".$element."'"; - $sql.= " AND tc.source = '".$source."'"; - $sql.= " AND tc.code = '".$code."'"; - - $resql=$this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { - $result[$i]=$obj->fk_socpeople; - $i++; - } - } - else - { - $this->error=$this->db->error(); - return null; - } - - return $result; - } + /* gestion des contacts d'une facture */ /** * \brief Retourne id des contacts clients de facturation diff --git a/htdocs/projet/commandes.php b/htdocs/projet/commandes.php index f7243ab6598..e69c04f522c 100644 --- a/htdocs/projet/commandes.php +++ b/htdocs/projet/commandes.php @@ -32,7 +32,7 @@ require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); -$langs->load("projects"); +if ($conf->projet->enabled) $langs->load("projects"); $langs->load("companies"); $langs->load("orders"); diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 947187c3d1b..e4095074b42 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -33,6 +33,7 @@ \version $Revision$ */ +require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT ."/product.class.php"); require_once(DOL_DOCUMENT_ROOT ."/contact.class.php"); @@ -42,10 +43,12 @@ require_once(DOL_DOCUMENT_ROOT ."/contact.class.php"); \brief Classe permettant la gestion des propales */ -class Propal +class Propal extends CommonObject { - var $id; var $db; + var $element='propal'; + + var $id; var $socidp; var $contactid; var $projetidp; @@ -349,275 +352,10 @@ class Propal /** - * \brief Liste les valeurs possibles de type de contacts pour les factures - * \param source 'internal' ou 'external' - * \return array Tableau des types de contacts + * + * */ - function liste_type_contact($source) - { - global $langs; - $element='propal'; - $tab = array(); - - $sql = "SELECT distinct tc.rowid, tc.code, tc.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE element='".$element."'"; - $sql.= " AND source='".$source."'"; - $sql.= " ORDER by tc.code"; - - $resql=$this->db->query($sql); - - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - $transkey="TypeContact_".$element."_".$source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - $tab[$obj->rowid]=$libelle_type; - $i++; - } - - return $tab; - } - else - { - $this->error=$this->db->error(); - return null; - } - } - - - /** - * \brief Récupère les lignes de contact de l'objet - * \param statut Statut des lignes detail à récupérer - * \param source Source du contact external (llx_socpeople) ou internal (llx_user) - * \return array Tableau des rowid des contacts - */ - function liste_contact($statut=-1,$source='external') - { - global $langs; - $element='propal'; - $tab=array(); - - $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,"; - if ($source == 'internal') $sql.=" '-1' as socid,"; - if ($source == 'external') $sql.=" t.fk_soc as socid,"; - if ($source == 'internal') $sql.=" t.name as nom,"; - if ($source == 'external') $sql.=" t.name as nom,"; - $sql.= "tc.source, tc.element, tc.code, tc.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,"; - if ($source == 'internal') $sql.=" ".MAIN_DB_PREFIX."user t,"; - if ($source == 'external') $sql.=" ".MAIN_DB_PREFIX."socpeople t,"; - $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc"; - $sql.= " WHERE element_id =".$this->id; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element='".$element."'"; - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; - if ($source == 'external') $sql.= " AND tc.source = 'external'"; - $sql.= " AND tc.active=1"; - if ($source == 'internal') $sql.= " AND ec.fk_socpeople = t.rowid"; - if ($source == 'external') $sql.= " AND ec.fk_socpeople = t.idp"; - if ($statut >= 0) $sql.= " AND statut = '$statut'"; - $sql.=" ORDER BY t.name ASC"; - - $resql=$this->db->query($sql); - - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,'nom'=>$obj->nom,'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut); - $i++; - } - - return $tab; - } - else - { - $this->error=$this->db->error(); - dolibarr_print_error($this->db); - return -1; - } - } - - - /** - * \brief Ajoute un contact associé une commande - * \param fk_socpeople Id du contact a ajouter. - * \param type_contact Type de contact - * \param source extern=Contact externe (llx_socpeople), intern=Contact interne (llx_user) - * \return int <0 si erreur, >0 si ok - */ - function add_contact($fk_socpeople, $type_contact, $source='extern') - { - dolibarr_syslog("Commande::add_contact $fk_socpeople, $type_contact, $source"); - - if ($fk_socpeople <= 0) return -1; - - // Verifie type_contact - if (! $type_contact || ! is_numeric($type_contact)) - { - $this->error="Valeur pour type_contact incorrect"; - return -3; - } - - $datecreate = time(); - - // Insertion dans la base - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; - $sql.= $this->db->idate($datecreate); - $sql.= ", 4, '". $type_contact . "' "; - $sql.= ")"; - - // Retour - if ( $this->db->query($sql) ) - { - return 1; - } - else - { - $this->error=$this->db->error()." - $sql"; - return -1; - } - } - - - /** - * \brief Supprime une ligne de contact - * \param rowid La reference du contact - * \return statur >0 si ok, <0 si ko - */ - function delete_contact($rowid) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; - $sql.= " WHERE rowid =".$rowid; - - if ($this->db->query($sql)) - { - return 1; - } - else - { - return -1; - } - } - - /** - * \brief Le détail d'un contact - * \param rowid L'identifiant du contact - * \return object L'objet construit par DoliDb.fetch_object - */ - function detail_contact($rowid) - { - $element='propal'; - - $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; - $sql.= " tc.code, tc.libelle, s.fk_soc"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc, "; - $sql.= " ".MAIN_DB_PREFIX."socpeople as s"; - $sql.= " WHERE ec.rowid =".$rowid; - $sql.= " AND ec.fk_socpeople=s.idp"; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element = '".$element."'"; - - $resql=$this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - return $obj; - } - else - { - $this->error=$this->db->error(); - dolibarr_print_error($this->db); - return null; - } - } - - /** - * \brief Mise a jour du contact associé à une commande - * \param rowid La reference du lien commande-contact - * \param statut Le nouveau statut - * \param type_contact_id Description du type de contact - * \return int <0 si erreur, =0 si ok - */ - function update_contact($rowid, $statut, $type_contact_id) - { - // Insertion dans la base - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; - $sql.= " statut = $statut,"; - $sql.= " fk_c_type_contact = '".$type_contact_id ."'"; - $sql.= " where rowid = ".$rowid; - // Retour - if ( $this->db->query($sql) ) - { - return 0; - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } - - /** - * \brief Renvoi tableau des id des contacts d'un type donné - * \param source 'internel' ou 'external' - * \param code Type de contact - * \param array Tableau des id de réponses - */ - function getIdContact($source,$code) - { - $element='propal'; // Contact sur propal - $result=array(); - $i=0; - - $sql = "SELECT ec.fk_socpeople"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE ec.element_id = ".$this->id; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element = '".$element."'"; - $sql.= " AND tc.source = '".$source."'"; - $sql.= " AND tc.code = '".$code."'"; - - $resql=$this->db->query($sql); - - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { - $result[$i]=$obj->fk_socpeople; - $i++; - } - } - else - { - $this->error=$this->db->error(); - return null; - } - - return $result; - } - - - /** - * - * - */ - - function fetch_client() + function fetch_client() { $client = new Societe($this->db); $client->fetch($this->socidp); @@ -625,12 +363,11 @@ class Propal } - /** - * - * - */ - - function fetch_adresse_livraison($id) + /** + * + * + */ + function fetch_adresse_livraison($id) { $idadresse = $id; $adresse = new Societe($this->db); @@ -638,20 +375,6 @@ class Propal $this->adresse = $adresse; } - /** - * - * - */ - - function fetch_contact_propal($id) - { - $idcontact = $id; - $contact = new Contact($this->db); - $contact->fetch($idcontact); - $this->contact = $contact; - } - - /** * \brief Supprime une ligne de detail