251 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			251 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <mask.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <urldefid.h>
 | 
						|
#include <saldi.h>
 | 
						|
#include <pconti.h>
 | 
						|
#include <partite.h>
 | 
						|
#include <scadenze.h> 
 | 
						|
#include <lffiles.h>
 | 
						|
#include <relation.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include "../cg/conto.h"
 | 
						|
#include "../cg/pagament.h"
 | 
						|
#include "sc1200.h"
 | 
						|
 | 
						|
class TCreatepart_app : public TApplication
 | 
						|
{ 
 | 
						|
  TLocalisamfile* _conti;
 | 
						|
  TLocalisamfile* _partite;
 | 
						|
  TLocalisamfile* _scadenze;
 | 
						|
  
 | 
						|
  int _anno;
 | 
						|
  
 | 
						|
protected:
 | 
						|
 | 
						|
  virtual bool create();
 | 
						|
  virtual bool destroy();
 | 
						|
  virtual bool menu(MENU_TAG m);  
 | 
						|
 | 
						|
  long    get_last_partita(bool check_erase);
 | 
						|
  
 | 
						|
public: 
 | 
						|
 | 
						|
  bool is_clifo(int g, int c, char& cf);
 | 
						|
  TCreatepart_app() {}
 | 
						|
  virtual ~TCreatepart_app() {}  
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
bool TCreatepart_app::create()
 | 
						|
{
 | 
						|
  TApplication::create();
 | 
						|
 | 
						|
  _conti    = new TLocalisamfile(LF_PCON);
 | 
						|
  _partite  = new TLocalisamfile(LF_PARTITE);
 | 
						|
  _scadenze = new TLocalisamfile(LF_SCADENZE);
 | 
						|
 | 
						|
  dispatch_e_menu(BAR_ITEM(1));
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TCreatepart_app::destroy()
 | 
						|
{                                      
 | 
						|
  delete _conti;  
 | 
						|
  delete _partite;
 | 
						|
  delete _scadenze;
 | 
						|
  
 | 
						|
  return TApplication::destroy();
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
long  TCreatepart_app::get_last_partita(bool zap)
 | 
						|
{
 | 
						|
  // ritorna il primo valore utile per partita temporanea AP;
 | 
						|
  // se ce ne sono gia' propone la cancellazione e se ok
 | 
						|
  // la esegue perfidamente
 | 
						|
  
 | 
						|
  _partite->zero();
 | 
						|
  _partite->put(PART_ANNO,    _anno);
 | 
						|
  _partite->put(PART_NUMPART, "AP");
 | 
						|
  
 | 
						|
  long last = 0l;  
 | 
						|
  bool go   = _partite->read(_isgteq) == NOERR;
 | 
						|
 | 
						|
  if (zap && go)
 | 
						|
    zap = yesno_box("Esistono gia' partite generate in base ai"
 | 
						|
                    " saldi contabili. Si desidera cancellarle?");     
 | 
						|
  
 | 
						|
  while (go)
 | 
						|
  {
 | 
						|
    if (zap)
 | 
						|
    {       
 | 
						|
      for (int i = 0; ; i++)
 | 
						|
      {  
 | 
						|
        // zappa scadenze
 | 
						|
        _scadenze->zero();
 | 
						|
        _scadenze->put(SCAD_ANNO,       _partite->get(PART_ANNO));
 | 
						|
        _scadenze->put(SCAD_NUMPART,    _partite->get(PART_NUMPART));
 | 
						|
        _scadenze->put(SCAD_NRATA,      i+1); 
 | 
						|
        
 | 
						|
        if (_scadenze->read() == NOERR) _scadenze->remove();
 | 
						|
        else                            
 | 
						|
        { 
 | 
						|
          _partite->remove(); 
 | 
						|
          break; 
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
    else     last = atol(_partite->get(PART_NUMPART).mid(2)) + 1l;
 | 
						|
    
 | 
						|
    go = _partite->next() == NOERR &&
 | 
						|
      _partite->get(PART_NUMPART).mid(0,2) == "AP";
 | 
						|
  }
 | 
						|
  
 | 
						|
  return last;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TCreatepart_app::is_clifo(int g, int c, char& cf)
 | 
						|
{
 | 
						|
  static int gr = -1, ct = -1;
 | 
						|
  
 | 
						|
  if (g != gr || c != ct)
 | 
						|
  {
 | 
						|
    _conti->zero();
 | 
						|
    _conti->put(PCN_GRUPPO, g);
 | 
						|
    _conti->put(PCN_CONTO, c);
 | 
						|
    if (_conti->read() != NOERR)
 | 
						|
      error_box("Piano dei conti disallineato con archivio saldi");
 | 
						|
    gr = g; ct = c;
 | 
						|
  }                
 | 
						|
  
 | 
						|
  if (_conti->get(PCN_TMCF).empty())
 | 
						|
    return FALSE;
 | 
						|
  
 | 
						|
  cf = _conti->get_char(PCN_TMCF); 
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TCreatepart_app::menu(MENU_TAG)
 | 
						|
{ 
 | 
						|
  TMask m("sc1200a");
 | 
						|
  TRelation saldi(LF_SALDI);
 | 
						|
  saldi.zero();
 | 
						|
  
 | 
						|
 | 
						|
  while (m.run() != K_QUIT) 
 | 
						|
  {                 
 | 
						|
    int n_part = 0;
 | 
						|
    TDate      data(m.get(F_DATA));
 | 
						|
    TString16  codpag(m.get(F_CODPAG));
 | 
						|
 | 
						|
    TPagamento pag(codpag, data.string()); 
 | 
						|
    
 | 
						|
    m.set(F_NUMPART, format("%d",n_part));
 | 
						|
    _anno = m.get_int(F_ANNO);
 | 
						|
 | 
						|
    saldi.lfile().zero();
 | 
						|
    saldi.lfile().put(SLD_ANNOES, _anno);
 | 
						|
 | 
						|
    TCursor cur(&saldi, "", 1, &saldi.curr(), &saldi.curr());      
 | 
						|
    const long items = cur.items();
 | 
						|
    long npart = 0L;
 | 
						|
    
 | 
						|
    if (items > 0)
 | 
						|
    {  
 | 
						|
      begin_wait();       
 | 
						|
      int hw = 0;
 | 
						|
      for (cur = 0, hw = 0 ; cur.pos() < items; ++cur, hw++)
 | 
						|
      {               
 | 
						|
        char cf;
 | 
						|
        int  gruppo = cur.curr().get_int(SLD_GRUPPO);
 | 
						|
        int  conto  = cur.curr().get_int(SLD_CONTO);  
 | 
						|
        long sottoc = cur.curr().get_long(SLD_SOTTOCONTO);
 | 
						|
        
 | 
						|
        if (is_clifo(gruppo, conto, cf))
 | 
						|
        {         
 | 
						|
          TImporto saldo(cur.curr().get_char(SLD_FLAGSALINI), cur.curr().get_real(SLD_SALDO));
 | 
						|
          TImporto pdare('D',  cur.curr().get_real(SLD_PDARE));   
 | 
						|
          TImporto pavere('A', cur.curr().get_real(SLD_PAVERE));
 | 
						|
          
 | 
						|
          saldo += pdare;         
 | 
						|
          saldo += pavere;                 
 | 
						|
          saldo.normalize();
 | 
						|
          
 | 
						|
          if (!saldo.is_zero())
 | 
						|
          { 
 | 
						|
            TString16 id; 
 | 
						|
            real val(saldo.valore());              
 | 
						|
            
 | 
						|
            pag.set_total(val, ZERO, ZERO);
 | 
						|
            pag.set_rate_auto();
 | 
						|
            
 | 
						|
            // determina ultima partita; la prima volta,
 | 
						|
            // se ce n'e' chiedi se si vuole cancellare
 | 
						|
            long last_partita = get_last_partita(hw == 0);
 | 
						|
            
 | 
						|
            // apri partita dimmerda              
 | 
						|
            id << format("AP%05ld", last_partita);
 | 
						|
            
 | 
						|
            _partite->zero();
 | 
						|
            _partite->put(PART_ANNO,      _anno);
 | 
						|
            _partite->put(PART_NUMPART,   id);
 | 
						|
            _partite->put(PART_NUMRIG,    1);
 | 
						|
            _partite->put(PART_NRIGA,     1);
 | 
						|
            _partite->put(PART_DATAREG,   data);
 | 
						|
            _partite->put(PART_DATADOC,   data);
 | 
						|
            _partite->put(PART_SEZ,       saldo.sezione());
 | 
						|
            _partite->put(PART_IMPORTO,   saldo.valore());
 | 
						|
            _partite->put(PART_CODPAG,    codpag);
 | 
						|
            _partite->put(PART_CODVAL,    "LIT"); 
 | 
						|
            _partite->put(PART_TIPOCF,    cf);
 | 
						|
            _partite->put(PART_GRUPPO,    gruppo);
 | 
						|
            _partite->put(PART_CONTO,     conto);
 | 
						|
            _partite->put(PART_SOTTOCONTO,sottoc);
 | 
						|
            _partite->put(PART_DESCR,     "Apertura partite da saldi contabili");
 | 
						|
            _partite->write();
 | 
						|
            
 | 
						|
            // apri scadenze dimmerda
 | 
						|
            for (int i = 0; i < pag.n_rate(); i++)
 | 
						|
            {
 | 
						|
              _scadenze->zero();
 | 
						|
              _scadenze->put(SCAD_ANNO,       _anno);
 | 
						|
              _scadenze->put(SCAD_NUMPART,    id);
 | 
						|
              _scadenze->put(SCAD_NRATA,      i+1);
 | 
						|
              _scadenze->put(SCAD_CODPAG,     codpag);
 | 
						|
              _scadenze->put(SCAD_ULTCLASS,   pag.ulc_rata(i));
 | 
						|
              _scadenze->put(SCAD_TIPOPAG,    pag.tipo_rata(i));
 | 
						|
              _scadenze->put(SCAD_IMPORTO,    pag.tpay_rata(i));
 | 
						|
              _scadenze->put(SCAD_DATASCAD,   pag.data_rata(i));
 | 
						|
              _scadenze->put(SCAD_TIPOCF,     cf);
 | 
						|
              _scadenze->put(SCAD_GRUPPO,     gruppo);
 | 
						|
              _scadenze->put(SCAD_CONTO,      conto);
 | 
						|
              _scadenze->put(SCAD_SOTTOCONTO, sottoc);
 | 
						|
              _scadenze->write();
 | 
						|
            }
 | 
						|
            
 | 
						|
            n_part++;  
 | 
						|
            m.set(F_NUMPART, format("%d",n_part));
 | 
						|
          }
 | 
						|
        }  
 | 
						|
      }
 | 
						|
      end_wait();
 | 
						|
    }
 | 
						|
    else 
 | 
						|
      message_box("Nessun saldo presente per l'anno %d", _anno);    
 | 
						|
  } // while run 
 | 
						|
  
 | 
						|
  return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
int sc1200(int argc, char** argv)
 | 
						|
{
 | 
						|
  TCreatepart_app a;
 | 
						|
  a.run(argc, argv, "Apertura scadenze da saldi contabili");
 | 
						|
  return 0;
 | 
						|
}
 |