app/Actions/Billing/GenerateInvoice.php
/***
     *Check for queued subscription to be activated for account and if there is one then activate it
     */
Check for queued subscription to be activated for account and if there is one then activate it
Check for queued subscription to be activated for account and if there is one then activate it
public static function isQueuedSubscriptionImplemented($subscription)
    {
        self::$commandObject->info(
            "Checking for queued subscriptions for " .
                $subscription["account"]["registration_number"]
        );
        $account = $subscription->account_id;
        $queuedSubscription = Subscription::where("account_id", $account)
            ->queue()
            ->latest()
            ->first();
        if ($queuedSubscription) {
            self::$commandObject->info(
                "Queued subscription found for changing plan from " .
                    $subscription["plan"]["name"] .
                    " to " .
                    $queuedSubscription->plan->name .
                    " for " .
                    $subscription["account"]["registration_number"]
            );
            self::$commandObject->info(
                "Updating ongoing subscription with queued subscription details for " .
                    $subscription["account"]["registration_number"]
            );
            $ongoingSubscription = Subscription::where("account_id", $account)
                ->active()
                ->latest()
                ->first();
            self::$commandObject->info(
                "Start and end date of Ongoing subscription " .
                    $ongoingSubscription->start_date .
                    " - " .
                    $ongoingSubscription->end_date
            );
            $ongoingSubscription->status = 4;
            $ongoingSubscription->save();
            self::$commandObject->info(
                "Start and end date of queued/new subscription " .
                    $queuedSubscription->start_date .
                    " - " .
                    $queuedSubscription->end_date
            );
            $queuedSubscription->status = 1;
            $queuedSubscription->save();
            self::$commandObject->info(
                "Update done for " .
                    $subscription["account"]["registration_number"] .
                    "and new plan is " .
                    $queuedSubscription->plan->name
            );
            return $queuedSubscription;
        }
        self::$commandObject->info(
            "Queued subscription not found for " .
                $subscription["account"]["registration_number"]
        );
        return false;
    }
public static function isQueuedSubscriptionImplemented ( $ subscription ) { self :: $ commandObject -> info ( " Checking for queued subscriptions for  " . $ subscription [ " account " ] [ " registration_number " ] ) ; $ account = $ subscription -> account_id ; $ queuedSubscription = Subscription :: where ( " account_id " , $ account ) -> queue ( ) -> latest ( ) -> first ( ) ; if ( $ queuedSubscription ) { self :: $ commandObject -> info ( " Queued subscription found for changing plan from  " . $ subscription [ " plan " ] [ " name " ] . "  to  " . $ queuedSubscription -> plan -> name . "  for  " . $ subscription [ " account " ] [ " registration_number " ] ) ; self :: $ commandObject -> info ( " Updating ongoing subscription with queued subscription details for  " . $ subscription [ " account " ] [ " registration_number " ] ) ; $ ongoingSubscription = Subscription :: where ( " account_id " , $ account ) -> active ( ) -> latest ( ) -> first ( ) ; self :: $ commandObject -> info ( " Start and end date of Ongoing subscription  " . $ ongoingSubscription -> start_date . "  -  " . $ ongoingSubscription -> end_date ) ; $ ongoingSubscription -> status = 4 ; $ ongoingSubscription -> save ( ) ; self :: $ commandObject -> info ( " Start and end date of queued/new subscription  " . $ queuedSubscription -> start_date . "  -  " . $ queuedSubscription -> end_date ) ; $ queuedSubscription -> status = 1 ; $ queuedSubscription -> save ( ) ; self :: $ commandObject -> info ( " Update done for  " . $ subscription [ " account " ] [ " registration_number " ] . " and new plan is  " . $ queuedSubscription -> plan -> name ) ; return $ queuedSubscription ; } self :: $ commandObject -> info ( " Queued subscription not found for  " . $ subscription [ " account " ] [ " registration_number " ] ) ; return false ; }
Check for queued subscription to be activated for account and if there is one then activate it
Check for queued subscription to be activated for account and if there is one then activate it
//get the active , latest and first subscription. // As of now, customer can have one active subscription at a time but then also we are picking latest and first //            $ongoingSubscription->plan_id = $queuedSubscription->plan_id; //            $ongoingSubscription->start_date = $queuedSubscription->start_date; //            $ongoingSubscription->end_date = $queuedSubscription->end_date; //            $ongoingSubscription->charge = $queuedSubscription->charge; //make the queue subscription as active