You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.5KB

  1. let mixinPriceWithTaxField = {
  2. data() {
  3. return {
  4. price: null,
  5. priceWithTax: null,
  6. buyingPrice: null,
  7. buyingPriceWithTax: null,
  8. differentSupplierTaxRate: null,
  9. multiplyingFactor: null,
  10. priceByRefUnit:null,
  11. priceByRefUnitWithTax:null
  12. };
  13. },
  14. computed:{
  15. taxRateValue: function () {
  16. return $('#productfamily_taxRate').find('option[value="'+this.taxRate+'"]').data('tax-rate-value');
  17. },
  18. supplierTaxRateValue: function () {
  19. if($('#productfamily_supplierTaxRate').find('option[value="'+this.supplierTaxRate+'"]').data('tax-rate-value') == 'inherited') {
  20. return this.taxRateValue;
  21. }else{
  22. return $('#productfamily_supplierTaxRate').find('option[value="'+this.supplierTaxRate+'"]').data('tax-rate-value');
  23. }
  24. },
  25. },
  26. mounted: function () {
  27. },
  28. methods: {
  29. /*changeTaxRate: function () {
  30. this.$emit('tax-rate-change');
  31. this.changePriceWithTax();
  32. },*/
  33. changeBuyingPrice: function () {
  34. this.buyingPriceUpdate('buyingPrice');
  35. },
  36. changeBuyingPriceWithTax: function () {
  37. this.buyingPriceUpdate('buyingPriceWithTax');
  38. },
  39. changePrice: function () {
  40. this.priceUpdate('price');
  41. this.setMultiplyingFactor();
  42. },
  43. changePriceWithTax: function () {
  44. this.priceUpdate('priceWithTax');
  45. this.setMultiplyingFactor();
  46. },
  47. priceUpdate: function (priceType) {
  48. if (priceType == 'priceWithTax' && this.price) {
  49. this.price = parseFloat(this.price.replace(',', '.')).toFixed(3);
  50. this.priceWithTax = getPriceWithTax(this.price, this.taxRateValue);
  51. } else if (this.priceWithTax) {
  52. if(typeof this.priceWithTax !="number"){
  53. this.priceWithTax = parseFloat(this.priceWithTax.replace(',', '.'));
  54. }
  55. this.priceWithTax = this.priceWithTax.toFixed(2);
  56. this.price = getPrice(this.priceWithTax, this.taxRateValue);
  57. }
  58. this.priceByRefUnitUpdate();
  59. },
  60. buyingPriceUpdate: function (priceType) {
  61. if (priceType == 'buyingPriceWithTax' && this.buyingPrice) {
  62. this.buyingPrice = parseFloat(this.buyingPrice.replace(',', '.')).toFixed(3);
  63. this.buyingPriceWithTax = getPriceWithTax(this.buyingPrice, this.supplierTaxRateValue);
  64. } else if (this.buyingPriceWithTax) {
  65. this.buyingPriceWithTax = parseFloat(this.buyingPriceWithTax.replace(',', '.')).toFixed(2);
  66. this.buyingPrice = getPrice(this.buyingPriceWithTax, this.supplierTaxRateValue);
  67. }
  68. this.setMultiplyingFactor();
  69. this.priceByRefUnitUpdate();
  70. },
  71. updateMultiplyingFactor: function () {
  72. this.priceWithTax = this.buyingPriceValue * this.multiplyingFactor;
  73. this.priceUpdate('price');
  74. },
  75. setMultiplyingFactor:function () {
  76. if(this.priceWithTax || this.buyingPrice) {
  77. this.multiplyingFactor = parseFloat(this.priceWithTaxValue / this.buyingPriceValue).toFixed(3);
  78. }
  79. },
  80. priceByRefUnitUpdate:function () {
  81. if(this.unitArray[this.unitValue]){
  82. this.priceByRefUnit = parseFloat((this.priceValue / this.quantityValue) *this.unitArray[this.unitValue].coefficient).toFixed(2);
  83. this.priceByRefUnitWithTax = parseFloat((this.priceWithTaxValue / this.quantityValue )*this.unitArray[this.unitValue].coefficient).toFixed(2);
  84. }
  85. }
  86. },
  87. watch: {
  88. }
  89. };
  90. let mixinUnit = {
  91. data() {
  92. return Object.assign(
  93. {
  94. quantity:null,
  95. unit: null,
  96. unitArray: null
  97. }, window.mixinUnitValues);
  98. },
  99. computed: {
  100. unitReference: function () {
  101. if (this.unit) {
  102. return this.unitArray[this.unit].ref
  103. } else {
  104. return '';
  105. }
  106. }
  107. }
  108. };
  109. let mixinTemplate = {
  110. data() {
  111. return {
  112. templateRender: null,
  113. }
  114. },
  115. render(h) {
  116. if (!this.templateRender) {
  117. return h('div', 'loading...');
  118. } else { // If there is a template, I'll show it
  119. return this.templateRender();
  120. }
  121. },
  122. watch: {
  123. // Every time the template prop changes, I recompile it to update the DOM
  124. template: {
  125. immediate: true, // makes the watcher fire on first render, too.
  126. handler() {
  127. if (this.template) {
  128. var res = Vue.compile(this.template);
  129. this.templateRender = res.render;
  130. // staticRenderFns belong into $options,
  131. // appearantly
  132. this.$options.staticRenderFns = []
  133. // clean the cache of static elements
  134. // this is a cache with the results from the staticRenderFns
  135. this._staticTrees = []
  136. // Fill it with the new staticRenderFns
  137. for (var i in res.staticRenderFns) {
  138. //staticRenderFns.push(res.staticRenderFns[i]);
  139. this.$options.staticRenderFns.push(res.staticRenderFns[i])
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }