'doList', 'cancel' => 'doBack', 'back' => 'doBack', 'edit' => 'doEdit', 'update' => 'doUpdate', 'del' => 'doDelete', 'view' => 'doView', ); function App_Invoice_Admin_AbstractView($options) { $this->_options = $options; } function getTemplate($template) { return SiteMap::getPath($this->_templatePath . '/' . $template); } function _doListBindCommon(&$DB_List) { $DB_List->insertColLast( 'date_sent', array( 'title' => 'Date Sent', 'order_by' => 'date_sent', 'tpl' => DB_LIST_CELL_DATE, 'params' => array('date_sent'), ) ); $DB_List->insertColLast( 'number', array( 'title' => 'Invoice #', 'order_by' => 'number', 'tpl' => DB_LIST_CELL_TEXT_CENTER, 'params' => array('number'), ) ); $DB_List->insertColLast( 'date_due', array( 'title' => 'Date Due', 'order_by' => 'date_due', 'tpl' => DB_LIST_CELL_DATE, 'params' => array('date_due'), ) ); $DB_List->insertColLast( 'overdue', array( 'title' => 'Overdue', 'order_by' => 'overdue', 'tpl' => SiteMap::getPath('Invoice/tpl/Admin/cells/overdue.tpl'), 'params' => array('overdue'), ) ); $DB_List->insertColLast( 'paid', array( 'title' => 'Payment Status', 'order_by' => 'paid', 'tpl' => SiteMap::getPath('Invoice/tpl/Admin/cells/paid.tpl'), 'params' => array('paid'), ) ); $DB_List->insertColLast( 'amount', array( 'title' => 'Amount', 'order_by' => 'amount', 'tpl' => DB_LIST_CELL_MONEY, 'params' => array('amount'), ) ); $DB_List->insertColLast( 'sent', array( 'title' => 'Green Invoice Sent', 'order_by' => 'sent', 'tpl' => SiteMap::getPath('Invoice/tpl/Admin/cells/green-invoice-sent.tpl'), 'values' => array('y' => 'Yes', 'n' => 'No'), 'params' => array('sent'), ) ); $DB_List->insertColLast( 'options', array( 'title' => 'Options', 'tpl' => SiteMap::getPath('Invoice/tpl/Admin/cells/options.tpl'), 'params' => array('id'), ) ); $DB_List->bind(); } function doList() { $filterForm = $this->getFilterForm(); if ($filterForm->validate()) { $this->DBObj->addFilter($filterForm->exportValues()); } $item = array(); $this->_initInfoBlock($item); $item['total_amount_due'] = $this->DBObj->getTotalAmountDue(); $item['amount_overdue'] = $this->DBObj->getAmountOverdue(); $item['filterForm'] = $filterForm->exec(); $item['tpl'] = $this->getTemplate('info.tpl'); $this->Doc->addContent($item); parent::doList(); } function addLink() { if (!$this->DBObj->getObjectData()) { return false; } $links = array( 'tpl' => 'center_link.tpl', 'link_list' => array() ); $links['link_list'][] = array( 'link' => Constant::get('BASE_URL') . '/'. CURR_PAGE, 'title' => 'Show invoices for all ' . $this->DBObj->ownersName ); $this->Doc->addContent($links); } function getFilterForm() { $form = $this->_getBaseForm('get'); $form->setRendType(FORM_RENDERER_ARRAY_SMARTY); $form->return_form_arr = true; $form->addElement('text', 'query', 'Search', array('size' => '45', 'class' => 'digit')); $form->addElement( 'select', 'paid', 'Filter by Payment Status', array('' => 'All', 'n' => 'Not Received', 'y' => 'Received'), array('onchange' => 'this.form.submit()') ); $form->addElement('submit', 'btnSubmit', 'Search', array('class' => 'btn')); $form->addElement( 'button', 'btnCancel', 'Reset', array( 'class' => 'btn', 'onclick' => "document.location.href = '" . Constant::get('BASE_URL') . '/' . CURR_PAGE_FULL . "'" ) ); return $form; } function _bindFormFields($form) { $form->cancelUrl = BASE_URL . '/' . CURR_PAGE_FULL . '?action=cancel'; $form->addElement('text', 'number', 'Invoice #', array('size' => '23', 'class' => 'digit')); $dateSent = $form->addElement('calendar', 'date_sent', 'Date Invoice Sent'); $dateSent->_options['addEmptyOption'] = true; $dateSent->_options['minYear'] = date('Y') - 10; $dateSent->_options['maxYear'] = date('Y') + 5; $dateDue = $form->addElement('calendar', 'date_due', 'Date Invoice Due'); $dateDue->_options['addEmptyOption'] = true; $dateDue->_options['minYear'] = date('Y') - 10; $dateDue->_options['maxYear'] = date('Y') + 5; $form->addElement('text', 'amount', 'Amount', array('size' => '23', 'class' => 'digit')); $form->addElement('select', 'paid', 'Payment', array('n' => 'Not Received', 'y' => 'Received')); $form->addElement('advcheckbox', 'send_email', 'Send invoice via e-mail', '', array(), array('n', 'y')); $form->addElement('static', 'attachment', 'Attach invoice (pdf file)'); // Rules $form->addRuleRequired(array('number', 'date_sent', 'date_due', 'amount')); $form->addRuleEx(array('number'), ' is in wrong format', 'regex', $this->_numberRegex); $form->addRuleEx(array('amount'), ' is in wrong format', 'numeric'); $form->addFormRule(array($this, 'validateForm')); return $form; } function validateForm($data, $files) { $errors = array(); if (!$this->DBObj->isUnique('number', $data['number'])) { $errors['number'] = 'Invoice # must be unique'; } if ($data['amount'] <= 0) { $errors['amount'] = 'Amount must be higer than zero'; } return (empty($errors)) ? true : $errors; } function postUpdate() { $this->postSave(); } function postInsert() { $this->postSave(); } function postSave() {} function _sendMail2Member($data) { Constant::set('DEBUG', false); $this->Doc->assign('item', $data); $html = $this->Doc->fetch(SiteMap::getPath('Invoice/tpl/Admin/mail2member.tpl')); require_once('lib/htmlMimeMail/htmlMimeMail.php'); $mail = new htmlMimeMail(); $mail->setHtml($html); $attachment = WWW_PATH . '/userfile/' . $data['attachment']; if (file_exists($attachment)) { $mail->addAttachment(file_get_contents($attachment), 'Invoice.pdf', 'application/pdf'); } $mail->setReturnPath('no-reply@mncar.org'); require_once('app/Settings/Settings.php'); $mail->setFrom(Settings::get('admin_email_from')); $mail->setSubject('You have received a new invoice from MNCAR.ORG'); $mail->setHeader('X-Mailer', 'HTML Mime mail class'); $result = $mail->send(array($data['member']['email'])); return $result; } function doView() { $this->DBObj->initFromDB(); $item = $this->DBObj->getData(); $item['tpl'] = SiteMap::getPath('Invoice/tpl/Admin/view.tpl'); $this->Doc->addContent($item); } function doEdit() { $this->DBObj->initFromDB(); $form = $this->_getEditForm(); $data = $this->DBObj->getData(); $data['attachment'] = 'download'; if (false === strtotime($data['date_sent'])) { unset($data['date_sent']); } if (false === strtotime($data['date_due'])) { unset($data['date_due']); } //vdie($data); $form->setDefaults($data); $this->renderForm($form); } }