Member.php 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591
  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. public $type = 'dati';
  18. public $from = '';
  19. public $selectedCourseMember = 0;
  20. protected $messages = [
  21. 'birth_nation_id.required' => 'birth_nation_id',
  22. 'birth_province_id.required' => 'birth_province_id',
  23. 'birth_city_id.required' => 'birth_city_id',
  24. 'nation_id.required' => 'nation_id',
  25. 'province_id.required' => 'province_id',
  26. 'city_id.required' => 'city_id',
  27. 'gender' => 'gender'
  28. ];
  29. public function change($type)
  30. {
  31. $this->type = $type;
  32. }
  33. public function sortBy($field)
  34. {
  35. if ($this->sortField === $field) {
  36. $this->sortAsc = ! $this->sortAsc;
  37. } else {
  38. $this->sortAsc = true;
  39. }
  40. $this->sortField = $field;
  41. }
  42. public $records, $first_name, $last_name, $image, $image_old, $status, $birth_place, $birth_city_id, $birth_province_id, $birth_nation_id, $birth_date, $gender, $no_send_mail, $exclude_from_records, $fiscal_code, $address, $zip_code, $nation_id, $province_id, $city_id, $phone, $phone2, $phone3, $email, $enabled, $dataId, $update = false, $add = false;
  43. public $isSaving = false;
  44. public $importoBorsellino, $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, $mother_document_files, $father_document_files;
  45. public $document_type, $document_number, $document_from, $document_expire_date, $document_files, $document_files_old;
  46. public $selectId = 0;
  47. public $causalId = 0;
  48. public $error_fc = false;
  49. public $under18 = false;
  50. public $money = 0;
  51. public $refreshAfter = 0;
  52. public $checkedAll = false;
  53. public $multipleIds = [];
  54. public $multipleAction = '';
  55. public $isItaly = true;
  56. public $isBirthItaly = true;
  57. public $showDetail = false;
  58. public $currentMember;
  59. public $currentStatus;
  60. public $age = '';
  61. public $disciplines = array();
  62. public $cards = array();
  63. public $categories = array();
  64. public $courses = array();
  65. public $course_names = array();
  66. public $course_levels = array();
  67. public $course_types = array();
  68. public $course_frequencies = array();
  69. public $course_subscriptions = array();
  70. public $createSubscription = false;
  71. public $payMonths = array();
  72. public $suspendedMonths = array();
  73. public $showCourse = array();
  74. public $searchTxt;
  75. public $search;
  76. public $showReset = false;
  77. public $advanced = false;
  78. public $birthNations = array();
  79. public $birthProvinces = array();
  80. public $birthCities = array();
  81. public $active;
  82. // Card data
  83. 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;
  84. // Categories data
  85. public $member_categories = array(), $category_category_id;
  86. // Courses data
  87. public $member_courses = array(), $course_course_id, $course_course_type, $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;
  88. public $course_months_list = [];
  89. public $course_price_list = [];
  90. public $course_name, $course_level_id, $course_type_id, $course_frequency_id;
  91. // Certificates data
  92. public $member_certificates = array(), $certificate_type, $certificate_filename_old, $certificate_filename, $certificate_expire_date, $certificate_status, $addCertificate, $updateCertificate, $certificateDataId;
  93. public $filterCard = [];
  94. public $filterCategory = [];
  95. public $filterCertNormal = 0;
  96. public $filterCertAgonistic = 0;
  97. public $filterCertScaduto = 0;
  98. public $filterCertInScadenza = 0;
  99. protected $rules = [
  100. 'first_name' => 'required',
  101. 'last_name' => 'required',
  102. 'email' => 'required',
  103. 'phone' => 'required',
  104. 'birth_date' => 'before_or_equal:today'
  105. ];
  106. public function resetFields()
  107. {
  108. $this->dataId = -1;
  109. $this->first_name = '';
  110. $this->last_name = '';
  111. $this->status = '';
  112. $this->birth_city_id = null;
  113. $this->birth_province_id = null;
  114. $this->birth_nation_id = null;
  115. $this->birth_date = null;
  116. $this->birth_place = '';
  117. $this->importoBorsellino = 0;
  118. $this->father_name = '';
  119. $this->mother_name = '';
  120. $this->father_email = '';
  121. $this->mother_email = '';
  122. $this->father_phone = '';
  123. $this->mother_phone = '';
  124. $this->father_fiscal_code = '';
  125. $this->mother_fiscal_code = '';
  126. $this->father_doc_number = '';
  127. $this->mother_doc_number = '';
  128. $this->father_doc_type = '';
  129. $this->mother_doc_type = '';
  130. $this->mother_document_files = array();
  131. $this->father_document_files = array();
  132. $this->gender = null;
  133. $this->no_send_mail = false;
  134. $this->exclude_from_records = false;
  135. $this->fiscal_code = '';
  136. $this->address = '';
  137. $this->zip_code = '';
  138. $this->document_type = '';
  139. $this->document_number = '';
  140. $this->document_from = '';
  141. $this->document_expire_date = null;
  142. $this->document_files = array();
  143. //$this->nation_id = null;
  144. //$this->province_id = null;
  145. $this->nation_id = null;
  146. $this->province_id = null;
  147. $this->city_id = null;
  148. $this->phone = '';
  149. $this->phone2 = '';
  150. $this->phone3 = '';
  151. $this->email = '';
  152. $this->enabled = true;
  153. $this->under18 = false;
  154. $this->money = 0;
  155. $this->image = null;
  156. $this->age = '';
  157. $this->error_fc = false;
  158. $this->isSaving = false;
  159. $this->emit('load-data-table');
  160. }
  161. public function resetCardFields()
  162. {
  163. $this->card_card_id = null;
  164. $this->card_number = '';
  165. $this->card_date = null;
  166. $this->card_accept_date = null;
  167. $this->card_status = 0;
  168. $this->card_discipline1_id = null;
  169. $this->card_discipline2_id = null;
  170. $this->card_discipline3_id = null;
  171. }
  172. public function resetCertificateFields()
  173. {
  174. $this->certificate_type = 'N';
  175. $this->certificate_filename = '';
  176. $this->certificate_filename_old = '';
  177. $this->certificate_expire_date = null;
  178. $this->certificate_status = 0;
  179. }
  180. public function resetCourseFields()
  181. {
  182. $this->course_course_id = null;
  183. $this->course_course_type = 'standard';
  184. $this->course_months_list = [];
  185. $this->course_price_list = [];
  186. $this->course_when = array();
  187. $this->course_when[] = array('day' => array(), 'from' => '', 'to' => '');
  188. $this->course_date_from = null;
  189. $this->course_date_to = null;
  190. $this->course_course_subscription_id = null;
  191. $this->course_status = 0;
  192. $this->course_price = 0;
  193. $this->course_subscription_price = 0;
  194. $this->course_exist = false;
  195. $this->course_subscribed = false;
  196. $this->course_months = array();
  197. $this->course_note = '';
  198. $this->course_name = '';
  199. $this->course_level_id = '';
  200. $this->course_type_id = '';
  201. $this->course_frequency_id = '';
  202. }
  203. public function executeMultipleAction()
  204. {
  205. if ($this->multipleAction == 'delete')
  206. $this->multipleDelete();
  207. }
  208. public function updatedImage()
  209. {
  210. $this->validate([
  211. 'image' => 'image|max:1024',
  212. ]);
  213. $this->image_old = '';
  214. }
  215. /*
  216. public function updatedCourseName()
  217. {
  218. $this->course_course_id = null;
  219. $this->course_level_id = '';
  220. $this->course_type_id = '';
  221. $this->course_frequency_id = '';
  222. $levels_ids = [];
  223. if ($this->course_name != '') {
  224. list($n, $y) = explode("(", $this->course_name);
  225. $y = trim(str_replace(")", "", $y));
  226. $all = \App\Models\Course::where('name', 'like', '%' . trim($n) . "%")->where('year', $y)->where('enabled', true)->get();
  227. foreach ($all as $a) {
  228. $levels_ids[] = $a->course_level_id;
  229. }
  230. }
  231. $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->whereIn('id', $levels_ids)->get();
  232. $this->course_types = [];
  233. $this->course_frequencies = [];
  234. }
  235. public function updatedCourseLevelId()
  236. {
  237. $this->course_course_id = null;
  238. $this->course_type_id = '';
  239. $this->course_frequency_id = '';
  240. $types_ids = [];
  241. if ($this->course_level_id != '') {
  242. list($n, $y) = explode("(", $this->course_name);
  243. $y = trim(str_replace(")", "", $y));
  244. $all = \App\Models\Course::where('name', 'like', '%' . trim($n) . "%")->where('year', $y)->where('enabled', true)->where('course_level_id', $this->course_level_id)->get();
  245. foreach ($all as $a) {
  246. $types_ids[] = $a->course_type_id;
  247. }
  248. }
  249. $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->whereIn('id', $types_ids)->get();
  250. $this->course_frequencies = [];
  251. }
  252. public function updatedCourseTypeId()
  253. {
  254. $this->course_course_id = null;
  255. $this->course_frequency_id = '';
  256. $frequencies_ids = [];
  257. if ($this->course_type_id != '') {
  258. list($n, $y) = explode("(", $this->course_name);
  259. $y = trim(str_replace(")", "", $y));
  260. $all = \App\Models\Course::where('name', 'like', '%' . trim($n) . "%")->where('year', $y)->where('enabled', true)->where('course_level_id', $this->course_level_id)->where('course_type_id', $this->course_type_id)->get();
  261. foreach ($all as $a) {
  262. $frequencies_ids[] = $a->course_frequency_id;
  263. }
  264. }
  265. $this->course_frequencies = \App\Models\CourseFrequency::select('*')->where('enabled', true)->whereIn('id', $frequencies_ids)->get();
  266. }
  267. public function updatedCourseFrequencyId()
  268. {
  269. $this->course_course_id = null;
  270. if ($this->course_frequency_id != '') {
  271. list($n, $y) = explode("(", $this->course_name);
  272. $y = trim(str_replace(")", "", $y));
  273. $this->course_course_id = \App\Models\Course::where('name', 'like', '%' . trim($n) . "%")->where('year', $y)->where('course_level_id', $this->course_level_id)->where('course_type_id', $this->course_type_id)->where('course_frequency_id', $this->course_frequency_id)->first()->id;
  274. if ($this->course_course_id > 0) {
  275. $c = \App\Models\Course::findOrFail($this->course_course_id);
  276. $this->course_price = formatPrice($c->price);
  277. $this->course_subscription_price = formatPrice($c->subscription_price);
  278. // Controllo se sono già iscritto la corso
  279. $this->course_exist = \App\Models\MemberCourse::where('course_id', $this->course_course_id)->where('member_id', $this->dataId)->count() > 0;
  280. } else {
  281. $this->course_price = 0;
  282. $this->course_subscription_price = 0;
  283. $this->course_exist = false;
  284. }
  285. } else {
  286. $this->course_price = 0;
  287. $this->course_subscription_price = 0;
  288. $this->course_exist = false;
  289. }
  290. }*/
  291. public function updatedCourseCourseType()
  292. {
  293. $this->course_course_id = null;
  294. }
  295. public function updatedCourseCourseSubscriptionId()
  296. {
  297. $this->course_price = 0;
  298. if (isset($this->course_price_list[$this->course_course_subscription_id]))
  299. $this->course_price = $this->course_price_list[$this->course_course_subscription_id];
  300. }
  301. public $documents = [];
  302. public $father_documents = [];
  303. public $mother_documents = [];
  304. public function removeDocument($idx, $type)
  305. {
  306. if ($type == 'father') {
  307. unset($this->father_document_files[$idx]);
  308. } elseif ($type == 'mother') {
  309. unset($this->mother_document_files[$idx]);
  310. } else {
  311. unset($this->document_files[$idx]);
  312. }
  313. }
  314. public function updatedDocuments()
  315. {
  316. foreach ($this->documents as $document) {
  317. $name = $document->getClientOriginalName();
  318. $document->storeAs('public', $name);
  319. $this->document_files[] = $name;
  320. }
  321. $this->documents = [];
  322. }
  323. public function updatedFatherDocuments()
  324. {
  325. foreach ($this->father_documents as $document) {
  326. $name = $document->getClientOriginalName();
  327. $document->storeAs('public', $name);
  328. $this->father_document_files[] = $name;
  329. }
  330. $this->father_documents = [];
  331. }
  332. public function updatedMotherDocuments()
  333. {
  334. foreach ($this->mother_documents as $document) {
  335. $name = $document->getClientOriginalName();
  336. $document->storeAs('public', $name);
  337. $this->mother_document_files[] = $name;
  338. }
  339. $this->mother_documents = [];
  340. }
  341. public function resetCategoryFields()
  342. {
  343. $this->category_category_id = null;
  344. }
  345. public function getCategories($records, $indentation)
  346. {
  347. foreach ($records as $record) {
  348. // $this->categories[] = array('id' => $record->id, 'name' => str_repeat(" / ", $indentation) . $record->name);
  349. $this->categories[] = array('id' => $record->id, 'name' => $record->getTree());
  350. if (count($record->childs))
  351. $this->getCategories($record->childs, $indentation + 1);
  352. }
  353. }
  354. public function getCourses($records, $indentation)
  355. {
  356. foreach ($records as $record) {
  357. // $this->categories[] = array('id' => $record->id, 'name' => str_repeat(" / ", $indentation) . $record->name);
  358. $this->courses[] = array('id' => $record->id, 'name' => $record->getTree());
  359. if (count($record->childs))
  360. $this->getCourses($record->childs, $indentation + 1);
  361. }
  362. }
  363. public function updatedBirthDate()
  364. {
  365. $this->validateOnly('birth_date');
  366. $date1 = new DateTime($this->birth_date);
  367. $date2 = new DateTime("now");
  368. $interval = $date1->diff($date2);
  369. $this->age = $interval->y . " anni";
  370. $this->under18 = $interval->y < 18;
  371. }
  372. public function mount()
  373. {
  374. if (isset($_GET["new"])) {
  375. $this->refreshAfter = 1;
  376. $this->add();
  377. }
  378. if (isset($_GET["from"])) {
  379. $this->from = $_GET["from"];
  380. }
  381. $this->cards = \App\Models\Card::select('id', 'name')->get();
  382. $this->disciplines = \App\Models\Discipline::select('id', 'name')->get();
  383. $this->categories = array();
  384. $this->getCategories(\App\Models\Category::select('id', 'name')->where('parent_id', null)->get(), 0);
  385. // $this->getCourses(\App\Models\Course::select('id', 'name')->where('parent_id', null)->get(), 0);
  386. /*$this->nations = \App\Models\Nation::select('id', 'name')->orderBy('name')->get();
  387. $this->provinces = \App\Models\Province::where('nation_id', 1)->orderBy('name')->get();
  388. $this->cities = \App\Models\City::where('province_id', 178)->orderBy('name')->orderBy('name')->get();*/
  389. $c = \App\Models\Causal::where('type', 'IN')->where('money', true)->first();
  390. if ($c)
  391. $this->causalId = $c->id;
  392. if (isset($_GET["member_detail"])) {
  393. $this->showDetailF($_GET["member_detail"]);
  394. $this->refreshAfter = 1;
  395. }
  396. /*$this->birthNations = \App\Models\Nation::select('id', 'name')->orderBy('name')->get();
  397. $this->birthProvinces = \App\Models\Province::where('nation_id', 1)->orderBy('name')->get();
  398. $this->birthCities = \App\Models\City::where('province_id', 178)->orderBy('name')->orderBy('name')->get();*/
  399. }
  400. public function updated()
  401. {
  402. if ($this->isSaving) {
  403. $zzz = [];
  404. if ($this->birth_nation_id == null)
  405. $zzz[] = 'birth_nation_id=' . $this->birth_nation_id;
  406. if ($this->isBirthItaly) {
  407. if ($this->birth_province_id == null)
  408. $zzz[] = 'birth_province_id=' . $this->birth_province_id;
  409. if ($this->birth_city_id == null)
  410. $zzz[] = 'birth_city_id=' . $this->birth_city_id;
  411. }
  412. if ($this->nation_id == null)
  413. $zzz[] = 'nation_id=' . $this->nation_id;
  414. if ($this->isItaly) {
  415. if ($this->province_id == null)
  416. $zzz[] = 'province_id=' . $this->province_id;
  417. if ($this->city_id == null)
  418. $zzz[] = 'city_id=' . $this->city_id;
  419. }
  420. $this->emit('setErrorMsg', $zzz);
  421. }
  422. // $this->emit('load-select');
  423. }
  424. public function hydrate()
  425. {
  426. if ($this->isSaving) {
  427. $zzz = [];
  428. if ($this->birth_nation_id == null)
  429. $zzz[] = 'birth_nation_id=' . $this->birth_nation_id;
  430. if ($this->isBirthItaly) {
  431. if ($this->birth_province_id == null)
  432. $zzz[] = 'birth_province_id=' . $this->birth_province_id;
  433. if ($this->birth_city_id == null)
  434. $zzz[] = 'birth_city_id=' . $this->birth_city_id;
  435. }
  436. if ($this->nation_id == null)
  437. $zzz[] = 'nation_id=' . $this->nation_id;
  438. if ($this->isItaly) {
  439. if ($this->province_id == null)
  440. $zzz[] = 'province_id=' . $this->province_id;
  441. if ($this->city_id == null)
  442. $zzz[] = 'city_id=' . $this->city_id;
  443. }
  444. $this->emit('setErrorMsg', $zzz);
  445. }
  446. $this->emit('load-select');
  447. // $this->emit('destroy-data-table');
  448. }
  449. public function checkIsItaly()
  450. {
  451. $n = \App\Models\Nation::findOrFail($this->nation_id);
  452. $this->isItaly = $n->is_italy;
  453. }
  454. public function checkIsBirthItaly()
  455. {
  456. if ($this->birth_nation_id > 0) {
  457. $n = \App\Models\Nation::findOrFail($this->birth_nation_id);
  458. $this->isBirthItaly = $n->is_italy;
  459. } else
  460. $this->isBirthItaly = false;
  461. }
  462. /*public function loadProvinces()
  463. {
  464. $n = \App\Models\Nation::findOrFail($this->nation_id);
  465. $this->isItaly = $n->is_italy;
  466. $this->provinces = \App\Models\Province::where('nation_id', $this->nation_id)->orderBy('name')->get();
  467. $this->cities = array();
  468. $this->selectId++;
  469. }
  470. public function loadCities()
  471. {
  472. $this->cities = \App\Models\City::where('province_id', $this->province_id)->orderBy('name')->orderBy('name')->get();
  473. $this->selectId++;
  474. }
  475. public function loadBirthProvinces()
  476. {
  477. $n = \App\Models\Nation::findOrFail($this->birth_nation_id);
  478. $this->isBirthItaly = $n->is_italy;
  479. $this->birthProvinces = \App\Models\Province::where('nation_id', $this->birth_nation_id)->orderBy('name')->get();
  480. $this->birthCities = array();
  481. $this->selectId++;
  482. }
  483. public function loadBirthCities()
  484. {
  485. $this->birthCities = \App\Models\City::where('province_id', $this->birth_province_id)->get();
  486. $this->selectId++;
  487. }
  488. */
  489. public function search()
  490. {
  491. if ($this->searchTxt != '') {
  492. $this->search = $this->searchTxt;
  493. $this->showReset = true;
  494. }
  495. }
  496. public function resetSearch()
  497. {
  498. $this->showReset = false;
  499. $this->searchTxt = '';
  500. $this->search = $this->searchTxt;
  501. }
  502. public function advancedSearch()
  503. {
  504. $this->advanced = true;
  505. }
  506. public function advancedSearchCancel()
  507. {
  508. $this->filterCard = [];
  509. $this->filterCategory = [];
  510. $this->filterCertNormal = 0;
  511. $this->filterCertAgonistic = 0;
  512. $this->filterCertScaduto = 0;
  513. $this->filterCertInScadenza = 0;
  514. $this->advanced = false;
  515. }
  516. public function render()
  517. {
  518. $this->course_names = [];
  519. $allC = \App\Models\Course::orderBy('name')->get();
  520. foreach ($allC as $c) {
  521. $cN = $c->name . " (" . $c->year . ")";
  522. if (!in_array($cN, $this->course_names))
  523. $this->course_names[] = $cN;
  524. }
  525. //$this->course_names = \App\Models\Course::orderBy('name')->groupBy('name')->pluck('name');
  526. $datas = [];
  527. // $this->emit('destroy-data-table');
  528. if (false) {
  529. if (!$this->advanced) {
  530. /*if ($this->search != '')
  531. $datas = \App\Models\Member::select('members.*') // , \DB::raw('SUM(records.id) As total'))
  532. ->where('first_name', 'LIKE', '%' . $this->search . '%')
  533. ->orWhere('last_name', 'LIKE', '%' . $this->search . '%')
  534. ->orWhere('email', 'LIKE', '%' . $this->search . '%');
  535. $this->records = \App\Models\Member::where('first_name', 'LIKE', '%' . $this->search . '%')->orWhere('last_name', 'LIKE', '%' . $this->search . '%')->orWhere('email', 'LIKE', '%' . $this->search . '%')->get();
  536. else*/
  537. $this->records = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone')->get();
  538. //$datas = \App\Models\Member::select('members.*');
  539. } else {
  540. //$this->records = \App\Models\Member::where('id', '>', 0);
  541. $datas = \App\Models\Member::select('members.*')->where('id', '>', 0);
  542. if (sizeof($this->filterCard) > 0) {
  543. $card_ids = \App\Models\MemberCard::whereIn('card_id', $this->filterCard)->pluck('member_id');
  544. //$this->records->whereIn('id', $card_ids);
  545. $datas = $datas->whereIn('id', $card_ids);
  546. }
  547. if (sizeof($this->filterCategory) > 0) {
  548. $cats_ids = \App\Models\MemberCategory::whereIn('category_id', $this->filterCategory)->pluck('member_id');
  549. //$this->records->whereIn('id', $cats_ids);
  550. $datas = $datas->whereIn('id', $cats_ids);
  551. }
  552. $certs = [];
  553. if ($this->filterCertNormal > 0) {
  554. $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
  555. //$this->records->whereIn('id', $normal);
  556. $datas = $datas->whereIn('id', $normal);;
  557. }
  558. if ($this->filterCertAgonistic > 0) {
  559. $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
  560. //$this->records->whereIn('id', $agonistic);
  561. $datas = $datas->whereIn('id', $agonistic);
  562. }
  563. if ($this->filterCertScaduto > 0) {
  564. $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  565. //$this->records->whereIn('id', $scaduto);
  566. $datas = $datas->whereIn('id', $scaduto);
  567. }
  568. if ($this->filterCertInScadenza > 0) {
  569. $scaduto = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  570. //$this->records->whereIn('id', $scaduto);
  571. $datas = $datas->whereIn('id', $scaduto);
  572. }
  573. if (sizeof($certs) > 0) {
  574. $datas = $datas->whereIn('id', $certs);
  575. //$this->records->whereIn('id', $certs);
  576. }
  577. $this->records = $datas->get();
  578. }
  579. foreach ($this->records as $r) {
  580. $r->age = $r->getAge();
  581. $active = $r->isActive();
  582. $r->status = $active["status"];
  583. $r->date = $active["date"];
  584. $r->certificate = $r->hasCertificate()["date"];
  585. $r->state = $r->getStatus()["status"];
  586. }
  587. /*
  588. if ($this->sortAsc)
  589. $this->records = $this->records->sortBy($this->sortField);
  590. else
  591. $this->records = $this->records->sortByDesc($this->sortField);
  592. */
  593. //$datas = $datas->get(); // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10);
  594. //$this->records = $this->records->get();
  595. $this->emit('load-data-table');
  596. }
  597. $this->loadMemberCards();
  598. $this->loadMemberCourses();
  599. $this->loadMemberCategories();
  600. $this->loadMemberCertificates();
  601. $this->courses = \App\Models\Course::select('id', 'name')->where('type', $this->course_course_type)->get();
  602. $this->course_subscriptions = \App\Models\CourseSubscription::select('*')->where('enabled', true)->get();
  603. return view('livewire.member', ['datas' => $datas]);
  604. }
  605. public function updatedCourseCourseId()
  606. {
  607. if ($this->course_course_id > 0) {
  608. $c = \App\Models\Course::findOrFail($this->course_course_id);
  609. $this->course_price = formatPrice($c->price);
  610. $this->course_subscription_price = formatPrice($c->subscription_price);
  611. // Controllo se sono già iscritto la corso
  612. $this->course_exist = \App\Models\MemberCourse::where('course_id', $this->course_course_id)->where('member_id', $this->dataId)->count() > 0;
  613. // Carico gli abbonamenti e i mesi
  614. $period = \Carbon\CarbonPeriod::create($c->date_from, '1 month', $c->date_to);
  615. $this->course_months_list = [];
  616. foreach ($period as $dt)
  617. {
  618. $this->course_months_list[] = $dt->format("m");
  619. }
  620. $this->course_price_list = [];
  621. if ($c->prices != null)
  622. {
  623. foreach(json_decode($c->prices) as $z)
  624. {
  625. $this->course_price_list[$z->course_subscription_id] = $z->price;
  626. }
  627. }
  628. } else {
  629. $this->course_price = 0;
  630. $this->course_subscription_price = 0;
  631. $this->course_exist = false;
  632. }
  633. }
  634. public function loadMemberCards()
  635. {
  636. $this->member_cards = \App\Models\MemberCard::where('member_id', $this->dataId)->get();
  637. // return view('livewire.member');
  638. }
  639. public function loadMemberCourses()
  640. {
  641. $this->member_courses = \App\Models\MemberCourse::where('member_id', $this->dataId)->get();
  642. // return view('livewire.member');
  643. }
  644. public function loadMemberCategories()
  645. {
  646. $this->member_categories = \App\Models\MemberCategory::where('member_id', $this->dataId)->get();
  647. // return view('livewire.member');
  648. }
  649. public function loadMemberCertificates()
  650. {
  651. $this->member_certificates = \App\Models\MemberCertificate::where('member_id', $this->dataId)->orderBy('expire_date', 'DESC')->get();
  652. // return view('livewire.member');
  653. }
  654. public function showDetailF($id)
  655. {
  656. if (!isset($_GET["from"]) && $this->from == '')
  657. $this->from = 'members';
  658. $this->currentMember = \App\Models\Member::findOrFail($id);
  659. $this->currentStatus = $this->currentMember->getStatus();
  660. $this->showDetail = true;
  661. }
  662. public function add()
  663. {
  664. //$this->from = 'members';
  665. $this->emit('load-select');
  666. $this->emit('hide-search');
  667. $this->showDetail = false;
  668. $this->resetFields();
  669. $this->add = true;
  670. $this->update = false;
  671. $this->emit('setEdit', true);
  672. $this->emit('setEditCorso', false);
  673. }
  674. public function store($close)
  675. {
  676. $this->isSaving = true;
  677. $this->emit('load-select');
  678. $this->emit('goToTop');
  679. $rules = [
  680. 'first_name' => 'required',
  681. 'last_name' => 'required',
  682. 'email' => 'required',
  683. 'phone' => 'required',
  684. 'birth_nation_id' => 'required',
  685. //'birth_place' => 'required',
  686. 'address' => 'required',
  687. 'zip_code' => 'required',
  688. 'nation_id' => 'required',
  689. 'fiscal_code' => 'required',
  690. 'birth_date' => 'before_or_equal:today',
  691. 'gender' => 'required'
  692. ];
  693. if ($this->isBirthItaly) {
  694. $rules['birth_province_id'] = 'required';
  695. $rules['birth_city_id'] = 'required';
  696. } else {
  697. $rules['birth_place'] = 'required';
  698. }
  699. if ($this->isItaly) {
  700. $rules['province_id'] = 'required';
  701. $rules['city_id'] = 'required';
  702. }
  703. $zzz = [];
  704. if ($this->birth_nation_id == null)
  705. $zzz[] = 'birth_nation_id=' . $this->birth_nation_id;
  706. if ($this->isBirthItaly) {
  707. if ($this->birth_province_id == null)
  708. $zzz[] = 'birth_province_id=' . $this->birth_province_id;
  709. if ($this->birth_city_id == null)
  710. $zzz[] = 'birth_city_id=' . $this->birth_city_id;
  711. }
  712. if ($this->nation_id == null)
  713. $zzz[] = 'nation_id=' . $this->nation_id;
  714. if ($this->isItaly) {
  715. if ($this->province_id == null)
  716. $zzz[] = 'province_id=' . $this->province_id;
  717. if ($this->city_id == null)
  718. $zzz[] = 'city_id=' . $this->city_id;
  719. }
  720. $this->emit('setErrorMsg', $zzz);
  721. $existingMember = \App\Models\Member::where('fiscal_code', $this->fiscal_code)->first();
  722. if ($existingMember) {
  723. $this->addError('fiscal_code', 'Codice fiscale già presente.');
  724. return;
  725. }
  726. $this->validate($rules);
  727. //$this->emit('setErrors');
  728. try {
  729. $name = '';
  730. if ($this->image) {
  731. $name = md5($this->image . microtime()) . '.' . $this->image->extension();
  732. $this->image->storeAs('public', $name);
  733. }
  734. $docs = implode("|", $this->document_files);
  735. $father_docs = implode("|", $this->father_document_files);
  736. $mother_docs = implode("|", $this->mother_document_files);
  737. $member = \App\Models\Member::create([
  738. 'first_name' => strtoupper($this->first_name),
  739. 'last_name' => strtoupper($this->last_name),
  740. 'status' => $this->status,
  741. 'birth_city_id' => $this->birth_city_id > 0 ? $this->birth_city_id : null,
  742. 'birth_province_id' => $this->birth_province_id > 0 ? $this->birth_province_id : null,
  743. 'birth_nation_id' => $this->birth_nation_id > 0 ? $this->birth_nation_id : null,
  744. 'birth_date' => $this->birth_date,
  745. 'birth_place' => $this->birth_place,
  746. 'father_name' => $this->father_name,
  747. 'mother_name' => $this->mother_name,
  748. 'father_email' => strtolower($this->father_email),
  749. 'mother_email' => strtolower($this->mother_email),
  750. 'father_phone' => $this->father_phone,
  751. 'mother_phone' => $this->mother_phone,
  752. 'father_fiscal_code' => $this->father_fiscal_code,
  753. 'mother_fiscal_code' => $this->mother_fiscal_code,
  754. 'father_doc_number' => $this->father_doc_number,
  755. 'father_doc_type' => $this->father_doc_type,
  756. 'mother_doc_number' => $this->mother_doc_number,
  757. 'mother_doc_type' => $this->mother_doc_type,
  758. 'document_type' => $this->document_type,
  759. 'document_number' => $this->document_number,
  760. 'document_from' => $this->document_from,
  761. 'document_expire_date' => $this->document_expire_date,
  762. 'document_files' => $docs,
  763. 'mother_document_files' => $mother_docs,
  764. 'father_document_files' => $father_docs,
  765. 'gender' => $this->gender,
  766. 'no_send_mail' => $this->no_send_mail,
  767. 'exclude_from_records' => $this->exclude_from_records,
  768. 'fiscal_code' => $this->fiscal_code,
  769. 'address' => $this->address,
  770. 'zip_code' => $this->zip_code,
  771. 'nation_id' => $this->nation_id > 0 ? $this->nation_id : null,
  772. 'province_id' => $this->province_id > 0 ? $this->province_id : null,
  773. 'city_id' => $this->city_id > 0 ? $this->city_id : null,
  774. 'phone' => $this->phone,
  775. 'phone2' => $this->phone2,
  776. 'phone3' => $this->phone3,
  777. 'email' => strtolower($this->email),
  778. 'image' => $name,
  779. 'to_complete' => false,
  780. 'enabled' => $this->enabled
  781. ]);
  782. session()->flash('success, Tesserato creato');
  783. updateMemberData($member->id);
  784. $this->resetFields();
  785. if ($close) {
  786. $this->add = false;
  787. } else {
  788. $this->edit($member->id);
  789. }
  790. $this->emit('setEdit', false);
  791. } catch (\Exception $ex) {
  792. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  793. }
  794. }
  795. public function duplicate($id)
  796. {
  797. $member = \App\Models\Member::findOrFail($id);
  798. $newMember = $member->replicate();
  799. $newMember->save();
  800. $this->edit($newMember->id);
  801. }
  802. public function edit($id)
  803. {
  804. if (!isset($_GET["from"]) && $this->from == '')
  805. $this->from = 'members';
  806. $this->showDetail = false;
  807. $this->emit('setEdit', true);
  808. $this->emit('setEditCorso', false);
  809. $this->emit('hide-search');
  810. try {
  811. $member = \App\Models\Member::findOrFail($id);
  812. if (!$member) {
  813. session()->flash('error', 'Tesserato non trovato');
  814. } else {
  815. $this->first_name = $member->first_name;
  816. $this->last_name = $member->last_name;
  817. $this->status = $member->status;
  818. $this->birth_city_id = $member->birth_city_id;
  819. $this->birth_province_id = $member->birth_province_id;
  820. $this->birth_nation_id = $member->birth_nation_id;
  821. $this->birth_date = $member->birth_date;
  822. $this->birth_place = $member->birth_place;
  823. $this->father_name = $member->father_name;
  824. $this->mother_name = $member->mother_name;
  825. $this->father_email = strtolower($member->father_email);
  826. $this->mother_email = strtolower($member->mother_email);
  827. $this->father_phone = $member->father_phone;
  828. $this->mother_phone = $member->mother_phone;
  829. $this->father_fiscal_code = $member->father_fiscal_code;
  830. $this->mother_fiscal_code = $member->mother_fiscal_code;
  831. $this->father_doc_number = $member->father_doc_number;
  832. $this->mother_doc_number = $member->mother_doc_number;
  833. $this->father_doc_type = $member->father_doc_type;
  834. $this->mother_doc_type = $member->mother_doc_type;
  835. $this->father_document_files = explode("|", $member->father_document_files);
  836. $this->mother_document_files = explode("|", $member->mother_document_files);
  837. $this->document_type = $member->document_type;
  838. $this->document_number = $member->document_number;
  839. $this->document_from = $member->document_from;
  840. $this->document_expire_date = $member->document_expire_date;
  841. $this->document_files = explode("|", $member->document_files);
  842. $this->gender = $member->gender;
  843. $this->no_send_mail = $member->no_send_mail;
  844. $this->exclude_from_records = $member->exclude_from_records;
  845. $this->fiscal_code = $member->fiscal_code;
  846. $this->address = $member->address;
  847. $this->zip_code = $member->zip_code;
  848. $this->nation_id = $member->nation_id;
  849. $this->province_id = $member->province_id;
  850. $this->city_id = $member->city_id;
  851. $this->phone = $member->phone;
  852. $this->phone2 = $member->phone2;
  853. $this->phone3 = $member->phone3;
  854. $this->email = strtolower($member->email);
  855. $this->image_old = $member->image;
  856. $this->enabled = $member->enabled;
  857. $this->dataId = $member->id;
  858. $this->active = $member->getStatus();
  859. $this->money = $member->getMoney();
  860. $this->checkIsBirthItaly();
  861. $date1 = new DateTime($this->birth_date);
  862. $date2 = new DateTime("now");
  863. $interval = $date1->diff($date2);
  864. $this->age = $interval->y . " anni";
  865. $this->under18 = $interval->y < 18;
  866. //$this->provinces = \App\Models\Province::where('nation_id', $this->nation_id)->get();
  867. //$this->cities = \App\Models\City::where('province_id', $this->province_id)->get();
  868. //$this->birthProvinces = \App\Models\Province::where('nation_id', $this->birth_nation_id)->get();
  869. //$this->birthCities = \App\Models\City::where('province_id', $this->birth_province_id)->get();
  870. $this->update = true;
  871. $this->add = false;
  872. $this->emit('setIds', $this->nation_id, $this->birth_nation_id);
  873. $this->emit('load-select');
  874. $this->emit('load-provinces', $this->nation_id, 'provinceClass');
  875. $this->emit('load-provinces', $this->birth_nation_id, 'provinceBirthClass');
  876. $this->emit('load-cities', $this->province_id, 'cityClass');
  877. $this->emit('load-cities', $this->birth_province_id, 'cityBirthClass');
  878. }
  879. } catch (\Exception $ex) {
  880. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  881. }
  882. }
  883. public function updateAAA($close)
  884. {
  885. $this->emit('goToTop');
  886. $this->isSaving = true;
  887. $this->emit('load-select');
  888. $rules = [
  889. 'first_name' => 'required',
  890. 'last_name' => 'required',
  891. 'email' => 'required',
  892. 'phone' => 'required',
  893. 'birth_nation_id' => 'required',
  894. //'birth_place' => 'required',
  895. 'address' => 'required',
  896. 'zip_code' => 'required',
  897. 'nation_id' => 'required',
  898. 'fiscal_code' => 'required',
  899. 'birth_date' => 'before_or_equal:today'
  900. ];
  901. if ($this->isBirthItaly) {
  902. $rules['birth_province_id'] = 'required';
  903. $rules['birth_city_id'] = 'required';
  904. } else {
  905. $rules['birth_place'] = 'required';
  906. }
  907. if ($this->isItaly) {
  908. $rules['province_id'] = 'required';
  909. $rules['city_id'] = 'required';
  910. }
  911. $zzz = [];
  912. if ($this->birth_nation_id == null)
  913. $zzz[] = 'birth_nation_id=' . $this->birth_nation_id;
  914. if ($this->isBirthItaly) {
  915. if ($this->birth_province_id == null)
  916. $zzz[] = 'birth_province_id=' . $this->birth_province_id;
  917. if ($this->birth_city_id == null)
  918. $zzz[] = 'birth_city_id=' . $this->birth_city_id;
  919. }
  920. if ($this->nation_id == null)
  921. $zzz[] = 'nation_id=' . $this->nation_id;
  922. if ($this->isItaly) {
  923. if ($this->province_id == null)
  924. $zzz[] = 'province_id=' . $this->province_id;
  925. if ($this->city_id == null)
  926. $zzz[] = 'city_id=' . $this->city_id;
  927. }
  928. $this->emit('setErrorMsg', $zzz);
  929. $this->validate($rules);
  930. try {
  931. $name = '';
  932. if ($this->image) {
  933. $name = md5($this->image . microtime()) . '.' . $this->image->extension();
  934. $this->image->storeAs('public', $name);
  935. }
  936. $docs = implode("|", $this->document_files);
  937. $father_docs = implode("|", $this->father_document_files);
  938. $mother_docs = implode("|", $this->mother_document_files);
  939. \App\Models\Member::whereId($this->dataId)->update([
  940. 'first_name' => strtoupper($this->first_name),
  941. 'last_name' => strtoupper($this->last_name),
  942. 'status' => $this->status,
  943. 'birth_city_id' => $this->birth_city_id > 0 ? $this->birth_city_id : null,
  944. 'birth_province_id' => $this->birth_province_id > 0 ? $this->birth_province_id : null,
  945. 'birth_nation_id' => $this->birth_nation_id > 0 ? $this->birth_nation_id : null,
  946. 'birth_date' => $this->birth_date,
  947. 'birth_place' => $this->birth_place,
  948. 'father_name' => $this->father_name,
  949. 'mother_name' => $this->mother_name,
  950. 'father_email' => strtolower($this->father_email),
  951. 'mother_email' => strtolower($this->mother_email),
  952. 'father_phone' => $this->father_phone,
  953. 'mother_phone' => $this->mother_phone,
  954. 'father_fiscal_code' => $this->father_fiscal_code,
  955. 'mother_fiscal_code' => $this->mother_fiscal_code,
  956. 'father_doc_number' => $this->father_doc_number,
  957. 'father_doc_type' => $this->father_doc_type,
  958. 'mother_doc_number' => $this->mother_doc_number,
  959. 'mother_doc_type' => $this->mother_doc_type,
  960. 'father_document_files' => $father_docs,
  961. 'mother_document_files' => $mother_docs,
  962. 'document_type' => $this->document_type,
  963. 'document_number' => $this->document_number,
  964. 'document_from' => $this->document_from,
  965. 'document_expire_date' => $this->document_expire_date,
  966. 'document_files' => $docs,
  967. 'gender' => $this->gender,
  968. 'no_send_mail' => $this->no_send_mail,
  969. 'exclude_from_records' => $this->exclude_from_records,
  970. 'fiscal_code' => $this->fiscal_code,
  971. 'address' => $this->address,
  972. 'zip_code' => $this->zip_code,
  973. 'nation_id' => $this->nation_id > 0 ? $this->nation_id : null,
  974. 'province_id' => $this->province_id > 0 ? $this->province_id : null,
  975. 'city_id' => $this->city_id > 0 ? $this->city_id : null,
  976. 'image' => $name != '' ? $name : $this->image_old,
  977. 'phone' => $this->phone,
  978. 'phone2' => $this->phone2,
  979. 'phone3' => $this->phone3,
  980. 'email' => strtolower($this->email),
  981. 'to_complete' => false,
  982. 'enabled' => $this->enabled
  983. ]);
  984. updateMemberData($this->dataId);
  985. session()->flash('success', 'Tesserato aggiornato');
  986. if ($close) {
  987. $this->resetFields();
  988. $this->update = false;
  989. }
  990. $this->emit('setEdit', false);
  991. } catch (\Exception $ex) {
  992. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  993. }
  994. }
  995. public function cancel()
  996. {
  997. $this->add = false;
  998. $this->update = false;
  999. $this->showDetail = false;
  1000. $this->resetFields();
  1001. $this->emit('setEdit', false);
  1002. //$this->emit('setEditCorso', false);
  1003. $this->emit('reload');
  1004. }
  1005. public function delete($id)
  1006. {
  1007. try {
  1008. \App\Models\Member::find($id)->delete();
  1009. session()->flash('success', "Tesserato eliminato");
  1010. $this->emit('reload');
  1011. } catch (\Exception $e) {
  1012. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1013. }
  1014. }
  1015. public function checkUncheckAll()
  1016. {
  1017. if (!$this->checkedAll) {
  1018. $this->multipleIds = array();
  1019. } else {
  1020. foreach ($this->records as $r) {
  1021. $this->multipleIds[] = $r->id;
  1022. }
  1023. }
  1024. }
  1025. public function multipleDelete()
  1026. {
  1027. try {
  1028. foreach ($this->multipleIds as $id) {
  1029. \App\Models\Member::find($id)->delete();
  1030. }
  1031. } catch (\Exception $e) {
  1032. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1033. }
  1034. $this->multipleAction = '';
  1035. }
  1036. // Card
  1037. public function addCard()
  1038. {
  1039. $this->resetCardFields();
  1040. $this->addCard = true;
  1041. $this->updateCard = false;
  1042. }
  1043. public function storeCard()
  1044. {
  1045. $this->validate(['card_card_id' => 'required']);
  1046. try {
  1047. // in base alla card selezionata calcolo la scadenza
  1048. $expire_date = null;
  1049. if ($this->card_date != '') {
  1050. $y = date("Y", strtotime($this->card_date));
  1051. $card = \App\Models\Card::findOrFail($this->card_card_id);
  1052. if ($card->next_day_expire > 0 && $card->next_month_expire > 0) {
  1053. $m = strlen($card->next_month_expire) == 1 ? ('0' . $card->next_month_expire) : $card->next_month_expire;
  1054. if (date("md", strtotime($this->card_date)) > ($m . $card->next_day_expire))
  1055. $y += 1;
  1056. $next_exp = date($y . "-" . $m . "-" . $card->next_day_expire);
  1057. if ($next_exp > $this->card_date) {
  1058. $expire_date = $next_exp;
  1059. } else
  1060. $expire_date = date($y . "-" . $card->next_month_expire . "-" . $card->next_day_expire, strtotime(' + 1 years'));
  1061. } else {
  1062. if ($card->one_year_expire) {
  1063. $expire_date = date("Y-m-d", strtotime($this->card_date . ' + 1 years'));
  1064. }
  1065. }
  1066. }
  1067. \App\Models\MemberCard::create([
  1068. 'member_id' => $this->dataId,
  1069. 'card_id' => $this->card_card_id,
  1070. 'number' => $this->card_number,
  1071. 'date' => $this->card_date,
  1072. 'accept_date' => $this->card_accept_date != '' ? $this->card_accept_date : $this->card_date,
  1073. 'expire_date' => $expire_date,
  1074. 'status' => $this->card_status,
  1075. 'discipline1_id' => $this->card_discipline1_id,
  1076. 'discipline2_id' => $this->card_discipline2_id,
  1077. 'discipline3_id' => $this->card_discipline3_id,
  1078. ]);
  1079. updateMemberData($this->dataId);
  1080. session()->flash('success, Tesserato creato');
  1081. $this->resetCardFields();
  1082. $this->addCard = false;
  1083. } catch (\Exception $ex) {
  1084. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1085. }
  1086. }
  1087. public function editCard($id)
  1088. {
  1089. try {
  1090. $memberCard = \App\Models\MemberCard::findOrFail($id);
  1091. if (!$memberCard) {
  1092. session()->flash('error', 'Tesserato non trovato');
  1093. } else {
  1094. $this->card_card_id = $memberCard->card_id;
  1095. $this->card_number = $memberCard->number;
  1096. $this->card_date = $memberCard->date;
  1097. $this->card_accept_date = $memberCard->accept_date;
  1098. $this->card_status = $memberCard->status;
  1099. $this->card_discipline1_id = $memberCard->discipline1_id;
  1100. $this->card_discipline2_id = $memberCard->discipline2_id;
  1101. $this->card_discipline3_id = $memberCard->discipline3_id;
  1102. $this->cardDataId = $memberCard->id;
  1103. $this->updateCard = true;
  1104. $this->addCard = false;
  1105. }
  1106. } catch (\Exception $ex) {
  1107. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1108. }
  1109. }
  1110. public function updateCard()
  1111. {
  1112. $this->validate(['card_card_id' => 'required']);
  1113. try {
  1114. \Illuminate\Support\Facades\Log::info('Starting card update', [
  1115. 'member_id' => $this->dataId,
  1116. 'card_id' => $this->card_card_id,
  1117. 'card_number' => $this->card_number
  1118. ]);
  1119. $expire_date = null;
  1120. if ($this->card_date != '') {
  1121. $card = \App\Models\Card::findOrFail($this->card_card_id);
  1122. \Illuminate\Support\Facades\Log::info('Card details', [
  1123. 'card_id' => $card->id,
  1124. 'next_day_expire' => $card->next_day_expire,
  1125. 'next_month_expire' => $card->next_month_expire,
  1126. 'one_year_expire' => $card->one_year_expire
  1127. ]);
  1128. if ($card->next_day_expire > 0 && $card->next_month_expire > 0) {
  1129. $y = date("Y", strtotime($this->card_date));
  1130. $m = strlen($card->next_month_expire) == 1 ? ('0' . $card->next_month_expire) : $card->next_month_expire;
  1131. $d = strlen($card->next_day_expire) == 1 ? ('0' . $card->next_day_expire) : $card->next_day_expire;
  1132. $next_exp = $y . "-" . $m . "-" . $d;
  1133. // Format dates for comparison
  1134. $input_date_obj = new \DateTime($this->card_date);
  1135. $next_exp_obj = new \DateTime($next_exp);
  1136. if ($next_exp_obj > $input_date_obj) {
  1137. $expire_date = $next_exp;
  1138. } else {
  1139. // Add 1 year to the expiration date if the input date is after the expiration date
  1140. $next_exp_obj->modify('+1 year');
  1141. $expire_date = $next_exp_obj->format('Y-m-d');
  1142. }
  1143. \Illuminate\Support\Facades\Log::info('Calculated expiration date (next_day_expire/next_month_expire rule)', [
  1144. 'input_date' => $this->card_date,
  1145. 'next_exp' => $next_exp,
  1146. 'expire_date' => $expire_date,
  1147. 'comparison' => ($next_exp_obj > $input_date_obj) ? 'next_exp is after input_date' : 'next_exp is before or equal to input_date'
  1148. ]);
  1149. } else {
  1150. if ($card->one_year_expire) {
  1151. $expire_date = date("Y-m-d", strtotime($this->card_date . ' + 1 years'));
  1152. \Illuminate\Support\Facades\Log::info('Calculated expiration date (one_year_expire rule)', [
  1153. 'input_date' => $this->card_date,
  1154. 'expire_date' => $expire_date
  1155. ]);
  1156. }
  1157. }
  1158. }
  1159. \Illuminate\Support\Facades\Log::info('Updating member card', [
  1160. 'card_id' => $this->cardDataId,
  1161. 'member_id' => $this->dataId,
  1162. 'card_number' => $this->card_number,
  1163. 'date' => $this->card_date,
  1164. 'expire_date' => $expire_date,
  1165. 'status' => $this->card_status
  1166. ]);
  1167. \App\Models\MemberCard::whereId($this->cardDataId)->update([
  1168. 'member_id' => $this->dataId,
  1169. 'card_id' => $this->card_card_id,
  1170. 'number' => $this->card_number,
  1171. 'date' => $this->card_date,
  1172. 'accept_date' => $this->card_accept_date != '' ? $this->card_accept_date : $this->card_date,
  1173. 'expire_date' => $expire_date,
  1174. 'status' => $this->card_status,
  1175. 'discipline1_id' => $this->card_discipline1_id,
  1176. 'discipline2_id' => $this->card_discipline2_id,
  1177. 'discipline3_id' => $this->card_discipline3_id,
  1178. ]);
  1179. updateMemberData($this->dataId);
  1180. \Illuminate\Support\Facades\Log::info('Card updated successfully', [
  1181. 'card_id' => $this->cardDataId,
  1182. 'member_id' => $this->dataId
  1183. ]);
  1184. session()->flash('success', 'Tesserato aggiornato');
  1185. $this->resetCardFields();
  1186. $this->updateCard = false;
  1187. } catch (\Exception $ex) {
  1188. \Illuminate\Support\Facades\Log::error('Error updating card', [
  1189. 'card_id' => $this->cardDataId,
  1190. 'member_id' => $this->dataId,
  1191. 'error_message' => $ex->getMessage(),
  1192. 'error_trace' => $ex->getTraceAsString()
  1193. ]);
  1194. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1195. }
  1196. }
  1197. public function cancelCard()
  1198. {
  1199. $this->addCard = false;
  1200. $this->updateCard = false;
  1201. $this->resetCardFields();
  1202. }
  1203. public function deleteCard($id)
  1204. {
  1205. try {
  1206. \App\Models\MemberCard::find($id)->delete();
  1207. session()->flash('success', "Tesserato eliminato");
  1208. } catch (\Exception $e) {
  1209. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1210. }
  1211. }
  1212. // Courses
  1213. public function addCourse()
  1214. {
  1215. $this->resetCourseFields();
  1216. /*if ($this->under18)
  1217. {
  1218. $this->course_months[] = array("m" => 9, "status" => "");
  1219. $this->course_months[] = array("m" => 10, "status" => "");
  1220. $this->course_months[] = array("m" => 11, "status" => "");
  1221. $this->course_months[] = array("m" => 12, "status" => "");
  1222. $this->course_months[] = array("m" => 1, "status" => "");
  1223. $this->course_months[] = array("m" => 2, "status" => "");
  1224. $this->course_months[] = array("m" => 3, "status" => "");
  1225. $this->course_months[] = array("m" => 4, "status" => "");
  1226. $this->course_months[] = array("m" => 5, "status" => "");
  1227. $this->course_months[] = array("m" => 6, "status" => "");
  1228. }*/
  1229. $this->addCourse = true;
  1230. $this->updateCourse = false;
  1231. $this->emit('setEditCorso', true);
  1232. }
  1233. public function storeCourse()
  1234. {
  1235. $this->validate(['course_course_id' => 'required']);
  1236. try {
  1237. \App\Models\MemberCourse::create([
  1238. 'member_id' => $this->dataId,
  1239. 'course_id' => $this->course_course_id,
  1240. 'date_from' => $this->course_date_from,
  1241. 'date_to' => $this->course_date_to,
  1242. 'course_subscription_id' => $this->course_course_subscription_id,
  1243. 'status' => $this->course_status,
  1244. 'subscribed' => false, // default non iscritto
  1245. 'price' => currencyToDouble($this->course_price),
  1246. 'subscription_price' => currencyToDouble($this->course_subscription_price),
  1247. 'notes' => $this->course_note,
  1248. 'months' => json_encode($this->course_months),
  1249. 'when' => json_encode($this->course_when)
  1250. ]);
  1251. // Se il corso ha associato una categoria iscrivo anche al gruppo
  1252. $c = \App\Models\Course::findOrFail($this->course_course_id);
  1253. if ($c) {
  1254. if ($c->category_id > 0) {
  1255. \App\Models\MemberCategory::create([
  1256. 'member_id' => $this->dataId,
  1257. 'category_id' => $c->category_id,
  1258. 'date' => \Carbon\Carbon::now()
  1259. ]);
  1260. }
  1261. }
  1262. session()->flash('success, Corso creato');
  1263. $this->resetCourseFields();
  1264. $this->addCourse = false;
  1265. $this->emit('setEditCorso', false);
  1266. } catch (\Exception $ex) {
  1267. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1268. }
  1269. }
  1270. public function editCourse($id)
  1271. {
  1272. try {
  1273. $memberCourse = \App\Models\MemberCourse::findOrFail($id);
  1274. if (!$memberCourse) {
  1275. session()->flash('error', 'Corso non trovato');
  1276. } else {
  1277. $this->course_course_id = $memberCourse->course_id;
  1278. // Carico i dati relativi alla struttura ad albero
  1279. $c = \App\Models\Course::findOrFail($this->course_course_id);
  1280. $this->course_name = $c->name . " (" . $c->year . ")";
  1281. $this->course_level_id = $c->course_level_id;
  1282. $this->course_type_id = $c->course_type_id;
  1283. $this->course_frequency_id = $c->course_frequency_id;
  1284. $all = \App\Models\Course::where('name', 'like', '%' . $c->name . "%")->where('enabled', true)->get();
  1285. foreach ($all as $a) {
  1286. $levels_ids[] = $a->course_level_id;
  1287. }
  1288. $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->whereIn('id', $levels_ids)->get();
  1289. $all = \App\Models\Course::where('name', 'like', '%' . $c->name . "%")->where('enabled', true)->where('course_level_id', $this->course_level_id)->get();
  1290. foreach ($all as $a) {
  1291. $types_ids[] = $a->course_type_id;
  1292. }
  1293. $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->whereIn('id', $types_ids)->get();
  1294. $frequencies_ids = [];
  1295. $all = \App\Models\Course::where('name', 'like', '%' . $c->name . "%")->where('enabled', true)->where('course_level_id', $this->course_level_id)->where('course_type_id', $this->course_type_id)->get();
  1296. foreach ($all as $a) {
  1297. $frequencies_ids[] = $a->course_frequency_id;
  1298. }
  1299. $this->course_frequencies = \App\Models\CourseFrequency::select('*')->where('enabled', true)->whereIn('id', $frequencies_ids)->get();
  1300. $this->course_when = array();
  1301. $this->course_date_from = $memberCourse->date_from;
  1302. $this->course_date_to = $memberCourse->date_to;
  1303. foreach (json_decode($memberCourse->when) as $z) {
  1304. $this->course_when[] = array("day" => $z->day, "from" => $z->from, "to" => $z->to);
  1305. }
  1306. //$this->course_when = json_decode($memberCourse->when);
  1307. $this->course_course_subscription_id = $memberCourse->course_subscription_id;
  1308. $this->course_status = $memberCourse->status;
  1309. $this->course_subscribed = $memberCourse->subscribed == 1 ? true : false;
  1310. $this->course_price = formatPrice($memberCourse->price);
  1311. $this->course_subscription_price = formatPrice($memberCourse->subscription_price);
  1312. $this->course_note = $memberCourse->notes;
  1313. foreach (json_decode($memberCourse->months) as $z) {
  1314. $this->course_months[] = array("m" => $z->m, "status" => $z->status);
  1315. }
  1316. $this->courseDataId = $memberCourse->id;
  1317. $this->updateCourse = true;
  1318. $this->addCourse = false;
  1319. $this->emit('setEditCorso', true);
  1320. }
  1321. } catch (\Exception $ex) {
  1322. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1323. }
  1324. }
  1325. public function updateCourse()
  1326. {
  1327. //$this->validate();
  1328. $this->validate(['course_course_id' => 'required']);
  1329. try {
  1330. \App\Models\MemberCourse::whereId($this->courseDataId)->update([
  1331. 'member_id' => $this->dataId,
  1332. 'course_id' => $this->course_course_id,
  1333. 'date_from' => $this->course_date_from,
  1334. 'date_to' => $this->course_date_to,
  1335. 'course_subscription_id' => $this->course_course_subscription_id,
  1336. 'status' => $this->course_status,
  1337. 'price' => currencyToDouble($this->course_price),
  1338. 'subscription_price' => currencyToDouble($this->course_subscription_price),
  1339. 'notes' => $this->course_note,
  1340. 'months' => json_encode($this->course_months),
  1341. 'when' => json_encode($this->course_when)
  1342. ]);
  1343. session()->flash('success', 'Corso aggiornato');
  1344. $this->resetCourseFields();
  1345. $this->updateCourse = false;
  1346. $this->emit('setEditCorso', false);
  1347. } catch (\Exception $ex) {
  1348. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1349. }
  1350. }
  1351. public function cancelCourse()
  1352. {
  1353. $this->addCourse = false;
  1354. $this->updateCourse = false;
  1355. $this->emit('setEditCorso', false);
  1356. $this->resetCourseFields();
  1357. }
  1358. public function deleteCourse($id)
  1359. {
  1360. try {
  1361. \App\Models\MemberCourse::find($id)->delete();
  1362. session()->flash('success', "Corso eliminato");
  1363. } catch (\Exception $e) {
  1364. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1365. }
  1366. }
  1367. public function addRow()
  1368. {
  1369. $this->course_when[] = array('day' => array(), 'from' => '', 'to' => '');
  1370. }
  1371. public function delRow($idx)
  1372. {
  1373. unset($this->course_when[$idx]);
  1374. }
  1375. // Certificates
  1376. public function addCertificate()
  1377. {
  1378. $this->resetCertificateFields();
  1379. $this->addCertificate = true;
  1380. $this->updateCertificate = false;
  1381. }
  1382. public function storeCertificate()
  1383. {
  1384. $this->validate(['certificate_expire_date' => 'required']);
  1385. // $this->validate();
  1386. try {
  1387. $name = '';
  1388. try {
  1389. if ($this->certificate_filename) {
  1390. $name = md5($this->certificate_filename . microtime()) . '.' . $this->certificate_filename->extension();
  1391. $this->certificate_filename->storeAs('public', $name);
  1392. }
  1393. } catch (\Exception $ex) {
  1394. //session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1395. }
  1396. if ($this->dataId > -1) {
  1397. \App\Models\MemberCertificate::create([
  1398. 'member_id' => $this->dataId,
  1399. 'type' => $this->certificate_type,
  1400. 'filename' => $name,
  1401. 'expire_date' => $this->certificate_expire_date,
  1402. 'status' => $this->certificate_status
  1403. ]);
  1404. updateMemberData($this->dataId);
  1405. }
  1406. /*else
  1407. {
  1408. $this->certificateTmp = new \App\Models\MemberCertificate();
  1409. $this->certificateTmp->type = $this->certificate_type;
  1410. $this->certificateTmp->filename = $name;
  1411. $this->certificateTmp->expire_date = $this->certificate_expire_date;
  1412. $this->certificateTmp->status = $this->certificate_status;
  1413. $this->certificateTmp->status = $this->certificate_status;
  1414. // s $this->member_certificates[] = $certificateTmp;
  1415. }*/
  1416. session()->flash('success, Tesserato creato');
  1417. $this->resetCertificateFields();
  1418. $this->addCertificate = false;
  1419. } catch (\Exception $ex) {
  1420. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1421. }
  1422. }
  1423. public function editCertificate($id)
  1424. {
  1425. try {
  1426. $memberCertificate = \App\Models\MemberCertificate::findOrFail($id);
  1427. if (!$memberCertificate) {
  1428. session()->flash('error', 'Tesserato non trovato');
  1429. } else {
  1430. $this->certificate_type = $memberCertificate->type;
  1431. $this->certificate_filename_old = $memberCertificate->filename;
  1432. $this->certificate_expire_date = $memberCertificate->expire_date;
  1433. $this->certificate_status = $memberCertificate->status;
  1434. $this->cardCertificateId = $memberCertificate->id;
  1435. $this->updateCertificate = true;
  1436. $this->addCertificate = false;
  1437. }
  1438. } catch (\Exception $ex) {
  1439. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1440. }
  1441. }
  1442. public function updateCertificate()
  1443. {
  1444. $this->validate(['certificate_expire_date' => 'required']);
  1445. try {
  1446. $name = '';
  1447. try {
  1448. if ($this->certificate_filename) {
  1449. $name = md5($this->certificate_filename . microtime()) . '.' . $this->certificate_filename->extension();
  1450. $this->certificate_filename->storeAs('public', $name);
  1451. }
  1452. } catch (\Exception $ex) {
  1453. //session()->flash('error','Errore (' . $ex->getMessage() . ')');
  1454. }
  1455. \App\Models\MemberCertificate::whereId($this->cardCertificateId)->update([
  1456. 'member_id' => $this->dataId,
  1457. 'type' => $this->certificate_type,
  1458. 'filename' => $name != '' ? $name : $this->certificate_filename_old,
  1459. 'expire_date' => $this->certificate_expire_date,
  1460. 'status' => $this->certificate_status
  1461. ]);
  1462. updateMemberData($this->dataId);
  1463. session()->flash('success', 'Tesserato aggiornato');
  1464. $this->resetCertificateFields();
  1465. $this->updateCertificate = false;
  1466. } catch (\Exception $ex) {
  1467. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1468. }
  1469. }
  1470. public function cancelCertificate()
  1471. {
  1472. $this->addCertificate = false;
  1473. $this->updateCertificate = false;
  1474. $this->resetCertificateFields();
  1475. }
  1476. public function deleteCertificate($id)
  1477. {
  1478. try {
  1479. \App\Models\MemberCertificate::find($id)->delete();
  1480. session()->flash('success', "Tesserato eliminato");
  1481. } catch (\Exception $e) {
  1482. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1483. }
  1484. }
  1485. // Gruppi di appartenenza
  1486. public function storeCategory()
  1487. {
  1488. $this->validate(['category_category_id' => 'required']);
  1489. try {
  1490. \App\Models\MemberCategory::create([
  1491. 'member_id' => $this->dataId,
  1492. 'category_id' => $this->category_category_id,
  1493. 'date' => \Carbon\Carbon::now()
  1494. ]);
  1495. session()->flash('success, Associazione creato');
  1496. $this->resetCategoryFields();
  1497. $this->addCard = false;
  1498. } catch (\Exception $ex) {
  1499. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1500. }
  1501. }
  1502. public function hideMsg()
  1503. {
  1504. $this->groupMsg = '';
  1505. }
  1506. public function storeCategoryWithID($id)
  1507. {
  1508. $this->groupMsg = '';
  1509. try {
  1510. if (\App\Models\MemberCategory::where('member_id', $this->dataId)->where('category_id', $id)->first()) {
  1511. $this->groupMsg = '<br>Attenzione, questo corso è stato già inserito';
  1512. } else {
  1513. \App\Models\MemberCategory::create([
  1514. 'member_id' => $this->dataId,
  1515. 'category_id' => $id,
  1516. 'date' => \Carbon\Carbon::now()
  1517. ]);
  1518. session()->flash('success, Associazione creato');
  1519. $this->resetCategoryFields();
  1520. $this->addCard = false;
  1521. }
  1522. } catch (\Exception $ex) {
  1523. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1524. }
  1525. }
  1526. public function deleteCategory($id)
  1527. {
  1528. try {
  1529. \App\Models\MemberCategory::find($id)->delete();
  1530. session()->flash('success', "Associazione eliminata");
  1531. } catch (\Exception $e) {
  1532. session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
  1533. }
  1534. }
  1535. public function setCourse($id)
  1536. {
  1537. $this->course_course_id = $id;
  1538. }
  1539. public function getNation($nation)
  1540. {
  1541. if ($nation > 0) {
  1542. $ret = \App\Models\Nation::findOrFail($nation);
  1543. return $ret->name;
  1544. }
  1545. return "";
  1546. }
  1547. public function getProvince($province)
  1548. {
  1549. if ($province > 0) {
  1550. $ret = \App\Models\Province::findOrFail($province);
  1551. return $ret->name;
  1552. }
  1553. return "";
  1554. }
  1555. public function getCity($city)
  1556. {
  1557. if ($city > 0) {
  1558. $ret = \App\Models\City::findOrFail($city);
  1559. return $ret->name;
  1560. }
  1561. return "";
  1562. }
  1563. public function getFiscalCode()
  1564. {
  1565. $this->error_fc = false;
  1566. $cf = new codicefiscale();
  1567. $cf->setDateSeparator('-');
  1568. if ($this->first_name != '' && $this->last_name != '' && $this->birth_date != '' && $this->gender != '' && $this->birth_city_id > 0) {
  1569. $code = '';
  1570. if ($this->birth_city_id > 0) {
  1571. $code = \App\Models\City::findOrFail($this->birth_city_id)->code;
  1572. }
  1573. $codice = $cf->calcola($this->first_name, $this->last_name, $this->birth_date, $this->gender, $code);
  1574. $this->fiscal_code = $codice;
  1575. } else
  1576. $this->error_fc = true;
  1577. }
  1578. public function setMonth($m)
  1579. {
  1580. $exist = -1;
  1581. foreach ($this->course_months as $idx => $x) {
  1582. if ($x["m"] == $m) {
  1583. $exist = $idx;
  1584. break;
  1585. }
  1586. }
  1587. if ($exist > -1) {
  1588. array_splice($this->course_months, $exist, 1);
  1589. } else {
  1590. $this->course_months[] = array("m" => $m, "status" => "");
  1591. }
  1592. /*
  1593. if (in_array($m, $this->course_months))
  1594. {
  1595. $i = array_search($m, $this->course_months);
  1596. array_splice($this->course_months, $i, 1);
  1597. }
  1598. else
  1599. {
  1600. $this->course_months[] = $m;
  1601. }*/
  1602. }
  1603. public function newPayment($course)
  1604. {
  1605. $c = \App\Models\Course::findOrFail($course["course_id"]);
  1606. $price = $course["price"];
  1607. if (sizeof($this->payMonths) == 1)
  1608. {
  1609. $month = $this->payMonths[0];
  1610. $records = \App\Models\Record::where('member_course_id', $this->selectedCourseMember)->where('deleted', 0)->get();
  1611. foreach ($records as $record)
  1612. {
  1613. if (in_array($month, json_decode($record->months)))
  1614. {
  1615. foreach ($record->rows as $row)
  1616. {
  1617. if ($row->causal_id == $c->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
  1618. {
  1619. $tot = sizeof(json_decode($row->when));
  1620. foreach(json_decode($row->when) as $m)
  1621. {
  1622. $price -= $row->amount / $tot;
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. $this->emit('setEdit', false);
  1630. $this->emit('setEditCorso', false);
  1631. 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=' . $price . '&subscription_price=' . $course["subscription_price"] . "&courseId=" . $course["id"]);
  1632. }
  1633. public function block($course)
  1634. {
  1635. $xxx = json_decode($course["months"]);
  1636. foreach ($xxx as $idx => $mm) {
  1637. if (in_array($mm->m, $this->payMonths)) {
  1638. $xxx[$idx]->status = 2;
  1639. }
  1640. }
  1641. $c = \App\Models\MemberCourse::findOrFail($course["id"]);
  1642. $c->months = json_encode($xxx);
  1643. $c->save();
  1644. $this->payMonths = array();
  1645. }
  1646. public function reactivate($course)
  1647. {
  1648. $xxx = json_decode($course["months"]);
  1649. foreach ($xxx as $idx => $mm) {
  1650. if (in_array($mm->m, $this->suspendedMonths)) {
  1651. $xxx[$idx]->status = "";
  1652. }
  1653. }
  1654. $c = \App\Models\MemberCourse::findOrFail($course["id"]);
  1655. $c->months = json_encode($xxx);
  1656. $c->save();
  1657. $this->suspendedMonths = array();
  1658. }
  1659. public function setPayMonth($m, $months, $selectedCourseMember)
  1660. {
  1661. if ($this->selectedCourseMember != $selectedCourseMember)
  1662. $this->payMonths = array();
  1663. $this->selectedCourseMember = $selectedCourseMember;
  1664. if (in_array($m, $this->payMonths)) {
  1665. $i = array_search($m, $this->payMonths);
  1666. array_splice($this->payMonths, $i, 1);
  1667. } else if (in_array($m, $this->suspendedMonths)) {
  1668. $i = array_search($m, $this->suspendedMonths);
  1669. array_splice($this->suspendedMonths, $i, 1);
  1670. } else {
  1671. foreach (json_decode($months) as $mm) {
  1672. if ($mm->m == $m) {
  1673. if ($mm->status == "")
  1674. $this->payMonths[] = $m;
  1675. if ($mm->status == "1")
  1676. {
  1677. $mc = \App\Models\MemberCourse::findOrFail($selectedCourseMember);
  1678. $price = $mc->price;
  1679. $payed = 0;
  1680. $extraC = '';
  1681. $recordsPayed = \App\Models\Record::where('member_course_id', $selectedCourseMember)->where('deleted', 0)->get();
  1682. foreach ($recordsPayed as $record)
  1683. {
  1684. if (in_array($m, json_decode($record->months)))
  1685. {
  1686. foreach ($record->rows as $row)
  1687. {
  1688. if ($row->causal_id == $mc->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
  1689. {
  1690. $tot = sizeof(json_decode($row->when));
  1691. $payed += $row->amount / $tot;
  1692. }
  1693. }
  1694. if ($payed < $price)
  1695. $this->payMonths[] = $m;
  1696. }
  1697. }
  1698. }
  1699. if ($mm->status == "2")
  1700. $this->suspendedMonths[] = $m;
  1701. }
  1702. }
  1703. }
  1704. if (sizeof($this->payMonths) > 0 && sizeof($this->suspendedMonths) > 0) {
  1705. $this->payMonths = array();
  1706. $this->suspendedMonths = array();
  1707. }
  1708. }
  1709. public function setCreateSubscription($subscribed, $selectedCourseMember)
  1710. {
  1711. if ($this->selectedCourseMember != $selectedCourseMember)
  1712. $this->payMonths = array();
  1713. $this->selectedCourseMember = $selectedCourseMember;
  1714. if (!$subscribed)
  1715. $this->createSubscription = !$this->createSubscription;
  1716. }
  1717. public function showHideCourse($id)
  1718. {
  1719. if (in_array($id, $this->showCourse)) {
  1720. $i = array_search($id, $this->showCourse);
  1721. array_splice($this->showCourse, $i, 1);
  1722. } else {
  1723. $this->showCourse[] = $id;
  1724. }
  1725. }
  1726. public function getMonthStatus($m, $months, $selectedCourseMember)
  1727. {
  1728. $class = "grey";
  1729. foreach (json_decode($months) as $mm) {
  1730. if ($mm->m == $m) {
  1731. if ($mm->status == "") {
  1732. if (in_array($m, $this->payMonths) && $this->selectedCourseMember == $selectedCourseMember)
  1733. $class = "blue";
  1734. else
  1735. $class = "orange";
  1736. }
  1737. if ($mm->status == "1") {
  1738. $class = "green";
  1739. }
  1740. if ($mm->status == "2") {
  1741. if (in_array($m, $this->suspendedMonths) && $this->selectedCourseMember == $selectedCourseMember)
  1742. $class = "blue";
  1743. else
  1744. $class = "yellow";
  1745. }
  1746. if ($class == 'green')
  1747. {
  1748. $mc = \App\Models\MemberCourse::findOrFail($selectedCourseMember);
  1749. $price = $mc->price;
  1750. $payed = 0;
  1751. $extraC = '';
  1752. $recordsPayed = \App\Models\Record::where('member_course_id', $selectedCourseMember)->where('deleted', 0)->get();
  1753. foreach ($recordsPayed as $record)
  1754. {
  1755. if (in_array($m, json_decode($record->months)))
  1756. {
  1757. foreach ($record->rows as $row)
  1758. {
  1759. if ($row->causal_id == $mc->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
  1760. {
  1761. $tot = sizeof(json_decode($row->when));
  1762. $payed += $row->amount / $tot;
  1763. }
  1764. }
  1765. }
  1766. }
  1767. if ($payed < $price)
  1768. $class = 'orange half';
  1769. //$class .= $extraC;
  1770. }
  1771. }
  1772. }
  1773. return $class;
  1774. }
  1775. public function getSubscriptionStatus($subscribed, $selectedCourseMember)
  1776. {
  1777. $class = "grey";
  1778. if ($this->createSubscription && $this->selectedCourseMember == $selectedCourseMember)
  1779. $class = "blue";
  1780. else
  1781. $class = "orange";
  1782. if ($subscribed)
  1783. $class = "green";
  1784. return $class;
  1785. }
  1786. public function checkMonth($m)
  1787. {
  1788. $ret = false;
  1789. foreach ($this->course_months as $idx => $x) {
  1790. if ($x["m"] == $m) {
  1791. $ret = true;
  1792. break;
  1793. }
  1794. }
  1795. return $ret;
  1796. }
  1797. public function setDay($idx, $d)
  1798. {
  1799. if (in_array($d, $this->course_when[$idx]["day"])) {
  1800. $i = array_search($d, $this->course_when[$idx]["day"]);
  1801. array_splice($this->course_when[$idx]["day"], $i, 1);
  1802. } else {
  1803. $this->course_when[$idx]["day"][] = $d;
  1804. }
  1805. }
  1806. public function updateBorsellino($importoBorsellino, $s)
  1807. {
  1808. if ($importoBorsellino > 0) {
  1809. $imp = $importoBorsellino;
  1810. if ($s == "-")
  1811. $imp = $imp * -1;
  1812. $money = new \App\Models\Money();
  1813. $money->member_id = $this->currentMember->id;
  1814. $money->record_id = null;
  1815. $money->amount = $imp;
  1816. $money->date = date("Y-m-d");
  1817. $money->note = 'Forzato ' . $imp;
  1818. $money->save();
  1819. }
  1820. $this->emit('saved');
  1821. }
  1822. public function getMonth($m)
  1823. {
  1824. $ret = '';
  1825. switch ($m) {
  1826. case 1:
  1827. $ret = 'Gennaio';
  1828. break;
  1829. case 2:
  1830. $ret = 'Febbraio';
  1831. break;
  1832. case 3:
  1833. $ret = 'Marzo';
  1834. break;
  1835. case 4:
  1836. $ret = 'Aprile';
  1837. break;
  1838. case 5:
  1839. $ret = 'Maggio';
  1840. break;
  1841. case 6:
  1842. $ret = 'Giugno';
  1843. break;
  1844. case 7:
  1845. $ret = 'Luglio';
  1846. break;
  1847. case 8:
  1848. $ret = 'Agosto';
  1849. break;
  1850. case 9:
  1851. $ret = 'Settembre';
  1852. break;
  1853. case 10:
  1854. $ret = 'Ottobre';
  1855. break;
  1856. case 11:
  1857. $ret = 'Novembre';
  1858. break;
  1859. case 12:
  1860. $ret = 'Dicembre';
  1861. break;
  1862. default:
  1863. $ret = '';
  1864. break;
  1865. }
  1866. return $ret;
  1867. }
  1868. }
  1869. class codicefiscale
  1870. {
  1871. /**
  1872. * Array delle consonanti
  1873. */
  1874. protected $_consonanti = array(
  1875. 'B',
  1876. 'C',
  1877. 'D',
  1878. 'F',
  1879. 'G',
  1880. 'H',
  1881. 'J',
  1882. 'K',
  1883. 'L',
  1884. 'M',
  1885. 'N',
  1886. 'P',
  1887. 'Q',
  1888. 'R',
  1889. 'S',
  1890. 'T',
  1891. 'V',
  1892. 'W',
  1893. 'X',
  1894. 'Y',
  1895. 'Z'
  1896. );
  1897. /**
  1898. * Array delle vocali
  1899. */
  1900. protected $_vocali = array(
  1901. 'A',
  1902. 'E',
  1903. 'I',
  1904. 'O',
  1905. 'U'
  1906. );
  1907. /**
  1908. * Array per il calcolo della lettera del mese
  1909. * Al numero del mese corrisponde una lettera
  1910. */
  1911. protected $_mesi = array(
  1912. 1 => 'A',
  1913. 2 => 'B',
  1914. 3 => 'C',
  1915. 4 => 'D',
  1916. 5 => 'E',
  1917. 6 => 'H',
  1918. 7 => 'L',
  1919. 8 => 'M',
  1920. 9 => 'P',
  1921. 10 => 'R',
  1922. 11 => 'S',
  1923. 12 => 'T'
  1924. );
  1925. protected $_pari = array(
  1926. '0' => 0,
  1927. '1' => 1,
  1928. '2' => 2,
  1929. '3' => 3,
  1930. '4' => 4,
  1931. '5' => 5,
  1932. '6' => 6,
  1933. '7' => 7,
  1934. '8' => 8,
  1935. '9' => 9,
  1936. 'A' => 0,
  1937. 'B' => 1,
  1938. 'C' => 2,
  1939. 'D' => 3,
  1940. 'E' => 4,
  1941. 'F' => 5,
  1942. 'G' => 6,
  1943. 'H' => 7,
  1944. 'I' => 8,
  1945. 'J' => 9,
  1946. 'K' => 10,
  1947. 'L' => 11,
  1948. 'M' => 12,
  1949. 'N' => 13,
  1950. 'O' => 14,
  1951. 'P' => 15,
  1952. 'Q' => 16,
  1953. 'R' => 17,
  1954. 'S' => 18,
  1955. 'T' => 19,
  1956. 'U' => 20,
  1957. 'V' => 21,
  1958. 'W' => 22,
  1959. 'X' => 23,
  1960. 'Y' => 24,
  1961. 'Z' => 25
  1962. );
  1963. protected $_dispari = array(
  1964. '0' => 1,
  1965. '1' => 0,
  1966. '2' => 5,
  1967. '3' => 7,
  1968. '4' => 9,
  1969. '5' => 13,
  1970. '6' => 15,
  1971. '7' => 17,
  1972. '8' => 19,
  1973. '9' => 21,
  1974. 'A' => 1,
  1975. 'B' => 0,
  1976. 'C' => 5,
  1977. 'D' => 7,
  1978. 'E' => 9,
  1979. 'F' => 13,
  1980. 'G' => 15,
  1981. 'H' => 17,
  1982. 'I' => 19,
  1983. 'J' => 21,
  1984. 'K' => 2,
  1985. 'L' => 4,
  1986. 'M' => 18,
  1987. 'N' => 20,
  1988. 'O' => 11,
  1989. 'P' => 3,
  1990. 'Q' => 6,
  1991. 'R' => 8,
  1992. 'S' => 12,
  1993. 'T' => 14,
  1994. 'U' => 16,
  1995. 'V' => 10,
  1996. 'W' => 22,
  1997. 'X' => 25,
  1998. 'Y' => 24,
  1999. 'Z' => 23
  2000. );
  2001. protected $_controllo = array(
  2002. '0' => 'A',
  2003. '1' => 'B',
  2004. '2' => 'C',
  2005. '3' => 'D',
  2006. '4' => 'E',
  2007. '5' => 'F',
  2008. '6' => 'G',
  2009. '7' => 'H',
  2010. '8' => 'I',
  2011. '9' => 'J',
  2012. '10' => 'K',
  2013. '11' => 'L',
  2014. '12' => 'M',
  2015. '13' => 'N',
  2016. '14' => 'O',
  2017. '15' => 'P',
  2018. '16' => 'Q',
  2019. '17' => 'R',
  2020. '18' => 'S',
  2021. '19' => 'T',
  2022. '20' => 'U',
  2023. '21' => 'V',
  2024. '22' => 'W',
  2025. '23' => 'X',
  2026. '24' => 'Y',
  2027. '25' => 'Z'
  2028. );
  2029. /**
  2030. * Stringa di errore
  2031. */
  2032. protected $_error = null;
  2033. /**
  2034. * Separatore per la data di nascita
  2035. */
  2036. protected $_dateSeparator = '/';
  2037. /**
  2038. * Percorso del file del database SQLite
  2039. * dei codici catastali
  2040. */
  2041. protected $_dbCatastali = null;
  2042. /**
  2043. * Trasforma la stringa passata in un array di lettere
  2044. * e lo incrocia con un ulteriore array
  2045. */
  2046. protected function _getLettere($string, array $haystack)
  2047. {
  2048. $letters = array();
  2049. foreach (str_split($string) as $needle) {
  2050. if (in_array($needle, $haystack)) {
  2051. $letters[] = $needle;
  2052. }
  2053. }
  2054. return $letters;
  2055. }
  2056. /**
  2057. * Ritorna un array con le vocali di una data stringa
  2058. */
  2059. protected function _getVocali($string)
  2060. {
  2061. return $this->_getLettere($string, $this->_vocali);
  2062. }
  2063. /**
  2064. * Ritorna un array con le consonanti di una data stringa
  2065. */
  2066. protected function _getConsonanti($string)
  2067. {
  2068. return $this->_getLettere($string, $this->_consonanti);
  2069. }
  2070. /**
  2071. * Pulisce la stringa filtrando tutti i caratteri che
  2072. * non sono lettere. Lo switch $toupper se impostato a TRUE
  2073. * converte la stringa risultante in MAIUSCOLO.
  2074. */
  2075. protected function _sanitize($string, $toupper = true)
  2076. {
  2077. $result = preg_replace('/[^A-Za-z]*/', '', $string);
  2078. return ($toupper) ? strtoupper($result) : $result;
  2079. }
  2080. /**
  2081. * Se la stringa passata a funzione e' costituita
  2082. * da meno di 3 caratteri, rimpiazza le lettere
  2083. * mancanti con la lettera X.
  2084. */
  2085. protected function _addMissingX($string)
  2086. {
  2087. $code = $string;
  2088. while (strlen($code) < 3) {
  2089. $code .= 'X';
  2090. }
  2091. return $code;
  2092. }
  2093. /**
  2094. * Ottiene il codice identificativo del nome
  2095. */
  2096. protected function _calcolaNome($string)
  2097. {
  2098. $nome = $this->_sanitize($string);
  2099. $code = '';
  2100. // Se il nome inserito e' piu' corto di 3 lettere
  2101. // si aggiungono tante X quanti sono i caratteri
  2102. // mancanti.
  2103. if (strlen($nome) < 3) {
  2104. return $this->_addMissingX($nome);
  2105. }
  2106. $nome_cons = $this->_getConsonanti($nome);
  2107. // Se le consonanti contenute nel nome sono minori
  2108. // o uguali a 3 vengono considerate nell'ordine in cui
  2109. // compaiono.
  2110. if (count($nome_cons) <= 3) {
  2111. $code = implode('', $nome_cons);
  2112. } else {
  2113. // Se invece abbiamo almeno 4 consonanti, prendiamo
  2114. // la prima, la terza e la quarta.
  2115. for ($i = 0; $i < 4; $i++) {
  2116. if ($i == 1) continue;
  2117. if (!empty($nome_cons[$i])) {
  2118. $code .= $nome_cons[$i];
  2119. }
  2120. }
  2121. }
  2122. // Se compaiono meno di 3 consonanti nel nome, si
  2123. // utilizzano le vocali, nell'ordine in cui compaiono
  2124. // nel nome.
  2125. if (strlen($code) < 3) {
  2126. $nome_voc = $this->_getVocali($nome);
  2127. while (strlen($code) < 3) {
  2128. $code .= array_shift($nome_voc);
  2129. }
  2130. }
  2131. return $code;
  2132. }
  2133. protected function _calcolaCognome($string)
  2134. {
  2135. $cognome = $this->_sanitize($string);
  2136. $code = '';
  2137. // Se il cognome inserito e' piu' corto di 3 lettere
  2138. // si aggiungono tante X quanti sono i caratteri
  2139. // mancanti.
  2140. if (strlen($cognome) < 3) {
  2141. return $this->_addMissingX($cognome);
  2142. }
  2143. $cognome_cons = $this->_getConsonanti($cognome);
  2144. // Per il calcolo del cognome si prendono le prime
  2145. // 3 consonanti.
  2146. for ($i = 0; $i < 3; $i++) {
  2147. if (array_key_exists($i, $cognome_cons)) {
  2148. $code .= $cognome_cons[$i];
  2149. }
  2150. }
  2151. // Se le consonanti non bastano, vengono prese
  2152. // le vocali nell'ordine in cui compaiono.
  2153. if (strlen($code) < 3) {
  2154. $cognome_voc = $this->_getVocali($cognome);
  2155. while (strlen($code) < 3) {
  2156. $code .= array_shift($cognome_voc);
  2157. }
  2158. }
  2159. return $code;
  2160. }
  2161. /**
  2162. * Imposta il separatore di data ( default: / )
  2163. */
  2164. public function setDateSeparator($char)
  2165. {
  2166. $this->_dateSeparator = $char;
  2167. return $this;
  2168. }
  2169. /**
  2170. * Ritorna la parte di codice fiscale corrispondente
  2171. * alla data di nascita del soggetto (Forma: AAMGG)
  2172. */
  2173. protected function _calcolaDataNascita($data, $sesso)
  2174. {
  2175. $dn = explode($this->_dateSeparator, $data);
  2176. $giorno = (int) @$dn[2];
  2177. $mese = (int) @$dn[1];
  2178. $anno = (int) @$dn[0];
  2179. // Le ultime due cifre dell'anno di nascita
  2180. $aa = substr($anno, -2);
  2181. // La lettera corrispondente al mese di nascita
  2182. $mm = $this->_mesi[$mese];
  2183. // Il giorno viene calcolato a seconda del sesso
  2184. // del soggetto di cui si calcola il codice:
  2185. // se e' Maschio si mette il giorno reale, se e'
  2186. // Femmina viene aggiungo 40 a questo numero.
  2187. $gg = (strtoupper($sesso) == 'M') ? $giorno : ($giorno + 40);
  2188. // Bug #1: Thanks to Luca
  2189. if (strlen($gg) < 2) $gg = '0' . $gg;
  2190. return $aa . $mm . $gg;
  2191. }
  2192. /**
  2193. * Ritorna la cifra di controllo sulla base dei
  2194. * 15 caratteri del codice fiscale calcolati.
  2195. */
  2196. protected function _calcolaCifraControllo($codice)
  2197. {
  2198. $code = str_split($codice);
  2199. $sum = 0;
  2200. for ($i = 1; $i <= count($code); $i++) {
  2201. $cifra = $code[$i - 1];
  2202. $sum += ($i % 2) ? $this->_dispari[$cifra] : $this->_pari[$cifra];
  2203. }
  2204. $sum %= 26;
  2205. return $this->_controllo[$sum];
  2206. }
  2207. /**
  2208. * Imposta il messaggio di errore
  2209. */
  2210. protected function _setError($string)
  2211. {
  2212. $this->_error = $string;
  2213. }
  2214. /**
  2215. * Verifica la presenza di un errore.
  2216. * Ritorna TRUE se presente, FALSE altrimenti.
  2217. */
  2218. public function hasError()
  2219. {
  2220. return !is_null($this->_error);
  2221. }
  2222. /**
  2223. * Ritorna la stringa di errore
  2224. */
  2225. public function getError()
  2226. {
  2227. return $this->_error;
  2228. }
  2229. /**
  2230. * Ritorna il codice fiscale utilizzando i parametri
  2231. * passati a funzione. Se si verifica
  2232. */
  2233. public function calcola($nome, $cognome, $data, $sesso, $comune)
  2234. {
  2235. $codice = $this->_calcolaCognome($cognome) .
  2236. $this->_calcolaNome($nome) .
  2237. $this->_calcolaDataNascita($data, $sesso) .
  2238. $comune;
  2239. if ($this->hasError()) {
  2240. return false;
  2241. }
  2242. $codice .= $this->_calcolaCifraControllo($codice);
  2243. if (strlen($codice) != 16) {
  2244. //$this->_setError(self::ERR_GENERIC);
  2245. return 'ERROR';
  2246. }
  2247. return $codice;
  2248. }
  2249. }