<?php
/********************************************************************************
 * (c)1337 aheadware.com - All rights reserved
 ********************************************************************************/
require_once __DIR__ . '/../../src/server/config/boot_global.php';
require_once __DIR__ . '/../../src/server/config/boot_local.php';

function localCreateInvoiceForSubscriptionId( $subscriptionId, $periodStart = NULL, $periodEnd = NULL )
{
    // Set DB configuration for live teamdata access
    /*
    Francis_Utils_Config::set( 'db.tbteamdata.host', 'XXXXXXXXX' );
    Francis_Utils_Config::set( 'db.tbteamdata.name', 'd01c3281' );
    Francis_Utils_Config::set( 'db.tbteamdata.user', 'd01c3281' );
    Francis_Utils_Config::set( 'db.tbteamdata.pass', 'XXXXXXXXX' );
    */

    /** @var TB_Shared_Ent_TeamData_PremiumLog $entPremiumLog */
    $entPremiumLog = TB_Shared_Ent_TeamData_PremiumLog::getByBraintreeSubscriptionId( $subscriptionId );

    if ( $entPremiumLog instanceof TB_Shared_Ent_TeamData_PremiumLog )
    {
        TB_Server_Core_Premium::createInvoiceFromPremiumLog( $entPremiumLog, $periodStart, $periodEnd );
        echo "DONE...";
    }
    else
    {
        echo "INVALID SUBSCRIPTION ID";
    }
}

//$subscriptionId = 'bk5hww'; // IT-Autenriet
$subscriptionId = '2z852w'; // Fehren
$periodStart = new DateTime();
$periodEnd = new DateTime();
$periodEnd->add( new DateInterval( 'P1M' ) );

localCreateInvoiceForSubscriptionId( $subscriptionId, $periodStart, $periodEnd  );
