示例#1
0
 function get_all_parties($invoiceID)
 {
     if ($invoiceID) {
         $invoice = new invoice();
         $invoice->set_id($invoiceID);
         $invoice->select();
         $interestedPartyOptions = $invoice->get_all_partieS($invoice->get_value("projectID"), $invoice->get_value("clientID"));
     }
     if (is_object($this) && $this->get_id()) {
         $interestedPartyOptions = interestedParty::get_interested_parties("invoiceRepeat", $this->get_id(), $interestedPartyOptions);
     }
     return $interestedPartyOptions;
 }
示例#2
0
	function getData()
	{
		//echo "export - get data";
		global $smarty;
		global $siUrl;
		global $include_dir;
        
        $SI_BILLER = new SimpleInvoices_Db_Table_Biller();
        $SI_CUSTOM_FIELDS = new SimpleInvoices_Db_Table_CustomFields();
        $SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();
        
		switch ($this->module)
		{
			case "database":
			{
                $data = SimpleInvoices_Db::performBackup();
				break;
			}
			case "statement":
			{
				$invoice = new invoice();
				$invoice->biller = $this->biller_id;
				$invoice->customer = $this->customer_id;

				if ( $this->filter_by_date =="yes" )
				{
					if ( isset($this->start_date) )
					{
						$invoice->start_date = $this->start_date;
					}
					if ( isset($this->end_date) )
					{
						$invoice->end_date = $this->end_date;
					}

					if ( isset($this->start_date) AND isset($this->end_date) )
					{
						$invoice->having = "date_between";
					}
					$having_count = '1';
				}

				if ( $this->show_only_unpaid == "yes")
				{
					if ($having_count == '1')
					{

						$invoice->having_and = "money_owed";
					    $having_count = '2';

					} else {

						$invoice->having = "money_owed";
					    $having_count = '1';

					}
				}

				if ( $this->show_only_real == "yes")
				{
					if ($having_count == '2')
					{

						$invoice->having_and2 = "real";

					} elseif ($having_count == '1') {

						$invoice->having_and = "real";

					} else {

						$invoice->having = "real";

					}
				}

				$invoice_all = $invoice->select_all('count');

				$invoices = $invoice_all->fetchAll();

				foreach ($invoices as $i => $row) {
					$statement['total'] = $statement['total'] + $row['invoice_total'];
					$statement['owing'] = $statement['owing'] + $row['owing'] ;
					$statement['paid'] = $statement['paid'] + $row['INV_PAID'];

				}

                // ToDo: THIS FILE IS MISSING!!
				$templatePath = $include_dir . "sys/templates/default/statement/index.tpl";

				$biller_details = $SI_BILLER->getBiller($this->biller_id);
				$customer_details = customer::get($this->customer_id);

				$this->file_name = "statement_".$this->biller_id."_".$this->customer_id."_".$invoice->start_date."_".$invoice->end_date;

				$smarty -> assign('biller_id', $biller_id);
				$smarty -> assign('biller_details', $biller_details);
				$smarty -> assign('customer_id', $customer_id);
				$smarty -> assign('customer_details', $customer_details);

				$smarty -> assign('show_only_unpaid', $show_only_unpaid);
				$smarty -> assign('show_only_real', $show_only_real);
				$smarty -> assign('filter_by_date', $this->filter_by_date);

				$smarty -> assign('invoices', $invoices);
				$smarty -> assign('start_date', $this->start_date);
				$smarty -> assign('end_date', $this->end_date);

				$smarty -> assign('invoices',$invoices);
				$smarty -> assign('statement',$statement);
				$data = $smarty -> fetch(".".$templatePath);

				break;
			}
            case "payment":
            {
                $customFieldLabels = $SI_CUSTOM_FIELDS->getLabels();
                
                $payment = new SimpleInvoices_Payment($this->id);
                $invoice = $payment->getInvoice();
                $biller = $invoice->getBiller();
                $logo = $biller->getLogo();
                $logo = str_replace(" ", "%20", $logo);
                $customer = $invoice->getCustomer();
                
                $smarty -> assign("payment",$payment->toArray());
                $smarty -> assign("invoice",$invoice->toArray());
                $smarty -> assign("biller",$biller->toArray());
                $smarty -> assign("logo",$logo);
                $smarty -> assign("customer",$customer->toArray());
                $smarty -> assign("invoiceType",$invoice->getType());
                $smarty -> assign("paymentType",$payment->getType());
                $smarty -> assign("preference",$invoice->getPreference());
                $smarty -> assign("customFieldLabels",$customFieldLabels);

                $smarty -> assign('pageActive', 'payment');
                $smarty -> assign('active_tab', '#money');

				$css = $siUrl."/sys/templates/invoices/default/style.css";
				$smarty -> assign('css',$css);

                $templatePath = $include_dir . "sys/templates/default/modules/payments/print.tpl";
				$data = $smarty -> fetch($templatePath);
				
                break;
            }
			case "invoice":
			{
                $SI_SYSTEM_DEFAULTS = new SimpleInvoices_Db_Table_SystemDefaults();
                
				$invoice = invoice::select($this->id);
 			    $invoice_number_of_taxes = numberOfTaxesForInvoice($this->id);
				$customer = customer::get($invoice['customer_id']);
				$biller = biller::select($invoice['biller_id']);
				$preference = $SI_PREFERENCES->getPreferenceById($invoice['preference_id']);
				$defaults = $SI_SYSTEM_DEFAULTS->fetchAll();
				$logo = getLogo($biller);
				$logo = str_replace(" ", "%20", $logo);
				$invoiceItems = invoice::getInvoiceItems($this->id);

				$spc2us_pref = str_replace(" ", "_", $invoice['index_name']);
				$this->file_name = $spc2us_pref;

				$customFieldLabels = $SI_CUSTOM_FIELDS->getLabels();
				$customFieldDisplay = $SI_CUSTOM_FIELDS->getDisplay();

				/*Set the template to the default*/
				$template = $defaults['template'];

                // Instead of appending the CSS we are going to inject it allowing
                // a cleaner hierarchy tree while allowing public directories
				$css_file = $include_dir ."/sys/templates/invoices/${template}/style.css";
                
                if (file_exists($css_file)) {
                    $css = file_get_contents($css_file);
                    if ($css) {
                        // Create the tags
                        $css = '<style type="text/css" media="all">' . $css . '</style>';
                    }
                } else {
                    $css = '';
                }

                $smarty->addTemplateDir($include_dir . "sys/templates/invoices/${template}/", 'Invoice_' . $template);
				$smarty->addPluginsDir($include_dir ."sys/templates/invoices/${template}/plugins/");

				$pageActive = "invoices";
				$smarty->assign('pageActive', $pageActive);

                if ($smarty->templateExists('file:[Invoice_' . $template . ']template.tpl')) {
					$smarty -> assign('biller',$biller);
					$smarty -> assign('customer',$customer);
					$smarty -> assign('invoice',$invoice);
					$smarty -> assign('invoice_number_of_taxes',$invoice_number_of_taxes);
					$smarty -> assign('preference',$preference);
					$smarty -> assign('logo',$logo);
					$smarty -> assign('template',$template);
					$smarty -> assign('invoiceItems',$invoiceItems);
					$smarty -> assign('css',$css);
					$smarty -> assign('customFieldLabels',$customFieldLabels);
					$smarty -> assign('customFieldDisplay',$customFieldDisplay);

					$data = $smarty->fetch('file:[Invoice_' . $template . ']template.tpl');
				}

				break;
			}

		}

		return $data;

	}
示例#3
0
<?php

$saved = false;

if ( ($_POST['op'] =='add') AND (!empty($_POST['invoice_id'])) )
{

    $invoice= invoice::select($_POST['invoice_id']);

    $eway_check = new eway();
    $eway_check->invoice = $invoice;
    $eway_pre_check = $eway_check->pre_check();
    
    if($eway_pre_check == 'true')
    {
        //do eway payment
        $eway = new eway();
        $eway->invoice = $invoice;
        $saved = $eway->payment();  
    } else {
        $saved = 'check_failed';
    }
    
}      

$invoice_all = invoice::get_all();

$smarty -> assign('invoice_all',$invoice_all);
$smarty -> assign('saved',$saved);

$smarty -> assign('pageActive', 'payment');
示例#4
0
     #$payment->ac_inv_id = $_POST['invoice'];
     $payment->ac_amount = $p->ipn_data['mc_gross'];
     #$payment->ac_amount = $_POST['mc_gross'];
     $payment->ac_notes = $paypal_data;
     #$payment->ac_notes = $paypal_data;
     $payment->ac_date = date('Y-m-d', strtotime($p->ipn_data['payment_date']));
     #$payment->ac_date = date( 'Y-m-d', strtotime($_POST['payment_date']));
     $payment->online_payment_id = $p->ipn_data['txn_id'];
     $payment->domain_id = $domain_id;
     $payment_type = new payment_type();
     $payment_type->type = "Paypal";
     $payment_type->domain_id = $domain_id;
     $payment->ac_payment_type = $payment_type->select_or_insert_where();
     $logger->log('Paypal - payment_type=' . $payment->ac_payment_type, Zend_Log::INFO);
     $payment->insert();
     $invoice = invoice::select($p->ipn_data['invoice']);
     #$invoice = invoice::select($_POST['invoice']);
     $biller = getBiller($invoice['biller_id']);
     //send email
     $body = "A Paypal instant payment notification was successfully recieved into Simple Invoices\n";
     $body .= "from " . $p->ipn_data['payer_email'] . " on " . date('m/d/Y');
     $body .= " at " . date('g:i A') . "\n\nDetails:\n";
     $body .= $paypal_data;
     $email = new email();
     $email->notes = $body;
     $email->to = $biller['email'];
     $email->from = "*****@*****.**";
     $email->subject = 'Instant Payment Notification - Recieved Payment';
     $email->send();
     $xml_message['data'] .= $body;
 }
示例#5
0
 function get_amount_allocated($fmt = "%s%mo")
 {
     // Return total amount used and total amount allocated
     if (is_object($this) && $this->get_id()) {
         $db = new db_alloc();
         // Get most recent invoiceItem that this time sheet belongs to.
         $q = prepare("SELECT invoiceID\n                      FROM invoiceItem\n                     WHERE invoiceItem.timeSheetID = %d\n                  ORDER BY invoiceItem.iiDate DESC\n                     LIMIT 1\n                  ", $this->get_id());
         $db->query($q);
         $row = $db->row();
         $invoiceID = $row["invoiceID"];
         if ($invoiceID) {
             $invoice = new invoice();
             $invoice->set_id($invoiceID);
             $invoice->select();
             $maxAmount = page::money($invoice->get_value("currencyTypeID"), $invoice->get_value("maxAmount"), $fmt);
             // Loop through all the other invoice items on that invoice
             $q = prepare("SELECT sum(iiAmount) AS totalUsed FROM invoiceItem WHERE invoiceID = %d", $invoiceID);
             $db->query($q);
             $row2 = $db->row();
             return array(page::money($invoice->get_value("currencyTypeID"), $row2["totalUsed"], $fmt), $maxAmount);
         }
     }
 }
示例#6
0
checkLogin();
$maxInvoice = maxInvoice();
jsBegin();
jsFormValidationBegin("frmpost");
#jsValidateifNum("ac_inv_id",$LANG['invoice_id']);
#jsPaymentValidation("ac_inv_id",$LANG['invoice_id'],1,$maxInvoice['maxId']);
jsValidateifNum("ac_amount", $LANG['amount']);
jsValidateifNum("ac_date", $LANG['date']);
jsFormValidationEnd();
jsEnd();
/* end validataion code */
$today = date("Y-m-d");
$master_invoice_id = $_GET['id'];
$invoice = null;
if (isset($_GET['id'])) {
    $invoice = invoice::select($master_invoice_id);
} else {
    $sth = dbQuery("SELECT * FROM " . TB_PREFIX . "invoices");
    $invoice = $sth->fetch();
    #$sth = new invoice();
    #$invoice = $sth->select_all();
}
$customer = getCustomer($invoice['customer_id']);
$biller = getBiller($invoice['biller_id']);
$defaults = getSystemDefaults();
$pt = getPaymentType($defaults['payment_type']);
$invoices = new invoice();
$invoices->sort = 'id';
$invoices->having = 'money_owed';
$invoice_all = $invoices->select_all('count');
$smarty->assign('invoice_all', $invoice_all);
示例#7
0
//stop the direct browsing to this file - let index.php handle which files get displayed
checkLogin();
#get the invoice id
$expense_id = $_GET['id'];
$expenseobj = new expense();
$customerobj = new customer();
$billerobj = new biller();
$invoiceobj = new invoice();
$productobj = new product();
$expenseaccountobj = new expenseaccount();
$expensetaxobj = new expensetax();
$expense = $expenseobj->get($expense_id);
$detail = $expenseobj->detail();
$detail['customer'] = $customerobj->get($expense['customer_id']);
$detail['biller'] = $billerobj->select($expense['biller_id']);
$detail['invoice'] = $invoiceobj->select($expense['invoice_id']);
$detail['product'] = $productobj->get($expense['product_id']);
$detail['expense_account'] = $expenseaccountobj->select($expense['expense_account_id']);
$detail['expense_tax'] = $expensetaxobj->get_all($expense_id);
$detail['expense_tax_total'] = $expense['amount'] + $expensetaxobj->get_sum($expense_id);
$detail['expense_tax_grouped'] = $expensetaxobj->grouped($expense_id);
$detail['status_wording'] = $expense['status'] == 1 ? $LANG['paid'] : $LANG['not_paid'];
$taxes = getActiveTaxes();
#$tax_selected = getTaxRate($product['default_tax_id']);
$defaults = getSystemDefaults();
$smarty->assign('expense', $expense);
$smarty->assign('detail', $detail);
$smarty->assign('taxes', $taxes);
$smarty->assign('defaults', $defaults);
//$smarty -> assign('tax_selected',$tax_selected);
//$smarty -> assign('customFieldLabel',$customFieldLabel);
function updateInvoice($invoice_id, $domain_id = '')
{
    //  global $logger;
    global $db_server;
    $domain_id = domain_id::get($domain_id);
    $invoiceobj = new invoice();
    $current_invoice = $invoiceobj->select($_POST['id']);
    $current_pref_group = getPreference($current_invoice['preference_id']);
    $new_pref_group = getPreference($_POST['preference_id']);
    $index_id = $current_invoice['index_id'];
    //	$logger->log('Curent Index Group: '.$description, Zend_Log::INFO);
    //	$logger->log('Description: '.$description, Zend_Log::INFO);
    if ($current_pref_group['index_group'] != $new_pref_group['index_group']) {
        $index_id = index::increment('invoice', $new_pref_group['index_group']);
    }
    if ($db_server == 'mysql' && !_invoice_check_fk($_POST['biller_id'], $_POST['customer_id'], $type, $_POST['preference_id'])) {
        return null;
    }
    $sql = "UPDATE\n\t\t\t" . TB_PREFIX . "invoices\n\t\tSET\n\t\t\tindex_id = :index_id,\n\t\t\tbiller_id = :biller_id,\n\t\t\tcustomer_id = :customer_id,\n\t\t\tpreference_id = :preference_id,\n\t\t\tdate = :date,\n\t\t\tnote = :note,\n\t\t\tcustom_field1 = :customField1,\n\t\t\tcustom_field2 = :customField2,\n\t\t\tcustom_field3 = :customField3,\n\t\t\tcustom_field4 = :customField4\n\t\tWHERE\n\t\t\tid = :invoice_id\n\t\tAND domain_id = :domain_id";
    return dbQuery($sql, ':index_id', $index_id, ':biller_id', $_POST['biller_id'], ':customer_id', $_POST['customer_id'], ':preference_id', $_POST['preference_id'], ':date', $_POST['date'], ':note', trim($_POST['note']), ':customField1', $_POST['customField1'], ':customField2', $_POST['customField2'], ':customField3', $_POST['customField3'], ':customField4', $_POST['customField4'], ':invoice_id', $invoice_id, ':domain_id', $domain_id);
}
示例#9
0
if (is_object($invoice) && $invoice->get_id()) {
    $q = prepare("SELECT * FROM invoiceRepeat WHERE invoiceID = %d LIMIT 1", $invoice->get_id());
    $qid1 = $db->query($q);
    if ($db->row($qid1)) {
        $invoiceRepeat->read_db_record($db);
        $invoiceRepeat->set_values("invoiceRepeat_");
        foreach (explode(" ", $TPL["invoiceRepeat_frequency"]) as $id) {
            if ($id) {
                $qid2 = $db->query("SELECT * FROM invoice WHERE invoiceRepeatID = %d AND invoiceRepeatDate = '%s'", $invoiceRepeat->get_id(), $id);
                if ($idrow = $db->row($qid2)) {
                    $links[] = "<a href='" . $TPL["url_alloc_invoice"] . "invoiceID=" . $idrow["invoiceID"] . "'>" . $id . "</a>";
                } else {
                    $links[] = $id;
                }
            }
        }
        $TPL["message_help_no_esc"][] = "This invoice is also a template for the scheduled creation of new invoices on the following dates:\n                              <br>" . implode("&nbsp;&nbsp;", (array) $links) . "\n                              <br>Click the Repeating Invoice link for more information.";
    }
    if ($invoice->get_value("invoiceRepeatID")) {
        $ir = new invoiceRepeat();
        $ir->set_id($invoice->get_value("invoiceRepeatID"));
        $ir->select();
        $i = new invoice();
        $i->set_id($ir->get_value("invoiceID"));
        $i->select();
        $TPL["message_help_no_esc"][] = "This invoice was automatically generated by the\n                                   <a href='" . $TPL["url_alloc_invoice"] . "invoiceID=" . $ir->get_value("invoiceID") . "'>\n                                   repeating invoice " . $i->get_value("invoiceNum") . "</a>";
    }
}
$TPL["invoice"] = $invoice;
$TPL["invoiceRepeat"] = $invoiceRepeat;
include_template("templates/invoiceM.tpl");
示例#10
0
        $payment->ac_amount = $p->ipn_data['mc_gross'];
        #$payment->ac_amount = $_POST['mc_gross'];
        $payment->ac_notes = $paypal_data;
        #$payment->ac_notes = $paypal_data;
        $payment->ac_date = date('Y-m-d', strtotime($p->ipn_data['payment_date']));
        #$payment->ac_date = date( 'Y-m-d', strtotime($_POST['payment_date']));
        $payment->online_payment_id = $p->ipn_data['txn_id'];
        $payment->domain_id = $domain_id;
        $payment_type = new payment_type();
        $payment_type->type = "Paypal";
        $payment_type->domain_id = $domain_id;
        $payment->ac_payment_type = $payment_type->select_or_insert_where();
        $logger->log('Paypal - payment_type=' . $payment->ac_payment_type, Zend_Log::INFO);
        $payment->insert();
        $invoiceobj = new invoice();
        $invoice = $invoiceobj->select($p->ipn_data['invoice']);
        $biller = getBiller($invoice['biller_id']);
        //send email
        $body = "A Paypal instant payment notification was successfully recieved into Simple Invoices\n";
        $body .= "from " . $p->ipn_data['payer_email'] . " on " . date('m/d/Y');
        $body .= " at " . date('g:i A') . "\n\nDetails:\n";
        $body .= $paypal_data;
        $email = new email();
        $email->notes = $body;
        $email->to = $biller['email'];
        $email->from = "*****@*****.**";
        $email->subject = 'Instant Payment Notification - Recieved Payment';
        $email->send();
        $xml_message['data'] .= $body;
    }
} else {
$checkPermission = $acl->isAllowed($auth_session->role_name, $module, $view) ?  "allowed" : "denied"; // allowed

//sbasic customer page check - exmaple
/*
if( ($auth_session->role_name =='customer') AND ($module == 'customers') AND ($_GET['id'] != $auth_session->user_id) )
{
	$checkPermission = "denied";
}
*/

/*
 * Check customer
 */
if( ($auth_session->role_name =='customer') AND ($module == 'invoices') AND ($_GET['id']) )
{

   // Check invoice ID belongs to customer
   $invoice = invoice::select($_GET['id']);
   if($invoice['customer_id'] != $auth_session->role_link_id)
   {
        $checkPermission = "denied";
   }

}

//$checkPermission == "denied" ? exit($LANG['denied_page']) :"" ;

$checkPermission == "denied" ?  header("Location: index.php?module=error&view=401") : false;

示例#12
0
 function update_invoice_dates($invoiceID)
 {
     $db = new db_alloc();
     $db->query(prepare("SELECT max(iiDate) AS maxDate, min(iiDate) AS minDate\n                          FROM invoiceItem\n                         WHERE invoiceID=%d", $invoiceID));
     $db->next_record();
     $invoice = new invoice();
     $invoice->set_id($invoiceID);
     $invoice->select();
     $invoice->set_value("invoiceDateFrom", $db->f("minDate"));
     $invoice->set_value("invoiceDateTo", $db->f("maxDate"));
     return $invoice->save();
 }
function updateInvoice($invoice_id) {

    global $logger;
    $SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();
    
    $current_invoice = invoice::select($_POST['id']);
    $current_pref_group = $SI_PREFERENCES->getPreferenceById($current_invoice[preference_id]);

    $new_pref_group= $SI_PREFERENCES->getPreferenceById($_POST[preference_id]);

    $index_id = $current_invoice['index_id'];

//	$logger->log('Curent Index Group: '.$description, Zend_Log::INFO);
//	$logger->log('Description: '.$description, Zend_Log::INFO);

    if ($current_pref_group['index_group'] != $new_pref_group['index_group'])
    {
        $index_id = SimpleInvoices_Db_Table_Index::INCREMENT('invoice',$new_pref_group['index_group']);
    }

	if ($db_server == 'mysql' && !_invoice_check_fk(
		$_POST['biller_id'], $_POST['customer_id'],
		$type, $_POST['preference_id'])) {
		return null;
	}
	$sql = "UPDATE
			".TB_PREFIX."invoices
		SET
			index_id = :index_id,
			biller_id = :biller_id,
			customer_id = :customer_id,
			preference_id = :preference_id,
			date = :date,
			note = :note,
			custom_field1 = :customField1,
			custom_field2 = :customField2,
			custom_field3 = :customField3,
			custom_field4 = :customField4
		WHERE
			id = :invoice_id";

	return dbQuery($sql,
        ':index_id', $index_id,
		':biller_id', $_POST['biller_id'],
		':customer_id', $_POST['customer_id'],
		':preference_id', $_POST['preference_id'],
		':date', $_POST['date'],
		':note', $_POST['note'],
		':customField1', $_POST['customField1'],
		':customField2', $_POST['customField2'],
		':customField3', $_POST['customField3'],
		':customField4', $_POST['customField4'],
		':invoice_id', $invoice_id
		);
}
示例#14
0
<?php

//get invoice details

$invoice = invoice::select('1');
//echo json_encode($invoice);
//header('Content-type: application/xml');
echo encode::xml($invoice);
//print_r($invoice);
示例#15
0
<?php

$saved = false;
$invoiceobj = new invoice();
$invoice_all = $invoiceobj->get_all();
if ($_POST['op'] == 'add' and !empty($_POST['invoice_id'])) {
    $invoice = $invoiceobj->select($_POST['invoice_id']);
    $eway_check = new eway();
    $eway_check->invoice = $invoice;
    $eway_pre_check = $eway_check->pre_check();
    if ($eway_pre_check == 'true') {
        //do eway payment
        $eway = new eway();
        $eway->invoice = $invoice;
        $saved = $eway->payment();
    } else {
        $saved = 'check_failed';
    }
}
$smarty->assign('invoice_all', $invoice_all);
$smarty->assign('saved', $saved);
$smarty->assign('pageActive', 'payment');
$smarty->assign('subPageActive', 'payment_eway');
$smarty->assign('active_tab', '#money');
示例#16
0
$maxInvoice = maxInvoice();
jsBegin();
jsFormValidationBegin("frmpost");
#jsValidateifNum("ac_inv_id",$LANG['invoice_id']);
#jsPaymentValidation("ac_inv_id",$LANG['invoice_id'],1,$maxInvoice['maxId']);
jsValidateifNum("ac_amount", $LANG['amount']);
jsValidateifNum("ac_date", $LANG['date']);
jsFormValidationEnd();
jsEnd();
/* end validataion code */
$today = date("Y-m-d");
$master_invoice_id = $_GET['id'];
$invoice = null;
if (isset($_GET['id'])) {
    $invoiceobj = new invoice();
    $invoice = $invoiceobj->select($master_invoice_id);
} else {
    $sql = "SELECT * FROM " . TB_PREFIX . "invoices WHERE domain_id = :domain_id";
    /*
    	$sql = "SELECT iv.* FROM ".TB_PREFIX."invoices iv 
    				LEFT JOIN ".TB_PREFIX."preferences pr 
    					ON (pr.pref_id = iv.preference_id AND pr.domain_id = iv.domain_id)
    			WHERE pr.status = '1'";
    */
    $sth = dbQuery($sql, ':domain_id', domain_id::get());
    $invoice = $sth->fetch();
    #$sth = new invoice();
    #$invoice = $sth->select_all();
}
$customer = getCustomer($invoice['customer_id']);
$biller = getBiller($invoice['biller_id']);
示例#17
0
<?php

/*
 * Copyright (C) 2006-2011 Alex Lance, Clancy Malcolm, Cyber IT Solutions
 * Pty. Ltd.
 * 
 * This file is part of the allocPSA application <*****@*****.**>.
 * 
 * allocPSA is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * allocPSA is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with allocPSA. If not, see <http://www.gnu.org/licenses/>.
*/
require_once "../alloc.php";
if (!$current_user->is_employee()) {
    alloc_error("You do not have permission to access invoices", true);
}
$invoiceID = $_POST["invoiceID"] or $invoiceID = $_GET["invoiceID"];
$verbose = $_GET["verbose"];
$invoice = new invoice();
$invoice->set_id($invoiceID);
$invoice->select();
$invoice->generate_invoice_file($verbose);
示例#18
0
/*
* Script: email.php
* 	Email invoice page
*
* License:
*	 GPL v3 or above
*
* Website:
* 	http://www.simpleinvoices.org
*/
//stop the direct browsing to this file - let index.php handle which files get displayed
checkLogin();
#get the invoice id
$invoice_id = $_GET['id'];
$invoice = invoice::select($invoice_id);
$preference = getPreference($invoice['preference_id']);
$biller = getBiller($invoice['biller_id']);
$customer = getCustomer($invoice['customer_id']);
$sql = "SELECT inv_ty_description AS type FROM " . TB_PREFIX . "invoice_type WHERE inv_ty_id = :type";
$sth = dbQuery($sql, ':type', $invoice['type_id']);
$invoiceType = $sth->fetch();
#create PDF name
$spc2us_pref = str_replace(" ", "_", $invoice['index_name']);
$pdf_file_name = $spc2us_pref . '.pdf';
if ($_GET['stage'] == 2) {
    #echo $block_stage2;
    // Create invoice
    $export = new export();
    $export->format = "pdf";
    $export->file_location = 'file';
示例#19
0
	public function recur()
	{
		$invoice = invoice::select($this->id);
		$ni = new invoice();
		$ni->biller_id = $invoice['biller_id'];
		$ni->customer_id = $invoice['customer_id'];
		$ni->type_id = $invoice['type_id'];
		$ni->preference_id = $invoice['preference_id'];
		//$ni->date = $invoice['date_original'];
		$ni->date = date('Y-m-d');
		$ni->custom_field1 = $invoice['custom_field1'];
		$ni->custom_field2 = $invoice['custom_field2'];
		$ni->custom_field3 = $invoice['custom_field3'];
		$ni->custom_field4 = $invoice['custom_field4'];
		$ni->note = $invoice['note'];
		$ni_id = $ni->insert();
		//insert each line item
		foreach ($invoice['invoice_items'] as $key => $value)
		{
			$nii = new invoice();
			$nii->invoice_id=$ni_id;
			$nii->quantity=$invoice['invoice_items'][$key]['quantity'];
			$nii->product_id=$invoice['invoice_items'][$key]['product_id'];
			$nii->unit_price=$invoice['invoice_items'][$key]['unit_price'];
			$nii->tax_amount=$invoice['invoice_items'][$key]['tax_amount'];
			$nii->gross_total=$invoice['invoice_items'][$key]['gross_total'];
			$nii->description=$invoice['invoice_items'][$key]['description'];
			$nii->total=$invoice['invoice_items'][$key]['total'];
			$nii->tax=$invoice['invoice_items'][$key]['tax'];
			$nii_id = $nii->insert_item();
		}

		return $ni_id;
	}
示例#20
0
 public function run()
 {
     global $db;
     $today = date('Y-m-d');
     $cron = new cron();
     $data = $cron->select_crons_to_run();
     $return['cron_message'] = "Cron started";
     $number_of_crons_run = "0";
     $cron_log = new cronlog();
     $cron_log->run_date = $today;
     foreach ($data as $key => $value) {
         $cron->domain_id = $value['domain_id'];
         $cron_log->cron_id = $value['id'];
         $cron_log->domain_id = $domain_id = $value['domain_id'];
         $check_cron_log = $cron_log->check();
         $i = "0";
         if ($check_cron_log == 0) {
             //only proceed if cron has not been run for today
             $run_cron = false;
             $start_date = date('Y-m-d', strtotime($value['start_date']));
             $end_date = $value['end_date'];
             // Seconds in a day = 60 * 60 * 24 = 86400
             $diff = number_format((strtotime($today) - strtotime($start_date)) / 86400, 0);
             //only check if diff is positive
             if ($diff >= 0 and ($end_date == "" or $end_date >= $today)) {
                 if ($value['recurrence_type'] == 'day') {
                     $modulus = $diff % $value['recurrence'];
                     if ($modulus == 0) {
                         $run_cron = true;
                     } else {
                         #$return .= "cron does not runs TODAY-days";
                     }
                 }
                 if ($value['recurrence_type'] == 'week') {
                     $period = 7 * $value['recurrence'];
                     $modulus = $diff % $period;
                     if ($modulus == 0) {
                         $run_cron = true;
                     } else {
                         #$return .= "cron is not runs TODAY-week";
                     }
                 }
                 if ($value['recurrence_type'] == 'month') {
                     $start_day = date('d', strtotime($value['start_date']));
                     $start_month = date('m', strtotime($value['start_date']));
                     $start_year = date('Y', strtotime($value['start_date']));
                     $today_day = date('d');
                     $today_month = date('m');
                     $today_year = date('Y');
                     $months = $today_month - $start_month + 12 * ($today_year - $start_year);
                     $modulus = $months % $value['recurrence'];
                     if ($modulus == 0 and $start_day == $today_day) {
                         $run_cron = true;
                     } else {
                         #$return .= "cron is not runs TODAY-month";
                     }
                 }
                 if ($value['recurrence_type'] == 'year') {
                     $start_day = date('d', strtotime($value['start_date']));
                     $start_month = date('m', strtotime($value['start_date']));
                     $start_year = date('Y', strtotime($value['start_date']));
                     $today_day = date('d');
                     $today_month = date('m');
                     $today_year = date('Y');
                     $years = $today_year - $start_year;
                     $modulus = $years % $value['recurrence'];
                     if ($modulus == 0 and $start_day == $today_day and $start_month == $today_month) {
                         $run_cron = true;
                     } else {
                         #$return .= "cron is not runs TODAY-year";
                     }
                 }
                 //run the recurrence for this invoice
                 if ($run_cron) {
                     $number_of_crons_run++;
                     $return['cron_message_' . $value['cron_id']] = "Cron ID: " . $value['cron_id'] . " - Cron for " . $value['index_name'] . " with start date of " . $value['start_date'] . ", end date of " . $value['end_date'] . " where it runs each " . $value['recurrence'] . " " . $value['recurrence_type'] . " was run today :: Info diff=" . $diff;
                     $i++;
                     $ni = new invoice();
                     $ni->id = $value['invoice_id'];
                     $ni->domain_id = $domain_id;
                     // $domain_id gets propagated from invoice to be copied from
                     $new_invoice_id = $ni->recur();
                     //insert into cron_log date of run
                     //$cron_log = new cronlog();
                     //$cron_log->run_date = $today;
                     //$cron_log->domain_id = $domain_id;
                     //$cron_log->cron_id = $value['cron_id'];
                     $cron_log->insert();
                     ## email the people
                     $invoiceobj = new invoice();
                     $invoice = $invoiceobj->select($new_invoice_id, $domain_id);
                     $preference = getPreference($invoice['preference_id'], $domain_id);
                     $biller = getBiller($invoice['biller_id'], $domain_id);
                     $customer = getCustomer($invoice['customer_id'], $domain_id);
                     #print_r($customer);
                     #create PDF nameVj
                     $spc2us_pref = str_replace(" ", "_", $invoice['index_name']);
                     $pdf_file_name_invoice = $spc2us_pref . ".pdf";
                     // email invoice
                     if ($value['email_biller'] == "1" or $value['email_customer'] == "1") {
                         $export = new export();
                         $export->domain_id = $domain_id;
                         $export->format = "pdf";
                         $export->file_location = 'file';
                         $export->module = 'invoice';
                         $export->id = $invoice['id'];
                         $export->execute();
                         #$attachment = file_get_contents('./tmp/cache/' . $pdf_file_name);
                         $email = new email();
                         $email->domain_id = $domain_id;
                         $email->format = 'cron_invoice';
                         $email_body = new email_body();
                         $email_body->email_type = 'cron_invoice';
                         $email_body->customer_name = $customer['name'];
                         $email_body->invoice_name = $invoice['index_name'];
                         $email_body->biller_name = $biller['name'];
                         $email->notes = $email_body->create();
                         $email->from = $biller['email'];
                         $email->from_friendly = $biller['name'];
                         $email->to = $this->getEmailSendAddresses($value, $customer['email'], $biller['email']);
                         $email->invoice_name = $invoice['index_name'];
                         $email->subject = $email->set_subject();
                         $email->attachment = $pdf_file_name_invoice;
                         $return['email_message'] = $email->send();
                     }
                     //Check that all details are OK before doing the eway payment
                     $eway_check = new eway();
                     $eway_check->domain_id = $domain_id;
                     $eway_check->invoice = $invoice;
                     $eway_check->customer = $customer;
                     $eway_check->biller = $biller;
                     $eway_check->preference = $preference;
                     $eway_pre_check = $eway_check->pre_check();
                     //do eway payment
                     if ($eway_pre_check == 'true') {
                         // input customerID,  method (REAL_TIME, REAL_TIME_CVN, GEO_IP_ANTI_FRAUD) and liveGateway or not
                         $eway = new eway();
                         $eway->domain_id = $domain_id;
                         $eway->invoice = $invoice;
                         $eway->biller = $biller;
                         $eway->customer = $customer;
                         $payment_done = $eway->payment();
                         $payment_id = $db->lastInsertID();
                         $pdf_file_name_receipt = 'payment' . $payment_id . '.pdf';
                         if ($payment_done == 'true') {
                             //do email of receipt to biller and customer
                             if ($value['email_biller'] == "1" or $value['email_customer'] == "1") {
                                 /*
                                  * If you want a new copy of the invoice being emailed to the customer 
                                  * use this code
                                  */
                                 $export_rec = new export();
                                 $export_rec->domain_id = $domain_id;
                                 $export_rec->format = "pdf";
                                 $export_rec->file_location = 'file';
                                 $export_rec->module = 'invoice';
                                 $export_rec->id = $invoice['id'];
                                 $export_rec->execute();
                                 #$attachment = file_get_contents('./tmp/cache/' . $pdf_file_name);
                                 $email_rec = new email();
                                 $email_rec->domain_id = $domain_id;
                                 $email_rec->format = 'cron_invoice';
                                 $email_body_rec = new email_body();
                                 $email_body_rec->email_type = 'cron_invoice_receipt';
                                 $email_body_rec->customer_name = $customer['name'];
                                 $email_body_rec->invoice_name = $invoice['index_name'];
                                 $email_body_rec->biller_name = $biller['name'];
                                 $email_rec->notes = $email_body_rec->create();
                                 $email_rec->from = $biller['email'];
                                 $email_rec->from_friendly = $biller['name'];
                                 $email_rec->to = $this->getEmailSendAddresses($value, $customer['email'], $biller['email']);
                                 $email_rec->invoice_name = $invoice['index_name'];
                                 $email_rec->attachment = $pdf_file_name_invoice;
                                 $email_rec->subject = $email_rec->set_subject('invoice_eway_receipt');
                                 $return['email_message'] = $email_rec->send();
                                 /*
                                  * If you want a receipt as PDF being emailed to the customer
                                  * uncomment the code below
                                  */
                                 /*
                                 $export = new export();
                                 $export -> format = "pdf";
                                 $export -> file_location = 'file';
                                 $export -> module = 'payment';
                                 $export -> id = $payment_id;
                                 $export -> execute();
                                 
                                 $email = new email();
                                 $email -> format = 'cron_payment';
                                 
                                     $email_body = new email_body();
                                     $email_body->email_type = 'cron_payment';
                                     $email_body->customer_name = $customer['name'];
                                     $email_body->invoice_name = 'payment'.$payment_id;
                                     $email_body->biller_name = $biller['name'];
                                 
                                 $email -> notes = $email_body->create();
                                 $email -> from = $biller['email'];
                                 $email -> from_friendly = $biller['name'];
                                 if($value['email_customer'] == "1")
                                 {
                                     $email -> to = $customer['email'];
                                 }
                                 if($value['email_biller'] == "1" AND $value['email_customer'] == "1")
                                 {
                                     $email -> to = $customer['email'].";".$biller['email'];
                                 }
                                 if($value['email_biller'] == "1" AND $value['email_customer'] == "0")
                                 {
                                     $email -> to = $customer['email'];
                                 }
                                 $email -> subject = $pdf_file_name_receipt." from ".$biller['name'];
                                 $email -> attachment = $pdf_file_name_receipt;
                                 $return['email_message'] = $email->send();
                                 */
                             }
                         } else {
                             //do email to biller/admin - say error
                             $email = new email();
                             $email->domain_id = $domain_id;
                             $email->format = 'cron_payment';
                             $email->from = $biller['email'];
                             $email->from_friendly = $biller['name'];
                             $email->to = $biller['email'];
                             $email->subject = "Payment failed for " . $invoice['index_name'];
                             $error_message = "Invoice:  " . $invoice['index_name'] . "<br /> Amount: " . $invoice['total'] . " <br />";
                             foreach ($eway->get_message() as $key => $value) {
                                 $error_message .= "\n<br>\$ewayResponseFields[\"{$key}\"] = {$value}";
                             }
                             $email->notes = $error_message;
                             $return['email_message'] = $email->send();
                         }
                     }
                 } else {
                     //cron not run for this cron_id
                     $return['cron_message_' . $value['cron_id']] = "Cron ID: " . $value['cron_id'] . " NOT RUN: Cron for " . $value['index_name'] . " with start date of " . $value['start_date'] . ", end date of " . $value['end_date'] . " where it runs each " . $value['recurrence'] . " " . $value['recurrence_type'] . " did not recur today :: Info diff=" . $diff;
                 }
             } else {
                 //days diff is negative - whats going on
                 $return['cron_message_' . $value['cron_id']] = "Cron ID: " . $value['cron_id'] . " NOT RUN: - Not cheduled for today - Cron for " . $value['index_name'] . " with start date of " . $value['start_date'] . ", end date of " . $value['end_date'] . " where it runs each " . $value['recurrence'] . " " . $value['recurrence_type'] . " did not recur today :: Info diff=" . $diff;
             }
         } else {
             // cron has already been run for that cron_id today
             $return['cron_message_' . $value['cron_id']] = "Cron ID: " . $value['cron_id'] . " - Cron has already been run for domain: " . $domain_id . " for the date: " . $today . " for invoice " . $value['invoice_id'];
             $return['email_message'] = "";
         }
     }
     // no crons scheduled for today
     if ($number_of_crons_run == '0') {
         $return['id'] = $i;
         $return['cron_message'] = "No invoices recurred for this cron run for domain: " . $domain_id . " for the date: " . $today;
         $return['email_message'] = "";
     }
     //insert into cron_log date of run
     /*
     		    $cron_log = new cronlog();
         $cron_log->run_date = $today;
         $cron_log->domain_id = $domain_id;
         $cron_log->insert();
     */
     /*
      * If you want to get an email once cron has been run edit the below details
      *
      */
     /*
         $email = new email();
         $email -> format = 'cron';
         #$email -> notes = $return;
         $email -> from = "simpleinvoices@localhost";
         $email -> from_friendly = "Simple Invoices - Cron";
         $email -> to = "simpleinvoices@localhost";
         #$email -> bcc = $_POST['email_bcc'];
         $email -> subject = "Cron for Simple Invoices has been run for today:";
         $email -> send ();
     */
     return $return;
 }
示例#21
0
<?php

//get invoice details
$invoiceobj = new invoice();
// why hardcode invoice number below?
$invoice = $invoiceobj->select('1');
header('Content-type: application/xml');
echo encode::xml($invoice);
print_r($invoice);
示例#22
0
/*
* Script: email.php
* 	Email invoice page
*
* License:
*	 GPL v3 or above
*
* Website:
* 	http://www.simpleinvoices.org
*/
//stop the direct browsing to this file - let index.php handle which files get displayed
checkLogin();
#get the invoice id
$invoice_id = $_GET['id'];
$invoiceobj = new invoice();
$invoice = $invoiceobj->select($invoice_id);
$preference = getPreference($invoice['preference_id']);
$biller = getBiller($invoice['biller_id']);
$customer = getCustomer($invoice['customer_id']);
$invoiceType = getInvoiceType($invoice['type_id']);
#create PDF name
$spc2us_pref = str_replace(" ", "_", $invoice['index_name']);
$pdf_file_name = $spc2us_pref . '.pdf';
if ($_GET['stage'] == 2) {
    #echo $block_stage2;
    // Create invoice
    $export = new export();
    $export->format = "pdf";
    $export->file_location = 'file';
    $export->module = 'invoice';
    $export->id = $invoice_id;
示例#23
0
 if ($number_of_payments == '0') {
     $payment = new payment();
     $payment->ac_inv_id = $_POST['pg_consumerorderid'];
     $payment->ac_amount = $_POST['pg_total_amount'];
     $payment->ac_notes = $paypal_data;
     $payment->ac_date = date('Y-m-d');
     $payment->online_payment_id = $_POST['pg_consumerorderid'];
     $payment->domain_id = '1';
     $payment_type = new payment_type();
     $payment_type->type = "ACH";
     $payment_type->domain_id = '1';
     $payment->ac_payment_type = $payment_type->select_or_insert_where();
     $logger->log('ACH - payment_type=' . $payment->ac_payment_type, Zend_Log::INFO);
     $payment->insert();
     $invoiceobj = new invoice();
     $invoice = $invoiceobj->select($_POST['pg_consumerorderid']);
     $biller = getBiller($invoice['biller_id']);
     //send email
     $body = "A PaymentsGateway.com payment of " . $_POST['pg_total_amount'] . " was successfully received into Simple Invoices\n";
     $body .= "for invoice: " . $_POST['pg_consumerorderid'];
     $body .= " from " . $_POST['pg_billto_postal_name_company'] . " on " . date('m/d/Y');
     $body .= " at " . date('g:i A') . "\n\nDetails:\n";
     $body .= $paypal_data;
     $email = new email();
     $email->notes = $body;
     $email->to = $biller['email'];
     $email->from = "*****@*****.**";
     $email->subject = 'PaymentsGateway.com -Instant Payment Notification - Recieved Payment';
     $email->send();
     $xml_message = "+++++++++<br /><br />";
     $xml_message .= "Thank you for the payment, the details have been recorded and " . $biller['name'] . " has been notified via email.";
示例#24
0
<?php
//stop the direct browsing to this file - let index.php handle which files get displayed
checkLogin();

$SI_SYSTEM_DEFAULTS = new SimpleInvoices_Db_Table_SystemDefaults();
$SI_TAX = new SimpleInvoices_Db_Table_Tax();

#get the invoice id
$expense_id = $_GET['id'];

$expense = expense::get($expense_id);
$detail = expense::detail();
$detail['customer'] = customer::get($expense['customer_id']);
$detail['biller'] = biller::select($expense['biller_id']);
$detail['invoice'] = invoice::select($expense['invoice_id']);
$detail['product'] = product::get($expense['product_id']);
$detail['expense_account'] = expenseaccount::select($expense['expense_account_id']);
$detail['expense_tax'] = expensetax::get_all($expense_id);
$detail['expense_tax_total'] = $expense['amount'] + expensetax::get_sum($expense_id);
$detail['expense_tax_grouped'] = expensetax::grouped($expense_id);
$detail['status_wording'] = $expense['status']==1?$LANG['paid']:$LANG['not_paid'];

$taxes = $SI_TAX->fetchAllActive();
#$tax_selected = getTaxRate($product['default_tax_id']);
$defaults = $SI_SYSTEM_DEFAULTS->fetchAll();

$smarty -> assign('expense',$expense);
$smarty -> assign('detail',$detail);
$smarty -> assign('taxes',$taxes);
$smarty -> assign('defaults',$defaults);
$smarty -> assign('tax_selected',$tax_selected);
示例#25
0
 function attach_invoice($commentID, $entityID, $verbose)
 {
     $invoice = new invoice();
     $invoice->set_id($entityID);
     $invoice->select();
     $str = $invoice->generate_invoice_file($verbose, true);
     $rtn["name"] = "invoice_" . $entityID . ".pdf";
     $rtn["blob"] = $str;
     $rtn["size"] = strlen($str);
     return $rtn;
 }
示例#26
-1
 function getData()
 {
     //echo "export - get data";
     global $smarty;
     global $siUrl;
     switch ($this->module) {
         case "statement":
             $invoice = new invoice();
             $invoice->biller = $this->biller_id;
             $invoice->customer = $this->customer_id;
             if ($this->filter_by_date == "yes") {
                 if (isset($this->start_date)) {
                     $invoice->start_date = $this->start_date;
                 }
                 if (isset($this->end_date)) {
                     $invoice->end_date = $this->end_date;
                 }
                 if (isset($this->start_date) and isset($this->end_date)) {
                     $invoice->having = "date_between";
                 }
                 $having_count = 1;
             }
             if ($this->show_only_unpaid == "yes") {
                 if ($having_count == 1) {
                     $invoice->having_and = "money_owed";
                 } else {
                     $invoice->having = "money_owed";
                 }
             }
             $invoice_all = $invoice->select_all('count');
             $invoices = $invoice_all->fetchAll();
             foreach ($invoices as $i => $row) {
                 $statement['total'] = $statement['total'] + $row['invoice_total'];
                 $statement['owing'] = $statement['owing'] + $row['owing'];
                 $statement['paid'] = $statement['paid'] + $row['INV_PAID'];
             }
             $templatePath = "./templates/default/statement/index.tpl";
             $biller_details = getBiller($this->biller_id);
             $customer_details = getCustomer($this->customer_id);
             $this->file_name = "statement_" . $this->biller_id . "_" . $this->customer_id . "_" . $invoice->start_date . "_" . $invoice->end_date;
             $smarty->assign('biller_id', $biller_id);
             $smarty->assign('biller_details', $biller_details);
             $smarty->assign('customer_id', $customer_id);
             $smarty->assign('customer_details', $customer_details);
             $smarty->assign('show_only_unpaid', $show_only_unpaid);
             $smarty->assign('filter_by_date', $this->filter_by_date);
             $smarty->assign('invoices', $invoices);
             $smarty->assign('start_date', $this->start_date);
             $smarty->assign('end_date', $this->end_date);
             $smarty->assign('invoices', $invoices);
             $smarty->assign('statement', $statement);
             $data = $smarty->fetch("." . $templatePath);
             break;
         case "payment":
             $payment = getPayment($this->id);
             /*Code to get the Invoice preference - so can link from this screen back to the invoice - START */
             $invoice = getInvoice($payment['ac_inv_id']);
             $biller = getBiller($payment['biller_id']);
             $logo = getLogo($biller);
             $logo = str_replace(" ", "%20", $logo);
             $customer = getCustomer($payment['customer_id']);
             $invoiceType = getInvoiceType($invoice['type_id']);
             $customFieldLabels = getCustomFieldLabels();
             $paymentType = getPaymentType($payment['ac_payment_type']);
             $preference = getPreference($invoice['preference_id']);
             $smarty->assign("payment", $payment);
             $smarty->assign("invoice", $invoice);
             $smarty->assign("biller", $biller);
             $smarty->assign("logo", $logo);
             $smarty->assign("customer", $customer);
             $smarty->assign("invoiceType", $invoiceType);
             $smarty->assign("paymentType", $paymentType);
             $smarty->assign("preference", $preference);
             $smarty->assign("customFieldLabels", $customFieldLabels);
             $smarty->assign('pageActive', 'payment');
             $smarty->assign('active_tab', '#money');
             $css = $siUrl . "/templates/invoices/default/style.css";
             $smarty->assign('css', $css);
             $templatePath = "./templates/default/payments/print.tpl";
             $data = $smarty->fetch("." . $templatePath);
             break;
         case "invoice":
             $invoice = invoice::select($this->id);
             $invoice_number_of_taxes = numberOfTaxesForInvoice($this->id);
             $customer = getCustomer($invoice['customer_id']);
             $biller = biller::select($invoice['biller_id']);
             $preference = getPreference($invoice['preference_id']);
             $defaults = getSystemDefaults();
             $logo = getLogo($biller);
             $logo = str_replace(" ", "%20", $logo);
             $invoiceItems = invoice::getInvoiceItems($this->id);
             $spc2us_pref = str_replace(" ", "_", $invoice['index_name']);
             $this->file_name = $spc2us_pref;
             $customFieldLabels = getCustomFieldLabels();
             /*Set the template to the default*/
             $template = $defaults['template'];
             $templatePath = "./templates/invoices/{$template}/template.tpl";
             $template_path = "../templates/invoices/{$template}";
             $css = $siUrl . "/templates/invoices/{$template}/style.css";
             $pluginsdir = "./templates/invoices/{$template}/plugins/";
             //$smarty = new Smarty();
             $smarty->plugins_dir = $pluginsdir;
             $pageActive = "invoices";
             $smarty->assign('pageActive', $pageActive);
             if (file_exists($templatePath)) {
                 //echo "test";
                 $smarty->assign('biller', $biller);
                 $smarty->assign('customer', $customer);
                 $smarty->assign('invoice', $invoice);
                 $smarty->assign('invoice_number_of_taxes', $invoice_number_of_taxes);
                 $smarty->assign('preference', $preference);
                 $smarty->assign('logo', $logo);
                 $smarty->assign('template', $template);
                 $smarty->assign('invoiceItems', $invoiceItems);
                 $smarty->assign('template_path', $template_path);
                 $smarty->assign('css', $css);
                 $smarty->assign('customFieldLabels', $customFieldLabels);
                 $data = $smarty->fetch("." . $templatePath);
             }
             break;
     }
     return $data;
 }