Ejemplo n.º 1
0
	function addExpenses($expense_ids, $aggregation_type = SI_EXPENSE_AGGREGATION_DESC){
		if(!is_array($expense_ids) || count($expense_ids) <= 0){
			$this->error = "SI_Invoice::addExpenses(): Invalid parameter!";
			return FALSE;
		}

		$clause = " WHERE e.id IN (".implode(',', $expense_ids).")";
		$exp = new SI_Expense();
		$expenses = $exp->retrieveSet($clause);
		if($expenses === FALSE){
			$this->error = "SI_Invoice::addExpenses(): Error getting expenses: ".$exp->getLastError();
			return FALSE;
		}

		$expense_count = count($expenses);
		$lines = array();
		for($i=0; $i<$expense_count; $i++){
			if($aggregation_type == SI_EXPENSE_AGGREGATION_DESC){
				if(!isset($lines[md5(strtolower($expenses[$i]->description).'-'.$expenses[$i]->price)])){
					$lines[md5(strtolower($expenses[$i]->description).'-'.$expenses[$i]->price)] = new SI_InvoiceLine();
				}
				$il =& $lines[md5(strtolower($expenses[$i]->description).'-'.$expenses[$i]->price)];
			}elseif($aggregation_type == SI_EXPENSE_AGGREGATION_PRICE){
				if(!isset($lines[(string)$expenses[$i]->price])){
					$lines[(string)$expenses[$i]->price] = new SI_InvoiceLine();
				}
				$il =& $lines[(string)$expenses[$i]->price];
			}else{
				$lines[] = new SI_InvoiceLine();
				$il =& $lines[count($lines) - 1];	
			}
			$il->invoice_id = $this->id;
			$il->quantity += 1;
			$il->item_code_id = $expenses[$i]->item_code_id;
			$il->unit_price = $expenses[$i]->price;
			$il->description = $expenses[$i]->description;
			$il->addLink(SI_INVOICE_LINE_LINK_EXPENSE, $expenses[$i]->id);
			$il->addTax();
		}

		if(!$this->_lines)
			$this->_lines = array();
		
		foreach($lines as $line){
			if($line->add() === FALSE){
				$this->error = "SI_Invoice::addExpenses(): Error adding line item: ".$line->getLastError();
				return FALSE;
			}
			$this->_lines[] = $line;
		}

		return TRUE;
	}
Ejemplo n.º 2
0
	function getUnbilled(){
		return SI_Expense::retrieveSet("WHERE ill.id IS NULL");			
	}