Esempio n. 1
0
        if (class_exists('module_finance', false) && module_finance::is_plugin_enabled() && module_finance::can_i('view', 'Finance') && module_finance::is_enabled()) {
            // check if this finance has been added to the finance section yet.
            $existing_finance = get_single('finance', 'invoice_payment_id', $invoice_payment_data['invoice_payment_id']);
            if ($existing_finance) {
                ?>
 <a href="<?php 
                echo module_finance::link_open($existing_finance['finance_id']);
                ?>
"><?php 
                _e('More');
                ?>
</a> | <?php 
            } else {
                ?>
 <a href="<?php 
                echo module_finance::link_open('new', false) . '&invoice_payment_id=' . $invoice_payment_data['invoice_payment_id'];
                ?>
"><?php 
                _e('More');
                ?>
</a> | <?php 
            }
        }
        ?>

                                        <a href="<?php 
        echo module_invoice::link_receipt($invoice_payment_data['invoice_payment_id']);
        ?>
" target="_blank"><?php 
        _e('Receipt');
        ?>
Esempio n. 2
0
    echo !trim($transaction['name']) ? 'N/A' : htmlspecialchars($transaction['name']);
    ?>
</a>
                    </td>
                    <td>
                        <?php 
    echo $transaction['description'];
    ?>
                    </td>
                    <td>
                        <span class="success_text"><?php 
    echo $transaction['credit'] > 0 ? '+' . dollar($transaction['credit'], true, $transaction['currency_id']) : '';
    ?>
</span>
                    </td>
                    <td>
                        <span class="error_text"><?php 
    echo $transaction['debit'] > 0 ? '-' . dollar($transaction['debit'], true, $transaction['currency_id']) : '';
    ?>
</span>
                    </td>
                </tr>
            <?php 
}
?>
        </tbody>
    </table>
</div>
<?php 
$fieldset_data = array('heading' => array('title' => 'Job Finances:', 'type' => 'h3', 'button' => array('title' => _l('Add New'), 'url' => module_finance::link_open('new') . '&from_job_id=' . $job_id)), 'elements_before' => ob_get_clean());
echo module_form::generate_fieldset($fieldset_data);
Esempio n. 3
0
 public static function get_finances($search = array())
 {
     // we have to search for recent transactions. this involves combining the "finance" table with the "invoice_payment" table
     // then sort the results by date
     $hide_invoice_payments = false;
     $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 ";
     $where = " WHERE 1 ";
     if (isset($search['finance_account_id']) && is_array($search['finance_account_id'])) {
         $fo = array();
         foreach ($search['finance_account_id'] as $val) {
             if ((int) $val > 0) {
                 $fo[(int) $val] = true;
             }
         }
         if (count($fo) > 0) {
             $where .= " AND ( ";
             foreach ($fo as $f => $ff) {
                 $where .= " f.finance_account_id = " . $f . ' OR';
             }
             $where = rtrim($where, 'OR');
             $where .= ' )';
             $hide_invoice_payments = true;
         }
     }
     if (isset($search['finance_recurring_id']) && $search['finance_recurring_id']) {
         $where .= " AND f.finance_recurring_id = '" . (int) $search['finance_recurring_id'] . "'";
         $hide_invoice_payments = true;
     }
     if (isset($search['finance_category_id']) && is_array($search['finance_category_id'])) {
         $fo = array();
         foreach ($search['finance_category_id'] as $val) {
             if ((int) $val > 0) {
                 $fo[(int) $val] = true;
             }
         }
         if (count($fo) > 0) {
             $where .= " AND EXISTS ( SELECT * FROM `" . _DB_PREFIX . "finance_category_rel` fcr2 WHERE fcr2.finance_id = f.finance_id AND ( ";
             foreach ($fo as $f => $ff) {
                 $where .= " fcr2.finance_category_id = " . $f . ' OR';
             }
             $where = rtrim($where, 'OR');
             $where .= ' )';
             $where .= ' )';
             $hide_invoice_payments = true;
         }
     }
     if (isset($search['invoice_payment_id']) && $search['invoice_payment_id']) {
         $where .= " AND f.invoice_payment_id = '" . (int) $search['invoice_payment_id'] . "'";
         $hide_invoice_payments = true;
     }
     // below 6 searches are repeated again below in invoice payments
     if (isset($search['job_id']) && (int) $search['job_id'] > 0) {
         $where .= " AND f.`job_id` = " . (int) $search['job_id'];
     }
     if (isset($search['invoice_id']) && (int) $search['invoice_id'] > 0) {
         $where .= " AND f.`invoice_id` = " . (int) $search['invoice_id'];
     }
     if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) {
         $where .= " AND f.`customer_id` = " . (int) $search['customer_id'];
     }
     if (isset($search['company_id']) && (int) $search['company_id'] > 0) {
         // check this user can view this company id or not
         if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) {
             $companys = module_company::get_companys();
             if (isset($companys[$search['company_id']])) {
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON f.customer_id = cc.customer_id ";
                 $where .= " AND ( cc.`company_id` = " . (int) $search['company_id'] . " OR  f.`company_id` = " . (int) $search['company_id'] . " )";
             }
         }
     }
     if (isset($search['generic']) && strlen(trim($search['generic']))) {
         $name = mysql_real_escape_string(trim($search['generic']));
         $where .= " AND (f.`name` LIKE '%{$name}%' OR f.description LIKE '%{$name}%' )";
     }
     if (isset($search['date_from']) && $search['date_from'] != '') {
         $where .= " AND f.transaction_date >= '" . input_date($search['date_from']) . "'";
     }
     if (isset($search['date_to']) && $search['date_to'] != '') {
         $where .= " AND f.transaction_date <= '" . input_date($search['date_to']) . "'";
     }
     if (isset($search['amount_from']) && $search['amount_from'] != '') {
         $where .= " AND f.amount >= '" . mysql_real_escape_string($search['amount_from']) . "'";
     }
     if (isset($search['amount_to']) && $search['amount_to'] != '') {
         $where .= " AND f.amount <= '" . mysql_real_escape_string($search['amount_to']) . "'";
     }
     if (isset($search['type']) && $search['type'] != '' && $search['type'] != 'ie') {
         $where .= " AND f.type = '" . mysql_real_escape_string($search['type']) . "'";
     }
     // permissions from job module.
     /*switch(module_job::get_job_access_permissions()){
                 case _JOB_ACCESS_ALL:
     
                     break;
                 case _JOB_ACCESS_ASSIGNED:
                     // only assigned jobs!
                     //$from .= " LEFT JOIN `"._DB_PREFIX."task` t ON u.job_id = t.job_id ";
                     //u.user_id = ".(int)module_security::get_loggedin_id()." OR
                     $where .= " AND (t.user_id = ".(int)module_security::get_loggedin_id().")";
                     break;
                 case _JOB_ACCESS_CUSTOMER:
                     break;
             }*/
     // permissions from customer module.
     // tie in with customer permissions to only get jobs from customers we can access.
     switch (module_customer::get_customer_data_access()) {
         case _CUSTOMER_ACCESS_ALL:
             // all customers! so this means all jobs!
             break;
         case _CUSTOMER_ACCESS_ALL_COMPANY:
         case _CUSTOMER_ACCESS_CONTACTS:
         case _CUSTOMER_ACCESS_TASKS:
         case _CUSTOMER_ACCESS_STAFF:
             $valid_customer_ids = module_security::get_customer_restrictions();
             if (count($valid_customer_ids)) {
                 $where .= " AND f.customer_id IN ( ";
                 foreach ($valid_customer_ids as $valid_customer_id) {
                     $where .= (int) $valid_customer_id . ", ";
                 }
                 $where = rtrim($where, ', ');
                 $where .= " )";
             }
     }
     $where .= " GROUP BY f.finance_id ";
     $where .= " ORDER BY f.transaction_date DESC ";
     $sql .= $where;
     $finances_from_finance_db_table = qa($sql);
     // invoice payments:
     $finance_from_invoice_payments = array();
     $finance_from_job_staff_expenses = array();
     if (!$hide_invoice_payments && (!isset($search['invoice_id']) || !(int) $search['invoice_id'] > 0)) {
         $sql = "SELECT j.*, f.finance_id AS existing_finance_id ";
         $sql .= " FROM `" . _DB_PREFIX . "job` j ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance` f ON j.job_id = f.job_id AND f.job_staff_expense > 0 ";
         $where = " WHERE 1 ";
         //j.date_completed != '0000-00-00' ";
         $where .= " AND j.`c_staff_total_amount` > 0 ";
         if (isset($search['job_id']) && (int) $search['job_id'] > 0) {
             $where .= " AND (j.`job_id` = " . (int) $search['job_id'] . " ) ";
         }
         if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) {
             $where .= " AND j.`customer_id` = " . (int) $search['customer_id'];
         }
         /*if(isset($search['generic']) && strlen(trim($search['generic']))){
               $name = mysql_real_escape_string(trim($search['generic']));
               $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )";
           }*/
         if (isset($search['company_id']) && (int) $search['company_id'] > 0) {
             // check this user can view this company id or not
             if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) {
                 $companys = module_company::get_companys();
                 if (isset($companys[$search['company_id']])) {
                     $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON j.customer_id = cc.customer_id ";
                     $where .= " AND cc.`company_id` = " . (int) $search['company_id'];
                 }
             }
         }
         if (isset($search['date_from']) && $search['date_from'] != '') {
             $where .= " AND j.date_completed >= '" . input_date($search['date_from']) . "'";
         }
         if (isset($search['date_to']) && $search['date_to'] != '') {
             $where .= " AND j.date_completed <= '" . input_date($search['date_to']) . "'";
         }
         if (isset($search['amount_from']) && $search['amount_from'] != '') {
             $where .= " AND j.c_staff_total_amount >= '" . mysql_real_escape_string($search['amount_from']) . "'";
         }
         if (isset($search['amount_to']) && $search['amount_to'] != '') {
             $where .= " AND j.c_staff_total_amount <= '" . mysql_real_escape_string($search['amount_to']) . "'";
         }
         switch (module_job::get_job_access_permissions()) {
             case _JOB_ACCESS_ALL:
                 break;
             case _JOB_ACCESS_ASSIGNED:
                 // only assigned jobs!
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON j.job_id = t.job_id ";
                 $where .= " AND (j.user_id = " . (int) module_security::get_loggedin_id() . " OR t.user_id = " . (int) module_security::get_loggedin_id() . ")";
                 break;
             case _JOB_ACCESS_CUSTOMER:
                 // tie in with customer permissions to only get jobs from customers we can access.
                 $valid_customer_ids = module_security::get_customer_restrictions();
                 if (count($valid_customer_ids)) {
                     $where .= " AND j.customer_id IN ( ";
                     foreach ($valid_customer_ids as $valid_customer_id) {
                         $where .= (int) $valid_customer_id . ", ";
                     }
                     $where = rtrim($where, ', ');
                     $where .= " )";
                 }
                 break;
         }
         switch (module_customer::get_customer_data_access()) {
             case _CUSTOMER_ACCESS_ALL:
                 // all customers! so this means all jobs!
                 break;
             case _CUSTOMER_ACCESS_ALL_COMPANY:
             case _CUSTOMER_ACCESS_CONTACTS:
             case _CUSTOMER_ACCESS_TASKS:
             case _CUSTOMER_ACCESS_STAFF:
                 $valid_customer_ids = module_security::get_customer_restrictions();
                 if (count($valid_customer_ids)) {
                     $where .= " AND j.customer_id IN ( ";
                     foreach ($valid_customer_ids as $valid_customer_id) {
                         $where .= (int) $valid_customer_id . ", ";
                     }
                     $where = rtrim($where, ', ');
                     $where .= " )";
                 }
         }
         $sql .= $where . " GROUP BY j.job_id ORDER BY j.date_completed DESC ";
         //echo $sql;
         $finance_from_job_staff_expenses = array();
         $res = qa($sql);
         foreach ($res as $finance) {
             // we have a job with staff expenses. split this up into gruops based on staff members.
             $staff_total_grouped = false;
             if (isset($finance['c_staff_total_grouped']) && strlen($finance['c_staff_total_grouped'])) {
                 $staff_total_grouped = @unserialize($finance['c_staff_total_grouped']);
             }
             if ($staff_total_grouped === false) {
                 //	                echo 'here: ';
                 //	                var_dump($finance);
                 //	                var_dump($staff_total_grouped);
                 $job_data = module_job::get_job($finance['job_id']);
                 $staff_total_grouped = $job_data['staff_total_grouped'];
             }
             if (is_array($staff_total_grouped)) {
                 foreach ($staff_total_grouped as $staff_id => $staff_total) {
                     $staff_member = module_user::get_user($staff_id);
                     if ($staff_member && $staff_member['user_id'] == $staff_id) {
                         // make sure this entry doesn't already exist in the database table for this job
                         // there MAY be an existing entry if 'existing_finance_id' is set
                         if ($finance['existing_finance_id'] > 0) {
                             // check if it exists for this staff member.
                             $existing = get_single('finance', array('job_id', 'job_staff_expense', 'amount'), array($finance['job_id'], $staff_id, $staff_total));
                             if ($existing) {
                                 // match exists already, skip adding this one to the list.
                                 continue;
                             }
                         }
                         //$finance = self::_format_invoice_payment($finance, $finance);
                         //$finance['url'] = module_job::link_open($finance['job_id'],false,$finance);
                         $finance['url'] = module_finance::link_open('new', false) . '&job_staff_expense=' . $staff_id . '&from_job_id=' . $finance['job_id'];
                         $finance['transaction_date'] = $finance['date_completed'];
                         $finance['description'] = _l('Job Expense For Staff Member: %s', $staff_member['name'] . ' ' . $staff_member['last_name']);
                         //"Exiting: ".$finance['existing_finance_id'].": ".
                         $finance['amount'] = $staff_total;
                         $finance['debit'] = $staff_total;
                         $finance['sub_amount'] = $staff_total;
                         $finance['taxable_amount'] = $staff_total;
                         $finance['credit'] = 0;
                         $finance['type'] = 'e';
                         $finance_from_job_staff_expenses[] = $finance;
                     }
                 }
             }
         }
     }
     if (!$hide_invoice_payments) {
         $sql = "SELECT p.*, i.customer_id ";
         if (module_config::c('finance_date_type', 'payment') == 'invoice') {
             // show entries by invoice create date, not payment date.
             $sql .= " , i.date_create AS transaction_date ";
         } else {
             // default, show by paid date.
             $sql .= " , p.date_paid AS transaction_date ";
         }
         $sql .= " FROM `" . _DB_PREFIX . "invoice_payment` p ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice` i ON p.invoice_id = i.invoice_id ";
         $where = " WHERE p.date_paid != '0000-00-00' ";
         $where .= " AND p.`amount` != 0 ";
         $where .= " AND ( p.`payment_type` = " . _INVOICE_PAYMENT_TYPE_NORMAL . " OR p.`payment_type` = " . _INVOICE_PAYMENT_TYPE_REFUND . ' OR p.`payment_type` = ' . _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT . ' OR p.`payment_type` = ' . _INVOICE_PAYMENT_TYPE_CREDIT . ')';
         if (isset($search['job_id']) && (int) $search['job_id'] > 0) {
             $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice_item` ii ON i.invoice_id = ii.invoice_id";
             $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON ii.task_id = t.task_id";
             $where .= " AND (t.`job_id` = " . (int) $search['job_id'] . " OR i.`deposit_job_id` = " . (int) $search['job_id'] . " ) ";
         }
         if (isset($search['invoice_id']) && (int) $search['invoice_id'] > 0) {
             $where .= " AND p.`invoice_id` = " . (int) $search['invoice_id'];
         }
         if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) {
             $where .= " AND i.`customer_id` = " . (int) $search['customer_id'];
         }
         /*if(isset($search['generic']) && strlen(trim($search['generic']))){
               $name = mysql_real_escape_string(trim($search['generic']));
               $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )";
           }*/
         if (isset($search['company_id']) && (int) $search['company_id'] > 0) {
             // check this user can view this company id or not
             if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) {
                 $companys = module_company::get_companys();
                 if (isset($companys[$search['company_id']])) {
                     $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON i.customer_id = cc.customer_id ";
                     $where .= " AND cc.`company_id` = " . (int) $search['company_id'];
                 }
             }
         }
         if (isset($search['date_from']) && $search['date_from'] != '') {
             if (module_config::c('finance_date_type', 'payment') == 'invoice') {
                 $where .= " AND i.date_create >= '" . input_date($search['date_from']) . "'";
             } else {
                 $where .= " AND p.date_paid >= '" . input_date($search['date_from']) . "'";
             }
         }
         if (isset($search['date_to']) && $search['date_to'] != '') {
             if (module_config::c('finance_date_type', 'payment') == 'invoice') {
                 $where .= " AND i.date_create <= '" . input_date($search['date_to']) . "'";
             } else {
                 $where .= " AND p.date_paid <= '" . input_date($search['date_to']) . "'";
             }
         }
         if (isset($search['amount_from']) && $search['amount_from'] != '') {
             $where .= " AND p.amount >= '" . mysql_real_escape_string($search['amount_from']) . "'";
         }
         if (isset($search['amount_to']) && $search['amount_to'] != '') {
             $where .= " AND p.amount <= '" . mysql_real_escape_string($search['amount_to']) . "'";
         }
         if (isset($search['type']) && $search['type'] != '' && $search['type'] != 'ie') {
             if ($search['type'] == 'i') {
                 $where .= " AND p.amount > 0";
             } else {
                 if ($search['type'] == 'e') {
                     $where .= " AND p.amount < 0";
                 }
             }
         }
         switch (module_customer::get_customer_data_access()) {
             case _CUSTOMER_ACCESS_ALL:
                 // all customers! so this means all jobs!
                 break;
             case _CUSTOMER_ACCESS_ALL_COMPANY:
             case _CUSTOMER_ACCESS_CONTACTS:
             case _CUSTOMER_ACCESS_TASKS:
             case _CUSTOMER_ACCESS_STAFF:
                 $valid_customer_ids = module_security::get_customer_restrictions();
                 if (count($valid_customer_ids)) {
                     $where .= " AND i.customer_id IN ( ";
                     foreach ($valid_customer_ids as $valid_customer_id) {
                         $where .= (int) $valid_customer_id . ", ";
                     }
                     $where = rtrim($where, ', ');
                     $where .= " )";
                 }
         }
         $sql .= $where . " ORDER BY p.date_paid DESC ";
         //echo $sql;
         $finance_from_invoice_payments = qa($sql);
         foreach ($finance_from_invoice_payments as $finance_id => $finance) {
             // doesn't have an finance / account reference just yet.
             // but they can create one and this will become a child entry to it.
             $finance = self::_format_invoice_payment($finance, $finance);
             /*if(!isset($finance['customer_id']) || !$finance['customer_id']){
                   $invoice_data = module_invoice::get_invoice($finance['invoice_id'],2);
                   $finance['customer_id'] = $invoice_data['customer_id'];
               }*/
             // grab a new name/descriptino/etc.. from other plugins (at the moment only subscription)
             /*$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_from_invoice_payments[$finance_id] = $finance;
         }
         if (isset($search['generic']) && strlen(trim($search['generic']))) {
             $name = mysql_real_escape_string(trim($search['generic']));
             //                $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )";
             // we have to do a PHP search here because
             foreach ($finance_from_invoice_payments as $finance_id => $finance) {
                 if (stripos($finance['name'], $name) === false && stripos($finance['description'], $name) === false) {
                     unset($finance_from_invoice_payments[$finance_id]);
                 }
             }
         }
     }
     $finances = array_merge($finances_from_finance_db_table, $finance_from_invoice_payments, $finance_from_job_staff_expenses);
     unset($finances_from_finance_db_table);
     unset($finance_from_invoice_payments);
     unset($finance_from_job_staff_expenses);
     // sort this
     if (!function_exists('sort_finance')) {
         function sort_finance($a, $b)
         {
             $t1 = strtotime($a['transaction_date']);
             $t2 = strtotime($b['transaction_date']);
             if ($t1 == $t2) {
                 // sort by finance id, putting ones with a finance id first before others. then amount.
                 if (isset($a['finance_id']) && !isset($b['finance_id'])) {
                     // put $a before $b
                     return -1;
                 } else {
                     if (!isset($a['finance_id']) && isset($b['finance_id'])) {
                         // put $b before $a
                         return 1;
                     } else {
                         return $a['amount'] > $b['amount'];
                     }
                 }
             } else {
                 return $t1 < $t2;
             }
         }
     }
     uasort($finances, 'sort_finance');
     foreach ($finances as $finance_id => $finance) {
         // we load each of these transactions
         // transaction can be a "transaction" or an "invoice_payment"
         // find out if this transaction is a child transaction to another transaction.
         // if it is a child transaction and we haven't already dispayed it in this listing
         // then we find the parent transaction and display it along with all it's children in this place.
         // this wont be perfect all the time but will be awesome in 99% of cases.
         if (isset($finance['finance_id']) && $finance['finance_id']) {
             // displayed before already?
             if (isset($displayed_finance_ids[$finance['finance_id']])) {
                 $finances[$displayed_finance_ids[$finance['finance_id']]]['link_count']++;
                 unset($finances[$finance_id]);
                 continue;
             }
             $displayed_finance_ids[$finance['finance_id']] = $finance_id;
             if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id']) {
                 $displayed_invoice_payment_ids[$finance['invoice_payment_id']] = $finance_id;
                 // so we dont display again.
             }
         } else {
             if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] && isset($finance['invoice_id']) && $finance['invoice_id']) {
                 // this is an invoice payment (incoming payment)
                 // displayed before already?
                 if (isset($displayed_invoice_payment_ids[$finance['invoice_payment_id']])) {
                     $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]] = array_merge($finance, $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]]);
                     $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]]['link_count']++;
                     unset($finances[$finance_id]);
                     continue;
                 }
                 $displayed_invoice_payment_ids[$finance['invoice_payment_id']] = $finance_id;
                 // so we dont display again.
             } else {
                 if (isset($finance['c_staff_total_amount'])) {
                     // staff expense.
                 } else {
                     // nfi?
                     unset($finances[$finance_id]);
                     continue;
                 }
             }
         }
         if (isset($finance['parent_finance_id']) && $finance['parent_finance_id']) {
             // check if it's parent finance id has been displayed already somewhere.
             if (isset($displayed_finance_ids[$finance['parent_finance_id']])) {
                 $finances[$displayed_finance_ids[$finance['parent_finance_id']]]['link_count']++;
                 unset($finances[$finance_id]);
                 continue;
                 // already done it on this page.
             }
             $displayed_finance_ids[$finance['parent_finance_id']] = $finance_id;
             // we haven't displayed the parent one yet.
             // display the parent one in this listing.
             $finance = self::get_finance($finance['parent_finance_id']);
         }
         /*if(isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] && isset($finance['invoice_id']) && $finance['invoice_id']){
               // moved to above.
           }else*/
         if (isset($finance['finance_id']) && $finance['finance_id']) {
             $finance['url'] = self::link_open($finance['finance_id'], false);
             $finance['credit'] = $finance['type'] == 'i' ? $finance['amount'] : 0;
             $finance['debit'] = $finance['type'] == 'e' ? $finance['amount'] : 0;
             if (!isset($finance['categories'])) {
                 $finance['categories'] = '';
             }
             if (!isset($finance['account_name'])) {
                 $finance['account_name'] = '';
             }
         }
         if (isset($finance['taxes']) && !isset($finance['sub_amount'])) {
             $finance['sub_amount'] = $finance['amount'];
             foreach ($finance['taxes'] as $tax) {
                 if (isset($tax['amount'])) {
                     $finance['sub_amount'] -= $tax['amount'];
                 }
             }
         }
         $finance['link_count'] = 0;
         $finances[$finance_id] = $finance;
     }
     return $finances;
 }
Esempio n. 4
0
        $finance_debit_total[$finance['currency_id']] += $finance['debit'];
    }
}
// hack to add a "export" option to the pagination results.
if (class_exists('module_import_export', false) && module_finance::can_i('view', 'Export Finance')) {
    $export_settings = array('name' => 'Finance Export', 'parent_form' => 'finance_form', 'fields' => array('Date' => 'transaction_date', 'Name' => 'name', 'URL' => 'url', 'Description' => 'description', 'Credit' => 'credit', 'Debit' => 'debit', 'Account' => 'account_name', 'Categories' => 'categories'), 'summary' => array());
    if (module_config::c('finance_list_show_totals', 1)) {
        foreach ($finance_debit_total + $finance_credit_total as $currency_id => $foo) {
            $currency = get_single('currency', 'currency_id', $currency_id);
            $export_settings['summary'][] = array('description' => _l('%s Totals:', $currency && isset($currency['code']) ? $currency['code'] : ''), 'credit' => dollar(isset($finance_credit_total[$currency_id]) ? $finance_credit_total[$currency_id] : 0, true, $currency_id), 'debit' => dollar(isset($finance_debit_total[$currency_id]) ? $finance_debit_total[$currency_id] : 0, true, $currency_id));
        }
    }
    module_import_export::enable_pagination_hook($export_settings);
}
$upcoming_finances = array();
print_heading(array('title' => _l('Financial Transactions'), 'type' => 'h2', 'main' => true, 'button' => array('title' => _l('Add New'), 'url' => module_finance::link_open('new'), 'type' => 'add')));
?>



<form action="" method="post" id="finance_form" class="search_form">

    <?php 
$categories_rel = array();
foreach (module_finance::get_categories() as $category) {
    $categories_rel[$category['finance_category_id']] = $category['name'];
}
$accounts_rel = array();
foreach (module_finance::get_accounts() as $account) {
    $accounts_rel[$account['finance_account_id']] = $account['name'];
}
Esempio n. 5
0
<p>
    <a href="<?php 
echo module_calendar::link_calendar('alerts', array());
?>
" target="_blank"><?php 
echo module_calendar::link_calendar('alerts', array());
?>
</a>
</p>
<hr>

<?php 
if (is_file('includes/plugin_finance/pages/finance.php')) {
    ?>
<p><?php 
    _e('Here are the URL\'s for <strong>Completed Finance Transactions</strong> (ie: ones you see in the <a href="%s">transaction listing</a> page).', module_finance::link_open(false));
    ?>
</p>
<p>
    Credit Transactions: <a href="<?php 
    echo module_calendar::link_calendar('finance_transactions', array('credit' => 1));
    ?>
" target="_blank"><?php 
    echo module_calendar::link_calendar('finance_transactions', array('credit' => 1));
    ?>
</a> <br/>
    Debit Transactions: <a href="<?php 
    echo module_calendar::link_calendar('finance_transactions', array('debit' => 1));
    ?>
" target="_blank"><?php 
    echo module_calendar::link_calendar('finance_transactions', array('debit' => 1));
     ?>
             </td>
             <td>
                 <?php 
     if (isset($r['invoice_id']) && $r['invoice_id'] > 0) {
         echo module_invoice::link_open($r['invoice_id'], true);
     }
     ?>
             </td>
             <?php 
 } else {
     if (isset($r['finance_id'])) {
         ?>
             <td colspan="3">
                 <?php 
         echo module_finance::link_open($r['finance_id'], true);
         ?>
                 
                 <?php 
         echo htmlspecialchars($r['description']);
         ?>
             </td>
             <?php 
     }
 }
 ?>
             <td>
                 <?php 
 $total += $r['amount'];
 echo dollar($r['amount']);
 ?>
Esempio n. 7
0
                    </td>
                    <td width="30">
                        <?php 
_e('Category:');
?>

                    </td>
                    <td>
                        <?php 
echo print_select_box(module_finance::get_categories(), 'search[finance_category_id]', isset($search['finance_category_id']) ? $search['finance_category_id'] : '', '', true, 'name');
?>

                    </td>
                    <td class="search_action">
                        <?php 
echo create_link("Reset", "reset", module_finance::link_open(false));
?>

                        <?php 
echo create_link("Search", "submit");
?>

                    </td>
                </tr>
            </table>
            </form>

            <script type="text/javascript">
                function link_it(t){
                    // select all others of this same credit/debit price
                    $('.link_box').show();
Esempio n. 8
0
            </th>
            <td valign="top">
                <?php 
if (!isset($recurring['last_transaction_finance_id']) || !$recurring['last_transaction_finance_id']) {
    _e('Never');
} else {
    ?>
 <a href="<?php 
    echo module_finance::link_open($recurring['last_transaction_finance_id']);
    ?>
"><?php 
    echo _l('%s on %s', currency($recurring['last_amount']), print_date($recurring['last_transaction_date']));
    ?>
</a>
                    (<a href="<?php 
    echo module_finance::link_open(false);
    ?>
?search[finance_recurring_id]=<?php 
    echo $finance_recurring_id;
    ?>
"><?php 
    _e('view all');
    ?>
</a>)
                    <?php 
}
?>
            </td>
        </tr>
        <tr>
            <th>