Ajout possibilité de mettre des documents sur les factures

This commit is contained in:
Laurent Destailleur 2006-06-07 22:18:30 +00:00
parent 4aa4b5682d
commit d3ad176b82
4 changed files with 70 additions and 65 deletions

View File

@ -225,7 +225,7 @@ if ($id > 0)
$head = facture_prepare_head($facture); $head = facture_prepare_head($facture);
dolibarr_fiche_head($head, 1, $langs->trans('InvoiceCustomer')); dolibarr_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer'));
/* /*
* Facture synthese pour rappel * Facture synthese pour rappel

View File

@ -43,13 +43,12 @@ llxHeader();
$fac = new Facture($db); $fac = new Facture($db);
$fac->fetch($_GET["facid"]); $fac->fetch($_GET["facid"]);
$fac->info($_GET["facid"]); $fac->info($_GET["facid"]);
$soc = new Societe($db, $fac->socidp); $soc = new Societe($db, $fac->socidp);
$soc->fetch($fac->socidp); $soc->fetch($fac->socidp);
$head = facture_prepare_head($fac); $head = facture_prepare_head($fac);
$hselected = 3; dolibarr_fiche_head($head, 'info', $langs->trans("InvoiceCustomer"));
if ($conf->use_preview_tabs) $hselected++;
if ($fac->mode_reglement_code == 'PRE') $hselected++;
dolibarr_fiche_head($head, $hselected, $langs->trans("InvoiceCustomer"));
print '<table width="100%"><tr><td>'; print '<table width="100%"><tr><td>';

View File

@ -792,79 +792,74 @@ class Facture
if ($resql) if ($resql)
{ {
$this->facnumber=$numfa; $this->facnumber=$numfa;
dolibarr_syslog("Facture::set_valid() sql=$sql");
} }
else else
{ {
dolibarr_syslog("Facture::set_valid() Echec update - 10"); dolibarr_syslog("Facture::set_valid() Echec update - 10 - sql=$sql");
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
$error++; $error++;
} }
/* // On renomme repertoire facture ($this->ref = ancienne ref, $numfa = nouvelle ref)
* Lit les avoirs / remises absolues en cours et les décrémente // afin de ne pas perdre les fichiers attachés
*/ $facref = sanitize_string($this->ref);
$remise_a_decrementee=$this->remise_absolue; $dirsource = $conf->facture->dir_output.'/'.$facref;
if ($remise_a_decrementee) $dirdest = $conf->facture->dir_output.'/'.$numfa;
dolibarr_syslog("Facture::set_valid() renommage rep ".$dirsource." en ".$dirdest);
if (rename($dirsource, $dirdest))
{ {
$sql = 'SELECT rowid, fk_soc, datec, rc.amount_ht as amount, fk_user, description'; dolibarr_syslog("Renommage ok");
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc'; // Suppression ancien fichier PDF dans nouveau rep
$sql.= ' WHERE rc.fk_soc ='. $this->socidp; dol_delete_file($conf->facture->dir_output.'/'.$numfa.'/'.$facref.'.*');
$sql.= ' AND fk_facture IS NULL'; }
$sql.= ' ORDER BY datec';
$resql = $this->db->query($sql) ;
if ($resql) /*
* Tope les lignes de remises fixes avec id des lignes de facture au montant négatif
*/
/* TODO Toper les lignes de remises fixes avec id des lignes de facture au montant négatif.
while ($i < $nurmx && $remise_a_decrementee && ! $error)
{ {
$nurmx = $this->db->num_rows($resql); $obj = $this->db->fetch_object($resql);
if ($nurmx > 0) $avoir=$obj->amount;
// On met à jour avoir comme affecté à facture
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' SET fk_facture = '.$this->id.',';
$sql.= " amount_ht = '".price2num(min($remise_a_decrementee,$avoir))."'";
$sql.= ' WHERE rowid ='.$obj->rowid;
dolibarr_syslog("Societe::set_valid Mise a jour avoir sql=$sql");
if (! $this->db->query($sql))
{ {
$i=0; $error++;
while ($i < $nurmx && $remise_a_decrementee && ! $error) }
if ($remise_a_decrementee < $avoir)
{
// L'avoir n'a pas été complètement consommée, on insère ligne du reste
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' (fk_soc, datec, amount_ht, fk_user, fk_facture, description) ';
$sql.= ' VALUES ';
$sql.= ' ('.$this->socidp;
$sql.= ' ,'.$obj->datec;
$sql.= " ,'".price2num($avoir - $remise_a_decrementee)."'";
$sql.= ' ,'.$user->id;
$sql.= ' ,null';
$sql.= " ,'".addslashes($obj->description)."'";
$sql.= ')';
if (! $this->db->query( $sql))
{ {
$obj = $this->db->fetch_object($resql); $error++;
$avoir=$obj->amount;
// On met à jour avoir comme affecté à facture
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' SET fk_facture = '.$this->id.',';
$sql.= " amount_ht = '".price2num(min($remise_a_decrementee,$avoir))."'";
$sql.= ' WHERE rowid ='.$obj->rowid;
dolibarr_syslog("Societe::set_valid Mise a jour avoir sql=$sql");
if (! $this->db->query($sql))
{
$error++;
}
if ($remise_a_decrementee < $avoir)
{
// L'avoir n'a pas été complètement consommée, on insère ligne du reste
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' (fk_soc, datec, amount_ht, fk_user, fk_facture, description) ';
$sql.= ' VALUES ';
$sql.= ' ('.$this->socidp;
$sql.= ' ,'.$obj->datec;
$sql.= " ,'".price2num($avoir - $remise_a_decrementee)."'";
$sql.= ' ,'.$user->id;
$sql.= ' ,null';
$sql.= " ,'".addslashes($obj->description)."'";
$sql.= ')';
if (! $this->db->query( $sql))
{
$error++;
}
}
$remise_a_decrementee-=min($remise_a_decrementee,$avoir);
$i++;
} }
} }
$this->db->free($resql);
$remise_a_decrementee-=min($remise_a_decrementee,$avoir);
$i++;
} }
else */
{
dolibarr_syslog('Facture::set_valid() Erreur lecture Remise');
$error++;
}
}
/* /*

View File

@ -36,17 +36,19 @@ function facture_prepare_head($fac)
$head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id;
$head[$h][1] = $langs->trans('CardBill'); $head[$h][1] = $langs->trans('CardBill');
$hselected = $h; $head[$h][2] = 'compta';
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/contact.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/contact.php?facid='.$fac->id;
$head[$h][1] = $langs->trans('BillContacts'); $head[$h][1] = $langs->trans('BillContacts');
$head[$h][2] = 'contact';
$h++; $h++;
if ($conf->use_preview_tabs) if ($conf->use_preview_tabs)
{ {
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id;
$head[$h][1] = $langs->trans('Preview'); $head[$h][1] = $langs->trans('Preview');
$head[$h][2] = 'preview';
$h++; $h++;
} }
@ -54,14 +56,23 @@ function facture_prepare_head($fac)
{ {
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id;
$head[$h][1] = $langs->trans('StandingOrders'); $head[$h][1] = $langs->trans('StandingOrders');
$head[$h][2] = 'standingorders';
$h++; $h++;
} }
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id;
$head[$h][1] = $langs->trans('Note'); $head[$h][1] = $langs->trans('Note');
$head[$h][2] = 'note';
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/document.php?facid='.$fac->id;
$head[$h][1] = $langs->trans('Documents');
$head[$h][2] = 'documents';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id;
$head[$h][1] = $langs->trans('Info'); $head[$h][1] = $langs->trans('Info');
$head[$h][2] = 'info';
$h++; $h++;
return $head; return $head;