Showing posts with label client project. Show all posts
Showing posts with label client project. Show all posts

July 21, 2022

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

Problem

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

This issue happens due to version mismatch between swaggerfox and spring boot framework.


Solution




/**
 * @author aswathi sajeevan
 *
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build();
}
}


Pom.xml



<!--  swagger  -->

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>


Spring boot version



<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>



Swagger url


http://localhost:9090/swagger-ui/index.html




July 14, 2022

How to create a textile billing and inventory system using google spreadsheet and google app sheet

Hi 


We have created a textile inventory and billing system for Nijeeshma tailoring athanikkal kozhikode using google app sheet and google spreadsheet. Any one can develop this application with a day or two. No coding required


Please visit our git url


Video

May 14, 2022

Stock trading application source code | java code | how to get stock value of share through java code | yahoo finance

/**
 * 
 */
package com.proximotech.nyseticker.service;

import java.io.IOException;
import java.math.BigDecimal;

import org.springframework.stereotype.Service;

import com.proximotech.nyseticker.model.StockWrapper;

/**
 * @author apple
 *
 */
@Service
public class StockService {

public StockWrapper findStock(final String ticker) {
try {
return new StockWrapper(yahoofinance.YahooFinance.get(ticker));
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

public BigDecimal findPrice(final StockWrapper stock) throws IOException {
return stock.getStock().getQuote(true).getPrice();
}
}


Download application from git

https://javabelazy.blogspot.com/p/office.html

March 28, 2020

Tic Tac Toe Game developed in java full code play with computer


Main,java



/**
 *
 */
package com.cfed.tiktactoe;

/**
 * @author konzernites
 * @since 1.0
 *
 */
public class Main {

/**
* @param args
* @throws IllegalAccessException
*/
public static void main(String[] args) throws IllegalAccessException {

Matrix<Character> matrix = new Matrix<>(3, 3);

System.out.println(" **** INSTRUCTIONS **** ");
System.out.println(" User has to enter row and column ");
System.out.println(" Postion starts from (0,0) to (2,2) ");

TikTocToe tikTokToe = new TikTocToe(matrix);
tikTokToe.startGame();

System.out.println(" ***** GAME OVER ***** ");
System.out.println(" Developed by consumerfed I T Section ");


}

}

TicTacToe.java

/**
 * Tic Tac Toe 
 * The main class
 * 
 */
package com.cfed.tiktactoe;

import java.util.Scanner;

/**
 * @author konzernites
 * @param <E>
 * @since 1.0
 *
 */
public class TikTocToe {

public static final int MATRIX_SIZE = 3;
public static final int MAX_MOVE = 9;
protected static int moveCount = 1;
public static final char USER_MOVE = 'X';
public static final char COMP_MOVE = 'O';
private ComputerMove computerMove = null;
private Matrix<Character> matrix = null;
public Character winner = null;

public TikTocToe() {
intialize();
}

public TikTocToe(Matrix matrix) {
this.matrix = matrix;
intialize();
}

private void intialize() {
computerMove = new ComputerMove(matrix);
}

private boolean checkWinner() {
if (findWinner() == USER_MOVE) {
return true;
} else if (findWinner() == COMP_MOVE) {
return true;
}
return false;
}

@SuppressWarnings("unused")
private char findWinner() {
Object[][] newMatrix = matrix.getMatrix();
if (moveCount < 5 || moveCount > MAX_MOVE) {
return Matrix.EMPTY_DATA;
} else if (null!= matrix.getValue(0, 0) && (TikTocToe.USER_MOVE == matrix.getValue(0, 0) || TikTocToe.COMP_MOVE == matrix.getValue(0, 0))) {
winner = (Character)matrix.getValue(0, 0);
if ((null!= matrix.getValue(0, 1) && winner.equals(newMatrix[0][1])) && (null!= matrix.getValue(0, 2) && winner.equals(newMatrix[0][2]))) {
return winner;
} else if ((null!= matrix.getValue(0, 1) && winner.equals(newMatrix[1][0])) && (null!= matrix.getValue(2, 0) && winner.equals(newMatrix[2][0]))) {
return winner;
} else if ((null!= matrix.getValue(1, 1) && winner.equals(newMatrix[1][1])) && ( null!= matrix.getValue(2, 2) && winner.equals(newMatrix[2][2]))) {
return winner;
}
} else if (null!= matrix.getValue(1, 1) && (TikTocToe.USER_MOVE == matrix.getValue(1, 1) || TikTocToe.COMP_MOVE == matrix.getValue(1, 1))) {
winner = (Character)newMatrix[1][1];
if ((null!= matrix.getValue(1, 0) && winner.equals(newMatrix[1][0])) && (null!= matrix.getValue(1, 2) && winner.equals(newMatrix[1][2]))) {
return winner;
} else if ((null!= matrix.getValue(0, 0) && winner.equals(newMatrix[0][0])) && (null!= matrix.getValue(1, 2) && winner.equals(newMatrix[1][2]))) {
return winner;
} else if ((null!= matrix.getValue(0, 2) && winner.equals(newMatrix[0][2])) && (null!= matrix.getValue(2, 0) && winner.equals(newMatrix[2][0]))) {
return winner;
}
} else if (null!= matrix.getValue(2, 2) && (TikTocToe.USER_MOVE == matrix.getValue(2, 2) || TikTocToe.COMP_MOVE == matrix.getValue(2, 2))) {
winner = (Character)newMatrix[2][2];
if ((null!= matrix.getValue(2, 0) && winner.equals(newMatrix[2][0])) && (null!= matrix.getValue(2, 1) && winner.equals(newMatrix[2][1]))) {
return winner;
} else if ((null!= matrix.getValue(0, 2) && winner.equals(newMatrix[0][2])) && (null!= matrix.getValue(1, 2) && winner.equals(newMatrix[1][2]))) {
return winner;
}
}
return Matrix.EMPTY_DATA;
}


/**
* @param args
* @throws IllegalAccessException 
*/
public static void main(String[] args) throws IllegalAccessException {
System.out.println(" **** INSTRUCTION **** ");
System.out.println(" User has to enter row and column ");
System.out.println(" Postion starts from (0,0) to (2,2) ");
TikTocToe t = new TikTocToe();
t.startGame();
System.out.println(" **** GAME OVER ***** ");
System.out.println(" Developed by consumerfed I T section kozhikode ");

}
public void startGame() throws IllegalAccessException {
int rowMoved = 0;
int colMoved = 0;
Scanner scanner = new Scanner(System.in);
while (moveCount < MAX_MOVE) {

if (moveCount % 2 == 0) {

matrix = computerMove.computerMove(rowMoved, colMoved);
System.out.println("** COMPUTER MOVE **");
try {
Thread.sleep(3121);
} catch (InterruptedException e) {
e.printStackTrace();
}

} else {

System.out.println("** YOUR MOVE **");
System.out.println(" Enter the row (values from 0 to 2): ");
int row = scanner.nextInt();
validate(row);
System.out.println(" Enter the col (values from 0 to 2): ");
int col = scanner.nextInt();
validate(col);
matrix.add(row, col, USER_MOVE);
rowMoved = row;
colMoved = col;
}
matrix.print();
boolean isWon = checkWinner();
if (isWon) {
System.out.println("*** Congratulation *** ");
System.out.println(winner + " is the winner ");
break;
}
moveCount++;
}
}


Dimensions.java


/**
 * 
 */
package com.cfed.tiktactoe;

/**
 * @author konzernites
 * @since 1.0
 *
 */
public class Dimensions {
private static final long serialVersionUID = 8683452581122892188L;

private int row = 0;
private int column = 0;

public int getRow() {
return row;
}

public void setRow(int row) {
this.row = row;
}

public int getColumn() {
return column;
}

public void setColumn(int column) {
this.column = column;
}

}





private void validate(int value) {
if (value < 0 || value > 2) {
throw new IllegalArgumentException(" This value is not permitted");
}
}




}


Matrix.java


/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * Copyright (c) 1997-2017 Javabelazy and/or its affiliates. All rights reserved.
 *
 */
package com.cfed.tiktactoe;

import java.util.NoSuchElementException;

/**
 * @author konzernites
 * @since 1.0
 *
 */
public class Matrix<E> extends AbstractMatrix<E> {

@SuppressWarnings("unused")
private static final long serialVersionUID = 8683452581122892189L;

private final int MAX_COLUMN;
private final int MAX_ROW;
private final int MAX_CAPACITY;
protected static final char EMPTY_DATA = '\0';
private static boolean isEditable = false;

private E elementData[][];
private int capacity = 0;

public Matrix(int row, int column) {
this.MAX_COLUMN = column;
this.MAX_ROW = row;
this.MAX_CAPACITY = MAX_ROW * MAX_COLUMN;
intialize();
}

@SuppressWarnings("unchecked")
private void intialize() {
this.elementData = (E[][]) new Object[MAX_ROW][MAX_COLUMN];
}

public Matrix() {
this(2, 2);
}

public void add(int row, int column, E value) throws IllegalAccessException {
if (row > MAX_ROW || column > MAX_COLUMN)
throw new IllegalAccessException("Illegal capacity");
else if (isFull() || isElementExist(row, column))
throw new IllegalAccessException("Value already exist");
else {
capacity++;
this.elementData[row][column] = value;
}
}

public E[][] getMatrix() {
if (isEmpty())
throw new NoSuchElementException("Matrix is empty");
else
return this.elementData;
}
public E getValue(int row, int column) {
if (isEmpty())
return null;
else if(isElementExist(row, column)) 
return this.elementData[row][column];
else
return null;
}

public void remove(int row, int column) {
if (isEmpty())
throw new NoSuchElementException("Cannot remove value from an empty matrix");
else {
this.elementData[row][column] = null;
capacity--;
}
}

public void removeAll() {
if (isEmpty())
throw new NoSuchElementException("Cannot remove value from an empty matrix");
else {
// TODO remove all elements from matrix
}
}

public void print() {
if (isEmpty())
throw new NoSuchElementException("Cannot display an empty matrix");
else {
for (int r = 0; r < MAX_ROW; r++) {
for (int c = 0; c < MAX_COLUMN; c++) {
if (null == elementData[r][c])
System.out.print("  | ");
else
System.out.print(elementData[r][c] + " | ");
}
System.out.println("");
}
}
}

public Dimensions dimension() {
Dimensions dimensions = new Dimensions();
dimensions.setRow(MAX_ROW);
dimensions.setColumn(MAX_COLUMN);
return dimensions;
}

private boolean isEmpty() {
if (capacity == 0)
return true;
else
return false;
}

public boolean isElementExist(int row, int column) {
if (isEmpty())
return false;
else if (null != elementData[row][column])
return true;
else
return false;
}

private boolean isFull() {
if (capacity >= MAX_CAPACITY)
return true;
else
return false;
}

public int size() {
return capacity;
}

}

ComputerMove.java


/**
 * Computer Moves for user move in tik toc toe
 * Developed by consumerfed kozhikode I T section
 * Version 1.0 
 * consfedkozhikode@gmail.com
 * 
 */
package com.cfed.tiktactoe;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;

/**
 * @author konzernites
 * @since 1.0
 *
 */
public class ComputerMove {

private int MATRIX_SIZE = 3;
private static final char EMPTY_DATA = ' ';
private Map<String, Integer> priorityPosition = null;
private static final String techIssue = "EXPERIENCING SOME TECHNICAL ISSUE";
private Matrix<Character> matrix = null;


public ComputerMove(Matrix<Character> matrix) {
this.matrix = matrix;
}

public Matrix<Character> computerMove(int rowMoved, int colMoved) throws IllegalAccessException {

if (TikTocToe.moveCount <= 2) {
matrix = generateFirstCompMove();
} else {
matrix = generateCompMove(rowMoved, colMoved);
}
return matrix;
}

private Matrix<Character> generateCompMove(int rowMoved, int colMoved) throws IllegalAccessException {
priorityPosition = new HashMap<>();
boolean isInserted = false;
for (int row = 0; row < MATRIX_SIZE; row++) {
for (int col = 0; col < MATRIX_SIZE; col++) {

if (!matrix.isElementExist(row, col)) {
isInserted = findPriority(row, col);
if (isInserted)
return matrix;
}

}
}

if (!isInserted) {
String key = maxUsingCollectionsMaxAndLambda(priorityPosition);
int r = Integer.parseInt(key.substring(0, 1));
int c = Integer.parseInt(key.substring(1, 2));

if (!matrix.isElementExist(r, c))
matrix.add(r, c, TikTocToe.COMP_MOVE);

}
return matrix;
}

private Matrix<Character> generateFirstCompMove() throws IllegalAccessException {
int row = 0;
int col = 0;
if (matrix.getValue(1, 1).equals(EMPTY_DATA)) {
matrix.add(1, 1, TikTocToe.COMP_MOVE);
} else {
Random r = new Random();
row = r.nextInt(3);
col = r.nextInt(3);
col = (row == 1 && col == 1) ? col + 1 : col;
matrix.add(row, col, TikTocToe.COMP_MOVE);
}
return matrix;
}

private boolean findPriority(int row, int col) throws IllegalAccessException {
boolean isInserted = true;
if (diagonalOne(0, 0)) {
isInserted = true;
} else if (diagonalTwo(0, MATRIX_SIZE - 1)) {
isInserted = true;
} else if (rowCheck(row, col)) {
matrix.add(row, col, TikTocToe.COMP_MOVE);
} else if (colCheck(row, col)) {
matrix.add(row, col, TikTocToe.COMP_MOVE);
} else {
isInserted = false;
}
return isInserted;
}

private boolean colCheck(int row, int col) {
boolean isPrior = false;
boolean isSafe = false;
int loopCount = 1;
int value = 0;

int r = row;
int c = col;
while (loopCount < MATRIX_SIZE) {
if (r + 1 == MATRIX_SIZE) {
r = 0;
} else {
r++;
}
if (null != matrix.getValue(r, c) && TikTocToe.COMP_MOVE == matrix.getValue(r, c)) {
isSafe = true;
break;
} else if (null != matrix.getValue(r, c) && TikTocToe.USER_MOVE == matrix.getValue(r, c)) {
value++;
}
loopCount++;
}

if (!isSafe) {
String key = String.valueOf(row + "" + col);
priorityPosition.put(key, value);
}

if (value == 2 && !isSafe) {
isPrior = true;
}
return isPrior;
}

private boolean rowCheck(int row, int col) {
boolean isPrior = false;
boolean isSafe = false;
int loopCount = 1;
int value = 0;

int r = row;
int c = col;
while (loopCount < MATRIX_SIZE) {

c = (c + 1 == MATRIX_SIZE) ? 0 : c + 1;

if (null != matrix.getValue(r, c) && TikTocToe.COMP_MOVE == matrix.getValue(r, c)) {
isSafe = true;
break;
} else if (null != matrix.getValue(r, c) && TikTocToe.USER_MOVE == matrix.getValue(r, c)) {
value++;
}
loopCount++;
}

if (!isSafe) {
String key = String.valueOf(row + "" + col);
priorityPosition.put(key, value);
}

if (value == 2 && !isSafe) {
isPrior = true;
}
return isPrior;
}

private boolean diagonalTwo(int row, int col) throws IllegalAccessException {
boolean isPrior = false;
boolean isSafe = false;
int loopCount = 1;
int value = 0;
int r = 0;
int c = 0;
while (loopCount <= MATRIX_SIZE) {
if (null != matrix.getValue(row, col) && TikTocToe.COMP_MOVE == matrix.getValue(row, col)) {
isSafe = true;
break;
} else if (null != matrix.getValue(row, col) && TikTocToe.USER_MOVE == matrix.getValue(row, col)) {
value++;
}
if (!matrix.isElementExist(row, col)) {
r = row;
c = col;
}
row++;
col--;
loopCount++;
}

if (!isSafe) {
String key = String.valueOf(r + "" + c);
priorityPosition.put(key, value);
}

if (value == 2 && !isSafe) {
matrix.add(r, c, TikTocToe.COMP_MOVE);
isPrior = true;
}
return isPrior;
}

private boolean diagonalOne(int row, int col) throws IllegalAccessException {
boolean isPrior = false;
boolean isSafe = false;
int loopCount = 1;
int value = 0;
int r = 0;
int c = 0;
while (loopCount <= MATRIX_SIZE) {
if (null != matrix.getValue(row, col) && TikTocToe.COMP_MOVE == matrix.getValue(row, col)) {
isSafe = true;
break;
} else if (null != matrix.getValue(row, col) && TikTocToe.USER_MOVE == matrix.getValue(row, col)) {
value++;
}

if (!matrix.isElementExist(row, col)) {
r = row;
c = col;
}
row++;
col++;
loopCount++;
}

if (!isSafe) {
String key = String.valueOf(r + "" + c);
priorityPosition.put(key, value);
}

if (value == 2 && !isSafe) {
matrix.add(r, c, TikTocToe.COMP_MOVE);
isPrior = true;
}
return isPrior;
}

private <K, V extends Comparable<V>> K maxUsingCollectionsMaxAndLambda(Map<K, V> map) {
Entry<K, V> maxEntry = Collections.max(map.entrySet(),
(Entry<K, V> e1, Entry<K, V> e2) -> e1.getValue().compareTo(e2.getValue()));
return maxEntry.getKey();
}

}


Output


 **** INSTRUCTIONS ****
 User has to enter row and column
 Postion starts from (0,0) to (2,2)
** YOUR MOVE **
 Enter the row (values from 0 to 2):
1
 Enter the col (values from 0 to 2):
1
  |   |   |
  | X |   |
  |   |   |
** COMPUTER MOVE **
  |   | O |
  | X |   |
  |   |   |
** YOUR MOVE **
 Enter the row (values from 0 to 2):
2
 Enter the col (values from 0 to 2):
2
  |   | O |
  | X |   |
  |   | X |
** COMPUTER MOVE **
O |   | O |
  | X |   |
  |   | X |
** YOUR MOVE **
 Enter the row (values from 0 to 2):
1
 Enter the col (values from 0 to 2):
2
O |   | O |
  | X | X |
  |   | X |
** COMPUTER MOVE **
O |   | O |
O | X | X |
  |   | X |
** YOUR MOVE **
 Enter the row (values from 0 to 2):
2
 Enter the col (values from 0 to 2):
1
O |   | O |
O | X | X |
  | X | X |
** COMPUTER MOVE **
O | O | O |
O | X | X |
  | X | X |
*** Congratulation ***
O is the winner
 ***** GAME OVER *****
 Developed by consumerfed I T section kozhikode
O | O | O |
O | X | X |
  | X | X | 

October 22, 2017

Real Time Currency Converter in java - Webservice

Currency Converter API (xe.com)


Description


some time instead of keeping currency rate converter static data in your local database is not at all feasible for your project. Yahoo is providing a free web sevices for currency rate converter similar to google xe.com. The below code will return the currency converting ratio

import java.io.IOException;

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;

/**
 *
 */

/**
 * @author currency conversion
 *
 */
public class DCSCurrencyConvertor {



/**
* @param args
* @throws IOException
* @throws HttpException
*/
public static void main(String[] args) {
// TODO Auto-generated method stub;

DCSCurrencyConvertor convertor = new DCSCurrencyConvertor();
try {
String rate = convertor.convert("USD","AED");
System.out.println("USD to AED :"+rate);
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}





}

private String convert(String currencyFrom, String currencyTo) throws HttpException, IOException {
String currentRate = null;
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("http://quote.yahoo.com/d/quotes.csv?s=" + currencyFrom + currencyTo + "=X&f=l1&e=.csv");
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
    new DefaultHttpMethodRetryHandler(3, false));
int status = client.executeMethod(method);
System.out.println("status : "+status);

byte[] response = method.getResponseBody();
currentRate =new String(response);

return currentRate;
}

}

Jar files (Application Programming Interface)

commons-httpclient-3.1.jar
commons-codec-1.11.jar


Uri (Uniform Resource locator )


http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22USDEUR%22,%20%22USDJPY%22,%20%22USDBGN%22,%20%22USDCZK%22,%20%22USDDKK%22,%20%22USDGBP%22,%20%22USDHUF%22,%20%22USDLTL%22,%20%22USDLVL%22,%20%22USDPLN%22,%20%22USDRON%22,%20%22USDSEK%22,%20%22USDCHF%22,%20%22USDNOK%22,%20%22USDHRK%22,%20%22USDRUB%22,%20%22USDTRY%22,%20%22USDAUD%22,%20%22USDBRL%22,%20%22USDCAD%22,%20%22USDCNY%22,%20%22USDHKD%22,%20%22USDIDR%22,%20%22USDILS%22,%20%22USDINR%22,%20%22USDKRW%22,%20%22USDMXN%22,%20%22USDMYR%22,%20%22USDNZD%22,%20%22USDPHP%22,%20%22USDSGD%22,%20%22USDTHB%22,%20%22USDZAR%22,%20%22USDISK%22)&env=store://datatables.org/alltableswithkeys


Thanks to steffi for her support

August 01, 2016

pdf creator progam in java - portable document format

A pdf creator in java


Description

descripiton

Source code

package com.konzn.kims.utils;


import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;


import java.io.FileNotFoundException;

import java.io.FileOutputStream;
import java.io.File;

import javax.swing.JTable;

/**
 * 
 * @author aromal
 * @version 1.0
 */
public class PdfCreator {

String filename = "accounts_consumerfed";
String path = null;
String projectName = "accounts manager";

public PdfCreator(){
initialize();
}

private void initialize() {
path = System.getProperty("user.home");
createDirectory(path+"\\"+projectName);
}

/**

* @see 
* @param 
* @return void
* Description : to create a directory if not exists
* Date : Jan 4, 2012
* Coded by : +deepa
*/
private void createDirectory(String dirPath) {
File directory = new File(dirPath);
if(directory.exists() == false){
directory.mkdir();
path = dirPath;
}else if(directory.exists()){
path = dirPath;
}else{
System.out.println("error at create directory ");
}

}

public static void main(String[] args) {
}

public void createPdfFromTable(JTable test) {
String[] headers = new String[test.getColumnCount()];
for (int j = 0; j < test.getColumnCount(); j++) {
headers[j] = test.getColumnName(j);
}

//

// Create a new document.

//

Document document = new Document(PageSize.LETTER.rotate());

try {

// Get an instance of PdfWriter and create a Table.pdf file

// as an output.

//

PdfWriter.getInstance(document,

new FileOutputStream(new File("E:\\AromalTable.pdf")));

document.open();

//

// Create an instance of PdfPTable. After that we transform

// the header and data array into a PdfPCell object. When
// each table row is complete we have to call the

// table.completeRow() method.

//
// For better presentation we also set the cell font name,

// size and weight. And we also define the background fill

// for the cell.

//

PdfPTable table = new PdfPTable(headers.length);

for (int i = 0; i < headers.length; i++) {

String header = headers[i];

PdfPCell cell = new PdfPCell();

cell.setGrayFill(0.9f);

cell.setPhrase(new Phrase(header.toUpperCase(),

new Font(Font.HELVETICA, 10,

Font.BOLD)));

table.addCell(cell);

}

table.completeRow();

for (int i = 0; i < test.getRowCount(); i++) {

for (int j = 0; j < test.getColumnCount(); j++) {

String datum = test.getValueAt(i, j).toString();

PdfPCell cell = new PdfPCell();

cell.setPhrase(new Phrase(datum.toUpperCase(),

new Font(Font.HELVETICA, 10,

Font.NORMAL)));

table.addCell(cell);

}

table.completeRow();

}

document.addTitle("Table Demo");

document.add(table);

} catch (DocumentException e) {

e.printStackTrace();

} catch (FileNotFoundException e) {

e.printStackTrace();

} finally {

document.close();

}


}


/**

* @see 
* @param 
* @return String
* Description : create a pdf by specified name and table
* Date : Jan 4, 2012
* Coded by : nithin,aromal
*/
public String createPdfFromTable(JTable test,String fileName) {
String message = "error in creation";
filename = fileName+".pdf";
String location = path+"\\"+filename;
String[] headers = new String[test.getColumnCount()];
for (int j = 0; j < test.getColumnCount(); j++) {
headers[j] = test.getColumnName(j);
}
Document document = new Document(PageSize.LETTER.rotate());
try {
PdfWriter.getInstance(document,
new FileOutputStream(new File(location)));
document.open();
PdfPTable table = new PdfPTable(headers.length);
for (int i = 0; i < headers.length; i++) {
String header = headers[i];

PdfPCell cell = new PdfPCell();

cell.setGrayFill(0.9f);

cell.setPhrase(new Phrase(header.toUpperCase(),

new Font(Font.HELVETICA, 10,

Font.BOLD)));

table.addCell(cell);

}

table.completeRow();

for (int i = 0; i < test.getRowCount(); i++) {

for (int j = 0; j < test.getColumnCount(); j++) {

String datum =  null;
if(test.getValueAt(i, j)== null){
datum = "      ";
}
else{
datum =test.getValueAt(i, j).toString();
}


PdfPCell cell = new PdfPCell();

cell.setPhrase(new Phrase(datum.toUpperCase(),

new Font(Font.HELVETICA, 10,

Font.NORMAL)));

table.addCell(cell);

}

table.completeRow();

}

document.addTitle("Table Demo");

document.add(table);
message = fileName + " created ";
} catch (DocumentException e) {

e.printStackTrace();

} catch (FileNotFoundException e) {

e.printStackTrace();

} finally {

document.close();

}


return message;
}

/**

* @see 
* @param Bean
* @return String
* Description :TODO
* Date : Jan 9, 2012
* Coded by : +joseph james 
*/
public String createForm8(){

return null;
}
}


http://javabelazy.blogspot.in/

June 07, 2016

Hotel Management System - Travel Port

https://www.youtube.com/watch?v=QnQvC8UOTWE



https://www.youtube.com/channel/UC9KIf2hU7ROZQQtHdnzPBDQ



Adding to cart scenerios

scenerio 1

subtracting add to cart from inventory

if there are 10 items in stock,

5 persons added 2 each to cart then 6 th person could see out of stock issue...

scenerio 2

if not subtracted

1 items left, one person A add it to cart and the second one B purchased it,

A will get out of stock error while purchasing it

One solution

1. The customer puts a product in her cart.
2. Event is fired and the plugin stores the WC_Cart id (which holds the products) with a timestamp in a table.
3. Stock is then temporarily reduced by the plugin.
4. A cronjob (registered via. wp_cron) checks the table with carts and timestamps and resets the stock for old carts and removes the row from the table.




https://github.com/woocommerce/woocommerce/issues/5966


apply
minimum option to skip check
and
holding time

discussion : https://github.com/woocommerce/woocommerce/issues/5966

is there any procedure after add to cart like adding user details ?


https://www.datascience.com/resources/notebooks/dynamically-pricing-hotel-rooms-with-data-science

http://www.amadeus.com/blog/26/09/dynamic-pricing-way-forward-maximise-airline-revenue/




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/

October 19, 2014

Sending File from System to System in java

How to send a file from one system to another using java code

Description :The program will help you to send a file from one computer to another in network through a socket. the port number here used is 8025 (we eliminate all 1024 reserved ports, for example 21 are reserved port for ftp).  developer can declare the port number as static final. The server application will send a file specified by the user through socket where the client application receives it. please provide feedback after running the code, check the java source code.This is an example for java networking application.



CLIENT SERVER
SENDING IMAGE FROM CLIENT TO SERVER IN JAVA



FTPServer.java

/**
 *
 */
package pakistan;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author javabelazy
 *
 */
public class FTPServer {
  
    ServerSocket serverSocket = null;
    Socket socket = null;
    int data = -1;
    DataOutputStream dataOutputStream = null;
    OutputStream outputStreams = null;
    DataInputStream dataInputStream = new DataInputStream(System.in);
    String fileNameNew = null;
    String string = null;
    File file = null;
    FileInputStream fileInputStream = null;
  

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        FTPServer ftpServer = new FTPServer();
        ftpServer.sendFile();

    }

    private void sendFile() {
        // TODO Auto-generated method stub
        string = new String();
        try{
            //d = new DataInputStream(System.in);
            System.out.println(" Enter the file name to be transfered ");
            fileNameNew=dataInputStream.readLine();
            file = new File(fileNameNew);
            fileInputStream = new FileInputStream(file);
            serverSocket= new ServerSocket(8025);
            socket=serverSocket.accept();
            outputStreams=socket.getOutputStream();
            dataOutputStream=new DataOutputStream(outputStreams);
            while((data=fileInputStream.read())!=-1){
                char c = (char)data;
                string=string+c;
            }
            dataOutputStream.writeUTF(string);
            System.out.println("The file "+fileNameNew +" file transfered to client machine");

        }
        catch (Exception e) {
            // TODO: handle exception
            System.out.println(" The server system got an exception : "+e.getMessage());
        }
        finally{
            try {
                socket.close();
                serverSocket.close();
                outputStreams.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println(" Unable to send file (file transfer got the following exception ) : "+e.getMessage());
                e.printStackTrace();
            }

          
        }
      
    }

}


FTPClient.java

/**
 *
 */
package china;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * @author java belazy
 *
 */
public class FTPClient {
  
    Socket socket =  null;
    int len = 0;
    int count = 0;
    InputStream inputStream = null;
    DataInputStream dataInputStream = null;
    DataInputStream newDataInputStream = null;
    String fileName = null;
    String fileData = null;

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        FTPClient ftpClient = new FTPClient();
        ftpClient.receiveFile();

    }

    private void receiveFile() {
        // receiving file sent by host system
        while(true){
        try{
            socket=new Socket("", 8025);
            inputStream = socket.getInputStream();
            newDataInputStream=new DataInputStream(inputStream);
            System.out.println(" Enter the file name to be saved ");
            dataInputStream = new DataInputStream(System.in);
            fileName = dataInputStream.readLine();
            File file = new File(fileName);
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            fileData =newDataInputStream.readUTF();
            len= fileData.length();
            for(count=0;count<len;count++){
                char c =fileData.charAt(count);
                fileOutputStream.write(c);
            }
            System.out.println("File copied to system ");

                   
        }catch (Exception e) {
            // TODO: handle exception
            System.out.println(" The file tranfer client got an exception : "+e.getMessage());
        }finally{
            try {
                socket.close();
                inputStream.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println(" The file tranfer client got an exception : "+e.getMessage());
                e.printStackTrace();
            }
           
           
        }
       
        }
       
    }

}
 

file transfer protocol implementation in java

Facebook comments