'int', 'shopping_order_id' => 'int', 'user_invoice_id' => 'int', 'month' => 'int', 'year' => 'int', 'points' => 'int', 'month_points' => 'int', 'month_shop_points' => 'int', 'total_net' => 'float', 'month_total_net' => 'float', 'month_shop_total_net' => 'float', 'status' => 'int' ]; protected $dates = [ 'date' ]; protected $fillable = [ 'user_id', 'shopping_order_id', 'user_invoice_id', 'month', 'year', 'date', 'points', 'month_points', 'month_shop_points', 'total_net', 'month_total_net', 'month_shop_total_net', 'message', 'status' ]; public static $statusTypes = [ 0 => 'nicht zugewiesen', 1 => 'hinzugefügt aus Bestellung', 2 => 'hinzugefügt aus Shop', 3 => 'hinzugefügt aus Shop / pending', 10 => '' ]; public function shopping_order() { return $this->belongsTo(ShoppingOrder::class); } public function user() { return $this->belongsTo(User::class); } public function user_invoice() { return $this->belongsTo(UserInvoice::class); } public function getDateAttribute(){ 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 getStatusType(){ return isset(self::$statusTypes[$this->status]) ? self::$statusTypes[$this->status] : ""; } public static function getStatusByOrder($ShoppingOrder){ if($ShoppingOrder->payment_for){ if($ShoppingOrder->payment_for === 6){ //Kunde-Shop if($ShoppingOrder->shopping_user && $ShoppingOrder->shopping_user->is_like){ return 3; //shop Kunden, berater zuordnen } return 2; } return 1; } return 0; } public function getFormatedMonthYear(){ return str_pad($this->month, 2, "0", STR_PAD_LEFT)."/".$this->year; } public function setToUserAndCalculate($user_id){ $month = $this->month; $year = $this->year; $month_shop_points = UserSalesVolume::where('user_id', $user_id)->where('status', 2)->where('month', $month)->where('year', $year)->sum('points'); $month_shop_total_net = UserSalesVolume::where('user_id', $user_id)->where('status', 2)->where('month', $month)->where('year', $year)->sum('total_net'); $month_points = UserSalesVolume::where('user_id', $user_id)->where('status', 1)->where('month', $month)->where('year', $year)->sum('points'); $month_total_net = UserSalesVolume::where('user_id', $user_id)->where('status', 1)->where('month', $month)->where('year', $year)->sum('total_net'); $month_shop_points += $this->points; $month_shop_total_net += $this->total_net; $this->user_id = $user_id; $this->month_shop_points = $month_shop_points; $this->month_shop_total_net = $month_shop_total_net; $this->month_points = $month_points; $this->month_total_net = $month_total_net; $this->status = 2; $this->save(); } }