Example #1
0
if ($ps_items === FALSE) {
    echo "****ERR: Could not retreive upcoming scheduled billings! ****\n";
    debug_message($ps->getLastError());
} elseif (count($ps_items) > 0) {
    foreach ($ps_items as $scheduled_payment) {
        $ps_comp = $scheduled_payment->getCompany();
        $comp_ids[] = $ps_comp->id;
        echo "  * {$ps_comp->id} \n";
    }
}
echo " -Getting unbilled expenses.\n";
$expense = new SI_Expense();
$expenses = $expense->getUnbilled();
if ($expenses === FALSE) {
    echo "****ERR: Could not retreive unbilled expenses! ****\n";
    debug_message($expense->getLastError());
} elseif (count($expenses) > 0) {
    foreach ($expenses as $exp) {
        $comp_ids[] = $exp->getCompany()->id;
        echo "  * " . $exp->getCompany()->id . " \n";
    }
}
echo "\n\n\$\$\$\$ START MAKIN MONEY \$\$\$\$\n\n";
$comp_ids = array_unique($comp_ids);
if (count($comp_ids) > 0) {
    foreach ($comp_ids as $compid) {
        echo "\$\$\$ Generating Invoice for Company_id - {$compid}\n";
        $invoice = new SI_Invoice();
        $company = new SI_Company();
        if ($company->get($compid)) {
            $company_array = get_object_vars($company);
Example #2
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;
	}
Example #3
0
	function getExpenses($unbilled = FALSE){
		$exp = new SI_Expense();
		$expenses = $exp->getForProject($this->id, $unbilled);
		if($expenses === FALSE){
			$this->error = "SI_Project::getExpenses(): " . $exp->getLastError();
			return FALSE;
		}
		
		return $expenses;
	}
	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';
	}