Ehandel.se - Visa ett inlägg - Script för packsoft online
Visa ett inlägg
 
Gammal 2012-09-21, 12:45
Fractronics Fractronics är inte uppkopplad
Ivrig
www.nesconnector.se
Fractronics
 
Reg.datum: dec 2009
Inlägg: 87
Fractronics is on a distinguished road
Standard Script för packsoft online

Hej!

Har länge stört mig på det manuella arbetet att klippa och klistra in adresser i packsoft online.
Idag fick jag nog och knåpade ihop ett Greasemonkey script som gör mitt jobb.
(Eftersom jag kör chrome så kör jag egentligen inte Greasemonkey utan Tampermonkey men det borde fungera med Greasemonkey)

Scriptet startar när jag öppnar min sida med packsedlar (en eller flera), om jag klickar på ett visst objekt på sidan så sparas alla adresser och packsoft online öppnas, man loggas in, flyttas till utskriftsfavoriten varubrev, alla uppgifter fylls i automatiskt för alla insamlade adresser, och man flyttas slutligen till lagrade utskrifter där man kan trycka på skriv ut.
(Scriptet skulle kunna trycka på "skriv ut" också men jag stoppar här)

Äntligen slipper jag klippa och klistra.

Jag slängde ihop scriptet på en halvtimme (det går att göra bättre på alla sätt) och det är gjort för att fungera för mig och min utskriftsfavorit "varubrev", men om någon vill ha det att utgå ifrån så bifogar jag det här.

Kod:
// ==UserScript==
// @name          varubrev
// @namespace     www.fractalposter.com
// @author        Mikael Backlund
// @description   Varubrev
// @include       https://po.unifaun.se*
// @include       http://www.nesconnector.se*
// @require 	    http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
// @version		    001
// ==/UserScript==



// Base url of page to collect addresses on.
var customer_info_url_base = "http://www.nesconnector.se/admin/index.php?route=sale/order/packinginv";
// When object of this class is clicked on the above page addresses are collected 
var object_class_to_click = ".customer_addr2";
// Pacsoft online user id
var my_pacsoft_uid = "123456";
// Pacsoft online password 
var my_pacsoft_pwd = "abcdef";
// Name on image next to favorite <img name="xxxxxxxx">
var favorite_html_name = "act_ShipmentJobFavoriteSearchActions_SearchResultEdit_RowId_7249";
// Senders packsoft customer number
var my_packsoft_customer_nr = "987654321";
// Class of <p> with customer name etc...
var customer_name_class      = ".customer_name";
var customer_address1_class  = ".customer_address1";
var customer_address2_class  = ".customer_address2";
var customer_postcode_class  = ".customer_postcode";
var customer_email_class     = ".customer_email";
var customer_telephone_class = ".customer_telephone";
var customer_order_id_class  = ".customer_order_id";


var customer_names      = new Array();
var customer_address1s  = new Array();
var customer_address2s  = new Array();
var customer_postcodes  = new Array();
var customer_emails     = new Array();
var customer_telephones = new Array();
var customer_order_ids  = new Array();

// Attach the collect_addresses function to a object on the page with addresses
if (window.location.href.indexOf(customer_info_url_base) > -1){
  $(object_class_to_click).click(collect_addresses);
}
// The login page of packsoft online
else if (GM_getValue("trigger")=="1" && $('input[name="act_LoginActions_Login"]')[0]) {
  $('input[name="CompanyLogin"]').val(my_pacsoft_uid);
  $('input[name="UserPass"]').val(my_pacsoft_pwd);
  GM_setValue("trigger", "2");
  setTimeout(function() {$('input[name="act_LoginActions_Login"]').trigger("click");},100);
}
// Packsoft home screen, go to my favorite named Varubrev
else if (GM_getValue("trigger")=="2" && document.location.href.indexOf("Action=act_SystemActions_Body")>-1) {
  GM_setValue("trigger", "3");
  GM_setValue("session_link", document.location.href.split("&")[0].split("?")[1]);
  document.location = "webapp?"+GM_getValue("session_link")+"&Action="+favorite_html_name;  
}
// Fill the first page of the form press next (do while there is addresses left) 
else if (GM_getValue("trigger")=="3" && GM_getValue("no_of_customers")>0 && $('input[name="act_ShipmentJobEdit1Actions_Next"]')[0]) {  
  $('input[name="RECEIVERName"]').val(GM_getValue("customer_names").split("¤")[GM_getValue("no_of_customers")-1]);
  $('input[name="RECEIVERDeliveryAddress1"]').val(GM_getValue("customer_address1s").split("¤")[GM_getValue("no_of_customers")-1]);
  $('input[name="RECEIVERDeliveryAddress2"]').val(GM_getValue("customer_address2s").split("¤")[GM_getValue("no_of_customers")-1]);
  $('input[name="RECEIVERDeliveryZipcode"]').focus(); 
  $('input[name="RECEIVERDeliveryZipcode"]').val(GM_getValue("customer_postcodes").split("¤")[GM_getValue("no_of_customers")-1]);
  $('input[name="RECEIVERDeliveryZipcode"]').blur(); 
  $('input[name="RECEIVERPhone"]').focus(); 
  $('input[name="RECEIVERPhone"]').val(GM_getValue("customer_telephones").split("¤")[GM_getValue("no_of_customers")-1]);
  $('input[name="RECEIVEREmail"]').val(GM_getValue("customer_emails").split("¤")[GM_getValue("no_of_customers")-1]);
  setTimeout(function() {$('input[name="act_ShipmentJobEdit1Actions_Next"]').trigger("click");},100);
}
// Fill the second page of the form click "lagra" (do while there is addresses left) 
else if (GM_getValue("trigger")=="3" && GM_getValue("no_of_customers")>0 && $('input[name="act_ShipmentJobEdit2Actions_Store"]')[0]) {    
  $('input[name="ShipmentSndReference"]').val(GM_getValue("customer_order_ids").split("¤")[GM_getValue("no_of_customers")-1]);    
  $('select[name="SenderCustNo"]').val(my_packsoft_customer_nr);        
  $('input[name="AddonsNOTEMAIL"]').attr('checked', true);     
  GM_setValue("no_of_customers", GM_getValue("no_of_customers")-1);
  if (GM_getValue("no_of_customers")==0)
    GM_setValue("trigger", "4");
  setTimeout(function() {$('input[name="act_ShipmentJobEdit2Actions_Store"]').trigger("click");},100);                         
}
// Go to "Lagrade utskrifter"
else if (GM_getValue("trigger")=="4" && $('input[name="act_ShipmentJobEdit1Actions_Next"]')[0]) {    
  GM_setValue("trigger", "0");
  document.location = "webapp?"+GM_getValue("session_link")+"&Action=act_MenuActions_Item&Target=body&ItemHandler=ShipmentJobSearchActions";  
}

// This function collects addresses stores them and then opens packsoft online
// This function is attached to a object on the page with addresses
// It is triggered when the user clicks the object
function collect_addresses() {      
  $(customer_name_class).each(function (i, elem)   { customer_names[i]=$(elem).text().replace("¤",""); });
  $('.customer_address1').each(function (i, elem)  { customer_address1s[i]=$(elem).text().replace("¤",""); });
  $('.customer_address2').each(function (i, elem)  { customer_address2s[i]=$(elem).text().replace("¤",""); });
  $('.customer_postcode').each(function (i, elem)  { customer_postcodes[i]=$(elem).text().replace("¤",""); });
  $('.customer_email').each(function (i, elem)     { customer_emails[i]=$(elem).text().replace("¤",""); });
  $('.customer_telephone').each(function (i, elem) { customer_telephones[i]=$(elem).text().replace("¤",""); });
  $('.customer_order_id').each(function (i, elem)  { customer_order_ids[i]=$(elem).text().replace("¤",""); });
    
  GM_setValue("customer_names", customer_names.join("¤"));
  GM_setValue("customer_address1s", customer_address1s.join("¤"));
  GM_setValue("customer_address2s", customer_address2s.join("¤"));
  GM_setValue("customer_postcodes", customer_postcodes.join("¤"));
  GM_setValue("customer_emails", customer_emails.join("¤"));
  GM_setValue("customer_telephones", customer_telephones.join("¤"));
  GM_setValue("customer_order_ids", customer_order_ids.join("¤"));
    
  GM_setValue("no_of_customers", customer_names.length);
  GM_setValue("trigger", "1");
  alert("Collected " + customer_names.length + " customer addresses.");
  window.open("https://po.unifaun.se");
}
__________________
Säljer NES connector | Listar Sveriges Bästa Webbhotell

Senast redigerad av Fractronics den 2012-09-22 klockan 10:19.
Svara med citat