Patch level : 10.0
Files correlati : lv4.exe lv4100a.msk Ricompilazione Demo : [ ] Commento : Importazione partite aperte da cogeco git-svn-id: svn://10.65.10.50/trunk@19887 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
f022efeee2
commit
b093ad93fe
@ -15,6 +15,5 @@ int main(int argc, char** argv)
|
||||
default:
|
||||
lv4100(argc, argv); break; //importazione movimenti contabili
|
||||
}
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <utility.h>
|
||||
#include <relation.h>
|
||||
#include <reprint.h>
|
||||
//#include <tabutil.h>
|
||||
|
||||
#include "../cg/cglib01.h"
|
||||
|
||||
@ -38,6 +37,10 @@
|
||||
#define CGC_AVERE_PARTITARIO 14
|
||||
#define CGC_DATAAGG_PARTITARIO 15
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TImporta_cogeco_recset
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
real TImporta_cogeco_recset::get_real(int idx) const
|
||||
{
|
||||
TString80 imp = get(idx).as_string();
|
||||
@ -46,15 +49,23 @@ real TImporta_cogeco_recset::get_real(int idx) const
|
||||
return real(imp);
|
||||
}
|
||||
|
||||
bool TImporta_cogeco_recset::get_bill(TBill& bill) const
|
||||
bool TImporta_cogeco_recset::get_bill(TBill& bill, int idx_gruppo) const
|
||||
{
|
||||
const int g = get(CGC_GRUPPO).as_int();
|
||||
const int c = get(CGC_CONTO).as_int();
|
||||
const long s = get(CGC_SOTTOCONTO).as_int();
|
||||
const int g = get(idx_gruppo).as_int();
|
||||
const int c = get(idx_gruppo+1).as_int();
|
||||
const long s = get(idx_gruppo+2).as_int();
|
||||
bill.set(g, c, s);
|
||||
return bill.ok();
|
||||
}
|
||||
|
||||
TDate TImporta_cogeco_recset::get_date(int idx) const
|
||||
{
|
||||
int gg, mm, aaaa;
|
||||
const TString& str = get(idx).as_string();
|
||||
if (sscanf(str, "%2d/%2d/%4d", &gg, &mm, &aaaa) == 3 && gg > 0 && mm > 0 && aaaa > 2000)
|
||||
return TDate(gg, mm, aaaa);
|
||||
return TDate();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TAutomask
|
||||
@ -198,7 +209,7 @@ void TImporta_saldi::transfer(const TFilename& file)
|
||||
continue;
|
||||
|
||||
TBill bill;
|
||||
if (!s.get_bill(bill))
|
||||
if (!s.get_bill(bill, CGC_GRUPPO))
|
||||
continue;
|
||||
|
||||
if (lastgruppo != bill.gruppo() || nrow >= 99)
|
||||
|
@ -11,7 +11,8 @@ protected:
|
||||
|
||||
public:
|
||||
real get_real(int idx) const;
|
||||
bool get_bill(TBill& bill) const;
|
||||
bool get_bill(TBill& bill, int idx_gruppo) const;
|
||||
TDate get_date(int idx) const;
|
||||
TImporta_cogeco_recset(const char* query = "") : TCSV_recordset(TString("CSV(\";)\n") << query) {}
|
||||
};
|
||||
|
||||
|
602
lv/lv4200.cpp
602
lv/lv4200.cpp
@ -1,44 +1,29 @@
|
||||
#include <applicat.h>
|
||||
#include <automask.h>
|
||||
#include <clifo.h>
|
||||
#include <execp.h>
|
||||
#include <lffiles.h>
|
||||
#include <progind.h>
|
||||
#include <real.h>
|
||||
#include <recarray.h>
|
||||
#include <relation.h>
|
||||
#include <reputils.h>
|
||||
#include <utility.h>
|
||||
#include <relation.h>
|
||||
#include <reprint.h>
|
||||
#include <textset.h>
|
||||
#include <tabutil.h>
|
||||
|
||||
#include "../cg/cglib01.h"
|
||||
#include "../cg/cg2103.h"
|
||||
#include "../cg/cgsaldac.h"
|
||||
#include "../cg/cgpagame.h"
|
||||
|
||||
#include "lv4.h"
|
||||
#include "lv4100.h"
|
||||
#include "lv4200a.h"
|
||||
|
||||
#include <causali.h>
|
||||
#include <rcausali.h>
|
||||
#include <clifo.h>
|
||||
#include <pconti.h>
|
||||
#include <mov.h>
|
||||
#include <rmov.h>
|
||||
#include <rmoviva.h>
|
||||
|
||||
#define CGC_TIPO 0
|
||||
#define CGC_ANNO 1
|
||||
#define CGC_NUMEROPARTITA 2
|
||||
#define CGC_CODCF 3
|
||||
#define CGC_NUMERO REC. 4
|
||||
#define CGC_CAMBIO 5
|
||||
#define CGC_VALUTA 6
|
||||
#define CGC_TIPODOC 7
|
||||
#define CGC_DATA_DOCUM 8
|
||||
#define CGC_SCADENZA 9
|
||||
#define CGC_IMPORTO 10
|
||||
#define CGC_IMPORTO_VAL 11
|
||||
enum CGC_SALDAC { CGC_NULL, CGC_TIPOCF, CGC_ANNO, CGC_NUMPART, CGC_CODCF,
|
||||
CGC_NUMEROREC, CGC_CAMBIO, CGC_VALUTA, CGC_TIPODOC, CGC_DATADOC,
|
||||
CGC_SCADENZA, CGC_IMPORTO, CGC_IMPORTO_VAL };
|
||||
|
||||
class TCausali_cache : public TCache
|
||||
{
|
||||
@ -93,8 +78,7 @@ bool TImporta_sc_mask::on_field_event(TOperable_field& f, TField_event e, long j
|
||||
case F_NAME:
|
||||
if (e == fe_button)
|
||||
{
|
||||
TArray_sheet as(-1, -1, 72, 20, TR("Selezione file"),
|
||||
"File@32");
|
||||
TArray_sheet as(-1, -1, 72, 20, TR("Selezione file"), "File@32");
|
||||
TFilename path = get(F_PATH);
|
||||
path.add("*.txt"); //files delle testate
|
||||
list_files(path, as.rows_array());
|
||||
@ -122,114 +106,518 @@ bool TImporta_sc_mask::on_field_event(TOperable_field& f, TField_event e, long j
|
||||
class TImporta_sc : public TSkeleton_application
|
||||
{
|
||||
TImporta_sc_mask* _msk;
|
||||
|
||||
TCausali_cache _cache_causali;
|
||||
TBill _clienti, _fornitori;
|
||||
|
||||
private:
|
||||
void nuovo_pagamento_o_nota(const TImporta_cogeco_recset& recset, TPartita& game, tipo_movimento tm);
|
||||
|
||||
protected:
|
||||
bool log_error(TLog_report& log, const char* msg, const TRecordset& recset);
|
||||
const TString& find_causale(char tipocf, tipo_movimento tm) const;
|
||||
char get_tmcf(int gruppo, int conto) const;
|
||||
bool find_clifo_bill(char tipocf, int& gruppo, int& conto, long sottoconto) const;
|
||||
|
||||
TRiga_partite& nuova_fattura(const TImporta_cogeco_recset& recset, TPartita& game);
|
||||
void nuova_scadenza(const TImporta_cogeco_recset& recset, TPartita& game);
|
||||
void nuova_riba(const TImporta_cogeco_recset& recset, TPartita& game);
|
||||
void nuovo_pagamento(const TImporta_cogeco_recset& recset, TPartita& game);
|
||||
void nuova_nota_credito(const TImporta_cogeco_recset& recset, TPartita& game);
|
||||
bool nuovo_insoluto(const TImporta_cogeco_recset& recset, TPartita& game, TLog_report& log);
|
||||
void salva_partita(TPartita*& game, bool can_write);
|
||||
|
||||
public:
|
||||
virtual bool create();
|
||||
virtual bool destroy();
|
||||
virtual void main_loop();
|
||||
void transfer(const TFilename& file);
|
||||
|
||||
void transfer(const TFilename& file, bool can_write);
|
||||
};
|
||||
|
||||
void TImporta_sc::transfer(const TFilename& file)
|
||||
const TString& TImporta_sc::find_causale(char tipocf, tipo_movimento tm) const
|
||||
{
|
||||
TImporta_cogeco_recset s(file);
|
||||
TProgind pi(s.items(),"Importazione saldaconto in corso ...",true,true);
|
||||
TConfig* conf = NULL;
|
||||
TString4 codcaus;
|
||||
if (tm == tm_fattura)
|
||||
codcaus = _msk->get(tipocf == 'F' ? F_CODCAUSF : F_CODCAUSC);
|
||||
if (codcaus.blank())
|
||||
{
|
||||
TString query;
|
||||
query << "USE CAUS\nSELECT (TIPOMOV='" << tm << "')&&(RCAUS->TIPOCF='" << tipocf << "')"
|
||||
<< "\nJOIN RCAUS INTO CODCAUS=CODCAUS NRIGA=1";
|
||||
TISAM_recordset caus(query);
|
||||
if (caus.move_first())
|
||||
codcaus = caus.get(CAU_CODCAUS).as_string();
|
||||
}
|
||||
if (codcaus.full())
|
||||
return get_tmp_string() = codcaus;
|
||||
return EMPTY_STRING;
|
||||
}
|
||||
|
||||
char TImporta_sc::get_tmcf(int gruppo, int conto) const
|
||||
{
|
||||
char tmcf = ' ';
|
||||
if (gruppo > 0 && conto > 0)
|
||||
{
|
||||
TString8 key; key.format("%d|%d", gruppo, conto);
|
||||
const TRectype& pcon = cache().get(LF_PCON, key);
|
||||
tmcf = pcon.get_char(PCN_TMCF);
|
||||
}
|
||||
return tmcf;
|
||||
}
|
||||
|
||||
bool TImporta_sc::find_clifo_bill(char tipocf, int& gruppo, int& conto, long sottoconto) const
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
TString8 key;
|
||||
gruppo = conto = 0;
|
||||
|
||||
key.format("%c|%ld", tipocf, sottoconto);
|
||||
const TRectype& clifo = cache().get(LF_CLIFO, key);
|
||||
gruppo = clifo.get_int(CLI_GRUPPO);
|
||||
conto = clifo.get_int(CLI_CONTO);
|
||||
|
||||
found = get_tmcf(gruppo, conto) == tipocf;
|
||||
|
||||
if (!found)
|
||||
{
|
||||
const TString4 codcaus = find_causale(tipocf, tm_fattura);
|
||||
if (codcaus.full())
|
||||
{
|
||||
key.format("%s|1", (const char*)codcaus);
|
||||
const TRectype& rcaus = cache().get(LF_RCAUSALI, key);
|
||||
if (rcaus.get_char(RCA_TIPOCF) == tipocf)
|
||||
{
|
||||
gruppo = rcaus.get_int(RCA_GRUPPO);
|
||||
conto = rcaus.get_int(RCA_CONTO);
|
||||
found = get_tmcf(gruppo, conto) == tipocf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
if (tipocf == 'C')
|
||||
{
|
||||
gruppo = _clienti.gruppo();
|
||||
conto = _clienti.conto();
|
||||
}
|
||||
else
|
||||
{
|
||||
gruppo = _fornitori.gruppo();
|
||||
conto = _fornitori.conto();
|
||||
}
|
||||
found = gruppo > 0 && conto > 0;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
TRiga_partite& TImporta_sc::nuova_fattura(const TImporta_cogeco_recset& recset, TPartita& game)
|
||||
{
|
||||
int nriga = game.prima_fattura();
|
||||
if (game.prima_fattura() <= 0)
|
||||
{
|
||||
TRiga_partite& fattura = game.new_row();
|
||||
|
||||
const TDate datadoc = recset.get_date(CGC_DATADOC);
|
||||
fattura.put(PART_DATAREG, datadoc);
|
||||
fattura.put(PART_DATADOC, datadoc);
|
||||
fattura.put(PART_DESCR, TR("*** Fattura gnerata da COGECO ***"));
|
||||
|
||||
const char tipocf = game.conto().tipo();
|
||||
const TString& codcaus = find_causale(tipocf, tm_fattura);
|
||||
if (codcaus.full())
|
||||
{
|
||||
const TCausale& caus = _cache_causali.causale(codcaus, game.anno());
|
||||
fattura.put(PART_CODCAUS, codcaus);
|
||||
fattura.put(PART_REG, caus.reg().name());
|
||||
fattura.put(PART_TIPOMOV, caus.tipomov());
|
||||
fattura.put(PART_SEZ, caus.sezione(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
fattura.put(PART_TIPOMOV, tm_fattura);
|
||||
fattura.put(PART_SEZ, tipocf == 'C' ? 'D' : 'A');
|
||||
}
|
||||
nriga = fattura.get_int(PART_NRIGA);
|
||||
}
|
||||
|
||||
TRiga_partite& fattura = game.riga(nriga);
|
||||
const real importo = recset.get_real(CGC_IMPORTO);
|
||||
fattura.add(PART_IMPORTO, importo);
|
||||
|
||||
return fattura;
|
||||
}
|
||||
|
||||
void TImporta_sc::nuova_scadenza(const TImporta_cogeco_recset& recset, TPartita& game)
|
||||
{
|
||||
int nriga = game.prima_fattura();
|
||||
if (nriga <= 0)
|
||||
{
|
||||
nuova_fattura(recset, game);
|
||||
nriga = game.prima_fattura();
|
||||
}
|
||||
TRiga_partite& fattura = game.riga(nriga);
|
||||
TRiga_scadenze& scadenza = fattura.new_row();
|
||||
|
||||
const real importo = recset.get_real(CGC_IMPORTO);
|
||||
scadenza.put(SCAD_DATASCAD, recset.get_date(CGC_SCADENZA));
|
||||
scadenza.put(SCAD_IMPORTO, importo);
|
||||
scadenza.put(SCAD_DESCR, TR("*** Rata generata da COGECO ***"));
|
||||
}
|
||||
|
||||
void TImporta_sc::nuovo_pagamento_o_nota(const TImporta_cogeco_recset& recset, TPartita& game, tipo_movimento tm)
|
||||
{
|
||||
TRiga_partite& pagamento = game.new_row();
|
||||
const int nrigp = pagamento.get_int(PART_NRIGA);
|
||||
|
||||
const TDate datadoc = recset.get_date(CGC_DATADOC);
|
||||
pagamento.put(PART_DATAREG, datadoc);
|
||||
pagamento.put(PART_DATADOC, datadoc);
|
||||
if (tm == tm_nota_credito)
|
||||
pagamento.put(PART_DESCR, TR("*** Nota di credito generata da COGECO ***"));
|
||||
else
|
||||
pagamento.put(PART_DESCR, TR("*** Pagamento generato da COGECO ***"));
|
||||
|
||||
const char tipocf = game.conto().tipo();
|
||||
const TString& codcaus = find_causale(tipocf, tm);
|
||||
if (codcaus.full())
|
||||
{
|
||||
const TCausale& caus = _cache_causali.causale(codcaus, game.anno());
|
||||
pagamento.put(PART_CODCAUS, codcaus);
|
||||
pagamento.put(PART_REG, caus.reg().name());
|
||||
pagamento.put(PART_TIPOMOV, caus.tipomov());
|
||||
pagamento.put(PART_SEZ, caus.sezione(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
pagamento.put(PART_TIPOMOV, tm);
|
||||
pagamento.put(PART_SEZ, tipocf == 'F' ? 'A' : 'D');
|
||||
}
|
||||
|
||||
real importo = recset.get_real(CGC_IMPORTO);
|
||||
pagamento.put(PART_IMPORTO, importo);
|
||||
|
||||
const TValuta euro;
|
||||
const int nriga = game.prima_fattura();
|
||||
if (nriga > 0)
|
||||
{
|
||||
const TRiga_partite& fattura = game.riga(nriga);
|
||||
for (int nrata = 1; nrata <= fattura.rate() && !importo.is_zero(); nrata++)
|
||||
{
|
||||
TRiga_scadenze& scadenza = fattura.rata(nrata);
|
||||
const real residuo = scadenza.residuo(false).valore();
|
||||
if (!residuo.is_zero())
|
||||
{
|
||||
const real pagare = residuo > importo ? importo : residuo;
|
||||
TRectype rpag(LF_PAGSCA);
|
||||
const char* const field[] = { PAGSCA_TIPOC, PAGSCA_SOTTOCONTO, PAGSCA_ANNO, PAGSCA_NUMPART,
|
||||
PAGSCA_NRIGA, PAGSCA_NRATA, NULL };
|
||||
for (int k = 0; field[k]; k++)
|
||||
rpag.put(field[k], scadenza.get(field[k]));
|
||||
rpag.put(PAGSCA_NRIGP, nrigp);
|
||||
rpag.put(PAGSCA_IMPORTO, pagare);
|
||||
game.modifica_pagamento(rpag, euro, true);
|
||||
importo -= pagare;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!importo.is_zero())
|
||||
{
|
||||
TRectype rpag(LF_PAGSCA);
|
||||
const char* const field[] = { PAGSCA_TIPOC, PAGSCA_SOTTOCONTO, PAGSCA_ANNO, PAGSCA_NUMPART, NULL };
|
||||
for (int k = 0; field[k]; k++)
|
||||
rpag.put(field[k], pagamento.get(field[k]));
|
||||
rpag.put(PAGSCA_NRIGA, 9999);
|
||||
rpag.put(PAGSCA_NRATA, 9999);
|
||||
rpag.put(PAGSCA_NRIGP, nrigp);
|
||||
rpag.put(PAGSCA_IMPORTO, importo);
|
||||
game.modifica_pagamento(rpag, euro, true);
|
||||
}
|
||||
}
|
||||
|
||||
void TImporta_sc::nuova_riba(const TImporta_cogeco_recset& recset, TPartita& game)
|
||||
{
|
||||
nuova_scadenza(recset, game);
|
||||
nuovo_pagamento(recset, game);
|
||||
}
|
||||
|
||||
void TImporta_sc::nuovo_pagamento(const TImporta_cogeco_recset& recset, TPartita& game)
|
||||
{ nuovo_pagamento_o_nota(recset, game, tm_pagamento); }
|
||||
|
||||
void TImporta_sc::nuova_nota_credito(const TImporta_cogeco_recset& recset, TPartita& game)
|
||||
{ nuovo_pagamento_o_nota(recset, game, tm_nota_credito); }
|
||||
|
||||
bool TImporta_sc::nuovo_insoluto(const TImporta_cogeco_recset& recset, TPartita& game, TLog_report& log)
|
||||
{
|
||||
const int nriga = game.prima_fattura();
|
||||
if (nriga <= 0)
|
||||
return log_error(log, TR("Impossibile associare insoluto"), recset);
|
||||
|
||||
const TDate datadoc = recset.get_date(CGC_DATADOC);
|
||||
const real importo = recset.get_real(CGC_IMPORTO);
|
||||
|
||||
int best_rata = 0, best_score = 0;
|
||||
|
||||
const TRiga_partite& fattura = game.riga(nriga);
|
||||
for (int nrata = fattura.rate(); nrata > 0; nrata--)
|
||||
{
|
||||
const TRiga_scadenze& scadenza = fattura.rata(nrata);
|
||||
const TImporto imp = scadenza.importo_pagato(false);
|
||||
const TDate data = scadenza.get(SCAD_DATASCAD);
|
||||
int score = 0;
|
||||
if (imp.valore() == importo)
|
||||
score++;
|
||||
if (imp.valore() >= importo)
|
||||
score++;
|
||||
if (datadoc == data)
|
||||
score++;
|
||||
if (score > best_score)
|
||||
{
|
||||
best_rata = nrata;
|
||||
best_score = score;
|
||||
}
|
||||
}
|
||||
|
||||
if (best_rata > 0)
|
||||
{
|
||||
const TRiga_scadenze& scadenza = fattura.rata(best_rata);
|
||||
TRiga_partite& insoluto = game.new_row();
|
||||
const int nrigp = insoluto.get_int(PART_NRIGA);
|
||||
|
||||
insoluto.put(PART_DATAREG, datadoc);
|
||||
insoluto.put(PART_DATADOC, datadoc);
|
||||
insoluto.put(PART_DESCR, TR("*** Insoluto trasferito da COGECO ***"));
|
||||
|
||||
const char tipocf = game.conto().tipo();
|
||||
const TString& codcaus = find_causale(tipocf, tm_insoluto);
|
||||
if (codcaus.full())
|
||||
{
|
||||
const TCausale& caus = _cache_causali.causale(codcaus, game.anno());
|
||||
insoluto.put(PART_CODCAUS, codcaus);
|
||||
insoluto.put(PART_REG, caus.reg().name());
|
||||
insoluto.put(PART_TIPOMOV, caus.tipomov());
|
||||
insoluto.put(PART_SEZ, caus.sezione(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
insoluto.put(PART_TIPOMOV, tm_insoluto);
|
||||
insoluto.put(PART_SEZ, fattura.sezione());
|
||||
}
|
||||
insoluto.put(PART_IMPORTO, importo);
|
||||
|
||||
const TValuta euro;
|
||||
TRectype rpag(LF_PAGSCA);
|
||||
const char* const field[] = { PAGSCA_TIPOC, PAGSCA_SOTTOCONTO, PAGSCA_ANNO, PAGSCA_NUMPART,
|
||||
PAGSCA_NRIGA, PAGSCA_NRATA, NULL };
|
||||
for (int k = 0; field[k]; k++)
|
||||
rpag.put(field[k], scadenza.get(field[k]));
|
||||
rpag.put(PAGSCA_NRIGP, nrigp);
|
||||
rpag.put(PAGSCA_IMPORTO, importo);
|
||||
game.modifica_pagamento(rpag, euro, true);
|
||||
}
|
||||
else
|
||||
log_error(log, TR("Impossibile associare insoluto"), recset);
|
||||
|
||||
return best_rata > 0;
|
||||
}
|
||||
|
||||
|
||||
bool TImporta_sc::log_error(TLog_report& log, const char* msg, const TRecordset& recset)
|
||||
{
|
||||
TString message;
|
||||
message << TR("Riga") << ' ' << recset.current_row() << ": " << msg;
|
||||
log.log(2, message);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ordina le righe di partita per TIPOCF+CODCF+ANNO+NUMPART+SCADENZA+TIPODOC
|
||||
static int game_sorter(const TObject** o1, const TObject** o2)
|
||||
{
|
||||
TToken_string& r1 = *(TToken_string*)*o1;
|
||||
TToken_string& r2 = *(TToken_string*)*o2;
|
||||
|
||||
if (r1.get_int(0) != 1)
|
||||
return -1; // Riga testata!
|
||||
if (r2.get_int(0) != 1)
|
||||
return +1; // Riga testata!
|
||||
|
||||
const char tipocf1 = r1.get_char(CGC_TIPOCF);
|
||||
const char tipocf2 = r2.get_char(CGC_TIPOCF);
|
||||
int cmp = tipocf1 - tipocf2;
|
||||
if (cmp != 0)
|
||||
return cmp;
|
||||
|
||||
const long codice1 = r1.get_long(CGC_CODCF);
|
||||
const long codice2 = r2.get_long(CGC_CODCF);
|
||||
cmp = codice1 - codice2;
|
||||
if (cmp != 0)
|
||||
return cmp;
|
||||
|
||||
const int anno1 = r1.get_int(CGC_ANNO);
|
||||
const int anno2 = r2.get_int(CGC_ANNO);
|
||||
cmp = anno1 - anno2;
|
||||
if (cmp != 0)
|
||||
return cmp;
|
||||
|
||||
const int part1 = r1.get_int(CGC_NUMPART);
|
||||
const int part2 = r2.get_int(CGC_NUMPART);
|
||||
cmp = part1 - part2;
|
||||
if (cmp != 0)
|
||||
return cmp;
|
||||
|
||||
const TString data1 = r1.get(CGC_SCADENZA);
|
||||
if (data1.blank() || data1 == "00/00/0000")
|
||||
return -1;
|
||||
const TString data2 = r2.get(CGC_SCADENZA);
|
||||
if (data2.blank() || data2 == "00/00/0000")
|
||||
return +1;
|
||||
|
||||
cmp = TDate(data1)-TDate(data2);
|
||||
if (cmp != 0)
|
||||
return cmp;
|
||||
|
||||
const int tipodoc1 = r1.get_int(CGC_TIPODOC);
|
||||
const int tipodoc2 = r2.get_int(CGC_TIPODOC);
|
||||
cmp = tipodoc1 - tipodoc2;
|
||||
return cmp;
|
||||
}
|
||||
|
||||
void TImporta_sc::salva_partita(TPartita*& game, bool can_write)
|
||||
{
|
||||
if (game != NULL)
|
||||
{
|
||||
if (can_write)
|
||||
{
|
||||
// for (int r = game->last(); r > 0; r = game->pred(r))
|
||||
// game->riga(r).put(PART_IMPTOTDOC, totdoc);
|
||||
game->write();
|
||||
}
|
||||
delete game;
|
||||
game = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void TImporta_sc::transfer(const TFilename& file, bool can_write)
|
||||
{
|
||||
TImporta_cogeco_recset recset(file);
|
||||
recset.sort(game_sorter);
|
||||
recset.save_as("c:/temp/topartite.txt");
|
||||
|
||||
TString caption; _msk->get_caption(caption);
|
||||
TProgind pi(recset.items(), caption, true, true);
|
||||
|
||||
TConfig* conf = NULL;
|
||||
int anno = 0;
|
||||
int part = 0;
|
||||
long part = 0;
|
||||
char tipocf = ' ';
|
||||
long sottoconto = 0L;
|
||||
TPartita* game = NULL;
|
||||
TCausali_cache cache_causali;
|
||||
TToken_string key;
|
||||
const TString4 codcausc(_msk->get(F_CODCAUSC));
|
||||
const TString4 codcausf(_msk->get(F_CODCAUSF));
|
||||
TImporto totdoc;
|
||||
for (bool ok=s.move_to(1);ok;ok=s.move_next())
|
||||
const TString& codcausc = _msk->get(F_CODCAUSC);
|
||||
const TString& codcausf = _msk->get(F_CODCAUSF);
|
||||
|
||||
TLog_report log(caption);
|
||||
|
||||
for (bool ok = recset.move_to(0); ok; ok = recset.move_next())
|
||||
{
|
||||
if (!pi.addstatus(1))
|
||||
break;
|
||||
const int a = s.get(CGC_ANNO).as_int();
|
||||
const long p = s.get(CGC_NUMEROPARTITA).as_int();
|
||||
const char t = s.get(CGC_CODCF).as_string()[0];
|
||||
const long s = s.get(CGC_CODCF).as_int();
|
||||
// leggo tutte le righe di partita e le metto in un array
|
||||
if (anno != a || p != part || tipo != t || sottoconto != s)
|
||||
const int chk = recset.get(CGC_NULL).as_int();
|
||||
if (chk != 1) // Prende solo righe buone!
|
||||
continue;
|
||||
|
||||
const char t = recset.get(CGC_TIPOCF).as_string()[0];
|
||||
const long s = recset.get(CGC_CODCF).as_int();
|
||||
const int a = recset.get(CGC_ANNO).as_int();
|
||||
const long p = recset.get(CGC_NUMPART).as_int();
|
||||
|
||||
if (tipocf != t || sottoconto != s || anno != a || p != part)
|
||||
{
|
||||
salva_partita(game, can_write); // Salva parita corrente se non nulla
|
||||
|
||||
TToken_string key; key.format("%c|%ld", t, s);
|
||||
const TRectype& clifo = cache().get(LF_CLIFO, key);
|
||||
if (clifo.empty())
|
||||
{
|
||||
can_write = log_error(log, TR("Codice Cliente/Fornitore non valido"), recset);
|
||||
continue;
|
||||
}
|
||||
if (a < 2000)
|
||||
{
|
||||
can_write = log_error(log, TR("Anno partita non valido"), recset);
|
||||
continue;
|
||||
}
|
||||
if (p <= 0)
|
||||
{
|
||||
can_write = log_error(log, TR("Numero partita non valido"), recset);
|
||||
continue;
|
||||
}
|
||||
|
||||
tipocf = t;
|
||||
sottoconto = s;
|
||||
anno = a;
|
||||
part = p;
|
||||
tipocf = t;
|
||||
sottoconto = s;
|
||||
|
||||
if (game != NULL)
|
||||
{
|
||||
for (int r = game->first(); r >= 0; r = game->succ(r))
|
||||
game->riga(r).put(PART_IMPTOTDOC, totdoc.valore());
|
||||
game->write();
|
||||
delete game;
|
||||
game = NULL;
|
||||
}
|
||||
totdoc.reset();
|
||||
if (game == NULL)
|
||||
{
|
||||
int gruppo = 0, conto = 0;
|
||||
if (find_clifo_bill(tipocf, gruppo, conto, sottoconto))
|
||||
{
|
||||
const TBill codclifo(gruppo, conto, sottoconto, tipocf);
|
||||
game = new TPartita(codclifo, anno, format("%ld", part));
|
||||
}
|
||||
else
|
||||
{
|
||||
can_write = log_error(log, TR("Impossibile determinare il conto cliente/fornitore"), recset);
|
||||
break; // Esce subito, probabilmente il piano dei conti non e' stato ancora importato
|
||||
}
|
||||
}
|
||||
}
|
||||
TToken_string key;
|
||||
key.cut(0);
|
||||
key.add(tipocf);
|
||||
key.add(sottoconto);
|
||||
const TRectype & clifo = cache().get(LF_CLIFO, key);
|
||||
int gruppo = clifo.get_int(CLI_GRUPPO);
|
||||
int conto = clifo.get_int(CLI_CONTO);
|
||||
const TCausale& c = cache_causali.causale(tipocf == 'C' ? codcausc : codcausf, anno);
|
||||
if (gruppo == 0)
|
||||
{
|
||||
TBill cc;
|
||||
c.bill(1, cc);
|
||||
gruppo = cc.gruppo();
|
||||
conto = cc.conto();
|
||||
}
|
||||
TBill codclifo(gruppo, conto, sottoconto);
|
||||
const int tipodoc = s.get(CGC_TIPODOC).as_int();
|
||||
const TDate datadoc = s.get(CGC_DATA_DOCUM).as_date();
|
||||
if (game == NULL)
|
||||
game = new TPartita(codclifo, anno, format("%7d", part));
|
||||
TRiga_partite& partita = game->new_row();
|
||||
partita.put(PART_TIPOMOV, c.tipomov());
|
||||
partita.put(PART_DATAREG, datadoc);
|
||||
partita.put(PART_DATADOC, datadoc);
|
||||
partita.put(PART_CODCAUS, c.codice());
|
||||
partita.put(PART_REG, c.reg().name());
|
||||
partita.put(PART_SEZ, c.sezione(1));
|
||||
partita.put(PART_SOTTOCONTO, codclifo.sottoconto());
|
||||
const TString8 codpag(clifo.get(CLIFO_CODPAG)); // ?? verificare
|
||||
TPagamento pag(codpag);
|
||||
//partita.put(PART_CODPAG, codpag);
|
||||
partita.put(PART_TIPOPAG, pag.tipo_rata(0));
|
||||
partita.put(PART_GRUPPOCL, codclifo.gruppo());
|
||||
partita.put(PART_CONTOCL, codclifo.conto());
|
||||
|
||||
const real val = s.get(CGC_IMPORTO).as_real();
|
||||
TImporto importo(val.sign() < 0 ? 'A' : 'D', abs(val));
|
||||
importo.normalize(c.sezione(1));
|
||||
totdoc += importo; // somma se e' fattura ??? verificare
|
||||
partita.put(PART_IMPORTO, importo.valore());
|
||||
|
||||
TRiga_scadenze& scadenza = partita.new_row(); // ?? da fare
|
||||
scadenza.put(SCAD_CODPAG, codpag);
|
||||
scadenza.put(SCAD_DATASCAD, s.get(CGC_SCADENZA).as_string());
|
||||
scadenza.put(SCAD_IMPORTO, importo.valore());
|
||||
scadenza.put(SCAD_TIPOPAG, partita.get(PART_TIPOPAG));
|
||||
|
||||
if (game != NULL)
|
||||
{
|
||||
const int tipodoc = recset.get(CGC_TIPODOC).as_int();
|
||||
switch (tipodoc)
|
||||
{
|
||||
case 1: nuova_fattura(recset, *game); break; // Fattura
|
||||
case 2: nuova_nota_credito(recset, *game); break; // Nota di credito
|
||||
case 3: nuova_fattura(recset, *game); break; // Fattura in sospensione
|
||||
case 6: nuovo_insoluto(recset, *game, log); break; // Insoluto
|
||||
case 8: // Tratta
|
||||
case 9: // Ri.Ba.
|
||||
case 10: nuova_riba(recset, *game); break; // Cambiale
|
||||
case 11: nuovo_pagamento(recset, *game); break; // Pagamento
|
||||
case 19: nuova_riba(recset, *game); break; // Avviso di scadenza
|
||||
case 13: nuova_nota_credito(recset, *game); break; // Nota di credito su RB clienti
|
||||
case 15: nuova_scadenza(recset, *game); break;
|
||||
default: log_error(log, TR("Tipo documento non riconosciuto"), recset); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (game != NULL)
|
||||
{
|
||||
for (int r = game->first(); r >= 0; r = game->succ(r))
|
||||
game->riga(r).put(PART_IMPTOTDOC, totdoc.valore());
|
||||
game->write();
|
||||
delete game;
|
||||
}
|
||||
salva_partita(game, can_write); // Salva ultima partita se non nulla
|
||||
|
||||
if (log.recordset()->items() > 0)
|
||||
log.preview();
|
||||
}
|
||||
|
||||
bool TImporta_sc::create()
|
||||
{
|
||||
TString query; query << "USE PCON SELECT TMCF!=\'\'";
|
||||
TISAM_recordset pcon(query);
|
||||
for (bool ok = pcon.move_first(); ok; ok = pcon.move_next())
|
||||
{
|
||||
const TRectype& rec = pcon.cursor()->curr();
|
||||
const char tmcf = rec.get_char(PCN_TMCF);
|
||||
if (tmcf == 'C' && _clienti.gruppo() == 0)
|
||||
_clienti.get(rec);
|
||||
if (tmcf == 'F' && _fornitori.gruppo() == 0)
|
||||
_fornitori.get(rec);
|
||||
}
|
||||
|
||||
_msk = new TImporta_sc_mask();
|
||||
return TSkeleton_application::create();
|
||||
}
|
||||
@ -249,7 +637,7 @@ void TImporta_sc::main_loop()
|
||||
//genero il nome del file da caricare
|
||||
TFilename name = _msk->get(F_PATH);
|
||||
name.add(_msk->get(F_NAME));
|
||||
transfer(name);
|
||||
transfer(name, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ STRING F_CODCAUSC 3
|
||||
BEGIN
|
||||
PROMPT 3 9 "Clienti "
|
||||
FLAGS "UZ"
|
||||
USE LF_CAUSALI
|
||||
USE LF_CAUSALI SELECT TIPOMOV=1
|
||||
INPUT CODCAUS F_CODCAUSC
|
||||
DISPLAY "Codice" CODCAUS
|
||||
DISPLAY "Descrizione@60" DESCR
|
||||
@ -78,7 +78,7 @@ END
|
||||
STRING F_DESCRCAUSC 50
|
||||
BEGIN
|
||||
PROMPT 20 9 ""
|
||||
USE LF_CAUSALI KEY 2
|
||||
USE LF_CAUSALI KEY 2 SELECT TIPOMOV=1
|
||||
INPUT DESCR F_DESCRCAUSC
|
||||
DISPLAY "Descrizione@60" DESCR
|
||||
DISPLAY "Codice" CODCAUS
|
||||
@ -90,7 +90,7 @@ STRING F_CODCAUSF 3
|
||||
BEGIN
|
||||
PROMPT 3 10 "Fornitori "
|
||||
FLAGS "UZ"
|
||||
COPY USE F_CODCAUSC
|
||||
COPY USE F_CODCAUSC
|
||||
INPUT CODCAUS F_CODCAUSF
|
||||
COPY DISPLAY F_CODCAUSC
|
||||
OUTPUT F_CODCAUSF CODCAUS
|
||||
|
Loading…
x
Reference in New Issue
Block a user