Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.04 KB | None | 0 0
  1. <?php
  2. /**
  3. * ContasPagarForm2 Form
  4. * @author <your name here>
  5. */
  6. class ContasPagarFormBaixa extends TPage
  7. {
  8. protected $form; // form
  9.  
  10. /**
  11. * Form constructor
  12. * @param $param Request
  13. */
  14. public function __construct( $param )
  15. {
  16. parent::__construct();
  17.  
  18.  
  19. try
  20. {
  21. TTransaction::open('facilitasmart');
  22. $condominio = new Condominio(TSession::getValue('id_condominio'));
  23. //$logado = Imoveis::retornaImovel();
  24. TTransaction::close();
  25. }
  26. catch(Exception $e)
  27. {
  28. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  29. }
  30.  
  31. parent::add(new TLabel('Mês de Referência : ' . TSession::getValue('mesref') . ' / Condomínio : ' .
  32. TSession::getValue('id_condominio') . ' - ' . $condominio->resumo));
  33.  
  34. // creates the form
  35. //$this->form = new TQuickForm('form_ContasPagarBaixar');
  36. //$this->form->class = 'tform'; // change CSS class
  37. //$this->form = new BootstrapFormWrapper($this->form);
  38. //$this->form->style = 'display: table;width:100%'; // change style
  39.  
  40. $this->form = new BootstrapFormBuilder('form_ContasPagarBaixar');
  41. $this->form->setFormTitle('Liquidação de Despesas');
  42.  
  43. // define the form title
  44. $this->form->setFormTitle('Liquidação Despesas');
  45.  
  46. // create the form fields
  47. $id = new TEntry('id');
  48.  
  49. $condominio_id = new TDBCombo('condominio_id', 'facilitasmart', 'Condominio', 'id', 'resumo', 'resumo');
  50. $mes_ref = new TEntry('mes_ref');
  51.  
  52. // não pegava a situacao porque não estava definido aqui
  53. $situacao = new THidden('situacao');
  54.  
  55. //$planocontas_id = new TEntry('planocontas_id');
  56. //$planocontas_id = new TDBMultiSearch('planocontas_id','facilita','PlanoContas','id','descricao');
  57. //$criteria = new TCriteria;
  58. //$criteria->add(new TFilter("tipo", "=", 'D'));
  59. $planocontas_id = new TDBCombo('classe_id', 'facilitasmart', 'PlanoContas', 'id',
  60. '{codigo} - {descricao}','descricao');
  61.  
  62. $dt_vencimento = new TDate('dt_vencimento');
  63. $dt_liquidacao = new TDate('dt_liquidacao');
  64. $dt_pagamento = new TDate('dt_pagamento');
  65. $valor = new TEntry('valor');
  66.  
  67. $parcela = new TEntry('parcela');
  68. $descricao = new TEntry('descricao');
  69.  
  70. $tipo_pagamento_id = new TDBCombo('tipo_pagamento_id', 'facilitasmart', 'TipoPagamento', 'id', '{id}-{descricao}','descricao');
  71. $numero_doc_pagamento = new TEntry('numero_doc_pagamento');
  72. $conta_fechamento_id = new TDBCombo('conta_fechamento_id', 'facilitasmart', 'ContaFechamento', 'id', '{id}-{descricao}','descricao');
  73.  
  74. //liquidacao
  75. $multa = new TEntry('multa');
  76. $multa->setNumericMask(2, ',', '.');
  77. $juros = new TEntry('juros');
  78. $juros->setNumericMask(2, ',', '.');
  79. $correcao = new TEntry('correcao');
  80. $correcao->setNumericMask(2, ',', '.');
  81. $desconto = new TEntry('desconto');
  82. $desconto->setNumericMask(2, ',', '.');
  83. $valor_pago = new TEntry('valor_pago');
  84. $valor_pago->setNumericMask(2, ',', '.');
  85.  
  86.  
  87. $valor->setNumericMask(2, ',', '.');
  88. $dt_vencimento->setMask('dd/mm/yyyy');
  89. $dt_liquidacao->setMask('dd/mm/yyyy');
  90. $dt_pagamento->setMask('dd/mm/yyyy');
  91.  
  92. // validations
  93. $dt_vencimento->addValidation('dt_vencimento', new TRequiredValidator);
  94. $dt_liquidacao->addValidation('dt_liquidacao', new TRequiredValidator);
  95. $dt_pagamento->addValidation('dt_pagamento', new TRequiredValidator);
  96.  
  97. $descricao->setSize('100%');
  98.  
  99. //$planocontas_id->setSize(240,28);
  100. //$planocontas_id->setMinLength(1);
  101. //$planocontas_id->setMaxSize(1);
  102.  
  103. $parcela->setSize('20%');
  104.  
  105. //atribue o imovel selecionado
  106. // $imovel_id->setValue( TSession::getValue('id_imovel') );
  107. // $imovel_id->setEditable(FALSE);
  108. //
  109. // $mes_ref->setValue( TSession::getValue('mesref') );
  110.  
  111. $dt_vencimento->setEditable(FALSE);
  112. $mes_ref->setEditable(FALSE);
  113.  
  114. $planocontas_id->setEditable(FALSE);
  115. $condominio_id->setEditable(FALSE);
  116.  
  117. $valor->setEditable(FALSE);
  118. //$descricao->setEditable(FALSE);
  119.  
  120.  
  121. // define how many columns
  122. //$this->form->setFieldsByRow(2);
  123.  
  124. $lbl_parcela = new TLabel('Parcela');
  125. $lbl_parcela->setFontStyle('b');
  126. $lbl_valor = new TLabel('Valor');
  127. $lbl_valor->setFontStyle('b');
  128.  
  129. // define the sizes
  130. $id->setSize('100%');
  131. $mes_ref->setSize('100%');
  132. $condominio_id->setSize('100%');
  133. $planocontas_id->setSize('100%');
  134.  
  135. $multa->setSize('50%');
  136. $juros->setSize('50%');
  137. $correcao->setSize('50%');
  138. $desconto->setSize('50%');
  139.  
  140. $valor_pago->setSize('50%');
  141.  
  142. // add the fields
  143. $this->form->addFields( [new TLabel('Id')], [$id],
  144. [new TLabel('Mes Ref')], [$mes_ref]);
  145.  
  146. $this->form->addFields( [new TLabel('Condominio')], [$condominio_id],
  147. [new TLabel('Classe')], [$planocontas_id]);
  148.  
  149.  
  150. $this->form->addFields( [new TLabel('Vencimento')], [$dt_vencimento],
  151. [new TLabel('Valor')], [$valor] );
  152.  
  153. $this->form->addFields( [new TLabel('Descrição')], [$descricao]);
  154.  
  155. $this->form->addFields( [new TLabel('Tipo Pagamento')], [$tipo_pagamento_id],
  156. [new TLabel('Número Doc. Pagamento')], [$numero_doc_pagamento]);
  157.  
  158. $this->form->addFields( [new TLabel('Conta Fechamento')], [$conta_fechamento_id]);
  159. $this->form->addFields( [new TLabel('Data Liquidação')], [$dt_liquidacao],
  160. [new TLabel('Data Pagamento')], [$dt_pagamento]);
  161.  
  162. $this->form->addFields( [new TLabel('Multa')], [$multa],
  163. [new TLabel('Juros')], [$juros]);
  164. $this->form->addFields( [new TLabel('Correção')], [$correcao],
  165. [new TLabel('Desconto')], [$desconto]);
  166.  
  167. $this->form->addFields( [new TLabel('Valor Pago')], [$valor_pago]);
  168. //$this->form->addQuickField('', $situacao );
  169.  
  170. if (!empty($id))
  171. {
  172. $id->setEditable(FALSE);
  173. }
  174.  
  175. /** samples
  176. $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  177. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  178. $fieldX->setSize( 100, 40 ); // set size
  179. **/
  180.  
  181. $change_mes_ref = new TAction(array($this, 'onTestaMesRef'));
  182. $mes_ref->setExitAction($change_mes_ref);
  183.  
  184. //liquidacao
  185. $multa->setExitAction(new TAction(array($this, 'onUpdateTotal')));
  186. $juros->setExitAction(new TAction(array($this, 'onUpdateTotal')));
  187. $correcao->setExitAction(new TAction(array($this, 'onUpdateTotal')));
  188. $desconto->setExitAction(new TAction(array($this, 'onUpdateTotal')));
  189.  
  190. // create the form actions
  191. //$this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  192. //$this->form->addQuickAction(_t('New'), new TAction(array($this, 'onClear')), 'bs:plus-sign green');
  193. $btn = $this->form->addAction( _t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  194. $btn->class = 'btn btn-sm btn-primary';
  195.  
  196. $btn1 = $this->form->addAction(_t('List'), new TAction(array('ContasPagarList','onReload')), 'fa:table blue');
  197. $btn1->class = 'btn btn-sm btn-primary';
  198.  
  199. $this->alertBox = new TElement('div');
  200.  
  201. // creates the page structure using a vbox
  202. $container = new TVBox;
  203. $container->style = 'width: 100%';
  204. //$container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  205. $container->add($this->form);
  206. // add the vbox inside the page
  207. parent::add($container);
  208.  
  209. }
  210.  
  211. public static function onUpdateTotal($param)
  212. {
  213. $multa = (double) str_replace(',', '.', $param['multa']);
  214. $juros = (double) str_replace(',', '.', $param['juros']);
  215. $correcao = (double) str_replace(',', '.', $param['correcao']);
  216. $desconto = (double) str_replace(',', '.', $param['desconto']);
  217. $valor = (double) str_replace(',', '.', $param['valor']);
  218.  
  219. $soma = ($valor+$multa+$juros+$correcao)-$desconto;
  220.  
  221. //var_dump($param);
  222.  
  223. $obj = new StdClass;
  224.  
  225. $obj->valor_pago = number_format($soma, 2, ',', '.');
  226.  
  227. TForm::sendData('form_ContasPagarBaixar', $obj);
  228. }
  229.  
  230. public static function onTestaMesRef($param)
  231. {
  232. $obj = new StdClass;
  233. $string = new StringsUtil;
  234.  
  235. if(isset($param['mes_ref']))
  236. {
  237. // valida o mes referencia
  238. $mesreferencia = explode('/', $param['mes_ref']);
  239.  
  240. $d = '01';
  241. $m = $mesreferencia[0];
  242. $y = isset($mesreferencia[1]) ? $mesrefhttps://www.google.com.br/maps/place/R.+Manoel+do+Nascimento+Abreu+-+S%C3%A3o+Luiz,+Arapiraca+-+AL/@-9.7706145,-36.6481706,17z/data=!4m5!3m4!1s0x705d50234433921:0x6dd31e23a02692df!8m2!3d-9.7716374!4d-36.6463521erencia[1] : 0;
  243.  
  244. //if (isset($mesreferencia[1]))
  245. //{
  246. // $y = $mesreferencia[1];
  247. //
  248. //}
  249.  
  250. // verifica se a data é válida! // 1 = true (válida) // 0 = false (inválida)
  251. $res = checkdate($m,$d,$y);
  252.  
  253. if ($res == 1){
  254. if ( strlen($y) == 4){
  255. } else {
  256. new TMessage('info', 'Mês Referência Inválido');
  257. $obj->mes_ref='';
  258. }
  259. } else {
  260. //echo "data inválida!";
  261. new TMessage('info', 'Mês Referência Inválido');
  262. $obj->mes_ref='';
  263.  
  264. } https://www.google.com.br/maps/place/R.+Manoel+do+Nascimento+Abreu+-+S%C3%A3o+Luiz,+Arapiraca+-+AL/@-9.7706145,-36.6481706,17z/data=!4m5!3m4!1s0x705d50234433921:0x6dd31e23a02692df!8m2!3d-9.7716374!4d-36.6463521
  265.  
  266. TForm::sendData('form_ContasPagar', $obj, FALSE, FALSE);
  267. }
  268. }
  269.  
  270. /**
  271. * Save form data
  272. * @param $param Request
  273. */
  274. public function onSave( $param )
  275. {
  276. $string = new StringsUtil;
  277.  
  278. try
  279. {
  280. TTransaction::open('facilitasmart'); // open a transaction
  281.  
  282. /**
  283. // Enable Debug logger for SQL operations inside the transaction
  284. TTransaction::setLogger(new TLoggerSTD); // standard output
  285. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  286. **/
  287.  
  288. $this->form->validate(); // validate form data
  289.  
  290.  
  291. $object = new ContasPagar; // create an empty object
  292. $data = $this->form->getData(); // get form data as array
  293. $object->fromArray( (array) $data); // load the object with data
  294.  
  295. if ( $object->situacao == '1') {
  296. new TMessage('info', 'Título já baixado, não é possível edição !');
  297. TTransaction::close();
  298. $this->form->setData($object); // mantem os dados digitados;
  299. return;
  300. }
  301.  
  302. //var_dump($object->dt_vencimento);
  303. // valida a data de vencimento e mes_ref
  304. $dt_venc = explode("/", $object->dt_vencimento);
  305. $mes_referencia = explode("/", $object->mes_ref);
  306.  
  307. //var_dump($dt_venc[1]);
  308. //var_dump($mes_referencia[0]);
  309. if ( $dt_venc[1] != $mes_referencia[0]) {
  310. new TMessage('info', 'Divergência entre o mês da data de vencimento e o Mês Ref !');
  311. TTransaction::close();
  312. $this->form->setData($object); // mantem os dados digitados;
  313. return;
  314. }
  315.  
  316. if ( $dt_venc[2] != $mes_referencia[1]) {
  317. new TMessage('info', 'Divergência entre o ano da data de vencimento e o Mês Ref !');
  318. TTransaction::close();
  319. $this->form->setData($object); // mantem os dados digitados;
  320. return;
  321. }
  322.  
  323. // verifica se existe fechamento aberto possivel de edicao
  324. $fechamentos = Fechamento::where('condominio_id', '=', $object->condominio_id)->
  325. where('mes_ref', '=', $object->mes_ref)->load();
  326.  
  327. $status = '';
  328. foreach ($fechamentos as $fechamento) {
  329. $status = $fechamento->status;
  330. }
  331.  
  332. if ($status == 1 and $object->valor_pago == 0){
  333. //var_dump($status);
  334. new TMessage('info', 'Não existe um Fechamento aberto para a data de vencimento !');
  335. TTransaction::close();
  336. $this->form->setData($object); // mantem os dados digitados;
  337. return;
  338. }
  339.  
  340. $object->usuario_id = TSession::getValue('login');
  341.  
  342. //formato necessário no mysql
  343. $object->dt_vencimento = TDate::date2us($object->dt_vencimento );
  344. $object->dt_liquidacao = TDate::date2us($object->dt_liquidacao );
  345. $object->dt_pagamento = TDate::date2us($object->dt_pagamento );
  346.  
  347. $object->valor ? $object->valor = $string->desconverteReais($object->valor) : null;
  348. $object->multa ? $object->multa = $string->desconverteReais($object->multa) : null;
  349. $object->juros ? $object->juros = $string->desconverteReais($object->juros) : null;
  350. $object->desconto ? $object->desconto = $string->desconverteReais($object->desconto) : null;
  351. $object->correcao ? $object->correcao = $string->desconverteReais($object->correcao) : null;
  352.  
  353. //$object->dt_lancamento = date("Y-m-d");
  354.  
  355. // pega a chave do TDBMultiSearch
  356. //troquei opor combo ===== >$object->planocontas_id = key($data->planocontas_id);
  357. ///var_dump($object->planocontas_id);
  358.  
  359. $object->situacao = '1';
  360.  
  361. $object->store(); // save the object
  362.  
  363. // get the generated id
  364. $data->id = $object->id;
  365.  
  366. $this->form->setData($data); // fill form data
  367. TTransaction::close(); // close the transaction
  368.  
  369. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  370. }
  371. catch (Exception $e) // in case of exception
  372. {
  373. $this->alertBox->add( new TAlert('danger', $e->getMessage()) );
  374.  
  375. //new TMessage('error', $e->getMessage()); // shows the exception error message
  376. $this->form->setData( $this->form->getData() ); // keep form data
  377. TTransaction::rollback(); // undo all pending operations
  378. }
  379. }
  380.  
  381. /**
  382. * Clear form data
  383. * @param $param Request
  384. */
  385. public function onClear( $param )
  386. {
  387. $this->form->clear(TRUE);
  388. }
  389.  
  390. /**
  391. * Load object to form data
  392. * @param $param Request
  393. */
  394. public function onEdit( $param )
  395. {
  396. try
  397. {
  398. if (isset($param['key']))
  399. {
  400. $key = $param['key']; // get the parameter $key
  401. TTransaction::open('facilitasmart'); // open a transaction
  402. $object = new ContasPagar($key); // instantiates the Active Record
  403.  
  404. // necessário no mysql
  405. $object->dt_lancamento = TDate::date2br($object->dt_lancamento);
  406. $object->dt_vencimento = TDate::date2br($object->dt_vencimento);
  407. $object->dt_pagamento = TDate::date2br($object->dt_pagamento);
  408. $object->dt_liquidacao = TDate::date2br($object->dt_liquidacao);
  409.  
  410. $object->valor ? $object->valor = number_format($object->valor, 2, ',', '.') : null;
  411. $object->multa ? $object->multa = number_format($object->multa, 2, ',', '.') : null;
  412. $object->juros ? $object->juros = number_format($object->juros, 2, ',', '.') : null;
  413. $object->correcao ? $object->correcao = number_format($object->correcao, 2, ',', '.') : null;
  414. $object->desconto ? $object->desconto = number_format($object->desconto, 2, ',', '.') : null;
  415. $object->valor_pago ? $object->valor_pago = number_format($object->valor_pago, 2, ',', '.') : null;
  416.  
  417.  
  418.  
  419. $this->form->setData($object); // fill the form
  420. TTransaction::close(); // close the transaction
  421. }
  422. else
  423. {
  424. $this->form->clear(TRUE);
  425. }
  426. }
  427. catch (Exception $e) // in case of exception
  428. {
  429. $this->alertBox->add( new TAlert('danger', $e->getMessage()) );
  430.  
  431. //new TMessage('error', $e->getMessage()); // shows the exception error message
  432. TTransaction::rollback(); // undo all pending operations
  433. }
  434. }
  435. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement