Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PosEsterilizacaoForm extends TPage
- {
- protected $form;
- protected $formFields;
- protected $detail_list;
- protected $criteria_cartao;
- public function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new TForm('form_PosEsterilizacao');
- $this->form->class = 'tform'; // CSS class
- $this->form->style = 'width:100%;'; // style
- parent::include_css('app/resources/custom-frame.css');
- $table_master = new TTable;
- $table_master->width = '100%';
- $table_master->addRowSet( new TLabel('Pós Esterilização'), '', '')->class = 'tformtitle';
- $this->criteria_cartao = new TCriteria;
- $this->criteria_cartao->add(new TFilter('produto_id','in',"NOESC:(select id from produtos where gruposId=65)"));
- // add a table inside form
- $table_general = new TTable;
- $table_detail = new TTable;
- $table_composicao = new TTable;
- $table_botoes = new TTable;
- $table_informacoes = new TTable;
- $table_informacoes->width='100%';
- $table_composicao->width='100%';
- $table_general-> width = '100%';
- $table_detail-> width = '100%';
- $frame_general = new TFrame;
- $frame_general->setLegend('Pós Esterilização');
- $frame_general->style = 'background:whiteSmoke';
- $frame_general->add($table_general);
- $frame_general->add($table_botoes);
- $table_master->addRow()->addCell( $frame_general );
- $row = $table_master->addRow();
- $row->addCell( $table_detail );
- $this->form->add($table_master);
- // master fields
- $id = new TEntry('id');
- $montagens_ids = new TMultiSearch('montagens_ids');
- $data_entrada = new TDateTime('data_entrada');
- $data_saida = new TDateTime('data_saida');
- $montagens_ids->setEditable(false);
- $data_saida->setMask('dd/mm/yyyy hh:ii');
- $data_saida->setDatabaseMask('yyyy-mm-dd hh:ii');
- $data_saida->setEditable(false);
- $data_entrada->setMask('dd/mm/yyyy hh:ii');
- $data_entrada->setDatabaseMask('yyyy-mm-dd hh:ii');
- $data_entrada->setEditable(false);
- if (!empty($id))
- {
- $id->setEditable(FALSE);
- }
- // create an action button (save)
- $save_button=new TButton('save');
- $save_button->setAction(new TAction(array($this, 'onSave')), _t('Save'));
- $save_button->setImage('fa:save blue');
- $finalizar=new TButton('finalizar');
- $finalizar->setAction(new TAction(array($this, 'onFinalizar')), 'Finalizar Processo');
- $finalizar->setImage('fa:check green');
- $finalizar->setEditable(false);
- // master
- $table_general->addRowSet( new TLabel('Esterilização:'), $id );
- $table_general->addRowSet( new TLabel('Ordens de Montagens:'), $montagens_ids );
- $table_general->addRowSet( new TLabel('Data Entrada:'), $data_entrada );
- $table_general->addRowSet( new TLabel('Data Saída'), $data_saida );
- $table_botoes->addRowSet(array($save_button));
- $this->detail_list = new BootstrapDatagridWrapper(new TQuickGrid);
- $this->detail_list->style='margin-left:10px;';
- $this->detail_list->setHeight( 300 );
- $this->detail_list->makeScrollable();
- $this->detail_list->disableDefaultClick();
- // items
- $this->detail_list->addQuickColumn('Referência', 'referencia', 'left', 80);
- $this->detail_list->addQuickColumn('Produto', 'produto_id', 'left');
- $this->detail_list->addQuickColumn('Tipo Unidade', 'tipo_unidade_id', 'left');
- $this->detail_list->addQuickColumn('Quantidade', 'quantidade', 'left');
- $this->detail_list->addQuickColumn('Nº Lote', 'numero_lote', 'left');
- $this->detail_list->addQuickColumn('Cartão', 'cartao_id', 'left');
- $this->detail_list->createModel();
- $row = $table_detail->addRow();
- $row->addCell($this->detail_list);
- // create an new button (edit with no parameters)
- $voltar=new TButton('voltar');
- $voltar->setAction(new TAction(array('PosEsterilizacaoList', 'onReload')), 'Voltar');
- $voltar->setImage('ico_back.png');
- // define form fields
- $this->formFields = array($id,$montagens_ids,$data_entrada,$data_saida,$save_button,$voltar,$finalizar);
- $this->form->setFields( $this->formFields );
- $table_master->addRowSet( array($save_button,$finalizar,$voltar), '', '')->class = 'tformaction'; // CSS class
- // create the page container
- $container = new TVBox;
- $container->style = 'width: 100%';
- $container->add(new TXMLBreadCrumb('menu.xml', 'PosEsterilizacaoList'));
- $container->add($this->form);
- parent::add($container);
- }
- public static function onChangeCartao($param)
- {
- $items = TSession::getValue(__CLASS__.'_items');
- $parts = explode('_',$param['_field_name']);
- $key = $parts[1];
- $items[ $key ]['cartao_id'] = $param['_field_value'];
- TSession::setValue(__CLASS__.'_items', $items);
- }
- public static function onFinalizar($param)
- {
- if($param['id']!=null)
- {
- $action = new TAction(array('PosEsterilizacaoForm', 'Finalizar'));
- $action->setParameters($param);
- new TQuestion('Você realmente quer finalizar essa produção? Os cartões serão <b>deduzidos</b> do estoque!', $action);
- }
- }
- public static function Finalizar($param)
- {
- try
- {
- TTransaction::open('sample');
- $master = new Esterilizacao($param['id']);
- $string=null;
- $ficha_consumo=null;
- $items = TSession::getValue(__CLASS__.'_items');
- if( $items )
- {
- foreach( $items as $item )
- {
- $lote = new Lote($item['id']);
- $lote->montagem_item->montagem->ficha_consumo .= Montagem::reduz($item['cartao_id'],$item['quantidade']);
- $lote->store();
- }
- }
- $esterilizacao_montagens = $master->getMontagens();
- foreach($esterilizacao_montagens as $esterilizacao_montagem)
- {
- $montagem = new Montagem($esterilizacao_montagem->montagem_id);
- $montagem->situacao_id = 6;
- $montagem->store();
- }
- $master->store();
- TTransaction::close();
- Utils::setMensagem('info','Processo de Montagem concluído com sucesso');
- AdiantiCoreApplication::loadPage('MontagemList','onReload');
- }catch(Exception $e)
- {
- new TMessage('error',$e->getMessage());
- }
- }
- public function onClear($param)
- {
- TSession::setValue(__CLASS__.'situacao', 1);
- TSession::setValue(__CLASS__.'_items', array());
- $this->form->clear(TRUE);
- $this->onReload( $param );
- }
- public function onReload($param)
- {
- // read session items
- $items = TSession::getValue(__CLASS__.'_items');
- $this->detail_list->clear(); // clear detail list
- $data = $this->form->getData();
- $itens_editaveis=0;
- $produzido_editavel=0;
- //variaveis
- $totalPedido=0;
- $totalProduzido=0;
- if ($items)
- {
- $cont = 1;
- foreach ($items as $list_item_key => $list_item)
- {
- $item_name = 'prod_' . $cont++;
- $item = new StdClass;
- // items
- $item->id = $list_item['id'];
- $id = $list_item['produto_id'];
- TTransaction::open('sample');
- $produto = new Produto($id);
- $tarraxa = new Insumo($list_item['tarraxa_id']);
- $berco = new Insumo($list_item['berco_id']);
- $item->produto_id = $produto->descricao;
- $item->tarraxa_id = $tarraxa->produto->descricao;
- $item->berco_id = $berco->produto->descricao;
- $item->tipo_unidade_id = $produto->tipo_unidade->descricao;
- $item->referencia = $produto->referencia;
- $item->quantidade = $list_item['quantidade'];
- $item->numero_lote = $list_item['numero_lote'];
- TTransaction::close();
- //CRIAÇÃO DO TDBCOMBO
- $item->cartao_id = new TDBCombo('inline_'.$item->id,'sample','Insumo','id',' {produto->descricao} - Lote: {numero_lote} / Disponível: {quantidade_disponivel}','numero_lote',$this->criteria_cartao);
- $item->cartao_id->setSize(300);
- $item->cartao_id->setValue($list_item['cartao_id']);
- $item->cartao_id->setChangeAction(new TAction(array($this,'onChangeCartao')));
- $this->form->addField($item->cartao_id);
- $row = $this->detail_list->addItem( $item );
- }
- $this->form->setFields( $this->formFields );
- }
- if(TSession::getValue(__CLASS__.'mensagem')!=null)
- {
- new TMessage('info',TSession::getValue(__CLASS__.'mensagem'));
- TSession::setValue(__CLASS__.'mensagem',null);
- }
- $obj = new stdClass;
- $obj->total_pedido = $totalPedido;
- $obj->total_produzido = $totalProduzido;
- TForm::sendData('form_Montagem',$obj);
- $this->loaded = TRUE;
- }
- public function onEdit($param)
- {
- try
- {
- TTransaction::open('sample');
- if (isset($param['key']))
- {
- $key = $param['key'];
- $object = new Esterilizacao($key);
- $montagens_ids = null;
- $itens_combo = [];
- $montagens = $object->getMontagens();
- foreach($montagens as $montagem)
- {
- $montagens_ids = ($montagens_ids==null)?'':',';
- $montagens_ids = $montagem->montagem_id;
- $itens_combo[$montagem->montagem_id] = $montagem->montagem_id;
- }
- $object->montagens_ids = $itens_combo;
- $items = Lote::where('montagem_item_id', 'in', "NOESC:(Select id from montagem_itens where montagem_id in (".$montagens_ids."))")->load();
- $session_items = array();
- foreach( $items as $item )
- {
- $item_key = $item->id;
- $session_items[$item_key] = $item->toArray();
- $session_items[$item_key]['id'] = $item->id;
- $session_items[$item_key]['produto_id'] = $item->produto_id;
- $session_items[$item_key]['quantidade'] = $item->quantidade;
- $session_items[$item_key]['numero_lote'] = $item->numero_lote;
- $session_items[$item_key]['tarraxa_id'] = $item->montagem_item->tarraxa_id;
- $session_items[$item_key]['berco_id'] = $item->montagem_item->berco_id;
- $session_items[$item_key]['cartao_id'] = $item->cartao_id;
- $session_items[$item_key]['tipo_unidade_id'] = $item->produto->tipo_unidade_id;
- }
- TSession::setValue(__CLASS__.'_items', $session_items);
- $this->form->setData($object);
- $this->onReload( $param );
- TTransaction::close();
- }
- else
- {
- $this->form->clear(TRUE);
- TSession::setValue(__CLASS__.'_items', null);
- $this->onReload( $param );
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- /**
- * Save the Master/Detail data from form/session to database
- */
- public function onSave()
- {
- try
- {
- // open a transaction with database
- TTransaction::open('sample');
- $data = $this->form->getData();
- $master = new Esterilizacao;
- $master->fromArray( (array) $data);
- $this->form->validate(); // form validation
- $master->store(); // save master object
- // get session items
- $items = TSession::getValue(__CLASS__.'_items');
- if( $items )
- {
- foreach( $items as $item )
- {
- $detail = Lote::find($item['id']);
- $detail->cartao_id = $item['cartao_id'];
- $detail->store();
- }
- }
- TTransaction::close(); // close the transaction
- // reload form and session items
- $this->onEdit(array('key'=>$master->id));
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback();
- }
- }
- /**
- * Show the page
- */
- public function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
- {
- $this->onReload( func_get_arg(0) );
- }
- parent::show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement