|
| 1 | +<?php |
| 2 | + |
| 3 | +session_start(); |
| 4 | + |
| 5 | +include_once("../check.php"); |
| 6 | + |
| 7 | +include_once("../defines.php"); |
| 8 | +include_once("../ClassLibrary/Calendar.php"); |
| 9 | +include_once("../ClassLibrary/DataConnector.php"); |
| 10 | +include_once("../DataAccessObjects/BillingDAO.php"); |
| 11 | +include_once("../DataTransferObjects/BillingDTO.php"); |
| 12 | +include_once("../DataAccessObjects/MailingDAO.php"); |
| 13 | +include_once("../DataTransferObjects/MailingDTO.php"); |
| 14 | +include_once("../DataAccessObjects/BusinessPartnerDAO.php"); |
| 15 | +include_once("../DataTransferObjects/BusinessPartnerDTO.php"); |
| 16 | +include_once("../DataAccessObjects/ContractDAO.php"); |
| 17 | +include_once("../DataTransferObjects/ContractDTO.php"); |
| 18 | + |
| 19 | + |
| 20 | +$mailingId = 0; |
| 21 | +if (isset($_REQUEST["mailingId"]) && ($_REQUEST["mailingId"] != 0)) { |
| 22 | + $mailingId = $_REQUEST["mailingId"]; |
| 23 | +} |
| 24 | + |
| 25 | +// Abre a conexao com o banco de dados |
| 26 | +$dataConnector = new DataConnector('both'); |
| 27 | +$dataConnector->OpenConnection(); |
| 28 | +if (($dataConnector->mysqlConnection == null) || ($dataConnector->sqlserverConnection == null)) { |
| 29 | + echo 'Não foi possível se connectar ao bando de dados!'; |
| 30 | + exit; |
| 31 | +} |
| 32 | + |
| 33 | +// Cria o objeto de mapeamento objeto-relacional |
| 34 | +$billingDAO = new BillingDAO($dataConnector->mysqlConnection); |
| 35 | +$billingDAO->showErrors = 1; |
| 36 | +$mailingDAO = new MailingDAO($dataConnector->mysqlConnection); |
| 37 | +$mailingDAO->showErrors = 1; |
| 38 | +$businessPartnerDAO = new BusinessPartnerDAO($dataConnector->sqlserverConnection); |
| 39 | +$businessPartnerDAO->showErrors = 1; |
| 40 | +$contractDAO = new ContractDAO($dataConnector->mysqlConnection); |
| 41 | +$contractDAO->showErrors = 1; |
| 42 | + |
| 43 | + |
| 44 | +// Recupera o mailing correspondente ao faturamento |
| 45 | +$mailing = $mailingDAO->RetrieveRecord($mailingId); |
| 46 | + |
| 47 | +// Recupera o cliente |
| 48 | +$businessPartner = $businessPartnerDAO->RetrieveRecord($mailing->businessPartnerCode); |
| 49 | + |
| 50 | +// Recupera o contrato caso o mailing faça referencia a um |
| 51 | +if ($mailing->contrato_id != 0) |
| 52 | + $contract = $contractDAO->RetrieveRecord($mailing->contrato_id); |
| 53 | + |
| 54 | +// Calcula o valor de implantação a ser cobrado/parcelado |
| 55 | +$acrescimoDesconto = ""; |
| 56 | +$observacoes = ""; |
| 57 | +if (isset($contract)) { |
| 58 | + if (($contract->valorImplantacao > 0) && ($contract->quantParcelasImplantacao > 0)) { |
| 59 | + if ($contract->parcelaAtual <= $contract->quantParcelasImplantacao) { |
| 60 | + $infoParcela = $contract->parcelaAtual."/".$contract->quantParcelasImplantacao; |
| 61 | + $acrescimoDesconto = $contract->valorImplantacao / $contract->quantParcelasImplantacao; |
| 62 | + $observacoes = "PARCELA ".$infoParcela." DE IMPLANTAÇÃO: R$ ".number_format($acrescimoDesconto, 2, ',', '.'); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +?> |
| 68 | + |
| 69 | + <form name="fDados" action="Frontend/mailing/acaoFaturamento.php" method="post" > |
| 70 | + <input type="hidden" name="acao" value="store" /> |
| 71 | + <input type="hidden" name="businessPartnerCode" value="<?php echo $businessPartner->cardCode; ?>" /> |
| 72 | + <input type="hidden" name="businessPartnerName" value="<?php echo $businessPartner->cardName; ?>" /> |
| 73 | + <input type="hidden" name="mailingId" value="<?php echo $mailingId; ?>" /> |
| 74 | + |
| 75 | + <label class="left" style="width:45%; text-align: left;">Data Inicial<br/> |
| 76 | + <input class="datepick" type="text" name="dataInicial" style="width:95%;height:25px;" value="" ></input> |
| 77 | + </label> |
| 78 | + <label class="left" style="width:45%; text-align: left;">Data Final<br/> |
| 79 | + <input class="datepick" type="text" name="dataFinal" style="width:95%;height:25px;" value="" ></input> |
| 80 | + </label> |
| 81 | + <div style="clear:both;"> |
| 82 | + <br/> |
| 83 | + </div> |
| 84 | + |
| 85 | + <label class="left" style="width:45%; text-align: left;">Mês de Referência<br/> |
| 86 | + <select name="mesReferencia" style="width:95%;height:30px;" ><?php $calendar = new Calendar(); echo $calendar->GetMonthOptions(0); ?></select> |
| 87 | + </label> |
| 88 | + <label class="left" style="width:45%; text-align: left;">Ano de Referência<br/> |
| 89 | + <input type="text" name="anoReferencia" style="width:95%;height:30px;" value="" ></input> |
| 90 | + </label> |
| 91 | + <div style="clear:both;"> |
| 92 | + <br/> |
| 93 | + </div> |
| 94 | + |
| 95 | + <label class="left" style="width:45%; text-align: left;">Multa Recisoria<br/> |
| 96 | + <input type="text" name="multaRecisoria" style="width:95%;height:25px;" value="" ></input> |
| 97 | + </label> |
| 98 | + <label class="left" style="width:45%; text-align: left;">Outros<br/> |
| 99 | + <input type="text" name="outros" style="width:95%;height:25px;" value="" ></input> |
| 100 | + </label> |
| 101 | + <div style="clear:both;"> |
| 102 | + <br/> |
| 103 | + </div> |
| 104 | + |
| 105 | + <label class="left" style="width:99%; text-align: left;">Acréscimo/Desconto<br/> |
| 106 | + <input type="text" readonly="readonly" name="acrescimoDesconto" style="width:98%;height:25px;" value="<?php echo $acrescimoDesconto; ?>" ></input> |
| 107 | + </label> |
| 108 | + <div style="clear:both;"> |
| 109 | + <br/> |
| 110 | + </div> |
| 111 | + |
| 112 | + <label class="left" style="width:99%; text-align: left;">Observações<br/> |
| 113 | + <textarea name="obs" style="width:98%;height:50px;" ><?php echo $observacoes; ?></textarea> |
| 114 | + </label> |
| 115 | + <div style="clear:both;"> |
| 116 | + <br/> |
| 117 | + </div> |
| 118 | + |
| 119 | + <div class="left" style="width:99%; text-align: center;"> |
| 120 | + <input id="btnOK" type="button" value="OK" style="width:80px; height:30px;"></input> |
| 121 | + </div> |
| 122 | + </form> |
| 123 | + |
| 124 | +<?php |
| 125 | +// Fecha a conexão com o banco de dados |
| 126 | +$dataConnector->CloseConnection(); |
| 127 | +?> |
| 128 | + |
| 129 | + |
| 130 | +<script type="text/javascript" > |
| 131 | + |
| 132 | + // Seta o formato de data do datepicker para manter compatibilidade com o formato do MySQL |
| 133 | + $('.datepick').datepicker({dateFormat: 'yy-mm-dd'}); |
| 134 | + |
| 135 | + function OkButtonClicked() { |
| 136 | + var startDate = $("input[name=dataInicial]").val(); |
| 137 | + var endDate = $("input[name=dataFinal]").val(); |
| 138 | + if (!(startDate) || !(endDate) || (startDate == '') || (endDate == '')) { |
| 139 | + alert('É necessário preencher as datas inicial e final!'); |
| 140 | + return; |
| 141 | + } |
| 142 | + |
| 143 | + var anoReferencia = $("input[name=anoReferencia]").val(); |
| 144 | + if (!(anoReferencia) || (anoReferencia == '')) { |
| 145 | + alert('É necessário preencher o mês e o ano de referência!'); |
| 146 | + return; |
| 147 | + } |
| 148 | + |
| 149 | + var acrescimoDesconto = $("input[name=acrescimoDesconto]").val(); |
| 150 | + acrescimoDesconto = parseFloat(acrescimoDesconto) || 0; |
| 151 | + $("input[name=acrescimoDesconto]").val(acrescimoDesconto); |
| 152 | + |
| 153 | + |
| 154 | + // Faz um chamada sincrona a página de inserção |
| 155 | + var targetUrl1 = 'Frontend/mailing/acaoFaturamento.php'; |
| 156 | + $.ajax({ type: 'POST', url: targetUrl1, data: $("form").serialize(), success: function(response) { alert(response); }, async: false }); |
| 157 | + |
| 158 | + // Fecha o dialogo |
| 159 | + $("#addDialog").dialog('close'); |
| 160 | + |
| 161 | + // Recarrega a lista de registros de faturamento |
| 162 | + var targetUrl2 = 'AjaxCalls/GetBillingRecords.php?mailingId=<?php echo $mailingId; ?>'; |
| 163 | + $("#billingRecords").load(targetUrl2); |
| 164 | + } |
| 165 | + |
| 166 | + function TotalChanged() |
| 167 | + { |
| 168 | + var multaRecisoria = $("input[name=multaRecisoria]").val(); |
| 169 | + multaRecisoria = parseFloat(multaRecisoria) || 0; |
| 170 | + var outros = $("input[name=outros]").val(); |
| 171 | + outros = parseFloat(outros) || 0; |
| 172 | + |
| 173 | + $("input[name=acrescimoDesconto]").val(multaRecisoria + outros); |
| 174 | + } |
| 175 | + |
| 176 | + $("input[name=multaRecisoria]").keyup(function() { TotalChanged(); }); |
| 177 | + $("input[name=outros]").keyup(function() { TotalChanged(); }); |
| 178 | + |
| 179 | + $("#btnOK").button({ icons: {primary:'ui-icon-circle-check'} }).click(function() { OkButtonClicked(); }); |
| 180 | + |
| 181 | +</script> |
0 commit comments