示例#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
* Script: save.php
* 	Invoice save file
*
* License:
*	 GPL v3 or above
*	 
* Website:
* 	http://www.simpleinvoices.or
*/


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

$SI_PRODUCTS = new SimpleInvoices_Db_Table_Products();
$SI_INVOICES = new SimpleInvoices_Db_Table_Invoices();

$pageActive = "invoices";

$smarty->assign('pageActive', $pageActive);

# Deal with op and add some basic sanity checking


if(!isset( $_POST['type']) && !isset($_POST['action'])) {
	exit("no save action");
}

$saved = false;
$type = $_POST['type'];
示例#3
0
	public function insert()
	{
		//insert in si)invoice

		global $dbh;
		global $db_server;
		global $auth_session;
        $SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();

		$sql = "INSERT
				INTO
			".TB_PREFIX."invoices (
				id,
		 		index_id,
				domain_id,
				biller_id,
				customer_id,
				type_id,
				preference_id,
				date,
				note,
				custom_field1,
				custom_field2,
				custom_field3,
				custom_field4,
                inv_status,
			)
			VALUES
			(
				NULL,
				:index_id,
				:domain_id,
				:biller_id,
				:customer_id,
				:type_id,
				:preference_id,
				:date,
				:note,
				:custom_field1,
				:custom_field2,
				:custom_field3,
				:custom_field4,
                NULL
				)";

		$pref_group= $SI_PREFERENCES->getPreferenceById($this->preference_id);

		$sth= dbQuery($sql,
			':index_id', SimpleInvoices_Db_Table_Index::NEXT('invoice',$pref_group[index_group],$this->biller_id),
			':domain_id', $auth_session->domain_id,
			':biller_id', $this->biller_id,
			':customer_id', $this->customer_id,
			':type_id', $this->type_id,
			':preference_id', $this->preference_id,
			':date', $this->date,
			':note', $this->note,
			':custom_field1', $this->custom_field1,
			':custom_field2', $this->custom_field2,
			':custom_field3', $this->custom_field3,
			':custom_field4', $this->custom_field4
			);

	    SimpleInvoices_Db_Table_Index::INCREMENT('invoice',$pref_group[index_group],$this->biller_id);

	    //return $sth;
        return SimpleInvoices_Db_Table_Invoices::LAST_INSERT_ID();
		//insert into si_invoice_items

		//insert into

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