mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Working on adding transactions to the company ledger
This commit is contained in:
parent
10587c0494
commit
a2a0e6738e
@ -303,20 +303,34 @@ class InvoiceCalc
|
||||
|
||||
public function getInvoice()
|
||||
{
|
||||
//todo build invoice values here and return Invoice
|
||||
|
||||
//Build invoice values here and return Invoice
|
||||
$this->setCalculatedAttributes();
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build $this->invoice variable after
|
||||
* Build $this->invoice variables after
|
||||
* calculations have been performed.
|
||||
*/
|
||||
private function setCalculatedAttributes()
|
||||
{
|
||||
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
|
||||
if($this->invoice->amount != $this->invoice->balance)
|
||||
{
|
||||
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
|
||||
|
||||
$this->invoice->balance = $this->getTotal() - $paid_to_date;
|
||||
}
|
||||
else
|
||||
$this->invoice->balance = $this->getTotal();
|
||||
|
||||
/* Set new calculated total */
|
||||
$this->invoice->amount = $this->getTotal();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
private function setDiscount($amount, $discount, $is_amount_discount)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ class ApplyPaymentToInvoice implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
|
||||
/* The amoun we are adjusting the invoice by*/
|
||||
/* The amount we are adjusting the invoice by*/
|
||||
$adjustment = $this->payment->amount * -1;
|
||||
|
||||
/* Calculate if the amount paid is less than the partial value.
|
||||
|
@ -61,10 +61,7 @@ class MarkPaid implements ShouldQueue
|
||||
|
||||
/* Create a payment relationship to the invoice entity */
|
||||
$payment->invoices()->save($this->invoice);
|
||||
//Log::error($payment);
|
||||
//Log::error('num of payment invoice relations '.count($payment->invoices));
|
||||
//Log::error(print_r($payment->invoices,1));
|
||||
/* Need to engineer the ability to pass an array of invoices to the activity handler*/
|
||||
|
||||
$data = [
|
||||
'payment_id' => $payment->id,
|
||||
'invoice_ids' => [
|
||||
|
@ -856,8 +856,7 @@ class CreateUsersTable extends Migration
|
||||
$table->unsignedInteger('user_id')->nullable();
|
||||
|
||||
$table->decimal('adjustment', 13, 2)->nullable();
|
||||
$table->decimal('balance', 13, 2)->nullable();
|
||||
$table->decimal('balance_carried_forward', 13, 2)->nullable();
|
||||
$table->decimal('balance', 13, 2)->nullable(); //this is the clients balance carried forward
|
||||
$table->text('notes');
|
||||
|
||||
$table->unsignedInteger('company_ledger_id');
|
||||
|
@ -10,9 +10,6 @@ use App\Models\Payment;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -47,17 +44,13 @@ class MarkPaidInvoiceTest extends TestCase
|
||||
|
||||
$this->assertEquals(1, count($invoice->payments));
|
||||
|
||||
|
||||
foreach($invoice->payments as $payment) {
|
||||
Log::error($payment);
|
||||
//Log::error($payment);
|
||||
$this->assertEquals(10, $payment->amount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->assertEquals(Invoice::STATUS_PAID, $invoice->status_id);
|
||||
|
||||
|
||||
$this->assertEquals(0.00, $invoice->balance);
|
||||
|
||||
}
|
||||
|
@ -78,9 +78,8 @@ trait MockAccountData
|
||||
$this->invoice_calc = new InvoiceCalc($this->invoice, $this->settings);
|
||||
$this->invoice_calc->build();
|
||||
|
||||
$this->invoice->amount = $this->invoice_calc->getTotal();
|
||||
$this->invoice->balance = $this->invoice_calc->getTotal();
|
||||
|
||||
$this->invoice = $this->invoice_calc->getInvoice();
|
||||
|
||||
$this->invoice->save();
|
||||
$this->invoice->fresh();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user