From 08cdc71a4734e60e04eacc193783bb926089a78e Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 1 Jul 2011 16:24:44 +0000 Subject: [PATCH] task #11004: Create invoice from intervention --- htdocs/core/class/commonobject.class.php | 3 +- htdocs/fichinter/class/fichinter.class.php | 94 +++++++++++++++---- htdocs/fichinter/fiche.php | 39 +++++++- .../fichinter/tpl/linkedobjectblock.tpl.php | 58 ++++++++++++ htdocs/langs/ca_ES/interventions.lang | 4 + htdocs/langs/en_US/interventions.lang | 4 + htdocs/langs/es_ES/interventions.lang | 4 + htdocs/langs/fr_FR/interventions.lang | 4 + 8 files changed, 186 insertions(+), 24 deletions(-) create mode 100755 htdocs/fichinter/tpl/linkedobjectblock.tpl.php diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index dba9a784f4d..96d0eaf024e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -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'; } diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 259b4baa6c5..80334bba8b6 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2002-2003 Rodolphe Quiedeville * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2011 Juanjo Menent * * 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; } diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 61ddcc6ba9d..d929b3e2a01 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -2,6 +2,7 @@ /* Copyright (C) 2002-2007 Rodolphe Quiedeville * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2011 Juanjo Menent * * 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 ''.$langs->trans('SendByMail').''; } } + + //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 ''.$langs->trans("CreateBill").''; + else print ''.$langs->trans("CreateBill").''; + } + + if ($fichinter->statut != 2) + { + print ''.$langs->trans("ClassifyBilled").''; + } + } + } // Delete if (($fichinter->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer) @@ -1049,6 +1075,7 @@ elseif ($fichinterid) print ''.$langs->trans('Delete').''; } + } } @@ -1124,6 +1151,10 @@ elseif ($fichinterid) print "
\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 ""; print " "; print "\n"; @@ -1132,5 +1163,5 @@ elseif ($fichinterid) $db->close(); -llxFooter('$Date$ - $Revision$'); +llxFooter('$Date: 2011/07/01 16:24:44 $ - $Revision: 1.163 $'); ?> diff --git a/htdocs/fichinter/tpl/linkedobjectblock.tpl.php b/htdocs/fichinter/tpl/linkedobjectblock.tpl.php new file mode 100755 index 00000000000..193e9eaf838 --- /dev/null +++ b/htdocs/fichinter/tpl/linkedobjectblock.tpl.php @@ -0,0 +1,58 @@ + + * + * 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 $ + */ +?> + + + +linkedObjectBlock; + +$langs->load("interventions"); +echo '
'; +print_titre($langs->trans('RelatedInterventions')); + +?> + + + + + + + + > + + + + + +
trans("Ref"); ?>trans("Date"); ?>trans("Status"); ?>
+ trans("ShowIntervention"),"intervention").' '.$object->ref; ?>datev,'day'); ?>getLibStatut(3); ?>
+ + \ No newline at end of file diff --git a/htdocs/langs/ca_ES/interventions.lang b/htdocs/langs/ca_ES/interventions.lang index 480a300e960..9cccf6451d9 100644 --- a/htdocs/langs/ca_ES/interventions.lang +++ b/htdocs/langs/ca_ES/interventions.lang @@ -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 diff --git a/htdocs/langs/en_US/interventions.lang b/htdocs/langs/en_US/interventions.lang index c1797760413..4dea3b3e7d4 100644 --- a/htdocs/langs/en_US/interventions.lang +++ b/htdocs/langs/en_US/interventions.lang @@ -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 diff --git a/htdocs/langs/es_ES/interventions.lang b/htdocs/langs/es_ES/interventions.lang index e9900eeb32e..05f494afcf9 100644 --- a/htdocs/langs/es_ES/interventions.lang +++ b/htdocs/langs/es_ES/interventions.lang @@ -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 diff --git a/htdocs/langs/fr_FR/interventions.lang b/htdocs/langs/fr_FR/interventions.lang index 4b4f981e70a..c78f6e9da84 100644 --- a/htdocs/langs/fr_FR/interventions.lang +++ b/htdocs/langs/fr_FR/interventions.lang @@ -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