commit
44573c1f8e
92
tests/Feature/Banking/Transaction.php
Normal file
92
tests/Feature/Banking/Transaction.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Banking;
|
||||
|
||||
use App\Models\Expense\Bill;
|
||||
use App\Models\Expense\Payment;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Income\Revenue;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Transaction extends Model
|
||||
{
|
||||
public static function getUserTransactions($user_id, $type)
|
||||
{
|
||||
$transactions = array();
|
||||
|
||||
switch ($type) {
|
||||
case 'payments':
|
||||
$bills = Bill::where('vendor_id', $user_id)->get();
|
||||
|
||||
foreach ($bills as $bill) {
|
||||
$bill_payments = $bill->payments;
|
||||
|
||||
if ($bill_payments) {
|
||||
foreach ($bill_payments as $bill_payment) {
|
||||
$transactions[] = (object) [
|
||||
'date' => $bill_payment->paid_at,
|
||||
'account' => $bill_payment->account->name,
|
||||
'type' => trans('invoices.status.partial'),
|
||||
'category' => trans_choice('general.invoices', 1),
|
||||
'description' => $bill_payment->description,
|
||||
'amount' => $bill_payment->amount,
|
||||
'currency_code' => $bill_payment->currency_code,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$payments = Payment::where('vendor_id', $user_id)->get();
|
||||
|
||||
foreach ($payments as $payment) {
|
||||
$transactions[] = (object) [
|
||||
'date' => $payment->paid_at,
|
||||
'account' => $payment->account->name,
|
||||
'type' => 'Expense',
|
||||
'category' => $payment->category->name,
|
||||
'description' => $payment->description,
|
||||
'amount' => $payment->amount,
|
||||
'currency_code' => $payment->currency_code,
|
||||
];
|
||||
}
|
||||
break;
|
||||
case 'revenues':
|
||||
$invoices = Invoice::where('customer_id', $user_id)->get();
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
$invoice_payments = $invoice->payments;
|
||||
|
||||
if ($invoice_payments) {
|
||||
foreach ($invoice_payments as $invoice_payment) {
|
||||
$transactions[] = (object) [
|
||||
'date' => $invoice_payment->paid_at,
|
||||
'account' => $invoice_payment->account->name,
|
||||
'type' => trans('invoices.status.partial'),
|
||||
'category' => trans_choice('general.invoices', 1),
|
||||
'description' => $invoice_payment->description,
|
||||
'amount' => $invoice_payment->amount,
|
||||
'currency_code' => $invoice_payment->currency_code,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$revenues = Revenue::where('customer_id', $user_id)->get();
|
||||
|
||||
foreach ($revenues as $revenue) {
|
||||
$transactions[] = (object) [
|
||||
'date' => $revenue->paid_at,
|
||||
'account' => $revenue->account->name,
|
||||
'type' => trans_choice('general.payments', 1),
|
||||
'category' => $revenue->category->name,
|
||||
'description' => $revenue->description,
|
||||
'amount' => $revenue->amount,
|
||||
'currency_code' => $revenue->currency_code,
|
||||
];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
}
|
166
tests/Feature/Banking/TransfersTest.php
Normal file
166
tests/Feature/Banking/TransfersTest.php
Normal file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Banking;
|
||||
|
||||
use App\Models\Banking\Transfer;
|
||||
use App\Models\Expense\Payment;
|
||||
use App\Models\Income\Revenue;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class TransfersTest extends FeatureTestCase
|
||||
{
|
||||
public function testItShouldSeeTransferListPage()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('transfers.index'))
|
||||
->assertStatus(200)
|
||||
->assertSeeText(trans_choice('general.transfers', 2));
|
||||
}
|
||||
|
||||
public function testItShouldSeeTransferCreatePage()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('transfers.create'))
|
||||
->assertStatus(200)
|
||||
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.transfers', 1)]));
|
||||
}
|
||||
|
||||
public function testItShouldCreateTransfer()
|
||||
{
|
||||
// Create Revenue
|
||||
$revenue_request = $this->getRevenueRequest();
|
||||
$revenue = Revenue::create($revenue_request);
|
||||
|
||||
// Create Payment
|
||||
$payment_request = $this->getPaymentRequest();
|
||||
$payment = Payment::create($payment_request);
|
||||
|
||||
$this->loginAs()
|
||||
->post(url('banking/transfers'), $this->getTransferRequest($revenue, $payment))
|
||||
->assertStatus(302)
|
||||
->assertRedirect(url('banking/transfers'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldSeeTransferUpdatePage()
|
||||
{
|
||||
// Create Revenue
|
||||
$revenue_request = $this->getRevenueRequest();
|
||||
$revenue = Revenue::create($revenue_request);
|
||||
|
||||
// Create Payment
|
||||
$payment_request = $this->getPaymentRequest();
|
||||
$payment = Payment::create($payment_request);
|
||||
|
||||
$transfer = Transfer::create($this->getTransferRequest($revenue, $payment));
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('transfers.edit', ['transfer' => $transfer->id]))
|
||||
->assertStatus(200)
|
||||
->assertSee($payment->description);
|
||||
}
|
||||
|
||||
public function testItShouldDeleteTransfer()
|
||||
{
|
||||
// Create Revenue
|
||||
$revenue_request = $this->getRevenueRequest();
|
||||
$revenue = Revenue::create($revenue_request);
|
||||
|
||||
// Create Payment
|
||||
$payment_request = $this->getPaymentRequest();
|
||||
$payment = Payment::create($payment_request);
|
||||
|
||||
$transfer = Transfer::create($this->getTransferRequest($revenue, $payment));
|
||||
|
||||
$this->loginAs()
|
||||
->delete(url('banking/transfers', ['transfer' => $transfer->id]))
|
||||
->assertStatus(302)
|
||||
->assertRedirect(url('banking/transfers'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldUpdateTransfer()
|
||||
{
|
||||
// Create Revenue
|
||||
$revenue_request = $this->getRevenueRequest();
|
||||
$revenue = Revenue::create($revenue_request);
|
||||
|
||||
// Create Payment
|
||||
$payment_request = $this->getPaymentRequest();
|
||||
$payment = Payment::create($payment_request);
|
||||
|
||||
$request = $this->getTransferRequest($revenue, $payment);
|
||||
|
||||
$transfer = Transfer::create($request);
|
||||
|
||||
$request['description'] = $this->faker->text(10);
|
||||
|
||||
$this->loginAs()
|
||||
->patch(url('banking/transfers', ['transfer' => $transfer->id]), $request)
|
||||
->assertStatus(302)
|
||||
->assertRedirect(url('banking/transfers'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
private function getTransferRequest($revenue, $payment)
|
||||
{
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'revenue_id' => $revenue->id,
|
||||
'payment_id' => $payment->id,
|
||||
'from_account_id' => '1',
|
||||
'to_account_id' => '2',
|
||||
'amount' => '5',
|
||||
'transferred_at' => $this->faker->date(),
|
||||
'description'=> $this->faker->text(5),
|
||||
'payment_method' => 'offlinepayment.cash.1',
|
||||
'reference' => null,
|
||||
'currency_code' => setting('general.default_currency'),
|
||||
'currency_rate' => '1',
|
||||
];
|
||||
}
|
||||
|
||||
private function getRevenueRequest()
|
||||
{
|
||||
$attachment = UploadedFile::fake()->create('image.jpg');
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'customer_id' => '',
|
||||
'account_id' => setting('general.default_account'),
|
||||
'paid_at' => $this->faker->date(),
|
||||
'amount' => $this->faker->randomFloat(2, 2),
|
||||
'currency_code' => setting('general.default_currency'),
|
||||
'currency_rate' => '1',
|
||||
'description' => $this->faker->text(5),
|
||||
'category_id' => $this->company->categories()->type('income')->first()->id,
|
||||
'reference' => $this->faker->text(5),
|
||||
'payment_method' => setting('general.default_payment_method'),
|
||||
'attachment' => $attachment,
|
||||
];
|
||||
}
|
||||
|
||||
private function getPaymentRequest()
|
||||
{
|
||||
$attachment = UploadedFile::fake()->create('image.jpg');
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'account_id' => setting('general.default_account'),
|
||||
'vendor_id' => '',
|
||||
'paid_at' => $this->faker->date(),
|
||||
'amount' => $this->faker->randomFloat(2, 2),
|
||||
'currency_code' => setting('general.default_currency'),
|
||||
'currency_rate' => '1',
|
||||
'description' => $this->faker->text(5),
|
||||
'category_id' => $this->company->categories()->type('expense')->first()->id,
|
||||
'payment_method' => setting('general.default_payment_method'),
|
||||
'reference' => $this->faker->text(5),
|
||||
'attachment' => $attachment,
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user