Ejemplo n.º 1
0
 }
 // tva paid
 foreach (array_keys($x_paye) as $my_paye_rate) {
     $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
     $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
     if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
         $x_both[$my_paye_rate]['coll']['totalht'] = 0;
         $x_both[$my_paye_rate]['coll']['vat'] = 0;
     }
     $x_both[$my_paye_rate]['paye']['links'] = '';
     $x_both[$my_paye_rate]['paye']['detail'] = array();
     foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
         $invoice_supplier->id = $x_paye[$my_paye_rate]['facid'][$id];
         $invoice_supplier->ref = $x_paye[$my_paye_rate]['facnum'][$id];
         $invoice_supplier->type = $x_paye[$my_paye_rate]['type'][$id];
         $x_both[$my_paye_rate]['paye']['detail'][] = array('id' => $x_paye[$my_paye_rate]['facid'][$id], 'descr' => $x_paye[$my_paye_rate]['descr'][$id], 'pid' => $x_paye[$my_paye_rate]['pid'][$id], 'pref' => $x_paye[$my_paye_rate]['pref'][$id], 'ptype' => $x_paye[$my_paye_rate]['ptype'][$id], 'payment_id' => $x_paye[$my_paye_rate]['payment_id'][$id], 'payment_amount' => $x_paye[$my_paye_rate]['payment_amount'][$id], 'ftotal_ttc' => price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), 'dtotal_ttc' => price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), 'dtype' => $x_paye[$my_paye_rate]['dtype'][$id], 'ddate_start' => $x_paye[$my_paye_rate]['ddate_start'][$id], 'ddate_end' => $x_paye[$my_paye_rate]['ddate_end'][$id], 'totalht' => price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), 'vat' => $x_paye[$my_paye_rate]['vat_list'][$id], 'link' => $invoice_supplier->getNomUrl(1, '', 12));
     }
 }
 //now we have an array (x_both) indexed by rates for coll and paye
 //print table headers for this quadri - incomes first
 $x_coll_sum = 0;
 $x_coll_ht = 0;
 $x_paye_sum = 0;
 $x_paye_ht = 0;
 $span = 3;
 if ($modetax == 0) {
     $span += 2;
 }
 //print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
 // Customers invoices
 print '<tr class="liste_titre">';
Ejemplo n.º 2
0
     print '<td align="right">' . $langs->trans("AmountHT") . '</td>';
 }
 print '<td align="right">' . $langs->trans("AmountTTC") . '</td>';
 print '<td align="right">' . $langs->trans("Paid") . '</td>';
 print '<td width="16">&nbsp;</td>';
 print "</tr>\n";
 $societestatic = new Societe($db);
 if ($num) {
     $i = 0;
     $total = $total_ttc = $totalam = 0;
     while ($i < $num) {
         $obj = $db->fetch_object($resql);
         print '<tr ' . $bc[$var] . '><td>';
         $facstatic->ref = $obj->ref;
         $facstatic->id = $obj->rowid;
         print $facstatic->getNomUrl(1, '');
         print '</td>';
         $societestatic->id = $obj->socid;
         $societestatic->nom = $obj->nom;
         $societestatic->client = 0;
         print '<td>' . $societestatic->getNomUrl(1, 'supplier', 44) . '</td>';
         if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
             print '<td align="right">' . price($obj->total_ht) . '</td>';
         }
         print '<td align="right">' . price($obj->total_ttc) . '</td>';
         print '<td align="right">' . price($obj->am) . '</td>';
         print '<td>' . $facstatic->LibStatut($obj->paye, $obj->fk_statut, 3) . '</td>';
         print '</tr>';
         $total += $obj->total_ht;
         $total_ttc += $obj->total_ttc;
         $totalam += $obj->am;
Ejemplo n.º 3
0
			$total_ttc=0;
			$total_paid=0;

			while ($i < $num)
			{
				$objp = $db->fetch_object($result);

				$var=!$var;

				print "<tr $bc[$var]>";
				$classname = "impayee";

				print '<td nowrap>';
				$facturestatic->id=$objp->facid;
				$facturestatic->ref=$objp->ref;
				print $facturestatic->getNomUrl(1);
				print "</td>\n";

				print "<td nowrap>".dol_trunc($objp->facnumber,12)."</td>\n";

				print "<td nowrap align=\"center\">".dol_print_date($db->jdate($objp->df))."</td>\n";
				print "<td nowrap align=\"center\">".dol_print_date($db->jdate($objp->datelimite));
				if ($db->jdate($objp->datelimite) < ($now - $conf->facture->fournisseur->warning_delay) && ! $objp->paye && $objp->fk_statut == 1) print img_warning($langs->trans("Late"));
				print "</td>\n";

				print '<td>';
				$companystatic->id=$objp->socid;
				$companystatic->nom=$objp->nom;
				print $companystatic->getNomUrl(1,'supplier',32);
				print '</td>';
Ejemplo n.º 4
0
     foreach ($facidavoir as $id) {
         if ($i == 0) {
             print ' ';
         } else {
             print ',';
         }
         $facavoir = new FactureFournisseur($db);
         $facavoir->fetch($id);
         print $facavoir->getNomUrl(1);
     }
     print ')';
 }
 if (isset($facidnext) && $facidnext > 0) {
     $facthatreplace = new FactureFournisseur($db);
     $facthatreplace->fetch($facidnext);
     print ' (' . $langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)) . ')';
 }
 print '</td></tr>';
 // Label
 print '<tr><td>' . $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->fournisseur->facture->creer) . '</td>';
 print '<td colspan="3">' . $form->editfieldval("Label", 'label', $object->label, $object, $user->rights->fournisseur->facture->creer) . '</td>';
 /*
  * List of payments
  */
 $nbrows = 9;
 $nbcols = 2;
 if (!empty($conf->projet->enabled)) {
     $nbrows++;
 }
 if (!empty($conf->banque->enabled)) {
     $nbrows++;
Ejemplo n.º 5
0
 while ($i < $num) {
     $paiement = '';
     $ref = '';
     $refcomp = '';
     //$obj = $db->fetch_object($result);
     $obj = array_shift($tab_sqlobj);
     if ($obj->family == 'invoice_supplier') {
         $showline = 1;
         // Uncomment this line to avoid to count suppliers credit note (ff.type = 2)
         //$showline=(($obj->total_ttc < 0 && $obj->type != 2) || ($obj->total_ttc > 0 && $obj->type == 2))
         if ($showline) {
             $ref = $obj->ref;
             $facturefournstatic->ref = $ref;
             $facturefournstatic->id = $obj->objid;
             $facturefournstatic->type = $obj->type;
             $ref = $facturefournstatic->getNomUrl(1, '');
             $societestatic->id = $obj->socid;
             $societestatic->name = $obj->name;
             $refcomp = $societestatic->getNomUrl(1, '', 24);
             $paiement = -1 * $facturefournstatic->getSommePaiement();
             // Payment already done
         }
     }
     if ($obj->family == 'invoice') {
         $facturestatic->ref = $obj->ref;
         $facturestatic->id = $obj->objid;
         $facturestatic->type = $obj->type;
         $ref = $facturestatic->getNomUrl(1, '');
         $societestatic->id = $obj->socid;
         $societestatic->name = $obj->name;
         $refcomp = $societestatic->getNomUrl(1, '', 24);
Ejemplo n.º 6
0
     $facusing->fetch($object->fk_facture_source);
     print ' (' . $langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)) . ')';
 }
 $facidavoir = $object->getListIdAvoirFromInvoice();
 if (count($facidavoir) > 0) {
     print ' (' . $langs->transnoentities("InvoiceHasAvoir");
     $i = 0;
     foreach ($facidavoir as $id) {
         if ($i == 0) {
             print ' ';
         } else {
             print ',';
         }
         $facavoir = new FactureFournisseur($db);
         $facavoir->fetch($id);
         print $facavoir->getNomUrl(1);
     }
     print ')';
 }
 // FIXME $facidnext is not defined
 /*
 if ($facidnext > 0)
 {
 	$facthatreplace=new FactureFournisseur($db);
 	$facthatreplace->fetch($facidnext);
 	print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
 }
 */
 print '</td></tr>';
 // Label
 print '<tr><td>' . $form->editfieldkey("Label", 'label', $object->label, $object, 0) . '</td><td colspan="3">';
Ejemplo n.º 7
0
 $result = $db->query($sql);
 if ($result) {
     $num_lines = $db->num_rows($result);
     $i = 0;
     if ($num_lines) {
         $objp = $db->fetch_object($result);
         print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '" method="post">' . "\n";
         print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
         print '<input type="hidden" name="action" value="ventil">';
         print_fiche_titre($langs->trans("SuppliersVentilation"));
         print '<table class="border" width="100%" cellspacing="0" cellpadding="4">';
         // ref invoice
         print '<tr><td>' . $langs->trans("BillsSuppliers") . '</td>';
         $facturefournisseur_static->ref = $objp->facnumber;
         $facturefournisseur_static->id = $objp->facid;
         print '<td>' . $facturefournisseur_static->getNomUrl(1) . '</td>';
         print '</tr>';
         print '<tr><td width="20%">Ligne</td>';
         print '<td>' . stripslashes(nl2br($objp->description)) . '</td></tr>';
         print '<tr><td width="20%">' . $langs->trans("ProductLabel") . '</td>';
         print '<td>' . dol_trunc($objp->product_label, 24) . '</td>';
         print '<tr><td width="20%">' . $langs->trans("Account") . '</td><td>';
         print $objp->account_number . '-' . $objp->label;
         print '<tr><td width="20%">' . $langs->trans("NewAccount") . '</td><td>';
         print $formventilation->select_account($objp->fk_code_ventilation, 'codeventil', 1);
         print '</td></tr>';
         print '<tr><td>&nbsp;</td><td><input type="submit" class="button" value="' . $langs->trans("Update") . '"></td></tr>';
         print '</table>';
         print '</form>';
     } else {
         print "Error 1";
Ejemplo n.º 8
0
     print_liste_field_titre($langs->trans("SupplierCode"), $_SERVER["PHP_SELF"], "s.code_client", "", "&amp;id=" . $product->id, '', $sortfield, $sortorder);
     print_liste_field_titre($langs->trans("DateInvoice"), $_SERVER["PHP_SELF"], "f.datef", "", "&amp;id=" . $product->id, 'align="center"', $sortfield, $sortorder);
     print_liste_field_titre($langs->trans("Qty"), $_SERVER["PHP_SELF"], "d.qty", "", "&amp;id=" . $product->id, 'align="center"', $sortfield, $sortorder);
     print_liste_field_titre($langs->trans("AmountHT"), $_SERVER["PHP_SELF"], "f.total_ht", "", "&amp;id=" . $product->id, 'align="right"', $sortfield, $sortorder);
     print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", "&amp;id=" . $product->id, 'align="right"', $sortfield, $sortorder);
     print "</tr>\n";
     if ($num > 0) {
         $var = True;
         while ($i < $num && $conf->liste_limit) {
             $objp = $db->fetch_object($result);
             $var = !$var;
             print "<tr " . $bc[$var] . ">";
             print '<td>';
             $supplierinvoicestatic->id = $objp->facid;
             $supplierinvoicestatic->ref = $objp->facnumber;
             print $supplierinvoicestatic->getNomUrl(1);
             print "</td>\n";
             print '<td><a href="' . DOL_URL_ROOT . '/fourn/card.php?socid=' . $objp->socid . '">' . img_object($langs->trans("ShowCompany"), "company") . ' ' . dol_trunc($objp->name, 44) . '</a></td>';
             print "<td>" . $objp->code_client . "</td>\n";
             print "<td align=\"center\">";
             print dol_print_date($db->jdate($objp->datef)) . "</td>";
             print "<td align=\"center\">" . $objp->qty . "</td>\n";
             print "<td align=\"right\">" . price($objp->total_ht) . "</td>\n";
             print '<td align="right">' . $supplierinvoicestatic->LibStatut($objp->paye, $objp->statut, 5) . '</td>';
             print "</tr>\n";
             $i++;
         }
     }
 } else {
     dol_print_error($db);
 }
Ejemplo n.º 9
0
print "</tr>\n";
$var = true;
$r = '';
$invoicestatic = new FactureFournisseur($db);
$companystatic = new Fournisseur($db);
foreach ($tabfac as $key => $val) {
    $invoicestatic->id = $key;
    $invoicestatic->ref = $val["ref"];
    $invoicestatic->type = $val["type"];
    // product
    foreach ($tabht[$key] as $k => $mt) {
        if ($mt) {
            print "<tr " . $bc[$var] . " >";
            //print "<td>".$conf->global->COMPTA_JOURNAL_BUY."</td>";
            print "<td>" . $val["date"] . "</td>";
            print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
            print "<td>" . $k . "</td><td>" . $langs->trans("Products") . "</td>";
            print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
            print '<td align="right">' . ($mt < 0 ? price(-$mt) : '') . "</td>";
            print "</tr>";
        }
    }
    // vat
    //var_dump($tabtva);
    foreach ($tabtva[$key] as $k => $mt) {
        if ($mt) {
            print "<tr " . $bc[$var] . " >";
            //print "<td>".$conf->global->COMPTA_JOURNAL_BUY."</td>";
            print "<td>" . $val["date"] . "</td>";
            print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
            print "<td>" . $k . "</td><td>" . $langs->trans("VAT") . " " . $key . "</td>";
Ejemplo n.º 10
0
 /**
  *  Load data into info_box_contents array to show array later.
  *
  *  @param	int		$max        Maximum number of records to load
  *  @return	void
  */
 function loadBox($max = 5)
 {
     global $conf, $user, $langs, $db;
     $this->max = $max;
     include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
     include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php';
     $facturestatic = new FactureFournisseur($db);
     $thirdpartytmp = new Fournisseur($db);
     $this->info_box_head = array('text' => $langs->trans("BoxTitleLast" . ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE ? "" : "Modified") . "SupplierBills", $max));
     if ($user->rights->fournisseur->facture->lire) {
         $sql = "SELECT s.nom as name, s.rowid as socid,";
         $sql .= " s.code_fournisseur,";
         $sql .= " s.logo,";
         $sql .= " f.rowid as facid, f.ref, f.ref_supplier,";
         $sql .= " f.total_ht,";
         $sql .= " f.total_tva,";
         $sql .= " f.total_ttc,";
         $sql .= " f.paye, f.fk_statut,";
         $sql .= ' f.datef as df,';
         $sql .= ' f.datec as datec,';
         $sql .= ' f.date_lim_reglement as datelimite, f.tms, f.type';
         $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
         $sql .= ", " . MAIN_DB_PREFIX . "facture_fourn as f";
         if (!$user->rights->societe->client->voir && !$user->societe_id) {
             $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
         }
         $sql .= " WHERE f.fk_soc = s.rowid";
         $sql .= " AND f.entity = " . $conf->entity;
         if (!$user->rights->societe->client->voir && !$user->societe_id) {
             $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $user->societe_id;
         }
         if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) {
             $sql .= " ORDER BY f.datef DESC, f.ref DESC ";
         } else {
             $sql .= " ORDER BY f.tms DESC, f.ref DESC ";
         }
         $sql .= $db->plimit($max, 0);
         $result = $db->query($sql);
         if ($result) {
             $num = $db->num_rows($result);
             $now = dol_now();
             $line = 0;
             $l_due_date = $langs->trans('Late') . ' (' . $langs->trans('DateEcheance') . ': %s)';
             while ($line < $num) {
                 $objp = $db->fetch_object($result);
                 $datelimite = $db->jdate($objp->datelimite);
                 $date = $db->jdate($objp->df);
                 $datem = $db->jdate($objp->tms);
                 $facturestatic->id = $objp->facid;
                 $facturestatic->ref = $objp->ref;
                 $facturestatic->total_ht = $objp->total_ht;
                 $facturestatic->total_tva = $objp->total_tva;
                 $facturestatic->total_ttc = $objp->total_ttc;
                 $thirdpartytmp->id = $objp->socid;
                 $thirdpartytmp->name = $objp->name;
                 $thirdpartytmp->fournisseur = 1;
                 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
                 $thirdpartytmp->logo = $objp->logo;
                 $late = '';
                 if ($objp->paye == 0 && $datelimite && $datelimite < $now - $conf->facture->fournisseur->warning_delay) {
                     $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day')));
                 }
                 $this->info_box_contents[$line][] = array('td' => 'align="left"', 'text' => $facturestatic->getNomUrl(1), 'text2' => $late, 'asis' => 1);
                 $this->info_box_contents[$line][] = array('td' => 'align="left"', 'text' => $objp->ref_supplier, 'tooltip' => $langs->trans('SupplierInvoice') . ': ' . ($objp->ref ? $objp->ref : $objp->facid) . '<br>' . $langs->trans('RefSupplier') . ': ' . $objp->ref_supplier, 'url' => DOL_URL_ROOT . "/fourn/facture/card.php?facid=" . $objp->facid);
                 $this->info_box_contents[$line][] = array('td' => 'align="left"', 'text' => $thirdpartytmp->getNomUrl(1, 'supplier'), 'asis' => 1);
                 $this->info_box_contents[$line][] = array('td' => 'align="right"', 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency));
                 $this->info_box_contents[$line][] = array('td' => 'align="right"', 'text' => dol_print_date($date, 'day'));
                 $fac = new FactureFournisseur($db);
                 $fac->fetch($objp->facid);
                 $alreadypaid = $fac->getSommePaiement();
                 $this->info_box_contents[$line][] = array('td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut($objp->paye, $objp->fk_statut, 3, $alreadypaid, $objp->type));
                 $line++;
             }
             if ($num == 0) {
                 $this->info_box_contents[$line][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoModifiedSupplierBills"));
             }
             $db->free($result);
         } else {
             $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql);
         }
     } else {
         $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->transnoentities("ReadPermissionNotAllowed"));
     }
 }
 function get_origin($fk_origin, $origintype)
 {
     switch ($origintype) {
         case 'commande':
             require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
             $origin = new Commande($this->db);
             break;
         case 'shipping':
             require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
             $origin = new Expedition($this->db);
             break;
         case 'facture':
             require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
             $origin = new Facture($this->db);
             break;
         case 'order_supplier':
             require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
             $origin = new CommandeFournisseur($this->db);
             break;
         case 'invoice_supplier':
             require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
             $origin = new FactureFournisseur($this->db);
             break;
         default:
             return '';
             break;
     }
     $origin->fetch($fk_origin);
     return $origin->getNomUrl(1);
 }
Ejemplo n.º 12
0
 print '<td align="right">' . $langs->trans('AlreadyPaid') . '</td>';
 print '<td align="right">' . $langs->trans('RemainderToPay') . '</td>';
 print '<td align="center">' . $langs->trans('Amount') . '</td>';
 print '</tr>';
 $var = True;
 $total = 0;
 $total_ttc = 0;
 $totalrecu = 0;
 while ($i < $num) {
     $objp = $db->fetch_object($resql);
     $var = !$var;
     print '<tr ' . $bc[$var] . '>';
     print '<td>';
     $invoicesupplierstatic->ref = $objp->ref;
     $invoicesupplierstatic->id = $objp->facid;
     print $invoicesupplierstatic->getNomUrl(1);
     print '</td>';
     print '<td>' . $objp->ref_supplier . '</td>';
     if ($objp->df > 0) {
         print '<td align="center">';
         print dol_print_date($db->jdate($objp->df), 'day') . '</td>';
     } else {
         print '<td align="center"><b>!!!</b></td>';
     }
     print '<td align="right">' . price($objp->total_ttc) . '</td>';
     print '<td align="right">' . price($objp->am) . '</td>';
     print '<td align="right">' . price($objp->total_ttc - $objp->am) . '</td>';
     print '<td align="center">';
     $namef = 'amount_' . $objp->facid;
     if (!empty($conf->global->FAC_AUTO_FILLJS)) {
         print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='" . $namef . "' data-value='" . ($objp->total_ttc - $objp->am) . "'");
Ejemplo n.º 13
0
			$x_both[$my_paye_rate]['paye']['detail'][] = array(
				'id'        =>$x_paye[$my_paye_rate]['facid'][$id],
				'descr'     =>$x_paye[$my_paye_rate]['descr'][$id],
				'pid'       =>$x_paye[$my_paye_rate]['pid'][$id],
				'pref'      =>$x_paye[$my_paye_rate]['pref'][$id],
				'ptype'     =>$x_paye[$my_paye_rate]['ptype'][$id],
				'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
				'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
				'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
				'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
				'dtype'     =>$x_paye[$my_paye_rate]['dtype'][$id],
				'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
				'ddate_end'  =>$x_paye[$my_paye_rate]['ddate_end'][$id],
				'totalht'   =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
				'vat'       =>$x_paye[$my_paye_rate]['vat_list'][$id],
				'link'      =>$invoice_supplier->getNomUrl(1,'',12));
		}
	}
	//now we have an array (x_both) indexed by rates for coll and paye


	//print table headers for this quadri - incomes first

	$x_coll_sum = 0;
	$x_coll_ht = 0;
	$x_paye_sum = 0;
	$x_paye_ht = 0;

	$span=3;
	if ($modetax == 0) $span+=2;
Ejemplo n.º 14
0
    /**
     *      Show list of documents in a directory
     *      @param      upload_dir          Directory that was scanned
     *      @param      filearray           Array of files loaded by dol_dir_list function before calling this function
     *      @param      modulepart          Value for modulepart used by download wrapper
     *      @param      param               Parameters on sort links
     *      @param      forcedownload       Force to open dialog box "Save As" when clicking on file
     *      @param      relativepath        Relative path of docs (autodefined if not provided)
     *      @param      permtodelete        Permission to delete
     *      @param      useinecm            Change output for use in ecm module
     *      @param      textifempty         Text to show if filearray is empty
     *      @param      maxlength           Maximum length of file name shown
     *      @return     int                 <0 if KO, nb of files shown if OK
     */
    function list_of_autoecmfiles($upload_dir,$filearray,$modulepart,$param,$forcedownload=0,$relativepath='',$permtodelete=1,$useinecm=0,$textifempty='',$maxlength=0)
    {
        global $user, $conf, $langs;
        global $bc;
        global $sortfield, $sortorder;

        // Affiche liste des documents existant
        if (empty($useinecm)) print_titre($langs->trans("AttachedFiles"));
        //else { $bc[true]=''; $bc[false]=''; };
        $url=$_SERVER["PHP_SELF"];
        print '<table width="100%" class="nobordernopadding">';
        print '<tr class="liste_titre">';
        print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"","",$param,'align="left"',$sortfield,$sortorder);
        print_liste_field_titre($langs->trans("Documents2"),$_SERVER["PHP_SELF"],"name","",$param,'align="left"',$sortfield,$sortorder);
        print_liste_field_titre($langs->trans("Size"),$_SERVER["PHP_SELF"],"size","",$param,'align="right"',$sortfield,$sortorder);
        print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"date","",$param,'align="center"',$sortfield,$sortorder);
        print_liste_field_titre('','','');
        print '</tr>';

        if ($modulepart == 'invoice')
        {
            include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
            $object_static=new Facture($this->db);
        }
        if ($modulepart == 'invoice_supplier')
        {
            include_once(DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php');
            $object_static=new FactureFournisseur($this->db);
        }

        $var=true;
        foreach($filearray as $key => $file)
        {
            if (!is_dir($file['name'])
            && $file['name'] != '.'
            && $file['name'] != '..'
            && $file['name'] != 'CVS'
            && ! preg_match('/\.meta$/i',$file['name']))
            {
                // Define relative path used to store the file
                $relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
                //print 'eeee'.$relativefile;
                //var_dump($file);
                $var=!$var;
                print '<tr '.$bc[$var].'>';
                print '<td>';
                $id='';$ref='';
                if ($modulepart == 'invoice')
                {
                    preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);
                    $ref=$reg[1];
                    $object_static->fetch('',$ref);
                    //print $relativefile.'rr'.$id;
                    print $object_static->getNomUrl(1,'document');
                }
                if ($modulepart == 'invoice_supplier')
                {
                    preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg);
                    $id=$reg[1];
                    $object_static->fetch($id);
                    //print $relativefile.'rr'.$id;
                    print $object_static->getNomUrl(1,'document');
                }
                print '</td>';
                print '<td>';
                //print "XX".$file['name']; //$file['name'] must be utf8
                print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
                if ($forcedownload) print '&attachment=1';
                print '&file='.urlencode($relativefile).'">';
                print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')').' ';
                print dol_trunc($file['name'],$maxlength,'middle');
                print '</a>';
                print "</td>\n";
                print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
                print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>';
                print '<td align="right">';
                if (! empty($useinecm))  print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
                if ($forcedownload) print '&attachment=1';
                print '&file='.urlencode($relativefile).'">';
                print img_view().'</a> &nbsp; ';
                //if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
                //else print '&nbsp;';
                print "</td></tr>\n";
            }
        }
        if (sizeof($filearray) == 0)
        {
            print '<tr '.$bc[$var].'><td colspan="4">';
            if (empty($textifempty)) print $langs->trans("NoFileFound");
            else print $textifempty;
            print '</td></tr>';
        }
        print "</table>";
        // Fin de zone
    }