|
|
@@ -5,6 +5,9 @@ use Livewire\Component;
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
+use SimpleXMLElement;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
class RecordINOUT extends Component
|
|
|
{
|
|
|
@@ -51,7 +54,7 @@ class RecordINOUT extends Component
|
|
|
public function mount()
|
|
|
{
|
|
|
|
|
|
- if(\Auth::user()->level != env('LEVEL_ADMIN', 0))
|
|
|
+ if(Auth::user()->level != env('LEVEL_ADMIN', 0))
|
|
|
return redirect()->to('/dashboard');
|
|
|
|
|
|
$borsellino = \App\Models\Causal::where('money', true)->first();
|
|
|
@@ -684,4 +687,40 @@ class RecordINOUT extends Component
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public function importReceipts()
|
|
|
+ {
|
|
|
+ $this->validate([
|
|
|
+ 'receiptFile' => 'required|mimes:xml|max:2048',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ try {
|
|
|
+ $xmlString = file_get_contents($this->receiptFile->getRealPath());
|
|
|
+ $xml = new SimpleXMLElement($xmlString);
|
|
|
+ Log::info('XML Data: ' . print_r($xml, true));
|
|
|
+
|
|
|
+ // Extract data from XML and create receipts
|
|
|
+ foreach ($xml->receipt as $receiptData) {
|
|
|
+ Log::info('Receipt Data: ' . print_r($receiptData, true));
|
|
|
+ $member = Member::where('fiscal_code', (string)$receiptData->fiscal_code)->first();
|
|
|
+
|
|
|
+ if ($member) {
|
|
|
+ $receipt = new \App\Models\Receipt();
|
|
|
+ $receipt->member_id = $member->id;
|
|
|
+ $receipt->date = (string)$receiptData->date;
|
|
|
+ $receipt->amount = (float)$receiptData->amount;
|
|
|
+ $receipt->number = (string)$receiptData->number;
|
|
|
+ $receipt->year = (int)$receiptData->year;
|
|
|
+ $receipt->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ session()->flash('message', 'Ricevute importate con successo.');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ session()->flash('error', 'Errore durante l\'importazione del file XML: ' . $e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->reset('receiptFile');
|
|
|
+ $this->emit('load-data-table');
|
|
|
+ }
|
|
|
+
|
|
|
}
|