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

View File

@ -1,8 +1,5 @@
<?php
/* Copyright (C) 2004-2010 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>
/* 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
@ -15,16 +12,14 @@
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/expensereport/core/modules/expensereport/pdf_.modules.php
* \ingroup facture
* \brief File of class to generate invoices from crab model
* \author Laurent Destailleur
* \file htdocs/core/modules/expensereport/doc/pdf_standard.modules.php
* \ingroup expensereport
* \brief File of class to generate invoices from standard model
*/
dol_include_once("/expensereport/core/modules/expensereport/modules_expensereport.php");
@ -664,7 +659,7 @@ class pdf_ extends ModeleExpenseReport
/**
* Affiche la grille des lignes de factures
*
*
* @param $pdf Objet PDF
* @param $tab_top Tab top
* @param $tab_height Tab height

View File

@ -1,4 +1,21 @@
<?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';

View File

@ -1,8 +1,6 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
/* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
* 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
@ -15,8 +13,8 @@
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
@ -329,12 +327,12 @@ class modExpenseReport extends DolibarrModules
}
/**
* Function called when module is disabled.
* Function called when module is disabled.
* Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted.
*
* @param string Options
* @return int 1 if OK, 0 if KO
* @param string $options Options
* @return int 1 if OK, 0 if KO
*/
function remove($options='')
{

View File

@ -15,8 +15,8 @@
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**

View File

@ -14,8 +14,8 @@
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
@ -927,7 +927,7 @@ else if ($action == 'remove_file')
* View
*/
llxHeader();
llxHeader('', $langs->trans("ExpenseReport"));
$html = new Form($db);
$formfile = new FormFile($db);
@ -1028,7 +1028,7 @@ else
$object = new ExpenseReport($db);
$result = $object->fetch($id,$user);
if($result)
if ($result)
{
if ($object->fk_user_author != $user->id)
{
@ -1237,7 +1237,7 @@ else
}
print '<tr>';
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 '<td>'.$langs->trans("Note").'</td>';
@ -1261,9 +1261,12 @@ else
print '<tr>';
print '<td>'.$langs->trans("VALIDATOR").'</td>';
print '<td>';
$userfee=new User($db);
$userfee->fetch($object->fk_user_validator);
print $userfee->getNomUrl(1);
if ($object->fk_user_validator > 0)
{
$userfee=new User($db);
$userfee->fetch($object->fk_user_validator);
print $userfee->getNomUrl(1);
}
print '</td></tr>';
}
elseif($object->fk_c_expensereport_statuts==4)
@ -1271,9 +1274,12 @@ else
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;">';
$userfee=new User($db);
$userfee->fetch($object->fk_user_cancel);
print $userfee->getNomUrl(1);
if ($object->fk_user_cancel > 0)
{
$userfee=new User($db);
$userfee->fetch($object->fk_user_cancel);
print $userfee->getNomUrl(1);
}
print '</span></td></tr>';
print '<tr>';
print '<td><span style="font-weight:bold;color:red;">'.$langs->trans("MOTIF_CANCEL").'</span></td>';
@ -1289,9 +1295,12 @@ else
print '<tr>';
print '<td>'.$langs->trans("VALIDOR").'</td>';
print '<td>';
$userfee=new User($db);
$userfee->fetch($object->fk_user_valid);
print $userfee->getNomUrl(1);
if ($object->fk_user_valid > 0)
{
$userfee=new User($db);
$userfee->fetch($object->fk_user_valid);
print $userfee->getNomUrl(1);
}
print '</td></tr>';
print '<tr>';
print '<td>'.$langs->trans("DATE_VALIDE").'</td>';
@ -1302,9 +1311,12 @@ else
print '<tr>';
print '<td>'.$langs->trans("AUTHOR").'</td>';
print '<td>';
$userfee=new User($db);
$userfee->fetch($object->fk_user_author);
print $userfee->getNomUrl(1);
if ($object->fk_user_author > 0)
{
$userfee=new User($db);
$userfee->fetch($object->fk_user_author);
print $userfee->getNomUrl(1);
}
print '</td></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.= ' 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.= ' 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.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref';
$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.= ' 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;
$resql = $db->query($sql);
@ -1503,7 +1513,7 @@ else
//print '</div>';
// 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"),'','');
@ -1570,6 +1580,10 @@ else
} // Fin si c'est payé/validé
}
else
{
dol_print_error($db);
}
} // end edit or not edit
dol_fiche_end();
@ -1602,9 +1616,9 @@ if ($action != 'create' && $action != 'edit')
* ET fk_user_author == user courant
* 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)
{
// Modifier
print '<a class="butAction" href="'.$_SEVER["PHP_SELF"].'?action=edit&id='.$id.'">'.$langs->trans('ModifyInfoGen').'</a>';

View File

@ -139,10 +139,10 @@ class ExpenseReport extends CommonObject
$sql.= ", '".$this->db->idate($this->date_fin)."'";
$sql.= ", '".$this->db->idate($now)."'";
$sql.= ", ".($user->id > 0 ? $user->id:"null");
$sql.= ", ".($this->fk_user_validator > 0 ? $this->fk_user_validator:2);
$sql.= ", ".($this->fk_c_expensereport_statuts > 1 ? $this->fk_c_expensereport_statuts:1);
$sql.= ", ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:2);
$sql.= ", ".($this->note?"'".$this->note."'":"null");
$sql.= ", ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null");
$sql.= ", ".($this->fk_c_expensereport_statuts > 1 ? $this->fk_c_expensereport_statuts:0);
$sql.= ", ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null");
$sql.= ", ".($this->note?"'".$this->db->escape($this->note)."'":"null");
$sql.= ")";
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.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.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.= " dp.libelle as libelle_paiement, dp.code as code_paiement"; // INNER JOIN paiement
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." d";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement dp ON d.fk_c_paiement = dp.id";
$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.= " WHERE d.rowid = ".$id;
$sql.= $restrict;
@ -276,71 +275,78 @@ class ExpenseReport extends CommonObject
if ($result)
{
$obj = $db->fetch_object($result);
$this->id = $obj->rowid;
$this->ref = $obj->ref_number;
$this->ref_number = $obj->ref_number;
$this->total_ht = $obj->total_ht;
$this->total_tva = $obj->total_tva;
$this->total_ttc = $obj->total_ttc;
$this->note = $obj->note;
$this->detail_refuse = $obj->detail_refuse;
$this->detail_cancel = $obj->detail_cancel;
$this->date_debut = $obj->date_debut;
$this->date_fin = $obj->date_fin;
$this->date_paiement = $obj->date_paiement;
$this->date_valide = $obj->date_valide;
$this->date_create = $obj->date_create;
$this->date_refuse = $obj->date_refuse;
$this->date_cancel = $obj->date_cancel;
$this->fk_user_author = $obj->fk_user_author;
$this->fk_user_validator = $obj->fk_user_validator;
$this->fk_user_valid = $obj->fk_user_valid;
$this->fk_user_paid = $obj->fk_user_paid;
$this->fk_user_refuse = $obj->fk_user_refuse;
$this->fk_user_cancel = $obj->fk_user_cancel;
$user_author = new User($this->db);
$user_author->fetch($this->fk_user_author);
$this->user_author_infos = dolGetFirstLastname($user_author->firstname, $user_author->lastname);
$user_approver = new User($this->db);
$user_approver->fetch($this->fk_user_validator);
$this->user_validator_infos = dolGetFirstLastname($user_approver->firstname, $user_approver->lastname);
$this->fk_c_expensereport_statuts = $obj->fk_c_expensereport_statuts;
$this->fk_c_paiement = $obj->fk_c_paiement;
if ($this->fk_c_expensereport_statuts==5 || $this->fk_c_expensereport_statuts==6)
if ($obj)
{
$user_valid = new User($this->db);
$user_valid->fetch($this->fk_user_valid);
$this->user_valid_infos = dolGetFirstLastname($user_valid->firstname, $user_valid->lastname);
}
$this->id = $obj->rowid;
$this->ref = $obj->ref_number;
$this->ref_number = $obj->ref_number;
$this->total_ht = $obj->total_ht;
$this->total_tva = $obj->total_tva;
$this->total_ttc = $obj->total_ttc;
$this->note = $obj->note;
$this->detail_refuse = $obj->detail_refuse;
$this->detail_cancel = $obj->detail_cancel;
if ($this->fk_c_expensereport_statuts==6)
$this->date_debut = $obj->date_debut;
$this->date_fin = $obj->date_fin;
$this->date_paiement = $obj->date_paiement;
$this->date_valide = $obj->date_valide;
$this->date_create = $obj->date_create;
$this->date_refuse = $obj->date_refuse;
$this->date_cancel = $obj->date_cancel;
$this->fk_user_author = $obj->fk_user_author;
$this->fk_user_validator = $obj->fk_user_validator;
$this->fk_user_valid = $obj->fk_user_valid;
$this->fk_user_paid = $obj->fk_user_paid;
$this->fk_user_refuse = $obj->fk_user_refuse;
$this->fk_user_cancel = $obj->fk_user_cancel;
$user_author = new User($this->db);
$user_author->fetch($this->fk_user_author);
$this->user_author_infos = dolGetFirstLastname($user_author->firstname, $user_author->lastname);
$user_approver = new User($this->db);
$user_approver->fetch($this->fk_user_validator);
$this->user_validator_infos = dolGetFirstLastname($user_approver->firstname, $user_approver->lastname);
$this->fk_c_expensereport_statuts = $obj->status;
$this->status = $obj->status;
$this->fk_c_paiement = $obj->fk_c_paiement;
if ($this->fk_c_expensereport_statuts==5 || $this->fk_c_expensereport_statuts==6)
{
$user_valid = new User($this->db);
$user_valid->fetch($this->fk_user_valid);
$this->user_valid_infos = dolGetFirstLastname($user_valid->firstname, $user_valid->lastname);
}
if ($this->fk_c_expensereport_statuts==6)
{
$user_paid = new User($this->db);
$user_paid->fetch($this->fk_user_paid);
$this->user_paid_infos = dolGetFirstLastname($user_paid->firstname, $user_paid->lastname);
}
$this->libelle_statut = $obj->libelle_statut;
$this->libelle_paiement = $obj->libelle_paiement;
$this->code_statut = $obj->code_statut;
$this->code_paiement = $obj->code_paiement;
$this->lignes = array();
$result=$this->fetch_lines();
return 1;
}
else
{
$user_paid = new User($this->db);
$user_paid->fetch($this->fk_user_paid);
$this->user_paid_infos = dolGetFirstLastname($user_paid->firstname, $user_paid->lastname);
return 0;
}
$this->libelle_statut = $obj->libelle_statut;
$this->libelle_paiement = $obj->libelle_paiement;
$this->code_statut = $obj->code_statut;
$this->code_paiement = $obj->code_paiement;
$this->lignes = array();
$result=$this->fetch_lines();
return 1;
}
else
{
$this->error=$db->error();
$this->error=$db->lasterror();
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)
{
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();

View File

@ -19,6 +19,7 @@
*
* 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/
*/
/**

View File

@ -16,6 +16,7 @@
*
* 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/
*/
/**

View File

@ -14,6 +14,7 @@
*
* 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/
*/
/**
@ -46,15 +47,15 @@ if ($id)
$object = new ExpenseReport($db);
$object->fetch($id);
$object->info($id);
$head = trip_prepare_head($object);
dol_fiche_head($head, 'info', $langs->trans("TripCard"), 0, 'trip');
print '<table width="100%"><tr><td>';
dol_print_object_info($object);
print '</td></tr></table>';
print '</div>';
}

View File

@ -15,8 +15,8 @@
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
@ -81,7 +81,7 @@ $offset = $limit * $page;
$pageprev = $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.= " u.rowid as id_user, u.firstname, u.lastname";
$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_ttc).'</td>';
$expensereporttmp->status=$objp->statut;
print '<td align="right" colspan="2">'.$expensereporttmp->getLibStatut(5).'</td>';
$expensereporttmp->status=$objp->status;
print '<td align="right" colspan="2">';
//print $objp->status;
print $expensereporttmp->getLibStatut(5);
print '</td>';
print "</tr>\n";
$total_total_ht = $total_total_ht + $objp->total_ht;

View File

@ -1,4 +1,20 @@
<?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_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');