103 lines
4.2 KiB
JavaScript
103 lines
4.2 KiB
JavaScript
import { showSuccess, showError } from "@nextcloud/dialogs";
|
|
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
|
|
import { baseUrl, showLoader , cur} from "../mainFunction.mjs";
|
|
|
|
/**
|
|
* Update order date
|
|
* @param orderId
|
|
* @param dateValue
|
|
*/
|
|
export function updateOrderDate(orderId,dateValue) {
|
|
var payload = {
|
|
orderDate: dateValue
|
|
};
|
|
|
|
$.ajax({
|
|
url: baseUrl + '/order/'+orderId+'/updateDate',
|
|
type: 'PUT',
|
|
async: false,
|
|
contentType: 'application/json',
|
|
data: JSON.stringify(payload)
|
|
}).done(function (response, code) {
|
|
showSuccess(t('gestion', 'Succès'));
|
|
}).fail(function (response, code) {
|
|
showError(t('gestion', 'Erreur dans la mise à jour de la date du commande'));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get order products
|
|
*/
|
|
export function getOrderItemsByOrderId(orderId) {
|
|
$.ajax({
|
|
url: baseUrl + '/order/'+orderId+'/items',
|
|
type: 'PROPFIND',
|
|
async: false,
|
|
contentType: 'application/json'
|
|
}).done(function (response, code) {
|
|
$('#orderItems tbody').empty();
|
|
|
|
$.each(JSON.parse(response), function (arrayID, myresp) {
|
|
$('#orderItems tbody').append(
|
|
'<tr>' +
|
|
'<td>'+
|
|
'<div data-modifier="getOrderItemsByOrderId" data-id="' + myresp.order_item_id + '" data-table="order_item" class="deleteItem icon-delete"></div>'+
|
|
'<div class="selectableOrderItem" data-order-item-id="' + myresp.order_item_id +'" data-order-product-id="' + myresp.order_product_id + '" data-order-id="' + orderId + '" style="display:inline;">' + myresp.order_product_reference + '</div></td>' +
|
|
'<td>' + myresp.order_product_label + '</td>' +
|
|
'<td><div style="display:inline;" data-modifier="getOrderItemsByOrderId">' + myresp.order_item_quantity + '</div> </td>' +
|
|
'<td>' + cur.format(myresp.order_product_ht_amount) + '</td>' +
|
|
'<td>' + cur.format((myresp.order_item_quantity * myresp.order_product_ht_amount)) + '</td></tr>');
|
|
});
|
|
|
|
$("#totalOrderItems tbody").empty();
|
|
getTotalAmountOfOrder(orderId);
|
|
}).fail(function (response, code) {
|
|
showError(response);
|
|
});
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} orderId
|
|
*/
|
|
export function getTotalAmountOfOrder(orderId) {
|
|
$.ajax({
|
|
url: baseUrl + '/order/'+orderId+'/totalAmount',
|
|
type: 'PROPFIND',
|
|
contentType: 'application/json'
|
|
}).done((function (totalAmountResult) {
|
|
var totalAmount = JSON.parse(totalAmountResult);
|
|
$('#totalOrderItems tbody').empty();
|
|
$('#totalOrderItems tbody').append(
|
|
'<tr>'+
|
|
'<td style="text-align:center;">' + cur.format(totalAmount.totalHt)+'</td>'+
|
|
'<td id="tva" style="text-align:center;">' + totalAmount.tva + ' %</td>'+
|
|
'<td id="totaltva" style="text-align:center;">' + cur.format(Math.round((totalAmount.totalHt * totalAmount.tva)) / 100) + '</td>'+
|
|
'<td style="text-align:center;">' + cur.format(Math.round((totalAmount.totalHt * (totalAmount.tva + 100))) / 100) + '</td></tr>');
|
|
}));
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} select
|
|
* @param {*} orderItemId
|
|
* @param {*} orderProductId
|
|
*/
|
|
export function loadOrderProductIntoSelect(selectSelector, orderItemId, orderProductId,orderId) {
|
|
$.ajax({
|
|
url: baseUrl + '/orderProduct/list',
|
|
type: 'PROPFIND',
|
|
contentType: 'application/json'
|
|
}).done(function (response) {
|
|
selectSelector.append('<option data-table="order_item" data-column="fk_order_item_id" data-val="' + orderProductId + '" data-id="' + orderItemId + '">'+t('gestion','Cancel')+'</option>');
|
|
$.each(JSON.parse(response), function (arrayID, myresp) {
|
|
var selected = "";
|
|
if (orderProductId == myresp.id) {
|
|
selected = "selected";
|
|
}
|
|
selectSelector.append('<option ' + selected + ' data-table="order_item" data-column="fk_order_item_id" data-order-id="' + orderId + '" data-val="' + myresp.id + '" data-id="' + orderItemId + '">' + myresp.reference + '</option>');
|
|
});
|
|
}).fail(function (response, code) {
|
|
showError(response);
|
|
});
|
|
} |