<?php

if ( ($NomineeIdsinMyaccount == '') && ($NomineeIdsinCheckout == '') ) {
    if ( $enabledisablemaxpoints == 'yes' ) {
        $this->check_point_restriction( $restrictuserpoints , $productlevelrewardpointss , $pointsredeemed , $event_slug , $orderuserid , $nomineeid   = '' , $referrer_id = '' , $productid , $variationid , $reasonindetail ) ;
    } else {
        $equearnamt     = RSPointExpiry::earning_conversion_settings( $productlevelrewardpointss ) ;
        $valuestoinsert = array( 'pointstoinsert'    => $productlevelrewardpointss ,
            'pointsredeemed'    => 0 ,
            'event_slug'        => $event_slug ,
            'equalearnamnt'     => $equearnamt ,
            'equalredeemamnt'   => 0 ,
            'user_id'           => $orderuserid ,
            'referred_id'       => '' ,
            'product_id'        => $productid ,
            'variation_id'      => $variationid ,
            'reasonindetail'    => $reasonindetail ,
            'nominee_id'        => '' ,
            'nominee_points'    => '' ,
            'totalearnedpoints' => $productlevelrewardpointss ,
            'totalredeempoints' => 0 ) ;
        $this->total_points_management( $valuestoinsert ) ;
    }
} elseif ( ($NomineeIdsinMyaccount != '' && $EnableNomineeinMyaccount == 'yes') && ($NomineeIdsinCheckout != '') ) {
    $nomineeid   = $orderuserid ;
    $orderuserid = $NomineeIdsinCheckout ;
    $this->insert_points_for_product( $enabledisablemaxpoints , $order_id , $orderuserid , $nomineeid , $productlevelrewardpointss , $productid , $variationid , $reasonindetail ) ;
} elseif ( ($NomineeIdsinMyaccount != '' && $EnableNomineeinMyaccount == 'yes') && ($NomineeIdsinCheckout == '') ) {
    $nomineeid   = $orderuserid ;
    $orderuserid = $NomineeIdsinMyaccount ;
    $this->insert_points_for_product( $enabledisablemaxpoints , $order_id , $orderuserid , $nomineeid , $productlevelrewardpointss , $productid , $variationid , $reasonindetail ) ;
} elseif ( ($NomineeIdsinMyaccount != '' && $EnableNomineeinMyaccount == 'no') && ($NomineeIdsinCheckout != '') ) {
    $nomineeid   = $orderuserid ;
    $orderuserid = $NomineeIdsinCheckout ;
    $this->insert_points_for_product( $enabledisablemaxpoints , $order_id , $orderuserid , $nomineeid , $productlevelrewardpointss , $productid , $variationid , $reasonindetail ) ;
} elseif ( ($NomineeIdsinMyaccount != '' && $EnableNomineeinMyaccount == 'no') && ($NomineeIdsinCheckout == '') ) {
    if ( $enabledisablemaxpoints == 'yes' ) {
        $this->check_point_restriction( $restrictuserpoints , $productlevelrewardpointss , $pointsredeemed , $event_slug , $orderuserid , $nomineeid   = '' , $referrer_id = '' , $productid , $variationid , $reasonindetail ) ;
    } else {
        $equearnamt     = RSPointExpiry::earning_conversion_settings( $productlevelrewardpointss ) ;
        $valuestoinsert = array( 'pointstoinsert'    => $productlevelrewardpointss ,
            'pointsredeemed'    => 0 ,
            'event_slug'        => $event_slug ,
            'equalearnamnt'     => $equearnamt ,
            'equalredeemamnt'   => 0 ,
            'user_id'           => $orderuserid ,
            'referred_id'       => '' ,
            'product_id'        => $productid ,
            'variation_id'      => $variationid ,
            'reasonindetail'    => $reasonindetail ,
            'nominee_id'        => '' ,
            'nominee_points'    => '' ,
            'totalearnedpoints' => $productlevelrewardpointss ,
            'totalredeempoints' => 0 ) ;
        $this->total_points_management( $valuestoinsert ) ;
    }
} elseif ( ($NomineeIdsinMyaccount == '') && ($NomineeIdsinCheckout != '') ) {
    $nomineeid   = $orderuserid ;
    $orderuserid = $NomineeIdsinCheckout ;
    $this->insert_points_for_product( $enabledisablemaxpoints , $order_id , $orderuserid , $nomineeid , $productlevelrewardpointss , $productid , $variationid , $reasonindetail ) ;
}
if ( $orderuserid != 0 )
    update_order_meta_if_points_awarded( $order_id , $orderuserid ) ;
