1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00

Merge pull request #7908 from turbo124/v5-stable

v5.5.36
This commit is contained in:
David Bomba 2022-10-30 09:54:37 +11:00 committed by GitHub
commit 577f2a4809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 73 additions and 25 deletions

View File

@ -1 +1 @@
5.5.35
5.5.36

View File

@ -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);
}

View File

@ -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])
)
);

View File

@ -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',
];

View File

@ -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)];

View File

@ -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;
}

View File

@ -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()

View File

@ -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', ''),

View File

@ -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);
}
}