Example #1
0
 * You should have received a copy of the GNU General Public License along
 * 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_Check.php');
require_once('includes/SI_User.php');
require_once('includes/SI_UserTransaction.php');
require_once('includes/SI_TaskActivity.php');

checkLogin();

$activity = new SI_TaskActivity();
$check = new SI_Check();

$user = new SI_User();
if($user->get($_REQUEST['user_id']) === FALSE){
	$error_msg .= "Could not retrieve information for User ID ".$_REQUEST['user_id']."!\n";
	debug_message($user->getLastError());
}

$activities = $user->getActivities($user->id);
if($activities === FALSE){
	$error_msg .= "Could not retrieve Activity List for User ID ".$user->id."!\n";
	debug_message($user->getLastError());
}

$commissions = $user->getCommissions($user->id);
if($commissions === FALSE){
    $invoice_result = $si_db->query($invoice_insert_sql, TRUE);
    assert_die($invoice_result, "Could not add invoice!\n" . $si_db->getLastError());
    // Add activities
    $invoice->get($number);
    //	debug("Adding line items to invoice ".$invoice->id);
    assert_die($invoice->addTaskActivities($data['ids']), "Error adding task activities to invoice: " . $invoice->getLastError());
    // Add the company transaction
    $ct = new SI_CompanyTransaction();
    $ct->amount = $invoice->getTotal();
    $ct->company_id = $invoice->company_id;
    $ct->description = "Invoice #" . $invoice->id;
    $ct->timestamp = $invoice->timestamp;
    assert_die($ct->add(), "Error adding company transaction: " . $ct->getLastError());
}
// 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'];
Example #3
0
	function getByNumber($number){
		$Check = SI_Check::retrieveSet("WHERE number = '$number'", TRUE);
		if($Check === FALSE){
			return FALSE;
		}

		if(isset($Check[0])){
			$this->_populateData($Check[0]);
			if($this->_populateCommTransactions() === FALSE)
				return FALSE;
			if($this->_populateCostTransactions() === FALSE)
				return FALSE;
			$this->stripSlashes();
		}else{
			$this->error = "SI_Check::getByNumber() : No data retrieved from query\n";
			return FALSE;
		}
		return TRUE;
	}
Example #4
0
	function getChecks($id = NULL, $limit = 0, $offset = 0){
		global $db_conn;

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

		$limit_sql = '';		
		if($limit > 0 || $offset > 0){
			$limit_sql = " LIMIT $offset, $limit ";
		}

		$check = new SI_Check();
		$result = $check->retrieveSet("WHERE user_id = $id $limit_sql");
		if($result === FALSE){
			$this->error = "SI_User::getChecks(): Error getting checks: ".$check->getLastError();
			return FALSE;
		}

		return $result;
	}
Example #5
0
$user = new SI_User();
$users = $user->getUnpaidUsers();
if($users === FALSE){
	$error_msg .= "Could not retrieve Unpaid Users's list!\n";
	debug_message($user->getLastError());
}

$invoice = new SI_Invoice();
$invoices = $invoice->getOutstanding();
if($invoices === FALSE){
	$error_msg .= "Could not retrieve Outstanding Invoice list!\n";
	debug_message($invoice->getLastError());
}

$check = new SI_Check();
$checks = $check->retrieveSet("ORDER BY timestamp DESC LIMIT 5");
if($checks === FALSE){
	$error_msg .= "Could not retrieve Check list!\n";
	debug_message($check->getLastError());
}

$ps = new SI_PaymentSchedule();
$time = time() + 30 * (24 * (60 * 60));
$ps_items = $ps->getUpcoming($time);
if($ps_items === FALSE){
	$error_msg .= "Could not retreive upcoming scheduled billings!\n";
	debug_message($ps->getLastError());
}

$expense = new SI_Expense();
Example #6
0
		if($loggedin_user->company_id != $invoice->company_id){
			fatal_error('You do not have access to view this invoice!');
		}
	}
	
	$activities = $activity->getActivitiesForCompany(0, TRUE, $_REQUEST['invoice']);
	if($activities === FALSE){
		$error_msg .= "Could not retrieve Activity List for Invoice ".$_REQUEST['invoice']."!\n";
		debug_message($activity->getLastError());
	}
}else if($_REQUEST['check']){
	$title = "for Check Number ".$_REQUEST['check'];
	$field_header = 'Paid';
	$field = 'check';
	$url = $_SERVER['PHP_SELF']."?check=".$_REQUEST['check']."&";
	$check = new SI_Check();
	if($check->getByNumber($_REQUEST['check']) === FALSE){
		$error_msg .= "Could not retrieve Activity List for Check ".$_REQUEST['check']."!\n";
		debug_message($check->getLastError());
	}
	if(!$loggedin_user->hasRight('admin') && !$loggedin_user->hasRight('accounting')){
		if($loggedin_user->id != $check->user_id){
			fatal_error('You do not have access to view this check!');
		}
	}
	
	$activities = $check->getActivities();
	if($activities === FALSE){
		$error_msg .= "Could not retrieve Activity List for Check ID ".$_REQUEST['check']."!\n";
		debug_message($check->getLastError());
	}
	function _getLinked(){
		$id = intval($this->id);
		if($id <= 0)
			return TRUE;
			
		if($this->_ta == FALSE){
			$ta = new SI_TaskActivity();
			$tas = $ta->retrieveSet("WHERE a.cost_trans_id = $id OR a.com_trans_id = $id");
			if($tas === FALSE){
				$this->error = "Error getting linked task: ".$ta->getLastError();
				return FALSE;	
			}
			if(count($tas) == 1){
				$this->_ta = &$tas[0];
			}
		}
		
		if($this->_check == FALSE){
			$check = new SI_Check();
			$checks = $check->retrieveSet("WHERE trans_id = $id");
			if($checks === FALSE){
				$this->error = "Error getting linked task: ".$check->getLastError();
				return FALSE;	
			}
			if(count($checks) == 1){
				$this->_check = &$checks[0];
			}
		}

		return TRUE;
	}