subscription.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2012-2017 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  8. * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/adherents/subscription.php
  25. * \ingroup member
  26. * \brief Onglet d'ajout, edition, suppression des adhesions d'un adherent
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  38. $langs->loadLangs(array("companies","bills","members","users","mails",'other'));
  39. $action=GETPOST('action', 'alpha');
  40. $confirm=GETPOST('confirm', 'alpha');
  41. $rowid=GETPOST('rowid', 'int')?GETPOST('rowid', 'int'):GETPOST('id', 'int');
  42. $typeid=GETPOST('typeid', 'int');
  43. // Load variable for pagination
  44. $limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'alpha');
  46. $sortorder = GETPOST('sortorder', 'alpha');
  47. $page = GETPOST('page', 'int');
  48. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  49. $offset = $limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. // Default sort order (if not yet defined by previous GETPOST)
  53. if (! $sortfield) $sortfield="c.rowid";
  54. if (! $sortorder) $sortorder="DESC";
  55. // Security check
  56. $result=restrictedArea($user, 'adherent', $rowid, '', 'cotisation');
  57. $object = new Adherent($db);
  58. $extrafields = new ExtraFields($db);
  59. $adht = new AdherentType($db);
  60. // fetch optionals attributes and labels
  61. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  62. $errmsg='';
  63. $errmsgs=array();
  64. $defaultdelay=1;
  65. $defaultdelayunit='y';
  66. if ($rowid)
  67. {
  68. // Load member
  69. $result = $object->fetch($rowid);
  70. // Define variables to know what current user can do on users
  71. $canadduser=($user->admin || $user->rights->user->user->creer);
  72. // Define variables to know what current user can do on properties of user linked to edited member
  73. if ($object->user_id)
  74. {
  75. // $user est le user qui edite, $object->user_id est l'id de l'utilisateur lies au membre edite
  76. $caneditfielduser=( (($user->id == $object->user_id) && $user->rights->user->self->creer)
  77. || (($user->id != $object->user_id) && $user->rights->user->user->creer) );
  78. $caneditpassworduser=( (($user->id == $object->user_id) && $user->rights->user->self->password)
  79. || (($user->id != $object->user_id) && $user->rights->user->user->password) );
  80. }
  81. }
  82. // Define variables to know what current user can do on members
  83. $canaddmember=$user->rights->adherent->creer;
  84. // Define variables to know what current user can do on properties of a member
  85. if ($rowid)
  86. {
  87. $caneditfieldmember=$user->rights->adherent->creer;
  88. }
  89. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  90. $hookmanager->initHooks(array('subscription'));
  91. // PDF
  92. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  93. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  94. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  95. /*
  96. * Actions
  97. */
  98. // Create third party from a member
  99. if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer)
  100. {
  101. if ($result > 0)
  102. {
  103. // Creation of thirdparty
  104. $company = new Societe($db);
  105. $result=$company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha'));
  106. if ($result < 0)
  107. {
  108. $langs->load("errors");
  109. setEventMessages($company->error, $company->errors, 'errors');
  110. }
  111. else
  112. {
  113. $action='addsubscription';
  114. }
  115. }
  116. else
  117. {
  118. setEventMessages($object->error, $object->errors, 'errors');
  119. }
  120. }
  121. if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
  122. {
  123. $error=0;
  124. if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
  125. {
  126. if ($_POST["userid"] != $user->id && $_POST["userid"] != $object->user_id)
  127. {
  128. $error++;
  129. setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
  130. }
  131. }
  132. if (! $error)
  133. {
  134. if ($_POST["userid"] != $object->user_id) // If link differs from currently in database
  135. {
  136. $result=$object->setUserId($_POST["userid"]);
  137. if ($result < 0) dol_print_error('', $object->error);
  138. $_POST['action']='';
  139. $action='';
  140. }
  141. }
  142. }
  143. if ($action == 'setsocid')
  144. {
  145. $error=0;
  146. if (! $error)
  147. {
  148. if (GETPOST('socid', 'int') != $object->fk_soc) // If link differs from currently in database
  149. {
  150. $sql ="SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
  151. $sql.=" WHERE fk_soc = '".GETPOST('socid', 'int')."'";
  152. $resql = $db->query($sql);
  153. if ($resql)
  154. {
  155. $obj = $db->fetch_object($resql);
  156. if ($obj && $obj->rowid > 0)
  157. {
  158. $othermember=new Adherent($db);
  159. $othermember->fetch($obj->rowid);
  160. $thirdparty=new Societe($db);
  161. $thirdparty->fetch(GETPOST('socid', 'int'));
  162. $error++;
  163. setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
  164. }
  165. }
  166. if (! $error)
  167. {
  168. $result=$object->setThirdPartyId(GETPOST('socid', 'int'));
  169. if ($result < 0) dol_print_error('', $object->error);
  170. $_POST['action']='';
  171. $action='';
  172. }
  173. }
  174. }
  175. }
  176. if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && ! $_POST["cancel"])
  177. {
  178. $error=0;
  179. $langs->load("banks");
  180. $result = $object->fetch($rowid);
  181. $result = $adht->fetch($object->typeid);
  182. // Subscription informations
  183. $datesubscription=0;
  184. $datesubend=0;
  185. $paymentdate=0;
  186. if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"])
  187. {
  188. $datesubscription=dol_mktime(0, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
  189. }
  190. if ($_POST["endyear"] && $_POST["endmonth"] && $_POST["endday"])
  191. {
  192. $datesubend=dol_mktime(0, 0, 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]);
  193. }
  194. if ($_POST["paymentyear"] && $_POST["paymentmonth"] && $_POST["paymentday"])
  195. {
  196. $paymentdate=dol_mktime(0, 0, 0, $_POST["paymentmonth"], $_POST["paymentday"], $_POST["paymentyear"]);
  197. }
  198. $amount=price2num(GETPOST("subscription", 'alpha')); // Amount of subscription
  199. $label=$_POST["label"];
  200. // Payment informations
  201. $accountid=$_POST["accountid"];
  202. $operation=$_POST["operation"]; // Payment mode
  203. $num_chq=$_POST["num_chq"];
  204. $emetteur_nom=$_POST["chqemetteur"];
  205. $emetteur_banque=$_POST["chqbank"];
  206. $option=$_POST["paymentsave"];
  207. if (empty($option)) $option='none';
  208. $sendalsoemail=GETPOST("sendmail", 'alpha');
  209. // Check parameters
  210. if (! $datesubscription)
  211. {
  212. $error++;
  213. $langs->load("errors");
  214. $errmsg=$langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateSubscription"));
  215. setEventMessages($errmsg, null, 'errors');
  216. $action='addsubscription';
  217. }
  218. if (GETPOST('end') && ! $datesubend)
  219. {
  220. $error++;
  221. $langs->load("errors");
  222. $errmsg=$langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateEndSubscription"));
  223. setEventMessages($errmsg, null, 'errors');
  224. $action='addsubscription';
  225. }
  226. if (! $datesubend)
  227. {
  228. $datesubend=dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd');
  229. }
  230. if (($option == 'bankviainvoice' || $option == 'bankdirect') && ! $paymentdate)
  231. {
  232. $error++;
  233. $errmsg=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment"));
  234. setEventMessages($errmsg, null, 'errors');
  235. $action='addsubscription';
  236. }
  237. // Check if a payment is mandatory or not
  238. if (! $error && $adht->subscription) // Member type need subscriptions
  239. {
  240. if (! is_numeric($amount))
  241. {
  242. // If field is '' or not a numeric value
  243. $errmsg=$langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
  244. setEventMessages($errmsg, null, 'errors');
  245. $error++;
  246. $action='addsubscription';
  247. }
  248. else
  249. {
  250. if (! empty($conf->banque->enabled) && $_POST["paymentsave"] != 'none')
  251. {
  252. if ($_POST["subscription"])
  253. {
  254. if (! $_POST["label"]) $errmsg=$langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
  255. if ($_POST["paymentsave"] != 'invoiceonly' && ! $_POST["operation"]) $errmsg=$langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
  256. if ($_POST["paymentsave"] != 'invoiceonly' && ! ($_POST["accountid"] > 0)) $errmsg=$langs->trans("ErrorFieldRequired", $langs->transnoentities("FinancialAccount"));
  257. }
  258. else
  259. {
  260. if ($_POST["accountid"]) $errmsg=$langs->trans("ErrorDoNotProvideAccountsIfNullAmount");
  261. }
  262. if ($errmsg)
  263. {
  264. $error++;
  265. setEventMessages($errmsg, null, 'errors');
  266. $error++;
  267. $action='addsubscription';
  268. }
  269. }
  270. }
  271. }
  272. // Record the subscription then complementary actions
  273. if (! $error && $action=='subscription')
  274. {
  275. $db->begin();
  276. // Create subscription
  277. $crowid=$object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
  278. if ($crowid <= 0)
  279. {
  280. $error++;
  281. $errmsg=$object->error;
  282. setEventMessages($object->error, $object->errors, 'errors');
  283. }
  284. if (! $error)
  285. {
  286. $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque);
  287. if ($result < 0)
  288. {
  289. $error++;
  290. setEventMessages($object->error, $object->errors, 'errors');
  291. }
  292. else
  293. {
  294. // If an invoice was created, it is into $object->invoice
  295. }
  296. }
  297. if (! $error)
  298. {
  299. $db->commit();
  300. }
  301. else
  302. {
  303. $db->rollback();
  304. $action = 'addsubscription';
  305. }
  306. if (! $error)
  307. {
  308. setEventMessages("SubscriptionRecorded", null, 'mesgs');
  309. }
  310. // Send email
  311. if (! $error)
  312. {
  313. // Send confirmation Email
  314. if ($object->email && $sendalsoemail) // $object is 'Adherent'
  315. {
  316. $subject = '';
  317. $msg= '';
  318. // Send subscription email
  319. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  320. $formmail=new FormMail($db);
  321. // Set output language
  322. $outputlangs = new Translate('', $conf);
  323. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  324. // Load traductions files requiredby by page
  325. $outputlangs->loadLangs(array("main", "members"));
  326. // Get email content from template
  327. $arraydefaultmessage=null;
  328. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
  329. if (! empty($labeltouse)) $arraydefaultmessage=$formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  330. if (! empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0)
  331. {
  332. $subject = $arraydefaultmessage->topic;
  333. $msg = $arraydefaultmessage->content;
  334. }
  335. $substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
  336. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  337. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  338. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
  339. // Attach a file ?
  340. $file='';
  341. $listofpaths=array();
  342. $listofnames=array();
  343. $listofmimes=array();
  344. if (is_object($object->invoice))
  345. {
  346. $invoicediroutput = $conf->facture->dir_output;
  347. $fileparams = dol_most_recent_file($invoicediroutput . '/' . $object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
  348. $file = $fileparams['fullname'];
  349. $listofpaths=array($file);
  350. $listofnames=array(basename($file));
  351. $listofmimes=array(dol_mimetype($file));
  352. }
  353. $moreinheader='X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n";
  354. $result=$object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofnames, $listofmimes, "", "", 0, -1, '', $moreinheader);
  355. if ($result < 0)
  356. {
  357. $errmsg=$object->error;
  358. setEventMessages($object->error, $object->errors, 'errors');
  359. }
  360. else
  361. {
  362. setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
  363. }
  364. }
  365. else
  366. {
  367. setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs');
  368. }
  369. }
  370. // Clean some POST vars
  371. if (! $error)
  372. {
  373. $_POST["subscription"]='';
  374. $_POST["accountid"]='';
  375. $_POST["operation"]='';
  376. $_POST["label"]='';
  377. $_POST["num_chq"]='';
  378. }
  379. }
  380. }
  381. /*
  382. * View
  383. */
  384. $form = new Form($db);
  385. $now=dol_now();
  386. $title=$langs->trans("Member") . " - " . $langs->trans("Subscriptions");
  387. $helpurl="EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros";
  388. llxHeader("", $title, $helpurl);
  389. $param='';
  390. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  391. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
  392. $param.= '&id='.$rowid;
  393. if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
  394. // Add $param from extra fields
  395. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  396. if ($rowid > 0)
  397. {
  398. $res=$object->fetch($rowid);
  399. if ($res < 0) { dol_print_error($db, $object->error); exit; }
  400. $adht->fetch($object->typeid);
  401. $head = member_prepare_head($object);
  402. $rowspan=10;
  403. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan++;
  404. if (! empty($conf->societe->enabled)) $rowspan++;
  405. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  406. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  407. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  408. dol_fiche_head($head, 'subscription', $langs->trans("Member"), -1, 'user');
  409. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  410. dol_banner_tab($object, 'rowid', $linkback);
  411. print '<div class="fichecenter">';
  412. print '<div class="fichehalfleft">';
  413. print '<div class="underbanner clearboth"></div>';
  414. print '<table class="border centpercent tableforfield">';
  415. // Login
  416. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  417. {
  418. print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
  419. }
  420. // Type
  421. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  422. // Morphy
  423. print '<tr><td>'.$langs->trans("MemberNature").'</td><td class="valeur" >'.$object->getmorphylib().'</td>';
  424. print '</tr>';
  425. // Company
  426. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$object->company.'</td></tr>';
  427. // Civility
  428. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'&nbsp;</td>';
  429. print '</tr>';
  430. // Password
  431. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  432. {
  433. print '<tr><td>'.$langs->trans("Password").'</td><td>'.preg_replace('/./i', '*', $object->pass);
  434. if ((! empty($object->pass) || ! empty($object->pass_crypted)) && empty($object->user_id))
  435. {
  436. $langs->load("errors");
  437. $htmltext=$langs->trans("WarningPasswordSetWithNoAccount");
  438. print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
  439. }
  440. print '</td></tr>';
  441. }
  442. print '</table>';
  443. print '</div>';
  444. print '<div class="fichehalfright"><div class="ficheaddleft">';
  445. print '<div class="underbanner clearboth"></div>';
  446. print '<table class="border tableforfield" width="100%">';
  447. // Birthday
  448. print '<tr><td class="titlefield">'.$langs->trans("Birthday").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
  449. // Public
  450. print '<tr><td>'.$langs->trans("Public").'</td><td class="valeur">'.yn($object->public).'</td></tr>';
  451. // Categories
  452. if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire))
  453. {
  454. print '<tr><td>' . $langs->trans("Categories") . '</td>';
  455. print '<td colspan="2">';
  456. print $form->showCategories($object->id, 'member', 1);
  457. print '</td></tr>';
  458. }
  459. // Other attributes
  460. $cols=2;
  461. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  462. // Date end subscription
  463. print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
  464. if ($object->datefin)
  465. {
  466. print dol_print_date($object->datefin, 'day');
  467. if ($object->hasDelay()) {
  468. print " ".img_warning($langs->trans("Late"));
  469. }
  470. }
  471. else
  472. {
  473. if (! $adht->subscription)
  474. {
  475. print $langs->trans("SubscriptionNotRecorded");
  476. if ($object->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
  477. }
  478. else
  479. {
  480. print $langs->trans("SubscriptionNotReceived");
  481. if ($object->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
  482. }
  483. }
  484. print '</td></tr>';
  485. // Third party Dolibarr
  486. if (! empty($conf->societe->enabled))
  487. {
  488. print '<tr><td>';
  489. print '<table class="nobordernopadding" width="100%"><tr><td>';
  490. print $langs->trans("LinkedToDolibarrThirdParty");
  491. print '</td>';
  492. if ($action != 'editthirdparty' && $user->rights->adherent->creer) print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editthirdparty&amp;rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToThirdParty'), 1).'</a></td>';
  493. print '</tr></table>';
  494. print '</td><td colspan="2" class="valeur">';
  495. if ($action == 'editthirdparty')
  496. {
  497. $htmlname='socid';
  498. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
  499. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  500. print '<input type="hidden" name="action" value="set'.$htmlname.'">';
  501. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  502. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  503. print '<tr><td>';
  504. print $form->select_company($object->fk_soc, 'socid', '', 1);
  505. print '</td>';
  506. print '<td class="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  507. print '</tr></table></form>';
  508. }
  509. else
  510. {
  511. if ($object->fk_soc)
  512. {
  513. $company=new Societe($db);
  514. $result=$company->fetch($object->fk_soc);
  515. print $company->getNomUrl(1);
  516. }
  517. else
  518. {
  519. print $langs->trans("NoThirdPartyAssociatedToMember");
  520. }
  521. }
  522. print '</td></tr>';
  523. }
  524. // Login Dolibarr
  525. print '<tr><td>';
  526. print '<table class="nobordernopadding" width="100%"><tr><td>';
  527. print $langs->trans("LinkedToDolibarrUser");
  528. print '</td>';
  529. if ($action != 'editlogin' && $user->rights->adherent->creer)
  530. {
  531. print '<td class="right">';
  532. if ($user->rights->user->user->creer)
  533. {
  534. print '<a href="'.$_SERVER["PHP_SELF"].'?action=editlogin&amp;rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'), 1).'</a>';
  535. }
  536. print '</td>';
  537. }
  538. print '</tr></table>';
  539. print '</td><td colspan="2" class="valeur">';
  540. if ($action == 'editlogin')
  541. {
  542. $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', '');
  543. }
  544. else
  545. {
  546. if ($object->user_id)
  547. {
  548. $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'none');
  549. }
  550. else print $langs->trans("NoDolibarrAccess");
  551. }
  552. print '</td></tr>';
  553. print "</table>\n";
  554. print "</div></div></div>\n";
  555. print '<div style="clear:both"></div>';
  556. dol_fiche_end();
  557. print '</form>';
  558. /*
  559. * Action buttons
  560. */
  561. // Button to create a new subscription if member no draft neither resiliated
  562. if ($user->rights->adherent->cotisation->creer)
  563. {
  564. if ($action != 'addsubscription' && $action != 'create_thirdparty')
  565. {
  566. print '<div class="tabsAction">';
  567. if ($object->statut > 0) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'&action=addsubscription">'.$langs->trans("AddSubscription")."</a></div>";
  568. else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a></div>';
  569. print '</div>';
  570. }
  571. }
  572. /*
  573. * List of subscriptions
  574. */
  575. if ($action != 'addsubscription' && $action != 'create_thirdparty')
  576. {
  577. $sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type,";
  578. $sql.= " c.rowid as crowid, c.subscription,";
  579. $sql.= " c.datec, c.fk_type as cfk_type,";
  580. $sql.= " c.dateadh as dateh,";
  581. $sql.= " c.datef,";
  582. $sql.= " c.fk_bank,";
  583. $sql.= " b.rowid as bid,";
  584. $sql.= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code";
  585. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
  586. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
  587. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  588. $sql.= " WHERE d.rowid = c.fk_adherent AND d.rowid=".$rowid;
  589. $sql.= $db->order($sortfield, $sortorder);
  590. $result = $db->query($sql);
  591. if ($result)
  592. {
  593. $subscriptionstatic=new Subscription($db);
  594. $num = $db->num_rows($result);
  595. $i = 0;
  596. print '<table class="noborder" width="100%">'."\n";
  597. print '<tr class="liste_titre">';
  598. print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder);
  599. print '<td class="center">'.$langs->trans("DateCreation").'</td>';
  600. print '<td align="center">'.$langs->trans("Type").'</td>';
  601. print '<td class="center">'.$langs->trans("DateStart").'</td>';
  602. print '<td class="center">'.$langs->trans("DateEnd").'</td>';
  603. print '<td class="right">'.$langs->trans("Amount").'</td>';
  604. if (! empty($conf->banque->enabled))
  605. {
  606. print '<td class="right">'.$langs->trans("Account").'</td>';
  607. }
  608. print "</tr>\n";
  609. $accountstatic=new Account($db);
  610. $adh = new Adherent($db);
  611. $adht = new AdherentType($db);
  612. while ($i < $num)
  613. {
  614. $objp = $db->fetch_object($result);
  615. $adh->id = $objp->rowid;
  616. $adh->typeid = $objp->type;
  617. $subscriptionstatic->ref=$objp->crowid;
  618. $subscriptionstatic->id=$objp->crowid;
  619. $typeid = ($objp->cfk_type > 0 ? $objp->cfk_type : $adh->typeid);
  620. if ($typeid > 0)
  621. {
  622. $adht->fetch($typeid);
  623. }
  624. print '<tr class="oddeven">';
  625. print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
  626. print '<td class="center">'.dol_print_date($db->jdate($objp->datec), 'dayhour')."</td>\n";
  627. print '<td class="center">';
  628. if ($typeid > 0) {
  629. print $adht->getNomUrl(1);
  630. }
  631. print '</td>';
  632. print '<td class="center">'.dol_print_date($db->jdate($objp->dateh), 'day')."</td>\n";
  633. print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day')."</td>\n";
  634. print '<td class="right">'.price($objp->subscription).'</td>';
  635. if (! empty($conf->banque->enabled))
  636. {
  637. print '<td class="right">';
  638. if ($objp->bid)
  639. {
  640. $accountstatic->label=$objp->label;
  641. $accountstatic->id=$objp->baid;
  642. $accountstatic->number=$objp->number;
  643. $accountstatic->account_number=$objp->account_number;
  644. $accountstatic->currency_code=$objp->currency_code;
  645. if (! empty($conf->accounting->enabled) && $objp->fk_accountancy_journal > 0)
  646. {
  647. $accountingjournal = new AccountingJournal($db);
  648. $accountingjournal->fetch($objp->fk_accountancy_journal);
  649. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  650. }
  651. $accountstatic->ref=$objp->ref;
  652. print $accountstatic->getNomUrl(1);
  653. }
  654. else
  655. {
  656. print '&nbsp;';
  657. }
  658. print '</td>';
  659. }
  660. print "</tr>";
  661. $i++;
  662. }
  663. print "</table>";
  664. }
  665. else
  666. {
  667. dol_print_error($db);
  668. }
  669. }
  670. if (($action != 'addsubscription' && $action != 'create_thirdparty'))
  671. {
  672. // Shon online payment link
  673. $useonlinepayment = (! empty($conf->paypal->enabled) || ! empty($conf->stripe->enabled) || ! empty($conf->paybox->enabled));
  674. if ($useonlinepayment)
  675. {
  676. print '<br>';
  677. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  678. print showOnlinePaymentUrl('membersubscription', $object->ref);
  679. print '<br>';
  680. }
  681. }
  682. /*
  683. * Add new subscription form
  684. */
  685. if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->rights->adherent->cotisation->creer)
  686. {
  687. print '<br>';
  688. print load_fiche_titre($langs->trans("NewCotisation"));
  689. // Define default choice for complementary actions
  690. $bankdirect=0; // 1 means option by default is write to bank direct with no invoice
  691. $invoiceonly=0; // 1 means option by default is invoice only
  692. $bankviainvoice=0; // 1 means option by default is write to bank via invoice
  693. if (GETPOST('paymentsave'))
  694. {
  695. if (GETPOST('paymentsave') == 'bankdirect') $bankdirect=1;
  696. if (GETPOST('paymentsave') == 'invoiceonly') $invoiceonly=1;
  697. if (GETPOST('paymentsave') == 'bankviainvoice') $bankviainvoice=1;
  698. }
  699. else
  700. {
  701. if (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankviainvoice' && ! empty($conf->banque->enabled) && ! empty($conf->societe->enabled) && ! empty($conf->facture->enabled)) $bankviainvoice=1;
  702. elseif (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && ! empty($conf->banque->enabled)) $bankdirect=1;
  703. elseif (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && ! empty($conf->banque->enabled) && ! empty($conf->societe->enabled) && ! empty($conf->facture->enabled)) $invoiceonly=1;
  704. }
  705. print "\n\n<!-- Form add subscription -->\n";
  706. if ($conf->use_javascript_ajax)
  707. {
  708. //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly.'-'.empty($conf->global->ADHERENT_BANK_USE));
  709. print "\n".'<script type="text/javascript" language="javascript">';
  710. print '$(document).ready(function () {
  711. $(".bankswitchclass, .bankswitchclass2").'.(($bankdirect||$bankviainvoice)?'show()':'hide()').';
  712. $("#none, #invoiceonly").click(function() {
  713. $(".bankswitchclass").hide();
  714. $(".bankswitchclass2").hide();
  715. });
  716. $("#bankdirect, #bankviainvoice").click(function() {
  717. $(".bankswitchclass").show();
  718. $(".bankswitchclass2").show();
  719. });
  720. $("#selectoperation").change(function() {
  721. var code = $(this).val();
  722. if (code == "CHQ")
  723. {
  724. $(".fieldrequireddyn").addClass("fieldrequired");
  725. if ($("#fieldchqemetteur").val() == "")
  726. {
  727. $("#fieldchqemetteur").val($("#memberlabel").val());
  728. }
  729. }
  730. else
  731. {
  732. $(".fieldrequireddyn").removeClass("fieldrequired");
  733. }
  734. });
  735. ';
  736. if (GETPOST('paymentsave')) print '$("#'.GETPOST('paymentsave').'").prop("checked",true);';
  737. print '});';
  738. print '</script>'."\n";
  739. }
  740. // Confirm create third party
  741. if ($action == 'create_thirdparty')
  742. {
  743. $companyalias='';
  744. $fullname = $object->getFullName($langs);
  745. if ($object->morphy == 'mor')
  746. {
  747. $companyname=$object->company;
  748. if (! empty($fullname)) $companyalias=$fullname;
  749. }
  750. else
  751. {
  752. $companyname=$fullname;
  753. if (! empty($object->company)) $companyalias=$object->company;
  754. }
  755. // Create a form array
  756. $formquestion=array(
  757. array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
  758. array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
  759. );
  760. // If customer code was forced to "required", we ask it at creation to avoid error later
  761. if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
  762. {
  763. $tmpcompany = new Societe($db);
  764. $tmpcompany->name=$companyname;
  765. $tmpcompany->get_codeclient($tmpcompany, 0);
  766. $customercode = $tmpcompany->code_client;
  767. $formquestion[]=array(
  768. 'label' => $langs->trans("CustomerCode"),
  769. 'type' => 'text',
  770. 'name' => 'customercode',
  771. 'value' => $customercode,
  772. 'morecss' => 'minwidth300',
  773. 'moreattr' => 'maxlength="128"',
  774. );
  775. }
  776. // @TODO Add other extrafields mandatory for thirdparty creation
  777. print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 1);
  778. }
  779. print '<form name="subscription" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  780. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  781. print '<input type="hidden" name="action" value="subscription">';
  782. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  783. print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
  784. print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($object->company).'">';
  785. dol_fiche_head('');
  786. print "<table class=\"border\" width=\"100%\">\n";
  787. print '<tbody>';
  788. $today=dol_now();
  789. $datefrom=0;
  790. $dateto=0;
  791. $paymentdate=-1;
  792. // Date payment
  793. if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday'))
  794. {
  795. $paymentdate=dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear'));
  796. }
  797. print '<tr>';
  798. // Date start subscription
  799. print '<td class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
  800. if (GETPOST('reday'))
  801. {
  802. $datefrom=dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  803. }
  804. if (! $datefrom)
  805. {
  806. $datefrom=$object->datevalid;
  807. if ($object->datefin > 0)
  808. {
  809. $datefrom=dol_time_plus_duree($object->datefin, 1, 'd');
  810. }
  811. }
  812. print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1);
  813. print "</td></tr>";
  814. // Date end subscription
  815. if (GETPOST('endday'))
  816. {
  817. $dateto=dol_mktime(0, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
  818. }
  819. if (! $dateto)
  820. {
  821. $dateto=-1; // By default, no date is suggested
  822. }
  823. print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
  824. print $form->selectDate($dateto, 'end', '', '', '', "subscription", 1, 0);
  825. print "</td></tr>";
  826. if ($adht->subscription)
  827. {
  828. // Amount
  829. print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="subscription" size="6" value="'.GETPOST('subscription').'"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
  830. // Label
  831. print '<tr><td>'.$langs->trans("Label").'</td>';
  832. print '<td><input name="label" type="text" size="32" value="';
  833. if (empty($conf->global->MEMBER_NO_DEFAULT_LABEL)) print $langs->trans("Subscription").' '.dol_print_date(($datefrom?$datefrom:time()), "%Y");
  834. print '"></td></tr>';
  835. // Complementary action
  836. if (! empty($conf->banque->enabled) || ! empty($conf->facture->enabled))
  837. {
  838. $company=new Societe($db);
  839. if ($object->fk_soc)
  840. {
  841. $result=$company->fetch($object->fk_soc);
  842. }
  843. // Title payments
  844. //print '<tr><td colspan="2"><b>'.$langs->trans("Payment").'</b></td></tr>';
  845. // No more action
  846. print '<tr><td class="tdtop fieldrequired">'.$langs->trans('MoreActions');
  847. print '</td>';
  848. print '<td>';
  849. print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($invoiceonly) && empty($bankviainvoice)?' checked':'').'> '.$langs->trans("None").'<br>';
  850. // Add entry into bank accoun
  851. if (! empty($conf->banque->enabled))
  852. {
  853. print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(! empty($bankdirect)?' checked':'');
  854. print '> '.$langs->trans("MoreActionBankDirect").'<br>';
  855. }
  856. // Add invoice with no payments
  857. if (! empty($conf->societe->enabled) && ! empty($conf->facture->enabled))
  858. {
  859. print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(! empty($invoiceonly)?' checked':'');
  860. //if (empty($object->fk_soc)) print ' disabled';
  861. print '> '.$langs->trans("MoreActionInvoiceOnly");
  862. if ($object->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  863. else
  864. {
  865. print ' (';
  866. if (empty($object->fk_soc)) print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
  867. print $langs->trans("NoThirdPartyAssociatedToMember");
  868. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  869. print $langs->trans("CreateDolibarrThirdParty");
  870. print '</a>)';
  871. }
  872. if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') print '. '.$langs->trans("NoVatOnSubscription", 0);
  873. if (! empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (! empty($conf->product->enabled) || ! empty($conf->service->enabled)))
  874. {
  875. $prodtmp=new Product($db);
  876. $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
  877. print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
  878. }
  879. print '<br>';
  880. }
  881. // Add invoice with payments
  882. if (! empty($conf->banque->enabled) && ! empty($conf->societe->enabled) && ! empty($conf->facture->enabled))
  883. {
  884. print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.(! empty($bankviainvoice)?' checked':'');
  885. //if (empty($object->fk_soc)) print ' disabled';
  886. print '> '.$langs->trans("MoreActionBankViaInvoice");
  887. if ($object->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  888. else
  889. {
  890. print ' (';
  891. if (empty($object->fk_soc)) print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
  892. print $langs->trans("NoThirdPartyAssociatedToMember");
  893. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  894. print $langs->trans("CreateDolibarrThirdParty");
  895. print '</a>)';
  896. }
  897. if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') print '. '.$langs->trans("NoVatOnSubscription", 0);
  898. if (! empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (! empty($conf->product->enabled) || ! empty($conf->service->enabled)))
  899. {
  900. $prodtmp=new Product($db);
  901. $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
  902. print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
  903. }
  904. print '<br>';
  905. }
  906. print '</td></tr>';
  907. // Bank account
  908. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
  909. $form->select_comptes(GETPOST('accountid'), 'accountid', 0, '', 1);
  910. print "</td></tr>\n";
  911. // Payment mode
  912. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
  913. $form->select_types_paiements(GETPOST('operation'), 'operation', '', 2);
  914. print "</td></tr>\n";
  915. // Date of payment
  916. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
  917. print $form->selectDate(isset($paymentdate)?$paymentdate:-1, 'payment', 0, 0, 1, 'subscription', 1, 1);
  918. print "</td></tr>\n";
  919. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
  920. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  921. print '</td>';
  922. print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(! GETPOST('num_chq')?'':GETPOST('num_chq')).'"></td></tr>';
  923. print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
  924. print ' <em>('.$langs->trans("ChequeMaker").')</em>';
  925. print '</td>';
  926. print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(! GETPOST('chqemetteur')?'':GETPOST('chqemetteur')).'"></td></tr>';
  927. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
  928. print ' <em>('.$langs->trans("ChequeBank").')</em>';
  929. print '</td>';
  930. print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(! GETPOST('chqbank')?'':GETPOST('chqbank')).'"></td></tr>';
  931. }
  932. }
  933. print '<tr><td colspan="2">&nbsp;</td>';
  934. print '<tr><td width="30%">'.$langs->trans("SendAcknowledgementByMail").'</td>';
  935. print '<td>';
  936. if (! $object->email)
  937. {
  938. print $langs->trans("NoEMail");
  939. }
  940. else
  941. {
  942. $adht = new AdherentType($db);
  943. $adht->fetch($object->typeid);
  944. // Send subscription email
  945. $subject = '';
  946. $msg= '';
  947. // Send subscription email
  948. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  949. $formmail=new FormMail($db);
  950. // Set output language
  951. $outputlangs = new Translate('', $conf);
  952. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  953. // Load traductions files requiredby by page
  954. $outputlangs->loadLangs(array("main", "members"));
  955. // Get email content from template
  956. $arraydefaultmessage=null;
  957. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
  958. if (! empty($labeltouse)) $arraydefaultmessage=$formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  959. if (! empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0)
  960. {
  961. $subject = $arraydefaultmessage->topic;
  962. $msg = $arraydefaultmessage->content;
  963. }
  964. $substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
  965. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  966. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  967. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
  968. $tmp='<input name="sendmail" type="checkbox"'.(GETPOST('sendmail', 'alpha')?' checked':(! empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL)?' checked':'')).'>';
  969. $helpcontent='';
  970. $helpcontent.='<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
  971. $helpcontent.='<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
  972. $helpcontent.='<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
  973. $helpcontent.=$subjecttosend."\n";
  974. $helpcontent.="<br>";
  975. $helpcontent.='<b>'.$langs->trans("MailText").'</b>:<br>';
  976. $helpcontent.=dol_htmlentitiesbr($texttosend)."\n";
  977. print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
  978. }
  979. print '</td></tr>';
  980. print '</tbody>';
  981. print '</table>';
  982. dol_fiche_end();
  983. print '<div class="center">';
  984. print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
  985. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  986. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  987. print '</div>';
  988. print '</form>';
  989. print "\n<!-- End form subscription -->\n\n";
  990. }
  991. //print '</td></tr>';
  992. //print '</table>';
  993. }
  994. else
  995. {
  996. $langs->load("errors");
  997. print $langs->trans("ErrorRecordNotFound");
  998. }
  999. // End of page
  1000. llxFooter();
  1001. $db->close();