예제 #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);
 }
예제 #2
0
<?php

//stop the direct browsing to this file - let index.php handle which files get displayed
checkLogin();

$SI_INVOICE_ITEMS = new SimpleInvoices_Db_Table_InvoiceItems();

# Deal with op and add some basic sanity checking

#insert - process payment
#op=pay_selected_invoice means the user came from the print_view or manage_invoces
#op=pay_invoice means the user came from the process_paymen page

global $auth_session;
if ( isset($_POST['process_payment']) ) {
    
    $SI_PAYMENTS = new SimpleInvoices_Db_Table_Payment();
    
    $payment_data = array(
        'ac_inv_id'         => $_POST['invoice_id'],
        'ac_amount'         => $_POST['ac_amount'],
        'ac_notes'          => $_POST['ac_notes'],
        'ac_date'           => $_POST['ac_date'],
        'ac_payment_type'   => $_POST['ac_payment_type'],
        'online_payment_id' => NULL
    );
    
	//works out any funds that are in excess of invoice total:
	$invoicetotal = $SI_INVOICE_ITEMS->getInvoiceTotal($payment_data['ac_inv_id']);
    $orig_amt = $payment_data['ac_amount'];
    $extrapayment = $payment_data['ac_amount']; - $invoicetotal;
예제 #3
0
    public static function select($id)
    {
		global $logger;
		global $db;
        global $auth_session;
        global $dbh;
        
        $SI_INVOICE_ITEMS = new SimpleInvoices_Db_Table_InvoiceItems();

		$sql = "SELECT
                    i.*,
		            i.date as date_original,
                    (SELECT CONCAT(p.pref_inv_wording,' ',i.index_id)) as index_name,
                    p.pref_inv_wording AS preference,
                    p.status
                FROM
                    ".TB_PREFIX."invoices i,
                    ".TB_PREFIX."preferences p
                WHERE
                    i.domain_id = :domain_id
                    and
                    i.preference_id = p.pref_id
                    and
                    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'] = $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'];

	$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;

	}
예제 #4
0
function getInvoices(&$sth) {
	global $config;
	$invoice = null;

    $SI_INVOICE_ITEMS = new SimpleInvoices_Db_Table_InvoiceItems();
    
	if($invoice = $sth->fetch()) {

		$invoice['calc_date'] = date( 'Y-m-d', strtotime( $invoice['date'] ) );
		$invoice['date'] = siLocal::date($invoice['date']);

		#invoice total total - start
		$invoice['total'] = $SI_INVOICE_ITEMS->getInvoiceTotal($invoice['id']);
		#invoice total total - end

		#amount paid calc - start
		$invoice['paid'] = calc_invoice_paid($invoice['id']);
		#amount paid calc - end

		#amount owing calc - start
		$invoice['owing'] = $invoice['total'] - $invoice['paid'];
		#amount owing calc - end
	}
	return $invoice;
}