protected function SetupDepreciationClass() { // Lookup Object PK information from PathInfo (if applicable) // Set mode to Edit or New depending on what's found $intDepreciationClassId = QApplication::QueryString('intDepreciationClassId'); if ($intDepreciationClassId) { $this->objDepreciationClass = DepreciationClass::Load($intDepreciationClassId); if (!$this->objDepreciationClass) { throw new Exception('Could not find a DepreciationClass object with PK arguments: ' . $intDepreciationClassId); } $this->blnEditMode = true; } else { $this->objDepreciationClass = new DepreciationClass(); $this->blnEditMode = false; } }
/** * Static Helper Method to Create using PK arguments * You must pass in the PK arguments on an object to load, or leave it blank to create a new one. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to * edit, or if we are also allowed to create a new one, etc. * * @param mixed $objParentObject QForm or QPanel which will be using this DepreciationClassMetaControl * @param integer $intDepreciationClassId primary key value * @param QMetaControlCreateType $intCreateType rules governing DepreciationClass object creation - defaults to CreateOrEdit * @return DepreciationClassMetaControl */ public static function Create($objParentObject, $intDepreciationClassId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intDepreciationClassId)) { $objDepreciationClass = DepreciationClass::Load($intDepreciationClassId); // DepreciationClass was found -- return it! if ($objDepreciationClass) { return new DepreciationClassMetaControl($objParentObject, $objDepreciationClass); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a DepreciationClass object with PK arguments: ' . $intDepreciationClassId); } } // If EditOnly is specified, throw an exception } else { if ($intCreateType == QMetaControlCreateType::EditOnly) { throw new QCallerException('No PK arguments specified'); } } // If we are here, then we need to create a new record return new DepreciationClassMetaControl($objParentObject, new DepreciationClass()); }
protected function lblBookValue_Update() { if ($objAssetModel = AssetModel::Load($this->lstAssetModel->SelectedValue)) { $intDepreciationClassId = $objAssetModel->DepreciationClassId; if (!empty($intDepreciationClassId) && DepreciationClass::Load($intDepreciationClassId)) { $life = DepreciationClass::Load($intDepreciationClassId)->Life; } } if (is_numeric($this->txtPurchaseCost->Text) && isset($life) && $this->calPurchaseDate->DateTime instanceof DateTime && QDateTime::Now() > $this->calPurchaseDate->DateTime) { $interval = QDateTime::Now()->diff($this->calPurchaseDate->DateTime); $interval = $interval->y * 12 + $interval->m; $fltBookValue = $this->txtPurchaseCost->Text - $this->txtPurchaseCost->Text * ($interval / $life); // prevent negative results $fltBookValue = $fltBookValue < 0 ? 0 : $fltBookValue; $this->lblBookValue->Text = money_format('%i', $fltBookValue); } else { $this->lblBookValue->Text = '...'; } }
/** * Reload this DepreciationClass from the database. * @return void */ public function Reload() { // Make sure we are actually Restored from the database if (!$this->__blnRestored) { throw new QCallerException('Cannot call Reload() on a new, unsaved DepreciationClass object.'); } // Reload the Object $objReloaded = DepreciationClass::Load($this->intDepreciationClassId); // Update $this's local variables to match $this->DepreciationMethodQtypeId = $objReloaded->DepreciationMethodQtypeId; $this->strShortDescription = $objReloaded->strShortDescription; $this->intLife = $objReloaded->intLife; }
/** * Override method to perform a property "Get" * This will get the value of $strName * * @param string $strName Name of the property to get * @return mixed */ public function __get($strName) { switch ($strName) { /////////////////// // Member Variables /////////////////// case 'AssetModelId': // Gets the value for intAssetModelId (Read-Only PK) // @return integer return $this->intAssetModelId; case 'CategoryId': // Gets the value for intCategoryId // @return integer return $this->intCategoryId; case 'ManufacturerId': // Gets the value for intManufacturerId // @return integer return $this->intManufacturerId; case 'AssetModelCode': // Gets the value for strAssetModelCode // @return string return $this->strAssetModelCode; case 'ShortDescription': // Gets the value for strShortDescription (Not Null) // @return string return $this->strShortDescription; case 'LongDescription': // Gets the value for strLongDescription // @return string return $this->strLongDescription; case 'ImagePath': // Gets the value for strImagePath // @return string return $this->strImagePath; case 'CreatedBy': // Gets the value for intCreatedBy // @return integer return $this->intCreatedBy; case 'CreationDate': // Gets the value for dttCreationDate // @return QDateTime return $this->dttCreationDate; case 'ModifiedBy': // Gets the value for intModifiedBy // @return integer return $this->intModifiedBy; case 'ModifiedDate': // Gets the value for strModifiedDate (Read-Only Timestamp) // @return string return $this->strModifiedDate; case 'DepreciationClassId': // Gets the value for intDepreciationClassId // @return integer return $this->intDepreciationClassId; /////////////////// // Member Objects /////////////////// /////////////////// // Member Objects /////////////////// case 'Category': // Gets the value for the Category object referenced by intCategoryId // @return Category try { if (!$this->objCategory && !is_null($this->intCategoryId)) { $this->objCategory = Category::Load($this->intCategoryId); } return $this->objCategory; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'Manufacturer': // Gets the value for the Manufacturer object referenced by intManufacturerId // @return Manufacturer try { if (!$this->objManufacturer && !is_null($this->intManufacturerId)) { $this->objManufacturer = Manufacturer::Load($this->intManufacturerId); } return $this->objManufacturer; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'CreatedByObject': // Gets the value for the UserAccount object referenced by intCreatedBy // @return UserAccount try { if (!$this->objCreatedByObject && !is_null($this->intCreatedBy)) { $this->objCreatedByObject = UserAccount::Load($this->intCreatedBy); } return $this->objCreatedByObject; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'ModifiedByObject': // Gets the value for the UserAccount object referenced by intModifiedBy // @return UserAccount try { if (!$this->objModifiedByObject && !is_null($this->intModifiedBy)) { $this->objModifiedByObject = UserAccount::Load($this->intModifiedBy); } return $this->objModifiedByObject; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'DepreciationClass': // Gets the value for the DepreciationClass object referenced by intDepreciationClassId // @return DepreciationClass try { if (!$this->objDepreciationClass && !is_null($this->intDepreciationClassId)) { $this->objDepreciationClass = DepreciationClass::Load($this->intDepreciationClassId); } return $this->objDepreciationClass; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'AssetModelCustomFieldHelper': // Gets the value for the AssetModelCustomFieldHelper object that uniquely references this AssetModel // by objAssetModelCustomFieldHelper (Unique) // @return AssetModelCustomFieldHelper try { if ($this->objAssetModelCustomFieldHelper === false) { // We've attempted early binding -- and the reverse reference object does not exist return null; } if (!$this->objAssetModelCustomFieldHelper) { $this->objAssetModelCustomFieldHelper = AssetModelCustomFieldHelper::LoadByAssetModelId($this->intAssetModelId); } return $this->objAssetModelCustomFieldHelper; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// case '_Asset': // Gets the value for the private _objAsset (Read-Only) // if set due to an expansion on the asset.asset_model_id reverse relationship // @return Asset return $this->_objAsset; case '_AssetArray': // Gets the value for the private _objAssetArray (Read-Only) // if set due to an ExpandAsArray on the asset.asset_model_id reverse relationship // @return Asset[] return (array) $this->_objAssetArray; case '_AssetCustomFieldAssetModel': // Gets the value for the private _objAssetCustomFieldAssetModel (Read-Only) // if set due to an expansion on the asset_custom_field_asset_model.asset_model_id reverse relationship // @return AssetCustomFieldAssetModel return $this->_objAssetCustomFieldAssetModel; case '_AssetCustomFieldAssetModelArray': // Gets the value for the private _objAssetCustomFieldAssetModelArray (Read-Only) // if set due to an ExpandAsArray on the asset_custom_field_asset_model.asset_model_id reverse relationship // @return AssetCustomFieldAssetModel[] return (array) $this->_objAssetCustomFieldAssetModelArray; case '__Restored': return $this->__blnRestored; default: try { return parent::__get($strName); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } }