From 9a4ffd04ee15eb96e7a2fff9934b33aff5dd18e8 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Sun, 3 Aug 2003 19:15:39 +0000 Subject: [PATCH] Nouveau fichier --- htdocs/contrat/contrat.class.php | 115 ++++++++++ htdocs/contrat/fiche.php | 354 +++++++++++++++++++++++++++++++ htdocs/contrat/index.php | 94 ++++++++ htdocs/contrat/pre.inc.php | 48 +++++ 4 files changed, 611 insertions(+) create mode 100644 htdocs/contrat/contrat.class.php create mode 100644 htdocs/contrat/fiche.php create mode 100644 htdocs/contrat/index.php create mode 100644 htdocs/contrat/pre.inc.php diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php new file mode 100644 index 00000000000..203b06a3b2b --- /dev/null +++ b/htdocs/contrat/contrat.class.php @@ -0,0 +1,115 @@ + + * + * 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$ + * $Source$ + * + */ + +class Contrat +{ + var $id; + var $db; + + /* + * Initialisation + * + */ + + Function Contrat($DB) + { + include_once("../societe.class.php3"); + $this->db = $DB ; + $this->product = new Product($DB); + $this->societe = new Societe($DB); + } + /* + * + * + * + */ + Function fetch ($id) + { + $sql = "SELECT rowid, enservice, fk_soc, fk_product"; + $sql .= " FROM llx_contrat WHERE rowid = $id"; + + $result = $this->db->query($sql) ; + + if ( $result ) + { + $result = $this->db->fetch_array(); + + $this->id = $result["rowid"]; + $this->enservice = $result["enservice"]; + $this->product->fetch($result["fk_product"]); + $this->societe->fetch($result["fk_soc"]); + $this->db->free(); + } + else + { + print $this->db->error(); + } + + return $result; + } + /* + * + * + */ + Function create_from_facture($factureid, $user, $socid) + { + $sql = "SELECT p.rowid FROM llx_product as p, llx_facturedet as f"; + $sql .= " WHERE p.rowid = f.fk_product AND p.fk_product_type = 1 AND f.fk_facture = ".$factureid; + + if ($this->db->query($sql)) + { + $num = $this->db->num_rows(); + $i = 0; + + while ($i < $num) + { + $objp = $this->db->fetch_object($i); + $contrats[$i] = $objp->rowid; + $i++; + } + + $this->db->free(); + + while (list($key, $value) = each ($contrats)) + { + $sql = "INSERT INTO llx_contrat (fk_product, fk_facture, fk_soc, fk_user_author)"; + $sql .= " VALUES ($value, $factureid, $socid, $user->id)"; + if (! $this->db->query($sql)) + { + print $this->db->error(); + } + } + } + else + { + print $this->db->error(); + } + + return $result; + } + /* + * + * + */ + +} +?> diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php new file mode 100644 index 00000000000..bf0e949d84f --- /dev/null +++ b/htdocs/contrat/fiche.php @@ -0,0 +1,354 @@ + + * + * 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$ + * $Source$ + * + */ + +require("./pre.inc.php"); +require("./contrat.class.php"); +require("../facture.class.php3"); + +llxHeader(); + +$db = new Db(); +$mesg = ''; + +if ($action == 'add') +{ + $contrat = new Contrat($db); + + $id = $product->create($user); + $action = ''; +} + +if ($action == 'update' && $cancel <> 'Annuler') +{ + $product = new Product($db); + + $product->ref = $HTTP_POST_VARS["ref"]; + $product->libelle = $HTTP_POST_VARS["libelle"]; + $product->price = $HTTP_POST_VARS["price"]; + $product->tva_tx = $HTTP_POST_VARS["tva_tx"]; + $product->description = $HTTP_POST_VARS["desc"]; + $product->envente = $HTTP_POST_VARS["statut"]; + $product->duration_value = $HTTP_POST_VARS["duration_value"]; + $product->duration_unit = $HTTP_POST_VARS["duration_unit"]; + + if ( $product->update($id, $user)) + { + $action = ''; + $mesg = 'Fiche mise à jour'; + } + else + { + $action = 'edit'; + $mesg = 'Fiche non mise à jour !' . "
" . $product->mesg_error; + } +} +/* + * + * + */ +if ($action == 'create') +{ + print "
\n"; + print "\n"; + print ''."\n"; + print '
Nouveau '.$types[$type].'

'."\n"; + + print ''; + print ""; + print ''; + print ''; + print ''; + print ''; + print ""; + if ($type == 1) + { + print ''; + } + + print ''; + print '
Référence
Libellé
Prix de vente
Taux TVA'; + $html = new Form($db); + print $html->select_tva("tva_tx"); + print ' %
Description"; + print '
Durée'; + print 'jour '; + print 'semaine '; + print 'mois '; + print 'année'; + print '
 
'; + print '
'; +} +else +{ + if ($id) + { + $contrat = new Contrat($db); + $result = $contrat->fetch($id); + + if ( $result ) + { + print_fiche_titre('Fiche contrat : '.$contrat->id, $mesg); + + print ''; + print ""; + print ''; + print ''; + print ''; + print ''; + + print ""; + + if ($product->type == 1) + { + print ''; + } + + print "
Service'.$product->ref.''; + if ($product->enservice) + { + print "En service"; + } + else + { + print "Ce contrat n'est pas en service"; + } + print '
Société'.$contrat->societe->nom_url.'Statistiques
Description".nl2br($product->description)."
Durée'.$product->duration_value.' '; + if ($product->duration_value > 1) + { + $plu = "s"; + } + switch ($product->duration_unit) + { + case "d": + print "jour$plu "; + break; + case "w": + print "semaine$plu "; + break; + case "m": + print 'mois '; + break; + case "y": + print "an$plu "; + break; + } + print '
"; + } + + if ($action == 'edit') + { + print '
Edition de la fiche '.$types[$product->type].' : '.$product->ref.'

'; + + print "
\n"; + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ""; + + if ($product->type == 1) + { + print ''; + } + + print ''; + print '
Référence
Libellé
Prix de vente
Taux TVA'; + $html = new Form($db); + print $html->select_tva("tva_tx", $product->tva_tx); + print '
Statut'; + print '
Description"; + print '
Durée'; + print 'jour '; + print 'semaine '; + print 'mois '; + print 'année'; + print '
  '; + print '
'; + print '
'; + } + } + else + { + print "Error"; + } +} + +/* ************************************************************************** */ +/* */ +/* Barre d'action */ +/* */ +/* ************************************************************************** */ + +print '
'; +print ''; +print ''; +print ''; + +if ($action == 'create') +{ + print ''; +} +else +{ + print ''; +} +print ''; +print '
----[Editer]-

'; + +if ($id && $action == '' && $product->envente) +{ + + $htmls = new Form($db); + $propal = New Propal($db); + + print ''; + + print ''; + print ''; + + print ''; + print '
'; + print_titre("Ajouter ma proposition"); + print ''; + print_titre("Ajouter aux autres propositions"); + print '
'; + $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price - p.remise as price, p.ref,".$db->pdate("p.datep")." as dp"; + $sql .= " FROM llx_societe as s, llx_propal as p"; + $sql .=" WHERE p.fk_soc = s.idp AND p.fk_statut = 0 AND p.fk_user_author = ".$user->id; + $sql .= " ORDER BY p.datec DESC, tms DESC"; + + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + $i = 0; + print ''; + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object( $i); + + $var=!$var; + print ""; + print "\n"; + print "\n"; + print "\n"; + print ''; + print ''; + print '"; + print ''; + $i++; + } + print "
propalid\">$objp->refidp\">$objp->nom". strftime("%d %B %Y",$objp->dp)."
'; + print ''; + print ''; + print ''; + print "
"; + $db->free(); + } + + print '
'; + + $otherprop = $propal->liste_array(1, '<>'.$user->id); + if (sizeof($otherprop)) + { + print '
'; + print ''; + print ''; + print ""; + print '
Autres Propositions"; + $htmls->select_array("propalid", $otherprop); + print ''; + print ''; + print ''; + print ''; + print "
'; + } + print '
'; + print_titre("Ajouter ma facture"); + print ''; + print_titre("Ajouter aux autres factures"); + print '
'; + $sql = "SELECT s.nom, s.idp, f.rowid as factureid, f.facnumber,".$db->pdate("f.datef")." as df"; + $sql .= " FROM llx_societe as s, llx_facture as f"; + $sql .=" WHERE f.fk_soc = s.idp AND f.fk_statut = 0 AND f.fk_user_author = ".$user->id; + $sql .= " ORDER BY f.datec DESC, f.rowid DESC"; + + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + $i = 0; + print ''; + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object( $i); + + $var=!$var; + print ""; + print "\n"; + print "\n"; + print "\n"; + print ''; + print ''; + print '"; + print ''; + $i++; + } + print "
factureid\">$objp->facnumberidp\">$objp->nom". strftime("%d %B %Y",$objp->df)."
'; + print ''; + print ''; + print ''; + print "
"; + $db->free(); + } + else + { + print $db->error() . "
" . $sql; + } + print '
'; + print '
'; + +} + + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php new file mode 100644 index 00000000000..03c55e5c5e9 --- /dev/null +++ b/htdocs/contrat/index.php @@ -0,0 +1,94 @@ + + * + * 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$ + * $Source$ + * + */ +require("./pre.inc.php"); + +$db = new Db(); + + +llxHeader(); + +if ($page == -1) { + $page = 0 ; +} + +$limit = $conf->liste_limit; +$offset = $limit * $page ; + +if ($sortfield == "") +{ + $sortfield="c.tms"; +} + +if ($sortorder == "") +{ + $sortorder="DESC"; +} + +$sql = "SELECT s.nom, c.rowid as cid, c.enservice, p.label, p.rowid, s.idp as sidp"; +$sql .= " FROM llx_contrat as c, llx_societe as s, llx_product as p"; +$sql .= " WHERE c.fk_soc = s.idp AND c.fk_product = p.rowid"; +$sql .= " ORDER BY $sortfield $sortorder "; +$sql .= $db->plimit($limit + 1 ,$offset); + +if ( $db->query($sql) ) +{ + $num = $db->num_rows(); + $i = 0; + + + print_barre_liste("Liste des contrats", $page, $PHP_SELF, "&sref=$sref&snom=$snom", $sortfield, $sortorder,'',$num); + + print ''; + + print '"; + print "\n"; + + $var=True; + while ($i < min($num,$limit)) + { + $objp = $db->fetch_object( $i); + $var=!$var; + print ""; + print "\n"; + print "\n"; + print "\n"; + $i++; + } + $db->free(); + + print "
'; + print_liste_field_titre("Libellé",$PHP_SELF, "p.label"); + print ""; + print_liste_field_titre("Société",$PHP_SELF, "s.nom"); + print "
cid\">$objp->labelsidp\">$objp->nom
"; + +} +else +{ + print $db->error() . "
" .$sql; +} + + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/htdocs/contrat/pre.inc.php b/htdocs/contrat/pre.inc.php new file mode 100644 index 00000000000..eb1d1eee79b --- /dev/null +++ b/htdocs/contrat/pre.inc.php @@ -0,0 +1,48 @@ + + * + * 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$ + * $Source$ + * + */ +require("../main.inc.php3"); + +$types[0] = "produit"; +$types[1] = "service"; + +function llxHeader($head = "", $urlp = "") +{ + global $user, $conf; + + /* + * + * + */ + top_menu($head); + + $menu = new Menu(); + + $menu->add(DOL_URL_ROOT."/contrat/index.php", "Contrats"); + + left_menu($menu->liste); + /* + * + * + */ + +} +?>