New: Ajout methode load_board sur chaque objet métier pour tableau de bord Dolibarr.

This commit is contained in:
Laurent Destailleur 2005-08-11 20:01:25 +00:00
parent e4c4058211
commit ec36e49fa2
3 changed files with 333 additions and 257 deletions

View File

@ -21,15 +21,17 @@
* *
*/ */
/*! \file htdocs/don.class.php /**
\file htdocs/don.class.php
\ingroup don \ingroup don
\brief Fichier de la classe des dons \brief Fichier de la classe des dons
\version $Revision$ \version $Revision$
*/ */
/*! \class Don /**
\brief Classe permettant la gestion des dons \class Don
\brief Classe permettant la gestion des dons
*/ */
class Don class Don
@ -173,80 +175,79 @@ class Don
} }
/* /**
* \brief Création du don en base * \brief Création du don en base
* \param userid utilisateur qui crée le don * \param userid Objet utilisateur qui crée le don
* \return int id don crée si ok, <0 si ko
*/ */
function create($userid) function create($user)
{ {
$this->date = $this->db->idate($this->date); $this->date = $this->db->idate($this->date);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."don (datec, amount, fk_paiement,prenom, nom, societe,adresse, cp, ville, pays, public,"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."don (datec, amount, fk_paiement,prenom, nom, societe,adresse, cp, ville, pays, public,";
if ($this->projetid) if ($this->projetid)
{ {
$sql .= " fk_don_projet,"; $sql .= " fk_don_projet,";
} }
$sql .= " note, fk_user_author, datedon, email)"; $sql .= " note, fk_user_author, datedon, email)";
$sql .= " VALUES (now(),".ereg_replace(",",".", $this->amount).", $this->modepaiementid,'$this->prenom','$this->nom','$this->societe','$this->adresse', '$this->cp','$this->ville','$this->pays',$this->public, "; $sql .= " VALUES (now(),".ereg_replace(",",".", $this->amount).", $this->modepaiementid,'$this->prenom','$this->nom','$this->societe','$this->adresse', '$this->cp','$this->ville','$this->pays',$this->public, ";
if ($this->projetid) if ($this->projetid)
{ {
$sql .= " $this->projetid,"; $sql .= " $this->projetid,";
} }
$sql .= " '$this->commentaire', $userid, '$this->date','$this->email')"; $sql .= " '$this->commentaire', ".$user->id.", '$this->date','$this->email')";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result)
if ($result) {
{ return $this->db->last_insert_id(MAIN_DB_PREFIX."don");
return $this->db->last_insert_id(MAIN_DB_PREFIX."don"); }
} else
else {
{ dolibarr_print_error($this->db);
dolibarr_print_error($this->db); return -1;
return 0; }
}
} }
/* /**
* \brief Mise à jour du don * \brief Mise à jour du don
* \param userid utilisateur qui crée le don * \param user Objet utilisateur qui met à jour le don
* * \return int >0 si ok, <0 si ko
*/ */
function update($userid) function update($user)
{ {
$this->date = $this->db->idate($this->date); $this->date = $this->db->idate($this->date);
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET "; $sql = "UPDATE ".MAIN_DB_PREFIX."don SET ";
$sql .= "amount = " . $this->amount; $sql .= "amount = " . $this->amount;
$sql .= ",fk_paiement = ".$this->modepaiementid; $sql .= ",fk_paiement = ".$this->modepaiementid;
$sql .= ",prenom = '".$this->prenom ."'"; $sql .= ",prenom = '".$this->prenom ."'";
$sql .= ",nom='".$this->nom."'"; $sql .= ",nom='".$this->nom."'";
$sql .= ",societe='".$this->societe."'"; $sql .= ",societe='".$this->societe."'";
$sql .= ",adresse='".$this->adresse."'"; $sql .= ",adresse='".$this->adresse."'";
$sql .= ",cp='".$this->cp."'"; $sql .= ",cp='".$this->cp."'";
$sql .= ",ville='".$this->ville."'"; $sql .= ",ville='".$this->ville."'";
$sql .= ",pays='".$this->pays."'"; $sql .= ",pays='".$this->pays."'";
$sql .= ",public=".$this->public; $sql .= ",public=".$this->public;
if ($this->projetid) { $sql .= ",fk_don_projet=".$this->projetid; } if ($this->projetid) { $sql .= ",fk_don_projet=".$this->projetid; }
$sql .= ",note='".$this->commentaire."'"; $sql .= ",note='".$this->commentaire."'";
$sql .= ",datedon='".$this->date."'"; $sql .= ",datedon='".$this->date."'";
$sql .= ",email='".$this->email."'"; $sql .= ",email='".$this->email."'";
$sql .= ",fk_statut=".$this->statut; $sql .= ",fk_statut=".$this->statut;
$sql .= " WHERE rowid = $this->id"; $sql .= " WHERE rowid = $this->id";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result)
if ($result) {
{ return 1;
return 1; }
} else
else {
{ dolibarr_print_error($this->db);
dolibarr_print_error($this->db); return -1;
return 0; }
}
} }
/* /*
@ -266,13 +267,13 @@ class Don
} }
else else
{ {
return 0; return -1;
} }
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return 0; return -1;
} }
} }
@ -283,9 +284,11 @@ class Don
*/ */
function fetch($rowid) function fetch($rowid)
{ {
$sql = "SELECT d.rowid, ".$this->db->pdate("d.datedon")." as datedon, d.prenom, d.nom, d.societe, d.amount, p.libelle as projet, d.fk_statut, d.adresse, d.cp, d.ville, d.pays, d.public, d.amount, d.fk_paiement, d.note, cp.libelle, d.email, d.fk_don_projet"; $sql = "SELECT d.rowid, ".$this->db->pdate("d.datec")." as datec,";
$sql .= " FROM ".MAIN_DB_PREFIX."don as d, ".MAIN_DB_PREFIX."c_paiement as cp LEFT JOIN ".MAIN_DB_PREFIX."don_projet as p"; $sql.= " ".$this->db->pdate("d.datedon")." as datedon,";
$sql .= " ON p.rowid = d.fk_don_projet WHERE cp.id = d.fk_paiement AND d.rowid = $rowid"; $sql.= " d.prenom, d.nom, d.societe, d.amount, p.libelle as projet, d.fk_statut, d.adresse, d.cp, d.ville, d.pays, d.public, d.amount, d.fk_paiement, d.note, cp.libelle, d.email, d.fk_don_projet";
$sql.= " FROM ".MAIN_DB_PREFIX."don as d, ".MAIN_DB_PREFIX."c_paiement as cp LEFT JOIN ".MAIN_DB_PREFIX."don_projet as p";
$sql.= " ON p.rowid = d.fk_don_projet WHERE cp.id = d.fk_paiement AND d.rowid = $rowid";
if ( $this->db->query( $sql) ) if ( $this->db->query( $sql) )
{ {
@ -295,6 +298,7 @@ class Don
$obj = $this->db->fetch_object(); $obj = $this->db->fetch_object();
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->datec = $obj->datec;
$this->date = $obj->datedon; $this->date = $obj->datedon;
$this->prenom = stripslashes($obj->prenom); $this->prenom = stripslashes($obj->prenom);
$this->nom = stripslashes($obj->nom); $this->nom = stripslashes($obj->nom);

View File

@ -1219,7 +1219,7 @@ class Facture
} }
/** /**
* \brief Renvoi le libellé court d'un statut donn * \brief Renvoi le libellé court d'un statut donné
* \param paye etat paye * \param paye etat paye
* \param statut id statut * \param statut id statut
* \param amount amount already payed * \param amount amount already payed
@ -1264,10 +1264,10 @@ class Facture
} }
} }
/* /**
* \brief Charge les informations d'ordre info dans l'objet facture * \brief Charge les informations d'ordre info dans l'objet facture
* \param id id de la facture a charger * \param id Id de la facture a charger
*/ */
function info($id) function info($id)
{ {
$sql = "SELECT c.rowid, ".$this->db->pdate("datec")." as datec"; $sql = "SELECT c.rowid, ".$this->db->pdate("datec")." as datec";
@ -1569,32 +1569,64 @@ class Facture
} }
} }
} }
/**
* \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
* \return int <0 si ko, >0 si ok
*/
function load_board()
{
global $conf;
$this->nbtodo=$this->nbtodolate=0;
$sql = "SELECT f.rowid,".$this->db->pdate("f.date_lim_reglement")." as datefin";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " WHERE f.paye=0 AND f.fk_statut = 1";
$resql=$this->db->query($sql);
if ($resql)
{
while ($obj=$this->db->fetch_object($resql))
{
$this->nbtodo++;
if ($obj->datefin < (time() - $conf->facture->client->warning_delay)) $this->nbtodolate++;
}
return 1;
}
else
{
dolibarr_print_error($this->db);
$this->error=$this->db->error();
return -1;
}
}
} }
/** /**
\class FactureLigne \class FactureLigne
\brief Classe permettant la gestion des lignes de factures \brief Classe permettant la gestion des lignes de factures
*/ */
class FactureLigne class FactureLigne
{ {
/** /**
* \brief Constructeur d'objets ligne de facture * \brief Constructeur d'objets ligne de facture
* \param DB handler d'accès base de donnée * \param DB handler d'accès base de donnée
*/ */
function FactureLigne($DB) function FactureLigne($DB)
{ {
$this->db= $DB ; $this->db= $DB ;
} }
/** /**
* \brief Recupére l'objet ligne de facture * \brief Recupére l'objet ligne de facture
* \param rowid id de la ligne de facture * \param rowid id de la ligne de facture
* \param societe_id id de la societe * \param societe_id id de la societe
*/ */
function fetch($rowid, $societe_id=0) function fetch($rowid, $societe_id=0)
{ {
$sql = "SELECT fk_product, description, price, qty, rowid, tva_taux, remise, remise_percent, subprice, ".$this->db->pdate("date_start")." as date_start,".$this->db->pdate("date_end")." as date_end"; $sql = "SELECT fk_product, description, price, qty, rowid, tva_taux, remise, remise_percent, subprice, ".$this->db->pdate("date_start")." as date_start,".$this->db->pdate("date_end")." as date_end";

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Éric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Éric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com> * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -42,31 +42,35 @@
class Propal class Propal
{ {
var $id; var $id;
var $db; var $db;
var $socidp; var $socidp;
var $contactid; var $contactid;
var $projetidp; var $projetidp;
var $author; var $author;
var $ref; var $ref;
var $datep; var $datep;
var $remise; var $remise;
var $products; var $products;
var $products_qty; var $products_qty;
var $note; var $note;
var $price; var $price;
var $status; var $status;
var $labelstatut=array(); var $labelstatut=array();
var $labelstatut_short=array(); var $labelstatut_short=array();
var $product=array(); var $product=array();
// Pour board
var $nbtodo;
var $nbtodolate;
/** /**
* \brief Constructeur * \brief Constructeur
*/ */
function Propal($DB, $soc_idp="", $propalid=0) function Propal($DB, $soc_idp="", $propalid=0)
{ {
global $langs; global $langs;
@ -99,66 +103,65 @@ class Propal
* \see insert_product * \see insert_product
*/ */
function add_product($idproduct, $qty, $remise_percent=0) function add_product($idproduct, $qty, $remise_percent=0)
{ {
if ($idproduct > 0) if ($idproduct > 0)
{ {
$i = sizeof($this->products); $i = sizeof($this->products);
$this->products[$i] = $idproduct; $this->products[$i] = $idproduct;
if (!$qty) if (!$qty)
{ {
$qty = 1 ; $qty = 1 ;
} }
$this->products_qty[$i] = $qty; $this->products_qty[$i] = $qty;
$this->products_remise_percent[$i] = $remise_percent; $this->products_remise_percent[$i] = $remise_percent;
} }
} }
/** /**
* \brief Ajout d'un produit dans la proposition, en base * \brief Ajout d'un produit dans la proposition, en base
* \param idproduct id du produit à ajouter * \param idproduct id du produit à ajouter
* \param qty quantité * \param qty quantité
* \param remise_percent remise effectuée sur le produit * \param remise_percent remise effectuée sur le produit
* \return int 0 en cas de succès * \return int >0 si ok, <0 si ko
* \see add_product * \see add_product
*/ */
function insert_product($idproduct, $qty, $remise_percent=0)
function insert_product($idproduct, $qty, $remise_percent=0)
{ {
if ($this->statut == 0) if ($this->statut == 0)
{ {
$prod = new Product($this->db, $idproduct); $prod = new Product($this->db, $idproduct);
if ($prod->fetch($idproduct) > 0) if ($prod->fetch($idproduct) > 0)
{ {
$price = $prod->price; $price = $prod->price;
$subprice = $prod->price; $subprice = $prod->price;
if ($remise_percent > 0) if ($remise_percent > 0)
{ {
$remise = round(($prod->price * $remise_percent / 100), 2); $remise = round(($prod->price * $remise_percent / 100), 2);
$price = $prod->price - $remise; $price = $prod->price - $remise;
} }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
$sql .= " (".$this->id.",". $idproduct.",'". $qty."','". ereg_replace(",",".",$price)."','".$prod->tva_tx."','".addslashes($prod->label)."','".ereg_replace(",",".",$remise_percent)."','".ereg_replace(",",".",$subprice)."')"; $sql .= " (".$this->id.",". $idproduct.",'". $qty."','". ereg_replace(",",".",$price)."','".$prod->tva_tx."','".addslashes($prod->label)."','".ereg_replace(",",".",$remise_percent)."','".ereg_replace(",",".",$subprice)."')";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
$this->update_price(); $this->update_price();
return 1;
return 1; }
} else
else {
{ return -1;
return -1; }
} }
} else
else {
{ return -2;
return -2; }
} }
}
} }
/** /**
* \brief Mise à jour d'une ligne de produit * \brief Mise à jour d'une ligne de produit
* \param id id de la ligne * \param id id de la ligne
@ -168,93 +171,91 @@ class Propal
* \return int 0 en cas de succès * \return int 0 en cas de succès
*/ */
function UpdateLigne($id, $subprice, $qty, $remise_percent=0) function UpdateLigne($id, $subprice, $qty, $remise_percent=0)
{ {
if ($this->statut == 0) if ($this->statut == 0)
{ {
$price = $subprice; $price = $subprice;
if ($remise_percent > 0) if ($remise_percent > 0)
{ {
$remise = round(($subprice * $remise_percent / 100), 2); $remise = round(($subprice * $remise_percent / 100), 2);
$price = $subprice - $remise; $price = $subprice - $remise;
} }
$sql = "UPDATE ".MAIN_DB_PREFIX."propaldet "; $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet ";
$sql .= " SET qty='".$qty."'"; $sql .= " SET qty='".$qty."'";
$sql .= " , price='". ereg_replace(",",".",$price)."'"; $sql .= " , price='". ereg_replace(",",".",$price)."'";
$sql .= " , remise_percent='".ereg_replace(",",".",$remise_percent)."'"; $sql .= " , remise_percent='".ereg_replace(",",".",$remise_percent)."'";
$sql .= " , subprice='".ereg_replace(",",".",$subprice)."'"; $sql .= " , subprice='".ereg_replace(",",".",$subprice)."'";
$sql .= " WHERE rowid = '".$id."';"; $sql .= " WHERE rowid = '".$id."';";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
$this->update_price(); $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;
}
}
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;
$subprice = $p_price; $subprice = $p_price;
if ($remise_percent > 0) if ($remise_percent > 0)
{ {
$remise = round(($p_price * $remise_percent / 100), 2); $remise = round(($p_price * $remise_percent / 100), 2);
$price = $p_price - $remise; $price = $p_price - $remise;
} }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
$sql .= " (".$this->id.", 0,'". $p_qty."','". ereg_replace(",",".",$price)."','".$p_tva_tx."','".$p_desc."','$remise_percent', '".ereg_replace(",",".",$subprice)."') ; "; $sql .= " (".$this->id.", 0,'". $p_qty."','". ereg_replace(",",".",$price)."','".$p_tva_tx."','".$p_desc."','$remise_percent', '".ereg_replace(",",".",$subprice)."') ; ";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
if ($this->update_price() > 0) if ($this->update_price() > 0)
{ {
return 1; return 1;
} }
else else
{ {
return -1; return -1;
} }
} }
else else
{ {
print $this->db->error(); return -2;
print "<br>".$sql; }
return -2; }
}
}
} }
/* /**
* *
* *
*/ */
@ -348,12 +349,12 @@ class Propal
} }
else else
{ {
//dolibarr_print_error($this->db); return -2;
} }
} }
else else
{ {
//dolibarr_print_error($this->db); return -1;
} }
return $this->id; return $this->id;
} }
@ -582,7 +583,6 @@ class Propal
} }
else else
{ {
//dolibarr_print_error($this->db);
return -1; return -1;
} }
} }
@ -1059,18 +1059,58 @@ class Propal
* \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];
} }
/**
* \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
* \param mode opened pour propal à fermer, signed pour propale à facturer
* \return int <0 si ko, >0 si ok
*/
function load_board($mode)
{
global $conf;
$this->nbtodo=$this->nbtodolate=0;
$sql = "SELECT p.rowid,".$this->db->pdate("p.datec")." as datec,".$this->db->pdate("p.fin_validite")." as datefin";
$sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
if ($mode == 'opened') $sql.= " WHERE p.fk_statut = 1";
if ($mode == 'signed') $sql.= " WHERE p.fk_statut = 2";
$resql=$this->db->query($sql);
if ($resql)
{
while ($obj=$this->db->fetch_object($resql))
{
$this->nbtodo++;
if ($obj->datefin < (time() - $conf->propal->cloture->warning_delay)) $this->nbtodolate++;
}
return 1;
}
else
{
dolibarr_print_error($this->db);
$this->error=$this->db->error();
return -1;
}
}
} }
/**
\class PropalLigne
\brief Classe permettant la gestion des lignes de propales
*/
class PropaleLigne class PropaleLigne
{ {
function PropaleLigne() function PropaleLigne()
{ {
} }
} }
?> ?>