mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-02 15:14:36 -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 League\Csv\Statement;
|
||||||
use App\Factory\QuoteFactory;
|
use App\Factory\QuoteFactory;
|
||||||
use App\Factory\ClientFactory;
|
use App\Factory\ClientFactory;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
use App\Factory\InvoiceFactory;
|
use App\Factory\InvoiceFactory;
|
||||||
use App\Factory\PaymentFactory;
|
use App\Factory\PaymentFactory;
|
||||||
use App\Import\ImportException;
|
use App\Import\ImportException;
|
||||||
@ -495,7 +496,8 @@ class BaseImport
|
|||||||
|
|
||||||
/* Make sure we don't apply any payments to invoices with a Zero Amount*/
|
/* Make sure we don't apply any payments to invoices with a Zero Amount*/
|
||||||
if ($invoice->amount > 0) {
|
if ($invoice->amount > 0) {
|
||||||
$payment_repository->save(
|
|
||||||
|
$payment = $payment_repository->save(
|
||||||
$payment_data,
|
$payment_data,
|
||||||
PaymentFactory::create(
|
PaymentFactory::create(
|
||||||
$this->company->id,
|
$this->company->id,
|
||||||
@ -503,6 +505,16 @@ class BaseImport
|
|||||||
$invoice->client_id
|
$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.
|
* the company currency, we need to set a record.
|
||||||
* @param $data
|
* @param $data
|
||||||
* @param $payment
|
* @param $payment
|
||||||
* @return
|
* @return Payment $payment
|
||||||
*/
|
*/
|
||||||
public function processExchangeRates($data, $payment)
|
public function processExchangeRates($data, $payment)
|
||||||
{
|
{
|
||||||
|
@ -104,16 +104,6 @@ class ApplyPayment extends AbstractService
|
|||||||
|
|
||||||
$this->invoice->service()->applyNumber()->workFlow()->touchPdf()->save();
|
$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;
|
return $this->invoice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,19 +11,20 @@
|
|||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
use App\Factory\InvoiceFactory;
|
use Carbon\Carbon;
|
||||||
use App\Helpers\Invoice\InvoiceSum;
|
use Tests\TestCase;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use App\Factory\InvoiceFactory;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use App\Helpers\Invoice\InvoiceSum;
|
||||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Tests\MockAccountData;
|
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||||
use Tests\TestCase;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
@ -36,6 +37,8 @@ class UpdatePaymentTest extends TestCase
|
|||||||
use MockAccountData;
|
use MockAccountData;
|
||||||
use WithoutEvents;
|
use WithoutEvents;
|
||||||
|
|
||||||
|
public $faker;
|
||||||
|
|
||||||
protected function setUp() :void
|
protected function setUp() :void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@ -50,6 +53,37 @@ class UpdatePaymentTest extends TestCase
|
|||||||
$this->withoutMiddleware(
|
$this->withoutMiddleware(
|
||||||
ThrottleRequests::class
|
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()
|
public function testUpdatePaymentClientPaidToDate()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user