Created
November 1, 2018 02:17
-
-
Save FredAzevedo/f85035dfedff99167077c87835ac09a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ContaPagarList Listing | |
* @author Fred Az. | |
*/ | |
class ContaPagarList extends TStandardList | |
{ | |
protected $form; // registration form | |
protected $datagrid; // listing | |
protected $pageNavigation; | |
protected $transformCallback; | |
protected $formGrid; | |
public function __construct() | |
{ | |
parent::__construct(); | |
parent::setDatabase('sample'); // defines the database | |
parent::setActiveRecord('ContaPagar'); // defines the active record | |
parent::setDefaultOrder('id', 'desc'); // defines the default order | |
parent::addFilterField('descricao', 'like'); // add a filter field | |
parent::setTransformer( array($this, 'onReload') ); | |
// creates the form | |
$this->form = new TQuickForm('form_search_ContaPagar'); | |
$this->form->class = 'tform'; // change CSS class | |
$this->form = new BootstrapFormWrapper($this->form); | |
$this->form->style = 'display: table;width:100%'; // change style | |
$this->form->setFormTitle('ContasPagar'); | |
$criteria = new TCriteria; | |
$criteria->add(new TFilter('unit_id', '= ', TSession::getValue('userunitid'))); | |
$criteria->add(new TFilter('baixa', '= ', 'N')); | |
parent::setCriteria($criteria); | |
parent::addFilterField('descricao', 'like', 'descricao'); | |
$description = new TEntry('descricao'); | |
$this->form->addQuickField('Descrição', $description, '100%'); | |
$this->form->setData( TSession::getValue('ContaPagar_filter_data') ); | |
// add the search form actions | |
$btn = $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search'); | |
$btn->class = 'btn btn-sm btn-primary'; | |
$btn = $this->form->addQuickAction(_t('New'), new TAction(array('ContaPagarForm', 'onEdit')), 'bs:plus-sign green'); | |
$btnBaixar = $this->form->addQuickAction('Baixar', new TAction(array($this, 'onSave')), 'fa:arrow-circle-down'); | |
// creates a DataGrid | |
$this->datagrid = new TDataGrid; | |
$this->datagrid->disableDefaultClick(); | |
$this->datagrid = new BootstrapDatagridWrapper($this->datagrid); | |
$this->datagrid->style = 'width: 100%'; | |
$this->datagrid->datatable = 'true'; | |
// $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>'); | |
// form grid | |
$this->formGrid = new TForm; | |
$this->formGrid->add($this->datagrid); | |
$this->formGrid->addField($btnBaixar); | |
// creates the datagrid columns | |
$column_check = new TDataGridColumn('checkbox', ' ', 'center'); | |
$column_id = new TDataGridColumn('id', 'ID', 'right'); | |
$column_data_conta = new TDataGridColumn('data_conta', 'Data Conta', 'center'); | |
$column_descricao = new TDataGridColumn('descricao', 'Descrição', 'left'); | |
$column_documento = new TDataGridColumn('documento', 'Documento', 'left'); | |
$column_data_vencimento = new TDataGridColumn('data_vencimento', 'Vencimento', 'center'); | |
$column_valor = new TDataGridColumn('valor', 'Valor', 'right'); | |
// add the columns to the DataGrid | |
$this->datagrid->addColumn($column_check); | |
$this->datagrid->addColumn($column_id); | |
$this->datagrid->addColumn($column_data_conta); | |
$this->datagrid->addColumn($column_descricao); | |
$this->datagrid->addColumn($column_documento); | |
$this->datagrid->addColumn($column_data_vencimento); | |
$this->datagrid->addColumn($column_valor); | |
// creates the datagrid column actions | |
$order_id = new TAction(array($this, 'onReload')); | |
$order_id->setParameter('order', 'id'); | |
$column_id->setAction($order_id); | |
$order_data_conta = new TAction(array($this, 'onReload')); | |
$order_data_conta->setParameter('order', 'data_conta'); | |
$column_data_conta->setAction($order_data_conta); | |
$order_data_vencimento = new TAction(array($this, 'onReload')); | |
$order_data_vencimento->setParameter('order', 'data_vencimento'); | |
$column_data_vencimento->setAction($order_data_vencimento); | |
$order_valor = new TAction(array($this, 'onReload')); | |
$order_valor->setParameter('order', 'valor'); | |
$column_valor->setAction($order_valor); | |
// define the transformer method over image | |
$column_data_conta->setTransformer( function($value, $object, $row) { | |
$date = new DateTime($value); | |
return $date->format('d/m/Y'); | |
}); | |
// define the transformer method over image | |
$column_data_vencimento->setTransformer( function($value, $object, $row) { | |
$date = new DateTime($value); | |
return $date->format('d/m/Y'); | |
}); | |
// define the transformer method over image | |
$column_valor->setTransformer( function($value, $object, $row) { | |
return 'R$ ' . number_format($value, 2, ',', '.'); | |
}); | |
// create EDIT action | |
$action_edit = new TDataGridAction(array('ContaPagarForm', 'onEdit')); | |
//$action_edit->setUseButton(TRUE); | |
//$action_edit->setButtonClass('btn btn-default'); | |
$action_edit->setLabel(_t('Edit')); | |
$action_edit->setImage('fa:pencil-square-o blue fa-lg'); | |
$action_edit->setField('id'); | |
$this->datagrid->addAction($action_edit); | |
// create DELETE action | |
$action_del = new TDataGridAction(array($this, 'onDelete')); | |
//$action_del->setUseButton(TRUE); | |
//$action_del->setButtonClass('btn btn-default'); | |
$action_del->setLabel(_t('Delete')); | |
$action_del->setImage('fa:trash-o red fa-lg'); | |
$action_del->setField('id'); | |
$this->datagrid->addAction($action_del); | |
// create the datagrid model | |
$this->datagrid->createModel(); | |
// create the page navigation | |
$this->pageNavigation = new TPageNavigation; | |
$this->pageNavigation->setAction(new TAction(array($this, 'onReload'))); | |
$this->pageNavigation->setWidth($this->datagrid->getWidth()); | |
// vertical box container | |
$container = new TVBox; | |
$container->style = 'width: 100%'; | |
$container->add(new TXMLBreadCrumb('menu.xml', __CLASS__)); | |
$container->add(TPanelGroup::pack('Contas a Pagar', $this->form)); | |
$container->add(TPanelGroup::pack('', $this->formGrid, $this->pageNavigation)); | |
parent::add($container); | |
} | |
function onReload($param = NULL) | |
{ | |
try | |
{ | |
TTransaction::open('sample'); | |
$repository = new TRepository('ContaPagar'); | |
$criteria = new TCriteria; | |
$order = isset($param['order']) ? $param['order'] : 'id'; | |
$criteria->setProperty('order', $order); | |
$categories = $repository->load($criteria); | |
$this->datagrid->clear(); | |
if ($categories) | |
{ | |
foreach ($categories as $item) | |
{ | |
$item->checkbox = new TCheckButton('checkbox'.$item->id); | |
$item->checkbox->setIndexValue($item->id); | |
$this->datagrid->addItem($item); | |
$this->form->addField($item->checkbox); | |
} | |
} | |
TTransaction::close(); | |
$this->loaded = true; | |
} | |
catch (Exception $e) | |
{ | |
new TMessage('error', $e->getMessage()); | |
TTransaction::rollback(); | |
} | |
} | |
public function onSave($param) | |
{ | |
$data = $this->form->getData(); | |
$this->form->setData($data); | |
$selecionados = []; | |
foreach ($this->form->getFields() as $value => $field) | |
{ | |
if ($field instanceof TCheckButton) | |
{ | |
$parts = explode('checkbox', $value); | |
$id = $parts[1]; | |
if ($field->getValue() == $id) | |
{ | |
$selecionados[] = $id; | |
} | |
} | |
} | |
TSession::setValue('selecionados', $selecionados ); | |
} | |
/** | |
* shows the page | |
*/ | |
function show() | |
{ | |
//$this->onReload(); | |
parent::show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment