#include "commodityform.h"
#include "ui_commodityform.h"
#include <combodata.h>
#include <QSharedPointer>
#include <qlist.h>
#include "data/commoditytypedata.h"

CommodityForm::CommodityForm(QWidget *parent) :
    AutoForm<CommodityData>(parent),
    ui(new Ui::CommodityForm)
{
    ui->setupUi(this);
    registerBinding(ui->name);
    registerBinding(ui->shortName);
    registerBinding(ui->code);
    registerBinding(ui->price);
    QList<ComboData> vt ;
    vt << ComboData(Enums::HIGH,tr("High")) << ComboData(Enums::FIRST_LOWER,tr("First Lower")) << ComboData(Enums::SECOND_LOWER,tr("Second Lower"));
    registerBinding(ui->vat,vt);
    registerBinding(ui->count);
}

CommodityForm::~CommodityForm()
{
    delete ui;
}

void CommodityForm::registerCombos()
{
    QList<ComboData> ct;
    Service<CommodityTypeData> cts;
    foreach (QSharedPointer<CommodityTypeData> ctd , cts.all()) {
        ComboData cd(ctd);
        ct << cd;
    }
    registerBinding(ui->type,ct);
}
