Skip to content
Snippets Groups Projects
Commit 00113367 authored by Maximilian Schröger's avatar Maximilian Schröger
Browse files

Angebot/Angebotsposten Preislogik

parent 9149406d
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.0.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.0.0"> <neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.0.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.0.0">
<name>Offeritem_context</name> <name>Offeritem_context</name>
<title>Offeritem</title>
<majorModelMode>DISTRIBUTED</majorModelMode> <majorModelMode>DISTRIBUTED</majorModelMode>
<filterview>OfferitemFilter_view</filterview>
<preview>OfferitemPreview_view</preview>
<entity>Offeritem_entity</entity> <entity>Offeritem_entity</entity>
<references> <references>
<neonViewReference> <neonViewReference>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<cardViewTemplate> <cardViewTemplate>
<name>OfferHeader_template</name> <name>OfferHeader_template</name>
<iconField>IMAGE</iconField> <iconField>IMAGE</iconField>
<titleField>OFFERCODE</titleField> <titleField>PreviewTitle</titleField>
<descriptionField>RELATION_ID</descriptionField> <descriptionField>RELATION_ID</descriptionField>
<entityField>#ENTITY</entityField> <entityField>#ENTITY</entityField>
</cardViewTemplate> </cardViewTemplate>
...@@ -33,13 +33,17 @@ ...@@ -33,13 +33,17 @@
<entityField>LANGUAGE</entityField> <entityField>LANGUAGE</entityField>
</entityFieldLink> </entityFieldLink>
<entityFieldLink> <entityFieldLink>
<name>9e876b07-3029-42fe-a1e7-5c19b845e50d</name> <name>4843f0f0-4ee8-47c2-bc0f-99241bad4c51</name>
<entityField>NET</entityField> <entityField>NET</entityField>
</entityFieldLink> </entityFieldLink>
<entityFieldLink> <entityFieldLink>
<name>cd72899a-69b2-4fe2-bf58-4fb9f594324e</name> <name>cd72899a-69b2-4fe2-bf58-4fb9f594324e</name>
<entityField>VAT</entityField> <entityField>VAT</entityField>
</entityFieldLink> </entityFieldLink>
<entityFieldLink>
<name>10d8f38b-1e01-45a1-bc57-424284bf87be</name>
<entityField>TotalGross</entityField>
</entityFieldLink>
<entityFieldLink> <entityFieldLink>
<name>16d38881-d3d3-4c4d-9f23-39d60eadce8d</name> <name>16d38881-d3d3-4c4d-9f23-39d60eadce8d</name>
<entityField>CURRENCY</entityField> <entityField>CURRENCY</entityField>
...@@ -52,6 +56,10 @@ ...@@ -52,6 +56,10 @@
<name>3317b73e-68e8-41a8-a678-89c7c7c8513e</name> <name>3317b73e-68e8-41a8-a678-89c7c7c8513e</name>
<entityField>SALESPROJECT_ID</entityField> <entityField>SALESPROJECT_ID</entityField>
</entityFieldLink> </entityFieldLink>
<entityFieldLink>
<name>683e3a86-0f9f-4b40-85c0-ae102a5a4a9a</name>
<entityField>HEADER</entityField>
</entityFieldLink>
</fields> </fields>
</genericViewTemplate> </genericViewTemplate>
</children> </children>
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<children> <children>
<tableViewTemplate> <tableViewTemplate>
<name>OfferitemFilter_table</name> <name>OfferitemFilter_table</name>
<autoNewRow v="true" />
<entityField>#ENTITY</entityField> <entityField>#ENTITY</entityField>
<columns> <columns>
<neonTableColumn> <neonTableColumn>
...@@ -18,7 +19,7 @@ ...@@ -18,7 +19,7 @@
</neonTableColumn> </neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>545f79bf-2fee-4112-9541-0889d0e514eb</name> <name>545f79bf-2fee-4112-9541-0889d0e514eb</name>
<entityField>ITEMNAME</entityField> <entityField>PRODUCT_ID</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>2a907da4-b48d-4933-bc17-a40e7d4556f9</name> <name>2a907da4-b48d-4933-bc17-a40e7d4556f9</name>
......
...@@ -10,8 +10,29 @@ ...@@ -10,8 +10,29 @@
<children> <children>
<cardViewTemplate> <cardViewTemplate>
<name>OfferitemPreview_header</name> <name>OfferitemPreview_header</name>
<iconField>IMAGE</iconField>
<titleField>ITEMNAME</titleField> <titleField>ITEMNAME</titleField>
<descriptionField>DESCRIPTION</descriptionField> <descriptionField>DESCRIPTION</descriptionField>
<entityField>#ENTITY</entityField>
</cardViewTemplate> </cardViewTemplate>
<genericViewTemplate>
<name>Offeritem_generic</name>
<showDrawer v="true" />
<entityField>#ENTITY</entityField>
<fields>
<entityFieldLink>
<name>9868560c-41c7-4641-b0f1-627a61b796b3</name>
<entityField>TotalPrice</entityField>
</entityFieldLink>
<entityFieldLink>
<name>c0c04d1c-90a7-4c0b-9323-1f0783757987</name>
<entityField>GROUPCODEID</entityField>
</entityFieldLink>
<entityFieldLink>
<name>e25386dc-a740-4f93-a1f0-32317cf5a36a</name>
<entityField>OPTIONAL</entityField>
</entityFieldLink>
</fields>
</genericViewTemplate>
</children> </children>
</neonView> </neonView>
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
</neonTableColumn> </neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>695ce7be-d738-48a9-833d-e8815c6eff74</name> <name>695ce7be-d738-48a9-833d-e8815c6eff74</name>
<entityField>Pricelist_Relation</entityField> <entityField>PRICELIST</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>472a96ca-10ff-49c7-b2ae-6550e04c4e6f</name> <name>472a96ca-10ff-49c7-b2ae-6550e04c4e6f</name>
......
...@@ -18,10 +18,6 @@ ...@@ -18,10 +18,6 @@
<name>bc7ca35e-c454-4cc0-9b2e-0656e03f1f65</name> <name>bc7ca35e-c454-4cc0-9b2e-0656e03f1f65</name>
<entityField>IMAGE</entityField> <entityField>IMAGE</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn>
<name>0b2271ca-f55f-4339-b63f-f6f95d1d18e6</name>
<entityField>PRODUCT_GROUPCODEID</entityField>
</neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>9b809450-cbe5-40f3-8d64-b4a5bac5eb5b</name> <name>9b809450-cbe5-40f3-8d64-b4a5bac5eb5b</name>
<entityField>PRODUCT_ID</entityField> <entityField>PRODUCT_ID</entityField>
...@@ -46,6 +42,10 @@ ...@@ -46,6 +42,10 @@
<name>20efd64c-297d-4774-b020-437d3610e798</name> <name>20efd64c-297d-4774-b020-437d3610e798</name>
<entityField>CURRENCY</entityField> <entityField>CURRENCY</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn>
<name>787d2cce-ddb0-4d7e-8df4-5675e0d96d76</name>
<entityField>VAT</entityField>
</neonTableColumn>
</columns> </columns>
</tableViewTemplate> </tableViewTemplate>
</children> </children>
......
...@@ -30,4 +30,51 @@ function OfferUtils(){ ...@@ -30,4 +30,51 @@ function OfferUtils(){
this.getOfferNumberValidationFailString = function(){ this.getOfferNumberValidationFailString = function(){
return translate.text("The offer number already exists!"); return translate.text("The offer number already exists!");
} }
this.getOfferNetAndVAT = function(pOfferId, pOfferitemIdToDel){
//TODO: Bessere Möglichkeit als per SQL die zugehörigen Posten aus der DB zu holen?
var sum = 0;
var vat = 0;
var oiUtils = new OfferItemUtils();
var condition = "where OFFER_ID = '" + pOfferId + "'";
if(pOfferitemIdToDel != undefined)
condition += " and OFFERITEMID <> '" + pOfferitemIdToDel + "'";
var offerItems = db.table("select QUANTITY, PRICE, DISCOUNT, VAT, OPTIONAL "
+ "from OFFERITEM " + condition);
for(var i = 0; i < offerItems.length; i++){
sum += oiUtils.getItemSum(offerItems[i][0], offerItems[i][1], offerItems[i][2], offerItems[i][4]);
vat += oiUtils.getItemVAT(offerItems[i][0], offerItems[i][1], offerItems[i][2], offerItems[i][3], offerItems[i][4]);
}
return [sum, vat];
}
}
function OfferItemUtils(){
this.getItemSum = function(pQuantity, pPrice, pDiscount, pOptional){
pQuantity = pQuantity || 0;
pPrice = pPrice || 0;
pDiscount = pDiscount || 0;
return Number(pOptional) * parseFloat(pQuantity) * parseFloat(pPrice) * ((100 - parseFloat(pDiscount)) / 100);
}
this.getItemVAT = function(pQuantity, pPrice, pDiscount, pVAT, pOptional){
pQuantity = pQuantity || 0;
pPrice = pPrice || 0;
pDiscount = pDiscount || 0;
pVAT = pVAT || 0;
return Number(pOptional) * parseFloat(pQuantity) * parseFloat(pPrice) * ((100 - parseFloat(pDiscount)) / 100) * (parseFloat(pVAT) / 100);
}
this.roundPrice = function(pPrice){
return eMath.roundDec(pPrice, 2, eMath.ROUND_HALF_UP);
}
} }
\ No newline at end of file
...@@ -64,4 +64,120 @@ function ProductUtils() ...@@ -64,4 +64,120 @@ function ProductUtils()
throw new Error();//TODO: add message throw new Error();//TODO: add message
} }
} }
/**
* Delivers the stock
*
* @param pPid {String} ProductID
*
* @example productUtils.getStockCount(vars.get("$field.PRODUCTID"))
*
* @result {String} stock count
*/
this.getProductDetails = function( pPid, pPriceListFilter )
{
var ProductDetails = {};
var cols = [];
var colsProduct = ["PRODUCT.PRODUCTID", "PRODUCT.PRODUCTNAME", "PRODUCT.GROUPCODEID", "PRODUCT.UNIT"];
cols = cols.concat(colsProduct);
var joins = [];
var conditions = ["1=1"];
var orderby = ["PRODUCTID"];
var sqltypes = [];
//Prod2Prod
//TODO: get product structure
//PriceList
if(pPriceListFilter != undefined
&& pPriceListFilter.currency != undefined && pPriceListFilter.currency != ""
&& pPriceListFilter.quantity != undefined && pPriceListFilter.quantity != "")
{
var colsPricelist = ["PRODUCTPRICE.PRODUCTPRICEID", "PRODUCTPRICE.RELATION_ID", "PRODUCTPRICE.PRICELIST", "PRODUCTPRICE.PRICE", "PRODUCTPRICE.VAT"];
cols = cols.concat(colsPricelist);
joins.push(" left join PRODUCTPRICE on PRODUCTPRICE.PRODUCT_ID = PRODUCTID "
+ " and PRODUCTPRICE.CURRENCY = " + pPriceListFilter.currency
+ " and PRODUCTPRICE.VALID_FROM <= ? and (PRODUCTPRICE.VALID_TO > ? or PRODUCTPRICE.VALID_TO is null) "
+ " and PRODUCTPRICE.FROMQUANTITY <= " + pPriceListFilter.quantity
+ " and (PRODUCTPRICE.RELATION_ID = '" + pPriceListFilter.relationId + "' or (PRODUCTPRICE.RELATION_ID is null and PRODUCTPRICE.BUYSELL = 'SP')) ");
sqltypes.push([datetime.date().toString(), SQLTYPES.TIMESTAMP]);
sqltypes.push([datetime.date().toString(), SQLTYPES.TIMESTAMP]);
orderby = orderby.concat(["PRODUCTPRICE.VALID_FROM desc, PRODUCTPRICE.FROMQUANTITY desc"]);
}
var ProductDataSql = "select " + cols.join(", ")
+ " from PRODUCT "
+ joins.join(" ")
+ " where PRODUCTID = '" + pPid + "' "
+ " and " + conditions.join(" and ")
+ " order by " + orderby.join(", ");
var ProductData = db.table([ProductDataSql, sqltypes]);
for(var i = 0; i < ProductData.length; i++)
{
//Product
if(ProductDetails[ProductData[i][0]] == undefined)
{
ProductDetails[ProductData[i][0]] = {
productId: ProductData[i][0]
, productName: ProductData[i][1]
, groupCode: ProductData[i][2]
, unit: ProductData[i][3]
, Prod2Prod: {}
, CurrentValidPriceLists: {}
, PriceListToUse: null
};
}
//Pricelist
var colIdx = colsProduct.length;
if(ProductData[i][colIdx] != "") //Pricelist found
{
ProductDetails[ProductData[i][0]].CurrentValidPriceLists[ProductData[i][colIdx]] = {
priceListId: ProductData[i][colIdx++]
, relationId: ProductData[i][colIdx++]
, priceList: ProductData[i][colIdx++]
, price: ProductData[i][colIdx++]
, vat: ProductData[i][colIdx++]
}
}
}
ProductDetails[pPid].PriceListToUse = _getPriceListToUse(ProductDetails[pPid].CurrentValidPriceLists, pPriceListFilter);
return ProductDetails;
function _getPriceListToUse(pPriceLists, pPriceListFilter)
{
for(var list in pPriceLists)
{
//customer specific price (defined in Org -> Conditions)
if(pPriceListFilter.relationId != "" && pPriceListFilter.relationId == pPriceLists[list].relationId)
{
return pPriceLists[list];
}
//customer deposited price list (defined by Attribute)
if(pPriceListFilter.priceList != "" && pPriceListFilter.priceList == pPriceLists[list].priceList)
{
return pPriceLists[list];
}
//default price list
if(pPriceLists[list].priceList == "1")
{
return pPriceLists[list];
}
}
//no valid price list found
return null;
}
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment