Update Framework, Invoices

This commit is contained in:
Kevin Adametz 2022-04-14 13:14:36 +02:00
parent cc5c147c27
commit 9b0b5feb7e
174 changed files with 28356 additions and 8093 deletions

183
app/Models/UserInvoice.php Normal file
View file

@ -0,0 +1,183 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class UserInvoice
*
* @property int $id
* @property int $shopping_order_id
* @property int|null $month
* @property int|null $year
* @property Carbon|null $date
* @property string|null $full_number
* @property int|null $number
* @property string|null $file
* @property string|null $infos
* @property bool $paid
* @property Carbon|null $paid_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 ShoppingOrder $shopping_order
*
* @package App\Models
*/
class UserInvoice extends Model
{
use SoftDeletes;
protected $table = 'user_invoices';
protected $casts = [
'shopping_order_id' => 'int',
'month' => 'int',
'year' => 'int',
'number' => 'int',
'paid' => 'bool',
'cancellation' => 'bool',
'cancellation_id' => 'int',
'status' => 'int',
'infos' => 'array',
];
protected $dates = [
'date',
'paid_date',
'cancellation_date'
];
protected $fillable = [
'shopping_order_id',
'month',
'year',
'date',
'full_number',
'number',
'filename',
'dir',
'delivery_filename',
'delivery_dir',
'disk',
'infos',
'paid',
'paid_date',
'cancellation',
'cancellation_id',
'cancellation_date',
'status'
];
public static $monthNames = [
1 => 'Januar',
2 => 'Februar',
3 => 'März',
4 => 'April',
5 => 'Mai',
6 => 'Juni',
7 => 'Juli',
8 => 'August',
9 => 'September',
10 => 'Oktober',
11 => 'November',
12 => 'Dezember'
];
public static $statusTypes = [
0 => '-',
1 => 'Bestellung',
2 => 'Shop',
11 => 'storniert B.',
12 => 'storniert Shop',
];
public static $statusColors = [
0 => 'warning',
1 => 'success',
2 => 'secondary',
11 => 'danger',
12 => 'danger',
];
public function shopping_order(){
return $this->belongsTo(ShoppingOrder::class);
}
public function getDateAttribute($value){
return $this->attributes['date'] ? Carbon::parse($this->attributes['date'])->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 getPaidDateAttribute($value){
return $this->attributes['paid_date'] ? Carbon::parse($this->attributes['paid_date'])->format(\Util::formatDateDB()) : '';
}
public function setPaidDateAttribute( $value ) {
$this->attributes['paid_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getPaidDateRaw(){
return isset($this->attributes['paid_date']) ? $this->attributes['paid_date'] : NULL;
}
public function getCancellationDateAttribute($value){
return $this->attributes['cancellation_date'] ? Carbon::parse($this->attributes['cancellation_date'])->format(\Util::formatDateDB()) : '';
}
public function setCancellationDateAttribute( $value ) {
$this->attributes['cancellation_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getCancellationDateRaw(){
return isset($this->attributes['cancellation_date']) ? $this->attributes['cancellation_date'] : NULL;
}
public static function getYearRange()
{
$start = 2021;
$end = date("Y");
return array_reverse(range($start, $end));
}
public static function getMonthName($month)
{
return isset(self::$monthNames[$month]) ? self::$monthNames[$month] : $month;
}
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);
}
public function getDownloadPathDelivery($full = false){
if(!$full){
return $this->delivery_dir.$this->delivery_filename;
}
return \Storage::disk($this->disk)->path($this->delivery_dir.$this->delivery_filename);
}
}