在SQL(Doctrine)中计算增值税

时间:2014-09-05 06:14:41

标签: symfony doctrine

我试图为商店制作过滤器,我正在努力解决问题。 我有两个字段'价格'这是一个净价和税率,即税率,例如' 22'这是22%。在我的函数中,我尝试使用having子句在查询端进行计算,这里是我试图这样做的方法:

public function getCategoryActiveProductsQueryBuilder(CategoryInterface $category = null, $filter = null, $option = null) {
    $queryBuilder = $this->getCategoryProductsQueryBuilder($category);
    $queryBuilder->leftJoin('p.variations', 'pv')
            ->andWhere('p.parent IS NULL')      // Limit to master products or products without variations
            ->andWhere('p.enabled = :enabled')
            ->andWhere($queryBuilder->expr()->orX('pv.enabled = :enabled', 'pv.enabled IS NULL'))
            ->setParameter('enabled', true);

    $request = Request::createFromGlobals();

    $pfrom = $request->query->get('pfrom');
    $pto = $request->query->get('pto');


    if (is_numeric($pfrom)) {

        $queryBuilder->groupBy('p.price')
                ->andHaving('p.price * (1 + ( p.vatRate / 100)) >= ' . $pfrom . '');
    }

    if (is_numeric($pto)) {

        $queryBuilder->groupBy('p.price')
                ->andHaving('p.price * (1 + ( p.vatRate / 100)) <= ' . $pto . '');
    }

  return $queryBuilder;

我不确定是什么错,但它给了我错误

执行&#39; SELECT DISTINCT时发生异常p0_.id AS id0 FROM product__product p0_ LEFT JOIN media__media m1_ ON p0_.image_id = m1_.id LEFT JOIN media__gallery m2_ ON p0_.gallery_id = m2_.id LEFT JOIN product__product_category p3_ ON p0_.id = p3_.product_id LEFT JOIN product__product p4_ ON p0_.id = p4_.parent_id AND p4_.product_type IN(&#39; m2m.ecommerce.product.cloths&#39;,&#39; m2m.ecommerce.product .shoes&#39;,&#39; m2m.ecommerce.product.women_shoes&#39; m2m.ecommerce.product.accessories&#39; m2m.ecommerce.product.wear_accessories&#39; m2m.ecommerce.product.wear_accessories&#39; )WHERE(p3_.category_id =?AND p0_.parent_id IS NULL AND p0_.enabled =?AND(p4_.enabled =?OR p4_.enabled IS NULL))AND p0_.product_type IN(&#39; m2m.ecommerce.product .cloths&#39;,&#39; m2m.ecommerce.product.shoes&#39;,&#39; m2m.ecommerce.product.women_shoes&#39;,#m2; m2m.ecommerce.product.accessories&#39; ,&#39; m2m.ecommerce.product.wear_accessories&#39;)GROUP BY p0_.price HAVING p0_.price *(1 +(p0_.vat_rate / 100))&gt; = 0 LIMIT 9 OFFSET 0&#39;与params [16,1,1]:

SQLSTATE [42S22]:未找到列:1054未知列&#39; p0_.vat_rate&#39;在&#39;有条款&#39;

我做错了什么?

0 个答案:

没有答案