diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 6d464cceb29..b4aff6002d0 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -1792,7 +1792,8 @@ abstract class CommonObject
if (! $resql)
{
$error++;
- $this->error=$this->db->error();
+ $this->error=$this->db->lasterror();
+ $this->error[]=$this->db->lasterror();
}
}
diff --git a/htdocs/core/lib/expensereport.lib.php b/htdocs/core/lib/expensereport.lib.php
new file mode 100644
index 00000000000..f46e6416ec6
--- /dev/null
+++ b/htdocs/core/lib/expensereport.lib.php
@@ -0,0 +1,61 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ * or see http://www.gnu.org/
+ */
+
+/**
+ * \file htdocs/core/lib/expensereport.lib.php
+ * \brief Functions for module expensereport
+ */
+
+/**
+ * Prepare array with list of tabs
+ *
+ * @param Object $object Object related to tabs
+ * @return array Array of tabs to show
+ */
+function expensereport_prepare_head($object)
+{
+ global $langs, $conf;
+
+ $h = 0;
+ $head = array();
+
+ $head[$h][0] = DOL_URL_ROOT . '/expensereport/card.php?id=' . $object->id;
+ $head[$h][1] = $langs->trans("Card");
+ $head[$h][2] = 'card';
+ $h++;
+
+ // Show more tabs from modules
+ // Entries must be declared in modules descriptor with line
+ // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
+ // $this->tabs = array('entity:-tabname); to remove a tab
+ complete_head_from_modules($conf,$langs,$object,$head,$h,'expensereport');
+
+ $head[$h][0] = DOL_URL_ROOT.'/expensereport/document.php?id='.$object->id;
+ $head[$h][1] = $langs->trans("Documents");
+ $head[$h][2] = 'documents';
+ $h++;
+
+ $head[$h][0] = DOL_URL_ROOT . '/expensereport/info.php?id=' . $object->id;
+ $head[$h][1] = $langs->trans("Info");
+ $head[$h][2] = 'info';
+ $h++;
+
+ complete_head_from_modules($conf,$langs,$object,$head,$h,'expensereport','remove');
+
+ return $head;
+}
diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php
index 4eabd0ea765..b555746c05b 100755
--- a/htdocs/expensereport/card.php
+++ b/htdocs/expensereport/card.php
@@ -29,17 +29,20 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php');
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formmail.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formprojet.class.php");
+require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
-require_once(DOL_DOCUMENT_ROOT."/core/lib/trip.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/core/lib/expensereport.lib.php");
dol_include_once('/expensereport/core/modules/expensereport/modules_expensereport.php');
dol_include_once("/expensereport/class/expensereport.class.php");
$langs->load("trips");
$action=GETPOST('action');
+$cancel=GETPOST('cancel');
$date_start = dol_mktime(0, 0, 0, GETPOST('date_debutmonth'), GETPOST('date_debutday'), GETPOST('date_debutyear'));
$date_end = dol_mktime(0, 0, 0, GETPOST('date_finmonth'), GETPOST('date_finday'), GETPOST('date_finyear'));
-
+$date = dol_mktime(0, 0, 0, GETPOST('datemonth'), GETPOST('dateday'), GETPOST('dateyear'));
+$fk_projet=GETPOST('fk_projet');
// If socid provided by ajax company selector
if (! empty($_REQUEST['socid_id']))
@@ -54,8 +57,6 @@ $id=GETPOST("id",'int');
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'expensereport', 0, 'expensereport');
-$mesg="";
-
// Hack to use expensereport dir
$rootfordata = DOL_DATA_ROOT;
@@ -74,6 +75,8 @@ $conf->expensereport->dir_output = $rootfordata.'/expensereport';
* Actions
*/
+if ($cancel) $action='';
+
if ($action == 'confirm_delete' && $_GET["confirm"] == "yes" && $id > 0 && $user->rights->expensereport->supprimer)
{
$object = new ExpenseReport($db);
@@ -103,10 +106,12 @@ if ($action == 'add' && $user->rights->expensereport->creer)
if ($object->periode_existe($user,dol_print_date($object->date_debut, 'dayrfc'),dol_print_date($object->date_fin, 'dayrfc')))
{
+ $error++;
setEventMessage($langs->trans("ErrorDoubleDeclaration"),'errors');
$action='create';
}
- else
+
+ if (! $error)
{
$db->begin();
@@ -130,7 +135,7 @@ if ($action == 'add' && $user->rights->expensereport->creer)
if ($action == 'update' && $user->rights->expensereport->creer)
{
$object = new ExpenseReport($db);
- $object->fetch($_POST['id'],$user);
+ $object->fetch($id);
$object->date_debut = $date_start;
$object->date_fin = $date_end;
@@ -158,7 +163,7 @@ if ($action == 'update' && $user->rights->expensereport->creer)
if ($action == "confirm_save" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer)
{
$object = new ExpenseReport($db);
- $object->fetch($id,$user);
+ $object->fetch($id);
$result = $object->set_save($user);
if ($result > 0)
{
@@ -195,8 +200,8 @@ if ($action == "confirm_save" && GETPOST("confirm") == "yes" && $id > 0 && $user
if($resultPDF):
// ATTACHMENT
$filename=array(); $filedir=array(); $mimetype=array();
- array_push($filename,dol_sanitizeFileName($object->ref_number).".pdf");
- array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref_number) . "/" . dol_sanitizeFileName($object->ref_number).".pdf");
+ array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
+ array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf");
array_push($mimetype,"application/pdf");
// PREPARE SEND
@@ -232,7 +237,7 @@ if ($action == "confirm_save" && GETPOST("confirm") == "yes" && $id > 0 && $user
if ($action == "confirm_save_from_refuse" && $_GET["confirm"] == "yes" && $id > 0 && $user->rights->expensereport->creer)
{
$object = new ExpenseReport($db);
- $object->fetch($id,$user);
+ $object->fetch($id);
$result = $object->set_save_from_refuse($user);
if ($result > 0)
{
@@ -256,7 +261,7 @@ if ($action == "confirm_save_from_refuse" && $_GET["confirm"] == "yes" && $id >
$dateRefusEx = explode(" ",$object->date_refuse);
$message = "Bonjour {$destinataire->firstname},\n\n";
- $message.= "Le {$dateRefusEx[0]} à {$dateRefusEx[1]} vous avez refusé d'approuver la note de frais \"{$object->ref_number}\". Vous aviez émis le motif suivant : {$object->detail_refuse}\n\n";
+ $message.= "Le {$dateRefusEx[0]} à {$dateRefusEx[1]} vous avez refusé d'approuver la note de frais \"{$object->ref}\". Vous aviez émis le motif suivant : {$object->detail_refuse}\n\n";
$message.= "L'auteur vient de modifier la note de frais, veuillez trouver la nouvelle version en pièce jointe.\n";
$message.= "- Déclarant : {$expediteur->firstname} {$expediteur->lastname}\n";
$message.= "- Période : du {$object->date_debut} au {$object->date_fin}\n";
@@ -270,8 +275,8 @@ if ($action == "confirm_save_from_refuse" && $_GET["confirm"] == "yes" && $id >
if($resultPDF):
// ATTACHMENT
$filename=array(); $filedir=array(); $mimetype=array();
- array_push($filename,dol_sanitizeFileName($object->ref_number).".pdf");
- array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref_number) . "/" . dol_sanitizeFileName($object->ref_number).".pdf");
+ array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
+ array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref_number).".pdf");
array_push($mimetype,"application/pdf");
// PREPARE SEND
@@ -308,16 +313,13 @@ if ($action == "confirm_save_from_refuse" && $_GET["confirm"] == "yes" && $id >
if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->to_validate)
{
$object = new ExpenseReport($db);
- $object->fetch($id,$user);
+ $object->fetch($id);
$result = $object->set_valide($user);
if ($result > 0)
{
if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
{
- $object = new ExpenseReport($db);
- $object->fetch($id,$user);
-
// Send mail
// TO
@@ -338,7 +340,7 @@ if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $
// CONTENT
$message = "Bonjour {$destinataire->firstname},\n\n";
- $message.= "Votre note de frais \"{$object->ref_number}\" vient d'être approuvé!\n";
+ $message.= "Votre note de frais \"{$object->ref}\" vient d'être approuvé!\n";
$message.= "- Approbateur : {$expediteur->firstname} {$expediteur->lastname}\n";
$message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
$message.= "Bien cordialement,\n' SI";
@@ -350,12 +352,12 @@ if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $
if($resultPDF):
// ATTACHMENT
$filename=array(); $filedir=array(); $mimetype=array();
- array_push($filename,dol_sanitizeFileName($object->ref_number).".pdf");
+ array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
array_push($filedir, $conf->expensereport->dir_output.
"/".
- dol_sanitizeFileName($object->ref_number) .
+ dol_sanitizeFileName($object->ref) .
"/".
- dol_sanitizeFileName($object->ref_number).
+ dol_sanitizeFileName($object->ref).
".pdf"
);
array_push($mimetype,"application/pdf");
@@ -394,16 +396,13 @@ if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $
if ($action == "confirm_refuse" && $_POST['confirm']=="yes" && !empty($_POST['detail_refuse']) && $id > 0 && $user->rights->expensereport->to_validate)
{
$object = new ExpenseReport($db);
- $object->fetch($id,$user);
+ $object->fetch($id);
$result = $object->set_refuse($user,$_POST['detail_refuse']);
if ($result > 0)
{
if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
{
- $object = new ExpenseReport($db);
- $object->fetch($id,$user);
-
// Send mail
// TO
@@ -421,7 +420,7 @@ if ($action == "confirm_refuse" && $_POST['confirm']=="yes" && !empty($_POST['de
// CONTENT
$message = "Bonjour {$destinataire->firstname},\n\n";
- $message.= "Votre note de frais \"{$object->ref_number}\" vient d'être refusée.\n";
+ $message.= "Votre note de frais \"{$object->ref}\" vient d'être refusée.\n";
$message.= "- Refuseur : {$expediteur->firstname} {$expediteur->lastname}\n";
$message.= "- Motif de refus : {$_POST['detail_refuse']}\n";
$message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
@@ -458,7 +457,8 @@ if ($action == "confirm_refuse" && $_POST['confirm']=="yes" && !empty($_POST['de
if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && !empty($_POST['detail_cancel']) && $id > 0 && $user->rights->expensereport->to_validate)
{
$object = new ExpenseReport($db);
- $object->fetch($id,$user);
+ $object->fetch($id);
+
if($user->id == $object->fk_user_validator)
{
$result = $object->set_cancel($user,$_POST['detail_cancel']);
@@ -467,8 +467,6 @@ if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && !empty($_POST['d
{
if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
{
- $object = new ExpenseReport($db);
- $object->fetch($id,$user);
// Send mail
@@ -487,7 +485,7 @@ if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && !empty($_POST['d
// CONTENT
$message = "Bonjour {$destinataire->firstname},\n\n";
- $message.= "Votre note de frais \"{$object->ref_number}\" vient d'être annulée.\n";
+ $message.= "Votre note de frais \"{$object->ref}\" vient d'être annulée.\n";
$message.= "- Annuleur : {$expediteur->firstname} {$expediteur->lastname}\n";
$message.= "- Motif d'annulation : {$_POST['detail_cancel']}\n";
$message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
@@ -532,14 +530,12 @@ if ($action == "confirm_paid" && $_GET['confirm']=="yes" && $id > 0 && $user->ri
{
$object = new ExpenseReport($db);
$object->fetch($id,$user);
+
$result = $object->set_paid($user);
if ($result > 0)
{
if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
{
- $object = new ExpenseReport($db);
- $object->fetch($id,$user);
-
// Send mail
// TO
@@ -557,7 +553,7 @@ if ($action == "confirm_paid" && $_GET['confirm']=="yes" && $id > 0 && $user->ri
// CONTENT
$message = "Bonjour {$destinataire->firstname},\n\n";
- $message.= "Votre note de frais \"{$object->ref_number}\" vient d'être payée.\n";
+ $message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n";
$message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n";
$message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
$message.= "Bien cordialement,\n' SI";
@@ -579,13 +575,13 @@ if ($action == "confirm_paid" && $_GET['confirm']=="yes" && $id > 0 && $user->ri
$idAccount = 1;
$object = new ExpenseReport($db);
- $object->fetch($idTrip,$user);
+ $object->fetch($idTrip);
$datePaiement = explode("-",$object->date_paiement);
$dateop = dol_mktime(12,0,0,$datePaiement[1],$datePaiement[2],$datePaiement[0]);
$operation = $object->code_paiement;
- $label = "Règlement ".$object->ref_number;
+ $label = "Règlement ".$object->ref;
$amount = - price2num($object->total_ttc);
$num_chq = '';
$cat1 = '';
@@ -629,7 +625,7 @@ if ($action == "confirm_paid" && $_GET['confirm']=="yes" && $id > 0 && $user->ri
if ($action == "confirm_brouillonner" && $_GET['confirm']=="yes" && $id > 0 && $user->rights->expensereport->creer)
{
$object = new ExpenseReport($db);
- $object->fetch($id,$user);
+ $object->fetch($id);
if($user->id == $object->fk_user_author OR $user->id == $object->fk_user_validator)
{
$result = $object->set_draft($user);
@@ -651,133 +647,107 @@ if ($action == "confirm_brouillonner" && $_GET['confirm']=="yes" && $id > 0 && $
if ($action == "addline")
{
+ $error = 0;
+
$db->begin();
- $object_ligne = new ExpenseReportLigne($db);
+ $object_ligne = new ExpenseReportLine($db);
- $object_ligne->comments = empty($_POST['comments'])?"Aucun commentaire.":$_POST['comments'];
+ $object_ligne->comments = GETPOST('comments');
$object_ligne->qty = empty($_POST['qty'])?1:$_POST['qty'];
- // Convertion de "," en "." dans le nombre entré dans le champ
- if(preg_match("#,#",$_POST['value_unit']))
- {
- $object_ligne->value_unit = preg_replace("#,#",".",$_POST['value_unit']);
- }
- else
- {
- $object_ligne->value_unit = $_POST['value_unit'];
- }
+ $object_ligne->value_unit = price2num(GETPOST('value_unit'));
+ $object_ligne->value_unit = price2num($object_ligne->value_unit,'MU');
- $object_ligne->value_unit = number_format($object_ligne->value_unit,3,'.','');
+ $object_ligne->date = $date;
- $date = explode("/",$_POST['date']);
- $object_ligne->date = $date[2]."-".$date[1]."-".$date[0];
+ $object_ligne->fk_c_type_fees = GETPOST('fk_c_type_fees');
- $object_ligne->fk_c_type_fees = empty($_POST['fk_c_type_fees'])?1:$_POST['fk_c_type_fees'];
-
- // Get tax id from rate
- $tva_tx=GETPOST('fk_c_tva');
- $sql = "SELECT t.rowid, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as p";
- $sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$mysoc->country_code."'";
- $sql .= " AND t.taux = ".$db->escape($tva_tx)." AND t.active = 1";
-
- dol_syslog("get_localtax sql=".$sql);
- $resql=$db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- $tva=$obj->rowid;
- }
- else dol_print_error($db);
-
- // Force la TVA à 0% lorsque c'est du transport
- if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
- {
- if ($object_ligne->fk_c_type_fees==10)
- {
- $tva = 15; // TODO A virer le hardcoding
- }
- }
+ $tva=GETPOST('vatrate');
$object_ligne->fk_c_tva = $tva;
- $object_ligne->fk_projet = $_POST['fk_projet'];
+ $object_ligne->fk_projet = $fk_projet;
- // Tests des données rentrées
- $error = false;
+ if (! GETPOST('fk_c_type_fees') > 0)
+ {
+ $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")),'errors');
+ $action='';
+ }
+ if (GETPOST('vatrate') < 0 || GETPOST('vatrate') == '')
+ {
+ $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Vat")),'errors');
+ $action='';
+ }
// Si aucun projet n'est défini
- if (empty($object_ligne->fk_projet) || $object_ligne->fk_projet==-1)
+ if ($conf->projet->enabled)
{
- $error = true;
- $text_error[] = "NO_PROJECT";
+ if (empty($object_ligne->fk_projet) || $object_ligne->fk_projet==-1)
+ {
+ $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Project")), 'errors');
+ }
}
// Si aucune date n'est rentrée
- if($object_ligne->date=="--"):
- $error = true;
- $text_error[] = "NO_DATE";
- endif;
+ if (empty($object_ligne->date) || $object_ligne->date=="--")
+ {
+ $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors');
+ }
// Si aucun prix n'est rentré
- if($object_ligne->value_unit==0):
- $error = true;
- $text_error[] = "NO_PRICE";
- endif;
+ if($object_ligne->value_unit==0)
+ {
+ $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UP")), 'errors');
+ }
// S'il y'a eu au moins une erreur
- if($error)
- {
- $mesg = implode(",",$text_error);
- Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['fk_expensereport']."&mesg=$mesg");
- exit;
- }
- else
+ if (! $error)
{
$object_ligne->fk_expensereport = $_POST['fk_expensereport'];
- $object_ligne->fetch_taux($object_ligne->fk_c_tva);
-
// Calculs des totos
$object_ligne->total_ttc = $object_ligne->value_unit * $object_ligne->qty;
- $object_ligne->total_ttc = number_format($object_ligne->total_ttc,2,'.','');
+ $object_ligne->total_ttc = price2num($object_ligne->total_ttc,'MT');
- $tx_tva = $object_ligne->tva_taux/100;
+ $object_ligne->tva_taux = GETPOST('vatrate');
+
+ $tx_tva = $object_ligne->tva_taux / 100;
$tx_tva = $tx_tva + 1;
$object_ligne->total_ht = $object_ligne->total_ttc / $tx_tva;
$object_ligne->total_ht = price2num($object_ligne->total_ht,'MT');
$object_ligne->total_tva = $object_ligne->total_ttc - $object_ligne->total_ht;
- // Fin calculs des totos
$result = $object_ligne->insert();
if ($result > 0)
{
- $object = new ExpenseReport($db);
- $object->fetch($_POST['fk_expensereport'],$user);
- $object->update_totaux_add($object_ligne->total_ht,$object_ligne->total_tva);
-
$db->commit();
- Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['fk_expensereport']);
+ header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_GET['id']);
exit;
}
else
{
dol_print_error($db,$object->error);
$db->rollback();
- exit;
}
}
+
+ $action='';
}
if ($action == 'confirm_delete_line' && $_POST["confirm"] == "yes")
{
$object = new ExpenseReport($db);
- $object->fetch($_GET["id"],$user);
+ $object->fetch($id);
- $object_ligne = new ExpenseReportLigne($db);
+ $object_ligne = new ExpenseReportLine($db);
$object_ligne->fetch($_GET["rowid"]);
$total_ht = $object_ligne->total_ht;
$total_tva = $object_ligne->total_tva;
@@ -798,60 +768,43 @@ if ($action == 'confirm_delete_line' && $_POST["confirm"] == "yes")
if ($action == "updateligne" )
{
$object = new ExpenseReport($db);
-
- $object_id = GETPOST('id','int');
- $object->fetch($object_id,$user);
+ $object->fetch($id);
$rowid = $_POST['rowid'];
- $type_fees_id = empty($_POST['fk_c_type_fees'])?1:$_POST['fk_c_type_fees'];
-
- // Get tax id from rate
- $tva_tx=GETPOST('fk_c_tva');
- $sql = "SELECT t.rowid, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as p";
- $sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$mysoc->country_code."'";
- $sql .= " AND t.taux = ".$db->escape($tva_tx)." AND t.active = 1";
-
- dol_syslog("get_localtax sql=".$sql);
- $resql=$db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- $c_tva=$obj->rowid;
- }
- else dol_print_error($db);
-
- // Force la TVA à 0% lorsque c'est du transport
- if ($type_fees_id==10)
- {
- $c_tva = 15;
- }
-
+ $type_fees_id = GETPOST('fk_c_type_fees');
+ $c_tva=GETPOST('vatrate');
$object_ligne->fk_c_tva = $c_tva;
- $projet_id = $_POST['fk_projet'];
- $comments = $_POST['comments'];
- $qty = $_POST['qty'];
+ $projet_id = $fk_projet;
+ $comments = GETPOST('comments');
+ $qty = GETPOST('qty');
+ $value_unit = GETPOST('value_unit');
- // Convertion de "," en "." dans le nombre entré dans le champ
- if(preg_match("#,#",$_POST['value_unit'])):
- $value_unit = preg_replace("#,#",".",$_POST['value_unit']);
- else:
- $value_unit = $_POST['value_unit'];
- endif;
-
- $date = explode("/",$_POST['date']);
- $date = $date[2]."-".$date[1]."-".$date[0];
-
- $result = $object->updateline($rowid, $type_fees_id, $projet_id, $c_tva, $comments, $qty, $value_unit, $date, $object_id);
- if ($result >= 0)
+ if (! GETPOST('fk_c_type_fees') > 0)
{
- $object->recalculer($object_id);
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object_id);
- exit;
+ $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")),'errors');
+ $action='';
}
- else
+ if (GETPOST('vatrate') < 0 || GETPOST('vatrate') == '')
{
- setEventMessages($object->error, $object->errors, 'errors');
+ $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Vat")),'errors');
+ $action='';
+ }
+
+ if (! $error)
+ {
+ $result = $object->updateline($rowid, $type_fees_id, $projet_id, $c_tva, $comments, $qty, $value_unit, $date, $object_id);
+ if ($result >= 0)
+ {
+ $object->recalculer($object_id);
+ header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object_id);
+ exit;
+ }
+ else
+ {
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
}
}
@@ -876,7 +829,7 @@ if ($action == "recalc" && $id > 0)
if ($action == 'builddoc') // En get ou en post
{
$depl = new ExpenseReport($db, 0, $_GET['id']);
- $depl->fetch($_GET['id'],$user);
+ $depl->fetch($id);
if ($_REQUEST['model'])
{
@@ -929,10 +882,10 @@ else if ($action == 'remove_file')
llxHeader('', $langs->trans("ExpenseReport"));
-$html = new Form($db);
-$formfile = new FormFile($db);
$form = new Form($db);
+$formfile = new FormFile($db);
$formproject = new FormProjets($db);
+$projecttmp = new Project($db);
if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
{
@@ -976,13 +929,13 @@ if ($action == 'create')
print '
';
print '| '.$langs->trans("DateStart").' | ';
print '';
- $html->select_date($date_start?$date_start:-1,'date_debut',0,0,0,'',1,1);
+ $form->select_date($date_start?$date_start:-1,'date_debut',0,0,0,'',1,1);
print ' | ';
print '
';
print '';
print '| '.$langs->trans("DateEnd").' | ';
print '';
- $html->select_date($date_end?$date_end:-1,'date_fin',0,0,0,'',1,1);
+ $form->select_date($date_end?$date_end:-1,'date_fin',0,0,0,'',1,1);
print ' | ';
print '
';
print '';
@@ -990,8 +943,8 @@ if ($action == 'create')
print '| ';
$object = new ExpenseReport($db);
$include_users = $object->fetch_users_approver_expensereport();
- $s=$html->select_dolusers((GETPOST('fk_user_validator')?GETPOST('fk_user_validator'):$conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR), "fk_user_validator", 1, "", 0, $include_users);
- print $html->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
+ $s=$form->select_dolusers((GETPOST('fk_user_validator')?GETPOST('fk_user_validator'):$conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR), "fk_user_validator", 1, "", 0, $include_users);
+ print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
print ' | ';
print '
';
if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
@@ -999,7 +952,7 @@ if ($action == 'create')
print '';
print '| '.$langs->trans("ModePaiement").' | ';
print '';
- $html->select_types_paiements(2,'fk_c_paiement');
+ $form->select_types_paiements(2,'fk_c_paiement');
print ' | ';
print '
';
}
@@ -1026,9 +979,9 @@ else
if($id > 0)
{
$object = new ExpenseReport($db);
- $result = $object->fetch($id,$user);
+ $result = $object->fetch($id);
- if ($result)
+ if ($result > 0)
{
if ($object->fk_user_author != $user->id)
{
@@ -1048,19 +1001,20 @@ else
}
}
- //$head = trip_prepare_head($object);
-
+ $head = expensereport_prepare_head($object);
+ /*
$head[0][0] = $_SERVER['PHP_SELF'].'?id='.$object->id;
$head[0][1] = $langs->trans('Card');
$head[0][2] = 'card';
- $h++;
-
- dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
+ $h++;*/
if ($action == 'edit' && ($object->fk_c_expensereport_statuts < 3 || $object->fk_c_expensereport_statuts==99))
{
print "