Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.11 KB | None | 0 0
  1. <?php
  2. require_once "../../manager.php";
  3. verifySession();
  4. if(array_intersect(array('6'), $_SESSION['codRole'])) {
  5. $postCodFornecedor = isset($_POST['codFornecedor']) ? (int) $_POST['codFornecedor'] : false;
  6. $postCodOs         = isset($_POST['codOs']) ? (int) $_POST['codOs'] : false;
  7. $postCodOp         = isset($_POST['codOp']) ? (int) $_POST['codOp'] : false;
  8. $acao              = isset($_POST['acao']) ? $_POST['acao'] : false;
  9.  
  10. echo $postCodOp;
  11.  
  12. function detalhesOp($postCodOp)
  13. {
  14.     $sql              = new SqlManager();
  15.     $selectDetalhesOs = $sql->getFields("SELECT
  16.        códOP as codOp,
  17.        FORNECEDOR as codFornecedor,
  18.        OP as op,
  19.        CONDIÇÕES as condicoes,
  20.        FORMAPG as formaPagamento,
  21.        convert(char(10),[DT FECHAMENTO],103) as dataFechamento,
  22.        ATIVO as ativo
  23.  
  24. FROM [ORDENS DE PAGAMENTO]
  25.  
  26. Where [códOP] = " . $postCodOp);
  27.    
  28.     $sql->closeConnection();
  29.     return $selectDetalhesOs;
  30. }
  31.  
  32.  
  33. if(isset($postCodOp)) {
  34.     $infoOp = detalhesOp($postCodOp);
  35.     $infoOp = isset($infoOp[0]) ? $infoOp[0] : null;
  36.  
  37.    
  38. } if ($postCodOp == null)  {
  39.    
  40.     $mes=array('', 'JANEIRO', 'FEVEREIRO', 'MARÇO', 'ABRIL', 'MAIO', 'JUNHO', 'JULHO', 'AGOSTO', 'SETEMBRO', 'OUTUBRO', 'NOVEMBRO', 'DEZEMBRO');
  41.     $ano =date('Y');
  42.  
  43.     $infoOp['codOp'] =null;
  44.     $infoOp['codFornecedor'] = null;
  45.     $infoOp['op'] = null;
  46.     $infoOp['condicoes'] = "À Vista";
  47.     $infoOp['formaPagamento'] = "Depósito em Conta";
  48.     $infoOp['dataFechamento'] = null;
  49.     $postCodOp = 'null';
  50.     $infoOp['ativo'] = 1;
  51.  
  52. } elseif ($postCodOp) {
  53.     $infoOp = detalhesOp( $postCodOp );
  54.     $infoOp = isset( $infoOp[ 0 ] ) ? $infoOp[ 0 ] : null;
  55. }
  56.  
  57. $fornecedorSql = "SELECT CógidoDoNome as codFornecedor, Nome as nome FROM FORNECEDORES ORDER BY nome";
  58.  
  59. $sql    = new SqlManager();
  60. $listas = array(
  61.     "listaFornecedor" => $sql->getFields($fornecedorSql)
  62. );
  63. $sql->closeConnection();
  64. } ?>
  65. <?  if(array_intersect(array('6'), $_SESSION['codRole'])) { ?>
  66. <div id="modalPagamentosContent">
  67.  
  68.     <div class="modal-header">
  69.         <button type="button" class="close" data-dismiss="modal" id="fechaModal" onclick="carregatabelaOpGeral()">&times;</button>
  70.         <h4 class="modal-title">Ordem de Pagamento </h4>
  71.     </div>
  72.  
  73.     <div class="modal-body">
  74.         <div class="row">
  75.             <div class="col-sm-7">
  76.                 <label for="nome" class="control-label">Nome:</label>
  77.                 <select class="nomeSelect" id="nome" style="width:100%" value="<?= $postCodFornecedor ?>">
  78.                     <option value=""></option>
  79.                     <?php
  80.                     foreach ($listas["listaFornecedor"] as $lista) {
  81.                     ?>
  82.                         <option value="<?=$lista['codFornecedor']?>"<?php
  83.                         if ($lista['codFornecedor'] == $postCodFornecedor) {
  84.                             echo "selected";
  85.                         }
  86.                          
  87.                         ?>>
  88.                     <?= $lista["nome"] ?>
  89.                     </option>
  90.                     <?php
  91.                     }
  92.                     ?>
  93.                </select>
  94.             </div>
  95.             <div class="col-sm-3">
  96.                 <label> Forma de Pagamento: </label>
  97.                 <input type="text" class="form-control" id="formaPagamento" value="<?= $infoOp["formaPagamento"]?>">
  98.             </div><br>
  99.             <div class="col-sm-2">
  100.                 <label>Ativo: </label>
  101.                 <input type="checkbox" class="form-control" data-toggle="toggle" data-width="50%" id="ativo" data-size="mini" data-onstyle="success" data-on="Ativo" data-offstyle="danger" data-off="Inativo" <?= $infoOp['ativo'] != 0 ? "checked" : "" ?>
  102.    <?= $infoOp['ativo'] == 1 ? "checked" : "" ?>>
  103.             </div>
  104.         </div>
  105.        
  106.         <div class="row">
  107.             <div class="col-sm-6">
  108.                 <label> Identificação: </label>
  109.                 <input type="text" class="form-control op" id="op" value="<?=$infoOp["op"]?>">
  110.             </div>
  111.             <div class="col-sm-3">
  112.                 <label> Condições: </label>
  113.                 <input type="text" class="form-control condicoes" id="condicoes" value="<?=$infoOp["condicoes"]?>">
  114.             </div>
  115.             <div class="col-sm-3">
  116.                 <label>Data de Fechamento: </label>
  117.                 <input type="text" class="form-control dataFechamento" id="dataFechamento" value=<?= $infoOp["dataFechamento"]?>>
  118.             </div>
  119.         </div>  <br>
  120.  
  121.         <?php
  122. if ($infoOp["codOp"] == NULL) {
  123. ?>
  124.            <div class="box-body form-group" align="center">
  125.             <button type="button" class="btn btn-success" id="salvarOp">Salvar Op</button>
  126.             </div>
  127.         <?php
  128. }
  129. ?>
  130. <?php
  131. if (($postCodFornecedor != null) || ($infoOp["codOp"] =! null)) {
  132. ?>
  133.    <div class="box box-body" id="pagamentos">
  134.         <div class="col-sm-12">
  135.      
  136.             <table id="tabelaPagamentos" class="table table-bordered table-striped table-hover" data-order='[[0, "asc"]]' data-page-length="15">
  137.             <style>
  138.        .red {
  139.   background-color: red !important;
  140. }
  141.     </style>
  142.                 <thead>
  143.                     <tr>
  144.                         <th>Pedido</th>
  145.                         <th>Tarefa</th>
  146.                         <th>Início</th>
  147.                         <th>Conclusão</th>
  148.                         <th>Fechar</th>                    
  149.                        
  150.                     </tr>
  151.                     </thead>
  152.             </table>
  153.         </div>
  154.     </div>    
  155.  
  156.     <div class="modal fade" id="modalVoucher" role="dialog">
  157.                     <div class="modal-dialog" style="width:70%;height:auto">
  158.                         <div class="modal-content">              
  159.                             <div id="voucherContent"></div>
  160.                         </div>
  161.                     </div>
  162.             </div>
  163.             <div class="modal fade" id="modalNovaOs" role="dialog">
  164.                     <div class="modal-dialog" style="width:70%;height:auto">
  165.                         <div class="modal-content">              
  166.                             <div id="modalNovaOsContent"></div>
  167.                         </div>
  168.                     </div>
  169.             </div>
  170.     </div>
  171.  
  172. <?php
  173. }
  174. ?>
  175.  
  176. <?} else { ?>
  177.             <div class="box col-sm-12">
  178.             <label> Você não tem permissão para ver essa página </label>
  179.         </div>
  180.         <? } ?>
  181.  
  182. <script>
  183. function insertOp(data) {
  184.     var nome = $('#nome').val();
  185.     var op = $('#op').val();
  186.     var dataFechamento = $('#dataFechamento').val();
  187.     var formaPagamento = $('#formaPagamento').val();
  188.     var condicoes = $('#condicoes').val();
  189.     var ativo = $('#ativo').is(":checked") ? 1 : 0;
  190.  
  191.     $.post("op_insert.php", {
  192.         nome: nome,
  193.         op: op,
  194.         dataFechamento: dataFechamento,
  195.         formaPagamento: formaPagamento,
  196.         condicoes: condicoes,
  197.         ativo: ativo
  198.  
  199.     }, function(data, status) {
  200.         try {
  201.             if (status == "success") {
  202.                 showNotification('OP ', 'Op inserida com sucesso', "success");
  203.             }
  204.         } catch (e) {}
  205.         //console.log(data);    
  206.         var response = JSON.parse(data);
  207.         $("#voucherContent").load("detalhesOp.php", {
  208.             codOp: response.codOp,
  209.             codFornecedor: response.codFornecedor
  210.         });
  211.         return;
  212.     });
  213.  
  214. }
  215.  
  216. function concatenaNomeOp() {
  217.     var data = new Date();
  218.     var meses = new Array("JANEIRO", "FEVEREIRO", "MARÇO", "ABRIL", "MAIO", "JUNHO", "JULHO", "AGOSTO", "SETEMBRO", "OUTUBRO", "NOVEMBRO", "DEZEMBRO");
  219.     var ano = data.getFullYear();
  220.     var resultadoMes = meses[data.getMonth()];
  221.  
  222.     document.getElementById("op").value = resultadoMes + ' ' + ano + ' -' + $("#nome option:selected").text().toUpperCase().trim(); //coloca em Maiúsculo e remove os espaços desnecessários
  223. }
  224.  
  225. function updateOp() {
  226.     var nome = $('#nome').val();
  227.     var op = $('#op').val();
  228.     var dataFechamento = $('#dataFechamento').val();
  229.     var formaPagamento = $('#formaPagamento').val();
  230.     var condicoes = $('#condicoes').val();
  231.     var ativo = $('#ativo').is(":checked") ? 1 : 0;
  232.  
  233.     $.post("op_update.php", {
  234.         codOp: '<?= $postCodOp ?>',
  235.         nome: nome,
  236.         op: op,
  237.         dataFechamento: dataFechamento,
  238.         formaPagamento: formaPagamento,
  239.         condicoes: condicoes,
  240.         ativo: ativo
  241.     }, function(data, source) {
  242.         console.log(data);
  243.         try {} catch (e) {}
  244.     });
  245.     carregaTabelaPagamentos();
  246. }
  247. <?php
  248. if (isset($_POST['codOp'])) {
  249. ?>
  250. $("input").change(function() {
  251.     updateOp();
  252. });
  253. $("select").change(function() {
  254.     updateOp();
  255. });
  256.  
  257. <? } else { ?>
  258.     concatenaNomeOp();
  259. <? } ?>
  260.  
  261. $('#salvarOp').click(function() {
  262.     if ($("#nome").val() == null || $("#nome").val() == "") {
  263.         $("#nome").focus();
  264.         showNotification('NOME', 'Campo vazio!', "danger");
  265.         return false;
  266.     }
  267.     insertOp();
  268.     carregaTabelaPagamentos();
  269. });
  270.  
  271. <?php
  272. if ($postCodFornecedor != null )   {
  273. ?>
  274.  
  275. var dataObject = {
  276.     aoColumns: [{
  277.         "mDataProp": "fechar"
  278.     }],
  279.     stateSave: true,
  280.     paging: true,
  281.     lengthChange: true,
  282.     searching: true,
  283.     ordering: true,
  284.     info: true,
  285.     autoWidth: true,
  286.     bRetrieve: true,
  287.     language: {
  288.         url: "/dist/plugins/datatables/i18n/Portuguese-Brasil.json"
  289.     }
  290. }
  291.  
  292. function carregaTabelaPagamentos() {
  293.     $.post("detalhesOp_select.php", {
  294.         codFornecedor: <?= $postCodFornecedor ?>,
  295.         codOp: <?= $postCodOp ?>
  296.     }, function(data, status) {
  297.         console.log(data);
  298.         var response = JSON.parse(data);
  299.         var aoColumnsDataTable = [];
  300.         var arrayToTable = [];
  301.  
  302.         response.listaPagamentos.forEach(function(element, index, array) {
  303.             objTable = {};
  304.             element.tarefa = '<a href="" onclick="fItensOs(' + element.codOs + ')">' + element.tarefa + '</a>';
  305.  
  306.             if(element.op != null){
  307.                 element.fechar = 1;
  308.                 element.fechar = '<input type="checkbox" name="fechar"  <? if ($infoOp["codOp"] == null){ echo "disabled";}?> onchange="associaOp(' + element.codOs +  ',' + element.op +  ',' +  element.fechar + ');" checked>' <? if ($postCodOp == null){ echo "disabled";}?>;
  309.             } else {
  310.                 element.fechar = 0;
  311.                 element.fechar = '<input type="checkbox" name="fechar" <? if ($infoOp["codOp"] == null){ echo "disabled";}?> onchange="associaOp(' + element.codOs +  ',' + element.op +  ',' +  element.fechar + ');" >';
  312.             }
  313.             delete element.codOs;
  314.             delete element.op;
  315.             arrayToTable.push(element);
  316.  
  317.         });
  318.  
  319.         Object.keys(response.listaPagamentos[0]).forEach(function(element, index, array) {
  320.             aoColumnsDataTable.push({
  321.                 "mDataProp": element
  322.             });
  323.         });
  324.        
  325.  
  326.         dataObject.aoColumns = aoColumnsDataTable;
  327.         refreshTabela(arrayToTable, aoColumnsDataTable);
  328.  
  329.     });
  330.    
  331. }
  332.  
  333. function fItensOs(codOs) {
  334.     if (!(codOs > 0) || typeof codOs == "undefined" || codOs == null) {
  335.         warningNotification("Nenhum dublador foi escalado para esta gravação");
  336.         return;
  337.     }
  338.     $('#voucherContent').load("detalhesOs.php", {
  339.         codOs: codOs
  340.     }, function() { //fazer o debug quando o lote estiver zerado, não tiver OSs
  341.         //console.log();
  342.     });
  343.  
  344.     $('#modalVoucher2').modal("show");
  345. }
  346.  
  347. function associaOp(codOs, op, fechar) {
  348.     if(fechar == 1){
  349.         op = null;
  350.     } else if (fechar ==0){
  351.         op = <?= $postCodOp ?>;
  352.     }  
  353.    
  354.     alert(fechar);
  355.     alert(op);
  356.  
  357.     $.post("associaUpdate.php", {
  358.         codOs : codOs,
  359.         op : op,
  360.     }, function(data, source) {
  361.         try {
  362.             carregaTabelaPagamentos();
  363.         } catch (e) {}
  364.         //console.log(data);
  365.     });
  366. }
  367. <?php
  368. }
  369. ?>
  370.  
  371. $(document).ready(function() {
  372.     carregaTabelaPagamentos();
  373.     $('.nomeSelect').select2();
  374.     $('.dataFechamento').datepicker({
  375.         language: "pt-BR",
  376.         format: 'dd/mm/yyyy',
  377.         todayBtn: "linked",
  378.         todayHighlight: true,
  379.         autoclose: true,
  380.     });
  381.     $('#tabelaPagamentos').DataTable( {
  382.         dom: 'Bfrtip',
  383.         buttons: [
  384.             'copy', 'csv', 'excel', 'pdf', 'print'
  385.         ]
  386.     } );
  387.     $('#tabelaPagamentos').DataTable(dataObject);
  388.     $('#tabelaPagamentos').DataTable( {
  389.         dom: 'Bfrtip',
  390.         buttons: [
  391.             'copy', 'csv', 'excel', 'pdf', 'print'
  392.         ]
  393.     } );
  394.     $('#tabelaPagamentos').dataTable().fnClearTable();
  395.     $('#tabelaPagamentos').dataTable().fnAddData(dataObject);
  396.     $('#tabelaPagamentos').on('mouseover', function() {
  397.         $('table a').on('click', function(e) {
  398.             e.preventDefault();
  399.         });
  400.     });
  401. });
  402.  
  403. $('#modalVoucher').on('hidden.bs.modal', function() {});
  404. $('#modalNovaOs').on('hidden.bs.modal', function() {});
  405. $(document).ajaxStart(function() {
  406.     Pace.restart();
  407. });
  408.  
  409.  
  410. $("[data-toggle='toggle']").bootstrapToggle('destroy');
  411. $("[data-toggle='toggle']").bootstrapToggle();  
  412. </script>
  413.         </div>  
  414.     </div>
  415. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement