|
|
@@ -123,7 +123,6 @@ class RecordIN extends Component
|
|
|
public function boot()
|
|
|
{
|
|
|
app(TenantMiddleware::class)->setupTenantConnection();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function updatedMemberId()
|
|
|
@@ -551,7 +550,42 @@ class RecordIN extends Component
|
|
|
|
|
|
$this->validate($rules);
|
|
|
|
|
|
+ /* Validazione campi azienda per generazione ricevuta */
|
|
|
+ try {
|
|
|
+ if (!$this->financial_movement && !$this->commercial) {
|
|
|
+ $no_receipt_causal_azienda = false;
|
|
|
+ foreach ($this->rows as $row) {
|
|
|
+ $no_receipt_causal_azienda = false;
|
|
|
+
|
|
|
+ $cau = \App\Models\Causal::findOrFail($row["causal_id"]);
|
|
|
+ if ($cau->no_receipt)
|
|
|
+ $no_receipt_causal_azienda = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ $azienda = \App\Models\Azienda::first();
|
|
|
+
|
|
|
+ $payment_method = \App\Models\PaymentMethod::findOrFail($this->payment_method_id);
|
|
|
+ if (!$payment_method->money) {
|
|
|
+ if (!$no_receipt_causal_azienda) {
|
|
|
+ if (!$azienda->isValid()) {
|
|
|
+ session()->flash('error_ricevuta', implode("", array_map(function ($item) {
|
|
|
+ return "<li>$item</li>";
|
|
|
+ }, array_keys($azienda->validate()))));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (\Exception $ex) {
|
|
|
+ Log::error("Error in store method: " . $ex->getMessage());
|
|
|
+ Log::error("Stack trace: " . $ex->getTraceAsString());
|
|
|
+ session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
|
|
|
+ }
|
|
|
+ /* END - Validazione campi azienda per generazione ricevuta */
|
|
|
+
|
|
|
try {
|
|
|
+
|
|
|
+
|
|
|
$totalGross = 0;
|
|
|
$totalSconto = 0;
|
|
|
$totalNet = 0;
|
|
|
@@ -675,7 +709,7 @@ class RecordIN extends Component
|
|
|
}
|
|
|
|
|
|
|
|
|
-public function edit($id)
|
|
|
+ public function edit($id)
|
|
|
{
|
|
|
if (!isset($_GET["from"]) && $this->fromPage == '')
|
|
|
$this->fromPage = 'in';
|
|
|
@@ -691,7 +725,7 @@ public function edit($id)
|
|
|
} else {
|
|
|
if ($record->member_id) {
|
|
|
$member = \App\Models\Member::find($record->member_id);
|
|
|
- if (!$member || $member->status =='archived') {
|
|
|
+ if (!$member || $member->status == 'archived') {
|
|
|
$this->member_id = null;
|
|
|
} else {
|
|
|
$this->member_id = $record->member_id;
|
|
|
@@ -770,7 +804,7 @@ public function edit($id)
|
|
|
$visibleCausals = \App\Models\Causal::select('id', 'name')
|
|
|
->where('parent_id', null)
|
|
|
->where('type', 'IN')
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('hidden', false)->orWhereNull('hidden');
|
|
|
})
|
|
|
->get();
|
|
|
@@ -779,7 +813,7 @@ public function edit($id)
|
|
|
$this->payments = \App\Models\PaymentMethod::select('id', 'name')
|
|
|
->where('enabled', true)
|
|
|
->whereIn('type', array('ALL', 'IN'))
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('hidden', false)->orWhereNull('hidden');
|
|
|
})
|
|
|
->orderBy('name')
|
|
|
@@ -787,7 +821,7 @@ public function edit($id)
|
|
|
|
|
|
if ($this->commercial) {
|
|
|
$this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('status', '!=', 'archived');
|
|
|
})
|
|
|
->orderBy('last_name')
|
|
|
@@ -795,10 +829,10 @@ public function edit($id)
|
|
|
->get();
|
|
|
} else {
|
|
|
$this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('current_status', 2)->orWhere('current_status', 1);
|
|
|
})
|
|
|
- ->where(function($query) {
|
|
|
+ ->where(function ($query) {
|
|
|
$query->where('status', '!=', 'archived');
|
|
|
})
|
|
|
->orderBy('last_name')
|
|
|
@@ -822,6 +856,39 @@ public function edit($id)
|
|
|
|
|
|
$this->validate($rules);
|
|
|
|
|
|
+ /* Validazione campi azienda per generazione ricevuta */
|
|
|
+ try {
|
|
|
+ if (!$this->financial_movement && !$this->commercial) {
|
|
|
+ $no_receipt_causal_azienda = false;
|
|
|
+ foreach ($this->rows as $row) {
|
|
|
+ $no_receipt_causal_azienda = false;
|
|
|
+
|
|
|
+ $cau = \App\Models\Causal::findOrFail($row["causal_id"]);
|
|
|
+ if ($cau->no_receipt)
|
|
|
+ $no_receipt_causal_azienda = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ $azienda = \App\Models\Azienda::first();
|
|
|
+
|
|
|
+ $payment_method = \App\Models\PaymentMethod::findOrFail($this->payment_method_id);
|
|
|
+ if (!$payment_method->money) {
|
|
|
+ if (!$no_receipt_causal_azienda) {
|
|
|
+ if (!$azienda->isValid()) {
|
|
|
+ session()->flash('error_ricevuta', implode("", array_map(function ($item) {
|
|
|
+ return "<li>$item</li>";
|
|
|
+ }, array_keys($azienda->validate()))));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (\Exception $ex) {
|
|
|
+ Log::error("Error in store method: " . $ex->getMessage());
|
|
|
+ Log::error("Stack trace: " . $ex->getTraceAsString());
|
|
|
+ session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
|
|
|
+ }
|
|
|
+ /* END - Validazione campi azienda per generazione ricevuta */
|
|
|
+
|
|
|
try {
|
|
|
$totalGross = 0;
|
|
|
$totalSconto = 0;
|
|
|
@@ -890,18 +957,22 @@ public function edit($id)
|
|
|
|
|
|
Log::info("Final amount saved to record: " . $totalNet);
|
|
|
|
|
|
+ $receipt_created = true;
|
|
|
if (!$this->financial_movement) {
|
|
|
$payment_method = \App\Models\PaymentMethod::findOrFail($this->payment_method_id);
|
|
|
if (!$payment_method->money) {
|
|
|
if ($generate && !$no_receipt_causal)
|
|
|
- $this->createReceipt();
|
|
|
+ $receipt_created = $this->createReceipt();
|
|
|
}
|
|
|
}
|
|
|
- session()->flash('success', 'Movimento aggiornato');
|
|
|
- $this->resetFields();
|
|
|
- $this->update = false;
|
|
|
- $this->isDuplicate = false;
|
|
|
- $this->emit('setEdit', false);
|
|
|
+
|
|
|
+ if ($receipt_created) {
|
|
|
+ session()->flash('success', 'Movimento aggiornato');
|
|
|
+ $this->resetFields();
|
|
|
+ $this->update = false;
|
|
|
+ $this->isDuplicate = false;
|
|
|
+ $this->emit('setEdit', false);
|
|
|
+ }
|
|
|
} catch (\Exception $ex) {
|
|
|
Log::error("Error in update method: " . $ex->getMessage());
|
|
|
Log::error("Stack trace: " . $ex->getTraceAsString());
|
|
|
@@ -930,13 +1001,16 @@ public function edit($id)
|
|
|
|
|
|
$this->dataId = $newRecord->id;
|
|
|
|
|
|
- $this->createReceipt();
|
|
|
|
|
|
- session()->flash('success', 'Movimento aggiornato');
|
|
|
- $this->resetFields();
|
|
|
- $this->update = false;
|
|
|
- $this->isDuplicate = false;
|
|
|
- $this->emit('setEdit', false);
|
|
|
+ $receipt_created = $this->createReceipt();
|
|
|
+
|
|
|
+ if ($receipt_created) {
|
|
|
+ session()->flash('success', 'Movimento aggiornato');
|
|
|
+ $this->resetFields();
|
|
|
+ $this->update = false;
|
|
|
+ $this->isDuplicate = false;
|
|
|
+ $this->emit('setEdit', false);
|
|
|
+ }
|
|
|
} catch (\Exception $ex) {
|
|
|
session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
|
|
|
}
|
|
|
@@ -1064,7 +1138,6 @@ public function edit($id)
|
|
|
|
|
|
public function createReceipt()
|
|
|
{
|
|
|
-
|
|
|
// Ulteriore controllo commerciale/non commerciale
|
|
|
if (!$this->commercial) {
|
|
|
$create = false;
|
|
|
@@ -1139,6 +1212,8 @@ public function edit($id)
|
|
|
$this->emit('showReceipt', $this->currentReceip->id);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
public function removeReceipt()
|