GET /mnoe/jpi/v1/admin/invoices/current_billing_amount
776272
def current_billing_amount
      # Backward compatibility with old MnoHub (<= v1.0.2)
      # TODO: Remove once all mnohub are migrated to newer versions
      tenant.respond_to?(:current_billing_amount) && current_billing = tenant.current_billing_amount

      render json: {current_billing_amount: format_money(current_billing)}
    end
1271244
public function index()
    {
        if (!userHasPermission('admin:invoice:payment:view')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        //  Set method info
        $this->data['page']->title = 'Manage Payments';

        // --------------------------------------------------------------------------

        $oInput         = Factory::service('Input');
        $oDriverService = Factory::service('PaymentDriver', 'nails/module-invoice');
        $oPaymentModel  = Factory::model('Payment', 'nails/module-invoice');
        $oInvoiceModel  = Factory::model('Invoice', 'nails/module-invoice');

        // --------------------------------------------------------------------------

        $sTableAlias = $oPaymentModel->getTableAlias();

        //  Get pagination and search/sort variables
        $iPage      = $oInput->get('page') ? $oInput->get('page') : 0;
        $iPerPage   = $oInput->get('perPage') ? $oInput->get('perPage') : 50;
        $sSortOn    = $oInput->get('sortOn') ? $oInput->get('sortOn') : $sTableAlias . '.created';
        $sSortOrder = $oInput->get('sortOrder') ? $oInput->get('sortOrder') : 'desc';
        $sKeywords  = $oInput->get('keywords') ? $oInput->get('keywords') : '';

        // --------------------------------------------------------------------------

        //  Define the sortable columns
        $sortColumns = [
            $sTableAlias . '.created'    => 'Received Date',
            $sTableAlias . '.driver'     => 'Payment Gateway',
            $sTableAlias . '.invoice_id' => 'Invoice ID',
            $sTableAlias . '.txn_id'     => 'Transaction ID',
            $sTableAlias . '.amount'     => 'Amount',
            $sTableAlias . '.currency'   => 'Currency',
        ];

        // --------------------------------------------------------------------------

        //  Define the filters
        $aCbFilters = [];
        $aOptions   = [];
        $aDrivers   = $oDriverService->getAll();

        foreach ($aDrivers as $sSlug => $oDriver) {
            $aOptions[] = [
                $oDriver->name,
                $sSlug,
                true,
            ];
        }

        $aCbFilters[] = Helper::searchFilterObject(
            $sTableAlias . '.driver',
            'Gateway',
            $aOptions
        );

        $aCbFilters[] = Helper::searchFilterObject(
            $sTableAlias . '.status',
            'Status',
            $oPaymentModel->getStatusesHuman()
        );

        // --------------------------------------------------------------------------

        //  Define the $aData variable for the queries
        $aData = [
            'sort'      => [
                [$sSortOn, $sSortOrder],
            ],
            'keywords'  => $sKeywords,
            'cbFilters' => $aCbFilters,
        ];

        //  Get the items for the page
        $totalRows                   = $oPaymentModel->countAll($aData);
        $this->data['payments']      = $oPaymentModel->getAll($iPage, $iPerPage, $aData);
        $this->data['invoiceStates'] = $oInvoiceModel->getStates();

        //  Set Search and Pagination objects for the view
        $this->data['search']     = Helper::searchObject(true, $sortColumns, $sSortOn, $sSortOrder, $iPerPage, $sKeywords, $aCbFilters);
        $this->data['pagination'] = Helper::paginationObject($iPage, $iPerPage, $totalRows);

        // --------------------------------------------------------------------------

        //  Add a header button
        if (userHasPermission('admin:invoice:invoice:create')) {
            Helper::addHeaderButton(
                'admin/invoice/invoice/create',
                'Create Invoice'
            );
        }

        // --------------------------------------------------------------------------

        Helper::loadView('index');
    }
397543
def getTotalPaid(self, auction_id, buyer_id):
        """"""
        # TODO: it has to be better way to check payments.
        date_end = long(time.time())
        date_start = date_end - 60 * 60 * 24 * 90
        rc = self.__ask__('doGetMyIncomingPayments',
                          buyerId=buyer_id,
                          itemId=auction_id,
                          transRecvDateFrom=date_start,
                          transRecvDateTo=date_end,
                          transPageLimit=25,  # notneeded | TODO: can be more than 25 payments
                          transOffset=0)
        paid = 0
        for t in (rc or []):
            # t = t['item']
            if t['payTransStatus'] == u'Zakończona' and t['payTransIncomplete'] == 0:
                if t['payTransItId'] == 0:  # wplata laczna
                    for td in t['payTransDetails']['item']:
                        if td['payTransDetailsItId'] == auction_id:
                            paid += Decimal(str(td['payTransDetailsPrice']))
                else:  # wplata pojedyncza
                    paid += Decimal(str(t['payTransAmount']))
        return paid
1028859
public function getPending()
    {
        $dqb = $this->_em->createQueryBuilder();
        $dqb->select(array('j'))
            ->from('PlaygroundCore\Entity\Cronjob', 'j')
            ->where($dqb->expr()->in('j.status', array(self::STATUS_PENDING)))
            ->orderBy('j.scheduleTime', 'ASC');

        return $dqb->getQuery()->getResult();
    }
281245
protected function getAmount()
    {
        $request = $this->getRequest();
        return !is_null($request->getRequestParameter(self::MC_GROSS)) ? abs($request->getRequestParameter(self::MC_GROSS)) : null;
    }
1283868
int getAllPuCount() {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "getAllPuCount", this);
        int rtnCount = 0;

        synchronized (pxmlsInfo) {
            for (JPAPxmlInfo pxmlInfo : pxmlsInfo.values()) {
                rtnCount += pxmlInfo.getPuCount();
            }
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "getAllPuCount : " + rtnCount);
        return rtnCount;
    }
1359003
def getDiscountAmount(self):
        
        has_client_discount = self.aq_parent.getMemberDiscountApplies()
        if has_client_discount:
            discount = Decimal(self.getDefaultMemberDiscount())
            return Decimal(self.getSubtotal() * discount / 100)
        else:
            return 0
370229
public int getInvoicesCount(final QueryParams params) {
        FluentCaseInsensitiveStringsMap map = doHEAD(Invoices.INVOICES_RESOURCE, params);
        return Integer.parseInt(map.getFirstValue(X_RECORDS_HEADER_NAME));
    }
1240469
def get_quota_remaining(self):
        """"""
        api = self._get_api(billing.DefaultApi)
        quota = api.get_service_package_quota()
        return None if quota is None else int(quota.quota)
490747
public function index()
    {
        if (!userHasPermission('admin:invoice:invoice:manage')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        //  Are we dealing with a filtered view?
        $oInput         = Factory::service('Input');
        $oCustomerModel = Factory::model('Customer', 'nails/module-invoice');
        $iCustomerId    = $oInput->get('customer_id');

        if ($iCustomerId) {
            $oCustomer = $oCustomerModel->getbyId($iCustomerId);
        }

        // --------------------------------------------------------------------------

        //  Set method info
        $this->data['page']->title = empty($oCustomer) ? 'Manage Invoices' : possessive($oCustomer->label) . ' invoices';

        // --------------------------------------------------------------------------

        $sTableAlias = $this->oInvoiceModel->getTableAlias();

        //  Get pagination and search/sort variables
        $iPage      = $oInput->get('page') ? $oInput->get('page') : 0;
        $iPerPage   = $oInput->get('perPage') ? $oInput->get('perPage') : 50;
        $sSortOn    = $oInput->get('sortOn') ? $oInput->get('sortOn') : $sTableAlias . '.created';
        $sSortOrder = $oInput->get('sortOrder') ? $oInput->get('sortOrder') : 'desc';
        $sKeywords  = $oInput->get('keywords') ? $oInput->get('keywords') : '';

        // --------------------------------------------------------------------------

        //  Define the sortable columns
        $aSortColumns = [
            $sTableAlias . '.created'  => 'Created Date',
            $sTableAlias . '.modified' => 'Modified Date',
            $sTableAlias . '.state'    => 'Invoice State',
        ];

        // --------------------------------------------------------------------------

        //  Define the filters
        $aCbFilters = [];

        //  States
        $aStateOptions = [];
        $aStates       = $this->oInvoiceModel->getStates();

        foreach ($aStates as $sState => $sLabel) {
            $aStateOptions[] = [
                $sLabel,
                $sState,
                true,
            ];
        }

        $aCbFilters[] = Helper::searchFilterObject(
            $sTableAlias . '.state',
            'State',
            $aStateOptions
        );

        //  Currencies
        $oCurrency        = Factory::service('Currency', 'nails/module-currency');
        $aCurrencyOptions = [];
        $aCurrencies      = $oCurrency->getAllEnabled();

        foreach ($aCurrencies as $oCurrency) {
            $aCurrencyOptions[] = [
                $oCurrency->code,
                $oCurrency->code,
                true,
            ];
        }

        $aCbFilters[] = Helper::searchFilterObject(
            $sTableAlias . '.currency',
            'Currency',
            $aCurrencyOptions
        );

        // --------------------------------------------------------------------------

        //  Define the $aData variable for the queries
        $aData = [
            'where'     => array_filter([
                !empty($oCustomer) ? ['customer_id', $oCustomer->id] : null,
            ]),
            'sort'      => [
                [$sSortOn, $sSortOrder],
            ],
            'expand'    => ['customer', 'payments'],
            'keywords'  => $sKeywords,
            'cbFilters' => $aCbFilters,
        ];

        //  Get the items for the page
        $iTotalRows             = $this->oInvoiceModel->countAll($aData);
        $this->data['invoices'] = $this->oInvoiceModel->getAll($iPage, $iPerPage, $aData);

        //  Set Search and Pagination objects for the view
        $this->data['search']     = Helper::searchObject(true, $aSortColumns, $sSortOn, $sSortOrder, $iPerPage, $sKeywords, $aCbFilters);
        $this->data['pagination'] = Helper::paginationObject($iPage, $iPerPage, $iTotalRows);

        //  Add a header button
        if (userHasPermission('admin:invoice:invoice:create')) {
            Helper::addHeaderButton(
                'admin/invoice/invoice/create',
                'Create Invoice'
            );
        }

        // --------------------------------------------------------------------------

        Helper::loadView('index');
    }
460989
def get_email_context(self,**kwargs):
        '''  '''
        context = super(Invoice,self).get_email_context(**kwargs)
        context.update({
            'id': self.id,
            'url': '%s?v=%s' % (self.url, self.validationString),
            'amountPaid': self.amountPaid,
            'outstandingBalance': self.outstandingBalance,
            'status': self.statusLabel,
            'creationDate': self.creationDate,
            'modifiedDate': self.modifiedDate,
            'paidOnline': self.paidOnline,
            'grossTotal': self.grossTotal,
            'total': self.total,
            'adjustments': self.adjustments,
            'taxes': self.taxes,
            'fees': self.fees,
            'comments': self.comments,
        })
        return context
1123581
public function getOrderTotalAmount(){
        if (isset($this->data['OrderTotal']) && isset($this->data['OrderTotal']['Amount'])){
            return $this->data['OrderTotal']['Amount'];
        } else {
            return false;
        }
    }
353104
private static BigDecimal computeInvoiceAmountAdjustedForAccountCredit(final Currency currency, final Iterable<InvoiceItem> invoiceItems) {
        BigDecimal amountAdjusted = BigDecimal.ZERO;
        if (invoiceItems == null || !invoiceItems.iterator().hasNext()) {
            return KillBillMoney.of(amountAdjusted, currency);
        }

        for (final InvoiceItem invoiceItem : invoiceItems) {
            final Iterable<InvoiceItem> otherInvoiceItems = Iterables.filter(invoiceItems, new Predicate<InvoiceItem>() {
                @Override
                public boolean apply(final InvoiceItem input) {
                    return !input.getId().equals(invoiceItem.getId());
                }
            });

            if (InvoiceItemType.CREDIT_ADJ.equals(invoiceItem.getInvoiceItemType()) &&
                (Iterables.size(otherInvoiceItems) == 1 &&
                 InvoiceItemType.CBA_ADJ.equals(otherInvoiceItems.iterator().next().getInvoiceItemType()) &&
                 otherInvoiceItems.iterator().next().getInvoiceId().equals(invoiceItem.getInvoiceId()) &&
                 otherInvoiceItems.iterator().next().getAmount().compareTo(invoiceItem.getAmount().negate()) == 0)) {
                amountAdjusted = amountAdjusted.add(invoiceItem.getAmount());
            }
        }

        return KillBillMoney.of(amountAdjusted, currency);
    }
909470
public Invoices getAccountInvoices(final String accountCode) {
        return doGET(Accounts.ACCOUNTS_RESOURCE + "/" + accountCode + Invoices.INVOICES_RESOURCE,
                     Invoices.class, new QueryParams());
    }
613527
public function getVatAmounts()
    {
        $amounts = [];

        foreach ($this->getInvoiceElements() as $invoiceElement) {
            $rate = $invoiceElement->getVatRate();
            $amount = (string) $invoiceElement->getVatAmount();

            if (0 === $rate) {
                continue;
            }

            if (isset($amounts[$rate])) {
                $amounts[$rate]['amount'] = bcadd($amounts[$rate]['amount'], $amount);
            } else {
                $amounts[$rate] = [
                    'rate' => $rate,
                    'amount' => $amount,
                ];
            }
        }

        return $amounts;
    }
303190
function getTotal() {
		if ($this->total === null) {
			$q = clone $this->query;
			$q->setLimit(null);
			$q->setOffset(null);
			if ($this->className) {
				$total = call_user_func(array($this->className, 'doCount'), $q);
			} else {
				$total = $q->doCount();
			}
			$this->total = $total;
		}
		return $this->total;
	}
75123
private String getFormattedAmountByLocaleAndInvoiceCurrency(final BigDecimal amount) {
        final String invoiceCurrencyCode = invoice.getCurrency().toString();
        final CurrencyUnit currencyUnit = CurrencyUnit.of(invoiceCurrencyCode);

        final DecimalFormat numberFormatter = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale);
        final DecimalFormatSymbols dfs = numberFormatter.getDecimalFormatSymbols();
        dfs.setInternationalCurrencySymbol(currencyUnit.getCurrencyCode());

        try {
            Currency currency = Currency.fromCode(invoiceCurrencyCode);
            dfs.setCurrencySymbol(currency.getSymbol());
        } catch (final IllegalArgumentException e) {
            dfs.setCurrencySymbol(currencyUnit.getSymbol(locale));
        }

        numberFormatter.setDecimalFormatSymbols(dfs);
        numberFormatter.setMinimumFractionDigits(currencyUnit.getDefaultFractionDigits());
        numberFormatter.setMaximumFractionDigits(currencyUnit.getDefaultFractionDigits());

        return numberFormatter.format(amount.doubleValue());
    }