Ejemplo n.º 1
0
// Create checks
$check = new SI_Check();
foreach ($checks as $number => $data) {
    if ($number == 0) {
        continue;
    }
    //	debug("Going to create check $number for amount ".$data['amount']." with ids ".join(', ', $data['ids']));
    $check->user_id = $data['user_id'];
    $check->number = $number;
    $check->timestamp = $data['timestamp'];
    $check->amount = $data['amount'];
    $check->type = 'CHECK';
    $check->name = $users[$data['user_id']]['first_name'] . ' ' . $users[$data['user_id']]['last_name'];
    $check->address1 = $users[$data['user_id']]['address1'];
    $check->address2 = $users[$data['user_id']]['address2'];
    $check->city = $users[$data['user_id']]['city'];
    $check->state = $users[$data['user_id']]['state'];
    $check->zip = $users[$data['user_id']]['zip'];
    assert_die($check->add(), "Error adding check: " . $check->getLastError());
    assert_die($check->attachCostTransactions($data['ids']), "Error adding cost transactions to check: " . $check->getLastError());
    // Add user transaction
    $ut = new SI_UserTransaction();
    $ut->amount = -$check->amount;
    $ut->description = "Check #" . $check->number;
    $ut->timestamp = $check->timestamp;
    $ut->user_id = $check->user_id;
    assert_die($ut->add(), "Error adding user transaction: " . $ut->getLastError());
    // Update check trans id
    $check->trans_id = $ut->id;
    assert_die($check->update(), "Error updating transaction id for check: " . $check->getLastError());
}
Ejemplo n.º 2
0
				$error_msg .= "Error adding cost transactions to check!";
				debug_message($check->getLastError());
			}

			if($check->attachCommTransactions($comm_trans_ids) === FALSE){
				$error_msg .= "Error adding commission transactions to check!";
				debug_message($check->getLastError());
			}

			// Add user transaction
			if($check->type == 'CHECK'){
				$desc = "Check #".$check->number;
			}elseif($check->type == "EFT"){
				$desc = "Electronic Funds Transfer";
			}
			$ut = new SI_UserTransaction();
			$ut->amount = -$total_amount;
			$ut->description = $desc;
			$ut->timestamp = $check->timestamp;
			$ut->user_id = $user->id;
			if($ut->add() === FALSE){
				$error_msg .= "Error adding user transaction";
				debug_message($ut->getLastError());
			}else{
				$check->trans_id = $ut->id;
				if($check->update() === FALSE){
					$error_msg .= "Error updating transaction id for check";
					debug_message($check->getLastError());
				}
			}
			
Ejemplo n.º 3
0
	function _getUserTrans(){
		$trans_id = intval($this->trans_id);
		if($trans_id <= 0)
			return TRUE;
			
		if($this->_ut == FALSE){
			$ut = new SI_UserTransaction();
			if($ut->get($trans_id) === FALSE){
				$this->error = "Error getting linked transaction: ".$ut->getLastError();
				return FALSE;	
			}
			$this->_ut = &$ut;
		}
		
		return TRUE;
	}
Ejemplo n.º 4
0
	function getTransactionCount($id = NULL){
		global $db_conn;

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

		$ut = new SI_UserTransaction();
		$result = $ut->getTransactionCount($id);
		if($result === FALSE){
			$this->error = "SI_User::getTransactions(): Error getting transaction count: ".$ut->getLastError();
			return FALSE;
		}

		return $result;
	}
Ejemplo n.º 5
0
	function _updateTransactions($oldTA = null){
		$ut = new SI_UserTransaction();
		$ct = new SI_CompanyTransaction();

		if($this->start_ts > 0 && $this->end_ts > 0){
			$task = $this->getTask();
			if($task === FALSE)
				return FALSE;

			$project = $task->getProject();
			if($project === FALSE){
				$this->error = "SI_TaskActivity::_updateTransactions(): Error getting project: ".$task->getLastError();
				return FALSE;
			}

			$company = $project->getCompany();
			if($company === FALSE){
				$this->error = "SI_TaskActivity::_updateTransactions(): Error getting company: ".$project->getLastError();
				return FALSE;
			}

			if(is_null($oldTA) || $oldTA->start_ts != $this->start_ts || $oldTA->end_ts != $this->end_ts){
		
				// Calculate cost
				if($this->_calcCost() === FALSE)
					return FALSE;
	
				// Add cost transaction
				$act_user = $this->getUser();
	//			print("TA cost is ".$this->cost."\n");
				if($this->cost > 0.00 && $act_user->rate_type != 'SALARY'){
					$cost_trans = new SI_UserTransaction();
					$cost_trans->amount = $this->cost;
					// TODO Remove after migration is completed
					if(isset($GLOBALS['phpdt_import']) && $GLOBALS['phpdt_import'] == true){
						$cost_trans->timestamp = $GLOBALS['phpdt_cost_ts'];
					}else{ 
						$cost_trans->timestamp = time();
					}
					$cost_trans->description = $project->name.": ".$task->name;
					$cost_trans->user_id = $this->user_id;
					if($cost_trans->add() === FALSE){
						$this->error = "SI_TaskActivity::_updateTransactions(): Error adding cost transaction: ".$cost_trans->getLastError();
						return FALSE;
					}
		
					// Set cost trans id
					$this->cost_trans_id = $cost_trans->id;
				}else{
					$this->cost_trans_id = 0;	
				}
			}
			
			if($task->isBillable() || $task->isSpec()){
				if($task->hasCommission()){
					// Calculate commission
					if($this->_calcCommission() === FALSE)
						return FALSE;

					// Add commission transaction
					$sct_user = $task->getSalesCommissionUser();
					if($sct_user === FALSE){
						$this->error = "SI_TaskActivity::_updateTransactions(): Error getting sales commission user: "******"Commission on Task ".$task->name;
					$com_trans->user_id = $sct_user->id;
					if($com_trans->add() === FALSE){
						$this->error = "SI_TaskActivity::_updateTransactions(): Error adding cost transaction: ".$com_trans->getLastError();
						return FALSE;
					}

					// Set commission trans id
					$this->com_trans_id = $com_trans->id;
				}else{
					$this->com_trans_id = 0;
				}
			}

		}else{
			// It's not completed so 0-out all trans ids
			$this->com_trans_id = 0;
			$this->cost_trans_id = 0;
		}

		// Delete any remaining old transactions
		if($oldTA != null){
			if(($oldTA->com_trans_id != 0 && $this->com_trans_id == 0) ||
				 ($oldTA->com_trans_id != $this->com_trans_id)){
				$ut = new SI_UserTransaction();
				if($ut->delete($oldTA->com_trans_id) === FALSE){
					$this->error = "SI_TaskActivity::_updateTransactions(): Error removing commission transaction: ".$ut->getLastError();
					return FALSE;
				}
			}

			if(($oldTA->cost_trans_id != 0 && $this->cost_trans_id == 0) ||
				 ($oldTA->cost_trans_id != $this->cost_trans_id)){
				if($ut->delete($oldTA->cost_trans_id) === FALSE){
					$this->error = "SI_TaskActivity::_updateTransactions(): Error removing cost transaction: ".$ut->getLastError();
					return FALSE;
				}
			}
		}
	}
Ejemplo n.º 6
0
	function get($id = NULL){
		global $db_conn;

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

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

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

		if(isset($UserTransaction[0])){
			$this->_populateData($UserTransaction[0]);
			$this->stripSlashes();
		}else{
			$this->error = "SI_UserTransaction::get() : No data retrieved from query\n";
			return FALSE;
		}
		return TRUE;
	}