Esempio n. 1
0
			debug_message($item_code->getLastError());
		}
		$task_activity->hourly_rate = $hourly_rate;
		$task_activity->updateFromAssocArray($_POST);
		if($task_activity->update()){
			if(is_array($_POST['item_ids'])){
				if($task_activity->setItems($_POST['item_ids']) === FALSE){
					$error_msg .= "Error adding completed items to activity!\n";
					debug_message($task_activity->getLastError());
				}
			}
			if(is_array($_POST['expense']) && $_POST['expense']['item_code_id'] > 0){
				if(!empty($_POST['expense']['description']) && 
				   !empty($_POST['expense']['cost']) && 
				   !empty($_POST['expense']['price'])){
					$exp = new SI_Expense();
					$exp->updateFromAssocArray($_POST['expense']);
					$exp->task_id = $task_activity->task_id;
					$exp->created_ts = time();
					if($exp->add() === FALSE){
						$error_msg .= "Error adding new expense!\n";
						debug_message($exp->getLastError());	
					}
				}else{
					$error_msg .= "Not adding expense, description, cost and price must all be provided!";	
				}
			}elseif(is_array($_POST['expense']) && $_POST['expense']['item_code_id'] <= 0 && 
					(!empty($_POST['expense']['description']) ||
					!empty($_POST['expense']['cost']) ||
					!empty($_POST['expense']['price'])
					)){
Esempio n. 2
0
echo " -Getting Upcoming Scheduled Payment.\n";
$ps = new SI_PaymentSchedule();
$time = time() + 16 * (24 * (60 * 60));
$ps_items = $ps->getUpcoming($time);
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";
Esempio n. 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;
	}
Esempio n. 4
0
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 */
require_once('includes/common.php');
require_once('includes/SI_Expense.php');
require_once('includes/SI_CompanyTransaction.php');
require_once('includes/SI_Project.php');
require_once('includes/SI_Task.php');
require_once('includes/SI_ItemCode.php');

checkLogin('accounting');

$title = '';
$expense = new SI_Expense();
$company = new SI_Company();
$project = new SI_Project();
$task = new SI_Task();
$item_code = new SI_ItemCode();

// Clean up cost
if(!empty($_POST['cost'])){
	$_POST['cost'] = preg_replace('/[^0-9\.]/','', $_POST['cost']);
}

// Clean up price
if(!empty($_POST['price'])){
	$_POST['price'] = preg_replace('/[^0-9\.]/','', $_POST['price']);
}
Esempio n. 5
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;
	}
	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';
	}
Esempio n. 7
0
	function getUnbilled(){
		return SI_Expense::retrieveSet("WHERE ill.id IS NULL");			
	}