ajout changement statut devis
This commit is contained in:
@@ -18,8 +18,9 @@ pyramid.includes =
|
||||
pyramid_mailer
|
||||
pyramid_tm
|
||||
|
||||
|
||||
|
||||
sqlalchemy.url = mysql://phuoc:phuoc!@localhost/bddevfac?charset=utf8
|
||||
#sqlalchemy.url = mysql://phuoc:phuoc!@192.168.1.17/bddevfac?charset=utf8
|
||||
# sqlalchemy.url = mysql://phuoc:phuoc!@192.168.0.31/bddevfac?charset=utf8
|
||||
|
||||
mondumas.admin_email = cao.thien-phuoc@orange.fr
|
||||
|
||||
@@ -1,228 +1,236 @@
|
||||
# -*- coding: utf8 -*-
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import (
|
||||
scoped_session,
|
||||
sessionmaker,
|
||||
)
|
||||
from zope.sqlalchemy import (
|
||||
ZopeTransactionExtension,
|
||||
mark_changed
|
||||
)
|
||||
|
||||
from datetime import *
|
||||
import transaction
|
||||
import os
|
||||
|
||||
from ..views.default import (
|
||||
to_int,
|
||||
)
|
||||
|
||||
|
||||
def execute_query(request, query, params):
|
||||
"""Execute query and mark session as changed"""
|
||||
request.dbsession.execute(query, params)
|
||||
mark_changed(request.dbsession)
|
||||
transaction.commit()
|
||||
|
||||
def get_devis_byName(request, societe, name):
|
||||
numero = to_int(name)
|
||||
|
||||
if numero > 0:
|
||||
query = """SELECT date,'DE' AS TYPE, LPAD(no_id,6,'0') AS numero, nomcli, CONCAT(c_nom,'; ',c_adr,'; ',c_ville) AS chantier, COALESCE(totalht,0) AS montant, status, nosin, nopol, nochantier, web
|
||||
FROM devis WHERE societe=:societe AND no_id >=:name AND web = 'W' LIMIT 300;;""" % (societe, name)
|
||||
elif len(name) == 0:
|
||||
query = """SELECT date,'DE' AS TYPE, LPAD(no_id,6,'0') AS numero, nomcli, CONCAT(c_nom,'; ',c_adr,'; ',c_ville) AS chantier, COALESCE(totalht,0) AS montant, status, nosin, nopol, nochantier, web
|
||||
FROM devis WHERE societe=:societe AND web = 'W' ORDER BY no_id DESC LIMIT 300;"""
|
||||
else:
|
||||
query = """(SELECT date,'DE' AS TYPE, LPAD(no_id,6,'0') AS numero, nomcli, CONCAT(c_nom,'; ',c_adr,'; ',c_ville) AS chantier, COALESCE(totalht,0) AS montant, status, nosin, nopol , nochantier, web
|
||||
FROM devis WHERE societe=:societe AND c_nom LIKE ':name%' AND web = 'W' LIMIT 500)"""
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'name': name}).fetchall()
|
||||
return results
|
||||
|
||||
def get_devfac_by_no(request,nodossier):
|
||||
# lire devis, facture ou proforma
|
||||
|
||||
societe = nodossier[0:2]
|
||||
type_doc = nodossier[3:5]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
if type_doc == 'DE':
|
||||
query = """
|
||||
SELECT d.*, c.*, a.NOM as nom_cabinet, e.NOM as nom_expert FROM devis d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
elif type_doc == 'FA':
|
||||
query = """
|
||||
SELECT d.*, c.*, a.NOM as nom_cabinet, e.NOM as nom_expert FROM facture d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
else:
|
||||
query = """
|
||||
SELECT d.*, c.*, a.NOM as nom_cabinet, e.NOM as nom_expert FROM proforma d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).first()
|
||||
return results
|
||||
|
||||
def get_devis_lig_by_no(request,nodossier):
|
||||
|
||||
societe = nodossier[0:2]
|
||||
type_doc = nodossier[3:5]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
if type_doc == 'DE':
|
||||
query = "SELECT * FROM devis_lig WHERE societe = :societe and no_id=:no_id;"
|
||||
elif type_doc == 'FA':
|
||||
query = "SELECT * FROM facture_lig WHERE societe = :societe and no_id=:no_id;"
|
||||
else:
|
||||
query = "SELECT * FROM proforma_lig WHERE societe = :societe and no_id=:no_id;"
|
||||
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).fetchall()
|
||||
return results
|
||||
|
||||
def get_devis_lignes_by_no(request, nodossier, nolig):
|
||||
societe = nodossier[0:2]
|
||||
type_doc = nodossier[3:5]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
if nolig == '0':
|
||||
query = "SELECT * FROM devis_lignes WHERE societe = :societe and no_id=:no_id;"
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).fetchall()
|
||||
else:
|
||||
query = "SELECT * FROM devis_lignes WHERE societe = :societe and no_id=:no_id and nolig=:nolig;"
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id, 'nolig': nolig}).first()
|
||||
return results
|
||||
|
||||
|
||||
def insert_devis_from_dossier(request, nodossier, logged_in):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[3:]
|
||||
|
||||
query = "CALL spINS_DEVIS_FROM_DOSSIER(:societe, 'DDW', :no_id, :logged_in);"
|
||||
results = request.dbsession.execute(query,{'societe': societe, 'no_id': no_id, 'logged_in': logged_in}).first()
|
||||
return results
|
||||
|
||||
def get_devis_by_no(request,nodossier):
|
||||
# lire devis, facture ou proforma
|
||||
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
query = """
|
||||
SELECT d.*, c.*, a.NOM as nom_cabinet, e.NOM as nom_expert FROM devis d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).first()
|
||||
return results
|
||||
|
||||
def get_facture_by_no(request,nodossier):
|
||||
# lire facture
|
||||
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
query = """
|
||||
SELECT d.*, c.*, a.NOM as nom_cabinet, e.NOM as nom_expert FROM facture d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).first()
|
||||
return results
|
||||
|
||||
def get_proforma_by_no(request,nodossier):
|
||||
# lire facture
|
||||
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
query = """
|
||||
SELECT d.*, c.*, a.NOM as nom_cabinet, e.NOM as nom_expert FROM proforma d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).first()
|
||||
return results
|
||||
|
||||
def update_devis_ligne(request, nodossier, nolig, new_values):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
# formater les champs
|
||||
s = ''
|
||||
for param in new_values.keys():
|
||||
if s:
|
||||
s += ",%s=:%s" % (param, param)
|
||||
else:
|
||||
s = "%s=:%s" % (param, param)
|
||||
|
||||
if nolig == '0':
|
||||
query = "INSERT INTO devis_lignes SET %s" % s
|
||||
else:
|
||||
new_values['societe'] = societe
|
||||
new_values['no_id'] = no_id
|
||||
new_values['nolig'] = nolig
|
||||
query = "UPDATE devis_lignes SET %s WHERE societe = :societe and no_id=:no_id and nolig = :nolig;" % s
|
||||
# import pdb;pdb.set_trace()
|
||||
execute_query(request, query, new_values)
|
||||
|
||||
def sum_devis_totaux(request, nodossier):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
query = """UPDATE devis SET totalht = (SELECT SUM(mtht) FROM devis_lignes WHERE societe=:societe AND no_id=:no_id),
|
||||
totaltva = ROUND(totalht * tauxtva / 100,2),
|
||||
totalttc = totalht + totaltva
|
||||
WHERE societe=:societe AND no_id=:no_id;"""
|
||||
execute_query(request, query, {'societe': societe, 'no_id': no_id})
|
||||
|
||||
def delete_devis_ligne(request, nodossier, nolig):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
query = "DELETE FROM devis_lignes WHERE societe = :societe and no_id=:no_id and nolig=%s;"
|
||||
execute_query(request, query, {'societe': societe, 'no_id': no_id})
|
||||
|
||||
def move_devis_ligne(request, nodossier, nolig, move):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
# get max no ligne du devis
|
||||
query = "SELECT count(*) AS max_no FROM devis_lignes WHERE societe = :societe and no_id=:no_id;"
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).first()
|
||||
max_no = results.max_no + 1
|
||||
|
||||
step = 0
|
||||
if move == 'up':
|
||||
# déplacement vers le haut
|
||||
if nolig > 1:
|
||||
step = -1
|
||||
else:
|
||||
# déplacement vers le haut
|
||||
if nolig < max_no:
|
||||
step = +1
|
||||
|
||||
if step != 0:
|
||||
# déplacer le suivant ou précédent vers la fin
|
||||
query = """UPDATE devis_lignes SET nolig = :max_no WHERE societe = :societe and no_id=:no_id and nolig = :nolig + :step;"""
|
||||
execute_query(request, query, {'societe': societe, 'no_id': no_id, 'nolig': nolig, 'max_no': max_no, 'step': step})
|
||||
# permuter avec le suivant ou précédent
|
||||
query = """UPDATE devis_lignes SET nolig = nolig + :step WHERE societe = :societe and no_id=:no_id and nolig = :nolig;"""
|
||||
execute_query(request, query, {'societe': societe, 'no_id': no_id, 'nolig': nolig, 'step': step})
|
||||
# remettre le précédent ou suivant à la place de la ligne déplacée
|
||||
query = """UPDATE devis_lignes SET nolig = :nolig WHERE societe = :societe and no_id=:no_id and nolig = :max_no;"""
|
||||
execute_query(request, query, {'societe': societe, 'no_id': no_id, 'nolig': nolig, 'max_no': max_no})
|
||||
|
||||
# -*- coding: utf8 -*-
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import (
|
||||
scoped_session,
|
||||
sessionmaker,
|
||||
)
|
||||
from zope.sqlalchemy import (
|
||||
ZopeTransactionExtension,
|
||||
mark_changed
|
||||
)
|
||||
|
||||
from datetime import *
|
||||
import transaction
|
||||
import os
|
||||
|
||||
from ..views.default import (
|
||||
to_int,
|
||||
)
|
||||
|
||||
|
||||
def execute_query(request, query, params):
|
||||
"""Execute query and mark session as changed"""
|
||||
request.dbsession.execute(query, params)
|
||||
mark_changed(request.dbsession)
|
||||
transaction.commit()
|
||||
|
||||
def get_devis_byName(request, societe, name):
|
||||
numero = to_int(name)
|
||||
|
||||
if numero > 0:
|
||||
query = """SELECT date,'DE' AS TYPE, LPAD(no_id,6,'0') AS numero, nomcli, CONCAT(c_nom,'; ',c_adr,'; ',c_ville) AS chantier, COALESCE(totalht,0) AS montant, status, nosin, nopol, nochantier, web
|
||||
FROM devis WHERE societe=:societe AND no_id >=:name AND web = 'W' LIMIT 300;;""" % (societe, name)
|
||||
elif len(name) == 0:
|
||||
query = """SELECT date,'DE' AS TYPE, LPAD(no_id,6,'0') AS numero, nomcli, CONCAT(c_nom,'; ',c_adr,'; ',c_ville) AS chantier, COALESCE(totalht,0) AS montant, status, nosin, nopol, nochantier, web
|
||||
FROM devis WHERE societe=:societe AND web = 'W' ORDER BY no_id DESC LIMIT 300;"""
|
||||
else:
|
||||
query = """(SELECT date,'DE' AS TYPE, LPAD(no_id,6,'0') AS numero, nomcli, CONCAT(c_nom,'; ',c_adr,'; ',c_ville) AS chantier, COALESCE(totalht,0) AS montant, status, nosin, nopol , nochantier, web
|
||||
FROM devis WHERE societe=:societe AND c_nom LIKE ':name%' AND web = 'W' LIMIT 500)"""
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'name': name}).fetchall()
|
||||
return results
|
||||
|
||||
def get_devfac_by_no(request,nodossier):
|
||||
# lire devis, facture ou proforma
|
||||
|
||||
societe = nodossier[0:2]
|
||||
type_doc = nodossier[3:5]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
if type_doc == 'DE':
|
||||
query = """
|
||||
SELECT d.*, c.*, a.NOM as nom_cabinet, e.NOM as nom_expert FROM devis d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
elif type_doc == 'FA':
|
||||
query = """
|
||||
SELECT d.*, c.*, a.NOM as nom_cabinet, e.NOM as nom_expert FROM facture d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
else:
|
||||
query = """
|
||||
SELECT d.*, c.*, a.NOM as nom_cabinet, e.NOM as nom_expert FROM proforma d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).first()
|
||||
return results
|
||||
|
||||
def get_devis_lig_by_no(request,nodossier):
|
||||
|
||||
societe = nodossier[0:2]
|
||||
type_doc = nodossier[3:5]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
if type_doc == 'DE':
|
||||
query = "SELECT * FROM devis_lig WHERE societe = :societe and no_id=:no_id;"
|
||||
elif type_doc == 'FA':
|
||||
query = "SELECT * FROM facture_lig WHERE societe = :societe and no_id=:no_id;"
|
||||
else:
|
||||
query = "SELECT * FROM proforma_lig WHERE societe = :societe and no_id=:no_id;"
|
||||
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).fetchall()
|
||||
return results
|
||||
|
||||
def get_devis_lignes_by_no(request, nodossier, nolig):
|
||||
societe = nodossier[0:2]
|
||||
type_doc = nodossier[3:5]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
if nolig == '0':
|
||||
query = "SELECT * FROM devis_lignes WHERE societe = :societe and no_id=:no_id;"
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).fetchall()
|
||||
else:
|
||||
query = "SELECT * FROM devis_lignes WHERE societe = :societe and no_id=:no_id and nolig=:nolig;"
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id, 'nolig': nolig}).first()
|
||||
return results
|
||||
|
||||
|
||||
def insert_devis_from_dossier(request, nodossier, logged_in):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[3:]
|
||||
|
||||
query = "CALL spINS_DEVIS_FROM_DOSSIER(:societe, 'DDW', :no_id, :logged_in);"
|
||||
results = request.dbsession.execute(query,{'societe': societe, 'no_id': no_id, 'logged_in': logged_in}).first()
|
||||
return results
|
||||
|
||||
def get_devis_by_no(request,nodossier):
|
||||
# lire devis, facture ou proforma
|
||||
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
query = """
|
||||
SELECT d.*, c.*, s.libelle, a.NOM as nom_cabinet, e.NOM as nom_expert FROM devis d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
INNER JOIN p_statuts s ON d.STATUS = s.code
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).first()
|
||||
return results
|
||||
|
||||
def get_facture_by_no(request,nodossier):
|
||||
# lire facture
|
||||
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
query = """
|
||||
SELECT d.*, c.*, s.libelle, a.NOM as nom_cabinet, e.NOM as nom_expert FROM facture d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
INNER JOIN p_statuts s ON d.STATUS = s.code
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).first()
|
||||
return results
|
||||
|
||||
def get_proforma_by_no(request,nodossier):
|
||||
# lire facture
|
||||
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
query = """
|
||||
SELECT d.*, c.*, a.NOM as nom_cabinet, e.NOM as nom_expert FROM proforma d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
WHERE d.societe = :societe and d.no_id=:no_id;"""
|
||||
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).first()
|
||||
return results
|
||||
|
||||
def update_devis_ligne(request, nodossier, nolig, new_values):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
# formater les champs
|
||||
s = ''
|
||||
for param in new_values.keys():
|
||||
if s:
|
||||
s += ",%s=:%s" % (param, param)
|
||||
else:
|
||||
s = "%s=:%s" % (param, param)
|
||||
|
||||
if nolig == '0':
|
||||
query = "INSERT INTO devis_lignes SET %s" % s
|
||||
else:
|
||||
new_values['societe'] = societe
|
||||
new_values['no_id'] = no_id
|
||||
new_values['nolig'] = nolig
|
||||
query = "UPDATE devis_lignes SET %s WHERE societe = :societe and no_id=:no_id and nolig = :nolig;" % s
|
||||
# import pdb;pdb.set_trace()
|
||||
execute_query(request, query, new_values)
|
||||
|
||||
def sum_devis_totaux(request, nodossier):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
query = """UPDATE devis SET totalht = (SELECT SUM(mtht) FROM devis_lignes WHERE societe=:societe AND no_id=:no_id),
|
||||
totaltva = ROUND(totalht * tauxtva / 100,2),
|
||||
totalttc = totalht + totaltva
|
||||
WHERE societe=:societe AND no_id=:no_id;"""
|
||||
execute_query(request, query, {'societe': societe, 'no_id': no_id})
|
||||
|
||||
def delete_devis_ligne(request, nodossier, nolig):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
query = "DELETE FROM devis_lignes WHERE societe = :societe and no_id=:no_id and nolig=%s;"
|
||||
execute_query(request, query, {'societe': societe, 'no_id': no_id})
|
||||
|
||||
def move_devis_ligne(request, nodossier, nolig, move):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[5:]
|
||||
|
||||
# get max no ligne du devis
|
||||
query = "SELECT count(*) AS max_no FROM devis_lignes WHERE societe = :societe and no_id=:no_id;"
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'no_id': no_id}).first()
|
||||
max_no = results.max_no + 1
|
||||
|
||||
step = 0
|
||||
if move == 'up':
|
||||
# déplacement vers le haut
|
||||
if nolig > 1:
|
||||
step = -1
|
||||
else:
|
||||
# déplacement vers le haut
|
||||
if nolig < max_no:
|
||||
step = +1
|
||||
|
||||
if step != 0:
|
||||
# déplacer le suivant ou précédent vers la fin
|
||||
query = """UPDATE devis_lignes SET nolig = :max_no WHERE societe = :societe and no_id=:no_id and nolig = :nolig + :step;"""
|
||||
execute_query(request, query, {'societe': societe, 'no_id': no_id, 'nolig': nolig, 'max_no': max_no, 'step': step})
|
||||
# permuter avec le suivant ou précédent
|
||||
query = """UPDATE devis_lignes SET nolig = nolig + :step WHERE societe = :societe and no_id=:no_id and nolig = :nolig;"""
|
||||
execute_query(request, query, {'societe': societe, 'no_id': no_id, 'nolig': nolig, 'step': step})
|
||||
# remettre le précédent ou suivant à la place de la ligne déplacée
|
||||
query = """UPDATE devis_lignes SET nolig = :nolig WHERE societe = :societe and no_id=:no_id and nolig = :max_no;"""
|
||||
execute_query(request, query, {'societe': societe, 'no_id': no_id, 'nolig': nolig, 'max_no': max_no})
|
||||
|
||||
def update_devis_cloture(request, nodevis, status, logged_in):
|
||||
societe = nodevis[0:2]
|
||||
nochantier = int(nodevis[5:])
|
||||
# met le montant regle à 1 centime pour terminé le dossier
|
||||
query = "UPDATE devis SET STATUS = :status, USERMAJ = :logged_in WHERE societe=:societe AND no_id=:nochantier;"
|
||||
execute_query(request, query, {'societe': societe, 'nochantier': nochantier, 'status': status, 'logged_in': logged_in})
|
||||
@@ -30,13 +30,14 @@ def get_dossier_by_no(request,nodossier):
|
||||
societe = nodossier[0:2]
|
||||
no_id = nodossier[3:]
|
||||
query = """
|
||||
SELECT d.*, a.NOM as nom_cabinet, e.NOM as nom_expert,
|
||||
SELECT d.*, s.libelle, a.NOM as nom_cabinet, e.NOM as nom_expert,
|
||||
c.QUALITE AS cli_QUALITE, c.NOM AS cli_NOM, c.ADRESSE AS cli_ADRESSE, c.ADRESSE2 AS cli_ADRESSE2, c.CP AS cli_CP, c.VILLE AS cli_VILLE,
|
||||
c.TEL1 AS cli_TEL1, c.TEL2 AS cli_TEL2, c.TELP AS cli_TELP, c.FAX AS cli_FAX, c.NOMRESP AS cli_NOMRESP
|
||||
FROM dem_devis d
|
||||
INNER JOIN clients c ON d.societe = c.societe and d.cd_cli = c.cd_cli
|
||||
INNER JOIN p_cabinet a ON d.cabinet = a.code
|
||||
INNER JOIN p_experts e ON d.cabinet = e.code_cab and d.expert = e.code_exp
|
||||
INNER JOIN p_statuts s ON d.STATUS = s.code
|
||||
where d.societe = '%s' and d.no_id=%s;""" % (societe, no_id);
|
||||
results = request.dbsession.execute(query).first()
|
||||
return results
|
||||
@@ -329,6 +330,9 @@ def get_status_by_id(request, code):
|
||||
if code == '':
|
||||
query = """SELECT * FROM p_statuts;"""
|
||||
results = request.dbsession.execute(query,).fetchall()
|
||||
elif code == 'DE':
|
||||
query = """SELECT * FROM p_statuts WHERE code >= 3;"""
|
||||
results = request.dbsession.execute(query,).fetchall()
|
||||
else:
|
||||
query = """SELECT * FROM p_statuts WHERE code = :code;"""
|
||||
results = request.dbsession.execute(query, {'code': code}).first()
|
||||
|
||||
@@ -1,99 +1,157 @@
|
||||
<metal:block use-macro="main_template">
|
||||
<div metal:fill-slot="content">
|
||||
<br />
|
||||
<!-- ENTETE -->
|
||||
<div class="row">
|
||||
<!-- CHANTIER -->
|
||||
<div class="col-md-6">
|
||||
<table class="table table-condensed">
|
||||
<tr>
|
||||
<td><h4>CHANTIER</h4><h4 class="text-primary">${entete.societe}-${entete.nochantier}</h4>
|
||||
</td>
|
||||
<td>
|
||||
<h4>${entete.C_QUALITE} ${entete.C_NOM}</h4>
|
||||
${entete.C_ADR}<br />
|
||||
<span tal:condition="entete.C_ADR2">${entete.C_ADR2}<br /></span>
|
||||
${entete.C_CP} ${entete.C_VILLE}<br />
|
||||
${entete.C_EMAIL}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Etage - Code<br />
|
||||
Tél. domicile - prof.<br />
|
||||
Tél. mobile - fax
|
||||
</td>
|
||||
<td>
|
||||
${entete.C_ETAGE} - ${entete.C_CODE}<br />
|
||||
${entete.C_TEL1} - ${entete.C_TEL2}<br />
|
||||
${entete.C_TELP} - ${entete.C_FAX}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Mon compte -->
|
||||
<div class="col-md-6 ${bg_color}">
|
||||
<table class="table table-condensed ">
|
||||
<tr>
|
||||
<td><h4>CLIENT</h4></td>
|
||||
<td>
|
||||
<h4>${entete.QUALITE} ${entete.NOM}</h4>
|
||||
${entete.ADRESSE}<br />
|
||||
<span tal:condition="entete.ADRESSE2">${entete.ADRESSE2}<br /></span>
|
||||
${entete.CP} ${entete.VILLE}<br />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Responsable<br />
|
||||
Tél. 1 - 2<br />
|
||||
Tél. mobile - fax
|
||||
</td>
|
||||
<td>
|
||||
${entete.NOMRESP}<br />
|
||||
${entete.TEL1} - ${entete.TEL2}<br />
|
||||
${entete.TELP} - ${entete.FAX}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<h4>Statut : ${entete.STATUS}</h4>
|
||||
</div> <!-- row -->
|
||||
<!-- ENTETE entete -->
|
||||
<table class="table table-bordered table-condensed">
|
||||
<tr class="well">
|
||||
<th class="text-right">Total HT</th>
|
||||
<th class="text-right">Total TVA</th>
|
||||
<th class="text-right">Total TTC</th>
|
||||
<th class="text-right">TVA</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-right">${layout.to_euro(entete.TOTALHT)}</td>
|
||||
<td class="text-right">${layout.to_euro(entete.TOTALTVA)}</td>
|
||||
<td class="text-right">${layout.to_euro(entete.TOTALTTC)}</td>
|
||||
<td class="text-right">${entete.TAUXTVA} %</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table class="table table-bordered table-condensed">
|
||||
<tr class="well">
|
||||
<th>Réf</th>
|
||||
<th>Désignation</th>
|
||||
<th class="text-right">Qté</th>
|
||||
<th class="text-right">PU HT</th>
|
||||
<th class="text-right">Montant HT</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<tr tal:repeat="detail details">
|
||||
<td>${detail.REF}</td>
|
||||
<td>${detail.LIB}</td>
|
||||
<td class="text-right">${layout.to_euro(detail.QTE)}</td>
|
||||
<td class="text-right">${layout.to_euroz(detail.PRIXHT)}</td>
|
||||
<td class="text-right">${layout.to_euroz(detail.MTHT)}</td>
|
||||
<td class="text-center">${detail.USERMAJ}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</metal:block>
|
||||
<metal:block use-macro="main_template">
|
||||
<div metal:fill-slot="content">
|
||||
<br />
|
||||
<!-- ENTETE -->
|
||||
<div class="row">
|
||||
<!-- CHANTIER -->
|
||||
<div class="col-md-6">
|
||||
<table class="table table-condensed">
|
||||
<tr>
|
||||
<td><h4>CHANTIER</h4><h4 class="text-primary">${entete.societe}-${entete.nochantier}</h4>
|
||||
</td>
|
||||
<td>
|
||||
<h4>${entete.C_QUALITE} ${entete.C_NOM}</h4>
|
||||
${entete.C_ADR}<br />
|
||||
<span tal:condition="entete.C_ADR2">${entete.C_ADR2}<br /></span>
|
||||
${entete.C_CP} ${entete.C_VILLE}<br />
|
||||
${entete.C_EMAIL}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Etage - Code<br />
|
||||
Tél. domicile - prof.<br />
|
||||
Tél. mobile - fax
|
||||
</td>
|
||||
<td>
|
||||
${entete.C_ETAGE} - ${entete.C_CODE}<br />
|
||||
${entete.C_TEL1} - ${entete.C_TEL2}<br />
|
||||
${entete.C_TELP} - ${entete.C_FAX}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Mon compte -->
|
||||
<div class="col-md-6 ${bg_color}">
|
||||
<table class="table table-condensed ">
|
||||
<tr>
|
||||
<td><h4>CLIENT</h4></td>
|
||||
<td>
|
||||
<h4>${entete.QUALITE} ${entete.NOM}</h4>
|
||||
${entete.ADRESSE}<br />
|
||||
<span tal:condition="entete.ADRESSE2">${entete.ADRESSE2}<br /></span>
|
||||
${entete.CP} ${entete.VILLE}<br />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Responsable<br />
|
||||
Tél. 1 - 2<br />
|
||||
Tél. mobile - fax
|
||||
</td>
|
||||
<td>
|
||||
${entete.NOMRESP}<br />
|
||||
${entete.TEL1} - ${entete.TEL2}<br />
|
||||
${entete.TELP} - ${entete.FAX}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h4>Statut : ${entete.libelle}</h4>
|
||||
<div tal:condition="type_doc=='DE'">
|
||||
<p>Dernière modif. le <b>${entete.DATEMAJ.strftime('%d/%m/%Y à %H:%M')}</b> par <b>${entete.USERMAJ}</b></p>
|
||||
<p>
|
||||
<a class="btn btn-warning" role="button" href="#"
|
||||
data-toggle="modal" data-target="#confirmCloture"><span class="glyphicon glyphicon-check"></span> Modif. statut</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div> <!-- row -->
|
||||
<!-- ENTETE entete -->
|
||||
<table class="table table-bordered table-condensed">
|
||||
<tr class="well">
|
||||
<th class="text-right">Total HT</th>
|
||||
<th class="text-right">Total TVA</th>
|
||||
<th class="text-right">Total TTC</th>
|
||||
<th class="text-right">TVA</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-right">${layout.to_euro(entete.TOTALHT)}</td>
|
||||
<td class="text-right">${layout.to_euro(entete.TOTALTVA)}</td>
|
||||
<td class="text-right">${layout.to_euro(entete.TOTALTTC)}</td>
|
||||
<td class="text-right">${entete.TAUXTVA} %</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table class="table table-bordered table-condensed">
|
||||
<tr class="well">
|
||||
<th>Réf</th>
|
||||
<th>Désignation</th>
|
||||
<th class="text-right">Qté</th>
|
||||
<th class="text-right">PU HT</th>
|
||||
<th class="text-right">Montant HT</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<tr tal:repeat="detail details">
|
||||
<td>${detail.REF}</td>
|
||||
<td>${detail.LIB}</td>
|
||||
<td class="text-right">${layout.to_euro(detail.QTE)}</td>
|
||||
<td class="text-right">${layout.to_euroz(detail.PRIXHT)}</td>
|
||||
<td class="text-right">${layout.to_euroz(detail.MTHT)}</td>
|
||||
<td class="text-center">${detail.USERMAJ}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- Modal : Confirmation CLOTURE -->
|
||||
<div class="modal fade" id="confirmCloture" role="dialog" aria-labelledby="confirmClotureLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">Clôturer le devis</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<!-- The form is placed inside the body of modal -->
|
||||
<form id="add_justif-form" class="form-horizontal" action="${url}" method="post">
|
||||
<div class="form-group">
|
||||
<p class="text-center"><b>Voulez-vous changer le status du devis ?</b></p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="control-label col-xs-4" for="status">Sélectionner le statut :</label>
|
||||
<div class="col-xs-8">
|
||||
<select class="form-control" id="status" name="status">
|
||||
<div tal:repeat="item status">
|
||||
<option tal:attributes="selected entete.STATUS==item.code and 'selected' or None">${item.code} | ${item.libelle}</option>
|
||||
</div>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="row">
|
||||
<label class="control-label col-xs-4" for="motif">Motif :</label>
|
||||
<div class="col-xs-8">
|
||||
<input class="form-control" type="text" id="motif" name="motif" value=""
|
||||
placeholder="65 caractères maximum"
|
||||
data-fv-notempty="true"
|
||||
data-fv-notempty-message="Veuillez remplir un motif"
|
||||
data-fv-stringlength="true"
|
||||
data-fv-stringlength-max="65"
|
||||
data-fv-stringlength-message="65 caractères maximum"/>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
|
||||
<button type="submit" class="btn btn-warning" name="form.close">Clôturer</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</metal:block>
|
||||
|
||||
@@ -97,11 +97,11 @@
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h4>Statut : ${dossier.STATUS}</h4>
|
||||
<h4>Statut : ${dossier.libelle}</h4>
|
||||
<p>Dernière modif. le <b>${dossier.DATEMAJ.strftime('%d/%m/%Y à %H:%M')}</b> par <b>${dossier.USERMAJ}</b></p>
|
||||
<p>
|
||||
<a class="btn btn-warning" role="button" href="#"
|
||||
data-toggle="modal" data-target="#confirmCloture"><span class="glyphicon glyphicon-check"></span> Clôturer dossier</a>
|
||||
data-toggle="modal" data-target="#confirmCloture"><span class="glyphicon glyphicon-check"></span> Modif. statut dossier</a>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -70,6 +70,7 @@ def devis_create(request):
|
||||
def devis_view(request):
|
||||
nodevis = request.matchdict['nodevis']
|
||||
societe = nodevis[0:2]
|
||||
logged_in = request.authenticated_userid.upper()
|
||||
url = request.route_url("devis_view", nodevis=nodevis)
|
||||
|
||||
type_doc = nodevis[3:5]
|
||||
@@ -91,12 +92,34 @@ def devis_view(request):
|
||||
# select background color according to society
|
||||
bg_color = "bg-%s" % societe
|
||||
|
||||
status = get_status_by_id(request, 'DE')
|
||||
|
||||
if 'form.close' in request.params:
|
||||
status = request.params["status"]
|
||||
motif = request.params["motif"]
|
||||
|
||||
code, libelle = status.split(' | ')
|
||||
code = int(code)
|
||||
|
||||
nodossier = str(entete.societe) + '-' + str(entete.nochantier)
|
||||
|
||||
if type_doc == 'DE':
|
||||
if code >= 10:
|
||||
comment = 'Le devis est ' + libelle + ' : ' + motif
|
||||
insert_suivi(request, nodossier, comment)
|
||||
update_devis_cloture(request, nodevis, code, logged_in)
|
||||
request.session.flash(u"Le statut du devis a été changé avec succès.", 'success')
|
||||
return HTTPFound(url)
|
||||
|
||||
return {
|
||||
'page_title': page_title,
|
||||
'url': url,
|
||||
'nodevis': nodevis,
|
||||
'entete': entete,
|
||||
'details': details,
|
||||
'bg_color': bg_color,
|
||||
'status': status,
|
||||
'type_doc': type_doc,
|
||||
}
|
||||
|
||||
@view_config(route_name='devis_web', renderer='../templates/devis/devis_web.pt', permission='view')
|
||||
|
||||
Reference in New Issue
Block a user