card.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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", "banks"));
  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. $newdatestart = dol_mktime(GETPOST('datesubhour', 'int'), GETPOST('datesubmin', 'int'), 0, GETPOST('datesubmonth', 'int'), GETPOST('datesubday', 'int'), GETPOST('datesubyear', 'int'));
  71. $newdateend = dol_mktime(GETPOST('datesubendhour', 'int'), GETPOST('datesubendmin', 'int'), 0, GETPOST('datesubendmonth', 'int'), GETPOST('datesubendday', 'int'), GETPOST('datesubendyear', 'int'));
  72. if ($object->fk_bank > 0) {
  73. $accountline = new AccountLine($db);
  74. $result = $accountline->fetch($object->fk_bank);
  75. // If transaction consolidated
  76. if ($accountline->rappro) {
  77. $errmsg = $langs->trans("SubscriptionLinkedToConciliatedTransaction");
  78. } else {
  79. $accountline->datev = $newdatestart;
  80. $accountline->dateo = $newdatestart;
  81. $accountline->amount = $amount;
  82. $result = $accountline->update($user);
  83. if ($result < 0) {
  84. $errmsg = $accountline->error;
  85. }
  86. }
  87. }
  88. if (!$errmsg) {
  89. // Modify values
  90. $object->dateh = $newdatestart;
  91. $object->datef = $newdateend;
  92. $object->fk_type = $typeid;
  93. $object->note_public = $note;
  94. $object->note_private = $note;
  95. $object->amount = $amount;
  96. $result = $object->update($user);
  97. if ($result >= 0 && !count($object->errors)) {
  98. $db->commit();
  99. header("Location: card.php?rowid=".$object->id);
  100. exit;
  101. } else {
  102. $db->rollback();
  103. if ($object->error) {
  104. $errmsg = $object->error;
  105. } else {
  106. foreach ($object->errors as $error) {
  107. if ($errmsg) {
  108. $errmsg .= '<br>';
  109. }
  110. $errmsg .= $error;
  111. }
  112. }
  113. $action = '';
  114. }
  115. } else {
  116. $db->rollback();
  117. }
  118. }
  119. }
  120. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('adherent', 'cotisation', 'creer')) {
  121. $result = $object->fetch($rowid);
  122. $result = $object->delete($user);
  123. if ($result > 0) {
  124. header("Location: ".DOL_URL_ROOT."/adherents/card.php?rowid=".$object->fk_adherent);
  125. exit;
  126. } else {
  127. $errmesg = $adh->error;
  128. }
  129. }
  130. /*
  131. * View
  132. */
  133. $form = new Form($db);
  134. $help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
  135. llxHeader('', $langs->trans("SubscriptionCard"), $help_url);
  136. dol_htmloutput_errors($errmsg);
  137. if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'edit') {
  138. /********************************************
  139. *
  140. * Subscription card in edit mode
  141. *
  142. ********************************************/
  143. $object->fetch($rowid);
  144. $result = $adh->fetch($object->fk_adherent);
  145. $head = subscription_prepare_head($object);
  146. print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  147. print '<input type="hidden" name="token" value="'.newToken().'">';
  148. print "<input type=\"hidden\" name=\"action\" value=\"update\">";
  149. print "<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">";
  150. print "<input type=\"hidden\" name=\"fk_bank\" value=\"".$object->fk_bank."\">";
  151. print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), 0, 'payment');
  152. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  153. print "\n";
  154. print '<table class="border centpercent">';
  155. // Ref
  156. print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
  157. print '<td class="valeur">';
  158. print $form->showrefnav($object, 'rowid', $linkback, 1);
  159. print '</td></tr>';
  160. // Member
  161. $adh->ref = $adh->getFullName($langs);
  162. print '<tr>';
  163. print '<td>'.$langs->trans("Member").'</td>';
  164. print '<td class="valeur">'.$adh->getNomUrl(-1, 0, 'subscription').'</td>';
  165. print '</tr>';
  166. // Type
  167. print '<tr>';
  168. print '<td>'.$langs->trans("Type").'</td>';
  169. print '<td class="valeur">';
  170. print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOST("typeid") : $object->fk_type));
  171. print'</td></tr>';
  172. // Date start subscription
  173. print '<tr><td>'.$langs->trans("DateSubscription").'</td>';
  174. print '<td class="valeur">';
  175. print $form->selectDate($object->dateh, 'datesub', 1, 1, 0, 'update', 1);
  176. print '</td>';
  177. print '</tr>';
  178. // Date end subscription
  179. print '<tr><td>'.$langs->trans("DateEndSubscription").'</td>';
  180. print '<td class="valeur">';
  181. print $form->selectDate($object->datef, 'datesubend', 0, 0, 0, 'update', 1);
  182. print '</td>';
  183. print '</tr>';
  184. // Amount
  185. print '<tr><td>'.$langs->trans("Amount").'</td>';
  186. print '<td class="valeur">';
  187. print '<input type="text" class="flat width200" name="amount" value="'.price($object->amount).'"></td></tr>';
  188. // Label
  189. print '<tr><td>'.$langs->trans("Label").'</td>';
  190. print '<td class="valeur">';
  191. print '<input type="text" class="flat" name="note" value="'.$object->note_public.'"></td></tr>';
  192. // Bank line
  193. if (isModEnabled("banque") && (getDolGlobalString('ADHERENT_BANK_USE') || $object->fk_bank)) {
  194. print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
  195. if ($object->fk_bank) {
  196. $bankline = new AccountLine($db);
  197. $result = $bankline->fetch($object->fk_bank);
  198. print $bankline->getNomUrl(1, 0, 'showall');
  199. } else {
  200. print $langs->trans("NoneF");
  201. }
  202. print '</td></tr>';
  203. }
  204. print '</table>';
  205. print dol_get_fiche_end();
  206. print $form->buttonsSaveCancel();
  207. print '</form>';
  208. print "\n";
  209. }
  210. if ($rowid && $action != 'edit') {
  211. /********************************************
  212. *
  213. * Subscription card in view mode
  214. *
  215. ********************************************/
  216. $result = $object->fetch($rowid);
  217. $result = $adh->fetch($object->fk_adherent);
  218. $head = subscription_prepare_head($object);
  219. print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), -1, 'payment');
  220. // Confirmation to delete subscription
  221. if ($action == 'delete') {
  222. $formquestion=array();
  223. //$formquestion['text']='<b>'.$langs->trans("ThisWillAlsoDeleteBankRecord").'</b>';
  224. $text = $langs->trans("ConfirmDeleteSubscription");
  225. if (isModEnabled("banque") && getDolGlobalString('ADHERENT_BANK_USE')) {
  226. $text .= '<br>'.img_warning().' '.$langs->trans("ThisWillAlsoDeleteBankRecord");
  227. }
  228. print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("DeleteSubscription"), $text, "confirm_delete", $formquestion, 0, 1);
  229. }
  230. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  231. print '<input type="hidden" name="token" value="'.newToken().'">';
  232. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  233. dol_banner_tab($object, 'rowid', $linkback, 1);
  234. print '<div class="fichecenter">';
  235. print '<div class="underbanner clearboth"></div>';
  236. print '<table class="border centpercent tableforfield">';
  237. // Member
  238. $adh->ref = $adh->getFullName($langs);
  239. print '<tr>';
  240. print '<td class="titlefield">'.$langs->trans("Member").'</td><td class="valeur">'.$adh->getNomUrl(-1, 0, 'subscription').'</td>';
  241. print '</tr>';
  242. // Type
  243. print '<tr>';
  244. print '<td class="titlefield">'.$langs->trans("Type").'</td>';
  245. print '<td class="valeur">';
  246. if ($object->fk_type > 0 || $adh->typeid > 0) {
  247. $typeid = ($object->fk_type > 0 ? $object->fk_type : $adh->typeid);
  248. $adht->fetch($typeid);
  249. print $adht->getNomUrl(1);
  250. } else {
  251. print $langs->trans("NoType");
  252. }
  253. print '</td></tr>';
  254. // Date subscription
  255. print '<tr>';
  256. print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->dateh, 'day').'</td>';
  257. print '</tr>';
  258. // Date end subscription
  259. print '<tr>';
  260. print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dol_print_date($object->datef, 'day').'</td>';
  261. print '</tr>';
  262. // Amount
  263. print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur"><span class="amount">'.price($object->amount).'</span></td></tr>';
  264. // Label
  265. print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note_public)).'</td></tr>';
  266. // Bank line
  267. if (isModEnabled("banque") && (getDolGlobalString('ADHERENT_BANK_USE') || $object->fk_bank)) {
  268. print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
  269. if ($object->fk_bank > 0) {
  270. $bankline = new AccountLine($db);
  271. $result = $bankline->fetch($object->fk_bank);
  272. print $bankline->getNomUrl(1, 0, 'showall');
  273. } else {
  274. print $langs->trans("NoneF");
  275. }
  276. print '</td></tr>';
  277. }
  278. print "</table>\n";
  279. print '</div>';
  280. print '</form>';
  281. print dol_get_fiche_end();
  282. /*
  283. * Action bar
  284. */
  285. print '<div class="tabsAction">';
  286. if ($user->hasRight('adherent', 'cotisation', 'creer')) {
  287. if (empty($bankline->rappro) || empty($bankline)) {
  288. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".((int) $object->id).'&action=edit&token='.newToken().'">'.$langs->trans("Modify")."</a></div>";
  289. } else {
  290. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.$langs->trans("BankLineConciliated").'" href="#">'.$langs->trans("Modify")."</a></div>";
  291. }
  292. }
  293. // Delete
  294. if ($user->hasRight('adherent', 'cotisation', 'creer')) {
  295. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"]."?rowid=".((int) $object->id).'&action=delete&token='.newToken().'">'.$langs->trans("Delete")."</a></div>\n";
  296. }
  297. print '</div>';
  298. print '<div class="fichecenter"><div class="fichehalfleft">';
  299. print '<a name="builddoc"></a>'; // ancre
  300. // Generated documents
  301. /*
  302. $filename = dol_sanitizeFileName($object->ref);
  303. $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
  304. $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id;
  305. $genallowed = $user->hasRight('facture', 'lire');
  306. $delallowed = $user->hasRight('facture', 'creer');
  307. print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  308. $somethingshown = $formfile->numoffiles;
  309. */
  310. // Show links to link elements
  311. //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription'));
  312. $somethingshown = $form->showLinkedObjectBlock($object, '');
  313. // Show links to link elements
  314. /*$linktoelem = $form->showLinkToObjectBlock($object,array('order'));
  315. if ($linktoelem) print ($somethingshown?'':'<br>').$linktoelem;
  316. */
  317. print '</div><div class="fichehalfright">';
  318. // List of actions on element
  319. /*
  320. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  321. $formactions = new FormActions($db);
  322. $somethingshown = $formactions->showactions($object, $object->element, $socid, 1);
  323. */
  324. print '</div></div>';
  325. }
  326. // End of page
  327. llxFooter();
  328. $db->close();