rangka / quickbooks

PHP Library for connecting to QuickBooks.
MIT License
8 stars 11 forks source link

Fix Boolean Condition in Where Clause #5

Closed basherr closed 7 years ago

basherr commented 7 years ago

As of php Boolean value is being converted to either 1 or 0 while Quickbooks does not accept such parameters for Boolean values and will throw error as of value 1/0 is not recognized for such parameter. I've faced the issue while fetching jobs for the customer.

$this->jobService->query()
        ->where('Job', '=', true)
        ->paginate($this->start, $this->offset)
        ->get();//throws error value 1 is not valid for property 'Job'

I've come up with solution by adding a method for Bool values which fix that. Would you please add this code in Query.php or let me know if there is any alternate solution.

    public function whereBool($property, $operator, $constraint) {
        if($constraint === true) {
            $this->where[] = $property. $operator . "true";
        } else {
            $this->where[] = $property. $operator . "false";
        }
        return $this;
    } 

Or another solution would be

    public function whereTrue($property, $operator) {
        $this->where[] = $property. $operator . "true";
        return $this;
    } 

    public function whereFalse($property, $operator) {
        $this->where[] = $property. $operator . "false";
        return $this;
    } 

Thanks

khairulashraff commented 7 years ago

Or you could just send in true as a string instead of Boolean.

->where('Job', '=', 'true')

I'm not a fan of automatically correcting user's input under the hood.

basherr commented 7 years ago

@khairulashraff The suggestion does not seem to work as well. Here's what I get in response from QB. System Failure Error: java.lang.String cannot be cast to java.lang.Boolean

khairulashraff commented 7 years ago

Indeed you are correct. where() is wrapped in a quote hence will always be a string.

I have added (https://github.com/rangka/quickbooks/commit/4f716f895e9ad90e4b0dc64ed2245a1bc6456780) according to your second suggestion except skipping the operator argument. I don't think there's any less or greater for a boolean value.

Thanks!

basherr commented 7 years ago

@khairulashraff Thanks