app/Actions/Billing/GenerateInvoice.php
/**
     * Generate Bill - by defaults it picks today's date for bill generation but can be passed specific date
     * if the batch fails for a specific day
     */
Generate Bill - by defaults it picks today's date for bill generation but can be passed specific date
if the batch fails for a specific day
Generate Bill - by defaults it picks today ' s date for bill generation but can be passed specific date if the batch fails for a specific day
public static function generateBill($object, $billGenerationDate = null)
    {
        self::$commandObject = $object;
        $todaysDate = Carbon::now();
        self::$commandObject->newLine();
        if ($billGenerationDate) {
            self::$commandObject->info(
                "Bill Generation started for " . $billGenerationDate
            );
        } else {
            self::$commandObject->info(
                "Bill Generation started for " . $todaysDate->format("m/d/Y")
            );
        }
        $subscriptions = self::getActiveSubscriptionsWithAccountDetails(
            $billGenerationDate
        );
        self::$commandObject->newLine();
        self::$commandObject->info(
            "Count of members (subscriptions) for which bill would be generated " .
                $subscriptions->count()
        );
        foreach ($subscriptions as $subscription) {
            self::$commandObject->info("---------------------");
            self::$commandObject->info(
                "Running processing for membership number " .
                    $subscription["account"]["registration_number"]
            );
            DB::beginTransaction();
            try {
                $newSubscriptionEnabled = self::isQueuedSubscriptionImplemented(
                    $subscription
                );
                if (!$newSubscriptionEnabled) {
                    $updatedSubscription = self::extendSubscriptionEndDate(
                        $subscription
                    );
                } else {
                    $updatedSubscription = $newSubscriptionEnabled;
                }
                $bill = self::createBillingEntry(
                    $subscription,
                    $updatedSubscription
                );
                self::updateOutstandingPayment($bill);
                self::$commandObject->info(
                    "Queuing email delivery for " .
                    $subscription["account"]["contact"]["email"]
                );
                Mail::to($subscription["account"]["contact"]["email"])
                    ->send(
                        new BillGenerated( $subscription["account"]["id"], $bill, $updatedSubscription)
                    );
                self::$commandObject->newLine(1);
                DB::commit();
            } catch (\Exception $exception) {
                DB::rollback();
                self::$commandObject->error(
                    "Processing failed for membership number " .
                        $subscription["account"]
                );
                self::$commandObject->error("Exception Details " . $exception);
            }
            self::$commandObject->info("---------------------");
        }
        self::$commandObject->newLine();
        self::$commandObject->info("Exiting from bill generation process");
    }
public static function generateBill ( $ object , $ billGenerationDate = null ) { self :: $ commandObject = $ object ; $ todaysDate = Carbon :: now ( ) ; self :: $ commandObject -> newLine ( ) ; if ( $ billGenerationDate ) { self :: $ commandObject -> info ( " Bill Generation started for  " . $ billGenerationDate ) ; } else { self :: $ commandObject -> info ( " Bill Generation started for  " . $ todaysDate -> format ( " m/d/Y " ) ) ; } $ subscriptions = self :: getActiveSubscriptionsWithAccountDetails ( $ billGenerationDate ) ; self :: $ commandObject -> newLine ( ) ; self :: $ commandObject -> info ( " Count of members (subscriptions) for which bill would be generated  " . $ subscriptions -> count ( ) ) ; foreach ( $ subscriptions as $ subscription ) { self :: $ commandObject -> info ( " --------------------- " ) ; self :: $ commandObject -> info ( " Running processing for membership number  " . $ subscription [ " account " ] [ " registration_number " ] ) ; DB :: beginTransaction ( ) ; try { $ newSubscriptionEnabled = self :: isQueuedSubscriptionImplemented ( $ subscription ) ; if ( ! $ newSubscriptionEnabled ) { $ updatedSubscription = self :: extendSubscriptionEndDate ( $ subscription ) ; } else { $ updatedSubscription = $ newSubscriptionEnabled ; } $ bill = self :: createBillingEntry ( $ subscription , $ updatedSubscription ) ; self :: updateOutstandingPayment ( $ bill ) ; self :: $ commandObject -> info ( " Queuing email delivery for  " . $ subscription [ " account " ] [ " contact " ] [ " email " ] ) ; Mail :: to ( $ subscription [ " account " ] [ " contact " ] [ " email " ] ) -> send ( new BillGenerated ( $ subscription [ " account " ] [ " id " ] , $ bill , $ updatedSubscription ) ) ; self :: $ commandObject -> newLine ( 1 ) ; DB :: commit ( ) ; } catch ( \ Exception $ exception ) { DB :: rollback ( ) ; self :: $ commandObject -> error ( " Processing failed for membership number  " . $ subscription [ " account " ] ) ; self :: $ commandObject -> error ( " Exception Details  " . $ exception ) ; } self :: $ commandObject -> info ( " --------------------- " ) ; } self :: $ commandObject -> newLine ( ) ; self :: $ commandObject -> info ( " Exiting from bill generation process " ) ; }
Generate Bill - by defaults it picks today's date for bill generation but can be passed specific date
 if the batch fails for a specific day
Generate Bill - by defaults it picks today ' s date for bill generation but can be passed specific date if the batch fails for a specific day
// get all active subscriptions with associated account details with end date equal to today's date or passed date // loop through all the active subscriptions // Check if there is any queued subscription available for update for the account // if there is one then update the make the queued subscription as active and ongoing as inactive // and use new subscription for bill generation // if no queued subscription found then extend the existing subscription else use the updated existing subscription //create new bill //update outstanding amount in account's table with new billed amount // TODO send email on failure