Esempio n. 1
0
            echo '</span>';
        } else {
            echo $hours_value !== false ? $hours_value : '-';
        }
    }
}
if ($show_split_hours) {
    echo '<br/>';
    if ($task_data['staff_hours'] == 0 && $task_data['manual_task_type'] == _TASK_TYPE_AMOUNT_ONLY) {
        // only amount, no hours or qty
    } else {
        // are the logged hours different to the billed hours?
        // are we completed too?
        if ($task_data['staff_hours'] != 0) {
            if ($task_data['manual_task_type'] == _TASK_TYPE_HOURS_AMOUNT && function_exists('decimal_time_out')) {
                $hours_value = decimal_time_out($task_data['staff_hours']);
            } else {
                $hours_value = number_out($task_data['staff_hours'], true);
            }
        } else {
            $hours_value = false;
        }
        if ($percentage == 1 && $task_data['completed'] < $task_data['staff_hours']) {
            echo '<span class="">';
            echo $hours_value !== false ? $hours_value : '-';
            echo '</span>';
        } else {
            if ($percentage == 1 && $task_data['completed'] > $task_data['staff_hours']) {
                echo '<span class="">';
                echo $hours_value !== false ? $hours_value : '-';
                echo '</span>';
Esempio n. 2
0
        ?>

                                    </td>
                                    <?php 
    }
    ?>

                                    <td>
                                        <?php 
    if ($invoice_item_data['manual_task_type'] == _TASK_TYPE_AMOUNT_ONLY) {
        echo '-';
    } else {
        if ($invoice_item_data['hours'] != 0) {
            if ($invoice_item_data['manual_task_type'] == _TASK_TYPE_HOURS_AMOUNT && function_exists('decimal_time_out')) {
                //$hours_value = decimal_time_out($invoice_item_data['hours']);
                $hours_value = isset($invoice_item_data['hours_mins']) && !empty($invoice_item_data['hours_mins']) ? $invoice_item_data['hours_mins'] : decimal_time_out($invoice_item_data['hours']);
            } else {
                $hours_value = number_out($invoice_item_data['hours'], true);
            }
        } else {
            $hours_value = false;
        }
        echo $hours_value ? $hours_value : '-';
    }
    ?>

                                    </td>
                                    <td>
                                        <?php 
    if ($invoice_item_data['task_hourly_rate'] != 0) {
        echo dollar($invoice_item_data['task_hourly_rate'], true, $invoice['currency_id'], $task_decimal_places_trim, $task_decimal_places);
Esempio n. 3
0
 public static function get_invoice_items($invoice_id, $invoice = array())
 {
     $invoice_id = (int) $invoice_id;
     $invoice_items = array();
     if (!$invoice_id && isset($_REQUEST['job_id']) && (int) $_REQUEST['job_id'] > 0) {
         // hack for half completed invoices
         if (isset($_REQUEST['amount_due']) && $_REQUEST['amount_due'] > 0) {
             $amount = (double) $_REQUEST['amount_due'];
             $invoice_items = array('new0' => array('description' => isset($_REQUEST['description']) ? $_REQUEST['description'] : _l('Invoice Item'), 'custom_description' => '', 'long_description' => '', 'custom_long_description' => '', 'amount' => $amount, 'manual_task_type' => _TASK_TYPE_AMOUNT_ONLY, 'hours' => 0, 'taxable' => false, 'task_id' => 0));
         } else {
             $job_id = (int) $_REQUEST['job_id'];
             if ($job_id > 0) {
                 // we return the items from the job rather than the items from the invoice.
                 // for new invoice creation.
                 $tasks = module_job::get_invoicable_tasks($job_id);
                 $x = 0;
                 $job = module_job::get_job($job_id, false);
                 $invoice['hourly_rate'] = $job['hourly_rate'];
                 foreach ($tasks as $task) {
                     if (!isset($task['custom_description'])) {
                         $task['custom_description'] = '';
                     }
                     if (!isset($task['custom_long_description'])) {
                         $task['custom_long_description'] = '';
                     }
                     //$task['task_id'] = 'new'.$x;
                     // the 'hourly_rate' column will hold either
                     // = for hours/amount the default hourly rate from the job
                     // = for qty/amount the raw amount that will multiplu hours by
                     // = for amount only will be the raw amount.
                     $invoice_task_type = isset($task['manual_task_type']) && $task['manual_task_type'] >= 0 ? $task['manual_task_type'] : $job['default_task_type'];
                     if ($invoice_task_type == _TASK_TYPE_QTY_AMOUNT) {
                         $task['hourly_rate'] = $task['amount'];
                         $task['amount'] = 0;
                         // this forces our calc below to calculate teh amount for us.
                     } else {
                         $task['hourly_rate'] = $job['hourly_rate'];
                     }
                     $invoice_items['new' . $x] = $task;
                     $x++;
                 }
                 //print_r($tasks);exit;
             }
         }
     } else {
         if ($invoice_id) {
             if (!$invoice) {
                 $invoice = self::get_invoice($invoice_id, true);
             }
             $sql = "SELECT ii.invoice_item_id AS id, ii.*, t.job_id, t.description AS description, ii.description as custom_description, ii.long_description as custom_long_description, t.task_order, ii.task_order AS custom_task_order ";
             // , j.hourly_rate
             $sql .= ", t.date_done AS task_date_done ";
             $sql .= ", t.task_id ";
             $sql .= " FROM `" . _DB_PREFIX . "invoice_item` ii ";
             $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON ii.task_id = t.task_id ";
             $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` j ON t.job_id = j.job_id ";
             $sql .= " WHERE ii.invoice_id = {$invoice_id}";
             $sql .= " ORDER BY t.task_order ";
             $invoice_items = qa($sql);
         }
     }
     //        print_r($invoice_items);
     // DAVE READ THIS: tasks come in with 'hours' and 'amount' and 'manual_task_type'
     // calculate the 'task_hourly_rate' and 'invoite_item_amount' based on this.
     // 'amount' is NOT used in invoice items. only 'invoice_item_amount'
     //echo '<pre>';print_r($invoice_items);echo '</pre>';
     foreach ($invoice_items as $invoice_item_id => $invoice_item_data) {
         $invoice_item_data['task_hours'] = '';
         $invoice_item_data['task_hours_completed'] = '';
         if (isset($invoice_item_data['job_id']) && $invoice_item_data['task_id'] && $invoice_item_data['job_id'] && $invoice_item_data['task_id']) {
             $job_tasks = module_job::get_tasks($invoice_item_data['job_id']);
             if (isset($job_tasks[$invoice_item_data['task_id']])) {
                 // copied from ajax_task_edit.php:
                 if (function_exists('decimal_time_out')) {
                     $completed_value = decimal_time_out($job_tasks[$invoice_item_data['task_id']]['completed']);
                     $hours_value = decimal_time_out($job_tasks[$invoice_item_data['task_id']]['hours']);
                 } else {
                     $completed_value = number_out($job_tasks[$invoice_item_data['task_id']]['completed'], true);
                     $hours_value = number_out($job_tasks[$invoice_item_data['task_id']]['hours'], true);
                 }
                 $invoice_item_data['task_hours'] = $hours_value;
                 $invoice_item_data['task_hours_completed'] = $completed_value;
             }
         }
         // new feature, task type.
         $invoice_item_data['manual_task_type_real'] = $invoice_item_data['manual_task_type'];
         if ($invoice_item_data['manual_task_type'] < 0 && isset($invoice['default_task_type'])) {
             $invoice_item_data['manual_task_type'] = $invoice['default_task_type'];
         }
         if (isset($invoice_item_data['hours_mins'])) {
             if ($invoice_item_data['hours_mins'] == 0) {
                 $invoice_item_data['hours_mins'] = 0;
             } else {
                 $invoice_item_data['hours_mins'] = str_replace(".", ":", $invoice_item_data['hours_mins']);
             }
         }
         // if there are no hours logged against this task
         if (!$invoice_item_data['hours']) {
             //$invoice_item_data['task_hourly_rate']=0;
         }
         // task_hourly_rate is used for calculations, if the hourly_rate is -1 then we use the default invoice hourly rate
         $invoice_item_data['task_hourly_rate'] = isset($invoice_item_data['hourly_rate']) && $invoice_item_data['hourly_rate'] != 0 && $invoice_item_data['hourly_rate'] != -1 ? $invoice_item_data['hourly_rate'] : $invoice['hourly_rate'];
         // if we have a custom price for this task
         if ($invoice_item_data['manual_task_type'] == _TASK_TYPE_HOURS_AMOUNT) {
             if ($invoice_item_data['amount'] != 0) {
                 $invoice_item_data['invoice_item_amount'] = $invoice_item_data['amount'];
                 if ($invoice_item_data['hours'] == 0) {
                     // hack to fix $0 invoices
                     $invoice_item_data['hours'] = 1;
                     $invoice_item_data['task_hourly_rate'] = $invoice_item_data['amount'];
                 }
                 //echo '<pre>';print_r($invoice_items);echo '</pre>';
                 if (isset($invoice_item_data['hours_mins']) && !empty($invoice_item_data['hours_mins']) && function_exists('decimal_time_in')) {
                     $invoice_item_data['hours'] = decimal_time_in($invoice_item_data['hours_mins']);
                 }
                 if ($invoice_item_data['task_hourly_rate'] * $invoice_item_data['hours'] != $invoice_item_data['amount']) {
                     // check the rounding, just to be sure.
                     if (round($invoice_item_data['task_hourly_rate'] * $invoice_item_data['hours'], 2) == round($invoice_item_data['amount'], 2)) {
                         // all good
                     } else {
                         // hack to fix manual amount with non-matching hours.
                         $invoice_item_data['task_hourly_rate'] = $invoice_item_data['amount'] / $invoice_item_data['hours'];
                     }
                 }
             } else {
                 $invoice_item_data['invoice_item_amount'] = $invoice_item_data['task_hourly_rate'] * $invoice_item_data['hours'];
             }
         } else {
             if ($invoice_item_data['manual_task_type'] == _TASK_TYPE_QTY_AMOUNT) {
                 if ($invoice_item_data['amount'] != 0) {
                     $invoice_item_data['invoice_item_amount'] = $invoice_item_data['amount'];
                 } else {
                     $invoice_item_data['invoice_item_amount'] = $invoice_item_data['task_hourly_rate'] * $invoice_item_data['hours'];
                 }
                 //$invoice_item_data['amount'] = $invoice_item_data['hourly_rate'] * $invoice_item_data['hours'];
                 //$invoice_item_data['invoice_item_amount']  = $invoice_item_data['amount'];
                 //$invoice_item_data['task_hourly_rate'] = $invoice_item_data['hourly_rate'];
                 /*if($invoice_item_data['hours']>0){
                       $invoice_item_data['task_hourly_rate'] = round($invoice_item_data['invoice_item_amount']/$invoice_item_data['hours'],module_config::c('currency_decimal_places',2));
                   }else{
                   }*/
             } else {
                 // this item is an 'amount only' column.
                 // no calculations based on quantity and hours.
                 if ($invoice_item_data['amount'] != 0) {
                     $invoice_item_data['task_hourly_rate'] = $invoice_item_data['amount'];
                     $invoice_item_data['invoice_item_amount'] = $invoice_item_data['amount'];
                 } else {
                     $invoice_item_data['task_hourly_rate'] = 0;
                     $invoice_item_data['invoice_item_amount'] = 0;
                 }
                 /*
                 
                                 $invoice_item_data['task_hourly_rate'] = isset($invoice_item_data['hourly_rate']) && $invoice_item_data['hourly_rate']>0 ? $invoice_item_data['hourly_rate'] : $invoice['hourly_rate'];
                 
                                 if($invoice_item_data['amount']!=0 && $invoice_item_data['amount'] != ($invoice_item_data['hours']*$invoice_item_data['task_hourly_rate'])){
                                     $invoice_item_data['invoice_item_amount'] = $invoice_item_data['amount'];
                                     if(module_config::c('invoice_calculate_item_price_auto',1) && $invoice_item_data['hours'] > 0){
                                         $invoice_item_data['task_hourly_rate'] = round($invoice_item_data['invoice_item_amount']/$invoice_item_data['hours'],module_config::c('currency_decimal_places',2));
                                     }else{
                                         $invoice_item_data['task_hourly_rate'] = false;
                                     }
                                 }else if($invoice_item_data['hours']>0){
                                     $invoice_item_data['invoice_item_amount'] = $invoice_item_data['hours']*$invoice_item_data['task_hourly_rate'];
                                 }else{
                                     $invoice_item_data['invoice_item_amount'] = 0;
                                     $invoice_item_data['task_hourly_rate'] = false;
                                 }*/
             }
         }
         /*$invoice_item_amount = $invoice_item_data['amount'] > 0 ? $invoice_item_data['amount'] : $invoice_item_data['hours']*$task_hourly_rate;
           if($invoice_item_data['amount']>0 && !$invoice_item_data['hours']){
               $invoice_item_amount = $invoice_item_data['amount'];
               $invoice_item_data['hours'] = 1;
               $task_hourly_rate = $invoice_item_data['amount']; // not sure if this will be buggy
           }else{
               $invoice_item_amount = $invoice_item_data['hours']*$task_hourly_rate;
           }*/
         // new feature, date done.
         if (isset($invoice_item_data['date_done']) && $invoice_item_data['date_done'] != '0000-00-00') {
             // $invoice_item_data['date_done'] is ok to print!
         } else {
             $invoice_item_data['date_done'] = '0000-00-00';
             // check if this is linked to a task.
             if ($invoice_item_data['task_id']) {
                 if (isset($invoice_item_data['task_date_done'])) {
                     // moved it into SQL above, instead of doing a get_single() call below for each invoice line item
                     if ($invoice_item_data['task_date_done'] && $invoice_item_data['task_date_done'] != '0000-00-00') {
                         $invoice_item_data['date_done'] = $invoice_item_data['task_date_done'];
                     } else {
                         if (isset($invoice['date_create']) && $invoice['date_create'] != '0000-00-00') {
                             $invoice_item_data['date_done'] = $invoice['date_create'];
                         }
                     }
                 } else {
                     $task = get_single('task', 'task_id', $invoice_item_data['task_id']);
                     if ($task && isset($task['date_done']) && $task['date_done'] != '0000-00-00') {
                         $invoice_item_data['date_done'] = $task['date_done'];
                         // move it over ready for printing below
                     } else {
                         if (isset($invoice['date_create']) && $invoice['date_create'] != '0000-00-00') {
                             $invoice_item_data['date_done'] = $invoice['date_create'];
                         }
                     }
                 }
             }
         }
         // set a default taxes to match the invoice taxes if none defined
         if ((!isset($invoice_item_data['taxes']) || !count($invoice_item_data['taxes'])) && isset($invoice_item_data['taxable']) && $invoice_item_data['taxable'] && isset($invoice['taxes']) && count($invoice['taxes'])) {
             $invoice_item_data['taxes'] = $invoice['taxes'];
         }
         if (!isset($invoice_item_data['taxes'])) {
             $invoice_item_data['taxes'] = array();
         }
         $invoice_items[$invoice_item_id] = $invoice_item_data;
     }
     //print_r($invoice_items);exit;
     return $invoice_items;
 }
Esempio n. 4
0
    echo _l('%s of %s hours have been logged:', $completed_value, $hours_value);
    ?>
            <input type="hidden" name="job_task[<?php 
    echo $task_id;
    ?>
][completed]" value="<?php 
    echo $task_data['completed'];
    ?>
">
            <br/>
            <?php 
    // show a log of any existing hours against this task.
    $task_logs = module_job::get_task_log($task_id);
    foreach ($task_logs as $task_log) {
        if (function_exists('decimal_time_out')) {
            $hours_value = decimal_time_out($task_log['hours']);
        } else {
            $hours_value = number_out($task_log['hours'], true);
        }
        echo _l('%s hrs <span class="text_shrink">%s</a> - <span class="text_shrink">%s</span>', $hours_value, print_date($task_log['log_time'], true), $staff_member_rel[$task_log['create_user_id']]);
        ?>
 <a href="#" class="error_text" onclick="return delete_task_hours(<?php 
        echo $task_id;
        ?>
,<?php 
        echo $task_log['task_log_id'];
        ?>
);">x</a> <?php 
        echo '<br/>';
    }
}
Esempio n. 5
0
           $task = get_single('quote_task','quote_task_id',$quote_item_data['quote_task_id']);
           if($task && isset($task['date_done']) && $task['date_done'] != '0000-00-00'){
               $row_replace['item_date'] .= print_date($task['date_done']);
           }else{
               // check if quote has a date.
               if(isset($quote['date_create']) && $quote['date_create'] != '0000-00-00'){
                   $row_replace['item_date'] .= print_date($quote['date_create']);
               }
           }
       }
   }*/
 if ($quote_item_data['manual_task_type'] == _TASK_TYPE_AMOUNT_ONLY) {
     $row_replace['item_qty_or_hours'] = '-';
 } else {
     if ($quote_item_data['manual_task_type'] == _TASK_TYPE_HOURS_AMOUNT && function_exists('decimal_time_out')) {
         $hours_value = decimal_time_out($quote_item_data['hours']);
     } else {
         $hours_value = number_out($quote_item_data['hours'], true);
     }
     $row_replace['item_qty_or_hours'] = $hours_value ? $hours_value : '-';
 }
 if ($quote_item_data['task_hourly_rate'] != 0) {
     $row_replace['item_amount_or_rate'] = dollar($quote_item_data['task_hourly_rate'], true, $quote['currency_id'], $task_decimal_places_trim, $task_decimal_places);
 } else {
     $row_replace['item_amount_or_rate'] = '-';
 }
 $row_replace['item_total'] = dollar($quote_item_data['quote_item_amount'], true, $quote['currency_id']);
 // taxes per item
 if (isset($quote_item_data['taxes']) && is_array($quote_item_data['taxes']) && $quote_item_data['taxable'] && class_exists('module_finance', false)) {
     // this passes off the tax calculation to the 'finance' class, which modifies 'amount' to match the amount of tax applied here.
     $this_taxes = module_finance::sanatise_taxes($quote_item_data['taxes'], $quote_item_data['quote_item_amount']);
Esempio n. 6
0
        </td>
    </tr>
    <tr>
	    <?php 
        if ($show_task_numbers) {
            ?>
	    <td>&nbsp;</td>
	    <?php 
        }
        ?>
        <td>
            <?php 
        if ($show_hours_summary) {
            ?>
            <?php 
            echo _l('%s Hours / %s Tasks Remain', function_exists('decimal_time_out') ? decimal_time_out($job['total_hours_remain']) : $job['total_hours_remain'], $job['total_tasks_remain']);
            ?>
            <?php 
            if ($job['total_amount_todo'] > 0) {
                ?>
                <span class="error_text">
                    (<?php 
                echo dollar($job['total_amount_todo'], true, $job['currency_id']);
                ?>
)
                </span>
            <?php 
            }
            ?>
            <?php 
        }
Esempio n. 7
0
         $task = get_single('task', 'task_id', $invoice_item_data['task_id']);
         if ($task && isset($task['date_done']) && $task['date_done'] != '0000-00-00') {
             $row_replace['item_date'] .= print_date($task['date_done']);
         } else {
             // check if invoice has a date.
             if (isset($invoice['date_create']) && $invoice['date_create'] != '0000-00-00') {
                 $row_replace['item_date'] .= print_date($invoice['date_create']);
             }
         }
     }
 }
 if ($invoice_item_data['manual_task_type'] == _TASK_TYPE_AMOUNT_ONLY) {
     $row_replace['item_qty_or_hours'] = '-';
 } else {
     if ($invoice_item_data['manual_task_type'] == _TASK_TYPE_HOURS_AMOUNT && function_exists('decimal_time_out')) {
         $hours_value = decimal_time_out($invoice_item_data['hours']);
     } else {
         $hours_value = number_out($invoice_item_data['hours'], true);
     }
     $row_replace['item_qty_or_hours'] = $hours_value ? $hours_value : '-';
 }
 if ($invoice_item_data['task_hourly_rate'] != 0) {
     $row_replace['item_amount_or_rate'] = dollar($invoice_item_data['task_hourly_rate'], true, $invoice['currency_id'], $task_decimal_places_trim, $task_decimal_places);
 } else {
     $row_replace['item_amount_or_rate'] = '-';
 }
 $row_replace['item_total'] = dollar($invoice_item_data['invoice_item_amount'], true, $invoice['currency_id']);
 // taxes per item
 if (isset($invoice_item_data['taxes']) && is_array($invoice_item_data['taxes']) && $invoice_item_data['taxable'] && class_exists('module_finance', false)) {
     // this passes off the tax calculation to the 'finance' class, which modifies 'amount' to match the amount of tax applied here.
     foreach ($invoice_item_data['taxes'] as $key => $val) {