/** * Create project shelve and cabinet * @param $projectId * @param $year */ public static function createProjectStorages($projectId, $year) { $project = Projects::model()->findByPk($projectId); // check existing project cabinet $cabinet = Storages::model()->findByAttributes(array( 'Storage_Type' => self::CABINET, 'Created_By' => '0', 'Project_ID' => $projectId, 'Year' => $year, )); if (!$cabinet) { // if there is not cabinet for this project create it $cabinet = new Storages(); $cabinet->Storage_Name = $project->Project_Name; $cabinet->Project_ID = $projectId; $cabinet->Client_ID = Yii::app()->user->clientID; $cabinet->Year = $year; $cabinet->Created_By = 0; $cabinet->Row_Num = 0; $cabinet->Storage_Type = self::CABINET; $cabinet->Access_Type = self::HAS_ACCESS; if ($cabinet->validate()) { $cabinet->save(); } } // check existing project shelf $shelf = Storages::model()->findByAttributes(array( 'Storage_Type' => self::SHELF, 'Created_By' => '0', 'Project_ID' => $projectId, 'Year' => $year, )); if (!$shelf) { // if there is not cabinet for this project create it $shelf = new Storages(); $shelf->Storage_Name = $project->Project_Name; $shelf->Project_ID = $projectId; $shelf->Client_ID = Yii::app()->user->clientID; $shelf->Year = $year; $shelf->Created_By = 0; $shelf->Row_Num = 0; $shelf->Storage_Type = self::SHELF; $shelf->Access_Type = self::HAS_ACCESS; if ($shelf->validate()) { $shelf->save(); } } $countW9s = W9::getCountOfAvailableW9sOfYear($year); if ($countW9s > 0) { // also crete W9 book if it does not exist and there are Company's W9s $w9Binder = Sections::model()->findByAttributes(array( 'Section_Type' => self::SHELF, 'Created_By' => '0', 'Storage_ID' => $shelf->Storage_ID, 'Folder_Cat_ID' => Sections::W9_BOOK, )); if (!$w9Binder) { $w9Binder = new Sections(); $w9Binder->Storage_ID = $shelf->Storage_ID; $w9Binder->Section_Name = "W9s"; $w9Binder->Vendor_ID = 0; $w9Binder->Created_By = 0; $w9Binder->Section_Type = self::SHELF; $w9Binder->Folder_Cat_ID = Sections::W9_BOOK; $w9Binder->Access_Type = self::HAS_ACCESS; if ($w9Binder->validate()) { $w9Binder->save(); $tab = new Subsections(); $tab->Section_ID = $w9Binder->Section_ID; $tab->Subsection_Name = 'Tab 1'; $tab->Subsection_Type = self::SHELF; $tab->Created_By = 0; $tab->Access_Type = self::HAS_ACCESS; $tab->save(); } } } }