|
@@ -674,7 +674,8 @@ class RecordIN extends Component
|
|
|
$this->isDuplicate = true;
|
|
$this->isDuplicate = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function edit($id)
|
|
|
|
|
|
|
+
|
|
|
|
|
+public function edit($id)
|
|
|
{
|
|
{
|
|
|
if (!isset($_GET["from"]) && $this->fromPage == '')
|
|
if (!isset($_GET["from"]) && $this->fromPage == '')
|
|
|
$this->fromPage = 'in';
|
|
$this->fromPage = 'in';
|
|
@@ -682,15 +683,36 @@ class RecordIN extends Component
|
|
|
//if ($this->hasFilter)
|
|
//if ($this->hasFilter)
|
|
|
$this->emit('hide-search');
|
|
$this->emit('hide-search');
|
|
|
$this->emit('load-select');
|
|
$this->emit('load-select');
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
$record = \App\Models\Record::findOrFail($id);
|
|
$record = \App\Models\Record::findOrFail($id);
|
|
|
if (!$record) {
|
|
if (!$record) {
|
|
|
session()->flash('error', 'Movimento non trovato');
|
|
session()->flash('error', 'Movimento non trovato');
|
|
|
} else {
|
|
} else {
|
|
|
- $this->member_id = $record->member_id;
|
|
|
|
|
|
|
+ if ($record->member_id) {
|
|
|
|
|
+ $member = \App\Models\Member::find($record->member_id);
|
|
|
|
|
+ if (!$member || $member->status =='archived') {
|
|
|
|
|
+ $this->member_id = null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->member_id = $record->member_id;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->member_id = $record->member_id;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($record->payment_method_id) {
|
|
|
|
|
+ $paymentMethod = \App\Models\PaymentMethod::find($record->payment_method_id);
|
|
|
|
|
+ if (!$paymentMethod || (isset($paymentMethod->hidden) && $paymentMethod->hidden)) {
|
|
|
|
|
+ $this->payment_method_id = null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->payment_method_id = $record->payment_method_id;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->payment_method_id = $record->payment_method_id;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$this->supplier_id = $record->supplier_id;
|
|
$this->supplier_id = $record->supplier_id;
|
|
|
- $this->payment_method_id = $record->payment_method_id;
|
|
|
|
|
- $this->amount = $record->amount; // This is the net amount in DB
|
|
|
|
|
|
|
+ $this->amount = $record->amount;
|
|
|
$this->commercial = $record->commercial;
|
|
$this->commercial = $record->commercial;
|
|
|
$this->corrispettivo_fiscale = $record->corrispettivo_fiscale;
|
|
$this->corrispettivo_fiscale = $record->corrispettivo_fiscale;
|
|
|
$this->date = date("Y-m-d", strtotime($record->date));
|
|
$this->date = date("Y-m-d", strtotime($record->date));
|
|
@@ -709,8 +731,16 @@ class RecordIN extends Component
|
|
|
foreach ($rows as $i => $r) {
|
|
foreach ($rows as $i => $r) {
|
|
|
$grossAmount = $r->prediscount_amount ?? ($r->amount + $r->sconto);
|
|
$grossAmount = $r->prediscount_amount ?? ($r->amount + $r->sconto);
|
|
|
|
|
|
|
|
|
|
+ $causalId = $r->causal_id;
|
|
|
|
|
+ if ($causalId) {
|
|
|
|
|
+ $causal = \App\Models\Causal::find($causalId);
|
|
|
|
|
+ if (!$causal || (isset($causal->hidden) && $causal->hidden)) {
|
|
|
|
|
+ $causalId = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$this->rows[] = [
|
|
$this->rows[] = [
|
|
|
- 'causal_id' => $r->causal_id,
|
|
|
|
|
|
|
+ 'causal_id' => $causalId,
|
|
|
'note' => $r->note,
|
|
'note' => $r->note,
|
|
|
'commercial' => $r->commercial,
|
|
'commercial' => $r->commercial,
|
|
|
'when' => json_decode($r->when),
|
|
'when' => json_decode($r->when),
|
|
@@ -725,6 +755,8 @@ class RecordIN extends Component
|
|
|
$this->currentReceip = $exist;
|
|
$this->currentReceip = $exist;
|
|
|
$this->parent = $this->currentReceip->parent;
|
|
$this->parent = $this->currentReceip->parent;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ $this->refreshEditOptions();
|
|
|
}
|
|
}
|
|
|
} catch (\Exception $ex) {
|
|
} catch (\Exception $ex) {
|
|
|
Log::error("Error in edit method: " . $ex->getMessage());
|
|
Log::error("Error in edit method: " . $ex->getMessage());
|
|
@@ -732,6 +764,49 @@ class RecordIN extends Component
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private function refreshEditOptions()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->causals = array();
|
|
|
|
|
+ $visibleCausals = \App\Models\Causal::select('id', 'name')
|
|
|
|
|
+ ->where('parent_id', null)
|
|
|
|
|
+ ->where('type', 'IN')
|
|
|
|
|
+ ->where(function($query) {
|
|
|
|
|
+ $query->where('hidden', false)->orWhereNull('hidden');
|
|
|
|
|
+ })
|
|
|
|
|
+ ->get();
|
|
|
|
|
+ $this->getCausale($visibleCausals, 0);
|
|
|
|
|
+
|
|
|
|
|
+ $this->payments = \App\Models\PaymentMethod::select('id', 'name')
|
|
|
|
|
+ ->where('enabled', true)
|
|
|
|
|
+ ->whereIn('type', array('ALL', 'IN'))
|
|
|
|
|
+ ->where(function($query) {
|
|
|
|
|
+ $query->where('hidden', false)->orWhereNull('hidden');
|
|
|
|
|
+ })
|
|
|
|
|
+ ->orderBy('name')
|
|
|
|
|
+ ->get();
|
|
|
|
|
+
|
|
|
|
|
+ if ($this->commercial) {
|
|
|
|
|
+ $this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])
|
|
|
|
|
+ ->where(function($query) {
|
|
|
|
|
+ $query->where('status', '!=', 'archived');
|
|
|
|
|
+ })
|
|
|
|
|
+ ->orderBy('last_name')
|
|
|
|
|
+ ->orderBy('first_name')
|
|
|
|
|
+ ->get();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])
|
|
|
|
|
+ ->where(function($query) {
|
|
|
|
|
+ $query->where('current_status', 2)->orWhere('current_status', 1);
|
|
|
|
|
+ })
|
|
|
|
|
+ ->where(function($query) {
|
|
|
|
|
+ $query->where('status', '!=', 'archived');
|
|
|
|
|
+ })
|
|
|
|
|
+ ->orderBy('last_name')
|
|
|
|
|
+ ->orderBy('first_name')
|
|
|
|
|
+ ->get();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function update($generate = false)
|
|
public function update($generate = false)
|
|
|
{
|
|
{
|
|
|
Log::info("Starting update method");
|
|
Log::info("Starting update method");
|