Sign in to follow this  
Followers 0
tritina

Accounting script : Counting months

3 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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
1 person likes this

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Thanks a lot that's really what I was looking for

Share this post


Link to post
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
Sign in to follow this  
Followers 0