Files correlati : mg3.exe mg3100aa.frm Ricompilazione Demo : [ ] Commento : GF20120 Se lancio la stampa con i seguenti parametri SOLO PREZZI, ordinamento ARTICOLI sottordinamento GRUPPO MERCEOLOGICO, stampa TUTTO:Appare il seguente messaggio d'errore: IL CAMPO PREZZOVALORE NON PUO VALERE L continuare ugualmente, se dico si poi la stampa appare ma in essa è anche contenuta la colonna ULTIMO COSTO che invece non dovrebbe, come nella versione a 16 bit, apparire. git-svn-id: svn://10.65.10.50/trunk@11717 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1010 lines
		
	
	
		
			32 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1010 lines
		
	
	
		
			32 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <execp.h>
 | 
						||
#include <mailbox.h>
 | 
						||
#include <printer.h>
 | 
						||
 | 
						||
#include "movmag.h"
 | 
						||
#include "rmovmag.h"
 | 
						||
 | 
						||
#include "mglib.h"
 | 
						||
#include "mg3300.h"
 | 
						||
 | 
						||
#include "../cg/cglib01.h"
 | 
						||
 | 
						||
 | 
						||
TCausale_magazzino& get_cau(const char* codcaus)
 | 
						||
{        
 | 
						||
  static TAssoc_array _c;
 | 
						||
  TCausale_magazzino * caus = (TCausale_magazzino*) _c.objptr(codcaus);
 | 
						||
  if (caus == NULL)
 | 
						||
  {
 | 
						||
    caus = new TCausale_magazzino(codcaus);
 | 
						||
    _c.add(codcaus, caus);
 | 
						||
  }
 | 
						||
  return *caus;
 | 
						||
}
 | 
						||
 | 
						||
class TForm_schedemag : public TForm_stampemg
 | 
						||
{ 
 | 
						||
  int _tolivgiac,_tolivart;
 | 
						||
  TString16 _anno_prec;
 | 
						||
  bool _magazzino_chiuso;
 | 
						||
  bool _sottocatmer;
 | 
						||
  bool _sudd_mag;
 | 
						||
  bool _no_valori;
 | 
						||
  bool _no_ff;
 | 
						||
  bool _sintetica;
 | 
						||
  TDate _data_inizio, _data_fine;
 | 
						||
 | 
						||
  TToken_string *_rmov_sortexp;
 | 
						||
  TString *_rmov_raggcond,*_rmov_joinexp;
 | 
						||
 | 
						||
  TTipo_saldomag _tiposcheda;       // tipo scheda
 | 
						||
  int _annoes;
 | 
						||
 | 
						||
  bool ragg_exprs(int livart,int livgiac);
 | 
						||
  
 | 
						||
public:
 | 
						||
  TToken_string& rmov_sortexp() {return *_rmov_sortexp;}
 | 
						||
  TString & rmov_joinexp() {return *_rmov_joinexp;}
 | 
						||
 | 
						||
  void set_tiposcheda(const char * tipo);
 | 
						||
  void set_chiusura_mag(const int val);
 | 
						||
  void set_data_inizio(const TDate& d) { _data_inizio = d; }
 | 
						||
  bool validate(TForm_item &cf, TToken_string &s);
 | 
						||
  void setdett_perart(bool percatmer, bool sottocatmer,int livart,int livgiac,bool sudd_mag, bool sudd_dep);
 | 
						||
  void setdett_percatmer(bool sottocat,int livart,int livgiac,bool sudd_mag,bool sudd_dep);
 | 
						||
  void setdett_permag(bool sudd_dep, bool showdett,int livart,int livgiac);
 | 
						||
  void set_date_limite(const int anno, const TDate& d, const TDate& e);
 | 
						||
  void set_options(bool no_valori, bool no_ff, bool sintetica);
 | 
						||
  const char* descr_tiposcheda() const;
 | 
						||
  const char* nomecampo_scheda() const;
 | 
						||
  TTipo_saldomag tiposcheda() const {return _tiposcheda;} ;
 | 
						||
 | 
						||
  TForm_schedemag(const char *name,const char *code) ;
 | 
						||
  virtual ~TForm_schedemag();
 | 
						||
};
 | 
						||
 | 
						||
const char* TForm_schedemag::descr_tiposcheda() const
 | 
						||
{
 | 
						||
  switch (_tiposcheda)
 | 
						||
  {
 | 
						||
    case s_giac:
 | 
						||
      return ("Giacenza");
 | 
						||
    case s_acl:
 | 
						||
      return ("A conto lavoro");
 | 
						||
    case s_incl:
 | 
						||
      return ("In conto lavoro");
 | 
						||
    case s_prodc:
 | 
						||
      return ("In produzione componenti");
 | 
						||
    case s_prodf:
 | 
						||
      return ("In produzione finiti");
 | 
						||
    case s_ordc:
 | 
						||
      return ("Ordinato clienti");
 | 
						||
    case s_ordf:
 | 
						||
      return ("Ordinato fornitori");
 | 
						||
  }
 | 
						||
  return "";
 | 
						||
}
 | 
						||
 | 
						||
const char* TForm_schedemag::nomecampo_scheda() const
 | 
						||
{
 | 
						||
  switch (_tiposcheda)
 | 
						||
  {
 | 
						||
    case s_giac:
 | 
						||
      return (MAG_GIAC);
 | 
						||
    case s_acl:
 | 
						||
      return (MAG_ACL);
 | 
						||
    case s_incl:
 | 
						||
      return (MAG_INCL);
 | 
						||
    case s_prodc:
 | 
						||
      return (MAG_PRODCOMP);
 | 
						||
    case s_prodf:
 | 
						||
      return (MAG_PRODFIN);
 | 
						||
    case s_ordc:
 | 
						||
      return (MAG_ORDC);
 | 
						||
    case s_ordf:
 | 
						||
      return (MAG_ORDF);
 | 
						||
  }
 | 
						||
  return "";
 | 
						||
}
 | 
						||
 | 
						||
bool TForm_schedemag::validate(TForm_item &cf, TToken_string &s)
 | 
						||
{ 
 | 
						||
  const TString code(s.get(0)); // prende il primo parametro, il codice del messaggio
 | 
						||
  TString subcode;
 | 
						||
 | 
						||
  if (code=="_USER") {
 | 
						||
    subcode=s.get();
 | 
						||
    if (subcode=="TIPOSCHEDA") {
 | 
						||
      cf.set(descr_tiposcheda());
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
    if (subcode=="GRUPPOART") 
 | 
						||
    {
 | 
						||
      TString valore;
 | 
						||
      if (_tolivart==livelli_articolo().last_level())
 | 
						||
        valore=relation()->lfile(LF_ANAMAG).get("DESCR");
 | 
						||
      else
 | 
						||
        valore=livelli_articolo().group_descr_packed(relation()->lfile(LF_ANAMAG).get("CODART"),_tolivart);
 | 
						||
      cf.set(valore);
 | 
						||
      return TRUE;
 | 
						||
    } 
 | 
						||
    if (subcode=="CODGRUPPOGIAC") 
 | 
						||
    {
 | 
						||
      TString valore,levname;
 | 
						||
      int livello=_tolivgiac;
 | 
						||
      levname=livelli_giacenza().name(livello);
 | 
						||
      add_giaclev(levname,1,livello);
 | 
						||
      levname << ' ';
 | 
						||
      valore=livelli_giacenza().unpack_grpcode(relation()->lfile(LF_MAG).get("LIVELLO"),livello);
 | 
						||
      if (valore.empty())
 | 
						||
        valore = UNKNOWN_NAME;
 | 
						||
      cf.set(levname << valore);
 | 
						||
 | 
						||
      //TForm_stampemg::validate(cf, s);
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
    if (subcode=="CODGRUPPOART") 
 | 
						||
    {
 | 
						||
      TString valore(relation()->lfile(LF_ANAMAG).get("CODART"));
 | 
						||
      if (livelli_articolo().enabled())
 | 
						||
        valore.cut(min(valore.len(),livelli_articolo().packed_length(_tolivart)));
 | 
						||
      cf.set(valore);
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
    if (subcode=="GRUPPOGIAC") 
 | 
						||
    {
 | 
						||
      const char* valore=livelli_giacenza().group_descr_packed(relation()->lfile(LF_RMOVMAG).get("LIVGIAC"),_tolivgiac);
 | 
						||
      cf.set(valore);
 | 
						||
      return TRUE;
 | 
						||
    }  
 | 
						||
    if (subcode=="CODCATMER") 
 | 
						||
    {
 | 
						||
      TString valore(relation()->lfile(LF_ANAMAG).get("GRMERC"));
 | 
						||
      if (!_sottocatmer)
 | 
						||
        valore.cut(3);
 | 
						||
      cf.set(valore);
 | 
						||
      return TRUE;
 | 
						||
    }  
 | 
						||
    if (subcode=="CATMER") 
 | 
						||
    {
 | 
						||
      const char* valore = "";
 | 
						||
      if (_sottocatmer)
 | 
						||
        valore=relation()->lfile(-ALIAS_SOTTOCATMER).get("S0");
 | 
						||
      else
 | 
						||
        valore=relation()->lfile(-ALIAS_CATMER).get("S0");
 | 
						||
      cf.set(valore);
 | 
						||
      return TRUE;
 | 
						||
    }  
 | 
						||
    if (subcode=="DADATA")
 | 
						||
    {
 | 
						||
      cf.set(_data_inizio.string());      
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
    if (subcode=="ADATA")
 | 
						||
    {
 | 
						||
      cf.set(_data_fine.string());
 | 
						||
      return TRUE;
 | 
						||
    }   
 | 
						||
    
 | 
						||
    const TRectype& rmovmag = relation()->curr(LF_RMOVMAG);
 | 
						||
    const TRectype& movmag = relation()->curr(LF_MOVMAG);
 | 
						||
    const TString16 cau_r= rmovmag.get(RMOVMAG_CODCAUS);
 | 
						||
    const TString16 cau_m= movmag.get(MOVMAG_CODCAUS);
 | 
						||
//    const TCausale_magazzino cau(cau_r.empty() ? cau_m : cau_r);
 | 
						||
    const TCausale_magazzino & cau = get_cau(cau_r.empty() ? cau_m : cau_r);
 | 
						||
    if (subcode=="*SEGNOCAUS") {
 | 
						||
      const char qv = s.get_char();  // Segno per Quantita'o Valore
 | 
						||
      int sgn = cau.sgn(_tiposcheda);
 | 
						||
      switch(qv)
 | 
						||
      {       
 | 
						||
      case 'Q': if (!cau.update_qta()) sgn = 0; break;
 | 
						||
      case 'V': if (!cau.update_val()) sgn = 0; break;
 | 
						||
      default : break;
 | 
						||
      }
 | 
						||
      if (sgn)
 | 
						||
      {
 | 
						||
        real v(cf.get());
 | 
						||
        v *= real(sgn);
 | 
						||
        cf.set(v.string());
 | 
						||
      }
 | 
						||
      else
 | 
						||
        cf.set("");  
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
    if (subcode=="CAUSALERIGA") 
 | 
						||
    {
 | 
						||
      cf.set(cau.codice());
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
    if (subcode=="DESCRCAUSALE") 
 | 
						||
    {
 | 
						||
      cf.set(cau.descr());
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
    if (subcode=="CANPRINTSALDOPREC")   // Determina se e' possibile stampare il saldo precedente
 | 
						||
    {                                                  
 | 
						||
      bool yes = TRUE;
 | 
						||
      const TDate datareg = movmag.get(MOVMAG_DATAREG);
 | 
						||
      // Se il movimento corrente e' >= la data inizio stampa allora posso sempre stampare il saldo ...
 | 
						||
      if (datareg < _data_inizio)   // ... altrimenti devo fare altri controlli
 | 
						||
      {     
 | 
						||
        const bool stampa_perart = relation()->lfile().num() == LF_ANAMAG;
 | 
						||
        if (stampa_perart)  // Stampa per articoli
 | 
						||
        {
 | 
						||
          TSortedfile& rmm = (TSortedfile&)relation()->lfile(LF_RMOVMAG);
 | 
						||
          const TRecnotype oldpos = rmm.recno();
 | 
						||
          TString80 old_art; 
 | 
						||
          old_art << rmm.get(RMOVMAG_CODART); old_art << '|' << rmm.get(RMOVMAG_LIVGIAC);
 | 
						||
          const int err = rmm.next();
 | 
						||
          if (err == NOERR) // Se non sono sull'ultimo record ...
 | 
						||
          {
 | 
						||
            const TRectype& next_movmag = rmm.relation().curr(LF_MOVMAG);
 | 
						||
            const TDate next_datareg = next_movmag.get(MOVMAG_DATAREG);
 | 
						||
            // Se il prossimo record e' dopo la data iniziale devo stampre il saldo
 | 
						||
            // Lo stesso dicasi se la prossima data e' inferiore alla corrente (sono su un altro articolo!)
 | 
						||
            yes = next_datareg >= _data_inizio || next_datareg < datareg;
 | 
						||
            if (!yes)
 | 
						||
            {
 | 
						||
              // Se la prossima data e' >= della corrente verifico se cambio articolo
 | 
						||
              TString80 new_art; 
 | 
						||
              new_art << rmm.get(RMOVMAG_CODART); new_art << '|' << rmm.get(RMOVMAG_LIVGIAC);
 | 
						||
              yes = old_art != new_art;
 | 
						||
            }
 | 
						||
          }
 | 
						||
          rmm.readat(oldpos); // ripristino la posizione del file
 | 
						||
        }
 | 
						||
        else  // Stampa per magazzini  
 | 
						||
        {
 | 
						||
          TSortedfile& rmm = (TSortedfile&)relation()->lfile(LF_RMOVMAG);
 | 
						||
          const TRecnotype oldpos = rmm.recno();
 | 
						||
          TString80 old_art; 
 | 
						||
          old_art << rmm.get(RMOVMAG_CODART); 
 | 
						||
          old_art << '|' << rmm.get(RMOVMAG_LIVGIAC);
 | 
						||
          old_art << '|' << rmm.get(RMOVMAG_CODMAG);
 | 
						||
          
 | 
						||
          const int err = rmm.next();
 | 
						||
          if (err == NOERR) // Se non sono sull'ultimo record ...
 | 
						||
          {
 | 
						||
            const long next_num_reg =  rmm.get_long(RMOVMAG_NUMREG);
 | 
						||
            const TRectype& next_movmag = cache().get(LF_MOVMAG, next_num_reg);
 | 
						||
            const TDate next_datareg = next_movmag.get(MOVMAG_DATAREG);
 | 
						||
            // Se il prossimo record e' dopo la data iniziale devo stampre il saldo
 | 
						||
            // Lo stesso dicasi se la prossima data e' inferiore alla corrente (sono su un altro articolo!)
 | 
						||
            yes = next_datareg >= _data_inizio || next_datareg < datareg;
 | 
						||
            if (!yes)
 | 
						||
            {
 | 
						||
              // Se la prossima data e' >= della corrente verifico se cambio articolo
 | 
						||
              TString80 new_art; 
 | 
						||
              new_art << rmm.get(RMOVMAG_CODART); 
 | 
						||
              new_art << '|' << rmm.get(RMOVMAG_LIVGIAC);
 | 
						||
              new_art << '|' << rmm.get(RMOVMAG_CODMAG);
 | 
						||
              yes = old_art != new_art;
 | 
						||
            }
 | 
						||
          }
 | 
						||
          rmm.readat(oldpos); // ripristino la posizione del file
 | 
						||
        }  
 | 
						||
      }
 | 
						||
      cf.set(yes ? "1" : "0");
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
    if (subcode=="SALDOPREC") 
 | 
						||
    {
 | 
						||
      if (!_magazzino_chiuso) // mag precedente non chiuso, mancano i saldi di apertura
 | 
						||
      {
 | 
						||
        TLocalisamfile mag_annoprec(LF_MAG);
 | 
						||
        TString codmag, codart, livello;
 | 
						||
        
 | 
						||
        const bool stampa_perart = relation()->lfile().num() == LF_ANAMAG;
 | 
						||
        if (stampa_perart)  // Stampa per articoli
 | 
						||
        {
 | 
						||
          const TRectype& rmovmag = cursor()->curr(LF_RMOVMAG); // Record collegato a LF_ANAMAG
 | 
						||
          codmag = rmovmag.get(RMOVMAG_CODMAG);
 | 
						||
          codart = rmovmag.get(RMOVMAG_CODART);
 | 
						||
          livello = rmovmag.get(RMOVMAG_LIVGIAC);
 | 
						||
        }
 | 
						||
        else
 | 
						||
        {    
 | 
						||
          // Nella stampa per magazzini al momento del saldo sono avanti di un passo rispetto a dove mi serve
 | 
						||
          if (cursor()->pos() > 0L)
 | 
						||
          {
 | 
						||
            --(*cursor());
 | 
						||
            const TRectype& rmovmag = cursor()->curr(LF_RMOVMAG);  // Record principale
 | 
						||
            codmag = rmovmag.get(RMOVMAG_CODMAG);
 | 
						||
            codart = rmovmag.get(RMOVMAG_CODART);
 | 
						||
            livello = rmovmag.get(RMOVMAG_LIVGIAC);
 | 
						||
            ++(*cursor());
 | 
						||
          }
 | 
						||
        }
 | 
						||
        
 | 
						||
        mag_annoprec.put(MAG_ANNOES, _anno_prec);
 | 
						||
        mag_annoprec.put(MAG_CODMAG, codmag);
 | 
						||
        mag_annoprec.put(MAG_CODART, codart);
 | 
						||
        mag_annoprec.put(MAG_LIVELLO, livello);
 | 
						||
        if (_sudd_mag) // Se e' una stampa dettagliata per magazzino
 | 
						||
        {
 | 
						||
          mag_annoprec.setkey(2);  
 | 
						||
          if (mag_annoprec.read() == NOERR)  // Ho trovato un saldo precedente del magazzino in questione
 | 
						||
          {
 | 
						||
            const real saldoprec = mag_annoprec.get_real(nomecampo_scheda());
 | 
						||
            if (!saldoprec.is_zero())
 | 
						||
            {
 | 
						||
              real currsaldo = cf.get();   
 | 
						||
              currsaldo += saldoprec;       // Sommo il saldo precedente al campo corrente
 | 
						||
              cf.set(currsaldo.string());
 | 
						||
            }
 | 
						||
          }  
 | 
						||
        }
 | 
						||
        else
 | 
						||
        { 
 | 
						||
          // Calcolo la somma dei saldi di tutti i magazzini
 | 
						||
          mag_annoprec.setkey(1);
 | 
						||
          real currsaldo = cf.get();   
 | 
						||
          for (int r = 1; ; r++)
 | 
						||
          {           
 | 
						||
            mag_annoprec.put(MAG_NRIGA, r);
 | 
						||
            if (mag_annoprec.read() != NOERR)
 | 
						||
              break;
 | 
						||
            const real saldoprec = mag_annoprec.get_real(nomecampo_scheda());
 | 
						||
            currsaldo += saldoprec;       // Sommo il saldo precedente al campo corrente
 | 
						||
          }
 | 
						||
          cf.set(currsaldo.string());
 | 
						||
        }  
 | 
						||
      }
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
 | 
						||
    if (subcode.left(3) == "ADD")
 | 
						||
    {                         
 | 
						||
      const TString16 cau = cf.section().find_field(FF_CAUSALE_RIGA).get();
 | 
						||
      TCausale_magazzino & ccrr = get_cau(cau);
 | 
						||
      const bool is_qta = subcode.right(3) == "QTA"; 
 | 
						||
      const bool ok = is_qta && ccrr.update_qta() || !is_qta && ccrr.update_val();
 | 
						||
      if (ok)
 | 
						||
      {
 | 
						||
        const short fld = s.get_int(2);
 | 
						||
        TForm_item& dest = cf.section().find_field(fld);
 | 
						||
        real v1(cf.get());
 | 
						||
        real v2(dest.get());
 | 
						||
          
 | 
						||
        v2 += v1;
 | 
						||
        dest.set(v2.string());
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TForm_stampemg::validate(cf, s);
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
bool TForm_schedemag::ragg_exprs(int livart,int livgiac)
 | 
						||
{
 | 
						||
  TString piece,rest;
 | 
						||
  // ***********
 | 
						||
  int tolivart,tolivgiac;
 | 
						||
 | 
						||
  tolivart =livart  ? livart  : livelli_articolo().last_level() ;
 | 
						||
  tolivgiac=livgiac ? livgiac : livelli_giacenza().last_level();
 | 
						||
  // sezioni livello codice 
 | 
						||
  piece="CODART";
 | 
						||
  if (livelli_articolo().enabled())
 | 
						||
    piece << "[1," << livelli_articolo().packed_length(tolivart) <<']';
 | 
						||
  *_rmov_raggcond<< (_rmov_raggcond->empty()? "":"+" )<<piece;
 | 
						||
  _rmov_sortexp->add(piece);
 | 
						||
  _rmov_joinexp->cut(0) << piece << "==" << piece;
 | 
						||
  if (livart==0)
 | 
						||
  {
 | 
						||
    piece="LIVGIAC";
 | 
						||
    if (livelli_giacenza().enabled())
 | 
						||
      piece << "[1," << livelli_giacenza().packed_length(tolivgiac) <<']';
 | 
						||
    *_rmov_raggcond << '+' << piece;
 | 
						||
    _rmov_sortexp->add(piece);
 | 
						||
  }
 | 
						||
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
void TForm_schedemag::setdett_permag(bool sudd_dep,bool show_dett,int livart,int livgiac)
 | 
						||
{
 | 
						||
  TForm_subsection &h_d=(TForm_subsection &)find_field('B',odd_page,"HEADER_DEP");
 | 
						||
  h_d.enable(sudd_dep);
 | 
						||
  TForm_subsection &h_a=(TForm_subsection &)find_field('B',odd_page,"HEADER_ARTICOLO");
 | 
						||
  h_a.enable(show_dett);
 | 
						||
  TForm_subsection &h_g=(TForm_subsection &)find_field('B',odd_page,"HEADER_LIVGIAC");
 | 
						||
  h_g.enable(livelli_giacenza().enabled() && (livart ==0 || livgiac !=0 ));
 | 
						||
 | 
						||
  *_rmov_raggcond="CODMAG[1,3]";
 | 
						||
  _rmov_sortexp->add("CODMAG[1,3]");
 | 
						||
  if (sudd_dep) 
 | 
						||
  {
 | 
						||
    *_rmov_raggcond << "+CODMAG[4,5]";
 | 
						||
    _rmov_sortexp->add("CODMAG[4,5]");
 | 
						||
  }
 | 
						||
  if (show_dett)
 | 
						||
  {
 | 
						||
    ragg_exprs(livart,livgiac);
 | 
						||
  }
 | 
						||
  
 | 
						||
  TForm_subsection &s=(TForm_subsection &)find_field('B',odd_page,"GRUPPI_RMOVMAG");
 | 
						||
  s.setcondition(*_rmov_raggcond,_strexpr);
 | 
						||
 | 
						||
  TString cond;
 | 
						||
  cond << LF_MOVMAG << "->DATAREG";
 | 
						||
  _rmov_sortexp->add(cond);
 | 
						||
  _rmov_sortexp->add("NUMREG");
 | 
						||
 | 
						||
  _tolivart=livart  ? livart  :livelli_articolo().last_level() ;
 | 
						||
  _tolivgiac=livgiac ? livgiac :livelli_giacenza().last_level();
 | 
						||
  
 | 
						||
  _sudd_mag = TRUE;   // E' una stampa suddvisa per magazzini
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
void TForm_schedemag::setdett_percatmer(bool sottocat,int livart,int livgiac,bool sudd_mag,bool sudd_dep)
 | 
						||
{
 | 
						||
  TForm_subsection &h_c=(TForm_subsection &)find_field('B',odd_page,"HEADER_CATMER");
 | 
						||
  h_c.enable();
 | 
						||
  TForm_subsection &h_a=(TForm_subsection &)find_field('B',odd_page,"HEADER_ARTICOLO");
 | 
						||
  h_a.enable();
 | 
						||
  h_a.set_newpage(livart !=0 && livgiac ==0 && !sudd_mag && !_no_ff);
 | 
						||
  TForm_subsection &h_g=(TForm_subsection &)find_field('B',odd_page,"HEADER_GRMOV");
 | 
						||
  h_g.enable(livart ==0 || livgiac !=0 || sudd_mag);
 | 
						||
  h_g.set_newpage(livart ==0 || livgiac !=0 || sudd_mag && !_no_ff);
 | 
						||
  TForm_subsection &h_l=(TForm_subsection &)find_field('B',odd_page,"HEADER_LIVGIAC");
 | 
						||
  h_l.enable(livelli_giacenza().enabled() && (livgiac !=0 ||livart ==0));
 | 
						||
  TForm_subsection &h_m=(TForm_subsection &)find_field('B',odd_page,"HEADER_MAG");
 | 
						||
  h_m.enable(sudd_mag );
 | 
						||
  TForm_subsection &h_d=(TForm_subsection &)find_field('B',odd_page,"HEADER_DEP");
 | 
						||
  h_d.enable(sudd_dep);
 | 
						||
 | 
						||
  TString piece;
 | 
						||
  piece << LF_ANAMAG << "->GRMERC";
 | 
						||
  if (!sottocat)
 | 
						||
    piece << "[1,3]";
 | 
						||
 | 
						||
  *_rmov_raggcond=piece;
 | 
						||
  _rmov_sortexp->add(piece);
 | 
						||
 | 
						||
  ragg_exprs(livart,livgiac);
 | 
						||
  if (sudd_mag) {
 | 
						||
    *_rmov_raggcond="+CODMAG[1,3]";
 | 
						||
    _rmov_sortexp->add("CODMAG[1,3]");
 | 
						||
    if (sudd_dep) {
 | 
						||
      *_rmov_raggcond << "+CODMAG[4,5]";
 | 
						||
      _rmov_sortexp->add("CODMAG[4,5]");
 | 
						||
    }
 | 
						||
  }
 | 
						||
  
 | 
						||
  TForm_subsection &s=(TForm_subsection &)find_field('B',odd_page,"GRUPPI_RMOVMAG");
 | 
						||
  s.setcondition(*_rmov_raggcond,_strexpr);
 | 
						||
 | 
						||
  TString cond;
 | 
						||
  cond << LF_MOVMAG << "->DATAREG";
 | 
						||
  _rmov_sortexp->add(cond);
 | 
						||
  _rmov_sortexp->add("NUMREG");
 | 
						||
  _rmov_sortexp->add("CAUS");
 | 
						||
 | 
						||
  _tolivart=livart  ? livart  :livelli_articolo().last_level() ;
 | 
						||
  _tolivgiac=livgiac ? livgiac :livelli_giacenza().last_level();
 | 
						||
  _sottocatmer=sottocat;
 | 
						||
}
 | 
						||
 | 
						||
void TForm_schedemag::setdett_perart(bool percatmer,bool sottocatmer,int livart,int livgiac,bool sudd_mag,bool sudd_dep)
 | 
						||
{
 | 
						||
  // raggruppamento MAX fino all'articolo
 | 
						||
  TForm_subsection &h_cm=(TForm_subsection &)find_field('B',odd_page,"HEADER_CATMER");
 | 
						||
  h_cm.enable(percatmer);
 | 
						||
  TForm_subsection &h_cm2=(TForm_subsection &)find_field('B',odd_page,"HEADER_LIVGIACCATMER");
 | 
						||
  h_cm2.enable(percatmer);
 | 
						||
 | 
						||
  TForm_subsection &h_a=(TForm_subsection &)find_field('B',odd_page,"HEADER_ARTICOLO");
 | 
						||
  h_a.enable     (livart!=0 && !sudd_mag);
 | 
						||
  h_a.set_newpage(livart!=0 && !sudd_mag && !_no_ff);
 | 
						||
  TForm_subsection &t_a=(TForm_subsection &)find_field('B',odd_page,"TOTALI_GRUPPIART");
 | 
						||
  t_a.show(  livart!=0 && !sudd_mag);
 | 
						||
 | 
						||
  // raggruppamento MAX fino alla giacenza
 | 
						||
  TForm_subsection &h_g=(TForm_subsection &)find_field('B',odd_page,"HEADER_GRMOV");
 | 
						||
  h_g.enable(livart ==0 || livgiac !=0 || sudd_mag);   
 | 
						||
  h_g.set_newpage(!_no_ff && (livart ==0 || livgiac !=0 || sudd_mag));
 | 
						||
  TForm_subsection &h_l=(TForm_subsection &)find_field('B',odd_page,"HEADER_LIVGIAC");
 | 
						||
  h_l.enable(livelli_giacenza().enabled() && (livart ==0 || livgiac !=0 ));
 | 
						||
  TForm_subsection &h_m=(TForm_subsection &)find_field('B',odd_page,"HEADER_MAG");
 | 
						||
  h_m.enable(sudd_mag );
 | 
						||
  TForm_subsection &h_d=(TForm_subsection &)find_field('B',odd_page,"HEADER_DEP");
 | 
						||
  h_d.enable(sudd_dep);
 | 
						||
 | 
						||
  TForm_subsection &t_s=(TForm_subsection &)find_field('B',odd_page,"TOTALI_GRMOV");
 | 
						||
  t_s.show(livart==0 || livgiac !=0 || sudd_mag);
 | 
						||
 | 
						||
  _tolivart=livart  ? livart  :livelli_articolo().last_level() ;
 | 
						||
  _tolivgiac=livgiac ? livgiac :livelli_giacenza().last_level();
 | 
						||
  _sottocatmer=sottocatmer;
 | 
						||
 | 
						||
  // settaggio catmer/ragg codice
 | 
						||
  if (livart || percatmer) {
 | 
						||
    TForm_subsection &s=(TForm_subsection &)find_field('B',odd_page,"GRUPPI_ARTICOLO");
 | 
						||
    TString cond;
 | 
						||
    if (percatmer) 
 | 
						||
      cond << "GRMERC" << (sottocatmer ? "[1,3]" : "") << '+';   
 | 
						||
    cond << "CODART[1," << livelli_articolo().packed_length(_tolivart) << ']';    
 | 
						||
    s.setcondition(cond,_strexpr);
 | 
						||
  }
 | 
						||
  // settaggio raggruppamenti codice sulla scheda
 | 
						||
  ragg_exprs(livart,livgiac);
 | 
						||
  
 | 
						||
  _sudd_mag = sudd_mag;  // E' una stampa suddvisa per magazzini?
 | 
						||
  if (sudd_mag) 
 | 
						||
  {
 | 
						||
    *_rmov_raggcond << "+CODMAG[1,3]";
 | 
						||
    _rmov_sortexp->add("CODMAG[1,3]");
 | 
						||
    if (sudd_dep) 
 | 
						||
    {
 | 
						||
      *_rmov_raggcond << "+CODMAG[4,5]";
 | 
						||
      _rmov_sortexp->add("CODMAG[4,5]");
 | 
						||
    }
 | 
						||
  } 
 | 
						||
  TForm_subsection &s=(TForm_subsection &)find_field('B',odd_page,"GRUPPI_RMOVMAG");
 | 
						||
  s.setcondition(*_rmov_raggcond,_strexpr);
 | 
						||
  TString cond;
 | 
						||
  cond << LF_MOVMAG << "->DATAREG";
 | 
						||
  _rmov_sortexp->add(cond);
 | 
						||
  _rmov_sortexp->add("NUMREG");
 | 
						||
}
 | 
						||
 | 
						||
void TForm_schedemag::set_tiposcheda(const char * tipo)
 | 
						||
{
 | 
						||
  if (*tipo=='G')
 | 
						||
    _tiposcheda=s_giac;
 | 
						||
  if (*tipo=='A')
 | 
						||
    _tiposcheda=s_acl;
 | 
						||
  if (*tipo=='I')
 | 
						||
    _tiposcheda=s_incl;
 | 
						||
  if (*tipo=='P')
 | 
						||
  {
 | 
						||
    if (tipo[1]=='F')
 | 
						||
      _tiposcheda=s_prodf;
 | 
						||
    else
 | 
						||
      _tiposcheda=s_prodc;
 | 
						||
  }
 | 
						||
  if (*tipo=='O')
 | 
						||
  {
 | 
						||
    if (tipo[1]=='F')
 | 
						||
      _tiposcheda=s_ordf;
 | 
						||
    else
 | 
						||
      _tiposcheda=s_ordc;
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TForm_schedemag::set_options(bool no_valori, bool no_ff, bool sintetica)
 | 
						||
{
 | 
						||
  _no_valori = no_valori;
 | 
						||
  if (_no_valori)
 | 
						||
  {
 | 
						||
    ((TForm_item &)find_field('H',odd_page, 8)).hide();
 | 
						||
    ((TForm_item &)find_field('H',odd_page, 9)).hide();
 | 
						||
    ((TForm_item &)find_field('B',odd_page, 104)).hide();
 | 
						||
    
 | 
						||
    ((TForm_item &)find_field('B',odd_page, 105)).hide();
 | 
						||
    ((TForm_item &)find_field('B',odd_page, FF_VALORE_GART)).hide();
 | 
						||
    
 | 
						||
    ((TForm_item &)find_field('B',odd_page, FF_VALORE_MOV)).hide();
 | 
						||
    ((TForm_item &)find_field('B',odd_page, 190)).hide(); 
 | 
						||
 | 
						||
    if (name().left(7) == "mg3300a")
 | 
						||
      ((TForm_item &)find_field('B',odd_page, FF_VALORE_GRMOV)).hide();
 | 
						||
  }
 | 
						||
  _no_ff = no_ff;
 | 
						||
  _sintetica = sintetica;
 | 
						||
}
 | 
						||
 | 
						||
void TForm_schedemag::set_date_limite(const int anno, const TDate& d, const TDate& e)
 | 
						||
{
 | 
						||
  TEsercizi_contabili ec;
 | 
						||
  
 | 
						||
  _annoes = anno;
 | 
						||
  _anno_prec.format("%4d",ec.pred(anno));
 | 
						||
  _magazzino_chiuso = (ec.pred(anno) == 0) || !(ec.esercizio(atoi(_anno_prec)).chiusura_mag().empty());
 | 
						||
 
 | 
						||
   _data_inizio = d;
 | 
						||
   _data_fine = e;
 | 
						||
   
 | 
						||
   const TEsercizio& es = ec[_annoes];
 | 
						||
   
 | 
						||
   if (!_data_inizio.ok())
 | 
						||
   {
 | 
						||
     _data_inizio = es.inizio();
 | 
						||
   }
 | 
						||
   if (!_data_fine.ok())
 | 
						||
   {
 | 
						||
     _data_fine = es.fine();
 | 
						||
   }     
 | 
						||
}
 | 
						||
 | 
						||
TForm_schedemag::TForm_schedemag(const char *name,const char *code) 
 | 
						||
               : TForm_stampemg(name,code)
 | 
						||
{
 | 
						||
  _tolivgiac=0;
 | 
						||
  _tolivart=0;
 | 
						||
 | 
						||
  _rmov_sortexp=new TToken_string;
 | 
						||
  _rmov_joinexp=new TString;
 | 
						||
  _rmov_raggcond=new TString;
 | 
						||
}
 | 
						||
 | 
						||
TForm_schedemag::~TForm_schedemag()
 | 
						||
{
 | 
						||
  delete _rmov_sortexp;
 | 
						||
  delete _rmov_joinexp;
 | 
						||
  delete _rmov_raggcond;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
// mg3300       Stampa 
 | 
						||
// mg3300       Stampa 
 | 
						||
class TStampa_schede_mag : public TSkeleton_application
 | 
						||
{
 | 
						||
  static TStampemg_mask * _mask; // static so they are visible from filter function
 | 
						||
  TForm_schedemag *_form; // to be moved into TPrint_application
 | 
						||
  TCursor * _cur;
 | 
						||
 | 
						||
  int _codicees;
 | 
						||
  bool _raggmag;         
 | 
						||
  bool _autorun;
 | 
						||
  
 | 
						||
protected:
 | 
						||
  virtual bool create();
 | 
						||
  virtual bool destroy();
 | 
						||
  virtual void main_loop();
 | 
						||
  static bool negatives_only(const TRelation* rel);
 | 
						||
  static bool cau_filter(const TRelation* rel);
 | 
						||
 | 
						||
  void setprint_perarticoli();
 | 
						||
  void setprint_permagazzini();
 | 
						||
  
 | 
						||
protected:
 | 
						||
  static bool handle_dadata(TMask_field& f, KEY k);
 | 
						||
  static bool handle_adata(TMask_field& f, KEY k);
 | 
						||
    
 | 
						||
public:            
 | 
						||
  TTipo_saldomag tiposcheda() const {return _form->tiposcheda();} ;
 | 
						||
  void autorun() { _autorun = TRUE; }
 | 
						||
  TStampa_schede_mag() {}
 | 
						||
};
 | 
						||
 | 
						||
TStampa_schede_mag& app() { return (TStampa_schede_mag&)main_app(); }
 | 
						||
 | 
						||
TStampemg_mask* TStampa_schede_mag::_mask = NULL; 
 | 
						||
 | 
						||
bool TStampa_schede_mag::negatives_only(const TRelation* rel)
 | 
						||
{                           
 | 
						||
  const TString codart = rel->curr(LF_ANAMAG).get(ANAMAG_CODART);
 | 
						||
  const int anno = _mask->get_int(F_ANNOES);
 | 
						||
  TArticolo_giacenza artgiac(codart);
 | 
						||
  const real giac = artgiac.giacenza_anno(NULL, NULL, anno);
 | 
						||
  return giac < ZERO;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_schede_mag::cau_filter(const TRelation* rel)
 | 
						||
{      
 | 
						||
  const TRectype& rmov = rel->curr(LF_RMOVMAG);
 | 
						||
  TString16 cau = rmov.get(RMOVMAG_CODCAUS);
 | 
						||
  if (cau.empty())
 | 
						||
    cau = cache().get(LF_MOVMAG, rmov.get(RMOVMAG_NUMREG), MOVMAG_CODCAUS);
 | 
						||
  return get_cau(cau).sgn(app().tiposcheda()) != 0;
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_schede_mag::setprint_permagazzini()
 | 
						||
{
 | 
						||
  char subordine=*_mask->get(F_ORDINEART);
 | 
						||
  TRectype darec(LF_RMOVMAG),arec(LF_RMOVMAG);
 | 
						||
  TString cfilter;
 | 
						||
 | 
						||
  _form->set_tiposcheda(_mask->get(F_SCHEDA));
 | 
						||
  _cur = _form->cursor();
 | 
						||
  // filtering from/to MAGS
 | 
						||
  if (_mask->get(F_DAMAG).not_empty())
 | 
						||
    cfilter << "(CODMAG[1,3]>=" <<'"' << _mask->get(F_DAMAG)<< "\")&&" ;
 | 
						||
  if (_mask->get(F_AMAG).not_empty())
 | 
						||
    cfilter << "(CODMAG[1,3]<=" <<'"' << _mask->get(F_AMAG)<< "\")&&" ;
 | 
						||
 | 
						||
  if (_mask->get(F_DADEP).not_empty())
 | 
						||
    cfilter << "(CODMAG[4,]>=" <<'"' << _mask->get(F_DADEP)<< "\")&&" ;
 | 
						||
  if (_mask->get(F_ADEP).not_empty())
 | 
						||
    cfilter << "(CODMAG[4,]<=" <<'"' << _mask->get(F_ADEP)<< "\")&&" ;
 | 
						||
 | 
						||
  cfilter << "(" << LF_MOVMAG <<"->ANNOES==" <<'"' << _mask->get(F_ANNOES)<< "\")&&" ;
 | 
						||
  // filtering from/to DATA
 | 
						||
  if (*_mask->get(F_ADATA)) 
 | 
						||
  {
 | 
						||
    TDate d1(_mask->get(F_ADATA));
 | 
						||
    cfilter << "(ANSI(110->DATAREG)<=" <<'"' << d1.string(ANSI) << "\")&&" ;
 | 
						||
  }
 | 
						||
  if (_mask->get(F_DADATA).not_empty())
 | 
						||
  {
 | 
						||
    TDate d1(_mask->get(F_DADATA));
 | 
						||
    TString cond;
 | 
						||
    
 | 
						||
    cond << "ANSI(" << LF_MOVMAG << "->DATAREG)>=\"" << d1.string(ANSI) << '"';
 | 
						||
    ((TForm_subsection &)_form->find_field('B',odd_page,"MOVS_INTERESSATI")).setcondition(cond,_strexpr);   
 | 
						||
    ((TForm_subsection &)_form->find_field('B',odd_page,"H_MOVS_INTERESSATI")).setcondition(cond,_strexpr);   
 | 
						||
    cond.cut(0) << "ANSI(" << LF_MOVMAG << "->DATAREG)<\"" << d1.string(ANSI) << '"';
 | 
						||
    ((TForm_subsection &)_form->find_field('B',odd_page,"MOVS_PRECEDENTI")).setcondition(cond,_strexpr);    
 | 
						||
  }
 | 
						||
 | 
						||
  // Imposta i livelli di dettaglio della scheda
 | 
						||
  _form->setdett_permag(
 | 
						||
    _mask->get_bool(F_DETTAGLIOMAG),
 | 
						||
    _mask->get_bool(F_DETTAGLIODEP),
 | 
						||
    _mask->get_int(F_TOLIVELLOART),
 | 
						||
    _mask->get_int(F_TOLIVELLOGIAC));
 | 
						||
 | 
						||
  // filtering from/to ART
 | 
						||
  darec.put("CODART",_mask->get(F_DAART));
 | 
						||
  arec.put("CODART",_mask->get(F_AART));
 | 
						||
 | 
						||
  // filtering ONLY NEGATIVES
 | 
						||
  if (_mask->get(F_FILTRO)[0]=='N') 
 | 
						||
    _cur->set_filterfunction(negatives_only, TRUE);
 | 
						||
  
 | 
						||
  // prepare cursor to print....
 | 
						||
  ((TSorted_cursor *)_cur)->change_order(_form->rmov_sortexp());
 | 
						||
  if (cfilter.not_empty())
 | 
						||
    cfilter.rtrim(2); 
 | 
						||
 | 
						||
  TLocalisamfile *mag=new TLocalisamfile(LF_MAG);
 | 
						||
  mag->setkey(2);
 | 
						||
  TString mag_joinexp;
 | 
						||
  mag_joinexp << "ANNOES==\"" << _mask->get(F_ANNOES) << "\"|CODMAG==CODMAG|CODART==CODART|LIVELLO==LIVGIAC";
 | 
						||
 | 
						||
  _cur->relation()->replace(mag,1,mag_joinexp);
 | 
						||
  _cur->setfilter(cfilter,TRUE);
 | 
						||
  _cur->setregion(darec,arec,0x2);
 | 
						||
}
 | 
						||
 | 
						||
// ORDINAMENTO per articoli
 | 
						||
void TStampa_schede_mag::setprint_perarticoli()
 | 
						||
{
 | 
						||
  TRectype darec(LF_ANAMAG),arec(LF_ANAMAG);
 | 
						||
  TRectype darecr(LF_RMOVMAG),arecr(LF_RMOVMAG);
 | 
						||
  TString cfilter,filter;
 | 
						||
 | 
						||
  _form->set_tiposcheda(_mask->get(F_SCHEDA));
 | 
						||
  char subordine=_mask->get(F_ORDINEART)[0];
 | 
						||
  _cur = _form->cursor();
 | 
						||
  // filtering ANNOES
 | 
						||
  filter << '(' << LF_MOVMAG << "->ANNOES==" << _mask->get(F_ANNOES)<< ")&&" ;
 | 
						||
  // filtering from/to MAGS
 | 
						||
  if (*_mask->get(F_DAMAG))
 | 
						||
    filter << "(" << LF_RMOVMAG << "->CODMAG[1,3]>=" <<'"' << _mask->get(F_DAMAG)<< "\")&&" ;
 | 
						||
  if (*_mask->get(F_AMAG))
 | 
						||
    filter << "(" << LF_RMOVMAG << "->CODMAG[1,3]<=" <<'"' << _mask->get(F_AMAG)<< "\")&&" ;
 | 
						||
  
 | 
						||
  if (_mask->get(F_DADEP).not_empty())
 | 
						||
    filter << "(" << LF_RMOVMAG << "->CODMAG[4,]>=" <<'"' << _mask->get(F_DADEP)<< "\")&&" ;
 | 
						||
  if (_mask->get(F_ADEP).not_empty())
 | 
						||
    filter << "(" << LF_RMOVMAG << "->CODMAG[4,]<=" <<'"' << _mask->get(F_ADEP)<< "\")&&" ;
 | 
						||
 | 
						||
  // filtering from/to DATA
 | 
						||
  if (_mask->get(F_DADATA).not_empty())
 | 
						||
  {
 | 
						||
    TDate d1(_mask->get(F_DADATA));
 | 
						||
    TString cond;
 | 
						||
    cond << "ANSI(" << LF_MOVMAG << "->DATAREG)>=\"" << d1.string(ANSI) << '"';
 | 
						||
    ((TForm_subsection &)_form->find_field('B',odd_page,"MOVS_INTERESSATI")).setcondition(cond,_strexpr);   
 | 
						||
    ((TForm_subsection &)_form->find_field('B',odd_page,"H_MOVS_INTERESSATI")).setcondition(cond,_strexpr);   
 | 
						||
    cond.cut(0) << "ANSI(" << LF_MOVMAG << "->DATAREG)<\"" << d1.string(ANSI) << '"';
 | 
						||
    ((TForm_subsection &)_form->find_field('B',odd_page,"MOVS_PRECEDENTI")).setcondition(cond,_strexpr);
 | 
						||
  }
 | 
						||
  if (_mask->get(F_ADATA).not_empty()) 
 | 
						||
  {
 | 
						||
    TDate d1(_mask->get(F_ADATA));
 | 
						||
    filter << "(ANSI(110->DATAREG)<=" <<'"' << d1.string(ANSI) << "\")&&" ;
 | 
						||
  }
 | 
						||
 | 
						||
  // filtering ONLY NEGATIVES
 | 
						||
  if (_mask->get(F_FILTRO)[0]=='N') 
 | 
						||
   _cur->set_filterfunction(negatives_only);
 | 
						||
  
 | 
						||
  // Imposta i livelli di dettaglio della scheda
 | 
						||
  int tolivelloart=_mask->get_int(F_TOLIVELLOART);
 | 
						||
  int tolivellogiac=_mask->get_int(F_TOLIVELLOGIAC);
 | 
						||
  switch (subordine)
 | 
						||
  {
 | 
						||
    case 'C':
 | 
						||
    {
 | 
						||
      _cur->setkey(1);
 | 
						||
      darec.put("CODART",_mask->get(F_DAART));
 | 
						||
      arec.put("CODART", _mask->get(F_AART));
 | 
						||
      _form->setdett_perart(FALSE,FALSE,
 | 
						||
        tolivelloart,
 | 
						||
        tolivellogiac,
 | 
						||
        _mask->get_bool(F_SUDDIV_MAGAZZINI),
 | 
						||
        _mask->get_bool(F_SUDDIV_DEPOSITI));
 | 
						||
    }    
 | 
						||
    break;
 | 
						||
    case 'D':
 | 
						||
      _cur->setkey(2);
 | 
						||
      darec.put("DESCR",_mask->get(F_DADES));
 | 
						||
      arec.put("DESCR",_mask->get(F_ADES));
 | 
						||
      _form->setdett_perart(FALSE,FALSE,
 | 
						||
        tolivelloart,
 | 
						||
        tolivellogiac,
 | 
						||
        _mask->get_bool(F_SUDDIV_MAGAZZINI),
 | 
						||
        _mask->get_bool(F_SUDDIV_DEPOSITI));
 | 
						||
    break;
 | 
						||
    case  'M':
 | 
						||
      _cur->setkey(3);
 | 
						||
      darec.put("GRMERC",_mask->get(F_DACATMER));
 | 
						||
      arec.put("GRMERC",_mask->get(F_ACATMER));
 | 
						||
      if (_mask->get(F_AART).not_empty())
 | 
						||
        cfilter << "(CODART<=" <<'"' << _mask->get(F_AART)<< TString(20,(char)127)<< "\")&&" ;
 | 
						||
      if (_mask->get(F_DAART).not_empty())
 | 
						||
        cfilter << "(CODART>=" <<'"' << _mask->get(F_DAART) << "\")&&" ;
 | 
						||
      _form->setdett_perart(TRUE,FALSE,
 | 
						||
        tolivelloart,
 | 
						||
        tolivellogiac,
 | 
						||
        _mask->get_bool(F_SUDDIV_MAGAZZINI),
 | 
						||
        _mask->get_bool(F_SUDDIV_DEPOSITI));
 | 
						||
    break;
 | 
						||
  }
 | 
						||
  // prepare cursor's relation....
 | 
						||
  TRelation *aux=new TRelation (LF_RMOVMAG);
 | 
						||
  aux->add(LF_MOVMAG,"NUMREG==NUMREG");
 | 
						||
  if (filter.right(2) == "&&") 
 | 
						||
    filter.rtrim(2); 
 | 
						||
  TSortedfile *rmovmag= new TSortedfile(LF_RMOVMAG,aux,_form->rmov_sortexp(),filter,0x2);
 | 
						||
  darecr.put(RMOVMAG_CODART,darec.get(ANAMAG_CODART));
 | 
						||
  arecr.put(RMOVMAG_CODART,arec.get(ANAMAG_CODART));
 | 
						||
  rmovmag->setregion(darecr,arecr,0x2);
 | 
						||
  if (tiposcheda() != s_giac)
 | 
						||
    rmovmag->cursor().set_filterfunction(cau_filter);
 | 
						||
  _cur->relation()->replace(rmovmag,1, _form->rmov_joinexp() );
 | 
						||
 | 
						||
  TLocalisamfile *mag=new TLocalisamfile(LF_MAG);
 | 
						||
  mag->setkey(2);
 | 
						||
  TString mag_joinexp;
 | 
						||
  mag_joinexp << "ANNOES==\"" << _mask->get(F_ANNOES) << "\"|CODMAG==CODMAG|CODART==CODART|LIVELLO==LIVGIAC";
 | 
						||
  _cur->relation()->replace(mag,2,mag_joinexp);
 | 
						||
  
 | 
						||
  if (cfilter.not_empty()) 
 | 
						||
    cfilter.rtrim(2); 
 | 
						||
 | 
						||
  _cur->setfilter(cfilter);
 | 
						||
  _cur->setregion(darec,arec,0x2);
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_schede_mag::main_loop()
 | 
						||
{        
 | 
						||
  _autorun = FALSE;
 | 
						||
  while (TRUE) 
 | 
						||
  { 
 | 
						||
    if (!_autorun)
 | 
						||
      _autorun = _mask->run() == K_ENTER;
 | 
						||
    if (!_autorun)
 | 
						||
      break;
 | 
						||
    _autorun = FALSE;
 | 
						||
  
 | 
						||
    if (_mask->magazz_ini().gestmag(TRUE))
 | 
						||
    {
 | 
						||
      char dettaglio=_mask->get(F_ENABLER)[0];
 | 
						||
      if (dettaglio=='A' && _mask->get_int(F_TOLIVELLOART)==0)
 | 
						||
        _mask->set(F_TOLIVELLOART,livelli_articolo().last_level());
 | 
						||
      if (dettaglio=='G' && _mask->get_int(F_TOLIVELLOGIAC)==0)
 | 
						||
        _mask->set(F_TOLIVELLOGIAC,livelli_giacenza().last_level());
 | 
						||
      TString16 frmname;
 | 
						||
      const bool per_articoli = (*_mask->get(F_ORDINE) == 'A');
 | 
						||
      const bool sintetica = _mask->get_bool(F_SINTETICA);
 | 
						||
      if (per_articoli)
 | 
						||
        frmname = "mg3300a";
 | 
						||
      else
 | 
						||
        frmname = "mg3300b";
 | 
						||
      if (sintetica)
 | 
						||
        frmname << 's';
 | 
						||
      _form = new TForm_schedemag(frmname, "") ;
 | 
						||
      _form->set_options(_mask->get_bool(F_NO_VALORI), _mask->get_bool(F_NO_FF),
 | 
						||
                         sintetica);
 | 
						||
        
 | 
						||
      if (per_articoli)  
 | 
						||
        setprint_perarticoli();
 | 
						||
      else
 | 
						||
        setprint_permagazzini();
 | 
						||
 | 
						||
      _form->set_date_limite(_mask->get_int(F_ANNOES), _mask->get_date(F_DADATA), _mask->get_date(F_ADATA));
 | 
						||
  
 | 
						||
      _form->print();
 | 
						||
      delete _form;
 | 
						||
      _form = NULL;
 | 
						||
    }
 | 
						||
  } // while true  
 | 
						||
  return ;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_schede_mag::handle_dadata(TMask_field& f, KEY k)
 | 
						||
{ 
 | 
						||
  if (!f.empty() && f.to_check(k))       // se f deve essere controllato (cio<69> se <20> cambiato e sono uscito da lui o dalla maschera)
 | 
						||
  {
 | 
						||
    const int annoes = f.mask().get_int(F_ANNOES);
 | 
						||
    TEsercizi_contabili ec;
 | 
						||
    const TEsercizio& es = ec[annoes];
 | 
						||
    TDate data = f.get();
 | 
						||
    if (data < es.inizio())    
 | 
						||
      return f.error_box ("La data di inizio non puo' essere anteriore al %s", es.inizio().string());     
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_schede_mag::handle_adata(TMask_field& f, KEY k)
 | 
						||
{ 
 | 
						||
  if (!f.empty() && f.to_check(k))       // se f deve essere controllato (cio<69> se <20> cambiato e sono uscito da lui o dalla maschera)
 | 
						||
  {
 | 
						||
    const int annoes = f.mask().get_int(F_ANNOES);
 | 
						||
    TEsercizi_contabili ec;
 | 
						||
    const TEsercizio& es = ec[annoes];
 | 
						||
    TDate data = f.get();
 | 
						||
    if (data > es.fine())    
 | 
						||
      return f.error_box ("La data di fine non puo' essere successiva al %s", es.fine().string());     
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
static bool linker(int n, const char* str)
 | 
						||
{
 | 
						||
  TString80 ss; ss << "1|";
 | 
						||
  const char* run = NULL;
 | 
						||
  if (n == 0)
 | 
						||
  {
 | 
						||
    ss << str;           
 | 
						||
    run = "ve2 -3";
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    ss << atol(str);           
 | 
						||
    run = "mg1 -0";
 | 
						||
  }
 | 
						||
 | 
						||
  TMessage fs(run, MSG_LN, ss);
 | 
						||
  fs.send();              
 | 
						||
  TExternal_app prg(run);
 | 
						||
  prg.run();
 | 
						||
  
 | 
						||
  TMailbox m;  
 | 
						||
  while (m.next_s(MSG_LN) != NULL);  // Vuota mailbox
 | 
						||
  
 | 
						||
  if (n == 1 && yesno_box("Si desidera aggiornare la stampa?"))
 | 
						||
  { 
 | 
						||
    WINDOW viswin = cur_win();
 | 
						||
    dispatch_e_char(viswin, K_ESC);  // Chiude la viswin dell'anteprima
 | 
						||
    app().autorun();                 // forza il rilancio della stampa senza maschera 
 | 
						||
  }
 | 
						||
  return false;  // Gestisco IO l'aggiornamento della stampa
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_schede_mag::create()
 | 
						||
{
 | 
						||
  _mask = new TStampemg_mask("mg3300");
 | 
						||
  _mask->set_handler(F_DADATA,handle_dadata);
 | 
						||
  _mask->set_handler(F_ADATA,handle_adata);
 | 
						||
  
 | 
						||
  open_files(LF_RMOVMAG,LF_MOVMAG,LF_MAG,LF_TABCOM,LF_TAB,0);
 | 
						||
  
 | 
						||
  printer().links().add("Articolo |b|w");  // Crea il link blu alle anagrafiche
 | 
						||
  printer().links().add("Movimento |v|w");  // Crea il link viola ai movimenti
 | 
						||
  printer().setlinkhandler(linker);
 | 
						||
  
 | 
						||
  return TSkeleton_application::create();
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_schede_mag::destroy()
 | 
						||
{
 | 
						||
  delete _mask;
 | 
						||
  return TSkeleton_application::destroy();
 | 
						||
}
 | 
						||
 | 
						||
int mg3300(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TStampa_schede_mag a;// derivata da Application e con uso di form
 | 
						||
  a.run(argc,argv,"Stampa schede di magazzino");
 | 
						||
  return 0;
 | 
						||
} |