Ajout possibilité de modifier une ligne de propale

This commit is contained in:
Rodolphe Quiedeville 2005-08-02 07:23:45 +00:00
parent 4029cdebda
commit ea835c93c1
2 changed files with 1319 additions and 1238 deletions

File diff suppressed because it is too large Load Diff

View File

@ -159,21 +159,65 @@ class Propal
} }
} }
} }
/**
* \brief Mise à jour d'une ligne de produit
* \param id id de la ligne
* \param subprice prix unitaire
* \param qty quantité
* \param remise_percent remise effectuée sur le produit
* \return int 0 en cas de succès
*/
function UpdateLigne($id, $subprice, $qty, $remise_percent=0)
{
if ($this->statut == 0)
{
$price = $subprice;
if ($remise_percent > 0)
{
$remise = round(($subprice * $remise_percent / 100), 2);
$price = $subprice - $remise;
}
$sql = "UPDATE ".MAIN_DB_PREFIX."propaldet ";
$sql .= " SET qty='".$qty."'";
$sql .= " , price='". ereg_replace(",",".",$price)."'";
$sql .= " , remise_percent='".ereg_replace(",",".",$remise_percent)."'";
$sql .= " , subprice='".ereg_replace(",",".",$subprice)."'";
$sql .= " WHERE rowid = '".$id."';";
if ($this->db->query($sql) )
{
$this->update_price();
return 0;
}
else
{
dolibarr_syslog("Propal::UpdateLigne Erreur -1");
return -1;
}
}
else
{
dolibarr_syslog("Propal::UpdateLigne Erreur -2 Propal en mode incompatible pour cette action");
return -2;
}
}
/** /**
* *
* *
*/ */
function insert_product_generic($p_desc, $p_price, $p_qty, $p_tva_tx=19.6, $remise_percent=0) function insert_product_generic($p_desc, $p_price, $p_qty, $p_tva_tx=19.6, $remise_percent=0)
{ {
if ($this->statut == 0) if ($this->statut == 0)
{ {
if (strlen(trim($p_qty)) == 0) if (strlen(trim($p_qty)) == 0)
{ {
$p_qty = 1; $p_qty = 1;
} }
$p_price = ereg_replace(",",".",$p_price); $p_price = ereg_replace(",",".",$p_price);
$price = $p_price; $price = $p_price;
@ -303,13 +347,13 @@ class Propal
} }
} }
else else
{ {
dolibarr_print_error($this->db); //dolibarr_print_error($this->db);
} }
} }
else else
{ {
dolibarr_print_error($this->db); //dolibarr_print_error($this->db);
} }
return $this->id; return $this->id;
} }
@ -374,144 +418,150 @@ class Propal
* \brief Recupère de la base les caractéristiques d'une propale * \brief Recupère de la base les caractéristiques d'une propale
* \param rowid id de la propal à récupérer * \param rowid id de la propal à récupérer
*/ */
function fetch($rowid) function fetch($rowid)
{ {
$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_projet, fk_statut, remise_percent, fk_user_author"; $sql = "SELECT ref,total,price,remise,tva,fk_soc,fk_soc_contact";
$sql .= ", c.label as statut_label"; $sql .= " ,".$this->db->pdate("datep")."as dp";
$sql .= " FROM ".MAIN_DB_PREFIX."propal"; $sql .= " ,".$this->db->pdate("fin_validite")."as dfv, model_pdf, note";
$sql .= "," . MAIN_DB_PREFIX."c_propalst as c"; $sql .= " , fk_projet, fk_statut, remise_percent, fk_user_author";
$sql .= " WHERE rowid=$rowid AND fk_statut = c.id"; $sql .= ", c.label as statut_label";
$sql .= " FROM ".MAIN_DB_PREFIX."propal";
$sql .= "," . MAIN_DB_PREFIX."c_propalst as c";
$sql .= " WHERE fk_statut = c.id";
$sql .= " AND rowid='".$rowid."';";
$resql=$this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->id = $rowid;
$this->datep = $obj->dp;
$this->fin_validite = $obj->dfv;
$this->date = $obj->dp;
$this->ref = $obj->ref;
$this->price = $obj->price;
$this->remise = $obj->remise;
$this->remise_percent = $obj->remise_percent;
$this->total = $obj->total;
$this->total_ht = $obj->price;
$this->total_tva = $obj->tva;
$this->total_ttc = $obj->total;
$this->socidp = $obj->fk_soc;
$this->soc_id = $obj->fk_soc;
$this->projetidp = $obj->fk_projet;
$this->contactid = $obj->fk_soc_contact;
$this->modelpdf = $obj->model_pdf;
$this->note = $obj->note;
$this->statut = $obj->fk_statut;
$this->statut_libelle = $obj->statut_label;
$this->user_author_id = $obj->fk_user_author;
if ($obj->fk_statut == 0)
{
$this->brouillon = 1;
}
$resql=$this->db->query($sql); $this->lignes = array();
if ($resql) $this->db->free($resql);
{
if ($this->db->num_rows($resql)) $this->ref_url = '<a href="'.DOL_URL_ROOT.'/comm/propal.php?propalid='.$this->id.'">'.$this->ref.'</a>';
{
$obj = $this->db->fetch_object($resql);
$this->id = $rowid; /*
* Lignes produits
$this->datep = $obj->dp; */
$this->fin_validite = $obj->dfv;
$this->date = $obj->dp; $sql = "SELECT p.rowid, p.label, p.description, p.ref, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice";
$this->ref = $obj->ref; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d, ".MAIN_DB_PREFIX."product as p";
$this->price = $obj->price; $sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = p.rowid ORDER by d.rowid ASC";
$this->remise = $obj->remise;
$this->remise_percent = $obj->remise_percent; $result = $this->db->query($sql);
$this->total = $obj->total; if ($result)
$this->total_ht = $obj->price; {
$this->total_tva = $obj->tva; $num = $this->db->num_rows($result);
$this->total_ttc = $obj->total; $i = 0;
$this->socidp = $obj->fk_soc;
$this->soc_id = $obj->fk_soc;
$this->projetidp = $obj->fk_projet;
$this->contactid = $obj->fk_soc_contact;
$this->modelpdf = $obj->model_pdf;
$this->note = $obj->note;
$this->statut = $obj->fk_statut;
$this->statut_libelle = $obj->statut_label;
$this->user_author_id = $obj->fk_user_author; while ($i < $num)
{
$objp = $this->db->fetch_object($result);
if ($obj->fk_statut == 0) $ligne = new PropaleLigne();
{ $ligne->libelle = stripslashes($objp->label);
$this->brouillon = 1; $ligne->desc = stripslashes($objp->description);
} $ligne->qty = $objp->qty;
$ligne->ref = $objp->ref;
$ligne->tva_tx = $objp->tva_tx;
$ligne->subprice = $objp->subprice;
$ligne->remise_percent = $objp->remise_percent;
$ligne->price = $objp->price;
$ligne->product_id = $objp->rowid;
$this->lignes = array(); $this->lignes[$i] = $ligne;
$this->db->free(); $i++;
}
$this->db->free($result);
}
else
{
dolibarr_syslog("Propal::Fetch Erreur lecture des produits");
return -1;
}
$this->ref_url = '<a href="'.DOL_URL_ROOT.'/comm/propal.php?propalid='.$this->id.'">'.$this->ref.'</a>'; /*
* Lignes propales
*/
$sql = "SELECT d.qty, d.description, d.price, d.subprice, d.tva_tx, d.rowid, d.remise_percent";
$sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d";
$sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = 0";
/* $result = $this->db->query($sql);
* Lignes produits if ($result)
*/ {
$num = $this->db->num_rows($result);
$j = 0;
$sql = "SELECT p.rowid, p.label, p.description, p.ref, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice"; while ($j < $num)
$sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d, ".MAIN_DB_PREFIX."product as p"; {
$sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = p.rowid ORDER by d.rowid ASC"; $objp = $this->db->fetch_object($result);
$ligne = new PropaleLigne();
$ligne->libelle = stripslashes($objp->description);
$ligne->desc = stripslashes($objp->description);
$ligne->qty = $objp->qty;
$ligne->ref = $objp->ref;
$ligne->tva_tx = $objp->tva_tx;
$ligne->subprice = $objp->subprice;
$ligne->remise_percent = $objp->remise_percent;
$ligne->price = $objp->price;
$ligne->product_id = 0;
$result = $this->db->query($sql); $this->lignes[$i] = $ligne;
if ($result) $i++;
{ $j++;
$num = $this->db->num_rows($result); }
$i = 0;
while ($i < $num) $this->db->free($result);
{ }
$objp = $this->db->fetch_object($result); else
{
$ligne = new PropaleLigne(); dolibarr_syslog("Propal::Fetch Erreur lecture des lignes de propale");
$ligne->libelle = stripslashes($objp->label);
$ligne->desc = stripslashes($objp->description); return -1;
$ligne->qty = $objp->qty; }
$ligne->ref = $objp->ref; }
$ligne->tva_tx = $objp->tva_tx; return 1;
$ligne->subprice = $objp->subprice; }
$ligne->remise_percent = $objp->remise_percent; else
$ligne->price = $objp->price; {
$ligne->product_id = $objp->rowid; dolibarr_syslog("Propal::Fetch Erreur lecture de la propale $rowid");
return -1;
$this->lignes[$i] = $ligne; }
$i++; }
}
$this->db->free($result);
}
else
{
dolibarr_print_error($this->db);
return -1;
}
/*
* Lignes propales
*/
$sql = "SELECT d.qty, d.description, d.price, d.subprice, d.tva_tx, d.rowid, d.remise_percent";
$sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d";
$sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = 0";
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$j = 0;
while ($j < $num)
{
$objp = $this->db->fetch_object($result);
$ligne = new PropaleLigne();
$ligne->libelle = stripslashes($objp->description);
$ligne->desc = stripslashes($objp->description);
$ligne->qty = $objp->qty;
$ligne->ref = $objp->ref;
$ligne->tva_tx = $objp->tva_tx;
$ligne->subprice = $objp->subprice;
$ligne->remise_percent = $objp->remise_percent;
$ligne->price = $objp->price;
$ligne->product_id = 0;
$this->lignes[$i] = $ligne;
$i++;
$j++;
}
$this->db->free($result);
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
return 1;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
/* /*
* *
* *
@ -532,7 +582,7 @@ class Propal
} }
else else
{ {
dolibarr_print_error($this->db); //dolibarr_print_error($this->db);
return -1; return -1;
} }
} }
@ -545,89 +595,90 @@ class Propal
*/ */
function set_remise($user, $remise) function set_remise($user, $remise)
{ {
if ($user->rights->propale->creer) if ($user->rights->propale->creer)
{ {
$remise = ereg_replace(",",".",$remise); $remise = ereg_replace(",",".",$remise);
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise; $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise;
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
$this->remise_percent = $remise; $this->remise_percent = $remise;
$this->update_price(); $this->update_price();
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_syslog("Propal::set_remise Erreur SQL");
} }
} }
} }
/* /*
* *
* *
* *
*/ */
function set_project($user, $project_id) function set_project($user, $project_id)
{ {
if ($user->rights->propale->creer) if ($user->rights->propale->creer)
{ {
//verif que le projet et la société concordent //verif que le projet et la société concordent
$sql = 'SELECT p.rowid, p.title FROM '.MAIN_DB_PREFIX.'projet as p WHERE p.fk_soc ='.$this->socidp.' AND p.rowid='.$project_id; $sql = 'SELECT p.rowid, p.title FROM '.MAIN_DB_PREFIX.'projet as p WHERE p.fk_soc ='.$this->socidp.' AND p.rowid='.$project_id;
$sqlres = $this->db->query($sql); $sqlres = $this->db->query($sql);
if ($sqlres) if ($sqlres)
{ {
$numprojet = $this->db->num_rows($sqlres); $numprojet = $this->db->num_rows($sqlres);
if ($numprojet > 0) if ($numprojet > 0)
{ {
$this->projetidp=$project_id; $this->projetidp=$project_id;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_projet = '.$project_id; $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_projet = '.$project_id;
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;';
$this->db->query($sql); $this->db->query($sql);
} }
} }
else else
{ {
dolibarr_print_error($this->db);
} dolibarr_syslog("Propal::set_project Erreur SQL");
} }
} }
}
/* /*
* *
* *
* *
*/ */
function set_contact($user, $contact_id) function set_contact($user, $contact_id)
{ {
if ($user->rights->propale->creer) if ($user->rights->propale->creer)
{ {
//verif que le contact et la société concordent //verif que le contact et la société concordent
$sql = 'SELECT p.idp FROM '.MAIN_DB_PREFIX.'socpeople as p WHERE p.fk_soc = '.$this->socidp.' AND p.idp='.$contact_id; $sql = 'SELECT p.idp FROM '.MAIN_DB_PREFIX.'socpeople as p WHERE p.fk_soc = '.$this->socidp.' AND p.idp='.$contact_id;
$sqlres = $this->db->query($sql); $sqlres = $this->db->query($sql);
if ($sqlres) if ($sqlres)
{ {
$numprojet = $this->db->num_rows($sqlres); $numprojet = $this->db->num_rows($sqlres);
if ($numprojet > 0) if ($numprojet > 0)
{ {
$this->projetidp=$project_id; $this->projetidp=$project_id;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_soc_contact = '.$contact_id; $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_soc_contact = '.$contact_id;
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;';
$this->db->query($sql); $this->db->query($sql);
} }
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_syslog("Propal::set_contact Erreur SQL");
} }
} }
} }
/* /*
* *
* *
@ -923,103 +974,103 @@ class Propal
*/ */
function update_note($note) function update_note($note)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET note = '$note'"; $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET note = '$note'";
$sql .= " WHERE rowid = $this->id;"; $sql .= " WHERE rowid = $this->id;";
if ($this->db->query($sql) )
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
/**
* \brief Information sur l'objet propal
* \param id id de la propale
*/
function info($id)
{
$sql = "SELECT c.rowid, ";
$sql.= $this->db->pdate("datec")." as datec, ".$this->db->pdate("date_valid")." as datev, ".$this->db->pdate("date_cloture")." as dateo";
$sql.= ", fk_user_author, fk_user_valid, fk_user_cloture";
$sql.= " FROM ".MAIN_DB_PREFIX."propal as c";
$sql.= " WHERE c.rowid = $id";
if ($this->db->query($sql)) if ($this->db->query($sql) )
{ {
if ($this->db->num_rows()) return 1;
{ }
$obj = $this->db->fetch_object(); else
{
dolibarr_print_error($this->db);
return -1;
}
}
/**
* \brief Information sur l'objet propal
* \param id id de la propale
*/
function info($id)
{
$sql = "SELECT c.rowid, ";
$sql.= $this->db->pdate("datec")." as datec, ".$this->db->pdate("date_valid")." as datev, ".$this->db->pdate("date_cloture")." as dateo";
$sql.= ", fk_user_author, fk_user_valid, fk_user_cloture";
$sql.= " FROM ".MAIN_DB_PREFIX."propal as c";
$sql.= " WHERE c.rowid = $id";
$this->id = $obj->rowid; if ($this->db->query($sql))
{
$this->date_creation = $obj->datec; if ($this->db->num_rows())
$this->date_validation = $obj->datev; {
$this->date_cloture = $obj->dateo; $obj = $this->db->fetch_object();
$cuser = new User($this->db, $obj->fk_user_author); $this->id = $obj->rowid;
$cuser->fetch();
$this->user_creation = $cuser; $this->date_creation = $obj->datec;
$this->date_validation = $obj->datev;
if ($obj->fk_user_valid) $this->date_cloture = $obj->dateo;
{
$vuser = new User($this->db, $obj->fk_user_valid); $cuser = new User($this->db, $obj->fk_user_author);
$vuser->fetch(); $cuser->fetch();
$this->user_validation = $vuser; $this->user_creation = $cuser;
}
if ($obj->fk_user_valid)
if ($obj->fk_user_cloture) {
{ $vuser = new User($this->db, $obj->fk_user_valid);
$cluser = new User($this->db, $obj->fk_user_cloture); $vuser->fetch();
$cluser->fetch(); $this->user_validation = $vuser;
$this->user_cloture = $cluser; }
}
if ($obj->fk_user_cloture)
{
} $cluser = new User($this->db, $obj->fk_user_cloture);
$this->db->free(); $cluser->fetch();
$this->user_cloture = $cluser;
} }
else
{
dolibarr_print_error($this->db); }
} $this->db->free();
}
}
else
{
dolibarr_print_error($this->db);
}
}
/** /**
* \brief Retourne le libellé du statut d'une propale (brouillon, validée, ...) * \brief Retourne le libellé du statut d'une propale (brouillon, validée, ...)
* \return string Libellé * \return string Libellé
*/ */
function getLibStatut() function getLibStatut()
{ {
return $this->LibStatut($this->statut); return $this->LibStatut($this->statut);
} }
/** /**
* \brief Renvoi le libellé d'un statut donné * \brief Renvoi le libellé d'un statut donné
* \param statut id statut * \param statut id statut
* \param size Libellé court si 0, long si non défini * \param size Libellé court si 0, long si non défini
* \return string Libellé * \return string Libellé
*/ */
function LibStatut($statut,$size=1) function LibStatut($statut,$size=1)
{ {
if ($size) return $this->labelstatut[$statut]; if ($size) return $this->labelstatut[$statut];
else return $this->labelstatut_short[$statut]; else return $this->labelstatut_short[$statut];
} }
} }
class PropaleLigne class PropaleLigne
{ {
function PropaleLigne() function PropaleLigne()
{ {
} }
} }
?> ?>