Fix invoice payable rules (#3212)

This commit is contained in:
David Bomba 2020-01-15 19:43:40 +10:00 committed by GitHub
parent 633a75318e
commit 6167907a8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 11 deletions

View File

@ -614,8 +614,8 @@ class InvoiceController extends BaseController
# code...
break;
case 'mark_paid':
if ($invoice->balance <= 0 || $invoice->status_id == Invoice::STATUS_PAID) {
return $this->errorResponse(['message' => 'Invoice has no balance owing'], 400);
if ($invoice->balance < 0 || $invoice->status_id == Invoice::STATUS_PAID || $invoice->is_deleted === true) {
return $this->errorResponse(['message' => 'Invoice cannot be marked as paid'], 400);
}
$invoice = MarkInvoicePaid::dispatchNow($invoice, $invoice->company);

View File

@ -349,7 +349,7 @@ class ProductController extends BaseController
if($request->entityIsDeleted($product))
return $request->disallowUpdate();
$product = $this->product_repo->save($request, $product);
$product = $this->product_repo->save($request->all(), $product);
return $this->itemResponse($product);
}

View File

@ -56,7 +56,9 @@ class MarkInvoicePaid implements ShouldQueue
{
MultiDB::setDB($this->company->db);
if($this->invoice->status_id == Invoice::STATUS_DRAFT)
$this->invoice->markSent();
/* Create Payment */
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);

View File

@ -218,13 +218,13 @@ class Invoice extends BaseModel
public function isPayable() : bool
{
if ($this->status_id == Invoice::STATUS_SENT && $this->due_date > Carbon::now()) {
if ($this->status_id == Invoice::STATUS_SENT && $this->is_deleted == false) {
return true;
} elseif ($this->status_id == Invoice::STATUS_PARTIAL && $this->partial_due_date > Carbon::now()) {
} elseif ($this->status_id == Invoice::STATUS_PARTIAL && $this->is_deleted == false) {
return true;
} elseif ($this->status_id == Invoice::STATUS_SENT && $this->due_date < Carbon::now()) {
} elseif ($this->status_id == Invoice::STATUS_SENT && $this->is_deleted == false) {
return true;
} elseif ($this->status_id == Invoice::STATUS_PARTIAL && $this->partial_due_date < Carbon::now()) {
} elseif ($this->status_id == Invoice::STATUS_DRAFT && $this->is_deleted == false) {
return true;
} else {
return false;

View File

@ -369,6 +369,7 @@ class PaymentTest extends TestCase
$this->invoice = $this->invoice_calc->getInvoice();
$this->invoice->save();
$this->invoice->markSent();
$this->invoice->is_deleted = false;
$this->invoice->save();
@ -384,10 +385,20 @@ class PaymentTest extends TestCase
'date' => '2019/12/12',
];
$response = false;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data);
}
catch(ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(),1);
\Log::error($message);
}
$arr = $response->json();
$response->assertStatus(200);
@ -822,10 +833,10 @@ class PaymentTest extends TestCase
catch(ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(),1);
\Log::error(print_r($e->validator->getMessageBag(),1));
// \Log::error(print_r($e->validator->getMessageBag(),1));
$this->assertTrue(array_key_exists('invoices', $message));
\Log::error('hit error');
// \Log::error('hit error');
}
//$response->assertStatus(302);

View File

@ -45,7 +45,7 @@ class ProductTest extends TestCase
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
'name' => $this->faker->company,
'email' => $this->faker->unique()->safeEmail,
'email' => $this->faker->unique()->safeEmail,
'password' => 'ALongAndBrilliantPassword123',
'_token' => csrf_token(),
'privacy_policy' => 1,