diff --git a/htdocs/compta/facture.php3 b/htdocs/compta/facture.php3 index a2e20149f80..b366c2ccf53 100644 --- a/htdocs/compta/facture.php3 +++ b/htdocs/compta/facture.php3 @@ -46,7 +46,69 @@ if ($user->societe_id > 0) /* * */ +if ($HTTP_POST_VARS["action"] == 'add') +{ + $datefacture = mktime(12, 0 , 0, $remonth, $reday, $reyear); + $facture = new Facture($db, $socid); + + $facture->number = $HTTP_POST_VARS["facnumber"]; + $facture->date = $datefacture; + $facture->note = $HTTP_POST_VARS["note"]; + $facture->projetid = $HTTP_POST_VARS["projetid"]; + $facture->cond_reglement = $HTTP_POST_VARS["condid"]; + $facture->amount = $HTTP_POST_VARS["amount"]; + $facture->remise = $HTTP_POST_VARS["remise"]; + $facture->remise_percent = $HTTP_POST_VARS["remise_percent"]; + + if (!$HTTP_POST_VARS["propalid"]) + { + $facture->add_product($HTTP_POST_VARS["idprod1"],$HTTP_POST_VARS["qty1"]); + $facture->add_product($HTTP_POST_VARS["idprod2"],$HTTP_POST_VARS["qty2"]); + $facture->add_product($HTTP_POST_VARS["idprod3"],$HTTP_POST_VARS["qty3"]); + $facture->add_product($HTTP_POST_VARS["idprod4"],$HTTP_POST_VARS["qty4"]); + + $facid = $facture->create($user); + } + else + { + $facture->propalid = $HTTP_POST_VARS["propalid"]; + + $facid = $facture->create($user); + + if ($facid) + { + $prop = New Propal($db); + if ( $prop->fetch($HTTP_POST_VARS["propalid"]) ) + { + for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) + { + $result = $facture->addline($facid, + $prop->lignes[$i]->desc, + $prop->lignes[$i]->price, + $prop->lignes[$i]->qty, + $prop->lignes[$i]->tva_tx, + $prop->lignes[$i]->product_id); + } + } + else + { + print "Erreur"; + } + } + else + { + print "

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

Retour à la propal"; + print $db->error(); + } + } + + $action = ''; +} +/* + * + */ if ($action == 'add_paiement') { $datepaye = $db->idate(mktime(12, 0 , 0, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"])); @@ -149,65 +211,6 @@ if ($action == 'delete' && $user->rights->facture->supprimer) $facid = 0 ; } -if ($HTTP_POST_VARS["action"] == 'add') -{ - $datefacture = mktime(12, 0 , 0, $remonth, $reday, $reyear); - - $facture = new Facture($db, $socid); - - $facture->number = $HTTP_POST_VARS["facnumber"]; - $facture->date = $datefacture; - $facture->note = $HTTP_POST_VARS["note"]; - $facture->projetid = $HTTP_POST_VARS["projetid"]; - $facture->cond_reglement = $HTTP_POST_VARS["condid"]; - - if (!$HTTP_POST_VARS["propalid"]) - { - $facture->amount = $HTTP_POST_VARS["amount"]; - $facture->remise = $HTTP_POST_VARS["remise"]; - $facture->remise_percent = $HTTP_POST_VARS["remise_percent"]; - - $facture->add_product($HTTP_POST_VARS["idprod1"],$HTTP_POST_VARS["qty1"]); - $facture->add_product($HTTP_POST_VARS["idprod2"],$HTTP_POST_VARS["qty2"]); - $facture->add_product($HTTP_POST_VARS["idprod3"],$HTTP_POST_VARS["qty3"]); - $facture->add_product($HTTP_POST_VARS["idprod4"],$HTTP_POST_VARS["qty4"]); - - $facid = $facture->create($user); - } - else - { - $facture->remise_percent = $HTTP_POST_VARS["remise_percent"]; - $facture->amount = $HTTP_POST_VARS["amount"]; - $facture->remise = $remise; - $facture->propalid = $HTTP_POST_VARS["propalid"]; - - $facid = $facture->create($user); - //TODO - if ($facid) - { - $prop = New Propal($db); - $prop->fetch($HTTP_POST_VARS["propalid"]); - - for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) - { - $result = $facture->addline($facid, - $prop->lignes[$i]->desc, - $prop->lignes[$i]->price, - $prop->lignes[$i]->qty, - $prop->lignes[$i]->tva_tx, - $prop->lignes[$i]->product_id); - } - } - else - { - print "

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

Retour à la propal"; - print $db->error(); - } - } - $action = ''; - -} /* * */ @@ -373,7 +376,7 @@ if ($action == 'create') $html->select_array("projetid",$proj->liste_array($socidp)); print ""; - if ($propalid) + if ($propalid > 0) { $amount = ($obj->price); print ''."\n"; @@ -431,14 +434,45 @@ if ($action == 'create') print ''; print ''; } - - - print ''; print "\n"; print "\n"; - + + if ($propalid) + { + /* + * Produits + */ + print_titre("Produits"); + + print ''; + print ''; + print ''; + + $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid"; + $sql .= " FROM llx_propaldet as pt, llx_product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propalid"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows(); + $i = 0; + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($i); + $var=!$var; + print "\n"; + print ''; + print ""; + print ''; + print "\n"; + $i++; + } + } + print '
RéfProduitPrix Qté.
[$objp->ref]'.$objp->product.'".price($objp->price)." ".$objp->qty."
'; + } } } else @@ -458,72 +492,45 @@ else { $fac = New Facture($db); - $fac->fetch($facid); - - $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 llx_societe as s,llx_facture as f WHERE f.fk_soc = s.idp AND f.rowid = $facid"; - - if ($user->societe_id > 0) - { - $sql .= " AND s.idp = ".$user->societe_id; - } - - $result = $db->query( $sql); - - if ($result) - { - $num = $db->num_rows(); - if ($num) - { - $obj = $db->fetch_object( $i); - } - $db->free(); - } - else - { - print $db->error(); - } - - if ($num > 0) - { - - $soc = new Societe($db, $obj->socidp); - - $author = new User($db); - $author->id = $obj->fk_user_author; - $author->fetch(); - - print_titre("Facture : ".$fac->ref); - - /* - * Facture - */ - print ""; - print ""; - print ""; - - print ""; - - print ""; - print "\n"; - print ""; - print ""; - - if ($fac->remise_percent > 0) - { - print ''; if ($fac->note) { - print '"; + print '"; } print "
Client"; - print "socidp\">$obj->socnomConditions de réglement : " . $fac->cond_reglement ."
Date".strftime("%A %d %B %Y",$obj->df)."Date limite de réglement : " . strftime("%d %B %Y",$fac->date_lim_reglement) ."
Auteur$author->fullname'; - } - else - { - print ''; - } - - $_MONNAIE="euros"; - - /* - * Paiements - */ + if ( $fac->fetch($facid, $user->societe_id) > 0) + { + $soc = new Societe($db, $fac->socidp); + $soc->fetch($fac->socidp); + $author = new User($db); + $author->id = $fac->user_author; + $author->fetch(); + + print_titre("Facture : ".$fac->ref); + + /* + * Facture + */ + print ""; + print ""; + print "'; + + print ""; + + print ""; + print "\n"; + print ""; + print ""; + + if ($fac->remise_percent > 0) + { + print '"; print ""; print ""; - if (! $obj->paye) + if (! $fac->paye) { print ""; } @@ -553,7 +560,7 @@ else print "\n"; print "\n"; print '\n"; - if (! $obj->paye && $user->rights->facture->paiement) + if (! $fac->paye && $user->rights->facture->paiement) { print '\n"; - print "\n"; + print "\n"; - $resteapayer = price($obj->total - $total); + $resteapayer = price($fac->total_ttc - $total); print ""; - print "\n"; + print "\n"; } print "
Client"; + print ''.$soc->nom.'Conditions de réglement : " . $fac->cond_reglement ."
Date".strftime("%A %d %B %Y",$fac->date)."Date limite de réglement : " . strftime("%d %B %Y",$fac->date_lim_reglement) ."
Auteur$author->fullname'; + } + else + { + print ''; + } + + $_MONNAIE="euros"; + + /* + * Paiements + */ $sql = "SELECT ".$db->pdate("datep")." as dp, p.amount, c.libelle as paiement_type, p.num_paiement, p.rowid"; $sql .= " FROM llx_paiement as p, c_paiement as c WHERE p.fk_facture = $facid AND p.fk_paiement = c.id"; @@ -538,7 +545,7 @@ else print "DateTypeMontant  ".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement'.price($objp->amount)."$_MONNAIEDel'; } @@ -562,15 +569,15 @@ else $i++; } - if ($obj->paye == 0) + if ($fac->paye == 0) { print "
Total :".price($total)."$_MONNAIE
Facturé :".price($obj->total)."$_MONNAIE
Facturé :".price($fac->total_ttc)."$_MONNAIE
Reste à payer :".price($obj->total - $total)."$_MONNAIE
".price($fac->total_ttc - $total)."$_MONNAIE
"; $db->free(); @@ -597,7 +604,7 @@ else print '
euros TTC
Note : '.nl2br($obj->note)."
Note : '.nl2br($fac->note)."

"; @@ -654,7 +661,7 @@ else print ''.$objp->tva_taux.' %'; print ''.$objp->qty.''; print ''.price($objp->price)."\n"; - if ($obj->statut == 0) + if ($fac->statut == 0) { print 'del'; print 'edit'; @@ -695,7 +702,7 @@ else * Ajouter une ligne * */ - if ($obj->statut == 0) + if ($fac->statut == 0) { print "

"; // echo ''; @@ -728,11 +735,11 @@ else { print "

"; - if ($obj->statut == 0 && $user->rights->facture->supprimer) + if ($fac->statut == 0 && $user->rights->facture->supprimer) { print ""; } - elseif ($obj->statut == 1 && abs($resteapayer) > 0 && $user->rights->facture->envoyer) + elseif ($fac->statut == 1 && abs($resteapayer) > 0 && $user->rights->facture->envoyer) { print ""; } @@ -741,7 +748,7 @@ else print ""; } - if ($obj->statut == 1 && $resteapayer > 0 && $user->rights->facture->paiement) + if ($fac->statut == 1 && $resteapayer > 0 && $user->rights->facture->paiement) { print ""; } @@ -750,7 +757,7 @@ else print ""; } - if ($obj->statut == 1 && abs($resteapayer) == 0 && $obj->paye == 0) + if ($fac->statut == 1 && abs($resteapayer) == 0 && $fac->paye == 0) { if ($user->rights->facture->paiement) { @@ -761,7 +768,7 @@ else print ''; } } - elseif ($obj->statut == 1 && $resteapayer > 0 && $user->rights->facture->envoyer) + elseif ($fac->statut == 1 && $resteapayer > 0 && $user->rights->facture->envoyer) { print ""; } @@ -770,7 +777,7 @@ else print ''; } - if ($obj->statut == 0 && $obj->total > 0) + if ($fac->statut == 0 && $fac->total_ht > 0) { if ($user->rights->facture->valider) { @@ -781,7 +788,7 @@ else print ''; } } - elseif ($obj->statut == 1 && $obj->paye == 0) + elseif ($fac->statut == 1 && $fac->paye == 0) { if ($user->rights->facture->creer) { @@ -809,23 +816,23 @@ else print_titre("Documents"); print '
[Supprimer][Envoyer]-[Emettre un paiement]--[Envoyer une relance]--
'; - $file = FAC_OUTPUTDIR . "/" . $obj->facnumber . "/" . $obj->facnumber . ".pdf"; + $file = FAC_OUTPUTDIR . "/" . $fac->facnumber . "/" . $fac->facnumber . ".pdf"; if (file_exists($file)) { print ""; - print ''; + print ''; print ''; print ''; print ''; } - $file = FAC_OUTPUTDIR . "/" . $obj->facnumber . "/" . $obj->facnumber . ".ps"; + $file = FAC_OUTPUTDIR . "/" . $fac->facnumber . "/" . $fac->facnumber . ".ps"; if (file_exists($file)) { print ""; - print ''; + print ''; print ''; print ''; print ''; @@ -841,7 +848,7 @@ else * */ $sql = "SELECT ".$db->pdate("a.datea")." as da, a.note"; - $sql .= " FROM llx_actioncomm as a WHERE a.fk_soc = $obj->socidp AND a.fk_action in (9,10) AND a.fk_facture = $facid"; + $sql .= " FROM llx_actioncomm as a WHERE a.fk_soc = $fac->socidp AND a.fk_action in (9,10) AND a.fk_facture = $facid"; $result = $db->query($sql); if ($result) @@ -904,7 +911,7 @@ else $form = new Form($db); $form->select_array("destinataire",$soc->contact_email_array()); - print ""; + print ""; print ""; print ""; print "
Facture PDFfacnumber."/".$obj->facnumber.'.pdf">'.$obj->facnumber.'.pdffacnumber."/".$fac->facnumber.'.pdf">'.$fac->facnumber.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
Facture Postscriptfacnumber."/".$obj->facnumber.'.ps">'.$obj->facnumber.'.psfacnumber."/".$fac->facnumber.'.ps">'.$fac->facnumber.'.ps'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
email\">
email\">
Expéditeur$from_name$from_mail
Reply-to$replytoname$replytomail
"; @@ -932,7 +939,7 @@ else $form = new Form($db); $form->select_array("destinataire",$soc->contact_email_array()); - print "email\">"; + print "email\">"; print "Expéditeur$from_name$from_mail"; print "Reply-to$replytoname"; print "$replytomail"; diff --git a/htdocs/compta/paiement.php3 b/htdocs/compta/paiement.php3 index 1a6c185b650..b7e6ae3b9c5 100644 --- a/htdocs/compta/paiement.php3 +++ b/htdocs/compta/paiement.php3 @@ -43,7 +43,7 @@ llxHeader(); if ($action == 'create') { - $sql = "SELECT s.nom,s.idp, f.amount, f.total, f.facnumber"; + $sql = "SELECT s.nom,s.idp, f.amount, f.total_ttc as total, f.facnumber"; $sql .= " FROM llx_societe as s, llx_facture as f WHERE f.fk_soc = s.idp"; $sql .= " AND f.rowid = $facid"; diff --git a/htdocs/compta/propal.php3 b/htdocs/compta/propal.php3 index 843f198c314..c26aaa33c43 100644 --- a/htdocs/compta/propal.php3 +++ b/htdocs/compta/propal.php3 @@ -192,7 +192,7 @@ if ($propalid) /* * Factures associees */ - $sql = "SELECT f.facnumber, f.amount,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.paye"; + $sql = "SELECT f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.paye"; $sql .= " FROM llx_facture as f, llx_fa_pr as fp WHERE fp.fk_facture = f.rowid AND fp.fk_propal = $propalid"; $result = $db->query($sql); @@ -240,9 +240,9 @@ if ($propalid) { print "".$user->fullname."\n"; } - print ''.price($objp->amount).''; + print ''.price($objp->total).''; print ""; - $total = $total + $objp->amount; + $total = $total + $objp->total; $i++; } print "Total : $total Euros HT\n"; @@ -302,8 +302,7 @@ if ($propalid) $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid"; $sql .= " FROM llx_propaldet as pt, llx_product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propalid"; - $result = $db->query($sql); - if ($result) + if ($db->query($sql)) { $num = $db->num_rows(); $i = 0; diff --git a/htdocs/compta/stats/comp.php b/htdocs/compta/stats/comp.php index de0da225ac6..fd06d6272d8 100644 --- a/htdocs/compta/stats/comp.php +++ b/htdocs/compta/stats/comp.php @@ -25,7 +25,7 @@ require("./lib.inc.php"); function propals ($db, $year, $month) { global $bc; - $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price - p.remise as price, p.ref,".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid"; + $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid"; $sql .= " FROM llx_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 c.id in (1,2,4)"; $sql .= " AND date_format(p.datep, '%Y') = $year "; @@ -96,7 +96,7 @@ function propals ($db, $year, $month) { function factures ($db, $year, $month, $paye) { global $bc; - $sql = "SELECT s.nom, s.idp, f.facnumber, f.amount,".$db->pdate("f.datef")." as df, f.paye, f.rowid as facid "; + $sql = "SELECT s.nom, s.idp, f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.paye, f.rowid as facid "; $sql .= " FROM llx_societe as s,llx_facture as f WHERE f.fk_soc = s.idp AND f.paye = $paye"; $sql .= " AND date_format(f.datef, '%Y') = $year "; $sql .= " AND round(date_format(f.datef, '%m')) = $month "; @@ -135,7 +135,7 @@ function factures ($db, $year, $month, $paye) { print "!!!\n"; } - print "".price($objp->amount)."\n"; + print "".price($objp->total)."\n"; $payes[1] = "oui"; $payes[0] = "non"; @@ -143,7 +143,7 @@ function factures ($db, $year, $month, $paye) { print "".$payes[$objp->paye]."\n"; print "\n"; - $total = $total + $objp->amount; + $total = $total + $objp->total; $i++; } @@ -257,7 +257,7 @@ function ppt ($db, $year, $socidp) print ""; - $sql = "SELECT sum(f.amount) as sum, round(date_format(f.datef, '%m')) as dm"; + $sql = "SELECT sum(f.total) as sum, round(date_format(f.datef, '%m')) as dm"; $sql .= " FROM llx_facture as f WHERE f.paye = 1 AND date_format(f.datef,'%Y') = $year "; if ($socidp) { diff --git a/htdocs/facture.class.php3 b/htdocs/facture.class.php3 index a2be0e2ed5b..f7f45a0bb7e 100644 --- a/htdocs/facture.class.php3 +++ b/htdocs/facture.class.php3 @@ -156,13 +156,18 @@ class Facture * * */ - Function fetch($rowid) + Function fetch($rowid, $societe_id=0) { - $sql = "SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.total_ttc,f.remise,f.remise_percent,".$this->db->pdate("f.datef")."as df,f.fk_projet,".$this->db->pdate("f.date_lim_reglement")." as dlr, c.libelle, f.note, f.paye, f.fk_statut"; + $sql = "SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.total_ttc,f.remise,f.remise_percent,".$this->db->pdate("f.datef")."as df,f.fk_projet,".$this->db->pdate("f.date_lim_reglement")." as dlr, c.libelle, f.note, f.paye, f.fk_statut, f.fk_user_author"; $sql .= " FROM llx_facture as f, llx_cond_reglement as c"; $sql .= " WHERE f.rowid=$rowid AND c.rowid = f.fk_cond_reglement"; + if ($societe_id > 0) + { + $sql .= " AND f.fk_soc = ".$societe_id; + } + if ($this->db->query($sql) ) { if ($this->db->num_rows()) @@ -186,6 +191,7 @@ class Facture $this->cond_reglement = $obj->libelle; $this->projetid = $obj->fk_projet; $this->note = stripslashes($obj->note); + $this->user_author = $obj->fk_user_author; $this->lignes = array(); if ($this->statut == 0)