Member.php 89 KB

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