Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed May 4, 2016
0 parents commit 9b93886
Show file tree
Hide file tree
Showing 15 changed files with 3,177 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
lib
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
src
.*
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v6
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- "0.12"
- "4"
- "5"
- "6"
notifications:
email: false
after_success:
- npm run coveralls
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2016 Leonardo Gatica

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# sii

[![npm version](https://img.shields.io/npm/v/sii.svg?style=flat-square)](https://www.npmjs.com/package/sii)
[![npm downloads](https://img.shields.io/npm/dm/sii.svg?style=flat-square)](https://www.npmjs.com/package/sii)
[![Build Status](https://img.shields.io/travis/lgaticaq/sii.svg?style=flat-square)](https://travis-ci.org/lgaticaq/sii)
[![Coverage Status](https://img.shields.io/coveralls/lgaticaq/sii/master.svg?style=flat-square)](https://coveralls.io/github/lgaticaq/sii?branch=master)
[![dependency Status](https://img.shields.io/david/lgaticaq/sii.svg?style=flat-square)](https://david-dm.org/lgaticaq/sii#info=dependencies)
[![devDependency Status](https://img.shields.io/david/dev/lgaticaq/sii.svg?style=flat-square)](https://david-dm.org/lgaticaq/sii#info=devDependencies)

Crea facilmente boleta de honorarios

## Installation
```bash
npm i -S sii
```
19 changes: 19 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const sii = require('sii');

const user = {
rut: '11.111.111-1',
password: '0123456789'
};
const work = {
description: 'AMAZING WORK',
value: 555556
};
const destinatary = {
rut: 22222222,
dv: '2',
name: 'AMAZING COMPANY',
address: 'STREET 1'
};
const zone = 13;
const commune = 15103;
const sucess = await sii.byDestinatary(user, work, destinatary, zone, commune)
83 changes: 83 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"name": "sii",
"version": "0.0.1",
"description": "Crea facilmente boleta de honorarios",
"main": "lib",
"scripts": {
"prepublish": "npm run build -s",
"prebuild": "npm run lint -s && npm run clean -s",
"build": "babel src --out-dir lib --source-maps",
"lint": "eslint src",
"clean": "rimraf lib",
"pretest": "npm run lint -s",
"test": "babel-node ./node_modules/.bin/isparta cover _mocha",
"coveralls": "coveralls < coverage/lcov.info"
},
"engines": {
"node": ">=0.12"
},
"repository": {
"type": "git",
"url": "git://github.com/lgaticaq/sii.git"
},
"keywords": [
"sii"
],
"author": "Leonardo Gatica <[email protected]> (https://about.me/lgatica)",
"license": "MIT",
"bugs": {
"url": "https://github.com/lgaticaq/sii/issues"
},
"homepage": "https://github.com/lgaticaq/sii#readme",
"dependencies": {
"nightmare": "^2.3.4",
"phantom": "^2.1.1",
"request-promise": "^3.0.0"
},
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-core": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"chai": "^3.5.0",
"coveralls": "^2.11.9",
"eslint": "2.9.0",
"isparta": "^4.0.0",
"mocha": "^2.4.5",
"rimraf": "^2.5.2"
},
"eslintConfig": {
"env": {
"es6": true,
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"indent": [
2,
2
],
"linebreak-style": [
2,
"unix"
],
"quotes": [
2,
"single"
],
"semi": [
2,
"always"
]
}
},
"babel": {
"presets": [
"es2015"
]
},
"tonicExampleFilename": "example.js"
}
110 changes: 110 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/* global $ */

import Nightmare from 'nightmare';
import rp from 'request-promise';
import zones from '../zones.json';

const userAgent = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36';
const loginUri = 'https://zeus.sii.cl/AUT2000/InicioAutenticacion/IngresoRutClave.html?https://misii.sii.cl/cgi_misii/siihome.cgi';
const boletasUri = 'http://www.sii.cl/boleta_honorarios/';

const getDestinataryName = (rut) => {
const options = {
uri: 'https://siichile.herokuapp.com/consulta',
qs: {rut: rut},
json: true
};
return rp(options).then(data => data.razon_social);
};

const sendCredentials = (user) => {
$('#rutcntr').val(user.rut);
$('#rutcntr').blur();
$('#clave').val(user.password);
$('a[href="javascript:ejecuta_opcion()"]')[0].click();
};

const gotToLast = () => {
$('a[href="javascript:muestra_oculta_opc(1)"]')[0].click();
$('#menu1 ul li:nth-child(2) a')[0].click();
};

const gotToDestinatary = () => {
$('a[href="javascript:muestra_oculta_opc(1)"]')[0].click();
$('#menu1 ul li:nth-child(1) a')[0].click();
};

const selectLast = () => {
$('a[href="javascript:envia();"]')[0].click();
};

const selectRetention = () => {
$('input[name=OptTipoRetencion]').val('RETRECEPTOR');
$('#cmdContinuar').click();
};

const fillForm = (work, destinatary=null, zone=null, commune=null) => {
$('#desc_prestacion_1').val(work.description);
$('#valor_prestacion_1').val(work.value);
if (destinatary !== null) {
$('input[name=txt_rut_destinatario]').val(destinatary.rut);
$('input[name=txt_dv_destinatario]').val(destinatary.dv);
$('input[name=txt_nombres_destinatario]').val(destinatary.name);
$('input[name=txt_domicilio_destinatario]').val(destinatary.address);
}
if (zone !== null) {
$('select[name=cod_region]').val(zone);
$('select[name=cod_region]').change();
}
if (commune !== null) {
$('select[name=cbo_comuna]').val(commune);
$('select[name=cbo_comuna]').change();
}
};

const byLastInvoice = (user, work) => {
return new Promise((resolve, reject) => {
new Nightmare()
.viewport(1000, 1000)
.useragent(userAgent)
.goto(loginUri)
.wait()
.evaluate(sendCredentials, user)
.wait(1000)
.goto(boletasUri)
.evaluate(gotToLast)
.evaluate(selectLast)
.evaluate(fillForm, work)
.run(err => {
if (err) return reject(err);
resolve();
});
});
};

const byDestinatary = (user, work, destinatary, zone, commune) => {
return new Promise((resolve, reject) => {
new Nightmare()
.viewport(1000, 1000)
.useragent(userAgent)
.goto(loginUri)
.wait()
.evaluate(sendCredentials, user)
.wait(1000)
.goto(boletasUri)
.evaluate(gotToDestinatary)
.evaluate(selectRetention)
.evaluate(fillForm, work, destinatary, zone, commune)
.run(err => {
if (err) return reject(err);
resolve();
});
});
};

module.exports = {
byLastInvoice: byLastInvoice,
byDestinatary: byDestinatary,
getDestinataryName: getDestinataryName,
zones: zones
};
Loading

0 comments on commit 9b93886

Please sign in to comment.