diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 3044338f7a8..f9682823b5c 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -32,6 +32,7 @@ require("../project.class.php"); require("../propal.class.php"); require("./bank/account.class.php"); require("../contrat/contrat.class.php"); +require("../commande/commande.class.php"); llxHeader(); @@ -57,9 +58,9 @@ if ($HTTP_POST_VARS["action"] == 'classin') */ if ($HTTP_POST_VARS["action"] == 'add') { - $datefacture = mktime(12, 0 , 0, $remonth, $reday, $reyear); + $datefacture = mktime(12, 0 , 0, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"]); - $facture = new Facture($db, $socid); + $facture = new Facture($db, $HTTP_POST_VARS["socid"]); $facture->number = $HTTP_POST_VARS["facnumber"]; $facture->date = $datefacture; @@ -80,8 +81,8 @@ if ($HTTP_POST_VARS["action"] == 'add') $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"]) + + if (!$HTTP_POST_VARS["propalid"] && !$HTTP_POST_VARS["commandeid"]) { $facture->add_product($HTTP_POST_VARS["idprod1"],$HTTP_POST_VARS["qty1"],$HTTP_POST_VARS["remise_percent1"]); $facture->add_product($HTTP_POST_VARS["idprod2"],$HTTP_POST_VARS["qty2"],$HTTP_POST_VARS["remise_percent2"]); @@ -92,37 +93,74 @@ if ($HTTP_POST_VARS["action"] == 'add') } else { - $facture->propalid = $HTTP_POST_VARS["propalid"]; - - $facid = $facture->create($user); - - if ($facid) + /* + * Propale + */ + if ($HTTP_POST_VARS["propalid"]) { - $prop = New Propal($db); - if ( $prop->fetch($HTTP_POST_VARS["propalid"]) ) + $facture->propalid = $HTTP_POST_VARS["propalid"]; + + $facid = $facture->create($user); + + if ($facid) { - for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) + $prop = New Propal($db); + if ( $prop->fetch($HTTP_POST_VARS["propalid"]) ) { - $result = $facture->addline($facid, - addslashes($prop->lignes[$i]->libelle), - $prop->lignes[$i]->subprice, - $prop->lignes[$i]->qty, - $prop->lignes[$i]->tva_tx, - $prop->lignes[$i]->product_id, - $prop->lignes[$i]->remise_percent); + for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) + { + $result = $facture->addline($facid, + addslashes($prop->lignes[$i]->libelle), + $prop->lignes[$i]->subprice, + $prop->lignes[$i]->qty, + $prop->lignes[$i]->tva_tx, + $prop->lignes[$i]->product_id, + $prop->lignes[$i]->remise_percent); + } + } + else + { + print "Erreur"; + } + } + } + /* + * Commande + */ + + if ($HTTP_POST_VARS["commandeid"]) + { + $facid = $facture->create($user); + + if ($facid) + { + $comm = New Commande($db); + if ( $comm->fetch($HTTP_POST_VARS["commandeid"]) ) + { + $lines = $comm->fetch_lignes(); + print_r($lines); + for ($i = 0 ; $i < sizeof(lines) ; $i++) + { + $result = $facture->addline($facid, + addslashes($lines[$i]->description), + $lines[$i]->subprice, + $lines[$i]->qty, + $lines[$i]->tva_tx, + $lines[$i]->product_id, + $lines[$i]->remise_percent); + } + } + else + { + print "Erreur"; } } else { - print "Erreur"; + print "Erreur creation de facture"; } } - else - { - print "
Erreur : la facture n'a pas été créée, vérifier le numéro !"; - print "
Retour à la propal"; - print $db->error(); - } + } } @@ -239,8 +277,8 @@ if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] if ($user->rights->facture->supprimer ) { $fac = new Facture($db); - $fac->delete($facid); - $facid = 0 ; + $fac->delete($_GET["facid"]); + $_GET["facid"] = 0 ; } } @@ -332,7 +370,7 @@ $html = new Form($db); * * ************************************************************************/ -if ($action == 'create') +if ($_GET["action"] == 'create') { print_titre("Emettre une facture"); @@ -347,10 +385,18 @@ if ($action == 'create') { $sql = "SELECT s.nom, s.prefix_comm, s.idp "; $sql .= "FROM llx_societe as s "; - $sql .= "WHERE s.idp = $socidp"; + $sql .= "WHERE s.idp = ".$_GET["socidp"]; } - if ( $db->query($sql) ) + if ($_GET["commandeid"]) + { + $commande = New Commande($db); + $commande->fetch($_GET["commandeid"]); + $societe_id = $commande->soc_id; + } + + + if ( $societe_id ) { $num = $db->num_rows(); if ($num) @@ -358,16 +404,16 @@ if ($action == 'create') $obj = $db->fetch_object(0); $soc = new Societe($db); - $soc->fetch($obj->idp); + $soc->fetch($societe_id); print '