Odyssey
salesItemMaintenance.prg
1 <?php
2 /* File: salesItemMaintenance.html
3  * Purpose: To initialize grid and CRUD calls on the salesItem page
4  */
5 
6 $isInEditList = GetIsInEditList($dbh, $Hu);
7 ?>
8 
9 <script type="text/javascript">
10 
11 <?php
12 // Get common JS functions here.
13 getShowWaitFunctions();
14 ?>
15 
16 var prodDDLData = [];
17 var billingIdentifierDDLData = [];
18 
19 <?php
20 /**
21  * function SetupDialogs()
22  * Set up all the dialogs.
23  * OR supposed to. This is part of a restructuring.
24  * I want to decouple the read calls to one layer of the grid.
25  * I also want to decouple the popups from the grids.
26  * PURPOSE: this script keeps breaking because it is too complex.
27  *
28  * Alas, right now, only the delete dialog is in this function.
29  * Due to a problem deleting immediately after adding the same product.
30  * Adding the same product IS OKAY. There are situations where that makes sense for Paul.
31  */
32 ?>
33 function SetupDialogs() {
34  <?php
35  /**
36  * @var deleteSalesItemDialog
37  * The dialog to confirm deletion of a billing line item.
38  */
39  ?>
40  $("#salesItemGrid").on("click", ".k-grid-customDelete", function() {
41  var salesItemGrid = $("#salesItemGrid").data("kendoGrid");
42  var siTr = $(this).closest("tr");
43  var siDataItem = salesItemGrid.dataItem(siTr);
44 
45  var productId = siDataItem.productId;
46 
47  var deleteSalesItemDialog = $("#deleteSalesItemDialog").data("kendoDialog");
48  if (deleteSalesItemDialog == null) {
49  deleteSalesItemDialog = $("<div id='deleteSalesItemDialog'></div>").appendTo("body").kendoDialog({
50  title: "Confirm Deletion",
51  actions: [
52  {text: "Cancel"},
53  {text: "Delete", primary: true, action: function() {
54 
55  <?php // This is also a stopgap. The idea is to not use $.post.
56  // When the restructuring is done, then it will simply call a read on the grid.
57  // With the delete operation, it will delete and refresh the grid. ?>
58  var productId = $("#deleteSalesItemDialog").data("productId");
59 
60  var parameters = {productId: productId};
61 
62  $.post("index.prg?operation=salesItemRemove", parameters,
63  function (data){
64  hideWaitWindow();
65 
66  var productId = $("#deleteSalesItemDialog").data("productId");
67  var salesItemGrid = $("#salesItemGrid").data("kendoGrid");
68 
69  if (data.status !== "000") {
70  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
71  } else {
72  var gridData = salesItemGrid.dataSource.data();
73  gridData = $.grep(gridData, function(n,i) { return n.productId != productId; });
74  salesItemGrid.dataSource.data(gridData);
75  }
76  });
77  }}
78  ],
79  visible: false,
80  open: function() {
81  if (window.activeWindows != null) {
82  window.activeWindows.push(this);
83  }
84  },
85  close: function() {
86  if (window.activeWindows != null) {
87  window.activeWindows.pop();
88  }
89  },
90  modal: true,
91  content: "Are you sure that you want to delete this line item?"
92  }).data("kendoDialog");
93  }
94 
95  $("#deleteSalesItemDialog").data({productId: productId});
96  deleteSalesItemDialog.open().center();
97  });
98 }
99 
100 <?php
101 /* This function initializes the sales item grid.
102  */ ?>
103 function InitSalesItemMaintenance() {
104  $.homecuValidator.setup({formValidate:'formMain', formStatusField: 'formValidateMainDiv'});
105  var grid = $("#salesItemGrid").kendoGrid({
106  dataSource: {
107  transport: {
108  read: {
109  url: "index.prg?operation=salesItemLoad",
110  dataType: "json",
111  type: "POST"
112  },
113  update: {
114  url: "index.prg?operation=salesItemUpdate",
115  dataType: "json",
116  type: "POST"
117  },
118  create: {
119  url: "index.prg?operation=salesItemCreate",
120  dataType: "json",
121  type: "POST"
122  },
123  parameterMap: function(data, type) {
124  showWaitWindow();
125  if (type == "read") {
126  return {};
127  } else {
128  var parameters = {prodName: data.prodName, description: data.description, billingId: data.billingId, fixed: data.fixed,
129  variable: data.variable, qty1: data.qty1, qty2: data.qty2, calcId: data.calcId, frequency: data.frequency, billsOn: data.billsOn};
130  if (type == "update") {
131  parameters.productId = data.productId;
132  }
133  return parameters;
134  }
135  }
136  },
137  schema: {
138  model: {
139  id: "productId",
140  fields: {
141  productId: {type: "number", editable: false, nullable: false},
142  description: {type: "string"},
143  billingId: {type: "string"},
144  prodName: {type: "string"},
145  template: {type: "string"},
146  calcId: {type: "number"},
147  prodDescr: {type: "string"},
148  billingIdDescr: {type: "string"},
149 
150  // Only for adding and editing purposes
151  fixed: {type: "number"},
152  variable: {type: "number"},
153  qty1: {type: "number"},
154  qty2: {type: "number"},
155 
156  frequencyDescr: {type: "string"},
157  frequency: {type: "number"},
158  billsOn: {type: "string"}
159  }
160  },
161  parse: function (data) {
162  hideWaitWindow();
163  if (data.status !== "000") {
164  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
165  return [];
166  } else if (data.operation == "read") {
167  <?php // Also set up ddls ?>
168  prodDDLData = data.productDDL;
169  billingIdentifierDDLData = data.billingItemDDL;
170  }
171  return data.record;
172  }
173  }
174  },
175  columns: [
176  <?php if ($isInEditList) { ?> {title: "", width: "10%"}, <?php } ?>
177  {field: "prodDescr", title: "Product Name"},
178  {field: "billingIdDescr", title: "Billing Identifier"},
179  {field: "description", title: "Display Name"},
180  {field: "frequencyDescr", title: "Frequency"},
181  {field: "calcId", title: "Calc ID"}
182  ],
183  rowTemplate: $("#rowTemplate").html(),
184  sortable: true,
185  filterable: {extra: false},
186  toolbar: [<?php if ($isInEditList) { ?> {name: "create", text: "", iconClass: "fa fa-plus"},
187  <?php } ?> {name: "showDeleted", text: "Show Deleted Items"}],
188  <?php if ($isInEditList) { ?>
189  editable: {
190  mode: "popup",
191  template: kendo.template($("#popupTemplate").html()),
192  window: {
193  draggable: false,
194  resizable: false,
195  actions: [],
196  width: 500
197  }
198  },
199  edit: function (eThis) {
200 
201  $.homecuValidator.setup({formValidate:'popupForm', formStatusField: 'formValidatePopupDiv', homecuCustomRules: {
202  addRangeGtError: function(input) {
203  if (!$("#quantityRangeDiv").is(":visible")) {
204  return true;
205  }
206  if (!$(input).is("[name='qty2Range']")) {
207  return true;
208  }
209  var qty1 = qty1NtbRange.value();
210  var qty2 = qty2NtbRange.value();
211 
212  if(qty1 != null && qty2 != null && qty2 != -1 && qty2 < qty1) {
213  $(input).attr("data-addRangeGtError-msg", "Range is invalid.");
214  return false;
215  } else {
216  return true;
217  }
218  }
219  }});
220 
221  var popupWindow = eThis.sender.editable.element.data("kendoWindow");
222  popupWindow.title(eThis.model.isNew() ? "Add Sales Item" : "Edit Sales Item");
223 
224  var billingInfo = $.grep(billingIdentifierDDLData, function(n,i) { return n.value == eThis.model.billingId; });
225  var decimals = billingInfo.length === 0 ? 2 : billingInfo[0].configuration.decimals;
226  var format = "{0:c" + decimals + "}";
227 
228  $("input[name='calcId']").kendoNumericTextBox({
229  min: 0,
230  step: 1,
231  value: 0,
232  format: "#"
233  }).data("kendoNumericTextBox");
234 
235  $("#productNameDDL").kendoDropDownList({
236  dataSource: {
237  data: prodDDLData
238  },
239  dataTextField: "text",
240  dataValueField: "value",
241  filter: "startswith",
242  dataBound: function () {
243  if (eThis.model.isNew()) {
244  this.select(0);
245  eThis.model.prodName = this.value();
246  } else {
247  this.value(eThis.model.prodName);
248  }
249  },
250  change: function () {
251  eThis.model.prodName = this.value();
252  }
253  }).data("kendoDropDownList");
254 
255  var fixedNtb = $("input[name='fixed']").kendoNumericTextBox({
256  decimals: decimals,
257  format: format,
258  change: function () {
259  eThis.model.fixed = this.value();
260  }
261  }).data("kendoNumericTextBox");
262  var variableNtb = $("input[name='variable']").kendoNumericTextBox({
263  decimals: decimals,
264  format: format,
265  change: function () {
266  eThis.model.variable = this.value();
267  }
268  }).data("kendoNumericTextBox");
269  var qty1Ntb = $("input[name='qty1']").kendoNumericTextBox({
270  decimals: 0,
271  format: "#",
272  min: 0,
273  change: function () {
274  eThis.model.qty1 = this.value();
275  }
276  }).data("kendoNumericTextBox");
277  var qty2Ntb = $("input[name='qty2']").kendoNumericTextBox({
278  decimals: 0,
279  format: "#",
280  min: 0,
281  change: function () {
282  eThis.model.qty2 = this.value();
283  }
284  }).data("kendoNumericTextBox");
285  var qty1NtbRange = $("input[name='qty1Range']").kendoNumericTextBox({
286  decimals: 0,
287  format: "#",
288  min: 0,
289  change: function () {
290  eThis.model.qty1 = this.value();
291  }
292  }).data("kendoNumericTextBox");
293  var qty2NtbRange = $("input[name='qty2Range']").kendoNumericTextBox({
294  decimals: 0,
295  format: "#",
296  min: 0,
297  change: function () {
298  if (this.value() != null) {
299  eThis.model.qty2 = this.value();
300  } else {
301  eThis.model.qty2 = -1;
302  }
303  }
304  }).data("kendoNumericTextBox");
305 
306  <?php
307  /**
308  * function featureDetailDDLChange(e, theObject)
309  * This happens when the feature detail DDL changes. (You can find that on the contract detail's detail grid (on the edit.))
310  *
311  * @param object e -- a rather generic event argument variable
312  * @param object theObject -- the particular object being changed I suppose.
313  */
314  ?>
315  function FeatureDetailDDLChange(e, theObject) {
316  var dataItem = theObject.dataItem();
317  eThis.model.billingId = theObject.value();
318 
319  UpdateSetupRecurring(dataItem.configuration.setup);
320  UpdateQuantityLabels(dataItem.configuration, eThis.model);
321  UpdateFixedVariableLabels(dataItem.configuration, eThis.model);
322 
323  eThis.model.qty1 = 0;
324  eThis.model.fixed = 0;
325  eThis.model.variable = 0;
326  if ($("#quantityRangeDiv:visible").length > 0) {
327  eThis.model.qty2 = -1;
328  } else {
329  eThis.model.qty2 = 0;
330  }
331 
332  fixedNtb.value(0);
333  variableNtb.value(0);
334  qty1Ntb.value(0);
335  qty2Ntb.value(0);
336  qty1NtbRange.value(0);
337  qty2NtbRange.value(null);
338  }
339 
340  var billingIdDDL = $("#billingIdDDL").kendoDropDownList({
341  dataSource: {
342  data: billingIdentifierDDLData,
343  schema: {
344  model: {
345  id: "value",
346  fields: {
347  value: {type: "string"},
348  text: {type: "string"},
349  configuration: {type: "odata"}
350  }
351  }
352  }
353  },
354  dataTextField: "text",
355  dataValueField: "value",
356  filter: "startswith",
357  dataBound: function(e) {
358  if (eThis.model.isNew()) {
359  this.select(0);
360  } else {
361  this.value(eThis.model.billingId);
362  }
363  FeatureDetailDDLChange(e, this);
364  },
365  change: function(e) {
366  FeatureDetailDDLChange(e, this);
367  }
368  }).data("kendoDropDownList");
369 
370 
371  $("input[name='qty2Range']").prev().attr("placeholder", $("#infinity").text());
372  // &infin; has to be calculated by the browser first and then it can be used as an attribute.
373 
374  if (eThis.model.isNew()) {
375  $("#idLine").remove();
376  } else {
377 
378  <?php // Populate template fields ?>
379  var templateDecoded = JSON && JSON.parse(eThis.model.template) || $.parseJSON(eThis.model.template);
380  fixedNtb.value(templateDecoded.fixed);
381  variableNtb.value(templateDecoded.variable);
382  qty1Ntb.value(templateDecoded.qty1);
383  qty2Ntb.value(templateDecoded.qty2);
384  qty1NtbRange.value(templateDecoded.qty1);
385 
386  if (templateDecoded.qty2 == -1) {
387  qty2NtbRange.value(null);
388  } else {
389  qty2NtbRange.value(templateDecoded.qty2);
390  }
391 
392  eThis.model.fixed = templateDecoded.fixed;
393  eThis.model.variable = templateDecoded.variable;
394  eThis.model.qty1 = templateDecoded.qty1;
395  eThis.model.qty2 = templateDecoded.qty2;
396  }
397 
398  if (!eThis.model.setup) {
399  var months = [ {value: 0, text: "January"}, {value: 1, text: "February"}, {value: 2, text: "March"}, {value: 3, text: "April"}, {value: 4, text: "May"},
400  {value: 5, text: "June"}, {value: 6, text: "July"}, {value: 7, text: "August"}, {value: 8, text: "September"},
401  {value: 9, text: "October"}, {value: 10, text: "November"}, {value: 11, text: "December"} ];
402  var billsOn = {
403  dataSource: {
404  data: months
405  },
406  dataTextField: "text",
407  dataValueField: "value"
408  };
409 
410  var billsOn1DDL = $("#billsOn1DDL").kendoDropDownList(billsOn).data("kendoDropDownList");
411  var billsOn2DDL = $("#billsOn2DDL").kendoDropDownList(billsOn).data("kendoDropDownList");
412 
413  billsOn1DDL.bind("change", function () {
414  if ($("#billsOn2Div:visible").length > 0) {
415  var val1 = this.value();
416  var val2 = (val1 + 6) % 12;
417  billsOn2DDL.value(val2);
418  var data1 = $.grep(months, function(n,i) { return n.value != val2; });
419  billsOn1DDL.dataSource.data(data1);
420  var data2 = $.grep(months, function(n,i) { return n.value != val1; });
421  billsOn2DDL.dataSource.data(data2);
422  }
423  });
424 
425  billsOn2DDL.bind("change", function () {
426  if ($("#billsOn1Div:visible").length > 0) {
427  var val2 = this.value();
428  var val1 = (val2 - 6) % 12;
429  var data1 = $.grep(months, function(n,i) { return n.value != val2; });
430  billsOn1DDL.dataSource.data(data1);
431  var data2 = $.grep(months, function(n,i) { return n.value != val1; });
432  billsOn2DDL.dataSource.data(data2);
433  }
434  });
435 
436  var frequencyDDL = $("#frequencyDDL").kendoDropDownList({
437  dataSource: {
438  data: [{value: 0, text: "Monthly"}, {value: 1, text: "Semiyearly"}, {value: 2, text: "Yearly"}]
439  },
440  dataTextField: "text",
441  dataValueField: "value",
442  change: function() {
443  switch(this.value()) {
444  case 0:
445  $("#billsOn1Div").hide();
446  $("#billsOn2Div").hide();
447  break;
448  case 1:
449  $("#billsOn1Div").show();
450  $("#billsOn2Div").show();
451  billsOn1DDL.value(0);
452  billsOn2DDL.value(6);
453  billsOn1DDL.dataSource.data($.grep(months, function(n,i) { return n.value != 6; }));
454  billsOn2DDL.dataSource.data($.grep(months, function(n,i) { return n.value != 0; }));
455  break;
456  case 2:
457  $("#billsOn1Div").show();
458  $("#billsOn2Div").hide();
459  billsOn1DDL.value(0);
460  billsOn1DDL.dataSource.data(months.slice(0));
461  break;
462  }
463  }
464  }).data("kendoDropDownList");
465 
466  if (eThis.model.isNew()) {
467  frequencyDDL.value(0);
468  } else {
469  var billsOn = eThis.model.billsOn;
470  var digit = 1;
471  var frequency = eThis.model.frequency;
472  frequencyDDL.value(frequency);
473 
474  switch(frequency) {
475  case 1:
476  $("#billsOn1Div").show();
477  $("#billsOn2Div").show();
478  break;
479  case 2:
480  $("#billsOn1Div").show();
481  break;
482  }
483 
484  var billsOnArray = eThis.model.billsOn.split(",");
485  if (billsOnArray.length >= 2) {
486  billsOn2DDL.value(billsOnArray[1]);
487  billsOn1DDL.value(billsOnArray[0]);
488  billsOn1DDL.dataSource.data($.grep(months, function(n,i) { return n.value != billsOnArray[1]; }));
489  billsOn2DDL.dataSource.data($.grep(months, function(n,i) { return n.value != billsOnArray[0]; }));
490  } else if (billsOnArray.length == 1) {
491  billsOn1DDL.value(billsOnArray[0]);
492  }
493  }
494  }
495  },
496  save: function (e) {
497  if (!$.homecuValidator.validate()) {
498  e.preventDefault();
499  return false;
500  } else {
501  $.homecuValidator.setup({formValidate:'formMain', formStatusField: 'formValidateMainDiv'});
502  }
503 
504  if (!e.model.setup) {
505  e.model.frequency = $("#frequencyDDL").data("kendoDropDownList").value();
506 
507  var billsOn = [];
508  switch(e.model.frequency) {
509  case 1:
510  billsOn.push($("#billsOn1DDL").data("kendoDropDownList").value());
511  billsOn.push($("#billsOn2DDL").data("kendoDropDownList").value());
512  break;
513  case 2:
514  billsOn.push($("#billsOn1DDL").data("kendoDropDownList").value());
515  break;
516  }
517  e.model.billsOn = kendo.stringify(billsOn);
518  }
519  }
520  <?php } ?>
521  }).data("kendoGrid");
522 
523  $("#salesItemGrid .k-grid-showDeleted").click(function () {
524  ShowDeletedItemModal();
525  return false;
526  });
527 }
528 
529 <?php if ($isInEditList) {
530 /* This hides the recurring div if the billing item is setup, otherwise it shows the recurring div.
531  * Parameters: isSetup-- Boolean
532  */ ?>
533 function UpdateSetupRecurring(isSetup) {
534  var endDatePicker = $("#endDate").data("kendoDatePicker");
535  if (isSetup) {
536  $("#recurringOnly").hide();
537  } else {
538  $("#recurringOnly").show();
539  }
540 }
541 
542 <?php
543 /* Updates the labels of Quantity1 and Quantity2 according to the labelType: "range" will use a separate template; "left" will set labels to the left side of the text boxes;
544  * "left and right" will set labels to both sides; and any other value will set it to the default: "Quantity 1:" and "Quantity 2:" on the left side and nothing on the right side.
545  * Parameters: labels-- array of labels to set, labelType-- specifies what to do with the labels
546  */ ?>
547 function UpdateQuantityLabels(configuration, model) {
548  var labelType = configuration.quantityLabelType;
549  var labels = configuration.quantityLabels;
550  if (!model.isNew()) { // Get configuration specific to sales item id (if exists)
551  if (typeof(configuration.quantityLabelTypeVariance) != "undefined") {
552  var typeVariance = configuration.quantityLabelTypeVariance[model.productId];
553  labelType = typeof(typeVariance) == "undefined" ? configuration.quantityLabelType : typeVariance;
554  }
555 
556  if (typeof(configuration.quantityLabelsVariance) != "undefined") {
557  var labelsVariance = configuration.quantityLabelsVariance[model.productId];
558  labels = typeof(labelsVariance) == "undefined" ? configuration.quantityLabels : labelsVariance;
559  }
560  }
561  var legalArray = ["range", "left", "left and right", "none", "no qty1", "no qty2"];
562  if (typeof(labelType) == "undefined" || legalArray.indexOf(labelType) == -1) {
563  $("#quantity1Row").show();
564  $("#quantity2Row").show();
565  $("#quantityRangeDiv").hide();
566  $("#quantity1Row .custLabel:eq(0)").text("Quantity 1:");
567  $("#quantity1Row .custLabel:eq(1)").text("");
568  $("#quantity2Row .custLabel:eq(0)").text("Quantity 2:");
569  $("#quantity2Row .custLabel:eq(1)").text("");
570  } else if (labelType == "none") {
571  $("#quantity1Row").hide();
572  $("#quantity2Row").hide();
573  $("#quantityRangeDiv").hide();
574  } else if (labelType == "no qty1") {
575  $("#quantity1Row").hide();
576  $("#quantity2Row").show();
577  $("#quantityRangeDiv").hide();
578 
579  if (typeof(labels) == "undefined") {
580  $("#quantity2Row .custLabel:eq(0)").text("Quantity 2:");
581  $("#quantity2Row .custLabel:eq(1)").text("");
582  } else {
583  $("#quantity2Row .custLabel:eq(0)").text(labels[0]);
584  $("#quantity2Row .custLabel:eq(1)").text(labels[1]);
585  }
586  } else if (labelType == "no qty2") {
587  $("#quantity1Row").show();
588  $("#quantity2Row").hide();
589  $("#quantityRangeDiv").hide();
590 
591  if (typeof(labels) == "undefined") {
592  $("#quantity1Row .custLabel:eq(0)").text("Quantity 1:");
593  $("#quantity1Row .custLabel:eq(1)").text("");
594  } else {
595  $("#quantity1Row .custLabel:eq(0)").text(labels[0]);
596  $("#quantity1Row .custLabel:eq(1)").text(labels[1]);
597  }
598  } else if (labelType == "range") {
599  $("#quantity1Row").hide();
600  $("#quantity2Row").hide();
601  $("#quantityRangeDiv").show();
602 
603  if (typeof(labels) == "undefined") {
604  $("#quantityRangeDiv .custLabel:eq(0)").text("Range:");
605  } else {
606  $("#quantityRangeDiv .custLabel:eq(0)").text(labels[0]);
607  }
608  } else if (labelType == "left") {
609  $("#quantity1Row").show();
610  $("#quantity2Row").show();
611  $("#quantityRangeDiv").hide();
612  $("#quantity1Row .custLabel:eq(1)").text("");
613  $("#quantity2Row .custLabel:eq(1)").text("");
614 
615  if (typeof(labels) == "undefined") {
616  $("#quantity1Row .custLabel:eq(0)").text("Quantity 1:");
617  $("#quantity2Row .custLabel:eq(0)").text("Quantity 2:");
618  } else {
619  $("#quantity1Row .custLabel:eq(0)").text(labels[0]);
620  $("#quantity2Row .custLabel:eq(0)").text(labels[1]);
621  }
622  } else if (labelType == "left and right") {
623  $("#quantity1Row").show();
624  $("#quantity2Row").show();
625  $("#quantityRangeDiv").hide();
626 
627  if (typeof(labels) == "undefined") {
628  $("#quantity1Row .custLabel:eq(0)").text("Quantity 1:");
629  $("#quantity1Row .custLabel:eq(1)").text("");
630  $("#quantity2Row .custLabel:eq(0)").text("Quantity 2:");
631  $("#quantity2Row .custLabel:eq(1)").text("");
632  } else {
633  $("#quantity1Row .custLabel:eq(0)").text(labels[0]);
634  $("#quantity1Row .custLabel:eq(1)").text(labels[1]);
635  $("#quantity2Row .custLabel:eq(0)").text(labels[2]);
636  $("#quantity2Row .custLabel:eq(1)").text(labels[3]);
637  }
638  }
639 }
640 
641 <?php
642 /* Updates the labels of fixed and variable according to the labelType.
643  * Parameters: labels-- array of labels to set, labelType-- specifies what to do with the labels
644  */ ?>
645 function UpdateFixedVariableLabels(configuration, model) {
646  var labelType = configuration.fixedVariableLabelType;
647  var labels = configuration.fixedVariableLabels;
648  if (!model.isNew()) { // Get configuration specific to sales item id (if exists)
649  if (typeof(configuration.fixedVariableLabelTypeVariance) != "undefined") {
650  var typeVariance = configuration.fixedVariableLabelTypeVariance[model.productId];
651  labelType = typeof(typeVariance) == "undefined" ? configuration.fixedVariableLabelType : typeVariance;
652  }
653  if (typeof(configuration.fixedVariableLabelsVariance) != "undefined") {
654  var labelsVariance = configuration.fixedVariableLabelsVariance[model.productId];
655  labels = typeof(labelsVariance) == "undefined" ? configuration.fixedVariableLabels : labelsVariance;
656  }
657  }
658 
659  var legalArray = ["left", "none", "no fixed", "no variable"];
660  if (typeof(labelType) == "undefined" || legalArray.indexOf(labelType) == -1) {
661  $("#fixedRow").show();
662  $("#variableRow").show();
663  $("#fixedRow .custLabel:eq(0)").text("Fixed:");
664  $("#variableRow .custLabel:eq(0)").text("Variable:");
665  } else if (labelType == "none") {
666  $("#fixedRow").hide();
667  $("#variableRow").hide();
668  } else if (labelType == "no fixed") {
669  $("#fixedRow").hide();
670  $("#variableRow").show();
671 
672  if (typeof(labels) != "undefined") {
673  $("#variableRow .custLabel:eq(0)").text(labels[0]);
674  } else {
675  $("#variableRow .custLabel:eq(0)").text("Variable:");
676  }
677  } else if (labelType == "no variable") {
678  $("#fixedRow").show();
679  $("#variableRow").hide();
680 
681  if (typeof(labels) != "undefined") {
682  $("#fixedRow .custLabel:eq(0)").text(labels[0]);
683  } else {
684  $("#variableRow .custLabel:eq(0)").text("Fixed:");
685  }
686  } else if (labelType == "left") {
687  $("#fixedRow").show();
688  $("#variableRow").show();
689 
690  if (typeof(labels) != "undefined") {
691  $("#fixedRow .custLabel:eq(0)").text(labels[0]);
692  $("#variableRow .custLabel:eq(0)").text(labels[1]);
693  } else {
694  $("#fixedRow .custLabel:eq(0)").text("Fixed:");
695  $("#variableRow .custLabel:eq(0)").text("Variable:");
696  }
697  }
698 }
699 
700 <?php } ?>
701 
702 function ShowDeletedItemModal() {
703  var modal = $("#deletedItemModal").data("kendoWindow");
704  var grid = $("#deletedItemGrid").data("kendoGrid");
705  if (modal != null) {
706  grid.dataSource.read();
707  modal.open().center();
708  } else {
709  modal = $("<div id='deletedItemModal'></div>").kendoWindow({
710  content: {
711  template: kendo.template($("#deletedItemTemplate").html())
712  },
713  modal: true,
714  title: "Deleted Sales Items",
715  visible: false,
716  actions: [],
717  draggable: false,
718  resizable: false,
719  width: 600,
720  }).data("kendoWindow");
721 
722  grid = $("#deletedItemGrid").kendoGrid({
723  dataSource: {
724  transport: {
725  read: {
726  url: "index.prg?operation=getDeletedSalesItems",
727  dataType: "json",
728  type: "POST"
729  },
730  parameterMap: function(data, type) {
731  showWaitWindow();
732  return {};
733  }
734  },
735  schema: {
736  model: {
737  id: "salesItemId",
738  fields: {
739  salesItemId: {type: "number"},
740  deletedDate: {type: "date"},
741  productName: {type: "string"},
742  billingName: {type: "string"},
743  displayName: {type: "string"}
744  }
745  },
746  parse: function (data) {
747  hideWaitWindow();
748  if (data.status !== "000") {
749  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
750  return [];
751  } else {
752  return data.record;
753  }
754 
755  }
756  },
757  sort: {field: "deletedDate", dir: "desc"}
758  },
759  sortable: true,
760  filterable: true,
761  columns: [
762  {field: "deletedDate", title: "Date", format: "{0:d}"},
763  {field: "displayName", title: "Name"},
764  {field: "productName", title: "Product"},
765  {field: "billingName", title: "Feature"}
766  ]
767  }).data("kendoGrid");
768 
769  modal.open().center();
770 
771  $("#deletedItemModal .okayBtn").click(function () {
772  modal.close();
773  grid.dataSource.data([]);
774  return false;
775  });
776  }
777 }
778 
779 var activeWindows = [];
780 $(document).ready(function () {
781  InitSalesItemMaintenance();
782  SetupDialogs();
783  $("body").on("click", ".k-overlay", function() { if (activeWindows.length > 0) activeWindows[activeWindows.length - 1].close(); return false; });
784 });
785 </script>
786 <script id="deletedItemTemplate" type="text/x-kendo-template">
787  <div class="container_12">
788  <div class="grid_12"><div id="deletedItemGrid"></div></div>
789  <div class="grid_12">
790  <a class="k-button k-button-icontext okayBtn" href="\#">
791  <span class="k-icon k-update"></span>
792  Okay
793  </a>
794  </div>
795  </div>
796 </script>
797 <script id="rowTemplate" type="text/x-kendo-template">
798  <tr class="normalRow" data-uid="#= uid #">
799  <?php if ($isInEditList) { ?> <td class="needsBorder">
800  <a class="k-button k-button-icontext k-grid-edit" href="\#">
801  <span class="fa fa-edit"></span>
802  </a>
803  <a class="k-button k-button-icontext k-grid-customDelete" href="\#">
804  <span class="fa fa-trash"></span>
805  </a>
806  </td> <?php } ?>
807  <td class="needsBorder">#: prodDescr #</td>
808  <td>#: billingIdDescr #</td>
809  <td>#: description #</td>
810  <td>#: frequencyDescr #</td>
811  <td>#: calcId #</td>
812  </tr>
813 </script>
814 <?php if ($isInEditList) { ?>
815 <script id="popupTemplate" type="text/x-kendo-template">
816  <div id="formValidatePopupDiv" style="display:none;"></div>
817  <form id="popupForm">
818  <div class="container_12">
819  <div class="grid_12" id="idLine">
820  <div class="grid_4 alpha">
821  <label>Id:</label>
822  </div>
823  <div class="grid_7">
824  <div id="nameLabel">#: productId #</div>
825  </div>
826  <div class="grid_1 omega">
827  <span data-for='productId' class='k-invalid-msg'></span>
828  </div>
829  </div>
830  <div class="grid_12">
831  <div class="grid_4 alpha">
832  <label>Product Name:</label>
833  </div>
834  <div class="grid_7">
835  <div id="productNameDDL" style="width:100%"></div>
836  </div>
837  <div class="grid_1 omega">
838  <span data-for='prodName' class='k-invalid-msg'></span>
839  </div>
840  </div>
841  <div class="grid_12">
842  <div class="grid_4 alpha">
843  <label>Billing Identifier:</label>
844  </div>
845  <div class="grid_7">
846  <div id="billingIdDDL" style="width:100%"></div>
847  </div>
848  <div class="grid_1 omega">
849  <span data-for='billingId' class='k-invalid-msg'></span>
850  </div>
851  </div>
852  <div class="grid_12" id="descriptionRow">
853  <div class="grid_4 alpha">
854  <label>Display Name:</label>
855  </div>
856  <div class="grid_7">
857  <input type="text" class="k-input" id="descriptionInput" name="description" style="width: 100%" maxlength=20>
858  </div>
859  <div class="grid_1 omega">
860  <span data-for='description' class='k-invalid-msg'></span>
861  </div>
862  </div>
863  <div class="grid_12" id="fixedRow">
864  <div class="grid_4 alpha">
865  <label class="custLabel" data-for="fixed">Fixed:</label>
866  </div>
867  <div class="grid_4">
868  <input type="text" name="fixed" style="width: 100%" value="0">
869  </div>
870  <div class="grid_1 omega">
871  <span data-for='fixed' class='k-invalid-msg'></span>
872  </div>
873  </div>
874  <div id="recurringOnly">
875  <div class="grid_12" id="variableRow">
876  <div class="grid_4 alpha">
877  <label class="custLabel" data-for="variable">Variable:</label>
878  </div>
879  <div class="grid_4">
880  <input type="text" name="variable" style="width: 100%" value="0">
881  </div>
882  <div class="grid_1 omega">
883  <span data-for='variable' class='k-invalid-msg'></span>
884  </div>
885  </div>
886  <div class="grid_12" id="quantity1Row">
887  <div class="grid_4 alpha">
888  <label class="custLabel" data-for="qty1">Quantity 1:</label>
889  </div>
890  <div class="grid_4">
891  <input type="text" name="qty1" style="width: 100%" value="0">
892  </div>
893  <div class="grid_3">
894  <label class="custLabel" data-for="qty1"></label>
895  </div>
896  <div class="grid_1 omega">
897  <span data-for='qty1' class='k-invalid-msg'></span>
898  </div>
899  </div>
900  <div class="grid_12" id="quantity2Row">
901  <div class="grid_4 alpha">
902  <label class="custLabel" data-for="qty2">Quantity 2:</label>
903  </div>
904  <div class="grid_4">
905  <input type="text" name="qty2" style="width: 100%" value="0">
906  </div>
907  <div class="grid_3">
908  <label class="custLabel" data-for="qty2"></label>
909  </div>
910  <div class="grid_1 omega">
911  <span data-for='qty2' class='k-invalid-msg'></span>
912  </div>
913  </div>
914  <div class="grid_12" id="quantityRangeDiv" style="display:none;">
915  <div class="grid_4 alpha">
916  <label class="custLabel">Quantity 1:</label>
917  </div>
918  <div class="grid_3">
919  <input type="text" name="qty1Range" style="width: 100%" value="0">
920  </div>
921  <div class="grid_1">To</div>
922  <div class="grid_3">
923  <input type="text" name="qty2Range" style="width: 100%" data-gt-msg="The second amount has to be greater than the first.">
924  <div id="infinity" style="display:none;">&infin;</div>
925  </div>
926  <div class="grid_1 omega">
927  <span data-for='qty1Range' class='k-invalid-msg'></span>
928  <span data-for='qty2Range' class='k-invalid-msg'></span>
929  </div>
930  </div>
931  <div class="grid_12">
932  <div class="grid_4 alpha">
933  <label>Frequency:</label>
934  </div>
935  <div class="grid_3">
936  <div id="frequencyDDL"></div>
937  </div>
938  <div class="grid_1 omega">
939  &nbsp;
940  </div>
941  </div>
942  <div class="grid_12" id="billsOn1Div" style="display:none;">
943  <div class="grid_4 alpha">
944  <label>Bills On:</label>
945  </div>
946  <div class="grid_3">
947  <div id="billsOn1DDL"></div>
948  </div>
949  <div class="grid_1 omega">
950  &nbsp;
951  </div>
952  </div>
953  <div class="grid_12" id="billsOn2Div" style="display:none;">
954  <div class="grid_4 alpha">
955  <label>And:</label>
956  </div>
957  <div class="grid_3">
958  <div id="billsOn2DDL"></div>
959  </div>
960  <div class="grid_1 omega">
961  &nbsp;
962  </div>
963  </div>
964  </div>
965  <div class="grid_12">
966  <div class="grid_4 alpha">
967  <label>Calculation ID: </label>
968  </div>
969  <div class="grid_4 offset_3">
970  <input type="text" name="calcId" style="width:100%">
971  </div>
972  <div class="grid_1 omega">
973  <span data-for='calcId' class='k-invalid-msg'></span>
974  </div>
975  </div>
976  </div>
977  </form>
978 </script>
979 <?php } ?>
980 <div class="container_12">
981  <div id="formMain"></div>
982  <div id="formValidateMainDiv" style="display:none;"></div>
983  <div class="grid_12">
984  <div id="salesItemGrid" class="minifiedActionGrid"></div>
985  </div>
986 </div>