generate report test

This commit is contained in:
SUM2046
2026-07-06 15:25:45 +05:30
parent 720752a781
commit a4a7b09c10
3 changed files with 223 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace Modules\DailySalePaymentReportModule\Database\factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class CustomerFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = \Modules\DailySalePaymentReportModule\Entities\Customer::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
//
];
}
}

42
Entities/Customer.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
namespace Modules\DailySalePaymentReportModule\Entities;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Customer extends Model
{
use HasFactory;
protected $fillable = [
"customer_group_id",
"user_id",
"name",
"company_name",
"email",
"phone_number",
"tax_no",
"address",
"city",
"state",
"postal_code",
"country",
"customer_route",
"points",
"deposit",
"expense",
"is_active",
"credit_limit",
"document",
"employee_id",
"payable_account_id",
"receivable_account_id",
"customer_area_id"
];
protected static function newFactory()
{
return \Modules\DailySalePaymentReportModule\Database\factories\CustomerFactory::new();
}
}

View File

@@ -0,0 +1,154 @@
<?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');
}
}