task #11004: Create invoice from intervention

This commit is contained in:
Juanjo Menent 2011-07-01 16:24:44 +00:00
parent 8f7b41d3f2
commit 08cdc71a47
8 changed files with 186 additions and 24 deletions

View File

@ -22,7 +22,7 @@
* \file htdocs/core/class/commonobject.class.php
* \ingroup core
* \brief File of parent class of all other business classes (invoices, contracts, proposals, orders, ...)
* \version $Id: commonobject.class.php,v 1.140 2011/06/30 13:27:20 hregis Exp $
* \version $Id: commonobject.class.php,v 1.141 2011/07/01 16:24:45 simnandez Exp $
*/
@ -1287,6 +1287,7 @@ class CommonObject
if ($objecttype == 'delivery') { $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; }
if ($objecttype == 'invoice_supplier') { $classpath = 'fourn/class'; }
if ($objecttype == 'order_supplier') { $classpath = 'fourn/class'; }
if ($objecttype == 'fichinter') {$classpatch = 'fichinter/class'; $subelement ='fichinter'; $module ='ficheinter';}
$classfile = strtolower($subelement); $classname = ucfirst($subelement);
if ($objecttype == 'invoice_supplier') { $classfile = 'fournisseur.facture'; $classname='FactureFournisseur'; }

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
*
* 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
@ -21,7 +22,7 @@
/** \file htdocs/fichinter/class/fichinter.class.php
* \ingroup ficheinter
* \brief Fichier de la classe des gestion des fiches interventions
* \version $Id$
* \version $Id: fichinter.class.php,v 1.17 2011/07/01 16:24:44 simnandez Exp $
*/
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
@ -50,7 +51,7 @@ class Fichinter extends CommonObject
var $datev;
var $datem;
var $duree;
var $statut; // 0=draft, 1=validated
var $statut; // 0=draft, 1=validated, 2=invoiced
var $description;
var $note_private;
var $note_public;
@ -75,8 +76,10 @@ class Fichinter extends CommonObject
// List of language codes for status
$this->statuts[0]='Draft';
$this->statuts[1]='Validated';
$this->statuts[2]='Invoiced';
$this->statuts_short[0]='Draft';
$this->statuts_short[1]='Validated';
$this->statuts_short[2]='Invoiced';
}
@ -236,7 +239,15 @@ class Fichinter extends CommonObject
$this->modelpdf = $obj->model_pdf;
if ($this->statut == 0) $this->brouillon = 1;
/*
* Lines
*/
$result=$this->fetch_lines();
if ($result < 0)
{
return -3;
}
$this->db->free($resql);
return 1;
}
@ -337,6 +348,31 @@ class Fichinter extends CommonObject
}
}
}
/**
* set intervetnion as billed
* @return int <0 si ko, >0 si ok
*/
function setBilled()
{
global $conf;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'fichinter SET fk_statut = 2';
$sql.= ' WHERE rowid = '.$this->id;
$sql.= " AND entity = ".$conf->entity;
$sql.= " AND fk_statut = 1";
if ($this->db->query($sql) )
{
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* \brief Retourne le libelle du statut
@ -370,21 +406,25 @@ class Fichinter extends CommonObject
{
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]);
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]);
if ($statut==2) return img_picto($langs->trans('StatusInterInvoiced'),'statut6').' '.$langs->trans('StatusOrderProcessed');
}
if ($mode == 3)
{
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
if ($statut==2) return img_picto($langs->trans('StatusInterInvoiced'),'statut6');
}
if ($mode == 4)
{
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
if ($statut==2) return img_picto($langs->trans('StatusInterInvoiced'),'statut6').' '.$langs->trans('StatusInterInvoiced');
}
if ($mode == 5)
{
if ($statut==0) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
if ($statut==1) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
if ($statut==2) return $langs->trans('StatusInterInvoiced').' '.img_picto($langs->trans('StatusInterInvoiced'),'statut6');
}
}
@ -522,18 +562,30 @@ class Fichinter extends CommonObject
$error=0;
$this->db->begin();
if (! $error)
// Delete linked object
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element";
$sql.= " WHERE fk_target = ".$this->id;
$sql.= " AND targettype = '".$this->element."'";
dol_syslog("Fichinter::delete sql=".$sql);
if (! $this->db->query($sql) )
{
// Delete linked contacts
$res = $this->delete_linked_contact();
if ($res < 0)
{
$this->error='ErrorFailToDeleteLinkedContact';
//$error++;
$this->db->rollback();
return 0;
}
dol_syslog("Fichinter::delete error", LOG_ERR);
$error++;
}
// Delete linked contacts
$res = $this->delete_linked_contact();
if ($res < 0)
{
$this->error='ErrorFailToDeleteLinkedContact';
$error++;
}
if ($err > 0)
{
$this->db->rollback();
return -1;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
@ -767,7 +819,7 @@ class Fichinter extends CommonObject
*/
function fetch_lines()
{
$sql = 'SELECT rowid';
$sql = 'SELECT rowid, description, duree, date, rang';
$sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet';
$sql.= ' where fk_fichinter = '.$this->id;
@ -775,21 +827,25 @@ class Fichinter extends CommonObject
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($result);
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$objp = $this->db->fetch_object($result);
$objp = $this->db->fetch_object($resql);
$line = new FichinterLigne($this->db);
$line->id = $objp->rowid;
//...
$line->desc = $objp->description;
//For invoicing we calculing hours
$line->qty = round($objp->duree/3600,2);
$line->date = $this->db->jdate($objp->date);
$line->rang = $objp->rang;
$this->lines[$i] = $line;
$i++;
}
$this->db->free($result);
$this->db->free($resql);
return 1;
}

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
*
* 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
@ -22,7 +23,7 @@
* \file htdocs/fichinter/fiche.php
* \brief Fichier fiche intervention
* \ingroup ficheinter
* \version $Id$
* \version $Id: fiche.php,v 1.163 2011/07/01 16:24:44 simnandez Exp $
*/
require("../main.inc.php");
@ -70,7 +71,7 @@ $result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter');
* Actions
*/
if ($_REQUEST["action"] != 'create' && $_REQUEST["action"] != 'add' && ! ($_REQUEST["id"] > 0) && empty($_REQUEST["ref"]))
if ($_REQUEST["action"] != 'create' && $_REQUEST["action"] != 'add' && $_REQUEST["action"] != 'classifybilled' && ! ($_REQUEST["id"] > 0) && empty($_REQUEST["ref"]))
{
Header("Location: index.php");
return;
@ -281,6 +282,12 @@ if ($_POST['action'] == "addline" && $user->rights->ficheinter->creer)
}
}
// Classify Billed
if ($_GET['action'] == 'classifybilled')
{
$fichinter->setBilled();
}
/*
* Mise a jour d'une ligne d'intervention
*/
@ -1029,7 +1036,7 @@ elseif ($fichinterid)
}
// Send
if ($fichinter->statut == 1)
if ($fichinter->statut > 0)
{
$ficheinterref = dol_sanitizeFileName($fichinter->ref);
$file = $conf->ficheinter->dir_output . '/'.$ficheinterref.'/'.$ficheinterref.'.pdf';
@ -1042,6 +1049,25 @@ elseif ($fichinterid)
else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
}
}
//Invoicing
if ($conf->global->MAIN_FEATURES_LEVEL>=2)
{
if ($conf->facture->enabled && $fichinter->statut > 0)
{
$langs->load("bills");
if ($fichinter->statut < 2)
{
if ($user->rights->facture->creer) print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&amp;origin='.$fichinter->element.'&amp;originid='.$fichinter->id.'&amp;socid='.$fichinter->socid.'">'.$langs->trans("CreateBill").'</a>';
else print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CreateBill").'</a>';
}
if ($fichinter->statut != 2)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$fichinter->id.'&amp;action=classifybilled">'.$langs->trans("ClassifyBilled").'</a>';
}
}
}
// Delete
if (($fichinter->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer)
@ -1049,6 +1075,7 @@ elseif ($fichinterid)
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$fichinter->id.'&amp;action=delete"';
print '>'.$langs->trans('Delete').'</a>';
}
}
}
@ -1124,6 +1151,10 @@ elseif ($fichinterid)
print "<br>\n";
$somethingshown=$formfile->show_documents('ficheinter',$filename,$filedir,$urlsource,$genallowed,$delallowed,$fichinter->modelpdf,1,0,0,28,0,'','','',$societe->default_lang);
/*
* Linked object block
*/
$somethingshown=$fichinter->showLinkedObjectBlock();
print "</td><td>";
print "&nbsp;</td>";
print "</tr></table>\n";
@ -1132,5 +1163,5 @@ elseif ($fichinterid)
$db->close();
llxFooter('$Date$ - $Revision$');
llxFooter('$Date: 2011/07/01 16:24:44 $ - $Revision: 1.163 $');
?>

View File

@ -0,0 +1,58 @@
<?php
/* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: linkedobjectblock.tpl.php,v 1.1 2011/07/01 16:24:44 simnandez Exp $
*/
?>
<!-- BEGIN PHP TEMPLATE -->
<?php
$langs = $GLOBALS['langs'];
$linkedObjectBlock = $GLOBALS['object']->linkedObjectBlock;
$langs->load("interventions");
echo '<br />';
print_titre($langs->trans('RelatedInterventions'));
?>
<table class="noborder" width="100%">
<tr class="liste_titre">
<td><?php echo $langs->trans("Ref"); ?></td>
<td align="center"><?php echo $langs->trans("Date"); ?></td>
<td align="right"><?php echo $langs->trans("Status"); ?></td>
</tr>
<?php
$var=true;
foreach($linkedObjectBlock as $object)
{
$var=!$var;
?>
<tr <?php echo $GLOBALS['bc'][$var]; ?> ><td>
<a href="<?php echo DOL_URL_ROOT.'/fichinter/fiche.php?id='.$object->id ?>"><?php echo img_object($langs->trans("ShowIntervention"),"intervention").' '.$object->ref; ?></a></td>
<td align="center"><?php echo dol_print_date($object->datev,'day'); ?></td>
<td align="right"><?php echo $object->getLibStatut(3); ?></td>
</tr>
<?php
}
?>
</table>
<!-- END PHP TEMPLATE -->

View File

@ -34,6 +34,10 @@ InterLineId=Id línea detall
InterLineDate=Data línea
InterLineDuration=Duració línea
InterLineDesc=Descripció linea
ClassifyBilled=Classificar "Facturado"
StatusInterInvoiced=Facturado
RelatedInterventions=Intervencions adjuntes
ShowIntervention=Mostrar intervenció
##### Types de contacts #####
TypeContact_fichinter_internal_INTERREPFOLL=Responsable seguiment de la intervenció
TypeContact_fichinter_internal_INTERVENING=Interventor

View File

@ -23,6 +23,10 @@ ConfirmDeleteInterventionLine=Are you sure you want to delete this intervention
NameAndSignatureOfInternalContact=Name and signature of intervening :
NameAndSignatureOfExternalContact=Name and signature of customer :
DocumentModelStandard=Standard document model for interventions
ClassifyBilled=Classify "Billed"
StatusInterInvoiced=Billed
RelatedInterventions=Related interventions
ShowIntervention=Show intervention
##### Types de contacts #####
TypeContact_fichinter_internal_INTERREPFOLL=Representative following-up intervention
TypeContact_fichinter_internal_INTERVENING=Intervening

View File

@ -34,6 +34,10 @@ InterLineId=Id línea detalle
InterLineDate=Fecha línea
InterLineDuration=Duración línea
InterLineDesc=Descripción linea
ClassifyBilled=Clasificar "Facturado"
StatusInterInvoiced=Facturado
RelatedInterventions=Intervenciones adjuntas
ShowIntervention=Mostrar intervención
##### Types de contacts #####
TypeContact_fichinter_internal_INTERREPFOLL=Responsable seguimiento de la intervención
TypeContact_fichinter_internal_INTERVENING=Interventor

View File

@ -35,6 +35,10 @@ InterLineDate=Date ligne
InterLineDuration=Durée ligne
InterLineDesc=Description ligne
DocumentModelStandard=Modèle de fiche d'intervention standard
ClassifyBilled=Classer "Facturée"
StatusInterInvoiced=Facturée
RelatedInterventions=Interventions rattachées
ShowIntervention=Afficher intervention
##### Types de contacts #####
TypeContact_fichinter_internal_INTERREPFOLL=Responsable suivi de l'intervention
TypeContact_fichinter_internal_INTERVENING=Intervenant