/** * Prepare documents of subsection to view * @param $documents * @param $vendorId * @param $sectionFolderCategory * @param $year * @return array */ public static function prepareDocumentsOfSubsectionToView($documents, $vendorId, $sectionFolderCategory, $year) { $result = array(); // if section is W9 Book, add all available for company W9s (they are not in LibraryDocs) if ($sectionFolderCategory == Sections::W9_BOOK) { $w9Docs = W9::getAvailableW9sOfYear($year); foreach ($w9Docs as $w9Doc) { $result[] = $w9Doc; } } foreach($documents as $document) { $result[] = $document->document; } // if section is Vendor Documents, add last available for company W9s of this vendor (it is not in LibraryDocs) if ($vendorId != 0 && $sectionFolderCategory == Sections::VENDOR_DOCUMENTS) { $vendor = Vendors::model()->with('client')->findByPk($vendorId); if ($vendor) { $document = W9::getCompanyW9Doc($vendor->client->Client_ID); if ($document) { $result[] = $document; } } } return $result; }
/** * Get count of documents in storage * @param $id * @param $rowType * @return mixed */ public static function getDocumentsCount($id, $rowType) { $where = "(`ld`.`Access_Type` = '" . Storages::HAS_ACCESS . "' OR `ds`.`User_ID` = '" . Yii::app()->user->userID ."') "; $where .= " AND `st`.`Client_ID` = '" . Yii::app()->user->clientID ."' "; if (Yii::app()->user->projectID != 'all') { $where .= " AND `st`.`Project_ID` = '" . Yii::app()->user->projectID ."' "; } if ($rowType == 'storage') { $where .= " AND `st`.`Storage_ID` = '" . $id ."' "; } else if ($rowType == 'section') { $where .= " AND `sc`.`Section_ID` = '" .$id ."' "; } else { $where .= " AND `ss`.`Subsection_ID` = '" . $id ."' "; } if (Yii::app()->user->id == 'user') { $where .= " AND `ds`.`User_ID` = '" . Yii::app()->user->userID . "'"; } $query = "SELECT count(*) as count FROM `library_docs` as ld LEFT JOIN `documents` as ds ON `ds`.`Document_ID` = `ld`.`Document_ID` LEFT JOIN `subsections` as ss ON `ss`.`Subsection_ID` = `ld`.`Subsection_ID` LEFT JOIN `sections` as sc ON `sc`.`Section_ID` = `ss`.`Section_ID` LEFT JOIN `storages` as st ON `st`.`Storage_ID` = `sc`.`Storage_ID` WHERE $where"; $connection=Yii::app()->db; $command=$connection->createCommand($query); $row=$command->queryRow(); $count = $row['count']; // add unassigned W9s of Vendor folder and W9 book binder if ($rowType == 'storage') { $storage = Storages::model()->findByPk($id); if ($storage->Storage_Type == Storages::SHELF) { $count += W9::getCountOfAvailableW9sOfYear($storage->Year); } else { $condition = new CDbCriteria(); $condition->condition = "t.Storage_ID = '" . $id . "'"; $condition->addCondition("t.Folder_Cat_ID = '" . self::VENDOR_DOCUMENTS . "'"); $vendorFolders = Sections::model()->findAll($condition); foreach ($vendorFolders as $vendorFolder) { $w9 = W9::getCompanyW9Doc($vendorFolder->Vendor_ID); if ($w9) { $count++; } } } } else if ($rowType == 'section') { $section = Sections::model()->with('storage')->findByPk($id); if ($section->Folder_Cat_ID == self::W9_BOOK) { $count += W9::getCountOfAvailableW9sOfYear($section->storage->Year); } else if ($section->Folder_Cat_ID == self::VENDOR_DOCUMENTS) { $w9 = W9::getCompanyW9Doc($section->Vendor_ID); if ($w9) { $count++; } } } else { $subsection = Subsections::model()->with('user', 'section.storage')->findByPk($id); if ($subsection->section->Folder_Cat_ID == self::W9_BOOK && $subsection->Created_By == 0) { $count += W9::getCountOfAvailableW9sOfYear($subsection->section->storage->Year); } else if ($subsection->section->Folder_Cat_ID == self::VENDOR_DOCUMENTS && $subsection->Created_By == 0) { $w9 = W9::getCompanyW9Doc($subsection->section->Vendor_ID); if ($w9) { $count++; } } } return $count; }