diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php
index 0cbfa3dc490..e57948556cd 100644
--- a/htdocs/comm/addpropal.php
+++ b/htdocs/comm/addpropal.php
@@ -80,11 +80,12 @@ if ($action == 'create')
print_date_select();
print "";
- print '
';
+ print ' | ';
print '';
print ' | | Auteur | '.$user->fullname.' |
';
- print "| Numéro | |
\n";
+ print '| Numéro | |
'."\n";
+ print '| Validité | jours |
';
/*
*
* Destinataire de la propale
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index db799c6bf01..5cef6fac21a 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -67,14 +67,16 @@ if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"]
}
-if ($action == 'add')
+if ($HTTP_POST_VARS["action"] == 'add')
{
$propal = new Propal($db, $socidp);
- $propal->datep = $db->idate(mktime(12, 1 , 1,
- $HTTP_POST_VARS["remonth"],
- $HTTP_POST_VARS["reday"],
- $HTTP_POST_VARS["reyear"]));
+ $propal->datep = mktime(12, 1 , 1,
+ $HTTP_POST_VARS["remonth"],
+ $HTTP_POST_VARS["reday"],
+ $HTTP_POST_VARS["reyear"]);
+
+ $propal->duree_validite = $HTTP_POST_VARS["duree_validite"];
$propal->contactid = $HTTP_POST_VARS["contactidp"];
$propal->projetidp = $HTTP_POST_VARS["projetidp"];
@@ -122,6 +124,17 @@ if ($HTTP_POST_VARS["action"] == 'setstatut' && $user->rights->propale->cloturer
$propal->cloture($user, $statut, $note);
}
+if ($_GET["action"] == 'commande')
+{
+ /*
+ * Cloture de la propale
+ */
+ $propal = new Propal($db);
+ $propal->fetch($propalid);
+ $propal->create_commande($user);
+}
+
+
if ($action == 'modif' && $user->rights->propale->creer)
{
/*
@@ -263,7 +276,12 @@ if ($propalid)
print '| Société | '.$obj->nom.' | ';
print 'Statut | '.$obj->lst.' |
';
- print '| Date | '.strftime("%A %d %B %Y",$obj->dp).' | ';
+ print '
| Date | '.strftime("%A %d %B %Y",$obj->dp);
+ if ($propal->fin_validite)
+ {
+ print " (".strftime("%d %B %Y",$propal->fin_validite).")";
+ }
+ print ' | ';
print 'Auteur | ';
$author = new User($db, $obj->fk_user_author);
@@ -396,7 +414,9 @@ if ($propalid)
print " | ".price($objp->subprice)." | ";
if ($obj->statut == 0 && $user->rights->propale->creer)
{
- print 'Supprimer | ';
+ print '';
+ print img_delete();
+ print ' | ';
}
else
{
@@ -502,7 +522,7 @@ if ($propalid)
print "- | ";
}
}
- print "- | ";
+ print '- | ';
/*
*
*/
@@ -535,7 +555,7 @@ if ($propalid)
}
else
{
- print '! Propale non generee ! | ';
+ print '! Proposition non génerée ! | ';
}
}
else
@@ -632,7 +652,7 @@ if ($propalid)
$file = PROPALE_OUTPUTDIR . "/$obj->ref/$obj->ref.pdf";
if (file_exists($file))
{
- print "
| Propale PDF | ";
+ print "
| PDF | ";
print ''.$propal->ref.'.pdf | ';
print ''.filesize($file). ' bytes | ';
print ''.strftime("%d %b %Y %H:%M:%S",filemtime($file)).' |
';
@@ -648,6 +668,24 @@ if ($propalid)
print '';
}
print "\n";
+ /*
+ *
+ */
+ $nb_commande = sizeof($propal->commande_liste_array());
+ if ($nb_commande > 0)
+ {
+ $coms = $propal->commande_liste_array();
+ print '
';
+ print "| Commande Num. |
\n";
+
+ for ($i = 0 ; $i < $nb_commande ; $i++)
+ {
+ print '| '.$coms[$i]." | \n";
+ print "
\n";
+ }
+ print "
";
+ }
+ // print 'Générer";
/*
*
*/
@@ -667,7 +705,7 @@ if ($propalid)
{
print_titre("Propale envoyée");
- print "";
+ print '';
print "| Date | Auteur |
\n";
@@ -802,7 +840,7 @@ if ($propalid)
$pageprev = $page - 1;
$pagenext = $page + 1;
- $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid";
+ $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp,".$db->pdate("p.fin_validite")." as dfv, c.label as statut, c.id as statutid";
$sql .= " FROM llx_societe as s, llx_propal as p, c_propalst as c WHERE p.fk_soc = s.idp AND p.fk_statut = c.id";
if ($socidp)
@@ -857,18 +895,15 @@ if ($propalid)
while ($i < min($num,$limit))
{
$objp = $db->fetch_object( $i);
-
+ $now = time();
$var=!$var;
print "";
print "| propalid\">$objp->ref | \n";
print "idp\">$objp->nom | \n";
- $now = time();
- $lim = 3600 * 24 * 15 ;
-
- if ( ($now - $objp->dp) > $lim && $objp->statutid == 1 )
+ if ( $now > $objp->dfv && $objp->dfv > 0 )
{
- print " > 15 jours | ";
+ print "".strftime("%d %b %Y",$objp->dfv)." | ";
}
else
{
diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php
index 292a2a2b378..5abed48f596 100644
--- a/htdocs/propal.class.php
+++ b/htdocs/propal.class.php
@@ -103,7 +103,7 @@ class Propal
}
}
}
- /*
+ /**
*
*
*/
@@ -181,7 +181,7 @@ class Propal
}
}
}
- /*
+ /**
*
*
*
@@ -191,8 +191,10 @@ class Propal
/*
* Insertion dans la base
*/
- $sql = "INSERT INTO llx_propal (fk_soc, fk_soc_contact, price, remise, tva, total, datep, datec, ref, fk_user_author, note, model_pdf) ";
- $sql .= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, 0,0, $this->datep, now(), '$this->ref', $this->author, '$this->note','$this->modelpdf')";
+ $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
+
+ $sql = "INSERT INTO llx_propal (fk_soc, fk_soc_contact, price, remise, tva, total, datep, datec, ref, fk_user_author, note, model_pdf, fin_validite) ";
+ $sql .= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, 0,0,".$this->db->idate($this->datep).", now(), '$this->ref', $this->author, '$this->note','$this->modelpdf',".$this->db->idate($this->fin_validite).")";
$sqlok = 0;
if ( $this->db->query($sql) )
@@ -304,7 +306,7 @@ class Propal
Function fetch($rowid)
{
- $sql = "SELECT ref,total,price,remise,tva,fk_soc,fk_soc_contact,".$this->db->pdate(datep)."as dp, model_pdf, note, fk_statut, remise_percent";
+ $sql = "SELECT ref,total,price,remise,tva,fk_soc,fk_soc_contact,".$this->db->pdate("datep")."as dp,".$this->db->pdate("fin_validite")."as dfv, model_pdf, note, fk_statut, remise_percent";
$sql .= " FROM llx_propal WHERE rowid=$rowid;";
if ($this->db->query($sql) )
@@ -315,6 +317,7 @@ class Propal
$this->id = $rowid;
$this->datep = $obj->dp;
+ $this->fin_validite = $obj->dfv;
$this->date = $obj->dp;
$this->ref = $obj->ref;
$this->price = $obj->price;
@@ -329,7 +332,7 @@ class Propal
$this->contactid = $obj->fk_soc_contact;
$this->modelpdf = $obj->model_pdf;
$this->note = $obj->note;
-
+ $this->statut = $obj->fk_statut;
if ($obj->fk_statut == 0)
{
$this->brouillon = 1;
@@ -503,10 +506,12 @@ class Propal
/**
* Cloture de la propale
*
- *
*/
Function cloture($user, $statut, $note)
{
+ $this->statut = $statut;
+
+
$sql = "UPDATE llx_propal SET fk_statut = $statut, note = '$note', date_cloture=now(), fk_user_cloture=$user->id";
$sql .= " WHERE rowid = $this->id;";
@@ -516,8 +521,9 @@ class Propal
{
/* Propale signée */
include_once DOL_DOCUMENT_ROOT . "/commande/commande.class.php";
- $commande = new Commande($this->db);
- $commande->create_from_propale($user, $this->id);
+
+ $this->create_commande($user);
+
return 1;
}
else
@@ -531,8 +537,22 @@ class Propal
print $this->db->error() . ' in ' . $sql;
}
}
- /*
+ /**
*
+ *
+ */
+ Function create_commande($user)
+ {
+ if ($this->statut == 2)
+ {
+ /* Propale signée */
+ include_once DOL_DOCUMENT_ROOT . "/commande/commande.class.php";
+ $commande = new Commande($this->db);
+ $commande->create_from_propale($user, $this->id);
+ return 1;
+ }
+ }
+ /**
*
*
*/
@@ -551,7 +571,7 @@ class Propal
print $this->db->error() . ' in ' . $sql;
}
}
- /*
+ /**
*
*
*/
@@ -600,6 +620,38 @@ class Propal
print $this->db->error();
}
}
+ /**
+ * Renvoie un tableau contenant les numéros de commandes associées
+ *
+ */
+ Function commande_liste_array ()
+ {
+ $ga = array();
+
+ $sql = "SELECT fk_commande FROM llx_co_pr";
+ $sql .= " WHERE fk_propale = " . $this->id;
+ if ($this->db->query($sql) )
+ {
+ $nump = $this->db->num_rows();
+
+ if ($nump)
+ {
+ $i = 0;
+ while ($i < $nump)
+ {
+ $obj = $this->db->fetch_object($i);
+
+ $ga[$i] = $obj->fk_commande;
+ $i++;
+ }
+ }
+ return $ga;
+ }
+ else
+ {
+ print $this->db->error();
+ }
+ }
/*
*
*