Anagrafica.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. use Livewire\WithPagination;
  5. class Anagrafica extends Component
  6. {
  7. use WithPagination;
  8. public $type;
  9. public $firstname;
  10. public $lastname;
  11. public $gender;
  12. public $birth_date;
  13. public $birth_town_id;
  14. public $birth_prov_id;
  15. public $residenza_town_id;
  16. public $residenza_prov_id;
  17. public $residenza_address;
  18. public $residenza_cap;
  19. public $mobile;
  20. public $sedicente;
  21. public $documento_tipo;
  22. public $documento_patente_cat;
  23. public $documento_tipo_altro;
  24. public $documento_numero;
  25. public $documento_rilasciato_da;
  26. public $documento_rilasciato_da_altro;
  27. public $foreign_country;
  28. public $documento_rilasciato_da_di_foreign_localita;
  29. public $documento_rilasciato_da_di_foreign_country;
  30. public $documento_rilasciato_da_prov_id;
  31. public $documento_rilasciato_da_town_id;
  32. public $documento_rilasciato_il;
  33. public $documento_scadenza_il;
  34. public $state;
  35. public $created;
  36. public $created_by;
  37. public $updated;
  38. public $updated_by;
  39. public $locked;
  40. public $locked_by;
  41. public $nazionalita;
  42. public $nazione_straniera;
  43. public $localita_straniera;
  44. public $rag_soc;
  45. public $vat;
  46. public $sede_legale_address;
  47. public $sede_legale_town_id;
  48. public $sede_legale_prov_id;
  49. public $sede_legale_cap;
  50. public $sede_legale_state;
  51. public $phone;
  52. public $recordId; // Used for editing/updating a record
  53. public $updateMode = false;
  54. public $anag_foreign_birth_country;
  55. public $anag_foreign_birth_city;
  56. public $anag_foreign_residence_country;
  57. public $anag_foreign_residence_city;
  58. protected $rules = [
  59. 'type' => 'required|string|max:255',
  60. 'firstname' => 'required|string|max:255',
  61. 'lastname' => 'required|string|max:255',
  62. // Add other validation rules as needed
  63. ];
  64. public function render()
  65. {
  66. return view('livewire.anagrafica-crud', [
  67. 'anagraficas' => Anagrafica::paginate(10)
  68. ]);
  69. }
  70. public function resetInputFields()
  71. {
  72. $this->type = '';
  73. $this->firstname = '';
  74. $this->lastname = '';
  75. $this->gender = '';
  76. $this->birth_date = '';
  77. $this->birth_town_id = '';
  78. $this->birth_prov_id = '';
  79. $this->residenza_town_id = '';
  80. $this->residenza_prov_id = '';
  81. $this->residenza_address = '';
  82. $this->residenza_cap = '';
  83. $this->mobile = '';
  84. $this->sedicente = '';
  85. $this->documento_tipo = '';
  86. $this->documento_patente_cat = '';
  87. $this->documento_tipo_altro = '';
  88. $this->documento_numero = '';
  89. $this->documento_rilasciato_da = '';
  90. $this->documento_rilasciato_da_altro = '';
  91. $this->foreign_country = '';
  92. $this->documento_rilasciato_da_di_foreign_localita = '';
  93. $this->documento_rilasciato_da_di_foreign_country = '';
  94. $this->documento_rilasciato_da_prov_id = '';
  95. $this->documento_rilasciato_da_town_id = '';
  96. $this->documento_rilasciato_il = '';
  97. $this->documento_scadenza_il = '';
  98. $this->state = '';
  99. $this->created = '';
  100. $this->created_by = '';
  101. $this->updated = '';
  102. $this->updated_by = '';
  103. $this->locked = '';
  104. $this->locked_by = '';
  105. $this->nazionalita = '';
  106. $this->nazione_straniera = '';
  107. $this->localita_straniera = '';
  108. $this->rag_soc = '';
  109. $this->vat = '';
  110. $this->sede_legale_address = '';
  111. $this->sede_legale_town_id = '';
  112. $this->sede_legale_prov_id = '';
  113. $this->sede_legale_cap = '';
  114. $this->sede_legale_state = '';
  115. $this->phone = '';
  116. $this->anag_foreign_birth_country = '';
  117. $this->anag_foreign_birth_city = '';
  118. $this->anag_foreign_residence_country = '';
  119. $this->anag_foreign_residence_city = '';
  120. }
  121. public function store()
  122. {
  123. $this->validate();
  124. Anagrafica::create([
  125. 'type' => $this->type,
  126. 'firstname' => $this->firstname,
  127. 'lastname' => $this->lastname,
  128. 'gender' => $this->gender,
  129. 'birth_date' => $this->birth_date,
  130. 'birth_town_id' => $this->birth_town_id,
  131. 'birth_prov_id' => $this->birth_prov_id,
  132. 'residenza_town_id' => $this->residenza_town_id,
  133. 'residenza_prov_id' => $this->residenza_prov_id,
  134. 'residenza_address' => $this->residenza_address,
  135. 'residenza_cap' => $this->residenza_cap,
  136. 'mobile' => $this->mobile,
  137. 'sedicente' => $this->sedicente,
  138. 'documento_tipo' => $this->documento_tipo,
  139. 'documento_patente_cat' => $this->documento_patente_cat,
  140. 'documento_tipo_altro' => $this->documento_tipo_altro,
  141. 'documento_numero' => $this->documento_numero,
  142. 'documento_rilasciato_da' => $this->documento_rilasciato_da,
  143. 'documento_rilasciato_da_altro' => $this->documento_rilasciato_da_altro,
  144. 'foreign_country' => $this->foreign_country,
  145. 'documento_rilasciato_da_di_foreign_localita' => $this->documento_rilasciato_da_di_foreign_localita,
  146. 'documento_rilasciato_da_di_foreign_country' => $this->documento_rilasciato_da_di_foreign_country,
  147. 'documento_rilasciato_da_prov_id' => $this->documento_rilasciato_da_prov_id,
  148. 'documento_rilasciato_da_town_id' => $this->documento_rilasciato_da_town_id,
  149. 'documento_rilasciato_il' => $this->documento_rilasciato_il,
  150. 'documento_scadenza_il' => $this->documento_scadenza_il,
  151. 'state' => $this->state,
  152. 'created' => $this->created,
  153. 'created_by' => $this->created_by,
  154. 'updated' => $this->updated,
  155. 'updated_by' => $this->updated_by,
  156. 'locked' => $this->locked,
  157. 'locked_by' => $this->locked_by,
  158. 'nazionalita' => $this->nazionalita,
  159. 'nazione_straniera' => $this->nazione_straniera,
  160. 'localita_straniera' => $this->localita_straniera,
  161. 'rag_soc' => $this->rag_soc,
  162. 'vat' => $this->vat,
  163. 'sede_legale_address' => $this->sede_legale_address,
  164. 'sede_legale_town_id' => $this->sede_legale_town_id,
  165. 'sede_legale_prov_id' => $this->sede_legale_prov_id,
  166. 'sede_legale_cap' => $this->sede_legale_cap,
  167. 'sede_legale_state' => $this->sede_legale_state,
  168. 'phone' => $this->phone,
  169. 'anag_foreign_birth_country' => $this->anag_foreign_birth_country,
  170. 'anag_foreign_birth_city' => $this->anag_foreign_birth_city,
  171. 'anag_foreign_residence_country' => $this->anag_foreign_residence_country,
  172. 'anag_foreign_residence_city' => $this->anag_foreign_residence_city,
  173. ]);
  174. session()->flash('message', 'Record Created Successfully.');
  175. $this->resetInputFields();
  176. }
  177. public function edit($id)
  178. {
  179. $record = Anagrafica::findOrFail($id);
  180. $this->recordId = $id;
  181. $this->type = $record->type;
  182. $this->firstname = $record->firstname;
  183. $this->lastname = $record->lastname;
  184. $this->gender = $record->gender;
  185. $this->birth_date = $record->birth_date;
  186. $this->birth_town_id = $record->birth_town_id;
  187. $this->birth_prov_id = $record->birth_prov_id;
  188. $this->residenza_town_id = $record->residenza_town_id;
  189. $this->residenza_prov_id = $record->residenza_prov_id;
  190. $this->residenza_address = $record->residenza_address;
  191. $this->residenza_cap = $record->residenza_cap;
  192. $this->mobile = $record->mobile;
  193. $this->sedicente = $record->sedicente;
  194. $this->documento_tipo = $record->documento_tipo;
  195. $this->documento_patente_cat = $record->documento_patente_cat;
  196. $this->documento_tipo_altro = $record->documento_tipo_altro;
  197. $this->documento_numero = $record->documento_numero;
  198. $this->documento_rilasciato_da = $record->documento_rilasciato_da;
  199. $this->documento_rilasciato_da_altro = $record->documento_rilasciato_da_altro;
  200. $this->foreign_country = $record->foreign_country;
  201. $this->documento_rilasciato_da_di_foreign_localita = $record->documento_rilasciato_da_di_foreign_localita;
  202. $this->documento_rilasciato_da_di_foreign_country = $record->documento_rilasciato_da_di_foreign_country;
  203. $this->documento_rilasciato_da_prov_id = $record->documento_rilasciato_da_prov_id;
  204. $this->documento_rilasciato_da_town_id = $record->documento_rilasciato_da_town_id;
  205. $this->documento_rilasciato_il = $record->documento_rilasciato_il;
  206. $this->documento_scadenza_il = $record->documento_scadenza_il;
  207. $this->state = $record->state;
  208. $this->created = $record->created;
  209. $this->created_by = $record->created_by;
  210. $this->updated = $record->updated;
  211. $this->updated_by = $record->updated_by;
  212. $this->locked = $record->locked;
  213. $this->locked_by = $record->locked_by;
  214. $this->nazionalita = $record->nazionalita;
  215. $this->nazione_straniera = $record->nazione_straniera;
  216. $this->localita_straniera = $record->localita_straniera;
  217. $this->rag_soc = $record->rag_soc;
  218. $this->vat = $record->vat;
  219. $this->sede_legale_address = $record->sede_legale_address;
  220. $this->sede_legale_town_id = $record->sede_legale_town_id;
  221. $this->sede_legale_prov_id = $record->sede_legale_prov_id;
  222. $this->sede_legale_cap = $record->sede_legale_cap;
  223. $this->sede_legale_state = $record->sede_legale_state;
  224. $this->phone = $record->phone;
  225. $this->anag_foreign_birth_country = $record->anag_foreign_birth_country;
  226. $this->anag_foreign_birth_city = $record->anag_foreign_birth_city;
  227. $this->anag_foreign_residence_country = $record->anag_foreign_residence_country;
  228. $this->anag_foreign_residence_city = $record->anag_foreign_residence_city;
  229. //$this->residenza_address = $record->anag_residenza_address;
  230. $this->updateMode = true;
  231. }
  232. public function update()
  233. {
  234. $this->validate();
  235. if ($this->recordId) {
  236. $record = Anagrafica::find($this->recordId);
  237. $record->update([
  238. 'type' => $this->type,
  239. 'firstname' => $this->firstname,
  240. 'lastname' => $this->lastname,
  241. 'gender' => $this->gender,
  242. 'birth_date' => $this->birth_date,
  243. 'birth_town_id' => $this->birth_town_id,
  244. 'birth_prov_id' => $this->birth_prov_id,
  245. 'residenza_town_id' => $this->residenza_town_id,
  246. 'residenza_prov_id' => $this->residenza_prov_id,
  247. 'residenza_address' => $this->residenza_address,
  248. 'residenza_cap' => $this->residenza_cap,
  249. 'mobile' => $this->mobile,
  250. 'sedicente' => $this->sedicente,
  251. 'documento_tipo' => $this->documento_tipo,
  252. 'documento_patente_cat' => $this->documento_patente_cat,
  253. 'documento_tipo_altro' => $this->documento_tipo_altro,
  254. 'documento_numero' => $this->documento_numero,
  255. 'documento_rilasciato_da' => $this->documento_rilasciato_da,
  256. 'documento_rilasciato_da_altro' => $this->documento_rilasciato_da_altro,
  257. 'foreign_country' => $this->foreign_country,
  258. 'documento_rilasciato_da_di_foreign_localita' => $this->documento_rilasciato_da_di_foreign_localita,
  259. 'documento_rilasciato_da_di_foreign_country' => $this->documento_rilasciato_da_di_foreign_country,
  260. 'documento_rilasciato_da_prov_id' => $this->documento_rilasciato_da_prov_id,
  261. 'documento_rilasciato_da_town_id' => $this->documento_rilasciato_da_town_id,
  262. 'documento_rilasciato_il' => $this->documento_rilasciato_il,
  263. 'documento_scadenza_il' => $this->documento_scadenza_il,
  264. 'state' => $this->state,
  265. 'created' => $this->created,
  266. 'created_by' => $this->created_by,
  267. 'updated' => $this->updated,
  268. 'updated_by' => $this->updated_by,
  269. 'locked' => $this->locked,
  270. 'locked_by' => $this->locked_by,
  271. 'nazionalita' => $this->nazionalita,
  272. 'nazione_straniera' => $this->nazione_straniera,
  273. 'localita_straniera' => $this->localita_straniera,
  274. 'rag_soc' => $this->rag_soc,
  275. 'vat' => $this->vat,
  276. 'sede_legale_address' => $this->sede_legale_address,
  277. 'sede_legale_town_id' => $this->sede_legale_town_id,
  278. 'sede_legale_prov_id' => $this->sede_legale_prov_id,
  279. 'sede_legale_cap' => $this->sede_legale_cap,
  280. 'sede_legale_state' => $this->sede_legale_state,
  281. 'phone' => $this->phone,
  282. 'anag_foreign_birth_country' => $this->anag_foreign_birth_country,
  283. 'anag_foreign_birth_city' => $this->anag_foreign_birth_city,
  284. 'anag_foreign_residence_country' => $this->anag_foreign_residence_country,
  285. 'anag_foreign_residence_city' => $this->anag_foreign_residence_city,
  286. ]);
  287. $this->updateMode = false;
  288. session()->flash('message', 'Record Updated Successfully.');
  289. $this->resetInputFields();
  290. }
  291. }
  292. public function delete($id)
  293. {
  294. Anagrafica::find($id)->delete();
  295. session()->flash('message', 'Record Deleted Successfully.');
  296. }
  297. }