card.php 14 KB

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