Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -52,6 +52,14 @@ class _expireInvoices extends \IPS\Task
|
||||
$invoice->status = $invoice::STATUS_EXPIRED;
|
||||
$invoice->save();
|
||||
|
||||
/* Send tracked notifications */
|
||||
foreach ( \IPS\Db::i()->select( 'member_id', 'nexus_invoice_tracker', array( 'invoice_id=?', $invoice->id ) ) as $trackingMember )
|
||||
{
|
||||
$trackingMember = \IPS\Member::load( $trackingMember );
|
||||
\IPS\Email::buildFromTemplate( 'nexus', 'invoiceTrackExpired', array( $invoice, $invoice->summary( $trackingMember->language() ) ), \IPS\Email::TYPE_LIST )
|
||||
->send( $trackingMember );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$invoice->member->log( 'invoice', array(
|
||||
|
||||
@@ -39,6 +39,7 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
/* Get purchases grouped by member and currency */
|
||||
$select = $this->_getSelectQuery();
|
||||
$log = \IPS\Db::_replaceBinds( $select->query, $select->binds ) . "\n" . \count( $select ) . " matches\n\n";
|
||||
$availableTaxes = \IPS\nexus\Tax::roots();
|
||||
|
||||
$groupedPurchases = array();
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\nexus\Purchase' ) as $purchase )
|
||||
@@ -104,8 +105,8 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
$log .= "Invoice {$invoice->id} generated... ";
|
||||
|
||||
/* Try to take payment automatically, but *only* if we have a billing address (i.e. the customer has a primary billing address set)
|
||||
otherwise we don't know how we're taxing this and the customer will need to manually come and pay it */
|
||||
if ( $invoice->billaddress )
|
||||
otherwise we don't know how we're taxing this and the customer will need to manually come and pay it - we can skip this if tax has not been configured */
|
||||
if ( $invoice->billaddress OR \count( $availableTaxes ) === 0 )
|
||||
{
|
||||
/* Nothing to pay? */
|
||||
if ( $invoice->amountToPay()->amount->isZero() )
|
||||
@@ -127,41 +128,51 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
$credit = $credits[$currency]->amount;
|
||||
if( $credit->isGreaterThanZero() )
|
||||
{
|
||||
$log .= "{$credit} account credit available... ";
|
||||
|
||||
if ( $credit->compare( $invoice->total->amount ) === 1 )
|
||||
$take = NULL;
|
||||
/* If credit is equal or larger than invoice value */
|
||||
if ( \in_array( $credit->compare( $invoice->total->amount ), [ 0, 1 ] ) )
|
||||
{
|
||||
$take = $invoice->total->amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
$take = $credit;
|
||||
/* Only use credit if amount remaining is greater than card gateway min amount */
|
||||
if( $invoice->total->amount->subtract( $credit ) > new \IPS\Math\Number( '0.50' ) )
|
||||
{
|
||||
$take = $credit;
|
||||
}
|
||||
}
|
||||
|
||||
$transaction = new \IPS\nexus\Transaction;
|
||||
$transaction->member = $member;
|
||||
$transaction->invoice = $invoice;
|
||||
$transaction->amount = new \IPS\nexus\Money( $take, $currency );
|
||||
$transaction->extra = array('automatic' => TRUE);
|
||||
$transaction->save();
|
||||
$transaction->approve();
|
||||
|
||||
$log .= "Transaction {$transaction->id} generated... ";
|
||||
|
||||
$member->log( 'transaction', array(
|
||||
'type' => 'paid',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_PAID,
|
||||
'id' => $transaction->id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'invoice_title' => $invoice->title,
|
||||
'automatic' => TRUE,
|
||||
), FALSE );
|
||||
|
||||
$credits[$currency]->amount = $credits[$currency]->amount->subtract( $take );
|
||||
$member->cm_credits = $credits;
|
||||
$member->save();
|
||||
|
||||
$invoice->status = $transaction->invoice->status;
|
||||
|
||||
if( $take )
|
||||
{
|
||||
$log .= "{$credit} account credit available... ";
|
||||
|
||||
$transaction = new \IPS\nexus\Transaction;
|
||||
$transaction->member = $member;
|
||||
$transaction->invoice = $invoice;
|
||||
$transaction->amount = new \IPS\nexus\Money( $take, $currency );
|
||||
$transaction->extra = array('automatic' => TRUE);
|
||||
$transaction->save();
|
||||
$transaction->approve();
|
||||
|
||||
$log .= "Transaction {$transaction->id} generated... ";
|
||||
|
||||
$member->log( 'transaction', array(
|
||||
'type' => 'paid',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_PAID,
|
||||
'id' => $transaction->id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'invoice_title' => $invoice->title,
|
||||
'automatic' => TRUE,
|
||||
), FALSE );
|
||||
|
||||
$credits[$currency]->amount = $credits[$currency]->amount->subtract( $take );
|
||||
$member->cm_credits = $credits;
|
||||
$member->save();
|
||||
|
||||
$invoice->status = $transaction->invoice->status;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,9 +296,11 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
$renewalDate->add( new \DateInterval( 'PT' . \IPS\Settings::i()->cm_invoice_generate . 'H' ) );
|
||||
}
|
||||
|
||||
return \IPS\Db::i()->select( 'nexus_purchases.*', 'nexus_purchases', array(
|
||||
"ps_cancelled=0 AND ps_renewals>0 AND ps_invoice_pending=0 AND ps_active=1 AND ps_expire>0 AND ps_expire<? AND ps_billing_agreement IS NULL AND ( ps_grouped_renewals='' OR ps_grouped_renewals IS NULL )",
|
||||
$renewalDate->getTimestamp()
|
||||
), 'ps_member', 50 );
|
||||
return \IPS\Db::i()->select( 'ps.*', [ 'nexus_purchases', 'ps' ],
|
||||
[
|
||||
"ps_cancelled=0 AND ps_renewals>0 AND ps_invoice_pending=0 AND ps_active=1 AND ps_expire>0 AND ps_expire<? AND (ps_billing_agreement IS NULL OR ba.ba_canceled=1) AND ( ps_grouped_renewals='' OR ps_grouped_renewals IS NULL )",
|
||||
$renewalDate->getTimestamp()
|
||||
], 'ps_member', 50 )
|
||||
->join( [ 'nexus_billing_agreements', 'ba' ], 'ps.ps_billing_agreement=ba.ba_id' );
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,8 @@ class _sendInvoiceWarnings extends \IPS\Task
|
||||
|
||||
if ( $billingAgreement->status() == $billingAgreement::STATUS_CANCELED )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
/* BA is cancelled, don't include it in the email */
|
||||
$billingAgreement = NULL;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
|
||||
Reference in new issue
Block a user