Prechádzať zdrojové kódy

nascoste causali e metodi pagamento

FabioFratini 6 mesiacov pred
rodič
commit
06d38196c0
1 zmenil súbory, kde vykonal 80 pridanie a 5 odobranie
  1. 80 5
      app/Http/Livewire/RecordIN.php

+ 80 - 5
app/Http/Livewire/RecordIN.php

@@ -674,7 +674,8 @@ class RecordIN extends Component
         $this->isDuplicate = true;
     }
 
-    public function edit($id)
+
+public function edit($id)
     {
         if (!isset($_GET["from"]) && $this->fromPage == '')
             $this->fromPage = 'in';
@@ -682,15 +683,36 @@ class RecordIN extends Component
         //if ($this->hasFilter)
         $this->emit('hide-search');
         $this->emit('load-select');
+
         try {
             $record = \App\Models\Record::findOrFail($id);
             if (!$record) {
                 session()->flash('error', 'Movimento non trovato');
             } 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->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->corrispettivo_fiscale = $record->corrispettivo_fiscale;
                 $this->date = date("Y-m-d", strtotime($record->date));
@@ -709,8 +731,16 @@ class RecordIN extends Component
                 foreach ($rows as $i => $r) {
                     $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[] = [
-                        'causal_id' => $r->causal_id,
+                        'causal_id' => $causalId,
                         'note' => $r->note,
                         'commercial' => $r->commercial,
                         'when' => json_decode($r->when),
@@ -725,6 +755,8 @@ class RecordIN extends Component
                     $this->currentReceip = $exist;
                     $this->parent = $this->currentReceip->parent;
                 }
+
+                $this->refreshEditOptions();
             }
         } catch (\Exception $ex) {
             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)
     {
         Log::info("Starting update method");