public static function select($id) { global $logger; global $db; global $auth_session; $sql = "SELECT \n i.*,\n\t\t i.date as date_original, \n (SELECT CONCAT(p.pref_inv_wording,' ',i.index_id)) as index_name,\n p.pref_inv_wording AS preference,\n p.status\n FROM \n " . TB_PREFIX . "invoices i, \n " . TB_PREFIX . "preferences p \n WHERE \n i.domain_id = :domain_id \n and\n i.preference_id = p.pref_id\n and \n i.id = :id"; $sth = $db->query($sql, ':id', $id, ':domain_id', $auth_session->domain_id); $invoice = $sth->fetch(); $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date'])); $invoice['date'] = siLocal::date($invoice['date']); $invoice['total'] = getInvoiceTotal($invoice['id']); $invoice['gross'] = invoice::getInvoiceGross($invoice['id']); $invoice['paid'] = calc_invoice_paid($invoice['id']); $invoice['owing'] = $invoice['total'] - $invoice['paid']; $invoice['invoice_items'] = invoice::getInvoiceItems($id); #invoice total tax $sql2 = "SELECT SUM(tax_amount) AS total_tax, SUM(total) AS total FROM " . TB_PREFIX . "invoice_items WHERE invoice_id = :id"; $sth2 = dbQuery($sql2, ':id', $id) or die(htmlsafe(end($dbh->errorInfo()))); $result2 = $sth2->fetch(); //$invoice['total'] = number_format($result['total'],2); $invoice['total_tax'] = $result2['total_tax']; $invoice['tax_grouped'] = taxesGroupedForInvoice($id); return $invoice; }
* * Website: * http://www.simpleinvoices.or */ checkLogin(); #get the invoice id $invoice_id = $_GET['id']; $invoice = getInvoice($invoice_id); $invoice_number_of_taxes = numberOfTaxesForInvoice($invoice_id); $invoice_type = getInvoiceType($invoice['type_id']); $customer = getCustomer($invoice['customer_id']); $biller = getBiller($invoice['biller_id']); $preference = getPreference($invoice['preference_id']); $defaults = getSystemDefaults(); $invoiceobj = new invoice(); $invoiceItems = $invoiceobj->getInvoiceItems($invoice_id); $eway_check = new eway(); $eway_check->invoice = $invoice; $eway_pre_check = $eway_check->pre_check(); #Invoice Age - number of days - start if ($invoice['owing'] > 0) { $invoice_age_days = number_format((strtotime(date('Y-m-d')) - strtotime($invoice['calc_date'])) / (60 * 60 * 24), 0); $invoice_age = "{$invoice_age_days} {$LANG['days']}"; } else { $invoice_age = ""; } $url_for_pdf = "./index.php?module=export&view=pdf&id=" . $invoice['id']; $invoice['url_for_pdf'] = $url_for_pdf; $customFieldLabels = getCustomFieldLabels(); for ($i = 1; $i <= 4; $i++) { $customField[$i] = show_custom_field("invoice_cf{$i}", $invoice["custom_field{$i}"], "read", 'summary', '', '', 5, ':');
* Script: details.php * invoice details page * * License: * GPL v3 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 $master_invoice_id = $_GET['id']; $invoice = getInvoice($master_invoice_id); $invoiceItems = invoice::getInvoiceItems($master_invoice_id); //var_dump($invoiceItems); $customers = getActiveCustomers(); $preference = getPreference($invoice['preference_id']); $billers = getActiveBillers(); //$taxes = getActiveTaxes(); <--- look into this $defaults = getSystemDefaults(); $taxes = getTaxes(); $preferences = getActivePreferences(); $products = getActiveProducts(); for ($i = 1; $i <= 4; $i++) { $customFields[$i] = show_custom_field("invoice_cf{$i}", $invoice["custom_field{$i}"], "write", '', "details_screen", '', '', ''); } $smarty->assign("invoice", $invoice); $smarty->assign("defaults", $defaults); $smarty->assign("invoiceItems", $invoiceItems);
$invoiceItems = invoice::getInvoiceItems($invoice_id); $smarty->assign("invoice", $invoice); $smarty->assign("preference", $preference); $smarty->assign("defaults", $defaults); $smarty->assign("invoicePaid", $invoicePaid); $smarty->assign("invoiceItems", $invoiceItems); /*If delete is disabled - dont allow people to view this page*/ if ($defaults['delete'] == 'N') { die('Invoice deletion has been disabled, you are not supposed to be here'); } if ($_GET['stage'] == 2 and $_POST['doDelete'] == 'y') { global $dbh; $dbh->beginTransaction(); $error = false; //delete line item taxes $invoice_line_items = invoice::getInvoiceItems($invoice_id); foreach ($invoice_line_items as $key => $value) { //echo "line item id: ".$invoice_line_items[$key]['id']."<br />"; delete('invoice_item_tax', 'invoice_item_id', $invoice_line_items[$key]['id']); } // Start by deleting the line items if (!delete('invoice_items', 'invoice_id', $invoice_id)) { $error = true; } //delete products from producsts table for total style if ($invoice['type_id'] == 1) { if ($error || !delete('products', 'id', $invoiceItems['0']['product']['id'])) { $error = true; } } //delete the info from the invoice table
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; }
* invoice details page * * License: * GPL v3 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 $master_invoice_id = $_GET['id']; $invoice = getInvoice($master_invoice_id); $invoiceobj = new invoice(); $invoiceItems = $invoiceobj->getInvoiceItems($master_invoice_id); //var_dump($invoiceItems); $customers = getActiveCustomers(); $preference = getPreference($invoice['preference_id']); $billers = getActiveBillers(); //$taxes = getActiveTaxes(); <--- look into this $defaults = getSystemDefaults(); $taxes = getTaxes(); $preferences = getActivePreferences(); $products = getActiveProducts(); for ($i = 1; $i <= 4; $i++) { $customFields[$i] = show_custom_field("invoice_cf{$i}", $invoice["custom_field{$i}"], "write", '', "details_screen", '', '', ''); } foreach ($invoiceItems as $key => $value) { //get list of attributes $prod = getProduct($value['product_id']);
} $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(); $preferences = $SI_PREFERENCES->fetchAllActive(); $products = $SI_PRODUCTS->findActive(); $invoice_array = $invoice->toArray(); for($i=1;$i<=4;$i++) { $customFields[$i] = show_custom_field("invoice_cf$i",$invoice_array["custom_field$i"],"write",'',"details_screen",'','',''); }
function getData() { //echo "export - get data"; global $smarty; global $siUrl; switch ($this->module) { case "statement": $invoice = new invoice(); $invoice->biller = $this->biller_id; $invoice->customer = $this->customer_id; if ($this->filter_by_date == "yes") { if (isset($this->start_date)) { $invoice->start_date = $this->start_date; } if (isset($this->end_date)) { $invoice->end_date = $this->end_date; } if (isset($this->start_date) and isset($this->end_date)) { $invoice->having = "date_between"; } $having_count = 1; } if ($this->show_only_unpaid == "yes") { if ($having_count == 1) { $invoice->having_and = "money_owed"; } else { $invoice->having = "money_owed"; } } $invoice_all = $invoice->select_all('count'); $invoices = $invoice_all->fetchAll(); foreach ($invoices as $i => $row) { $statement['total'] = $statement['total'] + $row['invoice_total']; $statement['owing'] = $statement['owing'] + $row['owing']; $statement['paid'] = $statement['paid'] + $row['INV_PAID']; } $templatePath = "./templates/default/statement/index.tpl"; $biller_details = getBiller($this->biller_id); $customer_details = getCustomer($this->customer_id); $this->file_name = "statement_" . $this->biller_id . "_" . $this->customer_id . "_" . $invoice->start_date . "_" . $invoice->end_date; $smarty->assign('biller_id', $biller_id); $smarty->assign('biller_details', $biller_details); $smarty->assign('customer_id', $customer_id); $smarty->assign('customer_details', $customer_details); $smarty->assign('show_only_unpaid', $show_only_unpaid); $smarty->assign('filter_by_date', $this->filter_by_date); $smarty->assign('invoices', $invoices); $smarty->assign('start_date', $this->start_date); $smarty->assign('end_date', $this->end_date); $smarty->assign('invoices', $invoices); $smarty->assign('statement', $statement); $data = $smarty->fetch("." . $templatePath); break; case "payment": $payment = getPayment($this->id); /*Code to get the Invoice preference - so can link from this screen back to the invoice - START */ $invoice = getInvoice($payment['ac_inv_id']); $biller = getBiller($payment['biller_id']); $logo = getLogo($biller); $logo = str_replace(" ", "%20", $logo); $customer = getCustomer($payment['customer_id']); $invoiceType = getInvoiceType($invoice['type_id']); $customFieldLabels = getCustomFieldLabels(); $paymentType = getPaymentType($payment['ac_payment_type']); $preference = getPreference($invoice['preference_id']); $smarty->assign("payment", $payment); $smarty->assign("invoice", $invoice); $smarty->assign("biller", $biller); $smarty->assign("logo", $logo); $smarty->assign("customer", $customer); $smarty->assign("invoiceType", $invoiceType); $smarty->assign("paymentType", $paymentType); $smarty->assign("preference", $preference); $smarty->assign("customFieldLabels", $customFieldLabels); $smarty->assign('pageActive', 'payment'); $smarty->assign('active_tab', '#money'); $css = $siUrl . "/templates/invoices/default/style.css"; $smarty->assign('css', $css); $templatePath = "./templates/default/payments/print.tpl"; $data = $smarty->fetch("." . $templatePath); break; case "invoice": $invoice = invoice::select($this->id); $invoice_number_of_taxes = numberOfTaxesForInvoice($this->id); $customer = getCustomer($invoice['customer_id']); $biller = biller::select($invoice['biller_id']); $preference = getPreference($invoice['preference_id']); $defaults = getSystemDefaults(); $logo = getLogo($biller); $logo = str_replace(" ", "%20", $logo); $invoiceItems = invoice::getInvoiceItems($this->id); $spc2us_pref = str_replace(" ", "_", $invoice['index_name']); $this->file_name = $spc2us_pref; $customFieldLabels = getCustomFieldLabels(); /*Set the template to the default*/ $template = $defaults['template']; $templatePath = "./templates/invoices/{$template}/template.tpl"; $template_path = "../templates/invoices/{$template}"; $css = $siUrl . "/templates/invoices/{$template}/style.css"; $pluginsdir = "./templates/invoices/{$template}/plugins/"; //$smarty = new Smarty(); $smarty->plugins_dir = $pluginsdir; $pageActive = "invoices"; $smarty->assign('pageActive', $pageActive); if (file_exists($templatePath)) { //echo "test"; $smarty->assign('biller', $biller); $smarty->assign('customer', $customer); $smarty->assign('invoice', $invoice); $smarty->assign('invoice_number_of_taxes', $invoice_number_of_taxes); $smarty->assign('preference', $preference); $smarty->assign('logo', $logo); $smarty->assign('template', $template); $smarty->assign('invoiceItems', $invoiceItems); $smarty->assign('template_path', $template_path); $smarty->assign('css', $css); $smarty->assign('customFieldLabels', $customFieldLabels); $data = $smarty->fetch("." . $templatePath); } break; } return $data; }