git-svn-id: svn://10.65.10.50/branches/R_10_00@22767 c028cbd2-c16b-5b4b-a496-9718f37d4682
338 lines
8.5 KiB
C++
338 lines
8.5 KiB
C++
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <progind.h>
|
|
#include <recarray.h>
|
|
#include <relation.h>
|
|
#include <reputils.h>
|
|
#include <textset.h>
|
|
#include <validate.h>
|
|
|
|
#include "tc8.h"
|
|
|
|
#include <clifo.h>
|
|
#include <partite.h>
|
|
#include <scadenze.h>
|
|
#include <pagsca.h>
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TPayLine_recset
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TPayLine_recset : public TCSV_recordset
|
|
{
|
|
public:
|
|
TPayLine_recset() : TCSV_recordset("CSV(;)") {}
|
|
};
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TAutomask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TPayLine_mask : public TAutomask
|
|
{
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
public:
|
|
TPayLine_mask() :TAutomask ("tc8200a") {}
|
|
};
|
|
|
|
bool TPayLine_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
|
{
|
|
switch (f.dlg())
|
|
{
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
///////////////////////////////////////
|
|
// TSkeleton_application
|
|
///////////////////////////////////////
|
|
|
|
class TPayLine_app : public TSkeleton_application
|
|
{
|
|
protected:
|
|
bool find_clifo(long codcf, TPayLine_recset& clienti) const;
|
|
long export_clifo(long codcf, TPayLine_recset& clienti, TLog_report& log) const;
|
|
bool esporta(const TString& dir, const TDate& dt, TLog_report& log) const;
|
|
|
|
public:
|
|
virtual void main_loop();
|
|
};
|
|
|
|
bool TPayLine_app::find_clifo(long codcf, TPayLine_recset& clienti) const
|
|
{
|
|
for (bool ok = clienti.move_first(); ok; ok = clienti.move_next())
|
|
{
|
|
if (clienti.get(0L).as_int() == codcf)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
long TPayLine_app::export_clifo(long codcf, TPayLine_recset& clienti, TLog_report& log) const
|
|
{
|
|
TString8 key; key.format("C|%ld", codcf);
|
|
TRectype rec = cache().get(LF_CLIFO, key);
|
|
|
|
TString msg, str;
|
|
str = rec.get(CLI_RAGSOC);
|
|
str.strip_double_spaces();
|
|
|
|
msg << codcf << ' ' << str << ": ";
|
|
|
|
if (rec.get_bool(CLI_OCCAS))
|
|
{
|
|
msg << TR("OCCASIONALE");
|
|
log.log(1, msg);
|
|
return -1;
|
|
}
|
|
|
|
int alleg = rec.get_int(CLI_ALLEG);
|
|
while (alleg == 4)
|
|
{
|
|
alleg = 0;
|
|
const long altcf = rec.get_long(CLI_CODALLEG);
|
|
if (altcf > 0)
|
|
{
|
|
key.format("C|%ld", codcf);
|
|
rec = cache().get(LF_CLIFO, key);
|
|
if (!rec.empty())
|
|
{
|
|
codcf = altcf;
|
|
alleg = rec.get_int(CLI_ALLEG); // Ok, go on with new code
|
|
}
|
|
}
|
|
}
|
|
|
|
if (alleg >= 2 && alleg != 7)
|
|
{
|
|
switch (alleg)
|
|
{
|
|
case 2: msg << "OCCASIONALE"; break;
|
|
case 5:
|
|
case 9: msg << "ESTERO"; break;
|
|
case 6: msg << "PRIVATO"; break;
|
|
default: msg << "Codice allegato " << alleg; break;
|
|
}
|
|
log.log(1, msg);
|
|
return -2;
|
|
}
|
|
|
|
if (find_clifo(codcf, clienti))
|
|
return codcf; // Already saved
|
|
|
|
TToken_string row(256, ';');
|
|
|
|
row << codcf;
|
|
|
|
str = rec.get(CLI_RAGSOC);
|
|
str.strip_double_spaces(); str.strip(";");
|
|
row.add(str);
|
|
|
|
str = rec.get(CLI_INDCF);
|
|
str << ' ' << rec.get(CLI_CIVCF);
|
|
row.add(str);
|
|
row.add(rec.get(CLI_CAPCF), 3);
|
|
row.add(rec.get(CLI_LOCCF), 4);
|
|
|
|
TString4 stato = rec.get(CLI_STATOPAIV); // ""=Italia; "SM"=San Marino
|
|
|
|
str = rec.get(CLI_PAIV);
|
|
if (str.blank())
|
|
str = rec.get(CLI_COFI);
|
|
if (str.starts_with("SM"))
|
|
{
|
|
stato = "SM";
|
|
str = str.right(5);
|
|
}
|
|
|
|
if (stato != "SM")
|
|
stato = "IT";
|
|
row.add(stato, 6); // Stato partita IVA
|
|
|
|
if (!pi_check(stato, str))
|
|
{
|
|
msg << TR("Partita IVA non valida ") << str;
|
|
log.log(2, msg);
|
|
return -3; // Partita IVA non italiana?
|
|
}
|
|
|
|
if (stato != "SM") // No San Marino!
|
|
{
|
|
row.add(str, 7); // P.I.
|
|
row.add(rec.get(CLI_COFI), 8); // C.F.
|
|
}
|
|
|
|
clienti.new_rec(row);
|
|
return codcf;
|
|
}
|
|
|
|
bool TPayLine_app::esporta(const TString& dir, const TDate& al, TLog_report& log) const
|
|
{
|
|
TDate dal(al);
|
|
dal.set_day(1); // A scanso equivoci bisestili
|
|
dal.addyear(-1);
|
|
|
|
TPayLine_recset clienti;
|
|
TPayLine_recset movimenti;
|
|
|
|
TString query;
|
|
query << "USE SCAD "
|
|
<< "\nJOIN PART INTO TIPOC==TIPOC SOTTOCONTO==SOTTOCONTO ANNO==ANNO NUMPART==NUMPART NRIGA==NRIGA"
|
|
<< "\nFROM TIPOC=C\nTO TIPOC=C";
|
|
TISAM_recordset mov(query);
|
|
const TRectype& scad = mov.cursor()->curr();
|
|
const TRectype& part = mov.cursor()->curr(LF_PARTITE);
|
|
|
|
long lastcf = 0;
|
|
|
|
TProgind pi(mov.items(), log.title());
|
|
TToken_string row(256, ';');
|
|
TString str;
|
|
for (bool ok = mov.move_first(); ok; ok = mov.move_next())
|
|
{
|
|
if (!pi.addstatus(1))
|
|
break;
|
|
|
|
const TDate datascad = scad.get(SCAD_DATASCAD);
|
|
if (scad.get_bool(SCAD_PAGATA) || part.get_bool(PART_CHIUSA))
|
|
{
|
|
if (datascad < dal)
|
|
continue; // Ignora vecchia partita chiusa
|
|
}
|
|
|
|
const long codcf = scad.get_long(SCAD_SOTTOCONTO);
|
|
if (codcf != lastcf)
|
|
{
|
|
lastcf = export_clifo(codcf, clienti, log);
|
|
if (lastcf <= 0)
|
|
continue;
|
|
}
|
|
|
|
str.cut(0) << lastcf; str.right_just(6);
|
|
row.add(str, 0); // Codice cliente
|
|
|
|
str = part.get(PART_DATADOC); // Data Documento
|
|
if (str.blank())
|
|
str = part.get(PART_DATAREG);
|
|
row.add(str, 1);
|
|
|
|
str = part.get(PART_NUMDOC); str.left_just(8);
|
|
row.add(str, 2); // Numero Documento
|
|
|
|
row.add(row.get(1), 3); // Data riferimento
|
|
row.add(row.get(2), 4); // Numero riferimento
|
|
|
|
row.add(part.get(PART_DATAREG), 5); // Data registrazione
|
|
|
|
str = part.get(PART_NREG); str.right_just(7);
|
|
row.add(str, 6); // Numero registrazione
|
|
|
|
row.add(datascad, 7); // Data scadenza
|
|
row.add(scad.get_real(SCAD_IMPORTO).stringa(10,2), 8); // Importo
|
|
row.add(part.get(PART_SEZ), 9); // Dare/Avere
|
|
row.add("EF1#", 10); // Causale Fattura
|
|
|
|
movimenti.new_rec(row);
|
|
|
|
TToken_string key;
|
|
key.format("C|0|0|%ld|%d|%s|%d|%d",
|
|
lastcf, part.get_int(PART_ANNO), (const char*)part.get(PART_NUMPART),
|
|
scad.get_int(SCAD_NRIGA), scad.get_int(SCAD_NRATA));
|
|
TRecord_array pagsca(key, LF_PAGSCA);
|
|
for (int r = pagsca.first_row(); r > 0 && r <= pagsca.last_row(); r = pagsca.succ_row(r))
|
|
{
|
|
const TRectype& pag = pagsca.row(r);
|
|
key.add(r, 6);
|
|
const TRectype& part = cache().get(LF_PARTITE, key);
|
|
|
|
str = part.get(PART_DATADOC); // Data Documento
|
|
if (str.blank())
|
|
str = part.get(PART_DATAREG);
|
|
row.add(str, 1);
|
|
|
|
str = part.get(PART_NUMDOC); str.left_just(8);
|
|
row.add(str, 2); // Numero Documento
|
|
|
|
row.add(part.get(PART_DATAREG), 5); // Data registrazione
|
|
|
|
str = part.get(PART_NREG); str.right_just(7);
|
|
row.add(str, 6); // Numero registrazione
|
|
|
|
const int tm = part.get_int(PART_TIPOMOV);
|
|
|
|
real imp;
|
|
if (tm == 3 && pagsca.rows() == 1 && scad.get_bool(SCAD_PAGATA))
|
|
{
|
|
// Caso semplice: una rata pagata completamene con un solo pagamento
|
|
imp = scad.get_real(SCAD_IMPORTO); // Importo pagato = importo da pagare
|
|
}
|
|
else
|
|
{
|
|
imp = pag.get_real(PAGSCA_IMPORTO);
|
|
if (tm == 3)
|
|
{
|
|
if (pag.get_char(PAGSCA_PASSATT) == 'P')
|
|
imp += pag.get_real(PAGSCA_ABBUONI);
|
|
imp += pag.get_real(PAGSCA_RITENUTE);
|
|
imp += pag.get_real(PAGSCA_RITSOC);
|
|
}
|
|
}
|
|
row.add(imp.stringa(10,2), 8); // Importo
|
|
row.add(part.get(PART_SEZ), 9); // Dare/Avere
|
|
switch (tm)
|
|
{
|
|
case 2: row.add("EF7#", 10); // Nota di credito
|
|
case 5: row.add("EF5#", 10); // Insoluto
|
|
default: row.add("EF6#", 10); // Causale pagamento
|
|
}
|
|
row.add(part.get(PART_DATAPAG), 12); // Data pagamento
|
|
movimenti.new_rec(row);
|
|
}
|
|
}
|
|
|
|
TString msg;
|
|
log.log(0, msg);
|
|
|
|
msg << TR("Esportati ")
|
|
<< movimenti.items() << TR(" movimenti di ")
|
|
<< clienti.items() << TR(" clienti")
|
|
<< TR(" al ") << al;
|
|
log.log(0, msg);
|
|
|
|
TFilename fname = dir; fname.add("PLclienti.txt");
|
|
clienti.save_as(fname);
|
|
|
|
fname = dir; fname.add("PLmovimenti.txt");
|
|
return movimenti.save_as(fname);
|
|
}
|
|
|
|
void TPayLine_app::main_loop()
|
|
{
|
|
TPayLine_mask m;
|
|
while (m.run() == K_ENTER)
|
|
{
|
|
const TString& dir = m.get(101);
|
|
const TDate limit = m.get(102);
|
|
|
|
TString tit;
|
|
tit << title() << " al " << limit;
|
|
TLog_report log(tit);
|
|
log.kill_duplicates();
|
|
|
|
esporta(dir, limit, log);
|
|
log.preview();
|
|
}
|
|
}
|
|
|
|
int tc8200 (int argc, char* argv[])
|
|
{
|
|
TPayLine_app main_app;
|
|
main_app.run(argc, argv, TR("Esportazione PayLine"));
|
|
return 0;
|
|
}
|