Problem with control structure if else in function

QuestionsProblem with control structure if else in function
C3media asked 3 years ago

Hello Mr Abu,

I have this function to make some operations…

function update_data($data)
{
// you can also use grid object to execute sql, useful in non-mysql driver

// global $grid;
// $grid->execute_query("MY-SQL");
date_default_timezone_set('America/Bogota');
$date1 = date("Y-m-d H:i:s"); // This is Llegada Col
$date2 = $data["params"]["note"]; //This is Salida Col
// phpgrid_error($data);
//Convert them to timestamps.
$date1Timestamp = strtotime($date1);
$date2Timestamp = strtotime($date2);

//Calculate the difference.
$difference = ($date1Timestamp – $date2Timestamp)/60;
$diferencia= number_format($difference, 0, '.', ',');

$data["params"]["staff_note"] = $date1;

$data["params"]["due_date"] = $diferencia;

if
(($data["params"]["due_date"]) >= ($data["params"]["reference_no"])){
$data["params"]["updated_by"] = (($data["params"]["due_date"]) – ($data["params"]["reference_no"]));
}
else
{
$data["params"]["updated_by"] = 0;
}
endif;

//Recobro = excedió x 500
$data["params"]["updated_at"] = $data["params"]["updated_by"] * (500);

//subtotal = Recobro
$data["params"]["total_discount"] = $data["params"]["updated_at"];
//total = precio – descuento
$data["params"]["total"] = ($data["params"]["total"] – $data["params"]["product_discount"])+ $data["params"]["total_discount"];
//total = total + subtotal
//$data["params"]["total"] = $data["params"]["total"] + $data["params"]["total_discount"]

$data["params"]["grand_total"] = $data["params"]["total"];

$data["params"]["sale_status"] = "Completed";

$data["params"]["total_tax"] = 0;

$data["params"]["paid"] = $data["params"]["total"];

}

I'm trying compare two vars in If Else…

Look fine but not works!

Thanks by your help!

4 Answers
Abu Ghufran answered 3 years ago

You can debug the variables inside callback … and debug message will come as error.

function update_data($data)
{
phpgrid_error($data);

}

By this you can see what is posted in function and see the actual reason.

C3media answered 3 years ago

Hello Mr. Abu,

I tried it, but give me this issue:

Non using If Else sentence control structure.

error
Array ( [id] => 125 [params] => Array ( [id] => 125 [date] => 2017-03-05 09:20:00 [customer] => Shopping express [customer_id] => 3 [reference_no] => 10 [total] => 5000.00 [note] => 2017-03-05 09:23:00 [staff_note] => 0000-00-00 00:00:00 [due_date] => 0 [updated_by] => 0 [updated_at] => 0 [product_discount] => 0 [total_tax] => [total_discount] => 5000 ) )

And using If Else page no load show me this:

The localhost page does not work

The localhost page can not process this request now.

HTTP ERROR 500

I'll look forward for your answer…

Thank you!

Abu Ghufran answered 3 years ago

You need to debug using this function.
It is not error, it shows what data is coming in function.

You can also debug the 2 expressions of IF and see the result.
This is your custom code, you need to check what is data in
$data["params"]["due_date"]
and
$data["params"]["reference_no"]

Then check why IF is working or not.

C3media answered 3 years ago

Ok Abu, I decided to resolve it putting manual subtract (final time – inicial time).

Because finally could be ambiguous result for example:

rate time = 30

inicial time= 12:30:00
final time = 12:50:00

time = final time – inicial time

time duration = 20

Time = time duration – rate time

so subtract is: -10

This is my reason by now, I'll try in future!

Thank you

Your Answer

7 + 17 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?