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

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com> * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
@ -287,6 +287,19 @@ if ($_POST['addligne'] == $langs->trans('Add') && $user->rights->propale->creer)
} }
} }
if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer)
{
/*
* Mise à jour d'une ligne dans la propale
*/
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
$propal->UpdateLigne($_POST['ligne'], $_POST['subprice'], $_POST['qty'], $_POST['remise']);
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
}
if ($_POST['addproduct'] == $langs->trans('Add') && $user->rights->propale->creer) if ($_POST['addproduct'] == $langs->trans('Add') && $user->rights->propale->creer)
{ {
/* /*
@ -305,13 +318,6 @@ if ($_POST['addproduct'] == $langs->trans('Add') && $user->rights->propale->cree
} }
} }
if ($_POST['action'] == 'setremise' && $user->rights->propale->creer)
{
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
$propal->set_remise($user, $_POST['remise']);
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
}
if ($_POST['action'] == 'setpdfmodel' && $user->rights->propale->creer) if ($_POST['action'] == 'setpdfmodel' && $user->rights->propale->creer)
{ {
@ -341,6 +347,14 @@ if ($_GET['valid'] == 1 && $user->rights->propale->valider)
$propal->valid($user); $propal->valid($user);
} }
if ($_POST['action'] == 'setremise' && $user->rights->propale->creer)
{
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
$propal->set_remise($user, $_POST['remise']);
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
}
if ($_POST['action'] == 'set_project') if ($_POST['action'] == 'set_project')
{ {
$propal = new Propal($db); $propal = new Propal($db);
@ -446,7 +460,7 @@ if ($_GET['propalid'])
print '</tr>'; print '</tr>';
print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'; print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">';
print dolibarr_print_date($propal->date); print dolibarr_print_date($propal->date,'%a %e %B %Y');
print '</td>'; print '</td>';
print '<td>'.$langs->trans('DateEndPropal').'</td><td>'; print '<td>'.$langs->trans('DateEndPropal').'</td><td>';
@ -576,7 +590,7 @@ if ($_GET['propalid'])
print '</tr>'; print '</tr>';
print '<tr><td height="10">'.$langs->trans('AmountHT').'</td>'; print '<tr><td height="10">'.$langs->trans('AmountHT').'</td>';
print '<td align="right" colspan="2"><b>'.price($obj->price).'</b></td>'; print '<td align="right" colspan="2"><b>'.price($propal->price).'</b></td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
print '<tr><td height="10">'.$langs->trans('VAT').'</td><td align="right" colspan="2">'.price($propal->total_tva).'</td>'; print '<tr><td height="10">'.$langs->trans('VAT').'</td><td align="right" colspan="2">'.price($propal->total_tva).'</td>';
@ -697,6 +711,22 @@ if ($_GET['propalid'])
// Update ligne de propal // Update ligne de propal
// \todo // \todo
if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] == 'editline' && $_GET["ligne"] == $objp->rowid)
{
print '<form action="propal.php?propalid='.$propal->id.'" method="post">';
print '<input type="hidden" name="action" value="updateligne">';
print '<input type="hidden" name="ligne" value="'.$_GET["ligne"].'">';
print '<tr '.$bc[$var].'>';
print '<td colspan="2">&nbsp;</td>';
print '<td align="right"><input name="subprice" type="text" size="6" value="'.$objp->subprice.'"></td>';
print '<td align="right"><input name="qty" type="text" size="3" value="'.$objp->qty.'"></td>';
print '<td align="right"><input name="remise" type="text" size="4" value="'.$objp->remise_percent.'"> %</td>';
print '<td>&nbsp;</td>';
print '<td align="center" colspan="2"><input type="submit"></td>';
print '</tr></form>';
}
//
$total = $total + ($objp->qty * $objp->price); $total = $total + ($objp->qty * $objp->price);
$i++; $i++;
@ -712,7 +742,7 @@ if ($_GET['propalid'])
* Ajouter une ligne * Ajouter une ligne
* *
*/ */
if ($propal->statut == 0 && $user->rights->propale->creer) if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] <> 'editline')
{ {
print '<form action="propal.php?propalid='.$propal->id.'" method="post">'; print '<form action="propal.php?propalid='.$propal->id.'" method="post">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';

View File

@ -159,7 +159,51 @@ 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;
}
}
/** /**
* *
* *
@ -304,12 +348,12 @@ 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;
} }
@ -376,13 +420,18 @@ class Propal
*/ */
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 .= " ,".$this->db->pdate("datep")."as dp";
$sql .= " ,".$this->db->pdate("fin_validite")."as dfv, model_pdf, note";
$sql .= " , fk_projet, fk_statut, remise_percent, fk_user_author";
$sql .= ", c.label as statut_label"; $sql .= ", c.label as statut_label";
$sql .= " FROM ".MAIN_DB_PREFIX."propal"; $sql .= " FROM ".MAIN_DB_PREFIX."propal";
$sql .= "," . MAIN_DB_PREFIX."c_propalst as c"; $sql .= "," . MAIN_DB_PREFIX."c_propalst as c";
$sql .= " WHERE rowid=$rowid AND fk_statut = c.id"; $sql .= " WHERE fk_statut = c.id";
$sql .= " AND rowid='".$rowid."';";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
if ($this->db->num_rows($resql)) if ($this->db->num_rows($resql))
@ -419,7 +468,7 @@ class Propal
} }
$this->lignes = array(); $this->lignes = array();
$this->db->free(); $this->db->free($resql);
$this->ref_url = '<a href="'.DOL_URL_ROOT.'/comm/propal.php?propalid='.$this->id.'">'.$this->ref.'</a>'; $this->ref_url = '<a href="'.DOL_URL_ROOT.'/comm/propal.php?propalid='.$this->id.'">'.$this->ref.'</a>';
@ -459,7 +508,7 @@ class Propal
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_syslog("Propal::Fetch Erreur lecture des produits");
return -1; return -1;
} }
@ -499,7 +548,8 @@ class Propal
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_syslog("Propal::Fetch Erreur lecture des lignes de propale");
return -1; return -1;
} }
} }
@ -507,7 +557,7 @@ class Propal
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_syslog("Propal::Fetch Erreur lecture de la propale $rowid");
return -1; return -1;
} }
} }
@ -532,7 +582,7 @@ class Propal
} }
else else
{ {
dolibarr_print_error($this->db); //dolibarr_print_error($this->db);
return -1; return -1;
} }
} }
@ -561,7 +611,7 @@ class Propal
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_syslog("Propal::set_remise Erreur SQL");
} }
} }
} }
@ -592,7 +642,8 @@ class Propal
} }
else else
{ {
dolibarr_print_error($this->db);
dolibarr_syslog("Propal::set_project Erreur SQL");
} }
} }
} }
@ -623,7 +674,7 @@ class Propal
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_syslog("Propal::set_contact Erreur SQL");
} }
} }
} }