PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 2, 2022

[FIXED] How to get value of form field and past it to another form field

 January 02, 2022     yii, yii2     No comments   

Issue

I am developing HR system, I want to calculate how many days off the employee can take. In the HR table I have three attributes.

1- start_date(when the employee starting to work in the company).

2- leavestaken(how many days off the employee took before).

3- leaves(the number of days available for the employee to take off) which equal to=(months between current date and start_date) * 2.5(beacuse each month give 2.5 days off) - leavestaken

third attribute is automated and not from the user, how I can get the first and second attributive values from field forms, use them in the calculation and save the result in the leaves attribute?

I'm using sql and this only for server side


Solution

My solution was

if ($model->load(Yii::$app->request->post())  ) {

       $date = date('m/d/Y');

     $datetime1 = date_create($date); 
     $datetime2 = date_create($model->start_date); 

     // calculates the difference between DateTime objects 
     $interval = $datetime2->diff($datetime1);
     $n_month= $interval->m + 12*$interval->y;
     $model->leaves = ceil($n_month * 2.5) - $model->leavestaken;


        $model->save();


Answered By - Jassim Kadhem
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing