protected function Form_Create()
 {
     if (QApplication::QueryString('intDownloadCsv')) {
         $this->RenderBegin(false);
         session_cache_limiter('must-revalidate');
         // force a "no cache" effect
         header("Pragma: hack");
         // IE chokes on "no cache", so set to something, anything, else.
         $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT";
         header($ExpStr);
         header('Content-Type: text/csv');
         header('Content-Disposition: csv; filename=skipped_records.csv');
         $file = fopen(sprintf("%s/%s_contact_skipped.csv", __TRACMOR_TMP__, $_SESSION['intUserAccountId']), "r");
         ob_end_clean();
         while ($row = fgets($file, 1000)) {
             print $row;
             @ob_flush();
             flush();
         }
         QApplication::$JavaScriptArray = array();
         QApplication::$JavaScriptArrayHighPriority = array();
         $this->RenderEnd(false);
         exit;
     }
     // Create the Header Menu
     $this->ctlHeaderMenu_Create();
     //$this->ctlShortcutMenu_Create();
     $this->pnlMain_Create();
     $this->pnlStepOne_Create();
     $this->Buttons_Create();
     $this->intStep = 1;
     $this->intSkippedRecordCount = 0;
     $this->blnImportEnd = true;
     $this->btnRemoveArray = array();
     $this->arrItemCustomField = array();
     $this->Labels_Create();
     $this->objDatabase = Asset::GetDatabase();
     // Load Custom Field
     foreach (CustomField::LoadArrayByActiveFlagEntity(1, EntityQtype::Contact) as $objCustomField) {
         $this->arrItemCustomField[$objCustomField->CustomFieldId] = $objCustomField;
     }
     $this->blnError = true;
     $intRoleId = QApplication::$objUserAccount->RoleId;
     $objRoleEntityQtypeBuiltInAuthorization = RoleEntityQtypeBuiltInAuthorization::LoadByRoleIdEntityQtypeIdAuthorizationId($intRoleId, EntityQtype::Contact, 2);
     // Check the user have edit permissions
     if ($objRoleEntityQtypeBuiltInAuthorization && $objRoleEntityQtypeBuiltInAuthorization->AuthorizedFlag) {
         $this->blnError = false;
     }
     if (isset($intCustomFieldIdArray) && count($intCustomFieldIdArray)) {
         //QApplication::$Database[1]->EnableProfiling();
         // Load restrict permisions for Custom Fields
         $objConditions = QQ::AndCondition(QQ::Equal(QQN::RoleEntityQtypeCustomFieldAuthorization()->RoleId, (string) $intRoleId), QQ::In(QQN::RoleEntityQtypeCustomFieldAuthorization()->EntityQtypeCustomField->CustomFieldId, $intCustomFieldIdArray), QQ::Equal(QQN::RoleEntityQtypeCustomFieldAuthorization()->AuthorizedFlag, false));
         $objClauses = array();
         array_push($objClauses, QQ::Expand(QQN::RoleEntityQtypeCustomFieldAuthorization()->EntityQtypeCustomField->EntityQtypeCustomFieldId));
         array_push($objClauses, QQ::OrderBy(QQN::RoleEntityQtypeCustomFieldAuthorization()->EntityQtypeCustomFieldId));
         $arrRoleEntityQtypeCustomFieldAuthorization = RoleEntityQtypeCustomFieldAuthorization::QueryArray($objConditions, $objClauses);
         if ($arrRoleEntityQtypeCustomFieldAuthorization) {
             foreach ($arrRoleEntityQtypeCustomFieldAuthorization as $objRoleAuth) {
                 if (array_key_exists($objRoleAuth->EntityQtypeCustomField->CustomFieldId, $this->arrAssetCustomField)) {
                     unset($this->arrAssetCustomField[$objRoleAuth->EntityQtypeCustomField->CustomFieldId]);
                 }
             }
         }
         //QApplication::$Database[1]->OutputProfiling();
     }
     $this->intUserArray = array();
     // Load Users
     foreach (UserAccount::LoadAll() as $objUser) {
         $this->intUserArray[strtolower($objUser->Username)] = $objUser->UserAccountId;
     }
     $this->strAcceptibleMimeArray = array('text/plain' => 'txt', 'text/comma-separated-values' => 'csv', 'text/csv' => 'csv', 'text/x-comma-separated-values' => 'csv', 'application/vnd.ms-excel' => 'csv', 'application/csv' => 'csv', 'text/x-csv' => 'csv');
 }
Exemple #2
0
 public static function CountByEndDate($dates_condition)
 {
     $strQuery = sprintf(" SELECT\n                                 COUNT(`asset`.`asset_id`) AS `row_count`,\n                                 `asset`.`asset_id`   AS `asset_id`,\n\t\t\t\t                 `asset`.`depreciation_flag` AS `depreciation_flag`,\n\t\t\t\t\t             `asset`.`purchase_date` AS `purchase_date`,\n\t\t\t\t\t             `asset`.`asset_model_id`,\n\t\t\t\t\t             `asset_model`.`short_description` AS `model_name`,\n\t\t\t\t\t              DATE_ADD(`asset`.`purchase_date`, INTERVAL `depreciation_class`.`life` MONTH) AS `end_date`\n                                  FROM `asset` AS `asset`\n                                  LEFT JOIN `asset_model` AS `asset_model`\n                                  ON `asset`.`asset_model_id`=`asset_model`.`asset_model_id`\n                                  LEFT JOIN `depreciation_class` AS `depreciation_class`\n                                  ON `depreciation_class`.`depreciation_class_id`=`asset_model`.`depreciation_class_id`\n                                  WHERE `depreciation_flag` = 1\n                                  %s\n\t\t\t\t\t           ", $dates_condition);
     $objDatabase = Asset::GetDatabase();
     $objDbResult = $objDatabase->Query($strQuery);
     $strDbRow = $objDbResult->FetchRow();
     return QType::Cast($strDbRow[0], QType::Integer);
 }
Exemple #3
0
 protected function UndoImport()
 {
     $objDatabase = Asset::GetDatabase();
     //$strQuery = "SET FOREIGN_KEY_CHECKS=0;";
     //$objDatabase->NonQuery($strQuery);
     if (isset($this->arrOldAssetArray) && count($this->arrOldAssetArray)) {
         $strQuery = "SET FOREIGN_KEY_CHECKS=0;";
         $objDatabase->NonQuery($strQuery);
         foreach ($this->arrOldAssetArray as $intAssetId => $arrOldAsset) {
             $strModifiedBy = !$arrOldAsset['ModifiedBy'] || strtolower($arrOldAsset['ModifiedBy']) == "null" || $arrOldAsset['ModifiedBy'] == '0' ? "null" : "'" . $arrOldAsset['ModifiedBy'] . "'";
             $strModifiedDate = !$arrOldAsset['ModifiedDate'] || strtolower($arrOldAsset['ModifiedDate']) == "null" || $arrOldAsset['ModifiedDate'] == '0000-00-00 00:00:00' ? "null" : "'" . $arrOldAsset['ModifiedDate'] . "'";
             $strQuery = sprintf("UPDATE `asset` SET `asset_model_id`='%s', `modified_by`=%s, `modified_date`=%s WHERE `asset_id`='%s'", $arrOldAsset['AssetModelId'], $strModifiedBy, $strModifiedDate, $intAssetId);
             $objDatabase->NonQuery($strQuery);
             if (count($arrOldAsset['CFV'])) {
                 $strCFV = array();
                 foreach ($arrOldAsset['CFV'] as $intCustomFieldId => $strCFV) {
                     $strCFVArray[] = sprintf("`cfv_%s`='%s'", $intCustomFieldId, $strCFV);
                 }
                 $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", implode(", ", $strCFVArray), $intAssetId);
                 $objDatabase->NonQuery($strQuery);
             }
         }
         $strQuery = "SET FOREIGN_KEY_CHECKS=1;";
         $objDatabase->NonQuery($strQuery);
     }
     //$strQuery = "SET FOREIGN_KEY_CHECKS=0;";
     //$objDatabase->NonQuery($strQuery);
     if (count($this->objNewAssetArray)) {
         $strQuery = sprintf("DELETE FROM `asset` WHERE `asset_id` IN (%s)", implode(", ", array_keys($this->objNewAssetArray)));
         $objDatabase->NonQuery($strQuery);
         // Do not need to delete it manually (automatically CASCADE deletion)
         //$strQuery = sprintf("DELETE FROM `asset_custom_field_helper` WHERE `asset_id` IN (%s)", implode(", ", array_keys($this->objNewAssetArray)));
         //$objDatabase->NonQuery($strQuery);
     }
     if (count($this->objNewAssetModelArray)) {
         $strQuery = sprintf("DELETE FROM `asset_model` WHERE `asset_model_id` IN (%s)", implode(", ", array_keys($this->objNewAssetModelArray)));
         $objDatabase->NonQuery($strQuery);
         // Do not need to delete it manually (automatically CASCADE deletion)
         //$strQuery = sprintf("DELETE FROM `asset_model_custom_field_helper` WHERE `asset_model_id` IN (%s)", implode(", ", array_keys($this->objNewAssetModelArray)));
         //$objDatabase->NonQuery($strQuery);
     }
     if (count($this->objNewManufacturerArray)) {
         $strQuery = sprintf("DELETE FROM `manufacturer` WHERE `manufacturer_id` IN (%s)", implode(", ", array_keys($this->objNewManufacturerArray)));
         $objDatabase->NonQuery($strQuery);
     }
     if (count($this->objNewCategoryArray)) {
         $strQuery = sprintf("DELETE FROM `category` WHERE `category_id` IN (%s)", implode(", ", array_keys($this->objNewCategoryArray)));
         $objDatabase->NonQuery($strQuery);
     }
     if (count($this->objNewLocationArray)) {
         $strQuery = sprintf("DELETE FROM `location` WHERE `location_id` IN (%s)", implode(", ", array_keys($this->objNewLocationArray)));
         $objDatabase->NonQuery($strQuery);
     }
     //$strQuery = "SET FOREIGN_KEY_CHECKS=1;";
     //$objDatabase->NonQuery($strQuery);
 }
Exemple #4
0
 protected function UndoImport()
 {
     $objDatabase = Asset::GetDatabase();
     //$strQuery = "SET FOREIGN_KEY_CHECKS=0;";
     //$objDatabase->NonQuery($strQuery);
     /*if (isset($this->arrOldItemArray) && count($this->arrOldItemArray)) {
           $strQuery = "SET FOREIGN_KEY_CHECKS=0;";
           $objDatabase->NonQuery($strQuery);
           foreach ($this->arrOldItemArray as $intAssetId => $arrOldAsset) {
             $strModifiedBy = (!$arrOldAsset['ModifiedBy'] || strtolower($arrOldAsset['ModifiedBy']) == "null" || $arrOldAsset['ModifiedBy'] == '0') ? "null" : "'" . $arrOldAsset['ModifiedBy'] . "'";
             $strModifiedDate = (!$arrOldAsset['ModifiedDate'] || strtolower($arrOldAsset['ModifiedDate']) == "null" || $arrOldAsset['ModifiedDate'] == '0000-00-00 00:00:00') ? "null" : "'" . $arrOldAsset['ModifiedDate'] . "'";
             $strQuery = sprintf("UPDATE `asset` SET `asset_model_id`='%s', `modified_by`=%s, `modified_date`=%s WHERE `asset_id`='%s'", $arrOldAsset['AssetModelId'], $strModifiedBy, $strModifiedDate, $intAssetId);
             $objDatabase->NonQuery($strQuery);
             if (count($arrOldAsset['CFV'])) {
               $strCFV = array();
               foreach ($arrOldAsset['CFV'] as $intCustomFieldId => $strCFV) {
                 $strCFVArray[] = sprintf("`cfv_%s`='%s'", $intCustomFieldId, $strCFV);
               }
               $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", implode(", ", $strCFVArray), $intAssetId);
               $objDatabase->NonQuery($strQuery);
             }
           }
           $strQuery = "SET FOREIGN_KEY_CHECKS=1;";
           $objDatabase->NonQuery($strQuery);
         }
       if (count($this->objNewManufacturerArray)) {
           $strQuery = sprintf("DELETE FROM `manufacturer` WHERE `manufacturer_id` IN (%s)" , implode(", ", array_keys($this->objNewManufacturerArray)));
           $objDatabase->NonQuery($strQuery);
       }*/
     if (isset($this->arrOldItemArray)) {
         foreach ($this->arrOldItemArray as $intItemId => $objOldItem) {
             $strQuery = sprintf("UPDATE `category` SET `short_description`='%s', `long_description`='%s' WHERE `category_id`='%s'", $objOldItem->ShortDescription, $objOldItem->LongDescription, $objOldItem->CategoryId);
             $objDatabase->NonQuery($strQuery);
             $strCFVArray = array();
             foreach ($this->arrItemCustomField as $objCustomField) {
                 $strCFV = $objOldItem->GetVirtualAttribute($objCustomField->CustomFieldId);
                 $strCFVArray[] = sprintf("`cfv_%s`='%s'", $objCustomField->CustomFieldId, $strCFV);
             }
             if (isset($strCFVArray) && count($strCFVArray)) {
                 $strQuery = sprintf("UPDATE `category_custom_field_helper` SET %s WHERE `category_id`='%s'", implode(", ", $strCFVArray), $intItemId);
                 $objDatabase->NonQuery($strQuery);
             }
         }
     }
     if (count($this->objNewCategoryArray)) {
         $strQuery = sprintf("DELETE FROM `category` WHERE `category_id` IN (%s)", implode(", ", array_keys($this->objNewCategoryArray)));
         $objDatabase->NonQuery($strQuery);
     }
     //$strQuery = "SET FOREIGN_KEY_CHECKS=1;";
     //$objDatabase->NonQuery($strQuery);
 }
Exemple #5
0
    /**
     * Deletes all associated AssetTransactionsAsNew
     * @return void
     */
    public function DeleteAllAssetTransactionsAsNew()
    {
        if (is_null($this->intAssetId)) {
            throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAssetTransactionAsNew on this unsaved Asset.');
        }
        // Get the Database Object for this Class
        $objDatabase = Asset::GetDatabase();
        // Perform the SQL Query
        $objDatabase->NonQuery('
				DELETE FROM
					`asset_transaction`
				WHERE
					`new_asset_id` = ' . $objDatabase->SqlVariable($this->intAssetId) . '
			');
    }
 protected function Form_Create()
 {
     if (QApplication::QueryString('intDownloadCsv')) {
         $this->RenderBegin(false);
         session_cache_limiter('must-revalidate');
         // force a "no cache" effect
         header("Pragma: hack");
         // IE chokes on "no cache", so set to something, anything, else.
         $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT";
         header($ExpStr);
         header('Content-Type: text/csv');
         header('Content-Disposition: csv; filename=skipped_records.csv');
         $file = fopen(sprintf("%s/%s_manufacturer_skipped.csv", __TRACMOR_TMP__, $_SESSION['intUserAccountId']), "r");
         ob_end_clean();
         while ($row = fgets($file, 1000)) {
             print $row;
             @ob_flush();
             flush();
         }
         QApplication::$JavaScriptArray = array();
         QApplication::$JavaScriptArrayHighPriority = array();
         $this->RenderEnd(false);
         exit;
     }
     // Create the Header Menu
     $this->ctlHeaderMenu_Create();
     $this->pnlMain_Create();
     $this->pnlStepOne_Create();
     $this->Buttons_Create();
     $this->intStep = 1;
     $this->intSkippedRecordCount = 0;
     $this->blnImportEnd = true;
     $this->btnRemoveArray = array();
     $this->arrItemCustomField = array();
     $this->Labels_Create();
     $this->objDatabase = Asset::GetDatabase();
     // Load Custom Field
     foreach (CustomField::LoadArrayByActiveFlagEntity(1, EntityQtype::Manufacturer) as $objCustomField) {
         $this->arrItemCustomField[$objCustomField->CustomFieldId] = $objCustomField;
     }
     $this->intUserArray = array();
     // Load Users
     foreach (UserAccount::LoadAll() as $objUser) {
         $this->intUserArray[strtolower($objUser->Username)] = $objUser->UserAccountId;
     }
     $this->strAcceptibleMimeArray = array('text/plain' => 'txt', 'text/comma-separated-values' => 'csv', 'text/csv' => 'csv', 'text/x-comma-separated-values' => 'csv', 'application/vnd.ms-excel' => 'csv', 'application/csv' => 'csv', 'text/x-csv' => 'csv');
 }
Exemple #7
0
 protected function UndoImport()
 {
     $objDatabase = Asset::GetDatabase();
     //$strQuery = "SET FOREIGN_KEY_CHECKS=0;";
     //$objDatabase->NonQuery($strQuery);
     if (isset($this->arrOldItemArray)) {
         $strQuery = "SET FOREIGN_KEY_CHECKS=0;";
         $objDatabase->NonQuery($strQuery);
         foreach ($this->arrOldItemArray as $objOldItem) {
             $objDatabase->NonQuery($objOldItem['ItemSql']);
             if ($objOldItem['CFVSql']) {
                 $objDatabase->NonQuery($objOldItem['CFVSql']);
             }
         }
         $strQuery = "SET FOREIGN_KEY_CHECKS=1;";
         $objDatabase->NonQuery($strQuery);
     }
     //$strQuery = "SET FOREIGN_KEY_CHECKS=0;";
     //$objDatabase->NonQuery($strQuery);
     if (count($this->objNewAssetArray)) {
         $strQuery = sprintf("DELETE FROM `asset` WHERE `asset_id` IN (%s)", implode(", ", array_keys($this->objNewAssetArray)));
         $objDatabase->NonQuery($strQuery);
         // Do not need to delete it manually (automatically CASCADE deletion)
         //$strQuery = sprintf("DELETE FROM `asset_custom_field_helper` WHERE `asset_id` IN (%s)", implode(", ", array_keys($this->objNewAssetArray)));
         //$objDatabase->NonQuery($strQuery);
     }
     //$strQuery = "SET FOREIGN_KEY_CHECKS=1;";
     //$objDatabase->NonQuery($strQuery);
 }
 public function btnSave_Click($strFormId, $strControlId, $strParameter)
 {
     try {
         // Get an instance of the database
         $objDatabase = QApplication::$Database[1];
         // Begin a MySQL Transaction to be either committed or rolled back
         $objDatabase->TransactionBegin();
         // Generate a new AssetCode based on the MinAssetCode value
         // This happens whether or not they are creating a new one or editing an existing one
         if ($this->chkAutoGenerateAssetCode->Checked) {
             $this->txtAssetCode->Text = Asset::GenerateAssetCode();
         }
         $this->objAsset->AssetCode = $this->txtAssetCode->Text;
         $this->objAsset->AssetModelId = $this->lstAssetModel->SelectedValue;
         $blnError = false;
         // If a new asset is being created
         if (!$this->blnEditMode) {
             // Do not allow creation of an asset if asset limit will be exceeded
             $intAssetLimit = is_numeric(QApplication::$TracmorSettings->AssetLimit) ? QApplication::$TracmorSettings->AssetLimit : false;
             if (!$this->blnEditMode) {
                 if ($intAssetLimit && Asset::CountActive() >= $intAssetLimit) {
                     $blnError = true;
                     $this->txtAssetCode->Warning = "Your asset limit has been reached.";
                 }
             }
             //				 Check Depreciation fields
             if (QApplication::$TracmorSettings->DepreciationFlag == '1') {
                 if ($this->chkAssetDepreciation->Checked) {
                     if (!preg_match("/\\b\\d{1,3}(?:,?\\d{3})*(?:\\.\\d{2})?\\b/", $this->txtPurchaseCost->Text) || $this->txtPurchaseCost->Text <= 0) {
                         $blnError = true;
                         $this->txtPurchaseCost->Warning = "Purchase Cost value isn't valid";
                     } elseif (AssetModel::Load($this->lstAssetModel->SelectedValue)->DepreciationClassId != null) {
                         //print $this->calPurchaseDate->DateTime ."||". $this->txtPurchaseCost->Text."|";exit;
                         $this->objAsset->DepreciationFlag = true;
                         $this->objAsset->PurchaseDate = $this->calPurchaseDate->DateTime;
                         $this->objAsset->PurchaseCost = str_replace(',', '', $this->txtPurchaseCost->Text);
                     } else {
                         $blnError = true;
                         $this->chkAssetDepreciation->Warning = "Chosen Model isn't assigned to any Depreciation Class";
                     }
                 }
             }
             // Check to see if the asset tag already exists
             $AssetDuplicate = Asset::LoadByAssetCode($this->txtAssetCode->Text);
             if ($AssetDuplicate) {
                 $blnError = true;
                 $this->txtAssetCode->Warning = "That asset tag is already in use. Please try another.";
             }
             if (!$blnError && $this->txtParentAssetCode->Text) {
                 if ($this->txtParentAssetCode->Text != $this->objAsset->AssetCode) {
                     $objParentAsset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text);
                     if (!$objParentAsset) {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "That asset tag does not exist. Please try another.";
                     } else {
                         if ($this->chkLockToParent->Checked && $objParentAsset->LocationId != $this->lstLocation->SelectedValue) {
                             // If locking child to parent, make sure assets are at the same location
                             $blnError = true;
                             $this->chkLockToParent->Warning = 'Cannot lock to parent asset at another location.';
                         } else {
                             if ($this->chkLockToParent->Checked && ($objParentAsset->CheckedOutFlag || $objParentAsset->ReservedFlag || $objParentAsset->ArchivedFlag || $objParentAsset->LocationId == 2 || $objParentAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objParentAsset->AssetId))) {
                                 $blnError = true;
                                 $this->chkLockToParent->Warning = "Parent asset tag (" . $objParentAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                             } else {
                                 $this->objAsset->ParentAssetId = $objParentAsset->AssetId;
                                 if ($this->chkLockToParent->Checked) {
                                     $this->objAsset->LinkedFlag = 1;
                                 }
                             }
                         }
                     }
                 } else {
                     $blnError = true;
                     $this->txtParentAssetCode->Warning = "Parent asset tag must not be the same as asset tag. Please try another.";
                 }
             } else {
                 // If txtParentAssetCode is empty
                 $this->objAsset->LinkedFlag = false;
                 $this->objAsset->ParentAssetId = null;
             }
             if (!$blnError) {
                 // Location can only be decided when creating an asset. Otherwise they must conduct a transaction.
                 if (!$this->blnEditMode) {
                     $this->objAsset->LocationId = $this->lstLocation->SelectedValue;
                 }
                 // Save child assets
                 $this->SaveChildAssets();
                 // Object should be saved only if it is new, to obtain the proper AssetId to add to the custom field tables
                 $this->objAsset->Save();
                 $this->objParentObject->RefreshChildAssets();
             }
         }
         // Assign input values to custom fields
         if (is_array($this->arrCustomFields) && count($this->arrCustomFields) > 0 && !$blnError) {
             // Save the values from all of the custom field controls to save the asset
             CustomField::SaveControls($this->objAsset->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objAsset->AssetId, 1);
         }
         if ($this->blnEditMode) {
             // Check to see if the asset tag already exists (and is not the asset tag of the asset that the user is currently editing
             $AssetDuplicate = Asset::LoadByAssetCode($this->txtAssetCode->Text);
             if ($AssetDuplicate && $AssetDuplicate->AssetId != $this->objAsset->AssetId) {
                 $blnError = true;
                 $this->txtAssetCode->Warning = "That asset tag is already in use. Please try another.";
             }
             if (!$blnError && $this->txtParentAssetCode->Text) {
                 // Check if the parent asset tag is already a child asset of this asset
                 $arrChildAsset = Asset::LoadArrayByParentAssetId($this->objAsset->AssetId);
                 foreach ($arrChildAsset as $objChildAsset) {
                     if ($objChildAsset->AssetCode == $this->txtParentAssetCode->Text) {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "Parent asset tag is already a child of this asset. Please try another.";
                         break;
                     }
                 }
                 if (!$blnError) {
                     if ($this->txtParentAssetCode->Text != $this->objAsset->AssetCode) {
                         $objParentAsset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text);
                         if (!$objParentAsset) {
                             $blnError = true;
                             $this->txtParentAssetCode->Warning = "That asset tag does not exist. Please try another.";
                         } else {
                             if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && $objParentAsset->LocationId != $this->objAsset->LocationId) {
                                 // If locking child to parent, make sure assets are at the same location
                                 $blnError = true;
                                 $this->chkLockToParent->Warning = 'Cannot lock to parent asset at another location.';
                             } else {
                                 if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && ($objParentAsset->CheckedOutFlag || $objParentAsset->ReservedFlag || $objParentAsset->ArchivedFlag || $objParentAsset->LocationId == 2 || $objParentAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objParentAsset->AssetId))) {
                                     $blnError = true;
                                     $this->chkLockToParent->Warning = "Parent asset tag (" . $objParentAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                                 } else {
                                     if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && ($this->objAsset->CheckedOutFlag || $this->objAsset->ReservedFlag || $this->objAsset->ArchivedFlag || $this->objAsset->LocationId == 2 || $this->objAsset->LocationId == 5 || AssetTransaction::PendingTransaction($this->objAsset->AssetId))) {
                                         $blnError = true;
                                         $this->chkLockToParent->Warning .= "Child asset must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                                     } else {
                                         $this->objAsset->ParentAssetId = $objParentAsset->AssetId;
                                         if ($this->chkLockToParent->Checked) {
                                             $this->objAsset->LinkedFlag = 1;
                                         } else {
                                             $this->objAsset->LinkedFlag = 0;
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "Parent asset tag must not be the same as asset tag. Please try another.";
                     }
                 }
             } else {
                 // If txtParentAssetCode is empty
                 $this->objAsset->LinkedFlag = false;
                 $this->objAsset->ParentAssetId = null;
                 $this->chkLockToParent->Checked = false;
             }
             //				 Check Depreciation fields
             if (QApplication::$TracmorSettings->DepreciationFlag == '1') {
                 if ($this->chkAssetDepreciation->Checked) {
                     if (!preg_match("/\\b\\d{1,3}(?:,?\\d{3})*(?:\\.\\d{2})?\\b/", $this->txtPurchaseCost->Text) || $this->txtPurchaseCost->Text <= 0) {
                         $blnError = true;
                         $this->txtPurchaseCost->Warning = "Purchase Cost isn't valid";
                     } elseif (AssetModel::Load($this->lstAssetModel->SelectedValue)->DepreciationClassId != null) {
                         //print $this->calPurchaseDate->DateTime ."||". $this->txtPurchaseCost->Text."|";exit;
                         $this->objAsset->DepreciationFlag = true;
                         $this->objAsset->PurchaseDate = $this->calPurchaseDate->DateTime;
                         $this->objAsset->PurchaseCost = str_replace(',', '', $this->txtPurchaseCost->Text);
                     } else {
                         $blnError = true;
                         $this->chkAssetDepreciation->Warning = "Chosen Model isn't assigned to any Depreciation Class";
                     }
                 } else {
                     $this->objAsset->DepreciationFlag = false;
                     $this->objAsset->PurchaseDate = null;
                     $this->objAsset->PurchaseCost = null;
                 }
             }
             if (!$blnError) {
                 // Update the values of all fields for an Ajax reload
                 $this->UpdateAssetFields();
                 // Save child assets
                 $this->SaveChildAssets();
                 // If asset is not new, it must be saved after updating the assetfields
                 $this->objAsset->Save();
                 // This is called to retrieve the new Modified Date and User
                 $this->objParentObject->SetupAsset($this);
                 // Give the labels their appropriate values before display
                 $this->UpdateAssetLabels();
                 // This was necessary because it was not saving the changes of a second edit/save in a row
                 // Reload all custom fields
                 $this->objAsset->objCustomFieldArray = CustomField::LoadObjCustomFieldArray(1, $this->blnEditMode, $this->objAsset->AssetId, false, $this->objAsset->AssetModelId);
                 // Update not allowed custom fields set to null
                 $arrAllowed = array();
                 foreach (AssetCustomFieldAssetModel::LoadArrayByAssetModelId($this->objAsset->AssetModelId) as $objAssetCustomField) {
                     $arrAllowed[] = $objAssetCustomField->CustomFieldId;
                 }
                 $arrToClear = array();
                 foreach (EntityQtypeCustomField::LoadArrayByEntityQtypeId(1) as $objAssetCustomField) {
                     if (!in_array($objAssetCustomField->CustomFieldId, $arrAllowed) && $objAssetCustomField->CustomField->AllAssetModelsFlag != 1) {
                         $arrToClear[] = $objAssetCustomField->CustomFieldId;
                     }
                 }
                 if ($this->objAsset->AssetId && count($arrToClear)) {
                     $arrForQuery = array();
                     foreach ($arrToClear as $idToBeNull) {
                         $arrForQuery[] = sprintf("`cfv_%s`= NULL", $idToBeNull);
                     }
                     $objDatabase = Asset::GetDatabase();
                     $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", implode(", ", $arrForQuery), $this->objAsset->AssetId);
                     //  print($strQuery); exit;
                     $objDatabase->NonQuery($strQuery);
                 }
                 // Commit the above transactions to the database
                 $objDatabase->TransactionCommit();
                 // Hide inputs and display labels
                 $this->displayLabels();
                 // Enable the appropriate transaction buttons
                 $this->EnableTransactionButtons();
                 $this->objParentObject->RefreshChildAssets();
             }
         } elseif (!$blnError) {
             // Commit the above transactions to the database
             $objDatabase->TransactionCommit();
             // Reload the edit asset page with the newly created asset
             $strRedirect = sprintf('asset_edit.php?intAssetId=%s', $this->objAsset->AssetId);
             QApplication::Redirect($strRedirect);
         }
     } catch (QOptimisticLockingException $objExc) {
         // Rollback the database
         $objDatabase->TransactionRollback();
         // Output the error
         $this->btnCancel->Warning = sprintf('This asset has been updated by another user. You must <a href="asset_edit.php?intAssetId=%s">Refresh</a> to edit this Asset.', $this->objAsset->AssetId);
     }
 }
 protected function UndoImport()
 {
     $objDatabase = Asset::GetDatabase();
     //$strQuery = "SET FOREIGN_KEY_CHECKS=0;";
     //$objDatabase->NonQuery($strQuery);
     if (isset($this->arrOldItemArray)) {
         $strQuery = "SET FOREIGN_KEY_CHECKS=0;";
         $objDatabase->NonQuery($strQuery);
         foreach ($this->arrOldItemArray as $objOldItem) {
             /*$strQuery = sprintf("UPDATE `asset_model` SET `short_description`='%s', `long_description`='%s', `manufacturer_id`='%s', `category_id`='%s', `asset_model_code`='%s', `modified_by`=%s, `modified_date`=%s WHERE `asset_model_id`='%s'", $objOldItem->ShortDescription, $objOldItem->LongDescription, $objOldItem->ManufacturerId, $objOldItem->CategoryId, $objOldItem->AssetModelCode, (!$objOldItem->ModifiedBy) ? "NULL" : $objOldItem->ModifiedBy, (!$objOldItem->ModifiedBy) ? "NULL" : sprintf("'%s'", $objOldItem->ModifiedDate), $objOldItem->AssetModelId);
               $objDatabase->NonQuery($strQuery);
               $strCFVArray = array();
               foreach ($this->arrModelCustomField as $objCustomField) {
                 $strCFV = $objOldItem->GetVirtualAttribute($objCustomField->CustomFieldId);
                 $strCFVArray[] = sprintf("`cfv_%s`='%s'", $objCustomField->CustomFieldId, $strCFV);
               }
               if (isset($strCFVArray) && count($strCFVArray)) {
                 $strQuery = sprintf("UPDATE `asset_model_custom_field_helper` SET %s WHERE `asset_model_id`='%s'", implode(", ", $strCFVArray), $intItemId);
                 $objDatabase->NonQuery($strQuery);
               }*/
             $objDatabase->NonQuery($objOldItem['ItemSql']);
             if ($objOldItem['CFVSql']) {
                 $objDatabase->NonQuery($objOldItem['CFVSql']);
             }
         }
         $strQuery = "SET FOREIGN_KEY_CHECKS=1;";
         $objDatabase->NonQuery($strQuery);
     }
     //$strQuery = "SET FOREIGN_KEY_CHECKS=0;";
     //$objDatabase->NonQuery($strQuery);
     if (count($this->objNewAssetModelArray)) {
         $strQuery = sprintf("DELETE FROM `asset_model` WHERE `asset_model_id` IN (%s)", implode(", ", array_keys($this->objNewAssetModelArray)));
         $objDatabase->NonQuery($strQuery);
         // Do not need to delete it manually (automatically CASCADE deletion)
         //$strQuery = sprintf("DELETE FROM `asset_model_custom_field_helper` WHERE `asset_model_id` IN (%s)", implode(", ", array_keys($this->objNewAssetModelArray)));
         //$objDatabase->NonQuery($strQuery);
     }
     //$strQuery = "SET FOREIGN_KEY_CHECKS=1;";
     //$objDatabase->NonQuery($strQuery);
 }
Exemple #10
0
 public function Save($blnForceInsert = false, $blnForceUpdate = false)
 {
     if (!$this->__blnRestored || $blnForceInsert) {
         $this->CreatedBy = QApplication::$objUserAccount->UserAccountId;
         $this->CreationDate = new QDateTime(QDateTime::Now);
         parent::Save($blnForceInsert, $blnForceUpdate);
         // If we have no errors then will add the data to the helper table
         $objDatabase = Asset::GetDatabase();
         $strQuery = sprintf('INSERT INTO `asset_custom_field_helper` (`asset_id`) VALUES (%s);', $this->AssetId);
         $objDatabase->NonQuery($strQuery);
     } else {
         $this->ModifiedBy = QApplication::$objUserAccount->UserAccountId;
         parent::Save($blnForceInsert, $blnForceUpdate);
     }
 }