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

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

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源