Formula to cancel debit tickets [closed]

1

I have the following data in sql.

idImporte   idmovimientotipo   idcuentacorriente             importe                                 saldoInicial
----------- ------------------- -------------------- --------------------------------------- -----------------
2           2                   25089                342.6800                                342.6800
3           2                   25115                341.0100                                341.0100
4           2                   25141                337.9300                                337.9300
5           2                   25162                336.2600                                336.2600
6           2                   25172                334.6900                                334.6900
7           2                   25193                333.2300                                333.2300
107         2                   26354                174.3100                                174.3100
108         2                   26367                172.7000                                172.7000
109         2                   26374                171.0900                                171.0900
1           1                   25071                344.3000                                344.3000
15          1                   25315                320.4400                                320.4400
16          1                   25329                318.8800                                318.8800
17          1                   25345                317.2600                                317.2600
18          1                   25359                315.6400                                315.6400
19          1                   25369                314.1800                                314.1800

The idMovimientoType correspond to the type of invoice

  • They are those of Debit
  • They are those of Credit
  • The process that I must generate is the following:

    Always taking the least amount of information that is already ordered, start to go through and verify if I have credit bills, if you find, take the least amount of a debit invoice.

    With the credit invoice, I must cancel the total of the debit invoice, if the credit invoice does not reach it, I should take another one more credit following the order of the minor IDImport.

    If the credit invoice was greater than the debit invoice, I cancel that debit invoice and the remainder I use for the next debit invoice. I must register that idCuentacurrent account canceled to idCuentacurrent account.

    Variations in the amount of the invoices must be recorded in the Initial Balance column, remaining at zero when the cancellation is complete or registering the variation that suffered the credit against the debit. The process ends when there are no more credit bills.

    Sorry for not being able to present an advance, I really could not get it, I hope some guidance on how to deal with this process.

        
    asked by Sebastian 31.08.2018 в 00:41
    source

    0 answers