public function action_createOrUpdateWarehouse()
 {
     try {
         $post = Validate::factory($_POST)->rule('warehouse_name', 'not_empty')->rule('warehouse_short_name', 'not_empty')->rule('warehouse_office_location', 'not_empty');
         if (!$post->check()) {
             echo "0|ERROR - Empty Data Post";
             die;
         }
         $warehouse_id = StringHelper::cleanEmptyString4NULL($_POST['warehouse_id']);
         $warehouse_name = StringHelper::cleanEmptyString4NULL($_POST['warehouse_name']);
         $warehouse_short_name = StringHelper::cleanEmptyString4NULL($_POST['warehouse_short_name']);
         $warehouse_office_location = StringHelper::cleanEmptyString4NULL($_POST['warehouse_office_location']);
         $warehouse = new Model_Warehouse();
         if ($warehouse_id != 0) {
             $warehouse = ORM::factory('Warehouse', $warehouse_id);
         }
         $warehouse->name = trim($warehouse_name);
         $warehouse->shortName = trim($warehouse_short_name);
         $warehouse->status = $this->GENERAL_STATUS['ACTIVE'];
         $warehouse->idOfficeLocation = $warehouse_office_location;
         $warehouse->save();
         echo "1|ok";
     } catch (Exception $exc) {
         echo "0|" . $exc->getTraceAsString();
     }
     die;
 }
 public function action_createOrUpdateOfficeLocation()
 {
     try {
         $post = Validate::factory($_POST)->rule('office_location_name', 'not_empty')->rule('office_location_address', 'not_empty')->rule('office_location_country', 'not_empty');
         if (!$post->check()) {
             echo "0|ERROR - Empty Data Post";
             die;
         }
         $office_location_id = StringHelper::cleanEmptyString4NULL($_POST['office_location_id']);
         $office_location_name = StringHelper::cleanEmptyString4NULL($_POST['office_location_name']);
         $office_location_address = StringHelper::cleanEmptyString4NULL($_POST['office_location_address']);
         $office_location_country = StringHelper::cleanEmptyString4NULL($_POST['office_location_country']);
         $office_location = new Model_Officelocation();
         if ($office_location_id != 0) {
             $office_location = ORM::factory('Officelocation', $office_location_id);
         }
         $office_location->name = trim($office_location_name);
         $office_location->address = trim($office_location_address);
         $office_location->status = $this->GENERAL_STATUS['ACTIVE'];
         $office_location->idCountry = $office_location_country;
         $office_location->save();
         echo "1|ok";
     } catch (Exception $exc) {
         echo "0|" . $exc->getTraceAsString();
     }
     die;
 }
Beispiel #3
0
 public function action_createOrUpdateUser()
 {
     try {
         $post = Validate::factory($_POST)->rule('person_fname', 'not_empty')->rule('person_lname', 'not_empty')->rule('person_email', 'not_empty')->rule('user_id', 'not_empty')->rule('user_name', 'not_empty')->rule('user_password', 'not_empty')->rule('user_group', 'not_empty')->rule('person_country', 'not_empty');
         if (!$post->check()) {
             echo "0|ERROR - Empty Data Post";
             die;
         }
         $person_fname = StringHelper::cleanEmptyString4NULL($_POST['person_fname']);
         $person_lname = StringHelper::cleanEmptyString4NULL($_POST['person_lname']);
         $person_email = StringHelper::cleanEmptyString4NULL($_POST['person_email']);
         $user_id = $_POST['user_id'];
         $user_name = StringHelper::cleanEmptyString4NULL($_POST['user_name']);
         $user_password = $_POST['user_password'];
         $user_group = $_POST['user_group'];
         $person_country = $_POST['person_country'];
         $person_phone1 = StringHelper::cleanEmptyString4NULL($_POST['person_phone1']);
         $person_phone2 = StringHelper::cleanEmptyString4NULL($_POST['person_phone2']);
         $person_cellphone = StringHelper::cleanEmptyString4NULL($_POST['person_cellphone']);
         $person_address1 = StringHelper::cleanEmptyString4NULL($_POST['person_address1']);
         $person_address2 = StringHelper::cleanEmptyString4NULL($_POST['person_address2']);
         $person_city = StringHelper::cleanEmptyString4NULL($_POST['person_city']);
         $person_zipcode = StringHelper::cleanEmptyString4NULL($_POST['person_zipcode']);
         $person_array_data = array('fName' => $person_fname, 'lName' => $person_lname, 'phone1' => $person_phone1, 'phone2' => $person_phone2, 'address1' => $person_address1, 'address2' => $person_address2, 'idCountry' => $person_country, 'email' => $person_email, 'city' => $person_city, 'zipcode' => $person_zipcode, 'type' => $this->USER_TYPE['EMPLOYEE']);
         $user_array_data = array('idUser' => NULL, 'userName' => $user_name, 'password' => $user_password, 'status' => $this->GENERAL_STATUS['ACTIVE'], 'registrationDate' => NULL, 'idGroup' => $user_group);
         DB::query(NULL, "BEGIN WORK")->execute();
         $success = FALSE;
         if ($user_id == 0) {
             //CREATE PERSON
             $person_saved = DB::insert('person', array_keys($person_array_data))->values($person_array_data)->execute();
             //CREATE USER
             $user_array_data['idUser'] = $person_saved[0];
             $user_array_data['registrationDate'] = Date::formatted_time();
             $user_saved = DB::insert('user', array_keys($user_array_data))->values($user_array_data)->execute();
             $success = ($person_saved[1] and $user_saved[1]);
         } else {
             //UPDATE PERSON
             $person_update = DB::update('person')->set($person_array_data)->where('idPerson', '=', $user_id)->execute();
             //UPDATE USER
             unset($user_array_data['idUser']);
             unset($user_array_data['registrationDate']);
             $user_update = DB::update('user')->set($user_array_data)->where('idUser', '=', $user_id)->execute();
             $success = ($person_update >= 0 or $user_update >= 0);
         }
         if ($success) {
             DB::query(NULL, "COMMIT")->execute();
             echo "1|ok";
         }
     } catch (Exception $exc) {
         DB::query(NULL, "ROLLBACK")->execute();
         echo "0|COMMIT ERROR - ROLLBACK ACTION SUCCESS - " . $exc->getTraceAsString();
     }
     die;
 }