diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 0d28b8f7cf3..7c4e4489629 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -109,7 +109,8 @@ if ($_POST["action"] == 'add')
{
for ($i = 1 ; $i <= $NBLINES ; $i++)
{
- if ($_POST["idprod${i}"]) {
+ if ($_POST["idprod${i}"])
+ {
$startday='';
$endday='';
if ($_POST["date_start${i}year"] && $_POST["date_start${i}month"] && $_POST["date_start${i}day"]) {
diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php
index 50a56c979cf..28a21761f24 100644
--- a/htdocs/contrat/contrat.class.php
+++ b/htdocs/contrat/contrat.class.php
@@ -318,60 +318,136 @@ class Contrat
}
- /**
- * \brief Ajoute une ligne de commande
- * \return int <0 si KO, =0 si OK
- */
- function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
- {
- global $langs;
-
- $qty = ereg_replace(",",".",$qty);
- $pu = ereg_replace(",",".",$pu);
-
- if (strlen(trim($qty))==0)
+ /**
+ * \brief Ajoute une ligne de contrat en base
+ * \param rowid Id de la ligne de facture
+ * \param desc Description de la ligne
+ * \param pu Prix unitaire
+ * \param qty Quantité
+ * \param remise_percent Pourcentage de remise de la ligne
+ * \param datestart Date de debut prévue
+ * \param dateend Date de fin prévue
+ * \return int < 0 si erreur, > 0 si ok
+ */
+ function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $datestart, $dateend)
{
- $qty=1;
- }
-
- if ($fk_product > 0)
- {
- $prod = new Product($this->db, $fk_product);
- if ($prod->fetch($fk_product) > 0)
+ global $langs;
+
+ $qty = ereg_replace(",",".",$qty);
+ $pu = ereg_replace(",",".",$pu);
+
+ if (strlen(trim($qty))==0)
{
- $label = $prod->libelle;
- $pu = $prod->price;
- $txtva = $prod->tva_tx;
+ $qty=1;
+ }
+
+ if ($fk_product > 0)
+ {
+ $prod = new Product($this->db, $fk_product);
+ if ($prod->fetch($fk_product) > 0)
+ {
+ $label = $prod->libelle;
+ $pu = $prod->price;
+ $txtva = $prod->tva_tx;
+ }
+ }
+
+ $remise = 0;
+ $price = round(ereg_replace(",",".",$pu), 2);
+ $subprice = $price;
+ if (trim(strlen($remise_percent)) > 0)
+ {
+ $remise = round(($pu * $remise_percent / 100), 2);
+ $price = $pu - $remise;
+ }
+
+ // Insertion dans la base
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet ";
+ $sql.= "(fk_contrat,label,description,fk_product, price_ht,qty,tva_tx, remise_percent, subprice, remise";
+ if ($datestart > 0) { $sql.= ",date_ouverture_prevue"; }
+ if ($dateend > 0) { $sql.= ",date_fin_validite"; }
+ $sql.= ") VALUES ($this->id, '" . addslashes($label) . "','" . addslashes($desc) . "',$fk_product,".ereg_replace(",",".",$price).", '$qty', $txtva, $remise_percent,'".ereg_replace(",",".",$subprice)."','".ereg_replace(",",".", $remise)."'";
+ if ($datestart > 0) { $sql.= ",".$this->db->idate($datestart); }
+ if ($dateend > 0) { $sql.= ",".$this->db->idate($dateend); }
+ $sql.= ");";
+
+ // Retour
+ if ( $this->db->query($sql) )
+ {
+ //$this->update_price();
+ return 0;
+ }
+ else
+ {
+ dolibarr_print_error($this->db);
+ return -1;
}
}
- $remise = 0;
- $price = round(ereg_replace(",",".",$pu), 2);
- $subprice = $price;
- if (trim(strlen($remise_percent)) > 0)
+ /**
+ * \brief Mets à jour une ligne de contrat
+ * \param rowid Id de la ligne de facture
+ * \param desc Description de la ligne
+ * \param pu Prix unitaire
+ * \param qty Quantité
+ * \param remise_percent Pourcentage de remise de la ligne
+ * \param datestart Date de debut prévue
+ * \param dateend Date de fin prévue
+ * \return int < 0 si erreur, > 0 si ok
+ */
+ function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $datestart='', $dateend='')
{
- $remise = round(($pu * $remise_percent / 100), 2);
- $price = $pu - $remise;
- }
+ dolibarr_syslog("Contrat::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $datestart, $dateend");
+
+ $this->db->begin();
- // Insertion dans la base
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet ";
- $sql .= "(fk_contrat,label,description,fk_product, price_ht,qty,tva_tx, remise_percent, subprice, remise)";
- $sql .= " VALUES ($this->id, '" . addslashes($label) . "','" . addslashes($desc) . "',$fk_product,".ereg_replace(",",".",$price).", '$qty', $txtva, $remise_percent,'".ereg_replace(",",".",$subprice)."','".ereg_replace(",",".", $remise)."') ;";
+ if (strlen(trim($qty))==0)
+ {
+ $qty=1;
+ }
+ $remise = 0;
+ $price = ereg_replace(",",".",$pu);
+ $subprice = $price;
+ if (trim(strlen($remise_percent)) > 0)
+ {
+ $remise = round(($pu * $remise_percent / 100), 2);
+ $price = $pu - $remise;
+ }
+ else
+ {
+ $remise_percent=0;
+ }
- // Retour
- if ( $this->db->query( $sql) )
- {
- //$this->update_price();
- return 0;
- }
- else
- {
- dolibarr_print_error($this->db);
- return -1;
- }
- }
+ $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet set description='".addslashes($desc)."'";
+ $sql .= ",price_ht='" . ereg_replace(",",".",$price)."'";
+ $sql .= ",subprice='" . ereg_replace(",",".",$subprice)."'";
+ $sql .= ",remise='". ereg_replace(",",".",$remise)."'";
+ $sql .= ",remise_percent='".ereg_replace(",",".",$remise_percent)."'";
+ $sql .= ",qty='$qty'";
+ if ($datestart > 0) { $sql.= ",date_ouverture_prevue=".$this->db->idate($datestart); }
+ else { $sql.=",date_ouverture_prevue=null"; }
+ if ($dateend > 0) { $sql.= ",date_fin_validite=".$this->db->idate($dateend); }
+ else { $sql.=",date_fin_validite=null"; }
+
+ $sql .= " WHERE rowid = $rowid ;";
+
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $this->db->commit();
+
+ return $result;
+ }
+ else
+ {
+ $this->db->rollback();
+
+ dolibarr_print_error($this->db);
+ return -1;
+ }
+ }
+
/**
* \brief Supprime une ligne de detail du contrat
* \param idligne id de la ligne detail de contrat à supprimer
diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php
index 62a521fc6a2..201b239462a 100644
--- a/htdocs/contrat/fiche.php
+++ b/htdocs/contrat/fiche.php
@@ -43,6 +43,11 @@ require("../project.class.php");
require("../propal.class.php");
require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php");
+$date_start_update=mktime(12, 0 , 0, $_POST["date_start_updatemonth"], $_POST["date_start_updateday"], $_POST["date_start_updateyear"]);
+$date_end_update=mktime(12, 0 , 0, $_POST["date_end_updatemonth"], $_POST["date_end_updateday"], $_POST["date_end_updateyear"]);
+$date_start=mktime(12, 0 , 0, $_POST["date_startmonth"], $_POST["date_startday"], $_POST["date_startyear"]);
+$date_end=mktime(12, 0 , 0, $_POST["date_endmonth"], $_POST["date_endday"], $_POST["date_endyear"]);
+
/*
* Sécurité accés client
*/
@@ -106,7 +111,10 @@ if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
$_POST["pqty"],
$_POST["tva_tx"],
$_POST["p_idprod"],
- $_POST["premise"]);
+ $_POST["premise"],
+ $date_start,
+ $date_end
+ );
}
if ($result >= 0)
@@ -122,13 +130,25 @@ if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer)
{
$contrat = new Contrat($db,"",$_GET["id"]);
- if ($contrat->fetch($_GET["id"]) )
+ if ($contrat->fetch($_GET["id"]))
{
- $result = $contrat->update_line($_POST["elrowid"],
- $_POST["eldesc"],
- $_POST["elprice"],
- $_POST["elqty"],
- $_POST["elremise_percent"]);
+ $result = $contrat->updateline($_POST["elrowid"],
+ $_POST["eldesc"],
+ $_POST["elprice"],
+ $_POST["elqty"],
+ $_POST["elremise_percent"],
+ $date_start_update,
+ $date_end_update
+ );
+ if ($result > 0)
+ {
+ $db->commit();
+ }
+ else
+ {
+ dolibarr_print_error($db,"result=$result");
+ $db->rollback();
+ }
}
else
{
@@ -212,13 +232,13 @@ if ($_GET["action"] == 'create')
$sql .= "FROM ".MAIN_DB_PREFIX."societe as s ";
$sql .= "WHERE s.idp = ".$_GET["socid"];
-
- if ( $db->query($sql) )
+ $resql=$db->query($sql);
+ if ($resql)
{
- $num = $db->num_rows();
+ $num = $db->num_rows($resql);
if ($num)
{
- $obj = $db->fetch_object();
+ $obj = $db->fetch_object($resql);
$soc = new Societe($db);
$soc->fetch($obj->idp);
@@ -230,26 +250,27 @@ if ($_GET["action"] == 'create')
print '
';
@@ -336,17 +357,17 @@ if ($_GET["action"] == 'create')
$result = $db->query($sql);
if ($result)
{
- $num = $db->num_rows();
+ $num = $db->num_rows($result);
$i = 0;
$var=True;
while ($i < $num)
{
- $objp = $db->fetch_object();
+ $objp = $db->fetch_object($result);
$var=!$var;
print "[$objp->ref] \n";
print ''.$objp->product.' ';
print "".price($objp->price)." ";
- print ''.$objp->remise_percent.' % ';
+ print ''.$objp->remise_percent.'% ';
print "".$objp->qty." \n";
$i++;
}
@@ -354,18 +375,19 @@ if ($_GET["action"] == 'create')
$sql = "SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent";
$sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt WHERE pt.fk_propal = $propalid AND pt.fk_product = 0";
$sql .= " ORDER BY pt.rowid ASC";
- if ($db->query($sql))
+ $result=$db->query($sql);
+ if ($result)
{
- $num = $db->num_rows();
+ $num = $db->num_rows($result);
$i = 0;
while ($i < $num)
{
- $objp = $db->fetch_object();
+ $objp = $db->fetch_object($result);
$var=!$var;
print " \n";
print ''.$objp->product.' ';
print ''.price($objp->price).' ';
- print ''.$objp->remise_percent.' % ';
+ print ''.$objp->remise_percent.'% ';
print "".$objp->qty." \n";
$i++;
}
@@ -501,8 +523,8 @@ else
print "";
}
- print ''.$langs->trans("Commercial suivi").' '.$commercial_suivi->fullname.' ';
- print ''.$langs->trans("Commercial signature").' '.$commercial_signature->fullname.' ';
+ print ''.$langs->trans("SalesRepresentativeFollowUp").' '.$commercial_suivi->fullname.' ';
+ print ''.$langs->trans("SalesRepresentativeSignature").' '.$commercial_signature->fullname.' ';
print "";
if ($contrat->brouillon == 1 && $user->rights->contrat->creer)
@@ -523,7 +545,6 @@ else
$sql.= " ORDER BY cd .rowid";
$result = $db->query($sql);
-
if ($result)
{
$num = $db->num_rows($result);
@@ -532,13 +553,14 @@ else
if ($num)
{
print '';
- print ''.$langs->trans("Status").' ';
print ''.$langs->trans("Service").' ';
- print ''.$langs->trans("VAT").' ';
- print ''.$langs->trans("Qty").' ';
- print ''.$langs->trans("Discount").' ';
- print ''.$langs->trans("PriceU").' ';
- print ' ';
+ print ''.$langs->trans("VAT").' ';
+ print ''.$langs->trans("PriceUHT").' ';
+ print ''.$langs->trans("Qty").' ';
+ print ''.$langs->trans("Discount").' ';
+ print ' ';
+ print ' ';
+ print ''.$langs->trans("Status").' ';
print " \n";
}
$var=true;
@@ -547,117 +569,131 @@ else
$objp = $db->fetch_object($result);
$var=!$var;
- print '';
- if ($objp->fk_product > 0)
- {
- print '';
- print '';;
- print ' ';
- print '';
- print img_object($langs->trans("ShowService"),"service").' '.$objp->label.' ';
- if ($objp->description)
+ if ($_GET["action"] != 'editline' || $_GET["rowid"] != $objp->rowid)
+ {
+
+ print ' ';
+ if ($objp->fk_product > 0)
{
-
- print ' '.stripslashes(nl2br($objp->description));
+ print '';
+ print '';
+ print img_object($langs->trans("ShowService"),"service").' '.$objp->label.' ';
+ if ($objp->description) print ' '.stripslashes(nl2br($objp->description));
+ print ' ';
+ }
+ else
+ {
+ print "".stripslashes(nl2br($objp->description))." \n";
+ }
+ // TVA
+ print ''.$objp->tva_tx.'% ';
+ // Prix
+ print ''.price($objp->subprice)." \n";
+ // Quantité
+ print ''.$objp->qty.' ';
+ // Remise
+ if ($objp->remise_percent > 0)
+ {
+ print ''.$objp->remise_percent."% \n";
+ }
+ else
+ {
+ print ' ';
+ }
+ // Icon update et delete
+ if ($contrat->statut == 0 && $objp->statut == 0 && $user->rights->contrat->creer)
+ {
+ print '';
+ print img_edit();
+ print ' ';
+ print '';
+ print img_delete();
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+
+ if ($objp->fk_product > 0) {
+ print '';
+ print '';;
+ print ' ';
+ }
+ print " \n";
+
+ // Dates mise en service
+ print '';
+ print '';
+ // Si pas encore activé
+ if (! $objp->date_debut_reelle) {
+ print $langs->trans("DateStartPlanned").': ';
+ if ($objp->date_debut) print dolibarr_print_date($objp->date_debut);
+ else print $langs->trans("Unknown");
+ }
+ // Si activé
+ if ($objp->date_debut_reelle) {
+ print $langs->trans("DateStartReal").': ';
+ if ($objp->date_debut_reelle) print dolibarr_print_date($objp->date_debut_reelle);
+ else print $langs->trans("ContractStatusNotRunning");
}
+ print ' - ';
+
+ // Si pas encore activé
+ if (! $objp->date_debut_reelle) {
+ print $langs->trans("DateEndPlanned").': ';
+ if ($objp->date_fin) {
+ print dolibarr_print_date($objp->date_fin);
+ }
+ else print $langs->trans("Unknown");
+ }
+ // Si activé
+ if ($objp->date_debut_reelle && ! $objp->date_fin_reelle) {
+ print $langs->trans("DateEndPlanned").': ';
+ if ($objp->date_fin) {
+ print dolibarr_print_date($objp->date_fin);
+ if ($objp->date_fin < time()) { print " ".img_warning($langs->trans("Late")); }
+ }
+ else print $langs->trans("Unknown");
+ }
+ if ($objp->date_debut_reelle && $objp->date_fin_reelle) {
+ print $langs->trans("DateEndReal").': ';
+ dolibarr_print_date($objp->date_fin_reelle);
+ }
print ' ';
- }
- else
- {
- print "".stripslashes(nl2br($objp->description))." \n";
- }
- print ''.$objp->tva_tx.' % ';
- print ''.$objp->qty.' ';
- if ($objp->remise_percent > 0)
- {
- print ''.$objp->remise_percent." % \n";
- }
- else
- {
print ' ';
- }
-
- print ''.price($objp->subprice)." \n";
-
- // Icon delete
- if ($contrat->statut == 0 && $objp->statut == 0 && $user->rights->contrat->creer)
- {
- // print '';
- // print img_edit();
- // print ' ';
- print '';
- print img_delete();
- print ' ';
+ print ' ';
}
else
- {
- print ' ';
- }
- print "\n";
-
- // Dates mise en service
- print '';
- print ' ';
- print '';
- // Si pas encore activé
- if (! $objp->date_debut_reelle) {
- print $langs->trans("DateStartPlanned").': ';
- if ($objp->date_debut) print dolibarr_print_date($objp->date_debut);
- else print $langs->trans("Unknown");
- }
- // Si activé
- if ($objp->date_debut_reelle) {
- print $langs->trans("DateStartReal").': ';
- if ($objp->date_debut_reelle) print dolibarr_print_date($objp->date_debut_reelle);
- else print $langs->trans("ContractStatusNotRunning");
- }
-
- print ' - ';
-
- // Si pas encore activé
- if (! $objp->date_debut_reelle) {
- print $langs->trans("DateEndPlanned").': ';
- if ($objp->date_fin) {
- print dolibarr_print_date($objp->date_fin);
- }
- else print $langs->trans("Unknown");
- }
- // Si activé
- if ($objp->date_debut_reelle && ! $objp->date_fin_reelle) {
- print $langs->trans("DateEndPlanned").': ';
- if ($objp->date_fin) {
- print dolibarr_print_date($objp->date_fin);
- if ($objp->date_fin < time()) { print " ".img_warning($langs->trans("Late")); }
- }
- else print $langs->trans("Unknown");
- }
- if ($objp->date_debut_reelle && $objp->date_fin_reelle) {
- print $langs->trans("DateEndReal").': ';
- dolibarr_print_date($objp->date_fin_reelle);
- }
- print ' ';
- print ' ';
-
- if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid)
{
print "\n";
}
$i++;
}
- $db->free();
+ $db->free($result);
}
else
{
@@ -675,13 +711,14 @@ else
print ' ';
print "";
- print ' ';
print ''.$langs->trans("Service").' ';
print ''.$langs->trans("VAT").' ';
+ print ''.$langs->trans("PriceUHT").' ';
print ''.$langs->trans("Qty").' ';
print ''.$langs->trans("Discount").' ';
- print ''.$langs->trans("PriceU").' ';
- print ' '." \n";
+ print ' ';
+ print ' ';
+ print "\n";
/*
print "".' ';
@@ -695,22 +732,29 @@ else
print ' ';
*/
- $var=!$var;
+ $var=false;
print "";
- print ' ';
print '';
$html->select_produits('','p_idprod');
print ' ';
- print ' ';
- print ' % ';
print ' ';
- print ' ';
+ print ' ';
+ print ' % ';
+ print ' ';
print "\n";
print "";
- print ' ';
- print ' ';
+ print ' ';
print ' ';
+ print "";
+ print '';
+ print 'Date prévue mise en service ';
+ $html->select_date('',"date_start",0,0,1);
+ print ' Date prévue fin de service ';
+ $html->select_date('',"date_end",0,0,1);
+ print ' ';
+ print ' ';
+
print "";
}
print " ";
diff --git a/htdocs/contrat/ligne.php b/htdocs/contrat/ligne.php
index 95b29895a40..0e18f618d70 100644
--- a/htdocs/contrat/ligne.php
+++ b/htdocs/contrat/ligne.php
@@ -154,8 +154,8 @@ $html = new Form($db);
print "";
}
- print ''.$langs->trans("Commercial suivi").' '.$commercial_suivi->fullname.' ';
- print ''.$langs->trans("Commercial signature").' '.$commercial_signature->fullname.' ';
+ print ''.$langs->trans("SalesRepresentativeFollowUp").' '.$commercial_suivi->fullname.' ';
+ print ''.$langs->trans("SalesRepresentativeSignature").' '.$commercial_signature->fullname.' ';
print "";
@@ -194,15 +194,16 @@ $html = new Form($db);
if ($num)
{
- print '';
- print ''.$langs->trans("Status").' ';
- print ''.$langs->trans("Service").' ';
- print ''.$langs->trans("VAT").' ';
- print ''.$langs->trans("Qty").' ';
- print ''.$langs->trans("Discount").' ';
- print ''.$langs->trans("PriceU").' ';
- print ' ';
- print " \n";
+ print '';
+ print ''.$langs->trans("Service").' ';
+ print ''.$langs->trans("VAT").' ';
+ print ''.$langs->trans("PriceUHT").' ';
+ print ''.$langs->trans("Qty").' ';
+ print ''.$langs->trans("Discount").' ';
+ print ' ';
+ print ' ';
+ print ''.$langs->trans("Status").' ';
+ print " \n";
}
$var=true;
while ($i < $num)
@@ -210,10 +211,11 @@ $html = new Form($db);
$objp = $db->fetch_object($result);
$var=!$var;
- print "\n";
- if ($objp->fk_product > 0)
+ print " \n";
+
+ // Libellé
+ if ($objp->fk_product > 0)
{
- print ' ';
print ''.img_object($langs->trans("ShowService"),"service").' '.$objp->label.' ';
if ($objp->description)
@@ -227,20 +229,29 @@ $html = new Form($db);
{
print ' '.stripslashes(nl2br($objp->description))." \n";
}
- print ''.$objp->tva_tx.' % ';
+ print ''.$objp->tva_tx.'% ';
+
+ print ''.price($objp->subprice)." \n";
+
print ''.$objp->qty.' ';
+
if ($objp->remise_percent > 0)
{
- print ''.$objp->remise_percent." % \n";
+ print ''.$objp->remise_percent."% \n";
}
else
{
print ' ';
}
- print ''.price($objp->subprice)." \n";
print ' ';
+ if ($objp->fk_product > 0) {
+ print ' ';
+ } else {
+ print ' ';
+ }
+
print " \n";
if ($objp->date_debut) $dateactstart=$objp->date_debut;
@@ -248,7 +259,6 @@ $html = new Form($db);
// Dates mise en service
print '';
- print ' ';
print '';
// Si pas encore activé
if (! $objp->date_debut_reelle) {
@@ -287,6 +297,7 @@ $html = new Form($db);
dolibarr_print_date($objp->date_fin_reelle);
}
print ' ';
+ print ' ';
print ' ';
@@ -316,8 +327,6 @@ $html = new Form($db);
print '';
print ''.$langs->trans("ActivateService").' ';
- print ''.$langs->trans("User").' '.$user->fullname.' ';
-
// Definie date debut et fin par defaut
if ($_POST["remonth"]) $dateactstart = mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
elseif (! $dateactstart) $dateactstart = time();