#51 Festschreiben der Points, Gutschriftenmodul
This commit is contained in:
parent
dfd049aaa9
commit
3f2fbd6d5b
63 changed files with 4610 additions and 971 deletions
172
app/Models/UserCredit.php
Normal file
172
app/Models/UserCredit.php
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* Class UserCredit
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int|null $month
|
||||
* @property int|null $year
|
||||
* @property Carbon|null $date
|
||||
* @property string|null $full_number
|
||||
* @property int|null $number
|
||||
* @property float|null $net
|
||||
* @property float|null $tax_rate
|
||||
* @property float|null $tax
|
||||
* @property float|null $total
|
||||
* @property string|null $filename
|
||||
* @property string|null $dir
|
||||
* @property string|null $disk
|
||||
* @property array|null $infos
|
||||
* @property bool $paid_out
|
||||
* @property Carbon|null $paid_out_date
|
||||
* @property bool $cancellation
|
||||
* @property int|null $cancellation_id
|
||||
* @property Carbon|null $cancellation_date
|
||||
* @property int $status
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property string|null $deleted_at
|
||||
*
|
||||
* @property User $user
|
||||
* @property Collection|UserCreditItem[] $user_credit_items
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class UserCredit extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
protected $table = 'user_credits';
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'month' => 'int',
|
||||
'year' => 'int',
|
||||
'number' => 'int',
|
||||
'net' => 'float',
|
||||
'tax_rate' => 'float',
|
||||
'tax' => 'float',
|
||||
'taxable' => 'bool',
|
||||
'total' => 'float',
|
||||
'paid_out' => 'bool',
|
||||
'cancellation' => 'bool',
|
||||
'cancellation_id' => 'int',
|
||||
'status' => 'int',
|
||||
'infos' => 'array'
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'date',
|
||||
'paid_out_date',
|
||||
'cancellation_date'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'month',
|
||||
'year',
|
||||
'date',
|
||||
'full_number',
|
||||
'number',
|
||||
'net',
|
||||
'tax_rate',
|
||||
'tax',
|
||||
'total',
|
||||
'taxable',
|
||||
'filename',
|
||||
'dir',
|
||||
'disk',
|
||||
'infos',
|
||||
'paid_out',
|
||||
'paid_out_date',
|
||||
'cancellation',
|
||||
'cancellation_id',
|
||||
'cancellation_date',
|
||||
'status'
|
||||
];
|
||||
|
||||
public static $statusTypes = [
|
||||
0 => 'offen',
|
||||
1 => 'bezahlt',
|
||||
2 => 'prüfen',
|
||||
10 => 'storniert'
|
||||
];
|
||||
|
||||
public static $statusColors = [
|
||||
0 => 'warning',
|
||||
1 => 'success',
|
||||
2 => 'secondary',
|
||||
10 => 'danger',
|
||||
];
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function user_credit_items()
|
||||
{
|
||||
return $this->hasMany(UserCreditItem::class);
|
||||
}
|
||||
|
||||
public function isCredit(){
|
||||
return $this->filename ? true : false;
|
||||
}
|
||||
|
||||
public function getDateAttribute($value)
|
||||
{
|
||||
return $value ? Carbon::parse($value)->format(\Util::formatDateDB()) : "";
|
||||
}
|
||||
|
||||
|
||||
public function setDateAttribute( $value ) {
|
||||
$this->attributes['date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
||||
}
|
||||
public function getDateRaw(){
|
||||
return isset($this->attributes['date']) ? $this->attributes['date'] : NULL;
|
||||
}
|
||||
|
||||
public function getFormattedTax()
|
||||
{
|
||||
return formatNumber($this->attributes['tax']);
|
||||
}
|
||||
|
||||
public function getFormattedNet()
|
||||
{
|
||||
return formatNumber($this->attributes['net']);
|
||||
}
|
||||
|
||||
public function getFormattedTotal()
|
||||
{
|
||||
return formatNumber($this->attributes['total']);
|
||||
}
|
||||
|
||||
|
||||
public function getStatusType(){
|
||||
return isset(self::$statusTypes[$this->status]) ? self::$statusTypes[$this->status] : "";
|
||||
}
|
||||
|
||||
public function getStatusColor(){
|
||||
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
|
||||
}
|
||||
|
||||
public function getDownloadPath($full = false){
|
||||
if(!$full){
|
||||
return $this->dir.$this->filename;
|
||||
}
|
||||
return \Storage::disk($this->disk)->path($this->dir.$this->filename);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue