/** * Upload documents * @param $uploadType * @param bool $withoutMessage * @return int */ public static function uploadDocuments($uploadType, $withoutMessage = false) { if(isset($_SESSION[$uploadType]) && count($_SESSION[$uploadType]) > 0) { $settings = UsersSettings::model()->findByAttributes(array( 'User_ID' => Yii::app()->user->userID, )); //get default bank account $condition = new CDbCriteria(); $condition->condition = "users_project_list.User_ID = '" . Yii::app()->user->userID . "'"; $condition->addCondition("users_project_list.Client_ID = '" . Yii::app()->user->clientID . "'"); $condition->addCondition("t.Account_Num_ID = '" . $settings->Default_Bank_Acct . "'"); $condition->join = "LEFT JOIN projects ON projects.Project_ID = t.Project_ID LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID"; $bankAcct = BankAcctNums::model()->with('client.company', 'project')->find($condition); $defaultBankAcct = 0; if ($bankAcct) { $defaultBankAcct = $settings->Default_Bank_Acct; } //get user to send email $person_to_email = false; if (Yii::app()->user->id != 'user' && Yii::app()->user->id != 'single_user') { $person_to_email = Users::model()->with('person')->findByPk(Yii::app()->user->userID); } else { $condition = new CDbCriteria(); $condition->join = "LEFT JOIN users_client_list ON users_client_list.User_ID = t.User_ID"; $condition->addInCondition('users_client_list.User_Type', array(UsersClientList::APPROVER, UsersClientList::PROCESSOR, UsersClientList::CLIENT_ADMIN)); $condition->addInCondition('t.User_Type', array(Users::ADMIN, Users::DB_ADMIN, Users::DATA_ENTRY_CLERK), "OR"); $condition->addCondition("users_client_list.Client_ID = '" . Yii::app()->user->clientID . "'"); $person_to_email = Users::model()->with('person')->find($condition); } foreach ($_SESSION[$uploadType] as $key => $current_upload_file) { // check fed id if ($current_upload_file['doctype'] == self::W9) { if (!preg_match('/^(\d{2}\-\d{7})|(\d{3}\-\d{2}\-\d{4})|(IN[-]\d{6})|(T0[-]\d{7})$/', $current_upload_file['fed_id'])) { return 2; } } } // insert documents into DB foreach ($_SESSION[$uploadType] as $key => $current_upload_file) { if (file_exists($current_upload_file['filepath'])) { // create document $document = new Documents(); $document->Document_Type = $current_upload_file['doctype']; $document->User_ID = Yii::app()->user->userID; $document->Client_ID = Yii::app()->user->clientID; $document->Project_ID = Yii::app()->user->projectID; $document->Created = date("Y-m-d H:i:s"); $document->save(); $new_doc_id=$document->Document_ID; Audits::LogAction($document->Document_ID ,Audits::ACTION_UPLOAD); // insert image $image = new Images(); $imageData = addslashes(fread(fopen($current_upload_file['filepath'],"rb"),filesize($current_upload_file['filepath']))); //$imageData = FileModification::ImageToPdfByFilePath($current_upload_file['filepath']); $image->Document_ID = $document->Document_ID; $image->Img = $imageData; $image->File_Name = $current_upload_file['name']; $image->Mime_Type = $current_upload_file['mimetype']; $image->File_Hash = sha1_file($current_upload_file['filepath']); $image->File_Size = intval(filesize($current_upload_file['filepath'])); $image->Pages_Count = FileModification::calculatePagesByPath($current_upload_file['filepath']); $image->save(); $infile = @file_get_contents($current_upload_file['filepath'], FILE_BINARY); if (($current_upload_file['mimetype'] == 'application/pdf' && $image->findPdfText($infile) == '') || $current_upload_file['mimetype'] != 'application/pdf') { Documents::crateDocumentThumbnail($current_upload_file['filepath'], 'thumbs', $current_upload_file['mimetype'], $document->Document_ID, 80); } // delete file from temporary catalog and from cache table //unlink($current_upload_file['filepath']); FileCache::deleteBothFromCacheById($current_upload_file['file_id']); if ($current_upload_file['doctype'] == self::W9) { // if document is W9 // get additional fields $fedId = trim($current_upload_file['fed_id']); $newCompanyName = trim($current_upload_file['company_name']); // get company info $company = Companies::model()->with('client')->findByAttributes(array( 'Company_Fed_ID' => $fedId, )); // create w9 $W9 = new W9(); $W9->Document_ID = $document->Document_ID; $W9->W9_Owner_ID = Yii::app()->user->clientID; $W9->Creator_ID = Yii::app()->user->userID; $W9->Business_Name = trim($current_upload_file['bus_name']); $W9->Tax_Class = trim($current_upload_file['tax_name']); // get user info $user = Users::model()->with('person')->findByPk(Yii::app()->user->userID); if ($company) { // if company exisits $client = $company->client; //fill created company with dataentry values from session Companies::fillWithSessionDataEntry($company,$current_upload_file); $existingW9 = W9::model()->findByAttributes(array( 'Client_ID' => $client->Client_ID, 'W9_Owner_ID' => Yii::app()->user->clientID, )); if ($existingW9) { $W9->Revision_ID = -1; } else { $W9->Revision_ID = 0; } $vendor = Vendors::model()->findByAttributes(array( 'Client_Client_ID' => Yii::app()->user->clientID, 'Vendor_Client_ID' => $client->Client_ID, )); if (isset($vendor->Active_Relationship) && $vendor->Active_Relationship == Vendors::NOT_ACTIVE_RELATIONSHIP) { $vendor->Active_Relationship = Vendors::ACTIVE_RELATIONSHIP; $vendor->save(); } else if (!$vendor && Yii::app()->user->clientID != 0 && Yii::app()->user->clientID != $client->Client_ID) { $vendor = new Vendors(); $vendor->Vendor_ID_Shortcut = ''; $vendor->Vendor_Client_ID = $client->Client_ID; $vendor->Client_Client_ID = Yii::app()->user->clientID; $vendor->Vendor_Name_Checkprint = ''; $vendor->Vendor_1099 = ''; $vendor->Vendor_Default_GL = ''; $vendor->Vendor_Default_GL_Note = ''; $vendor->Vendor_Note_General = ''; $vendor->Vendor_Contact = trim($current_upload_file['contact']); $vendor->Vendor_Phone = trim($current_upload_file['phone']); $vendor->save(); } } else { //if company does not exists, create new company $client = Companies::createEmptyCompany($fedId, $newCompanyName); $company_model = Companies::model()->findByPk($client->Company_ID); //fill created company with dataentry values from session Companies::fillWithSessionDataEntry($company_model,$current_upload_file); if (Yii::app()->user->clientID != 0) { $vendor = new Vendors(); $vendor->Vendor_ID_Shortcut = ''; $vendor->Vendor_Client_ID = $client->Client_ID; $vendor->Client_Client_ID = Yii::app()->user->clientID; $vendor->Vendor_Name_Checkprint = ''; $vendor->Vendor_1099 = ''; $vendor->Vendor_Default_GL = ''; $vendor->Vendor_Default_GL_Note = ''; $vendor->Vendor_Note_General = ''; $vendor->Vendor_Contact = trim($current_upload_file['contact']); $vendor->Vendor_Phone = trim($current_upload_file['phone']); $vendor->save(); } $W9->Revision_ID = 0; } // save w9 $W9->Client_ID = $client->Client_ID; $W9->save(); if ($person_to_email) { Mail::sendNewW9ForDataEntry($person_to_email->person->Email, $person_to_email->person->First_Name, $person_to_email->person->Last_Name); } } else if ($current_upload_file['doctype'] == self::AP) { //create aps $aps = new Aps(); $aps->Document_ID = $document->Document_ID; $aps->Vendor_ID = 0; $aps->PO_ID = 0; $aps->AP_Approval_Value = Aps::NOT_READY_FOR_APPROVAL; $aps->Invoice_Number = 0; $aps->save(); } else if ($current_upload_file['doctype'] == self::PM) { //create payment $payment = new Payments(); $payment->Document_ID = $document->Document_ID; $payment->Vendor_ID = 0; $payment->Payment_Check_Number = 0; $payment->Payment_Amount = 0; if ($defaultBankAcct != 0) { $payment->Account_Num_ID = $defaultBankAcct; } else { $payment->Account_Num_ID = 0; } $payment->save(); } else if ($current_upload_file['doctype'] == self::PO) { //create pos $po = new Pos(); $po->Document_ID = $document->Document_ID; $po->Vendor_ID = 0; $po->PO_Number = Pos::getNewPoNumber(); $po->PO_Date = date('Y-m-d'); $po->PO_Backup_Document_ID = 0; $po->save(); } else if ($current_upload_file['doctype'] == self::PR) { $payroll = new Payrolls(); $payroll->Document_ID = $document->Document_ID; $payroll->save(); } else if ($current_upload_file['doctype'] == self::JE) { $je = new Journals(); $je->Document_ID = $document->Document_ID; $je->save(); } else if ($current_upload_file['doctype'] == self::PC) { $pc = new Pcs(); $pc->Document_ID = $document->Document_ID; $pc->save(); } else if ($current_upload_file['doctype'] == self::AR) { $ar = new Ars(); $ar->Document_ID = $document->Document_ID; $ar->save(); } } $arr[$current_upload_file['name']]['string']= Images::getAjaxStringForLastUploadSection($new_doc_id); $arr[$current_upload_file['name']]['key']=$key; } $_SESSION[$uploadType] = array(); if (!$withoutMessage) { Yii::app()->user->setFlash('success', "Documents have been uploaded!"); } return json_encode($arr); } else { $answer['empty']=1; return json_encode($answer); } }
function insert($db, $article, $database) { require_once "journals.php"; $journal_model = new Journals(); // Insert journal, if the journal already exists the existing journal_id is returned $journal_id = $journal_model->insert($db, $article["journal_title"], $article["journal_iso"], $article["journal_issn"]); // Insert article // Strip title of any characters other than a-z, used to compare articles to each other $title_stripped = preg_replace("/[^a-z]/i", "", strtolower($article["title"])); $title_fixed = addslashes($article["title"]); $abstract_fixed = addslashes($article["abstract"]); $sql = "INSERT INTO Articles (title, title_stripped, abstract, journal, day, month, year, doi, search_db) \n VALUES ('{$title_fixed}', '{$title_stripped}', '{$abstract_fixed}', '{$journal_id}', '{$article['day']}', \n '{$article['month']}', '{$article['year']}', '{$article['doi']}', '{$database}')"; if ($result = $db->query($sql)) { $article_id = $db->connection->insert_id; return $article_id; } return false; }
/** * Add document to folder * @param $docId * @param null $vendorID */ public static function addDocumentToFolder($docId, $vendorID = null) { $document = Documents::model()->findByPk($docId); if ($document) { $year = substr($document->Created, 0, 4); Storages::createProjectStorages($document->Project_ID, $year); $subsectionId = 0; if ($document->Document_Type == Documents::PM) { $payment = Payments::model()->findByAttributes(array( 'Document_ID' => $docId, )); $year = substr($payment->Payment_Check_Date, 0, 4); $subsectionId = Sections::createVendorFolder($document->Project_ID, $payment->Vendor_ID, $year); } elseif ($document->Document_Type == Documents::AP) { $ap = Aps::model()->findByAttributes(array( 'Document_ID' => $docId, )); $year = substr($ap->Invoice_Date, 0, 4); $subsectionId = Sections::createVendorFolder($document->Project_ID, $ap->Vendor_ID, $year); if ($ap->AP_Backup_Document_ID != 0) { $bu = LibraryDocs::model()->findByAttributes(array( 'Document_ID' => $ap->AP_Backup_Document_ID, 'Subsection_ID' => $subsectionId, )); if (!$bu) { $libDoc = new LibraryDocs(); $libDoc->Document_ID = $ap->AP_Backup_Document_ID; $libDoc->Subsection_ID = $subsectionId; $libDoc->Access_Type = Storages::HAS_ACCESS; $libDoc->Sort_Numb = 0; if ($libDoc->validate()) { $libDoc->save(); } } } } elseif ($document->Document_Type == Documents::PO) { $po = Pos::model()->findByAttributes(array( 'Document_ID' => $docId, )); $year = substr($po->PO_Date, 0, 4); $subsectionId = Sections::createVendorFolder($document->Project_ID, $po->Vendor_ID, $year); if ($po->PO_Backup_Document_ID != 0) { $bu = LibraryDocs::model()->findByAttributes(array( 'Document_ID' => $po->PO_Backup_Document_ID, 'Subsection_ID' => $subsectionId, )); if (!$bu) { $libDoc = new LibraryDocs(); $libDoc->Document_ID = $po->PO_Backup_Document_ID; $libDoc->Subsection_ID = $subsectionId; $libDoc->Access_Type = Storages::HAS_ACCESS; $libDoc->Sort_Numb = 0; if ($libDoc->validate()) { $libDoc->save(); } } } } elseif ($document->Document_Type == Documents::BU) { //get po or ap date $ap = Aps::model()->findByAttributes(array( 'AP_Backup_Document_ID' => $docId, )); if ($ap) { $year = substr($ap->Invoice_Date, 0, 4); } else { $po = Pos::model()->findByAttributes(array( 'PO_Backup_Document_ID' => $docId, )); if ($po) { $year = substr($po->PO_Date, 0, 4); } } $subsectionId = Sections::createVendorFolder($document->Project_ID, $vendorID, $year); } elseif ($document->Document_Type == Documents::PR) { $payroll = Payrolls::model()->findByAttributes(array( 'Document_ID' => $document->Document_ID, )); $year = substr($payroll->Week_Ending, 0, 4); $subsectionId = Sections::createPayrollFolder($document->Project_ID, $year, $payroll->Week_Ending); } elseif ($document->Document_Type == Documents::JE) { $je = Journals::model()->findByAttributes(array( 'Document_ID' => $document->Document_ID, )); $subsectionId = Sections::createJournalEntryFolder($document->Project_ID, $je->JE_Date); } elseif ($document->Document_Type == Documents::PC) { $pc = Pcs::model()->findByAttributes(array( 'Document_ID' => $document->Document_ID, )); $year = substr($pc->Envelope_Date, 0, 4); $subsectionId = Sections::createPettyCashFolder($document->Project_ID, $year, $pc->Employee_Name); } elseif ($document->Document_Type == Documents::AR) { $ar = Ars::model()->findByAttributes(array( 'Document_ID' => $document->Document_ID, )); $year = substr($ar->Invoice_Date, 0, 4); $subsectionId = Sections::createAccountsReceivableFolder($document->Project_ID, $year, $ar->Invoice_Date); } $libDoc = LibraryDocs::model()->findByAttributes(array( 'Document_ID' => $docId, 'Subsection_ID' => $subsectionId, )); if (!$libDoc) { $libDoc = new LibraryDocs(); $libDoc->Document_ID = $docId; $libDoc->Subsection_ID = $subsectionId; $libDoc->Access_Type = Storages::HAS_ACCESS; $libDoc->Sort_Numb = 0; if ($libDoc->validate()) { $libDoc->save(); } } LibraryDocs::sortDocumentsInSubsection($subsectionId); } }
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. $time_start = microtime(true); require_once "config.php"; require_once "database.php"; $db = new Connector(); $db->connect($config); if (isset($_GET) && isset($_GET["reinit"]) && $_GET["reinit"] == "true") { // Reset database require_once "models/journal_definitions.php"; require_once "models/journals.php"; require_once "models/articles.php"; $definitions_model = new Journal_definitions(); $journal_model = new Journals(); $article_model = new Articles(); // Clear tables $definitions_model->clear($db); $journal_model->clear($db); $article_model->clear($db); } // Parsing the journal list csv file if ($config["journal_list_run"] === true) { require_once "parsers/parse_journal_list.php"; new Journal_list($config, $db); } // Parsing pubmed central XML if ($config["pubmed_central_run"] === true) { require_once "parsers/pubmed_central_xml.php"; new Pubmed_central_parser($config, $db);
public function appendGeneralDocList ($client_id,$project_list,$doc_type){ $condition = new CDbCriteria(); $condition->condition =' documents.Client_ID = '.$client_id; $condition->addInCondition('documents.Project_ID ',$project_list); $condition->join = 'left join documents on documents.Document_ID = t.Document_ID'; if ($doc_type=='PC') { $models = Pcs::model()->with('document')->findAll($condition); } else if ($doc_type=='W9') { $models = W9::model()->with('document')->findAll($condition); } else if ($doc_type=='JE') { $models = Journals::model()->with('document')->findAll($condition); } else if ($doc_type=='AR') { $models = Ars::model()->with('document')->findAll($condition); } else if ($doc_type=='PR') { $models = Payrolls::model()->with('document')->findAll($condition); } else if ($doc_type=='GF') { //$models = G::model()->findAll($condition); } else if ($doc_type=='PM') { $models = Payments::model()->with('document')->findAll($condition); } else if ($doc_type=='PC') { $models = Ars::model()->with('document')->findAll($condition); } $xml_doc = $this->xml->createElement("document"); if($models) { foreach ($models as $model) { $xml_row = $this->xml->createElement("row"); foreach ($model->attributes as $key => $value) { $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1')); $xml_field->setAttribute('name', $key); $xml_row->appendChild($xml_field); } //+ we need to insert several columns from document model $xml_field = $this->xml->createElement("field",htmlentities($model->document->Origin,ENT_QUOTES | 'ENT_XML1')); $xml_field->setAttribute('name', 'DocumentsOrigin'); $xml_row->appendChild($xml_field); $xml_field = $this->xml->createElement("field",htmlentities($model->document->Created,ENT_QUOTES | 'ENT_XML1')); $xml_field->setAttribute('name', 'DocumentsCreated'); $xml_row->appendChild($xml_field); $xml_field = $this->xml->createElement("field",htmlentities($model->document->Project_ID,ENT_QUOTES | 'ENT_XML1')); $xml_field->setAttribute('name', 'DocumentsProject_ID'); $xml_row->appendChild($xml_field); // end of block $xml_doc_row = $this->xml->createElement("documents"); foreach ($model->document->attributes as $key => $value) { $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1')); $xml_field->setAttribute('name', $key); $xml_doc_row->appendChild($xml_field); } /**/ $xml_image_row = $this->xml->createElement("images"); $xml_field = $this->xml->createElement("field",$model->document->image->Image_ID); $xml_field->setAttribute('name', 'Image_ID'); $xml_image_row->appendChild($xml_field); $filename = FileModification::prepareFileForExport($model->document->image->Document_ID,$doc_type,$this->filepath); $xml_field = $this->xml->createElement("field",$filename); $xml_field->setAttribute('name', 'File_Name'); $xml_image_row->appendChild($xml_field); $xml_row->appendChild($xml_field); $xml_field = $this->xml->createElement("field",$model->document->image->Mime_Type); $xml_field->setAttribute('name', 'Mime_Type'); $xml_image_row->appendChild($xml_field); $xml_row->appendChild($xml_field); $xml_field = $this->xml->createElement("field",$model->document->image->Pages_Count); $xml_field->setAttribute('name', 'Pages_Count'); $xml_image_row->appendChild($xml_field); $xml_row->appendChild($xml_field); /**/ $xml_row->appendChild($xml_doc_row); $xml_row->appendChild($xml_image_row); $xml_doc->appendChild($xml_row); } $this->wrapper->appendChild($xml_doc); } }
/** * Find JEs to entry data */ public static function findJEsToEntry() { $queryString = $_SESSION['last_je_to_entry_search']['query']; $options = $_SESSION['last_je_to_entry_search']['options']; $condition = new CDbCriteria(); $condition->join = "right JOIN documents ON documents.Document_ID=t.Document_ID"; $condition->condition = "t.JE_Number = '0'"; $countCond = 0; if (count($options) > 0 && trim($queryString) != '') { $search_condition = new CDbCriteria(); if ($options['search_option_jdate']) { $search_condition->compare('t.JE_Date', $queryString, true, 'OR'); $countCond++; } if ($options['search_option_jnumber']) { $search_condition->compare('t.JE_Number', $queryString, true, 'OR'); $countCond++; } if ($options['search_option_transaction_num']) { $search_condition->compare('t.JE_Transaction_ID', $queryString, true, 'OR'); $countCond++; } if ($options['search_option_desc']) { $search_condition->compare('t.JE_Desc', $queryString, true, 'OR'); $countCond++; } } if (Yii::app()->user->userType == UsersClientList::PROCESSOR || Yii::app()->user->userType == UsersClientList::APPROVER || Yii::app()->user->userType == UsersClientList::CLIENT_ADMIN) { $condition->addCondition("documents.Client_ID='" . Yii::app()->user->clientID . "'"); } if (Yii::app()->user->userType == UsersClientList::PROCESSOR || ((Yii::app()->user->userType == UsersClientList::APPROVER || Yii::app()->user->userType == UsersClientList::CLIENT_ADMIN) && is_numeric(Yii::app()->user->projectID))) { $condition->addCondition("documents.Project_ID='" . Yii::app()->user->projectID . "'"); } if (Yii::app()->user->userType == UsersClientList::USER && is_numeric(Yii::app()->user->projectID)) { $condition->addCondition("documents.Project_ID='" . Yii::app()->user->projectID . "'"); $condition->addCondition("documents.User_ID='" . Yii::app()->user->userID . "'"); } if (Yii::app()->user->userType == Users::DATA_ENTRY_CLERK) { //adding condition to allow DEC see only documents of clients that he has access $cli_array = Clients::getClientsIDList(Yii::app()->user->userID); $condition->addInCondition('documents.Client_ID', $cli_array); } $condition->order = "documents.Created ASC"; if( $countCond > 0 ) $condition->mergeWith($search_condition); $jes = Journals::model()->findAll($condition); return $jes; }