mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Fix invoice payable rules (#3212)
This commit is contained in:
parent
633a75318e
commit
6167907a8e
@ -614,8 +614,8 @@ class InvoiceController extends BaseController
|
|||||||
# code...
|
# code...
|
||||||
break;
|
break;
|
||||||
case 'mark_paid':
|
case 'mark_paid':
|
||||||
if ($invoice->balance <= 0 || $invoice->status_id == Invoice::STATUS_PAID) {
|
if ($invoice->balance < 0 || $invoice->status_id == Invoice::STATUS_PAID || $invoice->is_deleted === true) {
|
||||||
return $this->errorResponse(['message' => 'Invoice has no balance owing'], 400);
|
return $this->errorResponse(['message' => 'Invoice cannot be marked as paid'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$invoice = MarkInvoicePaid::dispatchNow($invoice, $invoice->company);
|
$invoice = MarkInvoicePaid::dispatchNow($invoice, $invoice->company);
|
||||||
|
@ -349,7 +349,7 @@ class ProductController extends BaseController
|
|||||||
if($request->entityIsDeleted($product))
|
if($request->entityIsDeleted($product))
|
||||||
return $request->disallowUpdate();
|
return $request->disallowUpdate();
|
||||||
|
|
||||||
$product = $this->product_repo->save($request, $product);
|
$product = $this->product_repo->save($request->all(), $product);
|
||||||
|
|
||||||
return $this->itemResponse($product);
|
return $this->itemResponse($product);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,8 @@ class MarkInvoicePaid implements ShouldQueue
|
|||||||
{
|
{
|
||||||
MultiDB::setDB($this->company->db);
|
MultiDB::setDB($this->company->db);
|
||||||
|
|
||||||
|
if($this->invoice->status_id == Invoice::STATUS_DRAFT)
|
||||||
|
$this->invoice->markSent();
|
||||||
|
|
||||||
/* Create Payment */
|
/* Create Payment */
|
||||||
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
||||||
|
@ -218,13 +218,13 @@ class Invoice extends BaseModel
|
|||||||
|
|
||||||
public function isPayable() : bool
|
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;
|
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;
|
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;
|
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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -369,6 +369,7 @@ class PaymentTest extends TestCase
|
|||||||
$this->invoice = $this->invoice_calc->getInvoice();
|
$this->invoice = $this->invoice_calc->getInvoice();
|
||||||
$this->invoice->save();
|
$this->invoice->save();
|
||||||
$this->invoice->markSent();
|
$this->invoice->markSent();
|
||||||
|
$this->invoice->is_deleted = false;
|
||||||
$this->invoice->save();
|
$this->invoice->save();
|
||||||
|
|
||||||
|
|
||||||
@ -384,10 +385,20 @@ class PaymentTest extends TestCase
|
|||||||
'date' => '2019/12/12',
|
'date' => '2019/12/12',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$response = false;
|
||||||
|
|
||||||
|
try {
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $this->token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/payments?include=invoices', $data);
|
])->post('/api/v1/payments?include=invoices', $data);
|
||||||
|
}
|
||||||
|
catch(ValidationException $e) {
|
||||||
|
|
||||||
|
$message = json_decode($e->validator->getMessageBag(),1);
|
||||||
|
|
||||||
|
\Log::error($message);
|
||||||
|
}
|
||||||
|
|
||||||
$arr = $response->json();
|
$arr = $response->json();
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -822,10 +833,10 @@ class PaymentTest extends TestCase
|
|||||||
catch(ValidationException $e) {
|
catch(ValidationException $e) {
|
||||||
|
|
||||||
$message = json_decode($e->validator->getMessageBag(),1);
|
$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));
|
$this->assertTrue(array_key_exists('invoices', $message));
|
||||||
\Log::error('hit error');
|
// \Log::error('hit error');
|
||||||
}
|
}
|
||||||
|
|
||||||
//$response->assertStatus(302);
|
//$response->assertStatus(302);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user