-
-
Save fayqLs/578752b43c9a6e91b7febf8fd075df0a to your computer and use it in GitHub Desktop.
GERAR PARCELAS FORMATO 30/60/90 DIAS
This file contains hidden or 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 | |
public static function gerarParcelas($param = null) | |
{ | |
try | |
{ | |
(new TRequiredValidator)->validate('DATA INICIAL', $param['data_inicio']); | |
(new TRequiredValidator)->validate('DATA FINAL', $param['data_final']); | |
(new TRequiredValidator)->validate('VALOR TOTAL', $param['valor_total']); | |
$data_inicio = new DateTime(TDate::date2us($param['data_inicio'])); | |
$valor_total = (double) str_replace(',', '.', str_replace('.', '', $param['valor_total'])); | |
$intervalos = explode('/', $param['forma_pagamento']); | |
$parcelas = count($intervalos); | |
if ($parcelas > 0) | |
{ | |
$valor_parcela = $valor_total / $parcelas; | |
$data = new stdClass(); | |
$data->parcelas_valor = []; | |
$data->parcelas_vencimento = []; | |
foreach ($intervalos as $dias) | |
{ | |
$vencimento = clone $data_inicio; | |
$vencimento->modify("+$dias days"); | |
$data->parcelas_valor[] = number_format($valor_parcela, 2, ',', '.'); | |
$data->parcelas_vencimento[] = $vencimento->format('d/m/Y'); | |
} | |
TFieldList::clearRows('fieldList_parcelas'); | |
TFieldList::addRows('fieldList_parcelas', $parcelas - 1); | |
TForm::sendData(self::$formName, $data, false, true, 500); | |
} | |
} | |
catch (Exception $e) | |
{ | |
new TMessage('error', $e->getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment