*** empty log message ***

This commit is contained in:
Rodolphe Quiedeville 2002-12-14 16:25:46 +00:00
parent 6e44bde3ef
commit 93050f7deb
3 changed files with 364 additions and 237 deletions

View File

@ -29,35 +29,32 @@ $db = new Db();
$yn[1] = "oui"; $yn[1] = "oui";
$yn[0] = "<b>non</b>"; $yn[0] = "<b>non</b>";
if ($action == 'valid') { if ($action == 'valid')
$sql = "UPDATE llx_facture set fk_statut = 1 WHERE rowid = $facid ;"; {
$result = $db->query( $sql); $fac = new Facture($db);
$result = $fac->set_valid($facid, $user->id);
} }
if ($action == 'payed') { if ($action == 'payed')
$sql = "UPDATE llx_facture set paye = 1 WHERE rowid = $facid ;"; {
$result = $db->query( $sql); $fac = new Facture($db);
$result = $fac->set_payed($facid);
} }
if ($action == 'delete') { if ($action == 'delete')
$sql = "DELETE FROM llx_facture WHERE rowid = $facid;"; {
if ( $db->query( $sql) ) { $fac = new Facture($db);
$sql = "DELETE FROM llx_fa_pr WHERE fk_facture = $facid;"; $fac->delete($facid);
if (! $db->query( $sql) ) {
print $db->error();
}
} else {
print $db->error();
}
$facid = 0 ; $facid = 0 ;
} }
if ($action == 'add')
if ($action == 'add') { {
$datefacture = $db->idate(mktime(12, 0 , 0, $pmonth, $pday, $pyear)); $datefacture = $db->idate(mktime(12, 0 , 0, $pmonth, $pday, $pyear));
if (! $propalid) { if (! $propalid)
{
$facture = new Facture($db, $socid); $facture = new Facture($db, $socid);
$facture->number = $facnumber; $facture->number = $facnumber;
@ -69,25 +66,21 @@ if ($action == 'add') {
$facture->create($user->id, $statut, $note); $facture->create($user->id, $statut, $note);
} else { }
else
{
$sql = "INSERT INTO llx_facture (facnumber, fk_soc, datec, datef, note, amount, remise, tva, total, author) "; $facture = new Facture($db, $socid);
$sql .= " VALUES ('$facnumber', $socid, now(), $datefacture,'$note', $amount, $remise, $tva, $total, '$author');";
$result = $db->query($sql);
if ($result) { $facture->number = $facnumber;
$facture->date = $datefacture;
$sql = "SELECT rowid, facnumber FROM llx_facture WHERE facnumber='$facnumber';"; $facture->note = $note;
$result = $db->query($sql); $facture->amount = $amount;
if ($result) { $facture->remise = $remise;
$objfac = $db->fetch_object( 0); $facture->propalid = $propalid;
$facid = $objfac->rowid;
$facnumber = $objfac->facnumber;
$action = '';
$sql = "INSERT INTO llx_fa_pr (fk_facture,fk_propal) VALUES ($facid, $propalid);";
$result = $db->query($sql);
if ($facture->create($user->id) )
{
/* /*
* *
@ -104,7 +97,8 @@ if ($action == 'add') {
// print "<p>command : $command<br>"; // print "<p>command : $command<br>";
} }
} else { else
{
print "<p><b>Erreur : la facture n'a pas été créée, vérifier le numéro !</b>"; print "<p><b>Erreur : la facture n'a pas été créée, vérifier le numéro !</b>";
print "<p>Retour à la <a href=\"propal.php3?propalid=$propalid\">propal</a>"; print "<p>Retour à la <a href=\"propal.php3?propalid=$propalid\">propal</a>";
print $db->error(); print $db->error();
@ -122,10 +116,12 @@ if ($action == 'add') {
* *
*/ */
if ($action == 'create') { if ($action == 'create')
{
print_titre("Emettre une facture"); print_titre("Emettre une facture");
if ($propalid) { if ($propalid)
{
$sql = "SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.tva, p.total, p.ref, ".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst"; $sql = "SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.tva, p.total, p.ref, ".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst";
$sql .= " FROM societe as s, llx_propal as p, c_propalst as c WHERE p.fk_soc = s.idp AND p.fk_statut = c.id"; $sql .= " FROM societe as s, llx_propal as p, c_propalst as c WHERE p.fk_soc = s.idp AND p.fk_statut = c.id";
@ -139,10 +135,11 @@ if ($action == 'create') {
} }
if ( $db->query($sql) ) { if ( $db->query($sql) )
{
$num = $db->num_rows(); $num = $db->num_rows();
if ($num) { if ($num) {
$obj = $db->fetch_object( 0); $obj = $db->fetch_object(0);
$numfa = "F-" . $obj->prefix_comm . "-" . strftime("%y%m%d", time()); $numfa = "F-" . $obj->prefix_comm . "-" . strftime("%y%m%d", time());
@ -154,7 +151,8 @@ if ($action == 'create') {
print "<tr bgcolor=\"#e0e0e0\"><td>Société :</td><td>$obj->nom</td></tr>"; print "<tr bgcolor=\"#e0e0e0\"><td>Société :</td><td>$obj->nom</td></tr>";
if ($propalid) { if ($propalid)
{
$amount = ($obj->price - $obj->remise); $amount = ($obj->price - $obj->remise);
print '<input type="hidden" name="amount" value="'.$amount.'">'; print '<input type="hidden" name="amount" value="'.$amount.'">';
print '<input type="hidden" name="total" value="'.$obj->total.'">'; print '<input type="hidden" name="total" value="'.$obj->total.'">';
@ -163,50 +161,51 @@ if ($action == 'create') {
print '<input type="hidden" name="propalid" value="'.$propalid.'">'; print '<input type="hidden" name="propalid" value="'.$propalid.'">';
print "<tr><td>Propal :</td><td>$obj->ref</td></tr>"; print "<tr><td>Propal :</td><td>$obj->ref</td></tr>";
print '<tr bgcolor="#e0e0e0"><td>Montant HT :</td><td align="right">'.price($amount).'</td></tr>'; print '<tr bgcolor="#e0e0e0"><td>Montant HT :</td><td>'.price($amount).'</td></tr>';
print "<tr bgcolor=\"#e0e0e0\"><td>TVA 19.6% :</td><td align=\"right\">".price($obj->tva)."</td></tr>"; print "<tr bgcolor=\"#e0e0e0\"><td>TVA 19.6% :</td><td>".price($obj->tva)."</td></tr>";
print "<tr bgcolor=\"#e0e0e0\"><td>Total TTC :</td><td align=\"right\">".price($obj->total)."</td></tr>"; print "<tr bgcolor=\"#e0e0e0\"><td>Total TTC :</td><td>".price($obj->total)."</td></tr>";
} else { }
else
{
print '<tr bgcolor="#e0e0e0"><td>Montant HT :</td><td>'; print '<tr bgcolor="#e0e0e0"><td>Montant HT :</td><td>';
print '<input name="amount" type="text" value=""></td></tr>'; print '<input name="amount" type="text" value=""></td></tr>';
print '</td></tr>'; print '</td></tr>';
print '<tr bgcolor="#e0e0e0"><td>Remise :</td><td>'; print '<tr bgcolor="#e0e0e0"><td>Remise :</td><td>';
print '<input name="remise" type="text" value=""></td></tr>'; print '<input name="remise" type="text" value=""></td></tr>';
print '</td></tr>'; print '</td></tr>';
} }
print "<input type=\"hidden\" name=\"author\" value=\"$author\">"; print "<input type=\"hidden\" name=\"author\" value=\"$author\">";
print "<tr><td>Auteur :</td><td>".$user->fullname."</td></tr>"; print "<tr><td>Auteur :</td><td>".$user->fullname."</td></tr>";
$strmonth[1] = "Janvier"; $strmonth[2] = "F&eacute;vrier"; $strmonth[3] = "Mars"; $strmonth[4] = "Avril";
$strmonth[5] = "Mai"; $strmonth[6] = "Juin"; $strmonth[7] = "Juillet"; $strmonth[8] = "Ao&ucirc;t";
$strmonth[9] = "Septembre"; $strmonth[10] = "Octobre";
$strmonth[11] = "Novembre"; $strmonth[12] = "D&eacute;cembre";
print "<tr><td>Date :</td><td>"; print "<tr><td>Date :</td><td>";
$cday = date("d", time()); $cday = date("d", time());
print "<select name=\"pday\">"; print "<select name=\"pday\">";
for ($day = 1 ; $day < $sday + 32 ; $day++) { for ($day = 1 ; $day < $sday + 32 ; $day++)
if ($day == $cday) { {
if ($day == $cday)
{
print "<option value=\"$day\" SELECTED>$day"; print "<option value=\"$day\" SELECTED>$day";
} else { }
else
{
print "<option value=\"$day\">$day"; print "<option value=\"$day\">$day";
} }
} }
print "</select>"; print "</select>";
$cmonth = date("n", time()); $cmonth = date("n", time());
print "<select name=\"pmonth\">"; print "<select name=\"pmonth\">";
for ($month = 1 ; $month <= 12 ; $month++) { for ($month = 1 ; $month <= 12 ; $month++)
if ($month == $cmonth) { {
if ($month == $cmonth)
{
print "<option value=\"$month\" SELECTED>" . $strmonth[$month]; print "<option value=\"$month\" SELECTED>" . $strmonth[$month];
} else { }
else
{
print "<option value=\"$month\">" . $strmonth[$month]; print "<option value=\"$month\">" . $strmonth[$month];
} }
} }
@ -217,7 +216,8 @@ if ($action == 'create') {
print "<option value=\"".($syear-1)."\">".($syear-1); print "<option value=\"".($syear-1)."\">".($syear-1);
print "<option value=\"$syear\" SELECTED>$syear"; print "<option value=\"$syear\" SELECTED>$syear";
for ($year = $syear +1 ; $year < $syear + 5 ; $year++) { for ($year = $syear +1 ; $year < $syear + 5 ; $year++)
{
print "<option value=\"$year\">$year"; print "<option value=\"$year\">$year";
} }
print "</select></td></tr>"; print "</select></td></tr>";
@ -232,30 +232,47 @@ if ($action == 'create') {
print "</table>"; print "</table>";
} }
} else { }
else
{
print $db->error(); print $db->error();
} }
} else { }
else
/* *************************************************************************** */
/* */
/* */
/* */
/* *************************************************************************** */
{
if ($facid > 0) { if ($facid > 0) {
$sql = "SELECT s.nom as socnom, s.idp as socidp, f.facnumber, f.amount, f.total, ".$db->pdate("f.datef")." as df, f.paye, f.fk_statut as statut, f.author, f.note"; $sql = "SELECT s.nom as socnom, s.idp as socidp, f.facnumber, f.amount, f.total, ".$db->pdate("f.datef")." as df, f.paye, f.fk_statut as statut, f.fk_user_author, f.note";
$sql .= " FROM societe as s,llx_facture as f WHERE f.fk_soc = s.idp AND f.rowid = $facid"; $sql .= " FROM societe as s,llx_facture as f WHERE f.fk_soc = s.idp AND f.rowid = $facid";
$result = $db->query( $sql); $result = $db->query( $sql);
if ($result) { if ($result)
{
$num = $db->num_rows(); $num = $db->num_rows();
if ($num) { if ($num)
{
$obj = $db->fetch_object( $i); $obj = $db->fetch_object( $i);
} }
$db->free(); $db->free();
} else { }
else
{
print $db->error(); print $db->error();
} }
$author = new User($db);
$author->id = $obj->fk_user_author;
$author->fetch();
print_titre("Facture : ".$obj->facnumber); print_titre("Facture : ".$obj->facnumber);
print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">"; print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">";
@ -264,17 +281,25 @@ if ($action == 'create') {
* Facture * Facture
*/ */
print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">"; print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">";
print "<tr><td>Société</td><td colspan=\"3\"><b><a href=\"fiche.php3?socid=$obj->socidp\">$obj->socnom</a></b></td></tr>"; print "<tr><td>Société</td>";
print "<td colspan=\"3\">";
print "<b><a href=\"fiche.php3?socid=$obj->socidp\">$obj->socnom</a></b></td></tr>";
print "<tr><td>Date</td><td colspan=\"3\">".strftime("%A %d %B %Y",$obj->df)."</td></tr>\n"; print "<tr><td>Date</td>";
print "<tr><td>".translate("Author")."</td><td colspan=\"3\">$obj->author</td>"; print "<td colspan=\"3\">".strftime("%A %d %B %Y",$obj->df)."</td></tr>\n";
print "<tr><td>".translate("Author")."</td><td colspan=\"3\">$author->fullname</td>";
print '<tr><td>Montant</td><td align="right" colspan="2"><b>'.price($obj->amount).'</b></td><td>euros HT</td></tr>'; print '<tr><td>Montant</td>';
print '<tr><td>TVA</td><td align="right" colspan="2">'.tva($obj->amount).'</td><td>euros</td></tr>'; print '<td align="right" colspan="2"><b>'.price($obj->amount).'</b></td>';
print '<tr><td>Total</td><td align="right" colspan="2">'.price($obj->total).'</td><td>euros TTC</td></tr>'; print '<td>euros HT</td></tr>';
print '<tr><td>TVA</td><td align="right" colspan="2">'.tva($obj->amount).'</td>';
print '<td>euros</td></tr>';
print '<tr><td>Total</td><td align="right" colspan="2">'.price($obj->total).'</td>';
print '<td>euros TTC</td></tr>';
print '<tr><td>Statut</td><td align="center">'.$obj->statut.'</td>'; print '<tr><td>Statut</td><td align="center">'.$obj->statut.'</td>';
print "<td>Paye</td><td align=\"center\" bgcolor=\"#f0f0f0\"><b>".$yn[$obj->paye]."</b></td></tr>"; print "<td>".translate("Payed")."</td>";
print "<td align=\"center\" bgcolor=\"#f0f0f0\"><b>".$yn[$obj->paye]."</b></td></tr>";
print "</table>"; print "</table>";
print "</td><td valign=\"top\">"; print "</td><td valign=\"top\">";
@ -332,25 +357,52 @@ if ($action == 'create') {
print "</table>"; print "</table>";
print "<p><TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\"><tr>"; print "<p><TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\"><tr>";
/*
* Ajouter une ligne
*
*/
if ($obj->statut == 0)
{
if ($obj->statut == 0) { }
print "<td align=\"center\" bgcolor=\"#e0e0e0\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=delete\">Supprimer</a>]</td>"; /*
} else { * Fin Ajout ligne
*
*/
if ($obj->statut == 0)
{
print "<td align=\"center\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=delete\">Supprimer</a>]</td>";
}
else
{
print "<td align=\"center\" width=\"25%\">-</td>"; print "<td align=\"center\" width=\"25%\">-</td>";
} }
if ($obj->statut == 1 && $resteapayer > 0) {
print "<td align=\"center\" bgcolor=\"#e0e0e0\" width=\"25%\">[<a href=\"paiement.php3?facid=$facid&action=create\">Emettre un paiement</a>]</td>"; if ($obj->statut == 1 && $resteapayer > 0)
} else { {
print "<td align=\"center\" width=\"25%\">[<a href=\"paiement.php3?facid=$facid&action=create\">Emettre un paiement</a>]</td>";
}
else
{
print "<td align=\"center\" width=\"25%\">-</td>"; print "<td align=\"center\" width=\"25%\">-</td>";
} }
if ($obj->statut == 1 && abs($resteapayer == 0) && $obj->paye == 0) {
print "<td align=\"center\" bgcolor=\"#e0e0e0\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=payed\">Classer 'Payée'</a>]</td>"; if ($obj->statut == 1 && abs($resteapayer == 0) && $obj->paye == 0)
} else { {
print "<td align=\"center\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=payed\">Classer 'Payée'</a>]</td>";
}
else
{
print "<td align=\"center\" width=\"25%\">-</td>"; print "<td align=\"center\" width=\"25%\">-</td>";
} }
if ($obj->statut == 0) {
if ($obj->statut == 0)
{
print "<td align=\"center\" bgcolor=\"#e0e0e0\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=valid\">Valider</a>]</td>"; print "<td align=\"center\" bgcolor=\"#e0e0e0\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=valid\">Valider</a>]</td>";
} else { }
else
{
print "<td align=\"center\" width=\"25%\"><a href=\"facture.php3?facid=$facid&action=pdf\">Générer la facture</a></td>"; print "<td align=\"center\" width=\"25%\"><a href=\"facture.php3?facid=$facid&action=pdf\">Générer la facture</a></td>";
} }
print "</tr></table><p>"; print "</tr></table><p>";

View File

@ -34,6 +34,7 @@ class Facture {
var $total; var $total;
var $note; var $note;
var $db_table; var $db_table;
var $propalid;
/* /*
* Initialisation * Initialisation
@ -49,6 +50,7 @@ class Facture {
$this->remise = 0; $this->remise = 0;
$this->tva = 0; $this->tva = 0;
$this->total = 0; $this->total = 0;
$this->propalid = 0;
} }
/* /*
* *
@ -56,7 +58,7 @@ class Facture {
* *
*/ */
Function create() { Function create($userid) {
/* /*
* Insertion dans la base * Insertion dans la base
*/ */
@ -65,23 +67,39 @@ class Facture {
$amount = $this->amount; $amount = $this->amount;
$remise = $this->remise; $remise = $this->remise;
if (! $remise) { $remise = 0 ; } if (! $remise) {
$remise = 0 ;
}
$totalht = ($amount - $remise); $totalht = ($amount - $remise);
$tva = tva($totalht); $tva = tva($totalht);
$total = $totalht + $tva; $total = $totalht + $tva;
$sql = "INSERT INTO $this->db_table (facnumber, fk_soc, datec, amount, remise, tva, total, datef, note, fk_user_author) ";
$sql .= " VALUES ('$number', $socid, now(), $totalht, $remise, $tva, $total, $this->date,'$note',$userid);";
$sql = "INSERT INTO $this->db_table (facnumber, fk_soc, datec, datef, note, amount, remise, tva, total) "; if ( $this->db->query($sql) )
$sql .= " VALUES ('$number', $socid, now(), $this->date,'$note', $amount, $remise, $tva, $total);"; {
$this->id = $this->db->last_insert_id();
if ( $this->db->query($sql) ) { $sql = "INSERT INTO llx_fa_pr (fk_facture,fk_propal) VALUES ($this->id, $this->propalid);";
if ( $this->db->query($sql) )
} else { {
print $this->db->error() . '<b><br>'.$sql;
}
return $this->id; return $this->id;
} }
else
{
print $this->db->error() . '<b><br>'.$sql;
return $this->id;
}
}
else
{
print $this->db->error() . '<b><br>'.$sql;
return 0;
}
}
/* /*
* *
@ -124,5 +142,70 @@ class Facture {
} }
} }
/*
* Suppression de la facture
*
*/
Function delete($rowid)
{
$sql = "DELETE FROM llx_facture WHERE rowid = $rowid AND fk_statut = 0;";
if ( $this->db->query( $sql) )
{
if ( $this->db->affected_rows() )
{
$sql = "DELETE FROM llx_fa_pr WHERE fk_facture = $rowid;";
if ($this->db->query( $sql) )
{
return 1;
}
else
{
print "Err : ".$this->db->error();
return 0;
}
}
}
else
{
print "Err : ".$this->db->error();
return 0;
}
}
Function set_payed($rowid)
{
$sql = "UPDATE llx_facture set paye = 1 WHERE rowid = $rowid ;";
$return = $this->db->query( $sql);
}
Function set_valid($rowid, $userid)
{
$sql = "UPDATE llx_facture set fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid ;";
$result = $this->db->query( $sql);
}
/*
*
* Génération du PDF
*
*/
Function pdf()
{
print "<hr><b>Génération du PDF</b><p>";
$command = "export DBI_DSN=\"".$GLOBALS["DBI"]."\" ";
$command .= " ; ../../scripts/facture-tex.pl --facture=$facid --pdf --ps" ;
$output = system($command);
print "<p>command : $command<br>";
}
} }
?> ?>

View File

@ -40,8 +40,6 @@ if ($action == 'add')
$soc->fax = $fax; $soc->fax = $fax;
$soc->url = $url; $soc->url = $url;
$soc->siren = $siren; $soc->siren = $siren;
$soc->client = 1;
$soc->fournisseur = $fournisseur;
$socid = $soc->create(); $socid = $soc->create();
} }
@ -73,7 +71,7 @@ if ($action == 'update')
if ($action == 'create') if ($action == 'create')
{ {
print '<div class="titre">Nouveau client</div><br>'; print '<div class="titre">Nouvelle société</div><br>';
print '<form action="soc.php3" method="post">'; print '<form action="soc.php3" method="post">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="fournisseur" value="0">'; print '<input type="hidden" name="fournisseur" value="0">';
@ -90,13 +88,7 @@ if ($action == 'create')
print '<tr><td>Siren</td><td><input type="text" name="siren"></td></tr>'; print '<tr><td>Siren</td><td><input type="text" name="siren"></td></tr>';
print '<tr><td>Type</td><td><select name="type">';
print '</select>';
print '<tr><td>Effectif</td><td><select name="effectif">';
print '</select>';
print '</td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" value="Ajouter"></td></tr>'; print '<tr><td colspan="2" align="center"><input type="submit" value="Ajouter"></td></tr>';
print '</table>'; print '</table>';