Member.php 89 KB

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