diff --git a/app/Export/CSV/ActivityExport.php b/app/Export/CSV/ActivityExport.php index f1e98ef282f4..3cd1c8963273 100644 --- a/app/Export/CSV/ActivityExport.php +++ b/app/Export/CSV/ActivityExport.php @@ -158,9 +158,7 @@ class ActivityExport extends BaseExport $clean_row = []; foreach (array_values($this->input['report_keys']) as $key => $value) { - - nlog("key: {$key}, value: {$value}"); - nlog($row); + $clean_row[$key]['entity'] = 'activity'; $clean_row[$key]['id'] = $key; $clean_row[$key]['hashed_id'] = null; diff --git a/app/Export/CSV/TaskExport.php b/app/Export/CSV/TaskExport.php index 2a803df66837..87834c6aee4f 100644 --- a/app/Export/CSV/TaskExport.php +++ b/app/Export/CSV/TaskExport.php @@ -115,7 +115,7 @@ class TaskExport extends BaseExport $this->storage_array = []; }); - nlog($this->storage_item_array); + // nlog($this->storage_item_array); return array_merge(['columns' => $header], $this->storage_item_array); } diff --git a/app/Filters/GroupSettingFilters.php b/app/Filters/GroupSettingFilters.php index 0ea7512f503a..8123e6abda85 100644 --- a/app/Filters/GroupSettingFilters.php +++ b/app/Filters/GroupSettingFilters.php @@ -25,7 +25,8 @@ class GroupSettingFilters extends QueryFilters * @return Builder */ public function name(string $name = ''): Builder - {nlog("filter"); + { + if (strlen($name) == 0) { return $this->builder; } diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index d46bff3f9bca..cc2784f5c0bb 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -458,14 +458,15 @@ class ProductController extends BaseController */ public function bulk(BulkProductRequest $request) { + /** @var \App\Models\User $user */ + $user = auth()->user(); + $action = $request->input('action'); $ids = $request->input('ids'); $products = Product::withTrashed()->whereIn('id', $ids); - nlog($products->count()); - if($action == 'set_tax_id'){ $tax_id = $request->input('tax_id'); @@ -475,8 +476,8 @@ class ProductController extends BaseController return $this->listResponse(Product::withTrashed()->whereIn('id', $ids)); } - $products->cursor()->each(function ($product, $key) use ($action) { - if (auth()->user()->can('edit', $product)) { + $products->cursor()->each(function ($product, $key) use ($action, $user) { + if ($user->can('edit', $product)) { $this->product_repo->{$action}($product); } }); diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 8d47dbc3cd49..c849e7348092 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -182,7 +182,8 @@ class SetupController extends Controller * @return Application|ResponseFactory|JsonResponse|Response */ public function checkDB(CheckDatabaseRequest $request) - {nlog("trying"); + { + try { $status = SystemHealth::dbCheck($request); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index c9754a1fc006..6ad30e5c7c30 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -319,6 +319,14 @@ class Invoice extends BaseModel return $this->morphToMany(Payment::class, 'paymentable')->withTrashed()->withPivot('amount', 'refunded', 'deleted_at')->withTimestamps(); } + /** + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany + */ + public function net_payments(): \Illuminate\Database\Eloquent\Relations\MorphToMany + { + return $this->morphToMany(Payment::class, 'paymentable')->withTrashed()->where('is_deleted',0)->withPivot('amount', 'refunded', 'deleted_at')->withTimestamps(); + } + /** * @return \Illuminate\Database\Eloquent\Relations\MorphMany */ diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php index 3ea31c3c7b3d..41afd48b9685 100644 --- a/app/Repositories/ActivityRepository.php +++ b/app/Repositories/ActivityRepository.php @@ -135,7 +135,6 @@ class ActivityRepository extends BaseRepository $design = Design::withTrashed()->find($entity_design_id); if (! $entity->invitations()->exists() || ! $design) { - nlog("No invitations for entity {$entity->id} - {$entity->number}"); return ''; } @@ -204,8 +203,6 @@ class ActivityRepository extends BaseRepository $design = Design::withTrashed()->find($entity_design_id); if (! $entity->invitations()->exists() || ! $design) { - nlog("No invitations for entity {$entity->id} - {$entity->number}"); - return ''; } diff --git a/app/Services/Invoice/EInvoice/ZugferdEInvoice.php b/app/Services/Invoice/EInvoice/ZugferdEInvoice.php index 7bc153c30fd2..6b7dbe884350 100644 --- a/app/Services/Invoice/EInvoice/ZugferdEInvoice.php +++ b/app/Services/Invoice/EInvoice/ZugferdEInvoice.php @@ -138,7 +138,7 @@ class ZugferdEInvoice extends AbstractService $this->xrechnung->addDocumentPositionTax($taxtype, 'VAT', $item->tax_rate3); $this->addtoTaxMap($taxtype, $linenetamount, $item->tax_rate3); } else { - nlog("Can't add correct tax position"); + // nlog("Can't add correct tax position"); } } else { if (!empty($this->invoice->tax_name1)) { @@ -157,7 +157,7 @@ class ZugferdEInvoice extends AbstractService $taxtype = ZugferdDutyTaxFeeCategories::ZERO_RATED_GOODS; $this->xrechnung->addDocumentPositionTax($taxtype, 'VAT', 0); $this->addtoTaxMap($taxtype, $linenetamount, 0); - nlog("Can't add correct tax position"); + // nlog("Can't add correct tax position"); } } } diff --git a/app/Services/Invoice/HandleRestore.php b/app/Services/Invoice/HandleRestore.php index 836e604f0b75..45a960d4e86a 100644 --- a/app/Services/Invoice/HandleRestore.php +++ b/app/Services/Invoice/HandleRestore.php @@ -81,8 +81,6 @@ class HandleRestore extends AbstractService Paymentable::query() ->withTrashed() ->where('payment_id', $payment->id) - // ->where('paymentable_type', '=', 'invoices') - // ->where('paymentable_id', $this->invoice->id) ->update(['deleted_at' => null]); }); @@ -93,11 +91,6 @@ class HandleRestore extends AbstractService private function setAdjustmentAmount() { foreach ($this->invoice->payments as $payment) { - $this->adjustment_amount += $payment->paymentables - ->where('paymentable_type', '=', 'invoices') - ->where('paymentable_id', $this->invoice->id) - - ->sum('amount'); $this->adjustment_amount += $payment->paymentables ->where('paymentable_type', '=', 'invoices') ->where('paymentable_id', $this->invoice->id) @@ -108,6 +101,7 @@ class HandleRestore extends AbstractService ->where('paymentable_type', '=', 'App\Models\Credit') ->sum('amount'); + nlog("Adjustment amount: {$this->adjustment_amount}"); } $this->total_payments = $this->invoice->payments->sum('amount') - $this->invoice->payments->sum('refunded'); @@ -122,10 +116,12 @@ class HandleRestore extends AbstractService if ($this->adjustment_amount == $this->total_payments) { $this->invoice->payments()->update(['payments.deleted_at' => null, 'payments.is_deleted' => false]); } + else + $this->invoice->net_payments()->update(['payments.deleted_at' => null, 'payments.is_deleted' => false]); //adjust payments down by the amount applied to the invoice payment. - $this->invoice->payments->fresh()->each(function ($payment) { + $this->invoice->net_payments()->each(function ($payment) { $payment_adjustment = $payment->paymentables ->where('paymentable_type', '=', 'invoices') ->where('paymentable_id', $this->invoice->id) diff --git a/app/Services/Invoice/MarkInvoiceDeleted.php b/app/Services/Invoice/MarkInvoiceDeleted.php index 8402bda4f965..318737cae128 100644 --- a/app/Services/Invoice/MarkInvoiceDeleted.php +++ b/app/Services/Invoice/MarkInvoiceDeleted.php @@ -76,14 +76,12 @@ class MarkInvoiceDeleted extends AbstractService private function adjustPayments() { //if total payments = adjustment amount - that means we need to delete the payments as well. - if ($this->adjustment_amount == $this->total_payments) { $this->invoice->payments()->update(['payments.deleted_at' => now(), 'payments.is_deleted' => true]); } //adjust payments down by the amount applied to the invoice payment. - $this->invoice->payments->each(function ($payment) { $payment_adjustment = $payment->paymentables ->where('paymentable_type', '=', 'invoices')