Member.php 89 KB

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