Member.php 79 KB

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