1'use strict'; 2require('../../libs/datepicker/datepicker.js'); 3 4var Ajax = require('../../core/ajax.js'); 5var Requisites = require('/const/requisites'); 6// заменим инн (ÑолÑко Ð´Ð»Ñ Ð²Ð½ÐµÑнего банка) на нÑли, еÑли оно не заполнено. ТолÑко визÑалÑно, даннÑе никÑда не идÑÑ. 7if (Requisites && Requisites.length) { 8 Requisites.forEach(function(r) { 9 if (r.project_company_requisites && r.project_company_requisites.is_foreign_bank && !r.project_company_requisites.foreign_company_inn) { 10 r.project_company_requisites.foreign_company_inn = '000000000000'; 11 } 12 13 if (r.project_company_new_requisites && r.project_company_new_requisites.is_foreign_bank && !r.project_company_new_requisites.foreign_company_inn) { 14 r.project_company_new_requisites.foreign_company_inn = '000000000000'; 15 } 16 }); 17} 18 19var current_requesites = null; 20var $form = $('#requisites-form'); 21var $projects = $('select#project_id'); 22 23function areRequisitesChanged($items) { 24 var ok = true; 25 26 $items.each(function() { 27 if (($(this).attr('type') === 'radio') && (!$(this).prop('checked'))) { 28 return; 29 } 30 31 const expectedValue = current_requesites.project_company_requisites[this.name] || (this.name === 'value_added_tax' ? '0' : ''); 32 33 if (this.value !== expectedValue) 34 { 35 ok = false; 36 } 37 }); 38 39 if ((!ok) && (!confirm(I18n.t('common.msg.confirm_unsaved')))) { 40 $projects.val(current_requesites.project_id); 41 return true; 42 } 43 44 return false; 45} 46 47function getItems(isMediaCube, isForeignBank, onlyFormEl) { 48 var $items = []; // могÑÑ Ð±ÑÑÑ input(text, radio), select, .text-item 49 50 if (isMediaCube) { 51 $items = $form.find('.mediacube-req input'); 52 } else if (isForeignBank) { 53 $items = $form.find('.foreign-bank-req input[type="text"], .all-bank-req input[type="radio"], .foreign-bank-req select, .foreign-bank-req .text-item'); 54 } else { 55 $items = $form.find('.bank-req input[type="text"], .bank-req input[type="number"], .all-bank-req input[type="radio"], .bank-req #organization, .bank-req #value_added_tax'); 56 } 57 58 if (onlyFormEl) { 59 $items = $items.filter('input, select'); 60 } 61 62 return $items; 63} 64 65function getForm(projectId, onlyFormEl) { 66 var req = _.find(Requisites, {project_id: parseInt(projectId)}); 67 68 var confirmed = (!req.project_company_new_requisites); 69 var isMediaCube = (req.project_creator_type === 'mediacube'); 70 var isForeignBank = confirmed ? (!!parseInt(req.project_company_requisites.is_foreign_bank)) : (!!parseInt(req.project_company_new_requisites.is_foreign_bank)); 71 var $items = getItems(isMediaCube, isForeignBank, onlyFormEl); 72 73 var res = { 74 req: req, 75 confirmed: confirmed, 76 isMediaCube: isMediaCube, 77 isForeignBank: isForeignBank, 78 $items: $items 79 }; 80 81 return res; 82} 83 84function showFields($items) { 85 $('.wrap-req-item').hide(); 86 87 $items.each(function() { 88 $(this).closest('.wrap-req-item').show(); 89 }); 90} 91 92function clearFields() { 93 $('input[type="text"]').val('').prop('readonly', false); 94 $('input[type="number"]').val('').prop('readonly', false); 95 $('select[name="organization"]').val('').prop('disabled', false).trigger('chosen:updated'); 96 $('select[name="value_added_tax"]').val('0').prop('disabled', true); 97 $('select[name="foreign_country"]').val('').prop('disabled', false).trigger('chosen:updated'); 98 $('input[name="is_foreign_bank"]').prop('checked', false).prop('disabled', false); 99} 100 101function fillForm(data) { 102 showFields(data.$items); 103 104 var values = data.req.project_company_new_requisites || data.req.project_company_requisites; 105 // backward compatibility 106 if (typeof values.is_foreign_bank === 'undefined') { 107 values.is_foreign_bank = '0'; 108 } 109 110 clearFields(); 111 112 _.each(values, function(val, name) { 113 if (name === 'foreign_country') { 114 data.$items.filter('select[name="foreign_country"]').val(val).prop('disabled', !data.confirmed).trigger('chosen:updated'); 115 } else if (name === 'is_foreign_bank') { 116 data.$items.filter('input[name="is_foreign_bank"][value="'+ val +'"]').prop('checked', true); 117 data.$items.filter('input[name="is_foreign_bank"]').prop('disabled', !data.confirmed); 118 } else if (name === 'organization') { 119 data.$items.filter('select[name="organization"]').val(val).prop('readonly', !data.confirmed); 120 if (typeof values.value_added_tax === 'undefined') { 121 data.$items.filter('select[name="value_added_tax"]').val('0').prop('disabled', ['sp', 'llc'].indexOf(values.organization) === -1); 122 } 123 } else if (name === 'value_added_tax') { 124 data.$items.filter('select[name="value_added_tax"]').val(val).prop('disabled', ['sp', 'llc'].indexOf(values.organization) === -1); 125 } else if (name === 'company_inn') { 126 data.$items.filter('input[type="number"][name="' + name + '"]').val(val).prop('readonly', !data.confirmed); 127 } else { 128 data.$items.filter('input[type="text"][name="' + name + '"]').val(val).prop('readonly', !data.confirmed); 129 } 130 }); 131 132 // if ((!data.isForeignBank) && (!data.isMediaCube)) { 133 // $('.inn-check-msg').toggle(!data.req.project_company_requisites.company_inn); 134 // } else { 135 // $('.inn-check-msg').hide(); 136 // } 137 138 $('.req-check-msg').toggle(!data.confirmed); 139 $('input[type="submit"]').prop('disabled', ((data.isMediaCube) || (!data.confirmed))); 140} 141 142 143const updateFormView = (selectedOrg) => { 144 const $companyLabel = $('input[name="company_name"]').closest('.input').find('label'); 145 const $addressLabel = $('input[name="legal_address"]').closest('.input').find('label'); 146 const $passportContainer = $('input[name="passport_number"]').closest('.input'); 147 const $subdivisionCodeContainer = $('input[name="subdivision_code"]').closest('.input'); 148 const $passportIssuedContainer = $('input[name="passport_issued"]').closest('.input'); 149 const $birthDateContainer = $('input[name="birth_date"]').closest('.input'); 150 const $cardMsgContainer = $('.card-msg-container'); 151 const $yMoneyContainer = $('input[name="purpose_of_payment"]').closest('.req-2g'); 152 153 if (selectedOrg.length !== 0) { 154 if (selectedOrg === 'llc') { 155 $companyLabel.html(I18n.t('common.request_system.name.legal')); 156 $addressLabel.html(I18n.t('common.request_system.address.legal')); 157 $passportContainer.css({ opacity: 0, visibility: 'hidden' }); 158 $subdivisionCodeContainer.css({ opacity: 0, visibility: 'hidden' }); 159 $passportIssuedContainer.css({ opacity: 0, visibility: 'hidden' }); 160 $birthDateContainer.css({ opacity: 0, visibility: 'hidden' }); 161 $cardMsgContainer.hide(); 162 $yMoneyContainer.hide(); 163 164 const requiredForLLC = ['company_name', 'bank_name', 'bank_bik', 'bank_account']; 165 166 requiredForLLC.forEach(name => { 167 const $input = $(`input[name="${name}"]`); 168 if (selectedOrg === 'llc') { 169 $input.addClass('required'); 170 } else { 171 $input.removeClass('required'); 172 } 173 }); 174 } else { 175 $companyLabel.html(I18n.t('common.request_system.name.others')); 176 $addressLabel.html(I18n.t('common.request_system.address.others')); 177 $passportContainer.css({ opacity: 1, visibility: 'visible' }); 178 $subdivisionCodeContainer.css({ opacity: 1, visibility: 'visible' }); 179 $passportIssuedContainer.css({ opacity: 1, visibility: 'visible' }); 180 $birthDateContainer.css({ opacity: 1, visibility: 'visible' }); 181 $cardMsgContainer.show(); 182 $yMoneyContainer.show(); 183 } 184 } else { 185 $companyLabel.html(I18n.t('common.request_system.legal_entity')); 186 $addressLabel.html(I18n.t('form.placeholder.legal_address')); 187 $passportContainer.css({ opacity: 1, visibility: 'visible' }); 188 $subdivisionCodeContainer.css({ opacity: 1, visibility: 'visible' }); 189 $passportIssuedContainer.css({ opacity: 1, visibility: 'visible' }); 190 $birthDateContainer.css({ opacity: 1, visibility: 'visible' }); 191 $cardMsgContainer.show(); 192 $yMoneyContainer.show(); 193 } 194} 195 196$projects.change(function(e) { 197 if ((current_requesites) && (!current_requesites.project_company_new_requisites)) { 198 var currProject = getForm(current_requesites.project_id, true); 199 if (areRequisitesChanged(currProject.$items)) { 200 e.preventDefault(); 201 return; 202 } 203 } 204 205 var newProject = getForm(this.value); 206 fillForm(newProject); 207 updateFormView($('select[name="organization"]').val()); 208 209 current_requesites = newProject.req; 210 211}).trigger('change'); 212 213$form.submit(function(e) { 214 e.preventDefault(); 215 216 var isForeignBank = parseInt($('[name="is_foreign_bank"]:checked').val()) || 0; 217 var $items = getItems(false, isForeignBank, true); 218 219 if (!validateForm($items)) { 220 return; 221 } 222 223 var requisites = {}; 224 225 $items.each(function() { 226 var $el = $(this), 227 name = $el.attr('name'), 228 type = $el.attr('type'); 229 230 if (name) { 231 var val = $el.val(); 232 if (['bank_account', 'bank_cor_account', 'bank_bik', 'foreign_company_inn', 'foreign_ru_bank_account', 'company_inn'].indexOf(name) > -1) { 233 val = val.replaceAll(' ', ''); 234 } 235 236 if (name === 'foreign_company_inn') { 237 val = ''; 238 } 239 240 if (name === 'is_foreign_bank') { 241 val = parseInt(val) || 0; 242 } 243 244 if (name === 'phone') { 245 if (val.length > 0) { 246 val = val.trim() 247 val = val.replace(/[^0-9]/g, ''); 248 249 if (val.length > 0) { 250 if (val.length === 10) { 251 val = '+7' + val; 252 } else if (val.length === 11) { 253 if (val[0] === '7') { 254 val = '+' + val; 255 } else if (val[0] === '8') { 256 val = '+7' + val.substring(1) 257 } 258 } 259 } 260 } 261 } 262 263 if (name === 'passport_number') { 264 if (val.length > 0) { 265 val = val.trim().replace(/[^0-9]/g, ''); 266 } 267 } 268 269 if (name === 'subdivision_code') { 270 if (val.length > 0) { 271 val = val.trim().replace(/[^0-9]/g, ''); 272 val = val.substring(0, 3) + '-' + val.substring(3); 273 } 274 } 275 276 if (['passport_issued', 'birth_date'].indexOf(name) > -1) { 277 if (val.length > 0) { 278 val = val.trim().replace(/[-\/]/g, '.'); 279 } 280 } 281 282 if (type === 'radio') { 283 if ($el.prop('checked')) { 284 requisites[name] = val; 285 } 286 } else { 287 requisites[name] = val; 288 } 289 } 290 }); 291 292 Ajax.postJSON('/income/requisites-update', { 293 requisites: requisites, 294 project_id: $('#project_id').val() 295 }, function(result) { 296 if (result.response) { 297 window.location.href = '/income/withdraw'; 298 } else { 299 if(typeof result.error === 'object') { 300 if(result.error && result.error.code && result.error.code === 403 ) { 301 alert(I18n.t('project.roles.errors.forbidden')); 302 } else { 303 alert(JSON.stringify(result.error)); 304 } 305 } else { 306 alert(result.error); 307 } 308 } 309 }); 310}); 311 312function validateForm($items) { 313 var errors = 0; 314 315 $items.removeClass('error'); 316 317 const orgType = $('[name="organization"]').val(); 318 const isRussia = $('input[name="is_foreign_bank"]:checked').val() === '0'; 319 320 if (isRussia) { 321 $items.each(function() { 322 var val = this.value.trim(); 323 if (['organization'].indexOf($(this).attr('name')) > -1) { 324 if (!val) { 325 errors++; 326 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.client.invali
326d_org_type')); 327 } 328 } 329 330 if (['self', 'sp', 'fizik'].includes(orgType) && (['purpose_of_payment', 'name_of_recipient', 'organization', 'phone'].indexOf($(this).attr('name')) === -1)) { 331 if (!val) { 332 errors++; 333 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.required')); 334 } 335 } 336 337 if (['value_added_tax'].indexOf($(this).attr('name')) > -1) { 338 if (!val) { 339 errors++; 340 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.client.invalid_org_type')); 341 } 342 } 343 344 if (['legal_address'].indexOf($(this).attr('name')) > -1) { 345 if (val.length > 0 && val.length < 20) { 346 errors++; 347 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.client.invalid_address')); 348 } 349 } else if (['phone'].indexOf($(this).attr('name')) > -1) { 350 const newVal = val.replace(/[^0-9]/g, ''); 351 if (newVal.length > 0 || (val.length > 0 && newVal.length === 0)) { 352 if (newVal.length !== 10) { 353 if ((newVal.length === 11 && (newVal[0] !== '7' && newVal[0] !== '8'))) { 354 errors++; 355 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.client.invalid_phone')); 356 } else if (newVal.length < 10 || newVal.length > 11) { 357 errors++; 358 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.client.invalid_phone')); 359 } 360 } 361 } 362 } else if (['passport_number'].indexOf($(this).attr('name')) > -1) { 363 const newVal = val.replace(/[^0-9]/g, ''); 364 if ((newVal.length > 0 && newVal.length !== 10) || (val.length > 0 && newVal.length === 0)) { 365 errors++; 366 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.client.invalid_passport_number')); 367 } 368 } else if (['subdivision_code'].indexOf($(this).attr('name')) > -1) { 369 const newVal = val.replace(/[^0-9]/g, ''); 370 if ((newVal.length > 0 && newVal.length !== 6) || (val.length > 0 && newVal.length === 0)) { 371 errors++; 372 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.client.invalid_subdivision_code')); 373 } 374 } else if (['passport_issued', 'birth_date'].indexOf($(this).attr('name')) > -1) { 375 const dateRegex = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/g; 376 if (val.length > 0) { 377 if (!dateRegex.test(val)) { 378 errors++; 379 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.client.invalid_passport_issued')); 380 } 381 } 382 } 383 }) 384 } 385 386 $items = $items.filter('.required'); 387 388 $items.each(function() { 389 var val = this.value.trim(); 390 391 if (['foreign_requisites_info', 'foreign_swift'].indexOf($(this).attr('name')) > -1) { 392 } else if (['bank_account', 'bank_cor_account', 'bank_bik', 'foreign_company_inn', 'foreign_ru_bank_account', 'company_inn'].indexOf($(this).attr('name')) > -1) { 393 val = val.replaceAll(' ', ''); 394 395 var allowedLenght = []; 396 397 if (typeof $(this).data('length') === 'number') { 398 allowedLenght = ['' + $(this).data('length')]; 399 } else if (typeof $(this).data('length').split === 'function') { 400 allowedLenght = $(this).data('length').split('|'); 401 } 402 403 if (!val && ($(this).attr('name') === 'company_inn' || (['bank_bik', 'bank_account', 'bank_name'].includes($(this).attr('name'))))) { 404 errors++; 405 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.required')); 406 } 407 408 if ((val) && (allowedLenght.indexOf('' + val.length) === -1)) { 409 errors++; 410 411 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.client.lim_number', {limit_10_or_12: allowedLenght.join(' '+ I18n.t('common.or') +' ')})); 412 } 413 return; 414 } else if (!val) { 415 errors++; 416 $(this).addClass('error').parent().find('.error-msg').html(I18n.t('error.validator.required')); 417 } 418 }); 419 420 return (errors === 0); 421} 422 423$('select[name="foreign_country"]').chosen(); 424 425$('[name="is_foreign_bank"]').change(function(e) { 426 e.preventDefault(); 427 428 var $items = getItems(false, (parseInt(this.value) || 0)); 429 if ((parseInt(this.value) || 0) === 0) { 430 $('.ru-form').show(); 431 } 432 else { 433 $('.ru-form').hide(); 434 } 435 showFields($items); 436}); 437 438$('#organization').on('change', function() { 439 const selectedOrg = $(this).val(); 440 var $vatSelect = $('#value_added_tax'); 441 442 if (['sp', 'llc'].indexOf(selectedOrg) !== -1) { 443 $vatSelect.prop('disabled', false); 444 } else { 445 $vatSelect.prop('disabled', true); 446 $vatSelect.val('0'); 447 } 448 449 updateFormView(selectedOrg) 450}); 451 452$('#organization').trigger('change');
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.