Insert account with fortnightly, monthly, quarterly, semi-annual and annual period

2

I have a script to do financial control, in it I inform the value and quantity of each plot. I would like an idea of how to define the space of these parcels to determine whether they will be weekly, biweekly, monthly, quarterly, half-yearly or annual installments. The script I use today generates the installments only monthly.

include 'conectar.php';

$nParcelas = $_POST['PARCELAS'];
$dataPrimeiraParcela = $_POST['VENCIMENTO'];

function calcularParcelas($nParcelas, $dataPrimeiraParcela = null){
  if($dataPrimeiraParcela != null){
    $dataPrimeiraParcela = explode( "/",$dataPrimeiraParcela);
    $dia = $dataPrimeiraParcela[0];
    $mes = $dataPrimeiraParcela[1]-1;
    $ano = $dataPrimeiraParcela[2];

  } else {
    $dia = date("d");
    $mes = date("m")-1;
    $ano = date("Y");
  }

for($x = 1; $x <= $nParcelas; $x++){
$parcela = date("Y-m-d",strtotime("+".$x." month",mktime(0, 0, 0,$mes,$dia,$ano)));
$PAGO = $_POST['PAGO'];
$ID_TIPO = $_POST['ID_TIPO'];
$ID_PESSOA = $_POST['ID_PESSOA'];
$DESCRICAO = $_POST['DESCRICAO'];
$ID_CATEGORIA = $_POST['ID_CATEGORIA'];
$VALOR = $_POST['VALOR'];
$ID_RECEBIMENTO = $_POST['ID_RECEBIMENTO'];
$NP = $x."/".$nParcelas;

   if(mysql_query("INSERT INTO CONTAS
        (ID_TIPO, ID_PESSOA, VENCIMENTO, DESCRICAO, ID_CATEGORIA, VALOR, ID_RECEBIMENTO, PARCELA, ESTADO) 
        VALUES ('".$ID_TIPO."', '".$ID_PESSOA."', '".$parcela."', '".$DESCRICAO."', '".$ID_CATEGORIA."', '".$VALOR."', '".$ID_RECEBIMENTO."', '".$NP."', '".$PAGO."' )"))
  {


    echo "Parcela [".$x."]: ".$parcela."<br/>";

  } else {
    die("Erro ao inserir a parcela ".$x.": ".mysql_error());
  }
}
}
calcularParcelas($nParcelas, $dataPrimeiraParcela);

mysql_close($conexao);
    echo "<a href='conta_nova.php'>Voltar ao sistema</a>";
    
asked by anonymous 31.05.2016 / 21:50

1 answer

0

I use in a financial system currently for plots something similar, and I add in MySQL even with DATE_ADD, so SELECT * FROM table WHERE date = DATE_ADD(CURDATE(), INTERVAL 8 DAY) , there is also DATE_SUB, and of course you can put that in your INSERT

On my system the user chooses on his interface at the time of inserting and would come a $_POST['periodicidade'] and I make a switch to verify, for example:

  • Biweekly: DATE_ADD(CURDATE(), INTERVAL 15 DAY)
  • Monthly: DATE_ADD(CURDATE(), INTERVAL 1 MONTH)
  • Quarterly: DATE_ADD(CURDATE(), INTERVAL 3 MONTH)
  • Semester: DATE_ADD(CURDATE(), INTERVAL 6 MONTH)
  • Annual: DATE_ADD(CURDATE(), INTERVAL 1 YEAR)

And for this reason I am inserting the installments each with the expiration in the correct periodicity

    
01.06.2016 / 22:49