From 0b2724ead3572cc1dc4fe66d1c42da727947f26e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 12 Feb 2006 15:54:21 +0000 Subject: [PATCH] =?UTF-8?q?New:=20Toutes=20les=20entites=20(contrat,=20fac?= =?UTF-8?q?ture,=20propal,=20commande)=20poss=E8de=20un=20chanp=20note=20(?= =?UTF-8?q?non=20affich=E9=20sur=20PDF)=20et=20un=20champ=20note=20public?= =?UTF-8?q?=20(affich=E9=20sur=20PDF)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/compta/facture.php | 89 +++++++++------ htdocs/compta/facture/note.php | 72 +++++++++--- htdocs/facture.class.php | 194 +++++++++++++++++++++------------ htdocs/langs/en_US/main.lang | 2 + htdocs/langs/fr_FR/main.lang | 2 + htdocs/lib/functions.inc.php | 2 +- htdocs/product.class.php | 2 + 7 files changed, 246 insertions(+), 117 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 85ff4e77dda..daa48ee1ad7 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -118,6 +118,7 @@ if ($_POST['action'] == 'add') $facture->number = $_POST['facnumber']; $facture->date = $datefacture; + $facture->note_public = $_POST['note_public']; $facture->note = $_POST['note']; if ($_POST['fac_rec'] > 0) @@ -155,11 +156,16 @@ if ($_POST['action'] == 'add') } $facid = $facture->create($user); - if ($facid) + if ($facid > 0) { Header('Location: facture.php?facid='.$facid); exit; } + else + { + $_GET["action"]='create'; + $mesg='
'.$facture->error.'
'; + } } else { @@ -280,7 +286,7 @@ if ($_POST['action'] == 'add') } // Fin création facture, on l'affiche - if ($facid) + if ($facid > 0) { Header('Location: facture.php?facid='.$facid); exit; @@ -334,7 +340,8 @@ if ($_POST['action'] == 'addligne' && $user->rights->facture->creer) { $dateend=$_POST['date_endyear'].'-'.$_POST['date_endmonth'].'-'.$_POST['date_endday']; } - $result = $fac->addline($_POST['facid'], + $result = $fac->addline( + $_POST['facid'], $_POST['desc'], $_POST['product_desc'], $_POST['pu'], @@ -404,7 +411,7 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') if ($_POST['action'] == 'confirm_canceled' && $_POST['confirm'] == 'yes') { - if ($user->rights->facture->supprimer ) + if ($user->rights->facture->supprimer) { $fac = new Facture($db); $fac->fetch($_GET['facid']); @@ -595,6 +602,8 @@ if ($_GET['action'] == 'create') { print_titre($langs->trans('NewBill')); + if ($mesg) print $mesg; + $soc = new Societe($db); if ($_GET['propalid']) @@ -642,32 +651,12 @@ if ($_GET['action'] == 'create') print ''.$langs->trans('Company').''.$soc->nom.''; print ''; - print ''.$langs->trans('Author').''.$user->fullname.''; - print ''.$langs->trans('Comments').''; + print ''.$langs->trans('Author').''.$user->fullname.''; print ''; print ''.$langs->trans('Date').''; $html->select_date(); - print ''; - - // Notes - $nbrows=4; - if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++; - print ''; - print ''; + print ''; // Conditions de réglement $cond_reglement_id_defaut=1; @@ -688,10 +677,42 @@ if ($_GET['action'] == 'create') $html->select_projects($societe_id, $projet, 'projetid'); print ''; } - else + + // Note publique + print ''.$langs->trans('NotePublic').''; + print ''; + print ''; + + // Note privée + print ''.$langs->trans('NotePrivate').''; + print ''; + print ''; /* \todo @@ -753,7 +774,6 @@ if ($_GET['action'] == 'create') } else { - print ' '; print ''; print ''; @@ -1242,7 +1262,7 @@ else print ''; } - $nbrows=8; + $nbrows=7; if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++; print ''; - if ($fac->note) + /* + if ($fac->note_public) { - print ''; + print ''; + print ''; } else { print ''; } - + */ + print '
  '; @@ -1352,15 +1372,18 @@ else // Statut print '
'.$langs->trans('Status').''.($fac->getLibStatut()).'
'.$langs->trans('Note').' : '.nl2br($fac->note).'
'.$langs->trans('NotePublic').''.nl2br(dolibarr_trunc($fac->note_public,40)).'
 

'; /* diff --git a/htdocs/compta/facture/note.php b/htdocs/compta/facture/note.php index 124ccf88d65..a4f29203b2f 100644 --- a/htdocs/compta/facture/note.php +++ b/htdocs/compta/facture/note.php @@ -30,6 +30,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php'); +$socidp=isset($_GET["socidp"])?$_GET["socidp"]:isset($_POST["socidp"])?$_POST["socidp"]:""; $user->getrights('facture'); if (!$user->rights->facture->lire) @@ -38,9 +39,7 @@ if (!$user->rights->facture->lire) $langs->load("companies"); $langs->load("bills"); -/* - * Sécurité accés client - */ +// Sécurité accés if ($user->societe_id > 0) { unset($_GET["action"]); @@ -56,16 +55,43 @@ $fac->fetch($_GET["facid"]); /* Actions */ /******************************************************************************/ +if ($_POST["action"] == 'update_public' && $user->rights->facture->creer) +{ + $db->begin(); + + $res=$fac->update_note_public($_POST["note_public"]); + if ($res < 0) + { + $db->rollback(); + $msg=$fac->error(); + } + else + { + $db->commit(); + } +} + if ($_POST["action"] == 'update' && $user->rights->facture->creer) { - $fac->update_note($_POST["note"]); + $db->begin(); + + $res=$fac->update_note($_POST["note"]); + if ($res < 0) + { + $db->rollback(); + $msg=$fac->error(); + } + else + { + $db->commit(); + } } -/******************************************************************************/ -/* Fin des Actions */ -/******************************************************************************/ +/******************************************************************************/ +/* Affichage fiche */ +/******************************************************************************/ llxHeader(); @@ -108,19 +134,39 @@ if ($_GET["facid"]) $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none"); print ''; - print ''.$langs->trans("Note").' :'; - - print ''.($fac->note?nl2br($fac->note):" ").""; + // Note publique + print ''.$langs->trans("NotePublic").' :'; + print ''; + if ($_GET["action"] == 'edit') + { + print '
'; + print ''; + print '
"; + print ''; + print '
'; + } + else + { + print ($fac->note_public?nl2br($fac->note_public):" "); + } + print ""; + // Note privée + print ''.$langs->trans("NotePrivate").' :'; + print ''; if ($_GET["action"] == 'edit') { print '
'; print ''; - print '"; - print ''; + print '
"; + print ''; print '
'; } - + else + { + print ($fac->note?nl2br($fac->note):" "); + } + print ""; print ""; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 5560f366288..9d56567b65c 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -54,6 +54,7 @@ class Facture var $tva; var $total; var $note; + var $note_public; var $paye; var $propalid; var $projetid; @@ -94,12 +95,21 @@ class Facture function create($user) { global $langs,$conf; + $this->db->begin(); - /* On positionne en mode brouillon la facture */ - $this->brouillon = 1; + // Nettoyage paramètres + $this->note=trim($this->note); + $this->note_public=trim($this->note_public); + if (! $this->remise) $this->remise = 0 ; + if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; - /* Facture récurrente */ + // On positionne en mode brouillon la facture + $this->brouillon = 1; + + dolibarr_syslog("Facture::create"); + + // Facture récurrente if ($this->fac_rec > 0) { require_once DOL_DOCUMENT_ROOT . '/compta/facture/facture-rec.class.php'; @@ -119,56 +129,60 @@ class Facture // Definition de la date limite $datelim=$this->calculate_date_lim_reglement(); - /* - * Insertion dans la base - */ + // Insertion dans la base $socid = $this->socidp; $number = $this->number; $amount = $this->amount; $remise = $this->remise; - if (! $remise) $remise = 0 ; - if (strlen($this->mode_reglement_id)==0) $this->mode_reglement_id = 0; - if (! $this->projetid) $this->projetid = 'NULL'; - $totalht = ($amount - $remise); -// NE ME SEMBLE PLUS JUSTIFIE ICI -// $tva = tva($totalht); -// $total = $totalht + $tva; - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture (facnumber, fk_soc, datec, amount, remise, remise_percent'; - $sql .= ', datef, note, fk_user_author, fk_projet'; - $sql .= ', fk_cond_reglement, fk_mode_reglement, date_lim_reglement, ref_client) '; - $sql .= " VALUES ('$number','$socid', now(), '$totalht', '$remise'"; - $sql .= ",'$this->remise_percent', ".$this->db->idate($this->date); - $sql .= ",'".addslashes($this->note)."',$user->id, $this->projetid"; - $sql .= ','.$this->cond_reglement_id.','.$this->mode_reglement_id.','.$this->db->idate($datelim).', \''.$this->ref_client.'\')'; - if ( $this->db->query($sql) ) + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture ('; + $sql.= ' facnumber, fk_soc, datec, amount, remise, remise_percent,'; + $sql.= ' datef,'; + $sql.= ' note,'; + $sql.= ' note_public,'; + $sql.= ' fk_user_author, fk_projet,'; + $sql.= ' fk_cond_reglement, fk_mode_reglement, date_lim_reglement, ref_client) '; + $sql.= " VALUES ("; + $sql.= "'$number','$socid', now(), '$totalht', '$remise'"; + $sql.= ",'$this->remise_percent', ".$this->db->idate($this->date); + $sql.= ",".($this->note?"'".addslashes($this->note)."'":"null"); + $sql.= ",".($this->note_public?"'".addslashes($this->note_public)."'":"null"); + $sql.= ",".$user->id; + $sql.= ",".($this->projetid?$this->projetid:"null"); + $sql.= ','.$this->cond_reglement_id; + $sql.= ",".$this->mode_reglement_id; + $sql.= ','.$this->db->idate($datelim); + $sql.= ', \''.$this->ref_client.'\')'; + + $resql=$this->db->query($sql); + if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture'); $sql = 'UPDATE '.MAIN_DB_PREFIX."facture SET facnumber='(PROV".$this->id.")' WHERE rowid=".$this->id; - $this->db->query($sql); + $resql=$this->db->query($sql); - if ($this->id && $this->propalid) + if ($resql && $this->id && $this->propalid) { $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'fa_pr (fk_facture, fk_propal) VALUES ('.$this->id.','.$this->propalid.')'; - $this->db->query($sql); + $resql=$this->db->query($sql); } - if ($this->id && $this->commandeid) + if ($resql && $this->id && $this->commandeid) { $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_fa (fk_facture, fk_commande) VALUES ('.$this->id.','.$this->commandeid.')'; - $this->db->query($sql); + $resql=$this->db->query($sql); } /* - * Produits/services - * - */ + * Produits/services + */ for ($i = 0 ; $i < sizeof($this->products) ; $i++) { $prod = new Product($this->db, $this->products[$i]); - $prod->fetch($this->products[$i]); + $res=$prod->fetch($this->products[$i]); + // multiprix if($conf->global->PRODUIT_MULTIPRICES == 1) { @@ -177,8 +191,12 @@ class Facture $price = $prod->multiprices[$soc->price_level]; } else + { $price = $prod->price; - $result_insert = $this->addline($this->id, + } + + $resql = $this->addline( + $this->id, $prod->libelle, $prod->description, $price, @@ -188,19 +206,20 @@ class Facture $this->products_remise_percent[$i], $this->products_date_start[$i], $this->products_date_end[$i] - ); + ); - if ( $result_insert < 0) + if ($resql < 0) { + $this->error=$this->db->error; dolibarr_print_error($this->db); + break; } } /* - * Produits de la facture récurrente - * - */ - if ($this->fac_rec > 0) + * Produits de la facture récurrente + */ + if ($resql && $this->fac_rec > 0) { for ($i = 0 ; $i < sizeof($_facrec->lignes) ; $i++) { @@ -210,13 +229,14 @@ class Facture $prod->fetch($_facrec->lignes[$i]->produit_id); } - $result_insert = $this->addline($this->id, - addslashes($_facrec->lignes[$i]->desc), - $_facrec->lignes[$i]->subprice, - $_facrec->lignes[$i]->qty, - $_facrec->lignes[$i]->tva_taux, - $_facrec->lignes[$i]->produit_id, - $_facrec->lignes[$i]->remise_percent); + $result_insert = $this->addline( + $this->id, + $_facrec->lignes[$i]->desc, + $_facrec->lignes[$i]->subprice, + $_facrec->lignes[$i]->qty, + $_facrec->lignes[$i]->tva_taux, + $_facrec->lignes[$i]->produit_id, + $_facrec->lignes[$i]->remise_percent); if ( $result_insert < 0) { @@ -225,18 +245,26 @@ class Facture } } - $resql=$this->updateprice($this->id); if ($resql) { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('BILL_CREATE',$this,$user,$langs,$conf); - // Fin appel triggers - - $this->db->commit(); - return $this->id; - } + $resql=$this->updateprice($this->id); + if ($resql) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('BILL_CREATE',$this,$user,$langs,$conf); + // Fin appel triggers + + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -3; + } + } else { $this->db->rollback(); @@ -245,6 +273,8 @@ class Facture } else { + $this->error=$this->db->error(); + dolibarr_syslog("Facture::create error ".$this->error." sql=".$sql); $this->db->rollback(); return -1; } @@ -275,7 +305,7 @@ class Facture } $result_insert = $this->addline($this->id, - addslashes('Remise exceptionnelle'), + 'Remise exceptionnelle', (0 - $remise), 1, '0'); // Une remise est un négatif sur le TTC, on ne doit pas appliquer de TVA, @@ -340,7 +370,7 @@ class Facture $sql = 'SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.total_ttc,f.remise,f.remise_percent'; $sql .= ','.$this->db->pdate('f.datef').' as df, f.fk_projet'; $sql .= ','.$this->db->pdate('f.date_lim_reglement').' as dlr'; - $sql .= ', f.note, f.paye, f.fk_statut, f.fk_user_author'; + $sql .= ', f.note, f.note_public, f.paye, f.fk_statut, f.fk_user_author'; $sql .= ', f.fk_mode_reglement, f.ref_client, p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql .= ', f.fk_cond_reglement, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_facture'; $sql .= ' FROM '.MAIN_DB_PREFIX.'cond_reglement as c, '.MAIN_DB_PREFIX.'facture as f'; @@ -381,7 +411,8 @@ class Facture $this->cond_reglement = $obj->cond_reglement_libelle; $this->cond_reglement_facture = $obj->cond_reglement_libelle_facture; $this->projetid = $obj->fk_projet; - $this->note = stripslashes($obj->note); + $this->note = $obj->note; + $this->note_public = $obj->note_public; $this->user_author = $obj->fk_user_author; $this->lignes = array(); @@ -982,12 +1013,14 @@ class Facture { global $conf; dolibarr_syslog("facture.class.php::addline($facid,$desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$datestart,$dateend,$ventil)"); + if ($this->brouillon) { // Nettoyage paramètres $remise_percent=price2num($remise_percent); $qty=price2num($qty); - if (strlen(trim($qty))==0) $qty=1; + if (! $qty) $qty=1; + if (! $ventil) $ventil=0; if ($fk_product && ! $pu) { @@ -1045,13 +1078,13 @@ class Facture $sql.= ' (fk_facture, description, price, qty, tva_taux, fk_product, remise_percent, subprice, remise, date_start, date_end, fk_code_ventilation, rang)'; if ($conf->global->CHANGE_PROD_DESC) - { - $sql.= " VALUES ($facid, '".addslashes($product_desc)."','$price','$qty','$txtva',"; - } - else - { - $sql.= " VALUES ($facid, '".addslashes($desc)."','$price','$qty','$txtva',"; - } + { + $sql.= " VALUES ($facid, '".addslashes($product_desc)."','$price','$qty','$txtva',"; + } + else + { + $sql.= " VALUES ($facid, '".addslashes($desc)."','$price','$qty','$txtva',"; + } if ($fk_product) { $sql.= "'$fk_product',"; } else { $sql.='0,'; } @@ -1421,16 +1454,16 @@ class Facture } /** - * \brief Mets à jour les commentaires - * \param note note - * \return int <0 si erreur, >0 si ok + * \brief Mets à jour les commentaires privés + * \param note Commentaire + * \return int <0 si ko, >0 si ok */ function update_note($note) { $sql = 'UPDATE '.MAIN_DB_PREFIX."facture SET note = '".addslashes($note)."'"; $sql .= ' WHERE rowid ='. $this->id; - if ($this->db->query($sql) ) + if ($this->db->query($sql)) { $this->note = $note; return 1; @@ -1441,9 +1474,30 @@ class Facture } } + /** + * \brief Mets à jour les commentaires publiques + * \param note_public Commentaire + * \return int <0 si ko, >0 si ok + */ + function update_note_public($note_public) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX."facture SET note_public = '".addslashes($note_public)."'"; + $sql .= ' WHERE rowid ='. $this->id; + + if ($this->db->query($sql)) + { + $this->note_public = $note_public; + return 1; + } + else + { + return -1; + } + } + /** * \brief Charge les informations d'ordre info dans l'objet facture - * \param id Id de la facture a charger + * \param id Id de la facture a charger */ function info($id) { diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 8dc782921fb..5fbb240ce0c 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -31,6 +31,8 @@ ReturnCodeLastAccess=Return code for last database access InformationLastAccess=Information for last database access DolibarrHasDetectedError=Dolibarr has detected a technical error InformationToHelpDiagnose=This is informations that can help to diagnose +NotePublic=Note (public) +NotePrivate=Note (private) yes=yes Yes=Yes no=no diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 672ab546454..572a217b01e 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -31,6 +31,8 @@ ReturnCodeLastAccess=Code retour dernier acces en base InformationLastAccess=Information sur le dernier accès en base DolibarrHasDetectedError=Dolibarr a détecté une erreur technique InformationToHelpDiagnose=Voici les informations qui pourront aider au diagnostic +NotePublic=Note (publique) +NotePrivate=Note (privée) yes=oui Yes=Oui no=non diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 706f6b1ec36..8c9090ba550 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -282,7 +282,7 @@ function dolibarr_get_const($db, $name) if ($resql) { $obj=$db->fetch_object($resql); - $value=stripslashes($obj->value); + $value=$obj->value; } return $value; } diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 07491c3fe8e..5aea88454a5 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -530,6 +530,8 @@ class Product global $langs; global $conf; + dolibarr_syslog("Product::fecth $id=$id ref=$ref"); + // Verification parametres if (! $id && ! $ref) {