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

我的代码在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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告