} if(empty($error_msg)){ goBack(); } }else{ $error_msg .= "Error adding Task Activity!\n"; debug_message($task_activity->getLastError()); } } }else if($_REQUEST['mode'] == 'edit'){ $title = "Edit Time Entry"; if(empty($_REQUEST['id'])){ $error_msg .= "Error: No ID specified!\n"; }else{ if(!$task_activity->get($_REQUEST['id'])){ fatal_error("Could not retreive task activity!"); debug_message($task_activity->getLastError()); } if($task->get($task_activity->task_id) === FALSE){ fatal_error("Could not retreive task!"); debug_message($task->getLastError()); } if($project->get($task->project_id) === FALSE){ fatal_error("Could not retreive project!"); debug_message($project->getLastError()); } if(!$project->hasRights(PROJECT_RIGHT_EDIT)){ fatal_error('Insufficent access rights for this project!'); }
?> "><img src="images/edit.png" width="16" height="16" title="Edit Line" border="0" /></a> </td> <td class="gridActions"> <a class="link1" href="invoice_line.php?mode=delete&id=<?php echo $invoice->_lines[$i]->id; ?> "><img src="images/delete.png" width="16" height="16" title="Delete Line" border="0" /></a> </td> </tr> <? if($_REQUEST['detail']){ $links =& $invoice->_lines[$i]->_links; for($x=0; $x<count($links); $x++){ if($links[$x]->task_activity_id > 0){ $ta = new SI_TaskActivity(); $ta->get($links[$x]->task_activity_id); ?> <tr> <td colspan="11" class="dg_data_cell_1"> <table cellpadding="2" cellspacing="0"> <tr> <td valign="top" nowrap><b><?php echo date("n/j/y H:i", $ta->start_ts) . "-" . date("H:i", $ta->end_ts); ?> </b></td> <td valign="top"><?php echo $ta->text; ?> </td> </tr> </table> </td>
function addDiscountLine(){ if($this->company_id == 0){ $this->error = "SI_Invoice::addDiscountLine(): Company ID is not set\n"; return FALSE; } $discount_amount = 0.00; $company =& $this->getCompany(); $rs =& $company->getRateStructure(); //Get all months with time on this invoice $time = array(); foreach($this->_lines as $line){ if(in_array($line->item_code_id, $rs->item_code_ids) && $line->getType() == 'Task Activity'){ $links =& $line->getLinks(); foreach($links as $link){ $ta = new SI_TaskActivity(); if($ta->get($link->task_activity_id) === FALSE){ $this->error = "SI_Invoice::addDiscountLine(): Error getting task activity!\n"; return FALSE; } $time[date('n-Y', $ta->start_ts)]['new_hours'] += ($ta->end_ts - $ta->start_ts) / 60 / 60; } } } //Get billed hours for the months on this invoice foreach($time as $month => $hours){ $time[$month]['billed_hours'] = $company->getBilledQuantity($rs->item_code_ids, $month) - $time[$month]['new_hours']; } // var_dump($time); //Calculate Discount $discount = 0.00; foreach($time as $month => $hours){ // debug_message("Looking at month $month with billed hours of ".$hours['billed_hours']." and new hours of ".$hours['new_hours']); $ranges = $rs->getLines(); $current_hours = $hours['billed_hours']; $total_hours = $hours['billed_hours'] + $hours['new_hours']; foreach($ranges as $range){ // debug_message("Looking at range {$range->low} - {$range->high} with current hours of $current_hours"); if($range->high > 0 && $current_hours <= $range->high){ // debug_message("$current_hours is below range high"); if($current_hours < $range->low){ // debug_message("$current_hours is below range low adding ".($range->low - $current_hours)." to current hours"); $current_hours += $range->low - $current_hours; } if($current_hours < $range->high && $total_hours > $range->high){ // debug_message("$total_hours is above range high adding ".($range->high - $current_hours)." hours"); $discount += ($range->high - $current_hours) * $range->discount; $current_hours += ($range->high - $current_hours); }elseif($current_hours <= $range->high){ // debug_message("Adjusting discount and current hours for range with ".($total_hours - $current_hours)." hours"); $discount += ($total_hours - $current_hours) * $range->discount; $current_hours += ($total_hours - $current_hours); } }else{ if($range->high == 0){ // debug_message("range high is 0 adding ".($total_hours - $current_hours)." hours to discount."); $discount += ($total_hours - $current_hours) * $range->discount; } } } } var_dump($discount); //TODO Add discount line item $new_line = array(); $new_line[0]['item_code_id'] = $rs->discount_item_code_id; $new_line[0]['quantity'] = 1; $new_line[0]['description'] = 'Volume Discount'; $new_line[0]['price'] = $discount; return $this->addCustomLines($new_line); }
function getActivityDetailHTML($id){ global $loggedin_user; $ta = new SI_TaskActivity(); if($ta->get($id) === false){ return "Error getting detail for $id: ".$this->getLastError(); } $html = ''; //$html .= print_r($ta, true); $html .= '<div class="ad_div">'; $html .= '<span class="ad_label">Company:</span> '.$ta->company_name.'<br/>'; $html .= '<span class="ad_label">User:</span> '.$ta->getUserName().'<br/>'; if($loggedin_user->hasRight('accounting')){ $html .= '<span class="ad_label">Hourly Cost:</span> '.$ta->hourly_cost.'<br/>'; $html .= '<span class="ad_label">Hourly Rate:</span> '.$ta->hourly_rate.'<br/>'; } $html .= '<span class="ad_label">Note:</span><br/>'.nl2br($ta->text).'<br/>'; $html .= '</div>'; return $html; }
function getUnitPrice(){ if($this->task_activity_id > 0){ $ta = new SI_TaskActivity(); if($ta->get($this->task_activity_id) === FALSE){ $this->error = 'SI_InvoiceLineLink::getUnitPrice(): Error getting task activity: '.$ta->getLastError(); return FALSE; } return $ta->hourly_rate; }elseif($this->expense_id > 0){ $ex = new SI_Expense(); if($ex->get($this->expense_id) === FALSE){ $this->error = 'SI_InvoiceLineLink::getPrice(): Error getting expense: '.$ex->getLastError(); return FALSE; } return $ex->price; }elseif($this->payment_schedule_id > 0){ $ps = new SI_PaymentSchedule(); if($ps->get($this->payment_schedule_id) === FALSE){ $this->error = 'SI_InvoiceLineLink::getPrice(): Error getting scheduled payment: '.$ps->getLastError(); return FALSE; } return $ps->amount; } return 'Unknown'; }