mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
updates for paymentable dates on import
This commit is contained in:
parent
279de2dfff
commit
fd91db2f6e
@ -19,6 +19,7 @@ use App\Models\Invoice;
|
||||
use League\Csv\Statement;
|
||||
use App\Factory\QuoteFactory;
|
||||
use App\Factory\ClientFactory;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\PaymentFactory;
|
||||
use App\Import\ImportException;
|
||||
@ -495,7 +496,8 @@ class BaseImport
|
||||
|
||||
/* Make sure we don't apply any payments to invoices with a Zero Amount*/
|
||||
if ($invoice->amount > 0) {
|
||||
$payment_repository->save(
|
||||
|
||||
$payment = $payment_repository->save(
|
||||
$payment_data,
|
||||
PaymentFactory::create(
|
||||
$this->company->id,
|
||||
@ -503,6 +505,16 @@ class BaseImport
|
||||
$invoice->client_id
|
||||
)
|
||||
);
|
||||
|
||||
$payment_date = Carbon::parse($payment->date);
|
||||
|
||||
if(!$payment_date->isToday())
|
||||
{
|
||||
|
||||
$payment->paymentables()->update(['created_at' => $payment_date]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ class PaymentRepository extends BaseRepository
|
||||
* the company currency, we need to set a record.
|
||||
* @param $data
|
||||
* @param $payment
|
||||
* @return
|
||||
* @return Payment $payment
|
||||
*/
|
||||
public function processExchangeRates($data, $payment)
|
||||
{
|
||||
|
@ -104,16 +104,6 @@ class ApplyPayment extends AbstractService
|
||||
|
||||
$this->invoice->service()->applyNumber()->workFlow()->touchPdf()->save();
|
||||
|
||||
$transaction = [
|
||||
'invoice' => $this->invoice->transaction_event(),
|
||||
'payment' => $this->payment->transaction_event(),
|
||||
'client' => $this->invoice->client->transaction_event(),
|
||||
'credit' => [],
|
||||
'metadata' => [],
|
||||
];
|
||||
|
||||
// TransactionLog::dispatch(TransactionEvent::INVOICE_PAYMENT_APPLIED, $transaction, $this->invoice->company->db);
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
}
|
||||
|
@ -11,19 +11,20 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
use App\Models\Client;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use Tests\MockAccountData;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* @test
|
||||
@ -36,6 +37,8 @@ class UpdatePaymentTest extends TestCase
|
||||
use MockAccountData;
|
||||
use WithoutEvents;
|
||||
|
||||
public $faker;
|
||||
|
||||
protected function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
@ -50,6 +53,37 @@ class UpdatePaymentTest extends TestCase
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testUpdatingPaymentableDates()
|
||||
{
|
||||
$this->invoice = $this->invoice->service()->markPaid()->save();
|
||||
|
||||
$payment = $this->invoice->payments->first();
|
||||
|
||||
$this->assertNotNull($payment);
|
||||
|
||||
$payment->paymentables()->each(function ($pivot){
|
||||
|
||||
$this->assertTrue(Carbon::createFromTimestamp($pivot->created_at)->isToday());
|
||||
});
|
||||
|
||||
$payment->paymentables()->each(function ($pivot) {
|
||||
|
||||
$pivot->created_at = now()->startOfDay()->subMonth();
|
||||
$pivot->save();
|
||||
|
||||
});
|
||||
|
||||
$payment->paymentables()->each(function ($pivot) {
|
||||
|
||||
$this->assertTrue(Carbon::createFromTimestamp($pivot->created_at)->eq(now()->startOfDay()->subMonth()));
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testUpdatePaymentClientPaidToDate()
|
||||
|
Loading…
x
Reference in New Issue
Block a user