Luca Parisio 1 سال پیش
والد
کامیت
2a30bb641d

+ 11 - 2
app/Http/Livewire/Course.php

@@ -278,7 +278,7 @@ class Course extends Component
         $this->category_id = $id;
     }
 
-    public function duplicate($id){
+    public function duplicate($id, $isMultiple){
         $course = \App\Models\Course::findOrFail($id);
         $newCourse = $course->replicate();
         $newYear = date("Y") . "-" . (date("Y") + 1);
@@ -289,7 +289,16 @@ class Course extends Component
         }
         $newCourse->year = $newYear;
         $newCourse->save();
-        $this->edit($newCourse->id);
+        if (!$isMultiple)
+            $this->edit($newCourse->id);
+    }
+
+    public function duplicateMultiple($ids){
+        foreach($ids as $id)
+        {
+            $this->duplicate($id, true);
+        }
+        return redirect()->to('/courses');
     }
 
 }

+ 52 - 7
app/Http/Livewire/Profile.php

@@ -6,42 +6,55 @@ use Livewire\Component;
 
 class Profile extends Component
 {
-    public $name, $email, $password, $newPassword, $update = false;
+    public $name, $email, $password, $passwordConfirm, $update = false, $editPassword = false, $errorConfirm;
 
     protected $rules = [
         'name' => 'required',
-        'email' => 'required',
-        'password' => 'required'
+        'email' => 'required'
     ];
 
     protected $messages = [
         'name.required' => 'Il nome è obbligatorio',
         'email.required' => 'La mail è obbligatoria',
         'password.required' => 'La password è obbligatoria',
+        'passwordConfirm.required' => 'La conferma password è obbligatoria',
     ];
 
     public function resetFields(){
-        $this->name = '';
-        $this->email = '';
+        //$this->name = '';
+        //$this->email = '';
+        $this->errorConfirm = '';
         $this->password = '';
         $this->newPassword = '';
     }
 
-    public function render()
+    public function mount()
     {
         $this->name = \Auth::user()->name;
         $this->email = \Auth::user()->email;
+    }
+
+    public function render()
+    {
+        
         return view('livewire.profile');
     }
 
     public function edit()
     {
-        $this->resetFields();
+        //$this->resetFields();
         $this->update = true;
     }
 
+    public function editPwd()
+    {
+        $this->resetFields();
+        $this->editPassword = true;
+    }
+
     public function save()
     {
+
         $this->validate();
         try {
             $user = \Auth::user();
@@ -59,4 +72,36 @@ class Profile extends Component
             session()->flash('error','Errore (' . $ex->getMessage() . ')');
         }
     }
+
+    public function updatePwd()
+    {
+        $this->errorConfirm = '';
+        $this->validate(['password' => 'required', 'passwordConfirm' => 'required']);
+        try {
+            $user = \Auth::user();
+            if ($this->password == $this->passwordConfirm)
+            {
+                $user->password = bcrypt($this->password);
+                $user->save();
+                session()->flash('success','Dato creato');
+                $this->resetFields();
+                $this->update = false;
+            }
+            else
+            {
+                $this->errorConfirm = 'Le password non coincidono';
+            }
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
+    public function cancel()
+    {
+        $this->resetFields();
+        $this->update = false;
+        $this->editPassword = false;
+    }
+
 }
+

+ 34 - 0
app/Http/Livewire/RecordIN.php

@@ -779,6 +779,40 @@ class RecordIN extends Component
         }
     }
 
+    public function rigenerate()
+    {
+        $this->emit('refresh');
+        
+        try {
+
+            $record = \App\Models\Record::findOrFail($this->dataId);
+            $newRecord = $record->replicate();
+            $newRecord->date = date("Y-m-d");
+            $newRecord->save();
+
+            $recordRows = \App\Models\RecordRow::where('record_id', $this->dataId)->get();
+            // Inserisco le righe
+            foreach($recordRows as $row)
+            {
+                $newRow = $row->replicate();
+                $newRow->record_id = $newRecord->id;
+                $newRow->save();
+            }
+
+            $this->dataId = $newRecord->id;
+
+            $this->createReceipt();
+
+            session()->flash('success','Movimento aggiornato');
+            $this->resetFields();
+            $this->update = false;
+            $this->isDuplicate = false;
+            $this->emit('setEdit', false);
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
     public function cancel()
     {
         // Se arrivo da duplica elimino

+ 54 - 0
public/chunk.php

@@ -0,0 +1,54 @@
+<?php
+// (a) helper function - server response
+function verbose($ok = 1, $info = "")
+{
+    if ($ok == 0) {
+        http_response_code(400);
+    }
+    exit(json_encode(["ok" => $ok, "info" => $info]));
+}
+
+// (b) invalid upload
+if (empty($_FILES) || $_FILES["file"]["error"]) {
+    verbose(0, "Failed to move uploaded file.");
+}
+
+// (c) upload destination - change folder if required!
+$filePath = __DIR__ . DIRECTORY_SEPARATOR . "uploads";
+/*if (!file_exists($filePath)) {
+    if (!mkdir($filePath, 0777, true)) {
+        verbose(0, "Failed to create $filePath");
+    }
+}*/
+$fileName = isset($_REQUEST["name"])
+    ? $_REQUEST["name"]
+    : $_FILES["file"]["name"];
+$filePath = $filePath . DIRECTORY_SEPARATOR . $fileName;
+
+// (d) deal with chunks
+$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
+$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
+$out = @fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
+if ($out) {
+    $in = @fopen($_FILES["file"]["tmp_name"], "rb");
+    if ($in) {
+        while ($buff = fread($in, 4096)) {
+            fwrite($out, $buff);
+        }
+    } else {
+        verbose(0, "Failed to open input stream");
+    }
+    @fclose($in);
+    @fclose($out);
+    @unlink($_FILES["file"]["tmp_name"]);
+} else {
+    verbose(0, "Failed to open output stream");
+}
+
+// (e) check if file has been uploaded
+if (!$chunks || $chunk == $chunks - 1) {
+    rename("{$filePath}.part", $filePath);
+}
+verbose(1, "Upload OK");
+?>
+

+ 92 - 64
public/medere.html

@@ -1,70 +1,98 @@
-<!doctype html>
+<!DOCTYPE html>
+<html>
 <head>
-<script src="https://sdk.amazonaws.com/js/aws-sdk-2.357.0.min.js"></script>
-<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
-<script type="text/javascript">
-
-var s3 = new AWS.S3({
-        apiVersion: 'latest',
-        region: 'de',
-        endpoint: 'https://s3.de.io.cloud.ovh.net/',
-        params: {
-            Bucket: 'medere'
-        },
-        credentials: {
-            accessKeyId:'78bd8d437d004457b89b04d803ed4d9e',
-            secretAccessKey:'516669c11e974de280515fc5dedf4396'
-        }
-});
-
-</script>
-<meta name="referrer" content="same-origin" />
+  <title>File Uploader</title>
+  <style>
+    body {
+      font-family: Arial, sans-serif;
+      background-color: #f5f5f5;
+      padding: 20px;
+    }
+  
+    #container {
+      display: flex;
+      flex-direction: column;
+      align-items: center;
+      justify-content: center;
+      height: 100vh;
+    }
+  
+    #list {
+      margin-bottom: 20px;
+    }
+  
+    .file-row {
+      display: flex;
+      align-items: center;
+      margin-bottom: 10px;
+    }
+  
+    .file-name {
+      flex-grow: 1;
+    }
+  
+    .file-size {
+      margin-left: 10px;
+    }
+  
+    #pick {
+      padding: 10px 20px;
+      font-size: 16px;
+      background-color: #007bff;
+      color: #fff;
+      border: none;
+      cursor: pointer;
+    }
+  
+    #pick:hover {
+      background-color: #0056b3;
+    }
+  </style>
 </head>
 <body>
-    <!-- A functional html code-->
-    <div>
-        <input type="file" id="fileUpload">
-    </div>
-
-    <div>
-    <button onclick="s3upload()">Submit</button>
-    </div>
+  <div id="container">
+    <h1>File Uploader</h1>
 
-    <progress max=”100” value=”0”></progress>
+    <form>
+      <div id="list"></div>
+      <input type="button" id="pick" value="Upload">
+    </form>
+  </div>
 
-    <!--
-    <img src="https://medere.s3.de.io.cloud.ovh.net/medere/sample.jpg?123">
-    -->
-
-    <script type="text/javascript">
-
-      function s3upload() {  
-            const start = Date.now();
-                var files = document.getElementById('fileUpload').files;
-                if (files) 
-                {
-                    var file = files[0];
-                    var fileName = file.name;
-                    var filePath = fileName;
-                    var fileUrl = 'https://s3.de.io.cloud.ovh.net/' +  filePath;
-            
-                    s3.upload({
-                        Key: filePath,
-                        Body: file,
-                        ACL: 'public-read'
-                    }, function(err, data) {
-                        if(err) {
-                            console.log('error' + err);
-                        }                       
-                        const end = Date.now(); 
-                        const sec = (end - start) / 1000;
-                        alert(`File caricato in : ${sec} secondi`);
-                    }).on('httpUploadProgress', function (progress) {
-                        var uploaded = progress.loaded / progress.total;
-                        $("progress").attr('value', uploaded);
-                    });
-                }
-      };
-    </script>
+  <script src="https://cdnjs.cloudflare.com/ajax/libs/plupload/3.1.5/plupload.full.min.js"></script>
+  <script>
+    window.onload = () => {
+      var list = document.getElementById("list");
+  
+      var uploader = new plupload.Uploader({
+        runtimes: "html5",
+        browse_button: "pick",
+        url: "chunk.php",
+        chunk_size: "5mb",
+        init: {
+          PostInit: () => list.innerHTML = "<div>Ready</div>",
+          FilesAdded: (up, files) => {
+            plupload.each(files, file => {
+              let row = document.createElement("div");
+              row.className = "file-row";
+              row.id = file.id;
+              row.innerHTML = `
+                <div class="file-name"><a href="uploads/${file.name}">${file.name}</a></div>
+                <div class="file-size">(${plupload.formatSize(file.size)})</div>
+                <strong></strong>
+              `;
+              list.appendChild(row);
+            });
+            uploader.start();
+          },
+          UploadProgress: (up, file) => {
+            document.querySelector(`#${file.id} strong`).innerHTML = `${file.percent}%`;
+          },
+          Error: (up, err) => console.error(err)
+        }
+      });
+      uploader.init();
+    };
+  </script>
 </body>
-</html>
+</html>

BIN
public/uploads/aaa.mp4


BIN
public/uploads/sample.jpg


+ 33 - 4
resources/views/livewire/course.blade.php

@@ -28,6 +28,7 @@
             <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
                 <thead>
                     <tr>
+                        <th  style="text-align:center" scope="col"><input type="checkbox" class="checkAll"></th>
                         <th scope="col">Anno</th>
                         <th scope="col">Nome</th>
                         <th scope="col">Livello</th>
@@ -41,6 +42,7 @@
                 <tbody id="checkall-target">
                     @foreach($records as $record)
                         <tr>
+                            <td style="text-align:center"><input type="checkbox" class="chkCourse" name="{{$record->id}}"></td>
                             <td>{{$record->year}}</td>
                             <td>{{$record->name}}</td>
                             <td>{{$record->level->name ?? ""}}</td>
@@ -51,7 +53,7 @@
                             <td>
                                 <button type="button" class="btn" wire:click="edit({{ $record->id }})" data-bs-toggle="popover"  data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Modifica"><i class="fa-regular fa-pen-to-square"></i></button>
                                 <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="delete({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Elimina"><i class="fa-regular fa-trash-can"></i></button>
-                                <button type="button" class="btn" wire:click="duplicate({{ $record->id }})" data-bs-toggle="popover"  data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Duplica"><i class="fa-regular fa-copy"></i></button>
+                                <button type="button" class="btn" wire:click="duplicate({{ $record->id }}, false)" data-bs-toggle="popover"  data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Duplica"><i class="fa-regular fa-copy"></i></button>
                             </td>
                         </tr>
                     @endforeach
@@ -378,24 +380,51 @@
                     },
                     top1C :'search',
                 },
+                "columnDefs": [ {
+                "targets": 0,
+                "orderable": false
+                } ],
                 pagingType: 'numbers',
                 "language": {
                     "url": "/assets/js/Italian.json"
                 },
                 "fnInitComplete": function (oSettings, json) {
-                    var html = '&nbsp;<a href="#" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
+                    var html = '&nbsp;<a href="#" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>&nbsp;<a href="#" class="duplicateData btn--ui"><i class="fa-solid fa-copy"></i></a>';
                     $(".dt-search").append(html);
                 }
             });
             $('#tablesaw-350 thead tr th').addClass('col');
             $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
 
+            var courses = [];
+            $(".chkCourse").click(function(){
+                var id = $(this).attr('name');
+                if(!courses.includes(id)){
+                    courses.push(id);
+                }else{
+                    courses.splice(courses.indexOf(id), 1);  //deleting
+                }
+                console.log(courses);
+            });
+
             $(document).ready(function() {
-                $(document).on("click",".addData",function() {
-                    $(".title--section_addButton").trigger("click")
+                $(document).on("click",".duplicateData",function() {
+                    @this.duplicateMultiple(courses);
                 });
             } );
 
+            var all = false;
+            $(".checkAll").click(function(){
+                all = !all;
+                courses = [];
+                $('.chkCourse').each(function(){
+                    $(this).prop('checked', all);
+                    if (all)
+                        courses.push($(this).attr('name'));
+                });
+                console.log(courses);
+            });
+
         }
 
     </script>

+ 56 - 12
resources/views/livewire/profile.blade.php

@@ -1,12 +1,5 @@
 <div class="col card--ui" id="card--dashboard">
 
-        <header id="title--section" style="display:none !important"  class="d-flex align-items-center justify-content-between">
-            <div class="title--section_name d-flex align-items-center justify-content-between">
-                <i class="ico--ui title_section utenti me-2"></i>
-                <h2 class="primary">Profilo</h2>
-            </div>
-        </header>
-
         <div class="container">
 
             @if (session()->has('error'))
@@ -21,16 +14,30 @@
                     <form action="">
 
                         <div class="row mb-3">
-                            <div class="col">
+                            <div class="col-md-6">
                                 <div class="form--item">
-                                    <label for="inputName" class="form-label">Nome</label>
+                                    <label for="inputName" class="form-label"><b>Nome</b></label>
                                     @if($update)
-                                        <input class="form-control js-keyupTitle @error('name') is-invalid @enderror" type="text" id="name" placeholder="Nome" wire:model="name">
+                                        <input class="form-control  @error('name') is-invalid @enderror" type="text" id="name" placeholder="Nome" wire:model="name">
                                         @error('name')
                                             <div class="invalid-feedback">{{ $message }}</div>
                                         @enderror
                                     @else
-                                        {{$name}}
+                                        <br>{{$name}}
+                                    @endif
+                                </div>
+                            </div>
+                        
+                            <div class="col-md-6">
+                                <div class="form--item">
+                                    <label for="email" class="form-label"><b>Email</b></label>
+                                    @if($update)
+                                        <input class="form-control  @error('email') is-invalid @enderror" type="text" id="email" placeholder="Email" wire:model="email">
+                                        @error('email')
+                                            <div class="invalid-feedback">{{ $message }}</div>
+                                        @enderror
+                                    @else
+                                        <br>{{$email}}
                                     @endif
                                 </div>
                             </div>
@@ -40,13 +47,50 @@
 
                         <div class="form--item">
                             @if($update)
-                                <button type="submit" class="btn--ui" wire:click.prevent="update()">Salva</button>
+                                <button type="submit" class="btn--ui" wire:click.prevent="save()">Salva</button>
                             @else
                                 <button type="submit" class="btn--ui" wire:click.prevent="edit()">Modifica</button>
                             @endif
                             <button type="button" class="btn--ui lightGrey" wire:click="cancel()">Annulla</button>
                         </div>
 
+                        <br><br>
+
+                        @if($editPassword)
+
+                            <div class="row mb-3">
+                                <div class="col-md-6">
+                                    <div class="form--item">
+                                        <label for="password" class="form-label">Password</label>
+                                        <input class="form-control js-keyupTitle @error('password') is-invalid @enderror" type="password" id="password" wire:model="password">
+                                        @error('password')
+                                            <div class="invalid-feedback">{{ $message }}</div>
+                                        @enderror
+                                    </div>
+                                </div>
+                                <div class="col-md-6">
+                                    <div class="form--item">
+                                        <label for="passwordConfirm" class="form-label">Conferma password</label>
+                                        <input class="form-control js-keyupTitle @error('passwordConfirm') is-invalid @enderror" type="password" id="passwordConfirm" wire:model="passwordConfirm">
+                                        @error('passwordConfirm')
+                                            <div class="invalid-feedback">{{ $message }}</div>
+                                        @enderror
+                                    </div>
+                                </div>
+                            </div>
+                            <span style="color:red">{{$errorConfirm}}</span>
+                            
+                        @endif
+
+                        <div class="form--item" style="margin-top: 10px">
+                            @if($editPassword)
+                                <button type="submit" class="btn--ui" wire:click.prevent="updatePwd()">Salva</button>
+                            @else
+                                <button type="submit" class="btn--ui" wire:click.prevent="editPwd()">Modifica password</button>
+                            @endif
+                            <button type="button" class="btn--ui lightGrey" wire:click="cancel()">Annulla</button>
+                        </div>
+
                     </form>
                 </div>
             </div>

+ 8 - 3
resources/views/livewire/records_in.blade.php

@@ -534,8 +534,11 @@
                                             @if($this->member && !$commercial && !$this->member->isAdult() && $parent == '')
                                                 <span style="color:red">Devi selezionare un genitore</span>
                                             @else
-                                                <button class="btn--ui primary sendInvoice d-flex ms-auto" wire:click.prevent="store(true)" onclick='window.location.href = "#top";'><i class="ico--ui sendingBtn"></i><span>inserisci {{!$commercial ? 'genera ricevuta' : ''}}</span></button>
+                                                @if($currentReceip->status != 99)
+                                                    <button class="btn--ui primary sendInvoice d-flex ms-auto" wire:click.prevent="store(true)" onclick='window.location.href = "#top";'><i class="ico--ui sendingBtn"></i><span>inserisci {{!$commercial ? 'genera ricevuta' : ''}}</span></button>
+                                                @endif
                                             @endif
+
                                         @endif
 
                                     @endif
@@ -543,7 +546,9 @@
                                         @if($this->member && !$commercial && !$this->member->isAdult() && $parent == '')
                                             <span style="color:red">Devi selezionare un genitore</span>
                                         @else
-                                            <button class="btn--ui primary sendInvoice d-flex ms-auto" wire:click.prevent="update({{!$commercial}})"><i class="ico--ui sendingBtn"></i><span>inserisci {{!$commercial ? 'genera ricevuta' : ''}}</span></button>
+                                            @if($currentReceip->status != 99)
+                                                <button class="btn--ui primary sendInvoice d-flex ms-auto" wire:click.prevent="update({{!$commercial}})"><i class="ico--ui sendingBtn"></i><span>inserisci {{!$commercial ? 'genera ricevuta' : ''}}</span></button>
+                                            @endif
                                         @endif
                                     @endif
                                 @else
@@ -688,7 +693,7 @@
                                     @if($this->member && !$commercial && !$this->member->isAdult() && $parent == '')
                                         <span style="color:red">Devi selezionare un genitore</span>
                                     @else
-                                        <button class="btn--ui primary sendInvoice mt-5 d-flex ms-auto" wire:click.prevent="update(true)"><i class="ico--ui sendingBtn"></i><span>salva e rigenera ricevuta</span></button>
+                                        <button class="btn--ui primary sendInvoice mt-5 d-flex ms-auto" wire:click.prevent="rigenerate()"><i class="ico--ui sendingBtn"></i><span>salva e rigenera ricevuta</span></button>
                                     @endif
                                 @else
                                     <div class="mt-5 buttons--ricevuta d-flex align-items-center">

+ 13 - 2
routes/web.php

@@ -184,8 +184,19 @@ Route::group(['middleware' => 'auth'],function(){
         }
         if ($_GET["filterCategories"] != "null")
         {
-            $cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["filterCategories"]))->pluck('member_id');
-            $x = $x->whereIn('id', $cats_ids);
+            $cc = array();
+            $cats = explode(",", $_GET["filterCategories"]);
+            foreach($cats as $c)
+            {
+                $m_ids = \App\Models\MemberCategory::where('category_id', $c)->pluck('member_id')->toArray();
+                if (sizeof($cc) > 0)
+                    $cc = array_intersect($cc, $m_ids);
+                else
+                    $cc = $m_ids;
+            }
+            $x = $x->whereIn('id', $cc);
+            //$cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["filterCategories"]))->pluck('member_id');
+            //$x = $x->whereIn('id', $cats_ids);
         }
         if ($_GET["fromYear"] != "")
         {