Showing posts with label java script. Show all posts
Showing posts with label java script. Show all posts

July 16, 2015

online sales entering sheet for organisation having multiple branch

Online Sales Entering spreadsheet using google script

As our new software bee bee is down for last few months I T head +bithesh soubhagya assign me a task to create a parallel online sales entering application which helps users to inform their sales to regional office, thus we can debug our bee bee software by informing head office the actual sales. The project was great success, the data was informed head office daily and they correct it on bee bee software.


Created an online sales entering spreadsheet using google script code. The sheet changes daily so that end users can add/enter their daily sales and other details for that day, . The google script in background will automatically send reports daily as email  both in html and pdf formats, The sheet keeps a backup every month in google drive, Once backup is created the sheet will clear the whole data entered in the spreadsheet.





Link to google spreadsheet

Back up


These backup are created using google script code


Algorithm




1. Start

2. Declare variable columns, day, weekends, month, year

3. get todays date from google server (format dd/mm/yyyy)

4. get day from todaysDate

5. check if sunday then skip

6. else hide entire sheet

7. show sheet (day) // say 1,2,3...etc

8. Stop

Source code


function algorithm(){

      var sheetToPdf = SpreadsheetApp.openById("url to sheet ");
      var columnRanges = ["A:A","B:N","O:AA","AB:AN","AO:BA","BB:BN","BO:CA","CB:CN","CO:DA","DB:DN","DO:EA","EB:EN","EO:FA","FB:FN","FO:GA","GB:GN","GO:HA","HB:HN","HO:IA","IB:IN","IO:JA","JB:JN","JO:KA","KB:KN","KO:LA","LB:LN","LO:MA","MB:MN","MO:NA","NB:NN","NO:OA","OB:ON"];

      var todayDate = new Date();
      var day = todayDate.getDate();
      var actualDay = day - 1;
      var saleDay = day;
      var colToHide = day -1;
      var colToHide2 = day -2;
      var colToShow = day;
      var actualMonth = todayDate.getMonth() + 1;
   
      var rangeHide = sheetToPdf.getRange(columnRanges[colToHide]);
      var rangeToShow = sheetToPdf.getRange(columnRanges[colToShow]);
   
   
      sheetToPdf.unhideColumn(rangeToShow);
      sheetToPdf.hideColumn(rangeHide);
   
      if(day > 3){
        var rangeHide2 = sheetToPdf.getRange(columnRanges[colToHide2]);
        sheetToPdf.hideColumn(rangeHide2);
        Logger.log(" Previous date script running issue solved ");
      }
   
      Logger.log("Date : "+todayDate.getDate());
      Logger.log("col to show  : "+colToShow )
      Logger.log("range to show  : "+columnRanges[colToShow] )
   
      Logger.log("Date : "+todayDate.getDate());
      Logger.log("col to hide  : "+colToHide )
      Logger.log("range to hide  : "+columnRanges[colToHide] )
   
      Logger.log(todayDate.getDay());
      Logger.log(todayDate.getDate());
      Logger.log(todayDate.getMonth());
      Logger.log(todayDate.getYear());
   
      //if day is 1
      if(todayDate.getDate()==1){
        //Logger.log(' Today is first day ');
        //rangeToShow = sheetToPdf.getRange(columnRanges[colToShow]);
        sheetToPdf.unhideColumn(sheetToPdf.getRange(columnRanges[0]));
        sheetToPdf.unhideColumn(sheetToPdf.getRange(columnRanges[1]));
        sheetToPdf.hideColumn(sheetToPdf.getRange(columnRanges[28]));//28,29,30,31
        sheetToPdf.hideColumn(sheetToPdf.getRange(columnRanges[29]));
        sheetToPdf.hideColumn(sheetToPdf.getRange(columnRanges[30]));
        sheetToPdf.hideColumn(sheetToPdf.getRange(columnRanges[31]));
      }
   
     // sheetToPdf.copy("SALES_ON_"+todayDate.getYear()+"_"+actualMonth+"_"+saleDay);
      sheetToPdf.rename("SALES_ON_"+todayDate.getYear()+"_"+actualMonth+"_"+saleDay);
}



Email templates










Thanks for accounts manager +deepajayaprakash payyanakkal  for her support in creating this wonderful application for  regional office kozhikode...

Thanks to +Consumerfed IT Division  for assigning this work.



http://javabelazy.blogspot.in/

April 21, 2015

To call spring controller from ajax jquery in java spring

Ajax Jquery call to java spring controller


Description : The program will helps you to call java spring controller  from ajax jquery. To know spring configuration please refer this link. The link shows a  Hello world Model View Controller java spring example.

index.jsp


jquery api needed

<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="jqueryApps.js"></script>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

These jquery api should be paste in your WEB-INF folder.


jqueryApps.js


function callJavaSpringController(){
var jqueryData = 'java spring mvc';
alert(senderEmail);

 $.ajax({
       type: "GET",
       url: "callcontroller.html",
       data: { message : jqueryData }
     }).done(function( msg ) {
       alert( "Data Saved: " + msg );
     });
}


JavaSpringSampleController.java


/**
JavaSpringSampleController  class
*/
package net.cfed.oms.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.cfed.oms.model.SendMailModel;
import net.cfed.oms.service.EmployeeService;
import net.cfed.oms.serviceImpl.EmployeeServiceImpl;

import org.apache.catalina.connector.Request;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author free source codes
 *
 */
@Controller
public class JavaSpringSampleController {

@RequestMapping("/callcontroller")
public ModelAndView helloWorld(HttpServletRequest request, HttpServletResponse response) {

String message = "Welcome  to";
                message = message + request.getParameter("message");
System.out.println(message);
return new ModelAndView("index", "message", message);
}
}


Here is a sample for ajax jquery call to servlet , click on the link

http://javabelazy.blogspot.in/

June 05, 2014

Multiple Marker on Google Map

Google Map to view multiple marker example


Description :How to add google map to your java application: To view multiple markers on same google map. while clicking on the marker, the details of that branch will be shown in a separate div. The website can be useful for large business firms to show their branches. The first 3 line of code is of java spring ( No need of it for google map). Here we use simple google map marker instead of complex one.

the css for the html page is shown below (javasourcecode.css)

You can see a combo box on the google map, currently that feature won t work, working code for that will be updated shortly. The location details can be added through json object, using jquery and ajax will smooth-en your code.

Java Google Map multiple marker apps
Google map with multiple marker

jquery google map maker in java web application


<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title> Who will be the winner of football world cup 2014 </title>
      <link href="css/javasourcecode.css" rel="stylesheet" type="text/css" />

  <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
  <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.1.min.js"></script>
  <script type="text/javascript" src="js/units.js"></script>
<script>


function initialize() {
  var mapOptions = {
    zoom: 11,
    center: new google.maps.LatLng(1.319154,5.918564)
  }
  var map = new google.maps.Map(document.getElementById('map-canvas'),
                                mapOptions);

  setMarkers(map, beaches);
}
var infowindow = new google.maps.InfoWindow({
    maxWidth: 160
  });
// get javascript object here pass it to beach
//var triveniUnits = getUnits();
//alert(' Winner : '+triveniUnits.length);
var beaches = [
  ['Brazil', 1.253069,5.78281,'images/worldcup.png',4],
  ['Argentina', 1.291158,75.74415,'images/worldcup.png',5],
  ['Belgium', 1.273474,5.774783,'images/worldcup.png',3],
  ['Spain', 1.294241,5.815177,'images/worldcup.png',2],
  ['England ', 1.305014,5.876385,'images/worldcup.png',1]
];

function setMarkers(map, locations) {
  var markers = new Array();
  var marker;
  for (var i = 0; i < locations.length; i++) {
    var beach = locations[i];
    var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
        marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
title: beach[0],
        //zIndex: beach[3]
    });
        markers.push(marker);
     
google.maps.event.addListener(marker, 'click', (function(marker, i) {
            return function() {
            //var infoWinwhtml = '<div id="infowindow" style="width:320px; height:200px;" ><H4>'+locations[i][0]+'</H4></br><p><img src="'+locations[i][3]+'" alt="World cup football 2014"></p></div>';
             //infowindow.setContent(locations[i][0]);
             var infoWinwhtml = '<div id="infowindow"><H4>'+locations[i][0]+'</H4></div>';
             infowindow.setContent(infoWinwhtml);
             var infoHtml = '<div  class="triveniInfo"><H4>'+locations[i][0]+'</H4></br><p><img src="'+locations[i][3]+'" alt="Triveni Image"><h6> Distance : 200km </h6></p></div>';
              marker.setAnimation(google.maps.Animation.BOUNCE);
              infowindow.open(map, marker);
              var sidediv = document.getElementById('content-window');
              sidediv.innerHTML = infoHtml;
            }
          })(marker, i));
  }
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
  <div id="headerId" class="header">
<div id="logo" class="logos"><img src="images/worldcupLogo.jpg" alt="cfed Logo"></div>
<h1> How to integrate Google map features in java spring source code</h1>
<div id="menuTabsId" class="menuTabs"><a href="worldcupEvents.html"> event</a><a href="worldcupmap.html"> view map </a></div>

</div>
  <div id="panel">
  <b>Select: </b>
    <select id="worldcup football" onchange="calcRoute();">
      <option value="worldcup">Belgium</option>
      <option value="st louis, mo">Germany</option>
      <option value="joplin, mo">Spain</option>
      <option value="oklahoma city, ok">England</option>
      <option value="amarillo, tx">Brazil</option>
</select>
  </div>
    <div id="map-canvas" style="width:80%; height:80%; float:left"></div>
    <div id="content-window" style="width:20%; height:80%; float:left"></div>

  <div id="footerId" class="footer">
http://nikzblog/</div>
  </body>
</html>

javasourcecode.css


/*External Cascading style sheet for the above html code*/


/* Google map css */

html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
}

#panel {
        position: absolute;
        top: 120px;
        left: 20%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
}


/* Developed by shimjith kumar */
+Shimjith Kumar 

.logos{
    float: left;
}

.header{
    height:100px; 
    background-color: #EEEEEE;
}

.header h1{
    margin-bottom: 0;
    text-align: center;
}

.footer{
      background-color: #FFA500;
    height: 2%;
    clear: both;
    text-align: center;
}


.menuTabs{
    position:relative;
    top:0px;
    width:80px;
    height:20px;
    float:right;  
}


/*  external css design in java application */
.triveniInfo h4{
    text-align: center;
}
.triveniInfo p{
    text-align: center;
}

/* google map info window css design */
#infowindow h4{
    text-align: center;
}
#infowindow p{
    text-align: center;
}

Thanks for reading the code, Please provide your feedback through comments

author : +Shimjith


http://javabelazy.blogspot.in/

Facebook comments