Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

@@ -2,9 +2,9 @@
/**
* @brief Invoices
* @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 06 May 2014
* @version SVN_VERSION_NUMBER
@@ -38,12 +38,17 @@ class _invoices extends \IPS\Dispatcher\Controller
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
{
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
\IPS\Output::i()->redirect( \IPS\Request::i()->url()->setScheme('https') );
}
/* Load Invoice */
if ( isset( \IPS\Request::i()->id ) )
{
if ( isset( \IPS\Request::i()->printout ) )
{
\IPS\Request::i()->do = 'printout';
}
try
{
$this->invoice = \IPS\nexus\Invoice::loadAndCheckPerms( \IPS\Request::i()->id );
@@ -71,6 +76,11 @@ class _invoices extends \IPS\Dispatcher\Controller
\IPS\Output::i()->sidebar['enabled'] = FALSE;
parent::execute();
}
/**
* @brief Invoices Per Page
*/
protected static $invoicesPerPage = 25;
/**
* View List
@@ -90,9 +100,26 @@ class _invoices extends \IPS\Dispatcher\Controller
$where[] = $id;
}
}
$count = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices', $where )->first();
$page = isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1;
if ( $page < 1 )
{
$page = 1;
}
$pages = ( $count > 0 ) ? ceil( $count / static::$invoicesPerPage ) : 1;
if ( $page > $pages )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=clients&controller=invoices", 'front', 'clients' ) );
}
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( \IPS\Http\Url::internal( "app=nexus&module=clients&controller=invoices", 'front', 'clients' ), $pages, $page, static::$invoicesPerPage );
$invoices = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_invoices', $where, 'i_date DESC' ), 'IPS\nexus\Invoice' );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->invoices( $invoices );
$invoices = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_invoices', $where, 'i_date DESC', array( ( $page - 1 ) * static::$invoicesPerPage, static::$invoicesPerPage ) ), 'IPS\nexus\Invoice' );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->invoices( $invoices, $pagination );
}
/**
@@ -152,7 +179,21 @@ class _invoices extends \IPS\Dispatcher\Controller
*/
public function printout()
{
$output = \IPS\Theme::i()->getTemplate( 'invoices', 'nexus', 'global' )->printInvoice( $this->invoice, $this->invoice->summary() );
$address = NULL;
if ( $this->invoice->billaddress )
{
$address = $this->invoice->billaddress;
}
else
{
try
{
$address = \IPS\nexus\Customer\Address::constructFromData( \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( "member=? AND primary_billing=?", $this->invoice->member->member_id, 1 ) )->first() )->address;
}
catch( \UnderflowException $e ) {}
}
$output = \IPS\Theme::i()->getTemplate( 'invoices', 'nexus', 'global' )->printInvoice( $this->invoice, $this->invoice->summary(), $address );
\IPS\Output::i()->title = 'I' . $this->invoice->id;
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $output ) );
}
@@ -164,16 +205,40 @@ class _invoices extends \IPS\Dispatcher\Controller
*/
public function cancel()
{
/* CSRF check */
\IPS\Session::i()->csrfCheck();
/* Can only cancel the invoice if it's pending */
if ( $this->invoice->status !== \IPS\nexus\Invoice::STATUS_PENDING )
{
\IPS\Output::i()->error( 'order_already_paid', '2X215/4', 403, '' );
}
/* If they have already made a partial payment, refund it to their account credit */
foreach ( $this->invoice->transactions( array( \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED ) ) as $transaction )
{
try
{
$transaction->refund( 'credit' );
}
catch ( \Exception $e )
{
\IPS\Output::i()->error( 'order_cancel_error', '4C171/5', 500, $e->getMessage() );
}
}
/* Cancel the invoice */
$this->invoice->status = \IPS\nexus\invoice::STATUS_CANCELED;
$this->invoice->save();
$this->invoice->member->log( 'invoice', array( 'type' => 'status', 'new' => 'canc', 'id' => $this->invoice->id, 'title' => $this->invoice->title ) );
/* Run any callbacks (for example, coupons get unmarked as being used) */
foreach ( $this->invoice->items as $k => $item )
{
$item->onInvoiceCancel( $this->invoice );
}
$this->invoice->member->log( 'invoice', array( 'type' => 'status', 'new' => 'canc', 'id' => $this->invoice->id, 'title' => $this->invoice->title ) );
/* Redirect */
\IPS\Output::i()->redirect( $this->invoice->url() );
}
}