diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index a170249aa77..d51b88e6739 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -422,7 +422,7 @@ if ($_GET['action'] == 'modif' && $user->rights->propale->creer)
*/
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
- $propal->reopen($user->id);
+ $propal->set_draft($user->id);
}
@@ -1554,16 +1554,18 @@ if ($conf->expedition->enabled)
*/
if($conf->commande->enabled)
{
- $coms = $propal->associated_orders();
+ $propal->loadOrders();
+ $coms = $propal->commandes;
if (sizeof($coms) > 0)
{
- print '
';
+ if ($somethingshown) { print '
'; $somethingshown=1; }
print_titre($langs->trans('RelatedOrders'));
print '
';
print '';
print '| '.$langs->trans("Ref").' | ';
print ''.$langs->trans("Date").' | ';
print ''.$langs->trans("Price").' | ';
+ print ''.$langs->trans("Status").' | ';
print '
';
$var=true;
for ($i = 0 ; $i < sizeof($coms) ; $i++)
@@ -1573,6 +1575,7 @@ if ($conf->expedition->enabled)
print ''.img_object($langs->trans("ShowOrder"),"order").' '.$coms[$i]->ref."\n";
print ''.dolibarr_print_date($coms[$i]->date).' | ';
print ''.$coms[$i]->total_ttc.' | ';
+ print ''.$coms[$i]->getLibStatut(3).' | ';
print "\n";
}
print '
';
diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index 4489efb5198..51c743c71d8 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -260,7 +260,7 @@ class Commande extends CommonObject
*
*
*/
- function reopen($userid)
+ function set_draft($userid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 0";
@@ -1052,11 +1052,11 @@ class Commande extends CommonObject
/**
- * \brief Renvoie un tableau avec les expéditions par ligne
+ * \brief Charge tableau avec les expéditions par ligne
* \param filtre_statut Filtre sur statut
* \return int 0 si OK, <0 si KO
*/
- function expedition_array($filtre_statut=-1)
+ function loadExpeditions($filtre_statut=-1)
{
$this->expeditions = array();
$sql = 'SELECT fk_product, sum(ed.qty)';
@@ -1068,11 +1068,11 @@ class Commande extends CommonObject
$result = $this->db->query($sql);
if ($result)
{
- $num = $this->db->num_rows();
+ $num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
- $row = $this->db->fetch_row( $i);
+ $row = $this->db->fetch_row($result);
$this->expeditions[$row[0]] = $row[1];
$i++;
}
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index aec088af08e..4ce0023dc73 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -420,7 +420,7 @@ if ($_GET['action'] == 'modif' && $user->rights->commande->creer)
*/
$commande = new Commande($db);
$commande->fetch($_GET['id']);
- $commande->reopen($user->id);
+ $commande->set_draft($user->id);
}
/*
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index e6577b5bff1..e835c3e69e1 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -203,7 +203,7 @@ if ($_GET['action'] == 'modif' && $user->rights->facture->modifier && $conf->glo
// On vérifie si aucun paiement n'a été effectué
if ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0)
{
- $fac->reopen($user);
+ $fac->set_draft($user);
}
}
diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php
index a8376fc600d..d8ab483573a 100644
--- a/htdocs/compta/paiement/fiche.php
+++ b/htdocs/compta/paiement/fiche.php
@@ -73,7 +73,7 @@ if ($_POST['action'] == 'confirm_valide' && $_POST['confirm'] == 'yes' && $user-
$paiement = new Paiement($db);
$paiement->id = $_GET['id'];
- if ( $paiement->valide() == 0 )
+ if ($paiement->valide() >= 0)
{
$db->commit();
Header('Location: fiche.php?id='.$paiement->id);
diff --git a/htdocs/compta/prelevement/rejet-prelevement.class.php b/htdocs/compta/prelevement/rejet-prelevement.class.php
index 355880fec57..0c8a06fb45e 100644
--- a/htdocs/compta/prelevement/rejet-prelevement.class.php
+++ b/htdocs/compta/prelevement/rejet-prelevement.class.php
@@ -132,7 +132,7 @@ class RejetPrelevement
/* Valide le paiement */
- if ($pai->valide() <> 0)
+ if ($pai->valide() < 0)
{
$error++;
dolibarr_syslog("RejetPrelevement::Create Erreur validation du paiement");
diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php
index a89075e9602..1bbfa484ddc 100644
--- a/htdocs/compta/propal.php
+++ b/htdocs/compta/propal.php
@@ -543,7 +543,7 @@ et non globalement
print '".$langs->trans("BuildBill")."";
}
- if ($propal->statut == 2 && sizeof($propal->getFactureListeArray()))
+ if ($propal->statut == 2 && sizeof($propal->getInvoiceArrayList()))
{
print '".$langs->trans("ClassifyBilled")."";
}
@@ -575,12 +575,10 @@ et non globalement
*/
if($conf->commande->enabled)
{
- $coms = $propal->associated_orders();
+ $propal->loadOrders();
+ $coms = $propal->commandes;
if (sizeof($coms) > 0)
{
- require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php');
- $staticcommande=new Commande($db);
-
$total=0;
if ($somethingshown) { print '
'; $somethingshown=1; }
print_titre($langs->trans('RelatedOrders'));
@@ -599,7 +597,7 @@ et non globalement
print ''.img_object($langs->trans("ShowOrder"),"order").' '.$coms[$i]->ref."\n";
print ''.dolibarr_print_date($coms[$i]->date).' | ';
print ''.price($coms[$i]->total_ttc).' | ';
- print ''.$staticcommande->LibStatut($coms[$i]->statut,$coms[$i]->facturee,3).' | ';
+ print ''.$coms[$i]->getLibStatut(3).' | ';
print "\n";
$total = $total + $objp->total;
}
diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php
index 6c68bfc63ad..e4cd3046619 100644
--- a/htdocs/expedition/commande.php
+++ b/htdocs/expedition/commande.php
@@ -85,7 +85,7 @@ if ($_GET["id"] > 0)
$commande = New Commande($db);
if ( $commande->fetch($_GET["id"]) > 0)
{
- $commande->expedition_array(1);
+ $commande->loadExpeditions(1);
$soc = new Societe($db);
$soc->fetch($commande->socidp);
diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index 811e9f70684..6a70f884313 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -186,7 +186,7 @@ if ($_GET["action"] == 'create')
}
$commande = new Commande($db);
- $commande->expedition_array();
+ $commande->loadExpeditions();
if ( $commande->fetch($_GET["commande_id"]))
{
@@ -274,7 +274,7 @@ if ($_GET["action"] == 'create')
$lignes = $commande->fetch_lignes(1);
/* Lecture des expeditions déjà effectuées */
- $commande->expedition_array();
+ $commande->loadExpeditions();
$num = sizeof($commande->lignes);
$i = 0;
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index f4d3d649b50..769e77c06b6 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -1140,7 +1140,7 @@ class Facture extends CommonObject
*
*
*/
- function reopen($userid)
+ function set_draft($userid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 0";
$sql .= " WHERE rowid = $this->id;";
diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php
index f8d3a1fc567..4b75103c932 100644
--- a/htdocs/fourn/commande/fiche.php
+++ b/htdocs/fourn/commande/fiche.php
@@ -136,8 +136,11 @@ if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->
$soc = new Societe($db);
$soc->fetch($commande->socidp);
$result = $commande->valid($user);
- Header("Location: fiche.php?id=".$_GET["id"]);
- exit;
+ if ($result >= 0)
+ {
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
+ }
}
if ($_POST["action"] == 'confirm_approve' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->approuver)
diff --git a/htdocs/fourn/paiement/fiche.php b/htdocs/fourn/paiement/fiche.php
index 0db280b0d30..448dea4b594 100644
--- a/htdocs/fourn/paiement/fiche.php
+++ b/htdocs/fourn/paiement/fiche.php
@@ -73,7 +73,7 @@ if ($_POST['action'] == 'confirm_valide' && $_POST['confirm'] == 'yes' && $user-
$paiement = new PaiementFourn($db);
$paiement->id = $_GET['id'];
- if ( $paiement->valide() == 0 )
+ if ($paiement->valide() >= 0)
{
$db->commit();
Header('Location: fiche.php?id='.$paiement->id);
diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php
index 60b6e717e11..6f9f7ca8d13 100644
--- a/htdocs/propal.class.php
+++ b/htdocs/propal.class.php
@@ -444,11 +444,10 @@ class Propal extends CommonObject
dolibarr_syslog("Propal::create ref=".$this->ref);
- $soc = new Societe($this->db);
- $soc->fetch($this->socidp);
-
$this->db->begin();
+ $this->fetch_client();
+
// Insertion dans la base
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, price, remise, remise_percent, remise_absolue,";
$sql.= " tva, total, datep, datec, ref, fk_user_author, note, note_public, model_pdf, fin_validite,";
@@ -476,10 +475,10 @@ class Propal extends CommonObject
$prod = new Product($this->db, $this->products[$i]);
if ($prod->fetch($this->products[$i]))
{
- $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
+ $tva_tx = get_default_tva($mysoc,$this->client,$prod->tva_tx);
// multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1)
- $price = $prod->multiprices[$soc->price_level];
+ $price = $prod->multiprices[$this->client->price_level];
else
$price = $prod->price;
@@ -1291,7 +1290,7 @@ class Propal extends CommonObject
*
*
*/
- function reopen($userid)
+ function set_draft($userid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 0";
@@ -1366,9 +1365,9 @@ class Propal extends CommonObject
/**
* \brief Renvoie un tableau contenant les numéros de commandes associées
* \remarks Fonction plus light que associated_orders
- * \sa associated_orders
+ * \sa loadOrders
*/
- function commande_liste_array ()
+ function getOrderArrayList()
{
$ga = array();
@@ -1398,26 +1397,29 @@ class Propal extends CommonObject
}
/**
- * \brief Renvoie un tableau contenant les commandes associées
- * \remarks Fonction plus lourde que commande_liste_array
- * \sa commande_liste_array
+ * \brief Charge tableau contenant les commandes associées
+ * \remarks Fonction plus lourde que getOrderArrayList
+ * \return int <0 si ko, >0 si ok
+ * \sa getOrdersArrayList
*/
- function associated_orders()
+ function loadOrders()
{
- $ga = array();
+ $this->commandes = array();
+ $ga = array();
$sql = "SELECT fk_commande FROM ".MAIN_DB_PREFIX."co_pr";
$sql.= " WHERE fk_propale = " . $this->id;
- if ($this->db->query($sql) )
+ $result=$this->db->query($sql);
+ if ($result)
{
- $nump = $this->db->num_rows();
+ $nump = $this->db->num_rows($result);
if ($nump)
{
$i = 0;
while ($i < $nump)
{
- $obj = $this->db->fetch_object();
+ $obj = $this->db->fetch_object($result);
$order=new Commande($this->db);
if ($obj->fk_commande)
@@ -1428,11 +1430,13 @@ class Propal extends CommonObject
$i++;
}
}
- return $ga;
+ $this->commandes=$ga;
+ return 1;
}
else
{
- print $this->db->error();
+ $this->error=$this->db->error();
+ return -1;
}
}
@@ -1440,9 +1444,9 @@ class Propal extends CommonObject
* \brief Renvoie un tableau contenant les numéros de factures associées
* \return array Tableau des id de factures
*/
- function getFactureListeArray ()
+ function getInvoiceArrayList ()
{
- return $this->FactureListeArray($this->id);
+ return $this->InvoiceArrayList($this->id);
}
/**
@@ -1450,7 +1454,7 @@ class Propal extends CommonObject
* \param id Id propal
* \return array Tableau des id de factures
*/
- function FactureListeArray($id)
+ function InvoiceArrayList($id)
{
$ga = array();
@@ -1479,60 +1483,60 @@ class Propal extends CommonObject
}
}
- /**
- * \brief Efface propal
- * \param user Objet du user qui efface
- */
- function delete($user)
- {
- global $conf;
-
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id;
- if ( $this->db->query($sql) )
- {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
- if ( $this->db->query($sql) )
- {
-
- // On efface le répertoire du pdf
- $propalref = sanitize_string($this->ref);
- if ($conf->propal->dir_output)
- {
- $dir = $conf->propal->dir_output . "/" . $propalref ;
- $file = $conf->propal->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
- if (file_exists($file))
- {
- propale_delete_preview($this->db, $this->id, $this->ref);
-
- if (!dol_delete_file($file))
- {
- $this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
- return 0;
- }
- }
- if (file_exists($dir))
- {
- if (!dol_delete_dir($dir))
- {
- $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
- return 0;
- }
- }
- }
-
- dolibarr_syslog("Suppression de la proposition $this->id par $user->fullname ($user->id)");
- return 1;
- }
- else
- {
- return -2;
- }
- }
- else
- {
- return -1;
- }
- }
+ /**
+ * \brief Efface propal
+ * \param user Objet du user qui efface
+ */
+ function delete($user)
+ {
+ global $conf;
+
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id;
+ if ( $this->db->query($sql) )
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
+ if ( $this->db->query($sql) )
+ {
+
+ // On efface le répertoire du pdf
+ $propalref = sanitize_string($this->ref);
+ if ($conf->propal->dir_output)
+ {
+ $dir = $conf->propal->dir_output . "/" . $propalref ;
+ $file = $conf->propal->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
+ if (file_exists($file))
+ {
+ propale_delete_preview($this->db, $this->id, $this->ref);
+
+ if (!dol_delete_file($file))
+ {
+ $this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
+ return 0;
+ }
+ }
+ if (file_exists($dir))
+ {
+ if (!dol_delete_dir($dir))
+ {
+ $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
+ return 0;
+ }
+ }
+ }
+
+ dolibarr_syslog("Suppression de la proposition $this->id par $user->fullname ($user->id)");
+ return 1;
+ }
+ else
+ {
+ return -2;
+ }
+ }
+ else
+ {
+ return -1;
+ }
+ }
/**
* \brief Mets à jour les commentaires privés
@@ -1820,10 +1824,13 @@ class Propal extends CommonObject
*/
function create_from()
{
+ $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
+
+ dolibarr_syslog("Propal::create_from ref=".$this->ref);
$this->db->begin();
- $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
+ $this->fetch_client();
// Insertion dans la base
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, price, remise, remise_percent, remise_absolue,";
@@ -1834,6 +1841,7 @@ class Propal extends CommonObject
$sql.= "'".addslashes($this->note_public)."',";
$sql.= "'$this->modelpdf','".$this->db->idate($this->fin_validite)."',";
$sql.= " '$this->cond_reglement_id', '$this->mode_reglement_id', '".$this->db->idate($this->date_livraison)."', '$this->adresse_livraison_id')";
+
$resql=$this->db->query($sql);
if ($resql)
{
@@ -1848,10 +1856,10 @@ class Propal extends CommonObject
{
$resql = $this->addline(
$this->id,
- $prod->description,
- $price,
+ $ligne->description,
+ $ligne->price,
$ligne->qty,
- $tva_tx,
+ $ligne->tva_tx,
$ligne->fk_product,
$ligne->remise_percent
);
@@ -1864,32 +1872,30 @@ class Propal extends CommonObject
}
}
- // Affectation au projet
- if ($this->projetidp)
- {
- $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_projet=$this->projetidp WHERE ref='$this->ref'";
- $result=$this->db->query($sql);
- }
-
- $resql=$this->update_price();
- if ($resql)
- {
- // Appel des triggers
- include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
- $interface=new Interfaces($this->db);
- $result=$interface->run_triggers('PROPAL_CREATE',$this,$user,$langs,$conf);
- // Fin appel triggers
-
- $this->db->commit();
- return $this->id;
- }
- else
- {
- $this->error=$this->db->error();
- dolibarr_syslog("Propal::Create_from -2 ".$this->error);
- $this->db->rollback();
- return -2;
- }
+ if ($resql)
+ {
+ // Mise a jour infos dénormalisés
+ $resql=$this->update_price();
+ if ($resql)
+ {
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('PROPAL_CREATE',$this,$user,$langs,$conf);
+ // Fin appel triggers
+
+ $this->db->commit();
+ dolibarr_syslog("Propal::Create_from done id=".$this->id);
+ return $this->id;
+ }
+ else
+ {
+ $this->error=$this->db->error();
+ dolibarr_syslog("Propal::Create_from -2 ".$this->error);
+ $this->db->rollback();
+ return -2;
+ }
+ }
}
}
else
@@ -1900,6 +1906,8 @@ class Propal extends CommonObject
return -1;
}
+ $this->db->commit();
+ dolibarr_syslog("Propal::Create_from done id=".$this->id);
return $this->id;
}