Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/workspace.xml
  • Loading branch information
faraz1380 committed Jul 24, 2020
2 parents 7eeb9bf + e0c1238 commit 114b47a
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 65 additions & 69 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Data/Accounts/Buyers.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"buyLogs":[{"discountValue":0,"sellerUsername":"Seller","addressOfBuyer":"home","wasProductHasFile":false,"date":"2020/07/24 01:00:20","price":10,"deliveryStatus":"Received","logId":26,"productId":10},{"discountValue":0,"sellerUsername":"Seller","addressOfBuyer":"my","wasProductHasFile":false,"date":"2020/07/24 01:04:44","price":10,"deliveryStatus":"Received","logId":27,"productId":10}],"discountIds":[1,2,3,4],"numberOfUse":{"1":0,"2":2,"3":2,"4":2},"cart":{"productsID":[],"muchOfProductID":{}},"username":"Buyer","firstName":"Buyer","lastName":"Buyer","password":"Buyer","email":"[email protected]","phoneNumber":"021","credit":8731},{"buyLogs":[],"discountIds":[1,2,4],"numberOfUse":{"1":0,"2":0,"4":0},"cart":{"productsID":[],"muchOfProductID":{}},"username":"parham","firstName":"parham","lastName":"chavoshian","password":"parham","email":"[email protected]","phoneNumber":"021","credit":99970},{"buyLogs":[],"discountIds":[],"numberOfUse":{},"cart":{"productsID":[],"muchOfProductID":{}},"username":"milad","firstName":"milad","lastName":"saadat","password":"salam","email":"[email protected]","phoneNumber":"1231","credit":12312}]
[{"buyLogs":[{"discountValue":0,"sellerUsername":"Seller","addressOfBuyer":"home","wasProductHasFile":false,"date":"2020/07/24 01:00:20","price":10,"deliveryStatus":"Received","logId":26,"productId":10},{"discountValue":0,"sellerUsername":"Seller","addressOfBuyer":"my","wasProductHasFile":false,"date":"2020/07/24 01:04:44","price":10,"deliveryStatus":"Received","logId":27,"productId":10},{"discountValue":0,"sellerUsername":"Seller","addressOfBuyer":"home","wasProductHasFile":false,"date":"2020/07/24 20:47:19","price":10,"deliveryStatus":"preparing...","logId":28,"productId":10},{"discountValue":0,"sellerUsername":"Seller","addressOfBuyer":"home","wasProductHasFile":false,"date":"2020/07/24 20:50:43","price":10,"deliveryStatus":"preparing...","logId":29,"productId":10}],"discountIds":[1,2,3,4],"numberOfUse":{"1":0,"2":2,"3":2,"4":2},"cart":{"productsID":[],"muchOfProductID":{}},"username":"Buyer","firstName":"Buyer","lastName":"Buyer","password":"Buyer","email":"[email protected]","phoneNumber":"021","credit":8731},{"buyLogs":[],"discountIds":[1,2,4],"numberOfUse":{"1":0,"2":0,"4":0},"cart":{"productsID":[],"muchOfProductID":{}},"username":"parham","firstName":"parham","lastName":"chavoshian","password":"parham","email":"[email protected]","phoneNumber":"021","credit":99970},{"buyLogs":[],"discountIds":[],"numberOfUse":{},"cart":{"productsID":[],"muchOfProductID":{}},"username":"milad","firstName":"milad","lastName":"saadat","password":"salam","email":"[email protected]","phoneNumber":"1231","credit":12312}]
2 changes: 1 addition & 1 deletion Data/Accounts/Sellers.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"company":"Selling","sellLogs":[{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 12:35:52","price":10,"deliveryStatus":"preparing...","logId":9,"productId":7},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/29 10:39:49","price":15,"deliveryStatus":"preparing...","logId":13,"productId":8},{"OffValue":2,"buyerUsername":"Buyer","date":"2020/06/29 10:57:55","price":10,"deliveryStatus":"preparing...","logId":14,"productId":7},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 14:49:19","price":10,"deliveryStatus":"preparing...","logId":17,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 14:52:11","price":10,"deliveryStatus":"preparing...","logId":18,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 15:04:43","price":10,"deliveryStatus":"preparing...","logId":19,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 15:08:29","price":10,"deliveryStatus":"preparing...","logId":20,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 15:16:34","price":10,"deliveryStatus":"preparing...","logId":21,"productId":9},{"OffValue":0,"buyerUsername":"parham","date":"2020/07/23 15:22:32","price":10,"deliveryStatus":"preparing...","logId":22,"productId":9},{"OffValue":0,"buyerUsername":"parham","date":"2020/07/23 15:30:19","price":10,"deliveryStatus":"preparing...","logId":23,"productId":9},{"OffValue":0,"buyerUsername":"parham","date":"2020/07/23 15:33:31","price":10,"deliveryStatus":"preparing...","logId":24,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 20:49:43","price":10,"deliveryStatus":"preparing...","logId":25,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/24 01:00:20","price":10,"deliveryStatus":"preparing...","logId":26,"productId":10},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/24 01:04:44","price":10,"deliveryStatus":"preparing...","logId":27,"productId":10}],"username":"Seller","firstName":"Seller","lastName":"Seller","password":"Seller","email":"[email protected]","phoneNumber":"021","credit":10168},{"company":"Selling","sellLogs":[],"username":"Seller","firstName":"Seller","lastName":"Seller","password":"Seller","email":"[email protected]","phoneNumber":"021","credit":100000},{"company":"sale","sellLogs":[{"OffValue":10,"buyerUsername":"Buyer","date":"2020/06/26 10:28:48","price":12,"deliveryStatus":"preparing...","logId":1,"productId":4},{"OffValue":10,"buyerUsername":"Buyer","date":"2020/06/26 10:34:00","price":12,"deliveryStatus":"preparing...","logId":2,"productId":4},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 10:56:44","price":123,"deliveryStatus":"preparing...","logId":3,"productId":3},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 10:57:58","price":123,"deliveryStatus":"preparing...","logId":4,"productId":3},{"OffValue":10,"buyerUsername":"Buyer","date":"2020/06/26 10:58:22","price":12,"deliveryStatus":"preparing...","logId":5,"productId":4},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 10:58:50","price":123,"deliveryStatus":"preparing...","logId":6,"productId":3},{"OffValue":10,"buyerUsername":"Buyer","date":"2020/06/26 11:14:40","price":12,"deliveryStatus":"preparing...","logId":7,"productId":4},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 11:16:31","price":123,"deliveryStatus":"preparing...","logId":8,"productId":3},{"OffValue":10,"buyerUsername":"Buyer","date":"2020/06/26 14:32:45","price":12,"deliveryStatus":"preparing...","logId":10,"productId":4},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 16:20:40","price":12,"deliveryStatus":"preparing...","logId":11,"productId":2},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 16:24:14","price":123,"deliveryStatus":"preparing...","logId":12,"productId":3},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/29 11:06:24","price":123,"deliveryStatus":"preparing...","logId":15,"productId":3},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/29 11:08:57","price":123,"deliveryStatus":"preparing...","logId":16,"productId":3}],"username":"saleman","firstName":"sale","lastName":"sale","password":"saleman","email":"[email protected]","phoneNumber":"1234","credit":2148}]
[{"company":"Selling","sellLogs":[{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 12:35:52","price":10,"deliveryStatus":"preparing...","logId":9,"productId":7},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/29 10:39:49","price":15,"deliveryStatus":"preparing...","logId":13,"productId":8},{"OffValue":2,"buyerUsername":"Buyer","date":"2020/06/29 10:57:55","price":10,"deliveryStatus":"preparing...","logId":14,"productId":7},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 14:49:19","price":10,"deliveryStatus":"preparing...","logId":17,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 14:52:11","price":10,"deliveryStatus":"preparing...","logId":18,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 15:04:43","price":10,"deliveryStatus":"preparing...","logId":19,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 15:08:29","price":10,"deliveryStatus":"preparing...","logId":20,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 15:16:34","price":10,"deliveryStatus":"preparing...","logId":21,"productId":9},{"OffValue":0,"buyerUsername":"parham","date":"2020/07/23 15:22:32","price":10,"deliveryStatus":"preparing...","logId":22,"productId":9},{"OffValue":0,"buyerUsername":"parham","date":"2020/07/23 15:30:19","price":10,"deliveryStatus":"preparing...","logId":23,"productId":9},{"OffValue":0,"buyerUsername":"parham","date":"2020/07/23 15:33:31","price":10,"deliveryStatus":"preparing...","logId":24,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/23 20:49:43","price":10,"deliveryStatus":"preparing...","logId":25,"productId":9},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/24 01:00:20","price":10,"deliveryStatus":"preparing...","logId":26,"productId":10},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/24 01:04:44","price":10,"deliveryStatus":"preparing...","logId":27,"productId":10},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/24 20:47:19","price":10,"deliveryStatus":"preparing...","logId":28,"productId":10},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/07/24 20:50:43","price":10,"deliveryStatus":"preparing...","logId":29,"productId":10}],"username":"Seller","firstName":"Seller","lastName":"Seller","password":"Seller","email":"[email protected]","phoneNumber":"021","credit":10188},{"company":"Selling","sellLogs":[],"username":"Seller","firstName":"Seller","lastName":"Seller","password":"Seller","email":"[email protected]","phoneNumber":"021","credit":100000},{"company":"sale","sellLogs":[{"OffValue":10,"buyerUsername":"Buyer","date":"2020/06/26 10:28:48","price":12,"deliveryStatus":"preparing...","logId":1,"productId":4},{"OffValue":10,"buyerUsername":"Buyer","date":"2020/06/26 10:34:00","price":12,"deliveryStatus":"preparing...","logId":2,"productId":4},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 10:56:44","price":123,"deliveryStatus":"preparing...","logId":3,"productId":3},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 10:57:58","price":123,"deliveryStatus":"preparing...","logId":4,"productId":3},{"OffValue":10,"buyerUsername":"Buyer","date":"2020/06/26 10:58:22","price":12,"deliveryStatus":"preparing...","logId":5,"productId":4},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 10:58:50","price":123,"deliveryStatus":"preparing...","logId":6,"productId":3},{"OffValue":10,"buyerUsername":"Buyer","date":"2020/06/26 11:14:40","price":12,"deliveryStatus":"preparing...","logId":7,"productId":4},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 11:16:31","price":123,"deliveryStatus":"preparing...","logId":8,"productId":3},{"OffValue":10,"buyerUsername":"Buyer","date":"2020/06/26 14:32:45","price":12,"deliveryStatus":"preparing...","logId":10,"productId":4},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 16:20:40","price":12,"deliveryStatus":"preparing...","logId":11,"productId":2},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/26 16:24:14","price":123,"deliveryStatus":"preparing...","logId":12,"productId":3},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/29 11:06:24","price":123,"deliveryStatus":"preparing...","logId":15,"productId":3},{"OffValue":0,"buyerUsername":"Buyer","date":"2020/06/29 11:08:57","price":123,"deliveryStatus":"preparing...","logId":16,"productId":3}],"username":"saleman","firstName":"sale","lastName":"sale","password":"saleman","email":"[email protected]","phoneNumber":"1234","credit":2148}]
2 changes: 1 addition & 1 deletion Data/IDs/Id.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[28,27,5,5,11]
[30,27,5,5,11]
2 changes: 1 addition & 1 deletion Data/Products/Products.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"productId":9,"status":"Greate","name":"TextFile","available":true,"number":1,"description":"Goood","averageScore":0.0,"categoryName":"cleaning","price":10,"sellerUsername":"Seller","scores":[],"comments":[],"offId":-1,"doesHasFile":true,"address":"Data/test.txt"},{"productId":10,"status":"greate","name":"shampoo","available":true,"number":23,"description":"good","averageScore":0.0,"categoryName":"cleaning","price":10,"sellerUsername":"Seller","scores":[],"comments":[],"offId":-1,"doesHasFile":false,"address":"DoesNotHaveFile"}]
[{"productId":9,"status":"Greate","name":"TextFile","available":true,"number":1,"description":"Goood","averageScore":0.0,"categoryName":"cleaning","price":10,"sellerUsername":"Seller","scores":[],"comments":[],"offId":-1,"doesHasFile":true,"address":"Data/test.txt"},{"productId":10,"status":"greate","name":"shampoo","available":true,"number":21,"description":"good","averageScore":0.0,"categoryName":"cleaning","price":10,"sellerUsername":"Seller","scores":[],"comments":[],"offId":-1,"doesHasFile":false,"address":"DoesNotHaveFile"}]
2 changes: 1 addition & 1 deletion src/main/java/Controller/AdminManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.ArrayList;

public class AdminManager {
private static int commission = 5 ;
private static int commission = 10 ;
private static int minimumValue = 100;

public static int getCommission() {
Expand Down
51 changes: 48 additions & 3 deletions src/main/java/Controller/BuyerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,60 @@ public String bankPay(Account account , int discountId , String address , String
if (discountId!=-1 && !((BuyerAccount) account).canUseDiscount(discountId))
return "You can't use this discount";
else {
String res = bankBuy(discountId,account, address);
String res = bankBuy(discountId , account, address , bankUsername , bankPassword , bankID);
if (res.equals("done successfully"))
return "product bought successfully";
return res;
}
}

private String bankBuy(int discountId, Account account, String address) {
return "";
private String bankBuy(int discountId, Account account, String address , String bankUsername , String bankPassword , String bankId) {
BuyerAccount buyerAccount = (BuyerAccount) account;
long cost = buyerAccount.getCart().getCost();

if (buyerAccount.canUseDiscount(discountId)) {
buyerAccount.useDiscount(discountId);
if (discountId != -1) {
Discount discount = Database.getDiscountById(discountId);
cost = cost - Math.min((int) cost * discount.getPercent() / 100, discount.getMaxValue());
}
}
String res = WorkWithBank.withdraw(Math.toIntExact(cost), bankUsername , bankPassword, bankId);
if (!res.equals("done successfully"))
return res;
if (discountId!=-1 && buyerAccount.canUseDiscount(discountId)) {
buyerAccount.useDiscount(discountId);
}
payToSellerWithBank(discountId, account, address);
buyerAccount.setCart(new Cart());
return res;
}

public void payToSellerWithBank(int discountId, Account account, String addressOfBuyer) {
BuyerAccount buyerAccount = (BuyerAccount) account;
int discountValue = 0;
if (buyerAccount.canUseDiscount(discountId))
discountValue = Database.getDiscountById(discountId).getPercent();
if (discountId == -1)
discountValue = 0;
for (Integer productId : buyerAccount.getCart().getProductsID()) {
Product product = Database.getProductByID(productId);
SellerAccount sellerAccount = (SellerAccount) Database.getAccountByUsername(product.getSellerUsername());
int amount = sellerAccount.getCredit();
sellerAccount.setCredit(sellerAccount.getCredit() + product.getPrice() * buyerAccount.getCart().getMuchOfProductID(productId));
int maxValue = product.getPrice();
int offValue = 0;
if (product.doesHaveOff()) {
maxValue = product.getOff().getMaxValue();
offValue = product.getPrice() * product.getOff().getPercent() / 100;
sellerAccount.setCredit(sellerAccount.getCredit() - Math.min(offValue, maxValue) * buyerAccount.getCart().getMuchOfProductID(productId));
}
amount = sellerAccount.getCredit() - amount;
Account adminAccount = Database.getAccountByUsername("Admin");
adminAccount.setCredit(adminAccount.getCredit() + (amount * AdminManager.getCommission())/100);
sellerAccount.setCredit(sellerAccount.getCredit() - (amount * AdminManager.getCommission())/100);
Log.addLog(buyerAccount.getUsername(), product.getSellerUsername(), product.getPrice(), productId, Math.min(offValue, maxValue), discountValue * product.getPrice() / 100, addressOfBuyer, product.doesHasFile());
}
}

public void joinAuction(Auction auction, Account account){
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Controller/ClientThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ else if (input.startsWith("addMessage")) {
}
else if (input.startsWith("BankPay ")){
details = input.split(" ");
buyerManager.bankPay(account , Integer.parseInt(details[1]), details[2] , details[3], details[4] ,details[5]);
output = buyerManager.bankPay(account , Integer.parseInt(details[1]), details[2] , details[3], details[4] ,details[5]);
}
else if (input.startsWith("Exit"))
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Controller/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class Server {
public static void main(String[] args) {
Server server = new Server();
Database.initialize();
/*try {
try {
WorkWithBank.ConnectToBankServer();
} catch (IOException e) {
e.printStackTrace();
}*/
}
server.waitForClient();
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/Controller/WorkWithBank.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.net.Socket;

public class WorkWithBank {
public static final int PORT = 2222;
public static final int PORT = 2020;
public static final String IP = "127.0.0.1";

private static DataOutputStream outputStream;
Expand Down Expand Up @@ -60,4 +60,14 @@ public static String decreaseCredit(int much, String bankUsername, String bankPa
}
return res ;
}

public static String withdraw(int much , String bankUsername, String bankPassword, String bankId) {
String token = get_token(bankUsername , bankPassword);
String res = sendMessage("create_receipt " + token + " withdraw " + much + " " + bankId + " " + -1 + " buying");
if (res.matches("[0-9]+")){
res = sendMessage("pay " + res) ;
}
return res ;

}
}

0 comments on commit 114b47a

Please sign in to comment.