diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 71f469ae0be..e011306322c 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -20,6 +20,7 @@ * */ require("./pre.inc.php"); +require("./facture-rec.class.php"); $user->getrights('facture'); if (!$user->rights->facture->lire) @@ -28,7 +29,7 @@ if (!$user->rights->facture->lire) require("../../facture.class.php"); require("../../project.class.php"); -llxHeader('','Nouvelle facture récurrente','ch-facture.html#s-fac-facture-rec'); +llxHeader('','Facture récurrente','ch-facture.html#s-fac-facture-rec'); /* * Sécurité accés client @@ -43,61 +44,19 @@ if ($user->societe_id > 0) */ if ($HTTP_POST_VARS["action"] == 'add') { - $facture = new Facture($db, $socid); + $facturerec = new FactureRec($db, $facid); - $facture->number = $HTTP_POST_VARS["facnumber"]; - $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"]; + $facturerec->titre = $HTTP_POST_VARS["titre"]; - 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); + if ($facturerec->create($user) > 0) + { + $facid = $facturerec->id; + $action = ''; } 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, - 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"; - } - } - else - { - print "
Erreur : la facture n'a pas été créée, vérifier le numéro !"; - print "
Retour à la propal"; - print $db->error(); - } + $action = "create"; } - - $action = ''; } /* * @@ -105,7 +64,7 @@ if ($HTTP_POST_VARS["action"] == 'add') if ($action == 'delete' && $user->rights->facture->supprimer) { - $fac = new Facture($db); + $fac = new FactureRec($db); $fac->delete($facid); $facid = 0 ; } @@ -134,8 +93,7 @@ if ($action == 'create') print '