Correzioni preventivazione per San Zeno
git-svn-id: svn://10.65.10.50/branches/R_10_00@22963 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
0b7472f1db
commit
8836353570
@ -1465,7 +1465,7 @@ int TPreventivo_app::save_rows(const TMask& m)
|
||||
tree.scan_depth_first(tree_save_row, &doc);
|
||||
|
||||
// Estrae campi analitica da maschera principale e li riporta sulle righe
|
||||
TString cms, fas, cos;
|
||||
TString cms, cos;
|
||||
FOR_EACH_MASK_FIELD(m, i, f) if (f->active() && f->is_edit() && f->dlg() >= F_CDC0)
|
||||
{
|
||||
const TFieldref* fref = f->field();
|
||||
@ -1473,8 +1473,6 @@ int TPreventivo_app::save_rows(const TMask& m)
|
||||
{
|
||||
if (fref->name() == DOC_CODCMS)
|
||||
cms << f->get();
|
||||
if (fref->name() == DOC_FASCMS)
|
||||
fas << f->get();
|
||||
if (fref->name() == DOC_CODCOSTO)
|
||||
cos << f->get();
|
||||
}
|
||||
@ -1482,7 +1480,6 @@ int TPreventivo_app::save_rows(const TMask& m)
|
||||
|
||||
TRecord_array& rdoc = doc.body();
|
||||
rdoc.renum_key(RDOC_CODCMS, cms);
|
||||
rdoc.renum_key(RDOC_FASCMS, fas);
|
||||
rdoc.renum_key(RDOC_CODCOSTO, cos);
|
||||
|
||||
const int err = doc.rewrite(get_relation()->file());
|
||||
@ -1556,7 +1553,8 @@ void TPreventivo_app::init_insert_mode(TMask& m)
|
||||
update_tools(m);
|
||||
|
||||
const TMultilevel_code_info& fi = ca_multilevel_code_info(LF_FASI);
|
||||
m.set(F_FASEMAX, fi.levels());
|
||||
const int fasemax = fi.levels() - fi.parent_levels();
|
||||
m.set(F_FASEMAX, fasemax);
|
||||
}
|
||||
|
||||
void TPreventivo_app::init_modify_mode(TMask& m)
|
||||
|
@ -35,6 +35,7 @@
|
||||
#define F_FASELT 246
|
||||
#define F_FASERT 247
|
||||
#define F_FASEMAX 248
|
||||
#define F_FASEART 249
|
||||
|
||||
#define F_CDC0 250
|
||||
|
||||
|
@ -511,16 +511,23 @@ END
|
||||
|
||||
TEXT DLG_NULL
|
||||
BEGIN
|
||||
PROMPT 50 0 "Fase max:"
|
||||
PROMPT 48 0 "Liv. Fasi "
|
||||
END
|
||||
|
||||
LIST F_FASEMAX 1 9
|
||||
LIST F_FASEMAX 1 1
|
||||
BEGIN
|
||||
PROMPT 50 1 ""
|
||||
ITEM "1|1 Livello"
|
||||
ITEM "2|2 Livelli"
|
||||
ITEM "3|3 Livelli"
|
||||
ITEM "4|4 Livelli"
|
||||
PROMPT 58 0 ""
|
||||
ITEM "1|1"
|
||||
ITEM "2|2"
|
||||
ITEM "3|3"
|
||||
ITEM "4|4"
|
||||
END
|
||||
|
||||
BOOLEAN F_FASEART
|
||||
BEGIN
|
||||
PROMPT 48 1 "Art.=Ult.liv."
|
||||
FIELD ADDBOLLI
|
||||
HELP "Usa codice articolo come ultimo livello delle fasi"
|
||||
END
|
||||
|
||||
SPREADSHEET F_DISTINTE 0 11
|
||||
|
291
pe/pe1500.cpp
291
pe/pe1500.cpp
@ -30,6 +30,118 @@ int pe_numero_fasi(const TRecord_array& preventivo)
|
||||
int pe_numero_fasi(const TDocumento& preventivo)
|
||||
{ return pe_numero_fasi(preventivo.body()); }
|
||||
|
||||
int pe_crea_fasi_preventivo(TDocumento& din)
|
||||
{
|
||||
const TString4 _strFasi = ini_get_string(CONFIG_DITTA, "pe", "TipoRigaFase", "05");
|
||||
const TString4 _strDist = ini_get_string(CONFIG_DITTA, "pe", "TipoRigaDist", "P1");
|
||||
|
||||
const int doc_levels = pe_numero_fasi(din);
|
||||
if (doc_levels <= 0)
|
||||
return 0; // Should never happen
|
||||
|
||||
TConfig& cfg = ca_config();
|
||||
TString_array picture_fasi;
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
const TString& pic = cfg.get("Fsc", "ca", i);
|
||||
if (pic.full())
|
||||
picture_fasi.add(pic);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
const int cfg_levels = picture_fasi.items();
|
||||
if (cfg_levels <= 0)
|
||||
{
|
||||
error_box(TR("Occorre configurare le fasi analitiche"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
const bool faseart = din.get_bool(DOC_ADDBOLLI);
|
||||
|
||||
TLocalisamfile fasi(LF_FASI);
|
||||
|
||||
TString16 fase[4], curfase; // Livelli delle fasi (max 4)
|
||||
int curliv = 0;
|
||||
|
||||
/* Vedere in futuro come gestire numero di fasi incoerente con la configurazione di CA
|
||||
// Crea gli eventuali livelli iniziali mancanti
|
||||
const int delta_levels = cfg_levels-doc_levels;
|
||||
if (delta_levels > 0)
|
||||
{
|
||||
TString80 descr;
|
||||
for (int lev = 0; lev < delta_levels; lev++)
|
||||
{
|
||||
fase[lev].format("%0*ld", picture_fasi.row(lev).len(), 0);
|
||||
fasi.put(FASI_CODCMSFAS, din.get(DOC_CODCMS));
|
||||
|
||||
int tot_len = 0;
|
||||
for (int l = 0; l <= lev; l++)
|
||||
tot_len += picture_fasi.row(lev).len();
|
||||
descr.format("%0*ld", tot_len, 0);
|
||||
fasi.put(FASI_CODFASE, descr);
|
||||
|
||||
descr.format(FR("FASE%d"), lev);
|
||||
fasi.put(FASI_DESCRIZ, descr);
|
||||
|
||||
fasi.write_rewrite();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
const int nrows = din.physical_rows();
|
||||
FOR_EACH_PHYSICAL_RDOC(din, r, rdoc)
|
||||
{
|
||||
const TString& tr = rdoc->get(RDOC_TIPORIGA);
|
||||
if (tr == _strFasi)
|
||||
{
|
||||
const int level = rdoc->get_int(RPRV_LEVEL); // Livello logico della riga [0,3]
|
||||
if (r >= nrows || (level == (cfg_levels-1) && din[r+1].is_descrizione()))
|
||||
continue; // Salta fasi vuote
|
||||
|
||||
if (level >= 0 && level < cfg_levels)
|
||||
{
|
||||
const int fase_len = picture_fasi.row(level).len();
|
||||
TString& cod = fase[level];
|
||||
cod = rdoc->get(RDOC_CODART).left(10);
|
||||
const int delta_len = fase_len - cod.len();
|
||||
if (delta_len != 0)
|
||||
{
|
||||
if (delta_len > 0)
|
||||
cod.rpad(fase_len, ' ');
|
||||
else
|
||||
cod.cut(fase_len);
|
||||
}
|
||||
curliv = level;
|
||||
curfase.cut(0);
|
||||
for (int i = 0; i <= level; i++)
|
||||
curfase << fase[i];
|
||||
fasi.put(FASI_CODCMSFAS, din.get(DOC_CODCMS));
|
||||
fasi.put(FASI_CODFASE, curfase);
|
||||
fasi.put(FASI_DESCRIZ, rdoc->get(RDOC_DESCR));
|
||||
fasi.write_rewrite();
|
||||
}
|
||||
} else
|
||||
if (tr == _strDist)
|
||||
{
|
||||
if (faseart && curliv == cfg_levels-2)
|
||||
{
|
||||
fasi.put(FASI_CODCMSFAS, din.get(DOC_CODCMS));
|
||||
TString80 fase = curfase; fase << rdoc->get(RDOC_CODART);
|
||||
fasi.put(FASI_CODFASE, fase);
|
||||
fasi.put(FASI_DESCRIZ, rdoc->get(RDOC_DESCR));
|
||||
fasi.write_rewrite();
|
||||
}
|
||||
}
|
||||
|
||||
// Aggiorna codice fase anche nella riga di input
|
||||
const TString& lastfase = fasi.get(FASI_CODFASE);
|
||||
if (lastfase.full() && rdoc->get(RDOC_FASCMS) != lastfase)
|
||||
rdoc->put(RDOC_FASCMS, lastfase);
|
||||
}
|
||||
|
||||
return cfg_levels;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TOrdinazione
|
||||
@ -45,7 +157,7 @@ public:
|
||||
TOrdinazione(const TString& cod);
|
||||
};
|
||||
|
||||
const TRectype& find_ordine(const TDocumento& doc, const TString& codnum, bool& bEvaso)
|
||||
const TRectype& find_precedente(const TDocumento& doc, const TString& codnum, bool& bEvaso)
|
||||
{
|
||||
TString query, limit;
|
||||
limit << RDOC_DAPROVV << '=' << doc.get(DOC_PROVV) << ' '
|
||||
@ -81,21 +193,6 @@ bool TOrdinazione::elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
||||
{
|
||||
const TString80 codart = ini_get_string(CONFIG_DITTA, "ci", "CODARTPR");
|
||||
|
||||
TConfig& cfg = ca_config();
|
||||
TString_array picture_fasi;
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
const TString& pic = cfg.get("Fsc", "ca", i);
|
||||
if (pic.full())
|
||||
picture_fasi.add(pic);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
const int cfg_levels = picture_fasi.items();
|
||||
if (cfg_levels <= 0)
|
||||
return error_box(TR("Occorre configurare le fasi analitiche"));
|
||||
|
||||
for (int i = 0; i < doc_in.items(); i++)
|
||||
{
|
||||
TDocumento& din = doc_in[i];
|
||||
@ -103,9 +200,9 @@ bool TOrdinazione::elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
||||
// Mi assicuro che ad ogni documento in ingresso ne corrisponda uno in uscita
|
||||
if (i >= doc_out.items())
|
||||
{
|
||||
const TString& codnum = codice_numerazione_finale();
|
||||
const TString4 codnum = codice_numerazione_finale();
|
||||
bool bEvaso = false;
|
||||
const TRectype& ord = find_ordine(din, codnum, bEvaso);
|
||||
const TRectype& ord = find_precedente(din, codnum, bEvaso);
|
||||
|
||||
if (!ord.empty())
|
||||
{
|
||||
@ -138,6 +235,10 @@ bool TOrdinazione::elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
||||
doc_out.add(doc);
|
||||
}
|
||||
|
||||
const int cfg_levels = pe_crea_fasi_preventivo(din);
|
||||
if (cfg_levels <= 0)
|
||||
return false;
|
||||
|
||||
TDocumento& don = doc_out[i];
|
||||
|
||||
din.put(DOC_STATO, stato_finale_doc_iniziale());
|
||||
@ -155,73 +256,20 @@ bool TOrdinazione::elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
||||
if (doc_levels <= 0)
|
||||
continue; // Should never happen
|
||||
|
||||
TLocalisamfile fasi(LF_FASI);
|
||||
|
||||
TString16 fase[4], codfase; // Livelli delle fasi (max 4)
|
||||
|
||||
// Crea gli eventuali livelli iniziali mancanti
|
||||
const int delta_levels = cfg_levels-doc_levels;
|
||||
if (delta_levels > 0)
|
||||
{
|
||||
TString80 descr;
|
||||
for (int lev = 0; lev < delta_levels; lev++)
|
||||
{
|
||||
fase[lev].format("%0*ld", picture_fasi.row(lev).len(), 0);
|
||||
fasi.put(FASI_CODCMSFAS, din.get(DOC_CODCMS));
|
||||
|
||||
int tot_len = 0;
|
||||
for (int l = 0; l <= lev; l++)
|
||||
tot_len += picture_fasi.row(lev).len();
|
||||
descr.format("%0*ld", tot_len, 0);
|
||||
fasi.put(FASI_CODFASE, descr);
|
||||
|
||||
descr.format(FR("FASE%d"), lev);
|
||||
fasi.put(FASI_DESCRIZ, descr);
|
||||
|
||||
fasi.write_rewrite();
|
||||
}
|
||||
}
|
||||
|
||||
const int nrows = din.physical_rows();
|
||||
FOR_EACH_PHYSICAL_RDOC(din, r, rdoc)
|
||||
{
|
||||
const TString& tr = rdoc->get(RDOC_TIPORIGA);
|
||||
if (tr == _strFasi)
|
||||
{
|
||||
int level = rdoc->get_int(RPRV_LEVEL); // Livello logico della riga [0,3]
|
||||
if (delta_levels > 0)
|
||||
level += delta_levels; // Livello fisico [0,3]
|
||||
|
||||
const int level = rdoc->get_int(RPRV_LEVEL); // Livello logico della riga [0,3]
|
||||
if (r >= nrows || (level == (cfg_levels-1) && din[r+1].is_descrizione()))
|
||||
continue; // Salta fasi vuote
|
||||
|
||||
TRiga_documento& rout = don.new_row(_strFasi);
|
||||
TDocumento::copy_data(rout, *rdoc);
|
||||
|
||||
if (level >= 0 && level < cfg_levels)
|
||||
{
|
||||
const int fase_len = picture_fasi.row(level).len();
|
||||
TString& cod = fase[level];
|
||||
cod = rdoc->get(RDOC_CODART).left(10);
|
||||
const int delta_len = fase_len - cod.len();
|
||||
if (delta_len != 0)
|
||||
{
|
||||
if (delta_len > 0)
|
||||
{
|
||||
if (isdigit(cod[0]))
|
||||
cod.lpad(fase_len, '0');
|
||||
else
|
||||
cod.rpad(fase_len, ' ');
|
||||
}
|
||||
else
|
||||
cod.cut(fase_len);
|
||||
}
|
||||
codfase.cut(0); for (int i = 0; i <= level; i++) codfase << fase[i];
|
||||
fasi.put(FASI_CODCMSFAS, din.get(DOC_CODCMS));
|
||||
fasi.put(FASI_CODFASE, codfase);
|
||||
fasi.put(FASI_DESCRIZ, rdoc->get(RDOC_DESCR));
|
||||
fasi.write_rewrite();
|
||||
}
|
||||
rout.set_original_rdoc_key(*rdoc);
|
||||
rout.put(RDOC_CODCMS, din.get(DOC_CODCMS));
|
||||
} else
|
||||
if (tr == _strDist)
|
||||
{
|
||||
@ -229,12 +277,9 @@ bool TOrdinazione::elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
||||
TDocumento::copy_data(rout, *rdoc);
|
||||
rout.set_original_rdoc_key(*rdoc);
|
||||
rout.put(RDOC_CODCMS, din.get(DOC_CODCMS));
|
||||
rout.put(RDOC_FASCMS, codfase);
|
||||
rout.put(RDOC_CODARTMAG, codart);
|
||||
rdoc->put(RDOC_FASCMS, codfase); // Aggiorna codice fase anche nella riga di input
|
||||
}
|
||||
}
|
||||
din.rewrite(); // Aggiorna codici fase nelle righe
|
||||
don.write(); // Salva ordine
|
||||
}
|
||||
return true;
|
||||
@ -257,22 +302,49 @@ class TFabbisognazione : public TElaborazione_esterna
|
||||
public:
|
||||
virtual bool elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
||||
const TDate& data_elab, bool interattivo = false);
|
||||
|
||||
TFabbisognazione(const TString& cod);
|
||||
};
|
||||
|
||||
|
||||
bool TFabbisognazione::elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
||||
const TDate& data_elab, bool interattivo)
|
||||
{
|
||||
for (int i = 0; i < doc_in.items(); i++)
|
||||
{
|
||||
TDocumento& din = doc_in[i];
|
||||
if (i >= doc_out.items())
|
||||
{
|
||||
TDocumento* doc = new TDocumento('D', data_elab.year(), codice_numerazione_finale(), 0L);
|
||||
const TString4 codnum = codice_numerazione_finale();
|
||||
bool bEvaso = false;
|
||||
const TRectype& fabb = find_precedente(din, codnum, bEvaso);
|
||||
|
||||
if (!fabb.empty())
|
||||
{
|
||||
if (bEvaso)
|
||||
{
|
||||
if (interattivo)
|
||||
error_box("Il preventivo è collegato al fabbisogno già evaso %s %d/%ld",
|
||||
(const char*)fabb.get(DOC_CODNUM), fabb.get_int(DOC_ANNO), fabb.get_long(DOC_NDOC));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (interattivo)
|
||||
warning_box("Il preventivo aggiornerà il fabbisogno %s %d/%ld",
|
||||
(const char*)fabb.get(DOC_CODNUM), fabb.get_int(DOC_ANNO), fabb.get_long(DOC_NDOC));
|
||||
}
|
||||
}
|
||||
|
||||
TDocumento* doc = new TDocumento('D', data_elab.year(), codnum, 0L);
|
||||
doc->put(DOC_TIPODOC, tipo_finale());
|
||||
doc_out.add(doc);
|
||||
}
|
||||
|
||||
TDocumento& din = doc_in[i];
|
||||
const int cfg_levels = pe_crea_fasi_preventivo(din);
|
||||
if (cfg_levels <= 0)
|
||||
continue;
|
||||
|
||||
TDocumento& don = doc_out[i];
|
||||
|
||||
din.put(DOC_STATO, stato_finale_doc_iniziale());
|
||||
@ -290,19 +362,7 @@ bool TFabbisognazione::elabora(TLista_documenti& doc_in, TLista_documenti& doc_o
|
||||
if (doc_levels <= 0)
|
||||
continue; // Should never happen
|
||||
|
||||
TLocalisamfile fasi(LF_FASI);
|
||||
|
||||
TString16 fase[4], codfase; // Livelli delle fasi (max 4)
|
||||
|
||||
|
||||
const TMultilevel_code_info cfg_fasi(LF_FASI);
|
||||
const int cfg_levels = cfg_fasi.levels();
|
||||
if (cfg_levels <= 0)
|
||||
return error_box(TR("Occorre configurare le fasi analitiche"));
|
||||
|
||||
// Calcola gli eventuali livelli iniziali mancanti
|
||||
const int delta_levels = cfg_levels-doc_levels;
|
||||
|
||||
bool dettagliato = false;
|
||||
real qta = UNO;
|
||||
const int nrows = din.rows();
|
||||
FOR_EACH_PHYSICAL_RDOC(din, r, rdoc)
|
||||
@ -310,37 +370,11 @@ bool TFabbisognazione::elabora(TLista_documenti& doc_in, TLista_documenti& doc_o
|
||||
const TString& tr = rdoc->get(RDOC_TIPORIGA);
|
||||
if (tr == _strFasi)
|
||||
{
|
||||
int level = rdoc->get_int(RPRV_LEVEL); // Livello logico della riga [0,3]
|
||||
if (delta_levels > 0)
|
||||
level += delta_levels; // Livello fisico [0,3]
|
||||
|
||||
if (r >= nrows || (level == (cfg_levels-1) && din[r+1].is_descrizione()))
|
||||
continue; // Salta fasi vuote
|
||||
|
||||
if (level >= 0 && level < cfg_levels)
|
||||
{
|
||||
const int fase_len = cfg_fasi.len(level);
|
||||
TString& cod = fase[level];
|
||||
cod = rdoc->get(RDOC_CODART).left(10);
|
||||
const int delta_len = fase_len - cod.len();
|
||||
if (delta_len != 0)
|
||||
{
|
||||
if (delta_len > 0)
|
||||
{
|
||||
if (isdigit(cod[0]))
|
||||
cod.lpad(fase_len, '0');
|
||||
else
|
||||
cod.rpad(fase_len, ' ');
|
||||
}
|
||||
else
|
||||
cod.cut(fase_len);
|
||||
}
|
||||
codfase.cut(0);
|
||||
for (int i = 0; i <= level; i++) codfase << fase[i];
|
||||
}
|
||||
}
|
||||
// Nothig to do
|
||||
} else
|
||||
if (tr == _strDist)
|
||||
{
|
||||
// Aggiorna quantità
|
||||
qta = rdoc->get_real(RDOC_QTA);
|
||||
if (qta <= ZERO)
|
||||
qta = UNO;
|
||||
@ -349,13 +383,22 @@ bool TFabbisognazione::elabora(TLista_documenti& doc_in, TLista_documenti& doc_o
|
||||
{
|
||||
TRiga_documento& rout = don.new_row(_strDett);
|
||||
TDocumento::copy_data(rout, *rdoc);
|
||||
rout.set_original_rdoc_key(*rdoc);
|
||||
rout.put(RDOC_CODCMS, din.get(DOC_CODCMS));
|
||||
rout.put(RDOC_QTA, real(qta * rdoc->get_real(RDOC_QTA)));
|
||||
rout.put(RDOC_PREZZO, rdoc->get(RDOC_QTAGG5));
|
||||
rout.set_original_rdoc_key(*rdoc);
|
||||
rout.put(RDOC_FASCMS, codfase);
|
||||
dettagliato = true;
|
||||
}
|
||||
}
|
||||
don.write(); // Salva nuovo documento
|
||||
|
||||
if (dettagliato)
|
||||
don.write(); // Salva nuovo documento
|
||||
else
|
||||
{
|
||||
if (interattivo)
|
||||
error_box(FR("Il preventivo %s %d/%ld non ha articoli: impossibile generare il fabbisogno"),
|
||||
(const char*)din.get(DOC_CODNUM), din.get_int(DOC_ANNO), din.get_long(DOC_NDOC));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user