Member.php 88 KB

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