freedom@diversity

Sutff about my job and comments about personal activities. Take a look to the first idea.

Monday, April 16, 2018

Microsip - Precios con descuentos

En Microsip, el modulo de comercio exterior no coinciden los totales de la factura vs el total del módulo de comercio exterior, por lo q es necesario modificar los precios para q incluya el descuento.

Se creo un script en python q permite hacer este cambio.

#!/usr/bin/env python
# @author Beto Reyes
# @date 28/Marzo/2018
# http://kinterbasdb.sourceforge.net/dist_docs/usage.html#tutorial
# syntax on
# colorscheme darkblue
import kinterbasdb as k
import csv, datetime, os
import argparse, sys, glob
import logging, logging.handlers
from sets import Set
from datetime import timedelta

parser = argparse.ArgumentParser(description='Actualiza el precio de cada partida en base al descuento')
parser.add_argument('--database', dest='strAliasfdb', default='Prueba')
parser.add_argument('--force', dest='boolForce', default='0') # False
parser.add_argument('--commit', dest='commit', default='0') # False
parser.add_argument('--folio', dest='folio', default='0') # False
args = parser.parse_args()
globals().update(vars(args))
#print args

class doctosVentas:
       #strAliasfdb='Prueba'
       #strAliasfdb='IRSA'

       def __init__(self, strDBHost, strAliasfdb, strPassword):
               logger.info("Conectandose a DB %s:%s" % (strDBHost, strAliasfdb))
               self.con = k.connect(dsn='%s:%s.fdb' % (strDBHost, strAliasfdb), user='sysdba', password=strPassword,
                       timeout={'period': 60.0}) # time out after 60.0 seconds of inactivity
               self.cur = self.con.cursor()
               self.strAliasfdb = strAliasfdb

       #
       def convierteDescuento(self, folio):
               if folio == "0": return 1

               strSql = "select folio, tipo_docto, subtipo_docto, estatus, aplicado, cfdi_certificado, docto_ve_id \n\
                       from doctos_ve where folio like '%s%%%s'" % (folio[0], folio[1:])
               logger.debug("%s" % (strSql))
               cur = self.con.cursor()
               cur.execute(strSql)
               docto = cur.fetchone()
               folio = docto[0]
               tipo_docto = docto[1]
               subtipo_docto = docto[2]
               estatus = docto[3]
               aplicado = docto[4]
               cfdi_certificado = docto[5]
               docto_ve_id = docto[6]
               logger.info( "Folio:%s Tipo:%s Subtipo:%s Estatus:%s Aplicado:%s CFDI:%s" %
                       (folio, tipo_docto, subtipo_docto, estatus, aplicado, cfdi_certificado ))
               if not ((( tipo_docto == 'F' and  estatus == 'N' ) or ( tipo_docto == 'R' and  estatus == 'P' )) and
                       subtipo_docto == 'N' and aplicado == 'S' and cfdi_certificado == 'N'):
                       logger.info ("No es posible modificar la factura")
                       return 1
               strSql = "select precio_unitario, pctje_dscto, docto_ve_det_id from doctos_ve_det \n\
                       where docto_ve_id = %s" % (docto_ve_id)
               cur.execute(strSql)
               detalle = cur.fetchall()
               detalle2 = []
               for row in detalle:
                       precio_unitario = row[0]
                       pctje_dscto = row[1]
                       docto_ve_det_id = row[2]
                       if pctje_dscto > 0:
                               #detalle2.append( [round(row[0]*(100-row[1])/100,3), 0, row[2]])
                               detalle2.append( [format(row[0]*(100-row[1])/100,'.2f'), 0, row[2]])
                       else:
                               detalle2.append( [format(row[0],'.2f'), 0, row[2]])
                       logger.info("id:%s precio:%s dscto:%s" % (docto_ve_det_id, precio_unitario, pctje_dscto))
               cur.executemany("update doctos_ve_det set precio_unitario = ? , pctje_dscto = ? where docto_ve_det_id = ?", de
talle2)
               logger.info("Actualizando...")
               cur.execute(strSql)
               detalle = cur.fetchall()
               for row in detalle:
                       precio_unitario = row[0]
                       pctje_dscto = row[1]
                       docto_ve_det_id = row[2]
                       logger.info("id:%s precio:%s dscto:%s" % (docto_ve_det_id, precio_unitario, pctje_dscto))

# Add log to unix syslog
logger = logging.getLogger('corrigeFactura')
syslog = logging.handlers.SysLogHandler()
syslog.setFormatter(logging.Formatter('%(name)s: %(message)s'))
logger.addHandler(syslog)
logger.setLevel(logging.INFO)

# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# set a format which is simpler for console use
formatter = logging.Formatter('%(levelname)-8s %(message)s')
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)

# Log everything and send it to stderr
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)

myFactura = doctosVentas('localhost', strAliasfdb, '437880')
#myFactura.convierteDescuento('C29877')
myFactura.convierteDescuento(folio)

if commit=='0':
       logger.info('Desconectando de DB: rollback')
       myFactura.con.rollback()
else:
       logger.info('Desconectando de DB: commit')
       myFactura.con.commit()
myFactura.con.close()

Thursday, June 01, 2017

NetworkManager

When using NetworkManager, it is posible to start a VPN connection after a successful wireless connection.
I have autofs configured on my home directory, so I need to start autofs after VPN connection:
/etc/NetworkManager/dispatcher.d/10autofs

#!/bin/bash
SERVER='172.16.1.1'
# Nothing to do if user does not have requisite binaries.
ping -c 1 $SERVER &>/dev/null
if [ $? -ne 0 ]; then
        # server is down so unmount
        /etc/init.d/autofs stop
else
        # server is up
        /etc/init.d/autofs start
fi
Whenever a VPN or wireless disconnection ocurrs, I've to stop autofs:
/etc/NetworkManager/dispatcher.d/pre-down.d/autofs
#!/bin/bash
interface=$1 
status=$2
if [ "$interface" == "wlan0" ] || [ "$CONNECTION_ID" == "reyesdf-tap" ]; then
        for dir in $(mount | grep "/mnt/auto" | awk '{print $3}' | tail -n +2)
        do
            umount $dir
        done
        sleep 5
        /etc/init.d/autofs stop
fi

References for understanding the scripts:
https://wiki.archlinux.org/index.php/NetworkManager
https://developer.gnome.org/NetworkManager/unstable/NetworkManager.html

Sunday, April 23, 2017

Running Asterisk with different web user

Freepbx 12 install configure "asterisk" user to run apache server... as explained here:
https://community.freepbx.org/t/running-asterisk-with-different-web-user/26812/1

But, as the same post explain, its better to use www-data user to run apache server...
The diagnostic is that everytime  "amportal chown" or "amportal start" is executed, the ownership of files are changed to "asterisk"...

The config files are needed to modify before running freepbx install
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-12.0-latest.tgz
tar xvfz freepbx-12.0-latest.tgz
freepbx/amp_conf/bin/freepbx_engine:AMPASTERISKUSER=www-data
freepbx/install_amp:$runas_uid = "www-data";
freepbx/libfreepbx.install.php: $set['value'] = 'www-data';
freepbx/libfreepbx.install.php: $set['value'] = 'www-data';
cd freepbx
./install_amp --installdb

Wednesday, January 28, 2015

Android: How to Delete synced Contacts

If you wish to delete all contacts from your Android device, without deleting from gmail...

1. Disable syncing by going to Settings > Accounts & sync. Select your Google account and uncheck Contacts. If you sync contacts with other apps such as Facebook or Twitter, be sure to disable syncing for those apps as well.

2. Go to Settings > Applications > Manage applications > All > Contacts Storage and select Clear data.
Note: This will also clear other data like your recent calls and Favorites

Thanks to  Mitch Bartlett for his post of Android: How to Delete All Contacts

Tuesday, December 23, 2014

Dongle gsm

Asterisk huawei 3g dongle
https://code.google.com/p/asterisk-chan-dongle/

All the instrucctions specifically for asterisk 11 are here:
http://zaliasrobotas.blogspot.mx/2013/10/chandongle-do-not-compile-with-asterisk.html