/**
  * Get a system default value
  * 
  * @param mixed $name
  * @return mixed
  */
 public function findByName($name)
 {
     switch ($name) {
         case 'biller':
             $SI_BILLER = new SimpleInvoices_Db_Table_Biller();
             return $SI_BILLER->getDefault();
             break;
         case 'customer':
             $SI_CUSTOMERS = new SimpleInvoices_Db_Table_Customers();
             return $SI_CUSTOMERS->getDefault();
             break;
         case 'payment_type':
             $SI_PAYMENT_TYPES = new SimpleInvoices_Db_Table_PaymentTypes();
             return $SI_PAYMENT_TYPES->getDefault();
             break;
         case 'preference':
             $SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();
             return $SI_PREFERENCES->getDefault();
             break;
         case 'tax':
             $SI_TAX = new SimpleInvoices_Db_Table_Tax();
             return $SI_TAX->getDefault();
             break;
         default:
             $auth_session = Zend_Registry::get('auth_session');
             $select = $this->select();
             $select->where('name = ?', $name);
             $select->where('domain_id = ?', $auth_session->domain_id);
             $result = $this->getAdapter()->fetchRow($select);
             return $result['value'];
             break;
     }
 }
 /**
  * Insert an Invoice
  * 
  * ToDo: missing check foreign keys
  * 
  * @see lib/Zend/Db/Table/Zend_Db_Table_Abstract::insert()
  */
 public function insert($data)
 {
     $SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();
     $pref_group = $SI_PREFERENCES->getPreferenceById($_POST['preference_id']);
     $auth_session = Zend_Registry::get('auth_session');
     $data['domain_id'] = $auth_session->domain_id;
     $data['index_id'] = SimpleInvoices_Db_Table_Index::NEXT('invoice', $pref_group['index_group']);
     $result = parent::insert($data);
     $this->_last_inserted_id = $this->getAdapter()->lastInsertId($this->_name, 'id');
     // Increment Index if inserted
     if ($result) {
         SimpleInvoices_Db_Table_Index::INCREMENT('invoice', $pref_group['index_group']);
     }
     return $result;
 }
Example #3
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_PAYMENT_TYPES = new SimpleInvoices_Db_Table_PaymentTypes();
$SI_CUSTOMERS = new SimpleInvoices_Db_Table_Customers();
$SI_TAX = new SimpleInvoices_Db_Table_Tax();
$SI_BILLER = new SimpleInvoices_Db_Table_Biller();
$SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();

#system defaults query

$defaults = $SI_SYSTEM_DEFAULTS->fetchAll();

if ($_GET["submit"] == "line_items") {

	jsBegin();
	jsFormValidationBegin("frmpost");
	jsValidateifNum("def_num_line_items","Default number of line items");
	jsFormValidationEnd();
	jsEnd();

	$default = "line_items";

	$escaped = htmlsafe($defaults[line_items]);
	$value = <<<EOD
<input type="text" size="25" name="value" value="$escaped">
EOD;
	$description = "{$LANG['default_number_items']}";
Example #4
0
*
* 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();

$SI_PRODUCTS = new SimpleInvoices_Db_Table_Products();
$SI_SYSTEM_DEFAULTS = new SimpleInvoices_Db_Table_SystemDefaults();
$SI_CUSTOMERS = new SimpleInvoices_Db_Table_Customers();
$SI_TAX = new SimpleInvoices_Db_Table_Tax();
$SI_BILLER = new SimpleInvoices_Db_Table_Biller();
$SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();

$billers = $SI_BILLER->fetchAllActive();
$customers = $SI_CUSTOMERS->fetchAllActive();
$taxes = $SI_TAX->fetchAllActive();
$products = $SI_PRODUCTS->findActive();
$preferences = $SI_PREFERENCES->fetchAllActive();
$defaults = $SI_SYSTEM_DEFAULTS->fetchAll();


$defaultBiller = $SI_BILLER->getDefault();
$defaultCustomerID = (isset($_GET['customer_id'])) ? $_GET['customer_id'] : $SI_CUSTOMERS->getDefault();
$defaultTax = $SI_TAX->getDefault();
$defaultPreference = $SI_PREFERENCES->getDefault();

if (!empty( $_GET['get_num_line_items'] )) {
Example #5
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;
        
    }
Example #6
0
 public function getPreference()
 {
     $preferences = new SimpleInvoices_Db_Table_Preferences();
     return $preferences->getPreferenceById($this->_data['preference_id']);
 }
Example #7
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;

	}
Example #8
0
	public function insert()
	{
		//insert in si)invoice

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

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

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

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

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

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

		//insert into

	}
Example #9
0
<?php

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

//gets the long language name out of the short name
$SI_SYSTEM_DEFAULTS = new SimpleInvoices_Db_Table_SystemDefaults();
$SI_PAYMENT_TYPES = new SimpleInvoices_Db_Table_PaymentTypes();
$SI_CUSTOMERS = new SimpleInvoices_Db_Table_Customers();
$SI_BILLER = new SimpleInvoices_Db_Table_Biller();
$SI_TAX = new SimpleInvoices_Db_Table_Tax();
$SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();

$lang = $SI_SYSTEM_DEFAULTS->findByName('language');
$languages = getLanguageList($include_dir . 'sys/lang/');
foreach($languages as $language) {
	if($language->shortname == $lang) {
		$lang = $language->name;
		break;
	}
}

// Default delete
$defaults['delete'] = $system_defaults->findByName('delete');
$defaults['delete'] = $defaults['delete']==1?$LANG['enabled']:$LANG['disabled'];

// Default Logging
$defaults['logging'] = $system_defaults->findByName('logging');
$defaults['logging'] = $defaults['logging']==1?$LANG['enabled']:$LANG['disabled'];

// Default inventory
Example #10
0
 */
#table

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

if(!isset($_GET['id'])) {
	throw new SimpleInvoices_Exception('Invalid invoice identifier');
}

$SI_PRODUCTS = new SimpleInvoices_Db_Table_Products();
$SI_SYSTEM_DEFAULTS = new SimpleInvoices_Db_Table_SystemDefaults();
$SI_TAX = new SimpleInvoices_Db_Table_Tax();
$SI_CUSTOMERS = new SimpleInvoices_Db_Table_Customers();
$SI_BILLER = new SimpleInvoices_Db_Table_Biller();
$SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();

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

$invoice = new SimpleInvoices_Invoice($_GET['id']);

//$invoice = getInvoice($master_invoice_id);
$invoiceItems = invoice::getInvoiceItems($invoice->getId());
//var_dump($invoiceItems);
$customers = $SI_CUSTOMERS->fetchAllActive();
$preference = $invoice->getPreference();
$billers = $SI_BILLER->fetchAllActive();
//$taxes = $SI_TAX->fetchAllActive();
$defaults = $SI_SYSTEM_DEFAULTS->fetchAll();
$taxes = $SI_TAX->fetchAll();
Example #11
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 ;		
    }
* 	 2008-01-03
*
* License:
*	 GPL v2 or above
*	 
* Website:
* 	http://www.simpleinvoices.or
 */

checkLogin();

$SI_SYSTEM_DEFAULTS = new SimpleInvoices_Db_Table_SystemDefaults();
$SI_CUSTOMERS = new SimpleInvoices_Db_Table_Customers();
$SI_INVOICE_TYPE = new SimpleInvoices_Db_Table_InvoiceType();
$SI_BILLER = new SimpleInvoices_Db_Table_Biller();
$SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();
$SI_CUSTOM_FIELDS = new SimpleInvoices_Db_Table_CustomFields();

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


$invoice = getInvoice($invoice_id);
$invoice_type = $SI_INVOICE_TYPE->getInvoiceType($invoice['type_id']);
$customer = $SI_CUSTOMERS->getCustomerById($invoice['customer_id']);
$biller = $SI_BILLER->getBiller($invoice['biller_id']);
$preference = $SI_PREFERENCES->getPreferenceById($invoice['preference_id']);
$defaults = $SI_SYSTEM_DEFAULTS->fetchAll();
$invoiceItems = matrix_invoice::getInvoiceItems($invoice_id);

#Invoice Age - number of days - start
Example #13
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_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();

//if valid then do save
if ($_POST['p_description'] != "" ) {
	include("sys/modules/preferences/save.php");
}

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

$preference = $SI_PREFERENCES->getPreferenceById($preference_id);
$index_group = $SI_PREFERENCES->getPreferenceById($preference['index_group']);

$preferences = $SI_PREFERENCES->fetchAllActive();
$defaults = $SI_SYSTEM_DEFAULTS->fetchAll();
$status = array(array('id'=>'0','status'=>$LANG['draft']), array('id'=>'1','status'=>$LANG['real']));

$smarty->assign('preference',$preference);
$smarty->assign('defaults',$defaults);
$smarty->assign('index_group',$index_group);
$smarty->assign('preferences',$preferences);
$smarty->assign('status',$status);

$smarty -> assign('pageActive', 'preference');
$subPageActive = $_GET['action'] =="view"  ? "preferences_view" : "preferences_edit" ;
$smarty -> assign('subPageActive', $subPageActive);
Example #14
0
* 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
$master_invoice_id = $_GET['invoice'];

$SI_PRODUCTS = new SimpleInvoices_Db_Table_Products();
$SI_CUSTOMERS = new SimpleInvoices_Db_Table_Customers();
$SI_TAX = new SimpleInvoices_Db_Table_Tax();
$SI_BILLER = new SimpleInvoices_Db_Table_Biller();
$SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();

$invoice = getInvoice($master_invoice_id);
$invoiceItems = matrix_invoice::getInvoiceItems($master_invoice_id);
$customers = $SI_CUSTOMERS->fetchAllActive();
$preference = $SI_PREFERENCES->getPreferenceById($invoice['preference_id']);
$billers = $SI_BILLER->fetchAllActive();
$taxes = $SI_TAX->fetchAllActive();
$preferences = $SI_PREFERENCES->fetchAllActive();
$products = $SI_PRODUCTS->findActive();


for($i=1;$i<=4;$i++) {
	$customFields[$i] = show_custom_field("invoice_cf$i",$invoice["custom_field$i"],"write",'',"details_screen",'','','');
}
Example #15
0
<?php

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

$SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();

$preferences = $SI_PREFERENCES->fetchAll();

$smarty -> assign("preferences",$preferences);

$smarty -> assign('pageActive', 'preference');
$smarty -> assign('active_tab', '#setting');
?>
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
		);
}