New: Le lien entre le contrat et la ligne de facture qui l'a gnr est fait.
New: Lors de la mise en service, les date de dbut et fin propose sont mises par dfaut aux valeurs saisies dans la ligne de facture. Si pas de date ont t saisies, les valeurs par dfaut sont positionnes la date courante pour le dbut et la date de fin=date courante+dure du service.
This commit is contained in:
parent
94d39f64b1
commit
b3c3e451d0
@ -1,5 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004 Destailleur Laurent <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
|
||||
@ -38,52 +39,50 @@ class Contrat
|
||||
$this->user_service = new User($DB);
|
||||
$this->user_cloture = new User($DB);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*
|
||||
* Modifie date de mise en service d'un contrat
|
||||
* Si la duree est renseignée, date_start=date_start et date_end=date_start+duree
|
||||
* sinon date_start=date_start et date_end=date_end
|
||||
*/
|
||||
Function mise_en_service($user, $date, $duree)
|
||||
Function mise_en_service($user, $date_start, $duree=0, $date_end)
|
||||
{
|
||||
$duree_value = substr($duree,0,strlen($duree)-1);
|
||||
$duree_unit = substr($duree,-1);
|
||||
if ($duree) {
|
||||
// Si duree renseignee
|
||||
$duree_value = substr($duree,0,strlen($duree)-1);
|
||||
$duree_unit = substr($duree,-1);
|
||||
|
||||
$month = date("m",$date);
|
||||
$day = date("d",$date);
|
||||
$year = date("Y",$date);
|
||||
$month = date("m",$date_start);
|
||||
$day = date("d",$date_start);
|
||||
$year = date("Y",$date_start);
|
||||
|
||||
switch($duree_unit)
|
||||
{
|
||||
case "d":
|
||||
$day = $day + $duree_value;
|
||||
break;
|
||||
case "w":
|
||||
$day = $day + ($duree_value * 7);
|
||||
break;
|
||||
case "m":
|
||||
$month = $month + $duree_value;
|
||||
break;
|
||||
case "y":
|
||||
$year = $year + $duree_value;
|
||||
break;
|
||||
}
|
||||
|
||||
$fin = mktime(date("H",$date),
|
||||
date("i",$date),
|
||||
0,
|
||||
$month,
|
||||
$day,
|
||||
$year);
|
||||
switch($duree_unit)
|
||||
{
|
||||
case "d":
|
||||
$day = $day + $duree_value;
|
||||
break;
|
||||
case "w":
|
||||
$day = $day + ($duree_value * 7);
|
||||
break;
|
||||
case "m":
|
||||
$month = $month + $duree_value;
|
||||
break;
|
||||
case "y":
|
||||
$year = $year + $duree_value;
|
||||
break;
|
||||
}
|
||||
$date_end = mktime(date("H",$date_start), date("i",$date_start), 0, $month, $day, $year);
|
||||
}
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET enservice = 1";
|
||||
$sql .= " , mise_en_service = ".$this->db->idate($date).", fk_user_mise_en_service = ".$user->id;
|
||||
$sql .= " , fin_validite = ". $this->db->idate($fin);
|
||||
$sql .= " , mise_en_service = ".$this->db->idate($date_start).", fk_user_mise_en_service = ".$user->id;
|
||||
$sql .= " , fin_validite = ". $this->db->idate($date_end);
|
||||
$sql .= " WHERE rowid = ".$this->id . " AND enservice = 0";
|
||||
|
||||
$result = $this->db->query($sql) ;
|
||||
if (!$result)
|
||||
{
|
||||
print $this->db->error() . "<br>" . $sql;
|
||||
print $this->db->error() . "<br>" . $sql;
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -119,7 +118,7 @@ class Contrat
|
||||
$sql = "SELECT rowid, enservice, fk_soc, fk_product, ".$this->db->pdate("mise_en_service")." as datemise";
|
||||
$sql .= ", fk_user_mise_en_service, ".$this->db->pdate("date_cloture")." as datecloture";
|
||||
$sql .= ", ".$this->db->pdate("fin_validite")." as datefin";
|
||||
$sql .= ", fk_user_cloture, fk_facture";
|
||||
$sql .= ", fk_user_cloture, fk_facture, fk_facturedet";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."contrat WHERE rowid = $id";
|
||||
|
||||
$result = $this->db->query($sql) ;
|
||||
@ -131,9 +130,10 @@ class Contrat
|
||||
$this->id = $result["rowid"];
|
||||
$this->enservice = $result["enservice"];
|
||||
$this->factureid = $result["fk_facture"];
|
||||
$this->facturedetid = $result["fk_facturedet"];
|
||||
$this->mise_en_service = $result["datemise"];
|
||||
$this->date_cloture = $result["datecloture"];
|
||||
$this->date_fin_validite = $result["datefin"];
|
||||
$this->date_cloture = $result["datecloture"];
|
||||
|
||||
$this->user_service->id = $result["fk_user_mise_en_service"];
|
||||
$this->user_cloture->id = $result["fk_user_cloture"];
|
||||
@ -152,13 +152,13 @@ class Contrat
|
||||
return $result;
|
||||
}
|
||||
/*
|
||||
*
|
||||
* Crée autant de contrats que de lignes de facture, pour une facture donnée
|
||||
*
|
||||
*/
|
||||
Function create_from_facture($factureid, $user, $socid)
|
||||
{
|
||||
$sql = "SELECT p.rowid FROM ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."facturedet as f";
|
||||
$sql .= " WHERE p.rowid = f.fk_product AND p.fk_product_type = 1 AND f.fk_facture = ".$factureid;
|
||||
$sql = "SELECT p.rowid as rowid, fd.rowid as fdrowid FROM ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."facturedet as fd";
|
||||
$sql .= " WHERE p.rowid = fd.fk_product AND p.fk_product_type = 1 AND fd.fk_facture = ".$factureid;
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
@ -171,19 +171,20 @@ class Contrat
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $this->db->fetch_object($i);
|
||||
$contrats[$i] = $objp->rowid;
|
||||
$prowid[$i] = $objp->rowid;
|
||||
$fdrowid[$i] = $objp->fdrowid;
|
||||
$i++;
|
||||
}
|
||||
|
||||
$this->db->free();
|
||||
|
||||
while (list($key, $value) = each ($contrats))
|
||||
while (list($i, $value) = each ($prowid))
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (fk_product, fk_facture, fk_soc, fk_user_author)";
|
||||
$sql .= " VALUES ($value, $factureid, $socid, $user->id)";
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (fk_product, fk_facture, fk_facturedet, fk_soc, fk_user_author)";
|
||||
$sql .= " VALUES (".$prowid[$i].", $factureid, ".$fdrowid[$i].", $socid, $user->id)";
|
||||
if (! $this->db->query($sql))
|
||||
{
|
||||
print $this->db->error();
|
||||
print "Erreur : ".$this->db->error()."<br>".$sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 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
|
||||
@ -53,14 +53,10 @@ if ($_POST["action"] == 'miseenservice')
|
||||
$contrat->id = $id;
|
||||
$contrat->fetch($id);
|
||||
$contrat->mise_en_service($user,
|
||||
mktime($_POST["rehour"],
|
||||
$_POST["remin"],
|
||||
0,
|
||||
$_POST["remonth"],
|
||||
$_POST["reday"],
|
||||
$_POST["reyear"]),
|
||||
$_POST["duration"]
|
||||
);
|
||||
mktime($_POST["date_starthour"],$_POST["date_startmin"],0,$_POST["date_startmonth"],$_POST["date_startday"],$_POST["date_startyear"]),
|
||||
0,
|
||||
mktime($_POST["date_endhour"],$_POST["date_endmin"],0,$_POST["date_endmonth"],$_POST["date_endday"],$_POST["date_endyear"])
|
||||
);
|
||||
}
|
||||
|
||||
if ($_GET["action"] == 'cloture')
|
||||
@ -102,13 +98,13 @@ if ($action == 'update' && $cancel <> 'Annuler')
|
||||
$mesg = 'Fiche non mise à jour !' . "<br>" . $product->mesg_error;
|
||||
}
|
||||
}
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
$html = new Form($db);
|
||||
|
||||
|
||||
/*
|
||||
* Fiche création
|
||||
*
|
||||
*/
|
||||
if ($action == 'create')
|
||||
{
|
||||
print "<form action=\"$PHP_SELF?type=$type\" method=\"post\">\n";
|
||||
@ -129,7 +125,8 @@ if ($action == 'create')
|
||||
print "</textarea></td></tr>";
|
||||
if ($type == 1)
|
||||
{
|
||||
print '<tr><td>Durée</td><TD><input name="duration_value" size="6" value="'.$product->duree.'">';
|
||||
// Si contrat de type service
|
||||
print '<tr><td>Durée</td><td><input name="duration_value" size="6" value="'.$product->duree.'">';
|
||||
print '<input name="duration_unit" type="radio" value="d">jour ';
|
||||
print '<input name="duration_unit" type="radio" value="w">semaine ';
|
||||
print '<input name="duration_unit" type="radio" value="m">mois ';
|
||||
@ -143,25 +140,33 @@ if ($action == 'create')
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Fiche visu/édition
|
||||
*
|
||||
*/
|
||||
if ($id)
|
||||
{
|
||||
$contrat = new Contrat($db);
|
||||
$result = $contrat->fetch($id);
|
||||
|
||||
if ( $result )
|
||||
{
|
||||
$facture = new Facture($db);
|
||||
$facture->fetch($contrat->factureid);
|
||||
|
||||
|
||||
{
|
||||
$date_start='';
|
||||
$date_end='';
|
||||
|
||||
print_fiche_titre('Fiche contrat : '.$contrat->id, $mesg);
|
||||
|
||||
print '<table class="border" width="100%" cellspacing="0" cellpadding="4">';
|
||||
print "<tr>";
|
||||
print '<td width="20%">Service</td><td colspan=4>'.($contrat->product->ref).' - '.($contrat->product->label_url).'</td>';
|
||||
print '</tr><tr>';
|
||||
if ($contrat->factureid)
|
||||
if ($contrat->facturedetid)
|
||||
{
|
||||
// Si contrat lié à une ligne de factures (ce n'est pas le cas sur les anciennes données)
|
||||
$facturedet = new FactureLigne($db);
|
||||
$facturedet->fetch($contrat->facturedetid);
|
||||
$date_start=$facturedet->date_start;
|
||||
$date_end=$facturedet->date_end;
|
||||
print '<td>Société</td><td>'.$contrat->societe->nom_url.'</td>';
|
||||
print '<td>Facture</td><td><a href="../compta/facture.php?facid='.$contrat->factureid.'">Facture</td>';
|
||||
}
|
||||
@ -179,24 +184,62 @@ else
|
||||
{
|
||||
print "<b>Ce contrat n'est pas en service</b>";
|
||||
}
|
||||
print '</td></tr>';
|
||||
print "</td></tr>\n";
|
||||
if ($request == 'miseenservice')
|
||||
{
|
||||
// Si date_start et date_end ne sont pas connues de la ligne de facture, on les
|
||||
// definit à une valeur par défaut en fonction de la durée définie pour le service.
|
||||
if (! $date_start) { $date_start=mktime(); }
|
||||
if (! $date_end) {
|
||||
if ($contrat->product->duration) {
|
||||
// Si duree du service connue
|
||||
$duree_value = substr($contrat->product->duration,0,strlen($contrat->product->duration)-1);
|
||||
$duree_unit = substr($contrat->product->duration,-1);
|
||||
|
||||
$month = date("m",$date_start);
|
||||
$day = date("d",$date_start);
|
||||
$year = date("Y",$date_start);
|
||||
|
||||
switch($duree_unit)
|
||||
{
|
||||
case "d":
|
||||
$day = $day + $duree_value;
|
||||
break;
|
||||
case "w":
|
||||
$day = $day + ($duree_value * 7);
|
||||
break;
|
||||
case "m":
|
||||
$month = $month + $duree_value;
|
||||
break;
|
||||
case "y":
|
||||
$year = $year + $duree_value;
|
||||
break;
|
||||
}
|
||||
$date_end = mktime(date("H",$date_start), date("i",$date_start), 0, $month, $day, $year);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print '<form action="fiche.php?id='.$id.'" method="post">';
|
||||
print '<input type="hidden" name="action" value="miseenservice">';
|
||||
print '<tr><td>Date de mise en service</td><td colspan="3">';
|
||||
print $html->select_date('','re',1,1);
|
||||
print " ";
|
||||
print '</td></tr>';
|
||||
print '<tr><td>Date de fin</td><td colspan="3">';
|
||||
|
||||
// TODO : Offrir le choix de la date de fin de contrat par la durée prédéfinie ou par
|
||||
// une date explicite.
|
||||
print $contrat->product->duration." après";
|
||||
//print "<br>";$html->select_date('','fin',1,1);
|
||||
|
||||
print '<tr><td>Durée standard pour ce service</td><td colspan="3">';
|
||||
print $contrat->product->duration;
|
||||
print '<input type="hidden" name="duration" value="'.$contrat->product->duration.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
// Date de début de mise en service
|
||||
print '<tr><td>Date de mise en service</td><td colspan="3">';
|
||||
print $html->select_date($date_start,'date_start',1,1);
|
||||
print " ";
|
||||
print '</td></tr>';
|
||||
|
||||
// Date de fin prévue de mise en service
|
||||
print '<tr><td>Date de fin prévue</td><td colspan="3">';
|
||||
print $html->select_date($date_end,'date_end',1,1);
|
||||
print " ";
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td colspan="4" align="center">';
|
||||
print '<input type="submit" value="Enregistrer">';
|
||||
print '</td></tr>';
|
||||
@ -251,7 +294,7 @@ if (! $contrat->enservice)
|
||||
}
|
||||
elseif ($contrat->enservice == 1)
|
||||
{
|
||||
print '<a class="tabAction" href="fiche.php?action=annule&id='.$id.'">Annuler</a>';
|
||||
print '<a class="tabAction" href="fiche.php?action=annule&id='.$id.'">Mettre hors service</a>';
|
||||
print '<a class="tabAction" href="fiche.php?action=cloture&id='.$id.'">Clôturer</a>';
|
||||
}
|
||||
print '</div>';
|
||||
|
||||
@ -21,13 +21,50 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class FactureLigne
|
||||
{
|
||||
Function FactureLigne()
|
||||
Function FactureLigne($DB)
|
||||
{
|
||||
$this->db= $DB ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recupére l'objet ligne de facture
|
||||
*
|
||||
*/
|
||||
Function fetch($rowid, $societe_id=0)
|
||||
{
|
||||
$sql = "SELECT fk_product, description, price, qty, rowid, tva_taux, remise, remise_percent, subprice, ".$this->db->pdate("date_start")." as date_start,".$this->db->pdate("date_end")." as date_end";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$rowid;
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$objp = $this->db->fetch_object($i);
|
||||
$this->desc = stripslashes($objp->description);
|
||||
$this->qty = $objp->qty;
|
||||
$this->price = $objp->price;
|
||||
$this->subprice = $objp->subprice;
|
||||
$this->tva_taux = $objp->tva_taux;
|
||||
$this->remise = $objp->remise;
|
||||
$this->remise_percent = $objp->remise_percent;
|
||||
$this->produit_id = $objp->fk_product;
|
||||
$this->date_start = $objp->date_start;
|
||||
$this->date_end = $objp->date_end;
|
||||
$i++;
|
||||
}
|
||||
else {
|
||||
print "Erreur ".$this->db->error()."<br>".$sql;
|
||||
}
|
||||
$this->db->free();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class Facture
|
||||
{
|
||||
var $id;
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
alter table llx_contrat add fk_facturedet integer NOT NULL default 0 after fk_facture;
|
||||
alter table llx_contrat change fk_user_cloture fk_user_cloture integer;
|
||||
alter table llx_contrat change fk_user_mise_en_service fk_user_mise_en_service integer;
|
||||
|
||||
alter table llx_facturedet add date_start date;
|
||||
alter table llx_facturedet add date_end date;
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
-- ============================================================================
|
||||
-- Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
-- Copyright (C) 2004 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
|
||||
@ -31,8 +32,9 @@ create table llx_contrat
|
||||
fk_soc integer NOT NULL,
|
||||
fk_product integer NOT NULL,
|
||||
fk_facture integer NOT NULL default 0,
|
||||
fk_user_author integer NOT NULL,
|
||||
fk_user_mise_en_service integer NOT NULL,
|
||||
fk_user_cloture integer NOT NULL
|
||||
fk_facturedet integer NOT NULL default 0,
|
||||
fk_user_author integer NOT NULL default 0,
|
||||
fk_user_mise_en_service integer,
|
||||
fk_user_cloture integer
|
||||
)type=innodb;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user