1 Replies - 1057 Views - Last Post: 22 December 2008 - 11:05 AM Rate Topic: -----

#1 jamie kate   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-December 08

can't add back the number of days i have deducted previously

Post icon  Posted 22 December 2008 - 12:32 AM

Hi all ,
i'm currently working on a project. I have met a problem in adding back the amount i have deducted from my user table.
This is how my logic works, i'm doing on a leave magement where after i apply a particualr leave , it will automically minus the days i have in default,
example : days left - 7 days (before i apply), the next time i go apply the same leave it should appear as
days left - 5 days (assume i applied for 2 days leave previously).


my codes for deduct the number of days :
$hosp_leave = mysql_result(mysql_query("SELECT hosp_leave FROM user WHERE staff_id = $id LIMIT 1"),0);
$hosp_day1 = $hosp_leave - $no_day (the date i have entered);
$hosp_leave = "UPDATE user SET hosp_leave= $hosp_day1 WHERE staff_id = $id";
// run queries
$result = mysql_query($hospitalisation);




Although i can deduct the number of days from my user table, but i have problem adding back the days i have applied if my leave is disapproved by another person.

here is my codes when i tried to added back to my user table under hosp_leave:
$query = mysql_query("SELECT DATEDIFF(end_leave, start_leave) FROM leave_leave WHERE leave_id = $leave_id");
$result1 = mysql_result(($query),0);

// add back to the user table 
if ($leave_type ='HOSPITALISATION')
	{
	$original_hosp_days_remain = mysql_result(mysql_query("SELECT hosp_leave FROM user WHERE staff_id = $id"),0);
	mysql_query("UPDATE user SET hosp_leave = ($original_hosp_days_remain + $result1) WHERE staff_id = $id");
	}

the problem here is that ,
staff_id = $id 
belong to the person who is approving or disapproving this particular leave as there is a
 $access = $_SESSION['id'] 
at the beginning of the code, which is for this particualr person who login to his or her acct, it no longer belong to the person who have applied for the leave.
I have tried many ways to solve my problem , but it juz don't work. =(((
Can anyone help me to solve my problem , thank so much ....

This post has been edited by jamie kate: 22 December 2008 - 09:20 AM


Is This A Good Question/Topic? 0
  • +

Replies To: can't add back the number of days i have deducted previously

#2 ghqwerty   User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: can't add back the number of days i have deducted previously

Posted 22 December 2008 - 11:05 AM

well personally i dont like having sums in queries so i would do

$query = mysql_query("SELECT DATEDIFF(end_leave, start_leave) FROM leave_leave WHERE leave_id = $leave_id");
$result1 = mysql_result(($query),0);

// add back to the user table 
if ($leave_type ='HOSPITALISATION')
	{
	$original_hosp_days_remain = mysql_result(mysql_query("SELECT hosp_leave FROM user WHERE staff_id = $id"),0);
	$new_leave = $original_hosp_days_remain + $result1;
	mysql_query("UPDATE user SET hosp_leave = $new_leave WHERE staff_id = $id");
	}


i dont know if that will change any thing

secondly, could you please explain some more

my idea of what you need so far is.
in your db you have a number with however many leave days the employee has.
then if the apply to take some of that leave then it should deduct the amount of days they want from that number .
if this is approved then the db does not change .
if it is disproved then the days are added back on.

MY SOLUTION
well for starters that is a wierd system but i would say to make it easier
add another column with applying days or something

then when a employee applies for leave for say 3 days it will then add 3 to applying days but do nothing to the total leave days. To prevent a user from requesting say 3 lots of 3 days leave (total 9 days when you only have 7) then when the user applies have it automatically take applying days from total allowed leave to give you a temporary total allowed leave.

then you get whoever is allowing this leave when they press approve it will take away however many days there is in applying days from total leave days

that would solve your problem
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1