'paymend_paid', 'appointed' => 'paymend_open', 'failed' => 'paymend_failed', 'extern' => 'extern_open', //offen 'extern_paid' => 'extern_paid', 'invoice_open' => 'invoice_open', 'invoice_paid' => 'invoice_paid', 'invoice_non' => 'invoice_no_payment', 'NULL' => 'no_payment', ]; public static function userHasAbo(User $user){ $user = $user ? $user : \Auth::user(); return UserAbo::where('user_id', $user->id)->where('is_for', 'me')->where('status', '>', 1)->first() === null ? false : true; } public static function memberHasAbo(ShoppingUser $shopping_user){ if(!$shopping_user){ return false; } return UserAbo::where('email', $shopping_user->billing_email)->where('is_for', 'ot')->where('status', '>', 1)->first() === null ? false : true; } public static function hasAboByEmail($email){ return UserAbo::where('email', $email)->where('status', '>', 1)->first() === null ? false : true; } public static function setAboStatus(ShoppingOrder $shopping_order, $status){ $user_abo = $shopping_order->getUserAbo(); if($user_abo && $user_abo->status < 2){ //status < 2 is not active $user_abo->update(['status' => $status]); } UserAboOrder::where('user_abo_id', $user_abo->id)->where('shopping_order_id', $shopping_order->id)->update(['status' => $status]); } public static function setAboActive(ShoppingOrder $shopping_order, $status){ self::setAboStatus($shopping_order, $status); //delete UserAbo is not active status = 1 //is_for = me UserAbo::where('user_id', $shopping_order->auth_user_id)->where('is_for', 'me')->where('status', 1)->delete(); //is_for = ot UserAbo::where('member_id', $shopping_order->member_id)->where('email', $shopping_order->shopping_user->billing_email)->where('is_for', 'ot')->where('status', 1)->delete(); } public static function aboHasBaseProduct($yard_products){ foreach($yard_products as $product){ if(is_array($product->options->show_on)){ if(in_array('12', $product->options->show_on)){ return true; } } } return false; } public static function getAboShowOn(Product $product){ $show_on = $product->show_on; if(in_array('12', $show_on)){ return 'base'; } if(in_array('13', $show_on)){ return 'upgrade'; } return false; } public static function getAboTypeBadge($abo_type){ if($abo_type === 'base'){ return ' '.__('abo.'.$abo_type).''; } if($abo_type === 'upgrade'){ return ' '.__('abo.'.$abo_type).''; } return ''; } public static function setNextDate($date, $abo_interval){ $nextDate = Carbon::parse($date)->firstOfMonth(); $nextDate->addDays($abo_interval-1); return $nextDate->gt($date) ? $nextDate : $nextDate->addMonth(1); } public static function createNewAbo(ShoppingPayment $shopping_payment){ //is Abo - create init Abo from PP or else if($shopping_payment->shopping_order->is_abo && $shopping_payment->shopping_order->abo_interval > 0){ $payment_transaction = $shopping_payment->payment_transactions->last(); $user_abo = UserAbo::create([ 'user_id' => $shopping_payment->shopping_order->auth_user_id, 'member_id' => $shopping_payment->shopping_order->member_id, 'shopping_user_id' => $shopping_payment->shopping_order->shopping_user_id, 'email' => $shopping_payment->shopping_order->shopping_user->billing_email, 'is_for' => $shopping_payment->shopping_order->shopping_user->is_for, 'payone_userid' => $payment_transaction->userid, 'clearingtype' => $shopping_payment->clearingtype, 'wallettype' => $shopping_payment->wallettype, 'carddata' => $shopping_payment->carddata, 'amount' => $shopping_payment->amount, 'status' => 1, 'abo_interval' => $shopping_payment->abo_interval, 'start_date' => now(), 'last_date' => now(), 'next_date' => self::setNextDate(now(), $shopping_payment->abo_interval), ]); if($user_abo){ self::createAboItems($user_abo, $shopping_payment); UserAboOrder::create([ 'user_abo_id' => $user_abo->id, 'shopping_order_id' => $shopping_payment->shopping_order_id, 'status' => 1, ]); } } } public static function createAboItems($user_abo, ShoppingPayment $shopping_payment){ foreach($shopping_payment->shopping_order->shopping_order_items as $item){ UserAboItem::create([ 'user_abo_id' => $user_abo->id, 'product_id' => $item->product_id, 'comp' => $item->comp ?? 0, 'qty' => $item->qty, 'status' => 1, ]); } } public static function getTransStatusFilterText(){ $ret = []; foreach(self::$txaction_filter_text as $key=>$val){ $ret[$key] = trans('payment.'.$val); } return $ret; } }