Member.php 83 KB

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