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

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

报告相同问题?

悬赏问题

  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA