Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. /**
  2. * File: \src\AllFt\AllFt_SourceOther_wfInitialize.js
  3. * Project: mDocs Cloud Solution
  4. * Created Date: 14.08.2017 07:08:68
  5. * Author: mitjak
  6. * Description:
  7. * -----
  8. * Last Modified: 08.01.2018
  9. * Modified By: mitjak
  10. * -----
  11. * Copyright (c) 2017 Mikrografija d.o.o.
  12. */
  13.  
  14. // #import "Prototype";
  15. // #import "AllFtExtendedLib";
  16. // #import "IncomingInvoiceLib"; // CUSTOM SIMONAV 09-09-2019
  17.  
  18. try {
  19.  
  20. var docFile = context.file;
  21. var su = context.getSystemUser();
  22. var fileType = docFile.getAutoText("%fileType%");// CUSTOM SIMONAV 09-09-2019
  23.  
  24.  
  25. switch(docFile.Source) {
  26. case "manual":
  27. break;
  28. case "eRacun":// CUSTOM START
  29. case "eracun":
  30. var hrs = null;
  31. var organizations = null;
  32.  
  33. // Set organization
  34. docFile.DocumentNumber = "";
  35. docFile.setFieldAttribute("DocumentNumber", "Value", "");
  36.  
  37. var orgTaxNumber = docFile.Contact;
  38. hrs = new HitResultset("OrganizationalUnit", "TechnicalName!='' AND Enabled='1'", "", ["Id"]);
  39. for (var hitFile = hrs.first(); hitFile; hitFile = hrs.next()) {
  40. var organizationalUnitFile = hitFile.getFile();
  41. if(organizationalUnitFile) {
  42. if(organizationalUnitFile.CompanyTaxNumber.indexOf(orgTaxNumber)!=-1){
  43. docFile.setFieldAttribute("OrganizationalUnit", "Value", organizationalUnitFile.TechnicalName);
  44. docFile.OrganizationalUnit = organizationalUnitFile.TechnicalName;
  45.  
  46. //docFile.ConfigRef = docFile.getAutoText("fileType") + "_" + docFile.Organization;
  47. //docFile.setFieldAttribute("ConfigRef", "Value", docFile.ConfigRef);
  48. docFile = context.file;
  49. }
  50. }
  51. }
  52.  
  53. organizations=null;
  54.  
  55. // Set Company
  56. var comTaxNumber = docFile.TaxNumber;
  57. hrs = new HitResultset("Account", "TaxNumber~'" + comTaxNumber + "' ", "", ["Id"]);
  58.  
  59. //util.out("TaxNumber='" + comTaxNumber + "'");
  60. //util.out("hrs.size() = " + hrs.size());
  61.  
  62. if(hrs.size() > 0) {
  63. docFile.CompanyNumber = hrs.first().getFile().getAutoText("%id%");
  64. }
  65. hrs.dispose();
  66. hrs = null;
  67.  
  68. if(docFile.OrganizationalUnit=="17") {
  69. docFile.setFieldAttribute("c_SaopTransfer", "Value", 1);
  70. docFile.c_SaopTransfer = 1;
  71. }
  72.  
  73. docFile.Contact = "";
  74. docFile.setFieldAttribute("Contact", "Value", "");
  75.  
  76. if(!docFile.sync())
  77. throw docFile.getLastError();
  78.  
  79. if(docFile.getAutoText("%fileType%")=="IncomingInvoice") {
  80. IncomingInvoiceHelper.setDocumentNumber(docFile);
  81. }
  82.  
  83. /*organization = util.getOrganization(docFile);
  84. if(
  85. organization &&
  86. organization != "all"
  87. ) {
  88. ConfirmationHelper.setDefaultConfirmationValues(docFile, true);
  89. ConfirmationHelper.setConfirmationFields(docFile, true);
  90. } else {*/
  91. if(fileType == "IncomingInvoice") {
  92. ConfirmationHelper.setConfirmationFields(docFile, false);
  93. } else {
  94. ConfirmationHelper.setConfirmationFields(docFile, true);
  95. }
  96. //}
  97.  
  98. break;
  99. case "mScan":
  100. case "mscan":
  101. case "TIS":
  102. case "tis":
  103. case "import":
  104. default:
  105.  
  106. var organization = util.getOrganization(docFile);
  107. var configRegExist = docFile.hasField("ConfigRef");
  108.  
  109. var confirmationEnabled = (util.getModuleConfigAttribute(docFile.getAutoText("fileType"), "ConfirmationEnabled") == 1);
  110.  
  111. /*if(
  112. organization &&
  113. organization != "all"
  114. ) {*/
  115. /*if(configRegExist) {
  116. docFile.ConfigRef = docFile.getAutoText("fileType") + "_" + organization;
  117.  
  118. docFile.setFieldAttribute("ConfigRef", "Value", docFile.ConfigRef);
  119. docFile = context.file;
  120. }*/
  121. /*if(confirmationEnabled) {
  122. ConfirmationHelper.setDefaultConfirmationValues(docFile, true);
  123. ConfirmationHelper.setConfirmationFields(docFile, true);
  124. }
  125. } else {*/
  126. /*if(configRegExist) {
  127. docFile.ConfigRef = docFile.getAutoText("fileType");
  128. docFile.setFieldAttribute("ConfigRef", "Value", docFile.ConfigRef);
  129. docFile = context.file;
  130. }*/
  131. if(fileType == "IncomingInvoice") {
  132. ConfirmationHelper.setConfirmationFields(docFile, false);
  133. } else {
  134. ConfirmationHelper.setConfirmationFields(docFile, true);
  135. }
  136. //}
  137.  
  138. if(confirmationEnabled) {
  139. ConfirmationHelper.setConfirmer(docFile, "Confirmer1");
  140. docFile.sync();
  141. }
  142.  
  143. break; // CUSTOM END
  144. }
  145.  
  146. ModuleHelper.repairFields(docFile);
  147.  
  148. var messageCommentField = util.getFileTypeProperty(
  149. docFile.getAutoText("%fileType%"),
  150. "$CommentField"
  151. );
  152. if(
  153. util.buildNo >= 2060 &&
  154. messageCommentField &&
  155. docFile.hasField(messageCommentField) &&
  156. docFile[messageCommentField]
  157. ) {
  158. try {
  159. if(
  160. messageCommentField &&
  161. //docFile.hasField(messageCommentField) &&
  162. docFile[messageCommentField] &&
  163. (
  164. docFile[messageCommentField].toString().indexOf("{") != 0 ||
  165. docFile[messageCommentField].toString().indexOf("_$$$_") > 0
  166. )
  167. ) {
  168.  
  169. var json = {
  170. fileId: docFile.getAutoText("%id%"),
  171. messages: [],
  172. member: []
  173. };
  174.  
  175. var repair = false;
  176.  
  177. var indexDollars = docFile[messageCommentField].toString().indexOf("_$$$_");
  178. if(indexDollars > 0) {
  179. repair = true;
  180. docFile[messageCommentField] = JSON.stringify(JSON.parse(docFile[messageCommentField].toString().substring(0, indexDollars)));
  181. } else if(docFile[messageCommentField].toString().indexOf("{") != 0) {
  182. repair = true;
  183.  
  184. json.messages.push({
  185. body: docFile[messageCommentField].toString(),
  186. recipients: [],
  187. id: "",
  188. author: (su ? su.login : ""),
  189. authorLabel: (su ? su.firstName + " " + su.lastName : ""),
  190. timestamp: ((new Date).getTime()/1000)
  191. });
  192.  
  193. docFile[messageCommentField] = JSON.stringify(json);
  194. }
  195.  
  196. if(repair) {
  197. docFile.setFieldAttribute(messageCommentField, "ShortValue", docFile[messageCommentField]);
  198. docFile.setFieldAttribute(messageCommentField, "Value", docFile[messageCommentField]);
  199.  
  200. docFile.sync();
  201. }
  202.  
  203. }
  204. } catch(eComment) {
  205. util.errorLog(eComment);
  206. }
  207. }
  208.  
  209. Helper.executeCustomScript(docFile);
  210.  
  211. } catch (e) {
  212. util.errorLog(e);
  213. //context.errorMessage = e;
  214. //return -1;
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement