Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Purchases
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 11 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
@@ -52,6 +52,16 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$this->view();
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
@@ -131,20 +141,23 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
/* Work stuff out */
|
||||
$renewals = $this->purchase->renewals ?: NULL;
|
||||
$groupedChildren = array();
|
||||
if ( $renewals and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_parent=? AND ps_grouped_renewals<>?', $this->purchase->id, '' ) )->first() )
|
||||
if ( $renewals and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_parent=? AND ps_grouped_renewals<>? AND ps_cancelled=0', $this->purchase->id, '' ) )->first() )
|
||||
{
|
||||
$costPerDay = $this->purchase->renewals->costPerDay()->amount;
|
||||
$renewals = $this->purchase->renewals;
|
||||
foreach ( $this->purchase->children() as $child )
|
||||
{
|
||||
if ( $child->grouped_renewals )
|
||||
if ( $child->grouped_renewals and !$child->cancelled )
|
||||
{
|
||||
$groupedChildren[] = $child;
|
||||
$childGroupedRenewals = $child->grouped_renewals;
|
||||
$childGroupedRenewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $childGroupedRenewals['price'], $this->purchase->renewals->cost->currency ), new \DateInterval( 'P' . $childGroupedRenewals['term'] . mb_strtoupper( $childGroupedRenewals['unit'] ) ) );
|
||||
$costPerDay -= $childGroupedRenewalTerm->costPerDay()->amount;
|
||||
try
|
||||
{
|
||||
$childGroupedRenewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $childGroupedRenewals['price'], $this->purchase->renewals->cost->currency ), new \DateInterval( 'P' . $childGroupedRenewals['term'] . mb_strtoupper( $childGroupedRenewals['unit'] ) ) );
|
||||
$renewals = new \IPS\nexus\Purchase\RenewalTerm( $renewals->subtract( $childGroupedRenewalTerm ), $renewals->interval );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
}
|
||||
$renewals = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $costPerDay * $renewals->days(), $this->purchase->renewals->cost->currency ), $renewals->interval );
|
||||
}
|
||||
|
||||
/* Build form */
|
||||
@@ -192,6 +205,10 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_grouped', '2X195/6', 403, '' );
|
||||
}
|
||||
if ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/G', 403, '' );
|
||||
}
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
@@ -223,21 +240,22 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
*/
|
||||
public function renew()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_edit', 'nexus', 'payments' );
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'invoices_add', 'nexus', 'payments' );
|
||||
|
||||
if ( $this->purchase->grouped_renewals )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_grouped', '2X195/7', 403, '' );
|
||||
}
|
||||
if ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/D', 403, '' );
|
||||
}
|
||||
|
||||
/* If this purchase has renewal term, we cannot generate a renewal invoice */
|
||||
if ( !$this->purchase->renewals )
|
||||
{
|
||||
\IPS\Output::i()->error( 'purchase_no_renew', '2X195/3', 403, '' );
|
||||
}
|
||||
if ( !$this->purchase->expire )
|
||||
{
|
||||
\IPS\Output::i()->error( 'purchase_no_expire', '1X195/C', 403, '' );
|
||||
}
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
@@ -290,9 +308,12 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
protected function cancel()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_cancel' );
|
||||
if ( $this->purchase->grouped_renewals )
|
||||
|
||||
$parent = $this->purchase->parent();
|
||||
|
||||
if ( ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled ) or ( $this->purchase->grouped_renewals and $parent->billing_agreement and !$parent->billing_agreement->canceled ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_grouped', '2X195/8', 403, '' );
|
||||
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/H', 403, '' );
|
||||
}
|
||||
|
||||
/* What options are available for cancelling? */
|
||||
@@ -307,12 +328,25 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'cancel_type', 'no_renew', FALSE, array(
|
||||
'options' => $options,
|
||||
'toggles' => array( 'cancel' => array( 'form_cancel_type_warning' ) )
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'ps_can_reactivate', FALSE ) );
|
||||
if ( $onCancelWarning = $this->purchase->onCancelWarning() )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['cancel_type_warning'] = $onCancelWarning;
|
||||
}
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* If grouped, ungroup */
|
||||
$grouped = $this->purchase->grouped_renewals;
|
||||
if ( $grouped )
|
||||
{
|
||||
$this->purchase->ungroupFromParent();
|
||||
$this->purchase->save();
|
||||
}
|
||||
|
||||
/* Update purchase and log */
|
||||
if ( $values['cancel_type'] === 'no_renew' )
|
||||
{
|
||||
@@ -327,6 +361,13 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
$this->purchase->can_reactivate = $values['ps_can_reactivate'];
|
||||
$this->purchase->save();
|
||||
|
||||
/* If grouped, regroup */
|
||||
if ( $grouped )
|
||||
{
|
||||
$this->purchase->groupWithParent();
|
||||
$this->purchase->save();
|
||||
}
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect();
|
||||
}
|
||||
@@ -343,15 +384,35 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
protected function reactivate()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_cancel' );
|
||||
if ( $this->purchase->grouped_renewals )
|
||||
|
||||
$parent = $this->purchase->parent();
|
||||
|
||||
if ( ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled ) or ( $this->purchase->grouped_renewals and $parent->billing_agreement and !$parent->billing_agreement->canceled ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_grouped', '2X195/9', 403, '' );
|
||||
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/I', 403, '' );
|
||||
}
|
||||
|
||||
/* If grouped, ungroup */
|
||||
$grouped = $this->purchase->grouped_renewals;
|
||||
if ( $grouped )
|
||||
{
|
||||
$this->purchase->ungroupFromParent();
|
||||
$this->purchase->save();
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
$this->purchase->cancelled = FALSE;
|
||||
$this->purchase->save();
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'uncancel', 'id' => $this->purchase->id, 'name' => $this->purchase->name ) );
|
||||
|
||||
/* If grouped, regroup */
|
||||
if ( $grouped )
|
||||
{
|
||||
$this->purchase->groupWithParent();
|
||||
$this->purchase->save();
|
||||
}
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect();
|
||||
}
|
||||
|
||||
@@ -363,16 +424,32 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
protected function delete()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_delete' );
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
|
||||
$parent = $this->purchase->parent();
|
||||
|
||||
if ( ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled ) or ( $this->purchase->grouped_renewals and $parent->billing_agreement and !$parent->billing_agreement->canceled ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/J', 403, '' );
|
||||
}
|
||||
|
||||
if ( $this->purchase->grouped_renewals )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_grouped', '2X195/A', 403, '' );
|
||||
$this->purchase->ungroupFromParent();
|
||||
$this->purchase->save();
|
||||
}
|
||||
|
||||
$this->purchase->member->log( 'purchase', array( 'type' => 'delete', 'id' => $this->purchase->id, 'name' => $this->purchase->name ) );
|
||||
$this->purchase->delete();
|
||||
|
||||
\IPS\Output::i()->redirect( $this->purchase->member->acpUrl() );
|
||||
if ( $parent )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $parent->acpUrl() );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->purchase->member->acpUrl() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -400,6 +477,11 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
protected function group()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
|
||||
if ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/E', 403, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->purchase->groupWithParent();
|
||||
@@ -420,6 +502,11 @@ class _purchases extends \IPS\Dispatcher\Controller
|
||||
protected function ungroup()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'purchases_edit' );
|
||||
if ( $this->purchase->billing_agreement and !$this->purchase->billing_agreement->canceled )
|
||||
{
|
||||
\IPS\Output::i()->error( 'not_with_billing_agreement', '2X195/F', 403, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->purchase->ungroupFromParent();
|
||||
|
||||
Reference in new issue
Block a user