PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/adherent/card_subscriptions.old.php

https://bitbucket.org/speedealing/speedealing
PHP | 1015 lines | 780 code | 133 blank | 102 comment | 207 complexity | 4fe1150c8147fe0aed03616cc9c397c6 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/adherents/card_subscriptions.php
  22. * \ingroup member
  23. * \brief Onglet d'ajout, edition, suppression des adhesions d'un adherent
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/adherents/class/cotisation.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  33. $langs->load("companies");
  34. $langs->load("bills");
  35. $langs->load("members");
  36. $langs->load("users");
  37. $langs->load("mails");
  38. $action=GETPOST('action','alpha');
  39. $confirm=GETPOST('confirm','alpha');
  40. $rowid=GETPOST('rowid','int');
  41. $typeid=GETPOST('typeid','int');
  42. // Security check
  43. $result=restrictedArea($user,'adherent',$rowid);
  44. $object = new Adherent($db);
  45. $extrafields = new ExtraFields($db);
  46. $adht = new AdherentType($db);
  47. $errmsg='';
  48. $errmsgs=array();
  49. $defaultdelay=1;
  50. $defaultdelayunit='y';
  51. if ($rowid)
  52. {
  53. // Load member
  54. $result = $object->fetch($rowid);
  55. // Define variables to know what current user can do on users
  56. $canadduser=($user->admin || $user->rights->user->user->creer);
  57. // Define variables to know what current user can do on properties of user linked to edited member
  58. if ($object->user_id)
  59. {
  60. // $user est le user qui edite, $object->user_id est l'id de l'utilisateur lies au membre edite
  61. $caneditfielduser=( (($user->id == $object->user_id) && $user->rights->user->self->creer)
  62. || (($user->id != $object->user_id) && $user->rights->user->user->creer) );
  63. $caneditpassworduser=( (($user->id == $object->user_id) && $user->rights->user->self->password)
  64. || (($user->id != $object->user_id) && $user->rights->user->user->password) );
  65. }
  66. }
  67. // Define variables to know what current user can do on members
  68. $canaddmember=$user->rights->adherent->creer;
  69. // Define variables to know what current user can do on properties of a member
  70. if ($rowid)
  71. {
  72. $caneditfieldmember=$user->rights->adherent->creer;
  73. }
  74. /*
  75. * Actions
  76. */
  77. // Create third party from a member
  78. if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer)
  79. {
  80. if ($result > 0)
  81. {
  82. // Creation user
  83. $company = new Societe($db);
  84. $result=$company->create_from_member($object,$_POST["companyname"]);
  85. if ($result < 0)
  86. {
  87. $langs->load("errors");
  88. $errmsg=$langs->trans($company->error);
  89. $errmsgs=$company->errors;
  90. }
  91. else
  92. {
  93. $action='addsubscription';
  94. }
  95. }
  96. else
  97. {
  98. $errmsg=$object->error;
  99. }
  100. }
  101. if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
  102. {
  103. $error=0;
  104. if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
  105. {
  106. if ($_POST["userid"] != $user->id && $_POST["userid"] != $object->user_id)
  107. {
  108. $error++;
  109. $mesg='<div class="error">'.$langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly").'</div>';
  110. }
  111. }
  112. if (! $error)
  113. {
  114. if ($_POST["userid"] != $object->user_id) // If link differs from currently in database
  115. {
  116. $result=$object->setUserId($_POST["userid"]);
  117. if ($result < 0) dol_print_error($object->db,$object->error);
  118. $_POST['action']='';
  119. $action='';
  120. }
  121. }
  122. }
  123. if ($action == 'setsocid')
  124. {
  125. $error=0;
  126. if (! $error)
  127. {
  128. if (GETPOST('socid','int') != $object->fk_soc) // If link differs from currently in database
  129. {
  130. $sql ="SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
  131. $sql.=" WHERE fk_soc = '".GETPOST('socid','int')."'";
  132. $resql = $db->query($sql);
  133. if ($resql)
  134. {
  135. $obj = $db->fetch_object($resql);
  136. if ($obj && $obj->rowid > 0)
  137. {
  138. $othermember=new Adherent($db);
  139. $othermember->fetch($obj->rowid);
  140. $thirdparty=new Societe($db);
  141. $thirdparty->fetch(GETPOST('socid','int'));
  142. $error++;
  143. $mesg='<div class="error">'.$langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty",$othermember->getFullName($langs),$othermember->login,$thirdparty->name).'</div>';
  144. }
  145. }
  146. if (! $error)
  147. {
  148. $result=$object->setThirdPartyId(GETPOST('socid','int'));
  149. if ($result < 0) dol_print_error($object->db,$object->error);
  150. $_POST['action']='';
  151. $action='';
  152. }
  153. }
  154. }
  155. }
  156. if ($user->rights->adherent->cotisation->creer && $action == 'cotisation' && ! $_POST["cancel"])
  157. {
  158. $error=0;
  159. $langs->load("banks");
  160. $result=$object->fetch($rowid);
  161. $result=$adht->fetch($object->typeid);
  162. // Subscription informations
  163. $datecotisation=0;
  164. $datesubend=0;
  165. $paymentdate=0;
  166. if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"])
  167. {
  168. $datecotisation=dol_mktime(0, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
  169. }
  170. if ($_POST["endyear"] && $_POST["endmonth"] && $_POST["endday"])
  171. {
  172. $datesubend=dol_mktime(0, 0, 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]);
  173. }
  174. if ($_POST["paymentyear"] && $_POST["paymentmonth"] && $_POST["paymentday"])
  175. {
  176. $paymentdate=dol_mktime(0, 0, 0, $_POST["paymentmonth"], $_POST["paymentday"], $_POST["paymentyear"]);
  177. }
  178. $cotisation=$_POST["cotisation"]; // Amount of subscription
  179. $label=$_POST["label"];
  180. // Payment informations
  181. $accountid=$_POST["accountid"];
  182. $operation=$_POST["operation"]; // Payment mode
  183. $num_chq=$_POST["num_chq"];
  184. $emetteur_nom=$_POST["chqemetteur"];
  185. $emetteur_banque=$_POST["chqbank"];
  186. $option=$_POST["paymentsave"];
  187. if (empty($option)) $option='none';
  188. // Check parameters
  189. if (! $datecotisation)
  190. {
  191. $error++;
  192. $langs->load("errors");
  193. $errmsg=$langs->trans("ErrorBadDateFormat",$langs->transnoentitiesnoconv("DateSubscription"));
  194. $action='addsubscription';
  195. }
  196. if (GETPOST('end') && ! $datesubend)
  197. {
  198. $error++;
  199. $langs->load("errors");
  200. $errmsg=$langs->trans("ErrorBadDateFormat",$langs->transnoentitiesnoconv("DateEndSubscription"));
  201. $action='addsubscription';
  202. }
  203. if (! $datesubend)
  204. {
  205. $datesubend=dol_time_plus_duree(dol_time_plus_duree($datecotisation,$defaultdelay,$defaultdelayunit),-1,'d');
  206. }
  207. if (($option == 'bankviainvoice' || $option == 'bankdirect') && ! $paymentdate)
  208. {
  209. $error++;
  210. $errmsg=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment"));
  211. $action='addsubscription';
  212. }
  213. // Check if a payment is mandatory or not
  214. if (! $error && $adht->cotisation) // Type adherent soumis a cotisation
  215. {
  216. if (! is_numeric($_POST["cotisation"]))
  217. {
  218. // If field is '' or not a numeric value
  219. $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount"));
  220. $error++;
  221. $action='addsubscription';
  222. }
  223. else
  224. {
  225. if (! empty($conf->banque->enabled) && $_POST["paymentsave"] != 'none')
  226. {
  227. if ($_POST["cotisation"])
  228. {
  229. if (! $_POST["label"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
  230. if ($_POST["paymentsave"] != 'invoiceonly' && ! $_POST["operation"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode"));
  231. if ($_POST["paymentsave"] != 'invoiceonly' && ! $_POST["accountid"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("FinancialAccount"));
  232. }
  233. else
  234. {
  235. if ($_POST["accountid"]) $errmsg=$langs->trans("ErrorDoNotProvideAccountsIfNullAmount");
  236. }
  237. if ($errmsg) $action='addsubscription';
  238. }
  239. }
  240. }
  241. if (! $error && $action=='cotisation')
  242. {
  243. $db->begin();
  244. // Create subscription
  245. $crowid=$object->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $option);
  246. if ($crowid <= 0)
  247. {
  248. $error++;
  249. $errmsg=$object->error;
  250. $errmsgs=$object->errors;
  251. }
  252. if (! $error)
  253. {
  254. // Insert into bank account directlty (if option choosed for) + link to llx_cotisation if option is 'bankdirect'
  255. if ($option == 'bankdirect' && $accountid)
  256. {
  257. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  258. $acct=new Account($db);
  259. $result=$acct->fetch($accountid);
  260. $dateop=$paymentdate;
  261. $insertid=$acct->addline($dateop, $operation, $label, $cotisation, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
  262. if ($insertid > 0)
  263. {
  264. $inserturlid=$acct->add_url_line($insertid, $object->id, DOL_URL_ROOT.'/adherents/fiche.php?rowid=', $object->getFullname($langs), 'member');
  265. if ($inserturlid > 0)
  266. {
  267. // Met a jour la table cotisation
  268. $sql ="UPDATE ".MAIN_DB_PREFIX."cotisation SET fk_bank=".$insertid;
  269. $sql.=" WHERE rowid=".$crowid;
  270. dol_syslog("card_subscriptions::cotisation sql=".$sql);
  271. $resql = $db->query($sql);
  272. if (! $resql)
  273. {
  274. $error++;
  275. $errmsg=$db->lasterror();
  276. }
  277. }
  278. else
  279. {
  280. $error++;
  281. $errmsg=$acct->error;
  282. }
  283. }
  284. else
  285. {
  286. $error++;
  287. $errmsg=$acct->error;
  288. }
  289. }
  290. // If option choosed, we create invoice
  291. if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly')
  292. {
  293. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  294. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
  295. $invoice=new Facture($db);
  296. $customer=new Societe($db);
  297. $result=$customer->fetch($object->fk_soc);
  298. if ($result <= 0)
  299. {
  300. $errmsg=$customer->error;
  301. $error++;
  302. }
  303. // Create draft invoice
  304. $invoice->type=0;
  305. $invoice->cond_reglement_id=$customer->cond_reglement_id;
  306. if (empty($invoice->cond_reglement_id))
  307. {
  308. $paymenttermstatic=new PaymentTerm($db);
  309. $invoice->cond_reglement_id=$paymenttermstatic->getDefaultId();
  310. if (empty($invoice->cond_reglement_id))
  311. {
  312. $error++;
  313. $errmsg='ErrorNoPaymentTermRECEPFound';
  314. }
  315. }
  316. $invoice->socid=$object->fk_soc;
  317. $invoice->date=$datecotisation;
  318. $result=$invoice->create($user);
  319. if ($result <= 0)
  320. {
  321. $errmsg=$invoice->error;
  322. $error++;
  323. }
  324. // Add line to draft invoice
  325. $idprodsubscription=0;
  326. $vattouse=get_default_tva($mysoc, $customer, $idprodsubscription);
  327. //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
  328. $result=$invoice->addline($invoice->id,$label,0,1,$vattouse,0,0,$idprodsubscription,0,$datecotisation,$datesubend,0,0,'','TTC',$cotisation,1);
  329. if ($result <= 0)
  330. {
  331. $errmsg=$invoice->error;
  332. $error++;
  333. }
  334. // Validate invoice
  335. $result=$invoice->validate($user);
  336. // Add payment onto invoice
  337. if ($option == 'bankviainvoice' && $accountid)
  338. {
  339. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  340. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  341. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  342. // Creation de la ligne paiement
  343. $amounts[$invoice->id] = price2num($cotisation);
  344. $paiement = new Paiement($db);
  345. $paiement->datepaye = $paymentdate;
  346. $paiement->amounts = $amounts;
  347. $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement');
  348. $paiement->num_paiement = $num_chq;
  349. $paiement->note = $label;
  350. if (! $error)
  351. {
  352. $paiement_id = $paiement->create($user);
  353. if (! $paiement_id > 0)
  354. {
  355. $errmsg=$paiement->error;
  356. $error++;
  357. }
  358. }
  359. if (! $error)
  360. {
  361. $bank_line_id=$paiement->addPaymentToBank($user,'payment','(SubscriptionPayment)',$accountid,$emetteur_nom,$emetteur_banque);
  362. if (! ($bank_line_id > 0))
  363. {
  364. $errmsg=$paiement->error;
  365. $errmsgs=$paiement->errors;
  366. $error++;
  367. }
  368. }
  369. if (! $error)
  370. {
  371. // Update fk_bank for subscriptions
  372. $sql = 'UPDATE '.MAIN_DB_PREFIX.'cotisation SET fk_bank='.$bank_line_id;
  373. $sql.= ' WHERE rowid='.$crowid;
  374. dol_syslog('sql='.$sql);
  375. $result = $db->query($sql);
  376. if (! $result)
  377. {
  378. $error++;
  379. }
  380. }
  381. }
  382. }
  383. }
  384. if (! $error)
  385. {
  386. $db->commit();
  387. }
  388. else
  389. {
  390. $db->rollback();
  391. $action = 'addsubscription';
  392. }
  393. // Send email
  394. if (! $error)
  395. {
  396. // Send confirmation Email
  397. if ($object->email && $_POST["sendmail"])
  398. {
  399. $subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_COTIS_SUBJECT);
  400. $texttosend=$object->makeSubstitution($adht->getMailOnSubscription());
  401. $result=$object->send_an_email($texttosend,$subjecttosend,array(),array(),array(),"","",0,-1);
  402. if ($result < 0) $errmsg=$object->error;
  403. }
  404. $_POST["cotisation"]='';
  405. $_POST["accountid"]='';
  406. $_POST["operation"]='';
  407. $_POST["label"]='';
  408. $_POST["num_chq"]='';
  409. }
  410. }
  411. }
  412. /*
  413. * View
  414. */
  415. $form = new Form($db);
  416. $now=dol_now();
  417. llxHeader('',$langs->trans("Subscriptions"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
  418. if ($rowid)
  419. {
  420. $res=$object->fetch($rowid,$ref);
  421. if ($res < 0) { dol_print_error($db,$object->error); exit; }
  422. //$res=$object->fetch_optionals($object->id,$extralabels);
  423. //if ($res < 0) { dol_print_error($db); exit; }
  424. $adht->fetch($object->typeid);
  425. $head = member_prepare_head($object);
  426. dol_fiche_head($head, 'subscription', $langs->trans("Member"), 0, 'user');
  427. $rowspan=9;
  428. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan+=1;
  429. if (! empty($conf->societe->enabled)) $rowspan++;
  430. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  431. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  432. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  433. print '<table class="border" width="100%">';
  434. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/liste.php">'.$langs->trans("BackToList").'</a>';
  435. // Ref
  436. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  437. print '<td class="valeur" colspan="2">';
  438. print $form->showrefnav($object, 'rowid', $linkback);
  439. print '</td></tr>';
  440. $showphoto='<td rowspan="'.$rowspan.'" align="center" valign="middle" width="25%">'.$form->showphoto('memberphoto',$object).'</td>';
  441. // Login
  442. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  443. {
  444. print '<tr><td>'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td>';
  445. print $showphoto; $showphoto='';
  446. print '</tr>';
  447. }
  448. // Morphy
  449. print '<tr><td>'.$langs->trans("Nature").'</td><td class="valeur" >'.$object->getmorphylib().'</td>';
  450. print $showphoto; $showphoto='';
  451. print '</tr>';
  452. // Type
  453. print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  454. // Company
  455. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$object->societe.'</td></tr>';
  456. // Civility
  457. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'&nbsp;</td>';
  458. print '</tr>';
  459. // Name
  460. print '<tr><td>'.$langs->trans("Lastname").'</td><td class="valeur">'.$object->lastname.'&nbsp;</td>';
  461. print '</tr>';
  462. // Firstname
  463. print '<tr><td>'.$langs->trans("Firstname").'</td><td class="valeur">'.$object->firstname.'&nbsp;</td>';
  464. print '</tr>';
  465. // Status
  466. print '<tr><td>'.$langs->trans("Status").'</td><td class="valeur">'.$object->getLibStatut(4).'</td></tr>';
  467. // Date end subscription
  468. print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
  469. if ($object->datefin)
  470. {
  471. print dol_print_date($object->datefin,'day');
  472. if ($object->datefin < ($now - $conf->adherent->cotisation->warning_delay) && $object->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
  473. }
  474. else
  475. {
  476. print $langs->trans("SubscriptionNotReceived");
  477. if ($object->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
  478. }
  479. print '</td></tr>';
  480. // Third party Dolibarr
  481. if (! empty($conf->societe->enabled))
  482. {
  483. print '<tr><td>';
  484. print '<table class="nobordernopadding" width="100%"><tr><td>';
  485. print $langs->trans("LinkedToSpeedealingThirdParty");
  486. print '</td>';
  487. if ($_GET['action'] != 'editthirdparty' && $user->rights->adherent->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editthirdparty&amp;rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToThirdParty'),1).'</a></td>';
  488. print '</tr></table>';
  489. print '</td><td class="valeur">';
  490. if ($_GET['action'] == 'editthirdparty')
  491. {
  492. $htmlname='socid';
  493. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
  494. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  495. print '<input type="hidden" name="action" value="set'.$htmlname.'">';
  496. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  497. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  498. print '<tr><td>';
  499. print $form->select_company($object->fk_soc,'socid','',1);
  500. print '</td>';
  501. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  502. print '</tr></table></form>';
  503. }
  504. else
  505. {
  506. if ($object->fk_soc)
  507. {
  508. $company=new Societe($db);
  509. $result=$company->fetch($object->fk_soc);
  510. print $company->getNomUrl(1);
  511. }
  512. else
  513. {
  514. print $langs->trans("NoThirdPartyAssociatedToMember");
  515. }
  516. }
  517. print '</td></tr>';
  518. }
  519. // Login Dolibarr
  520. print '<tr><td>';
  521. print '<table class="nobordernopadding" width="100%"><tr><td>';
  522. print $langs->trans("LinkedToSpeedealingUser");
  523. print '</td>';
  524. if ($action != 'editlogin' && $user->rights->adherent->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlogin&amp;rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'),1).'</a></td>';
  525. print '</tr></table>';
  526. print '</td><td class="valeur">';
  527. if ($action == 'editlogin')
  528. {
  529. /*$include=array();
  530. if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
  531. {
  532. $include=array($object->user_id,$user->id);
  533. }*/
  534. print $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'userid','');
  535. }
  536. else
  537. {
  538. if ($object->user_id)
  539. {
  540. print $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'none');
  541. }
  542. else print $langs->trans("NoSpeedealingAccess");
  543. }
  544. print '</td></tr>';
  545. print "</table>\n";
  546. print '</form>';
  547. dol_fiche_end();
  548. dol_htmloutput_errors($errmsg,$errmsgs);
  549. /*
  550. * Barre d'actions
  551. */
  552. // Lien nouvelle cotisation si non brouillon et non resilie
  553. if ($user->rights->adherent->cotisation->creer)
  554. {
  555. if ($action != 'addsubscription' && $action != 'create_thirdparty')
  556. {
  557. print '<div class="tabsAction">';
  558. if ($object->statut > 0) print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'&action=addsubscription">'.$langs->trans("AddSubscription")."</a>";
  559. else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a>';
  560. print "<br>\n";
  561. print '</div>';
  562. print '<br>';
  563. }
  564. }
  565. /*
  566. * List of subscriptions
  567. */
  568. if ($action != 'addsubscription' && $action != 'create_thirdparty')
  569. {
  570. $sql = "SELECT d.rowid, d.prenom, d.nom, d.societe,";
  571. $sql.= " c.rowid as crowid, c.cotisation,";
  572. $sql.= " c.dateadh,";
  573. $sql.= " c.datef,";
  574. $sql.= " c.fk_bank,";
  575. $sql.= " b.rowid as bid,";
  576. $sql.= " ba.rowid as baid, ba.label, ba.bank";
  577. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."cotisation as c";
  578. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
  579. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  580. $sql.= " WHERE d.rowid = c.fk_adherent AND d.rowid=".$rowid;
  581. $result = $db->query($sql);
  582. if ($result)
  583. {
  584. $cotisationstatic=new Cotisation($db);
  585. $accountstatic=new Account($db);
  586. $num = $db->num_rows($result);
  587. $i = 0;
  588. print "<table class=\"noborder\" width=\"100%\">\n";
  589. print '<tr class="liste_titre">';
  590. print '<td>'.$langs->trans("Ref").'</td>';
  591. print '<td align="center">'.$langs->trans("DateSubscription").'</td>';
  592. print '<td align="center">'.$langs->trans("DateEnd").'</td>';
  593. print '<td align="right">'.$langs->trans("Amount").'</td>';
  594. if (! empty($conf->banque->enabled))
  595. {
  596. print '<td align="right">'.$langs->trans("Account").'</td>';
  597. }
  598. print "</tr>\n";
  599. $var=True;
  600. while ($i < $num)
  601. {
  602. $objp = $db->fetch_object($result);
  603. $var=!$var;
  604. print "<tr $bc[$var]>";
  605. $cotisationstatic->ref=$objp->crowid;
  606. $cotisationstatic->id=$objp->crowid;
  607. print '<td>'.$cotisationstatic->getNomUrl(1).'</td>';
  608. print '<td align="center">'.dol_print_date($db->jdate($objp->dateadh),'day')."</td>\n";
  609. print '<td align="center">'.dol_print_date($db->jdate($objp->datef),'day')."</td>\n";
  610. print '<td align="right">'.price($objp->cotisation).'</td>';
  611. if (! empty($conf->banque->enabled))
  612. {
  613. print '<td align="right">';
  614. if ($objp->bid)
  615. {
  616. $accountstatic->label=$objp->label;
  617. $accountstatic->id=$objp->baid;
  618. print $accountstatic->getNomUrl(1);
  619. }
  620. else
  621. {
  622. print '&nbsp;';
  623. }
  624. print '</td>';
  625. }
  626. print "</tr>";
  627. $i++;
  628. }
  629. print "</table>";
  630. }
  631. else
  632. {
  633. dol_print_error($db);
  634. }
  635. // Link for paypal payment
  636. if (! empty($conf->paypal->enabled))
  637. {
  638. include_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
  639. print showPaypalPaymentUrl('membersubscription',$object->ref);
  640. }
  641. }
  642. /*
  643. * Add new subscription form
  644. */
  645. if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->rights->adherent->cotisation->creer)
  646. {
  647. print '<br>';
  648. print_fiche_titre($langs->trans("NewCotisation"));
  649. $bankdirect=0; // Option to write to bank is on by default
  650. $bankviainvoice=0; // Option to write via invoice is on by default
  651. $invoiceonly=0;
  652. if (! empty($conf->banque->enabled) && $conf->global->ADHERENT_BANK_USE && (empty($_POST['paymentsave']) || $_POST["paymentsave"] == 'bankdirect')) $bankdirect=1;
  653. if (! empty($conf->banque->enabled) && ! empty($conf->societe->enabled) && ! empty($conf->facture->enabled) && $object->fk_soc) $bankviainvoice=1;
  654. print "\n\n<!-- Form add subscription -->\n";
  655. if ($conf->use_javascript_ajax)
  656. {
  657. print "\n".'<script type="text/javascript" language="javascript">';
  658. print '$(document).ready(function () {
  659. $(".bankswitchclass, .bankswitchclass2").'.($bankdirect||$bankviainvoice||in_array(GETPOST('paymentsave'),array('bankdirect','bankviainvoice'))?'show()':'hide()').';
  660. $("#none, #invoiceonly").click(function() {
  661. $(".bankswitchclass").hide();
  662. $(".bankswitchclass2").hide();
  663. });
  664. $("#bankdirect, #bankviainvoice").click(function() {
  665. $(".bankswitchclass").show();
  666. $(".bankswitchclass2").show();
  667. });
  668. $("#selectoperation").change(function() {
  669. var code = $(this).val();
  670. if (code == "CHQ")
  671. {
  672. $(".fieldrequireddyn").addClass("fieldrequired");
  673. if ($("#fieldchqemetteur").val() == "")
  674. {
  675. $("#fieldchqemetteur").val($("#memberlabel").val());
  676. }
  677. }
  678. else
  679. {
  680. $(".fieldrequireddyn").removeClass("fieldrequired");
  681. }
  682. });
  683. ';
  684. if (GETPOST('paymentsave')) print '$("#'.GETPOST('paymentsave').'").attr("checked",true);';
  685. print '});';
  686. print '</script>'."\n";
  687. }
  688. // Confirm create third party
  689. if ($action == 'create_thirdparty')
  690. {
  691. $name = $object->getFullName($langs);
  692. if (! empty($name))
  693. {
  694. if ($object->societe) $name.=' ('.$object->societe.')';
  695. }
  696. else
  697. {
  698. $name=$object->societe;
  699. }
  700. // Create a form array
  701. $formquestion=array(array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $name));
  702. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?rowid=".$object->id,$langs->trans("CreateSpeedealingThirdParty"),$langs->trans("ConfirmCreateThirdParty"),"confirm_create_thirdparty",$formquestion,1);
  703. if ($ret == 'html') print '<br>';
  704. }
  705. print '<form name="cotisation" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  706. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  707. print '<input type="hidden" name="action" value="cotisation">';
  708. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  709. print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
  710. print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($company->name).'">';
  711. print "<table class=\"border\" width=\"100%\">\n";
  712. $today=dol_now();
  713. $datefrom=0;
  714. $dateto=0;
  715. $paymentdate=-1;
  716. // Date payment
  717. if ($_POST["paymentyear"] && $_POST["paymentmonth"] && $_POST["paymentday"])
  718. {
  719. $paymentdate=dol_mktime(0, 0, 0, $_POST["paymentmonth"], $_POST["paymentday"], $_POST["paymentyear"]);
  720. }
  721. // Date start subscription
  722. print '<tr><td width="30%" class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
  723. if ($_POST["reday"])
  724. {
  725. $datefrom=dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
  726. }
  727. if (! $datefrom)
  728. {
  729. if ($object->datefin > 0)
  730. {
  731. $datefrom=dol_time_plus_duree($object->datefin,1,'d');
  732. }
  733. else
  734. {
  735. $datefrom=dol_now();
  736. }
  737. }
  738. $form->select_date($datefrom,'','','','',"cotisation");
  739. print "</td></tr>";
  740. // Date end subscription
  741. if ($_POST["endday"])
  742. {
  743. $dateto=dol_mktime(0,0,0,$_POST["endmonth"],$_POST["endday"],$_POST["endyear"]);
  744. }
  745. if (! $dateto)
  746. {
  747. $dateto=-1; // By default, no date is suggested
  748. }
  749. print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
  750. $form->select_date($dateto,'end','','','',"cotisation");
  751. print "</td></tr>";
  752. if ($adht->cotisation)
  753. {
  754. // Amount
  755. print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="cotisation" size="6" value="'.$_POST["cotisation"].'"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
  756. // Label
  757. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td>';
  758. print '<td><input name="label" type="text" size="32" value="'.$langs->trans("Subscription").' ';
  759. print dol_print_date(($datefrom?$datefrom:time()),"%Y").'" ></td></tr>';
  760. // Complementary action
  761. if (! empty($conf->banque->enabled) || ! empty($conf->facture->enabled))
  762. {
  763. $company=new Societe($db);
  764. if ($object->fk_soc)
  765. {
  766. $result=$company->fetch($object->fk_soc);
  767. }
  768. // Title payments
  769. //print '<tr><td colspan="2"><b>'.$langs->trans("Payment").'</b></td></tr>';
  770. // Define a way to write payment
  771. print '<tr><td valign="top" class="fieldrequired">'.$langs->trans('MoreActions');
  772. print '</td>';
  773. print '<td>';
  774. print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($bankviainvoice)?' checked="checked"':'').'> '.$langs->trans("None").'<br>';
  775. if (! empty($conf->banque->enabled))
  776. {
  777. print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(! empty($bankdirect)?' checked="checked"':'');
  778. print '> '.$langs->trans("MoreActionBankDirect").'<br>';
  779. }
  780. if (! empty($conf->societe->enabled) && ! empty($conf->facture->enabled))
  781. {
  782. print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(empty($conf->global->ADHERENT_BANK_USE) || $invoiceonly?' checked="checked"':'');
  783. if (empty($object->fk_soc) || empty($bankviainvoice)) print ' disabled="disabled"';
  784. print '> '.$langs->trans("MoreActionInvoiceOnly");
  785. if ($object->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  786. else
  787. {
  788. print ' ('.$langs->trans("NoThirdPartyAssociatedToMember");
  789. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  790. print $langs->trans("CreateSpeedealingThirdParty");
  791. print '</a>)';
  792. }
  793. print '<br>';
  794. }
  795. if (! empty($conf->banque->enabled) && ! empty($conf->societe->enabled) && ! empty($conf->facture->enabled))
  796. {
  797. print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.($bankviainvoice && !empty($conf->global->ADHERENT_BANK_USE)?' checked="checked"':'');
  798. if (empty($object->fk_soc) || empty($bankviainvoice)) print ' disabled="disabled"';
  799. print '> '.$langs->trans("MoreActionBankViaInvoice");
  800. if ($object->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  801. else
  802. {
  803. print ' ('.$langs->trans("NoThirdPartyAssociatedToMember");
  804. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  805. print $langs->trans("CreateSpeedealingThirdParty");
  806. print '</a>)';
  807. }
  808. print '<br>';
  809. }
  810. print '</td></tr>';
  811. // Bank account
  812. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
  813. $form->select_comptes($_POST["accountid"],'accountid',0,'',1);
  814. print "</td></tr>\n";
  815. // Payment mode
  816. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
  817. $form->select_types_paiements($_POST["operation"],'operation','',2);
  818. print "</td></tr>\n";
  819. // Date of payment
  820. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
  821. $form->select_date($paymentdate?$paymentdate:-1,'payment',0,0,1,'cotisation',1,1);
  822. print "</td></tr>\n";
  823. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
  824. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  825. print '</td>';
  826. print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(empty($_POST['num_chq'])?'':$_POST['num_chq']).'"></td></tr>';
  827. print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
  828. print ' <em>('.$langs->trans("ChequeMaker").')</em>';
  829. print '</td>';
  830. print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(empty($_POST['chqemetteur'])?$facture->client->name:$_POST['chqemetteur']).'"></td></tr>';
  831. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
  832. print ' <em>('.$langs->trans("ChequeBank").')</em>';
  833. print '</td>';
  834. print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(empty($_POST['chqbank'])?'':$_POST['chqbank']).'"></td></tr>';
  835. }
  836. }
  837. print '<tr><td colspan="2">&nbsp;</td>';
  838. print '<tr><td width="30%">'.$langs->trans("SendAcknowledgementByMail").'</td>';
  839. print '<td>';
  840. if (! $object->email)
  841. {
  842. print $langs->trans("NoEMail");
  843. }
  844. else
  845. {
  846. $adht = new AdherentType($db);
  847. $adht->fetch($object->typeid);
  848. $subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_COTIS_SUBJECT);
  849. $texttosend=$object->makeSubstitution($adht->getMailOnSubscription());
  850. $tmp='<input name="sendmail" type="checkbox"'.((isset($_POST["sendmail"])?$_POST["sendmail"]:$conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL)?' checked="checked"':'').'>';
  851. $helpcontent='';
  852. $helpcontent.='<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
  853. $helpcontent.='<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
  854. $helpcontent.='<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
  855. $helpcontent.=$subjecttosend."\n";
  856. $helpcontent.="<br>";
  857. $helpcontent.='<b>'.$langs->trans("MailText").'</b>:<br>';
  858. $helpcontent.=dol_htmlentitiesbr($texttosend)."\n";
  859. print $form->textwithpicto($tmp,$helpcontent,1,'help');
  860. }
  861. print '</td></tr>';
  862. print '</table>';
  863. print '<br>';
  864. print '<center>';
  865. print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
  866. print ' &nbsp; &nbsp; ';
  867. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  868. print '</center>';
  869. print '</form>';
  870. print "\n<!-- End form subscription -->\n\n";
  871. }
  872. //print '</td></tr>';
  873. //print '</table>';
  874. }
  875. else
  876. {
  877. $langs->load("errors");
  878. print $langs->trans("ErrorRecordNotFound");
  879. }
  880. llxFooter();
  881. $db->close();
  882. ?>