Fix: Update of supplier invoice line

This commit is contained in:
Laurent Destailleur 2010-10-30 10:51:56 +00:00
parent 803ea1e7cc
commit 4e83c0a7ea
2 changed files with 1273 additions and 1263 deletions

View File

@ -771,19 +771,19 @@ class FactureFournisseur extends Facture
} }
/** /**
* \brief Update line * Update a line detail into database
* \param id Id of line invoice * @param id Id of line invoice
* \param label Description of line * @param label Description of line
* \param pu Prix unitaire (HT ou TTC selon price_base_type) * @param pu Prix unitaire (HT ou TTC selon price_base_type)
* \param tauxtva VAT Rate * @param vatrate VAT Rate
* \param qty Quantity * @param qty Quantity
* \param idproduct Id produit * @param idproduct Id produit
* \param price_base_type HT or TTC * @param price_base_type HT or TTC
* \param info_bits Miscellanous informations of line * @param info_bits Miscellanous informations of line
* \param type Type of line (0=product, 1=service) * @param type Type of line (0=product, 1=service)
* \return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function updateline($id, $label, $pu, $tauxtva, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0) function updateline($id, $label, $pu, $vatrate, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0)
{ {
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
@ -794,11 +794,14 @@ class FactureFournisseur extends Facture
if (! is_numeric($pu) || ! is_numeric($qty)) return -1; if (! is_numeric($pu) || ! is_numeric($qty)) return -1;
if ($type < 0) return -1; if ($type < 0) return -1;
// Clean parameters
if (empty($vatrate)) $vatrate=0;
// Calcul du total TTC et de la TVA pour la ligne a partir de // Calcul du total TTC et de la TVA pour la ligne a partir de
// qty, pu, remise_percent et txtva // qty, pu, remise_percent et txtva
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$tabprice = calcul_price_total($qty, $pu, 0, $tauxtva, 0,0, 0, $price_base_type, $info_bits); $tabprice = calcul_price_total($qty, $pu, 0, $vatrate, 0,0, 0, $price_base_type, $info_bits);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
$total_tva = $tabprice[1]; $total_tva = $tabprice[1];
$total_ttc = $tabprice[2]; $total_ttc = $tabprice[2];
@ -822,7 +825,7 @@ class FactureFournisseur extends Facture
$sql.= ", pu_ht = ".price2num($pu_ht); $sql.= ", pu_ht = ".price2num($pu_ht);
$sql.= ", pu_ttc = ".price2num($pu_ttc); $sql.= ", pu_ttc = ".price2num($pu_ttc);
$sql.= ", qty = ".price2num($qty); $sql.= ", qty = ".price2num($qty);
$sql.= ", tva_tx = ".price2num($tauxtva); $sql.= ", tva_tx = ".price2num($vatrate);
$sql.= ", total_ht = ".price2num($total_ht); $sql.= ", total_ht = ".price2num($total_ht);
$sql.= ", tva= ".price2num($total_tva); $sql.= ", tva= ".price2num($total_tva);
$sql.= ", total_ttc = ".price2num($total_ttc); $sql.= ", total_ttc = ".price2num($total_ttc);
@ -835,20 +838,22 @@ class FactureFournisseur extends Facture
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
// Mise a jour prix total facture // Update total price into invoice record
return $this->update_price(); $result=$this->update_price();
return $result;
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->lasterror();
dol_syslog("Fournisseur.facture::updateline error=".$this->error, LOG_ERR); dol_syslog("Fournisseur.facture::updateline error=".$this->error, LOG_ERR);
return -1; return -1;
} }
} }
/** /**
* \brief Supprime une ligne facture de la base * Delete a detail line from database
* \param rowid id de la ligne de facture a supprimer * @param rowid id of line to delete
*/ */
function deleteline($rowid) function deleteline($rowid)
{ {

View File

@ -24,7 +24,7 @@
/** /**
* \file htdocs/fourn/facture/fiche.php * \file htdocs/fourn/facture/fiche.php
* \ingroup facture, fournisseur * \ingroup facture, fournisseur
* \brief Page for supplier invoice card * \brief Page for supplier invoice card (view, edit, validate)
* \version $Id$ * \version $Id$
*/ */
@ -120,7 +120,7 @@ if ($_REQUEST['action'] == 'confirm_deleteproductline' && $_REQUEST['confirm'] =
{ {
$facturefourn = new FactureFournisseur($db); $facturefourn = new FactureFournisseur($db);
$facturefourn->fetch($facid); $facturefourn->fetch($facid);
$facturefourn->deleteline($_REQUEST['ligne_id']); $facturefourn->deleteline($_REQUEST['lineid']);
$_GET['action'] = ''; $_GET['action'] = '';
} }
} }
@ -274,7 +274,7 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
if ($_GET['action'] == 'del_ligne') if ($_GET['action'] == 'del_ligne')
{ {
$facfou = new FactureFournisseur($db,'',$_GET['facid']); $facfou = new FactureFournisseur($db,'',$_GET['facid']);
$facfou->deleteline($_GET['ligne_id']); $facfou->deleteline($_GET['lineid']);
$_GET['action'] = 'edit'; $_GET['action'] = 'edit';
} }
@ -310,7 +310,11 @@ if ($_REQUEST['action'] == 'update_line')
$type = $_POST["type"]?$_POST["type"]:0; $type = $_POST["type"]?$_POST["type"]:0;
} }
$facfou->updateline($_GET['ligne_id'], $label, $pu, $_POST['tauxtva'], $_POST['qty'], $_POST['idprod'], $price_base_type, 0, $type); $result=$facfou->updateline($_GET['lineid'], $label, $pu, $_POST['tauxtva'], $_POST['qty'], $_POST['idprod'], $price_base_type, 0, $type);
if ($result >= 0)
{
unset($_POST['label']);
}
} }
} }
@ -401,6 +405,7 @@ if ($_GET['action'] == 'addline')
unset($_POST['np_desc']); unset($_POST['np_desc']);
unset($_POST['pu']); unset($_POST['pu']);
unset($_POST['tva_tx']); unset($_POST['tva_tx']);
unset($_POST['label']);
} }
else if (empty($mesg)) else if (empty($mesg))
{ {
@ -926,7 +931,7 @@ else
// Confirmation de la suppression d'une ligne produit // Confirmation de la suppression d'une ligne produit
if ($_GET['action'] == 'confirm_delete_line') if ($_GET['action'] == 'confirm_delete_line')
{ {
$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id.'&ligne_id='.$_GET["ligne_id"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline', '', 1, 1); $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline', '', 1, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -1218,9 +1223,9 @@ else
$var=!$var; $var=!$var;
// Edit line // Edit line
if ($fac->statut == 0 && $_GET['action'] == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['ligne_id'] == $fac->lines[$i]->rowid) if ($fac->statut == 0 && $_GET['action'] == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['lineid'] == $fac->lines[$i]->rowid)
{ {
print '<form action="fiche.php?facid='.$fac->id.'&amp;etat=1&amp;ligne_id='.$fac->lines[$i]->rowid.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;etat=1&amp;lineid='.$fac->lines[$i]->rowid.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update_line">'; print '<input type="hidden" name="action" value="update_line">';
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
@ -1324,12 +1329,12 @@ else
print '<td align="right" nowrap="nowrap">'.price($fac->lines[$i]->total_ttc).'</td>'; print '<td align="right" nowrap="nowrap">'.price($fac->lines[$i]->total_ttc).'</td>';
print '<td align="center" width="16">'; print '<td align="center" width="16">';
if ($fac->statut == 0) print '<a href="fiche.php?facid='.$fac->id.'&amp;action=mod_ligne&amp;etat=0&amp;ligne_id='.$fac->lines[$i]->rowid.'">'.img_edit().'</a>'; if ($fac->statut == 0) print '<a href="fiche.php?facid='.$fac->id.'&amp;action=mod_ligne&amp;etat=0&amp;lineid='.$fac->lines[$i]->rowid.'">'.img_edit().'</a>';
else print '&nbsp;'; else print '&nbsp;';
print '</td>'; print '</td>';
print '<td align="center" width="16">'; print '<td align="center" width="16">';
if ($fac->statut == 0) print '<a href="fiche.php?facid='.$fac->id.'&amp;action=confirm_delete_line&amp;ligne_id='.$fac->lines[$i]->rowid.'">'.img_delete().'</a>'; if ($fac->statut == 0) print '<a href="fiche.php?facid='.$fac->id.'&amp;action=confirm_delete_line&amp;lineid='.$fac->lines[$i]->rowid.'">'.img_delete().'</a>';
else print '&nbsp;'; else print '&nbsp;';
print '</td>'; print '</td>';
@ -1377,7 +1382,7 @@ else
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$nbrows=ROWS_2; $nbrows=ROWS_2;
if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
$doleditor=new DolEditor('label',$_POST["label"],100,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); $doleditor=new DolEditor('label',GETPOST("label"),100,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
$doleditor->Create(); $doleditor->Create();
print '</td>'; print '</td>';