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
		
			
				
	
	
		
			649 lines
		
	
	
		
			19 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			649 lines
		
	
	
		
			19 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | |
| #include <automask.h>
 | |
| #include <progind.h>
 | |
| #include <relation.h>
 | |
| #include <reputils.h>
 | |
| #include <utility.h>
 | |
| 
 | |
| #include "../cg/cglib01.h"
 | |
| #include "../cg/cg2103.h"
 | |
| #include "../cg/cgsaldac.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>
 | |
| 
 | |
| 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
 | |
| {
 | |
| protected:
 | |
|   virtual TObject* key2obj(const char* key);
 | |
| 
 | |
| public:
 | |
|   const TCausale& causale(const char* codice, int annoiva);
 | |
| };
 | |
| 
 | |
| TObject* TCausali_cache::key2obj(const char* key)
 | |
| {
 | |
|   // Metodo bastardo per evitare TToken_string temporanee "a randa"
 | |
|   // sfrutto chiave a lunghezza fissa
 | |
|   const int anno = atoi(key);
 | |
|   const char* codice = key+5;
 | |
|   TCausale* pcaus = new TCausale(codice, anno);
 | |
|   return pcaus;
 | |
| }
 | |
| 
 | |
| const TCausale& TCausali_cache::causale(const char* codice, int annoiva)
 | |
| {
 | |
|   // Metodo bastardo per evitare TToken_string temporanee "a randa"
 | |
|   // creo chiave a lunghezza fissa anno+codice = 9999|AAA
 | |
|   TString8 key;
 | |
|   key.format("%04d|%s", annoiva, codice);
 | |
|   return *(const TCausale*)objptr(key);
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TAutomask
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TImporta_sc_mask : public TAutomask
 | |
| {
 | |
| protected:
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| 
 | |
| public:
 | |
|   TImporta_sc_mask();
 | |
| };
 | |
|   
 | |
| TImporta_sc_mask::TImporta_sc_mask() :TAutomask ("lv4200a")
 | |
| {
 | |
| }  
 | |
| 
 | |
| bool TImporta_sc_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
 | |
| { 
 | |
| 	switch (f.dlg())
 | |
| 	{
 | |
| 		//giochetto per avere la lista dei files validi nella directory di trasferimento!
 | |
| 		case F_NAME:
 | |
| 			if (e == fe_button)
 | |
| 			{
 | |
| 				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());
 | |
| 				TFilename name;
 | |
| 				FOR_EACH_ARRAY_ROW(as.rows_array(), i, row)
 | |
| 				{
 | |
| 					name = *row;
 | |
| 					*row = name.name();
 | |
| 				}
 | |
| 				if (as.run() == K_ENTER)
 | |
| 				{
 | |
| 					f.set(as.row(as.selected()));
 | |
| 				}
 | |
| 			}
 | |
| 			break;
 | |
| 		default:
 | |
| 			break;
 | |
| 	}
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////
 | |
| // TSkeleton_application
 | |
| ///////////////////////////////////////
 | |
| 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, bool can_write);
 | |
| };
 | |
| 
 | |
| const TString& TImporta_sc::find_causale(char tipocf, tipo_movimento tm) const
 | |
| {
 | |
|   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;
 | |
| 	long part = 0;
 | |
| 	char tipocf = ' ';
 | |
| 	long sottoconto = 0L;
 | |
| 	TPartita* game = NULL;
 | |
| 	TToken_string key;
 | |
| 	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 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;
 | |
| 
 | |
|       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
 | |
|         }
 | |
|       }
 | |
| 		}
 | |
| 
 | |
|     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;
 | |
|       }
 | |
|     }
 | |
|   }
 | |
|   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();
 | |
| }
 | |
| 
 | |
| bool TImporta_sc::destroy()
 | |
| {
 | |
| 	delete _msk;
 | |
|   return TApplication::destroy();
 | |
| }
 | |
| 
 | |
| void TImporta_sc::main_loop()
 | |
| {
 | |
|   KEY	tasto;
 | |
| 	tasto = _msk->run();
 | |
|   if (tasto == K_ENTER)
 | |
|   {
 | |
|     //genero il nome del file da caricare
 | |
|     TFilename name = _msk->get(F_PATH);
 | |
|     name.add(_msk->get(F_NAME));
 | |
| 		transfer(name, true);
 | |
|   }   
 | |
| }
 | |
| 
 | |
| int lv4200 (int argc, char* argv[])
 | |
| {
 | |
|   TImporta_sc main_app;
 | |
|   main_app.run(argc, argv, TR("Importazione saldaconto COGECO"));
 | |
|   return true;
 | |
| } |