Problem on check condition on laravel php - php

I have a problem on my laravel code. I want to check condition and show up using dd my code here.
$ca = floatval($sw->terminal_ca); // $sw->terminal_ca from postgresql type number(8,6) = 0.003480
$max_ca = $this->terminal_ca*(1+($this->tolerance/100)); // $this->terminal_ca from postgresql type number(16,4) = 0.0029
// $this->tolerance from postgresql type number(16,4) = 20.0000
dd(
$ca,
$max_ca,
($ca <= $max_ca));
but my result here
not acceptable.
it should be true.
What's wrong on my code?
How can I solve it?

I have given static values in the controller and it's working fine.
Kindly check your type in the database from where you are fetching data dynamically.

I round it before comparison is ok now. Thank #El_Vanja
$ca = round($ca, 6);
$min_ca = round($min_ca, 6);

Related

Vtiger. API create PurchaseOrder

There is a problem over which I am puzzling for the second day.
$purchaseOrders = new PurchaseOrder();
$lists = new ItemLists();
$lists->productid->set(201);
$lists->hdnGrandTotal->set($balance);
$lists->hdnSubTotal->set($balance);
$lists->quantity->set(1);
$lists->listprice->set($balance);
$arrayDataLineItems = [];
$arrayDataLineItems[] = $lists;
$purchaseOrders->dataLineItems->set($arrayDataLineItems);
$purchaseOrders->subject->set($data['caseId']);
$purchaseOrders->purchaseorderNo->set('PO');
$purchaseOrders->vendorid->set($getVendor->id->getCrmValue());
$purchaseOrders->postatus->set('Created');
$purchaseOrders->bill_street->set($getVendor->street->getCrmValue());
$purchaseOrders->ship_street->set($getVendor->street->getCrmValue());
$purchaseOrders->productid->set(201);
$purchaseOrders->balance->set($balance);
$purchaseOrders->assignedUserId->set(6);
$purchaseOrders->conversion_rate->set(1);
$purchaseOrders->currency_id->set('21x1');
$purchaseOrders->hdnTaxType->set('group');
$purchaseOrders->terms_conditions->set('SEE FULL TERMS OF SERVICE AT https://www.salvagedata.com/about/service-terms/');
$valueMapPurchase = $purchaseOrders->toCrmMap();
$crmPurchase = $api->doCreate(PurchaseOrder::getModuleName(),$valueMapPurchase);
There is such a code. It does not add a PurchaseOrder and does not even return any errors. When I do an error check, it returns just Null. Please help, nothing in my head does not climb as it could be corrected.
Now i have database mysql 5.6
Try something like this:
$po = Vtiger_Record_Model::getCleanInstance('PurchaseOrder');
$po->set('subject', 'my po');
$po->set('assigned_user_id', 1);
//set other variables as needed...
$po->save();

PHPUnit test - Failed asserting that actual size 11935 matches expected size 3

I'm brand new to phpunit and attempting to write a test that asserts that three notes were created, but I'm getting all of the notes from the DB.
/** #test */
public function it_gets_notes()
{
$address = Address::first();
$notes = factory(AddressNote::class, 3)->create(['address_id'
=> $address->id]);
$found = $this->notesClass->getData(['address_id' => $address-
>id]);
$this->assertCount(3, $found);
}
}
The Address and AddressNote models are working properly. I think I'm most confused about the getData method, which I know I need for my code coverage. Anyone see what I'm missing that would generate the error in the title?
If you need to check the difference after running your create method, then save $found before and after adding them, and the subtraction will be your number:
public function it_gets_notes()
{
$address = Address::first();
$found = $this->notesClass->getData(['address_id' => $address->id]);
$notes = factory(AddressNote::class, 3)->create(['address_id' => $address->id]);
$foundAfter = $this->notesClass->getData(['address_id' => $address->id]);
$difference = count($foundAfter) - count($found);
$this->assertEquals(3, $difference);
}
Note that you need to use assertEquals() with 3 and the difference now instead of assertCount(), since you're comparing numbers.
I don't know the whole your story, but I assume that your first mistake was that you did not create a testing database.
So, that would be the first step - in addition to your databaseName (whatever the name) create a databaseName_test.
There are some other steps to do - in your ,env file change the name of the databaseName to databaseName_testing - but only while you're doing your testing (and then immediately rollback to your original databaseName).
Yet, the problem can still persist (PHP Unit is not a perfect tool, just like PHP), and here is the hack that can help.
Instead of:
$this->assertEquals(3, $difference);
write:
$this->assertEquals(11935, $difference); //the number is specific for your case
Yep, it's stupid, but it should work...

Sending data from AngularJS to PHP for IF-statement in PHP with perhaps in proper syntax?

I am trying to send data from AngularJS to PHP.
I am sending the data from the controller.js of AngularJS.
I am receiving the data through PHP. The data comes well for others variables.
However, I don't know which part is the problem.
My goal is to have the PHP recognize $step_number and run through the IF-statement in PHP, but even though I send wrong data, it works!
Which means,
if the $step_number in PHP is '2', then the IF-statement in PHP should not work as shown in below. But, it runs!
I thought this was the proper way to write the code as other data are being passed to PHP.
Controller.js
$http.post("../crud/projects_update.php",{
step_number : '1', // This one, I am trying to send, but I don't know whether this is not being sent or the problem is occurred in PHP.
project_id : $scope.project_data.project_id // This works in the PHP. It is well sent.
project_title : $scope.project_data.project_title
}
PHP
require_once 'connect.php';
$data = json_decode(file_get_contents("php://input"));
$step_number = $data->step_number; // This should be received from AngularJS and if the $step_number is not matched in the IF-statement, then the function in { } should not work.
if ($step_number = '1'){
$project_id = $data->project_id;
$project_title = $data->project_title;
$conn->query("UPDATE `projects` SET
`project_title` = '$project_title',WHERE `project_id` = $project_id") or die(mysqli_error());
}
Two things need to change:-
1.Change step_number : '1', to step_number : 1,
2.Change
if ($step_number = '1'){ //this is assignment not comparison
to:-
if ($step_number == 1){ // now it's comparison

variable sphinx filter with PHP

i m sorry for my english, i m french, i need your help for one thing please :
It s about filtering in php sphinx
this my code :
$filtres= array();
if(isset($_POST['Pharmacie']) and $_POST['Pharmacie'] ="1" ){ $filtres[]= 1;}
if(isset($_POST['Autres']) and $_POST['Autres'] ="8" ){ $filtres[] = 8;}
$varfiltres = 'array('.implode(" , ",$filtres).')';
if($filtres != array()){
$sphinx->SetFilter('Type', array(implode(",",$filtres)));
}
i have error :
Warning: assert(): Assertion failed in \sphinxapi.php on line 850
in case only one variable isset (pharmacie or Autres) that work!
also if i do $sphinx->SetFilter('Type', array(1,8)) it work!
thanks for help.
SetFilter, takes an array directly. With:
$sphinx->SetFilter('Type', array(implode(",",$filtres)));
you are first converting the Array to a String, and then putting it in an new array. Don't do that :)
This is all that is needed:
$sphinx->SetFilter('Type', $filtres);

Problem in implementing Sphinx API along with Cake php

I am working on project where I need to implement SphinxSearch with Cake php. So I am simply trying to use a component and behaviour into it. The link to it, is :-
http://bakery.cakephp.org/articles/eugenioclrc/2010/07/10/sphinx-component-and-behavior
I am requesting Sphinx API like below :
$sphinx = array('matchMode' => SPH_MATCH_ALL, 'sortMode' => array(SPH_SORT_EXTENDED => '#relevance DESC'));
$results = $this->ModelName->find('all', array('search' => 'Search_Query', 'sphinx' => $sphinx));
pr($result);
For above it is working fine ,but when I tried to minimise the response time querying to a particular field of the table (using extended match modes,i.e. SPH_MATCH_EXTENDED2) , Sphinx just fails to output any result. The extended query which I used is given below :-
$sphinx = array('matchMode' => SPH_MATCH_EXTENDED2, 'sortMode' => array(SPH_SORT_EXTENDED => '#relevance DESC'));
$results = $this->ModelName->find('all', array('search' => '#Field_name Search_Query', 'sphinx' => $sphinx));
pr($results);
Can anyone recognise where am I going wrong with it? Please help if I am going wrong some where.
Thanks in advance.
Btw, when you use EXTENDED2 mode make sure your rank mode is set accordingly.
Edit:
Anyway back to you problem, looking at that component/behavior code you can see right away that no error checking is done whatsoever. Try changing the code a bit so you can at least see the errors and/or warnings.
Component
if(!isset($query['search'])){
$result = self::$sphinx->Query('', $indexes);
} else {
$result = self::$sphinx->Query($query['search'], $indexes);
}
if ($result === false) {
// throw new SphinxException();
die(self::$sphinx->GetLastError());
}
$warn = self::$sphinx->GetLastWarning();
if ($warn) echo $warn;
Behavior
$result=$this->runtime[$model->alias]['sphinx']->search($s);
if ($result === false) {
die($this->runtime[$model->alias]['sphinx']->GetLastError());
}
$warn = $this->runtime[$model->alias]['sphinx']->GetLastWarning();
if ($warn) echo $warn;
I hope that helps.
As you said ,
Sphinx just fails to output any result.
That means it's an error :
Please check whether you have added the specific field to the indexing by using sql_query
Also check if the field you are searching for is not an attribute
As per the sphinx documentation :
Attributes, unlike the fields, are not full-text indexed. They are stored in the index, but it is not possible to search them as full-text, and attempting to do so results in an error.

Categories