From 93050f7deb3934ee05b6b24323e07aeeef8fef4c Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Sat, 14 Dec 2002 16:25:46 +0000 Subject: [PATCH] *** empty log message *** --- htdocs/compta/facture.php3 | 488 ++++++++++++++++++++----------------- htdocs/facture.class.php3 | 103 +++++++- htdocs/soc.php3 | 10 +- 3 files changed, 364 insertions(+), 237 deletions(-) diff --git a/htdocs/compta/facture.php3 b/htdocs/compta/facture.php3 index beb37b399c1..bda0481f607 100644 --- a/htdocs/compta/facture.php3 +++ b/htdocs/compta/facture.php3 @@ -29,90 +29,84 @@ $db = new Db(); $yn[1] = "oui"; $yn[0] = "non"; -if ($action == 'valid') { - $sql = "UPDATE llx_facture set fk_statut = 1 WHERE rowid = $facid ;"; - $result = $db->query( $sql); +if ($action == 'valid') +{ + $fac = new Facture($db); + $result = $fac->set_valid($facid, $user->id); } -if ($action == 'payed') { - $sql = "UPDATE llx_facture set paye = 1 WHERE rowid = $facid ;"; - $result = $db->query( $sql); +if ($action == 'payed') +{ + $fac = new Facture($db); + $result = $fac->set_payed($facid); } -if ($action == 'delete') { - $sql = "DELETE FROM llx_facture WHERE rowid = $facid;"; - if ( $db->query( $sql) ) { - $sql = "DELETE FROM llx_fa_pr WHERE fk_facture = $facid;"; - if (! $db->query( $sql) ) { - print $db->error(); - } - } else { - print $db->error(); - } +if ($action == 'delete') +{ + $fac = new Facture($db); + $fac->delete($facid); $facid = 0 ; } - -if ($action == 'add') { +if ($action == 'add') +{ $datefacture = $db->idate(mktime(12, 0 , 0, $pmonth, $pday, $pyear)); + + if (! $propalid) + { - if (! $propalid) { - - $facture = new Facture($db, $socid); - $facture->number = $facnumber; - $facture->date = $datefacture; - - $facture->note = $note; - $facture->amount = $amount; - $facture->remise = $remise; - - $facture->create($user->id, $statut, $note); - - } else { - - $sql = "INSERT INTO llx_facture (facnumber, fk_soc, datec, datef, note, amount, remise, tva, total, author) "; - $sql .= " VALUES ('$facnumber', $socid, now(), $datefacture,'$note', $amount, $remise, $tva, $total, '$author');"; - $result = $db->query($sql); - - if ($result) { - - $sql = "SELECT rowid, facnumber FROM llx_facture WHERE facnumber='$facnumber';"; - $result = $db->query($sql); - if ($result) { - $objfac = $db->fetch_object( 0); - $facid = $objfac->rowid; - $facnumber = $objfac->facnumber; - $action = ''; - - $sql = "INSERT INTO llx_fa_pr (fk_facture,fk_propal) VALUES ($facid, $propalid);"; - $result = $db->query($sql); - - - /* - * - * Génération du PDF - * - */ - - // print "
Génération du PDF

"; - - // $command = "export DBI_DSN=\"".$GLOBALS["DBI"]."\" "; - // $command .= " ; ../../scripts/facture-tex.pl --facture=$facid --pdf --ps" ; - - // $output = system($command); - // print "

command : $command
"; + $facture = new Facture($db, $socid); + $facture->number = $facnumber; + $facture->date = $datefacture; - } - } else { - print "

Erreur : la facture n'a pas été créée, vérifier le numéro !"; - print "

Retour à la propal"; - print $db->error(); + $facture->note = $note; + $facture->amount = $amount; + $facture->remise = $remise; + + $facture->create($user->id, $statut, $note); + + } + else + { + + $facture = new Facture($db, $socid); + + $facture->number = $facnumber; + $facture->date = $datefacture; + $facture->note = $note; + $facture->amount = $amount; + $facture->remise = $remise; + $facture->propalid = $propalid; + + if ($facture->create($user->id) ) + { + + /* + * + * Génération du PDF + * + */ + + // print "


Génération du PDF

"; + + // $command = "export DBI_DSN=\"".$GLOBALS["DBI"]."\" "; + // $command .= " ; ../../scripts/facture-tex.pl --facture=$facid --pdf --ps" ; + + // $output = system($command); + // print "

command : $command
"; + + } + else + { + print "

Erreur : la facture n'a pas été créée, vérifier le numéro !"; + print "

Retour à la propal"; + print $db->error(); + } } - } $facid = $facid; $action = ''; - + } /* * @@ -122,139 +116,162 @@ if ($action == 'add') { * */ -if ($action == 'create') { +if ($action == 'create') +{ 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 .= " 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 .= " AND p.rowid = $propalid"; - } else { - - $sql = "SELECT s.nom, s.prefix_comm, s.idp "; - $sql .= "FROM societe as s "; - $sql .= "WHERE s.idp = $socidp"; - - } - - if ( $db->query($sql) ) { - $num = $db->num_rows(); - if ($num) { - $obj = $db->fetch_object( 0); - - $numfa = "F-" . $obj->prefix_comm . "-" . strftime("%y%m%d", time()); - - print "

"; - print ""; - print "idp\">"; - - print ''; - - print ""; - - if ($propalid) { - $amount = ($obj->price - $obj->remise); - print ''; - print ''; - print ''; - print ''; - print ''; - - print ""; - print ''; - print ""; - print ""; - - } else { - - print ''; - - print ''; - - print ''; - print ''; - - - } - - print ""; - print ""; - - $strmonth[1] = "Janvier"; $strmonth[2] = "Février"; $strmonth[3] = "Mars"; $strmonth[4] = "Avril"; - $strmonth[5] = "Mai"; $strmonth[6] = "Juin"; $strmonth[7] = "Juillet"; $strmonth[8] = "Août"; - $strmonth[9] = "Septembre"; $strmonth[10] = "Octobre"; - $strmonth[11] = "Novembre"; $strmonth[12] = "Décembre"; - - print ""; - print ""; - - print ''; - print ''; - - print ""; - print ""; - print "
Société :$obj->nom
Propal :$obj->ref
Montant HT :'.price($amount).'
TVA 19.6% :".price($obj->tva)."
Total TTC :".price($obj->total)."
Montant HT :'; - - print '
Remise :'; - print '
Auteur :".$user->fullname."
Date :"; - $cday = date("d", time()); - print ""; - $cmonth = date("n", time()); - print ""; + $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 .= " AND p.rowid = $propalid"; + } else { + + $sql = "SELECT s.nom, s.prefix_comm, s.idp "; + $sql .= "FROM societe as s "; + $sql .= "WHERE s.idp = $socidp"; - print "
Numéro :
Commentaires :
'; - print '
"; - } - } else { - print $db->error(); - } + + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + if ($num) { + $obj = $db->fetch_object(0); + + $numfa = "F-" . $obj->prefix_comm . "-" . strftime("%y%m%d", time()); + + print "
"; + print ""; + print "idp\">"; + + print ''; + + print ""; + + if ($propalid) + { + $amount = ($obj->price - $obj->remise); + print ''; + print ''; + print ''; + print ''; + print ''; + + print ""; + print ''; + print ""; + print ""; + + } + else + { + + print ''; + print ''; + + print ''; + print ''; + } + + print ""; + print ""; + + print ""; + print ""; + + print ''; + print ''; + + print ""; + print ""; + print "
Société :$obj->nom
Propal :$obj->ref
Montant HT :'.price($amount).'
TVA 19.6% :".price($obj->tva)."
Total TTC :".price($obj->total)."
Montant HT :'; + print '
Remise :'; + print '
Auteur :".$user->fullname."
Date :"; + $cday = date("d", time()); + print ""; + $cmonth = date("n", time()); + print ""; + + print "
Numéro :
Commentaires :
'; + print '
"; + + } + } + else + { + print $db->error(); + } -} else { - +} +else +/* *************************************************************************** */ +/* */ +/* */ +/* */ +/* *************************************************************************** */ +{ + 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"; $result = $db->query( $sql); - if ($result) { - $num = $db->num_rows(); - if ($num) { - $obj = $db->fetch_object( $i); + if ($result) + { + $num = $db->num_rows(); + if ($num) + { + $obj = $db->fetch_object( $i); + } + $db->free(); } - $db->free(); - } else { - print $db->error(); - } + else + { + print $db->error(); + } + + $author = new User($db); + $author->id = $obj->fk_user_author; + $author->fetch(); print_titre("Facture : ".$obj->facnumber); @@ -264,17 +281,25 @@ if ($action == 'create') { * Facture */ print ""; - print ""; + print ""; + print ""; - print "\n"; - print ""; + print ""; + print "\n"; + print ""; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; - print ""; + print ""; + print ""; print "
Sociétésocidp\">$obj->socnom
Société"; + print "socidp\">$obj->socnom
Date".strftime("%A %d %B %Y",$obj->df)."
".translate("Author")."$obj->author
Date".strftime("%A %d %B %Y",$obj->df)."
".translate("Author")."$author->fullname
Montant'.price($obj->amount).'euros HT
TVA'.tva($obj->amount).'euros
Total'.price($obj->total).'euros TTC
Montant'.price($obj->amount).'euros HT
TVA'.tva($obj->amount).'euros
Total'.price($obj->total).'euros TTC
Statut'.$obj->statut.'Paye".$yn[$obj->paye]."
".translate("Payed")."".$yn[$obj->paye]."
"; print ""; @@ -332,27 +357,54 @@ if ($action == 'create') { print ""; print "

"; - - if ($obj->statut == 0) { - print ""; - } else { - print ""; - } - if ($obj->statut == 1 && $resteapayer > 0) { - print ""; - } else { - print ""; - } - if ($obj->statut == 1 && abs($resteapayer == 0) && $obj->paye == 0) { - print ""; - } else { - print ""; - } - if ($obj->statut == 0) { - print ""; - } else { - print ""; - } + /* + * Ajouter une ligne + * + */ + if ($obj->statut == 0) + { + + } + /* + * Fin Ajout ligne + * + */ + + if ($obj->statut == 0) + { + print ""; + } + else + { + print ""; + } + + if ($obj->statut == 1 && $resteapayer > 0) + { + print ""; + } + else + { + print ""; + } + + if ($obj->statut == 1 && abs($resteapayer == 0) && $obj->paye == 0) + { + print ""; + } + else + { + print ""; + } + + if ($obj->statut == 0) + { + print ""; + } + else + { + print ""; + } print "
[Supprimer]-[Emettre un paiement]-[Classer 'Payée']-[Valider]Générer la facture[Supprimer]-[Emettre un paiement]-[Classer 'Payée']-[Valider]Générer la facture

"; /* diff --git a/htdocs/facture.class.php3 b/htdocs/facture.class.php3 index 1c03771efad..c3f057d2348 100644 --- a/htdocs/facture.class.php3 +++ b/htdocs/facture.class.php3 @@ -34,6 +34,7 @@ class Facture { var $total; var $note; var $db_table; + var $propalid; /* * Initialisation @@ -49,6 +50,7 @@ class Facture { $this->remise = 0; $this->tva = 0; $this->total = 0; + $this->propalid = 0; } /* * @@ -56,7 +58,7 @@ class Facture { * */ - Function create() { + Function create($userid) { /* * Insertion dans la base */ @@ -65,22 +67,38 @@ class Facture { $amount = $this->amount; $remise = $this->remise; - if (! $remise) { $remise = 0 ; } + if (! $remise) { + $remise = 0 ; + } $totalht = ($amount - $remise); $tva = tva($totalht); $total = $totalht + $tva; - - $sql = "INSERT INTO $this->db_table (facnumber, fk_soc, datec, datef, note, amount, remise, tva, total) "; - $sql .= " VALUES ('$number', $socid, now(), $this->date,'$note', $amount, $remise, $tva, $total);"; + $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);"; - if ( $this->db->query($sql) ) { + if ( $this->db->query($sql) ) + { + $this->id = $this->db->last_insert_id(); - } else { - print $this->db->error() . '
'.$sql; - } - return $this->id; + $sql = "INSERT INTO llx_fa_pr (fk_facture,fk_propal) VALUES ($this->id, $this->propalid);"; + if ( $this->db->query($sql) ) + { + return $this->id; + } + else + { + print $this->db->error() . '
'.$sql; + return $this->id; + } + + } + else + { + print $this->db->error() . '
'.$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 "


Génération du PDF

"; + + $command = "export DBI_DSN=\"".$GLOBALS["DBI"]."\" "; + $command .= " ; ../../scripts/facture-tex.pl --facture=$facid --pdf --ps" ; + + $output = system($command); + print "

command : $command
"; + } + } ?> diff --git a/htdocs/soc.php3 b/htdocs/soc.php3 index 54084308d65..b806daa527a 100644 --- a/htdocs/soc.php3 +++ b/htdocs/soc.php3 @@ -40,8 +40,6 @@ if ($action == 'add') $soc->fax = $fax; $soc->url = $url; $soc->siren = $siren; - $soc->client = 1; - $soc->fournisseur = $fournisseur; $socid = $soc->create(); } @@ -73,7 +71,7 @@ if ($action == 'update') if ($action == 'create') { - print '

Nouveau client

'; + print '
Nouvelle société

'; print '
'; print ''; print ''; @@ -90,13 +88,7 @@ if ($action == 'create') print 'Siren'; - print 'Type'; - print 'Effectif'; - - print ''; print ''; print '';