Files correlati : Ricompilazione Demo : [ ] Commento : Aggiunta ricezione documenti di vendita e righe documenti di vendita git-svn-id: svn://10.65.10.50/trunk@7104 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1510 lines
		
	
	
		
			43 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1510 lines
		
	
	
		
			43 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <browfile.h>
 | 
						|
#include <filetext.h>
 | 
						|
#include <prefix.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <tabutil.h>
 | 
						|
#include <utility.h>
 | 
						|
#include <viswin.h>
 | 
						|
 | 
						|
#include "ibm36.h"
 | 
						|
 | 
						|
#include <comuni.h>
 | 
						|
#include <cfven.h>
 | 
						|
#include <clifo.h>
 | 
						|
 | 
						|
#define CENTO  100.0
 | 
						|
#define CMILA  100000.0
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TMask36 Maschera principale di selezione
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TMask36 : public TAutomask
 | 
						|
{
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
  TMask36() : TAutomask("ibm36100") { }
 | 
						|
  virtual ~TMask36() { }
 | 
						|
};
 | 
						|
 | 
						|
bool TMask36::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  const short id = o.dlg();
 | 
						|
  switch(id)
 | 
						|
  {
 | 
						|
  case 100: 
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    {
 | 
						|
      if (!fexist(o.get()))
 | 
						|
        return error_box("Directory non valida");
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  default : 
 | 
						|
    if (id > 100 && id < 200)
 | 
						|
    {
 | 
						|
      if (e == fe_modify || e == fe_close)
 | 
						|
      {
 | 
						|
        TFilename name = get(100);
 | 
						|
        name.add(o.get());
 | 
						|
        if (!name.exist())
 | 
						|
          return error_box("File non valido");
 | 
						|
      }
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TBankitalia 
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TBankitalia : public TObject
 | 
						|
{
 | 
						|
  TAssoc_array _bank;
 | 
						|
 | 
						|
public:
 | 
						|
  const TString* codban2abicab(const char* codban);
 | 
						|
  void update();
 | 
						|
 | 
						|
  TBankitalia() { }
 | 
						|
  virtual ~TBankitalia() { }
 | 
						|
};
 | 
						|
 | 
						|
void TBankitalia::update()
 | 
						|
{
 | 
						|
  TTable ban("%BAN");
 | 
						|
  const TRectype& curban = ban.curr();
 | 
						|
 | 
						|
  _bank.destroy();
 | 
						|
  for (int err = ban.first(); err == NOERR; err = ban.next())
 | 
						|
  {
 | 
						|
    TString16 codban = curban.get("S9");
 | 
						|
    if (codban.not_empty())
 | 
						|
    {
 | 
						|
      const TString& abicab = curban.get("CODTAB");
 | 
						|
      _bank.add(codban, abicab);
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
const TString* TBankitalia::codban2abicab(const char* cod)
 | 
						|
{
 | 
						|
  if (_bank.items() == 0)
 | 
						|
    update();
 | 
						|
  const TString* abicab = (const TString*)_bank.objptr(cod);
 | 
						|
  return abicab;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TTrasfer36 Applicazione di importazione dati da IBM36
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TTrasfer36 : public TSkeleton_application  
 | 
						|
{
 | 
						|
  TBankitalia _bankitalia;
 | 
						|
  TAssoc_array _testate;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual void main_loop();
 | 
						|
  virtual const char* extra_modules() const { return "*"; }  // Non e' un modulo normale
 | 
						|
 | 
						|
public:
 | 
						|
  void mask2ini(TMask& m, bool load = FALSE);
 | 
						|
  void ini2mask(TMask& m) { mask2ini(m, TRUE); }
 | 
						|
  
 | 
						|
  const TString& cap2com(const TString& cap, const TString& name) const;
 | 
						|
  void split_indir(const TString& indir, TString& via, TString& civ) const;
 | 
						|
  void mettilavirgola(TFile_text& file, TRecord_text& curr, const char* field, int len, int comma);
 | 
						|
  void permille(TFile_text& file, TRecord_text& curr, const char* field);
 | 
						|
  void machedata(TFile_text& file, TRecord_text& curr, const char* field);
 | 
						|
  void macheseqric(TFile_text& file, TRecord_text& curr, const char* field);
 | 
						|
 | 
						|
  void import_tables(const TFilename& name, TBrowsefile_field& bf);
 | 
						|
  void import_clifor(const TFilename& name, TBrowsefile_field& bf);
 | 
						|
  void import_anaart(const TFilename& name, TBrowsefile_field& bf);
 | 
						|
  void import_condv(const TFilename& name, TBrowsefile_field& bf);
 | 
						|
  void import_movmag(const TFilename& name, TBrowsefile_field& bf);
 | 
						|
  void import_rigmag(const TFilename& name, TBrowsefile_field& bf);
 | 
						|
  void import_docven(const TFilename& name, TBrowsefile_field& bf);
 | 
						|
  void import_rdocven(const TFilename& name, TBrowsefile_field& bf);
 | 
						|
};
 | 
						|
 | 
						|
const TString& TTrasfer36::cap2com(const TString& cap, const TString& name) const
 | 
						|
{
 | 
						|
  if (cap.not_empty())
 | 
						|
  {
 | 
						|
    TString16 str(cap); str.right_just(5, '0');
 | 
						|
    if (str[2] == '1')
 | 
						|
      str.overwrite("00", 3);
 | 
						|
 | 
						|
    TRelation rel(LF_COMUNI);
 | 
						|
    TRectype filter(LF_COMUNI); filter.put(COM_CAPCOM, cap);
 | 
						|
    TCursor comuni(&rel, "", 3, &filter, &filter);
 | 
						|
    const TRecnotype total = comuni.items();
 | 
						|
    if (total > 0)
 | 
						|
    {
 | 
						|
      comuni = 0;
 | 
						|
      if (total > 1)
 | 
						|
      {
 | 
						|
        TRecnotype bestpos = 0L;
 | 
						|
        int bestlen = 0;
 | 
						|
        comuni.freeze(TRUE);
 | 
						|
        for (; comuni.pos() < total; ++comuni)
 | 
						|
        {
 | 
						|
          const TString& dencom = comuni.curr().get(COM_DENCOM);
 | 
						|
          for (int l = 0; toupper(dencom[l]) == toupper(name[l]); l++);
 | 
						|
          if (l > bestlen)
 | 
						|
          {
 | 
						|
            bestlen = l;
 | 
						|
            bestpos = comuni.pos();
 | 
						|
          }
 | 
						|
        }
 | 
						|
        comuni = bestpos;
 | 
						|
      }
 | 
						|
      return comuni.curr().get(COM_COM);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return EMPTY_STRING;
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::split_indir(const TString& indir, TString& via, TString& civ) const
 | 
						|
{
 | 
						|
  const int comma = indir.rfind(',');
 | 
						|
  if (comma > 0)
 | 
						|
  {
 | 
						|
    via = indir.left(comma);
 | 
						|
    civ = indir.mid(comma+1);
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    bool has_digit = FALSE;
 | 
						|
    for (int i = indir.len()-1; i > 0; i--)
 | 
						|
    {
 | 
						|
      if (has_digit)
 | 
						|
      {
 | 
						|
        if (indir[i] == ' ')
 | 
						|
          break;
 | 
						|
      }
 | 
						|
      else
 | 
						|
      {
 | 
						|
        if (isdigit(indir[i]))
 | 
						|
          has_digit = TRUE;
 | 
						|
      }
 | 
						|
    }
 | 
						|
    if (i > 0 && has_digit)
 | 
						|
    {
 | 
						|
      via = indir.left(i);
 | 
						|
      civ = indir.mid(i+1);
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  if (via.empty())
 | 
						|
  {
 | 
						|
    via = indir;
 | 
						|
    civ.cut(0);
 | 
						|
  }
 | 
						|
 | 
						|
  via.cut(35);
 | 
						|
  civ.cut(10);
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::import_tables(const TFilename& name, TBrowsefile_field& bf)
 | 
						|
{
 | 
						|
  TString msg;
 | 
						|
  msg = "Importazione tabelle vendite";
 | 
						|
 | 
						|
  TProgind pi(::fsize(name), msg, TRUE, TRUE);
 | 
						|
  long valid = 0;
 | 
						|
 | 
						|
  msg.insert("@b", 0);
 | 
						|
  msg << " dal file " << name;
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
 | 
						|
  TFile_text file(name, "ibm36tab.ini");
 | 
						|
  
 | 
						|
  TTable ban("%BAN");
 | 
						|
  
 | 
						|
  TRecord_text curr;
 | 
						|
  while (file.read(curr) == NOERR)
 | 
						|
  {
 | 
						|
    pi.setstatus(file.read_file()->tellg());
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
    
 | 
						|
    const TString& type = curr.type();
 | 
						|
    if (type == "A26") // Tabella banche
 | 
						|
    {
 | 
						|
      const TString& ann = file.get_field(curr, "ANNULLATO");
 | 
						|
      if (ann != "A")
 | 
						|
      {
 | 
						|
        msg = "Importazione tabelle vendite - Record validi: ";
 | 
						|
        msg << ++valid;
 | 
						|
        pi.set_text(msg);
 | 
						|
 | 
						|
        TString16 cod = file.get_field(curr, "CODICE");
 | 
						|
        TString16 abi = file.get_field(curr, "ABI");
 | 
						|
        TString16 cab = file.get_field(curr, "CAB");
 | 
						|
        if (abi.empty() || cab.empty())
 | 
						|
        {
 | 
						|
          if (abi.empty()) 
 | 
						|
            abi = "99999";
 | 
						|
          if (cab.empty()) 
 | 
						|
          { 
 | 
						|
            const TString* abicab = _bankitalia.codban2abicab(cod);
 | 
						|
            if (abicab != NULL)
 | 
						|
            {
 | 
						|
              abi = abicab->left(5);
 | 
						|
              cab = abicab->mid(5);
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
              ban.last();
 | 
						|
              const TString16 abicab = ban.get("CODTAB");
 | 
						|
              if (abicab.left(5) == "99999")
 | 
						|
              {
 | 
						|
                long numcab = atol(abicab.mid(5)) + 1;
 | 
						|
                cab.format("%05ld", numcab);
 | 
						|
              }
 | 
						|
              else
 | 
						|
                cab = "00001";
 | 
						|
            }
 | 
						|
          }
 | 
						|
        }
 | 
						|
        abi.right_just(5, '0');
 | 
						|
        cab.right_just(5, '0');
 | 
						|
 | 
						|
        TString16 codtab;
 | 
						|
        codtab = abi;
 | 
						|
        ban.put("CODTAB", codtab);
 | 
						|
        if (ban.read() != NOERR)
 | 
						|
        {
 | 
						|
          msg = "- Creazione dell'istituto fittizio ";
 | 
						|
          msg << abi;
 | 
						|
          bf.add_line(msg);
 | 
						|
 | 
						|
          ban.put("CODTAB", codtab);
 | 
						|
          ban.put("S0", "Banca per trasferimenti IBM36");
 | 
						|
          ban.write();
 | 
						|
        }
 | 
						|
 | 
						|
        codtab << cab;
 | 
						|
        ban.put("CODTAB", codtab);
 | 
						|
        if (ban.read() == NOERR)
 | 
						|
        {
 | 
						|
          ban.put("S9", cod);
 | 
						|
          ban.rewrite();
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
          msg = "! La banca ";
 | 
						|
          msg << cod << " non dispone di un codice ABI/CAB valido";
 | 
						|
          bf.add_line(msg);
 | 
						|
          msg = "- Verra' creata la banca fittizia ";
 | 
						|
          msg << abi << ' ' << cab;
 | 
						|
          bf.add_line(msg);
 | 
						|
 | 
						|
          ban.put("CODTAB", codtab);
 | 
						|
          ban.put("S0", file.get_field(curr, "RAGSOC"));
 | 
						|
          ban.put("S9", cod);
 | 
						|
 | 
						|
          const TString& cap = file.get_field(curr, "CAP");
 | 
						|
          ban.put("S3", cap);
 | 
						|
 | 
						|
          const TString& loc = file.get_field(curr, "LOCALITA");
 | 
						|
          ban.put("S1", loc);
 | 
						|
 | 
						|
          const TString& com = cap2com(cap, loc);
 | 
						|
          ban.put("S5", com);
 | 
						|
 | 
						|
          const TString& ind = file.get_field(curr, "INDIRIZZO");
 | 
						|
          TString via, civ;
 | 
						|
          split_indir(ind, via, civ);
 | 
						|
          ban.put("S2", via);
 | 
						|
          ban.put("S7", civ);    
 | 
						|
 | 
						|
          ban.write();
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
    else
 | 
						|
      if (type == "A11" || type == "A27") // File testate listini(A11) e contratti (A27)
 | 
						|
      {
 | 
						|
        const TString& ann = file.get_field(curr, "ANNULLATO");
 | 
						|
        if (ann != "A")
 | 
						|
        {
 | 
						|
          file.add_field(curr, "TIPO", type == "A11" ? "L" : "C");
 | 
						|
 | 
						|
          if (type == "A27") // ..trattasi di contratti...
 | 
						|
          {
 | 
						|
            const int tcf = atoi(file.get_field(curr, "TIPO ANAGRAFICA"));
 | 
						|
            file.add_field(curr, "TIPO ANAGRAFICA", tcf == 1 ? "C" : "F");
 | 
						|
          }
 | 
						|
          mettilavirgola(file, curr, "CAMBIO", 11, 5);
 | 
						|
          machedata(file, curr, "INIZIO VALIDITA");
 | 
						|
          machedata(file, curr, "FINE VALIDITA");
 | 
						|
          machedata(file, curr, "DATA CAMBIO");
 | 
						|
          macheseqric(file, curr, "SEQUENZA RICERCA");
 | 
						|
          const int err = file.autosave(curr);
 | 
						|
          if (err != NOERR)
 | 
						|
          {
 | 
						|
            msg = "! Errore di scrittura sul file LF_CONDV: ";
 | 
						|
            msg << err;
 | 
						|
            bf.add_line(msg);
 | 
						|
          }
 | 
						|
          else
 | 
						|
            valid++;
 | 
						|
        }
 | 
						|
      }
 | 
						|
  }
 | 
						|
 | 
						|
  _bankitalia.update();
 | 
						|
 | 
						|
  msg = "Record importati: ";
 | 
						|
  msg << valid;
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::mettilavirgola(TFile_text& file, TRecord_text& curr, const char* field, int len, int comma)
 | 
						|
{
 | 
						|
  TString80 num = file.get_field(curr, field);
 | 
						|
  if (!real::is_null(num))
 | 
						|
  {
 | 
						|
    num.right_just(len, '0');
 | 
						|
    num.insert(".", len - comma);
 | 
						|
    file.add_field(curr, field, num);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::permille(TFile_text& file, TRecord_text& curr, const char* field)
 | 
						|
{
 | 
						|
  TString80 num = file.get_field(curr, field);
 | 
						|
  if (!real::is_null(num))
 | 
						|
  {
 | 
						|
    num << "000";
 | 
						|
    file.add_field(curr, field, num);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::macheseqric(TFile_text& file, TRecord_text& curr, const char* field)
 | 
						|
{
 | 
						|
  TString16 seq(file.get_field(curr, field));
 | 
						|
  const int l = seq.len();
 | 
						|
  for (int i=0; i<l; i++)
 | 
						|
    switch(seq[i])
 | 
						|
    {
 | 
						|
      case '1':
 | 
						|
        seq[i] = 'A';
 | 
						|
      break;
 | 
						|
      case '2':
 | 
						|
        seq[i] = 'G';
 | 
						|
      break;
 | 
						|
      case '3':
 | 
						|
        seq[i] = 'S';
 | 
						|
      break;
 | 
						|
      case '4':
 | 
						|
        seq[i] = 'R';
 | 
						|
      break;
 | 
						|
      default:
 | 
						|
        seq[i] = '-';
 | 
						|
      break;
 | 
						|
    }
 | 
						|
  for (i=l; i<4; i++)
 | 
						|
    seq << '-'; // Padding...
 | 
						|
  file.add_field(curr, field, seq);
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::machedata(TFile_text& file, TRecord_text& curr, const char* field)
 | 
						|
{
 | 
						|
  TString80 num = file.get_field(curr, field);
 | 
						|
  if (!real::is_null(num))
 | 
						|
  {
 | 
						|
    switch (num.len())
 | 
						|
    {
 | 
						|
    case 6:
 | 
						|
      {
 | 
						|
        num.insert("19", 0);
 | 
						|
        const TDate data(atol(num));
 | 
						|
        file.add_field(curr, field, data.string());
 | 
						|
      }
 | 
						|
      break;
 | 
						|
    case 7:    
 | 
						|
      {
 | 
						|
        const int secolo = num[0] - '0';
 | 
						|
        long ansidata = atol(num.mid(1));
 | 
						|
        ansidata += (19 + secolo) * 1000000L;
 | 
						|
        const TDate data(ansidata);
 | 
						|
        file.add_field(curr, field, data.string());
 | 
						|
      }
 | 
						|
      break;
 | 
						|
    case 8:
 | 
						|
      num.insert("-", 4);
 | 
						|
      num.insert("-", 2);
 | 
						|
      file.add_field(curr, field, num);
 | 
						|
      break;
 | 
						|
    default:
 | 
						|
      break;
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::import_clifor(const TFilename& name, TBrowsefile_field& bf)
 | 
						|
{
 | 
						|
  TAssoc_array missing_firm;
 | 
						|
  TString msg;
 | 
						|
  long valid = 0;
 | 
						|
  
 | 
						|
  msg = "Importazione Clienti/Fornitori";
 | 
						|
  TProgind pi(::fsize(name), msg, TRUE, TRUE);
 | 
						|
  TFile_text file(name, "ibm36cf.ini");
 | 
						|
 | 
						|
  msg.insert("@b", 0);
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
 | 
						|
  TRelation rel(LF_CLIFO); rel.add(LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF");
 | 
						|
  
 | 
						|
  TRecord_text curr;
 | 
						|
  while (file.read(curr) == NOERR)
 | 
						|
  {
 | 
						|
    pi.setstatus(file.read_file()->tellg());
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
 | 
						|
    const int tipo_record = curr.type()[0] - '0';
 | 
						|
    if (tipo_record >= 1 && tipo_record <= 6)
 | 
						|
    {
 | 
						|
      const char stato_record = file.get_field(curr, "ANNULLATO")[0];
 | 
						|
      if (stato_record == 'A')
 | 
						|
        continue;
 | 
						|
 | 
						|
      const long ditta = atol(file.get_field(curr, "DITTA"));
 | 
						|
      if (prefix().get_codditta() != ditta)
 | 
						|
      {
 | 
						|
        if (prefix().exist(ditta))
 | 
						|
          prefix().set_codditta(ditta);
 | 
						|
        else
 | 
						|
        {
 | 
						|
          msg.format("%ld", ditta);
 | 
						|
          if (missing_firm.objptr(msg) == NULL)
 | 
						|
          {
 | 
						|
            missing_firm.add(msg, msg);
 | 
						|
            msg.insert("Non esiste la ditta ", 0);
 | 
						|
            msg << ": Effettuare il trasferimento della contabilita'";
 | 
						|
            bf.add_line(msg);
 | 
						|
          }
 | 
						|
          continue;
 | 
						|
        }
 | 
						|
      }
 | 
						|
 | 
						|
      const char* tipocf = (tipo_record & 0x1) ? "C" : "F";
 | 
						|
      const long codcf  = atol(file.get_field(curr, "CODCF"));
 | 
						|
      TString16 extcf; 
 | 
						|
      extcf << (*tipocf == 'C' ? "cliente" : "fornitore") << ' ' << codcf;
 | 
						|
 | 
						|
      TLocalisamfile& clifo = rel.lfile();
 | 
						|
      clifo.put(CLI_TIPOCF, tipocf);
 | 
						|
      clifo.put(CLI_CODCF, codcf);
 | 
						|
      int err = clifo.read();
 | 
						|
      if (err == NOERR)
 | 
						|
      {
 | 
						|
        file.add_field(curr, "TIPOCF", tipocf);
 | 
						|
      }
 | 
						|
 | 
						|
      switch(tipo_record)
 | 
						|
      {
 | 
						|
      case  1:
 | 
						|
      case  2:
 | 
						|
        if (err != NOERR)
 | 
						|
        {
 | 
						|
          msg = "! Non esiste il ";
 | 
						|
          msg << extcf;
 | 
						|
          bf.add_line(msg);
 | 
						|
          msg = "- Inserimento di ";
 | 
						|
          msg << file.get_field(curr, "COGNOME") << file.get_field(curr, "NOME");
 | 
						|
          bf.add_line(msg);
 | 
						|
 | 
						|
          rel.write_enable(LF_CFVEN, FALSE);
 | 
						|
          const int err = file.autosave(rel, curr);
 | 
						|
          if (err != NOERR)
 | 
						|
          {
 | 
						|
            msg = "! Errore di scrittura sul file LF_CLIFO: ";
 | 
						|
            msg << err;
 | 
						|
            bf.add_line(msg);
 | 
						|
          }
 | 
						|
        }
 | 
						|
        break;
 | 
						|
      case  3:
 | 
						|
        if (err == NOERR)
 | 
						|
        {
 | 
						|
          TString cod = file.get_field(curr, "CODICE BANCA D'APPOGGIO");
 | 
						|
          if (!cod.blank())
 | 
						|
          {
 | 
						|
            const TString* abicab = _bankitalia.codban2abicab(cod);
 | 
						|
            if (abicab)
 | 
						|
            {
 | 
						|
              rel.curr().put(CLI_CODABI, abicab->left(5));
 | 
						|
              rel.curr().put(CLI_CODCAB, abicab->mid(5));
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
              msg = "Ipossibile determinare l'ABI/CAB della banca d'appoggio ";
 | 
						|
              msg << cod << " del " << extcf;
 | 
						|
              bf.add_line(msg);
 | 
						|
            }
 | 
						|
          }
 | 
						|
         
 | 
						|
          cod = file.get_field(curr, "CODICE BANCA PRESENTAZIONE EFFETTI");
 | 
						|
          if (!cod.blank())
 | 
						|
          {
 | 
						|
            const TString* abicab = _bankitalia.codban2abicab(cod);
 | 
						|
            if (abicab)
 | 
						|
            {
 | 
						|
              rel.curr(LF_CFVEN).put(CFV_CODABIPR, abicab->left(5));
 | 
						|
              rel.curr(LF_CFVEN).put(CFV_CODCABPR, abicab->mid(5));
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
              msg = "Ipossibile determinare l'ABI/CAB della banca di presentazione ";
 | 
						|
              msg << cod << " del " << extcf;
 | 
						|
              bf.add_line(msg);
 | 
						|
            }
 | 
						|
          }
 | 
						|
 | 
						|
          mettilavirgola(file, curr, "PROVVIGIONE AGENTE", 5, 2);
 | 
						|
          permille(file, curr, "IMPORTO MINIMO EFFETTI");
 | 
						|
          machedata(file, curr, "DATA INIZIO RID");
 | 
						|
          machedata(file, curr, "DATA REVOCA RID");
 | 
						|
 | 
						|
          rel.write_enable(LF_CFVEN);
 | 
						|
          const int err = file.autosave(rel, curr);
 | 
						|
          if (err != NOERR)
 | 
						|
          {
 | 
						|
            msg = "! Errore di scrittura sul file LF_CFVEN: ";
 | 
						|
            msg << err;
 | 
						|
            bf.add_line(msg);
 | 
						|
          }
 | 
						|
          else
 | 
						|
            valid++;
 | 
						|
        }
 | 
						|
        break;
 | 
						|
      case 5:
 | 
						|
        if (err != NOERR)
 | 
						|
        {
 | 
						|
          machedata(file, curr, "DATA INVIO ULTIMO ESTRATTO CONTO");
 | 
						|
          machedata(file, curr, "DATA INVIO ULTIMO SOLLECITO");
 | 
						|
          permille(file, curr, "FIDO");
 | 
						|
 | 
						|
          rel.write_enable(LF_CFVEN);
 | 
						|
          const int err = file.autosave(rel, curr);
 | 
						|
          if (err != NOERR)
 | 
						|
          {
 | 
						|
            msg = "! Errore di scrittura sul file LF_CFVEN: ";
 | 
						|
            msg << err;
 | 
						|
            bf.add_line(msg);
 | 
						|
          }
 | 
						|
          else
 | 
						|
            valid++;
 | 
						|
        }
 | 
						|
        break;
 | 
						|
      default: break;// Ignored
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  msg = "Record importati: ";
 | 
						|
  msg << valid;
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::import_anaart(const TFilename& name, TBrowsefile_field& bf)
 | 
						|
{
 | 
						|
  TArray languages; // Massimo 4 lingue... corrispondono in modo fisso
 | 
						|
  TMask msk_lng("ibm36101");
 | 
						|
  TString msg, des, codart, um;
 | 
						|
  TString16 codlin;
 | 
						|
  real r;
 | 
						|
  msg = "Importazione Anagrafica articoli";
 | 
						|
  TProgind pi(::fsize(name), msg, TRUE, TRUE);
 | 
						|
  TFile_text file(name, "ibm36art.ini");
 | 
						|
  long valid = 0;
 | 
						|
  int nriga;
 | 
						|
  
 | 
						|
  languages.add(new TString); languages.add(new TString);
 | 
						|
  languages.add(new TString); languages.add(new TString); // Max 4 linguacciones
 | 
						|
 | 
						|
  msg.insert("@b", 0);
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
  TRelation rel(LF_ANAMAG); 
 | 
						|
  rel.add(LF_UMART,"CODART=CODART");
 | 
						|
  TLocalisamfile deslin(LF_DESLIN);
 | 
						|
  
 | 
						|
  TRecord_text curr;
 | 
						|
  while (file.read(curr) == NOERR)
 | 
						|
  {
 | 
						|
    pi.setstatus(file.read_file()->tellg());
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
 | 
						|
 | 
						|
    const int tipo_record = curr.type()[0] - '0';
 | 
						|
    if (tipo_record == 0) // Anagrafica articoli
 | 
						|
    {
 | 
						|
      const char stato_record = file.get_field(curr, "ANNULLATO")[0];
 | 
						|
      if (stato_record == 'A')
 | 
						|
        continue;
 | 
						|
      des = file.get_field(curr, "DESCRIZIONE ARTICOLO");
 | 
						|
      des << " ";
 | 
						|
      des << file.get_field(curr, "ESTENSIONE DESCRIZIONE");
 | 
						|
      des.strip_d_spaces();
 | 
						|
      file.add_field(curr, "DESCRIZIONE ARTICOLO", des);
 | 
						|
      
 | 
						|
      mettilavirgola(file, curr, "COSTO STANDARD", 11, 2);
 | 
						|
      mettilavirgola(file, curr, "TARA", 7, 2);
 | 
						|
      mettilavirgola(file, curr, "PESO", 7, 2);
 | 
						|
      mettilavirgola(file, curr, "PERCENTUALE PROVVIGIONE", 5, 2);
 | 
						|
      mettilavirgola(file, curr, "PERCENTUALE SCONTO", 5, 2);
 | 
						|
 | 
						|
      int err = file.autosave(rel, curr);
 | 
						|
      if (err != NOERR)
 | 
						|
      {
 | 
						|
        msg = "! Errore di scrittura sul file LF_ANAMAG: ";
 | 
						|
        msg << err;
 | 
						|
        bf.add_line(msg);
 | 
						|
      }
 | 
						|
      else 
 | 
						|
        valid++;
 | 
						|
      codart = file.get_field(curr, "CODICE PRIMARIO");
 | 
						|
      TLocalisamfile& umart = rel.lfile(LF_UMART);
 | 
						|
      
 | 
						|
      for (int nriga = 1; nriga <=3; nriga++)
 | 
						|
      {
 | 
						|
        umart.put("CODART",codart);
 | 
						|
        umart.put("NRIGA",nriga);
 | 
						|
        if (nriga == 1)
 | 
						|
        {
 | 
						|
          umart.put("FC", "1.00");
 | 
						|
          um = file.get_field(curr,"UNITA DI MISURA");
 | 
						|
          r = real(file.get_field(curr,"PREZZO VENDITA")) / CENTO;
 | 
						|
          umart.put("PREZZO", r);
 | 
						|
        }
 | 
						|
        else
 | 
						|
          if (nriga == 2)
 | 
						|
          {
 | 
						|
            r = real(file.get_field(curr, "COEFFICIENTE CONVERSIONE 2")) / CMILA;
 | 
						|
            umart.put("FC", r);
 | 
						|
            um = file.get_field(curr,"SECONDA UNITA DI MISURA");
 | 
						|
          }
 | 
						|
          else
 | 
						|
          {
 | 
						|
            r = real(file.get_field(curr, "COEFFICIENTE CONVERSIONE 3")) / CMILA;
 | 
						|
            umart.put("FC", r);
 | 
						|
            um = file.get_field(curr,"TERZA UNITA DI MISURA");
 | 
						|
          }
 | 
						|
        umart.put("UM", um);
 | 
						|
        if (umart.write() != NOERR)
 | 
						|
          err = umart.rewrite();
 | 
						|
        if (err != NOERR)
 | 
						|
        {
 | 
						|
          msg.format("! Errore di scrittura sul file LF_UMART, articolo %s, UM %s: %d", (const char*) codart, (const char*) um, err);
 | 
						|
          bf.add_line(msg);
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
    else
 | 
						|
      if (tipo_record >= 1 && tipo_record <= 4) // Descrizioni in lingua
 | 
						|
      {
 | 
						|
        const char stato_record = file.get_field(curr, "ANNULLATO")[0];
 | 
						|
        if (stato_record == 'A')
 | 
						|
          continue;
 | 
						|
        // Il tipo record corrisponde ad una lingua fissa... ogni volta che se ne incontra una
 | 
						|
        // nuova si chiede all'utente in input a quale lingua corrisponde su EuroCAMPO
 | 
						|
        codlin = (TString&) languages[tipo_record-1];
 | 
						|
        if (codlin.empty()) // Non esiste la corrispondenza? La chiedo all'utente...
 | 
						|
        {
 | 
						|
          msk_lng.set(100, (long)tipo_record);
 | 
						|
          msk_lng.run();
 | 
						|
          codlin = msk_lng.get(101);
 | 
						|
          languages.add(codlin, tipo_record-1); // lo memorizzo al posto di quello vuoto
 | 
						|
        }
 | 
						|
        nriga = 1;
 | 
						|
        codart = file.get_field(curr, "CODICE PRIMARIO");
 | 
						|
        des = file.get_field(curr, "DESCRIZIONE");
 | 
						|
        des << " ";
 | 
						|
        des << file.get_field(curr, "ESTENSIONE DESCRIZIONE");
 | 
						|
        des.strip_d_spaces();
 | 
						|
        deslin.put("CODART", codart);
 | 
						|
        deslin.put("DESCR", des);
 | 
						|
        deslin.put("CODLIN", codlin);
 | 
						|
        deslin.put("NRIGA", nriga);
 | 
						|
        // Aggiunge sempre in coda perche' gli articoli possono essere mischiati
 | 
						|
        // al massimo pero' le lingue sono 4...
 | 
						|
        int err = NOERR;
 | 
						|
        while ((err = deslin.write()) == _isreinsert && nriga < 4)
 | 
						|
        {
 | 
						|
          nriga++;
 | 
						|
          deslin.put("NRIGA", nriga);
 | 
						|
        }
 | 
						|
        if (err == _isreinsert)  // Se non e' riuscito ad aggiungerlo... forza la riscrittura al tipo_record...
 | 
						|
        {
 | 
						|
          deslin.put("NRIGA", tipo_record); // Non importa se i numeri riga non saranno esattamente in sequenza
 | 
						|
          err = deslin.rewrite();           // perche' i record array leggono ugualmente
 | 
						|
        }
 | 
						|
        //const int err = file.autosave(curr);
 | 
						|
        if (err != NOERR)
 | 
						|
        {
 | 
						|
          msg = "! Errore di scrittura sul file LF_DESLIN: ";
 | 
						|
          msg << err;
 | 
						|
          bf.add_line(msg);
 | 
						|
        }
 | 
						|
        else
 | 
						|
          valid++;
 | 
						|
      }
 | 
						|
  }
 | 
						|
  
 | 
						|
  // Messaggio finale di elaborazione
 | 
						|
  msg = "Record importati: ";
 | 
						|
  msg << valid;
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::import_condv(const TFilename& name, TBrowsefile_field& bf)
 | 
						|
{
 | 
						|
  TMask msk_prm("ibm36102");
 | 
						|
  TString msg,des,cod, camp_seq_ric;
 | 
						|
  bool camp_um, camp_sca, camp_sco;
 | 
						|
  msg = "Importazione Condizioni di vendita";
 | 
						|
  TProgind pi(::fsize(name), msg, TRUE, TRUE);
 | 
						|
  TFile_text file(name, "ibm36cvn.ini");
 | 
						|
  long valid = 0;
 | 
						|
 | 
						|
  msg.insert("@b", 0);
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
 | 
						|
  TRelation rel(LF_RCONDV);
 | 
						|
  rel.add(LF_CONDV,"TIPO==TIPO|CATVEN==CATVEN|TIPOCF==TIPOCF|CODCF==CODCF|COD==COD");
 | 
						|
  TLocalisamfile& rcondv = rel.lfile();
 | 
						|
  TLocalisamfile& condv= rel.lfile(LF_CONDV);
 | 
						|
  
 | 
						|
  TRecord_text curr;
 | 
						|
  while (file.read(curr) == NOERR)
 | 
						|
  {
 | 
						|
    pi.setstatus(file.read_file()->tellg());
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
    
 | 
						|
    const char tipo_record = curr.type()[0];
 | 
						|
    int err = NOERR;
 | 
						|
 | 
						|
    if (tipo_record >= 'A' && tipo_record <= 'F')
 | 
						|
    {
 | 
						|
      const char stato_record = file.get_field(curr, "ANNULLATO")[0];
 | 
						|
      if (stato_record == 'A') // ANNULLATO is always defined for records A through F
 | 
						|
        continue;
 | 
						|
      file.add_field(curr, "TIPO ARCHIVIO", "A");      // E' sempre tipo <A>rticolo 
 | 
						|
    }
 | 
						|
    switch (tipo_record)
 | 
						|
    {
 | 
						|
      case 'A': // Righe listini. Non necessitano di scrittura testata
 | 
						|
      case 'B':
 | 
						|
        file.add_field(curr, "TIPO", "L"); // Sostituisce
 | 
						|
        if (tipo_record == 'A')
 | 
						|
        {
 | 
						|
          mettilavirgola(file, curr, "QTA LIMITE SCAGLIONE", 11, 3);
 | 
						|
          mettilavirgola(file, curr, "PREZZO VENDITA", 11, 2);
 | 
						|
          mettilavirgola(file, curr, "PERCENTUALE SCONTO", 5, 2);
 | 
						|
          mettilavirgola(file, curr, "PERCENTUALE PROVVIGIONE", 5, 2);
 | 
						|
          mettilavirgola(file, curr, "QTA MERCE SCONTATA", 9, 3);
 | 
						|
          // Scrive o aggiorna tranquillamente i record di tipo "A", se vi sono
 | 
						|
          // record omaggio vengono dopo, (cfr FLAG PRESENZA ARTICOLO OMAGGIO)
 | 
						|
          err = file.autosave(rel, curr); 
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
          mettilavirgola(file, curr, "PREZZO ARTICOLO OMAGGIO IN LIRE", 11, 2);
 | 
						|
          // Uff... in sto caso dobbiamo prima leggere il record corrispondente
 | 
						|
          // e se esiste assegnare solo i campi da aggiornare:
 | 
						|
          // CODARTOM CODLOTTO ADDIVA UMOM PROMAGGIO
 | 
						|
          rcondv.put("TIPO", "L");
 | 
						|
          rcondv.put("CATVEN", file.get_field(curr,"CATEGORIA VENDITE"));
 | 
						|
          rcondv.put("COD", file.get_field(curr,"CODICE LISTINO"));
 | 
						|
          rcondv.put("TIPORIGA", "A"); // See above... 
 | 
						|
          rcondv.put("CODRIGA", file.get_field(curr,"CHIAVE RIGA"));
 | 
						|
          rcondv.put("UM", file.get_field(curr,"UNITA MISURA"));
 | 
						|
          rcondv.put("NSCAGL", file.get_field(curr,"NUMERO SCAGLIONE"));
 | 
						|
          
 | 
						|
          if (rcondv.read() == NOERR) // Se esiste il record lo aggiorna...
 | 
						|
          {
 | 
						|
            rcondv.put("CODARTOM", file.get_field(curr,"CODICE ARTICOLO OMAGGIO"));
 | 
						|
            rcondv.put("CODLOTTO", file.get_field(curr,"CODICE LOTTO"));
 | 
						|
            rcondv.put("ADDIVA", file.get_field(curr,"ADDEBITO IVA OMAGGIO"));
 | 
						|
            rcondv.put("UMOM", file.get_field(curr,"UM QTA IN OMAGGIO"));
 | 
						|
            rcondv.put("PROMAGGIO", file.get_field(curr,"PREZZO ARTICOLO OMAGGIO IN LIRE"));
 | 
						|
            rcondv.rewrite();
 | 
						|
          }
 | 
						|
          else
 | 
						|
            err = file.autosave(rel, curr);  // Se non esiste lo scrive cosi' com'e'
 | 
						|
        }
 | 
						|
        
 | 
						|
        if (err != NOERR)
 | 
						|
        {
 | 
						|
          msg = "! Errore di scrittura righe listini sul file LF_RCONDV: ";
 | 
						|
          msg << err;
 | 
						|
          bf.add_line(msg);
 | 
						|
        }
 | 
						|
        else 
 | 
						|
          valid++;
 | 
						|
        break;
 | 
						|
      case 'C': // Righe campagne (offerte nel nostro caso)
 | 
						|
      case 'D':
 | 
						|
        file.add_field(curr, "TIPO", "O"); // Sostituisce
 | 
						|
        cod = file.get_field(curr,"CODICE");
 | 
						|
        // La prima volta chiede i parametri di default per la testata campagne:
 | 
						|
        // sequenza ricerca
 | 
						|
        // campagne per UM
 | 
						|
        // campagne a scaglioni
 | 
						|
        // campagne con sconti ed omaggi
 | 
						|
        if (camp_seq_ric.empty())
 | 
						|
        {
 | 
						|
          msk_prm.run();
 | 
						|
          camp_seq_ric = msk_prm.get(100);
 | 
						|
          camp_seq_ric << msk_prm.get(101);
 | 
						|
          camp_seq_ric << msk_prm.get(102);
 | 
						|
          camp_seq_ric << msk_prm.get(103);
 | 
						|
          camp_um  = msk_prm.get_bool(104);
 | 
						|
          camp_sca = msk_prm.get_bool(105);
 | 
						|
          camp_sco = msk_prm.get_bool(106);
 | 
						|
        }
 | 
						|
        
 | 
						|
        if (tipo_record == 'C')
 | 
						|
        {
 | 
						|
          mettilavirgola(file, curr, "QTA LIMITE SCAGLIONE", 11, 3);
 | 
						|
          mettilavirgola(file, curr, "PREZZO NETTO", 11, 2);
 | 
						|
          mettilavirgola(file, curr, "PERCENTUALE SCONTO", 5, 2);
 | 
						|
          mettilavirgola(file, curr, "PERCENTUALE PROVVIGIONE", 5, 2);
 | 
						|
          mettilavirgola(file, curr, "QTA MERCE SCONTATA", 9, 3);
 | 
						|
          // Scrive o aggiorna tranquillamente i record di tipo "C": se vi sono
 | 
						|
          // record omaggio vengono dopo, (cfr FLAG PRESENZA ARTICOLO OMAGGIO)
 | 
						|
          err = file.autosave(rel, curr); 
 | 
						|
          // Scrive la testata... ma solo se non esiste:
 | 
						|
          if (err == NOERR)
 | 
						|
          {
 | 
						|
            rel.read();
 | 
						|
            if (!rel.is_first_match(LF_CONDV)) // ... non esiste la testata?
 | 
						|
            {
 | 
						|
              des = "Offerta ";
 | 
						|
              des << cod;
 | 
						|
              condv.put("TIPO","O");
 | 
						|
              condv.put("CATVEN","");
 | 
						|
              condv.put("TIPOCF","");
 | 
						|
              condv.put("CODCF", "");
 | 
						|
              condv.put("COD",cod);
 | 
						|
              condv.put("DESCR", des);
 | 
						|
              condv.put("VALIN",file.get_field(curr,"VALIDITA INIZIALE"));
 | 
						|
              condv.put("VALFIN",file.get_field(curr,"VALIDITA FINALE"));
 | 
						|
              condv.put("SEQRIC", camp_seq_ric);
 | 
						|
              condv.put("GESTUM", camp_um);
 | 
						|
              condv.put("GESTSCAGL", camp_sca);
 | 
						|
              condv.put("GESTSCO", camp_sco);
 | 
						|
              if (condv.write() != NOERR) // Allora la scrive...
 | 
						|
              {
 | 
						|
                msg.format("! Errore %d di scrittura testata offerte sul file LF_CONDV: %s", condv.status(), (const char*) cod);
 | 
						|
                bf.add_line(msg);
 | 
						|
              }
 | 
						|
            }
 | 
						|
          }
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
          mettilavirgola(file, curr, "PREZZO ARTICOLO OMAGGIO IN LIRE", 11, 2);
 | 
						|
          rcondv.put("TIPO", "O");
 | 
						|
          rcondv.put("CATVEN", "");
 | 
						|
          rcondv.put("COD", cod);
 | 
						|
          rcondv.put("TIPORIGA", "A"); // See above... 
 | 
						|
          rcondv.put("CODRIGA", file.get_field(curr,"CHIAVE RIGA"));
 | 
						|
          rcondv.put("UM", file.get_field(curr,"UNITA MISURA"));
 | 
						|
          rcondv.put("NSCAGL", file.get_field(curr,"NUMERO SCAGLIONE"));
 | 
						|
          
 | 
						|
          if (rcondv.read() == NOERR) // Se esiste il record lo aggiorna...
 | 
						|
          {
 | 
						|
            rcondv.put("CODARTOM", file.get_field(curr,"CODICE ARTICOLO OMAGGIO"));
 | 
						|
            rcondv.put("CODLOTTO", file.get_field(curr,"CODICE LOTTO"));
 | 
						|
            rcondv.put("ADDIVA", file.get_field(curr,"ADDEBITO IVA OMAGGIO"));
 | 
						|
            rcondv.put("UMOM", file.get_field(curr,"UM QTA IN OMAGGIO"));
 | 
						|
            rcondv.put("PROMAGGIO", file.get_field(curr,"PREZZO ARTICOLO OMAGGIO IN LIRE"));
 | 
						|
            rcondv.rewrite();
 | 
						|
          }
 | 
						|
          else
 | 
						|
            err = file.autosave(rel, curr);  // Se non esiste lo scrive cosi' com'e'
 | 
						|
        }
 | 
						|
        if (err != NOERR)
 | 
						|
        {
 | 
						|
          msg = "! Errore di scrittura righe offerte sul file LF_RCONDV: ";
 | 
						|
          msg << err;
 | 
						|
          bf.add_line(msg);
 | 
						|
        }
 | 
						|
        else 
 | 
						|
          valid++;
 | 
						|
        break;
 | 
						|
      case 'E': // Righe contratti: non necessitano di scrittura testata
 | 
						|
      case 'F':
 | 
						|
      {
 | 
						|
        file.add_field(curr, "TIPO", "C"); // Sostituisce
 | 
						|
        const char* tipocf = (atol(file.get_field(curr,"TIPO ANAGRAFICA")) & 0x1) ? "C" : "F";
 | 
						|
        const long codcf   = atol(file.get_field(curr, "CODICE CLIENTE"));
 | 
						|
        cod = file.get_field(curr,"NUMERO CONTRATTO");
 | 
						|
        file.add_field(curr, "TIPO ANAGRAFICA", tipocf);
 | 
						|
        if (tipo_record == 'E')
 | 
						|
        {
 | 
						|
          mettilavirgola(file, curr, "QTA LIMITE SCAGLIONE", 11, 3);
 | 
						|
          mettilavirgola(file, curr, "PREZZO VENDITA", 11, 2);
 | 
						|
          mettilavirgola(file, curr, "PERCENTUALE SCONTO", 5, 2);
 | 
						|
          mettilavirgola(file, curr, "PERCENTUALE PROVVIGIONE", 5, 2);
 | 
						|
          mettilavirgola(file, curr, "QTA MERCE SCONTATA", 9, 3);
 | 
						|
          // Scrive o aggiorna tranquillamente i record di tipo "E": se vi sono
 | 
						|
          // record omaggio vengono dopo, (cfr FLAG PRESENZA ARTICOLO OMAGGIO)
 | 
						|
          err = file.autosave(rel, curr); 
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
          mettilavirgola(file, curr, "PREZZO ARTICOLO OMAGGIO IN LIRE", 11, 2);
 | 
						|
          rcondv.put("TIPO", "C");
 | 
						|
          rcondv.put("TIPOCF", tipocf);
 | 
						|
          rcondv.put("CODCF", codcf);
 | 
						|
          rcondv.put("CATVEN", "");
 | 
						|
          rcondv.put("COD", cod);
 | 
						|
          rcondv.put("TIPORIGA", "A"); // See above... 
 | 
						|
          rcondv.put("CODRIGA", file.get_field(curr,"CHIAVE RIGA"));
 | 
						|
          rcondv.put("UM", file.get_field(curr,"UNITA MISURA"));
 | 
						|
          rcondv.put("NSCAGL", file.get_field(curr,"NUMERO SCAGLIONE"));
 | 
						|
          
 | 
						|
          if (rcondv.read() == NOERR) // Se esiste il record lo aggiorna...
 | 
						|
          {
 | 
						|
            rcondv.put("CODARTOM", file.get_field(curr,"CODICE ARTICOLO OMAGGIO"));
 | 
						|
            rcondv.put("CODLOTTO", file.get_field(curr,"CODICE LOTTO"));
 | 
						|
            rcondv.put("ADDIVA", file.get_field(curr,"ADDEBITO IVA OMAGGIO"));
 | 
						|
            rcondv.put("UMOM", file.get_field(curr,"UM QTA IN OMAGGIO"));
 | 
						|
            rcondv.put("PROMAGGIO", file.get_field(curr,"PREZZO ARTICOLO OMAGGIO IN LIRE"));
 | 
						|
            rcondv.rewrite();
 | 
						|
          }
 | 
						|
          else
 | 
						|
            err = file.autosave(rel, curr);  // Se non esiste lo scrive cosi' com'e'
 | 
						|
        }
 | 
						|
        if (err != NOERR)
 | 
						|
        {
 | 
						|
          msg = "! Errore di scrittura righe contratti sul file LF_RCONDV: ";
 | 
						|
          msg << err;
 | 
						|
          bf.add_line(msg);
 | 
						|
        }
 | 
						|
        else 
 | 
						|
          valid++;
 | 
						|
        break;
 | 
						|
      }
 | 
						|
      default:
 | 
						|
        break;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  // Messaggio finale di elaborazione
 | 
						|
  msg = "Record importati: ";
 | 
						|
  msg << valid;
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::import_movmag(const TFilename& name, TBrowsefile_field& bf)
 | 
						|
{
 | 
						|
  TString msg, str;
 | 
						|
  msg = "Importazione Movimenti magazzino";
 | 
						|
  TProgind pi(::fsize(name), msg, TRUE, TRUE);
 | 
						|
  TFile_text file(name, "ibm36mag.ini");
 | 
						|
 | 
						|
  long valid = 0;
 | 
						|
 | 
						|
  msg.insert("@b", 0);
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
 | 
						|
  TRelation movmag(LF_MOVMAG);
 | 
						|
  TRectype& tesmag = movmag.curr();
 | 
						|
  
 | 
						|
  TRecord_text curr;
 | 
						|
  while (file.read(curr) == NOERR)
 | 
						|
  {
 | 
						|
    pi.setstatus(file.read_file()->tellg());
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
 | 
						|
    const char stato_record = file.get_field(curr, "STATO RECORD")[0];
 | 
						|
    if (stato_record == 'A')
 | 
						|
      continue;
 | 
						|
    
 | 
						|
    tesmag.zero();
 | 
						|
 | 
						|
    str = file.get_field(curr, "CODICE ESERCIZIO").right(1);
 | 
						|
    str[0] -= 5;
 | 
						|
    TString16 numreg = file.get_field(curr, "NUMERO REGISTRAZIONE");
 | 
						|
    numreg.right_just(6, '0');
 | 
						|
    numreg.insert(str, 0);
 | 
						|
    tesmag.put("NUMREG", numreg);
 | 
						|
 | 
						|
    str = file.get_field(curr, "TIPO CODICE");
 | 
						|
    const char* tipocf = (str == "2") ? "F" : "C";
 | 
						|
    file.add_field(curr, "TIPO CODICE", tipocf);
 | 
						|
 | 
						|
    machedata(file, curr, "DATA REGISTRAZIONE");
 | 
						|
    const TString& datacomp = file.get_field(curr, "DATA REGISTRAZIONE");
 | 
						|
    movmag.curr().put("DATACOMP", datacomp);
 | 
						|
 | 
						|
    const int err = file.autosave(movmag, curr);
 | 
						|
    if (err != NOERR)
 | 
						|
    {
 | 
						|
      msg = "! Errore di scrittura sul file LF_MOVMAG: ";
 | 
						|
      msg << err;
 | 
						|
      bf.add_line(msg);
 | 
						|
    }
 | 
						|
    else
 | 
						|
      valid++;
 | 
						|
  }
 | 
						|
 | 
						|
  // Messaggio finale di elaborazione
 | 
						|
  msg = "Record importati: ";
 | 
						|
  msg << valid;
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::import_rigmag(const TFilename& name, TBrowsefile_field& bf)
 | 
						|
{
 | 
						|
  TString msg, str;
 | 
						|
  msg = "Importazione righe magazzino";
 | 
						|
  TProgind pi(::fsize(name), msg, TRUE, TRUE);
 | 
						|
  TFile_text file(name, "ibm36rig.ini");
 | 
						|
 | 
						|
  long valid = 0;
 | 
						|
 | 
						|
  msg.insert("@b", 0);
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
 | 
						|
  TRelation rmovmag(LF_RMOVMAG);
 | 
						|
  TRectype& rigamag = rmovmag.curr();
 | 
						|
 | 
						|
  TString last_numreg;
 | 
						|
  int num_rig = 0;
 | 
						|
  
 | 
						|
  TRecord_text curr;
 | 
						|
  while (file.read(curr) == NOERR)
 | 
						|
  {
 | 
						|
    pi.setstatus(file.read_file()->tellg());
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
 | 
						|
    const int tipo_record = curr.type()[0] - '0';
 | 
						|
    if (tipo_record == 1 || tipo_record == 2)
 | 
						|
    {
 | 
						|
      const char stato_record = file.get_field(curr, "STATO RECORD")[0];
 | 
						|
      if (stato_record == 'A')
 | 
						|
        continue;
 | 
						|
 | 
						|
      TString16 numreg = file.get_field(curr, "NUMERO REGISTRAZIONE");
 | 
						|
      if (numreg != last_numreg)
 | 
						|
      {
 | 
						|
        last_numreg = numreg;
 | 
						|
        num_rig = 1;
 | 
						|
      }
 | 
						|
      else
 | 
						|
        num_rig++;
 | 
						|
 | 
						|
      rigamag.zero();
 | 
						|
 | 
						|
      str = file.get_field(curr, "CODICE ESERCIZIO").right(1);
 | 
						|
      str[0] -= 5;
 | 
						|
      numreg.right_just(6, '0');
 | 
						|
      numreg.insert(str, 0);
 | 
						|
      rigamag.put("NUMREG", numreg);
 | 
						|
      rigamag.put("NRIG", num_rig);
 | 
						|
 | 
						|
      if (num_rig == 1)
 | 
						|
      {
 | 
						|
        TLocalisamfile movmag(LF_MOVMAG);
 | 
						|
        movmag.put("NUMREG", numreg);
 | 
						|
        if (movmag.read() != NOERR)
 | 
						|
        {
 | 
						|
          msg = "!Le righe del movimento ";
 | 
						|
          msg << numreg << " non hanno una testata";
 | 
						|
          bf.add_line(msg);
 | 
						|
        }
 | 
						|
      }
 | 
						|
         
 | 
						|
      mettilavirgola(file, curr, "QUANT", 11, 3);
 | 
						|
      mettilavirgola(file, curr, "PREZZO", 11, 2);
 | 
						|
      
 | 
						|
      if (tipo_record == 2)
 | 
						|
        rigamag.put("AUTOMATICA", "A"); 
 | 
						|
      
 | 
						|
      const int err = file.autosave(rmovmag, curr);
 | 
						|
      if (err != NOERR)
 | 
						|
      {
 | 
						|
        msg = "! Errore di scrittura sul file LF_RMOVMAG: ";
 | 
						|
        msg << err;
 | 
						|
        bf.add_line(msg);
 | 
						|
      }
 | 
						|
      else
 | 
						|
        valid++;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  // Messaggio finale di elaborazione
 | 
						|
  msg = "Record importati: ";
 | 
						|
  msg << valid;
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::import_docven(const TFilename& name, TBrowsefile_field& bf)
 | 
						|
{
 | 
						|
  TString msg, str;
 | 
						|
  msg = "Importazione documenti di vendita";
 | 
						|
  TProgind pi(::fsize(name), msg, TRUE, TRUE);
 | 
						|
  TFile_text file(name, "ibm36dv.ini");
 | 
						|
 | 
						|
  _testate.destroy();
 | 
						|
  long valid = 0;
 | 
						|
 | 
						|
  msg.insert("@b", 0);
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
 | 
						|
  TRelation docven(LF_DOC);
 | 
						|
  TRectype& doc = docven.curr();
 | 
						|
  
 | 
						|
  TRecord_text curr;
 | 
						|
 | 
						|
  TString annodoc, mesedoc, giornodoc, datadoc;
 | 
						|
 | 
						|
  while (file.read(curr) == NOERR)
 | 
						|
  {
 | 
						|
    pi.setstatus(file.read_file()->tellg());
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
 | 
						|
    const char stato_record = file.get_field(curr, "STATO RECORD")[0];
 | 
						|
    if (stato_record == 'A')
 | 
						|
      continue;
 | 
						|
 | 
						|
    annodoc = file.get_field(curr, "ANNO DOCUMENTO");
 | 
						|
    annodoc.insert("19", 0);
 | 
						|
    file.add_field(curr, "ANNO DOCUMENTO", annodoc);
 | 
						|
 | 
						|
    datadoc = file.get_field(curr, "DATA DOCUMENTO");
 | 
						|
    mesedoc = datadoc.left(2);
 | 
						|
    giornodoc = datadoc.mid(2);
 | 
						|
    
 | 
						|
    datadoc = giornodoc;
 | 
						|
    datadoc << '-' << mesedoc << '-' << annodoc;
 | 
						|
    file.add_field(curr, "DATA DOCUMENTO", datadoc);
 | 
						|
 | 
						|
    str = file.get_field(curr, "TIPOCF");
 | 
						|
    str = (str == "2") ?  "F" : "C";
 | 
						|
    file.add_field(curr, "TIPOCF", str);
 | 
						|
 | 
						|
    mettilavirgola(file, curr, "CAMBIO", 18, 5);
 | 
						|
 | 
						|
    machedata(file, curr, "DATAINSC");
 | 
						|
 | 
						|
    str = file.get_field(curr, "CODICE BANCA");
 | 
						|
    if (str.not_empty())
 | 
						|
    {
 | 
						|
      const TString* bank = _bankitalia.codban2abicab(str);
 | 
						|
      if (bank)
 | 
						|
      {
 | 
						|
        docven.curr().put("CODABIP", bank->left(5));
 | 
						|
        docven.curr().put("CODCABP", bank->mid(5));
 | 
						|
      }
 | 
						|
      else
 | 
						|
      {
 | 
						|
        msg = "Ipossibile determinare l'ABI/CAB della banca di presentazione ";
 | 
						|
        msg << str << " in un documento di vendita";
 | 
						|
        bf.add_line(msg);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    str = file.get_field(curr, "SCONTO");
 | 
						|
    if (str.not_empty())
 | 
						|
    {
 | 
						|
      TString sconto;
 | 
						|
      for (int s = 0; s < 3; s++)
 | 
						|
      {
 | 
						|
        real sco(str.mid(s*5, 5));
 | 
						|
        sco /= 100.0;
 | 
						|
        if (!sco.is_zero())
 | 
						|
        {
 | 
						|
          if (sconto.not_empty() && sco > 0.0)
 | 
						|
            sconto << '+';
 | 
						|
        }
 | 
						|
        sconto << sco.string(".2");
 | 
						|
      }
 | 
						|
      file.add_field(curr, "SCONTO", sconto);
 | 
						|
    }
 | 
						|
 | 
						|
    machedata(file, curr, "DATADOCRIF");
 | 
						|
    machedata(file, curr, "DATAPART");
 | 
						|
    mettilavirgola(file, curr, "IMPPAGATO", 18, 2);
 | 
						|
 | 
						|
    str = file.get_field(curr, "ACCSALDO");
 | 
						|
    str = (str == "S") ? "X" : "";
 | 
						|
    file.add_field(curr, "ACCSALDO", str);
 | 
						|
 | 
						|
    machedata(file, curr, "DATACONS");
 | 
						|
 | 
						|
#ifdef DBG
 | 
						|
    docven.curr().put("PROVV", "P"); // Tutto provvisorio in DEBUG
 | 
						|
#else
 | 
						|
    docven.curr().put("PROVV", "D"); // Tutto definitivo alla PRASSI
 | 
						|
#endif
 | 
						|
 | 
						|
    const int err = file.autosave(docven, curr);
 | 
						|
    if (err != NOERR)
 | 
						|
    {
 | 
						|
      msg = "! Errore di scrittura sul file LF_DOC: ";
 | 
						|
      msg << err;
 | 
						|
      bf.add_line(msg);
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      valid++;
 | 
						|
 | 
						|
      // Memorizza il numero record per le righe del documento
 | 
						|
      str = file.get_field(curr, "NUMERO RECORD");
 | 
						|
      if (str.not_empty())
 | 
						|
      {
 | 
						|
        real recno = docven.lfile().recno();
 | 
						|
        _testate.add(str, recno);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  // Messaggio finale di elaborazione
 | 
						|
  msg = "Record importati: ";
 | 
						|
  msg << valid;
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::import_rdocven(const TFilename& name, TBrowsefile_field& bf)
 | 
						|
{
 | 
						|
  TString msg, str;
 | 
						|
  msg = "Importazione righe documenti di vendita";
 | 
						|
  TProgind pi(::fsize(name), msg, TRUE, TRUE);
 | 
						|
  TFile_text file(name, "ibm36rdv.ini");
 | 
						|
 | 
						|
  long testate = 0, righe = 0;
 | 
						|
 | 
						|
  msg.insert("@b", 0);
 | 
						|
  bf.add_line(msg);
 | 
						|
  bf.add_line("");
 | 
						|
 | 
						|
  TRelation docven(LF_DOC);
 | 
						|
  TRectype& doc = docven.curr();
 | 
						|
 | 
						|
  TRelation rdocven(LF_RIGHEDOC);
 | 
						|
  TRectype& rdoc = rdocven.curr();
 | 
						|
  
 | 
						|
  TRecord_text curr;
 | 
						|
  while (file.read(curr) == NOERR)
 | 
						|
  {
 | 
						|
    pi.setstatus(file.read_file()->tellg());
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
 | 
						|
    // Ignora i clienti occasionali ed altri tipi sconosciuti
 | 
						|
    if (curr.type() == "A1" || curr.type()[0] > 'B')
 | 
						|
      continue;
 | 
						|
 | 
						|
    const char stato_record = file.get_field(curr, "STATO RECORD")[0];
 | 
						|
    if (stato_record == 'A')
 | 
						|
      continue;
 | 
						|
 | 
						|
    str = file.get_field(curr, "NUMERO RECORD");
 | 
						|
    real* recno = (real*)_testate.objptr(str);
 | 
						|
    if (recno != NULL)
 | 
						|
    {
 | 
						|
      const int err = docven.lfile().readat(recno->integer());
 | 
						|
      if (err != NOERR)
 | 
						|
        recno = NULL;
 | 
						|
    }
 | 
						|
    if (recno == NULL)
 | 
						|
    {
 | 
						|
      msg = "! Impossibile tovare la testata del ";
 | 
						|
      msg << "record " << curr.type() << ' ' << str;
 | 
						|
      bf.add_line(msg);
 | 
						|
      continue;
 | 
						|
    }
 | 
						|
 | 
						|
    if (curr.type() == "A2")
 | 
						|
    {
 | 
						|
      str = file.get_field(curr, "PERCSPINC");
 | 
						|
      str = (str == "S") ? "100" : "0";
 | 
						|
      file.add_field(curr, "PERCSPINC", str);
 | 
						|
 | 
						|
      bool addebito_bolli = FALSE;
 | 
						|
      str = file.get_field(curr, "ADDEBITO BOLLI RIBA");
 | 
						|
      str << file.get_field(curr, "ADDEBITO BOLLI TRATTE");
 | 
						|
      str << file.get_field(curr, "ADDEBITO BOLLI DOCUMENTI");
 | 
						|
      str = (str.find('S') >= 0) ? "X" : " ";
 | 
						|
      file.add_field(curr, "ADDEBITO BOLLI RIBA", str);
 | 
						|
 | 
						|
      const int err = file.autosave(docven, curr);
 | 
						|
      if (err != NOERR)
 | 
						|
      {
 | 
						|
        msg = "! Errore di scrittura sul file LF_DOC: ";
 | 
						|
        msg << err;
 | 
						|
        bf.add_line(msg);
 | 
						|
      }
 | 
						|
      else
 | 
						|
        testate++;
 | 
						|
    }
 | 
						|
 | 
						|
    if (curr.type()[0] == 'B')
 | 
						|
    {
 | 
						|
      str = file.get_field(curr, "CODMAG");
 | 
						|
      str << file.get_field(curr, "CODDEP");
 | 
						|
      file.add_field(curr, "CODMAG", str);
 | 
						|
 | 
						|
      mettilavirgola(file, curr, "QTAEVASA", 11, 3);
 | 
						|
      mettilavirgola(file, curr, "QTA", 11, 3);
 | 
						|
      mettilavirgola(file, curr, "PREZZO", 11, 2);
 | 
						|
 | 
						|
      str.cut(0);
 | 
						|
      for (int s = 0; s < 2; s++)
 | 
						|
      {
 | 
						|
        TString16 sconto = file.get_field(curr, s == 0 ? "SCONTO" : "SCONTO2");
 | 
						|
        real sco(sconto); 
 | 
						|
        sco /= 100.0;
 | 
						|
        if (!sco.is_zero())
 | 
						|
        {
 | 
						|
          if (str.not_empty() && sco > 0.0)
 | 
						|
            sconto << '+';
 | 
						|
          str << sconto;
 | 
						|
        }
 | 
						|
      }
 | 
						|
      if (str.not_empty())
 | 
						|
        file.add_field(curr, "SCONTO", str);
 | 
						|
 | 
						|
      mettilavirgola(file, curr, "PERCPROVV", 5, 2);
 | 
						|
      mettilavirgola(file, curr, "TARA", 7, 2);
 | 
						|
      mettilavirgola(file, curr, "PNETTO", 7, 2);
 | 
						|
 | 
						|
      str = file.get_field(curr, "CODMAGC");
 | 
						|
      str << file.get_field(curr, "CODDEPC");
 | 
						|
      file.add_field(curr, "CODMAGC", str);
 | 
						|
 | 
						|
      rdoc.put("PROVV", doc.get("PROVV"));
 | 
						|
      rdoc.put("ANNO", doc.get("ANNO"));
 | 
						|
      rdoc.put("CODNUM", doc.get("CODNUM"));
 | 
						|
      rdoc.put("NDOC", doc.get("NDOC"));
 | 
						|
      str = file.get_field(curr, "NRIGA");
 | 
						|
      rdoc.put("NRIGA", str);
 | 
						|
 | 
						|
      const int err = file.autosave(rdocven, curr);
 | 
						|
      if (err != NOERR)
 | 
						|
      {
 | 
						|
        msg = "! Errore di scrittura sul file LF_RDOC: ";
 | 
						|
        msg << err;
 | 
						|
        bf.add_line(msg);
 | 
						|
      }
 | 
						|
      else
 | 
						|
        righe++;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  _testate.destroy();
 | 
						|
 | 
						|
  // Messaggio finale di elaborazione
 | 
						|
  msg = "Record di testata importati: ";
 | 
						|
  msg << testate;
 | 
						|
  bf.add_line(msg);
 | 
						|
 | 
						|
  msg = "Record di righe importati: ";
 | 
						|
  msg << righe;
 | 
						|
  bf.add_line(msg);
 | 
						|
 | 
						|
  bf.add_line("");
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::mask2ini(TMask& m, bool load)
 | 
						|
{
 | 
						|
  TConfig cfg(CONFIG_DITTA, "ibm36");
 | 
						|
  TString16 id;
 | 
						|
  
 | 
						|
  for (int f = m.fields()-1; f >= 0; f--)
 | 
						|
  {
 | 
						|
    TMask_field& fld = m.fld(f);
 | 
						|
    if (fld.is_edit())
 | 
						|
    {
 | 
						|
      id.format("%d", fld.dlg());
 | 
						|
      if (load)
 | 
						|
        fld.set(cfg.get(id));
 | 
						|
      else
 | 
						|
        cfg.set(id, fld.get());
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TTrasfer36::main_loop()
 | 
						|
{
 | 
						|
  TMask36 m;
 | 
						|
  ini2mask(m);
 | 
						|
 | 
						|
  TBrowsefile_field& bf = (TBrowsefile_field&)m.field(300);
 | 
						|
 | 
						|
  TViswin& vw = bf.vis_win();
 | 
						|
  vw.show_rulers(FALSE);
 | 
						|
 | 
						|
  while (m.run() == K_ENTER)
 | 
						|
  {
 | 
						|
    vw.destroy_lines();
 | 
						|
    const TFilename dir = m.get(100);
 | 
						|
    for (short id = 101; id <= 108; id++)
 | 
						|
    {
 | 
						|
      const TMask_field& fld = m.field(id);
 | 
						|
      if (fld.enabled() && !fld.empty())
 | 
						|
      {
 | 
						|
        TFilename name = dir;
 | 
						|
        name.add(fld.get());
 | 
						|
        switch(id)
 | 
						|
        {
 | 
						|
        case 101: import_tables(name, bf); break;
 | 
						|
        case 102: import_clifor(name, bf); break;
 | 
						|
        case 103: import_anaart(name, bf); break;
 | 
						|
        case 104: import_movmag(name, bf); break;
 | 
						|
        case 105: import_rigmag(name, bf); break;
 | 
						|
        case 106: import_condv(name, bf); break;
 | 
						|
        case 107: import_docven(name, bf); break;
 | 
						|
        case 108: import_rdocven(name, bf); break;
 | 
						|
        default : break;
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
    vw.goto_top();
 | 
						|
    mask2ini(m);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
int ibm36100(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TTrasfer36 a;
 | 
						|
  a.run(argc, argv, "Trasferimento IBM36");
 | 
						|
  return 0;
 | 
						|
}
 |