155 lines
4.7 KiB
PHP
155 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\DailySalePaymentReportModule\Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Tests\TestCase;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\DailySalePaymentReportModule\Entities\Customer;
|
|
|
|
class DailySalePaymentReportGenerateTest extends TestCase
|
|
{
|
|
/**
|
|
* A basic feature test example.
|
|
*
|
|
* @return void
|
|
*/
|
|
|
|
protected $reportDate;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
if (app()->environment() !== 'local') {
|
|
putenv('APP_ENV=local');
|
|
$_ENV['APP_ENV'] = 'local';
|
|
$_SERVER['APP_ENV'] = 'local';
|
|
}
|
|
DB::beginTransaction();
|
|
|
|
$this->reportDate = Carbon::today()->toDateString();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
DB::rollBack();
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**@test */
|
|
public function test_generate_report_button_loads_sales_and_credit_collection_data_correctly()
|
|
{
|
|
$cashier = User::factory()->create([
|
|
'name' => fake()->name(),
|
|
'is_active' => 1,
|
|
'is_deleted' => 0,
|
|
]);
|
|
|
|
$customer = Customer::factory()->create([
|
|
'name' => fake()->name(),
|
|
'customer_group_id' => 1,
|
|
]);
|
|
|
|
$cashOptionId = DB::table('payment_options')->insertGetId([
|
|
'name' => 'Cash',
|
|
'is_active' => 1,
|
|
]);
|
|
|
|
$card1OptionId = DB::table('payment_options')->insertGetId([
|
|
'name' => 'Card 1',
|
|
'is_active' => 1,
|
|
]);
|
|
|
|
$todaySaleId = DB::table('sales')->insertGetId([
|
|
'reference_no' => 'INV-TEST-' . fake()->unique()->numerify('####'),
|
|
'user_id' => $cashier->id,
|
|
'customer_id' => $customer->id,
|
|
'warehouse_id' => 1,
|
|
'item' => 1,
|
|
'total_qty' => 1,
|
|
'total_discount' => 0,
|
|
'total_tax' => 0,
|
|
'total_price' => 5000,
|
|
'grand_total' => 5000,
|
|
'sale_status' => 1,
|
|
'payment_status' => 1,
|
|
'due_amount' => 0,
|
|
'paid_amount' => 5000,
|
|
'created_at' => $this->reportDate . ' 10:00:00',
|
|
]);
|
|
|
|
DB::table('payments')->insert([
|
|
'payment_reference' => 'PAY-TEST-1',
|
|
'user_id' => $cashier->id,
|
|
'sale_id' => $todaySaleId,
|
|
'amount' => 5000,
|
|
'change' => 0,
|
|
'paying_method' => 'cash',
|
|
'payment_option_id' => $cashOptionId,
|
|
'created_at' => $this->reportDate . ' 10:00:00',
|
|
]);
|
|
|
|
$creditSaleId = DB::table('sales')->insertGetId([
|
|
'reference_no' => 'INV-TEST-' . fake()->unique()->numerify('####'),
|
|
'user_id' => $cashier->id,
|
|
'customer_id' => $customer->id,
|
|
'warehouse_id' => 1,
|
|
'item' => 1,
|
|
'total_qty' => 1,
|
|
'total_discount' => 0,
|
|
'total_tax' => 0,
|
|
'total_price' => 3000,
|
|
'grand_total' => 3000,
|
|
'sale_status' => 1,
|
|
'payment_status' => 0,
|
|
'due_amount' => 3000,
|
|
'paid_amount' => 0,
|
|
'created_at' => Carbon::parse($this->reportDate)->subDays(5)->format('Y-m-d H:i:s'),
|
|
]);
|
|
|
|
DB::table('payments')->insert([
|
|
'payment_reference' => 'PAY-TEST-2',
|
|
'user_id' => $cashier->id,
|
|
'sale_id' => $creditSaleId,
|
|
'amount' => 3000,
|
|
'change' => 0,
|
|
'paying_method' => 'card',
|
|
'payment_option_id' => $card1OptionId,
|
|
'created_at' => $this->reportDate . ' 14:00:00',
|
|
]);
|
|
|
|
$response = $this->actingAs($cashier)
|
|
->get('/dailysalepaymentreportmodule?report_date=' . $this->reportDate);
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee($customer->name);
|
|
$response->assertSee('5,000.00');
|
|
|
|
$response->assertSee('3,000.00');
|
|
|
|
$response->assertSee('Payment Method Summary');
|
|
$response->assertSee('8,000.00');
|
|
}
|
|
|
|
public function test_generate_report_shows_no_records_message_when_no_sales_exist_for_selected_date(){
|
|
$cashier = User::factory()->create([
|
|
'is_active' => 1,
|
|
'is_deleted' => 0,
|
|
]);
|
|
|
|
$emptyDate = Carbon::today()->subYears(5)->toDateString();
|
|
|
|
$response = $this->actingAs($cashier)
|
|
->get('/dailysalepaymentreportmodule?report_date=' . $emptyDate);
|
|
|
|
$response->assertStatus(200);
|
|
$response->assertSee('0.00');
|
|
}
|
|
|
|
}
|