public static function get_finance($finance_id, $full = true, $invoice_payment_id = false) { if (!$invoice_payment_id) { $invoice_payment_id = isset($_REQUEST['invoice_payment_id']) && (int) $_REQUEST['invoice_payment_id'] > 0 ? (int) $_REQUEST['invoice_payment_id'] : false; } $finance_id = (int) $finance_id; if ($finance_id > 0) { if (!$full) { return get_single("finance", "finance_id", $finance_id); } $sql = "SELECT f.* "; $sql .= " , fa.name AS account_name "; $sql .= " , GROUP_CONCAT(fc.`name` ORDER BY fc.`name` ASC SEPARATOR ', ') AS categories "; $sql .= " FROM `" . _DB_PREFIX . "finance` f "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_account` fa USING (finance_account_id) "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_category_rel` fcr ON f.finance_id = fcr.finance_id "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_category` fc ON fcr.finance_category_id = fc.finance_category_id "; $sql .= " WHERE f.finance_id = {$finance_id} "; $sql .= " GROUP BY f.finance_id "; $sql .= " ORDER BY f.transaction_date DESC "; $finance = qa1($sql); $finance_id = $finance['finance_id']; // get the categories. $finance['category_ids'] = get_multiple('finance_category_rel', array('finance_id' => $finance_id), 'finance_category_id'); $finance['taxes'] = get_multiple('finance_tax', array('finance_id' => $finance_id), 'finance_tax_id', 'exact', 'order'); // get any linked items. $linked_finances = $linked_invoice_payments = array(); // find any child / linked transactions to this one. if ((int) $finance_id > 0 && isset($finance['parent_finance_id']) && $finance['parent_finance_id'] > 0) { // todo - this could cause problems! $foo = module_finance::get_finance($finance['parent_finance_id'], false); if ($foo['finance_id'] != $finance_id) { // copied from get_finances() method $foo['url'] = module_finance::link_open($foo['finance_id'], false); $foo['credit'] = $foo['type'] == 'i' ? $foo['amount'] : 0; $foo['debit'] = $foo['type'] == 'e' ? $foo['amount'] : 0; if (!isset($foo['categories'])) { $foo['categories'] = ''; } if (!isset($foo['account_name'])) { $foo['account_name'] = ''; } $linked_finances[] = $foo; } // find any child finances that are also linked to this parent finance. foreach (module_finance::get_finances_simple(array('parent_finance_id' => $finance['parent_finance_id'])) as $foo) { if ($foo['finance_id'] != $finance_id) { // copied from get_finances() method $foo['url'] = module_finance::link_open($foo['finance_id'], false); $foo['credit'] = $foo['type'] == 'i' ? $foo['amount'] : 0; $foo['debit'] = $foo['type'] == 'e' ? $foo['amount'] : 0; if (!isset($foo['categories'])) { $foo['categories'] = ''; } if (!isset($foo['account_name'])) { $foo['account_name'] = ''; } $linked_finances[] = $foo; } } // find any child invoice payments that are also linked to this parent finance foreach (get_multiple('invoice_payment', array('parent_finance_id' => $finance['parent_finance_id'])) as $invoice_payments) { if ($invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_NORMAL || $invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_CREDIT || $invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT || $invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_REFUND) { $invoice_payments = module_invoice::get_invoice_payment($invoice_payments['invoice_payment_id']); // copied from get_finances() method $invoice_payments = self::_format_invoice_payment($invoice_payments, $finance); $linked_invoice_payments[$invoice_payments['invoice_payment_id']] = $invoice_payments; } } } if ((int) $finance_id > 0) { // find any child finances that are linked to this finance. foreach (module_finance::get_finances_simple(array('parent_finance_id' => $finance_id)) as $foo) { if ($foo['finance_id'] != $finance_id) { // copied from get_finances() method $foo['url'] = module_finance::link_open($foo['finance_id'], false); $foo['credit'] = $foo['type'] == 'i' ? $foo['amount'] : 0; $foo['debit'] = $foo['type'] == 'e' ? $foo['amount'] : 0; if (!isset($foo['categories'])) { $foo['categories'] = ''; } if (!isset($foo['account_name'])) { $foo['account_name'] = ''; } $linked_finances[] = $foo; } } // find any child invoice payments that are also linked to this parent finance foreach (get_multiple('invoice_payment', array('parent_finance_id' => $finance_id)) as $invoice_payments) { if ($invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_NORMAL || $invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT || $invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_CREDIT || $invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_REFUND) { // copied from get_finances() method $invoice_payments = module_invoice::get_invoice_payment($invoice_payments['invoice_payment_id']); $invoice_payments = self::_format_invoice_payment($invoice_payments, $finance); // hack to pull tax information from a linked invoice payment to replace current items tax if none is defined if (!$finance['taxes'] && count($invoice_payments['taxes']) && $invoice_payments['amount'] == $finance['amount']) { $finance['taxes'] = $invoice_payments['taxes']; $finance['taxable_amount'] = $invoice_payments['taxable_amount']; $finance['sub_amount'] = $invoice_payments['sub_amount']; } $linked_invoice_payments[$invoice_payments['invoice_payment_id']] = $invoice_payments; } } if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] > 0) { $invoice_payments = module_invoice::get_invoice_payment($finance['invoice_payment_id']); if ($invoice_payments && ($invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_NORMAL || $invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_CREDIT || $invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT || $invoice_payments['payment_type'] == _INVOICE_PAYMENT_TYPE_REFUND)) { $invoice_payments = self::_format_invoice_payment($invoice_payments, $finance); // hack to pull tax information from a linked invoice payment to replace current items tax if none is defined if (!$finance['taxes'] && count($invoice_payments['taxes']) && $invoice_payments['amount'] == $finance['amount']) { $finance['taxes'] = $invoice_payments['taxes']; $finance['taxable_amount'] = $invoice_payments['taxable_amount']; $finance['sub_amount'] = $invoice_payments['sub_amount']; } $linked_invoice_payments[$invoice_payments['invoice_payment_id']] = $invoice_payments; } else { if (!$invoice_payments) { // todo: this shou;ldnt happen, fix! } } } } $finance['linked_invoice_payments'] = $linked_invoice_payments; $finance['linked_finances'] = $linked_finances; } if ($finance_id <= 0) { $finance = array('finance_id' => 0, 'parent_finance_id' => 0, 'transaction_date' => print_date(time()), 'name' => '', 'description' => '', 'type' => 'e', 'sub_amount' => 0, 'taxable_amount' => 0, 'tax_mode' => module_config::c('finance_default_tax_mode', 0), 'taxes' => array(), 'amount' => 0, 'currency_id' => module_config::c('default_currency_id', 1), 'category_ids' => array(), 'customer_id' => 0, 'job_id' => 0, 'invoice_id' => 0, 'job_staff_expense' => 0, 'user_id' => 0); if (isset($_REQUEST['from_job_id'])) { $job_data = module_job::get_job((int) $_REQUEST['from_job_id']); $finance['job_id'] = $job_data['job_id']; if ($job_data['customer_id']) { $finance['customer_id'] = $job_data['customer_id']; } if (isset($_REQUEST['job_staff_expense']) && (int) $_REQUEST['job_staff_expense'] > 0) { // we have a job staff expense, load up the job tasks for this staff member and find out the cost. if (isset($job_data['staff_total_grouped'][$_REQUEST['job_staff_expense']])) { $staff_member = module_user::get_user($_REQUEST['job_staff_expense']); if ($staff_member && $staff_member['user_id'] == $_REQUEST['job_staff_expense']) { // valid job found, load in the defaults. $finance['name'] = $job_data['name']; $finance['description'] = _l('Job Expense For Staff Member: %s', $staff_member['name'] . ' ' . $staff_member['last_name']); $finance['type'] = 'e'; $finance['amount'] = $job_data['staff_total_grouped'][$_REQUEST['job_staff_expense']]; $finance['taxes'] = array(); $finance['job_staff_expense_id'] = $job_data['job_id']; $finance['job_id'] = $job_data['job_id']; $finance['currency_id'] = $job_data['currency_id']; $finance['transaction_date'] = print_date($job_data['date_completed']); $finance['user_id'] = $staff_member['user_id']; $finance['job_staff_expense'] = $staff_member['user_id']; } } } } if (!$full) { return $finance; } if ($invoice_payment_id && $invoice_payment_id > 0) { $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); if ($invoice_payment_data && $invoice_payment_data['invoice_id']) { $finance = self::_format_invoice_payment($invoice_payment_data, $finance); $finance['invoice_id'] = $invoice_payment_data['invoice_id']; $finance['currency_id'] = $invoice_payment_data['currency_id']; } } } if (isset($finance['invoice_id']) && $finance['invoice_id']) { $new_finance = hook_handle_callback('finance_invoice_listing', $finance['invoice_id'], $finance); if (is_array($new_finance) && count($new_finance)) { foreach ($new_finance as $n) { $finance = array_merge($finance, $n); } } } $finance['taxes'] = self::sanatise_taxes(isset($finance['taxes']) ? $finance['taxes'] : array(), isset($finance['taxable_amount']) ? $finance['taxable_amount'] : 0); return $finance; }
?> </tr> </thead> <tbody> <?php $c = 0; $total_by_currency = array(); $total = array('transaction_count' => 0, 'total_credit' => 0, 'total_sub_credit' => 0, 'total_credit_tax' => array(), 'total_debit' => 0, 'total_sub_debit' => 0, 'total_debit_tax' => array()); // calc taxes and stuff first loop, then display later. foreach ($tax_reports as $finance) { if (isset($finance['finance_id']) && $finance['finance_id']) { $finance_record = module_finance::get_finance($finance['finance_id']); } else { if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] > 0) { $finance_record = module_finance::get_finance(false, true, $finance['invoice_payment_id']); } else { $finance_record = false; } } if (!isset($total_by_currency[$finance['currency_id']])) { $total_by_currency[$finance['currency_id']] = $total; } $total_by_currency[$finance['currency_id']]['transaction_count']++; ?> <tr class="<?php echo $c++ % 2 ? "odd" : "even"; ?> "> <td>
echo number_format($finance['credit'], 2) . '_' . number_format($finance['debit'], 2); ?> " class="link_box"> <?php } } }); if (class_exists('module_extra', false)) { $table_manager->display_extra('finance', function ($finance) { module_extra::print_table_data('finance', isset($finance['finance_id']) ? $finance['finance_id'] : 0); }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($finance) { if (isset($finance['finance_id']) && $finance['finance_id']) { $finance['finance_record'] = module_finance::get_finance($finance['finance_id']); } else { $finance['finance_record'] = false; } return $finance; }; if (module_finance::can_i('create', 'Finance')) { $header_rows = array(); ob_start(); ?> <div style="height:18px; width:89px; overflow: hidden; position: absolute; background: #FFFFFF;" onmouseover="$(this).height('auto');$(this).width('auto');" onmouseout="$(this).height('18px');$(this).width('89px');"> <?php $categories = module_finance::get_categories(); foreach ($categories as $category) { ?>
/** * Copyright: dtbaker 2012 * Licence: Please check CodeCanyon.net for licence details. * More licence clarification available here: http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca * Package Date: 2015-11-25 02:55:20 * IP Address: 67.79.165.254 */ $locked = false; $linked_staff_members = $linked_finances = $linked_invoice_payments = array(); foreach (module_user::get_staff_members() as $staff) { $linked_staff_members[$staff['user_id']] = $staff['name'] . ' ' . $staff['last_name']; } $finance_id = (int) $_REQUEST['finance_id']; $finance = module_finance::get_finance($finance_id); if (!isset($finance['finance_id']) || $finance['finance_id'] != $finance_id) { $finance_id = 0; } if ($finance_id <= 0) { if (isset($_REQUEST['from_invoice_id'])) { $invoice_data = module_invoice::get_invoice((int) $_REQUEST['from_invoice_id'], false); $finance['invoice_id'] = $invoice_data['invoice_id']; if ($invoice_data['customer_id']) { $finance['customer_id'] = $invoice_data['customer_id']; } } if (isset($_REQUEST['invoice_payment_id'])) { $invoice_payment_data = module_invoice::get_invoice_payment($_REQUEST['invoice_payment_id']); if ($invoice_payment_data) { // we make sure this NEW invoice payment record hasn't already been recorded somewhere.