git-svn-id: svn://10.65.10.50/branches/R_10_00@22687 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			387 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			387 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#define __EXTRA__
 | 
						|
#include "../cg/cg2105.h"
 | 
						|
#include "../cg/cg2100p.h"
 | 
						|
#include "../cg/cgsalda3.h"
 | 
						|
 | 
						|
#include "sc0200b.h"
 | 
						|
#include "sc0100.h"
 | 
						|
 | 
						|
#include <defmask.h>
 | 
						|
#include <treectrl.h>
 | 
						|
 | 
						|
#include <mov.h>
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TPartite_mask
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TPartite_mask : public TAutomask
 | 
						|
{
 | 
						|
  TSolder_tree _tree;
 | 
						|
 | 
						|
private:
 | 
						|
  bool edit_fattura(TPartita& p, int nriga);
 | 
						|
  bool edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp);
 | 
						|
  char calcola_sezione(tipo_movimento tm) const;
 | 
						|
  int nuova_riga_partita(TPartita& partita, tipo_movimento tm);
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
  void init(const TMask& qmask);
 | 
						|
  TPartite_mask();
 | 
						|
};
 | 
						|
 | 
						|
void TPartite_mask::init(const TMask& qmask)
 | 
						|
{
 | 
						|
  for (int f = qmask.fields()-1; f >= 0; f--)
 | 
						|
  {
 | 
						|
    TMask_field& campo = qmask.fld(f);
 | 
						|
    const short id = campo.dlg();
 | 
						|
    if (id > DLG_USER && id2pos(id) >= 0)
 | 
						|
      set(id, campo.get());
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
bool TPartite_mask::edit_fattura(TPartita& p, int nriga)
 | 
						|
{
 | 
						|
  const bool nuova = nriga <= 0;          
 | 
						|
  if (nuova)
 | 
						|
    nriga = nuova_riga_partita(p, tm_fattura);
 | 
						|
  
 | 
						|
  TRiga_partite& f = p.riga(nriga);
 | 
						|
  TFattura_mask fm(f);
 | 
						|
  const KEY k = fm.run();
 | 
						|
  bool updated = false;
 | 
						|
  if (k == K_SAVE || k == K_ENTER)  
 | 
						|
  {
 | 
						|
    fm.write_scadenze();
 | 
						|
    updated = true;
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    if (nuova || (k == K_DEL && noyes_box(TR("Confermare l'eliminazione"))))
 | 
						|
    {
 | 
						|
      p.rimuovi_riga(nriga);
 | 
						|
      updated = !nuova;
 | 
						|
      if (updated)
 | 
						|
        p.rewrite();
 | 
						|
    }  
 | 
						|
  }  
 | 
						|
 | 
						|
  return updated;
 | 
						|
}
 | 
						|
 | 
						|
char TPartite_mask::calcola_sezione(tipo_movimento tm) const
 | 
						|
{
 | 
						|
  const char tipoc = get(F_TIPO)[0];
 | 
						|
  char sezione = ' ';
 | 
						|
  if (tm == tm_fattura || tm == tm_insoluto) // calcola in base al tipo movimento e
 | 
						|
    sezione = (tipoc == 'C') ? 'D' : 'A';    // al tipo cliente/fornitore
 | 
						|
  else  
 | 
						|
    sezione = (tipoc == 'C') ? 'A' : 'D';
 | 
						|
  return sezione;
 | 
						|
}
 | 
						|
 | 
						|
int TPartite_mask::nuova_riga_partita(TPartita& partita, tipo_movimento tm)
 | 
						|
{
 | 
						|
  const int una_riga = partita.last();              // Memorizza una riga valida
 | 
						|
 | 
						|
  TRiga_partite& part = partita.new_row();          // Creazione nuova riga vuota
 | 
						|
  const int nriga = part.get_int(PART_NRIGA);       // Nuova riga
 | 
						|
  
 | 
						|
  // Forza il gruppo/conto cliente corretto 
 | 
						|
  part.put(PART_GRUPPOCL, get_int(F_GRUPPO));
 | 
						|
  part.put(PART_CONTOCL,  get_int(F_CONTO));
 | 
						|
  
 | 
						|
  part.put(PART_TIPOMOV, (int)tm);       
 | 
						|
  
 | 
						|
  if (una_riga > 0)
 | 
						|
  {
 | 
						|
    const char* valuta = partita.riga(una_riga).get(PART_CODVAL);
 | 
						|
    part.put(PART_CODVAL, valuta);
 | 
						|
  }
 | 
						|
 | 
						|
  const TDate oggi(TODAY);
 | 
						|
  const char* s = oggi.string();
 | 
						|
  part.put(PART_DATADOC, s);
 | 
						|
  part.put(PART_DATAREG, s);
 | 
						|
 | 
						|
  const char sezione = calcola_sezione(tm);
 | 
						|
  
 | 
						|
  // Memorizza solo la sezione (importi nulli)  
 | 
						|
  part.put(PART_SEZ,       sezione);
 | 
						|
  part.put(PART_SEZABB,    sezione); 
 | 
						|
  part.put(PART_SEZDIFCAM, sezione);
 | 
						|
  
 | 
						|
  return nriga;
 | 
						|
}
 | 
						|
 | 
						|
bool TPartite_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp)
 | 
						|
{ 
 | 
						|
  TRectype oldpag = p.pagamento(nriga, nrata, nrigp);
 | 
						|
  TRiga_partite& somma  = p.riga(nrigp);
 | 
						|
 | 
						|
  const bool nuovo = oldpag.get_char(PAGSCA_ACCSAL) != 'S' && 
 | 
						|
                     oldpag.get_real(PAGSCA_IMPORTO).is_zero() &&
 | 
						|
                     oldpag.get_real(PAGSCA_RITENUTE).is_zero() &&
 | 
						|
                     oldpag.get_real(PAGSCA_RITSOC).is_zero();
 | 
						|
 | 
						|
  // We must create masks on the heap
 | 
						|
  static TPay_mask* pm = NULL;
 | 
						|
  const TGame_mask* parent = NULL; // Parametro ignorato extra-contabilmente
 | 
						|
  if (pm == NULL)
 | 
						|
    pm = new TPay_mask(parent, nuovo ? MODE_INS : MODE_MOD);              
 | 
						|
  else
 | 
						|
    pm->init(parent, nuovo ? MODE_INS : MODE_MOD);               
 | 
						|
  TPay_mask& m = *pm;
 | 
						|
 | 
						|
  TImporto residuo;
 | 
						|
 | 
						|
  if (nriga == TPartita::UNASSIGNED)
 | 
						|
  {              
 | 
						|
    TRiga_scadenze& scaden = somma.new_row();        // Crea una rata falsa
 | 
						|
    scaden.put(SCAD_DATASCAD, somma.get(PART_DATADOC));
 | 
						|
    m.set_pag(oldpag, scaden, residuo);
 | 
						|
    somma.destroy_rows();                            // Distrugge la rata falsa
 | 
						|
  }  
 | 
						|
  else
 | 
						|
  {
 | 
						|
    const TRiga_scadenze& scaden = p.rata(nriga, nrata);
 | 
						|
    m.set_pag(oldpag, scaden, residuo);
 | 
						|
  }
 | 
						|
 | 
						|
  KEY key = m.run();
 | 
						|
  if (key == K_DEL)
 | 
						|
  {
 | 
						|
    const bool truly = noyes_box(TR("Confermare l'eliminazione"));
 | 
						|
    if (!truly) key = K_ESC;
 | 
						|
  }
 | 
						|
  if (key == K_ESC && nuovo)
 | 
						|
    key = K_DEL;
 | 
						|
  
 | 
						|
  if (key != K_ESC)
 | 
						|
  {
 | 
						|
    TRectype newpag(oldpag);
 | 
						|
 | 
						|
    if (key == K_DEL)
 | 
						|
    {
 | 
						|
      newpag.zero(PAGSCA_ACCSAL);      // Non puo' essere un saldo
 | 
						|
      newpag.zero(PAGSCA_IMPORTO);     // Azzera importo ...
 | 
						|
      newpag.zero(PAGSCA_IMPORTOVAL);  // .. anche in valuta
 | 
						|
      newpag.zero(PAGSCA_RITENUTE);    // Azzera ritenute
 | 
						|
      newpag.zero(PAGSCA_RITSOC);
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      m.get_pag(newpag, somma);   
 | 
						|
    }
 | 
						|
    
 | 
						|
    const TValuta val(somma);                              
 | 
						|
    p.modifica_pagamento(newpag, val, true);
 | 
						|
  }       
 | 
						|
 | 
						|
  if (key != K_ESC)
 | 
						|
    p.write(true);
 | 
						|
  
 | 
						|
  return key != K_ESC;
 | 
						|
}
 | 
						|
 | 
						|
bool TPartite_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case DLG_EDIT:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      TTree_field& tree = tfield(F_PARTITE);
 | 
						|
      tree.goto_selected();
 | 
						|
      TToken_string node; _tree.curr_id(node);
 | 
						|
      int level = node.items();
 | 
						|
      if (level < 2)
 | 
						|
        return false;
 | 
						|
 | 
						|
      TPartita& game = *_tree.partita();
 | 
						|
 | 
						|
      const int nriga = node.get_int(1);
 | 
						|
      const int nrata = node.get_int();
 | 
						|
      int nrigp = node.get_int();
 | 
						|
      if (nrigp <= 0 && nriga == TPartita::UNASSIGNED)
 | 
						|
        nrigp = game.unassigned().first_row();
 | 
						|
      
 | 
						|
      long numreg = 0;
 | 
						|
      if (nrigp > 0 && game.esiste(nrigp))
 | 
						|
      {
 | 
						|
        const TRiga_partite& rigp = game.riga(nrigp);
 | 
						|
        numreg = rigp.get_long(PART_NREG);
 | 
						|
      } else
 | 
						|
      if (nriga > 0 && nriga < TPartita::UNASSIGNED && game.esiste(nriga))
 | 
						|
      {
 | 
						|
        TRiga_partite& riga = game.riga(nriga);
 | 
						|
        numreg = riga.get_long(PART_NREG);
 | 
						|
      } 
 | 
						|
      else
 | 
						|
        return false; // Ho cliccato su un nodo impossibile
 | 
						|
 | 
						|
      if (numreg > 0)
 | 
						|
      {
 | 
						|
        TRectype mov(LF_MOV);
 | 
						|
        mov.put(MOV_NUMREG, numreg);
 | 
						|
        const bool done = mov.edit();
 | 
						|
        if (done)
 | 
						|
        {
 | 
						|
          const TPartita disk_game(game.conto(), game.anno(), game.numero());
 | 
						|
          if (disk_game.prima_riga(numreg) <= 0) // Rate spostate in prima nota?
 | 
						|
            app().partite().destroy(game);
 | 
						|
          field(F_TUTTE).on_hit();
 | 
						|
        }
 | 
						|
        return done;
 | 
						|
      }
 | 
						|
 | 
						|
      if (nrigp > 0)
 | 
						|
        edit_pagamento(game, nriga, nrata, nrigp);
 | 
						|
      else
 | 
						|
      {
 | 
						|
        edit_fattura(game, nriga);
 | 
						|
        if (!game.esiste(nriga))
 | 
						|
          app().partite().destroy(game);
 | 
						|
      }
 | 
						|
 | 
						|
      field(F_TUTTE).on_hit();
 | 
						|
      return false;
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case DLG_NEWREC:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      TTree_field& tree = tfield(F_PARTITE);
 | 
						|
      tree.goto_selected();
 | 
						|
      TToken_string node; _tree.curr_id(node);
 | 
						|
      const int level = node.items();
 | 
						|
      int nriga = node.get_int(1);
 | 
						|
      int nrata = node.get_int();
 | 
						|
      int nrigp = node.get_int();
 | 
						|
 | 
						|
      const char tipocf = get(F_TIPO)[0]; 
 | 
						|
      const bool allow_fatt = level < 2;
 | 
						|
 | 
						|
      TNew_mask nm(tipocf, allow_fatt, true);
 | 
						|
      if (level > 0)
 | 
						|
      {
 | 
						|
        const TPartita& game = *_tree.partita();
 | 
						|
        nm.set(P_ANNO, game.anno());
 | 
						|
        nm.set(P_NUMERO, game.numero());
 | 
						|
      }
 | 
						|
 | 
						|
      if (nm.run() == K_ENTER)
 | 
						|
      {
 | 
						|
        const tipo_movimento tm = (tipo_movimento)nm.get_int(P_NUOVO);
 | 
						|
        // modifica o crea partita
 | 
						|
        const int anno = nm.get_int(P_ANNO);
 | 
						|
        const TString& numpart = nm.get(P_NUMERO);
 | 
						|
        TPartita& game = app().partite().partita(_tree.bill(), anno, numpart);
 | 
						|
        if (tm == tm_fattura)
 | 
						|
        {
 | 
						|
          // Crea nuova fattura
 | 
						|
          nriga = nuova_riga_partita(game, tm_fattura);
 | 
						|
          edit_fattura(game, nriga); 
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
          if (level < 3 || nrata <= 0 || nrata >= TPartita::UNASSIGNED)
 | 
						|
            nriga = nrata = TPartita::UNASSIGNED;
 | 
						|
          nrigp = nuova_riga_partita(game, tm);
 | 
						|
          edit_pagamento(game, nriga, nrata, nrigp);
 | 
						|
        }
 | 
						|
        field(F_TUTTE).on_hit();
 | 
						|
      }
 | 
						|
      return  false;
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case F_CODVAL:
 | 
						|
    if (e == fe_modify)
 | 
						|
      field(F_TUTTE).on_hit();
 | 
						|
    break;
 | 
						|
  case F_TUTTE:
 | 
						|
    if (e == fe_init || e == fe_modify)
 | 
						|
    {
 | 
						|
      TBill bill; 
 | 
						|
      const char tipo = get(F_TIPO)[0];
 | 
						|
      const short dlg = tipo == 'C' ? F_CLIENTE : (tipo == 'F' ? F_FORNITORE : F_SOTTOCONTO);
 | 
						|
      bill.get(*this, F_GRUPPO, F_CONTO, dlg, F_TIPO, dlg+1);
 | 
						|
      const TString& codval = get(F_CODVAL);
 | 
						|
      const real cambio = UNO;
 | 
						|
      const TSolder_tree_flags flags = (TSolder_tree_flags)atoi(o.get());
 | 
						|
      _tree.set_root(app().partite(), bill, 0, 0, codval, cambio, flags);
 | 
						|
      //tfield(F_PARTITE).win().force_update();  //non basta la force_update...
 | 
						|
      tfield(F_PARTITE).set_tree(&_tree);        //...serve qualcosa di piu' 'radical' (Pannella?)
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case DLG_USER:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      TWait_cursor hourglass;
 | 
						|
      if (_tree.expanded())
 | 
						|
        _tree.shrink_all();
 | 
						|
      else
 | 
						|
        _tree.expand_all();
 | 
						|
      tfield(F_PARTITE).win().force_update();
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  default: break;
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
TPartite_mask::TPartite_mask() : TAutomask("sc0200b")
 | 
						|
{
 | 
						|
  tfield(F_PARTITE).set_tree(&_tree);
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TGestione_partite
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TGestione_partite : public TSaldaconto_app
 | 
						|
{
 | 
						|
  TPartite_mask* _emsk;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual void edit_partite(const TMask& m);
 | 
						|
 | 
						|
public:
 | 
						|
  TGestione_partite();
 | 
						|
  virtual ~TGestione_partite();
 | 
						|
};
 | 
						|
 | 
						|
void TGestione_partite::edit_partite(const TMask& m)
 | 
						|
{
 | 
						|
  if (_emsk == NULL)
 | 
						|
    _emsk = new TPartite_mask;
 | 
						|
  partite().destroy();
 | 
						|
  _emsk->init(m);
 | 
						|
  _emsk->run();
 | 
						|
}
 | 
						|
 | 
						|
TGestione_partite::TGestione_partite() : _emsk(NULL)
 | 
						|
{ }
 | 
						|
 | 
						|
TGestione_partite::~TGestione_partite()
 | 
						|
{
 | 
						|
  if (_emsk)
 | 
						|
    delete _emsk;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Main
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
int sc0200(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TGestione_partite* gp = new TGestione_partite;
 | 
						|
  gp->run(argc, argv, TR("Gestione Partite"));
 | 
						|
  delete gp;
 | 
						|
  return 0;
 | 
						|
}
 |