diff --git a/VERSION.txt b/VERSION.txt index 03a49a0ddb..aca435662b 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.5.35 \ No newline at end of file +5.5.36 \ No newline at end of file diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index f13d26ee64..276ed694ff 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -205,11 +205,14 @@ class Handler extends ExceptionHandler return response()->json(['message' => $exception->getMessage()], 400); } elseif ($exception instanceof StripeConnectFailure) { return response()->json(['message' => $exception->getMessage()], 400); - } elseif ($exception instanceof QueryException) { - return response()->json(['message' => 'We had a problem executing this query. Please retry.'], 500); } + // elseif ($exception instanceof QueryException) { + // return response()->json(['message' => 'We had a problem executing this query. Please retry.'], 500); + // } + + return parent::render($request, $exception); } diff --git a/app/Helpers/SwissQr/SwissQrGenerator.php b/app/Helpers/SwissQr/SwissQrGenerator.php index f2d1fc1c8a..6d134adf90 100644 --- a/app/Helpers/SwissQr/SwissQrGenerator.php +++ b/app/Helpers/SwissQr/SwissQrGenerator.php @@ -141,7 +141,7 @@ class SwissQrGenerator // Optionally, add some human-readable information about what the bill is for. $qrBill->setAdditionalInformation( QrBill\DataGroup\Element\AdditionalInformation::create( - $this->invoice->public_notes ?: ctrans('texts.invoice_number_placeholder', ['invoice' => $invoice_number]) + $this->invoice->public_notes ? substr($this->invoice->public_notes, 0, 139) : ctrans('texts.invoice_number_placeholder', ['invoice' => $invoice_number]) ) ); diff --git a/app/Http/Requests/Setup/StoreSetupRequest.php b/app/Http/Requests/Setup/StoreSetupRequest.php index 5432ea689e..7329a49b04 100644 --- a/app/Http/Requests/Setup/StoreSetupRequest.php +++ b/app/Http/Requests/Setup/StoreSetupRequest.php @@ -43,7 +43,7 @@ class StoreSetupRequest extends Request 'terms_of_service' => 'required', 'first_name' => 'required', 'last_name' => 'required', - 'email' => 'required|email:rfc,dns', + 'email' => 'required|email', 'password' => 'required', ]; diff --git a/app/Jobs/Inventory/AdjustProductInventory.php b/app/Jobs/Inventory/AdjustProductInventory.php index 49cba52cec..7846a5ffdc 100644 --- a/app/Jobs/Inventory/AdjustProductInventory.php +++ b/app/Jobs/Inventory/AdjustProductInventory.php @@ -61,6 +61,44 @@ class AdjustProductInventory implements ShouldQueue return $this->newInventoryAdjustment(); } + public function handleDeletedInvoice() + { + + MultiDB::setDb($this->company->db); + + foreach ($this->invoice->line_items as $item) { + + $p = Product::where('product_key', $item->product_key)->where('company_id', $this->company->id)->first(); + + if (! $p) { + continue; + } + + $p->in_stock_quantity += $item->quantity; + + $p->saveQuietly(); + } + + } + + public function handleRestoredInvoice() + { + + MultiDB::setDb($this->company->db); + + foreach ($this->invoice->line_items as $item) { + $p = Product::where('product_key', $item->product_key)->where('company_id', $this->company->id)->first(); + + if (! $p) { + continue; + } + + $p->in_stock_quantity -= $item->quantity; + $p->saveQuietly(); + } + + } + public function middleware() { return [new WithoutOverlapping($this->company->company_key)]; diff --git a/app/Services/Invoice/HandleRestore.php b/app/Services/Invoice/HandleRestore.php index fb33536b29..412013aceb 100644 --- a/app/Services/Invoice/HandleRestore.php +++ b/app/Services/Invoice/HandleRestore.php @@ -11,6 +11,7 @@ namespace App\Services\Invoice; +use App\Jobs\Inventory\AdjustProductInventory; use App\Models\Invoice; use App\Models\Paymentable; use App\Services\AbstractService; @@ -68,6 +69,11 @@ class HandleRestore extends AbstractService ->setAdjustmentAmount() ->adjustPayments(); + if ($this->invoice->company->track_inventory) { + (new AdjustProductInventory($this->invoice->company, $this->invoice, []))->handleRestoredInvoice(); + } + + return $this->invoice; } diff --git a/app/Services/Invoice/MarkInvoiceDeleted.php b/app/Services/Invoice/MarkInvoiceDeleted.php index 4b61f0a6f4..b16c468c7c 100644 --- a/app/Services/Invoice/MarkInvoiceDeleted.php +++ b/app/Services/Invoice/MarkInvoiceDeleted.php @@ -11,6 +11,7 @@ namespace App\Services\Invoice; +use App\Jobs\Inventory\AdjustProductInventory; use App\Jobs\Ninja\TransactionLog; use App\Models\Invoice; use App\Models\TransactionEvent; @@ -22,7 +23,7 @@ class MarkInvoiceDeleted extends AbstractService { use GeneratesCounter; - private $invoice; + public $invoice; private $adjustment_amount = 0; @@ -41,6 +42,10 @@ class MarkInvoiceDeleted extends AbstractService return $this->invoice; } + if ($this->invoice->company->track_inventory) { + (new AdjustProductInventory($this->invoice->company, $this->invoice, []))->handleDeletedInvoice(); + } + $this->cleanup() ->setAdjustmentAmount() ->deletePaymentables() diff --git a/config/ninja.php b/config/ninja.php index 637ca998a9..dcabadb4d3 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.5.35', - 'app_tag' => '5.5.35', + 'app_version' => '5.5.36', + 'app_tag' => '5.5.36', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), diff --git a/tests/Feature/Inventory/InventoryManagementTest.php b/tests/Feature/Inventory/InventoryManagementTest.php index a97ae0e6e0..eb62e19c88 100644 --- a/tests/Feature/Inventory/InventoryManagementTest.php +++ b/tests/Feature/Inventory/InventoryManagementTest.php @@ -84,27 +84,23 @@ class InventoryManagementTest extends TestCase $this->assertEquals(90, $product->in_stock_quantity); - // $arr = $response->json(); - // $invoice_hashed_id = $arr['data']['id']; + $data = $response->json(); - // $invoice_item = new InvoiceItem; - // $invoice_item->type_id = 1; - // $invoice_item->product_key = $product->product_key; - // $invoice_item->notes = $product->notes; - // $invoice_item->quantity = 5; - // $invoice_item->cost = 100; + $invoice = Invoice::find($this->decodePrimaryKey($data['data']['id'])); - // $line_items2[] = $invoice_item; - // $invoice->line_items = $line_items2; + $invoice->service()->markDeleted()->save(); + $invoice->is_deleted = true; + $invoice->save(); + + $this->assertEquals(100, $product->fresh()->in_stock_quantity); + + $invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($data['data']['id'])); + + $invoice->service()->handleRestore()->save(); + + $this->assertEquals(90, $product->fresh()->in_stock_quantity); - // $response = $this->withHeaders([ - // 'X-API-SECRET' => config('ninja.api_secret'), - // 'X-API-TOKEN' => $this->token, - // ])->put('/api/v1/invoices/'.$invoice_hashed_id, $invoice->toArray()) - // ->assertStatus(200); - // $product = $product->refresh(); - // $this->assertEquals(95, $product->in_stock_quantity); } }