Update Framework, Invoices
This commit is contained in:
parent
cc5c147c27
commit
9b0b5feb7e
174 changed files with 28356 additions and 8093 deletions
152
app/Models/UserSalesVolume.php
Normal file
152
app/Models/UserSalesVolume.php
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\ShoppingOrder;
|
||||
|
||||
/**
|
||||
* Class UserSalesVolume
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int|null $shopping_order_id
|
||||
* @property int|null $month
|
||||
* @property int|null $year
|
||||
* @property Carbon|null $date
|
||||
* @property int|null $points
|
||||
* @property int|null $month_points
|
||||
* @property float|null $total_net
|
||||
* @property float|null $month_total_net
|
||||
* @property string|null $message
|
||||
* @property int $status
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property ShoppingOrder|null $shopping_order
|
||||
* @property User $user
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class UserSalesVolume extends Model
|
||||
{
|
||||
protected $table = 'user_sales_volumes';
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => '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();
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue