Built files from Bizgaze WebServer
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

savetargetvalue.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. var Bizgaze;
  2. (function (Bizgaze) {
  3. let Apps;
  4. (function (Apps) {
  5. let TM;
  6. (function (TM) {
  7. let Targets;
  8. (function (Targets) {
  9. let Components;
  10. (function (Components) {
  11. class SaveTargetValue extends Unibase.Platform.Core.BaseComponent {
  12. cssFiles() {
  13. return [];
  14. }
  15. jsFiles() {
  16. return ['apps/tm/targets/managers/targetmanager.js'];
  17. }
  18. html() {
  19. var html = `<form id="frm_bizgazeApp_Employee_edit" data-validate="parsley" method="post"><header class="bg-white modal-header pa-10" id="contactheader"></header><div data-simplebar class="scrollable w-f-md simple-scroll-bar" style="overflow:auto;"><div class="table-responsive"><table class="tblContactTarget table-bordered"></table></div></div><footer class="bg-white modal-footer pa-10"><a href="javascript:;" id="btn_CloseTargetemp" class="btn btn-light btn-sm mr-auto">Close</a><a href="javascript:;" id="btn_SaveEmployeeTarget" class="btn btn-primary btn-sm">Save</a></footer></form>`;
  20. return html;
  21. }
  22. load(formId, containerid, callback) {
  23. var instance = this;
  24. $('.modal-body').css('overflow', '');
  25. $("#btn_CloseTargetemp").click(function () {
  26. $('#' + containerid).modal('hide');
  27. $('#' + containerid).remove();
  28. });
  29. $("#btn_SaveEmployeeTarget").click(function () {
  30. instance.saveTarget(containerid);
  31. $('#' + containerid).modal('hide');
  32. $('#' + containerid).remove();
  33. });
  34. }
  35. saveTarget(containerid) {
  36. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  37. var targetdefinitionid = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_targetdefinitionid").Value);
  38. var itemList = [];
  39. $(".tblContactTarget").find(".TargetValue-row").each(function () {
  40. var TagId = Number($(this).find("#hfTagId").val());
  41. var BreakupTenureId = Number($(this).find("#BreakupTenureId").val());
  42. var ContactTargetId = Number($(this).find("#ContactTargetId").val());
  43. var TargetValue = Number($(this).find("#TargetValue").val());
  44. var ContactId = Number($('#hfcontactId').val());
  45. var TotalTarget = Number($(".tblContactTarget").find(".row-total-rw-" + TagId).html());
  46. itemList.push({
  47. TagId: TagId,
  48. BreakupTenureId: BreakupTenureId,
  49. TargetDefinitionId: targetdefinitionid,
  50. ContactTargetId: ContactTargetId,
  51. TargetValue: TargetValue,
  52. ContactId: ContactId,
  53. });
  54. });
  55. var instance = this;
  56. instance.fileCacheHelper.loadJsFile('apps/tm/targets/managers/targetmanager.js', function () {
  57. Bizgaze.Apps.TM.Targets.Managers.TargetManager.Instance().savecontacttargets(itemList).then(function (response) {
  58. if (response != null) {
  59. MessageHelper.Instance().showSuccess(response.message, '');
  60. }
  61. var detailobj = Unibase.Themes.Compact.Components.Details.Instance();
  62. var detail_instance = Unibase.Themes.Compact.Components.Details.Instance();
  63. var containerid = detail_instance._containerId;
  64. var portletid = detail_instance.unibase_core_activeportletid;
  65. detail_instance.loadWidgets(detailobj._installedAppId, portletid, "#" + containerid + "");
  66. });
  67. });
  68. }
  69. loadForm(FormId, Pk_Value, AppConfigurationId, Callback, ElementId) {
  70. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  71. var targetdefinitionid = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_targetdefinitionid").Value);
  72. Bizgaze.Apps.TM.Targets.Components.SaveTargetValue.instance.loadTarget(targetdefinitionid, Pk_Value);
  73. var instance = this;
  74. instance.loadData(Pk_Value);
  75. }
  76. loadData(Pk_Value) {
  77. this.navigationHelper.popup(Pk_Value, '', Bizgaze.Apps.TM.Targets.Components.SaveTargetValue.Instance(), null, Unibase.Platform.Helpers.Size.Large);
  78. }
  79. loadTarget(TargetDefinitionId, ContactId) {
  80. var instance = this;
  81. var ar = [];
  82. this.fileCacheHelper.loadJsFile('apps/tm/targets/managers/targetmanager.js', function () {
  83. Bizgaze.Apps.TM.Targets.Managers.TargetManager.Instance().LoadTargetDetails(TargetDefinitionId, ContactId).then(function (response) {
  84. if (response != null) {
  85. var contacthtml = '<strong class="biz-highlight-bg-color cname">' + response.result.ContactName + '</strong><input type="hidden" id="hfcontactId" class="hf-' + response.result.Contactid + '"value="' + response.result.Contactid + '" />';
  86. $("#contactheader").html(contacthtml);
  87. var element = $(".tblContactTarget");
  88. var html = '<thead> <tr class="text-dark"><td>Tag Name</td>';
  89. var bname = response.result.BreakupTenureName;
  90. for (var i = 0; i < bname.length; i++) {
  91. html += '<td class="text-left volume">' + bname[i] + '</td>';
  92. }
  93. var btid = response.result.BreakupTenureid;
  94. var btid1 = response.result.TenureTypeId;
  95. html += '<td class="text-left">Total</td></tr></thead>';
  96. var contacttaglist = response.result.ContactList;
  97. html += '<tbody>';
  98. var totaltarget = 0;
  99. for (var i = 0; i < contacttaglist.length; i++) {
  100. html += '<tr class="rw-' + contacttaglist[i].TagId + '" id="totvalue"><td style="height: 29px; width: 126px;">' + contacttaglist[i].TagName + '</td>';
  101. var tlist = contacttaglist[i].TargetValues;
  102. var targetval = 0;
  103. for (var j = 0; j < tlist.length; j++) {
  104. html += '<td class="TargetValue-row ' + tlist[j].BreakupTenureName + '">';
  105. html += '<input type = "hidden" id = "hfbreakupname" class="' + tlist[j].BreakupTenureName + '" />' +
  106. ' <input type="hidden" id="hfTagId" class="hf-' + contacttaglist[i].TagId + '" value="' + contacttaglist[i].TagId + '" />' +
  107. ' <input type="hidden" id="BreakupTenureId" class="hf-' + tlist[j].BreakupTenureId + '" value="' + tlist[j].BreakupTenureId + '" />' +
  108. '<input type="hidden" id="ContactTargetId" class="hf-' + tlist[j].ContactTargetId + '" value="' + tlist[j].ContactTargetId + '" />' +
  109. '<input type="text" onkeypress="return (event.charCode == 8 || event.charCode == 0 || event.charCode == 13 || event.charCode == 46) ? null : event.charCode >= 48 && event.charCode <= 57" class="no-border text-left " style="height: 29px; width: 126px;" id="TargetValue" value="' + tlist[j].TargetValue + '" /></td>';
  110. targetval = targetval + tlist[j].TargetValue;
  111. var bval = {
  112. BreakupTenureName: tlist[j].BreakupTenureName,
  113. TargetValue: tlist[j].TargetValue
  114. };
  115. ar.push(bval);
  116. }
  117. html += '<td class="font-bold text-left row-total-rw-' + contacttaglist[i].TagId + '" style="height: 29px; width: 126px;">' + Number(targetval) + '</td>';
  118. html += '</tr>';
  119. totaltarget = totaltarget + targetval;
  120. }
  121. html += '<tr class="font-bold text-left cc" style="height: 29px; width: 126px;">';
  122. html += '<td >Total</td>';
  123. for (var k = 0; k < bname.length; k++) {
  124. var tval = 0;
  125. for (var l = 0; l < ar.length; l++) {
  126. if (bname[k] == ar[l].BreakupTenureName) {
  127. tval = tval + ar[l].TargetValue;
  128. }
  129. }
  130. html += '<td class="col-tot-' + bname[k] + ' coltot">' + tval + '</td>';
  131. }
  132. html += '<td class="maintotal">' + totaltarget + '</td>';
  133. html += '</tr>';
  134. html += '</tbody>';
  135. element.html(html);
  136. var ProviderName = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_providername").Value;
  137. if (ProviderName == "Sales Target By Value For Employee" || ProviderName == "Sales Target By Volume For Employee" || ProviderName == "Sales Target By Value For Customer" || ProviderName == "Sales Target By Volume For Customer") {
  138. $('.TargetValue-row').keyup(function (event) {
  139. if (event.which != 46 && (event.which < 47 || event.which > 59)) {
  140. event.preventDefault();
  141. if ((event.which == 46)) {
  142. event.preventDefault();
  143. }
  144. }
  145. });
  146. }
  147. else {
  148. $('.TargetValue-row').keyup(function (event) {
  149. if ((event.which > 47 && event.which < 58) || (event.which == 37 || event.which == 124)) {
  150. }
  151. else {
  152. event.preventDefault();
  153. }
  154. }).on('paste', function (event) {
  155. event.preventDefault();
  156. });
  157. }
  158. Bizgaze.Apps.TM.Targets.Components.SaveTargetValue.instance.bind(element);
  159. }
  160. });
  161. });
  162. }
  163. bind(element) {
  164. $('.tblContactTarget tr').each(function () {
  165. $(this).find('.TargetValue-row').each(function () {
  166. var cls = $(this).attr('class').split(' ');
  167. Bizgaze.Apps.TM.Targets.Components.SaveTargetValue.instance.calculate(cls[0]);
  168. });
  169. });
  170. }
  171. calculate(cls) {
  172. function delay(callback, ms) {
  173. var timer = 0;
  174. return function () {
  175. var context = this, args = arguments;
  176. clearTimeout(timer);
  177. timer = setTimeout(function () {
  178. callback.apply(context, args);
  179. }, ms || 0);
  180. };
  181. }
  182. $('.' + cls + '').keyup(delay(function (e) {
  183. var brekupclass = $(this).find('#hfbreakupname').attr('class');
  184. var elemrn = $(this).parent().attr('class');
  185. const $cells = $('.' + elemrn).find('.TargetValue-row');
  186. var rowTotal = 0;
  187. $cells.each(function eachCell(i) {
  188. var val2 = $(this).find("#TargetValue").val();
  189. rowTotal += Number(val2);
  190. });
  191. $('.row-total-' + elemrn).text(rowTotal.toFixed(2));
  192. var sumcolumn = 0;
  193. $('.' + brekupclass).each(function () {
  194. var value = $(this).find("#TargetValue").val();
  195. if (!isNaN(value) && value.length != 0) {
  196. sumcolumn += Number(value);
  197. }
  198. });
  199. $(".col-tot-" + brekupclass + "").text(sumcolumn.toFixed(2));
  200. var maintotal = 0;
  201. var element = $('.cc').find('.coltot');
  202. element.each(function () {
  203. var value = $(this).text();
  204. if (!isNaN(value) && value.length != 0) {
  205. maintotal += parseFloat(value);
  206. }
  207. $('.maintotal').text(maintotal.toFixed(2));
  208. });
  209. }, 500));
  210. }
  211. static Instance() {
  212. if (this.instance === undefined) {
  213. this.instance = new SaveTargetValue();
  214. }
  215. return this.instance;
  216. }
  217. }
  218. Components.SaveTargetValue = SaveTargetValue;
  219. })(Components = Targets.Components || (Targets.Components = {}));
  220. })(Targets = TM.Targets || (TM.Targets = {}));
  221. })(TM = Apps.TM || (Apps.TM = {}));
  222. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  223. })(Bizgaze || (Bizgaze = {}));