Fix: Le use de validation des factures fournisseurs n'tait pas renseign, Optim: Suppression de codes inutils et remplacement de 'select' par l'appel aux methodes de l'objet appropri

This commit is contained in:
Laurent Destailleur 2004-06-09 18:37:17 +00:00
parent ea63c23baa
commit 2111f95863
6 changed files with 172 additions and 152 deletions

View File

@ -23,37 +23,60 @@ require("./pre.inc.php");
$acts[0] = "add";
$acts[1] = "delete";
$actl[0] = "Ajouter";
$actl[1] = "Enlever";
$actl[0] = "Activer";
$actl[1] = "Désactiver";
$active = 1;
// Mettre ici tous les caractéristiques des dictionnaires editables
$tabid[1] = "llx_c_forme_juridique";
$tabid[2] = "llx_c_departements";
$tabid[3] = "llx_c_regions";
$tabid[4] = "llx_c_pays";
if (!$user->admin)
$tabnom[1] = "Formes juridiques";
$tabnom[2] = "Départements";
$tabnom[3] = "Régions";
$tabnom[4] = "Pays";
$tabsql[1] = "SELECT code, libelle, active FROM llx_c_forme_juridique ORDER BY active DESC, code ASC";
$tabsql[2] = "SELECT rowid, code_departement as code , nom as libelle, active FROM llx_c_departements ORDER BY active DESC, code ASC";
$tabsql[3] = "SELECT r.rowid as rowid, code_region as code , nom as libelle, p.libelle as pays, r.active FROM llx_c_regions as r, llx_c_pays as p WHERE r.fk_pays=p.rowid ORDER BY active DESC, code ASC";
$tabsql[4] = "SELECT rowid, code, libelle, active FROM llx_c_pays ORDER BY active DESC, code ASC";
// Champs à afficher
$tabfield[1] = "code,libelle";
$tabfield[2] = "code,libelle";
$tabfield[3] = "code,libelle,pays";
$tabfield[4] = "code,libelle";
if (! $user->admin)
accessforbidden();
if ($user->admin)
if ($_GET["action"] == 'delete')
{
if ($_GET["action"] == 'delete')
if ($_GET["rowid"] >0) {
$sql = "UPDATE ".$tabid[$_GET["id"]]." SET active = 0 WHERE rowid=".$_GET["rowid"];
}
elseif ($_GET["code"] >0) {
$sql = "UPDATE ".$tabid[$_GET["id"]]." SET active = 0 WHERE code=".$_GET["code"];
}
$result = $db->query($sql);
if (!$result)
{
print $db->error();
}
}
if ($_GET["action"] == 'add')
{
$sql = "UPDATE ".$tabid[$_GET["id"]]." SET active = 1 WHERE rowid=".$_GET["rowid"];
$result = $db->query($sql);
if (!$result)
{
$sql = "UPDATE ".$tabid[$_GET["id"]]." SET active = 0 WHERE rowid=".$_GET["rowid"];
$result = $db->query($sql);
if (!$result)
{
print $db->error();
}
}
if ($_GET["action"] == 'add')
{
$sql = "UPDATE ".$tabid[$_GET["id"]]." SET active = 1 WHERE rowid=".$_GET["rowid"];
$result = $db->query($sql);
if (!$result)
{
print $db->error();
}
print $db->error();
}
}
@ -61,60 +84,80 @@ if ($user->admin)
llxHeader();
print_titre("Configuration des dictionnaires de données");
print '<br>';
$active = 1;
$sql = array();
if ($_GET["id"])
{
ShowTable($db,1, $_GET["id"], $actl, $acts);
ShowTable($db,0, $_GET["id"], $actl, $acts);
}
else
{
print '<a href="dict.php?id=1">Forme Juridique</a><br>';
print '<a href="dict.php?id=2">Départements</a><br>';
print '<a href="dict.php?id=3">Régions</a><br>';
}
print_titre("Configuration des dictionnaires de données : ".$tabnom[$_GET["id"]]);
print '<br>';
$db->close();
llxFooter();
Function ShowTable($db, $active, $id, $actl, $acts)
{
global $bc;
$sql[1] = "SELECT code, libelle, active FROM llx_c_forme_juridique WHERE active = $active ORDER BY code ASC";
$sql[2] = "SELECT rowid, code_departement as code , nom as libelle, active FROM llx_c_departements WHERE active = $active ORDER BY code ASC";
$sql[3] = "SELECT rowid, code_region as code , nom as libelle, active FROM llx_c_regions WHERE active = $active ORDER BY code ASC";
if ($db->query($sql[$id]))
// Affiche table des valeurs
$sql=$tabsql[$_GET["id"]];
if ($db->query($sql))
{
$num = $db->num_rows();
$i = 0;
$var=True;
if ($num)
{
$num = $db->num_rows();
$i = 0; $var=True;
if ($num)
{
print '<table class="noborder" cellpadding="3" cellspacing="0" width="100%">';
print '<tr class="liste_titre"><td>Code</td><td>Valeur</td><td>Type</td></tr>';
print '<tr class="liste_titre">';
$fieldlist=split(',',$tabfield[$_GET["id"]]);
foreach ($fieldlist as $field => $value) {
print '<td>'.ucfirst($fieldlist[$field]).'</td>';
}
print '<td>Actif</td>';
print '<td>Inactif</td>';
print '</tr>';
while ($i < $num)
{
$obj = $db->fetch_object( $i);
$obj = $db->fetch_object($i);
$var=!$var;
print "<tr $bc[$var] class=\"value\"><td width=\"10%\">\n";
print $obj->code.'</td><td>'.$obj->libelle.'</td><td width=\"30%\">';
print '<a href="'.$PHP_SELF.'?rowid='.$obj->rowid.'&amp;id='.$id.'&amp;action='.$acts[$active].'">'.$actl[$active].'</a>';
print "</td></tr>\n";
print "<tr $bc[$var] class=\"value\">";
foreach ($fieldlist as $field => $value) {
print '<td>'.$obj->$fieldlist[$field].'</td>';
}
if ($obj->active) {
print '<td>';
print '<a href="'.$PHP_SELF.'?rowid='.$obj->rowid.'&amp;code='.$obj->code.'&amp;id='.$_GET["id"].'&amp;action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
print "</td>";
}
else print '<td>&nbsp;</td>';
if (! $obj->active) {
print '<td>';
print '<a href="'.$PHP_SELF.'?rowid='.$obj->rowid.'&amp;code='.$obj->code.'&amp;id='.$_GET["id"].'&amp;action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
print "</td>";
}
else print '<td>&nbsp;</td>';
print "</tr>\n";
$i++;
}
print '</table>';
}
}
else {
print "Erreur : $sql : ".$db->error();
}
}
else
{
print_titre("Configuration des dictionnaires de données");
print '<br>';
foreach ($tabid as $i => $value) {
print '<a href="dict.php?id='.$i.'">'.$tabnom[$i].'</a> (Table '.$tabid[$i].')<br>';
}
}
print '<br>';
$db->close();
llxFooter();
?>

View File

@ -384,16 +384,17 @@ if ($action == 'pdf')
facture_pdf_create($db, $facid);
}
llxHeader();
$html = new Form($db);
/*********************************************************************
*
* Mode creation
*
*
*
************************************************************************/
if ($_GET["action"] == 'create')
{
@ -894,7 +895,7 @@ else
{
$objp = $db->fetch_object( $i);
$var=!$var;
print "<TR $bc[$var]>";
print "<tr $bc[$var]>";
if ($objp->fk_product > 0)
{
print '<td><a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a>';
@ -908,9 +909,9 @@ else
print "</td>\n";
}
print '<TD align="right">'.$objp->tva_taux.' %</TD>';
print '<TD align="right">'.price($objp->subprice)."</td>\n";
print '<TD align="right">'.$objp->qty.'</TD>';
print '<td align="right">'.$objp->tva_taux.' %</td>';
print '<td align="right">'.price($objp->subprice)."</td>\n";
print '<td align="right">'.$objp->qty.'</td>';
if ($objp->remise_percent > 0)
{
print '<td align="right">'.$objp->remise_percent." %</td>\n";
@ -1321,7 +1322,6 @@ else
/***************************************************************************
* *
* Mode Liste *
* *
* *
***************************************************************************/
if ($page == -1)
@ -1340,7 +1340,7 @@ else
if ($sortfield == "")
$sortfield="f.datef";
$sql = "SELECT s.nom,s.idp,f.facnumber,f.total,f.total_ttc,".$db->pdate("f.datef")." as df,f.paye,f.rowid as facid, f.fk_statut, sum(pf.amount) as am";
$sql = "SELECT s.nom,s.idp,f.facnumber,f.total,f.total_ttc,".$db->pdate("f.datef")." as df, f.paye as paye, f.rowid as facid, f.fk_statut, sum(pf.amount) as am";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture WHERE f.fk_soc = s.idp";
if ($socidp)
@ -1369,7 +1369,12 @@ else
$sql .= " GROUP BY f.facnumber";
$sql .= " ORDER BY $sortfield $sortorder, f.rowid DESC ";
$sql .= " ORDER BY ";
$listfield=split(',',$sortfield);
foreach ($listfield as $key => $value) {
$sql.="$listfield[$key] $sortorder,";
}
$sql .= " f.rowid DESC ";
$sql .= $db->plimit($limit,$offset);
@ -1395,8 +1400,9 @@ else
print_liste_field_titre("Montant TTC",$PHP_SELF,"f.total_ttc","","&amp;socidp=$socidp");
print '</td><td align="right">';
print_liste_field_titre("Reçu",$PHP_SELF,"am","","&amp;socidp=$socidp");
print '</td><td align="right">';
print_liste_field_titre("Statut",$PHP_SELF,"fk_statut,paye","","&amp;socidp=$socidp");
print '</td>';
print '<td align="center">Status</td>';
print "</tr>\n";
if ($num > 0)
@ -1444,14 +1450,14 @@ else
}
else
{
print "<TD align=\"center\"><b>!!!</b></TD>\n";
print "<td align=\"center\"><b>!!!</b></td>\n";
}
print '<TD><a href="fiche.php?socid='.$objp->idp.'">'.$objp->nom.'</a></td>';
print "<TD align=\"right\">".price($objp->total)."</TD>";
print "<TD align=\"right\">".price($objp->total_ttc)."</TD>";
print "<TD align=\"right\">".price($objp->am)."</TD>";
print '<td><a href="fiche.php?socid='.$objp->idp.'">'.$objp->nom.'</a></td>';
print "<td align=\"right\">".price($objp->total)."</td>";
print "<td align=\"right\">".price($objp->total_ttc)."</td>";
print "<td align=\"right\">".price($objp->am)."</td>";
// Affiche statut de la facture
if (! $objp->paye)
{
if ($objp->fk_statut == 0)
@ -1472,7 +1478,7 @@ else
print '<td align="center">payée</td>';
}
print "</TR>\n";
print "</tr>\n";
$total+=$objp->total;
$total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am;
@ -1482,10 +1488,10 @@ else
if ($num <= $limit) {
// Print total
print "<tr ".$bc[!$var].">";
print "<TD colspan=3 align=\"left\">Total : </TD>";
print "<TD align=\"right\"><b>".price($total)."</b></TD>";
print "<TD align=\"right\"><b>".price($total_ttc)."</b></TD>";
print "<TD align=\"right\"><b>".price($totalrecu)."</b></TD>";
print "<td colspan=3 align=\"left\">Total : </TD>";
print "<td align=\"right\"><b>".price($total)."</b></TD>";
print "<td align=\"right\"><b>".price($total_ttc)."</b></TD>";
print "<td align=\"right\"><b>".price($totalrecu)."</b></TD>";
print '<td align="center">&nbsp;</td>';
print "</tr>\n";
}

View File

@ -81,7 +81,7 @@ if ($_POST["action"] == 'add_paiement')
// Insertion dans llx_bank
$label = "Règlement charge";
$acc = new Account($db, $_POST["accountid"]);
$bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, $total, $paiement->num_paiement, '', $user);
$bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -abs($total), $paiement->num_paiement, '', $user);
// Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a généré l'écriture bancaire
if ($bank_line_id) {

View File

@ -41,11 +41,11 @@ class FactureFourn
var $db_table;
var $propalid;
var $lignes;
/*
* Initialisation
*
*/
Function FactureFourn($DB, $soc_idp="", $facid="")
{
$this->db = $DB ;
@ -150,8 +150,9 @@ class FactureFourn
$this->updateprice($this->id);
return 1;
}
/*
*
* Création d'une facture fournisseur
*
*/
Function create($user)
@ -286,25 +287,6 @@ class FactureFourn
print $this->db->error();
}
}
/*
*
*
*
*/
Function valid($userid, $dir)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid";
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
if ($this->db->query($sql) )
{
return 1;
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
/*
* Suppression de la facture
@ -338,48 +320,40 @@ class FactureFourn
return 0;
}
}
/*
*
*
*
*/
Function set_payed($rowid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facture set paye = 1 WHERE rowid = $rowid ;";
$return = $this->db->query( $sql);
}
/*
*
*
*
*
*/
Function set_valid($rowid, $userid)
{
global $conf;
$sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid ;";
/*
* Passe une facture fournisseur a l'état validé
*
*/
Function set_valid($userid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set fk_statut = 1, fk_user_valid = $userid WHERE rowid = ".$this->id;
$result = $this->db->query( $sql);
$dir = $conf->facture->outputdir . "/" . $rowid;
if (! is_dir ("$dir"))
{
if (! mkdir ("$dir"))
{
print $dir;
}
}
if (! $result) {
print "Erreur : $sql : ".$this->db->error();
}
}
/*
* Passe une facture fournisseur a l'état payé
*
*
*/
Function set_payed($userid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set paye = 1 WHERE rowid = ".$this->id;
$result = $this->db->query( $sql);
if (! $result) {
print "Erreur : $sql : ".$this->db->error();
}
}
/*
*
*
*/
Function addline($facid, $desc, $pu, $qty)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet (fk_facture,description,price,qty) VALUES ($facid, '$desc', $pu, $qty) ;";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture,description,price,qty) VALUES ($facid, '$desc', $pu, $qty) ;";
$result = $this->db->query( $sql);
$this->updateprice($facid);
@ -390,7 +364,7 @@ class FactureFourn
*/
Function updateline($rowid, $desc, $pu, $qty)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set description='$desc',price=$pu,qty=$qty WHERE rowid = $rowid ;";
$sql = "UPDATE ".MAIN_DB_PREFIX."facture-fourn_det set description='$desc',price=$pu,qty=$qty WHERE rowid = $rowid ;";
$result = $this->db->query( $sql);
$this->updateprice($this->id);
@ -401,7 +375,7 @@ class FactureFourn
*/
Function deleteline($rowid)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = $rowid;";
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det WHERE rowid = $rowid;";
$result = $this->db->query( $sql);
$this->updateprice($this->id);
@ -448,14 +422,6 @@ class FactureFourn
Function pdf()
{
print "<hr><b>Génération du PDF</b><p>";
$command = "export DBI_DSN=\"".$GLOBALS["DBI"]."\" ";
$command .= " ; ../../scripts/facture-tex.pl --facture=$facid --pdf --ps" ;
$output = system($command);
print "<p>command : $command<br>";
}
}

View File

@ -22,6 +22,7 @@
*/
require("./pre.inc.php");
require("./paiementfourn.class.php");
require("../../facturefourn.class.php");
/*
* Sécurité accés client
@ -36,14 +37,19 @@ $html = new Form($db);
if ($action == 'valid')
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set fk_statut = 1 WHERE rowid = $facid ;";
$result = $db->query( $sql);
print "ddddddddddddddd";
$facturefourn=new FactureFourn($db);
$facturefourn->fetch($_GET["facid"]);
$facturefourn->set_valid($user->id);
}
if ($action == 'payed')
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set paye = 1 WHERE rowid = $facid ;";
$result = $db->query( $sql);
$facturefourn=new FactureFourn($db);
$facturefourn->fetch($_GET["facid"]);
$facturefourn->set_payed($user->id);
}
if($_GET["action"] == 'deletepaiement')

View File

@ -1,5 +1,6 @@
<?PHP
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,14 +21,12 @@
*
*/
require("../../main.inc.php");
require("../../facturefourn.class.php");
include_once DOL_DOCUMENT_ROOT."/compta/bank/account.class.php";
function llxHeader($head = "", $urlp = "") {
global $user, $conf;
/*
*
*