calculations change number of copies

I have a stock of books. When I get new copies to the stock, I need to update the number of copies

[u]

id book copy[/u]

1 Raven 3

What function could I use and where? maybe afterSave function in the model (?)

I don’t want just update the number in admin. I need to:

  • insert number of new copies in a form

  • let the function handle the calculations

  • update the number of copies in the table

Fx there are 3 copies in the table.I get 2 more copies so I there should be 5 copies instead of 3 in the table.

Hi,

You could use beforeSave for that


protected function beforeSave()

{

    if(parent::beforeSave())

    {

        if($this->isNewRecord)

        {

            // increase your database counter, here 

        }


        return true;

    }

    else

        return false;

}



Thank you for reply.

anyway, the problem is the database counter. table:library, column:copy. I need to change the number of copies based on user input.

meaning user form input + current number of coppies = [b]updated number of copies in the table (column copy)

[/b]