246 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			246 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <confapp.h>
 | 
						|
#include <isam.h>
 | 
						|
#include <tabutil.h>
 | 
						|
#include <prefix.h>
 | 
						|
#include <attiv.h> 
 | 
						|
#include <extcdecl.h>
 | 
						|
#include <utility.h>
 | 
						|
#include <modaut.h>
 | 
						|
#include "cg5100a.h"
 | 
						|
 | 
						|
class TParametri_ditta : public TConfig_application
 | 
						|
{
 | 
						|
  //  bool      _change_pcon;
 | 
						|
  // TString16 _val;
 | 
						|
  TArray    _atts;   
 | 
						|
  
 | 
						|
  void swap_file(int logicnum, bool tocom);
 | 
						|
  void load_file(int logicnum);
 | 
						|
  void check_registers(int year);   
 | 
						|
  
 | 
						|
public:
 | 
						|
  virtual bool preprocess_config (TMask& mask, TConfig& config);
 | 
						|
  virtual bool postprocess_config (TMask& mask, TConfig& config);
 | 
						|
  virtual bool postprocess_config_changed(const char* par, const char* var, 
 | 
						|
                                          const char* oldv, const char* newv);
 | 
						|
 | 
						|
  virtual bool user_create(); 
 | 
						|
  TParametri_ditta() : TConfig_application(CONFIG_DITTA) {}
 | 
						|
  virtual ~TParametri_ditta() {}
 | 
						|
};
 | 
						|
 | 
						|
bool TParametri_ditta::user_create()
 | 
						|
{
 | 
						|
  //  _change_pcon = FALSE;          
 | 
						|
  
 | 
						|
  TLocalisamfile attiv(LF_ATTIV);
 | 
						|
  attiv.zero();
 | 
						|
  
 | 
						|
  attiv.put(ATT_CODDITTA, get_firm());
 | 
						|
  TRectype r(attiv.curr());
 | 
						|
 | 
						|
  for(attiv.read(_isgteq); attiv.status() == NOERR && attiv.curr() == r; 
 | 
						|
      attiv.next())
 | 
						|
    // istanzia array _atts on le attivita' della ditta corrente
 | 
						|
    _atts.add(new TString(attiv.get(ATT_CODATT)));
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TParametri_ditta::check_registers(int year)
 | 
						|
{
 | 
						|
  // controlla che per ogni data attivita' esistano almeno un registro
 | 
						|
  // acquisti, vendite e giornale; warning appropriato in caso negativo 
 | 
						|
  TTable reg("REG");
 | 
						|
  TRecfield reg_year(reg.curr(), "CODTAB", 0,3);
 | 
						|
  
 | 
						|
  const byte R_ACQ = 0x01;
 | 
						|
  const byte R_VEN = 0x02;
 | 
						|
  const byte R_ALL = R_ACQ | R_VEN;
 | 
						|
 | 
						|
  bool is_giornale = FALSE;       
 | 
						|
  
 | 
						|
  byte flags = 0x00;      
 | 
						|
 | 
						|
  for (int i = 0; i < _atts.items(); i++)
 | 
						|
  {
 | 
						|
    TString& att = (TString&)_atts[i];
 | 
						|
    for (reg.first(); !reg.eof(); reg.next())
 | 
						|
    {               
 | 
						|
      if (atoi(reg_year) == year && reg.get_int("I0") == 5) 
 | 
						|
      {
 | 
						|
        is_giornale = TRUE;
 | 
						|
        continue;
 | 
						|
      }
 | 
						|
      if (atoi(reg_year) != year || att != reg.get("S8")) 
 | 
						|
        continue;
 | 
						|
      
 | 
						|
      switch (reg.get_int("I0"))
 | 
						|
      {
 | 
						|
      case 1:    // vendite 
 | 
						|
        flags |= R_VEN; break;
 | 
						|
      case 2:    // acquisti
 | 
						|
        flags |= R_ACQ; break;
 | 
						|
      default:
 | 
						|
        break;  
 | 
						|
      }
 | 
						|
      if (flags ==  R_ALL && is_giornale) break;
 | 
						|
    } 
 | 
						|
    if (flags < R_ALL)
 | 
						|
    {      
 | 
						|
      TString wrn("I seguenti registri non esistono per l'attivita' "); 
 | 
						|
      wrn << att << "(" << year << "):";
 | 
						|
      if ((flags & R_VEN) == 0x00) wrn << "\n\tregistro vendite";
 | 
						|
      if ((flags & R_ACQ) == 0x00) wrn << "\n\tregistro acquisti";
 | 
						|
      warning_box(wrn);
 | 
						|
    }
 | 
						|
  } 
 | 
						|
 | 
						|
  // libro giornale non si controlla per attivita'
 | 
						|
  if(!is_giornale)
 | 
						|
    warning_box("Non esiste probabilmente nessun "
 | 
						|
                "libro giornale per l'anno %d", year);
 | 
						|
}                                      
 | 
						|
 | 
						|
 | 
						|
 | 
						|
void TParametri_ditta::swap_file(int logicnum, bool tocom)
 | 
						|
{
 | 
						|
  TDir dir;
 | 
						|
  TString file(16);
 | 
						|
 | 
						|
  dir.get(logicnum, _lock, _nordir, _sysdirop);
 | 
						|
  file = dir.name();
 | 
						|
  file[0] = tocom ? '%' : '$';
 | 
						|
  dir.set(file, dir.eod(), dir.flags(), dir.des(), dir.expr());
 | 
						|
  dir.put(logicnum, _nordir, _sysdirop);
 | 
						|
  dir.get(logicnum, _lock, (tocom ? _comdir :_nordir), _sysdirop);
 | 
						|
  if (tocom)
 | 
						|
  {
 | 
						|
    file = dir.name();
 | 
						|
    file[0] = '%';
 | 
						|
    dir.set(file, dir.eod(), dir.flags(), dir.des(), dir.expr());
 | 
						|
    dir.put(logicnum, _comdir, _sysdirop);
 | 
						|
  }
 | 
						|
  else
 | 
						|
    dir.get(logicnum, _unlock, (tocom ? _comdir :_nordir), _sysdirop);
 | 
						|
  
 | 
						|
  if (dir.eox() == 0L)
 | 
						|
  {
 | 
						|
    set_autoload_new_files(FALSE);
 | 
						|
    TSystemisamfile s(logicnum);
 | 
						|
    s.build(10L);
 | 
						|
    set_autoload_new_files(TRUE);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TParametri_ditta::load_file(int logicnum)
 | 
						|
{
 | 
						|
  TDir dir;
 | 
						|
 | 
						|
  dir.get(logicnum);
 | 
						|
 | 
						|
  TSystemisamfile f(logicnum);
 | 
						|
  TFilename lf;
 | 
						|
 | 
						|
  if (dir.eox() > 0L)
 | 
						|
    f.build(10L);
 | 
						|
  lf.format("%sstd/lf%04d.txt", __ptprf, logicnum);
 | 
						|
  if (fexist(lf))
 | 
						|
    f.load(lf, '|', '\0', '\n', TRUE, TRUE);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TParametri_ditta::preprocess_config (TMask& mask, TConfig& config)
 | 
						|
{ 
 | 
						|
  // these are disabled in normal applications
 | 
						|
  TLocalisamfile mov(LF_MOV); 
 | 
						|
  const bool movempty = mov.empty();
 | 
						|
  mask.enable(CHK_ANCFCM, movempty);
 | 
						|
  mask.enable(CHK_PCTCCM, movempty);
 | 
						|
 | 
						|
  // check auth for Saldaconto              
 | 
						|
  if (!has_module(SCAUT, CHK_DONGLE))
 | 
						|
    // disable saldaconting 
 | 
						|
    mask.disable(-GROUP_SALDACONTO);
 | 
						|
 | 
						|
  return TRUE; 
 | 
						|
}
 | 
						|
 | 
						|
bool TParametri_ditta::postprocess_config(TMask& mask, TConfig& config)
 | 
						|
{          
 | 
						|
  check_registers(mask.get_int(FLD_ANLIIV));
 | 
						|
  if (mask.get_bool(CHK_GELIDI))
 | 
						|
  {
 | 
						|
    TLocalisamfile ditte(LF_NDITTE);
 | 
						|
    const long ditta = get_firm();
 | 
						|
    ditte.put("CODDITTA", ditta);
 | 
						|
    ditte.read();
 | 
						|
    if (ditte.get("DINIZIOATT").empty()) 
 | 
						|
      error_box("La gestione della liquidazione differita richiede "
 | 
						|
                "la data di inizio attivita' sull'anagrafica della ditta.");  
 | 
						|
 | 
						|
    char freqiva = ditte.get_char("FREQVIVA");
 | 
						|
    
 | 
						|
    TString16 key; key.format("%05ld%d", ditta, mask.get_int(FLD_ANLIIV));
 | 
						|
    TTable lia("%LIA");
 | 
						|
    lia.put("CODTAB", key);
 | 
						|
    if (lia.read() == NOERR)
 | 
						|
      freqiva = lia.get_char("S7");
 | 
						|
    
 | 
						|
    if (freqiva != 'M')
 | 
						|
      error_box("La gestione della liquidazione differita richiede "
 | 
						|
                "la frequenza dei versamenti IVA mensile.");  
 | 
						|
  }
 | 
						|
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TParametri_ditta::postprocess_config_changed(const char* par, const char* var, 
 | 
						|
                                                  const char* oldv, const char* newv)
 | 
						|
{
 | 
						|
  TString v(var);
 | 
						|
 | 
						|
  if (v == "AnCfCm")
 | 
						|
  {
 | 
						|
    if (yesno_box("Confermi il cambiamento dell'anagrafica clienti/fornitori"))
 | 
						|
      swap_file(LF_CLIFO, *newv == 'X');
 | 
						|
    else
 | 
						|
      return FALSE;
 | 
						|
  }
 | 
						|
  else if (v == "PcTcCm")
 | 
						|
  {
 | 
						|
    if (yesno_box("Confermi il cambiamento del piano conti/causali"))
 | 
						|
    {
 | 
						|
      //     _change_pcon = TRUE;
 | 
						|
      //     _val = newv;        
 | 
						|
      swap_file(LF_PCON, *newv == 'X');
 | 
						|
      swap_file(LF_CAUSALI, *newv == 'X');
 | 
						|
      swap_file(LF_RCAUSALI, *newv == 'X');
 | 
						|
      prefix().reopen();         
 | 
						|
      if (*newv == 'X')
 | 
						|
      {
 | 
						|
        TDir d;
 | 
						|
        d.get(LF_PCON, _nolock,  _comdir);
 | 
						|
        if (d.eod() == 0 && yesno_box("Vuoi caricare gli archivi standard ?"))
 | 
						|
        {
 | 
						|
          load_file(LF_PCON);
 | 
						|
          load_file(LF_CAUSALI);
 | 
						|
          load_file(LF_RCAUSALI);
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
    else
 | 
						|
      return FALSE;
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
int cg5100 (int argc, char* argv[])
 | 
						|
{
 | 
						|
  TParametri_ditta appc;
 | 
						|
  appc.run(argc, argv, "Parametri Ditta");
 | 
						|
  return 0;
 | 
						|
}
 |