Prima versione completa pareggio partite

git-svn-id: svn://10.65.10.50/branches/R_10_00@22631 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2012-04-10 07:48:22 +00:00
parent 9131478f5f
commit 366aee3fd0
4 changed files with 109 additions and 71 deletions

View File

@ -122,6 +122,7 @@ TFieldtypes TPareggio_tree::get_var(const TString& name, TVariant& var) const
bool TPareggio_tree::init(const TBill& bill, const TString& valuta, bool nc, int stato) bool TPareggio_tree::init(const TBill& bill, const TString& valuta, bool nc, int stato)
{ {
_games.destroy();
goto_root(); goto_root();
kill_node(); kill_node();
@ -276,6 +277,16 @@ bool TScad_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
case F_TUTTE: case F_TUTTE:
if (e == se_query_add || e == se_query_del) if (e == se_query_add || e == se_query_del)
return false; return false;
if (e = fe_close)
{
TSheet_field& s = (TSheet_field&)o;
real tot, imp = get_real(F_IMPORTO);
FOR_EACH_SHEET_ROW(s, r, row)
tot += real(row->get(0));
if (tot > imp)
return error_box(FR("Il totale degli importi (%s) supera la cifra disponibile (%s)"),
tot.stringa(), imp.stringa());
}
break; break;
default: break; default: break;
} }
@ -294,23 +305,25 @@ class TPareggio_mask : public TAutomask
protected: protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
const TString& causale_nc_reg(const TString& reg) const; const TString& reg2caus(const TString& reg) const;
bool converti(const TRectype& rec); bool ft2nc(const TRectype& rec);
bool abbuona_rata(const real& imp, const TRectype& nota, TRiga_scadenze& scad); bool abbuona_rata(const real& imp, const TRectype& nota, TRiga_scadenze& scad);
bool elabora(const TRectype& nota, const TPointer_array& fatture); bool elabora(const TRectype& nota, TPointer_array& scadenze);
void refill();
public: public:
TPareggio_mask(); TPareggio_mask();
}; };
// Cerca una causale di nota di credito sul registro reg // Cerca una causale di nota di credito compatibile col registro reg
const TString& TPareggio_mask::causale_nc_reg(const TString& reg) const const TString& TPareggio_mask::reg2caus(const TString& reg) const
{ {
if (reg.full()) if (reg.full())
{ {
const TString& codcaus = get(get(F_TIPO) == "C" ? F_CODCAUS_C : F_CODCAUS_F); const char tipocf = get(F_TIPO)[0];
const TString& cr = cache().get(LF_CAUSALI, codcaus, CAU_REG); const TString& codcaus = get(tipocf == 'F' ? F_CODCAUS_F : F_CODCAUS_C);
if (cr == reg) const TString& cod = cache().get(LF_CAUSALI, codcaus, CAU_REG);
if (cod == reg)
return codcaus; // Siamo fortunati: va bene la causale standard return codcaus; // Siamo fortunati: va bene la causale standard
TISAM_recordset recset("USE CAUS SELECT (REG=#CODREG)&&(TIPOMOV=2)"); TISAM_recordset recset("USE CAUS SELECT (REG=#CODREG)&&(TIPOMOV=2)");
@ -321,14 +334,15 @@ const TString& TPareggio_mask::causale_nc_reg(const TString& reg) const
return EMPTY_STRING; return EMPTY_STRING;
} }
bool TPareggio_mask::converti(const TRectype& rec) // Trasforma una fattura negativa in nota di credito
bool TPareggio_mask::ft2nc(const TRectype& rec)
{ {
CHECK(rec.num() == LF_PARTITE, "Solo partite, grazie!"); CHECK(rec.num() == LF_PARTITE, "Solo partite, grazie!");
const long numreg = rec.get_long(PART_NREG); const long numreg = rec.get_long(PART_NREG);
const TString4 codreg = rec.get(PART_REG); const TString4 codreg = rec.get(PART_REG);
const TString4 codcau = causale_nc_reg(codreg); const TString4 codcau = reg2caus(codreg);
if (codcau.blank()) if (codcau.blank())
return error_box(FR("E' necessario creare una causale di note di credito sul registro %s"), (const char*)codreg); return error_box(FR("E' necessario creare una causale di nota di credito sul registro %s"), (const char*)codreg);
TString msg; TString msg;
msg << TR("Si desidera trasformare la fattura in nota di credito con causale ") msg << TR("Si desidera trasformare la fattura in nota di credito con causale ")
@ -379,11 +393,12 @@ bool TPareggio_mask::abbuona_rata(const real& imp, const TRectype& nota, TRiga_s
const TValuta valuta(scad.riga()); const TValuta valuta(scad.riga());
const char* imp_field = valuta.in_valuta() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO; const char* imp_field = valuta.in_valuta() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
TPartita& old_nc = _nc.partita(nota); TPartita& nc = _nc.partita(nota);
TPartita& ft = scad.partita(); TPartita& ft = scad.partita();
TRiga_partite& new_nc = ft.new_row(); TRiga_partite& new_nc = ft.new_row();
new_nc.put(PART_SEZ, scad.riga().get_char(PART_SEZ) == 'D' ? 'A' : 'D'); new_nc.put(PART_SEZ, scad.riga().get_char(PART_SEZ) == 'D' ? 'A' : 'D');
new_nc.put(PART_TIPOMOV, tm_nota_credito);
new_nc.put(PART_NREG, nota.get(PART_NREG)); new_nc.put(PART_NREG, nota.get(PART_NREG));
new_nc.put(PART_CODCAUS, nota.get(PART_CODCAUS)); new_nc.put(PART_CODCAUS, nota.get(PART_CODCAUS));
new_nc.put(PART_REG, nota.get(PART_REG)); new_nc.put(PART_REG, nota.get(PART_REG));
@ -393,30 +408,34 @@ bool TPareggio_mask::abbuona_rata(const real& imp, const TRectype& nota, TRiga_s
TRectype new_pag = scad.new_row(new_nc.get_int(PART_NRIGA)); TRectype new_pag = scad.new_row(new_nc.get_int(PART_NRIGA));
new_pag.put(imp_field, imp); new_pag.put(imp_field, imp);
ft.modifica_pagamento(new_pag, valuta, true); ft.modifica_pagamento(new_pag, valuta, true);
ft.write(true);
TRectype unass = old_nc.unassigned().row(nota.get_int(PART_NRIGA)); TRectype unass = nc.unassigned().row(nota.get_int(PART_NRIGA));
if (new_nc.get(PART_SEZ) == nota.get(PART_SEZ)) if (new_nc.get(PART_SEZ) == nota.get(PART_SEZ))
unass.add(imp_field, -imp); unass.add(imp_field, -imp);
else else
unass.add(imp_field, imp); unass.add(imp_field, imp);
old_nc.modifica_pagamento(unass, valuta, true); nc.modifica_pagamento(unass, valuta, true);
nc.write(true);
return true; return true;
} }
bool TPareggio_mask::elabora(const TRectype& nota, const TPointer_array& scadenze) bool TPareggio_mask::elabora(const TRectype& nota, TPointer_array& scadenze)
{ {
CHECK(nota.num() == LF_PARTITE, "Solo partite, grazie!"); CHECK(nota.num() == LF_PARTITE, "Solo partite, grazie!");
const tipo_movimento tm = (tipo_movimento)nota.get_int(PART_TIPOMOV); const tipo_movimento tm = (tipo_movimento)nota.get_int(PART_TIPOMOV);
if (tm == tm_fattura && !converti(nota)) if (tm == tm_fattura && !ft2nc(nota))
return false; return false;
TScad_mask ass; TScad_mask ass;
const TString& codval = get(F_CODVAL); const TString& codval = get(F_CODVAL);
ass.set(F_CODVAL, codval); ass.set(F_CODVAL, codval);
TSheet_field& sheet = ass.sfield(F_TUTTE);
real residuo_nc = abs(nota.get_real(is_true_value(codval) ? PART_IMPORTOVAL : PART_IMPORTO)); real residuo_nc = abs(nota.get_real(is_true_value(codval) ? PART_IMPORTOVAL : PART_IMPORTO));
ass.set(F_IMPORTO, residuo_nc);
TSheet_field& sheet = ass.sfield(F_TUTTE);
TString_array rate; TString_array rate;
FOR_EACH_ARRAY_ITEM(scadenze, i, s) FOR_EACH_ARRAY_ITEM(scadenze, i, s)
{ {
@ -428,9 +447,9 @@ bool TPareggio_mask::elabora(const TRectype& nota, const TPointer_array& scadenz
imp = residuo_scad; imp = residuo_scad;
row.add(imp.string()); row.add(imp.string());
residuo_nc -= imp; residuo_nc -= imp;
row.add(scad.get(SCAD_DATASCAD));
row.add(residuo_scad.string()); row.add(residuo_scad.string());
row.add(scad.importo(true).valore().string()); row.add(scad.importo(true).valore().string());
row.add(scad.get(SCAD_DATASCAD));
} }
if (ass.run() == K_ENTER) if (ass.run() == K_ENTER)
@ -449,6 +468,25 @@ bool TPareggio_mask::elabora(const TRectype& nota, const TPointer_array& scadenz
return true; return true;
} }
void TPareggio_mask::refill()
{
TWait_cursor hourglass;
const short id = efield(F_FORNITORE).active() ? F_FORNITORE :
(efield(F_SOTTOCONTO).active() ? F_SOTTOCONTO : F_CLIENTE);
TBill bill; bill.get(*this, F_GRUPPO, F_CONTO, id, F_TIPO);
const int tipo = get_int(F_TUTTE);
const TString& codval = get(F_CODVAL);
_nc.init(bill, codval, true, 1); // Solo aperte
_ft.init(bill, codval, false, tipo);
tfield(F_NC_TREE).set_tree(&_nc);
tfield(F_FT_TREE).set_tree(&_ft);
_numreg = 0;
disable(DLG_LINK);
disable(DLG_RECALC);
}
bool TPareggio_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) bool TPareggio_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{ {
switch (o.dlg()) switch (o.dlg())
@ -456,25 +494,13 @@ bool TPareggio_mask::on_field_event(TOperable_field& o, TField_event e, long jol
//case F_SOTTOCONTO: //case F_SOTTOCONTO:
case F_CLIENTE: case F_CLIENTE:
case F_FORNITORE: case F_FORNITORE:
if (e == fe_modify && !o.empty())
refill();
break;
case F_CODVAL: case F_CODVAL:
case F_TUTTE: case F_TUTTE:
if (e == fe_modify && !o.empty()) if (e == fe_modify)
{ refill();
TWait_cursor hourglass;
const short id = efield(F_FORNITORE).active() ? F_FORNITORE :
(efield(F_SOTTOCONTO).active() ? F_SOTTOCONTO : F_CLIENTE);
TBill bill; bill.get(*this, F_GRUPPO, F_CONTO, id, F_TIPO);
const int tipo = get_int(F_TUTTE);
const TString& codval = get(F_CODVAL);
_nc.init(bill, codval, true, 1); // Solo aperte
_ft.init(bill, codval, false, tipo);
tfield(F_NC_TREE).set_tree(&_nc);
tfield(F_FT_TREE).set_tree(&_ft);
_numreg = 0;
disable(DLG_LINK);
disable(DLG_RECALC);
}
break; break;
case F_CODCAUS_C: case F_CODCAUS_C:
case F_CODCAUS_F: case F_CODCAUS_F:
@ -514,7 +540,7 @@ bool TPareggio_mask::on_field_event(TOperable_field& o, TField_event e, long jol
TRectype mov(LF_MOV); TRectype mov(LF_MOV);
mov.put(MOV_NUMREG, _numreg); mov.put(MOV_NUMREG, _numreg);
if (mov.edit()) if (mov.edit())
send_key(K_SPACE, F_TUTTE, &o); refill();
} }
break; break;
case DLG_RECALC: case DLG_RECALC:
@ -523,38 +549,37 @@ bool TPareggio_mask::on_field_event(TOperable_field& o, TField_event e, long jol
TTree_field& nc = tfield(F_NC_TREE); TTree_field& nc = tfield(F_NC_TREE);
TPareggio_tree* nct = (TPareggio_tree*)nc.tree(); TPareggio_tree* nct = (TPareggio_tree*)nc.tree();
const TRectype* nota = nct->node2rec(EMPTY_STRING); const TRectype* nota = nct->node2rec(EMPTY_STRING);
if (nota != NULL && converti(*nota)) if (nota != NULL && ft2nc(*nota))
send_key(K_SPACE, F_TUTTE, &o); refill();
} }
break; break;
case DLG_ELABORA: case DLG_ELABORA:
if (e == fe_button) if (e == fe_button)
{ {
TTree_field& nc = tfield(F_NC_TREE); const TRectype* nota = _nc.node2rec(EMPTY_STRING);
TTree_field& ft = tfield(F_FT_TREE);
TPareggio_tree* nct = (TPareggio_tree*)nc.tree();
const TRectype* nota = nct->node2rec(EMPTY_STRING);
if (nota == NULL) if (nota == NULL)
return error_box(TR("Selezionare una nota di credito nel pannello di sinistra")); return error_box(TR("Selezionare una nota di credito nel pannello di sinistra"));
TPointer_array fatture; const TTree_field& ft = tfield(F_FT_TREE);
TPointer_array rate;
TString_array a; TString_array a;
if (ft.selection(a) > 0) if (ft.selection(a) > 0)
{ {
TPareggio_tree* ftt = (TPareggio_tree*)ft.tree();
FOR_EACH_ARRAY_ROW(a, r, riga) FOR_EACH_ARRAY_ROW(a, r, riga)
{ {
const TRectype* rec = ftt->node2rec(*riga); const TRectype* rec = _ft.node2rec(*riga);
if (rec) if (rec)
fatture.add((TRectype*)rec); rate.add((TRectype*)rec);
} }
} }
if (fatture.items() > 0) if (rate.items() > 0)
elabora(*nota, fatture); {
if (elabora(*nota, rate))
refill();
}
else else
return error_box(TR("Selezionare almeno una fattura nel pannello di destra")); return error_box(TR("Selezionare almeno una rata nel pannello di destra"));
} }
break; break;
default: break; default: break;
@ -564,14 +589,17 @@ bool TPareggio_mask::on_field_event(TOperable_field& o, TField_event e, long jol
TPareggio_mask::TPareggio_mask() : TAutomask("sc0300a"), _numreg(0L) TPareggio_mask::TPareggio_mask() : TAutomask("sc0300a"), _numreg(0L)
{ {
RCT rct_nc; field(F_NC_TREE).get_rect(rct_nc); TTree_field& nc = tfield(F_NC_TREE);
RCT rct_ft; field(F_FT_TREE).get_rect(rct_ft); TTree_field& ft = tfield(F_FT_TREE);
RCT rct_nc; nc.get_rect(rct_nc);
RCT rct_ft; ft.get_rect(rct_ft);
rct_nc.right = rct_ft.left-8; rct_nc.right = rct_ft.left-8;
rct_ft.right = rct_ft.left + rct_nc.right - rct_nc.left; rct_ft.right = rct_ft.left + rct_nc.right - rct_nc.left;
field(F_NC_TREE).set_rect(rct_nc); nc.set_rect(rct_nc);
field(F_FT_TREE).set_rect(rct_ft); ft.set_rect(rct_ft);
} }
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -587,7 +615,7 @@ protected:
void TPareggio_partite::main_loop() void TPareggio_partite::main_loop()
{ {
const int anno = xvt_vobj_get_attr(NULL_WIN, ATTR_APPL_VERSION_YEAR); const int anno = xvt_vobj_get_attr(NULL_WIN, ATTR_APPL_VERSION_YEAR);
if (anno > 2101) if (anno >= 2121)
{ {
TPareggio_mask pm; TPareggio_mask pm;
pm.run(); pm.run();

View File

@ -1,6 +1,7 @@
#include "sc0200b.h" #include "sc0200b.h"
#define F_CODCAUS_C 119 #define F_CODCAUS_C 120
#define F_CODCAUS_F 120 #define F_CODCAUS_F 121
#define F_NC_TREE 121 #define F_IMPORTO 122
#define F_FT_TREE 122 #define F_NC_TREE 131
#define F_FT_TREE 132

View File

@ -222,8 +222,8 @@ BEGIN
DISPLAY "Riga@4R" NRIGA DISPLAY "Riga@4R" NRIGA
DISPLAY "Rata@4R" NRATA DISPLAY "Rata@4R" NRATA
DISPLAY "Scadenza@8" DATASCAD DISPLAY "Scadenza@8" DATASCAD
DISPLAY "Importo@10R" IMPORTO
DISPLAY "Residuo@10R" RESIDUO DISPLAY "Residuo@10R" RESIDUO
DISPLAY "Importo@10R" IMPORTO
DISPLAY "Descrizione Fattura@35" PART.DESCR DISPLAY "Descrizione Fattura@35" PART.DESCR
DISPLAY "P.N.@6R" PART.NREG DISPLAY "P.N.@6R" PART.NREG
FLAGS "M" FLAGS "M"

View File

@ -4,17 +4,24 @@ PAGE "Assegnamento" -1 -1 75 12
STRING F_CODVAL 3 STRING F_CODVAL 3
BEGIN BEGIN
PROMPT 1 0 "" PROMPT 41 0 "Valuta"
FLAGS "H" FLAGS "D"
END
CURRENCY F_IMPORTO 15
BEGIN
PROMPT 1 0 "Importo da suddividere "
DRIVENBY F_CODVAL
FLAGS "D"
END END
SPREADSHEET F_TUTTE SPREADSHEET F_TUTTE
BEGIN BEGIN
PROMPT 0 1 "" PROMPT 0 1 ""
ITEM "Importo\nnota credito@15R" ITEM "Importo\nnota credito@15R"
ITEM "Scadenza\nrata@10"
ITEM "Residuo\nrata@15R" ITEM "Residuo\nrata@15R"
ITEM "Importo\nrata@15R" ITEM "Importo\nrata@15R"
ITEM "Scadenza\nrata@10"
END END
ENDPAGE ENDPAGE
@ -41,28 +48,30 @@ CURRENCY 101 15
BEGIN BEGIN
PROMPT 1 1 "Importo nota credito " PROMPT 1 1 "Importo nota credito "
DRIVENBY -F_CODVAL DRIVENBY -F_CODVAL
NUM_EXPR #THIS_FIELD>=0
WARNING "Inserire un importo positivo"
END END
CURRENCY 102 15 DATE 102
BEGIN
PROMPT 1 4 "Data scadenza "
FLAGS "D"
END
CURRENCY 103 15
BEGIN BEGIN
PROMPT 1 2 "Residuo rata " PROMPT 1 2 "Residuo rata "
FLAGS "D" FLAGS "D"
DRIVENBY -F_CODVAL DRIVENBY -F_CODVAL
END END
CURRENCY 103 15 CURRENCY 104 15
BEGIN BEGIN
PROMPT 1 3 "Importo rata " PROMPT 1 3 "Importo rata "
FLAGS "D" FLAGS "D"
DRIVENBY -F_CODVAL DRIVENBY -F_CODVAL
END END
DATE 104
BEGIN
PROMPT 1 4 "Data scadenza "
FLAGS "D"
END
ENDPAGE ENDPAGE
TOOLBAR "" -2 0 0 2 TOOLBAR "" -2 0 0 2