Member.php 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. use Livewire\Attributes\Url;
  5. use Livewire\WithFileUploads;
  6. use Livewire\WithPagination;
  7. use DateTime;
  8. class Member extends Component
  9. {
  10. use WithPagination;
  11. protected $paginationTheme = 'bootstrap';
  12. protected $listeners = ['storeCategoryWithID' => 'storeCategoryWithID', 'setCourse' => 'setCourse', 'hideMsg' => 'hideMsg'];
  13. use WithFileUploads;
  14. public $sortField ='id';
  15. public $sortAsc = false;
  16. public $groupMsg = '';
  17. protected $messages = [
  18. 'birth_nation_id.required' => 'birth_nation_id',
  19. 'birth_province_id.required' => 'birth_province_id',
  20. 'birth_city_id.required' => 'birth_city_id',
  21. 'nation_id.required' => 'nation_id',
  22. 'province_id.required' => 'province_id',
  23. 'city_id.required' => 'city_id',
  24. 'gender' => 'Obbligatorio'
  25. ];
  26. public function sortBy($field)
  27. {
  28. if($this->sortField === $field)
  29. {
  30. $this->sortAsc = ! $this->sortAsc;
  31. } else {
  32. $this->sortAsc = true;
  33. }
  34. $this->sortField = $field;
  35. }
  36. public $records, $first_name, $last_name, $image, $image_old, $status, $birth_place, $birth_city_id, $birth_province_id, $birth_nation_id, $birth_date, $gender, $fiscal_code, $address, $zip_code, $nation_id, $province_id, $city_id, $phone, $phone2, $phone3, $email, $enabled, $dataId, $update = false, $add = false;
  37. public $father_name, $mother_name, $father_email, $mother_email, $father_phone, $mother_phone, $father_fiscal_code, $mother_fiscal_code, $father_doc_number, $father_doc_type, $mother_doc_number, $mother_doc_type;
  38. public $document_type, $document_number, $document_from, $document_expire_date, $document_files, $document_files_old;
  39. public $selectId = 0;
  40. public $causalId = 0;
  41. public $error_fc = false;
  42. public $under18 = false;
  43. public $refreshAfter = 0;
  44. public $checkedAll = false;
  45. public $multipleIds = [];
  46. public $multipleAction = '';
  47. public $isItaly = true;
  48. public $isBirthItaly = true;
  49. public $showDetail = false;
  50. public $currentMember;
  51. public $currentStatus;
  52. public $age = '';
  53. public $disciplines = array();
  54. public $cards = array();
  55. public $categories = array();
  56. public $courses = array();
  57. public $course_subscriptions = array();
  58. public $createSubscription = false;
  59. public $payMonths = array();
  60. public $showCourse = array();
  61. public $searchTxt;
  62. public $search;
  63. public $showReset = false;
  64. public $advanced = false;
  65. public $birthNations = array();
  66. public $birthProvinces = array();
  67. public $birthCities = array();
  68. public $active;
  69. // Card data
  70. public $member_cards = array(), $card_card_id, $card_number, $card_date, $card_accept_date, $card_status, $card_discipline1_id, $card_discipline2_id, $card_discipline3_id, $addCard, $updateCard, $cardDataId;
  71. // Categories data
  72. public $member_categories = array(), $category_category_id;
  73. // Courses data
  74. public $member_courses = array(), $course_course_id, $course_date_from, $course_date_to, $course_when = array(), $addCourse, $updateCourse, $courseDataId, $course_course_subscription_id, $course_status, $course_note, $course_price, $course_subscription_price, $course_subscribed, $course_months = array(), $course_exist;
  75. // Certificates data
  76. public $member_certificates = array(), $certificate_type, $certificate_filename_old, $certificate_filename, $certificate_expire_date, $certificate_status, $addCertificate, $updateCertificate, $certificateDataId;
  77. public $filterCard = [];
  78. public $filterCategory = [];
  79. public $filterCertNormal = 0;
  80. public $filterCertAgonistic = 0;
  81. public $filterCertScaduto = 0;
  82. public $filterCertInScadenza = 0;
  83. protected $rules = [
  84. 'first_name' => 'required',
  85. 'last_name' => 'required',
  86. 'email' => 'required',
  87. 'phone' => 'required',
  88. 'birth_date' => 'before_or_equal:today'
  89. ];
  90. public function resetFields(){
  91. $this->dataId = -1;
  92. $this->first_name = '';
  93. $this->last_name = '';
  94. $this->status = '';
  95. $this->birth_city_id = null;
  96. $this->birth_province_id = null;
  97. $this->birth_nation_id = null;
  98. $this->birth_date = null;
  99. $this->birth_place = '';
  100. $this->father_name = '';
  101. $this->mother_name = '';
  102. $this->father_email = '';
  103. $this->mother_email = '';
  104. $this->father_phone = '';
  105. $this->mother_phone = '';
  106. $this->father_fiscal_code = '';
  107. $this->mother_fiscal_code = '';
  108. $this->father_doc_number = '';
  109. $this->mother_doc_number = '';
  110. $this->father_doc_type = '';
  111. $this->mother_doc_type = '';
  112. $this->gender = null;
  113. $this->fiscal_code = '';
  114. $this->address = '';
  115. $this->zip_code = '';
  116. $this->document_type = '';
  117. $this->document_number = '';
  118. $this->document_from = '';
  119. $this->document_expire_date = null;
  120. $this->document_files = array();
  121. //$this->nation_id = null;
  122. //$this->province_id = null;
  123. $this->nation_id = null;
  124. $this->province_id = null;
  125. $this->city_id = null;
  126. $this->phone = '';
  127. $this->phone2 = '';
  128. $this->phone3 = '';
  129. $this->email = '';
  130. $this->enabled = true;
  131. $this->under18 = false;
  132. $this->image = null;
  133. $this->error_fc = false;
  134. $this->emit('load-data-table');
  135. }
  136. public function resetCardFields(){
  137. $this->card_card_id = null;
  138. $this->card_number = '';
  139. $this->card_date = null;
  140. $this->card_accept_date = null;
  141. $this->card_status = 0;
  142. $this->card_discipline1_id = null;
  143. $this->card_discipline2_id = null;
  144. $this->card_discipline3_id = null;
  145. }
  146. public function resetCertificateFields(){
  147. $this->certificate_type = 'N';
  148. $this->certificate_filename = '';
  149. $this->certificate_filename_old = '';
  150. $this->certificate_expire_date = null;
  151. $this->certificate_status = 0;
  152. }
  153. public function resetCourseFields(){
  154. $this->course_course_id = null;
  155. $this->course_when = array();
  156. $this->course_when[] = array('day' => array(), 'from' => '', 'to' => '');
  157. $this->course_date_from = null;
  158. $this->course_date_to = null;
  159. $this->course_course_subscription_id = null;
  160. $this->course_status = 0;
  161. $this->course_price = 0;
  162. $this->course_subscription_price = 0;
  163. $this->course_exist = false;
  164. $this->course_subscribed = false;
  165. $this->course_months = array();
  166. $this->course_note = '';
  167. }
  168. public function executeMultipleAction(){
  169. if ($this->multipleAction == 'delete')
  170. $this->multipleDelete();
  171. }
  172. public function updatedImage()
  173. {
  174. $this->validate([
  175. 'image' => 'image|max:1024',
  176. ]);
  177. $this->image_old = '';
  178. }
  179. public $documents = [];
  180. public function removeDocument($idx)
  181. {
  182. unset($this->document_files[$idx]);
  183. }
  184. public function updatedDocuments()
  185. {
  186. foreach ($this->documents as $document)
  187. {
  188. $name = $document->getClientOriginalName(); // . '.'.$allegato->extension();
  189. $document->storeAs('public', $name);
  190. $this->document_files[] = $name;
  191. }
  192. $this->documents = [];
  193. }
  194. public function resetCategoryFields(){
  195. $this->category_category_id = null;
  196. }
  197. public function getCategories($records, $indentation)
  198. {
  199. foreach($records as $record)
  200. {
  201. // $this->categories[] = array('id' => $record->id, 'name' => str_repeat(" / ", $indentation) . $record->name);
  202. $this->categories[] = array('id' => $record->id, 'name' => $record->getTree());
  203. if(count($record->childs))
  204. $this->getCategories($record->childs, $indentation + 1);
  205. }
  206. }
  207. public function getCourses($records, $indentation)
  208. {
  209. foreach($records as $record)
  210. {
  211. // $this->categories[] = array('id' => $record->id, 'name' => str_repeat(" / ", $indentation) . $record->name);
  212. $this->courses[] = array('id' => $record->id, 'name' => $record->getTree());
  213. if(count($record->childs))
  214. $this->getCourses($record->childs, $indentation + 1);
  215. }
  216. }
  217. public function updatedBirthDate()
  218. {
  219. $this->validateOnly('birth_date');
  220. $date1 = new DateTime($this->birth_date);
  221. $date2 = new DateTime("now");
  222. $interval = $date1->diff($date2);
  223. $this->age = $interval->y . " anni";
  224. $this->under18 = $interval->y < 18;
  225. }
  226. public function mount()
  227. {
  228. if (isset($_GET["new"]))
  229. {
  230. $this->refreshAfter = 1;
  231. $this->add();
  232. }
  233. $this->cards = \App\Models\Card::select('id', 'name')->get();
  234. $this->disciplines = \App\Models\Discipline::select('id', 'name')->get();
  235. $this->categories = array();
  236. $this->getCategories(\App\Models\Category::select('id', 'name')->where('parent_id', null)->get(), 0);
  237. $this->courses = \App\Models\Course::select('id', 'name')->where('parent_id', null)->get();
  238. $this->course_subscriptions = \App\Models\CourseSubscription::select('*')->where('enabled', true)->get();
  239. // $this->getCourses(\App\Models\Course::select('id', 'name')->where('parent_id', null)->get(), 0);
  240. /*$this->nations = \App\Models\Nation::select('id', 'name')->orderBy('name')->get();
  241. $this->provinces = \App\Models\Province::where('nation_id', 1)->orderBy('name')->get();
  242. $this->cities = \App\Models\City::where('province_id', 178)->orderBy('name')->orderBy('name')->get();*/
  243. $c = \App\Models\Causal::where('type', 'IN')->where('money', true)->first();
  244. if ($c)
  245. $this->causalId = $c->id;
  246. if (isset($_GET["member_detail"]))
  247. {
  248. $this->showDetailF($_GET["member_detail"]);
  249. $this->refreshAfter = 1;
  250. }
  251. /*$this->birthNations = \App\Models\Nation::select('id', 'name')->orderBy('name')->get();
  252. $this->birthProvinces = \App\Models\Province::where('nation_id', 1)->orderBy('name')->get();
  253. $this->birthCities = \App\Models\City::where('province_id', 178)->orderBy('name')->orderBy('name')->get();*/
  254. }
  255. public function updated()
  256. {
  257. // $this->emit('load-select');
  258. }
  259. public function hydrate()
  260. {
  261. $this->emit('load-select');
  262. // $this->emit('destroy-data-table');
  263. }
  264. public function checkIsItaly()
  265. {
  266. $n = \App\Models\Nation::findOrFail($this->nation_id);
  267. $this->isItaly = $n->is_italy;
  268. }
  269. public function checkIsBirthItaly()
  270. {
  271. $n = \App\Models\Nation::findOrFail($this->birth_nation_id);
  272. $this->isBirthItaly = $n->is_italy;
  273. }
  274. /*public function loadProvinces()
  275. {
  276. $n = \App\Models\Nation::findOrFail($this->nation_id);
  277. $this->isItaly = $n->is_italy;
  278. $this->provinces = \App\Models\Province::where('nation_id', $this->nation_id)->orderBy('name')->get();
  279. $this->cities = array();
  280. $this->selectId++;
  281. }
  282. public function loadCities()
  283. {
  284. $this->cities = \App\Models\City::where('province_id', $this->province_id)->orderBy('name')->orderBy('name')->get();
  285. $this->selectId++;
  286. }
  287. public function loadBirthProvinces()
  288. {
  289. $n = \App\Models\Nation::findOrFail($this->birth_nation_id);
  290. $this->isBirthItaly = $n->is_italy;
  291. $this->birthProvinces = \App\Models\Province::where('nation_id', $this->birth_nation_id)->orderBy('name')->get();
  292. $this->birthCities = array();
  293. $this->selectId++;
  294. }
  295. public function loadBirthCities()
  296. {
  297. $this->birthCities = \App\Models\City::where('province_id', $this->birth_province_id)->get();
  298. $this->selectId++;
  299. }
  300. */
  301. public function search()
  302. {
  303. if ($this->searchTxt != '')
  304. {
  305. $this->search = $this->searchTxt;
  306. $this->showReset = true;
  307. }
  308. }
  309. public function resetSearch()
  310. {
  311. $this->showReset = false;
  312. $this->searchTxt = '';
  313. $this->search = $this->searchTxt;
  314. }
  315. public function advancedSearch()
  316. {
  317. $this->advanced = true;
  318. }
  319. public function advancedSearchCancel()
  320. {
  321. $this->filterCard = [];
  322. $this->filterCategory = [];
  323. $this->filterCertNormal = 0;
  324. $this->filterCertAgonistic = 0;
  325. $this->filterCertScaduto = 0;
  326. $this->filterCertInScadenza = 0;
  327. $this->advanced = false;
  328. }
  329. public function render()
  330. {
  331. $datas = [];
  332. // $this->emit('destroy-data-table');
  333. if (false)
  334. {
  335. if (!$this->advanced)
  336. {
  337. /*if ($this->search != '')
  338. $datas = \App\Models\Member::select('members.*') // , \DB::raw('SUM(records.id) As total'))
  339. ->where('first_name', 'LIKE', '%' . $this->search . '%')
  340. ->orWhere('last_name', 'LIKE', '%' . $this->search . '%')
  341. ->orWhere('email', 'LIKE', '%' . $this->search . '%');
  342. $this->records = \App\Models\Member::where('first_name', 'LIKE', '%' . $this->search . '%')->orWhere('last_name', 'LIKE', '%' . $this->search . '%')->orWhere('email', 'LIKE', '%' . $this->search . '%')->get();
  343. else*/
  344. $this->records = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone')->get();
  345. //$datas = \App\Models\Member::select('members.*');
  346. }
  347. else
  348. {
  349. //$this->records = \App\Models\Member::where('id', '>', 0);
  350. $datas = \App\Models\Member::select('members.*')->where('id', '>', 0);
  351. if (sizeof($this->filterCard) > 0)
  352. {
  353. $card_ids = \App\Models\MemberCard::whereIn('card_id', $this->filterCard)->pluck('member_id');
  354. //$this->records->whereIn('id', $card_ids);
  355. $datas = $datas->whereIn('id', $card_ids);
  356. }
  357. if (sizeof($this->filterCategory) > 0)
  358. {
  359. $cats_ids = \App\Models\MemberCategory::whereIn('category_id', $this->filterCategory)->pluck('member_id');
  360. //$this->records->whereIn('id', $cats_ids);
  361. $datas = $datas->whereIn('id', $cats_ids);
  362. }
  363. $certs = [];
  364. if ($this->filterCertNormal > 0)
  365. {
  366. $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
  367. //$this->records->whereIn('id', $normal);
  368. $datas = $datas->whereIn('id', $normal);;
  369. }
  370. if ($this->filterCertAgonistic > 0)
  371. {
  372. $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
  373. //$this->records->whereIn('id', $agonistic);
  374. $datas = $datas->whereIn('id', $agonistic);
  375. }
  376. if ($this->filterCertScaduto > 0)
  377. {
  378. $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  379. //$this->records->whereIn('id', $scaduto);
  380. $datas = $datas->whereIn('id', $scaduto);
  381. }
  382. if ($this->filterCertInScadenza > 0)
  383. {
  384. $scaduto = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  385. //$this->records->whereIn('id', $scaduto);
  386. $datas = $datas->whereIn('id', $scaduto);
  387. }
  388. if (sizeof($certs) > 0)
  389. {
  390. $datas = $datas->whereIn('id', $certs);
  391. //$this->records->whereIn('id', $certs);
  392. }
  393. $this->records = $datas->get();
  394. }
  395. foreach($this->records as $r)
  396. {
  397. $r->age = $r->getAge();
  398. $active = $r->isActive();
  399. $r->status = $active["status"];
  400. $r->date = $active["date"];
  401. $r->certificate = $r->hasCertificate()["date"];
  402. $r->state = $r->getStatus()["status"];
  403. }
  404. /*
  405. if ($this->sortAsc)
  406. $this->records = $this->records->sortBy($this->sortField);
  407. else
  408. $this->records = $this->records->sortByDesc($this->sortField);
  409. */
  410. //$datas = $datas->get(); // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10);
  411. //$this->records = $this->records->get();
  412. $this->emit('load-data-table');
  413. }
  414. $this->loadMemberCards();
  415. $this->loadMemberCourses();
  416. $this->loadMemberCategories();
  417. $this->loadMemberCertificates();
  418. return view('livewire.member', ['datas' => $datas]);
  419. }
  420. public function updatedCourseCourseId()
  421. {
  422. if ($this->course_course_id > 0)
  423. {
  424. $c = \App\Models\Course::findOrFail($this->course_course_id);
  425. $this->course_price = formatPrice($c->price);
  426. $this->course_subscription_price = formatPrice($c->subscription_price);
  427. // Controllo se sono già iscritto la corso
  428. $this->course_exist = \App\Models\MemberCourse::where('course_id', $this->course_course_id)->where('member_id', $this->dataId)->count() > 0;
  429. }
  430. else
  431. {
  432. $this->course_price = 0;
  433. $this->course_subscription_price = 0;
  434. $this->course_exist = false;
  435. }
  436. }
  437. public function loadMemberCards()
  438. {
  439. $this->member_cards = \App\Models\MemberCard::where('member_id', $this->dataId)->get();
  440. // return view('livewire.member');
  441. }
  442. public function loadMemberCourses()
  443. {
  444. $this->member_courses = \App\Models\MemberCourse::where('member_id', $this->dataId)->get();
  445. // return view('livewire.member');
  446. }
  447. public function loadMemberCategories()
  448. {
  449. $this->member_categories = \App\Models\MemberCategory::where('member_id', $this->dataId)->get();
  450. // return view('livewire.member');
  451. }
  452. public function loadMemberCertificates()
  453. {
  454. $this->member_certificates = \App\Models\MemberCertificate::where('member_id', $this->dataId)->orderBy('expire_date', 'DESC')->get();
  455. // return view('livewire.member');
  456. }
  457. public function showDetailF($id)
  458. {
  459. $this->currentMember = \App\Models\Member::findOrFail($id);
  460. $this->currentStatus = $this->currentMember->getStatus();
  461. $this->showDetail = true;
  462. }
  463. public function add()
  464. {
  465. $this->emit('load-select');
  466. $this->emit('hide-search');
  467. $this->showDetail = false;
  468. $this->resetFields();
  469. $this->add = true;
  470. $this->update = false;
  471. $this->emit('setEdit', true);
  472. }
  473. public function store($close)
  474. {
  475. $this->emit('load-select');
  476. $rules = [
  477. 'first_name' => 'required',
  478. 'last_name' => 'required',
  479. 'email' => 'required',
  480. 'phone' => 'required',
  481. 'birth_nation_id' => 'required',
  482. //'birth_place' => 'required',
  483. 'address' => 'required',
  484. 'zip_code' => 'required',
  485. 'nation_id' => 'required',
  486. 'fiscal_code' => 'required',
  487. 'birth_date' => 'before_or_equal:today',
  488. 'gender' => 'required'
  489. ];
  490. if ($this->isBirthItaly)
  491. {
  492. $rules['birth_province_id'] = 'required';
  493. $rules['birth_city_id'] = 'required';
  494. }
  495. else
  496. {
  497. $rules['birth_place'] = 'required';
  498. }
  499. if ($this->isItaly)
  500. {
  501. $rules['province_id'] = 'required';
  502. $rules['city_id'] = 'required';
  503. }
  504. $zzz = [];
  505. if ($this->birth_nation_id == null)
  506. $zzz[] = 'birth_nation_id='.$this->birth_nation_id;
  507. if ($this->isBirthItaly)
  508. {
  509. if ($this->birth_province_id == null)
  510. $zzz[] = 'birth_province_id='.$this->birth_province_id;
  511. if ($this->birth_city_id == null)
  512. $zzz[] = 'birth_city_id='.$this->birth_city_id;
  513. }
  514. if ($this->nation_id == null)
  515. $zzz[] = 'nation_id='.$this->nation_id;
  516. if ($this->isItaly)
  517. {
  518. if ($this->province_id == null)
  519. $zzz[] = 'province_id='.$this->province_id;
  520. if ($this->city_id == null)
  521. $zzz[] = 'city_id='.$this->city_id;
  522. }
  523. $this->emit('setErrorMsg', $zzz);
  524. $this->validate($rules);
  525. //$this->emit('setErrors');
  526. try {
  527. $name = '';
  528. if ($this->image)
  529. {
  530. $name = md5($this->image . microtime()).'.'.$this->image->extension();
  531. $this->image->storeAs('public', $name);
  532. }
  533. $docs = implode("|", $this->document_files);
  534. $member = \App\Models\Member::create([
  535. 'first_name' => strtoupper($this->first_name),
  536. 'last_name' => strtoupper($this->last_name),
  537. 'status' => $this->status,
  538. 'birth_city_id' => $this->birth_city_id > 0 ? $this->birth_city_id : null,
  539. 'birth_province_id' => $this->birth_province_id > 0 ? $this->birth_province_id : null,
  540. 'birth_nation_id' => $this->birth_nation_id > 0 ? $this->birth_nation_id : null,
  541. 'birth_date' => $this->birth_date,
  542. 'birth_place' => $this->birth_place,
  543. 'father_name' => $this->father_name,
  544. 'mother_name' => $this->mother_name,
  545. 'father_email' => strtolower($this->father_email),
  546. 'mother_email' => strtolower($this->mother_email),
  547. 'father_phone' => $this->father_phone,
  548. 'mother_phone' => $this->mother_phone,
  549. 'father_fiscal_code' => $this->father_fiscal_code,
  550. 'mother_fiscal_code' => $this->mother_fiscal_code,
  551. 'father_doc_number' => $this->father_doc_number,
  552. 'father_doc_type' => $this->father_doc_type,
  553. 'mother_doc_number' => $this->mother_doc_number,
  554. 'mother_doc_type' => $this->mother_doc_type,
  555. 'document_type' => $this->document_type,
  556. 'document_number' => $this->document_number,
  557. 'document_from' => $this->document_from,
  558. 'document_expire_date' => $this->document_expire_date,
  559. 'document_files' => $docs,
  560. 'gender' => $this->gender,
  561. 'fiscal_code' => $this->fiscal_code,
  562. 'address' => $this->address,
  563. 'zip_code' => $this->zip_code,
  564. 'nation_id' => $this->nation_id > 0 ? $this->nation_id : null,
  565. 'province_id' => $this->province_id > 0 ? $this->province_id : null,
  566. 'city_id' => $this->city_id > 0 ? $this->city_id : null,
  567. 'phone' => $this->phone,
  568. 'phone2' => $this->phone2,
  569. 'phone3' => $this->phone3,
  570. 'email' => strtolower($this->email),
  571. 'image' => $name,
  572. 'enabled' => $this->enabled
  573. ]);
  574. session()->flash('success, Tesserato creato');
  575. $this->resetFields();
  576. if ($close)
  577. {
  578. $this->add = false;
  579. }
  580. else
  581. {
  582. $this->edit($member->id);
  583. }
  584. $this->emit('setEdit', false);
  585. } catch (\Exception $ex) {
  586. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  587. }
  588. }
  589. public function duplicate($id){
  590. $member = \App\Models\Member::findOrFail($id);
  591. $newMember = $member->replicate();
  592. $newMember->save();
  593. $this->edit($newMember->id);
  594. }
  595. public function edit($id){
  596. $this->showDetail = false;
  597. $this->emit('setEdit', true);
  598. $this->emit('hide-search');
  599. try {
  600. $member = \App\Models\Member::findOrFail($id);
  601. if( !$member) {
  602. session()->flash('error','Tesserato non trovato');
  603. } else {
  604. $this->first_name = $member->first_name;
  605. $this->last_name = $member->last_name;
  606. $this->status = $member->status;
  607. $this->birth_city_id = $member->birth_city_id;
  608. $this->birth_province_id = $member->birth_province_id;
  609. $this->birth_nation_id = $member->birth_nation_id;
  610. $this->birth_date = $member->birth_date;
  611. $this->birth_place = $member->birth_place;
  612. $this->father_name = $member->father_name;
  613. $this->mother_name = $member->mother_name;
  614. $this->father_email = strtolower($member->father_email);
  615. $this->mother_email = strtolower($member->mother_email);
  616. $this->father_phone = $member->father_phone;
  617. $this->mother_phone = $member->mother_phone;
  618. $this->father_fiscal_code = $member->father_fiscal_code;
  619. $this->mother_fiscal_code = $member->mother_fiscal_code;
  620. $this->father_doc_number = $member->father_doc_number;
  621. $this->mother_doc_number = $member->mother_doc_number;
  622. $this->father_doc_type = $member->father_doc_type;
  623. $this->mother_doc_type = $member->mother_doc_type;
  624. $this->document_type = $member->document_type;
  625. $this->document_number = $member->document_number;
  626. $this->document_from = $member->document_from;
  627. $this->document_expire_date = $member->document_expire_date;
  628. $this->document_files = explode("|", $member->document_files);
  629. $this->gender = $member->gender;
  630. $this->fiscal_code = $member->fiscal_code;
  631. $this->address = $member->address;
  632. $this->zip_code = $member->zip_code;
  633. $this->nation_id = $member->nation_id;
  634. $this->province_id = $member->province_id;
  635. $this->city_id = $member->city_id;
  636. $this->phone = $member->phone;
  637. $this->phone2 = $member->phone2;
  638. $this->phone3 = $member->phone3;
  639. $this->email = strtolower($member->email);
  640. $this->image_old = $member->image;
  641. $this->enabled = $member->enabled;
  642. $this->dataId = $member->id;
  643. $this->active = $member->getStatus();
  644. $date1 = new DateTime($this->birth_date);
  645. $date2 = new DateTime("now");
  646. $interval = $date1->diff($date2);
  647. $this->age = $interval->y . " anni";
  648. $this->under18 = $interval->y < 18;
  649. //$this->provinces = \App\Models\Province::where('nation_id', $this->nation_id)->get();
  650. //$this->cities = \App\Models\City::where('province_id', $this->province_id)->get();
  651. //$this->birthProvinces = \App\Models\Province::where('nation_id', $this->birth_nation_id)->get();
  652. //$this->birthCities = \App\Models\City::where('province_id', $this->birth_province_id)->get();
  653. $this->update = true;
  654. $this->add = false;
  655. $this->emit('load-select');
  656. $this->emit('load-provinces', $this->nation_id, 'provinceClass');
  657. $this->emit('load-provinces', $this->birth_nation_id, 'provinceBirthClass');
  658. $this->emit('load-cities', $this->province_id, 'cityClass');
  659. $this->emit('load-cities', $this->birth_province_id, 'cityBirthClass');
  660. }
  661. } catch (\Exception $ex) {
  662. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  663. }
  664. }
  665. public function update($close)
  666. {
  667. $this->emit('load-select');
  668. $rules = [
  669. 'first_name' => 'required',
  670. 'last_name' => 'required',
  671. 'email' => 'required',
  672. 'phone' => 'required',
  673. 'birth_nation_id' => 'required',
  674. //'birth_place' => 'required',
  675. 'address' => 'required',
  676. 'zip_code' => 'required',
  677. 'nation_id' => 'required',
  678. 'fiscal_code' => 'required',
  679. 'birth_date' => 'before_or_equal:today'
  680. ];
  681. if ($this->isBirthItaly)
  682. {
  683. $rules['birth_province_id'] = 'required';
  684. $rules['birth_city_id'] = 'required';
  685. }
  686. else
  687. {
  688. $rules['birth_place'] = 'required';
  689. }
  690. if ($this->isItaly)
  691. {
  692. $rules['province_id'] = 'required';
  693. $rules['city_id'] = 'required';
  694. }
  695. $zzz = [];
  696. if ($this->birth_nation_id == null)
  697. $zzz[] = 'birth_nation_id='.$this->birth_nation_id;
  698. if ($this->isBirthItaly)
  699. {
  700. if ($this->birth_province_id == null)
  701. $zzz[] = 'birth_province_id='.$this->birth_province_id;
  702. if ($this->birth_city_id == null)
  703. $zzz[] = 'birth_city_id='.$this->birth_city_id;
  704. }
  705. if ($this->nation_id == null)
  706. $zzz[] = 'nation_id='.$this->nation_id;
  707. if ($this->isItaly)
  708. {
  709. if ($this->province_id == null)
  710. $zzz[] = 'province_id='.$this->province_id;
  711. if ($this->city_id == null)
  712. $zzz[] = 'city_id='.$this->city_id;
  713. }
  714. $this->emit('setErrorMsg', $zzz);
  715. $this->validate($rules);
  716. try {
  717. $name = '';
  718. if ($this->image)
  719. {
  720. $name = md5($this->image . microtime()).'.'.$this->image->extension();
  721. $this->image->storeAs('public', $name);
  722. }
  723. $docs = implode("|", $this->document_files);
  724. \App\Models\Member::whereId($this->dataId)->update([
  725. 'first_name' => strtoupper($this->first_name),
  726. 'last_name' => strtoupper($this->last_name),
  727. 'status' => $this->status,
  728. 'birth_city_id' => $this->birth_city_id > 0 ? $this->birth_city_id : null,
  729. 'birth_province_id' => $this->birth_province_id > 0 ? $this->birth_province_id : null,
  730. 'birth_nation_id' => $this->birth_nation_id > 0 ? $this->birth_nation_id : null,
  731. 'birth_date' => $this->birth_date,
  732. 'birth_place' => $this->birth_place,
  733. 'father_name' => $this->father_name,
  734. 'mother_name' => $this->mother_name,
  735. 'father_email' => strtolower($this->father_email),
  736. 'mother_email' => strtolower($this->mother_email),
  737. 'father_phone' => $this->father_phone,
  738. 'mother_phone' => $this->mother_phone,
  739. 'father_fiscal_code' => $this->father_fiscal_code,
  740. 'mother_fiscal_code' => $this->mother_fiscal_code,
  741. 'father_doc_number' => $this->father_doc_number,
  742. 'father_doc_type' => $this->father_doc_type,
  743. 'mother_doc_number' => $this->mother_doc_number,
  744. 'mother_doc_type' => $this->mother_doc_type,
  745. 'document_type' => $this->document_type,
  746. 'document_number' => $this->document_number,
  747. 'document_from' => $this->document_from,
  748. 'document_expire_date' => $this->document_expire_date,
  749. 'document_files' => $docs,
  750. 'gender' => $this->gender,
  751. 'fiscal_code' => $this->fiscal_code,
  752. 'address' => $this->address,
  753. 'zip_code' => $this->zip_code,
  754. 'nation_id' => $this->nation_id > 0 ? $this->nation_id : null,
  755. 'province_id' => $this->province_id > 0 ? $this->province_id : null,
  756. 'city_id' => $this->city_id > 0 ? $this->city_id : null,
  757. 'image' => $name != '' ? $name : $this->image_old,
  758. 'phone' => $this->phone,
  759. 'phone2' => $this->phone2,
  760. 'phone3' => $this->phone3,
  761. 'email' => strtolower($this->email),
  762. 'enabled' => $this->enabled
  763. ]);
  764. session()->flash('success','Tesserato aggiornato');
  765. if ($close)
  766. {
  767. $this->resetFields();
  768. $this->update = false;
  769. }
  770. $this->emit('setEdit', false);
  771. } catch (\Exception $ex) {
  772. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  773. }
  774. }
  775. public function cancel()
  776. {
  777. $this->add = false;
  778. $this->update = false;
  779. $this->showDetail = false;
  780. $this->resetFields();
  781. $this->emit('setEdit', false);
  782. }
  783. public function delete($id)
  784. {
  785. try{
  786. \App\Models\Member::find($id)->delete();
  787. session()->flash('success',"Tesserato eliminato");
  788. }catch(\Exception $e){
  789. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  790. }
  791. }
  792. public function checkUncheckAll()
  793. {
  794. if (!$this->checkedAll)
  795. {
  796. $this->multipleIds = array();
  797. }
  798. else
  799. {
  800. foreach($this->records as $r)
  801. {
  802. $this->multipleIds[] = $r->id;
  803. }
  804. }
  805. }
  806. public function multipleDelete()
  807. {
  808. try{
  809. foreach($this->multipleIds as $id)
  810. {
  811. \App\Models\Member::find($id)->delete();
  812. }
  813. }catch(\Exception $e){
  814. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  815. }
  816. $this->multipleAction = '';
  817. }
  818. // Card
  819. public function addCard()
  820. {
  821. $this->resetCardFields();
  822. $this->addCard = true;
  823. $this->updateCard = false;
  824. }
  825. public function storeCard()
  826. {
  827. $this->validate(['card_card_id' => 'required']);
  828. try {
  829. // in base alla card selezionata calcolo la scadenza
  830. $expire_date = null;
  831. if ($this->card_date != '')
  832. {
  833. $y = date("Y", strtotime($this->card_date));
  834. $card = \App\Models\Card::findOrFail($this->card_card_id);
  835. if ($card->next_day_expire > 0 && $card->next_month_expire > 0)
  836. {
  837. $m = strlen($card->next_month_expire) == 1 ? ('0' . $card->next_month_expire) : $card->next_month_expire;
  838. if (date("md", strtotime($this->card_date)) > ($m . $card->next_day_expire))
  839. $y += 1;
  840. $next_exp = date($y . "-" . $m . "-" . $card->next_day_expire);
  841. if ($next_exp > $this->card_date)
  842. {
  843. $expire_date = $next_exp;
  844. }
  845. else
  846. $expire_date = date($y . "-" . $card->next_month_expire . "-" . $card->next_day_expire, strtotime(' + 1 years'));
  847. }
  848. else
  849. {
  850. if ($card->one_year_expire)
  851. {
  852. $expire_date = date("Y-m-d", strtotime($this->card_date . ' + 1 years'));
  853. }
  854. }
  855. }
  856. \App\Models\MemberCard::create([
  857. 'member_id' => $this->dataId,
  858. 'card_id' => $this->card_card_id,
  859. 'number' => $this->card_number,
  860. 'date' => $this->card_date,
  861. 'accept_date' => $this->card_accept_date != '' ? $this->card_accept_date : $this->card_date,
  862. 'expire_date' => $expire_date,
  863. 'status' => $this->card_status,
  864. 'discipline1_id' => $this->card_discipline1_id,
  865. 'discipline2_id' => $this->card_discipline2_id,
  866. 'discipline3_id' => $this->card_discipline3_id,
  867. ]);
  868. session()->flash('success, Tesserato creato');
  869. $this->resetCardFields();
  870. $this->addCard = false;
  871. } catch (\Exception $ex) {
  872. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  873. }
  874. }
  875. public function editCard($id){
  876. try {
  877. $memberCard = \App\Models\MemberCard::findOrFail($id);
  878. if( !$memberCard) {
  879. session()->flash('error','Tesserato non trovato');
  880. } else {
  881. $this->card_card_id = $memberCard->card_id;
  882. $this->card_number = $memberCard->number;
  883. $this->card_date = $memberCard->date;
  884. $this->card_accept_date = $memberCard->accept_date;
  885. $this->card_status = $memberCard->status;
  886. $this->card_discipline1_id = $memberCard->discipline1_id;
  887. $this->card_discipline2_id = $memberCard->discipline2_id;
  888. $this->card_discipline3_id = $memberCard->discipline3_id;
  889. $this->cardDataId = $memberCard->id;
  890. $this->updateCard = true;
  891. $this->addCard = false;
  892. }
  893. } catch (\Exception $ex) {
  894. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  895. }
  896. }
  897. public function updateCard()
  898. {
  899. //$this->validate();
  900. $this->validate(['card_card_id' => 'required']);
  901. try {
  902. // in base alla card selezionata calcolo la scadenza
  903. $expire_date = null;
  904. if ($this->card_date != '')
  905. {
  906. $card = \App\Models\Card::findOrFail($this->card_card_id);
  907. if ($card->next_day_expire > 0 && $card->next_month_expire > 0)
  908. {
  909. $y = date("Y", strtotime($this->card_date));
  910. $m = strlen($card->next_month_expire) == 1 ? ('0' . $card->next_month_expire) : $card->next_month_expire;
  911. $next_exp = date($y . "-" . $m . "-" . $card->next_day_expire);
  912. if ($next_exp > $this->card_date)
  913. {
  914. $expire_date = $next_exp;
  915. }
  916. else
  917. $expire_date = date($y . "-" . $card->next_month_expire . "-" . $card->next_day_expire, strtotime(' + 1 years'));
  918. }
  919. else
  920. {
  921. if ($card->one_year_expire)
  922. {
  923. $expire_date = date("Y-m-d", strtotime($this->card_date . ' + 1 years'));
  924. }
  925. }
  926. }
  927. \App\Models\MemberCard::whereId($this->cardDataId)->update([
  928. 'member_id' => $this->dataId,
  929. 'card_id' => $this->card_card_id,
  930. 'number' => $this->card_number,
  931. 'date' => $this->card_date,
  932. 'accept_date' => $this->card_accept_date != '' ? $this->card_accept_date : $this->card_date,
  933. 'expire_date' => $expire_date,
  934. 'status' => $this->card_status,
  935. 'discipline1_id' => $this->card_discipline1_id,
  936. 'discipline2_id' => $this->card_discipline2_id,
  937. 'discipline3_id' => $this->card_discipline3_id,
  938. ]);
  939. session()->flash('success','Tesserato aggiornato');
  940. $this->resetCardFields();
  941. $this->updateCard = false;
  942. } catch (\Exception $ex) {
  943. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  944. }
  945. }
  946. public function cancelCard()
  947. {
  948. $this->addCard = false;
  949. $this->updateCard = false;
  950. $this->resetCardFields();
  951. }
  952. public function deleteCard($id)
  953. {
  954. try{
  955. \App\Models\MemberCard::find($id)->delete();
  956. session()->flash('success',"Tesserato eliminato");
  957. }catch(\Exception $e){
  958. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  959. }
  960. }
  961. // Courses
  962. public function addCourse()
  963. {
  964. $this->resetCourseFields();
  965. $this->addCourse = true;
  966. $this->updateCourse = false;
  967. }
  968. public function storeCourse()
  969. {
  970. $this->validate(['course_course_id' => 'required']);
  971. try {
  972. \App\Models\MemberCourse::create([
  973. 'member_id' => $this->dataId,
  974. 'course_id' => $this->course_course_id,
  975. 'date_from' => $this->course_date_from,
  976. 'date_to' => $this->course_date_to,
  977. 'course_subscription_id' => $this->course_course_subscription_id,
  978. 'status' => $this->course_status,
  979. 'subscribed' => false, // default non iscritto
  980. 'price' => currencyToDouble($this->course_price),
  981. 'subscription_price' => currencyToDouble($this->course_subscription_price),
  982. 'notes' => $this->course_note,
  983. 'months' => json_encode($this->course_months),
  984. 'when' => json_encode($this->course_when)
  985. ]);
  986. session()->flash('success, Corso creato');
  987. $this->resetCourseFields();
  988. $this->addCourse = false;
  989. } catch (\Exception $ex) {
  990. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  991. }
  992. }
  993. public function editCourse($id){
  994. try {
  995. $memberCourse = \App\Models\MemberCourse::findOrFail($id);
  996. if( !$memberCourse) {
  997. session()->flash('error','Corso non trovato');
  998. } else {
  999. $this->course_course_id = $memberCourse->course_id;
  1000. $this->course_date_from = $memberCourse->date_from;
  1001. $this->course_date_to = $memberCourse->date_to;
  1002. foreach(json_decode($memberCourse->when) as $z)
  1003. {
  1004. $this->course_when[] = array("day" => $z->day, "from" => $z->from, "to" => $z->to);
  1005. }
  1006. //$this->course_when = json_decode($memberCourse->when);
  1007. $this->course_course_subscription_id = $memberCourse->course_subscription_id;
  1008. $this->course_status = $memberCourse->status;
  1009. $this->course_subscribed = $memberCourse->subscribed == 1 ? true : false;
  1010. $this->course_price = formatPrice($memberCourse->price);
  1011. $this->course_subscription_price = formatPrice($memberCourse->subscription_price);
  1012. $this->course_note = $memberCourse->notes;
  1013. foreach(json_decode($memberCourse->months) as $z)
  1014. {
  1015. $this->course_months[] = array("m" => $z->m, "status" => $z->status);
  1016. }
  1017. $this->courseDataId = $memberCourse->id;
  1018. $this->updateCourse = true;
  1019. $this->addCourse = false;
  1020. }
  1021. } catch (\Exception $ex) {
  1022. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1023. }
  1024. }
  1025. public function updateCourse()
  1026. {
  1027. //$this->validate();
  1028. $this->validate(['course_course_id' => 'required']);
  1029. try {
  1030. \App\Models\MemberCourse::whereId($this->courseDataId)->update([
  1031. 'member_id' => $this->dataId,
  1032. 'course_id' => $this->course_course_id,
  1033. 'date_from' => $this->course_date_from,
  1034. 'date_to' => $this->course_date_to,
  1035. 'course_subscription_id' => $this->course_course_subscription_id,
  1036. 'status' => $this->course_status,
  1037. 'price' => currencyToDouble($this->course_price),
  1038. 'subscription_price' => currencyToDouble($this->course_subscription_price),
  1039. 'notes' => $this->course_note,
  1040. 'months' => json_encode($this->course_months),
  1041. 'when' => json_encode($this->course_when)
  1042. ]);
  1043. session()->flash('success','Corso aggiornato');
  1044. $this->resetCourseFields();
  1045. $this->updateCourse = false;
  1046. } catch (\Exception $ex) {
  1047. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1048. }
  1049. }
  1050. public function cancelCourse()
  1051. {
  1052. $this->addCourse = false;
  1053. $this->updateCourse = false;
  1054. $this->resetCourseFields();
  1055. }
  1056. public function deleteCourse($id)
  1057. {
  1058. try{
  1059. \App\Models\MemberCourse::find($id)->delete();
  1060. session()->flash('success',"Corso eliminato");
  1061. }catch(\Exception $e){
  1062. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1063. }
  1064. }
  1065. public function addRow()
  1066. {
  1067. $this->course_when[] = array('day' => array(), 'from' => '', 'to' => '');
  1068. }
  1069. public function delRow($idx)
  1070. {
  1071. unset($this->course_when[$idx]);
  1072. }
  1073. // Certificates
  1074. public function addCertificate()
  1075. {
  1076. $this->resetCertificateFields();
  1077. $this->addCertificate = true;
  1078. $this->updateCertificate = false;
  1079. }
  1080. public function storeCertificate()
  1081. {
  1082. $this->validate(['certificate_expire_date' => 'required']);
  1083. // $this->validate();
  1084. try {
  1085. $name = '';
  1086. try{
  1087. if ($this->certificate_filename)
  1088. {
  1089. $name = md5($this->certificate_filename . microtime()).'.'.$this->certificate_filename->extension();
  1090. $this->certificate_filename->storeAs('public', $name);
  1091. }
  1092. } catch (\Exception $ex) {
  1093. //session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1094. }
  1095. if ($this->dataId > -1)
  1096. {
  1097. \App\Models\MemberCertificate::create([
  1098. 'member_id' => $this->dataId,
  1099. 'type' => $this->certificate_type,
  1100. 'filename' => $name,
  1101. 'expire_date' => $this->certificate_expire_date,
  1102. 'status' => $this->certificate_status
  1103. ]);
  1104. }
  1105. /*else
  1106. {
  1107. $this->certificateTmp = new \App\Models\MemberCertificate();
  1108. $this->certificateTmp->type = $this->certificate_type;
  1109. $this->certificateTmp->filename = $name;
  1110. $this->certificateTmp->expire_date = $this->certificate_expire_date;
  1111. $this->certificateTmp->status = $this->certificate_status;
  1112. $this->certificateTmp->status = $this->certificate_status;
  1113. // s $this->member_certificates[] = $certificateTmp;
  1114. }*/
  1115. session()->flash('success, Tesserato creato');
  1116. $this->resetCertificateFields();
  1117. $this->addCertificate = false;
  1118. } catch (\Exception $ex) {
  1119. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1120. }
  1121. }
  1122. public function editCertificate($id){
  1123. try {
  1124. $memberCertificate = \App\Models\MemberCertificate::findOrFail($id);
  1125. if( !$memberCertificate) {
  1126. session()->flash('error','Tesserato non trovato');
  1127. } else {
  1128. $this->certificate_type = $memberCertificate->type;
  1129. $this->certificate_filename_old = $memberCertificate->filename;
  1130. $this->certificate_expire_date = $memberCertificate->expire_date;
  1131. $this->certificate_status = $memberCertificate->status;
  1132. $this->cardCertificateId = $memberCertificate->id;
  1133. $this->updateCertificate = true;
  1134. $this->addCertificate = false;
  1135. }
  1136. } catch (\Exception $ex) {
  1137. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1138. }
  1139. }
  1140. public function updateCertificate()
  1141. {
  1142. $this->validate(['certificate_expire_date' => 'required']);
  1143. try {
  1144. $name = '';
  1145. try{
  1146. if ($this->certificate_filename)
  1147. {
  1148. $name = md5($this->certificate_filename . microtime()).'.'.$this->certificate_filename->extension();
  1149. $this->certificate_filename->storeAs('public', $name);
  1150. }
  1151. } catch (\Exception $ex) {
  1152. //session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1153. }
  1154. \App\Models\MemberCertificate::whereId($this->cardCertificateId)->update([
  1155. 'member_id' => $this->dataId,
  1156. 'type' => $this->certificate_type,
  1157. 'filename' => $name != '' ? $name : $this->certificate_filename_old,
  1158. 'expire_date' => $this->certificate_expire_date,
  1159. 'status' => $this->certificate_status
  1160. ]);
  1161. session()->flash('success','Tesserato aggiornato');
  1162. $this->resetCertificateFields();
  1163. $this->updateCertificate = false;
  1164. } catch (\Exception $ex) {
  1165. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1166. }
  1167. }
  1168. public function cancelCertificate()
  1169. {
  1170. $this->addCertificate = false;
  1171. $this->updateCertificate = false;
  1172. $this->resetCertificateFields();
  1173. }
  1174. public function deleteCertificate($id)
  1175. {
  1176. try{
  1177. \App\Models\MemberCertificate::find($id)->delete();
  1178. session()->flash('success',"Tesserato eliminato");
  1179. }catch(\Exception $e){
  1180. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1181. }
  1182. }
  1183. // Gruppi di appartenenza
  1184. public function storeCategory()
  1185. {
  1186. $this->validate(['category_category_id' => 'required']);
  1187. try {
  1188. \App\Models\MemberCategory::create([
  1189. 'member_id' => $this->dataId,
  1190. 'category_id' => $this->category_category_id,
  1191. 'date' => \Carbon\Carbon::now()
  1192. ]);
  1193. session()->flash('success, Associazione creato');
  1194. $this->resetCategoryFields();
  1195. $this->addCard = false;
  1196. } catch (\Exception $ex) {
  1197. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1198. }
  1199. }
  1200. public function hideMsg()
  1201. {
  1202. $this->groupMsg = '';
  1203. }
  1204. public function storeCategoryWithID($id)
  1205. {
  1206. $this->groupMsg = '';
  1207. try {
  1208. if (\App\Models\MemberCategory::where('member_id', $this->dataId)->where('category_id', $id)->first())
  1209. {
  1210. $this->groupMsg = '<br>Attenzione, questo corso è stato già inserito';
  1211. }
  1212. else
  1213. {
  1214. \App\Models\MemberCategory::create([
  1215. 'member_id' => $this->dataId,
  1216. 'category_id' => $id,
  1217. 'date' => \Carbon\Carbon::now()
  1218. ]);
  1219. session()->flash('success, Associazione creato');
  1220. $this->resetCategoryFields();
  1221. $this->addCard = false;
  1222. }
  1223. } catch (\Exception $ex) {
  1224. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1225. }
  1226. }
  1227. public function deleteCategory($id)
  1228. {
  1229. try{
  1230. \App\Models\MemberCategory::find($id)->delete();
  1231. session()->flash('success',"Associazione eliminata");
  1232. }catch(\Exception $e){
  1233. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1234. }
  1235. }
  1236. public function setCourse($id)
  1237. {
  1238. $this->course_course_id = $id;
  1239. }
  1240. public function getNation($nation)
  1241. {
  1242. if ($nation > 0)
  1243. {
  1244. $ret = \App\Models\Nation::findOrFail($nation);
  1245. return $ret->name;
  1246. }
  1247. return "";
  1248. }
  1249. public function getProvince($province)
  1250. {
  1251. if ($province > 0)
  1252. {
  1253. $ret = \App\Models\Province::findOrFail($province);
  1254. return $ret->name;
  1255. }
  1256. return "";
  1257. }
  1258. public function getCity($city)
  1259. {
  1260. if ($city > 0)
  1261. {
  1262. $ret = \App\Models\City::findOrFail($city);
  1263. return $ret->name;
  1264. }
  1265. return "";
  1266. }
  1267. public function getFiscalCode()
  1268. {
  1269. $this->error_fc = false;
  1270. $cf = new codicefiscale();
  1271. $cf->setDateSeparator('-');
  1272. if ($this->first_name != '' && $this->last_name != '' && $this->birth_date != '' && $this->gender != '' && $this->birth_city_id > 0)
  1273. {
  1274. $code = '';
  1275. if ($this->birth_city_id > 0)
  1276. {
  1277. $code = \App\Models\City::findOrFail($this->birth_city_id)->code;
  1278. }
  1279. $codice = $cf->calcola($this->first_name, $this->last_name, $this->birth_date, $this->gender, $code);
  1280. $this->fiscal_code = $codice;
  1281. }
  1282. else
  1283. $this->error_fc = true;
  1284. }
  1285. public function setMonth($m)
  1286. {
  1287. $exist = -1;
  1288. foreach($this->course_months as $idx => $x)
  1289. {
  1290. if ($x["m"] == $m)
  1291. {
  1292. $exist = $idx;
  1293. break;
  1294. }
  1295. }
  1296. if ($exist > -1)
  1297. {
  1298. array_splice($this->course_months, $exist, 1);
  1299. }
  1300. else
  1301. {
  1302. $this->course_months[] = array("m" => $m, "status" => "");
  1303. }
  1304. /*
  1305. if (in_array($m, $this->course_months))
  1306. {
  1307. $i = array_search($m, $this->course_months);
  1308. array_splice($this->course_months, $i, 1);
  1309. }
  1310. else
  1311. {
  1312. $this->course_months[] = $m;
  1313. }*/
  1314. }
  1315. public function newPayment($course)
  1316. {
  1317. $c = \App\Models\Course::findOrFail($course["course_id"]);
  1318. return redirect()->to('/in?new=1&memberId=' . $this->dataId . '&causalId=' . $c->causal_id . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=' . $this->createSubscription . (sizeof($this->payMonths) > 0 ? '&months=' . implode("|", $this->payMonths) : "") . '&price=' . $course["price"] . '&subscription_price=' . $course["subscription_price"] . "&courseId=" . $course["id"]);
  1319. }
  1320. public function block($course)
  1321. {
  1322. $xxx = json_decode($course["months"]);
  1323. foreach($xxx as $idx => $mm)
  1324. {
  1325. if (in_array($mm->m, $this->payMonths))
  1326. {
  1327. $xxx[$idx]->status = 2;
  1328. }
  1329. }
  1330. $c = \App\Models\MemberCourse::findOrFail($course["id"]);
  1331. $c->months = json_encode($xxx);
  1332. $c->save();
  1333. $this->payMonths = array();
  1334. }
  1335. public function setPayMonth($m, $months)
  1336. {
  1337. if (in_array($m, $this->payMonths))
  1338. {
  1339. $i = array_search($m, $this->payMonths);
  1340. array_splice($this->payMonths, $i, 1);
  1341. }
  1342. else
  1343. {
  1344. foreach(json_decode($months) as $mm)
  1345. {
  1346. if ($mm->m == $m)
  1347. {
  1348. if ($mm->status == "")
  1349. $this->payMonths[] = $m;
  1350. }
  1351. }
  1352. }
  1353. }
  1354. public function setCreateSubscription($subscribed)
  1355. {
  1356. if (!$subscribed)
  1357. $this->createSubscription = !$this->createSubscription;
  1358. }
  1359. public function showHideCourse($id)
  1360. {
  1361. if (in_array($id, $this->showCourse))
  1362. {
  1363. $i = array_search($id, $this->showCourse);
  1364. array_splice($this->showCourse, $i, 1);
  1365. }
  1366. else
  1367. {
  1368. $this->showCourse[] = $id;
  1369. }
  1370. }
  1371. public function getMonthStatus($m, $months)
  1372. {
  1373. $class = "grey";
  1374. foreach(json_decode($months) as $mm)
  1375. {
  1376. if ($mm->m == $m)
  1377. {
  1378. if ($mm->status == "")
  1379. {
  1380. if (in_array($m, $this->payMonths))
  1381. $class = "blue";
  1382. else
  1383. $class = "orange";
  1384. }
  1385. if ($mm->status == "1")
  1386. {
  1387. $class = "green";
  1388. }
  1389. if ($mm->status == "2")
  1390. {
  1391. $class = "yellow";
  1392. }
  1393. }
  1394. }
  1395. return $class;
  1396. }
  1397. public function getSubscriptionStatus($subscribed)
  1398. {
  1399. $class = "grey";
  1400. if ($this->createSubscription)
  1401. $class = "blue";
  1402. else
  1403. $class = "orange";
  1404. if ($subscribed)
  1405. $class = "green";
  1406. return $class;
  1407. }
  1408. public function checkMonth($m)
  1409. {
  1410. $ret = false;
  1411. foreach($this->course_months as $idx => $x)
  1412. {
  1413. if ($x["m"] == $m)
  1414. {
  1415. $ret = true;
  1416. break;
  1417. }
  1418. }
  1419. return $ret;
  1420. }
  1421. public function setDay($idx, $d)
  1422. {
  1423. if (in_array($d, $this->course_when[$idx]["day"]))
  1424. {
  1425. $i = array_search($d, $this->course_when[$idx]["day"]);
  1426. array_splice($this->course_when[$idx]["day"], $i, 1);
  1427. }
  1428. else
  1429. {
  1430. $this->course_when[$idx]["day"][] = $d;
  1431. }
  1432. }
  1433. public function getMonth($m)
  1434. {
  1435. $ret = '';
  1436. switch ($m) {
  1437. case 1:
  1438. $ret = 'Gennaio';
  1439. break;
  1440. case 2:
  1441. $ret = 'Febbraio';
  1442. break;
  1443. case 3:
  1444. $ret = 'Marzo';
  1445. break;
  1446. case 4:
  1447. $ret = 'Aprile';
  1448. break;
  1449. case 5:
  1450. $ret = 'Maggio';
  1451. break;
  1452. case 6:
  1453. $ret = 'Giugno';
  1454. break;
  1455. case 7:
  1456. $ret = 'Luglio';
  1457. break;
  1458. case 8:
  1459. $ret = 'Agosto';
  1460. break;
  1461. case 9:
  1462. $ret = 'Settembre';
  1463. break;
  1464. case 10:
  1465. $ret = 'Ottobre';
  1466. break;
  1467. case 11:
  1468. $ret = 'Novembre';
  1469. break;
  1470. case 12:
  1471. $ret = 'Dicembre';
  1472. break;
  1473. default:
  1474. $ret = '';
  1475. break;
  1476. }
  1477. return $ret;
  1478. }
  1479. }
  1480. class codicefiscale {
  1481. /**
  1482. * Array delle consonanti
  1483. */
  1484. protected $_consonanti = array(
  1485. 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K',
  1486. 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T',
  1487. 'V', 'W', 'X', 'Y', 'Z'
  1488. );
  1489. /**
  1490. * Array delle vocali
  1491. */
  1492. protected $_vocali = array(
  1493. 'A', 'E', 'I', 'O', 'U'
  1494. );
  1495. /**
  1496. * Array per il calcolo della lettera del mese
  1497. * Al numero del mese corrisponde una lettera
  1498. */
  1499. protected $_mesi = array(
  1500. 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => 'E',
  1501. 6 => 'H', 7 => 'L', 8 => 'M', 9 => 'P', 10 => 'R',
  1502. 11 => 'S', 12 => 'T'
  1503. );
  1504. protected $_pari = array(
  1505. '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4,
  1506. '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9,
  1507. 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4,
  1508. 'F' => 5, 'G' => 6, 'H' => 7, 'I' => 8, 'J' => 9,
  1509. 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14,
  1510. 'P' => 15, 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19,
  1511. 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, 'Y' => 24,
  1512. 'Z' => 25
  1513. );
  1514. protected $_dispari = array(
  1515. '0' => 1, '1' => 0, '2' => 5, '3' => 7, '4' => 9,
  1516. '5' => 13, '6' => 15, '7' => 17, '8' => 19, '9' => 21,
  1517. 'A' => 1, 'B' => 0, 'C' => 5, 'D' => 7, 'E' => 9,
  1518. 'F' => 13, 'G' => 15, 'H' => 17, 'I' => 19, 'J' => 21,
  1519. 'K' => 2, 'L' => 4, 'M' => 18, 'N' => 20, 'O' => 11,
  1520. 'P' => 3, 'Q' => 6, 'R' => 8, 'S' => 12, 'T' => 14,
  1521. 'U' => 16, 'V' => 10, 'W' => 22, 'X' => 25, 'Y' => 24,
  1522. 'Z' => 23
  1523. );
  1524. protected $_controllo = array(
  1525. '0' => 'A', '1' => 'B', '2' => 'C', '3' => 'D',
  1526. '4' => 'E', '5' => 'F', '6' => 'G', '7' => 'H',
  1527. '8' => 'I', '9' => 'J', '10' => 'K', '11' => 'L',
  1528. '12' => 'M', '13' => 'N', '14' => 'O', '15' => 'P',
  1529. '16' => 'Q', '17' => 'R', '18' => 'S', '19' => 'T',
  1530. '20' => 'U', '21' => 'V', '22' => 'W', '23' => 'X',
  1531. '24' => 'Y', '25' => 'Z'
  1532. );
  1533. /**
  1534. * Stringa di errore
  1535. */
  1536. protected $_error = null;
  1537. /**
  1538. * Separatore per la data di nascita
  1539. */
  1540. protected $_dateSeparator = '/';
  1541. /**
  1542. * Percorso del file del database SQLite
  1543. * dei codici catastali
  1544. */
  1545. protected $_dbCatastali = null;
  1546. /**
  1547. * Trasforma la stringa passata in un array di lettere
  1548. * e lo incrocia con un ulteriore array
  1549. */
  1550. protected function _getLettere($string, array $haystack) {
  1551. $letters = array();
  1552. foreach(str_split($string) as $needle) {
  1553. if (in_array($needle, $haystack)) {
  1554. $letters[] = $needle;
  1555. }
  1556. }
  1557. return $letters;
  1558. }
  1559. /**
  1560. * Ritorna un array con le vocali di una data stringa
  1561. */
  1562. protected function _getVocali($string) {
  1563. return $this->_getLettere($string, $this->_vocali);
  1564. }
  1565. /**
  1566. * Ritorna un array con le consonanti di una data stringa
  1567. */
  1568. protected function _getConsonanti($string) {
  1569. return $this->_getLettere($string, $this->_consonanti);
  1570. }
  1571. /**
  1572. * Pulisce la stringa filtrando tutti i caratteri che
  1573. * non sono lettere. Lo switch $toupper se impostato a TRUE
  1574. * converte la stringa risultante in MAIUSCOLO.
  1575. */
  1576. protected function _sanitize($string, $toupper = true) {
  1577. $result = preg_replace('/[^A-Za-z]*/', '', $string);
  1578. return ($toupper) ? strtoupper($result) : $result;
  1579. }
  1580. /**
  1581. * Se la stringa passata a funzione e' costituita
  1582. * da meno di 3 caratteri, rimpiazza le lettere
  1583. * mancanti con la lettera X.
  1584. */
  1585. protected function _addMissingX($string) {
  1586. $code = $string;
  1587. while(strlen($code) < 3) {
  1588. $code .= 'X';
  1589. }
  1590. return $code;
  1591. }
  1592. /**
  1593. * Ottiene il codice identificativo del nome
  1594. */
  1595. protected function _calcolaNome($string) {
  1596. $nome = $this->_sanitize($string);
  1597. $code = '';
  1598. // Se il nome inserito e' piu' corto di 3 lettere
  1599. // si aggiungono tante X quanti sono i caratteri
  1600. // mancanti.
  1601. if (strlen($nome) < 3) {
  1602. return $this->_addMissingX($nome);
  1603. }
  1604. $nome_cons = $this->_getConsonanti($nome);
  1605. // Se le consonanti contenute nel nome sono minori
  1606. // o uguali a 3 vengono considerate nell'ordine in cui
  1607. // compaiono.
  1608. if (count($nome_cons) <= 3) {
  1609. $code = implode('', $nome_cons);
  1610. } else {
  1611. // Se invece abbiamo almeno 4 consonanti, prendiamo
  1612. // la prima, la terza e la quarta.
  1613. for($i=0; $i<4; $i++) {
  1614. if ($i == 1) continue;
  1615. if (!empty($nome_cons[$i])) {
  1616. $code .= $nome_cons[$i];
  1617. }
  1618. }
  1619. }
  1620. // Se compaiono meno di 3 consonanti nel nome, si
  1621. // utilizzano le vocali, nell'ordine in cui compaiono
  1622. // nel nome.
  1623. if (strlen($code) < 3) {
  1624. $nome_voc = $this->_getVocali($nome);
  1625. while (strlen($code) < 3) {
  1626. $code .= array_shift($nome_voc);
  1627. }
  1628. }
  1629. return $code;
  1630. }
  1631. protected function _calcolaCognome($string) {
  1632. $cognome = $this->_sanitize($string);
  1633. $code = '';
  1634. // Se il cognome inserito e' piu' corto di 3 lettere
  1635. // si aggiungono tante X quanti sono i caratteri
  1636. // mancanti.
  1637. if (strlen($cognome) < 3) {
  1638. return $this->_addMissingX($cognome);
  1639. }
  1640. $cognome_cons = $this->_getConsonanti($cognome);
  1641. // Per il calcolo del cognome si prendono le prime
  1642. // 3 consonanti.
  1643. for ($i=0; $i<3; $i++) {
  1644. if (array_key_exists($i, $cognome_cons)) {
  1645. $code .= $cognome_cons[$i];
  1646. }
  1647. }
  1648. // Se le consonanti non bastano, vengono prese
  1649. // le vocali nell'ordine in cui compaiono.
  1650. if (strlen($code) < 3) {
  1651. $cognome_voc = $this->_getVocali($cognome);
  1652. while (strlen($code) < 3) {
  1653. $code .= array_shift($cognome_voc);
  1654. }
  1655. }
  1656. return $code;
  1657. }
  1658. /**
  1659. * Imposta il separatore di data ( default: / )
  1660. */
  1661. public function setDateSeparator($char) {
  1662. $this->_dateSeparator = $char;
  1663. return $this;
  1664. }
  1665. /**
  1666. * Ritorna la parte di codice fiscale corrispondente
  1667. * alla data di nascita del soggetto (Forma: AAMGG)
  1668. */
  1669. protected function _calcolaDataNascita($data, $sesso) {
  1670. $dn = explode($this->_dateSeparator, $data);
  1671. $giorno = (int) @$dn[2];
  1672. $mese = (int) @$dn[1];
  1673. $anno = (int) @$dn[0];
  1674. // Le ultime due cifre dell'anno di nascita
  1675. $aa = substr($anno, -2);
  1676. // La lettera corrispondente al mese di nascita
  1677. $mm = $this->_mesi[$mese];
  1678. // Il giorno viene calcolato a seconda del sesso
  1679. // del soggetto di cui si calcola il codice:
  1680. // se e' Maschio si mette il giorno reale, se e'
  1681. // Femmina viene aggiungo 40 a questo numero.
  1682. $gg = (strtoupper($sesso) == 'M') ? $giorno : ($giorno + 40);
  1683. // Bug #1: Thanks to Luca
  1684. if (strlen($gg) < 2) $gg = '0' . $gg;
  1685. return $aa . $mm . $gg;
  1686. }
  1687. /**
  1688. * Ritorna la cifra di controllo sulla base dei
  1689. * 15 caratteri del codice fiscale calcolati.
  1690. */
  1691. protected function _calcolaCifraControllo($codice) {
  1692. $code = str_split($codice);
  1693. $sum = 0;
  1694. for($i=1; $i <= count($code); $i++) {
  1695. $cifra = $code[$i-1];
  1696. $sum += ($i % 2) ? $this->_dispari[$cifra] : $this->_pari[$cifra];
  1697. }
  1698. $sum %= 26;
  1699. return $this->_controllo[$sum];
  1700. }
  1701. /**
  1702. * Imposta il messaggio di errore
  1703. */
  1704. protected function _setError($string) {
  1705. $this->_error = $string;
  1706. }
  1707. /**
  1708. * Verifica la presenza di un errore.
  1709. * Ritorna TRUE se presente, FALSE altrimenti.
  1710. */
  1711. public function hasError() {
  1712. return !is_null($this->_error);
  1713. }
  1714. /**
  1715. * Ritorna la stringa di errore
  1716. */
  1717. public function getError() {
  1718. return $this->_error;
  1719. }
  1720. /**
  1721. * Ritorna il codice fiscale utilizzando i parametri
  1722. * passati a funzione. Se si verifica
  1723. */
  1724. public function calcola($nome, $cognome, $data, $sesso, $comune) {
  1725. $codice = $this->_calcolaCognome($cognome) .
  1726. $this->_calcolaNome($nome) .
  1727. $this->_calcolaDataNascita($data, $sesso) .
  1728. $comune;
  1729. if ($this->hasError()) {
  1730. return false;
  1731. }
  1732. $codice .= $this->_calcolaCifraControllo($codice);
  1733. if (strlen($codice) != 16) {
  1734. //$this->_setError(self::ERR_GENERIC);
  1735. return 'ERROR';
  1736. }
  1737. return $codice;
  1738. }
  1739. }