<repo_name>nghiavtn12/LearnSomethingEveryday<file_sep>/README.md
# LearnSomethingEveryday
Learn More Do More Play More
<file_sep>/login-getlistbyjs/common.js
// calendar
$(function () {
  var $date = $('.calendar');
  var options = {
    show: function (e) {},
    hide: function (e) {},
    pick: function (e) {},
    format: 'dd/mm/yyyy',
    autoHide: true,
    zIndex: 9999
  };

  $date.on({
    'show.datepicker': function (e) {},
    'hide.datepicker': function (e) {},
    'pick.datepicker': function (e) {}
  }).datepicker(options);


})<file_sep>/ReactJS/react02h/src/Component/convertST.js
const convertDate = (date) => {
  var dateStd = date
    .split(" ")[0]
    .split("-")
    .reverse()
    .join("/");
  return dateStd;
}

const converTransferType = (type) => {
  var typeVi = (type === 'move_sale' ? 'Chuyển bán' : 'Chuyển liên khu vực');
  return typeVi;
}

export {
  convertDate,
  converTransferType,
}
<file_sep>/login-getlistbyjs/getlist.js
$(function () {
  if (
    localStorage.getItem("token") === null ||
    localStorage.getItem("token") === "undefined"
  ) {
    alert("Vui lòng đăng nhập");
    window.location.href = "index.html";
  } else {
    $("#username").text(localStorage.getItem("username"));
    getDataFillter();
    $.ajax({
      url: "http://103.68.68.142:8000/wfs/co/filter",
      headers: {
        Authorization: localStorage.getItem("token"),
        "Content-Type": "application/x-www-form-urlencoded"
      },
      dataType: "json",
      data: {},
      success: function (result) {
        var a = result.data.seller;
        var b = '<option value = "" >Tất cả</option> ';
        a.forEach(element => {
          b += "<option value='" + element.id + "'>";
          b += element.name;
          b += "</option>";
        });

        $("#seller").html(b);
      }
    });
    $.ajax({
      url: "http://192.168.3.11:8000/wfs/ir/get-filters?location_base=1&location_transfer=1",
      headers: {
        Authorization: localStorage.getItem("token"),
        "Content-Type": "application/x-www-form-urlencoded"
      },
      dataType: "json",
      data: {},
      success: function (result) {
        var a = result.location;
        var b = '<option value = " ">Tất cả</option> ';
        a.forEach(element => {
          b += "<option value='" + element.id + "'>";
          b += element.name;
          b += "</option>";
        });
        $(".warehouse").html(b);
      }
    });
  }
});

function getLogout() {
  localStorage.removeItem("token");
  localStorage.removeItem("username");
  window.location.href = "index.html";
}

function convertState(item) {
  var state = " ";
  switch (item) {
    case "draft":
      state = "Chờ luân chuyển";
      break;
    case "tr_picking":
      state = "Lấy hàng";
      break;
    case "tr_picked":
      state = "Đang luân chuyển";
      break;
    case "done":
      state = "Xong";
      break;
    case "cancel":
      state = "Hủy";
      break;
  }
  return state;
}

function convertDate(date) {
  var x = date
    .split(" ")[0]
    .split("-")
    .reverse()
    .join("-");
  return x;
}

function checkdate() {
  console.log($("#fromdate").val());
}

function checkFillter() {
  var a = {
    "code": $("#code").val(),
    "seller": $("#seller").val(),
    "from_date": $("#fromdate").val().split("/").reverse().join("-"),
    "to_date": $("#todate").val().split("/").reverse().join("-"),
    "location": $("#warehouse").val(),
    "location_dest": $("#warehouse_dest").val(),
    "state": $("#state").val(),
    "transfer_type": $("#type").val(),
    "limit": $("#limit").val()
  };
  for (x in a) {
    if (a[x] == null || a[x] == undefined || a[x] == " " || a[x] == "") {
      delete a[x]
    }
  }
  console.log(a)
  getDataFillter(a)
}

function changePage(page) {
  console.log($(page).attr("data-id"))
  var cp = {"page": $(page).attr("data-id")}
  getDataFillter(cp)
}

function getDataFillter(data) {
  $.ajax({
    url: "http://192.168.3.11:8000/wfs/transfer/list?",
    headers: {
      Authorization: localStorage.getItem("token"),
      "Content-Type": "application/x-www-form-urlencoded"
    },
    dataType: "json",
    data: data,
    success: function (result) {
      var a = result.data.records;
      var b = " ";
      var TotalPage =  Math.ceil(result.data.total / $("#limit").val());
      var liPage = "";
      for(i=1;i<TotalPage+1;i++)
      {
        liPage+="<li onclick='changePage(this)' data-id=" + i +"><a>"+i+"</a></li>"
      }
      $("#tbpage").html(liPage)
      a.forEach(element => {
        b += "<tr><td>";
        b += element.code;
        b += "</td><td>";
        b += element.seller;
        b += "</td><td>";
        b += convertDate(element.create_date);
        b += "</td><td>";
        b += element.warehouse;
        b += "</td><td>";
        b += element.warehouse_dest;
        b += "</td><td>";
        b +=
          element.transfer_type === "move_sale" ?
          "Chuyển bán" :
          "Chuyển liên khu vực";
        b += "</td><td>";
        b += element.product_qty;
        b += "</td><td>";
        b += convertState(element.state);
        b += "</td></tr>";
      });
      $("#trth").html(b);
    
    },
    error: function (request, status, error) {
      alert("Có lỗi trong quá trình thực thi. Vui lòng đăng nhập lại");
    }
  });
}
<file_sep>/JS/popupAuto/popup.js
isLoaded = () => {
  setTimeout(()=>{$("#popup").css("display","none");
  $("#main").css("display","block");},3000);
} 

isLoaded();<file_sep>/ReactJS/react02h/src/Component/LoginJS.js
import React, { Component } from 'react';
import { Redirect } from 'react-router-dom';
import axios from 'axios';
import './LoginJS.scss'

class Login extends Component {
  constructor(props) {
    super(props);
    this.state = {
      isLogin: false,
    }
  }

  onBtnClick = () => {
    const email = document.getElementById('username').value;
    const password = document.getElementById('password').value;
    const formData = new FormData();
      formData.set('email',email);
      formData.set('password',<PASSWORD>);
      axios.post('https://master-wfs.agilsun.com/wfs/auth/token', formData)
    .then((res) => {
      console.log(res.data);
      localStorage.setItem('token',res.data.token);
      this.setState({isLogin: true})
    })
    .catch(function (error) {
      this.setState({
        error: true
      });
      console.log(error);
    })
  }

  handleKeyPress = (e = '') => {
    if (e.key === 'Enter') {
      this.onBtnClick();
    }
  }

  render() {
    if(this.state.isLogin) {
      return <Redirect to="/list" />
    }
    return (
      <div className="LoginForm">
        <input type="text" name="username" id="username" placeholder="Username" onKeyPress={this.handleKeyPress}/><br/>
        <input type="password" name="password" id="password" placeholder="<PASSWORD>" onKeyPress={this.handleKeyPress}/><br/>
        <button type="button" onClick={this.onBtnClick}>Login</button>
      </div>
   )
  }
}

export default Login
<file_sep>/ReactJS/movie-center-web/src/components/menu/menu.js
import React, { Component } from 'react';
import logo from '../../asset/img/logo.jpg';
import './menu.css';

class Menu extends Component {
  render() {
    return (
      <div className='top-menu'>
          <img src = {logo} alt="logo"/>
        <input type="text" placeholder = "Tìm kiếm"/>
        <a src="#" data-toggle="modal" data-target="#myModal">Đăng nhập/đăng ký</a>
        <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
        <div id="myModal" class="modal fade" role="dialog">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
              <p>Some text in the modal.</p>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
          </div>

        </div>
      </div>   
      </div>
    )
  }
}

export default Menu;<file_sep>/JS/cal/cal.js
var valu = '',result = '';
document.getElementById('screenCal').value = 0;

resetValue = () => {
  this.valu = '';
  document.getElementById('screenCal').value = '0';
}

getValueInput = (v) => {
  valu += v.value;
  document.getElementById('screenCal').value = valu;
}

getCalculate = (u) => {
  var a = document.getElementById('screenCal').value;
  a += " " + u.value + " " ;
  valu = a;
  document.getElementById('screenCal').value = a;
}

getCalculating = (arr,i) => {
  var res;
  switch (cal[i]) {
    case "+":
      res = parseFloat(cal[i-1]) + parseFloat(cal[i+1]);
    break;
    case "-":
      res = parseFloat(cal[i-1]) - parseFloat(cal[i+1]);
    break;
    case "*":
      res = parseFloat(cal[i-1]) * parseFloat(cal[i+1]);
    break;
    default:
    if ( parseFloat(cal[i+1]) === 0 )
    {
      return alert("Không thể chia cho 0");
    }
      res = parseFloat(cal[i-1]) / parseFloat(cal[i+1]);
  }
  console.log(typeof(res));
  return res;
}

excCal = () => {
  var res,cal = document.getElementById('screenCal').value;
  console.log(cal);
  if(cal.length < 3) {
    return;
  }
  cal = cal.split(' ');
  console.log(cal,cal.length);
  for (var i = 0; i < cal.length; i++) {
    if(parseFloat(cal[i]) == NaN)
    {
      console.log('dzo');
      res += getCalculating(cal,i);
    }
  }

  document.getElementById('screenCal').value = res;
}
<file_sep>/JS/compare/compare.js
const a = [],b=[];
let i = 0;
let j = 0;
while(i < 10) {
 a[i] = Math.floor((Math.random() * 100) + 1);
 i++;
};
while(j < 10) {
 b[j] = Math.floor((Math.random() * 100) + 1);
 j++;
};

compare = (a,b) => {
  console.log(a,b);
  let res = [0,0];
  for (var x = 0; x<10 ; x++) {
    console.log(res[0],res[1]);
    if(a[x]>b[x]) {
      res[0]++;
    }
    else if (a[x]<b[x])
    {
      res[1]++;
    }
  }
  console.log(res);
  return res;
};

compare(a,b);