public function StockCreationExample()
 {
     $metric = new Metric();
     $metric->name = 'Unit';
     $metric->symbol = 'U';
     $metric->save();
     //Now, create a category to store the inventory record under:
     $category = new Category();
     $category->name = 'VoIP';
     $category->save();
     $item = new Inventory();
     $item->metric_id = $metric->id;
     $item->category_id = $category->id;
     $item->name = 'SNOM Headset';
     $item->description = 'Very nice for the ear';
     $item->save();
     $location = new Location();
     $location->name = 'Snowball Small Stock Room';
     $location->save();
     $item->createStockOnLocation(2, $location);
     $item->createSku('PART1234');
     dd($item->sku_code);
     //$res = Inventory::findBySku(Input::get('sku'));
     //$item = Inventory::find(1);
     //dd($item);
     $supplier = new Supplier();
     //Mandatory fields
     $supplier->name = 'Miro Distribution';
     //Optional fields
     $supplier->address = 'Montague Gardens';
     $supplier->postal_code = '8000';
     $supplier->zip_code = '12345';
     $supplier->country = 'South Africa';
     $supplier->region = 'Western Cape';
     $supplier->city = 'Cape Town';
     $supplier->contact_title = 'Sales Rep';
     $supplier->contact_name = 'Mark Sparky';
     $supplier->contact_phone = '555 555-5555';
     $supplier->contact_fax = '555 555-5556';
     $supplier->contact_email = '*****@*****.**';
     $supplier->save();
     $item = Inventory::find(1);
     //$supplier = Supplier::find(1);
     $item->addSupplier($supplier);
 }
 public function post()
 {
     $post = Input::all();
     $validator = Supplier::validate($post);
     $supplierId = $post['id'];
     if ($validator->fails()) {
         return Redirect::to('distribuidores/' . $supplierId)->withErrors($validator)->withInput();
     } else {
         $supplier = self::__checkExistence($supplierId);
         if (!$supplierId) {
             $supplier = new Supplier();
         }
         $supplier->name = $post['name'];
         $supplier->ruc = $post['ruc'];
         $supplier->address = $post['address'];
         $supplier->phone = $post['phone'];
         $supplier->email = $post['email'];
         $supplier->web = $post['web'];
         $supplier->contact = $post['contact'];
         $supplier->contact_phone = $post['contact_phone'];
         $supplier->save();
         if ($post['status'] == 'inactive') {
             $supplier->delete();
         } else {
             if ($supplier->trashed()) {
                 $supplier->restore();
             }
         }
         Session::flash('success', 'Distribuidor guardado correctamente.');
         return Redirect::to('distribuidores');
     }
 }
 /**
  * Store a newly created resource in storage.
  * POST /supplier
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), Supplier::$rules);
     if ($validator->fails()) {
         return Redirect::to('supplier')->withErrors($validator)->withInput(Input::all());
     } else {
         if (Supplier::where('id_supp', '=', Input::get('id_supp'))->exists()) {
             $supplier = Supplier::find(Input::get('id_supp'));
             $supplier->nm_supp = Input::get('nm_supp');
             $supplier->alamat = Input::get('alamat');
             $supplier->telp = Input::get('telp');
             $supplier->fax = Input::get('fax');
             $supplier->save();
             Session::flash('message', 'Successfully updated supplier!');
             return Redirect::to('supplier');
         } else {
             $supplier = new Supplier();
             $supplier->id_supp = Input::get('id_supp');
             $supplier->nm_supp = Input::get('nm_supp');
             $supplier->alamat = Input::get('alamat');
             $supplier->telp = Input::get('telp');
             $supplier->fax = Input::get('fax');
             $supplier->save();
             Session::flash('message', 'Successfully created supplier!');
             return Redirect::to('supplier');
         }
     }
 }
 public function createSupplier()
 {
     $rule = array('first_name' => 'required', 'email' => 'email|required');
     $cust = Input::all();
     $valid = Validator::make($cust, $rule);
     if ($valid->fails()) {
         return Redirect::to('add-supplier');
     } else {
         $supplier = new Supplier();
         $supplier->company_name = Input::get('company_name');
         $supplier->first_name = Input::get('first_name');
         $supplier->last_name = Input::get('last_name');
         $supplier->email = Input::get('email');
         $supplier->phone_number = Input::get('phone_number');
         $supplier->address_1 = Input::get('address_1');
         $supplier->address_2 = Input::get('address_2');
         $supplier->city = Input::get('city');
         $supplier->state = Input::get('state');
         $supplier->zip = Input::get('zip');
         $supplier->country = Input::get('country');
         $supplier->comment = Input::get('comment');
         $supplier->account = Input::get('account');
         $supplier->save();
         return Redirect::to('all-suppliers');
     }
 }
Exemple #5
0
 public static function Create($name, $person, $telephone, $email, $address, $bal)
 {
     $type = new PartyType('Supplier');
     $supplier = new Supplier($type, $name, $person, $telephone, $email, $address, $bal);
     if ($supplier->save()) {
         return $supplier;
     }
     return false;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Supplier();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Supplier'])) {
         $model->attributes = $_POST['Supplier'];
         if ($model->save()) {
             $this->redirect(['admin']);
         }
     }
     $this->render('create', ['model' => $model]);
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Supplier();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Supplier'])) {
         $model->attributes = $_POST['Supplier'];
         if ($model->save()) {
             Yii::app()->user->setFlash('info', MyFormatter::alertInfo('<strong>Selamat!</strong> Data telah berhasil disimpan.'));
             $this->redirect(array('view', 'id' => $model->ID_SUPPLIER));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($recv_mode = 'N', $trans_mode = null)
 {
     $model = new Supplier();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (Yii::app()->user->checkAccess('supplier.create')) {
         if (isset($_POST['Supplier'])) {
             $model->attributes = $_POST['Supplier'];
             if ($model->validate()) {
                 $transaction = Yii::app()->db->beginTransaction();
                 try {
                     if ($model->save()) {
                         AccountSupplier::model()->saveAccount($model->id, $model->company_name);
                         $transaction->commit();
                         if ($recv_mode == 'N') {
                             Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, 'Supplier : <strong>' . $model->company_name . '</strong> have been saved successfully!');
                             $this->redirect(array('create'));
                         } else {
                             Yii::app()->receivingCart->setSupplier($model->id);
                             $this->redirect(array('receivingItem/index', 'trans_mode' => $trans_mode));
                         }
                         /*
                         Yii::app()->clientScript->scriptMap['jquery.js'] = false;
                         echo CJSON::encode(array(
                            'status'=>'success',
                            'div'=>"<div class=alert alert-info fade in>Successfully added ! </div>",
                            ));
                         Yii::app()->end();
                          * 
                         */
                     }
                 } catch (CDbException $e) {
                     $transaction->rollback();
                     Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_WARNING, 'Oop something wrong : <strong>' . $e->getMessage());
                 }
             }
         }
     } else {
         throw new CHttpException(403, 'You are not authorized to perform this action');
     }
     if (Yii::app()->request->isAjaxRequest) {
         Yii::app()->clientScript->scriptMap['*.js'] = false;
         echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('_form', array('model' => $model), true, false)));
         Yii::app()->end();
     } else {
         $this->render('create', array('model' => $model));
     }
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aSupplier !== null) {
             if ($this->aSupplier->isModified() || $this->aSupplier->isNew()) {
                 $affectedRows += $this->aSupplier->save($con);
             }
             $this->setSupplier($this->aSupplier);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->detailBarangMasuksScheduledForDeletion !== null) {
             if (!$this->detailBarangMasuksScheduledForDeletion->isEmpty()) {
                 DetailBarangMasukQuery::create()->filterByPrimaryKeys($this->detailBarangMasuksScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->detailBarangMasuksScheduledForDeletion = null;
             }
         }
         if ($this->collDetailBarangMasuks !== null) {
             foreach ($this->collDetailBarangMasuks as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $rules = array('name' => 'required|unique:suppliers,name');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator);
     } else {
         // store
         $supplier = new Supplier();
         $supplier->name = Input::get('name');
         $supplier->phone_no = Input::get('phone_no');
         $supplier->email = Input::get('email');
         $supplier->physical_address = Input::get('physical_address');
         try {
             $supplier->save();
             return Redirect::route('supplier.index')->with('message', 'Successifully added a new supplier');
         } catch (QueryException $e) {
             Log::error($e);
         }
     }
 }
Exemple #11
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = array('name' => 'required|unique:suppliers,name');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->WithInput();
     } else {
         // store
         $supplier = new Supplier();
         $supplier->name = Input::get('name');
         $supplier->phone = Input::get('phone');
         $supplier->email = Input::get('email');
         $supplier->address = Input::get('address');
         $supplier->user_id = Auth::user()->id;
         try {
             $supplier->save();
             $url = Session::get('SOURCE_URL');
             return Redirect::to($url)->with('message', trans('messages.record-successfully-saved'));
         } catch (QueryException $e) {
             Log::error($e);
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $rules = array("supplierId" => "required", "supplierName" => "required", "firstAddress" => "required", "secondAddress" => "required", "area" => "required", "region" => "required", "supplierPhone" => "required|numeric", "supplierFax" => "required|numeric", "supplierEmail" => "required|email", "supplierContact" => "required", "supplierMobile" => "required|numeric");
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('/supplier/create')->withErrors($validator);
     }
     //
     $supplier = new Supplier();
     $supplier->supplierID = Input::get('supplierId');
     $supplier->supplierName = Input::get('supplierName');
     $supplier->supplierAddress1 = Input::get('firstAddress');
     $supplier->supplierAddress2 = Input::get('secondAddress');
     $supplier->areaID = Input::get("area");
     $supplier->regionID = Input::get("region");
     $supplier->supplierPhone = Input::get("supplierPhone");
     $supplier->supplierFax = Input::get("supplierFax");
     $supplier->supplierEmail = Input::get("supplierEmail");
     $supplier->supplierContact = Input::get("supplierContact");
     $supplier->supplierMobile = Input::get("supplierMobile");
     $supplier->save();
     return Redirect::to('/supplier');
 }
 /**
  * To get Vendor from client's Data
  */
 function getVendor()
 {
     $this->autoRender = false;
     $sql = "SELECT * FROM vendors;";
     $datas = $this->Cabinet->query($sql);
     App::uses("Supplier", "Inventory.Model");
     foreach ($datas as $data) {
         $supplier = new Supplier();
         $vendor['Supplier']['name'] = $data['vendors']['Name'];
         $vendor['Supplier']['address'] = $data['vendors']['AddressLine1'];
         $vendor['Supplier']['city'] = $data['vendors']['City'];
         $vendor['Supplier']['postal_code'] = $data['vendors']['Postal'];
         $vendor['Supplier']['province'] = $data['vendors']['Province'];
         $vendor['Supplier']['country'] = "Canada";
         $vendor['Supplier']['phone'] = $data['vendors']['PhoneNumber'];
         $vendor['Supplier']['fax_number'] = $data['vendors']['FaxNumber'];
         $vendor['Supplier']['terms'] = $data['vendors']['Terms'];
         $vendor['Supplier']['notes'] = $data['vendors']['Notes'];
         $vendor['Supplier']['email'] = $data['vendors']['EmailAddress'];
         $vendor['Supplier']['qb_suplier_name'] = $data['vendors']['QBAccountName'];
         $vendor['Supplier']['door_supplier'] = $data['vendors']['DoorVendor'];
         $vendor['Supplier']['cabinet_supplier'] = $data['vendors']['BoxVendor'];
         $vendor['Supplier']['laminate_supplier'] = $data['vendors']['LaminateVendor'];
         $vendor['Supplier']['hardware_supplier'] = $data['vendors']['HardwareVendor'];
         $vendor['Supplier']['gst_rate'] = $data['vendors']['GST'];
         $vendor['Supplier']['pst_rate'] = $data['vendors']['PST'];
         $vendor['Supplier']['notes_on_po'] = $data['vendors']['POMemo'];
         if (!$supplier->save($vendor)) {
             pr($supplier->validationErrors);
         }
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $filename = $this->argument('filename');
     if (!$this->option('testrun') == 'true') {
         $this->comment('======= Importing Licenses from ' . $filename . ' =========');
     } else {
         $this->comment('====== TEST ONLY License Import for ' . $filename . ' ====');
         $this->comment('============== NO DATA WILL BE WRITTEN ==============');
     }
     if (!ini_get("auto_detect_line_endings")) {
         ini_set("auto_detect_line_endings", '1');
     }
     $csv = Reader::createFromPath($this->argument('filename'));
     $csv->setNewline("\r\n");
     $csv->setOffset(1);
     $duplicates = '';
     // Loop through the records
     $nbInsert = $csv->each(function ($row) use($duplicates) {
         $status_id = 1;
         // Let's just map some of these entries to more user friendly words
         if (array_key_exists('0', $row)) {
             $user_name = trim($row[0]);
         } else {
             $user_name = '';
         }
         if (array_key_exists('1', $row)) {
             $user_email = trim($row[1]);
         } else {
             $user_email = '';
         }
         if (array_key_exists('2', $row)) {
             $user_username = trim($row[2]);
         } else {
             $user_username = '';
         }
         if (array_key_exists('3', $row)) {
             $user_license_name = trim($row[3]);
         } else {
             $user_license_name = '';
         }
         if (array_key_exists('4', $row)) {
             $user_license_serial = trim($row[4]);
         } else {
             $user_license_serial = '';
         }
         if (array_key_exists('5', $row)) {
             $user_licensed_to_name = trim($row[5]);
         } else {
             $user_licensed_to_name = '';
         }
         if (array_key_exists('6', $row)) {
             $user_licensed_to_email = trim($row[6]);
         } else {
             $user_licensed_to_email = '';
         }
         if (array_key_exists('7', $row)) {
             $user_license_seats = trim($row[7]);
         } else {
             $user_license_seats = '';
         }
         if (array_key_exists('8', $row)) {
             $user_license_reassignable = trim($row[8]);
             if ($user_license_reassignable != '') {
                 if (strtolower($user_license_reassignable) == 'yes' || strtolower($user_license_reassignable) == 'true' || $user_license_reassignable == '1') {
                     $user_license_reassignable = 1;
                 }
             } else {
                 $user_license_reassignable = 0;
             }
         } else {
             $user_license_reassignable = 0;
         }
         if (array_key_exists('9', $row)) {
             $user_license_supplier = trim($row[9]);
         } else {
             $user_license_supplier = '';
         }
         if (array_key_exists('10', $row)) {
             $user_license_maintained = trim($row[10]);
             if ($user_license_maintained != '') {
                 if (strtolower($user_license_maintained) == 'yes' || strtolower($user_license_maintained) == 'true' || $user_license_maintained == '1') {
                     $user_license_maintained = 1;
                 }
             } else {
                 $user_license_maintained = 0;
             }
         } else {
             $user_license_maintained = '';
         }
         if (array_key_exists('11', $row)) {
             $user_license_notes = trim($row[11]);
         } else {
             $user_license_notes = '';
         }
         if (array_key_exists('12', $row)) {
             if ($row[12] != '') {
                 $user_license_purchase_date = date("Y-m-d 00:00:01", strtotime($row[12]));
             } else {
                 $user_license_purchase_date = '';
             }
         } else {
             $user_license_purchase_date = 0;
         }
         // A number was given instead of a name
         if (is_numeric($user_name)) {
             $this->comment('User ' . $user_name . ' is not a name - assume this user already exists');
             $user_username = '';
             // No name was given
         } elseif ($user_name == '') {
             $this->comment('No user data provided - skipping user creation, just adding license');
             $first_name = '';
             $last_name = '';
             $user_username = '';
         } else {
             $name = explode(" ", $user_name);
             $first_name = $name[0];
             $email_last_name = '';
             $email_prefix = $first_name;
             if (!array_key_exists(1, $name)) {
                 $last_name = '';
                 $email_last_name = $last_name;
                 $email_prefix = $first_name;
             } else {
                 $last_name = str_replace($first_name, '', $user_name);
                 if ($this->option('email_format') == 'filastname') {
                     $email_last_name .= str_replace(' ', '', $last_name);
                     $email_prefix = $first_name[0] . $email_last_name;
                 } elseif ($this->option('email_format') == 'firstname.lastname') {
                     $email_last_name .= str_replace(' ', '', $last_name);
                     $email_prefix = $first_name . '.' . $email_last_name;
                 } elseif ($this->option('email_format') == 'firstname') {
                     $email_last_name .= str_replace(' ', '', $last_name);
                     $email_prefix = $first_name;
                 }
             }
             $user_username = $email_prefix;
             // Generate an email based on their name if no email address is given
             if ($user_email == '') {
                 if ($first_name == 'Unknown') {
                     $status_id = 7;
                 }
                 $email = strtolower($email_prefix) . '@' . $this->option('domain');
                 $user_email = str_replace("'", '', $email);
             }
         }
         $this->comment('Full Name: ' . $user_name);
         $this->comment('First Name: ' . $first_name);
         $this->comment('Last Name: ' . $last_name);
         $this->comment('Username: '******'Email: ' . $user_email);
         $this->comment('License Name: ' . $user_license_name);
         $this->comment('Serial No: ' . $user_license_serial);
         $this->comment('Licensed To Name: ' . $user_licensed_to_name);
         $this->comment('Licensed To Email: ' . $user_licensed_to_email);
         $this->comment('Seats: ' . $user_license_seats);
         $this->comment('Reassignable: ' . $user_license_reassignable);
         $this->comment('Supplier: ' . $user_license_supplier);
         $this->comment('Maintained: ' . $user_license_maintained);
         $this->comment('Notes: ' . $user_license_notes);
         $this->comment('Purchase Date: ' . $user_license_purchase_date);
         $this->comment('------------- Action Summary ----------------');
         if ($user_username != '') {
             if ($user = User::where('username', $user_username)->whereNotNull('username')->first()) {
                 $this->comment('User ' . $user_username . ' already exists');
             } else {
                 // Create the user
                 $user = Sentry::createUser(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $user_email, 'username' => $user_username, 'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10), 'activated' => true, 'permissions' => array('admin' => 0, 'user' => 1), 'notes' => 'User importerd through license importer'));
                 // Find the group using the group id
                 $userGroup = Sentry::findGroupById(3);
                 // Assign the group to the user
                 $user->addGroup($userGroup);
                 $this->comment('User ' . $first_name . ' created');
             }
         } else {
             $user = new User();
             $user->user_id = NULL;
         }
         // Check for the supplier match and create it if it doesn't exist
         if ($supplier = Supplier::where('name', $user_license_supplier)->first()) {
             $this->comment('Supplier ' . $user_license_supplier . ' already exists');
         } else {
             $supplier = new Supplier();
             $supplier->name = e($user_license_supplier);
             $supplier->user_id = 1;
             if ($supplier->save()) {
                 $this->comment('Supplier ' . $user_license_supplier . ' was created');
             } else {
                 $this->comment('Something went wrong! Supplier ' . $user_license_supplier . ' was NOT created');
             }
         }
         // Add the license
         $license = new License();
         $license->name = e($user_license_name);
         if ($user_license_purchase_date != '') {
             $license->purchase_date = $user_license_purchase_date;
         } else {
             $license->purchase_date = NULL;
         }
         $license->serial = e($user_license_serial);
         $license->seats = e($user_license_seats);
         $license->supplier_id = $supplier->id;
         $license->user_id = 1;
         if ($user_license_purchase_date != '') {
             $license->purchase_date = $user_license_purchase_date;
         } else {
             $license->purchase_date = NULL;
         }
         $license->license_name = $user_licensed_to_name;
         $license->license_email = $user_licensed_to_email;
         $license->notes = e($user_license_notes);
         if ($license->save()) {
             $this->comment('License ' . $user_license_name . ' with serial number ' . $user_license_serial . ' was created');
             $license_seat_created = 0;
             for ($x = 0; $x < $user_license_seats; $x++) {
                 // Create the license seat entries
                 $license_seat = new LicenseSeat();
                 $license_seat->license_id = $license->id;
                 $license_seat->assigned_to = $user->id;
                 if ($license_seat->save()) {
                     $license_seat_created++;
                 }
             }
             if ($license_seat_created > 0) {
                 $this->comment($license_seat_created . ' seats were created');
             } else {
                 $this->comment('Something went wrong! NO seats for ' . $user_license_name . ' were created');
             }
         } else {
             $this->comment('Something went wrong! License ' . $user_license_name . ' was NOT created');
         }
         $this->comment('=====================================');
         return true;
     });
 }
 public function actionUpload()
 {
     parent::actionUpload();
     $folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
     // folder for uploaded files
     $allowedExtensions = array("csv");
     $sizeLimit = (int) Yii::app()->params['sizeLimit'];
     // maximum file size in bytes
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload($folder, true);
     $row = 0;
     if (($handle = fopen($folder . $uploader->file->getName(), "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
             if ($row > 0) {
                 $model = Supplier::model()->findByPk((int) $data[0]);
                 if ($model === null) {
                     $model = new Supplier();
                 }
                 $model->addressbookid = (int) $data[0];
                 $model->fullname = $data[1];
                 $model->recordstatus = (int) $data[2];
                 try {
                     if (!$model->save()) {
                         $errormessage = $model->getErrors();
                         if (Yii::app()->request->isAjaxRequest) {
                             echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
                         }
                     }
                 } catch (Exception $e) {
                     $errormessage = $e->getMessage();
                     if (Yii::app()->request->isAjaxRequest) {
                         echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
                     }
                 }
             }
             $row++;
         }
         fclose($handle);
     }
     $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $result;
 }
 public function postUploadsuppliers()
 {
     $rules = array('event' => 'required', 'name' => 'required', 'desc' => 'required', 'categories' => 'required', 'country' => 'required', 'logo' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->passes()) {
         $s = new Supplier();
         $s->name = Input::get('name');
         $s->event = Input::get('event');
         $s->link = Input::get('link');
         $s->description = Input::get('desc');
         $s->categories = Input::get('categories');
         $s->country = Input::get('country');
         $s->order = Input::get('order');
         $image1 = Input::file('logo');
         $filename = date('Y-m-d-hh-mm-ss') . '-' . $image1->getClientOriginalName();
         Image::make($image1->getRealPath())->resize(100, 100)->save(getcwd() . '/images/admin/supplierlogos/' . $filename);
         $s->imgpath = 'images/admin/supplierlogos/' . $filename;
         $s->save();
         $message = "Supplier Added";
         return Redirect::to('admin/uploadsuppliers')->with('message', $message);
     }
     return Redirect::to('admin/uploadsuppliers')->with('message', 'Could not add. All fields required, including logo image')->withInput();
 }