sarga/packages/Webkul/Sales/src/Database/Factories/InvoiceFactory.php

96 lines
2.5 KiB
PHP
Raw Normal View History

2020-01-23 12:11:47 +00:00
<?php
namespace Webkul\Sales\Database\Factories;
2020-01-23 12:11:47 +00:00
use Webkul\Sales\Models\Invoice;
use Webkul\Sales\Models\Order;
use Webkul\Sales\Models\OrderAddress;
use Illuminate\Database\Eloquent\Factories\Factory;
2020-01-23 12:11:47 +00:00
class InvoiceFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Invoice::class;
2020-01-23 12:11:47 +00:00
/**
* @var array
*/
protected $states = [
'pending',
'paid',
'refunded',
2020-01-23 12:11:47 +00:00
];
/**
* Define the model's default state.
*
* @return array
*/
public function definition(): array
{
2021-10-06 12:26:08 +00:00
$subTotal = $this->faker->randomFloat(2);
2022-08-08 13:10:37 +00:00
$shippingAmount = $this->faker->randomFloat(2);
2022-08-08 13:10:37 +00:00
2021-10-06 12:26:08 +00:00
$taxAmount = $this->faker->randomFloat(2);
2020-01-23 12:11:47 +00:00
2022-08-08 13:10:37 +00:00
if (! isset($attributes['order_id'])) {
$attributes['order_id'] = Order::factory();
}
2022-08-08 13:10:37 +00:00
if (! isset($attributes['order_address_id'])) {
$attributes['order_address_id'] = OrderAddress::factory();
}
return [
2022-08-08 13:10:37 +00:00
'email_sent' => 0,
'total_qty' => $this->faker->randomNumber(),
'base_currency_code' => 'EUR',
'channel_currency_code' => 'EUR',
2022-08-08 13:10:37 +00:00
'order_currency_code' => 'EUR',
'sub_total' => $subTotal,
'base_sub_total' => $subTotal,
'grand_total' => $subTotal,
'base_grand_total' => $subTotal,
'shipping_amount' => $shippingAmount,
'base_shipping_amount' => $shippingAmount,
'tax_amount' => $taxAmount,
'base_tax_amount' => $taxAmount,
'discount_amount' => 0,
'base_discount_amount' => 0,
'order_id' => $attributes['order_id'],
'order_address_id' => $attributes['order_address_id'],
];
}
2020-01-23 12:11:47 +00:00
public function pending(): InvoiceFactory
{
return $this->state(function (array $attributes) {
return [
'status' => 'pending',
];
});
}
public function paid(): InvoiceFactory
{
return $this->state(function (array $attributes) {
return [
'status' => 'paid',
];
});
}
public function refunded(): InvoiceFactory
{
return $this->state(function (array $attributes) {
return [
'status' => 'refunded',
];
});
}
}