function get($id = NULL){
		global $db_conn;

		if(!isset($id)){
			$id = $this->id;
		}

		if(!isset($id)){
			$this->error = "SI_PaymentSchedule::get() : PaymentSchedule id not set\n";
			return FALSE;
		}

		$PaymentSchedule = SI_PaymentSchedule::retrieveSet("WHERE id = $id", TRUE);
		if($PaymentSchedule === FALSE){
			return FALSE;
		}

		if(isset($PaymentSchedule[0])){
			$this->updateFromAssocArray($PaymentSchedule[0]);
			$this->stripSlashes();
		}else{
			$this->error = "SI_PaymentSchedule::get() : No data retrieved from query\n";
			return FALSE;
		}
		return TRUE;
	}
Beispiel #2
0
	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;
	}