diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 6266bdf11a83..ac241216ce4b 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -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); diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index d5b5d3e82370..fea5c5b7e5df 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -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); } diff --git a/app/Jobs/Invoice/MarkInvoicePaid.php b/app/Jobs/Invoice/MarkInvoicePaid.php index f1001101bcad..f33e89d7568c 100644 --- a/app/Jobs/Invoice/MarkInvoicePaid.php +++ b/app/Jobs/Invoice/MarkInvoicePaid.php @@ -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); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index e39e1c5d574f..e103436fd61e 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -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; diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index cd6bc667bfd3..9653f7f872bc 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -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); diff --git a/tests/Feature/ProductTest.php b/tests/Feature/ProductTest.php index 8ecacba6131a..6974bb432f41 100644 --- a/tests/Feature/ProductTest.php +++ b/tests/Feature/ProductTest.php @@ -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,