|
|
@@ -8,6 +8,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
use App\Models\MemberCourse;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
class CourseList extends Component
|
|
|
{
|
|
|
@@ -47,6 +48,8 @@ class CourseList extends Component
|
|
|
public $totals = [];
|
|
|
public $totalIsc = [];
|
|
|
|
|
|
+ public $selectedCourseId;
|
|
|
+ public $selectedMemberId;
|
|
|
public $aaa;
|
|
|
|
|
|
public $months = array('Set', 'Ott', 'Nov', 'Dic', 'Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago');
|
|
|
@@ -70,27 +73,33 @@ class CourseList extends Component
|
|
|
|
|
|
}
|
|
|
|
|
|
- public function updatedfilterCourse($value){
|
|
|
+ public function updatedfilterCourse($value)
|
|
|
+ {
|
|
|
$this->emit('load-data-table');
|
|
|
}
|
|
|
|
|
|
- public function updatedfilterLevel($value){
|
|
|
+ public function updatedfilterLevel($value)
|
|
|
+ {
|
|
|
$this->emit('load-data-table');
|
|
|
}
|
|
|
|
|
|
- public function updatedfilterFrequency($value){
|
|
|
+ public function updatedfilterFrequency($value)
|
|
|
+ {
|
|
|
$this->emit('load-data-table');
|
|
|
}
|
|
|
|
|
|
- public function updatedfilterType($value){
|
|
|
+ public function updatedfilterType($value)
|
|
|
+ {
|
|
|
$this->emit('load-data-table');
|
|
|
}
|
|
|
|
|
|
- public function updatedfilterDuration($value){
|
|
|
+ public function updatedfilterDuration($value)
|
|
|
+ {
|
|
|
$this->emit('load-data-table');
|
|
|
}
|
|
|
|
|
|
- public function updatedpageLength($value){
|
|
|
+ public function updatedpageLength($value)
|
|
|
+ {
|
|
|
$this->emit('load-data-table');
|
|
|
}
|
|
|
|
|
|
@@ -100,13 +109,10 @@ class CourseList extends Component
|
|
|
|
|
|
$member_course = \App\Models\MemberCourse::with('member')->with('course');
|
|
|
|
|
|
- if ($this->hasFilter)
|
|
|
- {
|
|
|
- if (isset($_GET["search"]["value"]))
|
|
|
- {
|
|
|
+ if ($this->hasFilter) {
|
|
|
+ if (isset($_GET["search"]["value"])) {
|
|
|
|
|
|
- if ($_GET["search"]["value"] != '')
|
|
|
- {
|
|
|
+ if ($_GET["search"]["value"] != '') {
|
|
|
$v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
|
|
|
$member_ids = \App\Models\Member::where(function ($query) use ($v) {
|
|
|
$query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
|
|
|
@@ -122,39 +128,32 @@ class CourseList extends Component
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (sizeof($this->filterCourse) > 0)
|
|
|
- {
|
|
|
+ if (sizeof($this->filterCourse) > 0) {
|
|
|
$course_ids = [];
|
|
|
$courses = $this->filterCourse;
|
|
|
- foreach($courses as $c)
|
|
|
- {
|
|
|
+ foreach ($courses as $c) {
|
|
|
$all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
|
|
|
- foreach($all as $a)
|
|
|
- {
|
|
|
+ foreach ($all as $a) {
|
|
|
$course_ids[] = $a->id;
|
|
|
}
|
|
|
}
|
|
|
$member_course = $member_course->whereIn('course_id', $course_ids);
|
|
|
}
|
|
|
|
|
|
- if (sizeof($this->filterLevel) > 0)
|
|
|
- {
|
|
|
+ if (sizeof($this->filterLevel) > 0) {
|
|
|
$course_ids = \App\Models\Course::whereIn('course_level_id', $this->filterLevel)->pluck('id');
|
|
|
$member_course = $member_course->whereIn('course_id', $course_ids);
|
|
|
}
|
|
|
|
|
|
- if (sizeof($this->filterFrequency) > 0)
|
|
|
- {
|
|
|
+ if (sizeof($this->filterFrequency) > 0) {
|
|
|
$course_ids = \App\Models\Course::whereIn('course_frequency_id', $this->filterFrequency)->pluck('id');
|
|
|
$member_course = $member_course->whereIn('course_id', $course_ids);
|
|
|
}
|
|
|
- if (sizeof($this->filterType) > 0)
|
|
|
- {
|
|
|
+ if (sizeof($this->filterType) > 0) {
|
|
|
$course_ids = \App\Models\Course::whereIn('course_type_id', $this->filterType)->pluck('id');
|
|
|
$member_course = $member_course->whereIn('course_id', $course_ids);
|
|
|
}
|
|
|
- if (sizeof($this->filterDuration) > 0)
|
|
|
- {
|
|
|
+ if (sizeof($this->filterDuration) > 0) {
|
|
|
$course_ids = \App\Models\Course::whereIn('course_duration_id', $this->filterDuration)->pluck('id');
|
|
|
$member_course = $member_course->whereIn('course_id', $course_ids);
|
|
|
}
|
|
|
@@ -177,61 +176,44 @@ class CourseList extends Component
|
|
|
|
|
|
$column = '';
|
|
|
$sort_value = 0;
|
|
|
- if ($this->sort != '')
|
|
|
- {
|
|
|
+ if ($this->sort != '') {
|
|
|
$f = $this->sort;
|
|
|
$d = $this->dir;
|
|
|
- if ($f >= 5 && $f <= 16)
|
|
|
- {
|
|
|
+ if ($f >= 5 && $f <= 16) {
|
|
|
$column = 'column_' . ($f - 2);
|
|
|
- if (session()->get('sort_column'))
|
|
|
- {
|
|
|
- if (session()->get('sort_column') != $f)
|
|
|
- {
|
|
|
+ if (session()->get('sort_column')) {
|
|
|
+ if (session()->get('sort_column') != $f) {
|
|
|
session()->put('sort_column', $f);
|
|
|
session()->put('sort_order', $d);
|
|
|
session()->put('sort_value', 0);
|
|
|
$sort_value = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (session()->get('sort_order') == $d)
|
|
|
- {
|
|
|
+ } else {
|
|
|
+ if (session()->get('sort_order') == $d) {
|
|
|
//session()->put('sort_value', 0);
|
|
|
$sort_value = session()->get('sort_value', 0);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (session()->get('sort_value', 0) == 0)
|
|
|
- {
|
|
|
+ } else {
|
|
|
+ if (session()->get('sort_value', 0) == 0) {
|
|
|
$sort_value = 1;
|
|
|
}
|
|
|
- if (session()->get('sort_value', 0) == 1)
|
|
|
- {
|
|
|
+ if (session()->get('sort_value', 0) == 1) {
|
|
|
$sort_value = 2;
|
|
|
}
|
|
|
- if (session()->get('sort_value', 0) == 2)
|
|
|
- {
|
|
|
+ if (session()->get('sort_value', 0) == 2) {
|
|
|
$sort_value = 3;
|
|
|
}
|
|
|
- if (session()->get('sort_value', 0) == 3)
|
|
|
- {
|
|
|
+ if (session()->get('sort_value', 0) == 3) {
|
|
|
$sort_value = 0;
|
|
|
}
|
|
|
session()->put('sort_value', $sort_value);
|
|
|
-
|
|
|
}
|
|
|
session()->put('sort_order', $d);
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
session()->put('sort_column', $f);
|
|
|
session()->put('sort_order', $d);
|
|
|
session()->put('sort_value', 0);
|
|
|
$sort_value = 0;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -241,29 +223,24 @@ class CourseList extends Component
|
|
|
$prices = [];
|
|
|
|
|
|
$member_course_totals = $member_course->get();
|
|
|
- foreach($member_course_totals as $x)
|
|
|
- {
|
|
|
+ foreach ($member_course_totals as $x) {
|
|
|
|
|
|
$price = 0;
|
|
|
$price = $x->price; // $x->course->price;
|
|
|
$subPrice = $x->subscription_price; // $x->course->subscription_price;
|
|
|
$records = \App\Models\Record::where('member_course_id', $x->id)->where('deleted', 0)->get();
|
|
|
$prices = [];
|
|
|
- foreach ($records as $record)
|
|
|
- {
|
|
|
- foreach ($record->rows as $row)
|
|
|
- {
|
|
|
+ foreach ($records as $record) {
|
|
|
+ foreach ($record->rows as $row) {
|
|
|
|
|
|
if ($row->causal_id == $x->course->sub_causal_id) // || str_contains(strtolower($row->note), 'iscrizione'))
|
|
|
//if (str_contains(strtolower($row->note), 'iscrizione'))
|
|
|
{
|
|
|
$subPrice = $row->amount;
|
|
|
}
|
|
|
- if ($row->causal_id == $x->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
|
|
|
- {
|
|
|
+ if ($row->causal_id == $x->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione')) {
|
|
|
$tot = sizeof(json_decode($row->when));
|
|
|
- foreach(json_decode($row->when) as $m)
|
|
|
- {
|
|
|
+ foreach (json_decode($row->when) as $m) {
|
|
|
if (isset($prices[$m->month]))
|
|
|
$prices[$m->month] += $row->amount / $tot;
|
|
|
else
|
|
|
@@ -273,30 +250,24 @@ class CourseList extends Component
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for($i=1; $i<=12; $i++)
|
|
|
- {
|
|
|
+ for ($i = 1; $i <= 12; $i++) {
|
|
|
|
|
|
$cls = $this->getColor($x->months, $i, isset($prices[$i]) && $prices[$i] == $price);
|
|
|
- if ($cls != 'wgrey')
|
|
|
- {
|
|
|
+ if ($cls != 'wgrey') {
|
|
|
|
|
|
- if (!isset($totals[$i]))
|
|
|
- {
|
|
|
+ if (!isset($totals[$i])) {
|
|
|
$totals[$i]['green'] = 0;
|
|
|
$totals[$i]['orange'] = 0;
|
|
|
$totals[$i]['yellow'] = 0;
|
|
|
}
|
|
|
- if ($cls == 'yellow')
|
|
|
- {
|
|
|
+ if ($cls == 'yellow') {
|
|
|
$totals[$i][$cls] += 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
$p = isset($prices[$i]) ? $prices[$i] : $price;
|
|
|
//if (isset($totals[$i][$cls]))
|
|
|
- $totals[$i][$cls] += $p;
|
|
|
+ $totals[$i][$cls] += $p;
|
|
|
//else
|
|
|
- //$totals[$i][$cls] = $p;
|
|
|
+ //$totals[$i][$cls] = $p;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -308,8 +279,7 @@ class CourseList extends Component
|
|
|
$totalIsc[$sub] = $subPrice;
|
|
|
|
|
|
$s = 0;
|
|
|
- if ($column != '')
|
|
|
- {
|
|
|
+ if ($column != '') {
|
|
|
$z = 0;
|
|
|
switch ($column) {
|
|
|
case 'column_3':
|
|
|
@@ -353,8 +323,7 @@ class CourseList extends Component
|
|
|
break;
|
|
|
}
|
|
|
$c = getColor($x->months, $z);
|
|
|
- if ($sort_value == 0)
|
|
|
- {
|
|
|
+ if ($sort_value == 0) {
|
|
|
switch ($c) {
|
|
|
case 'wgrey':
|
|
|
$s = 0;
|
|
|
@@ -373,8 +342,7 @@ class CourseList extends Component
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if ($sort_value == 1)
|
|
|
- {
|
|
|
+ if ($sort_value == 1) {
|
|
|
switch ($c) {
|
|
|
case 'wgrey':
|
|
|
$s = 3;
|
|
|
@@ -393,8 +361,7 @@ class CourseList extends Component
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if ($sort_value == 2)
|
|
|
- {
|
|
|
+ if ($sort_value == 2) {
|
|
|
switch ($c) {
|
|
|
case 'wgrey':
|
|
|
$s = 2;
|
|
|
@@ -413,8 +380,7 @@ class CourseList extends Component
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if ($sort_value == 3)
|
|
|
- {
|
|
|
+ if ($sort_value == 3) {
|
|
|
switch ($c) {
|
|
|
case 'wgrey':
|
|
|
$s = 1;
|
|
|
@@ -433,7 +399,6 @@ class CourseList extends Component
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
$datas[] = array(
|
|
|
@@ -459,7 +424,6 @@ class CourseList extends Component
|
|
|
"column_18" => $xxx++,
|
|
|
"column_20" => $s
|
|
|
);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
$count = $member_course->count();
|
|
|
@@ -470,20 +434,17 @@ class CourseList extends Component
|
|
|
//$js = '';
|
|
|
$xx = 4;
|
|
|
$str = '';
|
|
|
- if ($count > 0)
|
|
|
- {
|
|
|
+ if ($count > 0) {
|
|
|
$str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=green><small>" . (isset($totalIsc["Y"]) ? formatPrice($totalIsc["Y"]) : 0) . "</small></a><br>";
|
|
|
$str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=orange><small>" . (isset($totalIsc["N"]) ? formatPrice($totalIsc["N"]) : 0) . "</small></a><br>";
|
|
|
$str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=yellow><small>0</small></a><br>";
|
|
|
|
|
|
$this->totSExcel[] = array('green' => (isset($totalIsc["Y"]) ? formatPrice($totalIsc["Y"]) : 0), 'orange' => (isset($totalIsc["N"]) ? formatPrice($totalIsc["N"]) : 0), 'yellow' => 0);
|
|
|
-
|
|
|
}
|
|
|
$this->totS[] = $str;
|
|
|
|
|
|
$str = "";
|
|
|
- foreach($totals as $z => $t)
|
|
|
- {
|
|
|
+ foreach ($totals as $z => $t) {
|
|
|
if ($z == 1) $xx = 5;
|
|
|
if ($z == 2) $xx = 6;
|
|
|
if ($z == 3) $xx = 7;
|
|
|
@@ -498,8 +459,7 @@ class CourseList extends Component
|
|
|
if ($z == 12) $xx = 4;
|
|
|
$str = '';
|
|
|
$aaa = [];
|
|
|
- foreach($t as $x => $c)
|
|
|
- {
|
|
|
+ foreach ($t as $x => $c) {
|
|
|
$y = $x == 'yellow' ? $c : formatPrice($c);
|
|
|
$str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=" . $x . "><small>" . $y . "</small></a><br>";
|
|
|
$aaa[$x] = $y;
|
|
|
@@ -512,24 +472,21 @@ class CourseList extends Component
|
|
|
$xx += 1;
|
|
|
}
|
|
|
|
|
|
- for($e=sizeof($this->totS);$e<=12;$e++)
|
|
|
- {
|
|
|
+ for ($e = sizeof($this->totS); $e <= 12; $e++) {
|
|
|
$this->totS[] = '';
|
|
|
}
|
|
|
|
|
|
- if ($this->sort != '')
|
|
|
- {
|
|
|
+ if ($this->sort != '') {
|
|
|
$s = $this->sort;
|
|
|
if ($s == 1) $s = 21;
|
|
|
if ($column != '')
|
|
|
- array_multisort(array_column($datas, 'column_20'), SORT_ASC, SORT_NATURAL|SORT_FLAG_CASE, $datas);
|
|
|
+ array_multisort(array_column($datas, 'column_20'), SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE, $datas);
|
|
|
else
|
|
|
- array_multisort(array_column($datas, 'column_' . ($s - 2)), $this->dir == "ASC" ? SORT_ASC : SORT_DESC, SORT_NATURAL|SORT_FLAG_CASE, $datas);
|
|
|
+ array_multisort(array_column($datas, 'column_' . ($s - 2)), $this->dir == "ASC" ? SORT_ASC : SORT_DESC, SORT_NATURAL | SORT_FLAG_CASE, $datas);
|
|
|
}
|
|
|
|
|
|
$xxx = 1;
|
|
|
- foreach($datas as $yyy => $d)
|
|
|
- {
|
|
|
+ foreach ($datas as $yyy => $d) {
|
|
|
$datas[$yyy]["column_18"] = $xxx++;
|
|
|
}
|
|
|
|
|
|
@@ -549,7 +506,6 @@ class CourseList extends Component
|
|
|
//$this->totS = $js;
|
|
|
|
|
|
return view('livewire.course_list');
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function setPage($page)
|
|
|
@@ -580,24 +536,18 @@ class CourseList extends Component
|
|
|
public function getColor($months, $m, $all)
|
|
|
{
|
|
|
$class = "wgrey";
|
|
|
- foreach(json_decode($months) as $mm)
|
|
|
- {
|
|
|
- if ($mm->m == $m)
|
|
|
- {
|
|
|
- if ($mm->status == "")
|
|
|
- {
|
|
|
+ foreach (json_decode($months) as $mm) {
|
|
|
+ if ($mm->m == $m) {
|
|
|
+ if ($mm->status == "") {
|
|
|
$class = "orange";
|
|
|
}
|
|
|
- if ($mm->status == "1")
|
|
|
- {
|
|
|
+ if ($mm->status == "1") {
|
|
|
$class = "green";
|
|
|
}
|
|
|
- if ($mm->status == "2")
|
|
|
- {
|
|
|
+ if ($mm->status == "2") {
|
|
|
$class = "yellow";
|
|
|
}
|
|
|
- if (!$all && $class == "green")
|
|
|
- {
|
|
|
+ if (!$all && $class == "green") {
|
|
|
$class = "orange";
|
|
|
}
|
|
|
}
|
|
|
@@ -609,11 +559,9 @@ class CourseList extends Component
|
|
|
{
|
|
|
|
|
|
$newMonths = array();
|
|
|
- if ($months != '')
|
|
|
- {
|
|
|
+ if ($months != '') {
|
|
|
$mm = explode(",", $months);
|
|
|
- foreach($mm as $month)
|
|
|
- {
|
|
|
+ foreach ($mm as $month) {
|
|
|
if ($month < 5) $month += 12;
|
|
|
if ($month >= 5) $month -= 4;
|
|
|
$newMonths[] = $month;
|
|
|
@@ -627,21 +575,16 @@ class CourseList extends Component
|
|
|
$subscription_price = $m->subscription_price;
|
|
|
|
|
|
$records = \App\Models\Record::where('member_course_id', $m->id)->where('deleted', 0)->get();
|
|
|
- foreach ($records as $record)
|
|
|
- {
|
|
|
+ foreach ($records as $record) {
|
|
|
|
|
|
- if (in_array($month, json_decode($record->months)))
|
|
|
- {
|
|
|
+ if (in_array($month, json_decode($record->months))) {
|
|
|
|
|
|
- foreach ($record->rows as $row)
|
|
|
- {
|
|
|
+ foreach ($record->rows as $row) {
|
|
|
|
|
|
-
|
|
|
- if ($row->causal_id == $c->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
|
|
|
- {
|
|
|
+
|
|
|
+ if ($row->causal_id == $c->causal_id && !str_contains(strtolower($row->note), 'iscrizione')) {
|
|
|
$tot = sizeof(json_decode($row->when));
|
|
|
- foreach(json_decode($row->when) as $m)
|
|
|
- {
|
|
|
+ foreach (json_decode($row->when) as $m) {
|
|
|
$price -= $row->amount / $tot;
|
|
|
}
|
|
|
}
|
|
|
@@ -650,7 +593,6 @@ class CourseList extends Component
|
|
|
}
|
|
|
|
|
|
return redirect()->to('/in?new=1&memberId=' . $member_id . (sizeof($newMonths) > 0 ? '&causalId=' . $c->causal_id : '') . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=' . ($subscription ? 1 : 0) . (sizeof($newMonths) > 0 ? '&months=' . implode("|", $newMonths) : '') . (sizeof($newMonths) > 0 ? ('&price=' . $price) : '') . '&subscription_price=' . $subscription_price . "&courseId=" . $id);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function suspendPayment($course_id, $month, $member_id, $id, $subscription)
|
|
|
@@ -743,7 +685,7 @@ class CourseList extends Component
|
|
|
}
|
|
|
|
|
|
$monthsData = json_decode($memberCourse->months, true);
|
|
|
- Log::info('data mese',$monthsData);
|
|
|
+ Log::info('data mese', $monthsData);
|
|
|
if (!is_array($monthsData)) {
|
|
|
return response()->json(['error' => 'Invalid months data format'], 400);
|
|
|
}
|
|
|
@@ -777,7 +719,6 @@ class CourseList extends Component
|
|
|
{
|
|
|
$c = \App\Models\Course::findOrFail($course_id);
|
|
|
return redirect()->to('/in?new=1&memberId=' . $member_id . '&causalId=' . $c->causal_id . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=1&price=0.00&subscription_price=' . $c->subscription_price . "&courseId=" . $id);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function disableSearch()
|
|
|
@@ -788,7 +729,6 @@ class CourseList extends Component
|
|
|
$this->filterDuration = [];
|
|
|
$this->filterFrequency = [];
|
|
|
$this->hasFilter = false;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function export()
|
|
|
@@ -817,8 +757,7 @@ class CourseList extends Component
|
|
|
$activeWorksheet->setCellValue('P1', "Agosto");
|
|
|
|
|
|
$count = 2;
|
|
|
- foreach($this->recordsNoPaginate as $idx => $record)
|
|
|
- {
|
|
|
+ foreach ($this->recordsNoPaginate as $idx => $record) {
|
|
|
|
|
|
$activeWorksheet->setCellValue('A' . $count, $record["column_19"]);
|
|
|
$activeWorksheet->setCellValue('B' . $count, $record["column_0"]);
|
|
|
@@ -826,9 +765,9 @@ class CourseList extends Component
|
|
|
list($color, $value) = explode("§", $record["column_2"]);
|
|
|
$activeWorksheet->setCellValue('D' . $count, $value);
|
|
|
$c = '#FFFFFF';
|
|
|
- if($color == 0)
|
|
|
+ if ($color == 0)
|
|
|
$c = 'ffa500';
|
|
|
- if($color == 1)
|
|
|
+ if ($color == 1)
|
|
|
$c = '00ff00';
|
|
|
|
|
|
$activeWorksheet->getStyle('D' . $count . ':D' . $count)
|
|
|
@@ -837,21 +776,19 @@ class CourseList extends Component
|
|
|
->getStartColor()
|
|
|
->setARGB($c);
|
|
|
|
|
|
- for($ii=3; $ii<=14; $ii++)
|
|
|
- {
|
|
|
+ for ($ii = 3; $ii <= 14; $ii++) {
|
|
|
list($color, $value) = explode("§", $record["column_" . $ii]);
|
|
|
$c = 'FFFFFF';
|
|
|
- if($color == 'orange')
|
|
|
+ if ($color == 'orange')
|
|
|
$c = 'ffa500';
|
|
|
- if($color == 'green')
|
|
|
+ if ($color == 'green')
|
|
|
$c = '00ff00';
|
|
|
- if($color == 'yellow')
|
|
|
- {
|
|
|
+ if ($color == 'yellow') {
|
|
|
$c = '5088bf';
|
|
|
$activeWorksheet->getStyle($letters[$ii + 1] . $count . ':' . $letters[$ii + 1] . $count)
|
|
|
- ->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);;
|
|
|
+ ->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);;
|
|
|
}
|
|
|
- if($color == 'wgrey')
|
|
|
+ if ($color == 'wgrey')
|
|
|
$value = '';
|
|
|
|
|
|
$activeWorksheet->setCellValue($letters[$ii + 1] . $count, $value);
|
|
|
@@ -868,7 +805,7 @@ class CourseList extends Component
|
|
|
});*/
|
|
|
}
|
|
|
|
|
|
- $activeWorksheet->getStyle("A1:P1")->getFont()->setBold( true );
|
|
|
+ $activeWorksheet->getStyle("A1:P1")->getFont()->setBold(true);
|
|
|
|
|
|
$count++;
|
|
|
}
|
|
|
@@ -877,44 +814,101 @@ class CourseList extends Component
|
|
|
$activeWorksheet->setCellValue('A' . (1 + $count), '');
|
|
|
$activeWorksheet->setCellValue('B' . (1 + $count), '');
|
|
|
$activeWorksheet->setCellValue('C' . (1 + $count), '');
|
|
|
- for($x=0; $x<=sizeof($this->totSExcel); $x++)
|
|
|
- {
|
|
|
+ for ($x = 0; $x <= sizeof($this->totSExcel); $x++) {
|
|
|
|
|
|
- if (isset($this->totSExcel[$x]))
|
|
|
- {
|
|
|
+ if (isset($this->totSExcel[$x])) {
|
|
|
|
|
|
$activeWorksheet->setCellValue($letters[$x + 3] . (1 + $count), isset($this->totSExcel[$x]['green']) ? $this->totSExcel[$x]['green'] : 0);
|
|
|
$activeWorksheet->getStyle($letters[$x + 3] . (1 + $count) . ':' . $letters[$x + 3] . (1 + $count))
|
|
|
- ->getFill()
|
|
|
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
|
|
- ->getStartColor()
|
|
|
- ->setARGB('00ff00');
|
|
|
+ ->getFill()
|
|
|
+ ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
|
|
+ ->getStartColor()
|
|
|
+ ->setARGB('00ff00');
|
|
|
|
|
|
$activeWorksheet->setCellValue($letters[$x + 3] . (2 + $count), isset($this->totSExcel[$x]['orange']) ? $this->totSExcel[$x]['orange'] : 0);
|
|
|
$activeWorksheet->getStyle($letters[$x + 3] . (2 + $count) . ':' . $letters[$x + 3] . (2 + $count))
|
|
|
- ->getFill()
|
|
|
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
|
|
- ->getStartColor()
|
|
|
- ->setARGB('ffa500');
|
|
|
+ ->getFill()
|
|
|
+ ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
|
|
+ ->getStartColor()
|
|
|
+ ->setARGB('ffa500');
|
|
|
|
|
|
$activeWorksheet->setCellValue($letters[$x + 3] . (3 + $count), isset($this->totSExcel[$x]['yellow']) ? $this->totSExcel[$x]['yellow'] : 0);
|
|
|
$activeWorksheet->getStyle($letters[$x + 3] . (3 + $count) . ':' . $letters[$x + 3] . (3 + $count))
|
|
|
- ->getFill()
|
|
|
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
|
|
- ->getStartColor()
|
|
|
- ->setARGB('5088bf');
|
|
|
+ ->getFill()
|
|
|
+ ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
|
|
+ ->getStartColor()
|
|
|
+ ->setARGB('5088bf');
|
|
|
$activeWorksheet->getStyle($letters[$x + 3] . (3 + $count) . ':' . $letters[$x + 3] . (3 + $count))
|
|
|
- ->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);;
|
|
|
+ ->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- $writer = new Xlsx($spreadsheet);
|
|
|
- $writer->save($path = storage_path('pagamento_corsi_' . date("YmdHis") . '.xlsx'));
|
|
|
+ try {
|
|
|
+ $currentClient = session('currentClient', 'default');
|
|
|
|
|
|
- $this->emit('load-data-table');
|
|
|
+ $filename = 'pagamento_corsi_' . date("YmdHis") . '.xlsx';
|
|
|
+
|
|
|
+ $tempPath = sys_get_temp_dir() . '/' . $filename;
|
|
|
+
|
|
|
+ $writer = new Xlsx($spreadsheet);
|
|
|
+ $writer->save($tempPath);
|
|
|
+
|
|
|
+ $disk = Storage::disk('s3');
|
|
|
+
|
|
|
+ $s3Path = $currentClient . '/exports/' . $filename;
|
|
|
+
|
|
|
+ $exportFolderPath = $currentClient . '/exports/.gitkeep';
|
|
|
+ if (!$disk->exists($exportFolderPath)) {
|
|
|
+ $disk->put($exportFolderPath, '');
|
|
|
+ Log::info("Created exports folder for client: {$currentClient}");
|
|
|
+ }
|
|
|
+
|
|
|
+ $fileContent = file_get_contents($tempPath);
|
|
|
+ $uploaded = $disk->put($s3Path, $fileContent, 'private');
|
|
|
+
|
|
|
+ if (!$uploaded) {
|
|
|
+ throw new \Exception('Failed to upload file to Wasabi S3');
|
|
|
+ }
|
|
|
+
|
|
|
+ Log::info("Excel file uploaded to Wasabi", [
|
|
|
+ 'client' => $currentClient,
|
|
|
+ 'path' => $s3Path,
|
|
|
+ 'size' => filesize($tempPath)
|
|
|
+ ]);
|
|
|
|
|
|
- return response()->download($path)->deleteFileAfterSend();
|
|
|
+ $downloadUrl = $disk->temporaryUrl($s3Path, now()->addHour());
|
|
|
|
|
|
+ if (file_exists($tempPath)) {
|
|
|
+ unlink($tempPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->emit('load-data-table');
|
|
|
+
|
|
|
+ return redirect($downloadUrl);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::error('Error exporting to Wasabi S3', [
|
|
|
+ 'error' => $e->getMessage(),
|
|
|
+ 'client' => session('currentClient', 'unknown')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $currentClient = session('currentClient', 'default');
|
|
|
+ $clientFolder = storage_path('app/exports/' . $currentClient);
|
|
|
+
|
|
|
+ if (!is_dir($clientFolder)) {
|
|
|
+ mkdir($clientFolder, 0755, true);
|
|
|
+ Log::info("Created local client folder: {$clientFolder}");
|
|
|
+ }
|
|
|
+
|
|
|
+ $localPath = $clientFolder . '/pagamento_corsi_' . date("YmdHis") . '.xlsx';
|
|
|
+ $writer = new Xlsx($spreadsheet);
|
|
|
+ $writer->save($localPath);
|
|
|
+
|
|
|
+ $this->emit('load-data-table');
|
|
|
+
|
|
|
+ // Show error message to user
|
|
|
+ session()->flash('warning', 'File saved locally due to cloud storage error.');
|
|
|
+
|
|
|
+ return response()->download($localPath)->deleteFileAfterSend();
|
|
|
+ }
|
|
|
}
|
|
|
}
|