Exemple #1
0
function getSubCustomers($customer_id)
{
    $domain_id = domain_id::get();
    $sql = "SELECT * FROM " . TB_PREFIX . "customers\n          WHERE parent_customer_id = :customer_id\n          AND domain_id = :domain_id";
    $sth = dbQuery($sql, ':customer_id', $customer_id, ':domain_id', $domain_id);
    return $sth->fetchAll();
}
Exemple #2
0
 function insert()
 {
     global $db;
     $domain_id = domain_id::get($this->domain_id);
     $sql = "INSERT INTO \n\t\t\t\t" . TB_PREFIX . "customers\n\t\t\t\t(\n\t\t\t\t\tdomain_id, attention, name, street_address, street_address2,\n\t\t\t\t\tcity, state, zip_code, country, phone, mobile_phone,\n\t\t\t\t\tfax, email, notes, custom_field1, custom_field2,\n\t\t\t\t\tcustom_field3, custom_field4, enabled\n\t\t\t\t)\n\t\t\t\tVALUES \n\t\t\t\t(\n\t\t\t\t\t:domain_id ,:attention, :name, :street_address, :street_address2,\n\t\t\t\t\t:city, :state, :zip_code, :country, :phone, :mobile_phone,\n\t\t\t\t\t:fax, :email, :notes, :custom_field1, :custom_field2,\n\t\t\t\t\t:custom_field3, :custom_field4, :enabled\n\t\t\t\t)";
     return $db->query($sql, ':attention', $this->attention, ':name', $this->name, ':street_address', $this->street_address, ':street_address2', $this->street_address2, ':city', $this->city, ':state', $this->state, ':zip_code', $this->zip_code, ':country', $this->country, ':phone', $this->phone, ':mobile_phone', $this->mobile_phone, ':fax', $this->fax, ':email', $this->email, ':notes', $this->notes, ':custom_field1', $this->custom_field1, ':custom_field2', $this->custom_field2, ':custom_field3', $this->custom_field3, ':custom_field4', $this->custom_field4, ':enabled', $this->enabled, ':domain_id', $domain_id);
 }
Exemple #3
0
 public static function rewind($node, $sub_node = 0, $domain_id = '', $sub_node_2 = 0)
 {
     $domain_id = domain_id::get($domain_id);
     $sql = "UPDATE " . TB_PREFIX . "index \n                SET id = (id - 1) \n                WHERE node = :node\n\t\t\t\tAND sub_node = :sub_node\n\t\t\t\tAND sub_node_2 = :sub_node_2\n                AND domain_id = :domain_id\n\t\t\t";
     $sth = dbQuery($sql, ':node', $node, ':sub_node', $sub_node, ':sub_node_2', $sub_node_2, ':domain_id', $domain_id);
     return $sth;
 }
function smarty_function_online_payment_link($params, &$smarty)
{
    global $LANG;
    $domain_id = domain_id::get($params['domain_id']);
    $url = getURL();
    if (in_array("paypal", explode(",", $params['type']))) {
        $link = "<a \n\t\t\t\thref=\"https://www.paypal.com/xclick/?business=" . urlencode($params['business']) . "&item_name=" . urlencode($params['item_name']) . "&invoice=" . urlencode($params['invoice']) . "&amount=" . urlencode(number_format($params['amount'], 2, '.', '')) . "&currency_code=" . urlencode($params['currency_code']) . "&notify_url=" . urlencode($params['notify_url']) . "&return=" . urlencode($params['return_url']) . "&no_shipping=1&no_note=1&custom=domain_id:" . urlencode($domain_id) . "; \">";
        if ($params['include_image'] == "true") {
            $link .= "<img border='0' src='" . urlsafe($url) . "/images/common/pay_with_paypal.gif'/>";
        } else {
            $link .= htmlsafe($params['link_wording']);
        }
        $link .= "</a>";
        echo $link;
    }
    if (in_array("eway_shared", explode(",", $params['type']))) {
        $link = "<a \n\t\t\t\thref=\"https://www.paypal.com/xclick/?business=" . urlencode($params['business'] . "\n\t\t\t\t&item_name=" . urlencode($params['item_name']) . "&invoice=" . urlencode($params['invoice']) . "\n\t\t\t\t&amount=" . urlencode(number_format($params['amount'], 2, '.', '')) . "&currency_code=" . $params['currency_code']) . "\n\t\t\t\t&return=http://vcsweb.com.au&no_shipping=1&no_note=1\">";
        if ($params['include_image'] == "true") {
            $link .= "<img border='0' src='" . urlsafe($url) . "/images/common/pay_with_eway.gif'/>";
        } else {
            $link .= htmlsafe($params['link_wording']);
        }
        $link .= "</a>";
        echo $link;
    }
}
 public function check_reorder_level()
 {
     global $db;
     global $auth_session;
     $domain_id = domain_id::get($this->domain_id);
     //sellect qty and reorder level
     $inventory = new product();
     $sth = $inventory->select_all('count');
     $inventory_all = $sth->fetchAll(PDO::FETCH_ASSOC);
     $email = "";
     foreach ($inventory_all as $row) {
         if ($row['quantity'] <= $row['reorder_level']) {
             $message = "The quantity of Product: " . $row['description'] . " is " . siLocal::number($row['quantity']) . ", which is equal to or below its reorder level of " . $row['reorder_level'];
             $return['row_' . $row['id']]['message'] = $message;
             $email_message .= $message . "<br />\n";
         }
     }
     //print_r($return);
     #$attachment = file_get_contents('./tmp/cache/' . $pdf_file_name);
     $email = new email();
     $email->notes = $email_message;
     $email->from = $email->get_admin_email();
     $email->to = $email->get_admin_email();
     #$email -> bcc = "justin@localhost";
     $email->subject = "Simple Invoices reorder level email";
     $email->send();
     return $return;
 }
	public function insert()
	{
  	global $db;
  	global $auth_session;
  	global $dbh;

		$domain_id = domain_id::get($this->domain_id);
        
    $sql = "INSERT INTO ".TB_PREFIX."payment_types (
				pt_description,
				pt_enabled,
				domain_id
			) VALUES (
				:pt_description,
				:pt_enabled,
				:domain_id
			)";
        	$sth = $db->query($sql,
				':pt_description',$this->pt_description,
				':pt_enabled',$this->pt_enabled,
				':domain_id',$domain_id 
			) or die(htmlsafe(end($dbh->errorInfo())));
        
 	       return $sth;
	}
	public function check()
	{
  	global $db;
  	global $dbh;
		
		$domain_id = domain_id::get($this->domain_id);

		$run_date = empty($this->run_date) ? $today : $this->run_date;
		$sql = "SELECT 
                    count(*) as count 
                FROM 
                    ".TB_PREFIX."cron_log 
                WHERE 
                    domain_id = :domain_id 
                AND 
                    cron_id = :cron_id 
                AND
                    run_date = :run_date";
        	$sth = $db->query($sql,
				':domain_id',$domain_id, 
				':cron_id',$this->cron_id, 
				':run_date',$run_date
			) or die(htmlsafe(end($dbh->errorInfo())));
        
 	       return $sth->fetchColumn();
	}
Exemple #8
0
function getExtensions()
{
    global $LANG;
    $domain_id = domain_id::get();
    $sql = "SELECT * FROM " . TB_PREFIX . "extensions WHERE domain_id = 0 OR domain_id = :domain_id ORDER BY name";
    $sth = dbQuery($sql, ':domain_id', $domain_id);
    $exts = null;
    for ($i = 0; $ext = $sth->fetch(); $i++) {
        $exts[$i] = $ext;
    }
    return $exts;
}
function smarty_function_online_payment_link($params, &$smarty)
{
    global $LANG;
    global $siUrl;
    global $config;
    global $siUrl;
    $domain_id = domain_id::get($params['domain_id']);
    $url = getURL();
    if (in_array("paypal", explode(",", $params['type']))) {
        $link = "<a \n            href=\"https://www.paypal.com/xclick/?business=" . urlencode($params['business']) . "&item_name=" . urlencode($params['item_name']) . "&invoice=" . urlencode($params['invoice']) . "&amount=" . urlencode(number_format($params['amount'], 2, '.', '')) . "&currency_code=" . urlencode($params['currency_code']) . "&notify_url=" . urlencode($params['notify_url']) . "&return=" . urlencode($params['return_url']) . "&no_shipping=1&no_note=1&custom=domain_id:" . urlencode($domain_id) . "; \">";
        if ($params['include_image'] == "true") {
            $link .= "<img border='0' src='" . urlsafe($url) . "/images/common/pay_with_paypal.gif'/>";
        } else {
            $link .= htmlsafe($params['link_wording']);
        }
        $link .= "</a>";
        echo $link;
    }
    if (in_array("eway_shared", explode(",", $params['type']))) {
        $link = "<a \n            href=\"https://www.paypal.com/xclick/?business=" . urlencode($params['business'] . "\n            &item_name=" . urlencode($params['item_name']) . "&invoice=" . urlencode($params['invoice']) . "\n            &amount=" . urlencode(number_format($params['amount'], 2, '.', '')) . "&currency_code=" . $params['currency_code']) . "\n            &return=http://vcsweb.com.au&no_shipping=1&no_note=1\">";
        if ($params['include_image'] == "true") {
            $link .= "<img border='0' src='" . urlsafe($url) . "/images/common/pay_with_eway.gif'/>";
        } else {
            $link .= htmlsafe($params['link_wording']);
        }
        $link .= "</a>";
        echo $link;
    }
    if (in_array("paymentsgateway", explode(",", $params['type']))) {
        // $today = date('Y-m-d',$x);
        /*
          $datetime1 = new DateTime('0001-01-01');
          $datetime2 = new DateTime('now', new DateTimeZone('UTC'));
          $interval = $datetime1->diff($datetime2);
                //$interval->format('%a %h %i %s ') ;
                $seconds = ( $interval->format('%a') * 24 * 60 * 60) + ( $interval->format('%h') * 60 * 60 )+  ($interval->format('%i') * 60) + ( $interval->format('%s') ) ;
        */
        //$time = time() + 62135596800;
        //$seconds =  $time . '0000000';
        //get biller secure trans key here
        // $hash_info = $params['api_id'] ."|1|1.0|". number_format($params['amount'], 2, '.', '') ."|". $seconds. "|". $params['invoice'] ;
        //$hash = hash_hmac('md5', $hash_info, $params['transaction_password']) ;
        $link = "<a \n            href='https://swp.paymentsgateway.net/co/default.aspx?pg_api_login_id=" . urlencode($params['api_id']) . "&pg_billto_postal_name_company=" . urlencode($params['customer']['name']) . "&pg_version_number=1.0&pg_total_amount=" . urlencode(number_format($params['amount'], 2, '.', '')) . "&pg_transaction_order_number=" . urlencode($params['invoice']) . "&pg_billto_postal_name_first=" . urlencode($params['customer']['attention']) . "&pg_billto_postal_name_last=-&pg_billto_postal_street_line1=" . urlencode($params['customer']['street_address']) . "&pg_billto_postal_street_line2=" . urlencode($params['customer']['street_address2']) . "&pg_billto_postal_city=" . urlencode($params['customer']['city']) . "&pg_billto_postal_stateprov=" . urlencode($params['customer']['state']) . "&pg_billto_postal_postalcode=" . urlencode($params['customer']['zip_code']) . "&pg_billto_telecom_phone_number=" . urlencode($params['customer']['phone']) . "&pg_billto_online_email=" . $params['customer']['email'] . "&pg_consumerorderid=" . $params['invoice'] . "&pg_return_url=" . $siUrl . "/api-ach&pg_save_client=2'>";
        if ($params['include_image'] == "true") {
            $link .= "<img border='0' src='" . urlsafe($url) . "/images/common/pay_with_ach.gif'/>";
        } else {
            $link .= htmlsafe($params['link_wording']);
        }
        $link .= "</a>";
        echo $link;
    }
}
Exemple #10
0
function sql($type = '', $dir, $sort, $rp, $page)
{
    global $config;
    global $LANG;
    $domain_id = domain_id::get();
    $valid_search_fields = array('e.id', 'b.name', 'c.name', 'ea.name', 'p.description', 'status_wording');
    //SC: Safety checking values that will be directly subbed in
    if (intval($page) != $page) {
        $page = 1;
    }
    if (intval($rp) != $rp) {
        $rp = 25;
    }
    /*SQL Limit - start*/
    $start = ($page - 1) * $rp;
    $limit = "LIMIT {$start}, {$rp}";
    if ($type == "count") {
        $limit = '';
    }
    /*SQL Limit - end*/
    if (!preg_match('/^(asc|desc)$/iD', $dir)) {
        $dir = 'DESC';
    }
    // can this line be removed ?
    $req = array_merge($_GET, $_POST);
    $where = "";
    $query = isset($_REQUEST['query']) ? $_REQUEST['query'] : null;
    $qtype = isset($_REQUEST['qtype']) ? $_REQUEST['qtype'] : null;
    if (!(empty($qtype) || empty($query))) {
        if (in_array($qtype, $valid_search_fields)) {
            $where = " AND {$qtype} LIKE :query ";
        } else {
            $qtype = null;
            $query = null;
        }
    }
    /*Check that the sort field is OK*/
    $validFields = array('id', 'status', 'amount', 'expense_account_id', 'biller_id', 'customer_id', 'invoice_id', 'date', 'amount', 'note');
    if (in_array($sort, $validFields)) {
        $sort = $sort;
    } else {
        $sort = "id";
    }
    $sql = "SELECT\n                e.id as EID,\n                e.status as status,\n                e.*,\n                i.id as invoice,\n                b.name as biller,\n                ea.name as expense_account,\n                c.name as customer,\n                p.description as product,\n                (select sum(tax_amount) from " . TB_PREFIX . "expense_item_tax where expense_id = EID) as tax,\n                (select tax + e.amount) as total,\n                (CASE WHEN status = 1 THEN '" . $LANG['paid'] . "'\n                      WHEN status = 0 THEN '" . $LANG['not_paid'] . "'\n                      END) AS status_wording\n\t\t\tFROM \n\t\t\t\t" . TB_PREFIX . "expense e\n                LEFT OUTER JOIN " . TB_PREFIX . "expense_account ea  \n                    ON (e.expense_account_id = ea.id)\n                LEFT OUTER JOIN " . TB_PREFIX . "biller b  \n                    ON (e.biller_id = b.id AND e.domain_id = b.domain_id)\n                LEFT OUTER JOIN " . TB_PREFIX . "customers c  \n                    ON (e.customer_id = c.id AND e.domain_id = c.domain_id)\n                LEFT OUTER JOIN " . TB_PREFIX . "products p  \n                    ON (e.product_id = p.id AND e.domain_id = p.domain_id)\n                LEFT OUTER JOIN " . TB_PREFIX . "invoices i  \n                    ON (e.invoice_id = i.id AND e.domain_id = i.domain_id)\n\t\t\t\tWHERE\n                    e.domain_id = :domain_id\n\t\t\t\t\t{$where}\n\t\t\t\tORDER BY \n\t\t\t\t\t{$sort} {$dir} \n\t\t\t\t{$limit}";
    if (empty($query)) {
        $result = dbQuery($sql, ':domain_id', $domain_id);
    } else {
        $result = dbQuery($sql, ':domain_id', $domain_id, ':query', "%{$query}%");
    }
    return $result;
}
Exemple #11
0
function sql($type = '', $dir, $sort, $rp, $page)
{
    global $config;
    global $LANG;
    $domain_id = domain_id::get();
    $valid_search_fields = array('id', 'name');
    //SC: Safety checking values that will be directly subbed in
    if (intval($page) != $page) {
        $page = 1;
    }
    if (intval($rp) != $rp) {
        $rp = 25;
    }
    /*SQL Limit - start*/
    $start = ($page - 1) * $rp;
    $limit = "LIMIT {$start}, {$rp}";
    if ($type == "count") {
        $limit = '';
    }
    /*SQL Limit - end*/
    if (!preg_match('/^(asc|desc)$/iD', $dir)) {
        $dir = 'DESC';
    }
    $where = "";
    $query = isset($_POST['query']) ? $_POST['query'] : null;
    $qtype = isset($_POST['qtype']) ? $_POST['qtype'] : null;
    if (!(empty($qtype) || empty($query))) {
        if (in_array($qtype, $valid_search_fields)) {
            $where = " AND {$qtype} LIKE :query ";
        } else {
            $qtype = null;
            $query = null;
        }
    }
    /*Check that the sort field is OK*/
    $validFields = array('id', 'biller_id', 'customer_id');
    if (in_array($sort, $validFields)) {
        $sort = $sort;
    } else {
        $sort = "id";
    }
    $sql = "SELECT \n\t\t\t\t\tid, \n\t\t\t\t\tname\n\t\t\t\tFROM \n\t\t\t\t\t" . TB_PREFIX . "expense_account  \n\t\t\t\tWHERE \n\t\t\t\t\tdomain_id = :domain_id\n\t\t\t\t\t{$where}\n\t\t\t\tORDER BY \n\t\t\t\t\t{$sort} {$dir} \n\t\t\t\t{$limit}";
    if (empty($query)) {
        $result = dbQuery($sql, ':domain_id', $domain_id);
    } else {
        $result = dbQuery($sql, ':domain_id', $domain_id, ':query', "%{$query}%");
    }
    return $result;
}
Exemple #12
0
 public static function getInvoiceItems($id, $domain_id = '')
 {
     // $domain_id is a parent class member
     $domain_id = domain_id::get($domain_id);
     $sql = "SELECT * FROM " . TB_PREFIX . "invoice_items WHERE invoice_id = :id AND domain_id = :domain_id";
     $sth = dbQuery($sql, ':id', $id, ':domain_id', $domain_id);
     $invoiceItems = null;
     for ($i = 0; $invoiceItem = $sth->fetch(); $i++) {
         $sql = "SELECT * FROM " . TB_PREFIX . "products WHERE id = :id AND domain_id = :domain_id";
         $tth = dbQuery($sql, ':id', $invoiceItem['product_id'], ':domain_id', $domain_id);
         $invoiceItem['product'] = $tth->fetch();
         // a.display_name was in old schema and is now a.name
         $attr_sql = "select \n                    CONCAT(a.display_name, '-',v.value) as display\n                FROM\n                    " . TB_PREFIX . "products_attributes a INNER JOIN \n                    " . TB_PREFIX . "products_values v ON (a.id = v.attribute_id)\n                WHERE\n                    v.id = :attr_id";
         // $invoiceItem['attribute_#'] (# = 1,2,3) was in old schema
         $attr1 = dbQuery($attr_sql, ':attr_id', $invoiceItem['attribute_1']);
         $invoiceItem['attr1'] = $attr1->fetch();
         $attr2 = dbQuery($attr_sql, ':attr_id', $invoiceItem['attribute_2']);
         $invoiceItem['attr2'] = $attr2->fetch();
         $attr3 = dbQuery($attr_sql, ':attr_id', $invoiceItem['attribute_3']);
         $invoiceItem['attr3'] = $attr3->fetch();
         $invoiceItems[$i] = $invoiceItem;
     }
     return $invoiceItems;
 }
Exemple #13
0
<?php

if ($_POST['op'] == 'edit' and !empty($_POST['invoice_id'])) {
    $cron = new cron();
    $cron->domain_id = domain_id::get();
    $cron->invoice_id = $_POST['invoice_id'];
    $cron->start_date = $_POST['start_date'];
    $cron->end_date = $_POST['end_date'];
    $cron->recurrence = $_POST['recurrence'];
    $cron->recurrence_type = $_POST['recurrence_type'];
    $cron->email_biller = $_POST['email_biller'];
    $cron->email_customer = $_POST['email_customer'];
    $result = $cron->insert();
    $saved = !empty($result) ? "true" : "false";
}
//$invoiceobj = new invoice();
//$invoice_all = $invoiceobj->get_all();
$get_cron = new cron();
$get_cron->id = $_GET['id'];
$cron = $get_cron->select();
//$smarty -> assign('invoice_all',$invoice_all);
$smarty->assign('saved', $saved);
$smarty->assign('cron', $cron);
$smarty->assign('pageActive', 'cron');
$smarty->assign('subPageActive', 'cron_view');
$smarty->assign('active_tab', '#money');
    public function get_admin_email()
    {
    
        global $db;
        global $dbh;
        
				$domain_id = domain_id::get($this->domain_id);
    
        $sql = "select email from ".TB_PREFIX."user where role_id = '1' and domain_id =:domain_id LIMIT 1";
        $sth  = $db->query($sql,':domain_id',$domain_id) or die(htmlsafe(end($dbh->errorInfo())));
 
        return $sth->fetchColumn();

    }
Exemple #15
0
<?php

if ($_POST['op'] == 'edit' and !empty($_POST['invoice_id'])) {
    $edit = new cron();
    $edit->domain_id = domain_id::get();
    $edit->id = $_GET['id'];
    $edit->invoice_id = $_POST['invoice_id'];
    $edit->start_date = $_POST['start_date'];
    $edit->end_date = $_POST['end_date'];
    $edit->recurrence = $_POST['recurrence'];
    $edit->recurrence_type = $_POST['recurrence_type'];
    $edit->email_biller = $_POST['email_biller'];
    $edit->email_customer = $_POST['email_customer'];
    $result = $edit->update();
    $saved = !empty($result) ? "true" : "false";
}
$invoices = new invoice();
$invoices->sort = 'id';
$invoice_all = $invoices->select_all('count');
$get_cron = new cron();
$get_cron->id = $_GET['id'];
$cron = $get_cron->select();
$smarty->assign('invoice_all', $invoice_all);
$smarty->assign('saved', $saved);
$smarty->assign('cron', $cron);
$smarty->assign('pageActive', 'cron');
$smarty->assign('subPageActive', 'cron_edit');
$smarty->assign('active_tab', '#money');
Exemple #16
0
*	 GPL v2 or above
*
* Website:
* 	http://www.simpleinvoices.org
*/
#table
//stop the direct browsing to this file - let index.php handle which files get displayed
checkLogin();
#get the invoice id
$defaults = getSystemDefaults();
$master_customer_id = $_GET['customer_id'];
$customer = getCustomer($master_customer_id);
if ($_GET['action'] == 'update_template') {
    /* update default template for customer */
    $sql = "UPDATE " . TB_PREFIX . "customers SET custom_field4 = :cf4 WHERE id = :id AND domain_id = :domain_id";
    dbQuery($sql, ':cf4', $_GET['id'], ':id', $master_customer_id, ':domain_id', domain_id::get());
    $smarty->assign("view", "quick_view");
    $smarty->assign("spec", "id");
    $smarty->assign("id", $_GET['id']);
    # print("debug=$sql");
} else {
    $template = $defaults['default_invoice'];
    /* GET DEFAULT TEMPLATE, OR NULL */
    $customer['custom_field4'] != null && ($template = $customer['custom_field4']);
    /* OVERRIDE WITH CF4 IF IT EXISTS */
    $invoice = getInvoice($template);
    $template = $invoice['id'];
    /* CHECK IF TEMPLATE EXISTS, OR NULL */
    if ($template == null) {
        /* No template for this customer */
        $smarty->assign("view", "itemised");
Exemple #17
0
 public function get_admin_email()
 {
     $domain_id = domain_id::get($this->domain_id);
     $sql = "SELECT u.email \n\t\t\t\tFROM " . TB_PREFIX . "user u \n\t\t\t\t\tLEFT JOIN " . TB_PREFIX . "user_role r \n\t\t\t\t\t\tON (u.role_id = r.id) \n\t\t\t\tWHERE r.name = 'administrator' \n\t\t\t\t\tAND domain_id = :domain_id \n\t\t\t\tLIMIT 1\n\t\t";
     $sth = dbQuery($sql, ':domain_id', $domain_id);
     return $sth->fetchColumn();
 }
 public function select_all_where()
 {
     global $logger;
     $domain_id = domain_id::get($this->domain_id);
     if ($this->filter == "date") {
         $where = "AND date BETWEEN '{$this->start_date}' AND '{$this->end_date}'";
     }
     $sql = "SELECT i.*, p.pref_description AS preference FROM " . TB_PREFIX . "invoices i LEFT JOIN " . TB_PREFIX . "preferences p  ON (i.preference_id = p.pref_id AND i.domain_id = p.domain_id) WHERE i.domain_id = :domain_id ORDER BY i.id";
     $sth = dbQuery($sql, ':domain_id', $domain_id);
     return $sth->fetchAll();
 }
Exemple #19
0
*	 GPL v2 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
$customer_id = $_GET['id'];
$customer = getCustomer($customer_id);
$customer['wording_for_enabled'] = $customer['enabled'] == 1 ? $LANG['enabled'] : $LANG['disabled'];
//TODO: Perhaps possible a bit nicer?
$stuff = null;
$stuff['total'] = calc_customer_total($customer['id'], domain_id::get(), true);
#amount paid calc - start
$stuff['paid'] = calc_customer_paid($customer['id'], domain_id::get(), true);
#amount paid calc - end
#amount owing calc - start
$stuff['owing'] = $stuff['total'] - $stuff['paid'];
#get custom field labels
$customFieldLabel = getCustomFieldLabels();
$invoices = getCustomerInvoices($customer_id);
//$start = (isset($_POST['start'])) ? $_POST['start'] : "0" ;
$dir = "DESC";
$sort = "id";
$rp = isset($_POST['rp']) ? $_POST['rp'] : "25";
$having = 'money_owed';
$page = isset($_POST['page']) ? $_POST['page'] : "1";
//$sql = "SELECT * FROM ".TB_PREFIX."invoices LIMIT $start, $limit";
$invoice_owing = new invoice();
$invoice_owing->sort = $sort;
Exemple #20
0
	public function run()
	{
        global $db;
        global $auth_session;
        
        $SI_BILLER = new SimpleInvoices_Db_Table_Biller();
        $SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();

        $today = date('Y-m-d');
        $domain_id = domain_id::get($this->domain_id);

        $cron_log = new cronlog();
        $cron_log->run_date = empty($this->run_date) ? $today : $this->run_date;
        $check_cron_log = $cron_log->check();        	

        //only proceed if cron has not been run for today
        $cron = new cron();
        $data = $cron->select_all('no_limit');

        $return['cron_message'] ="Cron started";
        $number_of_crons_run = "0";	
        foreach ($data as $key=>$value)
        {

            $cron_log = new cronlog();
            $cron_log->run_date = empty($this->run_date) ? $today : $this->run_date;
            $cron_log->cron_id = $data[$key]['cron_id'];
            $check_cron_log = $cron_log->check();        	

            $i="0";
            if ($check_cron_log == 0)
            {
                $run_cron ='false';
                $start_date = date('Y-m-d', strtotime( $data[$key]['start_date'] ) );
                $end_date = $data[$key]['end_date'] ;

                $diff = number_format((strtotime($today) - strtotime($start_date)) / (60 * 60 * 24),0);
                

                //only check if diff is positive
                if (($diff >= 0) AND ($end_date =="" OR $end_date >= $today))
                {

                    if($data[$key]['recurrence_type'] == 'day')
                    {
                        $modulus = $diff % $data[$key]['recurrence'] ;
                        if($modulus == 0)
                        { 
                            $run_cron ='true';
                        } else {
                            #$return .= "cron does not runs TODAY-days";

                        }

                    }

                    if($data[$key]['recurrence_type'] == 'week')
                    {
                        $period = 7 * $data[$key]['recurrence'];
                        $modulus = $diff % $period ;
                        if($modulus == 0)
                        { 
                            $run_cron ='true';
                        } else {
                            #$return .= "cron is not runs TODAY-week";
                        }

                    }
                    if($data[$key]['recurrence_type'] == 'month')
                    {
                        $start_day = date('d', strtotime( $data[$key]['start_date'] ) );
                        $start_month = date('m', strtotime( $data[$key]['start_date'] ) );
                        $start_year = date('Y', strtotime( $data[$key]['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 % $data[$key]['recurrence']  ;
                        if( ($modulus == 0) AND ( $start_day == $today_day ) )
                        { 
                            $run_cron ='true';
                        } else {
                            #$return .= "cron is not runs TODAY-month";
                        }

                    }
                    if($data[$key]['recurrence_type'] == 'year')
                    {
                        $start_day = date('d', strtotime( $data[$key]['start_date'] ) );
                        $start_month = date('m', strtotime( $data[$key]['start_date'] ) );
                        $start_year = date('Y', strtotime( $data[$key]['start_date'] ) );
                        $today_day = date('d');	
                        $today_month = date('m');	
                        $today_year = date('Y'); 	

                        $years = $today_year-$start_year;
                        $modulus =  $years % $data[$key]['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 == 'true')
                    {
                        $number_of_crons_run++;	
                        $return['cron_message_'.$data[$key]['cron_id']] = "Cron ID: ". $data[$key]['cron_id'] ." - Cron for ".$data[$key]['index_name']." with start date of ".$data[$key]['start_date'].", end date of ".$data[$key]['end_date']." where it runs each ".$data[$key]['recurrence']." ".$data[$key]['recurrence_type']." was run today :: Info diff=".$diff;
                        $i++;

                        $ni = new invoice();
                        $ni->id = $data[$key]['invoice_id'];
                        $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 = $data[$key]['cron_id'];
                        $cron_log->insert();

                        ## email the people
                        
                        $invoice= invoice::select($new_invoice_id);
                        $preference = $SI_PREFERENCES->getPreferenceById($invoice['preference_id']);
                        $biller = $_SI_BILLER->getBiller($invoice['biller_id']);
                        $customer = customer::get($invoice['customer_id']);
                        #print_r($customer);
                        #create PDF nameVj
                        $spc2us_pref = str_replace(" ", "_", $invoice['index_name']);
                        $pdf_file_name_invoice = $spc2us_pref.".pdf";
                            
                            
                        // email invoice
                        if( ($data[$key]['email_biller'] == "1") OR ($data[$key]['email_customer'] == "1") )
                        {
                            $export = new export();
                            $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 -> 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'];
                            if($data[$key]['email_customer'] == "1")
                            {
                                $email -> to = $customer['email'];
                            }
                            if($data[$key]['email_biller'] == "1" AND $data[$key]['email_customer'] == "1")
                            {
                                $email -> to = $customer['email'].";".$biller['email'];
                            }
                            if($data[$key]['email_biller'] == "1" AND $data[$key]['email_customer'] == "0")
                            {
                                $email -> to = $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->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->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( ($data[$key]['email_biller'] == "1") OR ($data[$key]['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 -> 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 -> 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'];
                                    if($data[$key]['email_customer'] == "1")
                                    {
                                        $email_rec -> to = $customer['email'];
                                    }
                                    if($data[$key]['email_biller'] == "1" AND $data[$key]['email_customer'] == "1")
                                    {
                                        $email_rec -> to = $customer['email'].";".$biller['email'];
                                    }
                                    if($data[$key]['email_biller'] == "1" AND $data[$key]['email_customer'] == "0")
                                    {
                                        $email_rec -> to = $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 below code
                                    */
                                    /*
                                    $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($data[$key]['email_customer'] == "1")
                                    {
                                        $email -> to = $customer['email'];
                                    }
                                    if($data[$key]['email_biller'] == "1" AND $data[$key]['email_customer'] == "1")
                                    {
                                        $email -> to = $customer['email'].";".$biller['email'];
                                    }
                                    if($data[$key]['email_biller'] == "1" AND $data[$key]['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 -> 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_'.$data[$key]['cron_id']] = "Cron ID: ". $data[$key]['cron_id'] ." NOT RUN: Cron for ".$data[$key]['index_name']." with start date of ".$data[$key]['start_date'].", end date of ".$data[$key]['end_date']." where it runs each ".$data[$key]['recurrence']." ".$data[$key]['recurrence_type']." did not recur today :: Info diff=".$diff;

                    }
            
                
                } else {		

                        //days diff is negaqtive - whats going on
                        $return['cron_message_'.$data[$key]['cron_id']] = "Cron ID: ". $data[$key]['cron_id'] ." NOT RUN: - Not cheduled for today - Cron for ".$data[$key]['index_name']." with start date of ".$data[$key]['start_date'].", end date of ".$data[$key]['end_date']." where it runs each ".$data[$key]['recurrence']." ".$data[$key]['recurrence_type']." did not recur today :: Info diff=".$diff;
                }
            } else {
                // cron has already been run for that cron_id toda
                   $return['cron_message_'.$data[$key]['cron_id']] = "Cron ID: ".$data[$key]['cron_id']." - Cron has already been run for domain: ".$domain_id." for the date: ".$today." for invoice ".$data[$key]['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;
        
    }
Exemple #21
0
<?php



if ($_POST['op'] =='edit' AND !empty($_POST['product_id']))
{
    $saved = "false";

	$inventory = new inventory();
	$inventory->id=$_GET['id'];
	$inventory->domain_id=domain_id::get();
	$inventory->product_id=$_POST['product_id'];
	$inventory->quantity=$_POST['quantity'];
	$inventory->cost=$_POST['cost'];
	$inventory->date=$_POST['date'];
	$inventory->note=$_POST['note'];
	$result = $inventory->update();

	$saved = !empty($result) ? "true" : "false";
}      

$invoices = new invoice();
$invoices->sort='id';
$invoice_all = $invoices->select_all('count');

$get_inventory = new inventory();
$get_inventory->id = $_GET['id'];
$inventory = $get_inventory->select();

$product_all = product::get_all();
$smarty -> assign('product_all',$product_all);
Exemple #22
0
    public function payment()
    {
    
        global $config;
        global $logger;
        
        $SI_BILLER = new SimpleInvoices_Db_Table_Biller();
        $SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();
        
        //set customer,biller and preference if not defined
        if(empty($this->customer))
        {
            $this->customer = customer::get($this->invoice['customer_id']);
        }
        if(empty($this->biller))
        {
            $this->biller = $SI_BILLER->getBiller($this->invoice['biller_id']);
        }
        if(empty($this->preference))
        {
            $this->preference = $SI_PREFERENCES->getPreferenceById($this->invoice['preference_id']);
        }

        $eway = new ewaylib($this->biller['eway_customer_id'],'REAL_TIME', false);

        //Eway only accepts amount in cents - so times 100
		$value = $this->invoice['total']*100;
		$eway_invoice_total = htmlsafe(trim($value));
        $logger->log("eway totla: " . $eway_invoice_total, Zend_Log::INFO);

        $enc = new encryption();
        $key = $config->encryption->default->key;	
        $credit_card_number = $enc->decrypt($key, $this->customer['credit_card_number']);

        $eway->setTransactionData("TotalAmount", $eway_invoice_total); //mandatory field
        $eway->setTransactionData("CustomerFirstName", $this->customer['name']);
    	$eway->setTransactionData("CustomerLastName", "");
        $eway->setTransactionData("CustomerAddress", "");
        $eway->setTransactionData("CustomerPostcode", "");
        $eway->setTransactionData("CustomerInvoiceDescription", "");
        $eway->setTransactionData("CustomerEmail", $this->customer['email']);
        $eway->setTransactionData("CustomerInvoiceRef", $this->invoice['index_name']);
        $eway->setTransactionData("CardHoldersName", $this->customer['credit_card_holder_name']); //mandatory field
        $eway->setTransactionData("CardNumber", $credit_card_number); //mandatory field
        $eway->setTransactionData("CardExpiryMonth", $this->customer['credit_card_expiry_month']); //mandatory field
        $eway->setTransactionData("CardExpiryYear", $this->customer['credit_card_expiry_year']); //mandatory field
        $eway->setTransactionData("Option1", "");
        $eway->setTransactionData("Option2", "");
        $eway->setTransactionData("Option3", "");
        $eway->setTransactionData("TrxnNumber", $this->invoice['id']);
        
        //special preferences for php Curl
        $eway->setCurlPreferences(CURLOPT_SSL_VERIFYPEER, 0);  //pass a long that is set to a zero value to stop curl from verifying the peer's certificate 
        $ewayResponseFields = $eway->doPayment();
        $this->message = $ewayResponseFields;
        $message ="";
        if($ewayResponseFields["EWAYTRXNSTATUS"]=="False"){
			$logger->log("Transaction Error: " . $ewayResponseFields["EWAYTRXNERROR"] . "<br>\n", Zend_Log::INFO);
            foreach($ewayResponseFields as $key => $value)
                $message .= "\n<br>\$ewayResponseFields[\"$key\"] = $value";
			$logger->log("Eway message: " . $message . "<br>\n", Zend_Log::INFO);
            //header("Location: trasnactionerrorpage.php");
            //exit();
            $return = 'false';		
        }else if($ewayResponseFields["EWAYTRXNSTATUS"]=="True"){


			$logger->log("Transaction Success: " . $ewayResponseFields["EWAYTRXNERROR"] . "<br>\n", Zend_Log::INFO);
            foreach($ewayResponseFields as $key => $value)
                $message .= "\n<br>\$ewayResponseFields[\"$key\"] = $value";
			$logger->log("Eway message: " . $message . "<br>\n", Zend_Log::INFO);
            //header("Location: trasnactionsuccess.php");
            //exit();
            $payment = new payment();
            $payment->ac_inv_id = $this->invoice['id'];
            #$payment->ac_inv_id = $_POST['invoice'];
            $payment->ac_amount = $this->invoice['total'];
            #$payment->ac_amount = $ewayResponseFields['EWAYRETURNAMOUNT']/100;
            #$payment->ac_amount = $_POST['mc_gross'];
            $payment->ac_notes = $message;
            $payment->ac_date = date( 'Y-m-d' );
            $payment->online_payment_id = $ewayResponseFields['EWAYTRXNNUMBER'];
            $payment->domain_id = domain_id::get($this->domain_id);

                $payment_type = new payment_type();
                $payment_type->type = "Eway";
                $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();
            #echo $db->lastInsertID();
            $return = 'true';		
        }

        return $return ;		
    }
Exemple #23
0
<?php

header("Content-type: text/xml");
$start = isset($_POST['start']) ? $_POST['start'] : "0";
$dir = isset($_POST['sortorder']) ? $_POST['sortorder'] : "ASC";
$sort = "id";
$rp = isset($_POST['rp']) ? $_POST['rp'] : "25";
$page = isset($_POST['page']) ? $_POST['page'] : "1";
$domain_id = domain_id::get();
$valid_search_fields = array('id', 'name', 'description');
$xml = "";
$extension_dir = './extensions';
$extension_entries = array_diff(scandir($extension_dir), array(".", ".."));
//Skip entries starting with a dot from dir list
$available_extensions = array();
foreach ($extension_entries as $entry) {
    if (file_exists($extension_dir . "/" . $entry . "/DESCRIPTION")) {
        $description = file_get_contents($extension_dir . "/" . $entry . "/DESCRIPTION");
    } else {
        $description = "DESCRIPTION not available (in {$extension_dir}/{$entry}/)";
    }
    $available_extensions[$entry] = array("name" => $entry, "enabled" => 0, "registered" => 0, "description" => $description, "id" => "");
}
//SC: Safety checking values that will be directly subbed in
if (intval($start) != $start) {
    $start = 0;
}
if (intval($rp) != $rp) {
    $rp = 25;
}
if (!preg_match('/^(asc|desc)$/iD', $dir)) {
    public function insert()
    {
        global $db;
        global $auth_session;

        $domain_id = domain_id::get($this->domain_id);
        
        $sql = "INSERT INTO ".TB_PREFIX."payment (
            ac_inv_id,
            ac_amount,
            ac_notes,
            ac_date,
            ac_payment_type,
            online_payment_id,
            domain_id
        ) VALUES (
            :ac_inv_id,
            :ac_amount,
            :ac_notes,
            :ac_date,
            :ac_payment_type,
            :online_payment_id,
            :domain_id
        )";
        $sth = $db->query($sql,
            ':ac_inv_id',$this->ac_inv_id,
            ':ac_amount',$this->ac_amount,
            ':ac_notes',$this->ac_notes,
            ':ac_date',$this->ac_date,
            ':ac_payment_type',$this->ac_payment_type,
            ':online_payment_id',$this->online_payment_id,
            ':domain_id',$domain_id 
        ) or die();
    
       return $sth;
    }
Exemple #25
0
<?php

/*
* Script: manage.php
* 	Manage Invoices page
*
* License:
*	 GPL v2 or above
*
* Website:
* 	http://www.simpleinvoices.org
*/
//stop the direct browsing to this file - let index.php handle which files get displayed
checkLogin();
$sql = "SELECT count(*) as count FROM " . TB_PREFIX . "cron where domain_id = :domain_id";
$sth = dbQuery($sql, ':domain_id', domain_id::get()) or die(htmlsafe(end($dbh->errorInfo())));
$number_of_crons = $sth->fetch(PDO::FETCH_ASSOC);
//all funky xml - sql stuff done in xml.php
//$smarty -> assign("invoices",$invoices);
$smarty->assign("number_of_crons", $number_of_crons);
$smarty->assign('pageActive', 'cron');
$smarty->assign('active_tab', '#money');
$url = 'index.php?module=cron&view=xml';
$smarty->assign('url', $url);
Exemple #26
0
/* 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']);
$defaults = getSystemDefaults();
$pt = getPaymentType($defaults['payment_type']);
$invoices = new invoice();
$invoices->sort = 'id';
$invoices->having = 'money_owed';
$invoices->having_and = 'real';
$invoice_all = $invoices->select_all('count');
$smarty->assign('invoice_all', $invoice_all);
$paymentTypes = getActivePaymentTypes();
Exemple #27
0
 public function __construct()
 {
     $this->domain_id = domain_id::get($this->domain_id);
 }
/**
* Function: show_custom_field
* 
* If a custom field has been defined then show it in the add,edit, or view invoice screen. This is used for the Invoice Custom Fields - may be used for the others as wll based on the situation
*
* Parameters:
* custom_field		- the db name of the custom field ie invoice_cf1
* custom_field_value	- the value of this custom field for a given invoice
* permission		- the permission level - ie. in a print view its gets a read level, in an edit or add screen its write leve
* css_class_tr		- the css class the the table row (tr)
* css_class1		- the css class of the first td
* css_class2		- the css class of the second td
* td_col_span		- the column span of the right td
* seperator		- used in the print view ie. adding a : between the 2 values
*
* Returns:
* Depending on the permission passed, either a formatted input box and the label of the custom field or a table row and data
**/
function show_custom_field($custom_field, $custom_field_value, $permission, $css_class_tr, $css_class1, $css_class2, $td_col_span, $seperator)
{
    $domain_id = domain_id::get();
    # get the last character of the $custom field - used to set the name of the field
    $custom_field_number = substr($custom_field, -1, 1);
    #get the label for the custom field
    $display_block = "";
    $get_custom_label = "SELECT cf_custom_label FROM " . TB_PREFIX . "custom_fields WHERE cf_custom_field = :field AND domain_id = :domain_id";
    $sth = dbQuery($get_custom_label, ':field', $custom_field, ':domain_id', $domain_id);
    while ($Array_cl = $sth->fetch()) {
        $has_custom_label_value = $Array_cl['cf_custom_label'];
    }
    /*if permision is write then coming from a new invoice screen show show only the custom field and have a label
     * if custom_field_value !null coming from existing invoice so show only the cf that they actually have
     */
    if ($has_custom_label_value != null and $permission == "write" or $custom_field_value != null) {
        $custom_label_value = htmlsafe(get_custom_field_label($custom_field));
        if ($permission == "read") {
            $display_block = <<<EOD
\t\t\t<tr class="{$css_class_tr}" >
\t\t\t\t<th class="{$css_class1}">
\t\t\t\t\t{$custom_label_value}{$seperator}
\t\t\t\t</th>
\t\t\t\t<td class="{$css_class2}" colspan="{$td_col_span}" >
\t\t\t\t\t{$custom_field_value}
\t\t\t\t</td>
\t\t\t</tr>
EOD;
        } else {
            if ($permission == "write") {
                $display_block = <<<EOD
\t\t\t<tr>
\t\t\t\t<th class="{$css_class1}">{$custom_label_value}
\t\t\t\t\t<a class="cluetip" href="#"\trel="index.php?module=documentation&amp;view=view&amp;page=help_custom_fields" title="Custom Fields"><img src="./images/common/help-small.png" alt="" /></a>
\t\t\t\t</th>
\t\t\t\t<td>
\t\t\t\t\t<input type="text" name="customField{$custom_field_number}" value="{$custom_field_value}" size="25" />
\t\t\t\t</td>
\t\t\t</tr>
EOD;
            }
        }
    }
    return $display_block;
}