EmpId : | 1 |
Name : | kumar |
Designation : | Assistant |
Department : | ED |
BasicSalary : | 45000 |
Allowance : | 15000 |
Deduction : | 9000 |
Question:
parameters: EmpId,EmployeeName,Designation,Department,Basic Salary,Allowance,Deduction
-
Write a PHP program to read the employee details from the text file and
-
calculate the Gross and Net Salary of the employees.
-
Display the Gross and Net Salary of each employee along with the other details.
-
(No need to update the text file after calculating the gross and net salary).
-
The program, whenexecuted, should ask the file name containing the employee details.
data file name : kumar.txt
{
"EmpId":1,
"Name":"kumar",
"Designation":"Assistant",
"Department":"ED",
"BasicSalary":45000,
"Allowance":15000,
"Deduction":9000
}
< ?php
$name="kumar";
if(isset($_POST['submit'])) // here isset function is using to check where a variable is set or not
{
$name=$_POST['name'];// accessing value from first text field
echo "EMPLOYEE NAME :-".$name;
}
$filename=$name.".txt";
$myfile = fopen($filename, "r") or die("Unable to open file!");
fclose($myfile);
$jsonstring = json_decode(file_get_contents ($filename));
// var_dump( ($jsonstring));
$basic= 0;
$allowance=0;
$deduction=0;
echo"";
foreach($jsonstring as $key=>$value)
{
echo " $key : ";
echo " $value ";
echo "";
echo "\n";
}
echo"
";
//Extracting data from json
$basic= $jsonstring->BasicSalary;
$allowance=$jsonstring->Allowance;
$deduction=$jsonstring->Deduction;
$GrossSalary = ($basic +$allowance) ;
$NetSalary= $GrossSalary-$deduction;
echo "Gross Salary =".$GrossSalary."
";
echo "NetSalary =".$NetSalary."
";
?>