Gestion d'affichage de specimen sur propale

This commit is contained in:
Laurent Destailleur 2006-06-12 22:20:24 +00:00
parent 4aeb30dd08
commit 0d3affa1f8
17 changed files with 1100 additions and 1028 deletions

View File

@ -31,6 +31,7 @@
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
$langs->load("admin"); $langs->load("admin");
$langs->load("bills"); $langs->load("bills");
@ -45,6 +46,31 @@ if (!$user->admin)
* Actions * Actions
*/ */
if ($_GET["action"] == 'specimen')
{
$modele=$_GET["module"];
$propal = new Propal($db);
$propal->initAsSpecimen();
// Charge le modele
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/propale/";
$file = "pdf_propale_".$modele.".modules.php";
if (file_exists($dir.$file))
{
$classname = "pdf_propale_".$modele;
require_once($dir.$file);
$obj = new $classname($db);
if ($obj->write_pdf_file($propal) > 0)
{
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=propal&file=SPECIMEN.pdf");
return;
}
}
}
if ($_POST["action"] == 'nbprod') if ($_POST["action"] == 'nbprod')
{ {
dolibarr_set_const($db, "PROPALE_NEW_FORM_NB_PRODUCT",$_POST["value"]); dolibarr_set_const($db, "PROPALE_NEW_FORM_NB_PRODUCT",$_POST["value"]);
@ -312,7 +338,9 @@ while (($file = readdir($handle))!==false)
$htmltooltip.='<br><b>'.$langs->trans("Logo").'</b>: '.yn($obj->option_logo); $htmltooltip.='<br><b>'.$langs->trans("Logo").'</b>: '.yn($obj->option_logo);
$htmltooltip.='<br><b>'.$langs->trans("PaymentMode").'</b>: '.yn($obj->option_modereg); $htmltooltip.='<br><b>'.$langs->trans("PaymentMode").'</b>: '.yn($obj->option_modereg);
$htmltooltip.='<br><b>'.$langs->trans("PaymentConditions").'</b>: '.yn($obj->option_condreg); $htmltooltip.='<br><b>'.$langs->trans("PaymentConditions").'</b>: '.yn($obj->option_condreg);
print '<td align="center" '.$html->tooltip_properties($htmltooltip).'>'.img_help(0).'</td>'; print '<td align="center" '.$html->tooltip_properties($htmltooltip).'>';
print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'" alt="" title="">'.img_help(0,0).'</a>';
print '</td>';
print "</tr>\n"; print "</tr>\n";
} }

View File

@ -68,6 +68,14 @@ class Facture
var $mode_reglement_id; var $mode_reglement_id;
var $mode_reglement_code; var $mode_reglement_code;
// Pour board
var $nbtodo;
var $nbtodolate;
var $specimen;
var $error;
/** /**
* \brief Constructeur de la classe * \brief Constructeur de la classe
* \param DB handler accès base de données * \param DB handler accès base de données

View File

@ -49,6 +49,10 @@ class pdf_propale_azur extends ModelePDFPropales
{ {
global $conf,$langs; global $conf,$langs;
$langs->load("main");
$langs->load("bills");
$langs->load("products");
$this->db = $db; $this->db = $db;
$this->name = "azur"; $this->name = "azur";
$this->description = "Modèle de propositions commerciales complet (logo...)"; $this->description = "Modèle de propositions commerciales complet (logo...)";
@ -127,9 +131,9 @@ class pdf_propale_azur extends ModelePDFPropales
\remarks MAIN_INFO_CAPITAL \remarks MAIN_INFO_CAPITAL
\remarks MAIN_INFO_TVAINTRA \remarks MAIN_INFO_TVAINTRA
*/ */
function write_pdf_file($propale) function write_pdf_file($propale,$outputlangs='')
{ {
global $user,$conf,$langs; global $user,$conf,$langs,$mysoc;
if ($conf->propal->dir_output) if ($conf->propal->dir_output)
{ {
@ -165,6 +169,8 @@ class pdf_propale_azur extends ModelePDFPropales
if (file_exists($dir)) if (file_exists($dir))
{ {
$nblignes = sizeof($propale->lignes);
// Initialisation document vierge // Initialisation document vierge
$pdf=new FPDF('P','mm',$this->format); $pdf=new FPDF('P','mm',$this->format);
$pdf->Open(); $pdf->Open();

View File

@ -85,9 +85,9 @@ class pdf_propale_bleu extends ModelePDFPropales
\remarks MAIN_INFO_CAPITAL \remarks MAIN_INFO_CAPITAL
\remarks MAIN_INFO_TVAINTRA \remarks MAIN_INFO_TVAINTRA
*/ */
function write_pdf_file($propale) function write_pdf_file($propale,$outputlangs='')
{ {
global $user,$conf,$langs; global $user,$conf,$langs,$mysoc;
if ($conf->propal->dir_output) if ($conf->propal->dir_output)
{ {

View File

@ -70,9 +70,9 @@ class pdf_propale_jaune extends ModelePDFPropales
\param propale Objet propal \param propale Objet propal
\return int 1=ok, 0=ko \return int 1=ok, 0=ko
*/ */
function write_pdf_file($propale) function write_pdf_file($propale,$outputlangs='')
{ {
global $user,$conf,$langs; global $user,$conf,$langs,$mysoc;
if ($conf->propal->dir_output) if ($conf->propal->dir_output)
{ {

View File

@ -73,9 +73,9 @@ class pdf_propale_rouge extends ModelePDFPropales
\param propale Objet propal \param propale Objet propal
\return int 1=ok, 0=ko \return int 1=ok, 0=ko
*/ */
function write_pdf_file($propale) function write_pdf_file($propale,$outputlangs='')
{ {
global $user,$conf,$langs; global $user,$conf,$langs,$mysoc;
if ($conf->propal->dir_output) if ($conf->propal->dir_output)
{ {

View File

@ -71,9 +71,9 @@ class pdf_propale_vert extends ModelePDFPropales
\param propale Objet propal \param propale Objet propal
\return int 1=ok, 0=ko \return int 1=ok, 0=ko
*/ */
function write_pdf_file($propale) function write_pdf_file($propale,$outputlangs='')
{ {
global $user,$conf,$langs; global $user,$conf,$langs,$mysoc;
if ($conf->propal->dir_output) if ($conf->propal->dir_output)
{ {

View File

@ -51,12 +51,13 @@ class Propal
var $projetidp; var $projetidp;
var $author; var $author;
var $ref; var $ref;
var $status;
var $datep; var $datep;
var $fin_validite;
var $products; var $products;
var $products_qty; var $products_qty;
var $price; var $price;
var $status;
var $fin_validite;
var $cond_reglement_id; var $cond_reglement_id;
var $cond_reglement_code; var $cond_reglement_code;
var $mode_reglement_id; var $mode_reglement_id;
@ -79,6 +80,7 @@ class Propal
var $nbtodo; var $nbtodo;
var $nbtodolate; var $nbtodolate;
var $specimen;
var $error; var $error;
@ -1053,10 +1055,10 @@ class Propal
$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>';
/* /*
* Lignes propales liées à un produit * Lignes propales liées à un produit ou non
*/ */
$sql = "SELECT d.description, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice,"; $sql = "SELECT d.description, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice, d.fk_product,";
$sql.= " d.fk_product, p.label, p.description as product_desc, p.ref"; $sql.= " p.label, p.description as product_desc, p.ref";
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d"; $sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
$sql.= " WHERE d.fk_propal = ".$this->id; $sql.= " WHERE d.fk_propal = ".$this->id;
@ -1089,7 +1091,7 @@ class Propal
$this->lignes[$i] = $ligne; $this->lignes[$i] = $ligne;
//dolibarr_syslog("1 ".$ligne->desc); //dolibarr_syslog("1 ".$ligne->desc);
//dolibarr_syslog("2 ".$ligne->product_desc); //print "xx $i ".$this->lignes[$i]->product_desc;
$i++; $i++;
} }
$this->db->free($result); $this->db->free($result);
@ -1100,54 +1102,6 @@ class Propal
return -1; return -1;
} }
/*
* Lignes propales liées à aucun produit
*/
/* // requête en double, du coup les "Lignes propales liées à aucun produit" n'était plus classé dans l'ordre
$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->desc = $objp->description;
$ligne->qty = $objp->qty;
$ligne->tva_tx = $objp->tva_tx;
$ligne->subprice = $objp->subprice;
$ligne->remise_percent = $objp->remise_percent;
$ligne->price = $objp->price;
$ligne->product_id = 0;
$ligne->libelle = $objp->description;
$ligne->product_desc = '';
$ligne->ref = '';
$this->lignes[$i] = $ligne;
$i++;
$j++;
}
$this->db->free($result);
}
else
{
dolibarr_syslog("Propal::Fetch Erreur lecture des lignes de propale");
return -1;
}
*/
} }
return 1; return 1;
} }
@ -2201,6 +2155,82 @@ class Propal
return $this->id; return $this->id;
} }
/**
* \brief Initialise la propale avec valeurs fictives aléatoire
* Sert à générer une facture pour l'aperu des modèles ou demo
*/
function initAsSpecimen()
{
global $user,$langs;
// Charge tableau des id de société socids
$socids = array();
$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
$resql = $this->db->query($sql);
if ($resql)
{
$num_socs = $this->db->num_rows($resql);
$i = 0;
while ($i < $num_socs)
{
$i++;
$row = $this->db->fetch_row($resql);
$socids[$i] = $row[0];
}
}
// Charge tableau des produits prodids
$prodids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE envente=1";
$resql = $this->db->query($sql);
if ($resql)
{
$num_prods = $this->db->num_rows($resql);
$i = 0;
while ($i < $num_prods)
{
$i++;
$row = $this->db->fetch_row($resql);
$prodids[$i] = $row[0];
}
}
// Initialise paramètres
$this->id=0;
$this->ref = 'SPECIMEN';
$this->specimen=1;
$socid = rand(1, $num_socs);
$this->socidp = $socids[$socid];
$this->date = time();
$this->date_lim_reglement=$this->date+3600*24*30;
$this->cond_reglement_code = 'RECEP';
$this->mode_reglement_code = 'CHQ';
$this->note_public='SPECIMEN';
$nbp = rand(1, 9);
$xnbp = 0;
while ($xnbp < $nbp)
{
$ligne=new PropaleLigne($this->db);
$ligne->desc=$langs->trans("Description")." ".$xnbp;
$ligne->qty=1;
$ligne->subprice=100;
$ligne->price=100;
$ligne->tva_taux=19.6;
$prodid = rand(1, $num_prods);
$ligne->produit_id=$prodids[$prodid];
$this->lignes[$xnbp]=$ligne;
$xnbp++;
}
$this->amount_ht = $xnbp*100;
$this->total_ht = $xnbp*100;
$this->total_tva = $xnbp*19.6;
$this->total_ttc = $xnbp*119.6;
}
} }