# good practises of sequentiel codefication and calculationRSS

## 3 replies

Last post Jul 18, 2017 11:22 AM by AngelinaJolie

• bensam16

Member

3 Points

50 Posts

### good practises of sequentiel codefication and calculation

hello all

I need to create asp.net mvc application for "dra" management

A dra is a transaction established by a organizational structure, contains purchases or services rendered by that structure sent in a slip (bordereau) to the finance department in order to reimburse the expenses

Each dra is numbered (codified) and the DRA numbering contains: Code of the structure in 3 three concatenated characters with a sequential number contains 3 digit

The sequential number starts at 001 each beginning of the year. The numbering of the first DRA of the year is xxx001, afterwards for the second dra it is xxx002 and so on (xxx: structure code that establishes dra)

Each structure contains a crate contains a sum of money to pay for its expenses and there remains an amount in this fund(crate) after the disbursements of each dra. This amount is the balance remaining in crate

The balance shall be determined by the following formula:

Final balance (balance after disbursements) = initial balance (crate balance before disbursement) + sum of cash receipts (previous dra reimburse) - amount of disbursements of this dra (total of expenses)

and the Final balance will become the intial balance in next dra and so on

Thank you for guiding me please how to implement this numbering in application asp.net mvc and how to implement the balance and its calculation?

have a good day

• AngelinaJoli...

Contributor

5260 Points

2307 Posts

### Re: good practises of sequentiel codefication and calculation

Hi bensam16,

If you are using EF code first, i think it is not difficult to implement the function;

First ,001 ,xxx002  ,it represent which one  ,

>> sum of cash receipts

For one :

1:  db.cash .where(a=> a.** =="001").Sum(b=> b.cash receipts)

>>amount of disbursements of this dra (total of expenses)

2: same as 1;

Then ,it could get according navigation collection via code first directly(for example: var q=db.maintable.Where(a=>a.maintableid==1).FirstOrDefault() ,then every one in q.cashes collection maintableid all is 1 ).

So,here is the generic idea:

`var FinalbalanceList=from a in db.maintable      select new {balance = a. balance + a. cashes.Sum(b=>b. cash receipts) - a.disbursements .Sum(c=>c. ** )) } .ToList();`

Hope it is helpful to you.

With Regards,

Angelina Jolie

MSDN Community Support
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
• bensam16

Member

3 Points

50 Posts

### Re: good practises of sequentiel codefication and calculation

#### AngelinaJolie

First ,001 ,xxx002  ,it represent which one  ,

xxx001, xxx002 represente the code of dra  Which is established by a structure xxx ( xxx is the code of  organisationnel structure  and 001 saquentiel numcer)

and i want that a code of dra is going to be Displayed and incremented automatically whenever the user wants to create a new dra (first dra created its code xxx001, if the user will create a second dra then its code xxx002 and so on)

i have created table for store the sequentiel number it containes three columns :

1. the first column for a structure,
2. the seconde for sequentiel number of 3 digits
3. and third for year

and i created a trigger for insert data in table of sequentiel number every begining of year

#### AngelinaJolie

var FinalbalanceList=from a in db.maintable
select new {balance = a. balance + a. cashes.Sum(b=>b. cash receipts) - a.disbursements .Sum(c=>c. ** )) } .ToList();

i have created two tables in database that have two column for the initial balance and final balence and

i use this  linq like your code  and inserte the result (number not list) in this table (final balence column) every save of each dra in database

but there is a way better then these approaches? Is there best practices

thank you AngilinaJolie for your help

• AngelinaJoli...

Contributor

5260 Points

2307 Posts

### Re: good practises of sequentiel codefication and calculation

Hi bensam,

#### bensam16

i use this  linq like your code  and inserte the result (number not list) in this table (final balence column) every save of each dra in database

#### bensam16

but there is a way better then these approaches? Is there best practices

I think your way just like what Blank to provide the final balance records, but I guess your code is good for calculation which in a certain period of time;

Best Regards,

Angelina Jolie

MSDN Community Support