void ScheduleDialog::accept() { RecordList assetSelection = mAssetTree->selection(); Element e = assetSelection.isEmpty() ? Element(mProject) : Element(assetSelection[0]); if( mSchedule.isRecord() ) { Database::current()->beginTransaction( "Modify Schedule" ); mSchedule.setDuration( Interval().addHours(mHoursSpin->value()) ); mSchedule.setElement( e ); mSchedule.setAssetType( mAssetType ); mSchedule.setUser( mEmployee ); mSchedule.setDate( mDateStartEdit->date() ); mSchedule.setCreatedByUser( User::currentUser() ); mSchedule.commit(); Database::current()->commitTransaction(); } else { Database::current()->beginTransaction( "Create Schedule" ); ScheduleList toCommit; QDate start = mDateStartEdit->date(); QDate end = mDateEndEdit->date(); while( start <= end ) { Schedule s; s.setUser( mEmployee ); s.setElement( e ); s.setAssetType( mAssetType ); s.setDate( start ); s.setDuration( Interval().addHours(mHoursSpin->value()) ); s.setCreatedByUser( User::currentUser() ); toCommit += s; start = start.addDays( 1 ); } toCommit.commit(); if( !e.users().contains( mEmployee ) ) { ElementUser eu; eu.setElement( e ); eu.setUser( mEmployee ); eu.commit(); } Database::current()->commitTransaction(); } QDialog::accept(); }
void ScheduleDialog::updateAssets() { if( mDisableUpdates ) return; bool en = mAssetType.isRecord() && mProject.isRecord(); mAssetTree->setEnabled( en ); mAssets.clear(); if( !en ) return; mAssets = Element::recordsByProject( mProject ); if( mTypeFilterAssetsCheck->isChecked() ) mAssets = mAssets.filter( "assettype", mAssetType.key() ); //LOG_5( "TimeEntryDialog::updateAssets: Got " + QString::number( list.size() ) + " assets" ); /* st_foreach( ElementIter, it, list ) { Element e(*it); QVariant v = e.getValue( "allowTime" ); if( (v.isNull() && e.children().isEmpty()) || (!v.isNull() && v.toBool()) ) mAssets += e; } */ RecordList sel = mAssetTree->selection(); mAssetModel->setRootList( TimeEntryDialog::filterAssets( mAssets, mAssetFilterEdit->text() ) ); if( !sel.isEmpty() ) { mAssetTree->setSelection( sel ); mAssetTree->scrollTo( sel ); } }