PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/dons/fiche.php

https://github.com/asterix14/dolibarr
PHP | 569 lines | 385 code | 112 blank | 72 comment | 80 complexity | 0021760e82f606e7517b5704915515ff MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/compta/dons/fiche.php
  20. * \ingroup don
  21. * \brief Page of donation card
  22. */
  23. require("../../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/core/modules/dons/modules_don.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/compta/dons/class/don.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/compta/paiement/class/paiement.class.php");
  29. if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php');
  30. $langs->load("companies");
  31. $langs->load("donations");
  32. $langs->load("bills");
  33. $mesg="";
  34. $mesgs=array();
  35. $don = new Don($db);
  36. $donation_date=dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
  37. /*
  38. * Actions
  39. */
  40. if ($_POST["action"] == 'update')
  41. {
  42. if (! empty($_POST['cancel']))
  43. {
  44. Header("Location: fiche.php?rowid=".$_POST["rowid"]);
  45. exit;
  46. }
  47. $error=0;
  48. if (empty($donation_date))
  49. {
  50. $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Date"));
  51. $_GET["action"] = "create";
  52. $error++;
  53. }
  54. if (! $_POST["amount"] > 0)
  55. {
  56. $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Amount"));
  57. $_GET["action"] = "create";
  58. $error++;
  59. }
  60. if (! $error)
  61. {
  62. $don->id = $_POST["rowid"];
  63. $don->fetch($_POST["rowid"]);
  64. $don->prenom = $_POST["prenom"];
  65. $don->nom = $_POST["nom"];
  66. $don->societe = $_POST["societe"];
  67. $don->adresse = $_POST["adresse"];
  68. $don->amount = price2num($_POST["amount"]);
  69. $don->cp = $_POST["zipcode"];
  70. $don->ville = $_POST["town"];
  71. $don->zip = $_POST["zipcode"];
  72. $don->town = $_POST["town"];
  73. $don->email = $_POST["email"];
  74. $don->date = $donation_date;
  75. $don->note = $_POST["note"];
  76. $don->pays = $_POST["pays"];
  77. $don->public = $_POST["public"];
  78. $don->fk_project = $_POST["projectid"];
  79. $don->note = $_POST["comment"];
  80. $don->modepaiementid = $_POST["modepaiement"];
  81. if ($don->update($user) > 0)
  82. {
  83. Header("Location: fiche.php?rowid=".$don->id);
  84. exit;
  85. }
  86. }
  87. }
  88. if ($_POST["action"] == 'add')
  89. {
  90. if (! empty($_POST['cancel']))
  91. {
  92. Header("Location: index.php");
  93. exit;
  94. }
  95. $error=0;
  96. if (empty($donation_date))
  97. {
  98. $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Date"));
  99. $_GET["action"] = "create";
  100. $error++;
  101. }
  102. if (! $_POST["amount"] > 0)
  103. {
  104. $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Amount"));
  105. $_GET["action"] = "create";
  106. $error++;
  107. }
  108. if (! $error)
  109. {
  110. $don->prenom = $_POST["prenom"];
  111. $don->nom = $_POST["nom"];
  112. $don->societe = $_POST["societe"];
  113. $don->adresse = $_POST["adresse"];
  114. $don->amount = price2num($_POST["amount"]);
  115. $don->cp = $_POST["zipcode"];
  116. $don->ville = $_POST["town"];
  117. $don->zip = $_POST["zipcode"];
  118. $don->town = $_POST["town"];
  119. $don->email = $_POST["email"];
  120. $don->date = $donation_date;
  121. $don->note = $_POST["note"];
  122. $don->pays = $_POST["pays"];
  123. $don->public = $_POST["public"];
  124. $don->fk_project = $_POST["projectid"];
  125. $don->note = $_POST["comment"];
  126. $don->modepaiementid = $_POST["modepaiement"];
  127. if ($don->create($user) > 0)
  128. {
  129. Header("Location: index.php");
  130. exit;
  131. }
  132. }
  133. }
  134. if ($_GET["action"] == 'delete')
  135. {
  136. $don->delete($_GET["rowid"]);
  137. Header("Location: liste.php");
  138. exit;
  139. }
  140. if ($_POST["action"] == 'commentaire')
  141. {
  142. $don->fetch($_POST["rowid"]);
  143. $don->update_note($_POST["commentaire"]);
  144. $_GET["rowid"] = $_POST["rowid"];
  145. }
  146. if ($_GET["action"] == 'valid_promesse')
  147. {
  148. if ($don->valid_promesse($_GET["rowid"], $user->id) >= 0)
  149. {
  150. Header("Location: fiche.php?rowid=".$_GET["rowid"]);
  151. exit;
  152. }
  153. else $mesg=$don->error;
  154. }
  155. if ($_GET["action"] == 'set_cancel')
  156. {
  157. if ($don->set_cancel($_GET["rowid"]) >= 0)
  158. {
  159. Header("Location: fiche.php?rowid=".$_GET["rowid"]);
  160. exit;
  161. }
  162. else $mesg=$don->error;
  163. }
  164. if ($_GET["action"] == 'set_paid')
  165. {
  166. if ($don->set_paye($_GET["rowid"], $modepaiement) >= 0)
  167. {
  168. Header("Location: fiche.php?rowid=".$_GET["rowid"]);
  169. exit;
  170. }
  171. else $mesg=$don->error;
  172. }
  173. if ($_GET["action"] == 'set_encaisse')
  174. {
  175. if ($don->set_encaisse($_GET["rowid"]) >= 0)
  176. {
  177. Header("Location: fiche.php?rowid=".$_GET["rowid"]);
  178. exit;
  179. }
  180. else $mesg=$don->error;
  181. }
  182. /*
  183. * Build doc
  184. */
  185. if ($_REQUEST['action'] == 'builddoc')
  186. {
  187. $donation = new Don($db);
  188. $donation->fetch($_GET['rowid']);
  189. if ($_REQUEST['model'])
  190. {
  191. $donation->setDocModel($user, $_REQUEST['model']);
  192. }
  193. // Define output language
  194. $outputlangs = $langs;
  195. $newlang='';
  196. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  197. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$donation->client->default_lang;
  198. if (! empty($newlang))
  199. {
  200. $outputlangs = new Translate("",$conf);
  201. $outputlangs->setDefaultLang($newlang);
  202. }
  203. $result=don_create($db, $donation->id, '', $donation->modelpdf, $outputlangs);
  204. if ($result <= 0)
  205. {
  206. dol_print_error($db,$result);
  207. exit;
  208. }
  209. else
  210. {
  211. Header('Location: '.$_SERVER["PHP_SELF"].'?rowid='.$donation->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
  212. exit;
  213. }
  214. }
  215. /*
  216. * View
  217. */
  218. llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Subvenciones');
  219. $form=new Form($db);
  220. $formfile = new FormFile($db);
  221. $formcompany = new FormCompany($db);
  222. /* ************************************************************************** */
  223. /* */
  224. /* Creation */
  225. /* */
  226. /* ************************************************************************** */
  227. if ($_GET["action"] == 'create')
  228. {
  229. print_fiche_titre($langs->trans("AddDonation"));
  230. dol_htmloutput_errors($mesg,$mesgs);
  231. print '<form name="add" action="fiche.php" method="post">';
  232. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  233. print '<table class="border" width="100%">';
  234. print '<input type="hidden" name="action" value="add">';
  235. $nbrows=11;
  236. if ($conf->projet->enabled) $nbrows++;
  237. // Date
  238. print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
  239. $form->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1);
  240. print '</td>';
  241. print '<td rowspan="'.$nbrows.'" valign="top">'.$langs->trans("Comments").' :<br>';
  242. print "<textarea name=\"comment\" wrap=\"soft\" cols=\"40\" rows=\"15\">".$_POST["comment"]."</textarea></td>";
  243. print "</tr>";
  244. // Amount
  245. print "<tr>".'<td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="amount" value="'.$_POST["amount"].'" size="10"> '.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
  246. print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
  247. print $form->selectyesno("public",isset($_POST["public"])?$_POST["public"]:1,1);
  248. print "</td></tr>\n";
  249. print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" value="'.$_POST["societe"].'" size="40"></td></tr>';
  250. print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td><input type="text" name="prenom" value="'.$_POST["prenom"].'" size="40"></td></tr>';
  251. print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="nom" value="'.$_POST["nom"].'" size="40"></td></tr>';
  252. print "<tr>".'<td>'.$langs->trans("Address").'</td><td>';
  253. print '<textarea name="adresse" wrap="soft" cols="40" rows="3">'.$_POST["adresse"].'</textarea></td></tr>';
  254. // Zip / Town
  255. print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
  256. print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$don->zip),'zipcode',array('town','selectpays_id','departement_id'),6);
  257. print ' ';
  258. print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$don->town),'town',array('zipcode','selectpays_id','departement_id'));
  259. print '</tr>';
  260. print "<tr>".'<td>'.$langs->trans("Country").'</td><td><input type="text" name="pays" value="'.$_POST["pays"].'" size="40"></td></tr>';
  261. print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" value="'.$_POST["email"].'" size="40"></td></tr>';
  262. print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n";
  263. $form->select_types_paiements('', 'modepaiement', 'CRDT', 0, 1);
  264. print "</td></tr>\n";
  265. if ($conf->projet->enabled)
  266. {
  267. // Si module projet actif
  268. print "<tr><td>".$langs->trans("Project")."</td><td>";
  269. select_projects('',$_POST["projectid"],"projectid");
  270. print "</td></tr>\n";
  271. }
  272. print "</table>\n";
  273. print '<br><center><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
  274. print "</form>\n";
  275. }
  276. /* ************************************************************ */
  277. /* */
  278. /* Fiche don en mode edition */
  279. /* */
  280. /* ************************************************************ */
  281. if ($_GET["rowid"] && $_GET["action"] == 'edit')
  282. {
  283. $don->id = $_GET["rowid"];
  284. $don->fetch($_GET["rowid"]);
  285. $h=0;
  286. $head[$h][0] = DOL_URL_ROOT."/compta/dons/fiche.php?rowid=".$_GET["rowid"];
  287. $head[$h][1] = $langs->trans("Card");
  288. $hselected=$h;
  289. $h++;
  290. dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
  291. print '<form name="update" action="fiche.php" method="post">';
  292. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  293. print '<table class="border" width="100%">';
  294. print '<input type="hidden" name="action" value="update">';
  295. print '<input type="hidden" name="rowid" value="'.$don->id.'">';
  296. // Ref
  297. print "<tr>".'<td>'.$langs->trans("Ref").'</td><td colspan="2">';
  298. print $don->getNomUrl();
  299. print '</td>';
  300. print '</tr>';
  301. $nbrows=12;
  302. if ($conf->projet->enabled) $nbrows++;
  303. // Date
  304. print "<tr>".'<td width="25%" class="fieldrequired">'.$langs->trans("Date").'</td><td>';
  305. $form->select_date($don->date,'','','','',"update");
  306. print '</td>';
  307. print '<td rowspan="'.$nbrows.'" valign="top">'.$langs->trans("Comments").' :<br>';
  308. print "<textarea name=\"comment\" wrap=\"soft\" cols=\"40\" rows=\"15\">".$don->note."</textarea></td>";
  309. print "</tr>";
  310. // Amount
  311. print "<tr>".'<td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="amount" size="10" value="'.$don->amount.'"> '.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
  312. print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
  313. print $form->selectyesno("public",1,1);
  314. print "</td>";
  315. print "</tr>\n";
  316. $langs->load("companies");
  317. print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.$don->societe.'"></td></tr>';
  318. print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td><input type="text" name="prenom" size="40" value="'.$don->prenom.'"></td></tr>';
  319. print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="nom" size="40" value="'.$don->nom.'"></td></tr>';
  320. print "<tr>".'<td>'.$langs->trans("Address").'</td><td>';
  321. print '<textarea name="adresse" wrap="soft" cols="40" rows="'.ROWS_3.'">'.$don->adresse.'</textarea></td></tr>';
  322. // Zip / Town
  323. print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
  324. print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$don->zip),'zipcode',array('town','selectpays_id','departement_id'),6);
  325. print ' ';
  326. print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$don->town),'town',array('zipcode','selectpays_id','departement_id'));
  327. print '</tr>';
  328. print "<tr>".'<td>'.$langs->trans("Country").'</td><td><input type="text" name="pays" size="40" value="'.$don->pays.'"></td></tr>';
  329. print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" size="40" value="'.$don->email.'"></td></tr>';
  330. print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n";
  331. $form->select_types_paiements('', 'modepaiement', 'CRDT', 0, 1);
  332. print "</td></tr>\n";
  333. print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$don->getLibStatut(4).'</td></tr>';
  334. // Project
  335. if ($conf->projet->enabled)
  336. {
  337. $langs->load('projects');
  338. print '<tr><td>'.$langs->trans('Project').'</td><td>';
  339. select_projects($soc->id, isset($_POST["projectid"])?$_POST["projectid"]:$don->fk_project, 'projectid');
  340. print '</td></tr>';
  341. }
  342. print "</table>\n";
  343. print '<br><center><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
  344. print "</form>\n";
  345. print "</div>\n";
  346. }
  347. /* ************************************************************ */
  348. /* */
  349. /* Fiche don en mode visu */
  350. /* */
  351. /* ************************************************************ */
  352. if ($_GET["rowid"] && $_GET["action"] != 'edit')
  353. {
  354. $don->id = $_GET["rowid"];
  355. $result=$don->fetch($_GET["rowid"]);
  356. $h=0;
  357. $head[$h][0] = DOL_URL_ROOT."/compta/dons/fiche.php?rowid=".$_GET["rowid"];
  358. $head[$h][1] = $langs->trans("Card");
  359. $hselected=$h;
  360. $h++;
  361. dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
  362. print "<form action=\"fiche.php\" method=\"post\">";
  363. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  364. print '<table class="border" width="100%">';
  365. $nbrows=12;
  366. if ($conf->projet->enabled) $nbrows++;
  367. // Ref
  368. print "<tr>".'<td>'.$langs->trans("Ref").'</td><td colspan="2">';
  369. print $form->showrefnav($don,'rowid','',1,'rowid','ref','');
  370. print '</td>';
  371. print '</tr>';
  372. // Date
  373. print '<tr><td width="25%">'.$langs->trans("Date").'</td><td>';
  374. print dol_print_date($don->date,"day");
  375. print "</td>";
  376. print '<td rowspan="'.$nbrows.'" valign="top" width="50%">'.$langs->trans("Comments").' :<br>';
  377. print nl2br($don->note).'</td></tr>';
  378. print "<tr>".'<td>'.$langs->trans("Amount").'</td><td>'.price($don->amount).' '.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
  379. print "<tr><td>".$langs->trans("PublicDonation")."</td><td>";
  380. print yn($don->public);
  381. print "</td></tr>\n";
  382. print "<tr>".'<td>'.$langs->trans("Company").'</td><td>'.$don->societe.'</td></tr>';
  383. print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td>'.$don->prenom.'</td></tr>';
  384. print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td>'.$don->nom.'</td></tr>';
  385. print "<tr>".'<td>'.$langs->trans("Address").'</td><td>'.dol_nl2br($don->adresse).'</td></tr>';
  386. // Zip / Town
  387. print "<tr>".'<td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>'.$don->cp.($don->cp && $don->ville?' / ':'').$don->ville.'</td></tr>';
  388. // Country
  389. print "<tr>".'<td>'.$langs->trans("Country").'</td><td>'.$don->pays.'</td></tr>';
  390. // EMail
  391. print "<tr>".'<td>'.$langs->trans("EMail").'</td><td>'.dol_print_email($don->email).'</td></tr>';
  392. // Payment mode
  393. print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
  394. print $don->modepaiement;
  395. print "</td></tr>\n";
  396. print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$don->getLibStatut(4).'</td></tr>';
  397. // Project
  398. if ($conf->projet->enabled)
  399. {
  400. print "<tr>".'<td>'.$langs->trans("Project").'</td><td>'.$don->projet.'</td></tr>';
  401. }
  402. print "</table>\n";
  403. print "</form>\n";
  404. print "</div>";
  405. // TODO Gerer action emettre paiement
  406. $resteapayer = 0;
  407. /**
  408. * Barre d'actions
  409. */
  410. print '<div class="tabsAction">';
  411. print '<a class="butAction" href="fiche.php?action=edit&rowid='.$don->id.'">'.$langs->trans('Modify').'</a>';
  412. if ($don->statut == 0)
  413. {
  414. print '<a class="butAction" href="fiche.php?rowid='.$don->id.'&action=valid_promesse">'.$langs->trans("ValidPromess").'</a>';
  415. }
  416. if (($don->statut == 0 || $don->statut == 1) && $resteapayer == 0 && $don->paye == 0)
  417. {
  418. print "<a class=\"butAction\" href=\"fiche.php?rowid=$don->id&action=set_cancel\">".$langs->trans("ClassifyCanceled")."</a>";
  419. }
  420. // TODO Gerer action emettre paiement
  421. if ($don->statut == 1 && $resteapayer > 0)
  422. {
  423. print "<a class=\"butAction\" href=\"paiement.php?facid=$facid&action=create\">".$langs->trans("DoPayment")."</a>";
  424. }
  425. if ($don->statut == 1 && $resteapayer == 0 && $don->paye == 0)
  426. {
  427. print "<a class=\"butAction\" href=\"fiche.php?rowid=$don->id&action=set_paid\">".$langs->trans("ClassifyPaid")."</a>";
  428. }
  429. if ($user->rights->don->supprimer)
  430. {
  431. print "<a class=\"butActionDelete\" href=\"fiche.php?rowid=$don->id&action=delete\">".$langs->trans("Delete")."</a>";
  432. }
  433. else
  434. {
  435. print "<a class=\"butActionRefused\" href=\"#\">".$langs->trans("Delete")."</a>";
  436. }
  437. print "</div>";
  438. print '<table width="100%"><tr><td width="50%" valign="top">';
  439. /*
  440. * Documents generes
  441. */
  442. $filename=dol_sanitizeFileName($don->id);
  443. $filedir=$conf->don->dir_output . '/' . get_exdir($filename,2);
  444. $urlsource=$_SERVER['PHP_SELF'].'?rowid='.$don->id;
  445. // $genallowed=($fac->statut == 1 && ($fac->paye == 0 || $user->admin) && $user->rights->facture->creer);
  446. // $delallowed=$user->rights->facture->supprimer;
  447. $genallowed=1;
  448. $delallowed=0;
  449. $var=true;
  450. print '<br>';
  451. $formfile->show_documents('donation',$filename,$filedir,$urlsource,$genallowed,$delallowed);
  452. print '</td><td>&nbsp;</td>';
  453. print '</tr></table>';
  454. }
  455. $db->close();
  456. llxFooter();
  457. ?>