';
- print ''; // ancre
-
- /*
- * Documents générés
- */
- $filename=sanitize_string($fac->ref);
- $filedir=$conf->facture->dir_output . '/' . sanitize_string($fac->ref);
- $urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id;
- $genallowed=$user->rights->facture->creer;
- $delallowed=$user->rights->facture->supprimer;
-
- $var=true;
-
- print ' ';
- $somethingshown=$formfile->show_documents('facture',$filename,$filedir,$urlsource,$genallowed,$delallowed,$fac->modelpdf);
-
- /*
- * Propales rattachées
- */
- $sql = 'SELECT '.$db->pdate('p.datep').' as dp, p.total_ht, p.ref, p.ref_client, p.rowid as propalid';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'propal as p';
- $sql .= ", ".MAIN_DB_PREFIX."fa_pr as fp";
- $sql .= " WHERE fp.fk_propal = p.rowid AND fp.fk_facture = ".$fac->id;
-
- dolibarr_syslog("facture.php: sql=".$sql);
- $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- if ($num)
- {
- $i = 0; $total = 0;
- if ($somethingshown) print ' ';
- $somethingshown=1;
- print_titre($langs->trans('RelatedCommercialProposals'));
- print '';
- print '';
- print '| '.$langs->trans('Ref').' | ';
- print ''.$langs->trans('RefCustomer').' | ';
- print ''.$langs->trans('Date').' | ';
- print ''.$langs->trans('AmountHT').' | ';
- print ' ';
-
- $var=True;
- while ($i < $num)
+
+ // Emettre remboursement ou Convertir en reduc
+ if ($fac->type == 2)
{
- $objp = $db->fetch_object($resql);
- $var=!$var;
- print '';
- print '| '.img_object($langs->trans('ShowPropal'),'propal').' '.$objp->ref.' | ';
- print ''.$objp->ref_client.' | ';
- print ''.dolibarr_print_date($objp->dp,'day').' | ';
- print ''.price($objp->total_ht).' | ';
- print ' ';
- $total = $total + $objp->total_ht;
- $i++;
+ if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement)
+ {
+ print ''.$langs->trans('DoPaymentBack').'';
+ }
+
+ if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->creer && $fac->getSommePaiement() == 0)
+ {
+ print 'id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').'';
+ }
}
- print '';
- print '| '.$langs->trans('TotalHT').' | ';
- print ' | ';
- print ' | ';
- print ''.price($total).' | ';
- print ' ';
+
+ // Classer 'payé'
+ if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement &&
+ (($fac->type != 2 && $resteapayer <= 0) || ($fac->type == 2 && $resteapayer >= 0)) )
+ {
+ print ''.$langs->trans('ClassifyPayed').'';
+ }
+
+ // Classer 'fermée' (possible si validée et pas encore classée payée)
+ if ($fac->statut == 1 && $fac->paye == 0 && $resteapayer > 0
+ && $user->rights->facture->paiement)
+ {
+ if ($totalpaye > 0 || $totalavoir > 0)
+ {
+ // If one payment or one credit note was linked to this invoice
+ print ''.$langs->trans('ClassifyPayedPartially').'';
+ }
+ else
+ {
+ if ($facidnext)
+ {
+ print ''.$langs->trans('ClassifyCanceled').'';
+ }
+ else
+ {
+ print ''.$langs->trans('ClassifyCanceled').'';
+ }
+ }
+ }
+
+ // Supprimer
+ if ($fac->is_erasable() && $user->rights->facture->supprimer && $_GET['action'] != 'delete')
+ {
+ if ($facidnext)
+ {
+ print ''.$langs->trans('Delete').'';
+ }
+ else
+ {
+ print 'id.'&action=delete">'.$langs->trans('Delete').'';
+ }
+ }
+
+ print '';
}
}
- else
+
+
+ if ($_GET['action'] != 'prerelance' && $_GET['action'] != 'presend')
{
- dolibarr_print_error($db);
- }
-
- /*
- * Commandes rattachées
- */
- if($conf->commande->enabled)
- {
- $sql = 'SELECT '.$db->pdate('c.date_commande').' as date_commande, c.total_ht, c.ref, c.ref_client, c.rowid as id';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'co_fa as co_fa WHERE co_fa.fk_commande = c.rowid AND co_fa.fk_facture = '.$fac->id;
+ print '';
+ print ''; // ancre
+
+ /*
+ * Documents générés
+ */
+ $filename=sanitize_string($fac->ref);
+ $filedir=$conf->facture->dir_output . '/' . sanitize_string($fac->ref);
+ $urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id;
+ $genallowed=$user->rights->facture->creer;
+ $delallowed=$user->rights->facture->supprimer;
+
+ $var=true;
+
+ print ' ';
+ $somethingshown=$formfile->show_documents('facture',$filename,$filedir,$urlsource,$genallowed,$delallowed,$fac->modelpdf);
+
+ /*
+ * Propales rattachées
+ */
+ $sql = 'SELECT '.$db->pdate('p.datep').' as dp, p.total_ht, p.ref, p.ref_client, p.rowid as propalid';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'propal as p';
+ $sql .= ", ".MAIN_DB_PREFIX."fa_pr as fp";
+ $sql .= " WHERE fp.fk_propal = p.rowid AND fp.fk_facture = ".$fac->id;
+
+ dolibarr_syslog("facture.php: sql=".$sql);
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
if ($num)
{
- $langs->load("orders");
-
$i = 0; $total = 0;
if ($somethingshown) print ' ';
$somethingshown=1;
- print_titre($langs->trans('RelatedOrders'));
+ print_titre($langs->trans('RelatedCommercialProposals'));
print '';
print '';
print '| '.$langs->trans('Ref').' | ';
- print ''.$langs->trans('RefCustomerOrderShort').' | ';
+ print ''.$langs->trans('RefCustomer').' | ';
print ''.$langs->trans('Date').' | ';
print ''.$langs->trans('AmountHT').' | ';
print ' ';
- $var=true;
+
+ $var=True;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
$var=!$var;
- print '| ';
- print ''.img_object($langs->trans('ShowOrder'), 'order').' '.$objp->ref." | \n";
+ print ' ';
+ print '| '.img_object($langs->trans('ShowPropal'),'propal').' '.$objp->ref.' | ';
print ''.$objp->ref_client.' | ';
- print ''.dolibarr_print_date($objp->date_commande,'day').' | ';
+ print ''.dolibarr_print_date($objp->dp,'day').' | ';
print ''.price($objp->total_ht).' | ';
- print " \n";
+ print '';
$total = $total + $objp->total_ht;
$i++;
}
@@ -2950,27 +2939,80 @@ else
{
dolibarr_print_error($db);
}
+
+ /*
+ * Commandes rattachées
+ */
+ if($conf->commande->enabled)
+ {
+ $sql = 'SELECT '.$db->pdate('c.date_commande').' as date_commande, c.total_ht, c.ref, c.ref_client, c.rowid as id';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'co_fa as co_fa WHERE co_fa.fk_commande = c.rowid AND co_fa.fk_facture = '.$fac->id;
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ if ($num)
+ {
+ $langs->load("orders");
+
+ $i = 0; $total = 0;
+ if ($somethingshown) print ' ';
+ $somethingshown=1;
+ print_titre($langs->trans('RelatedOrders'));
+ print '';
+ print '';
+ print '| '.$langs->trans('Ref').' | ';
+ print ''.$langs->trans('RefCustomerOrderShort').' | ';
+ print ''.$langs->trans('Date').' | ';
+ print ''.$langs->trans('AmountHT').' | ';
+ print ' ';
+ $var=true;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($resql);
+ $var=!$var;
+ print '| ';
+ print ''.img_object($langs->trans('ShowOrder'), 'order').' '.$objp->ref." | \n";
+ print ''.$objp->ref_client.' | ';
+ print ''.dolibarr_print_date($objp->date_commande,'day').' | ';
+ print ''.price($objp->total_ht).' | ';
+ print " \n";
+ $total = $total + $objp->total_ht;
+ $i++;
+ }
+ print '';
+ print '| '.$langs->trans('TotalHT').' | ';
+ print ' | ';
+ print ' | ';
+ print ''.price($total).' | ';
+ print ' ';
+ }
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
+ }
+
+ print '';
+
+ print ' ';
+
+ // List of actions on element
+ include_once(DOL_DOCUMENT_ROOT.'/html.formactions.class.php');
+ $formactions=new FormActions($db);
+ $somethingshown=$formactions->showactions($fac,'invoice',$socid);
+
+ print ' | ';
}
- print ' | ';
-
- print ' ';
-
- // List of actions on element
- include_once(DOL_DOCUMENT_ROOT.'/html.formactions.class.php');
- $formactions=new FormActions($db);
- $somethingshown=$formactions->showactions($fac,'invoice',$socid);
-
- print ' | ';
-
-
/*
* Affiche formulaire mail
*/
if ($_GET['action'] == 'presend')
{
- $facref = sanitize_string($fac->ref);
- $file = $conf->facture->dir_output . '/' . $facref . '/' . $facref . '.pdf';
+ $ref = sanitize_string($fac->ref);
+ $file = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
// Construit PDF si non existant
if (! is_readable($file))
@@ -3021,6 +3063,13 @@ else
$formmail->param['facid']=$fac->id;
$formmail->param['returnurl']=DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id;
+ // Init list of files
+ if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
+ {
+ $formmail->clear_attached_files();
+ $formmail->add_attached_files($file,$ref.'.pdf','application/pdf');
+ }
+
$formmail->show_form();
print ' ';
@@ -3028,8 +3077,8 @@ else
if ($_GET['action'] == 'prerelance')
{
- $facref = sanitize_string($fac->ref);
- $file = $conf->facture->dir_output . '/' . $facref . '/' . $facref . '.pdf';
+ $ref = sanitize_string($fac->ref);
+ $file = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
// Construit PDF si non existant
if (! is_readable($file))
@@ -3068,6 +3117,7 @@ else
$formmail->withfile=1;
$formmail->withbody=1;
$formmail->withdeliveryreceipt=1;
+ $formmail->withcancel=1;
// Tableau des substitutions
$formmail->substit['__FACREF__']=$fac->ref;
// Tableau des paramètres complémentaires
@@ -3076,6 +3126,13 @@ else
$formmail->param['facid']=$fac->id;
$formmail->param['returnurl']=DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id;
+ // Init list of files
+ if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
+ {
+ $formmail->clear_attached_files();
+ $formmail->add_attached_files($file,$ref.'.pdf','application/pdf');
+ }
+
$formmail->show_form();
print ' ';
diff --git a/htdocs/conf/conf.class.php b/htdocs/conf/conf.class.php
index 8b0b5c6b720..a0f68f3ba5f 100644
--- a/htdocs/conf/conf.class.php
+++ b/htdocs/conf/conf.class.php
@@ -141,7 +141,7 @@ class Conf
* Autres parametres globaux de configurations
*/
$this->users->dir_output=DOL_DATA_ROOT."/users";
-
+
/*
* Autorisation globale d'uploader (necessaire pour desactiver dans la demo)
* conf->upload peut etre ecrasee dans main.inc.php (selon user)
diff --git a/htdocs/html.formfile.class.php b/htdocs/html.formfile.class.php
index 819af96fbdc..108440f7ff1 100644
--- a/htdocs/html.formfile.class.php
+++ b/htdocs/html.formfile.class.php
@@ -436,69 +436,6 @@ class FormFile
}
- /**
- * \brief Show list of documents in a directory
- * \param upload_dir Dir to scan
- * \param object Object on which document is linked to
- * \param modulepart Value for modulepart used by download wrapper
- * \return int <0 if KO, nb of files shown if OK
- */
- function list_of_documents2($upload_dir,$object,$modulepart)
- {
- global $user, $conf, $langs;
- global $bc;
-
- // List of documents
- $errorlevel=error_reporting();
- error_reporting(0);
- $handle=opendir($upload_dir);
- error_reporting($errorlevel);
-
- // Affiche liste des documents existant
- print_titre($langs->trans("AttachedFiles"));
-
- print '';
-
- print '';
- print '| '.$langs->trans('Document').' | ';
- print ''.$langs->trans('Size').' | ';
- print ''.$langs->trans('Date').' | ';
- print ' | ';
- print ' ';
- $var=true;
-
- if ($handle)
- {
- while (($file = readdir($handle))!==false)
- {
- if (!is_dir($dir.$file)
- && $file != '.'
- && $file != '..'
- && $file != 'CVS'
- && ! eregi('\.meta$',$file)
- )
- {
- // Define relative path used to store the file
- $morepath=$object->ref.'/';
- if ($modulepart == 'facture_fournisseur') $morepath=get_exdir($object->id,2).$morepath;
-
- $var=!$var;
- print '';
- print '| ';
- print img_mime($file).' ';
- print ''.$file.'';
- print " | \n";
- print ''.filesize($upload_dir.'/'.$file). ' '.$langs->trans('bytes').' | ';
- print ''.dolibarr_print_date(filemtime($upload_dir.'/'.$file),'dayhour').' | ';
- print '';
- print 'id.'&action=delete&urlfile='.urlencode($file).'">'.img_delete($langs->trans('Delete')).'';
- print " | \n";
- }
- }
- closedir($handle);
- }
- print ' ';
- }
}
?>
diff --git a/htdocs/html.formmail.class.php b/htdocs/html.formmail.class.php
index 96b9de2e0b1..aa8ec32665c 100644
--- a/htdocs/html.formmail.class.php
+++ b/htdocs/html.formmail.class.php
@@ -32,7 +32,6 @@ require_once(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php");
\remarks $formmail->proprietes=1 ou chaine ou tableau de valeurs
\remarks $formmail->show_form() affiche le formulaire
*/
-
class FormMail
{
var $db;
@@ -49,7 +48,7 @@ class FormMail
var $withto;
var $withtocc;
var $withtopic;
- var $withfile;
+ var $withfile; // 0=No attaches files, 1=Show attached files, 2=Can add new attached files
var $withbody;
var $withfromreadonly;
@@ -95,9 +94,51 @@ class FormMail
return 1;
}
+ /**
+ * Clear list of attached files (store in SECTION array)
+ */
+ function clear_attached_files()
+ {
+ global $conf,$user;
+
+ $conf->users->dir_tmp=DOL_DATA_ROOT."/users/".$user->id;
+ $upload_dir = $conf->users->dir_tmp.'/temp';
+ if (is_dir($upload_dir)) dol_delete_dir_recursive($upload_dir);
+
+ unset($_SESSION["listofpaths"]);
+ unset($_SESSION["listofnames"]);
+ unset($_SESSION["listofmimes"]);
+ }
+
+ /**
+ * Add a file into the list of attached files (stored in SECTION array)
+ *
+ * @param unknown_type $path
+ * @param unknown_type $file
+ * @param unknown_type $type
+ */
+ function add_attached_files($path,$file,$type)
+ {
+ $listofpaths=array();
+ $listofnames=array();
+ $listofmimes=array();
+ if (! empty($_SESSION["listofpaths"])) $listofpaths=split(';',$_SESSION["listofpaths"]);
+ if (! empty($_SESSION["listofnames"])) $listofnames=split(';',$_SESSION["listofnames"]);
+ if (! empty($_SESSION["listofmimes"])) $listofmimes=split(';',$_SESSION["listofmimes"]);
+ if (! in_array($file,$listofnames))
+ {
+ $listofpaths[]=$path;
+ $listofnames[]=$file;
+ $listofmimes[]=$type;
+ $_SESSION["listofpaths"]=join(';',$listofpaths);
+ $_SESSION["listofnames"]=join(';',$listofnames);
+ $_SESSION["listofmimes"]=join(';',$listofmimes);
+ }
+ }
- /*
- * \brief Affiche la partie de formulaire pour saisie d'un mail en fonction des propriétés
+ /**
+ * \brief Affiche la partie de formulaire pour saisie d'un mail en fonction des propriétés
+ * \remarks this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files
*/
function show_form()
{
@@ -106,6 +147,15 @@ class FormMail
$langs->load("other");
$langs->load("mails");
+ // Define list of attached files
+ $listofpaths=array();
+ $listofnames=array();
+ $listofmimes=array();
+ if (! empty($_SESSION["listofpaths"])) $listofpaths=split(';',$_SESSION["listofpaths"]);
+ if (! empty($_SESSION["listofnames"])) $listofnames=split(';',$_SESSION["listofnames"]);
+ if (! empty($_SESSION["listofmimes"])) $listofmimes=split(';',$_SESSION["listofmimes"]);
+
+
$form=new Form($DB);
print "\n\n";
@@ -294,13 +344,32 @@ class FormMail
print " |
\n";
}
- // Si fichier joint
+ // Attached files
if ($this->withfile)
{
print "