diff --git a/app/controllers/Application.java b/app/controllers/Application.java index 56cda7261..31305cc2f 100644 --- a/app/controllers/Application.java +++ b/app/controllers/Application.java @@ -4,6 +4,7 @@ import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.exceptions.JWTCreationException; import enums.FeedbackRequestState; + import play.Play; import play.i18n.Lang; import play.i18n.Messages; @@ -15,6 +16,7 @@ import services.translaiton.Translation; import java.io.IOException; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -101,6 +103,7 @@ public static void wisehands(String client) { } public static void languageChooser(String client) { + System.out.println(" --- executing languageChooser ---"); ShopDTO shop = ShopDTO.find("byDomain", client).first(); if (shop == null) { shop = ShopDTO.find("byDomain", "localhost").first(); @@ -133,13 +136,16 @@ public static void languageChooser(String client) { "and c.isHidden = ?2 and p.isActive = ?3 and p.isDishOfDay = 0 order by p.sortOrder asc"; products = ProductDTO.find(query, shop, false, true).fetch(); - List pageList = PageConstructorDTO.find("byShop", shop).fetch(); - List translationPageList = new ArrayList(); - for(PageConstructorDTO _page: pageList){ - _page = Translation.setTranslationForPage(language, _page); - translationPageList.add(_page); + shop.pagesList = translatePageList(shop, language); + + String selectedCurrency = ""; + if (request.params.get("currency") != null){ + selectedCurrency = request.params.get("currency"); + shop.currencyShop = setCurrencyToShop(shop); + shop.currencyShop.selectedCurrency = selectedCurrency; + shop.save(); } - shop.pagesList = translationPageList; + List productList = new ArrayList(); String qr_uuid = ""; @@ -149,14 +155,15 @@ public static void languageChooser(String client) { for (ProductDTO product : products) { product = Translation.setTranslationForProduct(language, product); - productList.add(product); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); if(qr_uuid == null || qr_uuid.isEmpty()){ int totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); - product.priceWithAdditions = Double.valueOf(totalPriceForDefaultAdditions); + product.priceWithAdditions = DataBaseQueries.exchangePrice(totalPriceForDefaultAdditions, shop, selectedCurrency); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); } else { DataBaseQueries.hideDefaultAddition(product); } - + productList.add(product); } products = productList; @@ -216,23 +223,33 @@ public static void index(String client, String language) { translationPageList.add(_page); } shop.pagesList = translationPageList; - List productList = new ArrayList(); - String qr_uuid = ""; if (request.params.get("qr_uuid") != null){ qr_uuid = request.params.get("qr_uuid"); } + String selectedCurrency = ""; + if (request.params.get("currency") != null){ + selectedCurrency = request.params.get("currency"); + shop.currencyShop = setCurrencyToShop(shop); + shop.currencyShop.selectedCurrency = selectedCurrency; + shop.save(); + } + + shop.currencyShop = setCurrencyToShop(shop); + List productList = new ArrayList(); for (ProductDTO product : products) { product = Translation.setTranslationForProduct(language, product); - productList.add(product); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); if(qr_uuid == null || qr_uuid.isEmpty()){ int totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); - product.priceWithAdditions = Double.valueOf(totalPriceForDefaultAdditions); + product.priceWithAdditions = DataBaseQueries.exchangePrice(totalPriceForDefaultAdditions, shop, selectedCurrency); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); } else { DataBaseQueries.hideDefaultAddition(product); } + productList.add(product); } products = productList; @@ -243,9 +260,6 @@ public static void index(String client, String language) { List categories = shop.getActiveCategories(language); Translation.setTranslationForShop(language, shop); - System.out.println("request.params qr_uuid.isEmpty() in Index => " + qr_uuid); - - if(client.equals("americano.lviv.ua")){ renderTemplate("app/views/shopLanding/shopLanding.html", language); } @@ -256,6 +270,7 @@ public static void index(String client, String language) { public static void shop(String client, String language) { Date date = new Date(); + System.out.println(" --- executing shop ---"); ShopDTO shop = ShopDTO.find("byDomain", client).first(); if (shop == null) { @@ -305,15 +320,25 @@ public static void shop(String client, String language) { "and p.isActive = ?3 and p.isDishOfDay = 0 order by p.sortOrder asc"; products = ProductDTO.find(query, shop, false, true).fetch(); + String selectedCurrency = ""; + if (request.params.get("currency") != null){ + selectedCurrency = request.params.get("currency"); + shop.currencyShop = setCurrencyToShop(shop); + shop.currencyShop.selectedCurrency = selectedCurrency; + shop.save(); + } + for (ProductDTO product : products) { product = Translation.setTranslationForProduct(language, product); - productList.add(product); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); if(qr_uuid == null || qr_uuid.isEmpty()){ int totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); - product.priceWithAdditions = Double.valueOf(totalPriceForDefaultAdditions); + product.priceWithAdditions = DataBaseQueries.exchangePrice(totalPriceForDefaultAdditions, shop, selectedCurrency); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); } else { DataBaseQueries.hideDefaultAddition(product); } + productList.add(product); } products = productList; @@ -326,7 +351,7 @@ public static void shop(String client, String language) { System.out.println("request.params qr_uuid.isEmpty() in Shop => " + qr_uuid); - renderTemplate("Application/shop.html", shop, dishOfDay, products, language, categories, qr_uuid); + renderTemplate("Application/shop.html", shop, dishOfDay, products, language, categories, qr_uuid, selectedCurrency); } public static void categoryOld(String client, String uuid) { @@ -341,6 +366,7 @@ public static void category(String client, String uuid, String language){ if (shop == null) { shop = ShopDTO.find("byDomain", "localhost").first(); } + System.out.println(" --- executing category ---"); Http.Header acceptLanguage = request.headers.get("accept-language"); String languageFromHeader = LanguageForShop.getLanguageFromAcceptHeaders(acceptLanguage); @@ -357,20 +383,30 @@ public static void category(String client, String uuid, String language){ "and p.isDishOfDay = 0 and p.categoryUuid = ?4 order by p.sortOrder asc"; products = ProductDTO.find(query, shop, false, true, category.uuid).fetch(); + String selectedCurrency = ""; + if (request.params.get("currency") != null){ + selectedCurrency = request.params.get("currency"); + shop.currencyShop = setCurrencyToShop(shop); + shop.currencyShop.selectedCurrency = selectedCurrency; + shop.save(); + } + String qr_uuid = request.params.get("qr_uuid") != null ? request.params.get("qr_uuid") : ""; List productList = new ArrayList(); for (ProductDTO product : products) { product = Translation.setTranslationForProduct(language, product); - productList.add(product); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); if(qr_uuid == null || qr_uuid.isEmpty()){ int totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); - product.priceWithAdditions = Double.valueOf(totalPriceForDefaultAdditions); + product.priceWithAdditions = DataBaseQueries.exchangePrice(totalPriceForDefaultAdditions, shop, selectedCurrency); + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); } else { DataBaseQueries.hideDefaultAddition(product); } - + productList.add(product); } + Translation.setTranslationForShop(language, shop); List pageList = PageConstructorDTO.find("byShop", shop).fetch(); @@ -402,6 +438,7 @@ public static void productOld(String client, String uuid) { } public static void product(String client, String uuid, String language){ + System.out.println(" --- executing product ---"); ShopDTO shop = ShopDTO.find("byDomain", client).first(); if (shop == null){ shop = ShopDTO.find("byDomain", "localhost").first(); @@ -411,36 +448,46 @@ public static void product(String client, String uuid, String language){ String languageFromHeader = LanguageForShop.getLanguageFromAcceptHeaders(acceptLanguage); language = LanguageForShop.setLanguageForShop(language, languageFromHeader); - List pageList = PageConstructorDTO.find("byShop", shop).fetch(); - List translationPageList = new ArrayList(); - for(PageConstructorDTO _page: pageList){ - _page = Translation.setTranslationForPage(language, _page); - translationPageList.add(_page); - } - shop.pagesList = translationPageList; + shop.pagesList = translatePageList(shop, language); ProductDTO product = ProductDTO.findById(uuid); CategoryDTO category = product.category; List categories = shop.getActiveCategories(language); + product.feedbackList = DataBaseQueries.getFeedbackList(product); String additionsListQuery = "select s from SelectedAdditionDTO s where s.isSelected = 1 and s.isDefault = 0 and s.productUuid = ?1"; product.selectedAdditions = SelectedAdditionDTO.find(additionsListQuery, product.uuid).fetch(); - String qr_uuid = null; - int totalPriceForDefaultAdditions = 0; - List defaultAdditions = new ArrayList<>(); + String qr_uuid = null, selectedCurrency = ""; + + if (request.params.get("currency") != null){ + selectedCurrency = request.params.get("currency"); + shop.currencyShop = setCurrencyToShop(shop); + shop.currencyShop.selectedCurrency = selectedCurrency; + shop.save(); + } + if (request.params.get("qr_uuid") != null){ qr_uuid = request.params.get("qr_uuid"); DataBaseQueries.hideDefaultAddition(product); } - if(qr_uuid == null || qr_uuid.isEmpty()){ - totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); - product.priceWithAdditions = Double.valueOf(totalPriceForDefaultAdditions); + + double totalPriceForDefaultAdditions = 0; + List defaultAdditions = new ArrayList<>(); + + if(qr_uuid != null) { + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); + } else { defaultAdditions = DataBaseQueries.checkIsAdditionDefaultToProduct(product); product.defaultAdditions = defaultAdditions; + + totalPriceForDefaultAdditions = DataBaseQueries.getTotalPriceForDefaultAdditions(product.uuid); + product.priceWithAdditions = DataBaseQueries.exchangePrice(totalPriceForDefaultAdditions, shop, selectedCurrency); + totalPriceForDefaultAdditions = product.priceWithAdditions; + + DataBaseQueries.changePriceAccordingToCurrency(product, shop, selectedCurrency); } - System.out.println("request.params qr_uuid.isEmpty() in Product => " + qr_uuid); Translation.setTranslationForProduct(language, product); Translation.setTranslationForShop(language, shop); @@ -453,7 +500,26 @@ public static void product(String client, String uuid, String language){ } render(product, category, categories, shop, language, - defaultAdditions, totalPriceForDefaultAdditions, qr_uuid, mainShopUrl, urlToCategory); + defaultAdditions, totalPriceForDefaultAdditions, qr_uuid, mainShopUrl, urlToCategory, selectedCurrency); + } + + public static CurrencyShopDTO setCurrencyToShop(ShopDTO shop) { + CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); + if (currencyShop == null){ + currencyShop = new CurrencyShopDTO(shop); + currencyShop.save(); + } + return currencyShop; + } + + private static List translatePageList(ShopDTO shop, String language) { + List pageList = PageConstructorDTO.find("byShop", shop).fetch(); + List translationPageList = new ArrayList(); + for(PageConstructorDTO _page: pageList){ + _page = Translation.setTranslationForPage(language, _page); + translationPageList.add(_page); + } + return translationPageList; } public static void shopHeader(String client){ @@ -461,11 +527,16 @@ public static void shopHeader(String client){ if (shop == null) { shop = ShopDTO.find("byDomain", "localhost").first(); } - String qr_uuid = ""; + String qr_uuid = "", selectedCurrency = ""; if (request.params.get("qr_uuid") != null){ qr_uuid = request.params.get("qr_uuid"); } - renderTemplate("tags/footer-shop.html", shop, qr_uuid); + + if (request.params.get("currency") != null){ + selectedCurrency = request.params.get("currency"); + } + System.out.println("selectedCurrency shopHeader => " + selectedCurrency.isEmpty()); + renderTemplate("tags/footer-shop.html", shop, qr_uuid, selectedCurrency); } public static void footerShop(String client){ @@ -521,18 +592,14 @@ public static void selectAddress(String client, String language) { Http.Header acceptLanguage = request.headers.get("accept-language"); String languageFromHeader = LanguageForShop.getLanguageFromAcceptHeaders(acceptLanguage); language = LanguageForShop.setLanguageForShop(language, languageFromHeader); - System.out.println("LanguageForShop" + language); List pageList = PageConstructorDTO.find("byShop", shop).fetch(); - List translationPageList = new ArrayList(); - for(PageConstructorDTO _page: pageList){ - _page = Translation.setTranslationForPage(language, _page); - translationPageList.add(_page); + shop.pagesList = translatePageList(shop, language); - } List categories = shop.getActiveCategories(language); - shop.pagesList = translationPageList; - render(shop, categories, language); + Translation.setTranslationForShop(language, shop); + render(shop, pageList, language, categories); + } public static void pageOld(String client, String uuid) { @@ -549,21 +616,17 @@ public static void page(String client, String uuid, String language) { } Http.Header acceptLanguage = request.headers.get("accept-language"); String languageFromHeader = LanguageForShop.getLanguageFromAcceptHeaders(acceptLanguage); - System.out.println("page language from params " + language); language = LanguageForShop.setLanguageForShop(language, languageFromHeader); + Translation.setTranslationForShop(language, shop); + PageConstructorDTO page = PageConstructorDTO.findById(uuid); page = Translation.setTranslationForPage(language, page); + List pageList = PageConstructorDTO.find("byShop", shop).fetch(); - List translationPageList = new ArrayList(); - for(PageConstructorDTO _page: pageList){ - _page = Translation.setTranslationForPage(language, _page); - translationPageList.add(_page); - } - shop.pagesList = translationPageList; + shop.pagesList = translatePageList(shop, language); + List categories = shop.getActiveCategories(language); - Translation.setTranslationForShop(language, shop); - System.out.println("page language " + language); render(shop, page, pageList, language, categories); } @@ -612,6 +675,46 @@ public static String generateTokenForCookie(String shoppingCartId, String userAg return token; } + public static void shoppingCart(String client, String uuid, String language){ + ShopDTO shop = ShopDTO.find("byDomain", client).first(); + if (shop == null){ + shop = ShopDTO.find("byDomain", "localhost").first(); + } + + Http.Header acceptLanguage = request.headers.get("accept-language"); + String languageFromHeader = LanguageForShop.getLanguageFromAcceptHeaders(acceptLanguage); + language = LanguageForShop.setLanguageForShop(language, languageFromHeader); + + Translation.setTranslationForShop(language, shop); + shop.pagesList = translatePageList(shop, language); + + String qr_uuid = null; + if (request.params.get("qr_uuid") != null){ + qr_uuid = request.params.get("qr_uuid"); + } + + String selectedCurrency = ""; + if (request.params.get("currency") != null){ + selectedCurrency = request.params.get("currency"); + } + if (selectedCurrency.isEmpty()) { + selectedCurrency = setSelectedCurrency(shop); + } + List categories = shop.getActiveCategories(language); + + System.out.println("selectedCurrency in shopping cart => " + selectedCurrency); + render(shop, language, categories, qr_uuid, selectedCurrency); + } + + private static String setSelectedCurrency(ShopDTO shop) { + CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); + if (currencyShop.selectedCurrency != null && !currencyShop.selectedCurrency.isEmpty()){ + return currencyShop.selectedCurrency; + } else { + return currencyShop.currency; + } + } + public static void orderFeedback(String client, String uuid) { ShopDTO shop = ShopDTO.find("byDomain", client).first(); if (shop == null) { @@ -636,33 +739,6 @@ public static void orderFeedback(String client, String uuid) { renderTemplate("Application/orderFeedback.html", shop, order, isSendRequest, currency, language, shopName); } - public static void shoppingCart(String client, String uuid, String language){ - ShopDTO shop = ShopDTO.find("byDomain", client).first(); - if (shop == null){ - shop = ShopDTO.find("byDomain", "localhost").first(); - } - List pageList = PageConstructorDTO.find("byShop", shop).fetch(); - List translationPageList = new ArrayList(); - for(PageConstructorDTO _page: pageList){ - _page = Translation.setTranslationForPage(language, _page); - translationPageList.add(_page); - } - shop.pagesList = translationPageList; - shop.pagesList = pageList; - Http.Header acceptLanguage = request.headers.get("accept-language"); - String languageFromHeader = LanguageForShop.getLanguageFromAcceptHeaders(acceptLanguage); - language = LanguageForShop.setLanguageForShop(language, languageFromHeader); - Translation.setTranslationForShop(language, shop); - - String qr_uuid = null; - if (request.params.get("qr_uuid") != null){ - qr_uuid = request.params.get("qr_uuid"); - } - - List categories = shop.getActiveCategories(language); - - render(shop, language, categories, qr_uuid); - } public static void done(String client) { ShopDTO shop = ShopDTO.find("byDomain", client).first(); diff --git a/app/controllers/BalanceAPI.java b/app/controllers/BalanceAPI.java index 9613b1e21..68515491f 100644 --- a/app/controllers/BalanceAPI.java +++ b/app/controllers/BalanceAPI.java @@ -15,6 +15,34 @@ public class BalanceAPI extends AuthController { static MailSender mailSender = new MailSenderImpl(); static LiqPayService liqPay = LiqPayServiceImpl.getInstance(); + public static void getCurrencyList(String client) throws Exception { + ShopDTO shop = ShopDTO.find("byDomain", client).first(); + if (shop == null) { + shop = ShopDTO.find("byDomain", "localhost").first(); + } + checkAuthentification(shop); + + if (shop.currencyShop != null) { + renderJSON(json(shop.currencyShop.currencyList)); + } + } + + public static void setCurrency(String client, String currency) throws Exception { + + ShopDTO shop = ShopDTO.find("byDomain", client).first(); + if (shop == null) { + shop = ShopDTO.find("byDomain", "localhost").first(); + } + checkAuthentification(shop); + + if (!currency.isEmpty()){ + shop.currencyShop = Application.setCurrencyToShop(shop); + shop.currencyShop.currency = currency; + shop.currencyShop.save(); + } + + renderJSON(json(shop)); + } public static void getBalance(String client, String email) throws Exception { ShopDTO shop = ShopDTO.find("byDomain", client).first(); diff --git a/app/controllers/OrderAPI.java b/app/controllers/OrderAPI.java index 9d27bcb22..538ea9dc3 100644 --- a/app/controllers/OrderAPI.java +++ b/app/controllers/OrderAPI.java @@ -115,6 +115,9 @@ private static OrderItemListResult _parseOrderItemsList(List items, Or orderItem.additionsList = additionList; orderItem.save(); orderItemList.add(orderItem); + if (product.priceInCurrency != 0) { + product.price = product.priceInCurrency; + } totalCost += product.price * orderItem.quantity; } @@ -128,20 +131,22 @@ private static String getLanguagePartWithoutLocale(String language) { } public static String getTranslatedShopName(ShopDTO shop, String language) { - List translationList = null; - if (shop.shopNameTextTranslationBucket != null) { - translationList = shop.shopNameTextTranslationBucket.translationList; - } else { + if (shop.shopNameTextTranslationBucket == null) { return shop.shopName; - } - TranslationItemDTO adminTranslationItemDTO = translationList.stream().filter(shopTranslate -> shopTranslate.language.equals(language)).collect(Collectors.toList()).get(0); - if (!translationList.isEmpty() && !adminTranslationItemDTO.content.isEmpty()) { + } else { + List translationList = shop.shopNameTextTranslationBucket.translationList; + TranslationItemDTO adminTranslationItemDTO = translationList + .stream() + .filter(shopTranslate -> shopTranslate.language.equals(language)) + .collect(Collectors.toList()).get(0); + return adminTranslationItemDTO.content; } - return shop.shopName; + } public static void create(String client, String chosenLanguage) throws Exception { + String jsonCart = ""; if (request.params.get("cart") != null) { jsonCart = request.params.get("cart"); @@ -169,11 +174,11 @@ public static void create(String client, String chosenLanguage) throws Exception String languageFromAccept = languageList.get(0).getRange(); String[] strings = languageFromAccept.split("-"); clientLanguage = strings[0]; - } - OrderDTO order = new OrderDTO(shoppingCart, shop, agent, ip); + String currency = shop.currencyShop.selectedCurrency != null ? shop.currencyShop.selectedCurrency : shop.currencyShop. currency; + order.currency = currency; order.clientLanguage = clientLanguage; order.chosenClientLanguage = chosenLanguage; order.save(); @@ -242,6 +247,7 @@ public static void create(String client, String chosenLanguage) throws Exception json.put("reason", "Total amount is less than minimum order amount"); error(403, json.toString()); } + order.feedbackRequestState = FeedbackRequestState.REQUEST_NOT_SEND; order = order.save(); @@ -748,6 +754,7 @@ public static void success(String client, String data) throws Exception { } + private static String generateHtmlEmailForOrderPaymentError(ShopDTO shop, OrderDTO order, String changeLanguage) { String templateString = MailSenderImpl.readAllBytesJava7("app/emails/email_notification_payment_error.html"); Template template = Template.parse(templateString); @@ -770,6 +777,7 @@ private static String generateHtmlEmailForOrderPaymentError(ShopDTO shop, OrderD String rendered = template.render(map); return rendered; } + private static String generateHtmlEmailForOrderPaymentDone(ShopDTO shop, OrderDTO order, String changeLanguage) { String templateString = MailSenderImpl.readAllBytesJava7("app/emails/email_notification_payment_done.html"); Template template = Template.parse(templateString); @@ -792,6 +800,7 @@ private static String generateHtmlEmailForOrderPaymentDone(ShopDTO shop, OrderDT String rendered = template.render(map); return rendered; } + private static String generateHtmlEmailForOrderPaymentWaitAccept(ShopDTO shop, OrderDTO order, String changeLanguage) { String templateString = MailSenderImpl.readAllBytesJava7("app/emails/email_notification_payment_wait_accept.html"); Template template = Template.parse(templateString); @@ -814,6 +823,7 @@ private static String generateHtmlEmailForOrderPaymentWaitAccept(ShopDTO shop, O String rendered = template.render(map); return rendered; } + private static String generateHtmlEmailForFeedbackToOrder(ShopDTO shop, OrderDTO order, String changeLanguage) { String templateString = MailSenderImpl.readAllBytesJava7("app/emails/email_feedback_to_order.html"); Template template = Template.parse(templateString); @@ -841,14 +851,13 @@ private static String generateHtmlEmailForFeedbackToOrder(ShopDTO shop, OrderDTO return rendered; } + private static String generateHtmlEmailForNewOrder(ShopDTO shop, OrderDTO order, String language) { Filter.registerFilter(new Filter("total"){ @Override public Object apply(Object value, Object... params) { - DecimalFormat format = new DecimalFormat("0.##"); - return format.format(value); } }); @@ -953,7 +962,7 @@ public Object apply(Object value, Object... params) { String creditCardDeliveryPaymentType = Messages.get("mail.label.creditCardDeliveryPaymentType"); map.put("creditCardDeliveryPaymentType", creditCardDeliveryPaymentType); - String labelCurrencyUah = Messages.get("mail.label.currency.uah"); + String labelCurrencyUah = Messages.get("mail.label.currencyShop.uah"); map.put("labelCurrencyUah", labelCurrencyUah); String rendered = template.render(map); diff --git a/app/controllers/ProductAPI.java b/app/controllers/ProductAPI.java index dbbf6c85f..0458a269d 100644 --- a/app/controllers/ProductAPI.java +++ b/app/controllers/ProductAPI.java @@ -50,7 +50,7 @@ public static void create(String client, String name, String description, } CategoryDTO cat = CategoryDTO.findById(category); - ProductDTO product = new ProductDTO(name, description, price, images, shop, cat, wholesaleCount, wholesalePrice); + ProductDTO product = new ProductDTO(nameUk, descriptionUk, price, images, shop, cat, wholesaleCount, wholesalePrice); product.mainImage = images.get(mainPhotoIndex); product.isActive = isActive; product.sortOrder = sortOrder; diff --git a/app/controllers/ShopAPI.java b/app/controllers/ShopAPI.java index 39b8c9c40..91ebccc10 100644 --- a/app/controllers/ShopAPI.java +++ b/app/controllers/ShopAPI.java @@ -79,6 +79,10 @@ public static void details(String client) throws Exception { // /shop/details shop = ShopDTO.find("byDomain", "localhost").first(); } checkAuthentification(shop); + CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); + if (currencyShop != null) { + shop.currencyShop = currencyShop; + } renderJSON(json(shop)); } diff --git a/app/controllers/UserDashBoardAPI.java b/app/controllers/UserDashBoardAPI.java index 98908614d..fa036a68e 100644 --- a/app/controllers/UserDashBoardAPI.java +++ b/app/controllers/UserDashBoardAPI.java @@ -1,15 +1,12 @@ package controllers; +import jobs.GetDailyCurrency; import models.*; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import play.i18n.Lang; import play.mvc.Before; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.TimeZone; @@ -70,13 +67,19 @@ public static void createShop() throws Exception{ BalanceDTO balance = new BalanceDTO(); VisualSettingsDTO visualSettings = new VisualSettingsDTO(); + CurrencyShopDTO currencyShop = new CurrencyShopDTO(); + currencyShop.currency = user.wizard.shopCurrency; + ShopDTO shop = new ShopDTO(users, paymentSettings, delivery, contact, balance, visualSettings, user.wizard.shopName, - "public liqpay key here", "private liqpay key here", user.wizard.shopDomain, "uk_UA" - ); + "public liqpay key here", "private liqpay key here", user.wizard.shopDomain, + "uk_UA"); shop.googleStaticMapsApiKey = "AIzaSyCcBhIqH-XMcNu99hnEKvWIZTrazd9XgXg"; shop.googleMapsApiKey = "AIzaSyAuKg9jszEEgoGfUlIqmd4n9czbQsgcYRM"; visualSettings.shop = shop; + currencyShop.shop = shop; + shop.currencyShop = currencyShop; + currencyShop.save(); _appendDomainToList(user.wizard.shopDomain); shop.save(); @@ -84,6 +87,7 @@ public static void createShop() throws Exception{ } + private static void setTranslationForCashPaymentLabel(PaymentSettingsDTO payment) { if (payment.manualPaymentTitleTranslationBucket == null){ System.out.println("delivery.selfTakeTranslationBucket is null and will be creating NEW"); diff --git a/app/controllers/WayForPayAPI.java b/app/controllers/WayForPayAPI.java index 95cd28602..3199030cd 100644 --- a/app/controllers/WayForPayAPI.java +++ b/app/controllers/WayForPayAPI.java @@ -74,9 +74,6 @@ public WayForPayRequestParams(String merchantAccount, String merchantDomainName, this.serviceUrl = serviceUrl; } - - - } static String merchantAccount = "wisehands_me"; @@ -176,6 +173,7 @@ public static void generateSignatureWayForPay(String client) throws Exception{ ShopDTO shop = ShopDTO.findById(shopUuid); String productName = "Поповнення власного рахунку для магазину " + shop.shopName; + // TODO check url String serviceUrl = "https://wstore.pro/wayforpay/payment-confirmation"; Double amount = Double.valueOf(request.params.get("amount")); String formatDecimal = formatDecimal(amount); diff --git a/app/controllers/WizardAPI.java b/app/controllers/WizardAPI.java index 3b8694f88..116a4a6f7 100644 --- a/app/controllers/WizardAPI.java +++ b/app/controllers/WizardAPI.java @@ -146,6 +146,11 @@ public static void setVariantsOfDeliveryAndPaymentTypes() throws Exception{ boolean courierDelivery = (boolean) jsonBody.get("courierDelivery"); boolean postDepartment = (boolean) jsonBody.get("postDepartment"); boolean selfTake = (boolean) jsonBody.get("selfTake"); + + boolean uah = (boolean) jsonBody.get("uahCurrency"); + boolean usd = (boolean) jsonBody.get("usdCurrency"); + boolean eur = (boolean) jsonBody.get("eurCurrency"); + boolean payCash = true; boolean payOnline = false; @@ -159,12 +164,23 @@ public static void setVariantsOfDeliveryAndPaymentTypes() throws Exception{ user.wizard.selfTake = selfTake; user.wizard.payCash = payCash; user.wizard.payOnline = payOnline; + user.wizard.shopCurrency = setCurrencyToShop(uah, usd, eur); user.wizard.save(); renderJSON(json(user.wizard)); } + private static String setCurrencyToShop(boolean uah, boolean usd, boolean eur) { + if (uah){ + return "UAH"; + } else if (usd) { + return "USD"; + } else { + return "EUR"; + } + } + public static void setSocialNetworkInfo() throws Exception{ String facebookLink = request.params.get("facebook"); diff --git a/app/jobs/AdditionalSettingForShop.java b/app/jobs/AdditionalSettingForShop.java index 3b197f963..e29f96748 100644 --- a/app/jobs/AdditionalSettingForShop.java +++ b/app/jobs/AdditionalSettingForShop.java @@ -14,38 +14,38 @@ public AdditionalSettingForShop(){ } - public void setWorkkingTime(ShopDTO shop){ + public void setWorkingTime(ShopDTO shop){ if(shop.monStartTime == null) { - shop.monStartTime = "1970-01-01T05:00:00.000Z"; - shop.monEndTime = "1970-01-01T15:00:00.000Z"; + shop.monStartTime = "04:20"; + shop.monEndTime = "16:21"; } if(shop.tueStartTime == null) { - shop.tueStartTime = "1970-01-01T05:00:00.000Z"; - shop.tueEndTime = "1970-01-01T15:00:00.000Z"; + shop.tueStartTime = "04:20"; + shop.tueEndTime = "16:21"; } if(shop.wedStartTime == null) { - shop.wedStartTime = "1970-01-01T05:00:00.000Z"; - shop.wedEndTime = "1970-01-01T15:00:00.000Z"; + shop.wedStartTime = "04:20"; + shop.wedEndTime = "16:21"; } if(shop.thuStartTime == null) { - shop.thuStartTime = "1970-01-01T05:00:00.000Z"; - shop.thuEndTime = "1970-01-01T15:00:00.000Z"; + shop.thuStartTime = "04:20"; + shop.thuEndTime = "16:21"; } if(shop.friStartTime == null) { - shop.friStartTime = "1970-01-01T05:00:00.000Z"; - shop.friEndTime = "1970-01-01T15:00:00.000Z"; + shop.friStartTime = "04:20"; + shop.friEndTime = "16:21"; } if(shop.satStartTime == null) { - shop.satStartTime = "1970-01-01T05:00:00.000Z"; - shop.satEndTime = "1970-01-01T15:00:00.000Z"; + shop.satStartTime = "04:20"; + shop.satEndTime = "16:21"; } if(shop.sunStartTime == null) { - shop.sunStartTime = "1970-01-01T05:00:00.000Z"; - shop.sunEndTime = "1970-01-01T15:00:00.000Z"; + shop.sunStartTime = "04:20"; + shop.sunEndTime = "16:21"; } } diff --git a/app/jobs/GetDailyCurrency.java b/app/jobs/GetDailyCurrency.java new file mode 100644 index 000000000..3e80dd2b0 --- /dev/null +++ b/app/jobs/GetDailyCurrency.java @@ -0,0 +1,116 @@ +package jobs; +import models.CurrencyDTO; +import models.CurrencyShopDTO; +import models.ShopDTO; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import play.jobs.Every; +import play.jobs.Job; +import play.libs.WS; + +import java.util.List; + +@Every("6h") +public class GetDailyCurrency extends Job { + + public void doJob() throws Exception { + + WS.HttpResponse firstCurrencyResponse = WS.url("https://api.privatbank.ua/p24api/pubinfo?exchange&json&coursid=11").get(); + // TODO get PZt from second array and add to first array + WS.HttpResponse secondCurrencyResponseGetPlz = WS.url("https://api.privatbank.ua/p24api/pubinfo?exchange&json&coursid=12").get(); + + String currencyJson = firstCurrencyResponse.getString(); + String currencyPlzJson = secondCurrencyResponseGetPlz.getString(); + System.out.println("currencyJson => " + currencyJson); + System.out.println("currencyPlzJson => " + currencyPlzJson); + + + if (!currencyJson.isEmpty() || !currencyPlzJson.isEmpty()){ + JSONParser parser = new JSONParser(); + JSONArray currencyJsonArray = (JSONArray) parser.parse(currencyJson); + JSONArray currencyPLZJsonArray = (JSONArray) parser.parse(currencyPlzJson); + + List shopList = ShopDTO.findAll(); + for (ShopDTO shop : shopList){ + setCurrencyListToShop(shop, currencyJsonArray, currencyPLZJsonArray); + } + } + + } + + private void setCurrencyListToShop(ShopDTO shop, JSONArray currencyJsonArray, JSONArray currencyPLZJsonArray) { + CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); + if (currencyShop == null){ + currencyShop = new CurrencyShopDTO(shop); + currencyShop.save(); + shop.save(); + } + if (currencyShop.currencyList.isEmpty()) { + for (Object object : currencyJsonArray) { + JSONObject jsonObject = (JSONObject) object; + currencyShop.addCurrency(getCurrency(jsonObject)); + } + CurrencyDTO currencyPlz = getPlzCurrency(currencyPLZJsonArray); + currencyShop.addCurrency(currencyPlz); + System.out.println("currencyList in job isEmpty => " + currencyShop.currencyList); + + } else { + for (int i = 0; i < currencyJsonArray.size(); i++) { + JSONObject jsonObject = (JSONObject) currencyJsonArray.get(i); + updateCurrency(jsonObject, currencyShop.currencyList.get(i)); + } + updatePlzCurrency(currencyPLZJsonArray, currencyShop); + System.out.println("currencyList in job is full => " + currencyShop.currencyList); + } + currencyShop.save(); + } + + private void updatePlzCurrency(JSONArray currencyPLZJsonArray, CurrencyShopDTO currencyShop) { + for (Object object : currencyPLZJsonArray) { + JSONObject jsonObject = (JSONObject) object; + if(jsonObject.get("ccy").equals("PLZ")){ + CurrencyDTO currency = CurrencyDTO.find("byCcy", "PLZ").first(); + updateCurrency(jsonObject, currency); + } + } + } + + private CurrencyDTO getPlzCurrency(JSONArray currencyPLZJsonArray) { + CurrencyDTO currency = null; + for (Object object : currencyPLZJsonArray) { + JSONObject jsonObject = (JSONObject) object; + if (jsonObject.get("ccy").equals("PLZ")) currency = getCurrency(jsonObject); + } + return currency; + } + + private CurrencyDTO updateCurrency(JSONObject jsonObject, CurrencyDTO currency) { + + String ccy = (String) jsonObject.get("ccy"); + String baseCurrency = (String) jsonObject.get("base_ccy"); + double buy = Double.parseDouble((String) jsonObject.get("buy")); + double sale = Double.parseDouble((String) jsonObject.get("sale")); + + currency.ccy = ccy; + currency.base_ccy = baseCurrency; + currency.buy = buy; + currency.sale = sale; + currency.save(); + return currency; + + } + + private CurrencyDTO getCurrency(JSONObject jsonObject) { + + String ccy = (String) jsonObject.get("ccy"); + String baseCurrency = (String) jsonObject.get("base_ccy"); + double buy = Double.parseDouble((String) jsonObject.get("buy")); + double sale = Double.parseDouble((String) jsonObject.get("sale")); + + CurrencyDTO currency = new CurrencyDTO(ccy, baseCurrency, buy, sale); + currency.save(); + return currency; + } + +} diff --git a/app/jobs/MonthlyFee.java b/app/jobs/MonthlyFee.java index 0f96b7002..2a8d1d63e 100644 --- a/app/jobs/MonthlyFee.java +++ b/app/jobs/MonthlyFee.java @@ -20,9 +20,6 @@ public class MonthlyFee extends Job { public void doJob() throws Exception { System.out.println("MonthlyFee job"); - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); - - Calendar calendar = Calendar.getInstance(); // this takes current date calendar.set(Calendar.DAY_OF_MONTH, 1); @@ -37,34 +34,16 @@ public void doJob() throws Exception { List shopList = ShopDTO.findAll(); for (ShopDTO shop : shopList){ if (shop.pricingPlan != null){ - CoinAccountDTO coinAccount = CoinAccountDTO.find("byShop", shop).first(); - if(coinAccount == null) { - coinAccount = new CoinAccountDTO(shop); - coinAccount = coinAccount.save(); - } - CoinTransactionDTO transaction = new CoinTransactionDTO(); - transaction.type = TransactionType.MONTHLY_FEE; - transaction.status = TransactionStatus.OK; - transaction.account = coinAccount; - transaction.amount = -shop.pricingPlan.monthlyFee; - transaction.time = System.currentTimeMillis() / 1000L; - coinAccount.addTransaction(transaction); - coinAccount.balance += transaction.amount; - transaction.transactionBalance = coinAccount.balance; - transaction.save(); - coinAccount.save(); - System.out.println("paid a monthly fee!!!!!!!!!!!"); + setPricingPlan(shop); } } } } - public void getMonthlyFee(ShopDTO shop) { + public void setPricingPlan(ShopDTO shop) { CoinAccountDTO coinAccount = CoinAccountDTO.find("byShop", shop).first(); - Double commissionFee = shop.pricingPlan.commissionFee; - if(coinAccount == null) { coinAccount = new CoinAccountDTO(shop); coinAccount = coinAccount.save(); @@ -73,12 +52,14 @@ public void getMonthlyFee(ShopDTO shop) { transaction.type = TransactionType.MONTHLY_FEE; transaction.status = TransactionStatus.OK; transaction.account = coinAccount; - transaction.amount = -commissionFee; + transaction.amount = -shop.pricingPlan.monthlyFee; transaction.time = System.currentTimeMillis() / 1000L; - transaction = transaction.save(); coinAccount.addTransaction(transaction); coinAccount.balance += transaction.amount; + transaction.transactionBalance = coinAccount.balance; + transaction.save(); coinAccount.save(); + System.out.println("paid a monthly fee!!!!!!!!!!!"); } diff --git a/app/jobs/WisehandsSetup.java b/app/jobs/WisehandsSetup.java index 03377cfc7..381ce6c3c 100644 --- a/app/jobs/WisehandsSetup.java +++ b/app/jobs/WisehandsSetup.java @@ -44,7 +44,7 @@ public void doJob() throws Exception { boolean hasPages = listsPage.size() != 0; AdditionalSettingForShop additionalSettingForShop = new AdditionalSettingForShop(); - additionalSettingForShop.setWorkkingTime(shop); + additionalSettingForShop.setWorkingTime(shop); shop = shop.save(); if (!hasPages){ additionalSettingForShop.setPageListForFooter(shop); diff --git a/app/json/shoppingcart/CurrencyShopConfiguration.java b/app/json/shoppingcart/CurrencyShopConfiguration.java new file mode 100644 index 000000000..dc387bd39 --- /dev/null +++ b/app/json/shoppingcart/CurrencyShopConfiguration.java @@ -0,0 +1,22 @@ +package json.shoppingcart; + +import com.google.gson.annotations.Expose; +import models.CurrencyDTO; + +import java.util.List; + +public class CurrencyShopConfiguration { + + @Expose + public String currency; + + @Expose + public List currencyList; + + public CurrencyShopConfiguration(String currency, List currencyList){ + this.currency = currency; + this.currencyList = currencyList; + } + + +} diff --git a/app/json/shoppingcart/PaymentConfiguration.java b/app/json/shoppingcart/PaymentConfiguration.java index 1fce8f222..946bb4727 100644 --- a/app/json/shoppingcart/PaymentConfiguration.java +++ b/app/json/shoppingcart/PaymentConfiguration.java @@ -14,13 +14,19 @@ public class PaymentConfiguration { @Transient public PaymentCreditCardConfiguration creditCard; + @Expose + @Transient + public CurrencyShopConfiguration currencyShop; + @Expose Double minimumPaymentForOrder; - public PaymentConfiguration(PaymentCashConfiguration cash, PaymentCreditCardConfiguration creditCard, Double minimumPaymentForOrder){ + public PaymentConfiguration(PaymentCashConfiguration cash, PaymentCreditCardConfiguration creditCard, + Double minimumPaymentForOrder, CurrencyShopConfiguration currencyShop){ this.cash = cash; this.creditCard = creditCard; this.minimumPaymentForOrder = minimumPaymentForOrder; + this.currencyShop = currencyShop; } } diff --git a/app/models/AdditionDTO.java b/app/models/AdditionDTO.java index 32661406e..cc2065466 100644 --- a/app/models/AdditionDTO.java +++ b/app/models/AdditionDTO.java @@ -3,6 +3,7 @@ import com.google.gson.annotations.Expose; import org.hibernate.annotations.GenericGenerator; import play.db.jpa.GenericModel; +import services.querying.DataBaseQueries; import javax.persistence.*; @@ -21,6 +22,9 @@ public class AdditionDTO extends GenericModel { @Expose public Double price; + @Expose + public Double priceInCurrency = 0.0; + @Expose public String imagePath; @@ -33,27 +37,19 @@ public class AdditionDTO extends GenericModel { @Expose @OneToOne(cascade=CascadeType.ALL) public TranslationBucketDTO additionNameTranslationBucket; + + public AdditionDTO(){} public String getTitle() { return title; } - public Double getPrice() { - return price; + public Double getRightPrice() { + return this.priceInCurrency != 0 ? this.priceInCurrency : this.price; } - + public String getImagePath() { return imagePath; } - public String formatDecimal() { - Double number = this.price; - float epsilon = 0.004f; // 4 tenths of a cent - if (Math.abs(Math.round(number) - number) < epsilon) { - return String.format("%10.0f", number); // sdb - } else { - return String.format("%10.2f", number); // dj_segfault - } - } - } diff --git a/app/models/CategoryDTO.java b/app/models/CategoryDTO.java index eab57a554..b3f9b34d6 100644 --- a/app/models/CategoryDTO.java +++ b/app/models/CategoryDTO.java @@ -49,5 +49,18 @@ public CategoryDTO(ShopDTO shop, String name, String description) { this.description = description; } + public String getLinkToCategoryPage(String uuid, String language, String qr_uuid, String selectedCurrency){ + String link = "/" + language +"/category/" + uuid; + if (!qr_uuid.isEmpty() && !selectedCurrency.isEmpty()){ + return link + "?qr_uuid=" + qr_uuid + "¤cy=" + selectedCurrency; + } else if (!qr_uuid.isEmpty() && selectedCurrency.isEmpty()) { + return link + "?qr_uuid=" + qr_uuid; + } else if (!selectedCurrency.isEmpty() && qr_uuid.isEmpty()) { + return link + "?currency=" + selectedCurrency; + } else { + return link; + } + } + } diff --git a/app/models/CurrencyDTO.java b/app/models/CurrencyDTO.java new file mode 100644 index 000000000..f7a432bdd --- /dev/null +++ b/app/models/CurrencyDTO.java @@ -0,0 +1,40 @@ +package models; + +import com.google.gson.annotations.Expose; +import org.hibernate.annotations.GenericGenerator; +import play.db.jpa.GenericModel; + +import javax.persistence.*; + +@Entity +public class CurrencyDTO extends GenericModel { + + @Id + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + @Expose + public String uuid; + + @Expose + public String ccy; + + @Expose + public String base_ccy; + + @Expose + public double buy; + + @Expose + public double sale; + + @ManyToOne + public CurrencyShopDTO currencyShop; + + public CurrencyDTO(String ccy, String base_ccy, double buy, double sale){ + this.ccy = ccy; + this.base_ccy = base_ccy; + this.buy = buy; + this.sale = sale; + } + +} diff --git a/app/models/CurrencyShopDTO.java b/app/models/CurrencyShopDTO.java new file mode 100644 index 000000000..c68574c69 --- /dev/null +++ b/app/models/CurrencyShopDTO.java @@ -0,0 +1,73 @@ +package models; + +import com.google.gson.annotations.Expose; +import org.hibernate.annotations.GenericGenerator; +import play.db.jpa.GenericModel; +import util.CurrencySign; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +import static org.codehaus.groovy.runtime.DefaultGroovyMethods.round; + +@Entity +public class CurrencyShopDTO extends GenericModel { + + @Id + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + @Expose + public String uuid; + + @Expose + public String currency; + + @Expose + public String selectedCurrency = ""; + + @OneToOne(cascade=CascadeType.ALL) + public ShopDTO shop; + + @Expose + @OneToMany(cascade=CascadeType.ALL) + public List currencyList; + + public void addCurrency(CurrencyDTO currency){ + if (this.currencyList == null){ + this.currencyList = new ArrayList(); + } + this.currencyList.add(currency); + } + + public CurrencyShopDTO() { } + + public CurrencyShopDTO(ShopDTO shop) { + this.shop = shop; + this.currency = "UAH"; + this.currencyList = new ArrayList(); + } + + public String currencyFormat(String currencyValue) { + if (currencyValue.isEmpty()) { + currencyValue = this.currency; + } + System.out.println("currencyFormat in currencyShopDTO => " + currencyValue); + + return new CurrencySign().currencySigns.get(currencyValue); + } + + public String showCurrency(){ + return this.selectedCurrency == null || this.selectedCurrency.isEmpty() ? this.currency : this.selectedCurrency; + } + + public boolean isDefaultCurrencyNotEqualSelectedCurrency(String selectedCurrency){ + if (selectedCurrency.isEmpty()) { + return false; + } else { + return !(this.currency.equals(selectedCurrency)); + } + + } + +} diff --git a/app/models/OrderDTO.java b/app/models/OrderDTO.java index 8984302b7..60dfd0bc2 100644 --- a/app/models/OrderDTO.java +++ b/app/models/OrderDTO.java @@ -67,6 +67,9 @@ public class OrderDTO extends GenericModel { @Expose public Double total; + @Expose + public String currency; + @Expose public String comment; diff --git a/app/models/ProductDTO.java b/app/models/ProductDTO.java index b839ad1b4..437d3255f 100644 --- a/app/models/ProductDTO.java +++ b/app/models/ProductDTO.java @@ -4,10 +4,14 @@ import org.hibernate.annotations.GenericGenerator; import play.db.jpa.GenericModel; + import javax.persistence.*; + import java.util.ArrayList; import java.util.List; +import static org.codehaus.groovy.runtime.DefaultGroovyMethods.round; + @Entity public class ProductDTO extends GenericModel { @Id @@ -32,6 +36,9 @@ public class ProductDTO extends GenericModel { @Expose public Double priceWithAdditions; + @Expose + public double priceInCurrency; + @Expose public Double priceOfDay = 0D; @@ -79,12 +86,14 @@ public class ProductDTO extends GenericModel { public List images; @Expose - @OneToMany - public List selectedAdditions; + @OneToMany(mappedBy = "product") + @Column(columnDefinition = "varchar(255) null default null") + public List selectedAdditions = null; @Expose - @OneToMany(cascade = CascadeType.ALL) - public List defaultAdditions; + @OneToMany(mappedBy = "product") + @Column(columnDefinition = "varchar(255) null default null") + public List defaultAdditions = null; @Expose @OneToMany(cascade = CascadeType.ALL) @@ -127,30 +136,60 @@ public ProductDTO(String name, String description, Double price, List 0) number = this.priceOfDay; if(this.priceWithAdditions != null) number = number + this.priceWithAdditions; + return _roundAvoid(number, 2); // sdb + } - float epsilon = 0.004f; // 4 tenths of a cent - if (Math.abs(Math.round(number) - number) < epsilon) { - return String.format("%10.0f", number); // sdb + public double formatPrice(String currency, String selectedCurrency) { + boolean isSelectedCurrencyEqualShopCurrency = false; + if (selectedCurrency != null){ + isSelectedCurrencyEqualShopCurrency = selectedCurrency.equals(currency); + } + if (selectedCurrency == null || selectedCurrency.isEmpty()){ + return _formatPrice(); + } else if (isSelectedCurrencyEqualShopCurrency){ + return _formatPrice(); } else { - return String.format("%10.2f", number); // dj_segfault + return round(this.priceInCurrency + this.priceWithAdditions, 2); } } - public String formatDecimalOldPrice() { - Double number = this.oldPrice; - if (number != null) { - float epsilon = 0.004f; // 4 tenths of a cent - if (Math.abs(Math.round(number) - number) < epsilon) { - return String.format("%10.0f", number) + " " + "uah"; // sdb - } else { - return String.format("%10.2f", number) + " " + "uah"; // dj_segfault - } + public static double _roundAvoid(double value, int places) { + double scale = Math.pow(10, places); + return Math.round(value * scale) / scale; + } + + + + public double formatDecimalOldPrice() { + double price = this.oldPrice != null ? this.oldPrice : 0; + return _roundAvoid(price, 2); + } + + public String getLinkToProductPage(ProductDTO product, String language, String qr_uuid, String selectedCurrency){ + String link = "/" + language +"/product/" + product.uuid; + if (!qr_uuid.isEmpty() && !selectedCurrency.isEmpty()){ + return link + "?qr_uuid=" + qr_uuid + "¤cy=" + selectedCurrency; + } else if (!qr_uuid.isEmpty() && selectedCurrency.isEmpty()) { + return link + "?qr_uuid=" + qr_uuid; + } else if (!selectedCurrency.isEmpty() && qr_uuid.isEmpty()) { + return link + "?currency=" + selectedCurrency; + } else { + return link; } - return ""; } + + + } diff --git a/app/models/SelectedAdditionDTO.java b/app/models/SelectedAdditionDTO.java index 6bb6d4bc7..7099ff2de 100644 --- a/app/models/SelectedAdditionDTO.java +++ b/app/models/SelectedAdditionDTO.java @@ -24,6 +24,10 @@ public class SelectedAdditionDTO extends GenericModel { @Expose public boolean isSelected = false; + @ManyToOne + @JoinColumn(name="product_uuid") + private ProductDTO product; + @Expose @OneToOne(cascade=CascadeType.ALL) public AdditionDTO addition; diff --git a/app/models/ShopDTO.java b/app/models/ShopDTO.java index c42a9c67a..eaf1cbd9d 100644 --- a/app/models/ShopDTO.java +++ b/app/models/ShopDTO.java @@ -124,6 +124,10 @@ public class ShopDTO extends GenericModel { @Expose public String locale; + @Expose + @OneToOne(cascade=CascadeType.ALL) + public CurrencyShopDTO currencyShop; + @Expose @OneToOne(cascade=CascadeType.ALL) public BannerDTO banner; diff --git a/app/models/ShoppingCartDTO.java b/app/models/ShoppingCartDTO.java index 1cf8d3ef9..c63d07f72 100644 --- a/app/models/ShoppingCartDTO.java +++ b/app/models/ShoppingCartDTO.java @@ -7,6 +7,8 @@ import javax.persistence.*; import java.util.List; +import static services.querying.DataBaseQueries.exchangePrice; + @Entity public class ShoppingCartDTO extends GenericModel { @@ -71,13 +73,17 @@ public enum PaymentType { public ShoppingCartDTO() { } - public ShoppingCartDTO(DeliveryType deliveryType, PaymentType paymentType, List items, - ShoppingCartClientInfo client, ShoppingCartConfiguration configuration, - String clientName, String clientPhone, String clientEmail, String clientComments, - String clientAddressStreetName, String clientAddressBuildingNumber, String clientAddressApartmentNumber, - String clientAddressApartmentFloor, String clientAddressApartmentEntrance, - String clientAddressApartmentEntranceCode, String clientCity, String clientPostDepartmentNumber, - String clientAddressStreetLat, String clientAddressStreetLng, Boolean clientAddressGpsPointInsideDeliveryBoundaries) { + + public ShoppingCartDTO(DeliveryType deliveryType, PaymentType paymentType, + List items, ShoppingCartClientInfo client, + ShoppingCartConfiguration configuration, String clientName, + String clientPhone, String clientEmail, String clientComments, + String clientAddressStreetName, String clientAddressBuildingNumber, + String clientAddressApartmentNumber, String clientAddressApartmentFloor, + String clientAddressApartmentEntrance, String clientAddressApartmentEntranceCode, + String clientCity, String clientPostDepartmentNumber, String clientAddressStreetLat, + String clientAddressStreetLng, Boolean clientAddressGpsPointInsideDeliveryBoundaries) { + this.deliveryType = deliveryType; this.paymentType = paymentType; this.items = items; @@ -117,10 +123,12 @@ public void formatObject() { ShopDTO shop = ShopDTO.find("byUuid", this.shopUuid).first(); + String selectedCurrency = shop.currencyShop.selectedCurrency != null ? shop.currencyShop.selectedCurrency : ""; + Double courierPrice = exchangePrice(shop.delivery.courierPrice, shop, selectedCurrency); DeliveryCourierConfiguration courier = new DeliveryCourierConfiguration(shop.delivery.courierText, shop.delivery.isCourierAvailable, - shop.delivery.courierFreeDeliveryLimit, shop.delivery.courierPrice, + shop.delivery.courierFreeDeliveryLimit, courierPrice, shop.delivery.courierTextTranslationBucket); DeliverySelfTakeConfiguration selfTake = new DeliverySelfTakeConfiguration(shop.delivery.selfTakeText, shop.delivery.isSelfTakeAvailable, @@ -136,7 +144,8 @@ public void formatObject() { PaymentCreditCardConfiguration creditCard = new PaymentCreditCardConfiguration(shop.paymentSettings.onlinePaymentTitle, shop.paymentSettings.onlinePaymentEnabled, shop.paymentSettings.clientPaysProcessingCommission, shop.paymentSettings.onlinePaymentTitleTranslationBucket); - PaymentConfiguration payment = new PaymentConfiguration(cash, creditCard, shop.paymentSettings.minimumPayment); + CurrencyShopConfiguration currencyShop = new CurrencyShopConfiguration(shop.currencyShop.currency, shop.currencyShop.currencyList); + PaymentConfiguration payment = new PaymentConfiguration(cash, creditCard, shop.paymentSettings.minimumPayment, currencyShop); AdditionalConfiguration additionalConfiguration = new AdditionalConfiguration(shop.labelNameForBuyerNameFieldInShoppingCart, new VisualSettingsDTO(shop.visualSettingsDTO.isBannerOn, shop.visualSettingsDTO.bannerName, shop.visualSettingsDTO.bannerDescription)); @@ -145,4 +154,5 @@ public void formatObject() { this.configuration = configuration; } + } diff --git a/app/models/WizardDTO.java b/app/models/WizardDTO.java index f939908d9..6c7feb4c2 100644 --- a/app/models/WizardDTO.java +++ b/app/models/WizardDTO.java @@ -50,6 +50,9 @@ public class WizardDTO extends GenericModel { @Expose public boolean payCash; + @Expose + public String shopCurrency; + @Expose public String facebookLink; diff --git a/app/services/LiqPayServiceImpl.java b/app/services/LiqPayServiceImpl.java index 0435a2d98..ca80f9d7e 100644 --- a/app/services/LiqPayServiceImpl.java +++ b/app/services/LiqPayServiceImpl.java @@ -2,6 +2,7 @@ import com.liqpay.LiqPay; import models.BalanceTransactionDTO; +import models.CurrencyShopDTO; import models.OrderDTO; import models.ShopDTO; @@ -20,26 +21,44 @@ public static LiqPayService getInstance() { } public String payButton(OrderDTO order, ShopDTO shop){ + String currency = getCurrencyFromShop(shop); + System.out.println("LiqPayService currency => " + currency); + HashMap params = new HashMap(); params.put("action", "pay"); params.put("amount", order.total); - params.put("currency", "UAH"); + params.put("currencyShop", currency); params.put("description", "New Order"); params.put("order_id", order.uuid); + // sandbox need for testing + params.put("sandbox", "1"); LiqPay liqpay = new LiqPay(shop.liqpayPublicKey, shop.liqpayPrivateKey); return liqpay.cnb_form(params); - }; + } public String payForService(BalanceTransactionDTO balanceTransaction, ShopDTO shop){ + String currency = getCurrencyFromShop(shop); + System.out.println("payForService => " + currency); HashMap params = new HashMap(); params.put("action", "pay"); params.put("amount", balanceTransaction.amount); - params.put("currency", "UAH"); + params.put("currencyShop", currency); params.put("description", "Balance transaction for " + shop.shopName); params.put("order_id", balanceTransaction.uuid); LiqPay liqpay = new LiqPay(WISEHANDS_PUBLIC_KEY, WISEHANDS_PRIVATE_KEY); return liqpay.cnb_form(params); - }; + } + + private String getCurrencyFromShop(ShopDTO shop) { + CurrencyShopDTO currency = CurrencyShopDTO.find("byShop", shop).first(); + if(currency.selectedCurrency.isEmpty()){ + return currency.currency; + } else { + return currency.selectedCurrency; + } + } + + } diff --git a/app/services/MailSenderImpl.java b/app/services/MailSenderImpl.java index cb114c5d0..8199c40be 100644 --- a/app/services/MailSenderImpl.java +++ b/app/services/MailSenderImpl.java @@ -60,7 +60,7 @@ public void sendEmailLowShopBalance(ShopDTO shop, String status) throws Exceptio String shopBalanceLabel = Messages.get("shop.balance"); map.put("shopBalanceLabel", shopBalanceLabel); - String currencyLabel = Messages.get("shop.balance.currency"); + String currencyLabel = Messages.get("shop.balance.currencyShop"); map.put("currencyLabel", currencyLabel); String loginLabel = Messages.get("shop.login"); diff --git a/app/services/ShopServiceImpl.java b/app/services/ShopServiceImpl.java index 36ae698d3..384853f09 100644 --- a/app/services/ShopServiceImpl.java +++ b/app/services/ShopServiceImpl.java @@ -69,7 +69,7 @@ public ShopDTO createShop(String name, String domain, UserDTO user) { shop.googleMapsApiKey = WISEHANDS_MAPS_KEY; AdditionalSettingForShop additionalSettingForShop = new AdditionalSettingForShop(); - additionalSettingForShop.setWorkkingTime(shop); + additionalSettingForShop.setWorkingTime(shop); shop = shop.save(); additionalSettingForShop.setPageListForFooter(shop); diff --git a/app/services/ShoppingCartService.java b/app/services/ShoppingCartService.java index a59b284b9..1f40d078f 100644 --- a/app/services/ShoppingCartService.java +++ b/app/services/ShoppingCartService.java @@ -67,10 +67,10 @@ public static String getCart(String client) { public static String addProduct(String client) throws ParseException { ShopDTO shop = _getShop(client); - String qrUuid = request.params.get("qr_uuid"); String productUuid = request.params.get("uuid"); ProductDTO product = ProductDTO.findById(productUuid); + String qrUuid = request.params.get("qr_uuid"); List defaultAdditions = new ArrayList<>(); if(qrUuid == null || qrUuid.isEmpty()){ defaultAdditions = DataBaseQueries.checkIsAdditionDefaultToProduct(product); @@ -103,11 +103,18 @@ public static String addProduct(String client) throws ParseException { System.out.println("shoppingCart: " + shoppingCart); String stringAdditionList = request.params.get("additionList"); - List additionOrderDTOList = _createAdditionListOrderDTO(stringAdditionList, shop, defaultAdditions, languageFromHeader); + + List additionOrderDTOList = _createAdditionListOrderDTO(product, stringAdditionList, shop, defaultAdditions, languageFromHeader); String quantityParam = request.params.get("quantity"); int quantity = _getProductQuantity(quantityParam); + boolean isCurrencyPresent = shop.currencyShop.selectedCurrency != null && !shop.currencyShop.selectedCurrency.isEmpty(); + if (isCurrencyPresent){ + product.price = product.priceInCurrency; + } + double price = (product.priceOfDay != null && product.priceOfDay > 0) ? product.priceOfDay : product.price; + LineItem lineItem = new LineItem( product.uuid, product.name, product.mainImage.filename, quantity, price, shop, additionOrderDTOList, @@ -147,9 +154,10 @@ private static int _getProductQuantity(String quantityParam) { return quantity; } - private static List _createAdditionListOrderDTO(String stringAdditionList, ShopDTO shop, + private static List _createAdditionListOrderDTO(ProductDTO product, String stringAdditionList, ShopDTO shop, List defaultAdditions, String languageFromHeader){ + if (stringAdditionList == null){ stringAdditionList = "[]"; } @@ -172,7 +180,7 @@ private static List _createAdditionListOrderDTO(String stri AdditionDTO additionDTO = AdditionDTO.findById(object.get("uuid")); AdditionLineItemDTO additionLineItem = new AdditionLineItemDTO(); additionLineItem.title = additionDTO.getTitle(); - additionLineItem.price = additionDTO.getPrice(); + additionLineItem.price = additionDTO.getRightPrice(); additionLineItem.imagePath = _getWholePath(String.valueOf(additionDTO.getImagePath()), shop); additionLineItem.quantity = (Long) object.get("quantity"); if (additionDTO.additionNameTranslationBucket != null){ @@ -189,7 +197,7 @@ private static List _createAdditionListOrderDTO(String stri AdditionDTO additionDTO = AdditionDTO.findById(selectedAddition.addition.uuid); AdditionLineItemDTO additionLineItem = new AdditionLineItemDTO(); additionLineItem.title = additionDTO.getTitle(); - additionLineItem.price = additionDTO.getPrice(); + additionLineItem.price = additionDTO.getRightPrice(); additionLineItem.imagePath = _getWholePath(String.valueOf(additionDTO.getImagePath()), shop); additionLineItem.quantity = 1L; if (additionDTO.additionNameTranslationBucket != null){ diff --git a/app/services/SmsSenderImpl.java b/app/services/SmsSenderImpl.java index e81f1abce..46a282be0 100644 --- a/app/services/SmsSenderImpl.java +++ b/app/services/SmsSenderImpl.java @@ -49,7 +49,6 @@ public String sendSms(String phone, String text) throws Exception { } sum.append(PRIVATE_KEY); - MessageDigest md = MessageDigest.getInstance("MD5"); md.update(sum.toString().getBytes()); diff --git a/app/services/querying/DataBaseQueries.java b/app/services/querying/DataBaseQueries.java index 6a8882d0a..5de9ecd9c 100644 --- a/app/services/querying/DataBaseQueries.java +++ b/app/services/querying/DataBaseQueries.java @@ -1,18 +1,188 @@ package services.querying; -import models.AdditionDTO; import models.FeedbackDTO; import models.ProductDTO; import models.SelectedAdditionDTO; + +import models.*; + import play.db.jpa.JPA; import java.util.ArrayList; import java.util.List; +import static org.codehaus.groovy.runtime.DefaultGroovyMethods.round; + public class DataBaseQueries { + public static double exchangePrice(double price, ShopDTO shop, String selectedCurrency) { + CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); + if (currencyShop == null) { + return price; + } + else if (selectedCurrency.isEmpty()){ + return price; + } else { + boolean isSelectedCurrencyNotEqualShopCurrency = !currencyShop.currency.equals(selectedCurrency); + if (currencyShop.currency.equals("UAH") && isSelectedCurrencyNotEqualShopCurrency){ + String currencyQuery = "select c from CurrencyDTO c where c.base_ccy = ?1 and c.ccy = ?2"; + CurrencyDTO currency = CurrencyDTO.find(currencyQuery, currencyShop.currency, selectedCurrency).first(); + return ProductDTO._roundAvoid(price / currency.sale,2); + } + if (currencyShop.currency.equals("USD") && isSelectedCurrencyNotEqualShopCurrency){ + exchange(currencyShop.currency, selectedCurrency, price); + } + if (currencyShop.currency.equals("EUR") && isSelectedCurrencyNotEqualShopCurrency){ + exchange(currencyShop.currency, selectedCurrency, price); + } + return ProductDTO._roundAvoid(price, 2); + } + } + + private static double exchange(String shopCurrency, String selectedCurrency, double price) { + if (selectedCurrency.equals("UAH")){ + String currencyQuery = "select c from CurrencyDTO c where c.base_ccy = ?1 and c.ccy = ?2"; + CurrencyDTO currency = CurrencyDTO.find(currencyQuery, selectedCurrency, shopCurrency).first(); + return ProductDTO._roundAvoid(price * currency.buy,2); + } else { + CurrencyDTO currencyDTO = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", shopCurrency).first(); + CurrencyDTO currencyDTOSelected = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", selectedCurrency).first(); + return ProductDTO._roundAvoid(price * (currencyDTO.buy / currencyDTOSelected.buy), 2); + } + } + + public static void changePriceAccordingToCurrency(ProductDTO product, ShopDTO shop, String selectedCurrency){ + + CurrencyShopDTO currencyShop = CurrencyShopDTO.find("byShop", shop).first(); + if (selectedCurrency.isEmpty()){ + currencyShop.selectedCurrency = null; + currencyShop.save(); + setZeroPriceToSelectedAdditions(product); + } else { + currencyShop.selectedCurrency = selectedCurrency; + boolean isSelectedCurrencyNotEqualShopCurrency = !currencyShop.currency.equals(currencyShop.selectedCurrency); + if (currencyShop.currency.equals("UAH") && isSelectedCurrencyNotEqualShopCurrency){ + String currencyQuery = "select c from CurrencyDTO c where c.base_ccy = ?1 and c.ccy = ?2"; + CurrencyDTO currency = CurrencyDTO.find(currencyQuery, currencyShop.currency, selectedCurrency).first(); + product.priceInCurrency = round(product.price / currency.buy, 2); + exchangeCurrencyForAdditionsInUAHShop(product, shop, selectedCurrency); + product.save(); + } else if (currencyShop.currency.equals("UAH") && !isSelectedCurrencyNotEqualShopCurrency){ + product.priceInCurrency = 0; + setZeroPriceToSelectedAdditions(product); + product.save(); + } else if (currencyShop.currency.equals("USD") && isSelectedCurrencyNotEqualShopCurrency){ + exchangeCurrencyToProduct(currencyShop.currency, selectedCurrency, product); + } else if (currencyShop.currency.equals("USD") && !isSelectedCurrencyNotEqualShopCurrency){ + product.priceInCurrency = 0; + setZeroPriceToSelectedAdditions(product); + product.save(); + } else if (currencyShop.currency.equals("EUR") && isSelectedCurrencyNotEqualShopCurrency){ + exchangeCurrencyToProduct(currencyShop.currency, selectedCurrency, product); + } else if (currencyShop.currency.equals("EUR") && !isSelectedCurrencyNotEqualShopCurrency){ + product.priceInCurrency = 0; + setZeroPriceToSelectedAdditions(product); + product.save(); + } else if (currencyShop.currency.equals("PLZ") && isSelectedCurrencyNotEqualShopCurrency){ + exchangeCurrencyToProduct(currencyShop.currency, selectedCurrency, product); + } else if (currencyShop.currency.equals("PLZ") && !isSelectedCurrencyNotEqualShopCurrency){ + product.priceInCurrency = 0; + setZeroPriceToSelectedAdditions(product); + product.save(); + } + currencyShop.save(); + } + shop.currencyShop = currencyShop; + } + + private static void setZeroPriceToSelectedAdditions(ProductDTO product) { + if (!product.selectedAdditions.isEmpty()){ + for(SelectedAdditionDTO selectedAddition : product.selectedAdditions){ + selectedAddition.addition.priceInCurrency = 0D; + selectedAddition.addition.save(); + } + } + if (!product.defaultAdditions.isEmpty()){ + for(SelectedAdditionDTO selectedAddition : product.defaultAdditions){ + selectedAddition.addition.priceInCurrency = 0D; + selectedAddition.addition.save(); + } + } + } + + private static void exchangeCurrencyForAdditionsInUAHShop(ProductDTO product, ShopDTO shop, String selectedCurrency) { + if (!product.defaultAdditions.isEmpty()){ + for(SelectedAdditionDTO selectedAddition : product.defaultAdditions){ + selectedAddition.addition.priceInCurrency = exchangePrice(selectedAddition.addition.price, shop, selectedCurrency); + selectedAddition.addition.save(); + } + } + if (!product.selectedAdditions.isEmpty()){ + for(SelectedAdditionDTO selectedAddition : product.selectedAdditions){ + selectedAddition.addition.priceInCurrency = exchangePrice(selectedAddition.addition.price, shop, selectedCurrency); + selectedAddition.addition.save(); + } + } + + } + + private static void exchangeCurrencyToProduct(String shopCurrency, String selectedCurrency, ProductDTO product) { + if (selectedCurrency.equals("UAH")){ + String currencyQuery = "select c from CurrencyDTO c where c.base_ccy = ?1 and c.ccy = ?2"; + CurrencyDTO currency = CurrencyDTO.find(currencyQuery, selectedCurrency, shopCurrency).first(); + product.priceInCurrency = round(product.price * currency.buy, 2); + product.save(); + exchangeCurrencyForAdditionsInUahSelected(product, currency); + } else { + product.priceInCurrency = changePriceToUsdEurPlzCurrency(shopCurrency, selectedCurrency, product); + product.save(); + } + product.save(); + } + + private static void exchangeCurrencyForAdditionsInUahSelected(ProductDTO product, CurrencyDTO currency) { + if (!product.defaultAdditions.isEmpty()){ + for (int i = 0; i < product.defaultAdditions.size(); i++){ + product.defaultAdditions.get(i).addition.priceInCurrency = + round(product.defaultAdditions.get(i).addition.price * currency.buy, 2); + product.defaultAdditions.get(i).addition.save(); + } + } + if (!product.selectedAdditions.isEmpty()){ + for (int i = 0; i < product.selectedAdditions.size(); i++){ + product.selectedAdditions.get(i).addition.priceInCurrency = + round(product.selectedAdditions.get(i).addition.price * currency.buy, 2); + product.selectedAdditions.get(i).addition.save(); + + } + } + } + + private static double changePriceToUsdEurPlzCurrency(String currency, String selectedCurrency, ProductDTO product) { + CurrencyDTO currencyDTO = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", currency).first(); + CurrencyDTO currencyDTOSelected = CurrencyDTO.find("select c from CurrencyDTO c where c.ccy = ?1", selectedCurrency).first(); + exchangeCurrencyForAdditions(product, currencyDTO, currencyDTOSelected); + return round( product.price * (currencyDTO.buy / currencyDTOSelected.buy), 2); + } + + private static void exchangeCurrencyForAdditions(ProductDTO product, CurrencyDTO currencyDTO, CurrencyDTO currencyDTOSelected) { + if (!product.defaultAdditions.isEmpty()){ + for (int i = 0; i < product.defaultAdditions.size(); i++){ + product.defaultAdditions.get(i).addition.priceInCurrency = + round(product.defaultAdditions.get(i).addition.price * (currencyDTO.buy / currencyDTOSelected.buy), 2); + product.defaultAdditions.get(i).addition.save(); + } + } + if (!product.selectedAdditions.isEmpty()){ + for (int i = 0; i < product.selectedAdditions.size(); i++){ + product.selectedAdditions.get(i).addition.priceInCurrency = + round(product.selectedAdditions.get(i).addition.price * (currencyDTO.buy / currencyDTOSelected.buy),2); + product.selectedAdditions.get(i).addition.save(); + } + } + } + -// public static List getOrderList public static List getFeedbackList(ProductDTO product) { String query = "SELECT customerName, feedbackTime, quality, review, FeedbackCommentDTO.comment FROM FeedbackDTO" + @@ -37,7 +207,6 @@ private static FeedbackDTO createFeedbackDTO(Object[] item) { String quality = (String) item[2]; String review = (String) item[3]; String comment = (String) item[4]; - System.out.println("FeedbackDTO => " + customerName + feedbackTime + quality + review + comment); FeedbackDTO feedback = new FeedbackDTO(quality, review, customerName, feedbackTime); feedback.comment = comment; return feedback; diff --git a/app/util/CurrencySign.java b/app/util/CurrencySign.java new file mode 100644 index 000000000..cd6c05ac8 --- /dev/null +++ b/app/util/CurrencySign.java @@ -0,0 +1,43 @@ +package util; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +public class CurrencySign { + + public String usd = String.valueOf('\u0024'); + public String eur = String.valueOf('\u20ac'); + public String uah = String.valueOf('\u20B4'); + public String plz = "Zl"; + + public Map currencySigns = new HashMap(); + + + public CurrencySign() { + currencySigns.put("USD", this.usd); + currencySigns.put("EUR", this.eur); + currencySigns.put("UAH", this.uah); + currencySigns.put("PLZ", this.plz); + } + + public String getUSD() { + return usd; + } + + public String getEUR() { + return eur; + } + + public String getUAH() { + return uah; + } + + public String getPLZ() {return plz; } + + + + + +} diff --git a/app/views/Application/admin.html b/app/views/Application/admin.html index 447fa7b4a..f610e0691 100644 --- a/app/views/Application/admin.html +++ b/app/views/Application/admin.html @@ -72,6 +72,9 @@
Wise + + + @@ -169,6 +172,7 @@
Wise + @@ -177,5 +181,7 @@
Wise + + diff --git a/app/views/Application/category.html b/app/views/Application/category.html index 70995d8c2..e043ea018 100644 --- a/app/views/Application/category.html +++ b/app/views/Application/category.html @@ -3,6 +3,7 @@ #{set language:language /} #{set categories:categories /} #{set qr_uuid:qr_uuid /} +#{set selectedCurrency:selectedCurrency /} +
+
+
Loading...
+
+ Image not loaded or not found!! +
+
+
+ +
+
+ + + + -
- +
-
- +
diff --git a/wisehands/admin/partials/addNewProduct.html b/wisehands/admin/partials/addNewProduct.html index a33d74e39..2e0848904 100644 --- a/wisehands/admin/partials/addNewProduct.html +++ b/wisehands/admin/partials/addNewProduct.html @@ -1,5 +1,78 @@ +
- +
-
-
- - -
- slide1 + + + + + + +
+ +
+ +
+ +

{{'addNewProduct.addPhoto' | + translate}}

+

{{'addNewProduct.errorLoadPhoto' | translate}}

+
+ +
+
+
    +
  • + +
    + +
    +
  • +
-

{{'addNewProduct.addPhoto' | translate}}

-

{{'addNewProduct.errorLoadPhoto' | translate}}

+

{{'editProduct.general' | translate}}

@@ -47,7 +151,8 @@
{{'translationPage.ukrainian' | translate}}
- +
{{'translationPage.english' | translate}}
@@ -56,7 +161,8 @@
{{'translationPage.english' | translate}}
- +
@@ -68,90 +174,46 @@

{{'addNewProduct.category' | translate}}

-
-
+
+

{{category.name}}

-
-

{{'addNewProduct.showMoreButton' | translate}}

-

{{'addNewProduct.showLessButton' | translate}}

+
+

+ {{'addNewProduct.showMoreButton' | translate}}

+

+ {{'addNewProduct.showLessButton' | translate}}

-
+
-
-
-

{{'editProduct.properties' | translate}}

- - -
- -
-
- - +
+

{{'editProduct.properties' | translate}}

+ + +
+ + +
+
+ + +
+
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
- +
- - + +
diff --git a/wisehands/admin/partials/courierDelivery.html b/wisehands/admin/partials/courierDelivery.html index 63d5a27a6..5670f403c 100644 --- a/wisehands/admin/partials/courierDelivery.html +++ b/wisehands/admin/partials/courierDelivery.html @@ -34,14 +34,14 @@

{{'editProduct.general' | translate}}

-

{{'delivery.deliveryPrice' | translate}} ({{'products.currency' | translate}})

+

{{'delivery.deliveryPrice' | translate}} ({{currency}})

Delivery price can't be less than zero

-

{{'delivery.freeDeliveryPrice' | translate}} ({{'products.currency' | translate}})

+

{{'delivery.freeDeliveryPrice' | translate}} ({{currency}})

Minimum order amount for free shipping can't be less than zero

diff --git a/wisehands/admin/partials/editProduct.html b/wisehands/admin/partials/editProduct.html index f4f523c95..66b210d17 100644 --- a/wisehands/admin/partials/editProduct.html +++ b/wisehands/admin/partials/editProduct.html @@ -38,7 +38,7 @@

{{'editProduct.general' | translate}}

- +
diff --git a/wisehands/admin/partials/productDetails.html b/wisehands/admin/partials/productDetails.html index bcc9ec4e1..83cd6c28d 100644 --- a/wisehands/admin/partials/productDetails.html +++ b/wisehands/admin/partials/productDetails.html @@ -42,7 +42,7 @@
{{product.name}}
- +
{{product.price}} {{product.priceWithAdditions > 0 ? ('+ ') + (product.priceWithAdditions) + (' ') + ('selectAdditions.additionsPrice' | translate) : ''}}
@@ -61,7 +61,8 @@
{{product.description}}
-
+ +

{{'editProduct.properties' | translate}}

{{'addNewProduct.isShowInShop' | translate}}

{{'addNewProduct.isNotShowInShop' | translate}}

@@ -86,7 +87,7 @@

{{'productDetails.reviews' | translate}}

+
+
+
+
+
+
+
+
+
@@ -117,3 +125,7 @@

{{'settings.footer' | translate}}

+ + + + \ No newline at end of file diff --git a/wisehands/admin/partials/singleOrder.html b/wisehands/admin/partials/singleOrder.html index b94055823..2702fe0f3 100644 --- a/wisehands/admin/partials/singleOrder.html +++ b/wisehands/admin/partials/singleOrder.html @@ -165,7 +165,7 @@
{{'singleOrder.paymentState' | translate}}:

{{'singleOrder.titleOrder' | translate}}

{{'singleOrder.OrderAmount' | translate}}:
-

{{order.total}} {{'orderList.Currency' | translate}}

+

{{order.total}} {{order.currency}}

diff --git a/wisehands/admin/partials/userProfile.html b/wisehands/admin/partials/userProfile.html index b7c17f5ae..e89912c24 100644 --- a/wisehands/admin/partials/userProfile.html +++ b/wisehands/admin/partials/userProfile.html @@ -18,24 +18,17 @@
{{'userprofile.myProfile' | translate}}

{{'editProduct.general' | translate}}

-
+

{{'userprofile.fullname' | translate}}

-
+

{{'singleOrder.Phone' | translate}}

-
+

E-mail

- -
-
-
- - - \ No newline at end of file diff --git a/wisehands/admin/resources/locale-en_US.json b/wisehands/admin/resources/locale-en_US.json index bfb8e7748..805f87c27 100644 --- a/wisehands/admin/resources/locale-en_US.json +++ b/wisehands/admin/resources/locale-en_US.json @@ -262,7 +262,7 @@ "addNewProduct.category": "Category", "addNewProduct.errorChooseCategory": "Category Required", "addNewProduct.createCategory": "Create category", - "addNewProduct.addPhoto": "Add image (size ratio 4:3, e.g. 640*480px)", + "addNewProduct.addPhoto": "Add image.", "addNewProduct.errorLoadPhoto": "Image Required", "addNewProduct.makeMain": "Make the main", "addNewProduct.deletePhoto": "Remove image", @@ -439,6 +439,7 @@ "deleteproperty.deleteMessage1": "Do you really want to delete this property?", "deleteproperty.deleteMessage2": "Property deleted.", "directives.language-select.Language": "Language", + "directives.currency-select.Currency": "Currency", "hourssetting.title": "Hours setting", "hourssetting.monday": "Monday", "hourssetting.tuesday": "Tuesday", diff --git a/wisehands/admin/resources/locale-pl_PL.json b/wisehands/admin/resources/locale-pl_PL.json index 5b982aee1..2a75670d3 100644 --- a/wisehands/admin/resources/locale-pl_PL.json +++ b/wisehands/admin/resources/locale-pl_PL.json @@ -252,7 +252,7 @@ "addNewProduct.category": "Kategoria", "addNewProduct.errorChooseCategory": "Wymagana kategoria", "addNewProduct.createCategory": "Utwórz kategorię", - "addNewProduct.addPhoto": "Dodaj obraz (stosunek stron 4:3, stosunek stron 700 x 525 px)", + "addNewProduct.addPhoto": "Dodaj obraz", "addNewProduct.errorLoadPhoto": "Wymagany obraz", "addNewProduct.makeMain": "Zrób głównym", "addNewProduct.deletePhoto": "Usuń zdjęcie", diff --git a/wisehands/admin/resources/locale-uk_UA.json b/wisehands/admin/resources/locale-uk_UA.json index 693a3f8c2..4f85e3cbf 100644 --- a/wisehands/admin/resources/locale-uk_UA.json +++ b/wisehands/admin/resources/locale-uk_UA.json @@ -255,7 +255,7 @@ "addNewProduct.category": "Категорія", "addNewProduct.errorChooseCategory": "Категорія обов'язкова", "addNewProduct.createCategory": "Створити категорію", - "addNewProduct.addPhoto": "Додати зображення (співвідношення сторін 4:3, наприклад 640*480 пікс.)", + "addNewProduct.addPhoto": "Додати зображення", "addNewProduct.errorLoadPhoto": "Зображення обов'язкове", "addNewProduct.makeMain": "Зробити головною", "addNewProduct.deletePhoto": "Видалити", @@ -436,6 +436,7 @@ "deleteproperty.deleteMessage1": "Ви дійсно хочете видалити дану властивість?", "deleteproperty.deleteMessage2": "Властивість видалена.", "directives.language-select.Language": "Мова", + "directives.currency-select.Currency": "Валюта", "hourssetting.title": "Налаштування годин", "hourssetting.monday": "Понеділок", "hourssetting.tuesday": "Вівторок", diff --git a/wisehands/assets/angular-image-cropper/angular-image-cropper.js b/wisehands/assets/angular-image-cropper/angular-image-cropper.js index e8e8dc573..0c3d6dcbc 100644 --- a/wisehands/assets/angular-image-cropper/angular-image-cropper.js +++ b/wisehands/assets/angular-image-cropper/angular-image-cropper.js @@ -942,314 +942,314 @@ return /******/ (function(modules) { // webpackBootstrap /* 6 */ /***/ function(module, exports) { - /* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra - */ - // css base code, injected by the css-loader - module.exports = function() { - var list = []; - - // return the list of modules as css string - list.toString = function toString() { - var result = []; - for(var i = 0; i < this.length; i++) { - var item = this[i]; - if(item[2]) { - result.push("@media " + item[2] + "{" + item[1] + "}"); - } else { - result.push(item[1]); - } - } - return result.join(""); - }; - - // import a list of modules into the list - list.i = function(modules, mediaQuery) { - if(typeof modules === "string") - modules = [[null, modules, ""]]; - var alreadyImportedModules = {}; - for(var i = 0; i < this.length; i++) { - var id = this[i][0]; - if(typeof id === "number") - alreadyImportedModules[id] = true; - } - for(i = 0; i < modules.length; i++) { - var item = modules[i]; - // skip already imported module - // this implementation is not 100% perfect for weird media query combinations - // when a module is imported multiple times with different media queries. - // I hope this will never occur (Hey this way we have smaller bundles) - if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) { - if(mediaQuery && !item[2]) { - item[2] = mediaQuery; - } else if(mediaQuery) { - item[2] = "(" + item[2] + ") and (" + mediaQuery + ")"; - } - list.push(item); - } - } - }; - return list; - }; + /* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra + */ + // css base code, injected by the css-loader + module.exports = function() { + var list = []; + + // return the list of modules as css string + list.toString = function toString() { + var result = []; + for(var i = 0; i < this.length; i++) { + var item = this[i]; + if(item[2]) { + result.push("@media " + item[2] + "{" + item[1] + "}"); + } else { + result.push(item[1]); + } + } + return result.join(""); + }; + + // import a list of modules into the list + list.i = function(modules, mediaQuery) { + if(typeof modules === "string") + modules = [[null, modules, ""]]; + var alreadyImportedModules = {}; + for(var i = 0; i < this.length; i++) { + var id = this[i][0]; + if(typeof id === "number") + alreadyImportedModules[id] = true; + } + for(i = 0; i < modules.length; i++) { + var item = modules[i]; + // skip already imported module + // this implementation is not 100% perfect for weird media query combinations + // when a module is imported multiple times with different media queries. + // I hope this will never occur (Hey this way we have smaller bundles) + if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) { + if(mediaQuery && !item[2]) { + item[2] = mediaQuery; + } else if(mediaQuery) { + item[2] = "(" + item[2] + ") and (" + mediaQuery + ")"; + } + list.push(item); + } + } + }; + return list; + }; /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { - /* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra - */ - var stylesInDom = {}, - memoize = function(fn) { - var memo; - return function () { - if (typeof memo === "undefined") memo = fn.apply(this, arguments); - return memo; - }; - }, - isOldIE = memoize(function() { - return /msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase()); - }), - getHeadElement = memoize(function () { - return document.head || document.getElementsByTagName("head")[0]; - }), - singletonElement = null, - singletonCounter = 0, - styleElementsInsertedAtTop = []; - - module.exports = function(list, options) { - if(false) { - if(typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment"); - } - - options = options || {}; - // Force single-tag solution on IE6-9, which has a hard limit on the # of