Work on expensereport module

This commit is contained in:
Laurent Destailleur 2015-02-15 19:13:16 +01:00
parent 09ef15ea24
commit b00de9707a
12 changed files with 183 additions and 128 deletions

View File

@ -569,8 +569,10 @@ if (empty($reshook))
// Boucle sur chaque taux de tva // Boucle sur chaque taux de tva
$i = 0; $i = 0;
foreach ($object->lines as $line) { foreach ($object->lines as $line)
if($line->total_ht!=0) { // no need to create discount if amount is null {
if ($line->total_ht!=0)
{ // no need to create discount if amount is null
$amount_ht[$line->tva_tx] += $line->total_ht; $amount_ht[$line->tva_tx] += $line->total_ht;
$amount_tva[$line->tva_tx] += $line->total_tva; $amount_tva[$line->tva_tx] += $line->total_tva;
$amount_ttc[$line->tva_tx] += $line->total_ttc; $amount_ttc[$line->tva_tx] += $line->total_ttc;
@ -593,7 +595,8 @@ if (empty($reshook))
$error = 0; $error = 0;
foreach ($amount_ht as $tva_tx => $xxx) { foreach ($amount_ht as $tva_tx => $xxx)
{
$discount->amount_ht = abs($amount_ht[$tva_tx]); $discount->amount_ht = abs($amount_ht[$tva_tx]);
$discount->amount_tva = abs($amount_tva[$tva_tx]); $discount->amount_tva = abs($amount_tva[$tva_tx]);
$discount->amount_ttc = abs($amount_ttc[$tva_tx]); $discount->amount_ttc = abs($amount_ttc[$tva_tx]);

View File

@ -1,8 +1,5 @@
<?php <?php
/* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,16 +12,14 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program. If not, see <http://www.gnu.org/licenses/>.
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/ * or see http://www.gnu.org/
*/ */
/** /**
* \file htdocs/expensereport/core/modules/expensereport/pdf_.modules.php * \file htdocs/core/modules/expensereport/doc/pdf_standard.modules.php
* \ingroup facture * \ingroup expensereport
* \brief File of class to generate invoices from crab model * \brief File of class to generate invoices from standard model
* \author Laurent Destailleur
*/ */
dol_include_once("/expensereport/core/modules/expensereport/modules_expensereport.php"); dol_include_once("/expensereport/core/modules/expensereport/modules_expensereport.php");

View File

@ -1,4 +1,21 @@
<?php <?php
/* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 2 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 <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';

View File

@ -1,8 +1,6 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,8 +13,8 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program. If not, see <http://www.gnu.org/licenses/>.
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/
*/ */
/** /**
@ -333,7 +331,7 @@ class modExpenseReport extends DolibarrModules
* Remove from database constants, boxes and permissions from Dolibarr database. * Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted. * Data directories are not deleted.
* *
* @param string Options * @param string $options Options
* @return int 1 if OK, 0 if KO * @return int 1 if OK, 0 if KO
*/ */
function remove($options='') function remove($options='')

View File

@ -15,8 +15,8 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program. If not, see <http://www.gnu.org/licenses/>.
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/
*/ */
/** /**

View File

@ -14,8 +14,8 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program. If not, see <http://www.gnu.org/licenses/>.
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/
*/ */
/** /**
@ -927,7 +927,7 @@ else if ($action == 'remove_file')
* View * View
*/ */
llxHeader(); llxHeader('', $langs->trans("ExpenseReport"));
$html = new Form($db); $html = new Form($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
@ -1237,7 +1237,7 @@ else
} }
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans("Statut").'</td>'; print '<td>'.$langs->trans("Statut").'</td>';
print '<td style="font-weight:bold;">'.$object->libelle_statut.'</td>'; print '<td style="font-weight:bold;">'.$object->getLibStatut(4).'</td>';
print '</tr>'; print '</tr>';
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans("Note").'</td>'; print '<td>'.$langs->trans("Note").'</td>';
@ -1261,9 +1261,12 @@ else
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans("VALIDATOR").'</td>'; print '<td>'.$langs->trans("VALIDATOR").'</td>';
print '<td>'; print '<td>';
if ($object->fk_user_validator > 0)
{
$userfee=new User($db); $userfee=new User($db);
$userfee->fetch($object->fk_user_validator); $userfee->fetch($object->fk_user_validator);
print $userfee->getNomUrl(1); print $userfee->getNomUrl(1);
}
print '</td></tr>'; print '</td></tr>';
} }
elseif($object->fk_c_expensereport_statuts==4) elseif($object->fk_c_expensereport_statuts==4)
@ -1271,9 +1274,12 @@ else
print '<tr>'; print '<tr>';
print '<td><span style="font-weight:bold;color:red;">'.$langs->trans("CANCEL_USER").'</span></td>'; print '<td><span style="font-weight:bold;color:red;">'.$langs->trans("CANCEL_USER").'</span></td>';
print '<td><span style="font-weight:bold;color:red;">'; print '<td><span style="font-weight:bold;color:red;">';
if ($object->fk_user_cancel > 0)
{
$userfee=new User($db); $userfee=new User($db);
$userfee->fetch($object->fk_user_cancel); $userfee->fetch($object->fk_user_cancel);
print $userfee->getNomUrl(1); print $userfee->getNomUrl(1);
}
print '</span></td></tr>'; print '</span></td></tr>';
print '<tr>'; print '<tr>';
print '<td><span style="font-weight:bold;color:red;">'.$langs->trans("MOTIF_CANCEL").'</span></td>'; print '<td><span style="font-weight:bold;color:red;">'.$langs->trans("MOTIF_CANCEL").'</span></td>';
@ -1289,9 +1295,12 @@ else
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans("VALIDOR").'</td>'; print '<td>'.$langs->trans("VALIDOR").'</td>';
print '<td>'; print '<td>';
if ($object->fk_user_valid > 0)
{
$userfee=new User($db); $userfee=new User($db);
$userfee->fetch($object->fk_user_valid); $userfee->fetch($object->fk_user_valid);
print $userfee->getNomUrl(1); print $userfee->getNomUrl(1);
}
print '</td></tr>'; print '</td></tr>';
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans("DATE_VALIDE").'</td>'; print '<td>'.$langs->trans("DATE_VALIDE").'</td>';
@ -1302,9 +1311,12 @@ else
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans("AUTHOR").'</td>'; print '<td>'.$langs->trans("AUTHOR").'</td>';
print '<td>'; print '<td>';
if ($object->fk_user_author > 0)
{
$userfee=new User($db); $userfee=new User($db);
$userfee->fetch($object->fk_user_author); $userfee->fetch($object->fk_user_author);
print $userfee->getNomUrl(1); print $userfee->getNomUrl(1);
}
print '</td></tr>'; print '</td></tr>';
print '<tr>'; print '<tr>';
@ -1351,12 +1363,10 @@ else
$sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_projet, fde.date,'; $sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_projet, fde.date,';
$sql.= ' fde.fk_c_tva, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc,'; $sql.= ' fde.fk_c_tva, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc,';
$sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,'; $sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,';
$sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref,'; $sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref';
$sql.= ' tva.rowid as tva_id, tva.taux as tva_taux';
$sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det fde'; $sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det fde';
$sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees ctf ON fde.fk_c_type_fees=ctf.id'; $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees ctf ON fde.fk_c_type_fees=ctf.id';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet pjt ON fde.fk_projet=pjt.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet pjt ON fde.fk_projet=pjt.rowid';
$sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_tva tva ON fde.fk_c_tva=tva.rowid';
$sql.= ' WHERE fde.fk_expensereport = '.$id; $sql.= ' WHERE fde.fk_expensereport = '.$id;
$resql = $db->query($sql); $resql = $db->query($sql);
@ -1503,7 +1513,7 @@ else
//print '</div>'; //print '</div>';
// Ajouter une ligne // Ajouter une ligne
if (($object->fk_c_expensereport_statuts==1 || $object->fk_c_expensereport_statuts==99) && $action != 'editline') if (($object->fk_c_expensereport_statuts==0 || $object->fk_c_expensereport_statuts==99) && $action != 'editline')
{ {
print_fiche_titre($langs->trans("AddLine"),'',''); print_fiche_titre($langs->trans("AddLine"),'','');
@ -1570,6 +1580,10 @@ else
} // Fin si c'est payé/validé } // Fin si c'est payé/validé
} }
else
{
dol_print_error($db);
}
} // end edit or not edit } // end edit or not edit
dol_fiche_end(); dol_fiche_end();
@ -1602,7 +1616,7 @@ if ($action != 'create' && $action != 'edit')
* ET fk_user_author == user courant * ET fk_user_author == user courant
* Afficher : "Enregistrer" / "Modifier" / "Supprimer" * Afficher : "Enregistrer" / "Modifier" / "Supprimer"
*/ */
if($user->rights->expensereport->creer AND $object->fk_c_expensereport_statuts==1) if ($user->rights->expensereport->creer AND $object->fk_c_expensereport_statuts==0)
{ {
if ($object->fk_user_author == $user->id) if ($object->fk_user_author == $user->id)
{ {

View File

@ -139,10 +139,10 @@ class ExpenseReport extends CommonObject
$sql.= ", '".$this->db->idate($this->date_fin)."'"; $sql.= ", '".$this->db->idate($this->date_fin)."'";
$sql.= ", '".$this->db->idate($now)."'"; $sql.= ", '".$this->db->idate($now)."'";
$sql.= ", ".($user->id > 0 ? $user->id:"null"); $sql.= ", ".($user->id > 0 ? $user->id:"null");
$sql.= ", ".($this->fk_user_validator > 0 ? $this->fk_user_validator:2); $sql.= ", ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null");
$sql.= ", ".($this->fk_c_expensereport_statuts > 1 ? $this->fk_c_expensereport_statuts:1); $sql.= ", ".($this->fk_c_expensereport_statuts > 1 ? $this->fk_c_expensereport_statuts:0);
$sql.= ", ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:2); $sql.= ", ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null");
$sql.= ", ".($this->note?"'".$this->note."'":"null"); $sql.= ", ".($this->note?"'".$this->db->escape($this->note)."'":"null");
$sql.= ")"; $sql.= ")";
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
@ -263,11 +263,10 @@ class ExpenseReport extends CommonObject
$sql.= " d.date_refuse, d.date_cancel,"; // ACTIONS $sql.= " d.date_refuse, d.date_cancel,"; // ACTIONS
$sql.= " d.total_ht, d.total_ttc, d.total_tva,"; // TOTAUX (int) $sql.= " d.total_ht, d.total_ttc, d.total_tva,"; // TOTAUX (int)
$sql.= " d.date_debut, d.date_fin, d.date_create, d.date_valide, d.date_paiement,"; // DATES (datetime) $sql.= " d.date_debut, d.date_fin, d.date_create, d.date_valide, d.date_paiement,"; // DATES (datetime)
$sql.= " d.fk_user_author, d.fk_user_validator, d.fk_c_expensereport_statuts, d.fk_c_paiement,"; // FOREING KEY (int) $sql.= " d.fk_user_author, d.fk_user_validator, d.fk_c_expensereport_statuts as status, d.fk_c_paiement,";
$sql.= " d.fk_user_valid, d.fk_user_paid,"; // FOREING KEY 2 (int) $sql.= " d.fk_user_valid, d.fk_user_paid,"; // FOREING KEY 2 (int)
$sql.= " dp.libelle as libelle_paiement, dp.code as code_paiement"; // INNER JOIN paiement $sql.= " dp.libelle as libelle_paiement, dp.code as code_paiement"; // INNER JOIN paiement
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." d"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." d LEFT JOIN ".MAIN_DB_PREFIX."c_paiement dp ON d.fk_c_paiement = dp.id";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement dp ON d.fk_c_paiement = dp.id";
$sql.= " WHERE d.rowid = ".$id; $sql.= " WHERE d.rowid = ".$id;
$sql.= $restrict; $sql.= $restrict;
@ -276,7 +275,8 @@ class ExpenseReport extends CommonObject
if ($result) if ($result)
{ {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
if ($obj)
{
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ref = $obj->ref_number; $this->ref = $obj->ref_number;
$this->ref_number = $obj->ref_number; $this->ref_number = $obj->ref_number;
@ -310,7 +310,8 @@ class ExpenseReport extends CommonObject
$user_approver->fetch($this->fk_user_validator); $user_approver->fetch($this->fk_user_validator);
$this->user_validator_infos = dolGetFirstLastname($user_approver->firstname, $user_approver->lastname); $this->user_validator_infos = dolGetFirstLastname($user_approver->firstname, $user_approver->lastname);
$this->fk_c_expensereport_statuts = $obj->fk_c_expensereport_statuts; $this->fk_c_expensereport_statuts = $obj->status;
$this->status = $obj->status;
$this->fk_c_paiement = $obj->fk_c_paiement; $this->fk_c_paiement = $obj->fk_c_paiement;
if ($this->fk_c_expensereport_statuts==5 || $this->fk_c_expensereport_statuts==6) if ($this->fk_c_expensereport_statuts==5 || $this->fk_c_expensereport_statuts==6)
@ -340,7 +341,12 @@ class ExpenseReport extends CommonObject
} }
else else
{ {
$this->error=$db->error(); return 0;
}
}
else
{
$this->error=$db->lasterror();
return -1; return -1;
} }
} }
@ -980,7 +986,7 @@ class ExpenseReport extends CommonObject
function updateline($rowid, $type_fees_id, $projet_id, $c_tva, $comments, $qty, $value_unit, $date, $expensereport_id) function updateline($rowid, $type_fees_id, $projet_id, $c_tva, $comments, $qty, $value_unit, $date, $expensereport_id)
{ {
if ($this->fk_c_expensereport_statuts==1 || $this->fk_c_expensereport_statuts==99) if ($this->fk_c_expensereport_statuts==0 || $this->fk_c_expensereport_statuts==99)
{ {
$this->db->begin(); $this->db->begin();

View File

@ -19,6 +19,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/ */
/** /**

View File

@ -16,6 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/ */
/** /**

View File

@ -14,6 +14,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/ */
/** /**

View File

@ -15,8 +15,8 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program. If not, see <http://www.gnu.org/licenses/>.
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/
*/ */
/** /**
@ -81,7 +81,7 @@ $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
$sql = "SELECT d.rowid, d.ref_number, d.total_ht, d.total_tva, d.total_ttc, d.fk_c_expensereport_statuts,"; $sql = "SELECT d.rowid, d.ref_number, d.total_ht, d.total_tva, d.total_ttc, d.fk_c_expensereport_statuts as status,";
$sql.= " d.date_debut, d.date_fin,"; $sql.= " d.date_debut, d.date_fin,";
$sql.= " u.rowid as id_user, u.firstname, u.lastname"; $sql.= " u.rowid as id_user, u.firstname, u.lastname";
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport d\n"; $sql.= " FROM ".MAIN_DB_PREFIX."expensereport d\n";
@ -266,8 +266,11 @@ if ($resql)
print '<td align="right">'.price($objp->total_tva).'</td>'; print '<td align="right">'.price($objp->total_tva).'</td>';
print '<td align="right">'.price($objp->total_ttc).'</td>'; print '<td align="right">'.price($objp->total_ttc).'</td>';
$expensereporttmp->status=$objp->statut; $expensereporttmp->status=$objp->status;
print '<td align="right" colspan="2">'.$expensereporttmp->getLibStatut(5).'</td>'; print '<td align="right" colspan="2">';
//print $objp->status;
print $expensereporttmp->getLibStatut(5);
print '</td>';
print "</tr>\n"; print "</tr>\n";
$total_total_ht = $total_total_ht + $objp->total_ht; $total_total_ht = $total_total_ht + $objp->total_ht;

View File

@ -1,4 +1,20 @@
<?php <?php
/* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 2 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 <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
require '../main.inc.php'; require '../main.inc.php';
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');