Advertisement
fahmihilmansyah

javascript tulip21202014

Oct 21st, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.     var totalSection = '0';
  3.     var controller = 'purchasing_system/order';
  4.     var base_url = 'http://www.enumaelise.com/tulip/index.php';
  5.     var order_type_price;
  6.  
  7.     function getStock(id_branch){
  8.         $.ajax({
  9.             'url' : base_url + '/' + controller + '/getStock',
  10.             'type' : 'POST',
  11.             'data' : {'id_branch' : id_branch},
  12.             'success' : function(data){
  13.                 var container = $('#stock');
  14.                 container.html(data);
  15.             }
  16.         });
  17.     }
  18.  
  19.     function setTypePrice(id_branch){
  20.         $.ajax({
  21.             'url' : base_url + '/' + controller + '/setTypePrice',
  22.             'type' : 'POST',
  23.             'data' : {'id_branch' : id_branch},
  24.             'success' : function(data){
  25.                 order_type_price = data;
  26.                 document.getElementsByName('orderList[type_price]')[0].value = data;
  27.             }
  28.         });
  29.     }
  30.  
  31.     function generateMemberOption(id_unit){
  32.         $.ajax({
  33.             'url' : base_url + '/' + controller + '/generateMemberOption',
  34.             'type' : 'POST',
  35.             'data' : {'id_unit' : id_unit},
  36.             'success' : function(data){
  37.                 var container = $('.memberOption');
  38.                 container.html(data);
  39.  
  40.                 $('#content').html('');
  41.             }
  42.         });
  43.     }
  44.  
  45.     function generateMemberDetails(id_user){
  46.         $.ajax({
  47.             'url' : base_url + '/' + controller + '/generateMemberDetails',
  48.             'type' : 'POST',
  49.             'data' : {'id_user' : id_user},
  50.             'success' : function(data){
  51.                 var container = $('.memberDetails');
  52.                 container.html(data);
  53.                 order_id_user = id_user;
  54.  
  55.                 $('#content').html('');
  56.  
  57.                 totalSection = '0';
  58.  
  59.                 var orderMain = document.createElement('article');
  60.                 orderMain.setAttribute('id', 'orderMain');
  61.  
  62.                 var firstSection = document.createElement('section');
  63.                 firstSection.setAttribute('id', 'section'+totalSection);
  64.  
  65.                 var result = document.createElement('article');
  66.                 result.setAttribute('class', 'right');
  67.                 result.setAttribute('id', 'result');
  68.  
  69.                 orderMain.appendChild(firstSection);
  70.  
  71.                 $('#content').append(orderMain);
  72.                 $('#content').append(result);
  73.  
  74.                 generateOrderSection(totalSection).done(function() {  });
  75.             }
  76.         });
  77.     }
  78.  
  79.     function generateOrderSection(section_number)
  80.     {
  81.         return $.ajax({
  82.             'url' : base_url + '/' + controller + '/generateOrderSection',
  83.             'type' : 'POST',
  84.             'data' : {'section_number' : section_number},
  85.             'dataType' : 'json',
  86.             'success' : function(data){
  87.                 document.getElementById('section'+section_number).innerHTML = data[0];
  88.                 generatePurchaseTypeList(section_number);
  89.             }
  90.         });
  91.     }
  92.  
  93.     function generatePurchaseTypeList(section_number)
  94.     {
  95.         $.ajax({
  96.             'url' : base_url + '/' + controller + '/generatePurchaseTypeList',
  97.             'type' : 'POST',
  98.             'data' : {'section_number' : section_number},
  99.             'success' : function(data){
  100.                 document.getElementById('purchaseType_' + section_number).innerHTML = data;
  101.  
  102.                 var input = 'purchaseType' + section_number;
  103.                 var datalist = 'purchaseTypeList' + section_number;
  104.                 document.getElementById(input).addEventListener('input', function()
  105.                 {
  106.                     var id_purchaseType = $('#'+datalist).find('option[value="'+this.value+'"]').attr('id');
  107.                     var id_promo = 0;
  108.  
  109.                     generatePromoList(section_number, id_purchaseType);
  110.  
  111.                     document.getElementById('product_' + section_number).innerHTML = '<input type="hidden" id="lineNumber'+section_number+'" value="0">';
  112.                     generateProductList(section_number, id_purchaseType, id_promo);
  113.  
  114.                     document.getElementById('total_' + section_number).innerHTML = '';
  115.  
  116.                     document.getElementsByName('orderList['+section_number+'][purchaseType]')[0].value = id_purchaseType;
  117.  
  118.                     if(parseInt(section_number) == totalSection)
  119.                     {
  120.                         totalSection = parseInt(totalSection) + 1;
  121.  
  122.                         var section = document.createElement('section');
  123.                         section.setAttribute('id', 'section'+totalSection);
  124.  
  125.                         $('#orderMain').append(section);
  126.  
  127.                         generateOrderSection(totalSection).done(function() {  });
  128.                     }
  129.  
  130.                     showStock();
  131.                 });
  132.             }
  133.         });
  134.     }
  135.  
  136.     function generatePromoList(section_number, type_purchase)
  137.     {
  138.         var form_data = {
  139.             section_number: section_number,
  140.             type_purchase: type_purchase
  141.         };
  142.  
  143.         $.ajax({
  144.             'url' : base_url + '/' + controller + '/generatePromoList',
  145.             'type' : 'POST',
  146.             'data' : form_data,
  147.             'success' : function(data){
  148.                 document.getElementById('promo_' + section_number).innerHTML = data;
  149.  
  150.                 var input = 'promo' + section_number;
  151.                 var datalist = 'promoList' + section_number;
  152.                 document.getElementById(input).addEventListener('input', function()
  153.                 {
  154.                     var id_purchaseType = 0;
  155.                     var id_promo = $('#'+datalist).find('option[value="'+this.value+'"]').attr('id');
  156.                     generateProductList(section_number, id_purchaseType, id_promo);
  157.                     document.getElementsByName('orderList['+section_number+'][promo]')[0].value = id_promo;
  158.                     document.getElementById('product_' + section_number).innerHTML = '<input type="hidden" id="lineNumber'+section_number+'" value="0">';
  159.                    
  160.                     showStock();
  161.                 });
  162.             }
  163.         });
  164.     }
  165.  
  166.     function generateProductList(section_number, type_purchase, id_promo)
  167.     {
  168.         var form_data = {
  169.             section_number: section_number,
  170.             type_purchase: type_purchase,
  171.             id_promo: id_promo,
  172.             type_price: order_type_price
  173.         };
  174.  
  175.         $.ajax({
  176.             'url' : base_url + '/' + controller + '/generateProductList',
  177.             'type' : 'POST',
  178.             'data' : form_data,
  179.             'success' : function(data){
  180.                
  181.                 addProductLine(section_number, data);
  182.             }
  183.         });
  184.     }
  185.  
  186.     function addProductLine(section_number, data)
  187.     {
  188.         var lineNumber = parseInt($('#lineNumber' + section_number).val());
  189.         var label = 'product'+section_number+lineNumber;
  190.         var input = 'product'+section_number+lineNumber;
  191.         var datalist = 'productList'+section_number+lineNumber;
  192.  
  193.         var cover = document.createElement('div');
  194.         cover.setAttribute('id', 'productLine'+section_number+lineNumber);
  195.  
  196.         var productLabel = document.createElement('label');
  197.         productLabel.setAttribute('for', label);
  198.         productLabel.innerHTML = 'Product: ';
  199.  
  200.         var productInput = document.createElement('input');
  201.         productInput.type = 'text';
  202.         productInput.setAttribute('id', input);
  203.         productInput.setAttribute('list', datalist);
  204.  
  205.         var productDatalist = document.createElement('datalist');
  206.         productDatalist.setAttribute('id', datalist);
  207.         productDatalist.innerHTML = data;
  208.  
  209.         var idProduct = document.createElement('input');
  210.         idProduct.type = 'hidden';
  211.         idProduct.setAttribute('name', 'orderList['+section_number+'][idProduct]['+lineNumber+']');
  212.  
  213.         var price = document.createElement('input');
  214.         price.type = 'hidden';
  215.         price.setAttribute('name', 'orderList['+section_number+'][price]['+lineNumber+']');
  216.  
  217.         var pv = document.createElement('input');
  218.         pv.type = 'hidden';
  219.         pv.setAttribute('name', 'orderList['+section_number+'][pv]['+lineNumber+']');
  220.  
  221.         var omset = document.createElement('input');
  222.         omset.type = 'hidden';
  223.         omset.setAttribute('name', 'orderList['+section_number+'][omset]['+lineNumber+']');
  224.  
  225.         var komisi = document.createElement('input');
  226.         komisi.type = 'hidden';
  227.         komisi.setAttribute('name', 'orderList['+section_number+'][komisi]['+lineNumber+']');
  228.  
  229.  
  230.         label = 'qty'+section_number+lineNumber;
  231.         input = 'qty'+section_number+lineNumber;
  232.         width = 'width: 6em;';
  233.  
  234.         var qtyLabel = document.createElement('label');
  235.         qtyLabel.setAttribute('for', label);
  236.         qtyLabel.innerHTML = 'Qty: ';
  237.  
  238.         var qtyInput = document.createElement('input');
  239.         qtyInput.type = 'number';
  240.         qtyInput.setAttribute('id', input);
  241.         qtyInput.setAttribute('name', 'orderList['+section_number+'][qty]['+lineNumber+']');
  242.         qtyInput.setAttribute('style', width);
  243.  
  244.         label = 'qtyGiven'+section_number+lineNumber;
  245.         input = 'qtyGiven'+section_number+lineNumber;
  246.  
  247.         var qtyGivenLabel = document.createElement('label');
  248.         qtyGivenLabel.setAttribute('for', label);
  249.         qtyGivenLabel.innerHTML = 'Qty Given: ';
  250.  
  251.         var qtyGivenInput = document.createElement('input');
  252.         qtyGivenInput.type = 'number';
  253.         qtyGivenInput.setAttribute('id', input);
  254.         qtyGivenInput.setAttribute('name', 'orderList['+section_number+'][qtyGiven]['+lineNumber+']');
  255.         qtyGivenInput.setAttribute('style', width);
  256.  
  257.         cover.appendChild(productLabel);
  258.         cover.appendChild(productInput);
  259.         cover.appendChild(productDatalist);
  260.         cover.appendChild(idProduct);
  261.         cover.appendChild(price);
  262.         cover.appendChild(pv);
  263.         cover.appendChild(omset);
  264.         cover.appendChild(komisi);
  265.         cover.appendChild(qtyLabel);
  266.         cover.appendChild(qtyInput);
  267.         cover.appendChild(qtyGivenLabel);
  268.         cover.appendChild(qtyGivenInput);
  269.  
  270.  
  271.         var details = document.createElement('span');
  272.         details.setAttribute('id', 'details'+section_number+lineNumber);
  273.  
  274.         label = 'price'+section_number+lineNumber;
  275.         input = 'price'+section_number+lineNumber;
  276.  
  277.         var priceLabel = document.createElement('label');
  278.         priceLabel.setAttribute('for', label);
  279.         priceLabel.innerHTML = 'Price: ';
  280.  
  281.         var priceInput = document.createElement('input');
  282.         priceInput.type = 'text';
  283.         priceInput.setAttribute('id', input);
  284.         priceInput.setAttribute('disabled', 'disabled');
  285.         priceInput.setAttribute('style', width);
  286.  
  287.  
  288.         label = 'pv'+section_number+lineNumber;
  289.         input = 'pv'+section_number+lineNumber;
  290.  
  291.         var pvLabel = document.createElement('label');
  292.         pvLabel.setAttribute('for', label);
  293.         pvLabel.innerHTML = 'PV: ';
  294.  
  295.         var pvInput = document.createElement('input');
  296.         pvInput.type = 'text';
  297.         pvInput.setAttribute('id', input);
  298.         pvInput.setAttribute('disabled', 'disabled');
  299.         pvInput.setAttribute('style', width);
  300.  
  301.  
  302.         label = 'omset'+section_number+lineNumber;
  303.         input = 'omset'+section_number+lineNumber;
  304.  
  305.         var omsetLabel = document.createElement('label');
  306.         omsetLabel.setAttribute('for', label);
  307.         omsetLabel.innerHTML = 'Omset: ';
  308.  
  309.         var omsetInput = document.createElement('input');
  310.         omsetInput.type = 'text';
  311.         omsetInput.setAttribute('id', input);
  312.         omsetInput.setAttribute('disabled', 'disabled');
  313.         omsetInput.setAttribute('style', width);
  314.  
  315.  
  316.         label = 'komisi'+section_number+lineNumber;
  317.         input = 'komisi'+section_number+lineNumber;
  318.  
  319.         var komisiLabel = document.createElement('label');
  320.         komisiLabel.setAttribute('for', label);
  321.         komisiLabel.innerHTML = 'Komisi: ';
  322.  
  323.         var komisiInput = document.createElement('input');
  324.         komisiInput.type = 'text';
  325.         komisiInput.setAttribute('id', input);
  326.         komisiInput.setAttribute('disabled', 'disabled');
  327.         komisiInput.setAttribute('style', width);
  328.  
  329.         details.appendChild(priceLabel);
  330.         details.appendChild(priceInput);
  331.         details.appendChild(pvLabel);
  332.         details.appendChild(pvInput);
  333.         details.appendChild(omsetLabel);
  334.         details.appendChild(omsetInput);
  335.         details.appendChild(komisiLabel);
  336.         details.appendChild(komisiInput);
  337.  
  338.         cover.appendChild(details);
  339.  
  340.  
  341.         $('#product_'+section_number).append(cover);
  342.  
  343.         var input = 'product' + section_number + lineNumber;
  344.         var datalist = 'productList' + section_number + lineNumber;
  345.         document.getElementById(input).addEventListener('input', function()
  346.         {
  347.             var id_product = $('#'+datalist).find('option[value="'+this.value+'"]').attr('id');
  348.             var purchaseType = document.getElementsByName('orderList['+section_number+'][purchaseType]')[0].value;
  349.             var promo = document.getElementsByName('orderList['+section_number+'][promo]')[0].value;
  350.             document.getElementsByName('orderList['+section_number+'][idProduct]['+lineNumber+']')[0].value = id_product;
  351.             generateProductDetails(section_number, lineNumber, purchaseType, promo, id_product, order_type_price);
  352.             showStock();
  353.         });
  354.  
  355.         var input = 'qty' + section_number + lineNumber;
  356.         var datalist = 'productList' + section_number + lineNumber;
  357.         document.getElementById(input).addEventListener('input', function()
  358.         {
  359.             var id_product = document.getElementsByName('orderList['+section_number+'][idProduct]['+lineNumber+']')[0];
  360.             if(id_product && id_product.value && id_product.value != 0)
  361.             {
  362.                 id_product = document.getElementsByName('orderList['+section_number+'][idProduct]['+lineNumber+']')[0].value;
  363.                
  364.                 document.getElementsByName('orderList['+section_number+'][qtyGiven]['+lineNumber+']')[0].value = this.value;
  365.  
  366.                 var totalLine = parseInt($('#lineNumber' + section_number).val());
  367.                 $('#lineNumber' + section_number).val(lineNumber + 1);
  368.  
  369.                 var purchaseType = document.getElementsByName('orderList['+section_number+'][purchaseType]')[0].value;
  370.                 var promo = document.getElementsByName('orderList['+section_number+'][promo]')[0].value;
  371.                 generateProductList(section_number, purchaseType, promo);
  372.  
  373.                 if(parseInt(lineNumber) < totalLine)
  374.                 {
  375.                     for(i=parseInt(lineNumber)+1; i<totalLine+1; i++)
  376.                     {
  377.                         document.getElementById('productLine' + section_number + i).remove();
  378.                     }
  379.                 }
  380.  
  381.                 total();
  382.                 showStock();
  383.             }
  384.         });
  385.  
  386.         var input = 'qtyGiven' + section_number + lineNumber;
  387.         document.getElementById(input).addEventListener('input', function()
  388.         {
  389.             var qty = document.getElementsByName('orderList['+section_number+'][qty]['+lineNumber+']')[0].value;
  390.             if(this.value >= qty)
  391.             {
  392.                 this.value = qty;
  393.             }
  394.             showStock();
  395.         });
  396.     }
  397.  
  398.     function generateProductDetails(section_number, line_number, type_purchase, id_promo, id_product, type_price)
  399.     {
  400.         var form_data = {
  401.             type_purchase: type_purchase,
  402.             id_promo: id_promo,
  403.             id_product: id_product,
  404.             type_price: type_price
  405.         };
  406.  
  407.         $.ajax({
  408.             'url' : base_url + '/' + controller + '/generateProductDetails',
  409.             'type' : 'POST',
  410.             'data' : form_data,
  411.             'dataType' : 'json',
  412.             'success' : function(data){
  413.  
  414.                 addDetails(section_number, line_number, data);
  415.             }
  416.         });
  417.     }
  418.  
  419.     function addDetails(section_number, line_number, data)
  420.     {
  421.         document.getElementsByName('orderList['+section_number+'][price]['+line_number+']')[0].value = data['price'];
  422.         document.getElementsByName('orderList['+section_number+'][pv]['+line_number+']')[0].value = toFixed(data['pv'], 2);
  423.         document.getElementsByName('orderList['+section_number+'][omset]['+line_number+']')[0].value = data['omset'];
  424.         document.getElementsByName('orderList['+section_number+'][komisi]['+line_number+']')[0].value = data['komisi'];
  425.     }
  426.  
  427.     function showStock()
  428.     {
  429.         //hide semua stock dan reset semua outStock value
  430.         var nodes = document.getElementById('stockContent').childNodes;
  431.         for(var i=0; i<nodes.length; i++) {
  432.             if (nodes[i].nodeName.toLowerCase() == 'div') {
  433.                 nodes[i].style.display = 'none';
  434.                 $("[id^=outStock_]")[i].innerHTML = 0;
  435.             }
  436.         }
  437.         //munculin stock barang yg ada di nota
  438.         for(i=0; i<totalSection; i++)
  439.         {
  440.             for(j=0; j<=document.getElementById('lineNumber'+i).value; j++)
  441.             {
  442.                 var idProduct = document.getElementsByName('orderList['+i+'][idProduct]['+j+']')[0];
  443.                 if(idProduct && idProduct.value)
  444.                 {
  445.                     idProduct = document.getElementsByName('orderList['+i+'][idProduct]['+j+']')[0].value;
  446.                     var outStock = parseInt(document.getElementById('outStock_'+idProduct).innerHTML);
  447.                     var qtyGiven = parseInt(document.getElementsByName('orderList['+i+'][qtyGiven]['+j+']')[0].value);
  448.                    
  449.                     var docOut = document.getElementById('outStock_'+idProduct);
  450.                     var docFinal = document.getElementById('finalStock_'+idProduct);
  451.                     var docCurrent = document.getElementById('currentStock_'+idProduct);
  452.  
  453.                     docCurrent.parentNode.style.display = 'inline';
  454.                     if(qtyGiven >= 0)
  455.                     {
  456.                         docOut.innerHTML = outStock + qtyGiven;
  457.                     }
  458.                     docFinal.innerHTML = parseInt(docCurrent.innerHTML) - parseInt(docOut.innerHTML);
  459.                 }
  460.             }
  461.         }
  462.     }
  463.  
  464.     function total()
  465.     {
  466.         var totalPrice = 0;
  467.         var totalPv = 0;
  468.         var totalOmset = 0;
  469.         var totalKomisi = 0;
  470.         var arrayPurchase = new Array();
  471.        
  472.         for(i=0; i<totalSection; i++)
  473.         {
  474.             var temporaryPrice = 0;
  475.             var temporaryPv = 0;
  476.             var temporaryOmset = 0;
  477.             var temporaryKomisi = 0;
  478.  
  479.             var totalLine = document.getElementById('lineNumber'+i).value;
  480.             for(j=0; j<totalLine; j++)
  481.             {
  482.                 var qty = parseInt(document.getElementsByName('orderList['+i+'][qty]['+j+']')[0].value);
  483.                 var price = parseInt(document.getElementsByName('orderList['+i+'][price]['+j+']')[0].value);
  484.                 var pv = parseFloat(document.getElementsByName('orderList['+i+'][pv]['+j+']')[0].value);
  485.                 var omset = parseInt(document.getElementsByName('orderList['+i+'][omset]['+j+']')[0].value);
  486.                 var komisi = parseInt(document.getElementsByName('orderList['+i+'][komisi]['+j+']')[0].value);
  487.                 document.getElementById('price'+i+j).value = qty * price;
  488.                 document.getElementById('pv'+i+j).value = toFixed((qty * pv), 2);
  489.                 document.getElementById('omset'+i+j).value = qty * omset;
  490.                 document.getElementById('komisi'+i+j).value = qty * komisi;
  491.                 temporaryPrice += price * qty;
  492.                 temporaryPv = toFixed(parseFloat(temporaryPv) + parseFloat(qty * pv), 2);
  493.                 temporaryOmset += omset * qty;
  494.                 temporaryKomisi += komisi * qty;
  495.             }
  496.  
  497.             var total = document.getElementById('total_'+i);
  498.  
  499.             var label = 'totalPrice'+i;
  500.             var input = 'totalPrice'+i;
  501.  
  502.             var priceLabel = document.createElement('label');
  503.             priceLabel.setAttribute('for', label);
  504.             priceLabel.innerHTML = 'Total Price: ';
  505.  
  506.             var priceInput = document.createElement('input');
  507.             priceInput.type = 'text';
  508.             priceInput.setAttribute('id', input);
  509.             priceInput.setAttribute('disabled', 'disabled');
  510.             priceInput.setAttribute('style', width);
  511.             priceInput.setAttribute('value', temporaryPrice);
  512.  
  513.  
  514.             label = 'totalPv'+i;
  515.             input = 'totalPv'+i;
  516.  
  517.             var pvLabel = document.createElement('label');
  518.             pvLabel.setAttribute('for', label);
  519.             pvLabel.innerHTML = 'Total PV: ';
  520.  
  521.             var pvInput = document.createElement('input');
  522.             pvInput.type = 'text';
  523.             pvInput.setAttribute('id', input);
  524.             pvInput.setAttribute('disabled', 'disabled');
  525.             pvInput.setAttribute('style', width);
  526.             pvInput.setAttribute('value', temporaryPv);
  527.  
  528.  
  529.             label = 'totalOmset'+i;
  530.             input = 'totalOmset'+i;
  531.  
  532.             var omsetLabel = document.createElement('label');
  533.             omsetLabel.setAttribute('for', label);
  534.             omsetLabel.innerHTML = 'Total Omset: ';
  535.  
  536.             var omsetInput = document.createElement('input');
  537.             omsetInput.type = 'text';
  538.             omsetInput.setAttribute('id', input);
  539.             omsetInput.setAttribute('disabled', 'disabled');
  540.             omsetInput.setAttribute('style', width);
  541.             omsetInput.setAttribute('value', temporaryOmset);
  542.  
  543.  
  544.             label = 'totalKomisi'+i;
  545.             input = 'totalKomisi'+i;
  546.  
  547.             var komisiLabel = document.createElement('label');
  548.             komisiLabel.setAttribute('for', label);
  549.             komisiLabel.innerHTML = 'Total Komisi: ';
  550.  
  551.             var komisiInput = document.createElement('input');
  552.             komisiInput.type = 'text';
  553.             komisiInput.setAttribute('id', input);
  554.             komisiInput.setAttribute('disabled', 'disabled');
  555.             komisiInput.setAttribute('style', width);
  556.             komisiInput.setAttribute('value', temporaryKomisi);
  557.  
  558.             total.innerHTML = '';
  559.             total.appendChild(priceLabel);
  560.             total.appendChild(priceInput);
  561.             total.appendChild(pvLabel);
  562.             total.appendChild(pvInput);
  563.             total.appendChild(omsetLabel);
  564.             total.appendChild(omsetInput);
  565.             total.appendChild(komisiLabel);
  566.             total.appendChild(komisiInput);
  567.  
  568.             totalPrice += temporaryPrice;
  569.             totalPv = toFixed(parseFloat(totalPv) + parseFloat(temporaryPv), 2);
  570.             totalOmset += temporaryOmset;
  571.             totalKomisi += temporaryKomisi;
  572.  
  573.             var newType = true;
  574.             if(i>0)
  575.             {
  576.                 for(m=0; m<arrayPurchase.length; m++)
  577.                 {
  578.                     if(arrayPurchase[m]['typePurchase'] == document.getElementsByName('orderList['+i+'][purchaseType]')[0].value)
  579.                     {
  580.                         newType = false;
  581.                         arrayPurchase[m]['temporaryPrice'] = parseInt(arrayPurchase[m]['temporaryPrice']) + parseInt(temporaryPrice);
  582.                         arrayPurchase[m]['temporaryPv'] = toFixed(parseFloat(arrayPurchase[m]['temporaryPv']) + parseFloat(temporaryPv), 2);
  583.                         arrayPurchase[m]['temporaryOmset'] = parseInt(arrayPurchase[m]['temporaryOmset']) + parseInt(temporaryOmset);
  584.                         arrayPurchase[m]['temporaryKomisi'] = parseInt(arrayPurchase[m]['temporaryKomisi']) + parseInt(temporaryKomisi);
  585.                     }
  586.                 }
  587.             }
  588.             if(i == 0 || newType == true)
  589.             {
  590.                 var length = arrayPurchase.length;
  591.                 arrayPurchase[length] = [];
  592.                 arrayPurchase[length]['typePurchase'] = document.getElementsByName('orderList['+i+'][purchaseType]')[0].value;
  593.                 arrayPurchase[length]['purchaseTypeName'] = document.getElementById('purchaseType'+i).value;
  594.                 arrayPurchase[length]['temporaryPrice'] = temporaryPrice;
  595.                 arrayPurchase[length]['temporaryPv'] = temporaryPv;
  596.                 arrayPurchase[length]['temporaryOmset'] = temporaryOmset;
  597.                 arrayPurchase[length]['temporaryKomisi'] = temporaryKomisi;
  598.             }
  599.         }
  600.  
  601.  
  602.         var arr = new Array();
  603.         arr['totalPrice'] = totalPrice;
  604.         arr['totalPv'] = totalPv;
  605.         arr['totalOmset'] = totalOmset;
  606.         arr['totalKomisi'] = totalKomisi;
  607.  
  608.         document.getElementById('result').innerHTML = '';
  609.  
  610.         resultPurchaseType(arrayPurchase);
  611.         result(arr);
  612.     }
  613.  
  614.     function resultPurchaseType(array)
  615.     {
  616.         var total = document.getElementById('result');
  617.  
  618.         for(p=0; p<array.length; p++)
  619.         {
  620.             var type = document.createElement('div');
  621.             type.setAttribute('style', 'float:left;');
  622.  
  623.  
  624.             var sectionLabel = document.createElement('p');
  625.             sectionLabel.setAttribute('style', 'font-size:30px; font-weight:bold; margin-right:1em');
  626.             sectionLabel.innerHTML = array[p]['purchaseTypeName'];
  627.  
  628.  
  629.             var label = 'totalSectionPrice'+p;
  630.             var input = 'totalSectionPrice'+p;
  631.  
  632.             var priceLabel = document.createElement('label');
  633.             priceLabel.setAttribute('for', label);
  634.             priceLabel.innerHTML = 'Total Price: ';
  635.  
  636.             var priceInput = document.createElement('input');
  637.             priceInput.type = 'text';
  638.             priceInput.setAttribute('id', input);
  639.             priceInput.setAttribute('disabled', 'disabled');
  640.             priceInput.setAttribute('style', width);
  641.             priceInput.setAttribute('value', array[p]['temporaryPrice']);
  642.  
  643.  
  644.             label = 'totalSectionPv'+p;
  645.             input = 'totalSectionPv'+p;
  646.  
  647.             var pvLabel = document.createElement('label');
  648.             pvLabel.setAttribute('for', label);
  649.             pvLabel.innerHTML = 'Total PV: ';
  650.  
  651.             var pvInput = document.createElement('input');
  652.             pvInput.type = 'text';
  653.             pvInput.setAttribute('id', input);
  654.             pvInput.setAttribute('disabled', 'disabled');
  655.             pvInput.setAttribute('style', width);
  656.             pvInput.setAttribute('value', array[p]['temporaryPv']);
  657.  
  658.  
  659.             label = 'totalSectionOmset'+p;
  660.             input = 'totalSectionOmset'+p;
  661.  
  662.             var omsetLabel = document.createElement('label');
  663.             omsetLabel.setAttribute('for', label);
  664.             omsetLabel.innerHTML = 'Total Omset: ';
  665.  
  666.             var omsetInput = document.createElement('input');
  667.             omsetInput.type = 'text';
  668.             omsetInput.setAttribute('id', input);
  669.             omsetInput.setAttribute('disabled', 'disabled');
  670.             omsetInput.setAttribute('style', width);
  671.             omsetInput.setAttribute('value', array[p]['temporaryOmset']);
  672.  
  673.  
  674.             label = 'totalSectionKomisi'+p;
  675.             input = 'totalSectionKomisi'+p;
  676.  
  677.             var komisiLabel = document.createElement('label');
  678.             komisiLabel.setAttribute('for', label);
  679.             komisiLabel.innerHTML = 'Total Komisi: ';
  680.  
  681.             var komisiInput = document.createElement('input');
  682.             komisiInput.type = 'text';
  683.             komisiInput.setAttribute('id', input);
  684.             komisiInput.setAttribute('disabled', 'disabled');
  685.             komisiInput.setAttribute('style', width);
  686.             komisiInput.setAttribute('value', array[p]['temporaryKomisi']);
  687.  
  688.            
  689.             type.appendChild(sectionLabel);
  690.             type.appendChild(priceLabel);
  691.             type.appendChild(priceInput);
  692.             type.appendChild(document.createElement('br'));
  693.             type.appendChild(pvLabel);
  694.             type.appendChild(pvInput);
  695.             type.appendChild(document.createElement('br'));
  696.             type.appendChild(omsetLabel);
  697.             type.appendChild(omsetInput);
  698.             type.appendChild(document.createElement('br'));
  699.             type.appendChild(komisiLabel);
  700.             type.appendChild(komisiInput);
  701.             type.appendChild(document.createElement('br'));
  702.             total.appendChild(type);
  703.         }
  704.     }
  705.  
  706.     function result(array)
  707.     {
  708.         var result = document.getElementById('result');
  709.  
  710.         var totalLabel = document.createElement('p');
  711.         totalLabel.setAttribute('style', 'font-size:30px; font-weight:bold; margin-right:1em');
  712.         totalLabel.innerHTML = 'Total';
  713.  
  714.  
  715.         var label = 'totalPrice';
  716.         var input = 'totalPrice';
  717.         var width = 'width: 12em;';
  718.  
  719.         var priceLabel = document.createElement('label');
  720.         priceLabel.setAttribute('for', label);
  721.         priceLabel.innerHTML = 'Total Price: ';
  722.  
  723.         var priceInput = document.createElement('input');
  724.         priceInput.type = 'text';
  725.         priceInput.setAttribute('id', input);
  726.         priceInput.setAttribute('readonly', 'readonly');
  727.         priceInput.setAttribute('name', 'orderList[totalCost]');
  728.         priceInput.setAttribute('style', width);
  729.         priceInput.setAttribute('value', array['totalPrice']);
  730.  
  731.  
  732.         label = 'totalPv';
  733.         input = 'totalPv';
  734.  
  735.         var pvLabel = document.createElement('label');
  736.         pvLabel.setAttribute('for', label);
  737.         pvLabel.innerHTML = 'Total PV: ';
  738.  
  739.         var pvInput = document.createElement('input');
  740.         pvInput.type = 'text';
  741.         pvInput.setAttribute('id', input);
  742.         pvInput.setAttribute('disabled', 'disabled');
  743.         pvInput.setAttribute('style', width);
  744.         pvInput.setAttribute('value', array['totalPv']);
  745.  
  746.  
  747.         label = 'totalOmset';
  748.         input = 'totalOmset';
  749.  
  750.         var omsetLabel = document.createElement('label');
  751.         omsetLabel.setAttribute('for', label);
  752.         omsetLabel.innerHTML = 'Total Omset: ';
  753.  
  754.         var omsetInput = document.createElement('input');
  755.         omsetInput.type = 'text';
  756.         omsetInput.setAttribute('id', input);
  757.         omsetInput.setAttribute('disabled', 'disabled');
  758.         omsetInput.setAttribute('style', width);
  759.         omsetInput.setAttribute('value', array['totalOmset']);
  760.  
  761.  
  762.         label = 'totalKomisi';
  763.         input = 'totalKomisi';
  764.  
  765.         var komisiLabel = document.createElement('label');
  766.         komisiLabel.setAttribute('for', label);
  767.         komisiLabel.innerHTML = 'Total Komisi: ';
  768.  
  769.         var komisiInput = document.createElement('input');
  770.         komisiInput.type = 'text';
  771.         komisiInput.setAttribute('id', input);
  772.         komisiInput.setAttribute('disabled', 'disabled');
  773.         komisiInput.setAttribute('style', width);
  774.         komisiInput.setAttribute('value', array['totalKomisi']);
  775.  
  776.  
  777.         label = 'cash';
  778.         input = 'cash';
  779.  
  780.         var cashLabel = document.createElement('label');
  781.         cashLabel.setAttribute('for', label);
  782.         cashLabel.innerHTML = 'Cash: ';
  783.  
  784.         var cashInput = document.createElement('input');
  785.         cashInput.type = 'text';
  786.         cashInput.setAttribute('id', input);
  787.         cashInput.setAttribute('name', 'orderList[cash]');
  788.         cashInput.setAttribute('style', width);
  789.         cashInput.setAttribute('required', 'required');
  790.  
  791.  
  792.         label = 'debit';
  793.         input = 'debit';
  794.  
  795.         var debitLabel = document.createElement('label');
  796.         debitLabel.setAttribute('for', label);
  797.         debitLabel.innerHTML = 'Debit: ';
  798.  
  799.         var debitInput = document.createElement('input');
  800.         debitInput.type = 'text';
  801.         debitInput.setAttribute('id', input);
  802.         debitInput.setAttribute('name', 'orderList[debit]');
  803.         debitInput.setAttribute('style', width);
  804.         debitInput.setAttribute('required', 'required');
  805.  
  806.  
  807.         label = 'credit';
  808.         input = 'credit';
  809.  
  810.         var creditLabel = document.createElement('label');
  811.         creditLabel.setAttribute('for', label);
  812.         creditLabel.innerHTML = 'Credit: ';
  813.  
  814.         var creditInput = document.createElement('input');
  815.         creditInput.type = 'text';
  816.         creditInput.setAttribute('id', input);
  817.         creditInput.setAttribute('name', 'orderList[credit]');
  818.         creditInput.setAttribute('style', width);
  819.         creditInput.setAttribute('required', 'required');
  820.  
  821.  
  822.         var submitDisabled = document.createElement('input');
  823.         submitDisabled.type = 'button';
  824.         submitDisabled.setAttribute('id', 'submitDisabled');
  825.         submitDisabled.setAttribute('value', 'Submitting');
  826.         submitDisabled.setAttribute('disabled', 'disabled');
  827.         submitDisabled.setAttribute('style', 'display: none;');
  828.  
  829.         var submit = document.createElement('input');
  830.         submit.type = 'submit';
  831.         submit.setAttribute('value', 'Submit');
  832.         submit.setAttribute('onclick', "disableSubmit(this);");
  833.  
  834.         result.appendChild(totalLabel);
  835.         result.appendChild(priceLabel);
  836.         result.appendChild(priceInput);
  837.         result.appendChild(document.createElement('br'));
  838.         result.appendChild(pvLabel);
  839.         result.appendChild(pvInput);
  840.         result.appendChild(document.createElement('br'));
  841.         result.appendChild(omsetLabel);
  842.         result.appendChild(omsetInput);
  843.         result.appendChild(document.createElement('br'));
  844.         result.appendChild(komisiLabel);
  845.         result.appendChild(komisiInput);
  846.         result.appendChild(document.createElement('br'));
  847.         result.appendChild(cashLabel);
  848.         result.appendChild(cashInput);
  849.         result.appendChild(document.createElement('br'));
  850.         result.appendChild(debitLabel);
  851.         result.appendChild(debitInput);
  852.         result.appendChild(document.createElement('br'));
  853.         result.appendChild(creditLabel);
  854.         result.appendChild(creditInput);
  855.         result.appendChild(document.createElement('br'));
  856.         result.appendChild(submitDisabled);
  857.         result.appendChild(submit);
  858.     }
  859.  
  860.     function disableSubmit(input)
  861.     {
  862.         if(document.getElementById('cash').value != 0
  863.             && document.getElementById('debit').value != 0
  864.             && document.getElementById('credit').value != 0)
  865.         {
  866.             input.style.display='none';
  867.             document.getElementById('submitDisabled').style.display='inline';
  868.         }
  869.     }
  870.  
  871.     $("form").submit(function() {
  872.         $(this).submit(function() {
  873.             return false;
  874.         });
  875.         return true;
  876.     });
  877.  
  878.     function toFixed(value, precision) {
  879.         var precision = precision || 0,
  880.         neg = value < 0,
  881.         power = Math.pow(10, precision),
  882.         value = Math.round(value * power),
  883.         integral = String((neg ? Math.ceil : Math.floor)(value / power)),
  884.         fraction = String((neg ? -value : value) % power),
  885.         padding = new Array(Math.max(precision - fraction.length, 0) + 1).join('0');
  886.  
  887.         return precision ? integral + '.' +  padding + fraction : integral;
  888.     }
  889. </script>
  890.  
  891.     <section>
  892.         <header>Order</header>
  893.         <article id="stock" style="position: absolute;">
  894.         </article>
  895.         <form action="http://www.enumaelise.com/tulip/index.php/purchasing_system/order/purchase" method="post" accept-charset="utf-8">     <article class="right">
  896.             <header>
  897.                 <div><label for="branches">Branch: </label><input type="text" id="branches" list="branch">
  898.         <datalist id="branch"><option id="1" value="Wastu"><option id="2" value="Cimahi"></datalist>
  899.         <input type="hidden" name="orderList[branch]">
  900.         <input type="hidden" name="orderList[type_price]"><script>document.getElementById('branches').addEventListener('input', function () {
  901.       var id_branch = $('#branch').find('option[value="'+this.value+'"]').attr('id');
  902.       document.getElementsByName('orderList[branch]')[0].value = id_branch;
  903.       getStock(id_branch);
  904.       setTypePrice(id_branch);
  905.       });</script></div>
  906.                 <div><label for="units">Unit: </label><input type="text" id="units" list="unit">
  907.       <datalist id="unit"><option id="1" value="Test Unit"></datalist>
  908.       <input type="hidden" name="orderList[unit]"><script>document.getElementById('units').addEventListener('input', function () {
  909.       $('.memberDetails').html('');
  910.       var id_unit = $('#unit').find('option[value="'+this.value+'"]').attr('id');
  911.       document.getElementsByName('orderList[unit]')[0].value = id_unit;
  912.       generateMemberOption(id_unit);
  913.       });</script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement