Merge pull request #2340 from sevannerse/CU-1xphe64_Negative-Item-quantity_Sevan-Nerse
negative quantity not allowed #1xphe64
This commit is contained in:
commit
faa8eef8c4
@ -75,7 +75,7 @@ class Document extends FormRequest
|
|||||||
$size = 7;
|
$size = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rules['items.' . $key . '.quantity'] = 'required|max:' . $size;
|
$rules['items.' . $key . '.quantity'] = 'required|max:' . $size . '|numeric|gt:0';
|
||||||
$this->items_quantity_size[$key] = $size;
|
$this->items_quantity_size[$key] = $size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,6 +108,7 @@ class Document extends FormRequest
|
|||||||
if ($this->items_quantity_size) {
|
if ($this->items_quantity_size) {
|
||||||
foreach ($this->items_quantity_size as $key => $quantity_size) {
|
foreach ($this->items_quantity_size as $key => $quantity_size) {
|
||||||
$messages['items.' . $key . '.quantity.max'] = trans('validation.size', ['attribute' => Str::lower(trans('invoices.quantity')), 'size' => $quantity_size]);
|
$messages['items.' . $key . '.quantity.max'] = trans('validation.size', ['attribute' => Str::lower(trans('invoices.quantity')), 'size' => $quantity_size]);
|
||||||
|
$messages['items.' . $key . '.quantity.gt'] = trans('validation.gt.numeric', ['attribute' => Str::lower(trans('invoices.quantity')), 'value' => 0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +112,24 @@ class BillsTest extends FeatureTestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItShouldNotCreateBillWithNegativeQuantity()
|
||||||
|
{
|
||||||
|
$request = $this->getRequest();
|
||||||
|
|
||||||
|
$request['items'][0]['quantity'] = '-1';
|
||||||
|
|
||||||
|
$this->handleValidationExceptions();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(route('bills.store'), $request)
|
||||||
|
->assertRedirect()
|
||||||
|
->assertInvalid(['items.0.quantity']);
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('documents', [
|
||||||
|
'document_number' => $request['document_number'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function testItShouldSeeBillUpdatePage()
|
public function testItShouldSeeBillUpdatePage()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
@ -123,6 +123,24 @@ class InvoicesTest extends FeatureTestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItShouldNotCreateInvoiceWithNegativeQuantity()
|
||||||
|
{
|
||||||
|
$request = $this->getRequest();
|
||||||
|
|
||||||
|
$request['items'][0]['quantity'] = '-1';
|
||||||
|
|
||||||
|
$this->handleValidationExceptions();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(route('invoices.store'), $request)
|
||||||
|
->assertRedirect()
|
||||||
|
->assertInvalid(['items.0.quantity']);
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('documents', [
|
||||||
|
'document_number' => $request['document_number'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function testItShouldSeeInvoiceUpdatePage()
|
public function testItShouldSeeInvoiceUpdatePage()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user