function addPaymentSchedules($ps_ids){ if(!is_array($ps_ids) || count($ps_ids) <= 0){ $this->error = "SI_Invoice::addPaymentSchedules(): Invalid parameter!"; return FALSE; } $clause = " WHERE id IN (".implode(',', $ps_ids).")"; $ps = new SI_PaymentSchedule(); $ps_items = $ps->retrieveSet($clause); if($ps_items === FALSE){ $this->error = "SI_Invoice::addPaymentSchedules(): Error getting payment schedules: ".$ps->getLastError(); return FALSE; } $ps_count = count($ps_items); $lines = array(); for($i=0; $i<$ps_count; $i++){ if($ps_items[$i]->getProject() === FALSE){ $this->error = "SI_Invoice::addPaymentSchedules(): Error getting project for payment schedule: ".$tas[$i]->getLastError(); return FALSE; } $il = new SI_InvoiceLine(); $il->invoice_id = $this->id; $il->quantity = 1; $il->item_code_id = $ps_items[$i]->item_code_id; $il->unit_price = $ps_items[$i]->amount; $il->description = $ps_items[$i]->_project->name.": ".$ps_items[$i]->description; $ill = new SI_InvoiceLineLink(); $ill->payment_schedule_id = $ps_items[$i]->id; $il->_links[] = $ill; $il->addTax(); $lines[] = $il; } if(!$this->_lines) $this->_lines = array(); foreach($lines as $line){ if($line->add() === FALSE){ $this->error = "SI_Invoice::addPaymentSchedules(): Error adding line item: ".$line->getLastError(); return FALSE; } $this->_lines[] = $line; } return TRUE; }
$end_ts = getTSFromInput($_POST['end_ts']); $created_ps = SI_PaymentSchedule::generateScheduledPayments($_POST['project_id'], $_POST['task_id'], $_POST['recurrence'], $start_ts, $end_ts, $_POST['item_code_id'], $_POST['description'], $_POST['amount']); if($created_ps === FALSE){ $error_msg .= "Error creating scheduled payments!\n"; }else{ //var_dump($created_ps); goBack(); } }else{ $_POST['due_ts'] = getTSFromInput($_POST['due_ts']); $ps->updateFromAssocArray($_POST); if($ps->add()){ goBack(); }else{ $error_msg .= "Error adding Payment Schedule!\n"; debug_message($ps->getLastError()); } } } }else if($_REQUEST['mode'] == 'edit'){ $title = "Edit Payment Schedule"; if(empty($_REQUEST['id'])){ $error_msg .= "Error: No ID specified!\n"; }else{ if(!$ps->get($_REQUEST['id'])){ $error_msg .= "Error retrieving payment information!\n"; debug_message($ps->getLastError()); } } if($ps->task_id > 0){
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'; }