campo-sirio/src/in/in0200.cpp
Alessandro Bonazzi 8ee685d4b5 Patch level : 12.0 1040
Files correlati     : tutto in
Commento            :

Aggiornato il modulo intra

Interno :

Primo rilascio mancano  la generazione riepiloghi e l'invio delle righe di servizio
2021-03-16 13:20:02 +01:00

614 lines
16 KiB
C++
Executable File
Raw Blame History

#include <applicat.h>
#include <progind.h>
#include <recarray.h>
#include <relation.h>
#include <tabutil.h>
#include "in0.h"
#include "in0200a.h"
#include "inlib01.h"
#include <nditte.h>
#include <anagr.h>
#include <riepintra.h>
///////////////////////////////////////////////////////////
// TRecord_intra
///////////////////////////////////////////////////////////
class TRecord_intra : public TString
{
int _ndec;
protected:
virtual void print_on(ostream& o) const;
public:
void reset(const TIntra_context& ic);
void reset_data();
void put(const char* str, int pos, int dim, const char* flags = "");
void put(real num, int pos, int dim, int dec = 0);
void put(long num, int pos, int dim);
void put(char chr, int pos);
void genera_testata(const TIntra_context& ic);
void put(const TRectype& rec, TIntra_context& ic);
TRecord_intra();
};
// Scrive un campo generico sul record di invio
void TRecord_intra::put(const char* str, int pos, int dim, const char* flags)
{
CHECKD(pos > 0 && pos < size(), "Invalid field position:", pos);
CHECKD(dim > 0 && dim <= 200, "Invalid field dimension:", dim);
TString256 val(str);
if (val.len() < dim)
{
const bool rj = strchr(flags, 'R') != NULL;
const bool zf = strchr(flags, 'Z') != NULL;
if (rj)
val.right_just(dim, zf ? '0' : ' ');
else
val.left_just(dim, zf ? '0' : ' ');
}
else
val.cut(dim);
overwrite(val, pos-1);
}
// Scrive un campo numerico sul record di invio
void TRecord_intra::put(real num, int pos, int dim, int dec)
{
TString80 str;
if (!num.is_zero())
{
num.round(dec);
const bool negativo = num < ZERO;
if (negativo) num *= -1.0;
if (dec < 0)
{
str = num.string(dim-dec, 0, '0');
str.rtrim(-dec);
}
else
{
str = num.string(dim, dec, '0');
}
if (negativo)
str[dim-1] += 64;
}
put(str, pos, dim, "RZ");
}
// Scrive un campo intero sul record di invio
void TRecord_intra::put(long num, int pos, int dim)
{
TString16 str;
str.format("%0*ld", dim, num);
put(str, pos, dim, "RZ");
}
// Scrive un campo carattere sul record di invio
void TRecord_intra::put(char chr, int pos)
{
const char str[2] = { chr, '\0' };
put(str, pos, 1);
}
// Azzera il record
void TRecord_intra::reset(const TIntra_context& ic)
{
spaces();
put("EUROX", 1, 5);
const TRectype& ditta = cache().get(LF_NDITTE, main_app().get_firm());
TString16 cod;
cod.format("%c|%ld", ditta.get_char(NDT_TIPOA), ditta.get_long(NDT_CODANAGR));
const TRectype& anagr = cache().get(LF_ANAG, cod);
put(anagr.get(ANA_PAIV), 6, 11);
put(ic._progr, 17, 6);
}
void TRecord_intra::reset_data()
{
const TString80 key = left(22);
spaces();
overwrite(key, 0);
}
// Scrive la testata con le informazioni della ditta
void TRecord_intra::genera_testata(const TIntra_context& ic)
{
reset(ic);
put('0', 23); // Tipo record frontespizio
put("", 24, 5, "RZ"); // Numero riga (0 per frontespizio)
put(ic._tipo, 29); // Tipo riepilogo
put(ic._anno % 100, 30, 2);
put(ic._freq, 32);
const int periodo = ic._freq == 'A' ? 0 : ic._periodo;
put(periodo, 33, 2);
TString16 cod = mid(5, 11); // Ricopia la parita iva della ditta
put(cod, 35, 11);
const TRectype& ditta = cache().get(LF_NDITTE, main_app().get_firm());
put(ditta.get_bool("PRESELEN") ? '1' : '0', 46);
put(ditta.get_bool("CESSIVA") ? '1' : '0', 47);
cod.cut(0);
cod << ditta.get_char("TIPOSOGDEL") << '|';
cod << ditta.get("CODSOGDEL");
if (cod.len() >= 3)
{
const TRectype& sogdel = cache().get(LF_ANAG, cod);
put(sogdel.get(ANA_PAIV), 48, 11);
}
else
put("", 48, 11, "Z");
put(ic._righe_riep, 59, 5);
put(ic._totale_riep, 64, 13, _ndec);
put(ic._righe_rett, 77, 5);
put(ic._totale_rett, 82, 13, _ndec);
}
// Scrive un intero record del file riepiloghi/rettifiche
void TRecord_intra::put(const TRectype& rec, TIntra_context& ic)
{
reset_data();
put(rec.get_long("NUMRIG"), 24, 5);
const char tipointra = rec.get_char("TIPOINTRA");
const char tipo = rec.get_char("TIPO");
CHECK(tipointra == ic._tipointra, "Tipo Intra non previsto");
if (tipointra == 'B')
{
switch (tipo)
{
case 'A':
put('1', 23);
put(rec.get("STATO"), 29, 2);
put(rec.get("PIVA"), 31, 12);
put(rec.get_real("AMMLIRE"), 43, 13, _ndec);
put(rec.get_real("AMMVALUTA"), 56, 13);
put(rec.get_char("NATURA"), 69);
put(rec.get("NOMENCL").mid(0, 4), 70, 4, "Z"); //il campo viene spezzato in 3 pezzi
put(rec.get("NOMENCL").mid(4, 2), 74, 2, "Z");
put(rec.get("NOMENCL").mid(6, 2), 76, 2, "Z");
if (ic._freq == 'M')
{
put(rec.get_real("MASSAKG"), 78, 10, 0);
put(rec.get_real("MASSAUMS"), 88, 10, 0);
put(rec.get_real("VALSTAT"), 98, 13, _ndec);
put(rec.get_char("CONSEGNA"), 111);
put(rec.get_char("TRASPORTO"), 112);
put(rec.get("PAESE"), 113, 2);
put(rec.get("PAESEORIG"), 115, 2);
put(rec.get("PROV"), 117, 2);
}
else
put("", 78, 100);
break;
case 'B':
{
put('2', 23);
if (ic._freq == 'M')
put(rec.get("PERETT"), 29, 2, "RZ");
else
put("", 29, 2, "RZ");
if (ic._freq == 'T')
put(rec.get("PERETT")[1], 31);
else
put('0', 31);
put(rec.get("ANNORETT").right(2), 32, 2, "RZ");
put(rec.get("STATO"), 34, 2);
put(rec.get("PIVA"), 36, 12);
put(rec.get("SEGNORETT"), 48, 1);
put(rec.get_real("AMMLIRE"), 49, 13, _ndec);
put(rec.get_real("AMMVALUTA"), 62, 13);
put(rec.get_char("NATURA"), 75);
put(rec.get("NOMENCL").mid(0, 4), 76, 4, "Z"); //il campo viene spezzato in 3 pezzi
put(rec.get("NOMENCL").mid(4, 2), 80, 2, "Z");
put(rec.get("NOMENCL").mid(6, 2), 82, 2, "Z");
if (ic._freq == 'M')
put(rec.get_real("VALSTAT"), 84, 13, _ndec);
else
put("", 84, 13);
}
break;
case 'C':
put('1', 23);
put(rec.get("STATO"), 29, 2);
put(rec.get("PIVA"), 31, 12);
put(rec.get_real("AMMLIRE"), 43, 13, _ndec);
put(rec.get_char("NATURA"), 56);
put(rec.get("NOMENCL"), 57, 8, "Z"); //il campo NON viene spezzato in 3 pezzi
if (ic._freq == 'M')
{
put(rec.get_real("MASSAKG"), 65, 10);
put(rec.get_real("MASSAUMS"), 75, 10);
put(rec.get_real("VALSTAT"), 85, 13, _ndec);
put(rec.get_char("CONSEGNA"), 98);
put(rec.get_char("TRASPORTO"), 99);
put(rec.get("PAESE"), 100, 2);
put(rec.get("PROV"), 102, 2);
}
else
put("", 65, 100);
break;
case 'D':
{
put('2', 23);
if (ic._freq == 'M')
put(rec.get("PERETT"), 29, 2, "RZ");
else
put("", 29, 2, "RZ");
if (ic._freq == 'T')
put(rec.get("PERETT")[1], 31);
else
put('0', 31);
put(rec.get("ANNORETT").right(2), 32, 2, "RZ");
put(rec.get("STATO"), 34, 2);
put(rec.get("PIVA"), 36, 12);
put(rec.get("SEGNORETT"), 48, 1);
put(abs(rec.get_real("AMMLIRE")), 49, 13, _ndec);
put(rec.get("NATURA"), 62, 1);
put(rec.get("NOMENCL"), 63, 8, "Z"); // il campo NON viene spezzato in 3 pezzi
if (ic._freq == 'M')
put(abs(rec.get_real("VALSTAT")), 71, 13, _ndec);
else
put("", 71, 13);
}
break;
default:
NFCHECK("Record di tipo sconosciuto: %c", tipo);
break;
}
}
else
{
switch (tipo)
{
case 'A':
put('3', 23);
put(rec.get("STATO"), 29, 2);
put(rec.get("PIVA"), 31, 12);
put(rec.get_real("AMMLIRE"), 43, 13, _ndec);
put(rec.get_real("AMMVALUTA"), 56, 13);
// put(numero fattura, 69, 15);
// put(data fattura, 84, 6);
// put(codice servizio, 90, 6);
// put(modalit<69> di erogazione, 96);
// put(modalit<69> di incasso, 97);
// put(codice paese di pagamento, 98, 2);
break;
case 'B':
{
put('4', 23);
// put(sezione doganale, 29, 6);
put(rec.get("ANNORETT").right(2), 35, 2, "RZ");
// put(protocollo rettifica, 37, 6, "RZ");
// put(progressivo rettifica, 43, 5, "RZ");
put(rec.get("STATO"), 48, 2);
put(rec.get("PIVA"), 50, 12);
put(rec.get_real("AMMLIRE"), 62, 13, _ndec);
put(rec.get_real("AMMVALUTA"), 75, 13);
// put(numero fattura, 88, 15);
// put(data fattura, 103, 6);
// put(codice servizio, 109, 6);
// put(modalit<69> di erogazione, 115);
// put(modalit<69> di incasso, 116);
// put(codice paese di pagamento, 117, 2);
}
break;
case 'C':
put('3', 23);
put(rec.get("STATO"), 29, 2);
put(rec.get("PIVA"), 31, 12);
put(rec.get_real("AMMLIRE"), 43, 13, _ndec);
// put(numero fattura, 56, 15);
// put(data fattura, 71, 6);
// put(codice servizio, 77, 6);
// put(modalit<69> di erogazione, 83);
// put(modalit<69> di incasso,84);
// put(codice paese di pagamento, 85, 2);
break;
case 'D':
{
put('4', 23);
// put(sezione doganale, 29, 6);
put(rec.get("ANNORETT").right(2), 35, 2, "RZ");
// put(protocollo rettifica, 37, 6, "RZ");
// put(progressivo rettifica, 43, 5, "RZ");
put(rec.get("STATO"), 48, 2);
put(rec.get("PIVA"), 50, 12);
put(rec.get_real("AMMLIRE"), 2, 13, _ndec);
// put(numero fattura, 75, 15);
// put(data fattura, 90, 6);
// put(codice servizio, 96, 6);
// put(modalit<69> di erogazione, 102);
// put(modalit<69> di incasso, 103);
}
break;
default:
NFCHECK("Record di tipo sconosciuto: %c", tipo);
break;
}
}
}
// Scrive su file il record
void TRecord_intra::print_on(ostream& o) const
{
((TRecord_intra*)this)->rtrim();
TString::print_on(o);
o << endl;
}
TRecord_intra::TRecord_intra() : TString(132), _ndec(0)
{ }
///////////////////////////////////////////////////////////
// TInvioIntra1_2_mask
///////////////////////////////////////////////////////////
class TInvioIntra1_2_mask : public TIntra_mask
{
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
virtual short type_field() const { return F_TIPO; }
virtual short period_field() const { return F_PERIODO_M; }
virtual int anno() const { return get_int(F_ANNO); }
TRecnotype calcola_totale(TCursor& cur, real& tot) const;
void proponi_numero();
public:
void genera(char tipointra, char tipo);
TInvioIntra1_2_mask::TInvioIntra1_2_mask() : TIntra_mask("in0200a") {}
};
void TInvioIntra1_2_mask::proponi_numero()
{
const char tip = tipo();
int a = anno(), p = periodo();
long d = 0;
TTable ird("IRD");
int err = ird.last();
while (err == NOERR)
{
const TString16 str = ird.get("CODTAB");
a = atoi(str.mid(1,4));
p = atoi(str.mid(5,2));
d = ird.get_long("I0");
if (tip == 'T' || tip == str[0])
break;
err = ird.prev();
}
if (anno() > a || periodo() > p)
set(F_NUMERO, d+1);
else
set(F_NUMERO, 1L);
}
bool TInvioIntra1_2_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_ANNO:
if (e == fe_init || e == fe_modify)
{
const int anno = atoi(o.get());
const char fa = frequenza(anno, 'A');
const char fc = frequenza(anno, 'C');
TList_field& list = (TList_field&)field(type_field());
TToken_string codes = "A|C";
TToken_string descr;
descr.add(TR("Acquisti"));
descr.add(TR("Cessioni"));
if (fa == fc)
{
codes.add("T");
descr.add(TR("Tutti"));
}
list.replace_items(codes, descr);
proponi_numero();
}
break;
case F_TIPO:
case F_PERIODO_M:
case F_PERIODO_T:
case F_PERIODO_A:
if (e == fe_modify)
proponi_numero();
break;
case F_RIEPILOGHI:
if (e == fe_button)
{
const char tip = tipo();
if (tip == 'T')
{
::genera_riepiloghi('A', anno(), periodo());
::genera_riepiloghi('C', anno(), periodo());
}
else
::genera_riepiloghi(tip, anno(), periodo());
}
break;
default:break;
}
return TIntra_mask::on_field_event(o, e, jolly);
}
TRecnotype TInvioIntra1_2_mask::calcola_totale(TCursor& cur, real& tot) const
{
TWait_cursor arrow;
const TRecnotype items = cur.items();
cur.freeze();
tot = ZERO;
const TRectype& rec = cur.curr();
for (cur = 0L; cur.pos() < items; ++cur)
{
const char tipo = rec.get_char("TIPO");
const real val = rec.get_real("AMMLIRE").round(0); // Arrotonda all'Euro i valori intermedi
// Da chiarire: come sommare le rettifiche negative!
if ((tipo == 'B' || tipo == 'D') && rec.get_char("SEGNORETT") == '-')
tot -= val; // Rettifiche negative
else
tot += val;
}
return items;
}
void TInvioIntra1_2_mask::genera(char tipointra, char tipo)
{
TIntra_context ic;
ic._tipointra = tipointra;
ic._tipo = tipo;
ic._anno = anno();
ic._freq = frequenza(ic._anno);
ic._periodo = periodo();
ic._progr = get_long(F_NUMERO);
TString8 codtab; codtab.format("%c%04d%02d", ic._tipo, ic._anno, ic._periodo);
TTable ird("IRD");
ird.put("CODTAB", codtab);
const bool exist = ird.read() == NOERR;
if (exist)
{
const char* ac = tipo == 'A' ? TR("acquisti") : TR("cessioni");
if (!yesno_box(FR("Il file %s del periodo indicato <20> gi<67> stato generato:\n"
"Si desidera proseguire ugualmente?"), ac))
return;
}
TRelation rel(LF_RIEPRETT);
TRectype filter(LF_RIEPRETT);
filter.put("TIPOINTRA", ic._tipointra);
filter.put("TIPO", ic._tipo);
filter.put("ANNO", ic._anno);
filter.put("PERIODO", periodo_str());
TCursor riep(&rel, "", 1, &filter, &filter);
ic._righe_riep = calcola_totale(riep, ic._totale_riep);
filter.put("TIPO", char(ic._tipo+1));
TCursor rett(&rel, "", 1, &filter, &filter);
ic._righe_rett = calcola_totale(rett, ic._totale_rett);
TFilename name = get(F_PATH);
TString filename(get(F_CODUA));
filename << format("%02d%02d%02d", today.day(), today.month(), get_int(F_NUMERO));
name.add(filename);
if (name.exist() && yesno_box(FR("Il file %s esiste gi<67>: si desiderla sostituirlo ?\n"), (const char*)name))
return;
ofstream out(name, ios::out | ios::app);
if (!out)
{
cantwrite_box(name);
return;
}
const long total = ic._righe_riep + ic._righe_rett;
TProgress_monitor pi(total, TR("Generazione Intra 1/2"), false);
TRecord_intra rec;
rec.genera_testata(ic);
out << rec;
rec.reset_data();
for (riep = 0L; riep.pos() < ic._righe_riep; ++riep)
{
pi.add_status();
rec.put(riep.curr(), ic);
out << rec;
}
rec.reset_data();
for (rett = 0L; rett.pos() < ic._righe_rett; ++rett)
{
pi.add_status();
rec.put(riep.curr(), ic);
out << rec;
}
codtab.format("%c%04d%02d", ic._tipo, ic._anno, ic._periodo);
ird.put("CODTAB", codtab);
ird.put("I2", ic._righe_riep);
ird.put("I3", ic._righe_rett);
ird.put("R0", ic._totale_riep);
ird.put("R1", ic._totale_rett);
ird.rewrite_write();
set(F_NUMERO, ic._progr + 1);
TString msg("Generato il file ");
msg << name;
message_box(name);
}
///////////////////////////////////////////////////////////
// TInvioIntra1_2_app
///////////////////////////////////////////////////////////
class TInvioIntra1_2_app : public TSkeleton_application
{
protected:
virtual void main_loop();
};
void TInvioIntra1_2_app::main_loop()
{
TInvioIntra1_2_mask m;
open_files(LF_TABCOM, LF_TAB, LF_CLIFO, LF_INTRA, LF_RINTRA, LF_RIEPRETT, 0);
m.load();
m.set(F_PROGGIORN, 1);
while (m.run() == K_ENTER)
{
const char tip = m.tipo();
if (tip == 'T')
{
m.genera('B', 'C');
m.genera('B', 'A');
m.genera('S', 'C');
m.genera('S', 'A');
}
else
{
m.genera('B', tip);
m.genera('S', tip);
}
}
m.save();
}
int in0200(int argc, char* argv[])
{
TInvioIntra1_2_app a;
a.run(argc, argv, TR("Generazione Intra 1/2"));
return 0;
}