Example #1
0
 /**
  * Initializes invoice data.
  * This method is equivalent to the old getInvoice()
  */
 protected function _initData()
 {
     $invoices = new SimpleInvoices_Db_Table_Invoices();
     $invoiceItems = new SimpleInvoices_Db_Table_InvoiceItems();
     $payments = new SimpleInvoices_Db_Table_Payment();
     $this->_data = $invoices->getInvoice($this->_id);
     if (!is_array($this->_data)) {
         require_once 'SimpleInvoices/Exception.php';
         throw new SimpleInvoices_Exception('Invalid invoice identifier.');
     }
     // I unset the ID as I don't want it to be present in inserts or updates.
     unset($this->_data['id']);
     $this->_outData = array();
     $this->_outData['calc_date'] = date('Y-m-d', strtotime($this->_data['date']));
     $this->_outData['date'] = siLocal::date($this->_data['date']);
     $this->_outData['total'] = $invoiceItems->getInvoiceTotal($this->_id);
     $this->_outData['gross'] = $invoiceItems->getGrossForInvoice($this->_id);
     $this->_outData['paid'] = $payments->getPaidAmountForInvoice($this->_id);
     $this->_outData['owing'] = $this->_outData['total'] - $this->_outData['paid'];
     if (isset($this->_data['inv_status'])) {
         // This seems to be a thing of the past.
         // I think we could delete the whole "if".
         $this->_outData['status'] = $this->_data['inv_status'];
     } else {
         $this->_outData['status'] = '';
     }
     #invoice total tax
     $result = $invoiceItems->getTotals($this->_id);
     //$invoice['total'] = number_format($result['total'],2);
     $this->_outData['total_tax'] = $result['total_tax'];
     $this->_outData['tax_grouped'] = taxesGroupedForInvoice($id);
 }
 public function select($id, $domain_id = '')
 {
     global $logger;
     if (!empty($domain_id)) {
         $this->domain_id = $domain_id;
     }
     $sql = "SELECT \n                    i.*,\n\t\t            i.date as date_original, \n                    (SELECT CONCAT(p.pref_inv_wording,' ',i.index_id)) as index_name,\n                    p.pref_inv_wording AS preference,\n                    p.status\n                FROM \n                    " . TB_PREFIX . "invoices i LEFT JOIN \n\t\t\t\t\t" . TB_PREFIX . "preferences p  \n\t\t\t\t\t\tON (i.preference_id = p.pref_id AND i.domain_id = p.domain_id)\n                WHERE \n                    i.domain_id = :domain_id \n                AND \n\t\t\t\t\ti.id = :id";
     $sth = dbQuery($sql, ':id', $id, ':domain_id', $this->domain_id);
     $invoice = $sth->fetch();
     $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date']));
     $invoice['date'] = siLocal::date($invoice['date']);
     $invoice['total'] = getInvoiceTotal($invoice['id'], $domain_id);
     $invoice['gross'] = $this->getInvoiceGross($invoice['id'], $this->domain_id);
     $invoice['paid'] = calc_invoice_paid($invoice['id'], $domain_id);
     $invoice['owing'] = $invoice['total'] - $invoice['paid'];
     $invoice['invoice_items'] = $this->getInvoiceItems($id, $this->domain_id);
     #invoice total tax
     $sql2 = "SELECT SUM(tax_amount) AS total_tax, SUM(total) AS total FROM " . TB_PREFIX . "invoice_items WHERE invoice_id =  :id AND domain_id = :domain_id";
     $sth2 = dbQuery($sql2, ':id', $id, ':domain_id', $this->domain_id);
     $result2 = $sth2->fetch();
     //$invoice['total'] = number_format($result['total'],2);
     $invoice['total_tax'] = $result2['total_tax'];
     $invoice['tax_grouped'] = taxesGroupedForInvoice($id);
     return $invoice;
 }
Example #3
0
 public static function select($id)
 {
     global $logger;
     global $db;
     global $auth_session;
     $sql = "SELECT \n                    i.*,\n\t\t            i.date as date_original, \n                    (SELECT CONCAT(p.pref_inv_wording,' ',i.index_id)) as index_name,\n                    p.pref_inv_wording AS preference,\n                    p.status\n                FROM \n                    " . TB_PREFIX . "invoices i, \n                    " . TB_PREFIX . "preferences p \n                WHERE \n                    i.domain_id = :domain_id \n                    and\n                    i.preference_id = p.pref_id\n                    and \n                    i.id = :id";
     $sth = $db->query($sql, ':id', $id, ':domain_id', $auth_session->domain_id);
     $invoice = $sth->fetch();
     $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date']));
     $invoice['date'] = siLocal::date($invoice['date']);
     $invoice['total'] = getInvoiceTotal($invoice['id']);
     $invoice['gross'] = invoice::getInvoiceGross($invoice['id']);
     $invoice['paid'] = calc_invoice_paid($invoice['id']);
     $invoice['owing'] = $invoice['total'] - $invoice['paid'];
     $invoice['invoice_items'] = invoice::getInvoiceItems($id);
     #invoice total tax
     $sql2 = "SELECT SUM(tax_amount) AS total_tax, SUM(total) AS total FROM " . TB_PREFIX . "invoice_items WHERE invoice_id =  :id";
     $sth2 = dbQuery($sql2, ':id', $id) or die(htmlsafe(end($dbh->errorInfo())));
     $result2 = $sth2->fetch();
     //$invoice['total'] = number_format($result['total'],2);
     $invoice['total_tax'] = $result2['total_tax'];
     $invoice['tax_grouped'] = taxesGroupedForInvoice($id);
     return $invoice;
 }
function getInvoice($id, $domain_id = '')
{
    global $config;
    $domain_id = domain_id::get($domain_id);
    $sql = "SELECT * FROM " . TB_PREFIX . "invoices WHERE id =  :id AND domain_id =  :domain_id";
    $sth = dbQuery($sql, ':id', $id, ':domain_id', $domain_id);
    $invoice = $sth->fetch();
    $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date']));
    $invoice['date'] = siLocal::date($invoice['date']);
    $invoice['total'] = getInvoiceTotal($invoice['id']);
    $invoiceobj = new invoice();
    $invoiceobj->domain_id = $domain_id;
    $invoice['gross'] = $invoiceobj->getInvoiceGross($invoice['id']);
    $invoice['paid'] = calc_invoice_paid($invoice['id']);
    $invoice['owing'] = $invoice['total'] - $invoice['paid'];
    #invoice total tax
    $sql = "SELECT SUM(tax_amount) AS total_tax, SUM(total) AS total FROM " . TB_PREFIX . "invoice_items WHERE invoice_id =  :id AND domain_id =  :domain_id";
    $sth = dbQuery($sql, ':id', $id, ':domain_id', $domain_id);
    $result = $sth->fetch();
    //$invoice['total'] = number_format($result['total'],2);
    $invoice['total_tax'] = $result['total_tax'];
    $invoice['tax_grouped'] = taxesGroupedForInvoice($id);
    return $invoice;
}
Example #5
0
function getInvoice($id)
{
    global $dbh;
    global $config;
    global $auth_session;
    $sql = "SELECT * FROM " . TB_PREFIX . "invoices WHERE id =  :id and domain_id =  :domain_id";
    //echo $sql;
    $sth = dbQuery($sql, ':id', $id, ':domain_id', $auth_session->domain_id) or die(htmlsafe(end($dbh->errorInfo())));
    //print_r($query);
    $invoice = $sth->fetch();
    //print_r($invoice);
    //exit();
    $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date']));
    $invoice['date'] = siLocal::date($invoice['date']);
    $invoice['total'] = getInvoiceTotal($invoice['id']);
    $invoice['gross'] = invoice::getInvoiceGross($invoice['id']);
    $invoice['paid'] = calc_invoice_paid($invoice['id']);
    $invoice['owing'] = $invoice['total'] - $invoice['paid'];
    #invoice total tax
    $sql = "SELECT SUM(tax_amount) AS total_tax, SUM(total) AS total FROM " . TB_PREFIX . "invoice_items WHERE invoice_id =  :id";
    $sth = dbQuery($sql, ':id', $id) or die(htmlsafe(end($dbh->errorInfo())));
    $result = $sth->fetch();
    //$invoice['total'] = number_format($result['total'],2);
    $invoice['total_tax'] = $result['total_tax'];
    $invoice['tax_grouped'] = taxesGroupedForInvoice($id);
    return $invoice;
}
function getInvoice($id) {
	global $dbh;
	global $config;
	global $auth_session;
    
    $SI_INVOICES = new SimpleInvoices_Db_Table_Invoices();
    $SI_INVOICE_ITEMS = new SimpleInvoices_Db_Table_InvoiceItems();
    
    $invoice = $SI_INVOICES->getInvoice($id);

	$invoice['calc_date'] = date('Y-m-d', strtotime( $invoice['date'] ) );
	$invoice['date'] = siLocal::date( $invoice['date'] );
	$invoice['total'] = $SI_INVOICE_ITEMS->getInvoiceTotal($invoice['id']);
	$invoice['gross'] = invoice::getInvoiceGross($invoice['id']);
	$invoice['paid'] = calc_invoice_paid($invoice['id']);
	$invoice['owing'] = $invoice['total'] - $invoice['paid'];
    if (isset($invoice['inv_status'])) {
		// This seems to be a thing of the past.
		// I think we could delete the whole "if".
		$invoice['status'] = $invoice['inv_status'];
	}
	else {
		$invoice['status'] = '';
	}


	#invoice total tax
    $result = $SI_INVOICE_ITEMS->getTotals($id);
	
	//$invoice['total'] = number_format($result['total'],2);
	$invoice['total_tax'] = $result['total_tax'];
	$invoice['tax_grouped'] = taxesGroupedForInvoice($id);

	return $invoice;
}