/*! Constructor */ CntImageEditorView::CntImageEditorView() : mContact(NULL), mAvatar(NULL), mImageLabel(NULL), mRequest(NULL), mViewManager(NULL), mListView(NULL), mModel(NULL), mSaveManager(NULL) { bool ok = false; mDocumentLoader.load(CNT_IMAGE_XML, &ok); if (ok) { mView = static_cast<HbView*>(mDocumentLoader.findWidget(QString("view"))); } else { qFatal("Unable to read :/xml/contacts_if.docml"); } //back button mSoftkey = new HbAction(Hb::BackNaviAction, mView); connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView())); // menu action mRemoveImage = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:removeimage")); connect(mRemoveImage, SIGNAL(triggered()), this, SLOT(removeImage())); // closing the application from task swapper or end key will cause the contact to be saved connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(saveContact())); }
void vendorAddress::sSave() { if (! q.exec("BEGIN")) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } XSqlQuery rollback; rollback.prepare("ROLLBACK;"); int saveResult = _address->save(AddressCluster::CHECK); if (-2 == saveResult) { int answer = QMessageBox::question(this, tr("Question Saving Address"), tr("There are multiple uses of this Vendor " "Address.\nWhat would you like to do?"), tr("Change This One"), tr("Change Address for All"), tr("Cancel"), 2, 2); if (0 == answer) saveResult = _address->save(AddressCluster::CHANGEONE); else if (1 == answer) saveResult = _address->save(AddressCluster::CHANGEALL); } if (saveResult < 0) // not else-if: this is error check for CHANGE{ONE,ALL} { systemError(this, tr("There was an error saving this address (%1).\n" "Check the database server log for errors.") .arg(saveResult), __FILE__, __LINE__); rollback.exec(); _address->setFocus(); return; } if (saveContact(_contact) < 0) { rollback.exec(); _contact->setFocus(); return; } if (_mode == cNew) { q.exec("SELECT NEXTVAL('vendaddr_vendaddr_id_seq') AS vendaddr_id;"); if (q.first()) _vendaddrid = q.value("vendaddr_id").toInt(); else { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } q.prepare( "INSERT INTO vendaddrinfo " "( vendaddr_id, vendaddr_vend_id," " vendaddr_code, vendaddr_name," " vendaddr_cntct_id, vendaddr_comments, vendaddr_addr_id," " vendaddr_taxauth_id ) " "VALUES " "( :vendaddr_id, :vendaddr_vend_id," " :vendaddr_code, :vendaddr_name," " :vendaddr_cntct_id, :vendaddr_comments, :vendaddr_addr_id," " :vendaddr_taxauth_id );"); } else if (_mode == cEdit) q.prepare( "UPDATE vendaddrinfo " "SET vendaddr_code=:vendaddr_code, vendaddr_name=:vendaddr_name," " vendaddr_cntct_id=:vendaddr_cntct_id," " vendaddr_comments=:vendaddr_comments, " " vendaddr_addr_id=:vendaddr_addr_id," " vendaddr_taxauth_id=:vendaddr_taxauth_id " "WHERE (vendaddr_id=:vendaddr_id);" ); q.bindValue(":vendaddr_id", _vendaddrid); q.bindValue(":vendaddr_vend_id", _vendid); q.bindValue(":vendaddr_code", _number->text().trimmed()); q.bindValue(":vendaddr_name", _name->text().trimmed()); if (_contact->id() > 0) q.bindValue(":vendaddr_cntct_id", _contact->id()); if (_address->id() > 0) q.bindValue(":vendaddr_addr_id", _address->id()); q.bindValue(":vendaddr_comments", _notes->toPlainText().trimmed()); if(_taxauth->isValid()) q.bindValue(":vendaddr_taxauth_id", _taxauth->id()); q.exec(); if (q.lastError().type() != QSqlError::NoError) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } q.exec("COMMIT;"); done(_vendaddrid); }
void warehouse::sSave() { // Make sure that at least a warehouse code has been entered if (_code->text().stripWhiteSpace().length() == 0) { QMessageBox::information( this, tr("Cannot Save Warehouse"), tr("<p>You must enter a code for this Warehouse " "before saving it.") ); _code->setFocus(); return; } // Make sure that the Count Tag prefix is unique if (_mode != cNew) { q.prepare( "SELECT warehous_id " "FROM warehous " "WHERE ( (warehous_counttag_prefix=:prefix)" " AND (warehous_id<>:warehous_id) );" ); q.bindValue(":warehous_id", _warehousid); } else q.prepare( "SELECT warehous_id " "FROM warehous " "WHERE (warehous_counttag_prefix=:prefix)" ); q.bindValue(":prefix", _countTagPrefix->text()); q.exec(); if (q.first()) { QMessageBox::critical( this, tr("Count Tag Prefix not Unique"), tr("<p>The Count Tag prefix entered has been used " "in another Warehouse. To enable Count Tag " "audits, the application requires a unique Count " "Tag prefix for each Warehouse. Please enter a " "different Count Tag prefix." ) ); _countTagPrefix->clear(); _countTagPrefix->setFocus(); return; } else if (q.lastError().type() != QSqlError::None) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } q.prepare( "SELECT warehous_id " "FROM warehous " "WHERE ( (warehous_id<>:warehous_id)" " AND (UPPER(warehous_code)=UPPER(:warehous_code)) );" ); q.bindValue(":warehous_id", _warehousid); q.bindValue(":warehous_code", _code->text()); q.exec(); if (q.first()) { QMessageBox::critical( this, tr("Cannot Save Warehouse"), tr( "<p>The new Warehouse information cannot be " "saved as the new Warehouse Code that you " "entered conflicts with an existing Warehouse. " "You must uniquely name this Warehouse before " "you may save it." ) ); _code->setFocus(); return; } else if (q.lastError().type() != QSqlError::None) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } // Make sure that a default G/L Account has been entered if (_account->id() == -1) { QMessageBox::information( this, tr("Cannot Save Warehouse"), tr("<p>You must enter a default Account for this " "Warehouse before saving it.") ); _account->setFocus(); return; } if (_transit->isChecked() && ! _costcat->isValid()) { QMessageBox::information(this, tr("Cannot Save Warehouse"), tr("<p>You must select a Cost Category for this " "Transit Warehouse before saving it.") ); _costcat->setFocus(); return; } XSqlQuery rollback; rollback.prepare("ROLLBACK;"); if (! q.exec("BEGIN")) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } if (saveContact(_contact) < 0) { rollback.exec(); _contact->setFocus(); return; } int saveResult = _address->save(AddressCluster::CHECK); if (-2 == saveResult) { int answer = QMessageBox::question(this, tr("Question Saving Address"), tr("There are multiple uses of this Warehouse " "Address.\nWhat would you like to do?"), tr("Change This One"), tr("Change Address for All"), tr("Cancel"), 2, 2); if (0 == answer) saveResult = _address->save(AddressCluster::CHANGEONE); else if (1 == answer) saveResult = _address->save(AddressCluster::CHANGEALL); } if (saveResult < 0) // not else-if: this is error check for CHANGE{ONE,ALL} { rollback.exec(); systemError(this, tr("There was an error saving this address (%1).\n" "Check the database server log for errors.") .arg(saveResult), __FILE__, __LINE__); _address->setFocus(); return; } if (_mode == cNew) q.prepare( "INSERT INTO whsinfo " "( warehous_id, warehous_code, warehous_descrip," " warehous_cntct_id, warehous_fob, warehous_active," " warehous_bol_prefix, warehous_bol_number, warehous_shipping," " warehous_counttag_prefix, warehous_counttag_number, warehous_useslips," " warehous_aislesize, warehous_aislealpha," " warehous_racksize, warehous_rackalpha," " warehous_binsize, warehous_binalpha," " warehous_locationsize, warehous_locationalpha," " warehous_enforcearbl, warehous_usezones, " " warehous_default_accnt_id, warehous_shipping_commission, " " warehous_addr_id, warehous_taxauth_id, warehous_transit," " warehous_shipform_id, warehous_shipvia_id," " warehous_shipcomments, warehous_costcat_id ) " "VALUES " "( :warehous_id, :warehous_code, :warehous_descrip," " :warehous_cntct_id, :warehous_fob, :warehous_active," " :warehous_bol_prefix, :warehous_bol_number, :warehous_shipping," " :warehous_counttag_prefix, :warehous_counttag_number, :warehous_useslips," " :warehous_aislesize, :warehous_aislealpha," " :warehous_racksize, :warehous_rackalpha," " :warehous_binsize, :warehous_binalpha," " :warehous_locationsize, :warehous_locationalpha," " :warehous_enforcearbl, :warehous_usezones, " " :warehous_default_accnt_id, :warehous_shipping_commission, " " :warehous_addr_id, :warehous_taxauth_id, :warehous_transit," " :warehous_shipform_id, :warehous_shipvia_id," " :warehous_shipcomments, :warehous_costcat_id );" ); else if (_mode == cEdit) q.prepare( "UPDATE whsinfo " "SET warehous_code=:warehous_code," " warehous_descrip=:warehous_descrip," " warehous_cntct_id=:warehous_cntct_id, " " warehous_fob=:warehous_fob," " warehous_active=:warehous_active," " warehous_bol_prefix=:warehous_bol_prefix," " warehous_bol_number=:warehous_bol_number," " warehous_shipping=:warehous_shipping," " warehous_counttag_prefix=:warehous_counttag_prefix," " warehous_counttag_number=:warehous_counttag_number," " warehous_useslips=:warehous_useslips," " warehous_aislesize=:warehous_aislesize," " warehous_aislealpha=:warehous_aislealpha," " warehous_racksize=:warehous_racksize," " warehous_rackalpha=:warehous_rackalpha," " warehous_binsize=:warehous_binsize," " warehous_binalpha=:warehous_binalpha," " warehous_locationsize=:warehous_locationsize," " warehous_locationalpha=:warehous_locationalpha," " warehous_enforcearbl=:warehous_enforcearbl," " warehous_usezones=:warehous_usezones," " warehous_default_accnt_id=:warehous_default_accnt_id, " " warehous_shipping_commission=:warehous_shipping_commission," " warehous_addr_id=:warehous_addr_id," " warehous_taxauth_id=:warehous_taxauth_id," " warehous_transit=:warehous_transit," " warehous_shipform_id=:warehous_shipform_id," " warehous_shipvia_id=:warehous_shipvia_id," " warehous_shipcomments=:warehous_shipcomments," " warehous_costcat_id=:warehous_costcat_id " "WHERE (warehous_id=:warehous_id);" ); q.bindValue(":warehous_id", _warehousid); q.bindValue(":warehous_code", _code->text().stripWhiteSpace().upper()); q.bindValue(":warehous_descrip", _description->text()); if (_contact->id() > 0) q.bindValue(":warehous_cntct_id", _contact->id()); // else NULL if (_address->id() > 0) q.bindValue(":warehous_addr_id", _address->id()); // else NULL q.bindValue(":warehous_active", QVariant(_active->isChecked(), 0)); q.bindValue(":warehous_default_accnt_id", _account->id()); if (_standard->isChecked()) { q.bindValue(":warehous_fob", _defaultFOB->text()); q.bindValue(":warehous_bol_prefix", _bolPrefix->text()); q.bindValue(":warehous_bol_number", _bolNumber->text().toInt()); q.bindValue(":warehous_counttag_prefix", _countTagPrefix->text()); q.bindValue(":warehous_counttag_number", _countTagNumber->text().toInt()); q.bindValue(":warehous_shipping", QVariant(_shipping->isChecked(), 0)); q.bindValue(":warehous_useslips", QVariant(_useSlips->isChecked(), 0)); q.bindValue(":warehous_enforcearbl",QVariant(_arblGroup->isChecked(), 0)); q.bindValue(":warehous_aislesize", _aisleSize->value()); q.bindValue(":warehous_aislealpha", QVariant(_aisleAlpha->isChecked(), 0)); q.bindValue(":warehous_racksize", _rackSize->value()); q.bindValue(":warehous_rackalpha", QVariant(_rackAlpha->isChecked(), 0)); q.bindValue(":warehous_binsize", _binSize->value()); q.bindValue(":warehous_binalpha", QVariant(_binAlpha->isChecked(), 0)); q.bindValue(":warehous_locationsize", _locationSize->value()); q.bindValue(":warehous_locationalpha", QVariant(_locationAlpha->isChecked(), 0)); q.bindValue(":warehous_usezones", QVariant(_useZones->isChecked(), 0)); q.bindValue(":warehous_shipping_commission", (_shipcomm->toDouble() / 100)); if(_taxauth->isValid()) q.bindValue(":warehous_taxauth_id", _taxauth->id()); } q.bindValue(":warehous_transit", QVariant(_transit->isChecked(), 0)); if (_transit->isChecked()) { if (_shipform->isValid()) q.bindValue(":warehous_shipform_id", _shipform->id()); if (_shipvia->isValid()) q.bindValue(":warehous_shipvia_id", _shipvia->id()); q.bindValue(":warehous_shipcomments", _shipcomments->text()); if (_costcat->isValid()) q.bindValue(":warehous_costcat_id", _costcat->id()); } q.exec(); if (q.lastError().type() != QSqlError::None) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } q.exec("COMMIT;"); omfgThis->sWarehousesUpdated(); done(_warehousid); }
void shipTo::sSave() { XSqlQuery rollback; rollback.prepare("ROLLBACK;"); if (! q.exec("BEGIN")) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } if (saveContact(_contact) < 0) { rollback.exec(); _contact->setFocus(); return; } int saveResult = _address->save(AddressCluster::CHECK); if (-2 == saveResult) { int answer = QMessageBox::question(this, tr("Question Saving Address"), tr("<p>There are multiple uses of this Ship-To " "Address. What would you like to do?"), tr("Change This One"), tr("Change Address for All"), tr("Cancel"), 2, 2); if (0 == answer) saveResult = _address->save(AddressCluster::CHANGEONE); else if (1 == answer) saveResult = _address->save(AddressCluster::CHANGEALL); } if (saveResult < 0) // not else-if: this is error check for CHANGE{ONE,ALL} { systemError(this, tr("<p>There was an error saving this address (%1). " "Check the database server log for errors.") .arg(saveResult), __FILE__, __LINE__); rollback.exec(); _address->setFocus(); return; } if (_mode == cNew) { q.exec("SELECT NEXTVAL('shipto_shipto_id_seq') AS shipto_id;"); if (q.first()) _shiptoid = q.value("shipto_id").toInt(); else if (q.lastError().type() != QSqlError::None) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } q.prepare( "INSERT INTO shiptoinfo " "( shipto_id, shipto_cust_id, shipto_active, shipto_default," " shipto_num, shipto_name, shipto_cntct_id, shipto_commission," " shipto_comments, shipto_shipcomments," " shipto_taxauth_id, shipto_salesrep_id, shipto_shipzone_id," " shipto_shipvia, shipto_shipform_id, shipto_shipchrg_id, " " shipto_ediprofile_id, shipto_addr_id ) " "VALUES " "( :shipto_id, :shipto_cust_id, :shipto_active, :shipto_default," " :shipto_num, :shipto_name, :shipto_cntct_id, :shipto_commission," " :shipto_comments, :shipto_shipcomments," " :shipto_taxauth_id, :shipto_salesrep_id, :shipto_shipzone_id," " :shipto_shipvia, :shipto_shipform_id, :shipto_shipchrg_id, " " :shipto_ediprofile_id , :shipto_addr_id);" ); } else if (_mode == cEdit) q.prepare( "UPDATE shiptoinfo " "SET shipto_active=:shipto_active, shipto_default=:shipto_default," " shipto_name=:shipto_name, shipto_cntct_id=:shipto_cntct_id," " shipto_commission=:shipto_commission," " shipto_comments=:shipto_comments, shipto_shipcomments=:shipto_shipcomments," " shipto_taxauth_id=:shipto_taxauth_id, shipto_salesrep_id=:shipto_salesrep_id, shipto_shipzone_id=:shipto_shipzone_id," " shipto_shipvia=:shipto_shipvia, shipto_shipform_id=:shipto_shipform_id, shipto_shipchrg_id=:shipto_shipchrg_id," " shipto_ediprofile_id=:shipto_ediprofile_id, " " shipto_addr_id=:shipto_addr_id " "WHERE (shipto_id=:shipto_id);" ); q.bindValue(":shipto_id", _shiptoid); q.bindValue(":shipto_active", QVariant(_active->isChecked(), 0)); q.bindValue(":shipto_default", QVariant(_default->isChecked(), 0)); q.bindValue(":shipto_cust_id", _custid); q.bindValue(":shipto_num", _shipToNumber->text().stripWhiteSpace()); q.bindValue(":shipto_name", _name->text()); if (_contact->id() > 0) q.bindValue(":shipto_cntct_id", _contact->id()); if (_address->id() > 0) q.bindValue(":shipto_addr_id", _address->id()); q.bindValue(":shipto_commission", (_commission->toDouble() / 100)); q.bindValue(":shipto_comments", _comments->text()); q.bindValue(":shipto_shipcomments", _shippingComments->text()); q.bindValue(":shipto_shipvia", _shipVia->currentText()); if (_taxauth->isValid()) q.bindValue(":shipto_taxauth_id", _taxauth->id()); q.bindValue(":shipto_salesrep_id", _salesRep->id()); q.bindValue(":shipto_shipzone_id", _shipZone->id()); q.bindValue(":shipto_shipform_id", _shipform->id()); q.bindValue(":shipto_shipchrg_id", _shipchrg->id()); q.bindValue(":shipto_ediprofile_id", _ediProfile->id()); q.exec(); if (q.lastError().type() != QSqlError::None) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } q.exec("COMMIT;"); done(_shiptoid); }
void vendor::sSave() { XSqlQuery rollback; rollback.prepare("ROLLBACK;"); if (_number->text().stripWhiteSpace().length() == 0) { QMessageBox::critical( this, tr("Cannot Create Vendor"), tr("Please enter a Number for this new Vendor.") ); _number->setFocus(); return; } if (_name->text().stripWhiteSpace().length() == 0) { QMessageBox::critical( this, tr("Cannot Create Vendor"), tr("Please enter a Name for this new Vendor.") ); _name->setFocus(); return; } if (_defaultTerms->id() == -1) { QMessageBox::critical( this, tr("Select Terms"), tr("You must select a Terms code for this Vendor before continuing.") ); _defaultTerms->setFocus(); return; } if (_vendtype->id() == -1) { QMessageBox::critical( this, tr("Select Vendor Type"), tr("You must select a Vendor Type for this Vendor before continuing.") ); _vendtype->setFocus(); return; } if (_number->text().stripWhiteSpace().upper() != _cachedNumber.upper()) { q.prepare( "SELECT vend_name " "FROM vend " "WHERE (UPPER(vend_number)=UPPER(:vend_number)) " " AND (vend_id<>:vend_id);" ); q.bindValue(":vend_number", _number->text().stripWhiteSpace()); q.bindValue(":vend_id", _vendid); q.exec(); if (q.first()) { QMessageBox::critical( this, tr("Vendor Number Used"), tr( "The newly entered Vendor Number cannot be used as it is currently\n" "in use by the Vendor '%1'. Please correct or enter a new Vendor Number." ) .arg(q.value("vend_name").toString()) ); _number->setFocus(); return; } } if (! q.exec("BEGIN")) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } int saveResult = _address->save(AddressCluster::CHECK); if (-2 == saveResult) { int answer = QMessageBox::question(this, tr("Question Saving Address"), tr("There are multiple uses of this Vendor's " "Address.\nWhat would you like to do?"), tr("Change This One"), tr("Change Address for All"), tr("Cancel"), 2, 2); if (0 == answer) saveResult = _address->save(AddressCluster::CHANGEONE); else if (1 == answer) saveResult = _address->save(AddressCluster::CHANGEALL); } if (saveResult < 0) // not else-if: this is error check for CHANGE{ONE,ALL} { systemError(this, tr("There was an error saving this address (%1).\n" "Check the database server log for errors.") .arg(saveResult), __FILE__, __LINE__); rollback.exec(); _address->setFocus(); return; } if (saveContact(_contact1) < 0) { rollback.exec(); _contact1->setFocus(); return; } if (saveContact(_contact2) < 0) { rollback.exec(); _contact2->setFocus(); return; } if (_mode == cEdit) { q.prepare( "UPDATE vendinfo " "SET vend_number=:vend_number, vend_accntnum=:vend_accntnum," " vend_active=:vend_active," " vend_vendtype_id=:vend_vendtype_id, vend_name=:vend_name," " vend_cntct1_id=:vend_cntct1_id, vend_cntct2_id=:vend_cntct2_id," " vend_addr_id=:vend_addr_id," " vend_po=:vend_po, vend_restrictpurch=:vend_restrictpurch," " vend_1099=:vend_1099, vend_qualified=:vend_qualified," " vend_comments=:vend_comments, vend_pocomments=:vend_pocomments," " vend_fobsource=:vend_fobsource, vend_fob=:vend_fob," " vend_terms_id=:vend_terms_id, vend_shipvia=:vend_shipvia," " vend_curr_id=:vend_curr_id, " " vend_emailpodelivery=:vend_emailpodelivery, vend_ediemail=:vend_ediemail," " vend_ediemailbody=:vend_ediemailbody, vend_edisubject=:vend_edisubject," " vend_edifilename=:vend_edifilename, vend_edicc=:vend_edicc," " vend_taxauth_id=:vend_taxauth_id, vend_match=:vend_match " "WHERE (vend_id=:vend_id);" ); } else if (_mode == cNew) q.prepare( "INSERT INTO vendinfo " "( vend_id, vend_number, vend_accntnum," " vend_active, vend_vendtype_id, vend_name," " vend_cntct1_id, vend_cntct2_id, vend_addr_id," " vend_po, vend_restrictpurch," " vend_1099, vend_qualified," " vend_comments, vend_pocomments," " vend_fobsource, vend_fob," " vend_terms_id, vend_shipvia, vend_curr_id," " vend_emailpodelivery, vend_ediemail, vend_ediemailbody," " vend_edisubject, vend_edifilename, vend_edicc," " vend_taxauth_id, vend_match ) " "VALUES " "( :vend_id, :vend_number, :vend_accntnum," " :vend_active, :vend_vendtype_id, :vend_name," " :vend_cntct1_id, :vend_cntct2_id, :vend_addr_id," " :vend_po, :vend_restrictpurch," " :vend_1099, :vend_qualified," " :vend_comments, :vend_pocomments," " :vend_fobsource, :vend_fob," " :vend_terms_id, :vend_shipvia, :vend_curr_id, " " :vend_emailpodelivery, :vend_ediemail, :vend_ediemailbody," " :vend_edisubject, :vend_edifilename, :vend_edicc," " :vend_taxauth_id, :vend_match );" ); q.bindValue(":vend_id", _vendid); q.bindValue(":vend_vendtype_id", _vendtype->id()); q.bindValue(":vend_terms_id", _defaultTerms->id()); q.bindValue(":vend_curr_id", _defaultCurr->id()); q.bindValue(":vend_number", _number->text().stripWhiteSpace().upper()); q.bindValue(":vend_accntnum", _accountNumber->text().stripWhiteSpace()); q.bindValue(":vend_name", _name->text().stripWhiteSpace()); if (_contact1->id() > 0) q.bindValue(":vend_cntct1_id", _contact1->id()); // else NULL if (_contact2->id() > 0) q.bindValue(":vend_cntct2_id", _contact2->id()); // else NULL if (_address->id() > 0) q.bindValue(":vend_addr_id", _address->id()); // else NULL q.bindValue(":vend_comments", _notes->text()); q.bindValue(":vend_pocomments", _poComments->text()); q.bindValue(":vend_shipvia", _defaultShipVia->text()); q.bindValue(":vend_active", QVariant(_active->isChecked(), 0)); q.bindValue(":vend_po", QVariant(_poItems->isChecked(), 0)); q.bindValue(":vend_restrictpurch", QVariant(_restrictToItemSource->isChecked(), 0)); q.bindValue(":vend_1099", QVariant(_receives1099->isChecked(), 0)); q.bindValue(":vend_qualified", QVariant(_qualified->isChecked(), 0)); q.bindValue(":vend_match", QVariant(_match->isChecked(), 0)); q.bindValue(":vend_emailpodelivery", QVariant(_emailPODelivery->isChecked(), 0)); q.bindValue(":vend_ediemail", _ediEmail->text()); q.bindValue(":vend_ediemailbody", _ediEmailBody->text()); q.bindValue(":vend_edisubject", _ediSubject->text()); q.bindValue(":vend_edifilename", _ediFilename->text()); q.bindValue(":vend_edicc", _ediCC->text().stripWhiteSpace()); if(_taxauth->isValid()) q.bindValue(":vend_taxauth_id", _taxauth->id()); if (_useWarehouseFOB->isChecked()) { q.bindValue(":vend_fobsource", "W"); q.bindValue(":vend_fob", ""); } else if (_useVendorFOB) { q.bindValue(":vend_fobsource", "V"); q.bindValue(":vend_fob", _vendorFOB->text().stripWhiteSpace()); } q.exec(); if (q.lastError().type() != QSqlError::None) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } // Get the crmacct that was created by the vendinfo trigger q.prepare("SELECT crmacct_id " "FROM crmacct " "WHERE (crmacct_vend_id=:vend_id);"); q.bindValue(":vend_id", _vendid); q.exec(); if (!q.lastError().type() == QSqlError::None) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } _crmacctid = q.value("crmacct_id").toInt(); _contact1->setAccount(_crmacctid); _contact2->setAccount(_crmacctid); // need to save contacts again with updated CRM Account if (saveContact(_contact1) < 0) { rollback.exec(); _contact1->setFocus(); return; } if (saveContact(_contact2) < 0) { rollback.exec(); _contact2->setFocus(); return; } q.exec("COMMIT;"); _NumberGen = -1; omfgThis->sVendorsUpdated(); if(!_ignoreClose) close(); }
void prospect::sSave() { struct { bool condition; QString msg; QWidget* widget; } error[] = { { _number->text().stripWhiteSpace().length() == 0, tr("You must enter a number for this Prospect before saving"), _number }, { true, "", NULL } }; int errIndex; for (errIndex = 0; ! error[errIndex].condition; errIndex++) ; if (! error[errIndex].msg.isEmpty()) { QMessageBox::critical(this, tr("Cannot Save Prospect"), QString("<p>") + error[errIndex].msg); error[errIndex].widget->setFocus(); return; } if (_number->text().stripWhiteSpace() != _cachedNumber) { // in anticipation of converting prospects to customers, disallow overlap of prospect and customer numbers q.prepare( "SELECT prospect_name AS name " "FROM prospect " "WHERE (UPPER(prospect_number)=UPPER(:prospect_number)) " " AND (prospect_id<>:prospect_id) " "UNION " "SELECT cust_name AS name " "FROM cust " "WHERE (UPPER(cust_number)=UPPER(:prospect_number));" ); q.bindValue(":prospect_name", _number->text().stripWhiteSpace()); q.bindValue(":prospect_id", _prospectid); q.exec(); if (q.first()) { QMessageBox::critical( this, tr("Prospect Number Used"), tr("<p>The newly entered Prospect Number cannot " "be used as it is currently in use by '%1'. " "Please enter a different Prospect Number." ) .arg(q.value("name").toString()) ); _number->setFocus(); return; } } XSqlQuery rollback; rollback.prepare("ROLLBACK;"); if (! q.exec("BEGIN;")) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } if (saveContact(_contact) < 0) { rollback.exec(); _contact->setFocus(); return; } if (_mode == cEdit) { q.prepare( "UPDATE prospect SET " " prospect_number=:prospect_number," " prospect_name=:prospect_name," " prospect_cntct_id=:prospect_cntct_id," " prospect_comments=:prospect_comments," " prospect_taxauth_id=:prospect_taxauth_id," " prospect_salesrep_id=:prospect_salesrep_id," " prospect_warehous_id=:prospect_warehous_id," " prospect_active=:prospect_active " "WHERE (prospect_id=:prospect_id);" ); } else { q.prepare( "INSERT INTO prospect " "( prospect_id, prospect_number, prospect_name," " prospect_cntct_id, prospect_taxauth_id, prospect_comments," " prospect_salesrep_id, prospect_warehous_id, prospect_active) " " VALUES " "( :prospect_id, :prospect_number, :prospect_name," " :prospect_cntct_id, :prospect_taxauth_id, :prospect_comments," " :prospect_salesrep_id, :prospect_warehous_id, :prospect_active);"); } q.bindValue(":prospect_id", _prospectid); q.bindValue(":prospect_number", _number->text().stripWhiteSpace()); q.bindValue(":prospect_name", _name->text().stripWhiteSpace()); if (_contact->id() > 0) q.bindValue(":prospect_cntct_id", _contact->id()); // else NULL if (_taxauth->id() > 0) q.bindValue(":prospect_taxauth_id", _taxauth->id()); // else NULL if (_salesrep->id() > 0) q.bindValue(":prospect_salesrep_id", _salesrep->id()); // else NULL if (_site->id() > 0) q.bindValue(":prospect_warehous_id", _site->id()); // else NULL q.bindValue(":prospect_comments", _notes->text()); q.bindValue(":prospect_active", QVariant(_active->isChecked(), 0)); q.exec(); if (q.lastError().type() != QSqlError::None) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } if (_crmacct->id() > 0) { q.prepare("UPDATE crmacct SET crmacct_prospect_id = :prospect_id " "WHERE (crmacct_id=:crmacct_id);"); q.bindValue(":prospect_id", _prospectid); q.bindValue(":crmacct_id", _crmacct->id()); q.exec(); if (q.lastError().type() != QSqlError::None) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } } else { /* // This is now done in a trigger q.prepare( "SELECT createCrmAcct(:number, :name, :active, :type, NULL, " " NULL, NULL, :prospect_id, NULL, NULL, :cntct, NULL) AS crmacctid;"); q.bindValue(":number", _number->text().stripWhiteSpace()); q.bindValue(":name", _name->text().stripWhiteSpace()); q.bindValue(":active", QVariant(true, 0)); q.bindValue(":type", "O"); // TODO - when will this be "I"? q.bindValue(":prospect_id", _prospectid); if (_contact->id() > 0) q.bindValue(":cntct", _contact->id()); q.exec(); if (q.first()) { int crmacctid = q.value("crmacctid").toInt(); if (crmacctid <= 0) { rollback.exec(); systemError(this, storedProcErrorLookup("createCrmAcct", crmacctid), __FILE__, __LINE__); return; } _crmacct->setId(crmacctid); } else if (q.lastError().type() != QSqlError::None) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } // need to save contacts again with updated CRM Account if (saveContact(_contact) < 0) { rollback.exec(); _contact->setFocus(); return; } */ } q.exec("COMMIT;"); _NumberGen = -1; omfgThis->sProspectsUpdated(); if (_mode == cNew) omfgThis->sCrmAccountsUpdated(_crmacct->id()); close(); }
void fnSaveStateAndRebuildList(HWND hwnd, struct ClcData *dat) { NMCLISTCONTROL nm; int i, j; ClcGroup *group; ClcContact *contact; cli.pfnHideInfoTip(hwnd, dat); KillTimer(hwnd, TIMERID_INFOTIP); KillTimer(hwnd, TIMERID_RENAME); cli.pfnEndRename(hwnd, dat, 1); OBJLIST<SavedContactState_t> saveContact(10, NumericKeySortT); OBJLIST<SavedGroupState_t> saveGroup(100, NumericKeySortT); OBJLIST<SavedInfoState_t> saveInfo(10, NumericKeySortT); dat->needsResort = 1; group = &dat->list; group->scanIndex = 0; for (;;) { if (group->scanIndex == group->cl.count) { group = group->parent; if (group == NULL) break; } else if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) { group = group->cl.items[group->scanIndex]->group; group->scanIndex = 0; SavedGroupState_t* p = new SavedGroupState_t; p->groupId = group->groupId; p->expanded = group->expanded; saveGroup.insert(p); continue; } else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT) { SavedContactState_t* p = new SavedContactState_t; p->hContact = group->cl.items[group->scanIndex]->hContact; memcpy(p->iExtraImage, group->cl.items[group->scanIndex]->iExtraImage, sizeof(p->iExtraImage)); p->checked = group->cl.items[group->scanIndex]->flags & CONTACTF_CHECKED; saveContact.insert(p); } else if (group->cl.items[group->scanIndex]->type == CLCIT_INFO) { SavedInfoState_t* p = new SavedInfoState_t; p->parentId = (group->parent == NULL) ? -1 : group->groupId; p->contact = *group->cl.items[group->scanIndex]; saveInfo.insert(p); } group->scanIndex++; } cli.pfnFreeGroup(&dat->list); cli.pfnRebuildEntireList(hwnd, dat); group = &dat->list; group->scanIndex = 0; for (;;) { if (group->scanIndex == group->cl.count) { group = group->parent; if (group == NULL) break; } else if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) { group = group->cl.items[group->scanIndex]->group; group->scanIndex = 0; SavedGroupState_t tmp, *p; tmp.groupId = group->groupId; if ((p = saveGroup.find(&tmp)) != NULL) group->expanded = p->expanded; continue; } else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT) { SavedContactState_t tmp, *p; tmp.hContact = group->cl.items[group->scanIndex]->hContact; if ((p = saveContact.find(&tmp)) != NULL) { memcpy(group->cl.items[group->scanIndex]->iExtraImage, p->iExtraImage, sizeof(p->iExtraImage)); if (p->checked) group->cl.items[group->scanIndex]->flags |= CONTACTF_CHECKED; } } group->scanIndex++; } for (i=0; i < saveInfo.getCount(); i++) { if (saveInfo[i].parentId == -1) group = &dat->list; else { if (!cli.pfnFindItem(hwnd, dat, saveInfo[i].parentId | HCONTACT_ISGROUP, &contact, NULL, NULL)) continue; group = contact->group; } j = cli.pfnAddInfoItemToGroup(group, saveInfo[i].contact.flags, _T("")); *group->cl.items[j] = saveInfo[i].contact; } cli.pfnRecalculateGroupCheckboxes(hwnd, dat); cli.pfnRecalcScrollBar(hwnd, dat); nm.hdr.code = CLN_LISTREBUILT; nm.hdr.hwndFrom = hwnd; nm.hdr.idFrom = GetDlgCtrlID(hwnd); SendMessage(GetParent(hwnd), WM_NOTIFY, 0, (LPARAM) & nm); }
void vendor::sSave() { struct { bool condition; QString msg; QWidget *widget; } error[] = { { _number->text().trimmed().length() == 0, tr("Please enter a Number for this new Vendor."), _number }, { _name->text().trimmed().length() == 0, tr("Please enter a Name for this new Vendor."), _name }, { _defaultTerms->id() == -1, tr("You must select a Terms code for this Vendor before continuing."), _defaultTerms }, { _vendtype->id() == -1, tr("You must select a Vendor Type for this Vendor before continuing."), _vendtype }, { _achGroup->isChecked() && _routingNumber->text().stripWhiteSpace().length() == 0 && !omfgThis->_key.isEmpty(), tr("Please enter a Routing Number if ACH Check Printing is enabled."), _routingNumber }, { _achGroup->isChecked() && _routingNumber->text().stripWhiteSpace().length() < 9 && !omfgThis->_key.isEmpty(), tr("Routing Numbers for ACH Check Printing must be 9 digits long."), _routingNumber }, { _achGroup->isChecked() && _achAccountNumber->text().stripWhiteSpace().length() == 0 && !omfgThis->_key.isEmpty(), tr("Please enter an Account Number if ACH Check Printing is enabled."), _achAccountNumber }, { _achGroup->isChecked() && _useACHSpecial->isChecked() && _individualName->text().stripWhiteSpace().length() == 0 && !omfgThis->_key.isEmpty(), tr("Please enter an Individual Name if ACH Check Printing is enabled and " "'%1' is checked.").arg(_useACHSpecial->title()), _individualName } }; for (unsigned int i = 0; i < sizeof(error) / sizeof(error[0]); i++) if (error[i].condition) { QMessageBox::critical(this, tr("Cannot Save Vendor"), error[i].msg); error[i].widget->setFocus(); return; } if (_number->text().trimmed().toUpper() != _cachedNumber.upper()) { q.prepare( "SELECT vend_name " "FROM vendinfo " "WHERE (UPPER(vend_number)=UPPER(:vend_number)) " " AND (vend_id<>:vend_id);" ); q.bindValue(":vend_number", _number->text().trimmed()); q.bindValue(":vend_id", _vendid); q.exec(); if (q.first()) { QMessageBox::critical(this, tr("Vendor Number Used"), tr("<p>The newly entered Vendor Number cannot be " "used as it is already used by the Vendor '%1'. " "Please correct or enter a new Vendor Number." ) .arg(q.value("vend_name").toString()) ); _number->setFocus(); return; } } XSqlQuery rollback; rollback.prepare("ROLLBACK;"); if (! q.exec("BEGIN")) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } int saveResult = _address->save(AddressCluster::CHECK); if (-2 == saveResult) { int answer = QMessageBox::question(this, tr("Question Saving Address"), tr("<p>There are multiple uses of this Vendor's " "Address. What would you like to do?"), tr("Change This One"), tr("Change Address for All"), tr("Cancel"), 2, 2); if (0 == answer) saveResult = _address->save(AddressCluster::CHANGEONE); else if (1 == answer) saveResult = _address->save(AddressCluster::CHANGEALL); } if (saveResult < 0) // not else-if: this is error check for CHANGE{ONE,ALL} { systemError(this, tr("There was an error saving this address (%1).\n" "Check the database server log for errors.") .arg(saveResult), __FILE__, __LINE__); rollback.exec(); _address->setFocus(); return; } if (saveContact(_contact1) < 0) { rollback.exec(); _contact1->setFocus(); return; } if (saveContact(_contact2) < 0) { rollback.exec(); _contact2->setFocus(); return; } QString sql; if (_mode == cEdit) { sql = "UPDATE vendinfo " "SET vend_number=<? value(\"vend_number\") ?>," " vend_accntnum=<? value(\"vend_accntnum\") ?>," " vend_active=<? value(\"vend_active\") ?>," " vend_vendtype_id=<? value(\"vend_vendtype_id\") ?>," " vend_name=<? value(\"vend_name\") ?>," " vend_cntct1_id=<? value(\"vend_cntct1_id\") ?>," " vend_cntct2_id=<? value(\"vend_cntct2_id\") ?>," " vend_addr_id=<? value(\"vend_addr_id\") ?>," " vend_po=<? value(\"vend_po\") ?>," " vend_restrictpurch=<? value(\"vend_restrictpurch\") ?>," " vend_1099=<? value(\"vend_1099\") ?>," " vend_qualified=<? value(\"vend_qualified\") ?>," " vend_comments=<? value(\"vend_comments\") ?>," " vend_pocomments=<? value(\"vend_pocomments\") ?>," " vend_fobsource=<? value(\"vend_fobsource\") ?>," " vend_fob=<? value(\"vend_fob\") ?>," " vend_terms_id=<? value(\"vend_terms_id\") ?>," " vend_shipvia=<? value(\"vend_shipvia\") ?>," " vend_curr_id=<? value(\"vend_curr_id\") ?>," " vend_taxzone_id=<? value(\"vend_taxzone_id\") ?>," " vend_match=<? value(\"vend_match\") ?>," " vend_ach_enabled=<? value(\"vend_ach_enabled\") ?>," "<? if exists(\"key\") ?>" " vend_ach_routingnumber=encrypt(setbytea(<? value(\"vend_ach_routingnumber\") ?>)," " setbytea(<? value(\"key\") ?>), 'bf')," " vend_ach_accntnumber=encrypt(setbytea(<? value(\"vend_ach_accntnumber\") ?>)," " setbytea(<? value(\"key\") ?>), 'bf')," "<? endif ?>" " vend_ach_use_vendinfo=<? value(\"vend_ach_use_vendinfo\") ?>," " vend_ach_accnttype=<? value(\"vend_ach_accnttype\") ?>," " vend_ach_indiv_number=<? value(\"vend_ach_indiv_number\") ?>," " vend_ach_indiv_name=<? value(\"vend_ach_indiv_name\") ?> " "WHERE (vend_id=<? value(\"vend_id\") ?>);" ; } else if (_mode == cNew) sql = "INSERT INTO vendinfo " "( vend_id, vend_number, vend_accntnum," " vend_active, vend_vendtype_id, vend_name," " vend_cntct1_id, vend_cntct2_id, vend_addr_id," " vend_po, vend_restrictpurch," " vend_1099, vend_qualified," " vend_comments, vend_pocomments," " vend_fobsource, vend_fob," " vend_terms_id, vend_shipvia, vend_curr_id," " vend_taxzone_id, vend_match, vend_ach_enabled," " vend_ach_routingnumber, vend_ach_accntnumber," " vend_ach_use_vendinfo," " vend_ach_accnttype, vend_ach_indiv_number," " vend_ach_indiv_name ) " "VALUES " "( <? value(\"vend_id\") ?>," " <? value(\"vend_number\") ?>," " <? value(\"vend_accntnum\") ?>," " <? value(\"vend_active\") ?>," " <? value(\"vend_vendtype_id\") ?>," " <? value(\"vend_name\") ?>," " <? value(\"vend_cntct1_id\") ?>," " <? value(\"vend_cntct2_id\") ?>," " <? value(\"vend_addr_id\") ?>," " <? value(\"vend_po\") ?>," " <? value(\"vend_restrictpurch\") ?>," " <? value(\"vend_1099\") ?>," " <? value(\"vend_qualified\") ?>," " <? value(\"vend_comments\") ?>," " <? value(\"vend_pocomments\") ?>," " <? value(\"vend_fobsource\") ?>," " <? value(\"vend_fob\") ?>," " <? value(\"vend_terms_id\") ?>," " <? value(\"vend_shipvia\") ?>," " <? value(\"vend_curr_id\") ?>, " " <? value(\"vend_taxzone_id\") ?>," " <? value(\"vend_match\") ?>," " <? value(\"vend_ach_enabled\") ?>," "<? if exists(\"key\") ?>" " encrypt(setbytea(<? value(\"vend_ach_routingnumber\") ?>)," " setbytea(<? value(\"key\") ?>), 'bf')," " encrypt(setbytea(<? value(\"vend_ach_accntnumber\") ?>)," " setbytea(<? value(\"key\") ?>), 'bf')," "<? else ?>" " ''," " ''," "<? endif ?>" " <? value(\"vend_ach_use_vendinfo\") ?>," " <? value(\"vend_ach_accnttype\") ?>," " <? value(\"vend_ach_indiv_number\") ?>," " <? value(\"vend_ach_indiv_name\") ?>" " );" ; ParameterList params; params.append("vend_id", _vendid); params.append("vend_vendtype_id", _vendtype->id()); params.append("vend_terms_id", _defaultTerms->id()); params.append("vend_curr_id", _defaultCurr->id()); params.append("vend_number", _number->text().trimmed().upper()); params.append("vend_accntnum", _accountNumber->text().trimmed()); params.append("vend_name", _name->text().trimmed()); if (_contact1->id() > 0) params.append("vend_cntct1_id", _contact1->id()); // else NULL if (_contact2->id() > 0) params.append("vend_cntct2_id", _contact2->id()); // else NULL if (_address->id() > 0) params.append("vend_addr_id", _address->id()); // else NULL params.append("vend_comments", _notes->toPlainText()); params.append("vend_pocomments", _poComments->toPlainText()); params.append("vend_shipvia", _defaultShipVia->text()); params.append("vend_active", QVariant(_active->isChecked())); params.append("vend_po", QVariant(_poItems->isChecked())); params.append("vend_restrictpurch", QVariant(_restrictToItemSource->isChecked())); params.append("vend_1099", QVariant(_receives1099->isChecked())); params.append("vend_qualified", QVariant(_qualified->isChecked())); params.append("vend_match", QVariant(_match->isChecked())); if (!omfgThis->_key.isEmpty()) params.append("key", omfgThis->_key); params.append("vend_ach_enabled", QVariant(_achGroup->isChecked())); params.append("vend_ach_routingnumber",_routingNumber->text().trimmed()); params.append("vend_ach_accntnumber", _achAccountNumber->text().trimmed()); params.append("vend_ach_use_vendinfo", QVariant(! _useACHSpecial->isChecked())); params.append("vend_ach_indiv_number", _individualId->text().trimmed()); params.append("vend_ach_indiv_name", _individualName->text().trimmed()); if (_accountType->currentItem() == 0) params.append("vend_ach_accnttype", "K"); else if (_accountType->currentItem() == 1) params.append("vend_ach_accnttype", "C"); if(_taxzone->isValid()) params.append("vend_taxzone_id", _taxzone->id()); if (_useWarehouseFOB->isChecked()) { params.append("vend_fobsource", "W"); params.append("vend_fob", ""); } else if (_useVendorFOB) { params.append("vend_fobsource", "V"); params.append("vend_fob", _vendorFOB->text().trimmed()); } MetaSQLQuery mql(sql); q = mql.toQuery(params); if (q.lastError().type() != QSqlError::NoError) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } // Get the crmacct that was created by the vendinfo trigger q.prepare("SELECT crmacct_id " "FROM crmacct " "WHERE (crmacct_vend_id=:vend_id);"); q.bindValue(":vend_id", _vendid); q.exec(); if (q.first()) { _crmacctid = q.value("crmacct_id").toInt(); _contact1->setAccount(_crmacctid); _contact2->setAccount(_crmacctid); } else if (!q.lastError().type() == QSqlError::NoError) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } // need to save contacts again with updated CRM Account if (saveContact(_contact1) < 0) { rollback.exec(); _contact1->setFocus(); return; } if (saveContact(_contact2) < 0) { rollback.exec(); _contact2->setFocus(); return; } q.exec("COMMIT;"); _NumberGen = -1; omfgThis->sVendorsUpdated(); if (_mode == cNew) emit newId(_vendid); if(!_ignoreClose) close(); }
bool incident::save(bool partial) { if (! partial) { if(_crmacct->id() == -1) { QMessageBox::critical( this, tr("Incomplete Information"), tr("You must specify the Account that this incident is for.") ); return false; } if(_cntct->id() <= 0 && _cntct->name().simplified().isEmpty()) { QMessageBox::critical( this, tr("Incomplete Information"), tr("You must specify a Contact for this Incident.") ); return false; } if (_cntct->crmAcctId() != _crmacct->id() && _cntct->crmAcctId() > 0) { QMessageBox::critical( this, tr("Inaccurate Information"), tr("This Contact is affiliated with a different CRM Account.") ); return false; } if(_description->text().trimmed().isEmpty()) { QMessageBox::critical( this, tr("Incomplete Information"), tr("You must specify a description for this incident report.") ); _description->setFocus(); return false; } } XSqlQuery rollback; rollback.prepare("ROLLBACK;"); if (!q.exec("BEGIN")) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return false; } if (! partial) { if (saveContact(_cntct) < 0) { rollback.exec(); _cntct->setFocus(); return false; } } if (cNew == _mode && !_saved) q.prepare("INSERT INTO incdt" " (incdt_number, incdt_crmacct_id, incdt_cntct_id," " incdt_summary, incdt_descrip, incdt_item_id," " incdt_status, incdt_assigned_username," " incdt_incdtcat_id, incdt_incdtseverity_id," " incdt_incdtpriority_id, incdt_incdtresolution_id," " incdt_ls_id) " "VALUES(:incdt_number, :incdt_crmacct_id, :incdt_cntct_id," " :incdt_description, :incdt_notes, :incdt_item_id," " :incdt_status, :incdt_assigned_username," " :incdt_incdtcat_id, :incdt_incdtseverity_id," " :incdt_incdtpriority_id, :incdt_incdtresolution_id," " :incdt_ls_id);" ); else if (cEdit == _mode || _saved) q.prepare("UPDATE incdt" " SET incdt_cntct_id=:incdt_cntct_id," " incdt_crmacct_id=:incdt_crmacct_id," " incdt_summary=:incdt_description," " incdt_descrip=:incdt_notes," " incdt_item_id=:incdt_item_id," " incdt_status=:incdt_status," " incdt_assigned_username=:incdt_assigned_username," " incdt_incdtcat_id=:incdt_incdtcat_id," " incdt_incdtpriority_id=:incdt_incdtpriority_id," " incdt_incdtseverity_id=:incdt_incdtseverity_id," " incdt_incdtresolution_id=:incdt_incdtresolution_id," " incdt_ls_id=:incdt_ls_id" " WHERE (incdt_id=:incdt_id); "); q.bindValue(":incdt_id", _incdtid); q.bindValue(":incdt_number", _number->text()); if (_crmacct->id() > 0) q.bindValue(":incdt_crmacct_id", _crmacct->id()); if (_cntct->id() > 0) q.bindValue(":incdt_cntct_id", _cntct->id()); q.bindValue(":incdt_description", _description->text().trimmed()); q.bindValue(":incdt_notes", _notes->text().trimmed()); if(-1 != _item->id()) q.bindValue(":incdt_item_id", _item->id()); if(_assignedTo->isValid()) q.bindValue(":incdt_assigned_username", _assignedTo->username()); q.bindValue(":incdt_status", _statusCodes.at(_status->currentIndex())); if(_category->isValid()) q.bindValue(":incdt_incdtcat_id", _category->id()); if(_severity->isValid()) q.bindValue(":incdt_incdtseverity_id", _severity->id()); if(_priority->isValid()) q.bindValue(":incdt_incdtpriority_id", _priority->id()); if(_resolution->isValid()) q.bindValue(":incdt_incdtresolution_id", _resolution->id()); if ((_item->id() != -1) && (_lotserial->id() != -1)) q.bindValue(":incdt_ls_id", _lotserial->id()); if(!q.exec() && q.lastError().type() != QSqlError::None) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return false; } q.exec("COMMIT;"); if(q.lastError().type() != QSqlError::None) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return false; } if (cNew == _mode && ! _saved) { q.exec("SELECT CURRVAL('incdt_incdt_id_seq') AS result;"); if (q.first()) _incdtid = q.value("result").toInt(); else if(q.lastError().type() != QSqlError::None) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return false; } } _saved = true; return true; }
void customer::sSave() { if (_number->text().stripWhiteSpace().length() == 0) { QMessageBox::critical( this, tr("Enter Customer Number"), tr("You must enter a number for this Customer before continuing") ); _number->setFocus(); return; } if (_custtype->id() == -1) { QMessageBox::critical( this, tr("Select Customer Type"), tr("You must select a Customer Type code for this Customer before continuing.") ); _terms->setFocus(); return; } if (_terms->id() == -1) { QMessageBox::critical( this, tr("Select Terms"), tr("You must select a Terms code for this Customer before continuing.") ); _terms->setFocus(); return; } if (_salesrep->id() == -1) { QMessageBox::critical( this, tr("Select Sales Rep."), tr("You must select a Sales Rep. for this Customer before continuing.") ); _salesrep->setFocus(); return; } if (_shipform->id() == -1) { QMessageBox::critical( this, tr("Select Default Shipping Form"), tr("You must select a default Shipping Form for this Customer before continuing.") ); _shipform->setFocus(); return; } if (_salesrep->currentItem() == -1) { QMessageBox::warning( this, tr("Select Sales Representative"), tr( "You must select a Sales Representative before adding this Customer." )); _salesrep->setFocus(); return; } if (_number->text().stripWhiteSpace() != _cachedNumber) { q.prepare( "SELECT cust_name " "FROM custinfo " "WHERE (UPPER(cust_number)=UPPER(:cust_number)) " " AND (cust_id<>:cust_id);" ); q.bindValue(":cust_name", _number->text().stripWhiteSpace()); q.bindValue(":cust_id", _custid); q.exec(); if (q.first()) { QMessageBox::critical( this, tr("Customer Number Used"), tr( "The newly entered Customer Number cannot be used as it is currently\n" "in use by the Customer '%1'. Please correct or enter a new Customer Number." ) .arg(q.value("cust_name").toString()) ); _number->setFocus(); return; } } //Check to see if this is a prospect with quotes bool convertQuotes = false; q.prepare("SELECT * FROM prospect, quhead " " WHERE ((prospect_id=quhead_cust_id) " " AND (prospect_id=:prospect_id)); "); q.bindValue(":prospect_id", _custid); q.exec(); if (q.first()) if (_privleges->check("ConvertQuotes") && QMessageBox::question(this, tr("Convert"), tr("<p>Do you want to convert all of the Quotes " "for the Prospect to Sales Orders?"), QMessageBox::Yes | QMessageBox::Default, QMessageBox::No) == QMessageBox::Yes) convertQuotes = true; if (! q.exec("BEGIN")) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } XSqlQuery rollback; rollback.prepare("ROLLBACK;"); if (saveContact(_billCntct) < 0) { rollback.exec(); _billCntct->setFocus(); return; } if (saveContact(_corrCntct) < 0) { rollback.exec(); _corrCntct->setFocus(); return; } if (_mode == cEdit) { q.prepare( "UPDATE custinfo SET " " cust_number=:cust_number, cust_name=:cust_name," " cust_salesrep_id=:cust_salesrep_id," " cust_corrcntct_id=:cust_corrcntct_id, cust_cntct_id=:cust_cntct_id," " cust_custtype_id=:cust_custtype_id, cust_balmethod=:cust_balmethod," " cust_creditlmt=:cust_creditlmt, cust_creditlmt_curr_id=:cust_creditlmt_curr_id," " cust_creditrating=:cust_creditrating," " cust_autoupdatestatus=:cust_autoupdatestatus, cust_autoholdorders=:cust_autoholdorders," " cust_creditstatus=:cust_creditstatus," " cust_backorder=:cust_backorder, cust_ffshipto=:cust_ffshipto, cust_ffbillto=:cust_ffbillto," " cust_commprcnt=:cust_commprcnt," " cust_partialship=:cust_partialship, cust_shipvia=:cust_shipvia," " cust_shipchrg_id=:cust_shipchrg_id, cust_shipform_id=:cust_shipform_id," " cust_terms_id=:cust_terms_id," " cust_discntprcnt=:cust_discntprcnt," " cust_taxauth_id=:cust_taxauth_id, " " cust_active=:cust_active, cust_usespos=:cust_usespos," " cust_blanketpos=:cust_blanketpos, cust_comments=:cust_comments," " cust_emaildelivery=:cust_emaildelivery, cust_ediemail=:cust_ediemail," " cust_edisubject=:cust_edisubject, cust_edifilename=:cust_edifilename," " cust_ediemailbody=:cust_ediemailbody, cust_edicc=:cust_edicc," " cust_ediprofile_id=:cust_ediprofile_id, " " cust_soemaildelivery=:cust_soemaildelivery, cust_soediemail=:cust_soediemail," " cust_soedisubject=:cust_soedisubject, cust_soedifilename=:cust_soedifilename," " cust_soediemailbody=:cust_soediemailbody, cust_soedicc=:cust_soedicc," " cust_soediprofile_id=:cust_soediprofile_id, " " cust_preferred_warehous_id=:cust_preferred_warehous_id, " " cust_curr_id=:cust_curr_id " "WHERE (cust_id=:cust_id);" ); } else q.prepare( "INSERT INTO custinfo " "( cust_id, cust_number," " cust_salesrep_id, cust_name," " cust_corrcntct_id, cust_cntct_id," " cust_custtype_id, cust_balmethod," " cust_creditlmt, cust_creditlmt_curr_id," " cust_creditrating, cust_creditstatus," " cust_autoupdatestatus, cust_autoholdorders," " cust_backorder, cust_ffshipto, cust_ffbillto," " cust_commprcnt, cust_partialship," " cust_shipvia," " cust_shipchrg_id, cust_shipform_id, cust_terms_id," " cust_discntprcnt, cust_taxauth_id, " " cust_active, cust_usespos, cust_blanketpos, cust_comments," " cust_emaildelivery, cust_ediemail, cust_edisubject," " cust_edifilename, cust_ediemailbody, cust_edicc, " " cust_ediprofile_id," " cust_soemaildelivery, cust_soediemail, cust_soedisubject," " cust_soedifilename, cust_soediemailbody, cust_soedicc, " " cust_soediprofile_id, cust_preferred_warehous_id, " " cust_curr_id ) " "VALUES " "( :cust_id, :cust_number," " :cust_salesrep_id, :cust_name," " :cust_corrcntct_id, :cust_cntct_id," " :cust_custtype_id, :cust_balmethod," " :cust_creditlmt, :cust_creditlmt_curr_id," " :cust_creditrating, :cust_creditstatus," " :cust_autoupdatestatus, :cust_autoholdorders," " :cust_backorder, :cust_ffshipto, :cust_ffbillto," " :cust_commprcnt, :cust_partialship," " :cust_shipvia," " :cust_shipchrg_id, :cust_shipform_id, :cust_terms_id," " :cust_discntprcnt, :cust_taxauth_id," " :cust_active, :cust_usespos, :cust_blanketpos, :cust_comments," " :cust_emaildelivery, :cust_ediemail, :cust_edisubject," " :cust_edifilename, :cust_ediemailbody, :cust_edicc," " :cust_soediprofile_id," " :cust_soemaildelivery, :cust_soediemail, :cust_soedisubject," " :cust_soedifilename, :cust_soediemailbody, :cust_soedicc," " :cust_soediprofile_id, :cust_preferred_warehous_id, " " :cust_curr_id ) " ); q.bindValue(":cust_id", _custid); q.bindValue(":cust_number", _number->text().stripWhiteSpace()); q.bindValue(":cust_name", _name->text().stripWhiteSpace()); q.bindValue(":cust_salesrep_id", _salesrep->id()); if (_corrCntct->id() > 0) q.bindValue(":cust_corrcntct_id", _corrCntct->id()); // else NULL if (_billCntct->id() > 0) q.bindValue(":cust_cntct_id", _billCntct->id()); // else NULL q.bindValue(":cust_custtype_id", _custtype->id()); if (_balanceMethod->currentItem() == 0) q.bindValue(":cust_balmethod", "B"); else q.bindValue(":cust_balmethod", "O"); if (_inGoodStanding->isChecked()) q.bindValue(":cust_creditstatus", "G"); else if (_onCreditWarning->isChecked()) q.bindValue(":cust_creditstatus", "W"); else if (_onCreditHold->isChecked()) q.bindValue(":cust_creditstatus", "H"); else q.bindValue(":cust_creditstatus", "U"); q.bindValue(":cust_creditlmt_curr_id", _creditLimit->id()); q.bindValue(":cust_creditlmt", _creditLimit->localValue()); q.bindValue(":cust_creditrating", _creditRating->text()); q.bindValue(":cust_autoupdatestatus", QVariant(_autoUpdateStatus->isChecked(), 0)); q.bindValue(":cust_autoholdorders", QVariant(_autoHoldOrders->isChecked(), 0)); q.bindValue(":cust_commprcnt", (_defaultCommissionPrcnt->toDouble() / 100.0)); q.bindValue(":cust_terms_id", _terms->id()); q.bindValue(":cust_discntprcnt", (_defaultDiscountPrcnt->toDouble() / 100.0)); if (_taxauth->isValid()) q.bindValue(":cust_taxauth_id", _taxauth->id()); q.bindValue(":cust_shipvia", _shipvia->currentText()); q.bindValue(":cust_shipchrg_id", _shipchrg->id()); q.bindValue(":cust_shipform_id", _shipform->id()); q.bindValue(":cust_active", QVariant(_active->isChecked(), 0)); q.bindValue(":cust_usespos", QVariant(_usesPOs->isChecked(), 0)); q.bindValue(":cust_blanketpos", QVariant(_blanketPos->isChecked(), 0)); q.bindValue(":cust_partialship", QVariant(_partialShipments->isChecked(), 0)); q.bindValue(":cust_backorder", QVariant(_backorders->isChecked(), 0)); q.bindValue(":cust_ffshipto", QVariant(_allowFFShipto->isChecked(), 0)); q.bindValue(":cust_ffbillto", QVariant(_allowFFBillto->isChecked(), 0)); q.bindValue(":cust_comments", _notes->text()); q.bindValue(":cust_emaildelivery", QVariant((_ediProfile->id()==0), 0)); q.bindValue(":cust_ediemail", _ediEmail->text().stripWhiteSpace()); q.bindValue(":cust_edisubject", _ediSubject->text().stripWhiteSpace()); q.bindValue(":cust_edifilename", _ediFilename->text().stripWhiteSpace()); q.bindValue(":cust_ediemailbody", _ediEmailBody->text().stripWhiteSpace()); q.bindValue(":cust_edicc", _ediCC->text().stripWhiteSpace()); q.bindValue(":cust_soemaildelivery", QVariant((_soEdiProfile->id()==0), 0)); q.bindValue(":cust_soediemail", _soEdiEmail->text().stripWhiteSpace()); q.bindValue(":cust_soedisubject", _soEdiSubject->text().stripWhiteSpace()); q.bindValue(":cust_soedifilename", _soEdiFilename->text().stripWhiteSpace()); q.bindValue(":cust_soediemailbody", _soEdiEmailBody->text().stripWhiteSpace()); q.bindValue(":cust_soedicc", _soEdiCC->text().stripWhiteSpace()); q.bindValue(":cust_preferred_warehous_id", _sellingWarehouse->id()); q.bindValue(":cust_curr_id", _currency->id()); if(_ediProfile->id() > 0) q.bindValue(":cust_ediprofile_id", _ediProfile->id()); if(_soEdiProfile->id() > 0) q.bindValue(":cust_soediprofile_id", _soEdiProfile->id()); q.exec(); if (q.lastError().type() != QSqlError::None) { rollback.exec(); systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } //Save characteristics if (_widgetStack->currentIndex() == 1) { q.prepare("SELECT updateCharAssignment('C', :target_id, :char_id, :char_value);"); QModelIndex idx1, idx2; for(int i = 0; i < _custchar->rowCount(); i++) { idx1 = _custchar->index(i, 0); idx2 = _custchar->index(i, 1); q.bindValue(":target_id", _custid); q.bindValue(":char_id", _custchar->data(idx1, Qt::UserRole)); q.bindValue(":char_value", _custchar->data(idx2, Qt::DisplayRole)); q.exec(); } } if (convertQuotes) { q.prepare("SELECT MIN(convertQuote(quhead_id)) AS result " "FROM quhead " "WHERE (quhead_cust_id=:id);"); q.bindValue(":id", _custid); q.exec(); if (q.first()) { int result = q.value("result").toInt(); if (result < 0) { systemError(this, storedProcErrorLookup("convertQuote", result), __FILE__, __LINE__); // not fatal } omfgThis->sQuotesUpdated(-1); } else if (q.lastError().type() != QSqlError::None) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); // not fatal } } q.exec("COMMIT;"); omfgThis->sCustomersUpdated(_custid, TRUE); close(); }