/** * 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); } }
public function approveAction() { $vid = $this->_getParam('vid'); $v = new Vendors($vid); $v->status = Constants::VENDOR_STATUS_APPROVED; $v->save(); // Sending mail $subject = "GLAM ME"; $body = "<p>Congratulations! You have been approved! for next step, please click <br/><a href='http://dev.greatnetsolutions.com" . $this->view->baseUrl() . "/vendor/signup/submission/vid/" . $v->id . "'>This Link</a></p>"; $mail = Mail::factory(); $mail->setSubject($subject); $mail->addTo($v->email); $mail->setBodyHtml($body); $mail->send(); // Set message $msg = "You approved!"; $params = array('msg' => $msg); $this->_forward('thankyou', 'signup', 'vendor', $params); }
/** function used to create or map with existing vendor if the product has mapped with an vendor during import */ function add_create_vendor() { global $imported_ids; global $current_user; $vendor_name = trim($this->column_fields['vendor_id']); if (!isset($vendor_name) || $vendor_name == '') { return; } $arr = array(); // check if it already exists $focus = new Vendors(); $query = ''; // if user is defining the ec_vendor id to be associated with this contact.. //Modified to remove the spaces at first and last in ec_account name -- after 4.2 patch 2 $vendor_name = trim(addslashes($vendor_name)); //Modified the query to get the available vendor only ie., which is not deleted $query = "select * from ec_vendor WHERE vendorname like '%{$vendor_name}%' and deleted=0"; $result = $this->db->query($query); $row = $this->db->fetchByAssoc($result, -1, false); // we found a row with that id if (isset($row['vendorid']) && $row['vendorid'] != -1) { $focus->id = $row['vendorid']; } // if we didnt find the ec_account, so create it if (!isset($focus->id) || $focus->id == '') { $focus->column_fields['vendorname'] = $vendor_name; $focus->column_fields['assigned_user_id'] = $current_user->id; $focus->column_fields['modified_user_id'] = $current_user->id; $focus->save("Vendors"); $vendor_id = $focus->id; // avoid duplicate mappings: if (!isset($imported_ids[$vendor_id])) { $imported_ids[$vendor_id] = 1; } } // now just link the ec_vendor $this->column_fields["vendor_id"] = $focus->id; }
/** * 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(); } }
function create_vendor_from_webform($username, $sessionid, $vendorname, $email, $phone, $website) { global $log; global $adb; global $current_user; if (!validateSession($username, $sessionid)) { return null; } require_once "modules/Users/Users.php"; $seed_user = new Users(); $user_id = $seed_user->retrieve_user_id($username); $current_user = $seed_user; $current_user->retrieve_entity_info($user_id, 'Users'); $adb->println("Create New Vendor from Web Form - Starts"); require_once "modules/Vendors/Vendors.php"; if (isPermitted("Vendors", "EditView") == "yes") { $focus = new Vendors(); $focus->column_fields['vendorname'] = $vendorname; $focus->column_fields['email'] = $email; $focus->column_fields['phone'] = $phone; $focus->column_fields['website'] = $website; $focus->save("Vendors"); $focus->retrieve_entity_info($focus->id, "Vendors"); $adb->println("Create New Vendor from Web Form - Ends"); if ($focus->id != '') { return 'Vendor added successfully'; } else { return "Vendor creation failed. Try again"; } } else { return $accessDenied; } }
for ($i = 0; $i < 10; $i++) { $vendor = new Vendors(); $vendor->column_fields["vendorname"] = ucfirst(strtolower($first_name_array[$i])); $vendor->column_fields["phone"] = create_phone_number(); $vendor->column_fields["email"] = strtolower($vendor->column_fields["vendorname"]) . "@company.com"; $website = str_replace($whitespace, "", strtolower(ucfirst(strtolower($company_name_array[$i])))); $vendor->column_fields["website"] = "www." . $website . ".com"; $vendor->column_fields["assigned_user_id"] = $assigned_user_id; // Fill in a bogus address $vendor->column_fields["street"] = $street_address_array[rand(0, $street_address_count - 1)]; $key = array_rand($city_array); $vendor->column_fields["city"] = $city_array[$key]; $vendor->column_fields["state"] = "CA"; $vendor->column_fields["postalcode"] = '99999'; $vendor->column_fields["country"] = 'USA'; $vendor->save("Vendors"); $vendor_ids[] = $vendor->id; } //Populating Product Data $product_name_array = array("Vtiger Single User Pack", "Vtiger 5 Users Pack", "Vtiger 10 Users Pack", "Vtiger 25 Users Pack", "Vtiger 50 Users Pack", "Double Panel See-thru Clipboard", "abcd1234", "Cd-R CD Recordable", "Sharp - Plain Paper Fax", "Brother Ink Jet Cartridge"); $product_code_array = array("001", "002", "003", "023", "005", "sg-106", "1324356", "sg-108", "sg-119", "sg-125"); $subscription_rate = array("149", "699", "1299", "2999", "4995"); //added by jeri to populate product images $product_image_array = array("", "", "", ""); for ($i = 0; $i < 10; $i++) { $product = new Products(); if ($i > 4) { $parent_key = array_rand($opportunity_ids); $product->column_fields["parent_id"] = $opportunity_ids[$parent_key]; $usageunit = "Each"; $qty_per_unit = 1;
public function submissionAction() { $vid = $this->_getParam('vid'); $v = new Vendors($vid); if (!empty($_POST)) { $comment = $this->_getParam('comments'); $v->application_notes = $comment; $v->save(); if ($_FILES['submission']['tmp_name'] != "") { $tempFile = $_FILES['submission']['tmp_name']; $filename = $_FILES['submission']['name']; $cr_submission = $this->upload($tempFile, $filename); $vc = new VendorsCredentials(); $vc->vendor_id = $v->id; $vc->cred_id = Constants::CR_ESSAY_SUBMISSION; $vc->filename = $cr_submission; $vc->save(); } // Set message $msg = "Once an administrator has approved your application we will provide you with the next step."; $params = array('msg' => $msg); $this->_forward('thankyou', 'signup', 'vendor', $params); } $this->view->vendor = $v; }
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; }