Skip to content

Instantly share code, notes, and snippets.

@ctalkington
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctalkington/fb28c2a1d47d0c3ead83 to your computer and use it in GitHub Desktop.
Save ctalkington/fb28c2a1d47d0c3ead83 to your computer and use it in GitHub Desktop.
Blesta - Patch for Forum Post #3280
<?php
/**
* Admin Billing Management
*
* @package blesta
* @subpackage blesta.app.controllers
* @copyright Copyright (c) 2010, Phillips Data, Inc.
* @license http://www.blesta.com/license/ The Blesta License Agreement
* @link http://www.blesta.com/ Blesta
*/
class AdminBilling extends AppController {
/**
* Billing pre-action
*/
public function preAction() {
parent::preAction();
// Require login
$this->requireLogin();
Language::loadLang(array("admin_billing"));
}
/**
* Billing overview
*/
public function index() {
$this->uses(array("Invoices", "Staff"));
$this->components(array("SettingsCollection"));
$layout = $this->Staff->getSetting($this->Session->read("blesta_staff_id"), "billing_layout", $this->company_id);
$layout = ($layout ? $layout->value : "layout1");
// Check whether a passphrase is required or not for batch processing
$temp = $this->SettingsCollection->fetchSetting(null, $this->company_id, "private_key_passphrase");
$passphrase_required = (isset($temp['value']) && $temp['value'] != "");
unset($temp);
// Set all action items
$actions = array(
'printqueue' => array(
'enabled' => false,
'value' => $this->Invoices->getStatusCount(null, "to_print")
),
'batch' => array(
'enabled' => false,
'value' => $this->Invoices->getStatusCount(null, "to_autodebit")
)
);
// Set whether to show the actions
$show_actions = false;
foreach ($actions as $key=>&$item) {
if ($item['value'] > 0) {
// Batch requires passphrase set
if ($key == "batch" && ($passphrase_required == 1)) {
$item['enabled'] = true;
$show_actions = true;
}
else {
$item['enabled'] = true;
$show_actions = true;
}
}
}
$action_items = array(
'show_actions' => $show_actions,
'actions' => $actions
);
// Set the layout
$this->set("content", $this->partial("admin_billing_" . $layout));
$this->set("action_items", $action_items);
}
/**
* List invoices
*/
public function invoices() {
$this->uses(array("Invoices"));
// Set current page of results
$status = (isset($this->get[0]) ? $this->get[0] : "open");
$page = (isset($this->get[1]) ? (int)$this->get[1] : 1);
$sort = (isset($this->get['sort']) ? $this->get['sort'] : "date_billed");
$order = (isset($this->get['order']) ? $this->get['order'] : "desc");
// Set the number of invoices of each type
$status_count = array(
'open' => $this->Invoices->getStatusCount(null),
'closed' => $this->Invoices->getStatusCount(null, "closed"),
'draft' => $this->Invoices->getStatusCount(null, "draft"),
'void' => $this->Invoices->getStatusCount(null, "void"),
'past_due' => $this->Invoices->getStatusCount(null, "past_due"),
'recurring' => $this->Invoices->getRecurringCount(null),
'pending' => $this->Invoices->getStatusCount(null, "pending")
);
if ($status == "recurring") {
$sort = (isset($this->get['sort']) ? $this->get['sort'] : "id");
$order = (isset($this->get['order']) ? $this->get['order'] : "desc");
$invoices = $this->Invoices->getRecurringList(null, $page, array($sort => $order));
$total_results = $this->Invoices->getRecurringListCount(null);
}
else {
// Get invoices for the company
$invoices = $this->Invoices->getList(null, $status, $page, array($sort => $order));
$total_results = $this->Invoices->getListCount(null, $status);
}
$this->set("status", $status);
$this->set("status_count", $status_count);
$this->set("invoices", $invoices);
$this->set("sort", $sort);
$this->set("order", $order);
$this->set("negate_order", ($order == "asc" ? "desc" : "asc"));
// Overwrite default pagination settings
$settings = array_merge(Configure::get("Blesta.pagination"), array(
'total_results' => $total_results,
'uri'=>$this->base_uri . "billing/invoices/" . $status . "/[p]/",
'params'=>array('sort'=>$sort,'order'=>$order),
)
);
$this->helpers(array("Pagination"=>array($this->get, $settings)));
$this->Pagination->setSettings(Configure::get("Blesta.pagination_ajax"));
// Render the request if ajax
return $this->renderAjaxWidgetIfAsync(isset($this->get[1]) || isset($this->get['sort']));
}
/**
* AJAX request for all transactions an invoice has applied
*/
public function invoiceApplied() {
$this->uses(array("Clients","Invoices","Transactions"));
$invoice = $this->Invoices->get($this->get[0]);
// Ensure the invoice exists and this is an ajax request
if (!$this->isAjax() || !$invoice) {
header($this->server_protocol . " 403 Forbidden");
exit();
}
$vars = array(
'client'=>$this->Clients->get($invoice->client_id),
'applied'=>$this->Transactions->getApplied(null, $this->get[0]),
// Holds the name of all of the transaction types
'transaction_types'=>$this->Transactions->transactionTypeNames()
);
// Send the template
echo $this->partial("admin_billing_invoiceapplied", $vars);
// Render without layout
return false;
}
/**
* List transactions
*/
public function transactions() {
$this->uses(array("Transactions"));
// Set the number of transactions of each type
$status_count = array(
'approved' => $this->Transactions->getStatusCount(),
'declined' => $this->Transactions->getStatusCount(null, "declined"),
'void' => $this->Transactions->getStatusCount(null, "void"),
'error' => $this->Transactions->getStatusCount(null, "error"),
'pending' => $this->Transactions->getStatusCount(null, "pending"),
'refunded' => $this->Transactions->getStatusCount(null, "refunded"),
'returned' => $this->Transactions->getStatusCount(null, "returned")
);
$status = (isset($this->get[0]) ? $this->get[0] : "approved");
$page = (isset($this->get[1]) ? (int)$this->get[1] : 1);
$sort = (isset($this->get['sort']) ? $this->get['sort'] : "date_added");
$order = (isset($this->get['order']) ? $this->get['order'] : "desc");
$total_results = $this->Transactions->getListCount(null, $status);
$this->set("transactions", $this->Transactions->getList(null, $status, $page, array($sort => $order)));
$this->set("status", $status);
$this->set("status_count", $status_count);
$this->set("sort", $sort);
$this->set("order", $order);
$this->set("negate_order", ($order == "asc" ? "desc" : "asc"));
// Holds the name of all of the transaction types
$this->set("transaction_types", $this->Transactions->transactionTypeNames());
// Holds the name of all of the transaction status values
$this->set("transaction_status", $this->Transactions->transactionStatusNames());
// Overwrite default pagination settings
$settings = array_merge(Configure::get("Blesta.pagination"), array(
'total_results' => $total_results,
'uri'=>$this->base_uri . "billing/transactions/" . $status . "/[p]/",
'params'=>array('sort'=>$sort,'order'=>$order),
)
);
$this->helpers(array("Pagination"=>array($this->get, $settings)));
$this->Pagination->setSettings(Configure::get("Blesta.pagination_ajax"));
// Render the request if ajax
return $this->renderAjaxWidgetIfAsync(isset($this->get[1]) || isset($this->get['sort']));
}
/**
* AJAX request for all invoices a transaction has been applied to
*/
public function transactionApplied() {
$this->uses(array("Transactions"));
$transaction = $this->Transactions->get($this->get[0]);
// Ensure the transaction belongs to the client and this is an ajax request
if (!$this->isAjax() || !$transaction) {
header($this->server_protocol . " 403 Forbidden");
exit();
}
$vars = array(
'applied'=>$this->Transactions->getApplied($this->get[0])
);
// Send the template
echo $this->partial("admin_billing_transactionapplied", $vars);
// Render without layout
return false;
}
/**
* Invoice Print Queue
*/
public function printQueue() {
$this->uses(array("Invoices"));
// Set vars to select all checkboxes
$vars = new stdClass();
$vars->print_all = 1;
$status = (isset($this->get[0]) ? $this->get[0] : "to_print");
$page = (isset($this->get[1]) ? (int)$this->get[1] : 1);
$sort = (isset($this->get['sort']) ? $this->get['sort'] : "date_due");
$order = (isset($this->get['order']) ? $this->get['order'] : "asc");
// Default to date sent order for already-printed invoices
if ($status == "printed" && !isset($this->get[1]) && !isset($this->get['sort']) && !isset($this->get['order'])) {
$sort = "delivery_date_sent";
$order = "desc";
}
// Print invoices, or mark them printed
if (!empty($this->post['print']) && is_array($this->post['print'])) {
$invoice_ids = $this->post['print'];
// Print invoices
if ($this->post['mark_printed'] == "false") {
$this->components(array("InvoiceDelivery"));
$this->InvoiceDelivery->downloadInvoices($invoice_ids);
exit;
}
elseif ($this->post['mark_printed'] == "true") {
// Mark invoices printed
$invoices_delivered = array();
// Get the delivery info for each invoice, and mark them printed
foreach ($invoice_ids as $invoice_id) {
$invoice_delivery = $this->Invoices->getDelivery($invoice_id);
// Update the invoice paper method as printed
foreach ($invoice_delivery as $delivery) {
if ($delivery->method == "paper") {
// Mark invoice printed
$this->Invoices->delivered($delivery->id, $this->company_id);
break;
}
}
}
// Invoices marked printed
$this->setMessage("message", Language::_("AdminBilling.!success.invoices_marked_printed", true));
}
}
elseif (!empty($this->post) && empty($this->post['print'])) {
// User attempted to print with no invoices selected
$this->setMessage("error", Language::_("AdminBilling.!error.no_invoices_selected", true));
// Set to not select any invoices
$vars->print = array();
$vars->print_all = 0;
}
// Set the number of invoices of each type
$status_count = array(
'to_print' => $this->Invoices->getStatusCount(null, "to_print"),
'printed' => $this->Invoices->getStatusCount(null, "printed"),
);
// Get invoices for the company
$invoices = $this->Invoices->getList(null, $status, $page, array($sort => $order));
$total_results = $this->Invoices->getListCount(null, $status);
$this->set("invoices", $invoices);
$this->set("status_count", $status_count);
$this->set("status", $status);
$this->set("sort", $sort);
$this->set("order", $order);
$this->set("negate_order", ($order == "asc" ? "desc" : "asc"));
$this->set("vars", $vars);
// Overwrite default pagination settings
$settings = array_merge(Configure::get("Blesta.pagination"), array(
'total_results' => $total_results,
'uri'=>$this->base_uri . "billing/printqueue/" . $status . "/[p]/",
'params'=>array('sort'=>$sort,'order'=>$order)
)
);
$this->helpers(array("Pagination"=>array($this->get, $settings)));
$this->Pagination->setSettings(Configure::get("Blesta.pagination_ajax"));
// Render the request if ajax
return $this->renderAjaxWidgetIfAsync(isset($this->get[1]) || isset($this->get['sort']));
}
/**
* Batch process invoices
*/
public function batch() {
$this->components(array("SettingsCollection"));
// Fetch the passphrase value
$passphrase = $this->SettingsCollection->fetchSetting(null, $this->company_id, "private_key_passphrase");
$passphrase = (isset($passphrase['value']) ? $passphrase['value'] : null);
$cron_key = $this->SettingsCollection->fetchSetting(null, $this->company_id, "cron_key");
$cron_key = (isset($cron_key['value']) ? $cron_key['value'] : null);
$this->set("batch_enabled", (!empty($passphrase)));
$this->set("cron_key", $cron_key);
}
/**
* Verify the given passphrase is valid
*/
public function verifyPassphrase() {
if (!$this->isAjax()) {
header($this->server_protocol . " 403 Forbidden");
exit();
}
$this->uses(array("Encryption"));
$data = array('valid' => true);
if (!$this->Encryption->verifyPassphrase($this->post['passphrase'])) {
$data = array('valid' => false, 'message' => $this->setMessage("error", Language::_("AdminBilling.!error.invalid_passphrase", true), true));
}
$this->outputAsJson($data);
return false;
}
/**
* List reports
*/
public function reports() {
$this->uses(array("ReportManager"));
// Get the company settings
$company_settings = $this->SettingsCollection->fetchSettings(null, $this->company_id);
// Report types
$types = $this->ReportManager->getAvailable();
// Create the report
if (!empty($this->post)) {
// Set data to send to the report
$data = $this->post;
$type = (isset($data['report_type']) ? $data['report_type'] : null);
$format = (isset($data['format']) ? $data['format'] : null);
unset($data['report_type'], $data['format']);
// Generate the report and send it to the browser
$this->ReportManager->fetchAll($type, $data, $format);
// Reset fields if anything goes wrong
if (($errors = $this->ReportManager->errors())) {
$vars = (object)$this->post;
$this->setMessage("error", $errors);
// Reset the values for the report options
$report_fields = $this->ReportManager->getOptions($type, $data);
$this->set("report_fields", $report_fields);
}
}
$this->set("types", (array('' => Language::_("AppController.select.please", true)) + $types));
$this->set("formats", $this->ReportManager->getFormats());
$this->set("vars", (isset($vars) ? $vars : new stdClass()));
$this->Javascript->setFile("date.min.js");
$this->Javascript->setFile("jquery.datePicker.min.js");
$this->Javascript->setInline("Date.firstDayOfWeek=" . ($company_settings['calendar_begins'] == "sunday" ? 0 : 1) . ";");
}
/**
* AJAX retrieves the view for fields specific to a given report
*/
public function getReportFields() {
$this->components(array("Json"));
$this->uses(array("ReportManager"));
// Require the report is valid
if (!$this->isAjax() || empty($this->get['type']) || !array_key_exists($this->get['type'], $this->ReportManager->getAvailable())) {
header($this->server_protocol . " 401 Unauthorized");
exit();
}
// Fetch the report options view
$options = $this->ReportManager->getOptions($this->get['type']);
echo $this->Json->encode(array('fields' => $options));
exit();
}
/**
* List services
*/
public function services() {
$this->uses(array("Packages", "Services"));
// Set current page of results
$status = (isset($this->get[0]) ? $this->get[0] : "active");
$page = (isset($this->get[1]) ? (int)$this->get[1] : 1);
$sort = (isset($this->get['sort']) ? $this->get['sort'] : "date_added");
$order = (isset($this->get['order']) ? $this->get['order'] : "desc");
// Set the number of packages of each type
$status_count = array(
'active' => $this->Services->getListCount(null, "active"),
'canceled' => $this->Services->getListCount(null, "canceled"),
'pending' => $this->Services->getListCount(null, "pending"),
'suspended' => $this->Services->getListCount(null, "suspended"),
'in_review' => $this->Services->getListCount(null, "in_review"),
'scheduled_cancellation' => $this->Services->getListCount(null, "scheduled_cancellation")
);
$this->set("status", $status);
$this->set("status_count", $status_count);
$this->set("services", $this->Services->getList(null, $status, $page, array($sort => $order)));
$this->set("sort", $sort);
$this->set("order", $order);
$this->set("negate_order", ($order == "asc" ? "desc" : "asc"));
$total_results = $this->Services->getListCount(null, $status);
// Set language for periods
$periods = $this->Packages->getPricingPeriods();
foreach ($this->Packages->getPricingPeriods(true) as $period=>$lang)
$periods[$period . "_plural"] = $lang;
$this->set("periods", $periods);
// Overwrite default pagination settings
$settings = array_merge(Configure::get("Blesta.pagination"), array(
'total_results' => $total_results,
'uri'=>$this->base_uri . "billing/services/" . $status . "/[p]/",
'params'=>array('sort'=>$sort,'order'=>$order),
)
);
$this->helpers(array("Pagination"=>array($this->get, $settings)));
$this->Pagination->setSettings(Configure::get("Blesta.pagination_ajax"));
// Render the request if ajax
return $this->renderAjaxWidgetIfAsync(isset($this->get[1]) || isset($this->get['sort']));
}
/**
* AJAX
*/
public function serviceInfo() {
$this->uses(array("Services", "Packages", "ModuleManager"));
// Ensure we have a service
if (!isset($this->get[0]) || !($service = $this->Services->get((int)$this->get[0])))
$this->redirect($this->base_uri . "billing/services/");
$package = $this->Packages->get($service->package->id);
$module = $this->ModuleManager->initModule($service->package->module_id);
if ($module) {
$module->base_uri = $this->base_uri;
$module->setModuleRow($module->getModuleRow($service->module_row_id));
$this->set("content", $module->getAdminServiceInfo($service, $package));
}
echo $this->outputAsJson($this->view->fetch("admin_billing_serviceinfo"));
return false;
}
/**
* Export billing related data (transactions applied, transactions received,
* tax liability, invoice summary)
*/
public function export() {
#
# TODO: export
#
}
/**
* Renders a box to select the dashboard layout to use, and sets it
*/
public function updateDashboard() {
$billing_layout = null;
$billing_layouts = array("layout1", "layout2", "layout3", "layout4");
// Get the new dashboard layout if given
if (isset($this->get[0]) && in_array($this->get[0], $billing_layouts))
$billing_layout = $this->get[0];
$this->uses(array("Staff"));
// Ensure a valid staff member is set
if (!($staff = $this->Staff->get($this->Session->read("blesta_staff_id"), $this->company_id)))
$this->redirect($this->base_uri . "billing/");
// Update dashboard layout
if ($billing_layout != null) {
// Update the billing dashboard layout
$this->Staff->setSetting($staff->id, "billing_layout", $billing_layout);
// Redirect to billing dashboard
$this->redirect($this->base_uri . "billing/");
}
// Retrieve the current layout
$current_layout = $this->Staff->getSetting($staff->id, "billing_layout", $this->company_id);
// Set the default dashboard layout if one doesn't exist
if (!$current_layout)
$current_layout = $billing_layouts[0];
else
$current_layout = $current_layout->value;
// Set all of the billing layouts
$layouts = array();
foreach ($billing_layouts as $layout) {
$layouts[] = (object)array(
'name' => $layout,
'selected' => ($layout == $current_layout) ? true : false
);
}
$this->set("layouts", $layouts);
echo $this->view->fetch("admin_billing_updatedashboard");
return false;
}
/**
* Enable/Disable widgets from appearing on the dashboard
*/
public function manageWidgets() {
$this->uses(array("PluginManager", "Staff"));
// Get all displayed widgets
$active_widgets = $this->Staff->getBillingWidgetsState($this->Session->read("blesta_staff_id"), $this->company_id);
if (!empty($this->post)) {
if (is_array($this->post['widgets_on'])) {
// If a widget isn't displayed it must be disabled
foreach ($active_widgets as $key => $widget) {
if (!in_array($key, $this->post['widgets_on']))
$active_widgets[$key]['disabled'] = true;
}
// Set all widgets to be displayed
foreach ($this->post['widgets_on'] as $key) {
if (!isset($active_widgets[$key]))
$active_widgets[$key] = array('open'=>true, 'section'=> "section1");
else
unset($active_widgets[$key]['disabled']);
}
// Update this staff member's billing widgets for this company
$this->Staff->saveBillingWidgetsState($this->Session->read("blesta_staff_id"), $this->company_id, $active_widgets);
}
return false;
}
// Get all widgets installed for this location
$installed_widgets = $this->PluginManager->getActions($this->company_id, "widget_staff_billing");
$available_widgets = array();
foreach ($installed_widgets as $widget) {
$key = str_replace("/", "_", trim($widget->uri, "/"));
$available_widgets[$key] = $this->PluginManager->get($widget->plugin_id, true);
}
// Move all currently displayed widgets from available to displayed
$displayed_widgets = array();
foreach ($active_widgets as $key => $widget) {
if (isset($available_widgets[$key]) && !(isset($widget['disabled']) && $widget['disabled'])) {
$displayed_widgets[$key] = $available_widgets[$key];
unset($available_widgets[$key]);
}
}
// All widgets available and not displayed
$this->set("available_widgets", $available_widgets);
// All widgets available and displayed
$this->set("displayed_widgets", $displayed_widgets);
echo $this->view->fetch("admin_billing_managewidgets");
return false;
}
}
?>
<?php
echo $this->Html->ifSet($message);
$links = array(
array('name'=>$this->_("AdminBilling.transactions.category_approved", true) . " <span>(" . $this->Html->_($status_count['approved'], true) . ")</span>", 'current'=>($this->Html->ifSet($status) == "approved" ? true : false), 'attributes'=>array('href'=>$this->base_uri . "billing/transactions/approved/", 'class'=>"ajax")),
array('name'=>$this->_("AdminBilling.transactions.category_declined", true) . " <span>(" . $this->Html->_($status_count['declined'], true) . ")</span>", 'current'=>($this->Html->ifSet($status) == "declined" ? true : false), 'attributes'=>array('href'=>$this->base_uri . "billing/transactions/declined/", 'class'=>"ajax")),
array('name'=>$this->_("AdminBilling.transactions.category_voided", true) . " <span>(" . $this->Html->_($status_count['void'], true) . ")</span>", 'current'=>($this->Html->ifSet($status) == "void" ? true : false), 'attributes'=>array('href'=>$this->base_uri . "billing/transactions/void/", 'class'=>"ajax")),
array('name'=>$this->_("AdminBilling.transactions.category_error", true) . " <span>(" . $this->Html->_($status_count['error'], true) . ")</span>", 'current'=>($this->Html->ifSet($status) == "error" ? true : false), 'highlight'=>true, 'attributes'=>array('href'=>$this->base_uri . "billing/transactions/error/", 'class'=>"ajax")),
array('name'=>$this->_("AdminBilling.transactions.category_pending", true) . " <span>(" . $this->Html->_($status_count['pending'], true) . ")</span>", 'current'=>($this->Html->ifSet($status) == "pending" ? true : false), 'attributes'=>array('href'=>$this->base_uri . "billing/transactions/pending/", 'class'=>"ajax")),
array('name'=>$this->_("AdminBilling.transactions.category_refunded", true) . " <span>(" . $this->Html->_($status_count['refunded'], true) . ")</span>", 'current'=>($this->Html->ifSet($status) == "refunded" ? true : false), 'attributes'=>array('href'=>$this->base_uri . "billing/transactions/refunded/", 'class'=>"ajax")),
array('name'=>$this->_("AdminBilling.transactions.category_returned", true) . " <span>(" . $this->Html->_($status_count['returned'], true) . ")</span>", 'current'=>($this->Html->ifSet($status) == "returned" ? true : false), 'attributes'=>array('href'=>$this->base_uri . "billing/transactions/returned/", 'class'=>"ajax"))
);
$this->Widget->clear();
$this->Widget->setLinks($links);
$this->Widget->create($this->_("AdminBilling.transactions.boxtitle_transactions", true), array('id'=>"admin_billing_transactions"), $this->Html->ifSet($render_section, null));
if ($this->Html->ifSet($transactions, false) && ($num_transactions = count($transactions)) > 0) {
?>
<table class="table">
<tr class="heading_row">
<td><span><a href="<?php echo $this->Html->safe($this->base_uri . "billing/transactions/" . $this->Html->ifSet($status) . "/?sort=client_id_code&order=" . ($sort == "client_id_code" ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == "client_id_code" ? " " . $order : "");?>"><?php $this->_("AdminBilling.transactions.heading_client");?></a></span></td>
<td><span><a href="<?php echo $this->Html->safe($this->base_uri . "billing/transactions/" . $this->Html->ifSet($status) . "/?sort=type&order=" . ($sort == "type" ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == "type" ? " " . $order : "");?>"><?php $this->_("AdminBilling.transactions.heading_type");?></a></span></td>
<td><span><a href="<?php echo $this->Html->safe($this->base_uri . "billing/transactions/" . $this->Html->ifSet($status) . "/?sort=amount&order=" . ($sort == "amount" ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == "amount" ? " " . $order : "");?>"><?php $this->_("AdminBilling.transactions.heading_amount");?></a></span></td>
<td><span><?php $this->_("AdminBilling.transactions.heading_credit");?></span></td>
<td><span><a href="<?php echo $this->Html->safe($this->base_uri . "billing/transactions/" . $this->Html->ifSet($status) . "/?sort=applied_amount&order=" . ($sort == "applied_amount" ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == "applied_amount" ? " " . $order : "");?>"><?php $this->_("AdminBilling.transactions.heading_applied");?></a></span></td>
<td><span><a href="<?php echo $this->Html->safe($this->base_uri . "billing/transactions/" . $this->Html->ifSet($status) . "/?sort=transaction_id&order=" . ($sort == "transaction_id" ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == "transaction_id" ? " " . $order : "");?>"><?php $this->_("AdminBilling.transactions.heading_number");?></a></span></td>
<td><span><a href="<?php echo $this->Html->safe($this->base_uri . "billing/transactions/" . $this->Html->ifSet($status) . "/?sort=status&order=" . ($sort == "status" ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == "status" ? " " . $order : "");?>"><?php $this->_("AdminBilling.transactions.heading_status");?></a></span></td>
<td><span><a href="<?php echo $this->Html->safe($this->base_uri . "billing/transactions/" . $this->Html->ifSet($status) . "/?sort=date_added&order=" . ($sort == "date_added" ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == "date_added" ? " " . $order : "");?>"><?php $this->_("AdminBilling.transactions.heading_date");?></a></span></td>
<td class="last"><span><?php $this->_("AdminBilling.transactions.heading_options");?></span></td>
</tr>
<?php
// Display all transactions
for ($i=0; $i<$num_transactions; $i++) {
if ($this->Html->ifSet($transactions[$i]->type) == "other" && $this->Html->ifSet($transactions[$i]->gateway_type) == "nonmerchant")
$trans_type = $transactions[$i]->gateway_name;
else
$trans_type = $this->Html->ifSet($transaction_types[($transactions[$i]->type_name != "" ? $transactions[$i]->type_name : $transactions[$i]->type)]);
?>
<tr class="<?php echo $this->Html->concat(" ", ($i%2 == 1) ? "odd_row" : "", "expand", "transaction_applied");?>">
<td><span class="tooltip quiet"><a href="<?php echo $this->base_uri . "clients/view/" . $this->Html->_($transactions[$i]->client_id, true);?>"><?php $this->Html->_($transactions[$i]->client_id_code);?></a><div><?php echo $this->Html->_($transactions[$i]->client_first_name, true) . " " . $this->Html->_($transactions[$i]->client_last_name, true);?><br /><?php $this->Html->_($transactions[$i]->client_company);?></div></span></td>
<td><?php $this->Html->_($trans_type);?></td>
<td><?php echo $this->CurrencyFormat->format($this->Html->_($transactions[$i]->amount, true), $this->Html->_($transactions[$i]->currency, true), array('html_code'=>true));?></td>
<td><?php echo $this->CurrencyFormat->format($this->Html->_($transactions[$i]->credited_amount, true), $this->Html->_($transactions[$i]->currency, true), array('html_code'=>true));?></td>
<td><?php echo $this->CurrencyFormat->format($this->Html->_($transactions[$i]->applied_amount, true), $this->Html->_($transactions[$i]->currency, true), array('html_code'=>true));?></td>
<td><?php $this->Html->_($transactions[$i]->transaction_id);?></td>
<td><?php $this->Html->_($transaction_status[$transactions[$i]->status]);?></td>
<td><?php echo $this->Date->cast($this->Html->_($transactions[$i]->date_added, true), "date_time");?></td>
<td><a href="<?php echo $this->Html->safe($this->base_uri . "clients/edittransaction/" . $this->Html->ifSet($transactions[$i]->client_id) . "/" . $this->Html->ifSet($transactions[$i]->id) . "/");?>"><?php $this->_("AdminBilling.transactions.option_edit");?></a></td>
</tr>
<tr class="expand_details" id="transactions_<?php $this->Html->_($transactions[$i]->id);?>">
<td colspan="9" class="subtable">
</td>
</tr>
<?php
}
?>
</table>
<?php
$this->Pagination->build();
}
else {
?>
<div class="empty_section">
<div class="empty_box">
<?php $this->_("AdminBilling.transactions.no_results");?>
</div>
</div>
<?php
}
$this->Widget->end();
?>
<script type="text/javascript">
$(document).ready(function() {
// Fetch all invoices the given transaction has been applied to
$(".transaction_applied").click(function() {
$(this).blestaUpdateRow("<?php echo $this->Html->_($this->base_uri, true) . "billing/transactionapplied/";?>" + $(this).next("tr").attr("id").split("_")[1], ".subtable");
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment