'_doForm', 'cancel' => 'doBack', 'report' => '_doReport', 'save' => '_doSave', ); public function ExchangeDuesReportGrid($Doc, $DBObj) { parent::DB_Grid(&$Doc, &$DBObj); } protected function _getForm() { $form = $this->_getBaseForm(); $items = $this->DBObj->getList4Grid(array('order_by' => 'sorter')); foreach ($items['list'] as $item) { $form->addElement('text', 'price[' . $item['id'] . ']', '$'); } $form->action = CURR_PAGE; $form->addElement('hidden', 'action', 'save') ; return $form; } protected function _getReportForm() { $form = $this->_getBaseForm(); $form->addElement('text', 'format', 'Invoice Format'); $form->addElement('text', 'date', 'Invoice Date'); $form->addElement('text', 'batch_id', 'Batch ID'); $form->addElement('text', 'site_id', 'Site ID'); $form->addRuleRequired(array('format', 'date', 'site_id')); $form->action = CURR_PAGE; $form->addElement('hidden', 'action', 'report') ; return $form; } protected function _doForm() { $form = $this->_getForm(); $this->DBObj->initFromDB(); $form->setDefaults($this->DBObj->getData()); $form->return_form_arr = true; $item['itemform'] = $form->_execRendArrSmarty(); $item['itemlist'] = $this->DBObj->getList4Grid(array('order_by' => 'sorter')); $reportForm = $this->_getReportForm(); $reportForm->return_form_arr = true; $item['reportform'] = $reportForm->_execRendArrSmarty(); $item['tpl'] = 'ExchangeDuesReport/form.tpl'; $this->Doc->addContent($item); } protected function _doSave() { $form = $this->_getForm(); $this->DBObj->update($form->exportValues()); Session::setData($this->_getPage4SaveMessage(), 'msg', 'Items updated'); $this->doBack(); } protected function _doReport() { $reportForm = $this->_getReportForm(); $values = $reportForm->exportValues(); $result = $this->DBObj->getReportDbResult(); $columns = array( 'nrds_id' => 'Customer ID', 'pay_member' => 'Billing Person', 'first_name' => 'First Name', 'last_name' => 'Last Name', 'number' => 'Item Code', 'description' => 'Description', 'quantity' => 'Quantity', 'unit_price' => 'Unit Price', 'total' => 'Subtotal', 'physical_address' => 'Address', 'physical_city' => 'City', 'physical_state' => 'State', 'physical_zip' => 'Zip', 'location_name' => 'Location Name', 'company_name' => 'Company Name', 'contact_name' => 'Contact Name', 'invoice_format' => 'Invoice Format', 'invoice_data' => 'Invoice Data', 'batch_id' => 'Batch ID', 'site_id' => 'Site ID', ); header ("Content-type: text/comma-separated-values"); header('Content-disposition: attachment; filename=exchange_dues_report.csv'); $fp = fopen('php://output', 'w'); fputcsv($fp, $columns); $blankRow = array_combine(array_keys($columns), array_fill(0, count($columns), '')); $blankRow['invoice_format'] = strtoupper($values['format']); $blankRow['invoice_data'] = $values['date']; $blankRow['site_id'] = strtoupper($values['site_id']); while ($row = $result->fetchRow()) { $data = array_merge($blankRow, array_intersect_key($row, $columns)); /*if ($row['number'] == 'OFFICE') { $data['batch_id'] = 'LargeCompany'; } elseif (strpos($row['number'], 'STCLOUD')) { $data['batch_id'] = 'StCloud'; } elseif (strpos($row['number'], 'ROCHESTER')) { $data['batch_id'] = 'Rochester'; } else { $data['batch_id'] = 'TwinCities'; } if ('y' == $row['billing_send_paper_copy']) { $data['batch_id'] .= '-G'; }*/ fputcsv($fp, $data); } fclose($fp); die(); } }