Untitled
$("body").delegate(".download_Stock_Movement_Item_Report", "click", function () { if (!$(this).data('clicked')) { $(this).data('clicked', true); // id and product_code should be the closeset to find because we are getting from DOM Elements let product_id = '<?=json_encode($id);?>'; console.log(product_id); let product = '<?=json_encode($product_code);?>'; let sl_id = '<?=json_encode($sl_id);?>'; var brand_name = $("#brand_name").val(); var product_code = $("#product_code").val(); var product_name = $("#product_name").val(); var filename = '<?= $currentUserId . "-stock-movement-item-report.csv"; ?>'; /* var brand_id = $("#brand_id").val(); var product_id = $("#product_id").val(); var sl_id = $("#sl_id").val(); var product = $('#product_id').find(":selected").map(function() { return $(this).text(); }).get(); console.log("new",product_id); */ // $('#background-overlay').show(); // $('#loadingGIF').show(); $.ajax({ type: "POST", data: { product_id:product_id, product:product, brand_name:brand_name, product_code:product_code, product_name:product_name, filename:filename, }, global: false, url: "<?= $this->Url->build(['controller' => 'Stocks', 'action' => 'downloadStockMovementItemReport']) ?>", dataType: "text", success: function (data) { $('#background-overlay').hide(); $('#loadingGIF').hide(); var downloadLink = document.createElement("a"); var fileData = ['\ufeff'+data]; var blobObject = new Blob(fileData,{ type: "text/csv;charset=utf-8;" }); var url = URL.createObjectURL(blobObject); downloadLink.href = url; downloadLink.download = filename; document.body.appendChild(downloadLink); downloadLink.click(); document.body.removeChild(downloadLink); } }); } var _this = $(this); setTimeout(function() { _this.data('clicked', false); }, 100); });
Leave a Comment