|
|
@@ -22,6 +22,8 @@ class Record extends Component
|
|
|
public $in;
|
|
|
public $out;
|
|
|
public $payments = [];
|
|
|
+ public $origins = [];
|
|
|
+ public $destinations = [];
|
|
|
public $fromDate;
|
|
|
public $toDate;
|
|
|
public $appliedFromDate;
|
|
|
@@ -31,6 +33,9 @@ class Record extends Component
|
|
|
public $isExporting = false;
|
|
|
public $selectedPeriod = 'OGGI';
|
|
|
public $filterCausals = null;
|
|
|
+ public $filterPaymentMethods = null;
|
|
|
+ public $filterOrigins = null;
|
|
|
+ public $filterDestinations = null;
|
|
|
public $filterMember = null;
|
|
|
public $isFiltering = false;
|
|
|
public array $recordDatas = [];
|
|
|
@@ -50,6 +55,8 @@ class Record extends Component
|
|
|
'exportEmailAddress' => 'required_if:sendViaEmail,true|email',
|
|
|
'exportEmailSubject' => 'required_if:sendViaEmail,true|string|max:255',
|
|
|
];
|
|
|
+ public $total_in = 0;
|
|
|
+ public $total_out = 0;
|
|
|
|
|
|
protected $messages = [
|
|
|
'exportEmailAddress.required_if' => 'L\'indirizzo email è obbligatorio quando si sceglie di inviare via email.',
|
|
|
@@ -83,9 +90,19 @@ class Record extends Component
|
|
|
|
|
|
$this->getCausals(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->get(), 0);
|
|
|
|
|
|
- $this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])->orderBy('last_name')->orderBy('first_name')->get();
|
|
|
+ $this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])
|
|
|
+ ->where(function ($query) {
|
|
|
+ $query->where('is_archived', false)
|
|
|
+ ->orWhereNull('is_archived');
|
|
|
+ })
|
|
|
+ ->where(function ($query) {
|
|
|
+ $query->where('is_deleted', false)
|
|
|
+ ->orWhereNull('is_deleted');
|
|
|
+ })->orderBy('last_name')->orderBy('first_name')->get();
|
|
|
|
|
|
- $this->payments = \App\Models\PaymentMethod::select('id', 'name', 'type')->where('enabled', true)->where('money', false)->get();
|
|
|
+ $this->payments = \App\Models\PaymentMethod::select('id', 'name', 'type')->where('enabled', true)->where('money', false)->orderBy('name', 'asc')->get();
|
|
|
+ $this->origins = \App\Models\Bank::select('id', 'name')->where('enabled', true)->whereIn('visibility', ['OUT', 'ALL'])->orderBy('name', 'asc')->get();
|
|
|
+ $this->destinations = \App\Models\Bank::select('id', 'name')->where('enabled', true)->whereIn('visibility', ['IN', 'ALL'])->orderBy('name', 'asc')->get();
|
|
|
|
|
|
$this->selectedMonth = date('Y-m');
|
|
|
$this->selectedDay = date('Y-m-d');
|
|
|
@@ -158,6 +175,21 @@ class Record extends Component
|
|
|
Log::info('generateExportDataAndTotals: Causal filters applied', ['causal_count' => count($causals)]);
|
|
|
}
|
|
|
|
|
|
+ if ($this->filterPaymentMethods != null && sizeof($this->filterPaymentMethods) > 0) {
|
|
|
+ $datas->whereIn('payment_method_id', $this->filterPaymentMethods);
|
|
|
+ Log::info('generateExportDataAndTotals: Payment method filters applied', ['payment_method_count' => count($this->filterPaymentMethods)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->filterOrigins != null && sizeof($this->filterOrigins) > 0) {
|
|
|
+ $datas->whereIn('origin_id', $this->filterOrigins);
|
|
|
+ Log::info('generateExportDataAndTotals: Origin filters applied', ['origins_count' => count($this->filterOrigins)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->filterDestinations != null && sizeof($this->filterDestinations) > 0) {
|
|
|
+ $datas->whereIn('destination_id', $this->filterDestinations);
|
|
|
+ Log::info('generateExportDataAndTotals: Destination filters applied', ['destinations_count' => count($this->filterDestinations)]);
|
|
|
+ }
|
|
|
+
|
|
|
if ($this->filterMember != null && $this->filterMember > 0) {
|
|
|
$datas->where('member_id', $this->filterMember);
|
|
|
Log::info('generateExportDataAndTotals: Member filter applied', ['member_id' => $this->filterMember]);
|
|
|
@@ -306,7 +338,6 @@ class Record extends Component
|
|
|
|
|
|
if (!$group['deleted'])
|
|
|
$exportTotals[$group['payment_method']][$group['transaction_type']] += $group['amount'];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
$finalTime = microtime(true) - $finalStart;
|
|
|
@@ -382,6 +413,15 @@ class Record extends Component
|
|
|
}
|
|
|
$datas->whereIn('causal_id', $causals);
|
|
|
}
|
|
|
+ if ($this->filterPaymentMethods != null && sizeof($this->filterPaymentMethods) > 0) {
|
|
|
+ $datas->whereIn('payment_method_id', $this->filterPaymentMethods);
|
|
|
+ }
|
|
|
+ if ($this->filterOrigins != null && sizeof($this->filterOrigins) > 0) {
|
|
|
+ $datas->whereIn('origin_id', $this->filterOrigins);
|
|
|
+ }
|
|
|
+ if ($this->filterDestinations != null && sizeof($this->filterDestinations) > 0) {
|
|
|
+ $datas->whereIn('destination_id', $this->filterDestinations);
|
|
|
+ }
|
|
|
if ($this->filterMember != null && $this->filterMember > 0) {
|
|
|
$datas->where('member_id', $this->filterMember);
|
|
|
}
|
|
|
@@ -423,6 +463,9 @@ class Record extends Component
|
|
|
$this->showMonthPicker = false;
|
|
|
$this->showDayPicker = false;
|
|
|
$this->filterCausals = [];
|
|
|
+ $this->filterPaymentMethods = [];
|
|
|
+ $this->filterOrigins = [];
|
|
|
+ $this->filterDestinations = [];
|
|
|
$this->filterMember = null;
|
|
|
|
|
|
$today = date("Y-m-d");
|
|
|
@@ -621,6 +664,15 @@ class Record extends Component
|
|
|
}
|
|
|
$datas->whereIn('causal_id', $causals);
|
|
|
}
|
|
|
+ if ($this->filterPaymentMethods != null && sizeof($this->filterPaymentMethods) > 0) {
|
|
|
+ $datas->whereIn('payment_method_id', $this->filterPaymentMethods);
|
|
|
+ }
|
|
|
+ if ($this->filterOrigins != null && sizeof($this->filterOrigins) > 0) {
|
|
|
+ $datas->whereIn('origin_id', $this->filterOrigins);
|
|
|
+ }
|
|
|
+ if ($this->filterDestinations != null && sizeof($this->filterDestinations) > 0) {
|
|
|
+ $datas->whereIn('destination_id', $this->filterDestinations);
|
|
|
+ }
|
|
|
if ($this->filterMember != null && $this->filterMember > 0) {
|
|
|
$datas->where('member_id', $this->filterMember);
|
|
|
}
|
|
|
@@ -629,14 +681,30 @@ class Record extends Component
|
|
|
->orderBy('records_rows.id', 'ASC')
|
|
|
->get();
|
|
|
|
|
|
- foreach($datas as $data)
|
|
|
- {
|
|
|
+ $ret = array();
|
|
|
+
|
|
|
+ $this->total_in = 0;
|
|
|
+ $this->total_out = 0;
|
|
|
+
|
|
|
+ foreach ($datas as $data) {
|
|
|
$causal = \App\Models\Causal::findOrFail($data->causal_id);
|
|
|
- $data->causal_name = $causal->getTree();
|
|
|
+ $paymentCheck = $data->payment_method->money;
|
|
|
+ if (!$paymentCheck && ($causal->no_first == null || !$causal->no_first)) {
|
|
|
+ $data->causal_name = $causal->getTree();
|
|
|
+ $ret[] = $data;
|
|
|
+
|
|
|
+ if ($data->type == 'IN')
|
|
|
+ $this->total_in += $data->amount;
|
|
|
+ if ($data->type == 'OUT')
|
|
|
+ $this->total_out += $data->amount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->total_in > 0 || $this->total_out > 0) {
|
|
|
+ $ret[] = (object) array("date" => "", "total_in" => $this->total_in, "total_out" => $this->total_out);
|
|
|
}
|
|
|
-
|
|
|
- return $datas;
|
|
|
|
|
|
+ return $ret;
|
|
|
}
|
|
|
|
|
|
public function render()
|
|
|
@@ -946,10 +1014,10 @@ class Record extends Component
|
|
|
Log::info('Export: Starting COMBINED data generation phase (NO SEPARATE CALLS)');
|
|
|
$startTime = microtime(true);
|
|
|
|
|
|
- $records = $this->loadData($this->exportFromDate, $this->exportToDate);
|
|
|
-
|
|
|
+ $records = $this->loadData($this->exportFromDate, $this->exportToDate);
|
|
|
+
|
|
|
$dataGenTime = microtime(true) - $startTime;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
if ($this->sendViaEmail) {
|
|
|
@@ -1038,6 +1106,16 @@ class Record extends Component
|
|
|
$query->whereIn('causal_id', $causals);
|
|
|
}
|
|
|
|
|
|
+ if ($this->filterPaymentMethods != null && sizeof($this->filterPaymentMethods) > 0) {
|
|
|
+ $query->whereIn('payment_method_id', $this->filterPaymentMethods);
|
|
|
+ }
|
|
|
+ if ($this->filterOrigins != null && sizeof($this->filterOrigins) > 0) {
|
|
|
+ $query->whereIn('origin_id', $this->filterOrigins);
|
|
|
+ }
|
|
|
+ if ($this->filterDestinations != null && sizeof($this->filterDestinations) > 0) {
|
|
|
+ $query->whereIn('destination_id', $this->filterDestinations);
|
|
|
+ }
|
|
|
+
|
|
|
if ($this->filterMember != null && $this->filterMember > 0) {
|
|
|
$query->where('member_id', $this->filterMember);
|
|
|
}
|
|
|
@@ -1061,6 +1139,36 @@ class Record extends Component
|
|
|
return implode(', ', $causals);
|
|
|
}
|
|
|
|
|
|
+ private function getPaymentMethodsNames($paymentMethodIds)
|
|
|
+ {
|
|
|
+ if (!is_array($paymentMethodIds)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ $payment_methods = \App\Models\PaymentMethod::whereIn('id', $paymentMethodIds)->pluck('name')->toArray();
|
|
|
+ return implode(', ', $payment_methods);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getOriginsNames($originIds)
|
|
|
+ {
|
|
|
+ if (!is_array($originIds)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ $origins = \App\Models\Bank::whereIn('id', $originIds)->pluck('name')->toArray();
|
|
|
+ return implode(', ', $origins);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getDestinationsNames($destinationIds)
|
|
|
+ {
|
|
|
+ if (!is_array($destinationIds)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ $destinations = \App\Models\Bank::whereIn('id', $destinationIds)->pluck('name')->toArray();
|
|
|
+ return implode(', ', $destinations);
|
|
|
+ }
|
|
|
+
|
|
|
public function updatedExportFromDate()
|
|
|
{
|
|
|
$this->updateEmailSubject();
|
|
|
@@ -1111,6 +1219,9 @@ class Record extends Component
|
|
|
$filterDescriptions = [
|
|
|
'member' => $this->filterMember ? $this->getMemberName($this->filterMember) : null,
|
|
|
'causals' => $this->filterCausals ? $this->getCausalsNames($this->filterCausals) : null,
|
|
|
+ 'payment_methods' => $this->filterPaymentMethods ? $this->getPaymentMethodsNames($this->filterPaymentMethods) : null,
|
|
|
+ 'origins' => $this->filterOrigins ? $this->getOriginsNames($this->filterOrigins) : null,
|
|
|
+ 'destinations' => $this->filterDestinations ? $this->getDestinationsNames($this->filterDestinations) : null,
|
|
|
];
|
|
|
|
|
|
$paymentsArray = $this->payments->map(function ($payment) {
|
|
|
@@ -1562,7 +1673,13 @@ class Record extends Component
|
|
|
return $email;
|
|
|
}
|
|
|
|
|
|
- public function updatedSelectedDay($value)
|
|
|
+ public function updatedSelectedPeriod($value)
|
|
|
+ {
|
|
|
+ $this->setPeriodDates();
|
|
|
+ $this->applyFilters();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function updatedSelectedDay($value)
|
|
|
{
|
|
|
if (!empty($value)) {
|
|
|
$this->selectedPeriod = 'GIORNO_PERSONALIZZATO';
|
|
|
@@ -1623,7 +1740,6 @@ class Record extends Component
|
|
|
|
|
|
private function exportExcel($records)
|
|
|
{
|
|
|
-
|
|
|
$startTime = microtime(true);
|
|
|
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
@@ -1647,18 +1763,30 @@ class Record extends Component
|
|
|
$activeWorksheet->getStyle('A1:J1')->getFont()->getColor()->setARGB('FFFFFFFF');
|
|
|
|
|
|
$idx = 2;
|
|
|
- foreach($records as $record)
|
|
|
- {
|
|
|
- $activeWorksheet->setCellValue('A' . $idx, date("d/m/Y", strtotime($record->date)));
|
|
|
- $activeWorksheet->setCellValue('B' . $idx, $record->commercial ? 'Commerciale' : 'Non commerciale');
|
|
|
- $activeWorksheet->setCellValue('C' . $idx, $record->causal_name);
|
|
|
- $activeWorksheet->setCellValue('D' . $idx, $record->type == 'IN' ? ($record->member->first_name . " " . $record->member->last_name) : @$record->supplier->name);
|
|
|
- $activeWorksheet->setCellValue('E' . $idx, $record->deleted ? 'Annullata' : '');
|
|
|
- $activeWorksheet->setCellValue('F' . $idx, $record->type == 'IN' ? formatPrice($record->amount) : '');
|
|
|
- $activeWorksheet->setCellValue('G' . $idx, $record->type == 'OUT' ? formatPrice($record->amount) : '');
|
|
|
- $activeWorksheet->setCellValue('H' . $idx, $record->type == 'OUT' ? $record->origin : '');
|
|
|
- $activeWorksheet->setCellValue('I' . $idx, $record->type == 'IN' ? $record->destination : '');
|
|
|
- $activeWorksheet->setCellValue('J' . $idx, $record->payment_method->name);
|
|
|
+ foreach ($records as $record) {
|
|
|
+ if ($record->date != '') {
|
|
|
+ $activeWorksheet->setCellValue('A' . $idx, date("d/m/Y", strtotime($record->date)));
|
|
|
+ $activeWorksheet->setCellValue('B' . $idx, $record->commercial ? 'Commerciale' : 'Non commerciale');
|
|
|
+ $activeWorksheet->setCellValue('C' . $idx, $record->causal_name);
|
|
|
+ $activeWorksheet->setCellValue('D' . $idx, $record->type == 'IN' ? ($record->member->first_name . " " . $record->member->last_name) : @$record->supplier->name);
|
|
|
+ $activeWorksheet->setCellValue('E' . $idx, $record->deleted ? 'Annullata' : '');
|
|
|
+ $activeWorksheet->setCellValue('F' . $idx, $record->type == 'IN' ? formatPrice($record->amount) : '');
|
|
|
+ $activeWorksheet->setCellValue('G' . $idx, $record->type == 'OUT' ? formatPrice($record->amount) : '');
|
|
|
+ $activeWorksheet->setCellValue('H' . $idx, $record->type == 'OUT' ? $record->origin : '');
|
|
|
+ $activeWorksheet->setCellValue('I' . $idx, $record->type == 'IN' ? $record->destination : '');
|
|
|
+ $activeWorksheet->setCellValue('J' . $idx, $record->payment_method->name);
|
|
|
+ } else {
|
|
|
+ $activeWorksheet->setCellValue('A' . $idx, "Totali");
|
|
|
+ $activeWorksheet->setCellValue('B' . $idx, "");
|
|
|
+ $activeWorksheet->setCellValue('C' . $idx, "");
|
|
|
+ $activeWorksheet->setCellValue('D' . $idx, "");
|
|
|
+ $activeWorksheet->setCellValue('E' . $idx, "");
|
|
|
+ $activeWorksheet->setCellValue('F' . $idx, formatPrice($record->total_in));
|
|
|
+ $activeWorksheet->setCellValue('G' . $idx, formatPrice($record->total_out));
|
|
|
+ $activeWorksheet->setCellValue('H' . $idx, "");
|
|
|
+ $activeWorksheet->setCellValue('I' . $idx, "");
|
|
|
+ $activeWorksheet->setCellValue('J' . $idx, "");
|
|
|
+ }
|
|
|
$idx++;
|
|
|
}
|
|
|
|
|
|
@@ -1673,6 +1801,8 @@ class Record extends Component
|
|
|
$activeWorksheet->getColumnDimension('I')->setWidth(20);
|
|
|
$activeWorksheet->getColumnDimension('J')->setWidth(30);
|
|
|
|
|
|
+ $activeWorksheet->getStyle('A' . ($idx - 1) . ':J' . ($idx - 1))->getFont()->setBold(true);
|
|
|
+
|
|
|
$filename = 'prima_nota_' . date("YmdHis") . '.xlsx';
|
|
|
Log::info('exportWithData: Preparing to save file', [
|
|
|
'filename' => $filename,
|
|
|
@@ -1687,7 +1817,7 @@ class Record extends Component
|
|
|
$writer = new Xlsx($spreadsheet);
|
|
|
|
|
|
$writer->save($tempPath);
|
|
|
-
|
|
|
+
|
|
|
unset($spreadsheet, $activeWorksheet, $writer);
|
|
|
gc_collect_cycles();
|
|
|
|
|
|
@@ -1766,5 +1896,4 @@ class Record extends Component
|
|
|
return response()->download($localPath)->deleteFileAfterSend();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|