doukong1897
2014-02-05 11:39
浏览 28
已采纳

我的代码在OpenCart中显示增值税状态有什么问题?

I am having a little trouble writing a piece of code for OpenCart. First of all please let me say I really do appreciate any help and support offered and I certainly do not take it for granted! Also all of my experience with code is self tutored so please forgive me for my lack of knowledge, but you have to start somewhere! :)

I have a piece of code from my OpenCart installation that generates an invoice for customers.

The code looks like this:

            foreach ($products as $product) {
                $option_data = array();

                $options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);

                foreach ($options as $option) {
                    $option_data[] = array(
                        'name'  => $option['name'],
                        'value' => $option['value']
                    );
                }

                if ($product['tax'] > 0) {
                    $price_inc = (($product['price'] / 100) * 20);
                    $prod_tax = (float) $product['tax']."%";
                } else {
                    $price_inc = 0;
                    $prod_tax = "";
                }

                $total_inc = $price_inc * $product['quantity'];

                $product_data[] = array(
                    'name'     => $product['name'],
                    'model'    => $product['model'],
                    'option'   => $option_data,
                    'quantity' => $product['quantity'],
                    'price'    => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']),
                    'total'    => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value']),
                    'tax' => $prod_tax,
                    'price_inc'    => $this->currency->format($price_inc, $order_info['currency_code'], $order_info['currency_value']),
                    'total_inc'    => $this->currency->format($total_inc, $order_info['currency_code'], $order_info['currency_value'])
                );
            }

I am trying to create a new field for our invoice that displays the letter "Z" if the product has zero VAT and the letter V if the product has vat. I have tried to modify the code to declare $vat_status but I seem to have done something wrong.

            foreach ($products as $product) {
                $option_data = array();

                $options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);

                foreach ($options as $option) {
                    $option_data[] = array(
                        'name'  => $option['name'],
                        'value' => $option['value']
                    );
                }

                if ($product['tax'] > 0) {
                    $price_inc = (($product['price'] / 100) * 20);
                    $prod_tax = (float) $product['tax']."%";
                } else {
                    $price_inc = 0;
                    $prod_tax = "";
                }

                if ($product['tax'] > 0) {
                    $vat_status = V;
                } else {
                    $vat_status = Z;
                }

                $total_inc = $price_inc * $product['quantity'];

                $product_data[] = array(
                    'name'     => $product['name'],
                    'model'    => $product['model'],
                    'option'   => $option_data,
                    'quantity' => $product['quantity'],
                    'price'    => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']),
                    'total'    => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value']),
                    'tax' => $prod_tax,
                    'price_inc'    => $this->currency->format($price_inc, $order_info['currency_code'], $order_info['currency_value']),
                    'total_inc'    => $this->currency->format($total_inc, $order_info['currency_code'], $order_info['currency_value']),
                    'vat_status'     => $product['vat_status']
                );
            }

Any help is much appreciated and once again I apologize for my lack of knowledge. I come to Stack Overflow as a last resort :)

  • Tom
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongwuwu6104 2014-02-05 11:54
    已采纳

    Just change this line of code

    'vat_status'     => $product['vat_status']
    

    to

    'vat_status'     => $vat_status
    

    $product['vat_status'] does not exist in the first place

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题