diff --git a/.liquibase/Data_alias/basic/2020.2.2/Offer/addColumnOffer.xml b/.liquibase/Data_alias/basic/2020.2.2/Offer/addColumnOffer.xml index 073fd2b66133ba6f53df5ba7f437eecbd6ddc5e4..1ae38fd53a3e8cd90aa3ae2a373c704004c016f7 100644 --- a/.liquibase/Data_alias/basic/2020.2.2/Offer/addColumnOffer.xml +++ b/.liquibase/Data_alias/basic/2020.2.2/Offer/addColumnOffer.xml @@ -8,4 +8,9 @@ <column name="DISCOUNTED_NET" type="NUMERIC(14,2)" /> </addColumn> </changeSet> + <changeSet author="s.garb" id="801708bd-91f0-4468-bed9-0bbab7e46997"> + <addColumn tableName="OFFER"> + <column name="DISCOUNTED_VAT" type="NUMERIC(14,2)" /> + </addColumn> + </changeSet> </databaseChangeLog> \ No newline at end of file diff --git a/.liquibase/Data_alias/basic/2020.2.2/Offeritem/addColumnOfferitem.xml b/.liquibase/Data_alias/basic/2020.2.2/Offeritem/addColumnOfferitem.xml new file mode 100644 index 0000000000000000000000000000000000000000..b2e97c1707212e2baa7bcedd2d4b5a6b07f15f91 --- /dev/null +++ b/.liquibase/Data_alias/basic/2020.2.2/Offeritem/addColumnOfferitem.xml @@ -0,0 +1,10 @@ +<?xml version="1.1" encoding="UTF-8" standalone="no"?> +<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd"> + <changeSet author="s.garb" id="6f4092c9-205c-43d0-a9c1-57f464a3bcd8"> + <addColumn tableName="OFFERITEM"> + <column name="DISCOUNTED_PRICE" type="NUMERIC(14,2)" /> + </addColumn> + </changeSet> +</databaseChangeLog> \ No newline at end of file diff --git a/.liquibase/Data_alias/basic/2020.2.2/Offeritem/changelog.xml b/.liquibase/Data_alias/basic/2020.2.2/Offeritem/changelog.xml new file mode 100644 index 0000000000000000000000000000000000000000..a13f3ae448c7a6fc0532aca1fb714c762c06f2c6 --- /dev/null +++ b/.liquibase/Data_alias/basic/2020.2.2/Offeritem/changelog.xml @@ -0,0 +1,6 @@ +<?xml version="1.1" encoding="UTF-8" standalone="no"?> +<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd"> + <include file="addColumnOfferitem.xml" relativeToChangelogFile="true" /> +</databaseChangeLog> \ No newline at end of file diff --git a/.liquibase/Data_alias/basic/2020.2.2/changelog.xml b/.liquibase/Data_alias/basic/2020.2.2/changelog.xml index daa38a0545e87af0fd2c21655ed8c78ae9c953d1..09517398316bb9d4b6e41f3100baa134c16c26a3 100644 --- a/.liquibase/Data_alias/basic/2020.2.2/changelog.xml +++ b/.liquibase/Data_alias/basic/2020.2.2/changelog.xml @@ -2,6 +2,7 @@ <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd"> <include relativeToChangelogFile="true" file="Offer/changelog.xml"/> + <include relativeToChangelogFile="true" file="Offeritem/changelog.xml"/> <include relativeToChangelogFile="true" file="insert_commMediumTitleKeywordAttribute.xml"/> <include relativeToChangelogFile="true" file="Knowledgemanagement/changelog_knowledgeManagement.xml"/> </databaseChangeLog> \ No newline at end of file diff --git a/aliasDefinition/Data_alias/Data_alias.aod b/aliasDefinition/Data_alias/Data_alias.aod index 8442f4cfbb065d50a7626eaa7ddf845be140880a..4bfaf2da45d28a2c5c64282677c6b3f005690251 100644 --- a/aliasDefinition/Data_alias/Data_alias.aod +++ b/aliasDefinition/Data_alias/Data_alias.aod @@ -3136,6 +3136,20 @@ <title></title> <description></description> </entityFieldDb> + <entityFieldDb> + <name>DISCOUNTED_VAT</name> + <dbName></dbName> + <primaryKey v="false" /> + <columnType v="3" /> + <size v="14" /> + <scale v="2" /> + <notNull v="false" /> + <isUnique v="false" /> + <index v="false" /> + <documentation></documentation> + <title></title> + <description></description> + </entityFieldDb> </entityFields> </entityDb> <entityDb> @@ -3484,6 +3498,20 @@ </customBooleanProperty> </customProperties> </entityFieldDb> + <entityFieldDb> + <name>DISCOUNTED_PRICE</name> + <dbName></dbName> + <primaryKey v="false" /> + <columnType v="3" /> + <size v="14" /> + <scale v="2" /> + <notNull v="false" /> + <isUnique v="false" /> + <index v="false" /> + <documentation></documentation> + <title></title> + <description></description> + </entityFieldDb> </entityFields> </entityDb> <entityDb> diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod index 5bb9a98c287822037d485f6e7eb38d1b1209c8a1..7fb1855123c857d6f2076bc47345c6f7a07a59f1 100644 --- a/entity/Offer_entity/Offer_entity.aod +++ b/entity/Offer_entity/Offer_entity.aod @@ -1086,6 +1086,9 @@ <entityField> <name>DiscountChanged</name> </entityField> + <entityField> + <name>DISCOUNTED_VAT</name> + </entityField> </entityFields> <recordContainers> <dbRecordContainer> diff --git a/entity/Offer_entity/entityfields/object_rowid/displayValueProcess.js b/entity/Offer_entity/entityfields/object_rowid/displayValueProcess.js index fe2b7c72502d9937add9b539ed38483e6ca4bd51..174332cf1787fd2ad87979f7e60443b3fe8e4dc0 100644 --- a/entity/Offer_entity/entityfields/object_rowid/displayValueProcess.js +++ b/entity/Offer_entity/entityfields/object_rowid/displayValueProcess.js @@ -1,11 +1,11 @@ -import("system.neon"); -import("system.vars"); -import("system.db"); -import("system.result"); -import("Context_lib"); - -if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$field.OBJECT_ROWID") == null) { - result.string(""); -} else if (vars.exists("$field.OBJECT_TYPE") && vars.get("$field.OBJECT_TYPE")) { - result.string(db.cell(ContextUtils.getNameSql(vars.get("$field.OBJECT_TYPE"), vars.get("$field.OBJECT_ROWID")))); -} \ No newline at end of file +//import("system.neon"); +//import("system.vars"); +//import("system.db"); +//import("system.result"); +//import("Context_lib"); +// +//if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$field.OBJECT_ROWID") == null) { +// result.string(""); +//} else if (vars.exists("$field.OBJECT_TYPE") && vars.get("$field.OBJECT_TYPE")) { +// result.string(db.cell(ContextUtils.getNameSql(vars.get("$field.OBJECT_TYPE"), vars.get("$field.OBJECT_ROWID")))); +//} \ No newline at end of file diff --git a/entity/Offer_entity/recordcontainers/db/onDBInsert.js b/entity/Offer_entity/recordcontainers/db/onDBInsert.js index 7b8dd8ac9409eb2e4875956261abb5daee889705..30cc525485c381c1261eb01db1d3b81ad47670bd 100644 --- a/entity/Offer_entity/recordcontainers/db/onDBInsert.js +++ b/entity/Offer_entity/recordcontainers/db/onDBInsert.js @@ -1,3 +1,4 @@ +import("Context_lib"); import("system.workflow"); import("Workflow_lib"); import("system.db"); diff --git a/entity/Offer_entity/recordcontainers/db/onDBUpdate.js b/entity/Offer_entity/recordcontainers/db/onDBUpdate.js index 6b96baf10bbaf86b538d59cb1824a2cfe6c25df1..0631eebeb38e4f562f15ab672f79c4ae416b8db0 100644 --- a/entity/Offer_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Offer_entity/recordcontainers/db/onDBUpdate.js @@ -10,7 +10,7 @@ if(vars.get("$field.DiscountChanged") == "true" && oid){ var oiUtils = new OfferItemUtils(oid); var vals = oiUtils.getNetAndVat(); - var netDiscounted = OfferItemUtils.getDiscountedNet(vals[0], discount); + var netDiscounted = OfferItemUtils.getDiscountedNet(null, oid, discount); let config = entities.createConfigForUpdatingRows(); config.entity("Offer_entity"); diff --git a/entity/Offeritem_entity/Offeritem_entity.aod b/entity/Offeritem_entity/Offeritem_entity.aod index 81fb7d31b7653aa0fc62698a0d29813d33c89c66..70553e8c8571827c8db870ea0e76f0d9c5fa8b62 100644 --- a/entity/Offeritem_entity/Offeritem_entity.aod +++ b/entity/Offeritem_entity/Offeritem_entity.aod @@ -252,6 +252,14 @@ <name>Discount_param</name> <expose v="true" /> </entityParameter> + <entityField> + <name>DISCOUNTED_PRICE</name> + <valueProcess>%aditoprj%/entity/Offeritem_entity/entityfields/discounted_price/valueProcess.js</valueProcess> + </entityField> + <entityParameter> + <name>ExclDiscountGroupcodes_param</name> + <expose v="true" /> + </entityParameter> </entityFields> <recordContainers> <dbRecordContainer> diff --git a/entity/Offeritem_entity/entityfields/discounted_price/valueProcess.js b/entity/Offeritem_entity/entityfields/discounted_price/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..246cfeff9228f861004ab690a5e35bbb15e9c3ad --- /dev/null +++ b/entity/Offeritem_entity/entityfields/discounted_price/valueProcess.js @@ -0,0 +1,12 @@ +import("system.neon"); +import("system.vars"); + +if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT){ + var vat = vars.get("$field.VAT"); + var price = vars.get("$field.PRICE"); + + if(vars.exists("$param.ExclDiscountGroupcodes_param") && vars.get("$param.ExclDiscountGroupcodes_param")){ + + } + +} \ No newline at end of file diff --git a/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js b/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js index 75ca79d530941cb822269d379f2b001146a4d5c7..a3bbf5f082abd6a051b044179c424d3c1877566f 100644 --- a/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js +++ b/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js @@ -18,7 +18,7 @@ if(oid != "") var vals = oiUtils.getNetAndVat(deletedIds); - var netDiscounted = OfferItemUtils.getDiscountedNet(vals[0], discount); + var netDiscounted = OfferItemUtils.getDiscountedNet(deletedIds, oid, discount); if(netDiscounted){ vals.push(netDiscounted); diff --git a/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js b/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js index a912d7c78d50bbb65627eee0c0aad245f8755961..6fd275e6b9315353150d462d5d8a5601e9262143 100644 --- a/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js +++ b/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js @@ -23,7 +23,7 @@ if(oid != "") var vals = oiUtils.getNetAndVat(); var cols = ["NET", "VAT"]; - var netDiscounted = OfferItemUtils.getDiscountedNet(vals[0], discount); + var netDiscounted = OfferItemUtils.getDiscountedNet(null,oid, discount); if(netDiscounted){ vals.push(netDiscounted); diff --git a/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js b/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js index 03b7cff19347351b54443f9db016f361508210aa..540e33c4bd4e8275ff2507d20a2b3791d9c3bf2a 100644 --- a/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js @@ -11,7 +11,7 @@ if(oid != "") var cols = ["NET", "VAT"]; var oiUtils = new OfferItemUtils(oid); var vals = oiUtils.getNetAndVat(); - var netDiscounted = OfferItemUtils.getDiscountedNet(vals[0], discount); + var netDiscounted = OfferItemUtils.getDiscountedNet(null, oid, discount); if(netDiscounted){ vals.push(netDiscounted); diff --git a/process/Offer_lib/process.js b/process/Offer_lib/process.js index b446de8a78f94124a9d4fa288ce7982946c7ec8e..8e92f5bf31901891e00092bf16dd0c92afc38327 100644 --- a/process/Offer_lib/process.js +++ b/process/Offer_lib/process.js @@ -332,7 +332,7 @@ OfferUtils.buildOfferReport = function (pOfferID) "OFFER_DISCOUNTED_NET", "OFFER_DISCOUNTSUM" ]) - .add(itemData)); + .add(itemData)); return offerReport.exportReport(); } @@ -371,7 +371,7 @@ OfferUtils.copyOffer = function (pOfferId, pOfferData) "OfferPaymentTerm_param": pOfferData.paymentTerm || "", "ObjectType_param": pOfferData.objectType || "", "ObjectRowId_param": pOfferData.objectRowId || "", - "Discount_param" : pOfferData.discount || "" + "Discount_param" : pOfferData.discount || "" }; neon.openContext("Offer", null, null, neon.OPERATINGSTATE_NEW, params); } @@ -398,12 +398,23 @@ OfferUtils.copyOfferItems = function (pSourceOfferId, pTargetOfferId, pDiscount) //update order price var [netPrice, vat] = oiUtils.getNetAndVat(); + var netDiscounted = OfferItemUtils.getDiscountedNet(null, pSourceOfferId, pDiscount); - newWhere("OFFER.OFFERID", pTargetOfferId) + if(netDiscounted){ + newWhere("OFFER.OFFERID", pTargetOfferId) + .updateFields({ + "NET": netPrice, + "VAT": vat, + "DISCOUNTED_NET": netDiscounted + }); + } + else{ + newWhere("OFFER.OFFERID", pTargetOfferId) .updateFields({ "NET": netPrice, "VAT": vat }); + } } /** @@ -419,8 +430,8 @@ OfferUtils.copyOfferItems = function (pSourceOfferId, pTargetOfferId, pDiscount) */ OfferUtils.copyToOrder = function (pOfferId, pContextId, pRowId, pContactId, pLanguage, pCurrency, pAddress) { - var fieldparams = - { + var fieldparams = + { "$field.CONTACT_ID" : pContactId, "$field.ISOLANGUAGE" : pLanguage, "$field.OFFER_ID" : pOfferId, @@ -428,7 +439,7 @@ OfferUtils.copyToOrder = function (pOfferId, pContextId, pRowId, pContactId, pLa "$field.PAYMENTADDRESS" : pAddress || "", "$field.OBJECT_TYPE" : pContextId || "", "$field.OBJECT_ROWID" : pRowId || "" - }; + }; var params = {}; params["Copy_param"] = JSON.stringify(fieldparams); @@ -449,13 +460,13 @@ OfferUtils.getOfferTitleById = function (pOfferId) if (!pOfferId) return ""; var offerNumber = newSelect("OFFERCODE, VERSNR") - .from("OFFER") - .where("OFFER.OFFERID", pOfferId) - .arrayRow(); + .from("OFFER") + .where("OFFER.OFFERID", pOfferId) + .arrayRow(); return offerNumber.length > 0 - ? translate.text("Offer") + " " + offerNumber.join("-") - : ""; + ? translate.text("Offer") + " " + offerNumber.join("-") + : ""; } @@ -517,26 +528,26 @@ OfferItemUtils.prototype.insertPartsList = function(pProductId, pAssignedTo, pCu this.initItemTree(); var cols = ["OFFERITEMID" - , "OFFER_ID" - , "PRODUCT_ID" - , "GROUPCODEID" - , "ASSIGNEDTO" - , "ITEMNAME" - , "UNIT" - , "PRICE" - , "VAT" - , "QUANTITY" - , "OPTIONAL" - , "ITEMPOSITION" - , "ITEMSORT"]; + , "OFFER_ID" + , "PRODUCT_ID" + , "GROUPCODEID" + , "ASSIGNEDTO" + , "ITEMNAME" + , "UNIT" + , "PRICE" + , "VAT" + , "QUANTITY" + , "OPTIONAL" + , "ITEMPOSITION" + , "ITEMSORT"]; return ItemUtils.prototype.insertPartsList.apply(this, [cols, pProductId, pAssignedTo, pCurrency, pContactId, [[["info", "INFO"], ["info", - "( " + newSelect("DESCRIPTION") - .from("DESCRIPTIONTRANSLATION") - .where("DESCRIPTIONTRANSLATION.OBJECT_ROWID = PRODUCT.PRODUCTID") - .and("DESCRIPTIONTRANSLATION.OBJECT_TYPE", "Product") - .and("DESCRIPTIONTRANSLATION.LANG", pLanguage) - .toString() + ")"]]]]); + "( " + newSelect("DESCRIPTION") + .from("DESCRIPTIONTRANSLATION") + .where("DESCRIPTIONTRANSLATION.OBJECT_ROWID = PRODUCT.PRODUCTID") + .and("DESCRIPTIONTRANSLATION.OBJECT_TYPE", "Product") + .and("DESCRIPTIONTRANSLATION.LANG", pLanguage) + .toString() + ")"]]]]); } @@ -578,12 +589,42 @@ OfferItemUtils.prototype.reOrgItems = function() { -OfferItemUtils.getDiscountedNet = function(pNet, pDiscount){ +OfferItemUtils.getDiscountedNet = function(pExcludedIs, pOfferId, pDiscount, pExcludedProductgroups){ var ret; - if(pNet){ - let multi = eMath.mulDec(pNet, pDiscount); + var sum = 0; + var sumExcluded = 0; + if(pOfferId){ + var offeritemData = newSelect("QUANTITY, PRICE, DISCOUNT, VAT, OPTIONAL") + .from("OFFERITEM") + .where("OFFERITEM.OFFER_ID", pOfferId) + .andIfSet("OFFERITEM.GROUPCODEID", pExcludedProductgroups, SqlBuilder.NOT_IN()) + .andIfSet("OFFERITEM.OFFERITEMID", pExcludedIs, SqlBuilder.NOT_IN()) + .table(); + for (var i = 0; i < offeritemData.length; i++) + { + sum = eMath.addDec(sum, ItemUtils.prototype.getItemSum(offeritemData[i][0], offeritemData[i][1], offeritemData[i][2], offeritemData[i][4])); + + } + + let multi = eMath.mulDec(sum, pDiscount); let discount = eMath.divDec(multi, "100"); - ret = eMath.subDec(pNet, discount); + ret = eMath.subDec(sum, discount); + + if(pExcludedProductgroups){ + var excludedOfferitemData = newSelect("QUANTITY, PRICE, DISCOUNT, VAT, OPTIONAL") + .from("OFFERITEM") + .where("OFFERITEM.OFFER_ID", pOfferId) + .and("OFFERITEM.GROUPCODEID", pExcludedProductgroups, SqlBuilder.IN()) + .andIfSet("OFFERITEM.OFFERITEMID", pExcludedIs, SqlBuilder.NOT_IN()) + .table(); + for (var j = 0; j < excludedOfferitemData.length; j++) + { + sumExcluded = eMath.addDec(sumExcluded, ItemUtils.prototype.getItemSum(excludedOfferitemData[j][0], excludedOfferitemData[j][1], excludedOfferitemData[j][2], excludedOfferitemData[j][4])); + } + } + if(sumExcluded){ + ret = eMath.addDec(ret, sumExcluded); + } } return ret; }