|
|
@@ -4,6 +4,9 @@ namespace App\Http\Livewire;
|
|
|
|
|
|
use Livewire\Component;
|
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
+use SimpleXMLElement;
|
|
|
+
|
|
|
|
|
|
class Receipt extends Component
|
|
|
{
|
|
|
@@ -58,6 +61,42 @@ class Receipt 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 = \App\Models\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');
|
|
|
+ }
|
|
|
+
|
|
|
public function search()
|
|
|
{
|
|
|
$this->hasFilter = true;
|