|
@@ -133,8 +133,8 @@ class Record extends Component
|
|
|
}
|
|
}
|
|
|
*/
|
|
*/
|
|
|
$datas = \App\Models\Record::with('member', 'supplier', 'payment_method')
|
|
$datas = \App\Models\Record::with('member', 'supplier', 'payment_method')
|
|
|
|
|
+ ->select('records.*', 'records_rows.*') // Ensure all columns are selected
|
|
|
->join('records_rows', 'records.id', '=', 'records_rows.record_id')
|
|
->join('records_rows', 'records.id', '=', 'records_rows.record_id')
|
|
|
- //->where('records_rows.when', 'like', '%' . date("m-Y") . '%')
|
|
|
|
|
->whereBetween('date', [$this->fromDate, $this->toDate])
|
|
->whereBetween('date', [$this->fromDate, $this->toDate])
|
|
|
->where(function ($query) {
|
|
->where(function ($query) {
|
|
|
$query->where('type', 'OUT')
|
|
$query->where('type', 'OUT')
|
|
@@ -151,7 +151,8 @@ class Record extends Component
|
|
|
->orWhere(function ($subquery) use ($exclude_from_records) {
|
|
->orWhere(function ($subquery) use ($exclude_from_records) {
|
|
|
$subquery->whereNotIn('member_id', $exclude_from_records);
|
|
$subquery->whereNotIn('member_id', $exclude_from_records);
|
|
|
});
|
|
});
|
|
|
- }); if ($this->filterCausals != null && sizeof($this->filterCausals) > 0)
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ if ($this->filterCausals != null && sizeof($this->filterCausals) > 0)
|
|
|
{
|
|
{
|
|
|
$causals = array();
|
|
$causals = array();
|
|
|
foreach($this->filterCausals as $z)
|
|
foreach($this->filterCausals as $z)
|
|
@@ -175,7 +176,9 @@ class Record extends Component
|
|
|
{
|
|
{
|
|
|
$datas->where('member_id', $this->filterMember);
|
|
$datas->where('member_id', $this->filterMember);
|
|
|
}
|
|
}
|
|
|
- $datas = $datas->orderBy('date', 'ASC')->orderBy('records.created_at', 'ASC')
|
|
|
|
|
|
|
+ $datas = $datas->orderBy('date', 'ASC')
|
|
|
|
|
+ ->orderBy('records.created_at', 'ASC')
|
|
|
|
|
+ ->orderBy('records_rows.id', 'ASC') // Important to maintain row order
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
foreach($datas as $idx => $data)
|
|
foreach($datas as $idx => $data)
|
|
@@ -211,31 +214,27 @@ class Record extends Component
|
|
|
|
|
|
|
|
// aggiungere il nome * * *
|
|
// aggiungere il nome * * *
|
|
|
//$causal = $prefix . $data->date . "§" . $causalCheck->getTree();
|
|
//$causal = $prefix . $data->date . "§" . $causalCheck->getTree();
|
|
|
- $causal = $prefix . $data->date . "§" . $causalCheck->getTree() . "§" . ($data->type == "IN" ? ($data->member ? ($data->member->last_name . " " . $data->member->first_name) : "") : $data->supplier->name ?? "") . "§" . $data->note . "§" . ($data->deleted ? 'DELETED' : '');
|
|
|
|
|
-
|
|
|
|
|
- if (isset($this->records[$causal]))
|
|
|
|
|
- {
|
|
|
|
|
- if (isset($this->records[$causal][$data->payment_method->name]))
|
|
|
|
|
- {
|
|
|
|
|
- if ($data->commercial)
|
|
|
|
|
- {
|
|
|
|
|
- if ($data->deleted && $this->records[$causal][$data->payment_method->name][$data->type])
|
|
|
|
|
- $amount += $this->records[$causal][$data->payment_method->name][$data->type];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $causal = $prefix . $data->date . "§" . $causalCheck->getTree() . "§" .
|
|
|
|
|
+ ($data->type == "IN" ? ($data->member ? ($data->member->last_name . " " . $data->member->first_name) : "") :
|
|
|
|
|
+ $data->supplier->name ?? "") . "§" . $data->note . "§" . ($data->deleted ? 'DELETED' : '') .
|
|
|
|
|
+ "§" . $data->numero_linea;
|
|
|
|
|
|
|
|
|
|
+ if (!isset($this->records[$causal][$data->payment_method->name][$data->type])) {
|
|
|
|
|
+ $this->records[$causal][$data->payment_method->name][$data->type] = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!isset($this->totals[$data->payment_method->name]))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ // Add to the records array
|
|
|
|
|
+ $this->records[$causal][$data->payment_method->name][$data->type] += $amount;
|
|
|
|
|
+
|
|
|
|
|
+ // Initialize totals if needed
|
|
|
|
|
+ if (!isset($this->totals[$data->payment_method->name])) {
|
|
|
$this->totals[$data->payment_method->name]["IN"] = 0;
|
|
$this->totals[$data->payment_method->name]["IN"] = 0;
|
|
|
$this->totals[$data->payment_method->name]["OUT"] = 0;
|
|
$this->totals[$data->payment_method->name]["OUT"] = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $this->records[$causal][$data->payment_method->name][$data->type] = $amount;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // Update totals if not deleted
|
|
|
if (!$data->deleted)
|
|
if (!$data->deleted)
|
|
|
- $this->totals[$data->payment_method->name][$data->type] += $amount; // $data->amount;//$this->records[$causal][$data->payment_method->name][$data->type];
|
|
|
|
|
|
|
+ $this->totals[$data->payment_method->name][$data->type] += $amount;// $data->amount;//$this->records[$causal][$data->payment_method->name][$data->type];
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|