Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions manav(1710991453)/Administrator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.wipro.sales.service;

import java.sql.*;
import java.util.ArrayList;
import com.wipro.sales.dao.*;
import com.wipro.sales.bean.*;

public class Administrator {

private static StockDao stockDao = new StockDao();
private static SalesDao salesDao = new SalesDao();

public synchronized String insertStock(Stock stockobj) {
if (stockobj != null && stockobj.getProductName().length() >= 2) {
String productID = stockDao.generateProductID(stockobj.getProductName());
stockobj.setProductID(productID);
if (stockDao.insertStock(stockobj) == 1)
return productID;
else
return "Data not Valid ";
} else {
return "Data not Valid ";
}
}


public String deleteStock(String productID) {
if (stockDao.deleteStock(productID) == 1)
return "deleted";
else
return "record cannot be deleted";
}


public String insertSales(Sales salesobj) {
if (salesobj == null)
return "Object not valid for insertion";

if (stockDao.getStock(salesobj.getProductID()) == null)
return "Unknown Product";

if (stockDao.getStock(salesobj.getProductID()).getQuantityOnHand() < salesobj.getQuantitySold())
return "Not enough stock ";

if (salesobj.getSalesDate().before(new Date(0)))
return "Invalid date";

String salesID = salesDao.generateSalesID(salesobj.getSalesDate());
salesobj.setSalesID(salesID);

if (salesDao.insertSales(salesobj) == 1) {
if (stockDao.updateStock(salesobj.getProductID(), salesobj.getQuantitySold()) == 1)
return " record successfully";
else
return "Error";
} else {
return "Error";
}
}


public ArrayList<SalesReport> getSalesReport(){
return salesDao.getSalesReport();
}
}
20 changes: 20 additions & 0 deletions manav(1710991453)/DBUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.wipro.sales.util;

import java.sql.*;

public class DBUtil {
static String db_url = "jdbc:oracle:thin:@localhost:1521:xe";
static Connection con = null;
static String user = "username";
static String pass = "password";
public static Connection getDBConnection() {
try {
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521", "scott", "tiger");
return con;
} catch (SQLException e) {
System.out.println("Connection could not be estanlished");
e.printStackTrace();
return null;
}
}
}
40 changes: 40 additions & 0 deletions manav(1710991453)/Sales.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.wipro.sales.bean;

public class Sales {
String salesID;
java.util.Date salesDate;
String productID;
int quantitySold;
double salesPricePerUnit;
public String getSalesID() {
return salesID;
}
public void setSalesID(String salesID) {
this.salesID = salesID;
}
public java.util.Date getSalesDate() {
return salesDate;
}
public void setSalesDate(java.util.Date salesDate) {
this.salesDate = salesDate;
}
public String getProductID() {
return productID;
}
public void setProductID(String productID) {
this.productID = productID;
}
public int getQuantitySold() {
return quantitySold;
}
public void setQuantitySold(int quantitySold) {
this.quantitySold = quantitySold;
}
public double getSalesPricePerUnit() {
return salesPricePerUnit;
}
public void setSalesPricePerUnit(double salesPricePerUnit) {
this.salesPricePerUnit = salesPricePerUnit;
}

}
79 changes: 79 additions & 0 deletions manav(1710991453)/SalesApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.wipro.sales.main;

import java.util.Scanner;
import com.wipro.sales.bean.*;
import com.wipro.sales.service.*;
import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class SalesApplication {

public static void main(String[] args) throws ParseException {
Scanner sc = new Scanner(System.in);

Administrator admin = new Administrator();

int choice = 0;

do {
System.out.println("1. Insert Stock");
System.out.println("2. Delete Stock");
System.out.println("3. Insert Sales");
System.out.println("4. View Sales Report");
System.out.print("Enter your Choice: ");
choice = sc.nextInt();

switch (choice) {
case 1:
Stock stock = new Stock();
System.out.print("Enter product ID: ");
stock.setProductID(sc.nextLine());
System.out.print("Enter product name: ");
stock.setProductName(sc.nextLine());
System.out.print("Enter quantity on hand: ");
stock.setQuantityOnHand(sc.nextInt());
sc.nextLine();
System.out.print("Enter product unit price: ");
stock.setProductUnitPrice(sc.nextDouble());
System.out.print("Enter product reorder level: ");
stock.setReorderLevel(sc.nextInt());
sc.nextLine();
admin.insertStock(stock);
break;
case 2:
System.out.print("Enter product id to be deleted: ");
String removeId = sc.nextLine();
removeId = admin.deleteStock(removeId);
if (removeId != null) System.out.println(removeId + " removed successfully");
break;
case 3:
Sales sales = new Sales();
System.out.print("Enter sales id: ");
sales.setSalesID(sc.nextLine());
System.out.print("Enter date (dd-mm-yyyy): ");
String sDate = sc.nextLine();
Date date = (Date) new SimpleDateFormat("dd-mm-yyyy").parse(sDate);
sales.setSalesDate(date);
System.out.print("Enter product id: ");
sales.setProductID(sc.nextLine());
System.out.print("Enter quantity sold: ");
sales.setQuantitySold(sc.nextInt());
sc.nextLine();
System.out.print("Enter sales price per unit: ");
sales.setSalesPricePerUnit(sc.nextDouble());
admin.insertSales(sales);
break;
case 4:
admin.getSalesReport();
break;
default:
System.out.println("Exiting...");
choice = 0;
break;
}
} while (choice >= 1 && choice <= 4);

sc.close();
}

}
61 changes: 61 additions & 0 deletions manav(1710991453)/SalesReport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.wipro.sales.bean;

public class SalesReport {
String salesID;
java.util.Date salesDate;
String productID;
String productName;
int quantitySold;
double productUnitPrice;
double salesPricePerUnit;
double profitAmount;
public String getSalesID() {
return salesID;
}
public void setSalesID(String salesID) {
this.salesID = salesID;
}
public java.util.Date getSalesDate() {
return salesDate;
}
public void setSalesDate(java.util.Date salesDate) {
this.salesDate = salesDate;
}
public String getProductID() {
return productID;
}
public void setProductID(String productID) {
this.productID = productID;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public int getQuantitySold() {
return quantitySold;
}
public void setQuantitySold(int quantitySold) {
this.quantitySold = quantitySold;
}
public double getProductUnitPrice() {
return productUnitPrice;
}
public void setProductUnitPrice(double productUnitPrice) {
this.productUnitPrice = productUnitPrice;
}
public double getSalesPricePerUnit() {
return salesPricePerUnit;
}
public void setSalesPricePerUnit(double salesPricePerUnit) {
this.salesPricePerUnit = salesPricePerUnit;
}
public double getProfitAmount() {
return profitAmount;
}
public void setProfitAmount(double profitAmount) {
this.profitAmount = profitAmount;
}

}
40 changes: 40 additions & 0 deletions manav(1710991453)/Stock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.wipro.sales.bean;

public class Stock {
String productID;
String productName;
int quantityOnHand;
double productUnitPrice;
int reorderLevel;
public String getProductID() {
return productID;
}
public void setProductID(String productID) {
this.productID = productID;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public int getQuantityOnHand() {
return quantityOnHand;
}
public void setQuantityOnHand(int quantityOnHand) {
this.quantityOnHand = quantityOnHand;
}
public double getProductUnitPrice() {
return productUnitPrice;
}
public void setProductUnitPrice(double productUnitPrice) {
this.productUnitPrice = productUnitPrice;
}
public int getReorderLevel() {
return reorderLevel;
}
public void setReorderLevel(int reorderLevel) {
this.reorderLevel = reorderLevel;
}

}
Loading