diff --git a/htdocs/compta/dons/index.php b/htdocs/compta/dons/index.php index 2bddb58207c..a5d43325a15 100644 --- a/htdocs/compta/dons/index.php +++ b/htdocs/compta/dons/index.php @@ -66,7 +66,8 @@ print '
| '.$langs->trans("Status").' | '; print ''.$langs->trans("Number").' | '; -print ''.$langs->trans("Amount").' | '; +print ''.$langs->trans("AmountTotal").' | '; +print ''.$langs->trans("Average").' | '; print "
| '.$libelle[$i].' | '; print ''.$nb[$i].' | '; - print ''.price($somme[$i]).' | '; + print ''.($nb[$i]?price($somme[$i]):' ').' | '; + print ''.($nb[$i]?(price($somme[$i])/$nb[$i]):' ').' | '; $totalnb += $nb[$i]; $total += $somme[$i]; print "
| '.$langs->trans("Total").' | '; print ''.$totalnb.' | '; print ''.price($total).' | '; +print ''.($totalnb?(price($total)/$totalnb):' ').' | '; print '
| '.$langs->trans("DonationsNumber").' | '.$num.' |
| '.$langs->trans("Total").' | '.price($total).' | '; - print "
| '.$langs->trans("Average").' | '.price($total / ($num?$num:1)).' | '; - print "
| '.$langs->trans("Parameter").' | '.$langs->trans("Value").' |
| '.$langs->trans("DonationsNumber").' | '.$num.' |
| '.$langs->trans("AmountTotal").' | '.price($total).' | '; + $var=!$var; + print "
| '.$langs->trans("Average").' | '.price($total / ($num?$num:1)).' | '; + print "
DEBUG: la propale précédente en ligne " . $prop->lignes[$i]->libelle . " avait comme prix : " . $prop->lignes[$i]->price . " !\n"; - $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 $langs->trans("UnknownError"); - } - } - } + } + $facid = $facture->create($user); - /* - * Commande - */ - if ($_POST["commandeid"]) - { - $facture->commandeid = $_POST["commandeid"]; - $facid = $facture->create($user); + if ($facid) + { + Header("Location: facture.php?facid=".$facid); + exit; + } + } + else + { + /* + * Propale + */ + if ($_POST["propalid"]) + { + $facture->propalid = $_POST["propalid"]; - if ($facid) - { - $comm = New Commande($db); - if ( $comm->fetch($_POST["commandeid"]) ) - { - $lines = $comm->fetch_lignes(); - 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 $langs->trans("UnknownError"); - } - } - else - { - print "
Erreur : la facture n'a pas été créée, vérifier le numéro !"; - print "
Retour à la propale"; - dolibarr_print_error($db); - } - } - - if ($facid) - { - Header("Location: facture.php?facid=".$facid); - } - } + $facid = $facture->create($user); + + if ($facid) + { + $prop = New Propal($db); + if ( $prop->fetch($_POST["propalid"]) ) + { + for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) + { + // print "
DEBUG: la propale précédente en ligne " . $prop->lignes[$i]->libelle . " avait comme prix : " . $prop->lignes[$i]->price . " !\n"; + $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 $langs->trans("UnknownError"); + } + } + } + + /* + * Commande + */ + if ($_POST["commandeid"]) + { + $facture->commandeid = $_POST["commandeid"]; + $facid = $facture->create($user); + + if ($facid) + { + $comm = New Commande($db); + if ( $comm->fetch($_POST["commandeid"]) ) + { + $lines = $comm->fetch_lignes(); + 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 $langs->trans("UnknownError"); + } + } + else + { + print "
Erreur : la facture n'a pas été créée, vérifier le numéro !"; + print "
Retour à la propale"; + dolibarr_print_error($db); + } + } + + if ($facid) + { + Header("Location: facture.php?facid=".$facid); + exit; + } + } } } /* * */ - -if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == "yes" && $user->rights->facture->valider) +if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->facture->valider) { - $fac = new Facture($db); - $fac->fetch($_GET["facid"]); - $soc = new Societe($db); - $soc->fetch($fac->socidp); - $result = $fac->set_valid($fac->id, $user, $soc); - if ($result) + $fac = new Facture($db); + $fac->fetch($_GET["facid"]); + $soc = new Societe($db); + $soc->fetch($fac->socidp); + $result = $fac->set_valid($fac->id, $user, $soc); + if ($result) { - facture_pdf_create($db, $fac->id); + facture_pdf_create($db, $fac->id); } } -if ($_GET["action"] == 'payed' && $user->rights->facture->paiement) +if ($_GET["action"] == 'payed' && $user->rights->facture->paiement) { - $fac = new Facture($db); - $result = $fac->set_payed($_GET["facid"]); + $fac = new Facture($db); + $result = $fac->set_payed($_GET["facid"]); } -if ($_POST["action"] == 'setremise' && $user->rights->facture->creer) +if ($_POST["action"] == 'setremise' && $user->rights->facture->creer) { - $fac = new Facture($db); - $fac->fetch($_GET["facid"]); + $fac = new Facture($db); + $fac->fetch($_GET["facid"]); - $fac->set_remise($user, $_POST["remise"]); -} - -if ($_POST["action"] == 'addligne' && $user->rights->facture->creer) -{ - $fac = new Facture($db); - $fac->fetch($_POST["facid"]); - $datestart=''; - $dateend=''; - if ($_POST["date_startyear"] && $_POST["date_startmonth"] && $_POST["date_startday"]) { - $datestart=$_POST["date_startyear"].'-'.$_POST["date_startmonth"].'-'.$_POST["date_startday"]; - } - if ($_POST["date_endyear"] && $_POST["date_endmonth"] && $_POST["date_endday"]) { - $dateend=$_POST["date_endyear"].'-'.$_POST["date_endmonth"].'-'.$_POST["date_endday"]; - } - $result = $fac->addline($_POST["facid"], - $_POST["desc"], - $_POST["pu"], - $_POST["qty"], - $_POST["tva_tx"], - 0, - $_POST["remise_percent"], - $datestart, - $dateend - ); - - $_GET["facid"]=$_POST["facid"]; // Pour réaffichage de la fiche en cours d'édition + $fac->set_remise($user, $_POST["remise"]); } -if ($_POST["action"] == 'updateligne' && $user->rights->facture->creer && $_POST["save"] == $langs->trans("Save")) +if ($_POST["action"] == 'addligne' && $user->rights->facture->creer) { - $fac = new Facture($db,"",$_POST["facid"]); - $fac->fetch($_POST["facid"]); - $datestart=''; - $dateend=''; - if ($_POST["date_startyear"] && $_POST["date_startmonth"] && $_POST["date_startday"]) { - $datestart=$_POST["date_startyear"].'-'.$_POST["date_startmonth"].'-'.$_POST["date_startday"]; - } - if ($_POST["date_endyear"] && $_POST["date_endmonth"] && $_POST["date_endday"]) { - $dateend=$_POST["date_endyear"].'-'.$_POST["date_endmonth"].'-'.$_POST["date_endday"]; - } + $fac = new Facture($db); + $fac->fetch($_POST["facid"]); + $datestart=''; + $dateend=''; + if ($_POST["date_startyear"] && $_POST["date_startmonth"] && $_POST["date_startday"]) { + $datestart=$_POST["date_startyear"].'-'.$_POST["date_startmonth"].'-'.$_POST["date_startday"]; + } + if ($_POST["date_endyear"] && $_POST["date_endmonth"] && $_POST["date_endday"]) { + $dateend=$_POST["date_endyear"].'-'.$_POST["date_endmonth"].'-'.$_POST["date_endday"]; + } + $result = $fac->addline($_POST["facid"], + $_POST["desc"], + $_POST["pu"], + $_POST["qty"], + $_POST["tva_tx"], + 0, + $_POST["remise_percent"], + $datestart, + $dateend + ); - $result = $fac->updateline($_POST["rowid"], - $_POST["desc"], - $_POST["price"], - $_POST["qty"], - $_POST["remise_percent"], - $datestart, - $dateend - ); - - $_GET["facid"]=$_POST["facid"]; // Pour réaffichage de la fiche en cours d'édition + $_GET["facid"]=$_POST["facid"]; // Pour réaffichage de la fiche en cours d'édition } -if ($_POST["action"] == 'updateligne' && $user->rights->facture->creer && $_POST["cancel"] == $langs->trans("Cancel")) +if ($_POST["action"] == 'updateligne' && $user->rights->facture->creer && $_POST["save"] == $langs->trans("Save")) { - Header("Location: facture.php?facid=".$_POST["facid"]); // Pour réaffichage de la fiche en cours d'édition + $fac = new Facture($db,"",$_POST["facid"]); + $fac->fetch($_POST["facid"]); + + $datestart=''; + $dateend=''; + if ($_POST["date_startyear"] && $_POST["date_startmonth"] && $_POST["date_startday"]) { + $datestart=$_POST["date_startyear"].'-'.$_POST["date_startmonth"].'-'.$_POST["date_startday"]; + } + if ($_POST["date_endyear"] && $_POST["date_endmonth"] && $_POST["date_endday"]) { + $dateend=$_POST["date_endyear"].'-'.$_POST["date_endmonth"].'-'.$_POST["date_endday"]; + } + + $result = $fac->updateline($_POST["rowid"], + $_POST["desc"], + $_POST["price"], + $_POST["qty"], + $_POST["remise_percent"], + $datestart, + $dateend + ); + + $_GET["facid"]=$_POST["facid"]; // Pour réaffichage de la fiche en cours d'édition } -if ($_GET["action"] == 'deleteline' && $user->rights->facture->creer) +if ($_POST["action"] == 'updateligne' && $user->rights->facture->creer && $_POST["cancel"] == $langs->trans("Cancel")) { - $fac = new Facture($db,"",$_GET["facid"]); - $fac->fetch($_GET["facid"]); - $result = $fac->deleteline($_GET["rowid"]); + Header("Location: facture.php?facid=".$_POST["facid"]); // Pour réaffichage de la fiche en cours d'édition + exit; } -if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == yes) +if ($_GET["action"] == 'deleteline' && $user->rights->facture->creer) { - if ($user->rights->facture->supprimer ) + $fac = new Facture($db,"",$_GET["facid"]); + $fac->fetch($_GET["facid"]); + $result = $fac->deleteline($_GET["rowid"]); +} + +if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') +{ + if ($user->rights->facture->supprimer ) { - $fac = new Facture($db); - $fac->delete($_GET["facid"]); - $_GET["facid"] = 0 ; - Header("Location: facture.php"); + $fac = new Facture($db); + $fac->delete($_GET["facid"]); + $_GET["facid"] = 0 ; + Header("Location: facture.php"); + exit; } } -if ($_POST["action"] == 'confirm_canceled' && $_POST["confirm"] == yes) +if ($_POST["action"] == 'confirm_canceled' && $_POST["confirm"] == 'yes') { - if ($user->rights->facture->supprimer ) + if ($user->rights->facture->supprimer ) { - $fac = new Facture($db); - $result = $fac->set_canceled($_GET["facid"]); - $_GET["facid"] = 0 ; - Header("Location: facture.php"); + $fac = new Facture($db); + $result = $fac->set_canceled($_GET["facid"]); + $_GET["facid"] = 0 ; + Header("Location: facture.php"); + exit; } } -/* +/* * Ordonnancement des lignes */ -if ($_GET["action"] == 'up' && $user->rights->facture->creer) +if ($_GET["action"] == 'up' && $user->rights->facture->creer) { - $fac = new Facture($db,"",$_GET["facid"]); - $fac->line_up($_GET["rowid"]); + $fac = new Facture($db,"",$_GET["facid"]); + $fac->line_up($_GET["rowid"]); } -if ($_GET["action"] == 'down' && $user->rights->facture->creer) +if ($_GET["action"] == 'down' && $user->rights->facture->creer) { - $fac = new Facture($db,"",$_GET["facid"]); - $fac->line_down($_GET["rowid"]); + $fac = new Facture($db,"",$_GET["facid"]); + $fac->line_down($_GET["rowid"]); } /* @@ -348,96 +348,97 @@ if ($_GET["action"] == 'down' && $user->rights->facture->creer) */ if ($_POST["action"] == 'send' || $_POST["action"] == 'relance') { - $langs->load("mails"); - - $fac = new Facture($db,"",$_POST["facid"]); - if ( $fac->fetch($_POST["facid"]) ) + $langs->load("mails"); + + $fac = new Facture($db,"",$_POST["facid"]); + if ( $fac->fetch($_POST["facid"]) ) { - $forbidden_chars=array("/","\\",":","*","?","\"","<",">","|","[","]",",",";","="); - $facref = str_replace($forbidden_chars,"_",$fac->ref); - $file = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf"; - - if (is_readable($file)) - { - $soc = new Societe($db, $fac->socidp); + $forbidden_chars=array("/","\\",":","*","?","\"","<",">","|","[","]",",",";","="); + $facref = str_replace($forbidden_chars,"_",$fac->ref); + $file = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf"; - if ($_POST["sendto"]) { - // Le destinataire a été fourni via le champ libre - $sendto = $_POST["sendto"]; - $sendtoid = 0; - } - elseif ($_POST["receiver"]) { - // Le destinataire a été fourni via la liste déroulante - $sendto = $soc->contact_get_email($_POST["receiver"]); - $sendtoid = $_POST["receiver"]; - } - - if (strlen($sendto)) - { - if ($_POST["action"] == 'send') { - $subject = $langs->trans("Bill")." $fac->ref"; - $actioncode=9; - $actionmsg="Envoyée à $sendto"; - $actionmsg2="Envoi Facture par mail"; - } - if ($_POST["action"] == 'relance') { - $subject = "Relance facture $fac->ref"; - $actioncode=10; - $actionmsg="Relance envoyée à $sendto"; - $actionmsg2="Relance Facture par mail"; - } - $message = $_POST["message"]; - $from = $_POST["fromname"] . " <" . $_POST["frommail"] .">"; - $replyto = $_POST["replytoname"]. " <" . $_POST["replytomail"].">"; + if (is_readable($file)) + { + $soc = new Societe($db, $fac->socidp); - $filepath[0] = $file; - $filename[0] = $fac->ref.".pdf"; - $mimetype[0] = "application/pdf"; - $filepath[1] = $_FILES['addedfile']['tmp_name']; - $filename[1] = $_FILES['addedfile']['name']; - $mimetype[1] = $_FILES['addedfile']['type']; - - // Envoi de la facture - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath, $mimetype,$filename,$sendtocc); + if ($_POST["sendto"]) { + // Le destinataire a été fourni via le champ libre + $sendto = $_POST["sendto"]; + $sendtoid = 0; + } + elseif ($_POST["receiver"]) { + // Le destinataire a été fourni via la liste déroulante + $sendto = $soc->contact_get_email($_POST["receiver"]); + $sendtoid = $_POST["receiver"]; + } - if ( $mailfile->sendfile() ) - { - $msg='