card.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?php
  2. /* Copyright (C) 2007-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  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 3 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 <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/adherents/subscription/card.php
  20. * \ingroup member
  21. * \brief Page to add/edit/remove a member subscription
  22. */
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  28. if (! empty($conf->banque->enabled)) {
  29. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  30. }
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("companies","members","bills","users"));
  33. $adh = new Adherent($db);
  34. $adht = new AdherentType($db);
  35. $object = new Subscription($db);
  36. $errmsg='';
  37. $action=GETPOST("action", 'alpha');
  38. $rowid=GETPOST("rowid", "int")?GETPOST("rowid", "int"):GETPOST("id", "int");
  39. $typeid=GETPOST("typeid", "int");
  40. $cancel=GETPOST('cancel', 'alpha');
  41. $confirm=GETPOST('confirm');
  42. if (! $user->rights->adherent->cotisation->lire)
  43. accessforbidden();
  44. $permissionnote = $user->rights->adherent->cotisation->creer; // Used by the include of actions_setnotes.inc.php
  45. $permissiondellink=$user->rights->adherent->cotisation->creer; // Used by the include of actions_dellink.inc.php
  46. $permissiontoedit = $user->rights->adherent->cotisation->creer; // Used by the include of actions_lineupdonw.inc.php
  47. /*
  48. * Actions
  49. */
  50. if ($cancel) $action='';
  51. //include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
  52. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  53. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
  54. if ($user->rights->adherent->cotisation->creer && $action == 'update' && ! $cancel)
  55. {
  56. // Charge objet actuel
  57. $result=$object->fetch($rowid);
  58. if ($result > 0)
  59. {
  60. $db->begin();
  61. $errmsg='';
  62. if ($object->fk_bank)
  63. {
  64. $accountline=new AccountLine($db);
  65. $result=$accountline->fetch($object->fk_bank);
  66. // If transaction consolidated
  67. if ($accountline->rappro)
  68. {
  69. $errmsg=$langs->trans("SubscriptionLinkedToConciliatedTransaction");
  70. }
  71. else
  72. {
  73. $accountline->datev=dol_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
  74. $accountline->dateo=dol_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
  75. $accountline->amount=$_POST["amount"];
  76. $result=$accountline->update($user);
  77. if ($result < 0)
  78. {
  79. $errmsg=$accountline->error;
  80. }
  81. }
  82. }
  83. if (! $errmsg)
  84. {
  85. // Modifie valeures
  86. $object->dateh=dol_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
  87. $object->datef=dol_mktime($_POST['datesubendhour'], $_POST['datesubendmin'], 0, $_POST['datesubendmonth'], $_POST['datesubendday'], $_POST['datesubendyear']);
  88. $object->fk_type=$_POST["typeid"];
  89. $object->note=$_POST["note"];
  90. $object->amount=$_POST["amount"];
  91. //print 'datef='.$object->datef.' '.$_POST['datesubendday'];
  92. $result=$object->update($user);
  93. if ($result >= 0 && ! count($object->errors))
  94. {
  95. $db->commit();
  96. header("Location: card.php?rowid=".$object->id);
  97. exit;
  98. }
  99. else
  100. {
  101. $db->rollback();
  102. if ($object->error)
  103. {
  104. $errmsg=$object->error;
  105. }
  106. else
  107. {
  108. foreach($object->errors as $error)
  109. {
  110. if ($errmsg) $errmsg.='<br>';
  111. $errmsg.=$error;
  112. }
  113. }
  114. $action='';
  115. }
  116. }
  117. else
  118. {
  119. $db->rollback();
  120. }
  121. }
  122. }
  123. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->adherent->cotisation->creer)
  124. {
  125. $result=$object->fetch($rowid);
  126. $result=$object->delete($user);
  127. if ($result > 0)
  128. {
  129. header("Location: ".DOL_URL_ROOT."/adherents/card.php?rowid=".$object->fk_adherent);
  130. exit;
  131. }
  132. else
  133. {
  134. $mesg=$adh->error;
  135. }
  136. }
  137. /*
  138. * View
  139. */
  140. $form = new Form($db);
  141. llxHeader('', $langs->trans("SubscriptionCard"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
  142. dol_htmloutput_errors($errmsg);
  143. if ($user->rights->adherent->cotisation->creer && $action == 'edit')
  144. {
  145. /********************************************
  146. *
  147. * Subscription card in edit mode
  148. *
  149. ********************************************/
  150. $object->fetch($rowid);
  151. $result=$adh->fetch($object->fk_adherent);
  152. $head = subscription_prepare_head($object);
  153. print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  154. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  155. print "<input type=\"hidden\" name=\"action\" value=\"update\">";
  156. print "<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">";
  157. print "<input type=\"hidden\" name=\"fk_bank\" value=\"".$object->fk_bank."\">";
  158. dol_fiche_head($head, 'general', $langs->trans("Subscription"), 0, 'payment');
  159. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  160. print "\n";
  161. print '<table class="border" width="100%">';
  162. // Ref
  163. print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
  164. print '<td class="valeur" colspan="3">';
  165. print $form->showrefnav($object, 'rowid', $linkback, 1);
  166. print '</td></tr>';
  167. // Member
  168. $adh->ref=$adh->getFullName($langs);
  169. print '<tr>';
  170. print '<td>'.$langs->trans("Member").'</td><td class="valeur" colspan="3">'.$adh->getNomUrl(1, 0, 'subscription').'</td>';
  171. print '</tr>';
  172. // Type
  173. print '<tr>';
  174. print '<td>'.$langs->trans("Type").'</td><td class="valeur" colspan="3">';
  175. print $form->selectarray("typeid", $adht->liste_array(), (isset($_POST["typeid"])?$_POST["typeid"]:$object->fk_type));
  176. print'</td></tr>';
  177. // Date start subscription
  178. print '<tr><td>'.$langs->trans("DateSubscription").'</td><td class="valeur" colspan="2">';
  179. print $form->selectDate($object->dateh, 'datesub', 1, 1, 0, 'update', 1);
  180. print '</td>';
  181. print '</tr>';
  182. // Date end subscription
  183. print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur" colspan="2">';
  184. print $form->selectDate($object->datef, 'datesubend', 0, 0, 0, 'update', 1);
  185. print '</td>';
  186. print '</tr>';
  187. // Amount
  188. print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur" colspan="2">';
  189. print '<input type="text" class="flat" size="10" name="amount" value="'.price($object->amount).'"></td></tr>';
  190. // Label
  191. print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur" colspan="2">';
  192. print '<input type="text" class="flat" size="60" name="note" value="'.$object->note.'"></td></tr>';
  193. // Bank line
  194. if (! empty($conf->banque->enabled))
  195. {
  196. if ($conf->global->ADHERENT_BANK_USE || $object->fk_bank)
  197. {
  198. print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur" colspan="2">';
  199. if ($object->fk_bank)
  200. {
  201. $bankline=new AccountLine($db);
  202. $result=$bankline->fetch($object->fk_bank);
  203. print $bankline->getNomUrl(1, 0, 'showall');
  204. }
  205. else
  206. {
  207. print $langs->trans("NoneF");
  208. }
  209. print '</td></tr>';
  210. }
  211. }
  212. print '</table>';
  213. dol_fiche_end();
  214. print '<div class="center">';
  215. print '<input type="submit" class="button" name="submit" value="'.$langs->trans("Save").'">';
  216. print ' &nbsp; &nbsp; &nbsp; ';
  217. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  218. print '</div>';
  219. print '</form>';
  220. print "\n";
  221. }
  222. if ($rowid && $action != 'edit')
  223. {
  224. /********************************************
  225. *
  226. * Subscription card in view mode
  227. *
  228. ********************************************/
  229. $result=$object->fetch($rowid);
  230. $result=$adh->fetch($object->fk_adherent);
  231. $head = subscription_prepare_head($object);
  232. dol_fiche_head($head, 'general', $langs->trans("Subscription"), -1, 'payment');
  233. // Confirmation to delete subscription
  234. if ($action == 'delete')
  235. {
  236. //$formquestion=array();
  237. //$formquestion['text']='<b>'.$langs->trans("ThisWillAlsoDeleteBankRecord").'</b>';
  238. $text=$langs->trans("ConfirmDeleteSubscription");
  239. if (! empty($conf->banque->enabled) && ! empty($conf->global->ADHERENT_BANK_USE)) $text.='<br>'.img_warning().' '.$langs->trans("ThisWillAlsoDeleteBankRecord");
  240. print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("DeleteSubscription"), $text, "confirm_delete", $formquestion, 0, 1);
  241. }
  242. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  243. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  244. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  245. dol_banner_tab($object, 'rowid', $linkback, 1);
  246. print '<div class="fichecenter">';
  247. print '<div class="underbanner clearboth"></div>';
  248. print '<table class="border" width="100%">';
  249. // Member
  250. $adh->ref=$adh->getFullName($langs);
  251. print '<tr>';
  252. print '<td class="titlefield">'.$langs->trans("Member").'</td><td class="valeur">'.$adh->getNomUrl(1, 0, 'subscription').'</td>';
  253. print '</tr>';
  254. // Type
  255. print '<tr>';
  256. print '<td class="titlefield">'.$langs->trans("Type").'</td>';
  257. print '<td class="valeur">';
  258. if ($object->fk_type > 0 || $adh->typeid > 0) {
  259. $typeid = ($object->fk_type > 0 ? $object->fk_type : $adh->typeid);
  260. $adht->fetch($typeid);
  261. print $adht->getNomUrl(1);
  262. } else {
  263. print $langs->trans("NoType");
  264. }
  265. print '</td></tr>';
  266. // Date subscription
  267. print '<tr>';
  268. print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->dateh, 'day').'</td>';
  269. print '</tr>';
  270. // Date end subscription
  271. print '<tr>';
  272. print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dol_print_date($object->datef, 'day').'</td>';
  273. print '</tr>';
  274. // Amount
  275. print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur">'.price($object->amount).'</td></tr>';
  276. // Label
  277. print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur">'.$object->note.'</td></tr>';
  278. // Bank line
  279. if (! empty($conf->banque->enabled))
  280. {
  281. if ($conf->global->ADHERENT_BANK_USE || $object->fk_bank)
  282. {
  283. print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
  284. if ($object->fk_bank)
  285. {
  286. $bankline=new AccountLine($db);
  287. $result=$bankline->fetch($object->fk_bank);
  288. print $bankline->getNomUrl(1, 0, 'showall');
  289. }
  290. else
  291. {
  292. print $langs->trans("NoneF");
  293. }
  294. print '</td></tr>';
  295. }
  296. }
  297. print "</table>\n";
  298. print '</div>';
  299. print '</form>';
  300. dol_fiche_end();
  301. /*
  302. * Barre d'actions
  303. *
  304. */
  305. print '<div class="tabsAction">';
  306. if ($user->rights->adherent->cotisation->creer)
  307. {
  308. if (! $bankline->rappro)
  309. {
  310. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id."&action=edit\">".$langs->trans("Modify")."</a></div>";
  311. }
  312. else
  313. {
  314. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.$langs->trans("BankLineConciliated")."\" href=\"#\">".$langs->trans("Modify")."</a></div>";
  315. }
  316. }
  317. // Supprimer
  318. if ($user->rights->adherent->cotisation->creer)
  319. {
  320. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id."&action=delete\">".$langs->trans("Delete")."</a></div>\n";
  321. }
  322. print '</div>';
  323. print '<div class="fichecenter"><div class="fichehalfleft">';
  324. print '<a name="builddoc"></a>'; // ancre
  325. // Documents generes
  326. /*
  327. $filename = dol_sanitizeFileName($object->ref);
  328. $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
  329. $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id;
  330. $genallowed = $user->rights->facture->lire;
  331. $delallowed = $user->rights->facture->creer;
  332. print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  333. $somethingshown = $formfile->numoffiles;
  334. */
  335. // Show links to link elements
  336. //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription'));
  337. $somethingshown = $form->showLinkedObjectBlock($object, '');
  338. // Show links to link elements
  339. /*$linktoelem = $form->showLinkToObjectBlock($object,array('order'));
  340. if ($linktoelem) print ($somethingshown?'':'<br>').$linktoelem;
  341. */
  342. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  343. // List of actions on element
  344. /*
  345. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  346. $formactions = new FormActions($db);
  347. $somethingshown = $formactions->showactions($object, 'invoice', $socid, 1);
  348. */
  349. print '</div></div></div>';
  350. }
  351. // End of page
  352. llxFooter();
  353. $db->close();