Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ProductTemplateElementUtil.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
48  {
49  return "
50  function showHideDiscountOrMarkupPercentageTextField(helperValue, textFieldId)
51  {
52  var typeProfitMargin = " . SellPriceFormula::TYPE_PROFIT_MARGIN . ";
53  var typeMarkOverCost = " . SellPriceFormula::TYPE_MARKUP_OVER_COST . ";
54  var typeDiscountFromList = " . SellPriceFormula::TYPE_DISCOUNT_FROM_LIST . ";
55  if (helperValue == typeProfitMargin || helperValue == typeMarkOverCost || helperValue == typeDiscountFromList)
56  {
57  $('#' + textFieldId).show();
58  }
59  else
60  {
61  $('#' + textFieldId).hide();
62  }
63  }
64  ";
65  }
66 
71  {
72  return "
73  function enableDisableSellPriceElementBySellPriceFormula(helperValue, elementId, attribute)
74  {
75  var typeEditable = " . SellPriceFormula::TYPE_EDITABLE . ";
76  if (helperValue != typeEditable)
77  {
78  $('#' + elementId).attr('readonly', true);
79  $('#ProductTemplate_' + attribute + '_currency_id').attr('readonly', 'true');
80  $('#ProductTemplate_' + attribute + '_currency_id').addClass('disabled');
81  $('#' + elementId).addClass('disabled');
82  }
83  else
84  {
85  $('#' + elementId).removeAttr('readonly');
86  $('#ProductTemplate_' + attribute + '_currency_id').removeAttr('readonly');
87  $('#ProductTemplate_' + attribute + '_currency_id').removeClass('disabled');
88  $('#' + elementId).removeClass('disabled');
89  }
90  }
91  ";
92  }
93 
98  {
99  // Begin Not Coding Standard
100  return "
101  $('#ProductTemplate_cost_currency_id').change(function(){calculateSellPriceBySellPriceFormula()});
102  $('#ProductTemplate_listPrice_currency_id').change(function(){calculateSellPriceBySellPriceFormula()});
103  function calculateSellPriceBySellPriceFormula()
104  {
105  var priceCurrency = '';
106  var typeEditable = " . SellPriceFormula::TYPE_EDITABLE . ";
107  var typeProfitMargin = " . SellPriceFormula::TYPE_PROFIT_MARGIN . ";
108  var typeMarkOverCost = " . SellPriceFormula::TYPE_MARKUP_OVER_COST . ";
109  var typeDiscountFromList = " . SellPriceFormula::TYPE_DISCOUNT_FROM_LIST . ";
110  var typeSameAsList = " . SellPriceFormula::TYPE_SAME_AS_LIST . ";
111  var helperValue = $('#ProductTemplate_sellPriceFormula_type').val();
112  var calculatedSellPrice = 0;
113  var discountOrMarkupPercentage = $('#ProductTemplate_sellPriceFormula_discountOrMarkupPercentage').val();
114  if (discountOrMarkupPercentage == '')
115  {
116  discountOrMarkupPercentage = 0;
117  }
118  else
119  {
120  discountOrMarkupPercentage = parseFloat(discountOrMarkupPercentage)/100;
121  }
122  if (helperValue == typeProfitMargin)
123  {
124  var cost = parseFloat($('#ProductTemplate_cost_value').val());
125  calculatedSellPrice = parseFloat(cost/(1-discountOrMarkupPercentage));
126  modCalculatesSellPrice = (Math.round(calculatedSellPrice * 100)/100).toFixed(2);
127  $('#ProductTemplate_sellPrice_value').val(modCalculatesSellPrice);
128  priceCurrency = $('#ProductTemplate_cost_currency_id').val();
129  $('#ProductTemplate_sellPrice_currency_id').val(priceCurrency);
130  $('#ProductTemplate_listPrice_currency_id').val(priceCurrency);
131  $('#ProductTemplate_listPrice_currency_id').attr('readonly','readonly');
132  $('#ProductTemplate_listPrice_currency_id').addClass('disabled');
133  $('#ProductTemplate_cost_currency_id').removeAttr('readonly');
134  $('#ProductTemplate_cost_currency_id').removeClass('disabled');
135  }
136 
137  if (helperValue == typeMarkOverCost)
138  {
139  var cost = parseFloat($('#ProductTemplate_cost_value').val());
140  calculatedSellPrice = (discountOrMarkupPercentage * cost) + cost;
141  $('#ProductTemplate_sellPrice_value').val(calculatedSellPrice);
142  priceCurrency = $('#ProductTemplate_cost_currency_id').val();
143  $('#ProductTemplate_sellPrice_currency_id').val(priceCurrency);
144  $('#ProductTemplate_listPrice_currency_id').val(priceCurrency);
145  $('#ProductTemplate_listPrice_currency_id').attr('readonly','readonly');
146  $('#ProductTemplate_listPrice_currency_id').addClass('disabled');
147  $('#ProductTemplate_cost_currency_id').removeAttr('readonly');
148  $('#ProductTemplate_cost_currency_id').removeClass('disabled');
149  }
150 
151  if (helperValue == typeDiscountFromList)
152  {
153  var listPrice = parseFloat($('#ProductTemplate_listPrice_value').val());
154  calculatedSellPrice = listPrice - (listPrice * discountOrMarkupPercentage);
155  $('#ProductTemplate_sellPrice_value').val(calculatedSellPrice);
156  priceCurrency = $('#ProductTemplate_listPrice_currency_id').val();
157  $('#ProductTemplate_sellPrice_currency_id').val(priceCurrency);
158  $('#ProductTemplate_cost_currency_id').val(priceCurrency);
159  $('#ProductTemplate_cost_currency_id').attr('readonly','readonly');
160  $('#ProductTemplate_cost_currency_id').addClass('disabled');
161  $('#ProductTemplate_listPrice_currency_id').removeAttr('readonly');
162  $('#ProductTemplate_listPrice_currency_id').removeClass('disabled');
163  }
164 
165  if (helperValue == typeSameAsList)
166  {
167  var listPrice = parseFloat($('#ProductTemplate_listPrice_value').val());
168  $('#ProductTemplate_sellPrice_value').val(listPrice);
169  priceCurrency = $('#ProductTemplate_listPrice_currency_id').val();
170  $('#ProductTemplate_sellPrice_currency_id').val(priceCurrency);
171  $('#ProductTemplate_cost_currency_id').val(priceCurrency);
172  $('#ProductTemplate_cost_currency_id').attr('readonly','readonly');
173  $('#ProductTemplate_cost_currency_id').addClass('disabled');
174  $('#ProductTemplate_listPrice_currency_id').removeAttr('readonly');
175  $('#ProductTemplate_listPrice_currency_id').removeClass('disabled');
176  }
177 
178  if (helperValue == typeEditable)
179  {
180  $('#ProductTemplate_cost_currency_id').removeAttr('readonly');
181  $('#ProductTemplate_listPrice_currency_id').removeAttr('readonly');
182  $('#ProductTemplate_listPrice_currency_id').removeClass('disabled');
183  $('#ProductTemplate_cost_currency_id').removeClass('disabled');
184  }
185  }
186  ";
187  // End Not Coding Standard
188  }
189 
193  public static function bindActionsWithFormFieldsForSellPrice()
194  {
195  return "
196  $(document).ready(function()
197  {
198  $('#ProductTemplate_cost_value').bind('keyup', function()
199  {
200  calculateSellPriceBySellPriceFormula();
201  }
202  );
203  $('#ProductTemplate_listPrice_value').bind('keyup', function()
204  {
205  calculateSellPriceBySellPriceFormula();
206  }
207  );
208  });
209  ";
210  }
211 
215  public static function getProductTemplateStatusDropdownArray()
216  {
217  return array(
218  ProductTemplate::STATUS_ACTIVE => Yii::t('Core', 'Active'),
219  ProductTemplate::STATUS_INACTIVE => Yii::t('Default', 'Inactive'),
220  );
221  }
222 
226  public static function getProductTemplateTypeDropdownArray()
227  {
228  return array(
229  ProductTemplate::TYPE_PRODUCT => Yii::t('ProductsModule', 'Product'),
230  ProductTemplate::TYPE_SERVICE => Yii::t('Default', 'Service'),
231  ProductTemplate::TYPE_SUBSCRIPTION => Yii::t('Default', 'Subscription'),
232  );
233  }
234 
239  {
240  return array(
241  ProductTemplate::PRICE_FREQUENCY_ONE_TIME => Yii::t('Default', 'One Time'),
242  ProductTemplate::PRICE_FREQUENCY_MONTHLY => Yii::t('Core', 'Monthly'),
243  ProductTemplate::PRICE_FREQUENCY_ANNUALLY => Yii::t('Default', 'Annually'),
244  );
245  }
246 
253  public static function getSellPriceFormulaDisplayedGridValue($data, $row)
254  {
255  $sellPriceFormulaModel = $data->sellPriceFormula;
256  $type = $sellPriceFormulaModel->type;
257  $discountOrMarkupPercentage = $sellPriceFormulaModel->discountOrMarkupPercentage;
258  $displayedSellPriceFormulaList = SellPriceFormula::getDisplayedSellPriceFormulaArray();
259  $content = '';
260  if ($type != null)
261  {
262  $content = $displayedSellPriceFormulaList[$type];
263 
264  if ($type != SellPriceFormula::TYPE_EDITABLE)
265  {
266  $content = str_replace('{discount}', $discountOrMarkupPercentage/100, $content);
267  }
268  }
269 
270  return $content;
271  }
272 
273  public static function getProductTemplatePriceFrequencyDisplayedGridValue($data)
274  {
276  }
277 
278  public static function getProductTemplateTypeDisplayedGridValue($data)
279  {
281  }
282  }
283 ?>
static getSellPriceFormulaDisplayedGridValue($data, $row)
static getDisplayedSellPriceFormulaArray()
Generated on Sat Aug 15 2020 07:10:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.