/** * 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); } }
/** * Generate PDF for fake AP using FPDF library without saving to database. * @param $poId * @param bool $approved */ public static function generatePdfFpdfPreview($ap, $ckRequest, $apDists,$approved = false) { // get PO formatting $poFormatting = PoFormatting::model()->findByAttributes(array( 'Project_ID' => Yii::app()->user->projectID, )); // get Sign_Requested_By user info $signRequestedByUser = Users::model()->with('person')->findByPk($ckRequest->Sign_Requested_By); $aproval_detail_list = Audits::getApprovalDetailList($ap->Document_ID); // get current vendor info $currentVendor = Vendors::model()->with('client.company.adreses')->findByPk($ap->Vendor_ID); $condition = UsersClientList::getClientAdminCondition($currentVendor->client->Client_ID); $vendorAdmin = UsersClientList::model()->with('user.person')->find($condition); $pdf = new FpdfAp('P','mm','Letter'); $pdf->AddFont('HelveticaB','','helveticab.php'); $pdf->AddFont('Courier','','courier.php'); $pdf->AddFont('CourierB','','courierb.php'); $pdf->SetAutoPageBreak(true, 10); $pdf->setVariables($ap,$poFormatting,$ckRequest,$apDists,$currentVendor,$vendorAdmin,$signRequestedByUser,$aproval_detail_list,$approved); $pdf->AliasNbPages(); $pdf->setPageNo(1); //$pdf->AliasNbPages(); $pdf->AddPage('P'); $pdf->SetFont('Helvetica','',13.5); $pdf->SetXY(5,10); $pdf->PrintContent(); //$path=Helper::createDirectory('batches');// creates directory "protected/data/batches" if not exists $fileName = 'ApTempPdf'.date('Y-m-d h:i:s').'.pdf'; $filepath = Helper::createDirectory('ap'); $filepath = Helper::createDirectory('ap/'.Yii::app()->user->clientID); $filepath.= '/'.$fileName; $pdf->Output($filepath, 'F'); //$pdf->Output(); $last_page = $pdf->custom_page_num; $pdf->Close(); return array( 'filename'=>$fileName, 'filepath'=>$filepath ); }
/** * 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; }
/** * Import Vendors * @param $clientID * @param $importedVendors */ public static function importVendors($clientID, $importedVendors) { $all_amount=count($importedVendors); $i=0; $pb= ProgressBar::init(); foreach($importedVendors as $importedVendor) { $company = Companies::model()->with('client')->findByAttributes(array( 'Company_Fed_ID' => $importedVendor['fedId'], )); if ($company) { $client = $company->client; } else { //if company does not exists, create new company $client = Companies::createEmptyCompany($importedVendor['fedId'], $importedVendor['companyName'], $importedVendor); } $vendorClientId = $client->Client_ID; $vendor = Vendors::model()->findByAttributes(array( 'Client_Client_ID' => $clientID, 'Vendor_Client_ID' => $vendorClientId, )); $newVendor = false; if (!$vendor) { $vendor = new Vendors(); $newVendor = true; } else { $vendor->Active_Relationship = self::ACTIVE_RELATIONSHIP; $vendor->save(); } $vendor->Vendor_ID_Shortcut = $importedVendor['shortcut']; $vendor->Vendor_Client_ID = $vendorClientId; $vendor->Client_Client_ID = $clientID; $vendor->Vendor_Name_Checkprint = $importedVendor['checkprint']; $vendor->Vendor_1099 = $importedVendor['v1099']; $vendor->Vendor_Default_GL = $importedVendor['defG']; $vendor->Vendor_Default_GL_Note = $importedVendor['defGLNote']; $vendor->Vendor_Note_General = $importedVendor['noteGeneral']; if ($vendor->validate()) { $vendor->save(); } else if ($newVendor) { $vendor = new Vendors(); $vendor->Vendor_ID_Shortcut = ''; $vendor->Vendor_Client_ID = $vendorClientId; $vendor->Client_Client_ID = $clientID; $vendor->Vendor_Name_Checkprint = ''; $vendor->Vendor_1099 = ''; $vendor->Vendor_Default_GL = ''; $vendor->Vendor_Default_GL_Note = ''; $vendor->Vendor_Note_General = ''; $vendor->Active_Relationship = self::ACTIVE_RELATIONSHIP; $vendor->save(); } $i++; $percent=intval($i/$all_amount*100); session_start(); $_SESSION['progress']=$percent; session_write_close(); } }
/** * Generate or regenerate PDF for AP using FPDF library * @param $apId * @param bool $approved */ public static function generatePdfFpdf($doc_id, $doc_type, $approved = false) { if ( $doc_type == 'AP' ) { // get AP $ap = Aps::model()->with('dists', 'document', 'ck_req_detail')->findByAttributes( array('Document_ID' => $doc_id) ); $ckRequest = $ap->ck_req_detail; // get PO dists $apDists = $ap->dists; // get PO formatting $poFormatting = PoFormatting::model()->findByAttributes(array( 'Project_ID' => $ap->document->Project_ID, )); // get Sign_Requested_By user info $signRequestedByUser = Users::model()->with('person')->findByPk($ckRequest->Sign_Requested_By); $aproval_detail_list = Audits::getApprovalDetailList($ap->Document_ID); // get current vendor info $currentVendor = Vendors::model()->with('client.company.adreses')->findByPk($ap->Vendor_ID); $condition = UsersClientList::getClientAdminCondition($currentVendor->client->Client_ID); $vendorAdmin = UsersClientList::model()->with('user.person')->find($condition); $pdf = new FpdfAp('P','mm','Letter'); $pdf->AddFont('HelveticaB','','helveticab.php'); $pdf->AddFont('Courier','','courier.php'); $pdf->AddFont('CourierB','','courierb.php'); $pdf->SetAutoPageBreak(true, 10); $pdf->setVariables($ap,$poFormatting,$ckRequest,$apDists,$currentVendor,$vendorAdmin,$signRequestedByUser,$aproval_detail_list,$approved); $pdf->AliasNbPages(); $pdf->setPageNo(1); //$pdf->AliasNbPages(); $pdf->AddPage('P'); $pdf->SetFont('Helvetica','',13.5); $pdf->SetXY(5,10); $pdf->PrintContent(); //$path=Helper::createDirectory('batches');// creates directory "protected/data/batches" if not exists $fileName = 'ApTempPdf'.date('Y-m-d h:i:s').'.pdf'; $filepath = Helper::createDirectory('ap'); $filepath = Helper::createDirectory('ap/'.Yii::app()->user->clientID); $filepath.= '/'.$fileName; $pdf->Output($filepath, 'F'); //$pdf->Output(); $last_page = $pdf->custom_page_num; $pdf->Close(); } if (( $doc_type == 'PO' )) { $po = Pos::model()->findByAttributes( array('Document_ID' => $doc_id) ); // get PO dists $poDists = $po->dists; // get PO details $poDecrDetails = $po->decr_details; // get PO formatting $poFormatting = PoFormatting::model()->findByAttributes(array( 'Project_ID' => $po->document->Project_ID, )); // get Sign_Requested_By user info $signRequestedByUser = Users::model()->with('person')->findByPk($po->Sign_Requested_By); $aproval_detail_list = Audits::getApprovalDetailList($po->Document_ID); // get current vendor info $currentVendor = Vendors::model()->with('client.company.adreses')->findByPk($po->Vendor_ID); $condition = UsersClientList::getClientAdminCondition($currentVendor->client->Client_ID); $vendorAdmin = UsersClientList::model()->with('user.person')->find($condition); $paymentTypes = array( 'OA' => 'On Account', 'CC' => 'Credit Card', 'DP' => 'Deposit', 'CK' => 'Payment Check', 'PC' => 'Petty Cash', ); $pdf = new FpdfPo('P','mm','Letter'); $pdf->AddFont('HelveticaB','','helveticab.php'); $pdf->AddFont('Courier','','courier.php'); $pdf->AddFont('CourierB','','courierb.php'); $pdf->SetAutoPageBreak(true, 10); $pdf->setVariables($po,$poFormatting,$poDecrDetails,$poDists,$currentVendor,$vendorAdmin,$signRequestedByUser,$aproval_detail_list,$approved,$paymentTypes); $pdf->AliasNbPages(); $pdf->setPageNo(1); //$pdf->AliasNbPages(); $pdf->AddPage('P'); $pdf->SetFont('Helvetica','',13.5); $pdf->SetXY(5,10); $pdf->PrintContent(); //$path=Helper::createDirectory('batches');// creates directory "protected/data/batches" if not exists $fileName = 'TempFile.pdf'; $filepath = Helper::createDirectory('po'); $filepath = Helper::createDirectory('po/'.Yii::app()->user->clientID); $filepath.= '/'.$fileName; $pdf->Output($filepath, 'F'); //$pdf->Output(); $last_page = $pdf->custom_page_num; $pdf->Close(); } return array( 'path' => $filepath, 'pages'=> $last_page ); }
/** * Lists all models. */ public function actionIndex() { if (isset($_POST['oper']) && $_POST['oper'] == 'edit') { $vendorId = intval($_POST["id"]); $vendor = Vendors::model()->with('client')->findByPk($vendorId); if ($vendor) { $client = $vendor->client; $company = $client->company; $vendor->Vendor_ID_Shortcut = $_POST["Vendor_ID_Shortcut"]; $vendor->Vendor_Name_Checkprint = $_POST["Vendor_Name_Checkprint"]; $vendor->Vendor_1099 = $_POST["Vendor_1099"]; $vendor->Vendor_Default_GL = $_POST["Vendor_Default_GL"]; $vendor->Vendor_Default_GL_Note = $_POST["Vendor_Default_GL_Note"]; $vendor->Vendor_Note_General = $_POST["Vendor_Note_General"]; $vendor->Active_Relationship = $_POST["Active_Relationship"]; if ($vendor->validate()) { $vendor->save(); echo "vendor\n"; } if ($company->adreses) { $addresses = $company->adreses; if (isset($addresses[0])) { $address = $addresses[0]; $address->Address1 = $_POST["Address1"]; $address->Address2 = $_POST["Address2"]; $address->City = $_POST["City"]; $address->State = $_POST["State"]; $address->ZIP = $_POST["ZIP"]; $address->Country = $_POST["Country"]; $address->Phone = $_POST["Phone"]; $address->Fax = $_POST["Fax"]; if ($address->validate()) { $address->save(); echo "address\n"; } } } $company->Company_Name = $_POST["Company_Name"]; $company->Company_Fed_ID = $_POST["Company_Fed_ID"]; $company->Email = $_POST["Email"]; $company->SSN = $_POST["SSN"]; $company->Business_NameW9 = $_POST["Business_NameW9"]; if ($company->validate()) { $company->save(); echo "company\n"; } } die; } if (isset($_POST['oper']) && $_POST['oper'] == 'add') { die; } if (isset($_POST['oper']) && $_POST['oper'] == 'del') { $vendorId = intval($_POST["id"]); $vendor = Vendors::model()->findByPk($vendorId); if ($vendor) { $vendor->delete(); } die; } $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword); mysql_select_db(Yii::app()->params->dbname); mysql_query("SET NAMES 'utf8'"); Yii::import('ext.phpgrid.inc.jqgrid'); // set columns $col = array(); $col["title"] = "Vendor ID"; // caption of column $col["name"] = "Vendor_ID"; $col["dbname"] = "vendors.Vendor_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = false; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = false; $col["sortable"] = false; $cols[] = $col; // set columns $col = array(); $col["title"] = "Vendor Shortcut"; // caption of column $col["name"] = "Vendor_ID_Shortcut"; $col["dbname"] = "vendors.Vendor_ID_Shortcut"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Vendor Checkprint"; // caption of column $col["name"] = "Vendor_Name_Checkprint"; $col["dbname"] = "vendors.Vendor_Name_Checkprint"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Vendor 1099"; // caption of column $col["name"] = "Vendor_1099"; $col["dbname"] = "vendors.Vendor_1099"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $col["edittype"] = "select"; $col["editoptions"] = array("value"=>'0:0;1:1'); $cols[] = $col; $col = array(); $col["title"] = "Client_Client_ID"; // caption of column $col["name"] = "Client_Client_ID"; $col["dbname"] = "vendors.Client_Client_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = false; // this column is editable $col["viewable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Vendor Default GL"; // caption of column $col["name"] = "Vendor_Default_GL"; $col["dbname"] = "vendors.Vendor_Default_GL"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Vendor GL Note"; // caption of column $col["name"] = "Vendor_Default_GL_Note"; $col["dbname"] = "vendors.Vendor_Default_GL_Note"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Vendor Note General"; // caption of column $col["name"] = "Vendor_Note_General"; $col["dbname"] = "vendors.Vendor_Note_General"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $col["edittype"] = "textarea"; $col["editoptions"] = array("cols"=>'20', 'rows' => '3'); $cols[] = $col; // set columns $col = array(); $col["title"] = "Active Relationship"; // caption of column $col["name"] = "Active_Relationship"; $col["dbname"] = "vendors.Active_Relationship"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $col["edittype"] = "select"; $col["editoptions"] = array("value"=>'0:0;1:1'); $cols[] = $col; // set columns $col = array(); $col["title"] = "Company ID"; // caption of column $col["name"] = "Company_ID"; $col["dbname"] = "companies.Company_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = false; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = false; $col["sortable"] = false; $cols[] = $col; // set columns $col = array(); $col["title"] = "Company Name"; // caption of column $col["name"] = "Company_Name"; $col["dbname"] = "companies.Company_Name"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Fed ID"; // caption of column $col["name"] = "Company_Fed_ID"; $col["dbname"] = "companies.Company_Fed_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "SSN"; // caption of column $col["name"] = "SSN"; $col["dbname"] = "companies.SSN"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Email"; // caption of column $col["name"] = "Email"; $col["dbname"] = "companies.Email"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; $col = array(); $col["title"] = "Business_NameW9"; // caption of column $col["name"] = "Business_NameW9"; $col["dbname"] = "companies.Business_NameW9"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; $col = array(); $col["title"] = "Address1"; // caption of column $col["name"] = "Address1"; $col["dbname"] = "addresses.Address1"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Address2"; // caption of column $col["name"] = "Address2"; $col["dbname"] = "addresses.Address2"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "City"; // caption of column $col["name"] = "City"; $col["dbname"] = "addresses.City"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "State"; // caption of column $col["name"] = "State"; $col["dbname"] = "addresses.State"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "ZIP"; // caption of column $col["name"] = "ZIP"; $col["dbname"] = "addresses.ZIP"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Country"; // caption of column $col["name"] = "Country"; $col["dbname"] = "addresses.Country"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Phone"; // caption of column $col["name"] = "Phone"; $col["dbname"] = "addresses.Phone"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Fax"; // caption of column $col["name"] = "Fax"; $col["dbname"] = "addresses.Fax"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; $g = new jqgrid(); $grid["caption"] = "Vendor List"; // $grid["multiselect"] = true; $grid["autowidth"] = true; $grid["resizable"] = true; //$grid["toppager"] = true; $grid["sortname"] = 'companies.Company_Name'; $grid["sortorder"] = "ASC"; $grid["add_options"] = array( 'width'=>'420', "closeAfterEdit"=>true, // close dialog after add/edit "top"=>"200", // absolute top position of dialog "left"=>"200" // absolute left position of dialog ); $g->set_options($grid); $g->set_actions(array( "add"=>false, // allow/disallow add "edit"=>true, // allow/disallow edit "delete"=>true, // allow/disallow delete "rowactions"=>true, // show/hide row wise edit/del/save option "export"=>true, // show/hide export to excel option "autofilter" => true, // show/hide autofilter for search "search" => "advance" // show single/multi field search condition (e.g. simple or advance) ) ); $g->select_command = "SELECT vendors.*, companies.*, addresses.* FROM vendors LEFT JOIN clients ON clients.Client_ID = vendors.Vendor_Client_ID LEFT JOIN companies ON clients.Company_ID = companies.Company_ID LEFT JOIN company_addresses ON company_addresses.Company_ID = companies.Company_ID LEFT JOIN addresses ON addresses.Address_ID = company_addresses.Address_ID"; // set database table for CRUD operations $g->table = "vendors"; $g->set_columns($cols); // group columns header $g->set_group_header( array( "useColSpanStyle"=>true, "groupHeaders"=>array( array( "startColumnName"=>'Vendor_ID', // group starts from this column "numberOfColumns"=>9, // group span to next 2 columns "titleText"=>'Vendor Information' // caption of group header ), array( "startColumnName"=>'Company_ID', // group starts from this column "numberOfColumns"=>6, // group span to next 2 columns "titleText"=>'Vendor Company' // caption of group header ), array( "startColumnName"=>'Address1', // group starts from this column "numberOfColumns"=>8, // group span to next 2 columns "titleText"=>"Vendor's Address" // caption of group header ) ) ) ); // render grid and get html/js output $out = $g->render("Vendors"); $this->render('index',array( 'out'=>$out, )); }
public static function createNewFromSessionData($current_upload_file,$client){ 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 unlink($current_upload_file['filepath']); } $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->save(); } } else { //if company does not exists, create new company $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 = $company_model->Company_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->save(); } $W9->Revision_ID = 0; } // save w9 $W9->Client_ID = $client->Client_ID; $W9->save(); return $W9; }
/** * Lists all models. */ public function actionIndex() { if (isset($_POST['oper']) && $_POST['oper'] == 'edit') { $companyId = intval($_POST["id"]); $company = Companies::model()->with('client', 'adreses')->findByPk($companyId); if ($company) { if ($company->client) { $client = $company->client; $client->Client_Number = $_POST["Client_Number"]; $client->Client_Logo_Name = $_POST["Client_Logo_Name"]; $client->Client_Approval_Amount_1 = $_POST["Client_Approval_Amount_1"] ? $_POST["Client_Approval_Amount_1"] : null; $client->Client_Approval_Amount_2 = $_POST["Client_Approval_Amount_2"] ? $_POST["Client_Approval_Amount_2"] : null; if ($client->validate()) { $client->save(); echo "client\n"; } } if ($company->adreses) { $addresses = $company->adreses; if (isset($addresses[0])) { $address = $addresses[0]; $address->Address1 = $_POST["Address1"]; $address->Address2 = $_POST["Address2"]; $address->City = $_POST["City"]; $address->State = $_POST["State"]; $address->ZIP = $_POST["ZIP"]; $address->Country = $_POST["Country"]; $address->Phone = $_POST["Phone"]; $address->Fax = $_POST["Fax"]; if ($address->validate()) { $address->save(); echo "address\n"; } } } $company->Company_Name = $_POST["Company_Name"]; $company->Company_Fed_ID = $_POST["Company_Fed_ID"]; $company->Email = $_POST["Email"]; $company->SSN = $_POST["SSN"]; $company->Business_NameW9 = $_POST["Business_NameW9"]; if ($company->validate()) { $company->save(); echo "company\n"; } } die; } if (isset($_POST['oper']) && $_POST['oper'] == 'add') { die; } if (isset($_POST['oper']) && $_POST['oper'] == 'del') { $companyId = intval($_POST["id"]); $company = Companies::model()->with('client', 'adreses')->findByPk($companyId); $documents = Documents::model()->findByAttributes(array( 'Client_ID' => $company->client->Client_ID, )); if ($company && !$documents) { if ($company->client) { $client = $company->client; UsersToApprove::model()->deleteAllByAttributes(array( 'Client_ID' => $client->Client_ID, )); UsersClientList::model()->deleteAllByAttributes(array( 'Client_ID' => $client->Client_ID, )); UsersProjectList::model()->deleteAllByAttributes(array( 'Client_ID' => $client->Client_ID, )); BankAcctNums::model()->deleteAllByAttributes(array( 'Client_ID' => $client->Client_ID, )); Coa::model()->deleteAllByAttributes(array( 'Client_ID' => $client->Client_ID, )); Vendors::model()->deleteAllByAttributes(array( 'Client_Client_ID' => $client->Client_ID, )); Vendors::model()->deleteAllByAttributes(array( 'Vendor_Client_ID' => $client->Client_ID, )); $w9s = W9::model()->findAllByAttributes(array( 'Client_ID' => $client->Client_ID, )); if ($w9s) { foreach ($w9s as $w9) { W9::deleteW9($w9->W9_ID); } } $projects = Projects::model()->findAllByAttributes(array( 'Client_ID' => $client->Client_ID, )); if ($projects) { foreach ($projects as $project) { PoFormatting::model()->deleteAllByAttributes(array( 'Project_ID' => $project->Project_ID, )); $project->delete(); } } $client->delete(); } if ($company->adreses) { $addresses = $company->adreses; foreach ($addresses as $address) { $address->delete(); } } CompanyAddresses::model()->deleteAllByAttributes(array( 'Company_ID' => $companyId, )); $company->delete(); } die; } $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword); mysql_select_db(Yii::app()->params->dbname); mysql_query("SET NAMES 'utf8'"); Yii::import('ext.phpgrid.inc.jqgrid'); // set columns $col = array(); $col["title"] = "Company ID"; // caption of column $col["name"] = "Company_ID"; $col["dbname"] = "companies.Company_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = false; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = false; $col["sortable"] = false; $cols[] = $col; // set columns $col = array(); $col["title"] = "Company Name"; // caption of column $col["name"] = "Company_Name"; $col["dbname"] = "companies.Company_Name"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Fed ID"; // caption of column $col["name"] = "Company_Fed_ID"; $col["dbname"] = "companies.Company_Fed_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "SSN"; // caption of column $col["name"] = "SSN"; $col["dbname"] = "companies.SSN"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Email"; // caption of column $col["name"] = "Email"; $col["dbname"] = "companies.Email"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; $col = array(); $col["title"] = "Business_NameW9"; // caption of column $col["name"] = "Business_NameW9"; $col["dbname"] = "companies.Business_NameW9"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; // set columns $col = array(); $col["title"] = "Client ID"; // caption of column $col["name"] = "Client_ID"; $col["dbname"] = "clients.Client_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = false; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = false; $col["sortable"] = false; $cols[] = $col; $col = array(); $col["title"] = "Client Number"; // caption of column $col["name"] = "Client_Number"; $col["dbname"] = "clients.Client_Number"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Client Logo Name"; // caption of column $col["name"] = "Client_Logo_Name"; $col["dbname"] = "clients.Client_Logo_Name"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Client Approval Amount 1"; // caption of column $col["name"] = "Client_Approval_Amount_1"; $col["dbname"] = "clients.Client_Approval_Amount_1"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; $col = array(); $col["title"] = "Client Approval Amount 2"; // caption of column $col["name"] = "Client_Approval_Amount_2"; $col["dbname"] = "clients.Client_Approval_Amount_2"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; // set columns $col = array(); $col["title"] = "Address ID"; // caption of column $col["name"] = "Address_ID"; $col["dbname"] = "addresses.Address_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = false; // this column is editable $col["hidden"] = true; $col["viewable"] = true; $col["search"] = false; $col["sortable"] = false; $cols[] = $col; $col = array(); $col["title"] = "Address1"; // caption of column $col["name"] = "Address1"; $col["dbname"] = "addresses.Address1"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Address2"; // caption of column $col["name"] = "Address2"; $col["dbname"] = "addresses.Address2"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "City"; // caption of column $col["name"] = "City"; $col["dbname"] = "addresses.City"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "State"; // caption of column $col["name"] = "State"; $col["dbname"] = "addresses.State"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "ZIP"; // caption of column $col["name"] = "ZIP"; $col["dbname"] = "addresses.ZIP"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Country"; // caption of column $col["name"] = "Country"; $col["dbname"] = "addresses.Country"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Phone"; // caption of column $col["name"] = "Phone"; $col["dbname"] = "addresses.Phone"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $cols[] = $col; $col = array(); $col["title"] = "Fax"; // caption of column $col["name"] = "Fax"; $col["dbname"] = "addresses.Fax"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["viewable"] = true; $col["search"] = false; $cols[] = $col; $g = new jqgrid(); $grid["caption"] = "Clients"; // $grid["multiselect"] = true; $grid["autowidth"] = true; $grid["resizable"] = true; //$grid["toppager"] = true; $grid["sortname"] = 'companies.Company_Name'; $grid["sortorder"] = "ASC"; $grid["add_options"] = array( 'width'=>'420', "closeAfterEdit"=>true, // close dialog after add/edit "top"=>"200", // absolute top position of dialog "left"=>"200" // absolute left position of dialog ); $g->set_options($grid); $g->set_actions(array( "add"=>false, // allow/disallow add "edit"=>true, // allow/disallow edit "delete"=>true, // allow/disallow delete "rowactions"=>true, // show/hide row wise edit/del/save option "export"=>true, // show/hide export to excel option "autofilter" => true, // show/hide autofilter for search "search" => "advance" // show single/multi field search condition (e.g. simple or advance) ) ); $g->select_command = "SELECT clients.Client_ID, clients.Client_Number, clients.Client_Logo_Name, companies.*, addresses.*, clients.Client_Approval_Amount_1, clients.Client_Approval_Amount_2 FROM clients LEFT JOIN companies ON clients.Company_ID = companies.Company_ID LEFT JOIN company_addresses ON company_addresses.Company_ID = companies.Company_ID LEFT JOIN addresses ON addresses.Address_ID = company_addresses.Address_ID"; // set database table for CRUD operations $g->table = "clients"; $g->set_columns($cols); // group columns header $g->set_group_header( array( "useColSpanStyle"=>true, "groupHeaders"=>array( array( "startColumnName"=>'Company_ID', // group starts from this column "numberOfColumns"=>6, // group span to next 2 columns "titleText"=>'Company Information' // caption of group header ), array( "startColumnName"=>'Client_ID', // group starts from this column "numberOfColumns"=>5, // group span to next 2 columns "titleText"=>'Client Information' // caption of group header ), array( "startColumnName"=>'Address1', // group starts from this column "numberOfColumns"=>8, // group span to next 2 columns "titleText"=>"Company's Address" // caption of group header ) ) ) ); // render grid and get html/js output $out = $g->render("Clients"); $this->render('index',array( 'out'=>$out, )); }
/** * Create Vendor's folder for project * @param $projectId * @param $vendorId * @param $year * @return int */ public static function createVendorFolder($projectId, $vendorId, $year) { // get cabinet $cabinet = self::getCabinetForFolderCreate($projectId, $year); // get vendor info $vendor = Vendors::model()->with('client.company')->findByPk($vendorId); $folder = Sections::model()->findByAttributes(array( 'Section_Type' => Storages::CABINET, 'Created_By' => '0', 'Storage_ID' => $cabinet->Storage_ID, 'Vendor_ID' => $vendorId, 'Folder_Cat_ID' => self::VENDOR_DOCUMENTS, )); if (!$folder) { $folder = new Sections(); $folder->Storage_ID = $cabinet->Storage_ID; $folder->Section_Name = substr($vendor->client->company->Company_Name,0,50); $folder->Vendor_ID = $vendorId; $folder->Created_By = 0; $folder->Section_Type = Storages::CABINET; $folder->Folder_Cat_ID = self::VENDOR_DOCUMENTS; $folder->Access_Type = Storages::HAS_ACCESS; if ($folder->validate()) { $folder->save(); $panel = new Subsections(); $panel->Section_ID = $folder->Section_ID; $panel->Subsection_Name = 'Panel 1'; $panel->Subsection_Type = Storages::CABINET; $panel->Created_By = 0; $panel->Access_Type = Storages::HAS_ACCESS; $panel->save(); } } else { $panel = Subsections::model()->findByAttributes(array( 'Subsection_Type' => Storages::CABINET, 'Created_By' => '0', 'Section_ID' => $folder->Section_ID, )); } return $panel->Subsection_ID; }