void PurchaseEditor::addItemToList()
{
  ProductInfo pInfo;
  Azahar *myDb = new Azahar;
  myDb->setDatabase(db);
  bool ok=false;

  if (ui->editCode->text().isEmpty()) ui->editCode->setFocus();
  else if (ui->editDesc->text().isEmpty()) ui->editDesc->setFocus();
  else if (ui->editPoints->text().isEmpty()) ui->editPoints->setFocus();
  else if (ui->editCost->text().isEmpty()) ui->editCost->setFocus();
  else if (ui->editTax->text().isEmpty()) ui->editTax->setFocus();
  else if (ui->editFinalPrice->text().isEmpty()) ui->editFinalPrice->setFocus();
  else if (ui->editQty->text().isEmpty() || ui->editQty->text()=="0") ui->editQty->setFocus();
  else if ((ui->editUtility->text().isEmpty() && ui->editFinalPrice->text().isEmpty()) || ui->editFinalPrice->text().toDouble()<=ui->editCost->text().toDouble() ) ui->editFinalPrice->setFocus();
  else if (ui->groupBoxedItem->isChecked() && (ui->editItemsPerBox->text().isEmpty() || ui->editItemsPerBox->text()=="0"))  ui->editItemsPerBox->setFocus();
  else if (ui->groupBoxedItem->isChecked() && (ui->editPricePerBox->text().isEmpty() || ui->editPricePerBox->text()=="0")) ui->editPricePerBox->setFocus();
  else ok = true;

  if (ok) {
    ProductInfo info = myDb->getProductInfo( QString::number( getCode() ) );
    //FIX BUG: dont allow enter new products.. dont know why? new code on 'continue' statement.
    if (info.code == 0) { //new product
      info.code = getCode();
      info.stockqty = 0; //new product
      info.lastProviderId=1; //for now.. fixme in the future
    }
    //update p.info from the dialog
    info.desc    = getDescription();
    info.price   = getPrice();
    info.cost    = getCost();
    info.tax     = getTax1();
    info.extratax= getTax2();
    info.photo   = getPhotoBA();
    info.units   = getMeasureId();
    info.category= getCategoryId();
    info.utility = getProfit();
    info.points  = getPoints();
    info.purchaseQty = getPurchaseQty();
    info.validDiscount = productExists; //used to check if product is already on db.

    if (info.isAGroup) {
      // get each product fo the group/pack
      QStringList list = gelem.split(",");
      for (int i=0; i<list.count(); ++i) {
        QStringList tmp = list.at(i).split("/");
        if (tmp.count() == 2) { //ok 2 fields
          qulonglong  code  = tmp.at(0).toULongLong();
          pInfo = myDb->getProductInfo(QString::number(code));
          pInfo.purchaseQty = getPurchaseQty();
          pInfo.validDiscount = true; // all grouped products exists
          insertProduct(pInfo); ///inserting each product of the group
        } // correct fields
      }//for each element
    } else insertProduct(info);

    resetEdits();
    ui->editCode->setFocus();
  }
}
PurchaseEditor::PurchaseEditor( QWidget *parent)
: KDialog( parent )
{
    ui = new PurchaseEditorUI( this );
    setMainWidget( ui );
    setCaption( i18n("Purchase") );
    setButtons( KDialog::Ok|KDialog::Cancel );
    setDefaultButton(KDialog::None);

    ui->editDonor->setCustomLayout(1);

    ui->btnAddItem->setDefault(true);

    connect( ui->btnAddItem, SIGNAL( clicked() ), this, SLOT( addItemToList() ) );

    connect(ui->btnRemoveItem, SIGNAL( clicked() ), SLOT( deleteSelectedItem() ) );

    ui->chIsAGroup->setDisabled(true);

    
    QString path = KStandardDirs::locate("appdata", "styles/");
    path = path+"tip.svg";
    errorPanel = new MibitTip(this, ui->widgetPurchase, path, DesktopIcon("dialog-warning",32) );
    

    lastCode = "";
    status = estatusNormal;
    productExists = false;
    productsHash.clear();
    resetEdits();
    totalBuy = 0.0;
    itemCount = 0.0;
    ui->editDateTime->setDateTime(QDateTime::currentDateTime());
    QTimer::singleShot(500, this, SLOT(setupTable()));
}
Beispiel #3
0
void freeAllUndoLists(EdStruct *xx)
/*
 * Free all undos
 */
{
    freeUndoLists(xx, FREE_RECLAIM);
    DBI_discarded_undos(xx) = 0;
    resetEdits(xx);
}
PurchaseEditor::PurchaseEditor( QWidget *parent )
: KDialog( parent )
{
    ui = new PurchaseEditorUI( this );
    setMainWidget( ui );
    setCaption( i18n("Purchase") );
    setButtons( KDialog::Ok|KDialog::Cancel );
    setDefaultButton(KDialog::None);
    ui->btnAddItem->setDefault(true);

    //Set Validators for input boxes
    QRegExp regexpC("[0-9]{1,13}"); //(EAN-13 y EAN-8) .. y productos sin codigo de barras?
    QRegExpValidator * validatorEAN13 = new QRegExpValidator(regexpC, this);
    ui->editCode->setValidator(validatorEAN13);
    ui->editTax->setValidator(new QDoubleValidator(0.00, 999999999999.99, 3,ui->editTax));
    ui->editExtraTaxes->setValidator(new QDoubleValidator(0.00, 999999999999.99, 3,ui->editExtraTaxes));
    ui->editCost->setValidator(new QDoubleValidator(0.00, 999999999999.99, 3, ui->editCost));
    ui->editPoints->setValidator(new QIntValidator(0,999999999, ui->editPoints));
    ui->editFinalPrice->setValidator(new QDoubleValidator(0.00,999999999999.99, 3, ui->editFinalPrice));
    ui->editItemsPerBox->setValidator(new QDoubleValidator(0.00,999999999999.99, 2, ui->editItemsPerBox));
    ui->editPricePerBox->setValidator(new QDoubleValidator(0.00,999999999999.99, 2, ui->editPricePerBox));
    ui->editQty->setValidator(new QDoubleValidator(0.00,999999999999.99, 2, ui->editQty));

    connect( ui->btnPhoto          , SIGNAL( clicked() ), this, SLOT( changePhoto() ) );
    connect( ui->btnCalculatePrice , SIGNAL( clicked() ), this, SLOT( calculatePrice() ) );
    connect( ui->editItemsPerBox , SIGNAL( textEdited(const QString &) ), this, SLOT( calculatePrice() ) );
    connect( ui->editPricePerBox , SIGNAL( textEdited(const QString &) ), this, SLOT( calculatePrice() ) );
    connect( ui->editCost , SIGNAL( textEdited(const QString &) ), this, SLOT( calculatePrice() ) );
    connect( ui->editTax , SIGNAL( textEdited(const QString &) ), this, SLOT( calculatePrice() ) );
    connect( ui->editExtraTaxes , SIGNAL( textEdited(const QString &) ), this, SLOT( calculatePrice() ) );
    connect( ui->editUtility , SIGNAL( textEdited(const QString &) ), this, SLOT( calculatePrice() ) );
    connect( ui->editCode, SIGNAL(textEdited(const QString &)), SLOT(checkIfCodeExists()));
    connect( ui->editCode, SIGNAL(returnPressed()), ui->editQty, SLOT(setFocus()));
    connect( ui->btnAddItem, SIGNAL( clicked() ), this, SLOT( addItemToList() ) );
    connect(ui->groupBoxedItem, SIGNAL(toggled(bool)), this, SLOT(focusItemsPerBox(bool)) );

    connect(ui->btnRemoveItem, SIGNAL( clicked() ), SLOT( deleteSelectedItem() ) );

    ui->chIsAGroup->setDisabled(true);
    

    status = estatusNormal;
    productExists = false;
    productsHash.clear();
    resetEdits();
    totalBuy = 0.0;
    itemCount = 0.0;
    totalTaxes = 0.0;
    QTimer::singleShot(500, this, SLOT(setupTable()));
}
Beispiel #5
0
TEST(ShaderLib,editShader)
{

  auto shader = ngl::ShaderLib::instance();
  auto *shaderName="Edit";

  shader->createShaderProgram(shaderName,ngl::ErrorExit::OFF);
  constexpr auto Vertex="EditVert";
  shader->attachShader( Vertex, ngl::ShaderType::VERTEX ,ngl::ErrorExit::OFF);
  shader->loadShaderSource(Vertex,"files/EditVert.glsl");
  EXPECT_TRUE(shader->editShader(Vertex,"@breakMe","1.0"))<<"edit shader set breakMe ";
  EXPECT_TRUE(shader->editShader(Vertex,"@numLights","2"))<<"edit shader";
  EXPECT_TRUE(shader->compileShader(Vertex))<<"error compiling vert shader";
  constexpr auto Fragment="EditFrag";
  shader->attachShader( Fragment, ngl::ShaderType::FRAGMENT,ngl::ErrorExit::OFF );
  shader->loadShaderSource(Fragment,"files/EditFrag.glsl");
  EXPECT_TRUE(shader->editShader(Fragment,"@numLights","2"))<<"edit shader";
  EXPECT_TRUE(shader->compileShader(Fragment))<<"error compiling vert shader";
  shader->attachShaderToProgram(shaderName,Vertex);
  shader->attachShaderToProgram(shaderName,Fragment);
  EXPECT_TRUE(shader->linkProgramObject(shaderName))<<"First Link";
  (*shader)[shaderName]->use();
  EXPECT_TRUE(shader->getCurrentShaderName()==shaderName);
  // Now re-edit
  shader->resetEdits(Vertex);
  shader->resetEdits(Fragment);
  EXPECT_TRUE(shader->editShader(Vertex,"@numLights","5"))<<"edit shader 2nd";
  EXPECT_TRUE(shader->editShader(Vertex,"@breakMe","1.0"))<<"edit shader set breakMe 2nd";
  EXPECT_TRUE(shader->editShader(Fragment,"@numLights","5"))<<"edit shader";
  EXPECT_TRUE(shader->compileShader(Vertex))<<"error compiling vert shader";
  EXPECT_TRUE(shader->compileShader(Fragment))<<"error compiling vert shader";
  EXPECT_TRUE(shader->linkProgramObject(shaderName));




}
void PurchaseEditor::addItemToList()
{
    qDebug()<<"DATE:"<<getDate().toString()<<ui->editDateTime->dateTime().date().toString();
    ProductInfo pInfo;
    Azahar *myDb = new Azahar;
    myDb->setDatabase(db);
    // Exit here
    if (!ui->p->checkFieldsState()) {return;}
    if (ui->editQty->text().isEmpty() || ui->editQty->text()=="0") {
            ui->editQty->setFocus();
            return;
        }
    // in-db definition
    ProductInfo info = myDb->getProductInfo(  ui->p->getCode() );
    productExists=(info.code!="0");
    //if is an Unlimited stock product, do not allow to add to the purchase.
    if (info.hasUnlimitedStock)  {
        errorPanel->showTip(i18n("<b>Unlimited Stock Products cannot be purchased.</b>"), 10000);
        return;
    }

    // in-widget definition
    info=ui->p->getProductInfo();

    info.validDiscount = productExists; //used to check if product is already on db.
    if (info.isAGroup) {
        //FIXME!
        // get each product fo the group/pack
        QStringList list = gelem.split(",");
        for (int i=0; i<list.count(); ++i) {
            QStringList tmp = list.at(i).split("/");
            if (tmp.count() == 2) { //ok 2 fields
                qulonglong  code  = tmp.at(0).toULongLong();
                pInfo = myDb->getProductInfo(QString::number(code));
                pInfo.purchaseQty = getPurchaseQty();
                pInfo.validDiscount = true; // all grouped products exists
                insertProduct(pInfo); ///inserting each product of the group
            } // correct fields
        }//for each element
    } else {
        info.purchaseQty=getPurchaseQty();
        insertProduct(info);
    }
    resetEdits();
}
Beispiel #7
0
void PurchaseEditor::checkIfCodeExists()
{
  Azahar *myDb = new Azahar;
  myDb->setDatabase(db);
  gelem = "";
  QString codeStr = ui->editCode->text();
  if (codeStr.isEmpty()) codeStr = "0";
  ProductInfo pInfo = myDb->getProductInfo(codeStr);
  if (pInfo.code ==0 && pInfo.desc=="Ninguno") productExists = false;
  if (pInfo.code > 0) {
    status = estatusMod;
    productExists = true;
    qtyOnDb  = pInfo.stockqty;
    //Prepopulate dialog...
    ui->editDesc->setText(pInfo.desc);
    setCategory(pInfo.category);
    setMeasure(pInfo.units);
    ui->editCost->setText(QString::number(pInfo.cost));
    ui->editTax->setText(QString::number(pInfo.tax));
    //FIXME: add tax models
    //ui->editExtraTaxes->setText(QString::number(pInfo.extratax));
    ui->editFinalPrice->setText(QString::number(pInfo.price));
    ui->editPoints->setText(QString::number(pInfo.points));
    ui->chIsAGroup->setChecked(pInfo.isAGroup);
    gelem = pInfo.groupElementsStr;
    if (!(pInfo.photo).isEmpty()) {
      QPixmap photo;
      photo.loadFromData(pInfo.photo);
      setPhoto(photo);
    }
  } else {
    qDebug()<< "no product found with code "<<codeStr;
    qulonglong codeSaved = getCode();
    resetEdits();
    setCode(codeSaved);
  }
}
Beispiel #8
0
void PurchaseEditor::addItemToList()
{
  ProductInfo pInfo;
  Azahar *myDb = new Azahar;
  myDb->setDatabase(db);
  bool ok=false;

  if (ui->editCode->text().isEmpty()) ui->editCode->setFocus();
  else if (ui->editDesc->text().isEmpty()) ui->editDesc->setFocus();
  else if (ui->editPoints->text().isEmpty()) ui->editPoints->setFocus();
  else if (ui->editCost->text().isEmpty()) ui->editCost->setFocus();
  else if (ui->editTax->text().isEmpty()) ui->editTax->setFocus();
  else if (ui->editFinalPrice->text().isEmpty()) ui->editFinalPrice->setFocus();
  else if (ui->editQty->text().isEmpty() || ui->editQty->text()=="0") ui->editQty->setFocus();
  else if ((ui->editUtility->text().isEmpty() && ui->editFinalPrice->text().isEmpty()) || ui->editFinalPrice->text().toDouble()<=ui->editCost->text().toDouble() ) ui->editFinalPrice->setFocus();
  else if (ui->groupBoxedItem->isChecked() && (ui->editItemsPerBox->text().isEmpty() || ui->editItemsPerBox->text()=="0"))  ui->editItemsPerBox->setFocus();
  else if (ui->groupBoxedItem->isChecked() && (ui->editPricePerBox->text().isEmpty() || ui->editPricePerBox->text()=="0")) ui->editPricePerBox->setFocus();
  else ok = true;

  if (ok) {
    ProductInfo info = myDb->getProductInfo(QString::number(getCode()));
    if (info.code == 0) {
      info.code = getCode();
      info.lastProviderId=1; //for now.. fixme in the future
    }
    //update p.info from the dialog
    info.desc    = getDescription();
    info.price   = getPrice();
    info.cost    = getCost();
    info.tax     = getTax1();
    //FIXME: add tax models
    //info.extratax= getTax2();
    info.photo   = getPhotoBA();
    info.units   = getMeasureId();
    info.category= getCategoryId();
    info.profit  = getProfit();
    info.points  = getPoints();
    info.stockqty= getQtyOnDb();
    info.purchaseQty = getPurchaseQty();
    double finalCount = info.purchaseQty + info.stockqty; // WHAT FOR??
    info.validDiscount = productExists; //used to check if product is already on db.
    //FIXME: NEXT 2 lines are temporal remove on 0.8 version
    //info.alphaCode = "-NA-";
    //FIXME: last providerId for an existent must be gotten from db since we dont have that field here. Provide a combobox to select one and a button to add a new one.
    //info.lastProviderId = 1;

    if (info.isAGroup) {
      // get each product fo the group/pack
      QStringList list = gelem.split(",");
      for (int i=0; i<list.count(); ++i) {
        QStringList tmp = list.at(i).split("/");
        if (tmp.count() == 2) { //ok 2 fields
          qulonglong  code  = tmp.at(0).toULongLong();
          pInfo = myDb->getProductInfo(QString::number(code));
          pInfo.purchaseQty = getPurchaseQty();
          pInfo.validDiscount = true; // all grouped products exists
          insertProduct(pInfo); ///inserting each product of the group
        } // correct fields
      }//for each element
    } else insertProduct(info);

    resetEdits();
    ui->editCode->setFocus();
  }
}
void PurchaseEditor::insertProduct(ProductInfo info)
{
    //When a product is already on list, increment qty.
    bool existed = false;
    if (info.code=="0") {
        qDebug()<<"INVALID PRODUCT";
        return;
    }
    if (productsHash.contains(info.code)) {
        qDebug()<<"Item "<<info.code<<" already on hash";
        info = productsHash.take(info.code); //re get it from hash
        double finalStock = info.purchaseQty + info.stockqty;
        double suggested;
        if (-info.stockqty == 0)
            suggested = 1;
        else
            suggested = -info.stockqty;
        qDebug()<<"Purchase Qty:"<<info.purchaseQty<<" product stock:"<<info.stockqty<<" final Stock:"<<finalStock;
        if (finalStock < 0) {
            //this cannot be saved, negative stock is not allowed in database.
            qDebug()<<"Cannot be negative stock!, suggested purchase:"<<suggested;
            //launch a message
            errorPanel->showTip(i18n("<b>Stock cannot go negative.</b> The <i>minimum</i> purchase can be <b>%1</b>", suggested), 10000);
            setPurchaseQty(suggested);
            ui->editQty->setFocus();
            return;
        }
        info.purchaseQty += getPurchaseQty();
        itemCount += getPurchaseQty();
        totalBuy = totalBuy + info.cost*getPurchaseQty();
        existed = true;
    } else {
        double finalStock = info.purchaseQty + info.stockqty;
        double suggested;
        if (-info.stockqty == 0)
            suggested = 1;
        else
            suggested = -info.stockqty;
        qDebug()<<"Purchase Qty:"<<info.purchaseQty<<" product stock:"<<info.stockqty<<" final Stock:"<<finalStock;
        if (finalStock < 0) {
            //this cannot be saved, negative stock is not allowed in database.
            qDebug()<<"Cannot be negative stock!, suggested purchase:"<<suggested;
            //launch a message
            errorPanel->showTip(i18n("<b>Stock cannot go negative.</b> The <i>minimum</i> purchase can be <b>%1</b>", suggested), 10000);
            setPurchaseQty(suggested);
            ui->editQty->setFocus();
            return;
        }
        itemCount += info.purchaseQty;
        totalBuy = totalBuy + info.cost*info.purchaseQty;
    }
    //its ok to reset edits now...
    resetEdits();
    
    double finalCount = info.purchaseQty + info.stockqty;
    info.groupElementsStr=""; //grouped products cannot be a group.
    //insert item to productsHash
    productsHash.insert(info.code, info);
    //insert item to ListView
    if (!existed) {
        int rowCount = ui->tableView->rowCount();
        ui->tableView->insertRow(rowCount);
        ui->tableView->setItem(rowCount, 0, new QTableWidgetItem(info.code));
        ui->tableView->setItem(rowCount, 1, new QTableWidgetItem(info.desc));
        ui->tableView->setItem(rowCount, 2, new QTableWidgetItem(QString::number(info.purchaseQty)));
        ui->tableView->setItem(rowCount, 3, new QTableWidgetItem(QString::number(finalCount)));
    } else {
        //simply update the groupView with the new qty
        for (int ri=0; ri<ui->tableView->rowCount(); ++ri)
        {
            QTableWidgetItem * item = ui->tableView->item(ri, 0);
            QString name = item->data(Qt::DisplayRole).toString();
            if (name == info.code) {
                //update
                QTableWidgetItem *itemQ = ui->tableView->item(ri, 2);
                itemQ->setData(Qt::EditRole, QVariant(QString::number(info.purchaseQty)));
                itemQ = ui->tableView->item(ri, 3);
                itemQ->setData(Qt::EditRole, QVariant(QString::number(finalCount)));
                itemQ = ui->tableView->item(ri, 1);
                itemQ->setData(Qt::EditRole, QVariant(info.desc));
                continue; //HEY PURIST, WHEN I GOT SOME TIME I WILL CLEAN IT
            }
        }
    }
    
    ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
    ui->tableView->resizeRowsToContents();
    //totalBuy = totalBuy + info.cost*info.purchaseQty;
    //itemCount = itemCount + info.purchaseQty;

    //update info on group caption
    ui->groupBox->setTitle( i18n("Items in this purchase [ %1  items,  %2 ]",itemCount,
                                 KGlobal::locale()->formatMoney(totalBuy, QString(), 2)
                                 ) );
    
    qDebug()<<"totalBuy until now:"<<totalBuy<<" itemCount:"<<itemCount<<"info.cost:"<<info.cost<<"info.purchaseQty:"<<info.purchaseQty;

}