Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getbatches(page) {
  2.  
  3.         var arr = {};
  4.         var token = localStorage.getItem("americannex_atms_bearer_token");
  5.         arr["token"] = token;
  6.  
  7.         arr["pager"] = {
  8.                 page: page || 1,
  9.                 perpage: 50
  10.         }
  11.  
  12.         arr["companyid"] = $("#agent_packages_companyname").val();
  13.         arr["productclass"] = $("#agent_packages_productclass").val();
  14.         arr["producttype"] = $("#agent_packages_producttype").val();
  15.         arr["subproducttype"] = $("#agent_packages_subproducttype").val();
  16.         arr["productid"] = $("#agent_packages_productname").val();
  17.         arr["owned_by_userid"] = $("#agent_packages_ownedby").val();
  18.  
  19.  
  20.         var active = $("#agent_packages_show_inactive").prop('checked');
  21.  
  22.         if (active == true) {
  23.                 active = 'false';
  24.                 $("#agent_packages_btnnewbatch").hide();
  25.         }
  26.         else
  27.         {
  28.                 active = 'true';
  29.                 $("#agent_packages_btnnewbatch").show();
  30.         };
  31.  
  32.         arr["active"] = active;
  33.  
  34.         $('#agent_packages_batches_table').hide();
  35.  
  36.         $("#pleasewait_div").modal('show');
  37.  
  38.  
  39.         $('#agent_packages_batches_table tbody').empty();
  40.  
  41.                 return $.post(apiurl + "agent_packages.php", {action: "batches", obj: arr},
  42.                 function(data) {
  43.  
  44.                         var d = $.parseJSON(data);
  45.  
  46.                         if (d.message != "success") {
  47.                                 $("#pleasewait_div").modal('hide');
  48.                                 $('#agent_packages_batches_table').show();
  49.                                 showerrormessage(d.message);
  50.                                 return false;
  51.                         }
  52.                         else
  53.                         {
  54.                                 delete d["message"];
  55.                                 package_pager.paginate(d.pager.currentPage, d.pager.totalPages, d.pager.totalItems);
  56.                                 delete d.pager;
  57.                         };
  58.  
  59.                         $.each(d, function(key1, val1) {
  60.  
  61.                                 $.each(val1, function(key, val) {
  62.  
  63.                                 var batchid = val["batchid"];
  64.                                 var productname = val["productname"];
  65.                                 var productid = val["productid"];
  66.                                 var productclass = val["productclass"];
  67.                                 var companyname = val["companyname"];
  68.                                 /*
  69.                                 var cb_companyname = val["created_by_user"]["cb_companyname"];
  70.                                 var cb_firstname = val["created_by_user"]["cb_firstname"];
  71.                                 var colon = "";
  72.                                 if (cb_firstname.length > 0) {
  73.                                         colon = ":";
  74.                                 }
  75.                                 var cb_lastname = val["created_by_user"]["cb_lastname"];
  76.                                 var created_by_user = cb_companyname + colon + cb_firstname + " " + cb_lastname;
  77.                                 */
  78.  
  79.                                 var date_time_created = val["date_time_created"] + "";
  80.  
  81.                                 if (date_time_created.length > 0) {
  82.                                         date_time_created = formatdatetime(val["date_time_created"]);
  83.                                 }
  84.                                 var count = val["packagecount"];
  85.                                 var availableamount = val["availableamount"];
  86.                                 var unittype = val["unittype"];
  87.                                 var active = val["active"] + "1";
  88.  
  89.                                 var listed = val["listed"];
  90.  
  91.                                 var producttype = val["producttype"];
  92.                                 var subproducttype = val["subproducttype"];
  93.  
  94.                                 if (producttype == "Flower") {
  95.                                         availableamount = convertgramstopounds(availableamount, 0);
  96.                                 }
  97.                                 else
  98.                                 {
  99.                                         if (availableamount > 0) {
  100.                                                 availableamount = availableamount + " " + unittype;
  101.                                         };
  102.                                 };
  103.  
  104.                                 //temp
  105.                                 var state = val["state"];
  106.  
  107.                                 var visibility = val["visibility"];
  108.  
  109.                                 $("#agent_packages_batches_table tbody").append("<tr id=" + batchid + " data-productid=" + productid + " data-active=" + active + "><td>" + state + "</td><td>" + batchid + "</td><td>" + productname + "</td><td>" + companyname + "</td><td>" + productclass + "</td><td>" + producttype + "</td><td>" + subproducttype + "</td><td>" + count + "</td><td>" + listed + "</td><td>" + availableamount + "</td><td>" + visibility + "</td><td style=\"text-align:right;\"><button class=\"agent_packages_batches_table_createorder btn btn-default glyphicon glyphicon glyphicon-usd\" title=\"Create New Order\" data-batchid=\"" + batchid + "\"></button></td></tr>");
  110.  
  111.                         });
  112.  
  113.                         });
  114.  
  115.                         $("#agent_packages_batches_table").trigger("update");            
  116.             $("#agent_packages_batches_table").trigger("sorton",[0,0]);
  117.  
  118.                         $("#agent_packages_batches_table_createorder").off();
  119.  
  120.                         $(".agent_packages_batches_table_createorder").on("click", function(e) {
  121.  
  122.                                 e.preventDefault();
  123.                                 e.stopPropagation();
  124.  
  125.                                 var batchid = $(this).data("batchid");
  126.  
  127.                                 arr["batchid"] = batchid;
  128.  
  129.                                 return $.post(apiurl + "agent_packages.php", {action: "getpackageids", obj: arr},
  130.                                 function(data) {
  131.  
  132.                                                 var d = $.parseJSON(data);
  133.  
  134.                                                 if (d.message != "success") {
  135.                                                         showerrormessage(d.message);
  136.                                                         return false;
  137.                                                 }
  138.                                                 else
  139.                                                 {
  140.                                                         delete d["message"];
  141.                                                 };
  142.  
  143.                                         var obj = [];
  144.                                         var packageids = [];
  145.  
  146.                                         $.each(d["packages"], function(key, val) {
  147.                                                 packageids.push(val);
  148.                                         });
  149.  
  150.                                         if(packageids.length < 1) {
  151.                                                 showerrormessage("None of the packages in this batch are available for a new order.");
  152.                                                 return false;
  153.                                         };
  154.  
  155.                                         obj["packages"] = packageids;
  156.                                         obj["redirecturl"] = unitiurl + "agent_order.php";
  157.                                         create_order(obj);
  158.  
  159.                                 });
  160.  
  161.                         });
  162.  
  163.  
  164.  
  165.                         $("#agent_packages_batches_table tbody tr").click(function() {
  166.  
  167.                                 var productid = $(this).data("productid");
  168.                                 var active = $(this).data("active");
  169.                                 var batchid = $(this).prop("id");
  170.  
  171.                                 $.when( agent_packages_getpackages($(this).prop("id")) ).done(function() {
  172.                                         if (active === "true1") {
  173.                                                 $("#agent_packages_manage_batches_edit_packages_btnrestorebatch").hide();
  174.                                                 $("#agent_packages_manage_batches_edit_packages_btndeletebatch").show();
  175.                                         }
  176.                                         else
  177.                                         {
  178.                                                 $("#agent_packages_manage_batches_edit_packages_btndeletebatch").hide();
  179.                                                 //$("#agent_packages_manage_batches_edit_packages_btnrestorebatch").show();
  180.  
  181.                                         };
  182.  
  183.                                         $("#agent_packages_main_header_title").html("Manage Packages<br /><h4>Batch ID: <span id=\"agent_packages_manage_packages_batchid\">" + batchid + "</span></h4><span id=\"agent_packages_manage_packages_productid\" style=\"display:none;\">" + productid + "</span>");
  184.                                         $(".agent_packages_manage_batches").hide();
  185.                                         $("#agent_packages_manage_batches_edit_manage_product_div").hide();
  186.                                         $("#agent_packages_manage_batches_edit_packages_table_div").show();
  187.                                         $("#agent_packages_manage_batches_edit_packages_table").attr("data-productid", productid);
  188.                                         $("#agent_packages_manage_batches_home_div").hide();
  189.                                         $("#agent_packages_manage_batches_edit_div").fadeIn(250);
  190.  
  191.                                 });
  192.  
  193.                         });
  194.  
  195.                         $('#agent_packages_batches_table').fadeIn(250);
  196.  
  197.  
  198.                 setTimeout(function() {
  199.                         $("#pleasewait_div").modal('hide');
  200.                 }, 750);
  201.  
  202.                 setTimeout(function() {
  203.                         $("#productinfo_searchresults_div").show();
  204.                 }, 100);
  205.  
  206.  
  207.  
  208.         });
  209. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement