Exemplo n.º 1
0
 /**
  * Create or update an invoice from a subscription
  *
  * @param   object  $sub  The subscription record
  *
  * @return  bool
  */
 public function createInvoice($sub)
 {
     // Do we already have an invoice record?
     $db = $this->getDbo();
     $query = $db->getQuery(true)->select('*')->from($db->qn('#__akeebasubs_invoices'))->where($db->qn('akeebasubs_subscription_id') . ' = ' . $db->q($sub->akeebasubs_subscription_id));
     $db->setQuery($query);
     $invoiceRecord = $db->loadObject();
     $existingRecord = is_object($invoiceRecord);
     // Flag to know if the template allows me to create an invoice
     $preventInvoice = false;
     $invoiceData = array();
     // Preload helper classes
     if (!class_exists('AkeebasubsHelperCparams')) {
         require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/cparams.php';
     }
     if (!class_exists('AkeebasubsHelperFormat')) {
         require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/format.php';
     }
     if (!class_exists('AkeebasubsHelperMessage')) {
         require_once JPATH_ROOT . '/components/com_akeebasubs/helpers/message.php';
     }
     // Get the template
     $templateRow = $this->findTemplate($sub);
     if (is_object($templateRow)) {
         $template = $templateRow->template;
         $templateId = $templateRow->akeebasubs_invoicetemplate_id;
         $globalFormat = $templateRow->globalformat;
         $globalNumbering = $templateRow->globalnumbering;
         // Do I have a "no invoice" flag?
         $preventInvoice = (bool) $templateRow->noinvoice;
     } else {
         $template = '';
         $templateId = 0;
         $globalFormat = true;
         $globalNumbering = true;
     }
     // Do I have a "no invoice" flag on template or subscription?
     $sub_params = new JRegistry($sub->params);
     if ($preventInvoice || $sub_params->get('noinvoice', false)) {
         $sub_params->set('noinvoice', true);
         // I have to manually update the db, using the table object will cause an endless loop
         $query = $db->getQuery(true)->update('#__akeebasubs_subscriptions')->set($db->qn('params') . ' = ' . $db->quote((string) $sub_params))->where($db->qn('akeebasubs_subscription_id') . ' = ' . $sub->akeebasubs_subscription_id);
         $db->setQuery($query)->query();
         return false;
     }
     if ($globalFormat) {
         $numberFormat = AkeebasubsHelperCparams::getParam('invoice_number_format', '[N:5]');
     } else {
         $numberFormat = $templateRow->format;
     }
     if ($globalNumbering) {
         $numberOverride = AkeebasubsHelperCparams::getParam('invoice_override', 0);
     } else {
         $numberOverride = $templateRow->number_reset;
     }
     // Get the configuration variables
     if (!$existingRecord) {
         $jInvoiceDate = JFactory::getDate();
         $invoiceData = array('akeebasubs_subscription_id' => $sub->akeebasubs_subscription_id, 'extension' => 'akeebasubs', 'invoice_date' => $jInvoiceDate->toSql(), 'enabled' => 1, 'created_on' => $jInvoiceDate->toSql(), 'created_by' => $sub->user_id);
         if ($numberOverride) {
             // There's an override set. Use it and reset the override to 0.
             $invoice_no = $numberOverride;
             if ($globalNumbering) {
                 // Global number override reset
                 AkeebasubsHelperCparams::setParam('invoice_override', 0);
             } else {
                 // Invoice template number override reset
                 $templateTable = F0FModel::getTmpInstance('Invoicetemplates', 'AkeebasubsModel')->getItem($templateRow->akeebasubs_invoicetemplate_id);
                 $templateTable->save(array('number_reset' => 0));
             }
         } else {
             if ($globalNumbering) {
                 // Find all the invoice template IDs using Global Numbering and filter by them
                 $q = $db->getQuery(true)->select($db->qn('akeebasubs_invoicetemplate_id'))->from($db->qn('#__akeebasubs_invoicetemplates'))->where($db->qn('globalnumbering') . ' = ' . $db->q(1));
                 $db->setQuery($q);
                 $rawIDs = $db->loadColumn();
                 $gnitIDs = array();
                 foreach ($rawIDs as $id) {
                     $gnitIDs[] = $db->q($id);
                 }
             }
             // Get the new invoice number by adding one to the previous number
             $query = $db->getQuery(true)->select($db->qn('invoice_no'))->from($db->qn('#__akeebasubs_invoices'))->where($db->qn('extension') . ' = ' . $db->q('akeebasubs'))->order($db->qn('created_on') . ' DESC');
             // When not using global numbering search only invoices using this specific invoice template
             if (!$globalNumbering) {
                 $query->where($db->qn('akeebasubs_invoicetemplate_id') . ' = ' . $db->q($templateId));
             } else {
                 $query->where($db->qn('akeebasubs_invoicetemplate_id') . ' IN(' . implode(',', $gnitIDs) . ')');
             }
             $db->setQuery($query, 0, 1);
             $invoice_no = (int) $db->loadResult();
             if (empty($invoice_no)) {
                 $invoice_no = 0;
             }
             $invoice_no++;
         }
         // Parse the invoice number
         $formated_invoice_no = $this->formatInvoiceNumber($numberFormat, $invoice_no, $jInvoiceDate->toUnix());
         // Add the invoice number (plain and formatted) to the record
         $invoiceData['invoice_no'] = $invoice_no;
         $invoiceData['display_number'] = $formated_invoice_no;
         // Add the invoice template ID to the record
         $invoiceData['akeebasubs_invoicetemplate_id'] = $templateId;
     } else {
         // Existing record, make sure it's extension=akeebasubs or quit
         if ($invoiceRecord->extension != 'akeebasubs') {
             $this->setId(0);
             return false;
         }
         $invoice_no = $invoiceRecord->invoice_no;
         $formated_invoice_no = $invoiceRecord->display_number;
         if (empty($formated_invoice_no)) {
             $formated_invoice_no = $invoice_no;
         }
         $jInvoiceDate = JFactory::getDate($invoiceRecord->invoice_date);
         $invoiceData = (array) $invoiceRecord;
     }
     // Get the custom variables
     $vat_notice = '';
     $cyprus_tag = 'TRIANGULAR TRANSACTION';
     $cyprus_note = 'We are obliged by local tax laws to write the words "triangular transaction" on all invoices issued in Euros. This doesn\'t mean anything in particular about your transaction.';
     $kuser = F0FModel::getTmpInstance('Users', 'AkeebasubsModel')->user_id($sub->user_id)->getFirstItem();
     $country = $kuser->country;
     $isbusiness = $kuser->isbusiness;
     $viesregistered = $kuser->viesregistered;
     $inEU = in_array($country, array('AT', 'BE', 'BG', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'GB', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'));
     if ($inEU && $isbusiness && $viesregistered) {
         $vat_notice = AkeebasubsHelperCparams::getParam('invoice_vatnote', 'VAT liability is transferred to the recipient, pursuant EU Directive nr 2006/112/EC and local tax laws implementing this directive.');
         $cyprus_tag = 'REVERSE CHARGE';
         $cyprus_note = 'We are obliged by local and European tax laws to write the words "reverse charge" on all invoices issued to EU business when no VAT is charged. This is supposed to serve as a reminder that the recipient of the invoice (you) have to be registered to your local VAT office so as to apply to YOUR business\' VAT form the VAT owed by this transaction on the reverse charge basis, as described above. The words "reverse charge" DO NOT indicate a problem with your transaction, a cancellation or a refund.';
     }
     $extras = array('[INV:ID]' => $invoice_no, '[INV:PLAIN_NUMBER]' => $invoice_no, '[INV:NUMBER]' => $formated_invoice_no, '[INV:INVOICE_DATE]' => AkeebasubsHelperFormat::date($jInvoiceDate->toUnix()), '[INV:INVOICE_DATE_EU]' => $jInvoiceDate->format('d/m/Y', true), '[INV:INVOICE_DATE_USA]' => $jInvoiceDate->format('m/d/Y', true), '[INV:INVOICE_DATE_JAPAN]' => $jInvoiceDate->format('Y/m/d', true), '[VAT_NOTICE]' => $vat_notice, '[CYPRUS_TAG]' => $cyprus_tag, '[CYPRUS_NOTE]' => $cyprus_note);
     // Render the template into HTML
     $invoiceData['html'] = AkeebasubsHelperMessage::processSubscriptionTags($template, $sub, $extras);
     // Save the record
     if ($existingRecord) {
         $o = (object) $invoiceData;
         $db->updateObject('#__akeebasubs_invoices', $o, 'akeebasubs_subscription_id');
     } else {
         $o = (object) $invoiceData;
         $db->insertObject('#__akeebasubs_invoices', $o);
     }
     // Set up the return value
     $ret = $invoice_no;
     $this->setId($sub->akeebasubs_subscription_id);
     // Create PDF
     $this->createPDF();
     // Update subscription record with the invoice number without saving the
     // record through the Model, as this triggers the integration plugins,
     // which in turn causes double emails to be sent out. Baazinga!
     $query = $db->getQuery(true)->update($db->qn('#__akeebasubs_subscriptions'))->set($db->qn('akeebasubs_invoice_id') . ' = ' . $db->q($invoice_no))->where($db->qn('akeebasubs_subscription_id') . ' = ' . $db->q($sub->akeebasubs_subscription_id));
     $db->setQuery($query);
     $db->execute();
     $sub->akeebasubs_invoice_id = $invoice_no;
     // If auto-send is enabled, send the invoice by email
     $autoSend = AkeebasubsHelperCparams::getParam('invoice_autosend', 1);
     if ($autoSend) {
         $this->emailPDF();
     }
     return true;
 }
Exemplo n.º 2
0
				<img src="<?php 
    echo AkeebasubsHelperImage::getURL($level->image);
    ?>
" />
			</td>
		<?php 
}
?>
		</tr>
		<tr>
		<?php 
foreach ($this->items as $level) {
    ?>
			<td class="akeebasubs-strappy-description">
				<?php 
    echo JHTML::_('content.prepare', AkeebasubsHelperMessage::processLanguage($level->description));
    ?>
			</td>
		<?php 
}
?>
		</tr>
		<tr>
		<?php 
foreach ($this->items as $level) {
    ?>
			<td class="akeebasubs-strappy-subscribe">
				<button
					class="btn btn-inverse btn-primary"
					onclick="window.location='<?php 
    echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug=' . $level->slug . '&format=html&layout=default');
Exemplo n.º 3
0
 /**
  * Creates a mailer instance, preloads its subject and body with your email
  * data based on the key and extra substitution parameters and waits for
  * you to send a recipient and send the email.
  *
  * @param   object  $sub     The subscription record against which the email is sent
  * @param   string  $key     The email key, in the form PLG_LOCATION_PLUGINNAME_TYPE
  * @param   array   $extras  Any optional substitution strings you want to introduce
  *
  * @return  boolean|PHPMailer False if something bad happened, the PHPMailer instance in any other case
  */
 public static function getPreloadedMailer($sub, $key, array $extras = array())
 {
     // Load the template
     list($isHTML, $subject, $templateText, $loadLanguage) = self::loadEmailTemplate($key, $sub->akeebasubs_level_id, JFactory::getUser($sub->user_id));
     if (empty($subject)) {
         return false;
     }
     // Substitute variables in $templateText and $subject
     if (!class_exists('AkeebasubsHelperMessage')) {
         $included = @(include_once JPATH_ROOT . '/components/com_akeebasubs/helpers/message.php');
         if (!$included) {
             return false;
         }
     }
     $templateText = AkeebasubsHelperMessage::processSubscriptionTags($templateText, $sub, $extras);
     $subject = AkeebasubsHelperMessage::processSubscriptionTags($subject, $sub, $extras);
     // Get the mailer
     $mailer = self::getMailer($isHTML);
     $mailer->setSubject($subject);
     // Include inline images
     $pattern = '/(src)=\\"([^"]*)\\"/i';
     $number_of_matches = preg_match_all($pattern, $templateText, $matches, PREG_OFFSET_CAPTURE);
     if ($number_of_matches > 0) {
         $substitutions = $matches[2];
         $last_position = 0;
         $temp = '';
         // Loop all URLs
         $imgidx = 0;
         $imageSubs = array();
         foreach ($substitutions as &$entry) {
             // Copy unchanged part, if it exists
             if ($entry[1] > 0) {
                 $temp .= substr($templateText, $last_position, $entry[1] - $last_position);
             }
             // Examine the current URL
             $url = $entry[0];
             if (substr($url, 0, 7) == 'http://' || substr($url, 0, 8) == 'https://') {
                 // External link, skip
                 $temp .= $url;
             } else {
                 $ext = strtolower(JFile::getExt($url));
                 if (!JFile::exists($url)) {
                     // Relative path, make absolute
                     $url = dirname($template) . '/' . ltrim($url, '/');
                 }
                 if (!JFile::exists($url) || !in_array($ext, array('jpg', 'png', 'gif'))) {
                     // Not an image or inexistent file
                     $temp .= $url;
                 } else {
                     // Image found, substitute
                     if (!array_key_exists($url, $imageSubs)) {
                         // First time I see this image, add as embedded image and push to
                         // $imageSubs array.
                         $imgidx++;
                         $mailer->AddEmbeddedImage($url, 'img' . $imgidx, basename($url));
                         $imageSubs[$url] = $imgidx;
                     }
                     // Do the substitution of the image
                     $temp .= 'cid:img' . $imageSubs[$url];
                 }
             }
             // Calculate next starting offset
             $last_position = $entry[1] + strlen($entry[0]);
         }
         // Do we have any remaining part of the string we have to copy?
         if ($last_position < strlen($templateText)) {
             $temp .= substr($templateText, $last_position);
         }
         // Replace content with the processed one
         $templateText = $temp;
     }
     $mailer->setBody($templateText);
     return $mailer;
 }
Exemplo n.º 4
0
/**
 *  @package FrameworkOnFramework
 *  @copyright Copyright (c)2010-2014 Nicholas K. Dionysopoulos
 *  @license GNU General Public License version 3, or later
 */
// Protect from unauthorized access
defined('_JEXEC') or die;
$this->loadHelper('cparams');
$this->loadHelper('modules');
$this->loadHelper('format');
$this->loadHelper('message');
// Translate message
$message = AkeebasubsHelperMessage::processLanguage($this->item->ordertext);
// Parse merge tags
$message = AkeebasubsHelperMessage::processSubscriptionTags($message, $this->subscription);
// Process content plugins
$message = JHTML::_('content.prepare', $message);
?>

<?php 
if (AkeebasubsHelperCparams::getParam('stepsbar', 1) && $this->subscription->prediscount_amount > 0.01) {
    echo $this->loadAnyTemplate('level/steps', array('step' => 'done'));
}
?>

<h1 class="componentheading">
	<?php 
echo $this->escape(JText::_('COM_AKEEBASUBS_MESSAGE_THANKYOU'));
?>
</h1>
Exemplo n.º 5
0
    /**
     * Returns the payment form to be submitted by the user's browser. The form must have an ID of
     * "paymentForm" and a visible submit button.
     *
     * @param string $paymentmethod
     * @param JUser $user
     * @param AkeebasubsTableLevel $level
     * @param AkeebasubsTableSubscription $subscription
     * @return string
     */
    public function onAKPaymentNew($paymentmethod, $user, $level, $subscription)
    {
        if ($paymentmethod != $this->ppName) {
            return false;
        }
        // Set the payment status to Pending
        $oSub = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->setId($subscription->akeebasubs_subscription_id)->getItem();
        $updates = array('state' => 'P', 'enabled' => 0, 'processor_key' => md5(time()));
        $oSub->save($updates);
        // Activate the user account, if the option is selected
        $activate = $this->params->get('activate', 0);
        if ($activate && $user->block) {
            $updates = array('block' => 0, 'activation' => '');
            $user->bind($updates);
            $user->save($updates);
        }
        // Render the HTML form
        $nameParts = explode(' ', $user->name, 2);
        $firstName = $nameParts[0];
        if (count($nameParts) > 1) {
            $lastName = $nameParts[1];
        } else {
            $lastName = '';
        }
        $html = $this->params->get('instructions', '');
        if (empty($html)) {
            $html = <<<ENDTEMPLATE
<p>Dear Sir/Madam,<br/>
In order to complete your payment, please deposit {AMOUNT}€ to our bank account:</p>
<p>
<b>IBAN</b>: XX00.000000.00000000.00000000<br/>
<b>BIC</b>: XXXXXXXX
</p>
<p>Please reference subscription code {SUBSCRIPTION} in your payment. Make sure that any bank charges are paid by you in full and not deducted from the transferred amount. If you're using e-Banking to transfer the funds, please select the "OUR" bank expenses option.</p>
<p>Thank you in advance,<br/>
The management</p>
ENDTEMPLATE;
        }
        $html = str_replace('{AMOUNT}', sprintf('%01.02f', $subscription->gross_amount), $html);
        $html = str_replace('{SUBSCRIPTION}', sprintf('%06u', $subscription->akeebasubs_subscription_id), $html);
        $html = str_replace('{FIRSTNAME}', $firstName, $html);
        $html = str_replace('{LASTNAME}', $lastName, $html);
        $html = str_replace('{LEVEL}', $level->title, $html);
        // Get a preloaded mailer
        $mailer = AkeebasubsHelperEmail::getPreloadedMailer($subscription, 'plg_akeebasubs_subscriptionemails_offline');
        // Replace custom [INSTRUCTIONS] tag
        $body = str_replace('[INSTRUCTIONS]', $html, $mailer->Body);
        $mailer->setBody($body);
        if ($mailer !== false) {
            $mailer->addRecipient($user->email);
            $result = $mailer->Send();
            $mailer = null;
        }
        @(include_once JPATH_SITE . '/components/com_akeebasubs/helpers/message.php');
        if (class_exists('AkeebasubsHelperMessage')) {
            $html = AkeebasubsHelperMessage::processLanguage($html);
        }
        $html = '<div>' . $html . '</div>';
        return $html;
    }