#include "paperDef.h"
#include <QStringList>
int g_ItemOrderIndex;

QString Arab2Sinogram(int num)
{
    QStringList lNum = {QString::fromLocal8Bit("零"),
                        QString::fromLocal8Bit("一"),
                        QString::fromLocal8Bit("二"),
                        QString::fromLocal8Bit("三"),
                        QString::fromLocal8Bit("四"),
                        QString::fromLocal8Bit("五"),
                        QString::fromLocal8Bit("六"),
                        QString::fromLocal8Bit("七"),
                        QString::fromLocal8Bit("八"),
                        QString::fromLocal8Bit("九")};
    QStringList lBit = {"", QString::fromLocal8Bit("十"),
                        QString::fromLocal8Bit("百"),
                        QString::fromLocal8Bit("千")};
    QStringList lTep = {"",
                        QString::fromLocal8Bit("万"),
                        QString::fromLocal8Bit("亿"),
                        QString::fromLocal8Bit("万"),
                        QString::fromLocal8Bit("亿"),
                        QString::fromLocal8Bit("万"),
                        QString::fromLocal8Bit("亿")};
    std::vector<char> input;
    QString output;
    bool bZero = false;

    int n = (int)log10((float)num) + 1;
    for (int i = 0; i < n; i++, num = num / 10)
    {
        input.push_back((char)(num % 10));
    }
    for (int i = n - 1; i >= 0; i--)
    {
        num = input[i];
        if (num == 0)
        {
            bZero = true;
        }
        else if (num > 0 && bZero)
        {
          output += lNum[0];
          bZero = false;
        }
        if (num > 0)
        {
          output += lNum[num];
          output += lBit[(i) % 4];
        }
        if (i % 4 == 0)
        {
          output += lTep[i / 4];
          bZero = true;
        }
    }
    if (output.isEmpty())
    {
        output += lNum[0];
    }

    return output;
}
