#include "orderObject.h"
#include "preDefine.h"
#include <QJsonArray>
#include <QDateTime>
#include "QsLog.h"

OrderObject::OrderObject(const OrderObject &p, QObject *parent):BaseObject(parent)
{
    qDeleteAll(proList);
    proList.clear();

    qDeleteAll(disList);
    disList.clear();

    const QMetaObject *m = p.metaObject();
    for( int i=m->propertyOffset(); i<m->propertyCount(); i++)
    {
        QMetaProperty qmp = m->property(i);
        QString key = QString::fromLatin1(qmp.name());
        QVariant value = p.property(key.toUtf8());
        this->setProperty(key.toUtf8(), value);
    }
    foreach (auto ptr, p.proList) {
        ProductObject *product=new ProductObject(*ptr,this);
        this->proList.append(product);
    }

    foreach (auto ptr, p.disList) {
        DiscountObject *dis=new DiscountObject(*ptr,this);
        this->disList.append(dis);
    }

    if(this->refund_status == 0)
        this->refund_status = -100;
}

OrderObject &OrderObject::operator =(const OrderObject &p)
{
    qDeleteAll(proList);
    proList.clear();

    qDeleteAll(disList);
    disList.clear();

    const QMetaObject *m = p.metaObject();
    for( int i=m->propertyOffset(); i<m->propertyCount(); i++)
    {
        QMetaProperty qmp = m->property(i);
        QString key = QString::fromLatin1(qmp.name());
        QVariant value = p.property(key.toUtf8());
        this->setProperty(key.toUtf8(), value);
    }
    foreach (auto ptr, p.proList) {
        ProductObject *product=new ProductObject(*ptr,this);
        this->proList.append(product);
    }

    foreach (auto ptr, p.disList) {
        DiscountObject *dis=new DiscountObject(*ptr,this);
        this->disList.append(dis);
    }

    if(this->refund_status == 0)
        this->refund_status = -100;

    return *this;
}

void OrderObject::FromJson(const QJsonObject &json)
{
    tmp_total = "0.00";

    qDeleteAll(proList);
    proList.clear();

    qDeleteAll(disList);
    disList.clear();

    FetchDataFromJson(json);

    QJsonArray products = json[JSON_PRODUCTS].toArray();
    foreach(QJsonValue product, products)
    {
        QJsonObject proJson = product.toObject();
        ProductObject *proObject = new ProductObject(this);
        proObject->FromJson(proJson);
        proList.append(proObject);
    }

    QJsonArray diss = json[JSON_KEY_DISCOUNTS].toArray();

    if(diss.size() > 0 && diss[0].toObject().contains(JSON_KEY_PRICE))
        tmp_total = QString::number((-(diss[0].toObject()[JSON_KEY_PRICE].toInt())));

    foreach(QJsonValue disduct, diss)
    {
        QJsonObject disJson = disduct.toObject();
        DiscountObject *disObject = new DiscountObject(this);
        disObject->FromJson(disJson);
        disList.append(disObject);
    }


    if(json[JSON_KEY_DELIVERTIME].toInt()==0){
        this->delivery_time = (int)QDateTime::currentDateTime().toTime_t();
    }


    if(this->refund_status == 0)
        this->refund_status = -100;

    return;
}

QString OrderObject::getStore_phone() const
{
    return store_phone;
}

void OrderObject::setStore_phone(const QString &value)
{
    store_phone = value;
}

QString OrderObject::getstore_name() const
{
    return store_name;
}

void OrderObject::setstore_name(const QString &value)
{
    store_name = value;
}

QString OrderObject::getTmp_total() const
{
    return tmp_total;
}

void OrderObject::setTmp_total(const QString &value)
{
    tmp_total = value;
}

int OrderObject::getrefund_status() const
{
    return refund_status;
}

void OrderObject::setrefund_status(const int& v)
{
    refund_status = v;
}

int OrderObject::getservice_fee() const
{
    return service_fee;
}

void OrderObject::setservice_fee(const int &v)
{
    service_fee = v;
}
int OrderObject::getorder_type() const
{
    return order_type;
}

void OrderObject::setorder_type(const int &v)
{
    order_type = v;
}
int OrderObject::getproduct_fee() const
{
    return product_fee;
}

void OrderObject::setproduct_fee(const int &v)
{
    product_fee = v;
}

int OrderObject::getdis_platform_fee() const
{
    return dis_platform_fee;
}

void OrderObject::setdis_platform_fee(const int &v)
{
    dis_platform_fee = v;
}

int OrderObject::getdis_shop_fee() const
{
    return dis_shop_fee;
}

void OrderObject::setdis_shop_fee(const int &v)
{
    dis_shop_fee = v;
}

int OrderObject::getpackage_fee() const
{
    return package_fee;
}

void OrderObject::setpackage_fee(const int &v)
{
    package_fee = v;
}

int OrderObject::getDelivery_type() const
{
    return delivery_type;
}

void OrderObject::setDelivery_type(const int &v)
{
    delivery_type=v;
}

int OrderObject::getstatus() const
{
    return status;
}
void OrderObject::setstatus(const int &v)
{
    status = v;
}

QString OrderObject::getChannel() const
{
    return channel;
}
void OrderObject::setChannel(const QString &v)
{
    channel = v;
}

QString OrderObject::getchannelName() const
{
    return channel_name;
}
void OrderObject::setchannelName(const QString &v)
{
    channel_name = v;
}

QString OrderObject::getphone() const
{
    return phone;
}
void OrderObject::setphone(const QString& v)
{
    phone = v;
}

QString OrderObject::getaddress() const
{
    return address;
}
void OrderObject::setaddress(const QString& v)
{
    address = v;
}

QString OrderObject::getcustomer() const
{
    return customer;
}
void OrderObject::setcustomer(const QString& v)
{
    customer = v;
}

QString OrderObject::getdelivery_party() const
{
    return delivery_party;
}
void OrderObject::setdelivery_party(const QString& v)
{
    delivery_party = v;
}

QString OrderObject::getOrder_id() const
{
    return order_id;
}

void OrderObject::setOrder_id(const QString &v)
{
    order_id = v;
}

QString OrderObject::getposorder_id() const
{
    return posorder_id;
}

void OrderObject::setposorder_id(const QString &v)
{
    posorder_id = v;
}

int OrderObject::getpaid_fee() const
{
    return paid_fee;
}

void OrderObject::setpaid_fee(const int &v)
{
    paid_fee = v;
}

int OrderObject::getshop_fee() const
{
    return shop_fee;
}

void OrderObject::setshop_fee(const int &v)
{
    shop_fee = v;
}

int OrderObject::getrest_fee() const
{
    return rest_fee ;
}

void OrderObject::setrest_fee(const int &v)
{
    rest_fee = v;
}

int OrderObject::getuser_fee() const
{
    return user_fee ;
}

void OrderObject::setuser_fee(const int &v)
{
    user_fee = v;
}

QString OrderObject::getCoupon() const
{
    return coupon;
}

void OrderObject::setCoupon(const QString &v)
{
    coupon = v;
}

QString OrderObject::getRemark() const
{
    return remark;
}

void OrderObject::setRemark(const QString &v)
{
    remark = v;
}

int OrderObject::getCreate_time() const
{
    return create_time;
}

void OrderObject::setCreate_time(const int &v)
{
    create_time = v;
}

int OrderObject::getExpire_time() const
{
    return expire_time;
}

void OrderObject::setExpire_time(const int &v)
{
    expire_time = v;
}

QString OrderObject::getTimestamp() const
{
    return timestamp;
}

void OrderObject::setTimestamp(const QString &v)
{
    timestamp = v;
}

QString OrderObject::getpay_type() const
{
    return pay_type;
}

void OrderObject::setpay_type(const QString &v)
{
    pay_type = v;
}

QString OrderObject::getprintcfg() const
{
    return printcfg;
}

void OrderObject::setprintcfg(const QString &v)
{
    printcfg = v;
}

int OrderObject::gettotal_fee() const
{
    return total_fee;
}

void OrderObject::settotal_fee(const int &v)
{
    total_fee = v;
}
int OrderObject::getdiscount_fee() const
{
    return discount_fee;
}

void OrderObject::setdiscount_fee(const int &v)
{
    discount_fee = v;
}

int OrderObject::getsend_fee() const
{
    return send_fee;
}

void OrderObject::setsend_fee(const int &v)
{
    send_fee = v;
}
int OrderObject::gettotal_Amount() const
{
    return total_amount;
}

void OrderObject::settotal_Amount(const int &v)
{
    total_amount = v;
}

int OrderObject::getchannelNum() const
{
    return channelNum;
}

void OrderObject::setchannelNum(const int &v)
{
    channelNum = v;
}

int OrderObject::getorder_index() const
{
    return order_index;
}

void OrderObject::setorder_index(const int &v)
{
    order_index = v;
}

bool OrderObject::gethas_invoiced() const
{
    return has_invoiced;
}

void OrderObject::sethas_invoiced(const bool &v)
{
    has_invoiced = v;
}

QString OrderObject::getinvoice_title() const
{
    return invoice_title;
}

void OrderObject::setinvoice_title(const QString &v)
{
    invoice_title = v;
}

QString OrderObject::getcourier_name() const
{
    return courier_name;
}

void OrderObject::setcourier_name(const QString &v)
{
    courier_name =v;
}

QString OrderObject::getcourier_phone() const
{
    return courier_phone;
}

void OrderObject::setcourier_phone(const QString &v)
{
    courier_phone = v;
}

QString OrderObject::getstatus_desc() const
{
    return status_desc;
}

void OrderObject::setstatus_desc(const QString &v)
{
    status_desc = v;
}

int OrderObject::getdelivery_time() const
{
    return delivery_time;
}

void OrderObject::setdelivery_time(const int &v)
{
    delivery_time = v;
}

int OrderObject::getUpdate_time() const
{
    return update_time;
}

void OrderObject::setUpdate_time(const int &v)
{
    update_time = v;
}


QString OrderObject::getfm_id() const
{
    return fm_id;
}

void OrderObject::setfm_id(const QString &v)
{
    fm_id = v;
}

int OrderObject::getdelivery_status() const
{
    return delivery_status;
}

void OrderObject::setdelivery_status(const int &v)
{
    delivery_status = v;
}

QStringList OrderObject::getrecords() const
{
    return records;
}

void OrderObject::setrecords(const QStringList &v)
{
    records = v;
}
