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 Coupon Node
|
||||
* @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 Mar 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
@@ -49,6 +49,11 @@ class _Coupon extends \IPS\Node\Model
|
||||
*/
|
||||
protected static $databaseIdFields = array( 'c_code' );
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
* @code
|
||||
@@ -148,11 +153,11 @@ class _Coupon extends \IPS\Node\Model
|
||||
{
|
||||
return !( $node instanceof \IPS\nexus\Package\Group );
|
||||
} ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'c_renewals', $this->renewals, FALSE, array(), NULL, NULL, NULL, 'c_renewals' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'c_renewals', $this->renewals ?: FALSE, FALSE, array(), NULL, NULL, NULL, 'c_renewals' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'c_limit_discount', $this->limit_discount, FALSE, array( 'options' => array( 0 => 'c_limit_discount_no', 1 => 'c_limit_discount_yes' ) ), NULL, NULL, NULL, 'c_limit_discount' ) );
|
||||
|
||||
$form->addHeader( 'coupon_dates' );
|
||||
$form->add( new \IPS\Helpers\Form\Date( 'c_start', $this->id ? $this->start : \IPS\DateTime::ts( time() ), FALSE, array( 'time' => TRUE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Date( 'c_start', $this->id ? $this->start : \IPS\DateTime::ts( time() ), TRUE, array( 'time' => TRUE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Date( 'c_end', $this->id ? $this->end : 0, FALSE, array( 'time' => TRUE, 'unlimited' => 0, 'unlimitedLang' => 'no_end_date' ) ) );
|
||||
|
||||
$form->addHeader( 'coupon_restrictions' );
|
||||
@@ -331,18 +336,23 @@ class _Coupon extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
/* Restricted to products? */
|
||||
$items = NULL;
|
||||
if ( $this->products !== '*' )
|
||||
{
|
||||
$allowedProductIds = explode( ',', $this->products );
|
||||
$hasAllowedProduct = FALSE;
|
||||
$productTotal = 0;
|
||||
$productTotal = new \IPS\Math\Number('0');
|
||||
|
||||
foreach ( $invoice->items as $item )
|
||||
$items = array();
|
||||
|
||||
foreach ( $invoice->items as $k => $item )
|
||||
{
|
||||
if ( $item instanceof \IPS\nexus\extensions\nexus\Item\Package and in_array( $item->id, $allowedProductIds ) )
|
||||
{
|
||||
$hasAllowedProduct = TRUE;
|
||||
$productTotal += $item->price->amount;
|
||||
$productTotal = $productTotal->add( $item->price->amount );
|
||||
|
||||
$items[] = $k;
|
||||
}
|
||||
elseif ( $this->renewals and $item instanceof \IPS\nexus\Invoice\Item\Renewal )
|
||||
{
|
||||
@@ -352,7 +362,9 @@ class _Coupon extends \IPS\Node\Model
|
||||
if ( $purchase->app == 'nexus' and $purchase->type == 'package' and in_array( $purchase->item_id, $allowedProductIds ) )
|
||||
{
|
||||
$hasAllowedProduct = TRUE;
|
||||
$productTotal += $item->price->amount;
|
||||
$productTotal = $productTotal->add( $item->price->amount );
|
||||
|
||||
$items[] = $k;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
@@ -377,22 +389,23 @@ class _Coupon extends \IPS\Node\Model
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $this->limit_discount )
|
||||
if ( $this->limit_discount and isset( $productTotal ) )
|
||||
{
|
||||
$base = $productTotal;
|
||||
}
|
||||
else
|
||||
{
|
||||
$base = $invoice->total->amount;
|
||||
$summary = $invoice->summary();
|
||||
$base = $summary['subtotal']->amount;
|
||||
}
|
||||
|
||||
$discount = new \IPS\nexus\Money( -( $base / 100 * $this->discount ), $invoice->currency );
|
||||
|
||||
$discount = new \IPS\nexus\Money( $base->percentage( new \IPS\Math\Number( $this->discount ) )->multiply( new \IPS\Math\Number( '-1' ) ), $invoice->currency );
|
||||
}
|
||||
|
||||
/* Never allow a discount greater than the invoice total */
|
||||
if ( $discount->amount < -$invoice->total->amount )
|
||||
if ( $discount->amount->multiply( new \IPS\Math\Number( '-1' ) )->compare( $invoice->total->amount ) === 1 )
|
||||
{
|
||||
$discount = new \IPS\nexus\Money( -$invoice->total->amount, $invoice->currency );
|
||||
$discount = new \IPS\nexus\Money( $invoice->total->amount->multiply( new \IPS\Math\Number( '-1' ) ), $invoice->currency );
|
||||
}
|
||||
|
||||
/* Save that we've used it */
|
||||
@@ -411,6 +424,9 @@ class _Coupon extends \IPS\Node\Model
|
||||
$item = new \IPS\nexus\extensions\nexus\Item\CouponDiscount( $this->code, $discount );
|
||||
$item->id = $this->id;
|
||||
$item->extra['usedBy'] = $customer->member_id;
|
||||
$item->extra['type'] = $this->unit;
|
||||
$item->extra['value'] = $this->unit === 'v' ? $discount->amount : $this->discount;
|
||||
$item->extra['items'] = $items;
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user