Question

Please help with this question

Question :

On the Product edit page, develop a new button or action for calculating product popularity. Popularity is calculated as the ratio of the number 

 of products in invoice records that contain the current product, to the total number of products in invoice records. Display the calculation result 

 as a percentage using the message window.

how to solve it by esq?

Like 0

Like

1 comments

Dear Mohamad,

Please see the ESQ example below. The method can be triggered by the button click on th product page.

checkProductNumber: function() {
				var currentProduct = this.get("Id");
				var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "InvoiceProduct" });
				esq.addColumn("Product");
				esq.filters.add("Product", Terrasoft.createColumnFilterWithParameter(
					Terrasoft.ComparisonType.EQUAL, "Product", currentProduct));
				esq.getEntityCollection(function(response) {
					if (response && response.success) {
						var quantity = response.collection.collection.length;
						if (quantity > 0) {
							var esq1 = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "InvoiceProduct" });
							esq1.addColumn("Id");
							esq1.getEntityCollection(function(result) {
								if (result && result.success) {
									var total = result.collection.collection.length;
									this.showInformationDialog(quantity / total);
								}
							}, this);
						} else {
							this.showInformationDialog("This product is not indicated in any invoice.");
						}
					}
				}, this);
			}

Hope you will find it helpful.

Regards, 

Anastasia

Show all comments