Advertisement
Lusien_Lashans

app.js dealcollector

Jun 4th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let reader = new FileReader();
  2. let strBuffer = "";
  3. let sber_deals = null;
  4. let crm_deals = [];
  5.  
  6. function processFiles(files) {
  7.     let file = files[0];
  8.     reader.readAsText(file);
  9. }
  10.  
  11. reader.onload = function (e) {
  12.     strBuffer = e.target.result;
  13. };
  14.  
  15. function loadData() {
  16.     //взять только оплаченные по определенному способу оплаты
  17.     crm_deals.forEach(data => data.filter(deal => parser.check_payment_methods(get_user_field(deal, 'Способ оплаты'))));
  18.  
  19.     if (strBuffer == "")
  20.         alert("Файл не загружен");
  21.     else
  22.         sber_deals = parser.get_deals(strBuffer);
  23.    
  24.     modify(sber_deals, crm_deals, parser);
  25. }
  26.  
  27. function application () {
  28. }
  29.  
  30. application.prototype.displayErrorMessage = function(message) {
  31.     $('#deal-list').html(message);
  32.     $('#deal-sum').html(message);
  33. }
  34.  
  35. application.prototype.displayCurrentUser = function(selector) {
  36.     BX24.callMethod('user.current', {}, function(result){
  37.         $(selector).html(result.data().NAME + ' ' + result.data().LAST_NAME);
  38.     });
  39. }
  40.  
  41. application.prototype.displayUserClosedDeals = function (idUser) { 
  42.     var curapp = this;
  43.    
  44.     BX24.callMethod(
  45.         "crm.deal.list",
  46.         {
  47.             order: { "DATE_CREATE": "ASC" },
  48.             filter: { "ASSIGNED_BY_ID": idUser },
  49.             select: [ "TITLE", "OPPORTUNITY", "DATE_CREATE", "COMPANY_ID", "UF_*" ]
  50.         },
  51.         function(result)
  52.         {
  53.             if (result.error()) {
  54.                 curapp.displayErrorMessage('К сожалению, произошла ошибка получения сделок. Попробуйте повторить отчет позже');
  55.                 console.error(result.error());
  56.             }
  57.             else
  58.             {
  59.                 let data = result.data();
  60.  
  61.                 let requisites = null;
  62.  
  63.                 BX24.callMethod(
  64.                     "crm.requisite.list",
  65.                     {
  66.                         select: [ "ID", "NAME", "RQ_INN", "RQ_COMPANY_NAME"]
  67.                     },
  68.                     function(result)
  69.                     {
  70.                         if(result.error())
  71.                             console.error(result.error());
  72.                         else
  73.                         {
  74.                             //console.dir(result.data());
  75.                             requisites = result.data();    
  76.                             if(result.more())
  77.                                 result.next();                     
  78.                         }
  79.                     }
  80.                 );
  81.  
  82.                 data.forEach(deal => {
  83.                     let id = deal.COMPANY_ID;
  84.  
  85.                     if (id != 0) {
  86.                         BX24.callMethod(
  87.                             "crm.company.get",
  88.                             { id: id },
  89.                             function(result)
  90.                             {
  91.                                 if(result.error())
  92.                                     console.error(result.error());
  93.                                 else
  94.                                 {
  95.                                     //console.dir(result.data());
  96.                                     requisites.forEach( requisite => {
  97.                                         if (requisite.RQ_COMPANY_NAME == result.data().TITLE)
  98.                                             console.log(requisite.RQ_INN);//сюда надо
  99.                                     });
  100.                                 }
  101.                             }
  102.                         );
  103.                     }
  104.                 });
  105.                    
  106.                 //взять неоплаченные сделки
  107.                 data = data.filter(deal => get_user_field(deal, 'Оплата') == VALUES_PAYS[config.payment_status]);
  108.  
  109.                 //взять сделки за последние Х дней
  110.                 data = data.filter(deal => is_day_in_delta(config.days_count, deal.DATE_CREATE));
  111.                
  112.                 crm_deals.push(data);
  113.                            
  114.                 if (result.more())
  115.                     result.next();
  116.             }
  117.         }
  118.     );
  119. }
  120.  
  121. // create our application
  122. app = new application();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement