Dbut ajout modles commande et facture fournisseur

This commit is contained in:
Regis Houssin 2006-02-17 16:29:58 +00:00
parent 5d85f8db49
commit 3a390f8f1d
5 changed files with 171 additions and 41 deletions

View File

@ -96,7 +96,7 @@ if ($modulepart)
}
$original_file=$conf->propal->dir_output.'/'.$original_file;
}
// Wrapping pour les comandes
// Wrapping pour les commandes
if ($modulepart == 'commande')
{
$user->getrights('commande');
@ -106,6 +106,28 @@ if ($modulepart)
}
$original_file=$conf->commande->dir_output.'/'.$original_file;
}
// Wrapping pour les commandes fournisseurs
if ($modulepart == 'commande_fournisseur')
{
$user->getrights('fournisseur');
if ($user->rights->fournisseur->commande->lire)
{
$accessallowed=1;
}
$original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file;
}
// Wrapping pour les factures fournisseurs
if ($modulepart == 'facture_fournisseur')
{
$user->getrights('fournisseur');
if ($user->rights->fournisseur->facture->lire)
{
$accessallowed=1;
}
$original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file;
}
// Wrapping pour les rapport de paiements
if ($modulepart == 'facture_paiement')

View File

@ -31,6 +31,7 @@
require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/project.class.php");
require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
require_once(DOL_DOCUMENT_ROOT ."/fourn/commande/modules/modules_commandefournisseur.php");
if (!$user->rights->fournisseur->commande->lire) accessforbidden();
@ -204,6 +205,21 @@ if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->r
exit;
}
/*
* Generation de la commande
* définit dans /fourn/commande/modules/modules_commandefournisseur.php
*/
if ($_POST['action'] == 'builddoc')
{
commande_supplier_pdf_create($db, $_GET['id'],$_POST['model']);
}
if($_GET['action'] == 'builddoc')
{
$commande = new CommandeFournisseur($db);
$commande->fetch($_GET['id']);
commande_supplier_pdf_create($db, $_GET['id'],$commande->modelpdf);
}
/*
* Créé une commande
*/
@ -478,7 +494,7 @@ if ($_GET["id"] > 0)
/*
* Ajouter une ligne
*/
if ($_GET["action"] <> 'valid' && $commande->statut == 0 && $user->rights->fournisseur->commande->creer)
if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer && ($_GET["action"] <> 'valid' || $_GET['action'] == 'builddoc'))
{
print '<form action="fiche.php?id='.$commande->id.'" method="post">';
print '<input type="hidden" name="action" value="addligne">';
@ -510,7 +526,7 @@ if ($_GET["id"] > 0)
/**
* Boutons actions
*/
if ($user->societe_id == 0 && $commande->statut < 3 && $_GET["action"] <> 'valid')
if ($user->societe_id == 0 && $commande->statut < 3 && ($_GET["action"] <> 'valid' || $_GET['action'] == 'builddoc'))
{
print '<div class="tabsAction">';
@ -552,34 +568,46 @@ if ($_GET["id"] > 0)
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
}
}
// Build PDF
if ($user->rights->fournisseur->commande->creer)
{
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=builddoc">'.$langs->trans("BuildPDF").'</a>';
}
print "</div>";
}
/*
* Documents générés
*
*/
$file = $conf->commande->dir_output . "/" . $commande->ref . "/" . $commande->ref . ".pdf";
$relativepath=$commande->ref . "/" . $commande->ref . ".pdf";
$var=true;
if (file_exists($file))
{
print_titre($langs->trans("Documents"));
print '<table width="100%" class="border">';
print "<tr $bc[$var]><td>".$langs->trans("Order")." PDF</td>";
print '<td><a href="'.DOL_URL_ROOT.'/document.php?modulepart=commande&file='.urlencode($relativepath).'">'.$commande->ref.'.pdf</a></td>';
print '<td align="right">'.filesize($file). ' bytes</td>';
print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'</td>';
print '</tr>';
print "</table>\n";
/*
* Documents générés
*
*/
$comfournref = sanitize_string($commande->ref);
$comfournref = str_replace("(","",$comfournref);
$comfournref = str_replace(")","",$comfournref);
$file = $conf->fournisseur->commande->dir_output . '/' . $comfournref . '/' . $comfournref . '.pdf';
$relativepath = $comfournref.'/'.$comfournref.'.pdf';
$filedir = $conf->fournisseur->commande->dir_output . '/' . $comfournref;
$urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id;
$genallowed=$user->rights->fournisseur->commande->creer;
$delallowed=$user->rights->fournisseur->commande->supprimer;
print '</td><td valign="top" width="50%">';
}
$var=true;
/*
if (file_exists($file))
{
print_titre($langs->trans('Documents'));
print '<table width="100%" class="border">';
print '<tr '.$bc[$var].'><td>'.$langs->trans('Order').' PDF</td>';
print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=commande&file='.urlencode($relativepath).'">'.$commande->ref.'.pdf</a></td>';
print '<td align="right">'.filesize($file). ' bytes</td>';
print '<td align="right">'.strftime('%d %b %Y %H:%M:%S',filemtime($file)).'</td>';
print '</tr>';
print '</table>';
print '<br>';
}
*/
//$html->show_documents('propal',$filename,$filedir,$urlsource,$genallowed,$delallowed,$propal->modelpdf);
$html->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf);
/*
*

View File

@ -70,18 +70,15 @@ class CommandeFournisseur
$sql = "SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva";
$sql .= ", ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source, c.fk_methode_commande ";
$sql .= ", c.note";
$sql .= ", cm.libelle as methode_commande";
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm.rowid = c.fk_methode_commande";
$sql .= " WHERE c.rowid = ".$id;
$resql = $this->db->query($sql) ;
if ($resql)
$result = $this->db->query($sql) ;
if ($result)
{
$obj = $this->db->fetch_object($resql);
$obj = $this->db->fetch_object();
$this->id = $obj->rowid;
$this->ref = $obj->ref;
@ -102,26 +99,60 @@ class CommandeFournisseur
$this->projet_id = $obj->fk_projet;
$this->note = stripslashes($obj->note);
$this->db->free($resql);
$this->db->free();
if ($this->statut == 0)
{
$this->brouillon = 1;
}
$result = 0;
// export pdf -----------
$this->lignes = array();
$sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,';
$sql.= ' p.label, p.description as product_desc, p.ref, p.fk_product_type, p.rowid as prodid';
$sql.= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid';
$sql.= ' WHERE l.fk_commande = '.$this->id;
$sql.= ' ORDER BY l.rowid';
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
$objp = $this->db->fetch_object($result);
$ligne = new CommandeLigne();
$ligne->desc = $objp->description; // Description ligne
$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 = $objp->fk_product;
$ligne->libelle = $objp->label; // Label produit
$ligne->product_desc = $objp->product_desc; // Description produit
$ligne->ref = $objp->ref;
$this->lignes[$i] = $ligne;
//dolibarr_syslog("1 ".$ligne->desc);
//dolibarr_syslog("2 ".$ligne->product_desc);
$i++;
}
$this->db->free($result);
}
else
{
dolibarr_syslog("CommandeFournisseur::Fetch Error $sql");
dolibarr_syslog("CommandeFournisseur::Fetch Error ".$this->db->error());
$result = -1;
return -1;
}
return $result ;
}
}
/**
* \brief Insère ligne de log
@ -715,6 +746,32 @@ class CommandeFournisseur
$opdf->write_pdf_file($this);
}
/**
*
*
*
*/
function set_pdf_model($user, $modelpdf)
{
if ($user->rights->fournisseur->commande->creer)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET model_pdf = '$modelpdf'";
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
if ($this->db->query($sql) )
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return 0;
}
}
}
/**
*
*

View File

@ -1838,7 +1838,7 @@ class Form
$modellist=$model->liste_modeles($this->db);
}
}
else if ($modulepart == 'commande')
else if ($modulepart == 'commande')
{
if (is_array($genallowed)) $modellist=$genallowed;
else
@ -1868,6 +1868,26 @@ class Form
$modellist=$model->liste_modeles($this->db);
}
}
else if ($modulepart == 'commande_fournisseur')
{
if (is_array($genallowed)) $modellist=$genallowed;
else
{
include_once(DOL_DOCUMENT_ROOT.'/fourn/commande/modules/modules_commandefournisseur.php');
$model=new ModelePDFCommandesSuppliers();
$modellist=$model->liste_modeles();
}
}
else if ($modulepart == 'facture_fournisseur')
{
if (is_array($genallowed)) $modellist=$genallowed;
else
{
include_once(DOL_DOCUMENT_ROOT.'/fourn/facture/modules/modules_facturefournisseur.php');
$model=new ModelePDFFacturesSuppliers();
$modellist=$model->liste_modeles();
}
}
else
{
dolibarr_print_error($this->db,'Bad value for modulepart');

View File

@ -63,6 +63,9 @@ class modFournisseur extends DolibarrModules
// Dir
$this->dirs = array();
$this->const[0][0] = "COMMANDE_SUPPLIER_ADDON_PDF";
$this->const[0][1] = "chaine";
$this->const[0][2] = "muscadet";
// Dépendances
$this->depends = array("modSociete");