Jump to content

Accounting script : Counting months


tritina
 Share

Recommended Posts

Hi everyone

I am making an accounting script and I am stuck with couting the number of months of each year : example :

I bought a car on : 2000/04/01, this car can be used for 4 years

So I will need to write down the months for each year and count the value's decreasing.

The first year : 9 months (2000)

Second year : 12 months (2001)

Third year : 12 months (2002)

Fourth year : 12 months (2003)

Fifth year : 3 months (2004)

That's an example, so I can't automate the task since I need to count the months for each year from the date I bought the car.

I am not asking you to make the script for me, I already started coding it and spent more than 5 hours trying to solve this using, _dateadd, _datediff ... and other date fonctions

include <array.au3>
#include <string.au3>
#include <Date.au3>
; Le prix d'achat
$brut = 50000
; Durée de vie
$nb_amor = 4
; Taux d'ammortissement
$taux = 100/$nb_amor
; Date d'achat
$d_achat = "2000/2/01"
; Date d'ammortissement totale
$date_amortissement = _DateAdd("Y", $nb_amor, $d_achat)
; Reprendre les dates exactes
Dim $date_achat
Dim $time
_DateTimeSplit($d_achat, $date_achat, $time)
$nombre_de_mois = $nb_amor*12
; Année courante
$annee_courante = $date_achat[1]
;travailler sur chaque année
if $annee_courante = $date_achat[1] Then
$diff =_datediff("M",$d_achat, $date_achat[1]&$fin_exercice) +1
ConsoleWrite("Le nombre de mois de la première année " & $diff)
$nombre_de_mois -= $diff
ConsoleWrite(@CRLF & "Le nombre de mois restants est maitenant :" & $nombre_de_mois & @CRLF)
EndIf

Until now I did count the number of months for the first year, and the remaining months. But I need to make this automated since I don't know how many years I will be using each time.

Thank you.

Link to comment
Share on other sites

Hi,

Try this :

$aDateBuy = StringSplit("2000/04/01", "/") ;date dachat

$iValidYears = 4 ;pendant combien de temps la voiture peut etre utilisee

ConsoleWrite("year 1 : " & 12 - $aDateBuy[2] & " months (" & $aDateBuy[1] & ")" & @CRLF)

For $iYear = 1 To $iValidYears - 1 ;1ere annee deja calculee et on calculera a part la derniere annee
    ConsoleWrite("year " & $iYear & " : 12 months (" & $aDateBuy[1] + $iYear & ")" & @CRLF)
Next

ConsoleWrite("year " & $iValidYears & " : " & $aDateBuy[2] - 1 & " months (" & $aDateBuy[1] + $iValidYears & ")" & @CRLF)

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...