Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
Issue #592
  • Loading branch information
rsoika committed Aug 7, 2024
1 parent 4503f30 commit 48572dd
Showing 1 changed file with 70 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough">


<h:panelGroup layout="block" styleClass="imixs-form-section" rendered="#{!readonly}"
id="oderlist" binding="#{orderlistContainer}">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:a="http://xmlns.jcp.org/jsf/passthrough">


<h:panelGroup layout="block" styleClass="imixs-form-section" rendered="#{!readonly}" id="oderlist"
binding="#{orderlistContainer}">

<f:ajax render="oderlist" onevent="updateOrderItems">
<table class="imixsdatatable imixs-orderitems">

<tr>
<th style="">#{resourceBundleHandler.findMessage('orderitems.pos')}</th>
<th style="">#{resourceBundleHandler.findMessage('orderitems.description')}<span class="imixs-required"> *</span></th>
<th style="">#{resourceBundleHandler.findMessage('orderitems.description')}<span
class="imixs-required"> *</span></th>
<th style="width: 100px;">#{resourceBundleHandler.findMessage('orderitems.unit')}</th>
<th style="width: 50px;">#{resourceBundleHandler.findMessage('orderitems.quantity')}</th>
<th style="width: 100px;">#{resourceBundleHandler.findMessage('orderitems.price')}</th>
<th style="width: 100px">#{resourceBundleHandler.findMessage('orderitems.total')}<span class="imixs-required"> *</span></th>
<th style="width: 100px">#{resourceBundleHandler.findMessage('orderitems.total')}<span
class="imixs-required"> *</span></th>
<th style="width: 5px;">
<!-- delete -->
</th>
Expand All @@ -27,36 +26,43 @@
<ui:repeat var="orderitem" value="#{childItemController.childItems}">
<tr>
<!-- pos -->
<td><h:outputText value="#{orderitem.item['numpos']}" /></td>
<td>
<h:outputText value="#{orderitem.item['numpos']}" />
</td>

<!-- Name -->
<td><h:inputText value="#{orderitem.item['name']}" style="width:100%" /></td>


<td><h:inputText value="#{orderitem.item['unit']}" style="width:100%;" /></td>
<td>
<h:inputText value="#{orderitem.item['name']}" style="width:100%" />
</td>


<td>
<h:inputText value="#{orderitem.item['unit']}" style="width:100%;" />
</td>

<td><h:inputText value="#{orderitem.item['quantity']}"
a:data-id="orderitem_ammount" style="width:100%;"/>
<td>
<h:inputText value="#{orderitem.item['quantity']}" a:data-id="orderitem_amount"
style="width:100%;" />
</td>

<td><h:inputText value="#{orderitem.item['price']}"
a:data-id="orderitem_price" style="text-align: right;width:100%;">

<td>
<h:inputText value="#{orderitem.item['price']}" a:data-id="orderitem_price"
style="text-align: right;width:100%;">
<f:convertNumber minFractionDigits="2" locale="de" />
</h:inputText>
</td>

<td data-id="orderitem_summary" style="text-align: right;"></td>

<td><h:commandLink
actionListener="#{childItemController.remove(orderitem.item['numpos'])}">
<td>
<h:commandLink actionListener="#{childItemController.remove(orderitem.item['numpos'])}">
<span class="typcn typcn-trash imixs-state-info"></span>
<f:ajax render="#{orderlistContainer.clientId}"
onevent="updateOrderItems" />
</h:commandLink>
<f:ajax render="#{orderlistContainer.clientId}" onevent="updateOrderItems" />
</h:commandLink>
<!-- item summary -->
<h:inputHidden value="#{orderitem.item['total']}" a:data-id="orderitem_total">
<f:convertNumber minFractionDigits="2" locale="de" />
</h:inputHidden>
<f:convertNumber minFractionDigits="2" locale="de" />
</h:inputHidden>
</td>
</tr>
</ui:repeat>
Expand All @@ -76,7 +82,7 @@
<h:inputHidden value="#{workitem.item['order.total']}" a:data-id="orderitems_capacity">
<f:convertNumber minFractionDigits="2" locale="de" />
</h:inputHidden>

<!-- add button -->
<h:commandButton value="#{message.add}" a:data-id="addposbutton_id"
actionListener="#{childItemController.add}">
Expand All @@ -92,12 +98,12 @@
/*<![CDATA[*/

// display summary
$(document).ready(function() {
$(document).ready(function () {
// erste Zeile hinzufügen, falls tabelle noch leer ist
var posTableEmpty=#{empty childItemController.childItems};
var posTableEmpty =#{ empty childItemController.childItems };
if (posTableEmpty) {
// click on add button
posButton=$("[data-id='addposbutton_id']");
posButton = $("[data-id='addposbutton_id']");
if (posButton) {
$(posButton).click();
}
Expand All @@ -115,27 +121,29 @@

//Rechnet die Preise zusammen
function calculateSummary() {
var price = 0, ammount = 0, sum = 0, total = 0;
var price = 0, amount = 0, sum = 0, total = 0;
var summaryItems = $("[data-id='orderitem_summary']");
$(summaryItems).each(function(index, value) {
$(summaryItems).each(function (index, value) {
var tableRow = $(this).closest('tr');
var inputammout = $("[data-id='orderitem_ammount']", tableRow);
var inputprice = $("[data-id='orderitem_price']", tableRow);
if (inputammout && inputprice) {
ammount = convertToNumber(inputammout.val());
price = convertToNumber(inputprice.val());
console.log('ammount=' + ammount);
console.log('price=' + price);
if (!isNaN(ammount) && !isNaN(price)) {
sum = ammount * price;
var inputAmount = $("[data-id='orderitem_amount']", tableRow);
var inputPrice = $("[data-id='orderitem_price']", tableRow);
if (inputAmount && inputPrice) {
amount = convertToNumber(inputAmount.val());
price = convertToNumber(inputPrice.val());
// console.log('amount=' + amount);
// console.log('price=' + price);
if (!isNaN(amount) && !isNaN(price)) {
sum = amount * price;
// round
sum = Math.round(sum * 100) / 100;
total = total + sum;

$("[data-id='orderitem_price']",tableRow).val(convertToCurrency(price));
// round
total = Math.round(total * 100) / 100;

$("[data-id='orderitem_price']", tableRow).val(convertToCurrency(price));
sum = convertToCurrency(sum);
//console.log('sum=' + sum);
$("[data-id='orderitem_total']",tableRow).val(sum); // hidden field
// console.log('sum=' + sum);
$("[data-id='orderitem_total']", tableRow).val(sum); // hidden field
// update display column
$("[data-id='orderitem_summary']", tableRow).empty();
$("[data-id='orderitem_summary']", tableRow).append(sum);
Expand All @@ -151,27 +159,24 @@

}

/* format 1.000,00 to 1000.00 */
function convertToNumber(currency) {
// has ,?
if (currency && currency.indexOf(',')>-1) {
currency=currency.trim();
//remove .
currency = currency.replace('.', '');
// replace ,
currency = currency.replace(',', '.');
}
return currency;
currency = currency.replace(/\./g, '');
currency = currency.replace(/\,/g, '.');
return currency * 1; // convert to number
}

function convertToCurrency(sum) {
sum = ("" + sum).replace('.', ',');
if (sum.indexOf(',') == -1)
sum = sum + ",00";
if (sum.indexOf(',') == sum.length - 2)
sum = sum + "0";
return sum;
/* format 1000 into 1.000,00 */
function convertToCurrency(number) {
var splitNum;
//number = Math.abs(number);
number = number.toFixed(2);
splitNum = number.split('.');
splitNum[0] = splitNum[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");
return splitNum.join(",");
}



/*]]>*/
</script>

Expand Down

0 comments on commit 48572dd

Please sign in to comment.