525 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			525 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <colors.h>
 | |
| #include <execp.h>
 | |
| #include <modaut.h>
 | |
| #include <utility.h>
 | |
| #include <varmask.h>
 | |
| #include <windows.h>     
 | |
| 
 | |
| #include "cg2100.h"
 | |
| #include "cg2102.h"
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // Maschere per colori
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TRow_mask : public TMask
 | |
| { 
 | |
| public:
 | |
|   virtual void update();
 | |
| 
 | |
|   TRow_mask();
 | |
|   virtual ~TRow_mask() { }
 | |
| };
 | |
| 
 | |
| class TColor_mask : public TVariable_mask
 | |
| {        
 | |
|   HIDDEN TRow_mask* _sheet_mask;
 | |
|   HIDDEN TMask* get_mask(int, TMask&) { return _sheet_mask; }
 | |
| 
 | |
| protected:
 | |
|   static bool color_handler(TMask_field& f, KEY k);
 | |
|   static bool reset_handler(TMask_field& f, KEY k);
 | |
|   
 | |
| public:
 | |
|   void get_cur_colors(COLOR& back, COLOR& fore) const;  
 | |
|   void set_cur_colors(COLOR back, COLOR fore); 
 | |
| 
 | |
|   TColor_mask();
 | |
|   virtual ~TColor_mask();
 | |
| };
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TRow_mask
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| TRow_mask* TColor_mask::_sheet_mask = NULL;
 | |
| 
 | |
| TRow_mask::TRow_mask()
 | |
|          : TMask("cg2100k", 1)
 | |
| {
 | |
| }
 | |
| 
 | |
| void TRow_mask::update()
 | |
| {               
 | |
|   TSheet_field* s = get_sheet();
 | |
|   TColor_mask& m = (TColor_mask&)s->mask();
 | |
|   COLOR back, fore;
 | |
|   m.get_cur_colors(back, fore);
 | |
|   
 | |
|   _pixmap = TRUE;
 | |
|   set_pen(COLOR_BLACK);
 | |
| 
 | |
|   RCT rct; field(100).get_rect(rct);
 | |
|   set_brush(back);
 | |
|   frame(rct.left, 2*rct.top - rct.bottom - CHARY/2, rct.right, rct.top - CHARY/2, 0);
 | |
|   
 | |
|   field(99).get_rect(rct);
 | |
|   set_brush(fore);
 | |
|   frame(rct.left, 2*rct.top - rct.bottom - CHARY/2, rct.right, rct.top - CHARY/2, 0);
 | |
| 
 | |
|   _pixmap = FALSE;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TColor_mask
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| 
 | |
| void TColor_mask::get_cur_colors(COLOR& back, COLOR& fore) const
 | |
| {
 | |
|   TSheet_field& s = (TSheet_field&)fld(0);
 | |
|   TToken_string& row = s.row(s.selected());
 | |
|   const char tipo = row[5];
 | |
|   app().type2colors(tipo, back, fore);
 | |
| }
 | |
| 
 | |
| void TColor_mask::set_cur_colors(COLOR back, COLOR fore)
 | |
| {
 | |
|   TSheet_field& s = (TSheet_field&)fld(0);
 | |
|   int cur = s.selected();
 | |
|   TToken_string& row = s.row(cur);
 | |
|   const char tipo = row[5];
 | |
|   app().set_type_colors(tipo, back, fore);
 | |
|   s.set_back_and_fore_color(back, fore, cur); 
 | |
|   s.force_update(cur);
 | |
| }
 | |
|   
 | |
| bool TColor_mask::color_handler(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k == K_SPACE)
 | |
|   {                                               
 | |
|     TMask& m = f.mask();
 | |
|     TColor_mask& cm = (TColor_mask&)m.get_sheet()->mask();
 | |
|     
 | |
|     COLOR back, fore;
 | |
|     cm.get_cur_colors(back, fore);     
 | |
|     const bool use_back = f.dlg() == 100;
 | |
|     
 | |
|     const COLOR col = choose_color(use_back ? back : fore, m.win());
 | |
|     if (col != COLOR_INVALID)
 | |
|     {                   
 | |
|       if (use_back)
 | |
|         back = col;
 | |
|       else
 | |
|         fore = col;  
 | |
|       cm.set_cur_colors(back, fore);
 | |
|       cm._sheet_mask->update();
 | |
|       m.set_focus();
 | |
|     }  
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TColor_mask::reset_handler(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k == K_SPACE && f.yesno_box("Si desidera azzerare tutti i colori?"))
 | |
|   {           
 | |
|     app().reset_colors();                                     
 | |
|     TSheet_field& s = f.mask().sfield(101);
 | |
|     s.set_back_and_fore_color(NORMAL_BACK_COLOR, NORMAL_COLOR, -1);
 | |
|     s.force_update();
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| TColor_mask::TColor_mask() 
 | |
|            : TVariable_mask("cg2100k")
 | |
| {              
 | |
|   set_handler(102, reset_handler);
 | |
| 
 | |
|   CHECK(_sheet_mask == NULL, "One color at time, please");
 | |
|   _sheet_mask = new TRow_mask;
 | |
|   _sheet_mask->set_handler(99, color_handler);
 | |
|   _sheet_mask->set_handler(100, color_handler);
 | |
| 
 | |
|   TVariable_sheet_field& s = (TVariable_sheet_field&)fld(0);
 | |
|   s.set_getmask(get_mask);
 | |
| 
 | |
|   const char* const tipi = "TFSIDNAPRCGLK"; 
 | |
|   const char* const desc[] =             
 | |
|   {
 | |
|     "Tot. doc./sdo partite",
 | |
|     "Ritenute fiscali",
 | |
|     "Ritenute sociali",
 | |
|     "Generata (Imponibile)",
 | |
|     "IVA detraibile",
 | |
|     "IVA non detraibile",
 | |
|     "Abbuoni attivi",
 | |
|     "Abbuoni passivi",
 | |
|     "Ritenute professionali",
 | |
|     "Differenza cambi",
 | |
|     "Spese",
 | |
|     "Contropartita spese",
 | |
|     "Riga Cliente/Fornitore",
 | |
|   };
 | |
|   
 | |
|   TPrimanota_application& a = app();
 | |
|   
 | |
|   int row = 0;
 | |
|   int d = 0;
 | |
|   for (const char* c = tipi; *c; c++, d++)
 | |
|   {
 | |
|     COLOR back, fore;
 | |
|     a.type2colors(*c, back, fore);
 | |
|     TToken_string& riga = s.row(-1);
 | |
|     riga << "Riga " << *c << " - " << desc[d];
 | |
|     s.set_back_and_fore_color(back, fore, row++); 
 | |
|   }
 | |
| }
 | |
| 
 | |
| TColor_mask::~TColor_mask() 
 | |
| {
 | |
|   delete _sheet_mask;
 | |
|   _sheet_mask = NULL;
 | |
| }
 | |
| 
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // Gestione righe colorate
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| void TPrimanota_application::load_colors()
 | |
| {
 | |
|   TConfig conf(CONFIG_USER, "cg2");
 | |
|   TAssoc_array& colori = (TAssoc_array&)conf.list_variables();
 | |
|   for (THash_object* o = colori.get_hashobj(); o; o = colori.get_hashobj())
 | |
|   {
 | |
|     const TString& key = o->key();
 | |
|     if (key.len() == 7 && key.compare("Color", 5, TRUE) == 0)
 | |
|     {
 | |
|       const COLOR col = conf.get_color(key);
 | |
|       TString* strcol = new TString(15);
 | |
|       strcol->format("%ld", col);
 | |
|       _colori.add(key.mid(5), strcol);
 | |
|     }  
 | |
|   }
 | |
| }              
 | |
| 
 | |
| void TPrimanota_application::save_colors()
 | |
| {
 | |
|   TConfig conf(CONFIG_USER, "cg2");
 | |
|   TString16 tmp;
 | |
|   for (THash_object* o = _colori.get_hashobj(); o; o = _colori.get_hashobj())
 | |
|   {
 | |
|     tmp = "Color"; tmp << o->key();
 | |
|     const COLOR col = atol((TString&)o->obj());
 | |
|     
 | |
|     bool should_delete = FALSE;
 | |
|     if (tmp[5] == 'B')
 | |
|       should_delete = (col == NORMAL_BACK_COLOR);
 | |
|     else  
 | |
|       should_delete = (col == NORMAL_COLOR);
 | |
|     
 | |
|     if (should_delete)  
 | |
|       conf.remove(tmp);
 | |
|     else  
 | |
|       conf.set_color(tmp, col);
 | |
|   }
 | |
| }              
 | |
| 
 | |
| COLOR TPrimanota_application::type2color(char tipor, char tipoc)
 | |
| {  
 | |
|   COLOR col;                         
 | |
|   if (tipor > ' ')
 | |
|   {
 | |
|     const char key[3] = { tipoc, tipor, '\0' }; 
 | |
|     TString* colstr = (TString*)_colori.objptr(key);
 | |
|     if (colstr == NULL)
 | |
|     {
 | |
|       colstr = new TString(8);
 | |
|       colstr->format("%ld", tipoc == 'B' ? NORMAL_BACK_COLOR : NORMAL_COLOR);
 | |
|       _colori.add(key, colstr);
 | |
|     }    
 | |
|     col = atol(*colstr);
 | |
|   }  
 | |
|   else
 | |
|   {
 | |
|     col = tipoc == 'B' ? NORMAL_BACK_COLOR : NORMAL_COLOR;
 | |
|   }
 | |
|   return col;
 | |
| }
 | |
| 
 | |
| void TPrimanota_application::set_type_color(char tipor, char tipoc, COLOR col)
 | |
| { 
 | |
|   if (tipor > ' ')
 | |
|   {
 | |
|     const char key[3] = { tipoc, tipor, '\0' }; 
 | |
|     TString* colstr = (TString*)_colori.objptr(key);
 | |
|     if (colstr == NULL)
 | |
|     {
 | |
|       colstr = new TString(8);
 | |
|       _colori.add(key, colstr);
 | |
|     }
 | |
|     colstr->format("%ld", col);
 | |
|   }  
 | |
| }
 | |
| 
 | |
| void TPrimanota_application::type2colors(char tipor, COLOR& back, COLOR& fore)
 | |
| {      
 | |
|   back = type2color(tipor, 'B');
 | |
|   fore = type2color(tipor, 'F');
 | |
| }
 | |
| 
 | |
| void TPrimanota_application::set_type_colors(char tipor, COLOR back, COLOR fore)
 | |
| {      
 | |
|   set_type_color(tipor, 'B', back);
 | |
|   set_type_color(tipor, 'F', fore);
 | |
| }
 | |
| 
 | |
| void TPrimanota_application::reset_colors()
 | |
| {
 | |
|   _colori.destroy();
 | |
| }
 | |
| 
 | |
| void TPrimanota_application::set_colors()
 | |
| {                
 | |
|   disable_menu_item(M_FONT);
 | |
|   TColor_mask colors;
 | |
|   if (colors.run() == K_ENTER)
 | |
|     app().save_colors();
 | |
|   else
 | |
|     app().load_colors();
 | |
|   enable_menu_item(M_FONT);
 | |
| } 
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // Gestione cambiamento prorata
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| bool TPrimanota_application::test_prorata()
 | |
| {
 | |
|   if (iva() != iva_acquisti || !cgs().shown() || _as400)
 | |
|     return TRUE;
 | |
|   
 | |
|   bool esistono_righe_senza_tipo_detrazione = FALSE;
 | |
|   
 | |
|   TString_array& righe_iva = ivas().rows_array();
 | |
|   for (int r = 0; r < righe_iva.items(); r++)
 | |
|   {
 | |
|     TToken_string& row = righe_iva.row(r);       
 | |
|     const real imposta = row.get(3);
 | |
|     if (!imposta.is_zero())
 | |
|     {
 | |
|       const int tipodet = row.get_int(2);
 | |
|       if (tipodet == 0)
 | |
|       {
 | |
|         esistono_righe_senza_tipo_detrazione = TRUE;
 | |
|         break;
 | |
|       }  
 | |
|     }  
 | |
|   }
 | |
|   
 | |
|   bool ok = TRUE;                       
 | |
|   if (esistono_righe_senza_tipo_detrazione)
 | |
|   {                                                    
 | |
|     const int annodoc = _msk[2]->get_date(F_DATADOC).year();
 | |
|     const bool prorata100 = causale().reg().prorata100(annodoc);
 | |
|     const bool esiste_riga_iva_detraibile = type2pos('D') >= 0;
 | |
|     if (prorata100)
 | |
|       ok = !esiste_riga_iva_detraibile;
 | |
|     else
 | |
|       ok = esiste_riga_iva_detraibile;
 | |
|   }
 | |
|   
 | |
|   return ok;  
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::aggiusta_prorata()
 | |
| {
 | |
|   TWait_cursor hourglass;
 | |
| 
 | |
|   if (test_prorata())
 | |
|     return FALSE;
 | |
|     
 | |
|   TRegistro& reg = causale().reg();
 | |
|   const int annodoc = _msk[2]->get_date(F_DATADOC).year();
 | |
|   const real prorata_attuale = reg.prorata(annodoc);
 | |
|   const real vecchio_prorata = prorata_attuale < 100.0 ? 100.0 : 0.0;    
 | |
|   
 | |
|   TSheet_field& iva_sheet = ivas();
 | |
|   TString_array& righe_iva = iva_sheet.rows_array();
 | |
|     
 | |
|   TToken_string oldrow(128);
 | |
|   for (int i = 0; i < righe_iva.items(); i++)
 | |
|   {
 | |
|     TToken_string& r = righe_iva.row(i);
 | |
|     if (!r.empty_items())
 | |
|     {
 | |
|       oldrow = r;                          // Memorizza riga iva
 | |
|       reg.set_prorata(annodoc, vecchio_prorata);
 | |
|       iva_notify(iva_sheet, i, K_SPACE);   
 | |
|       r.add("", 0); r.add("", 3);          // Simula l'azzeramento degli importi
 | |
|       iva_notify(iva_sheet, i, K_ENTER);   // Simula uscita dalla riga
 | |
| 
 | |
|       reg.set_prorata(annodoc, prorata_attuale);
 | |
|       iva_notify(iva_sheet, i, K_SPACE);   
 | |
|       r = oldrow;                          // Simula riscrittura importi
 | |
|       iva_notify(iva_sheet, i, K_ENTER);   // Simula uscita dalla riga
 | |
|     }
 | |
|     else
 | |
|       break;
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| } 
 | |
| 
 | |
| bool TPrimanota_application::prorata_handler(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k == K_SPACE)
 | |
|   {
 | |
|     if (app().aggiusta_prorata())
 | |
|       f.hide();
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // Gestione EasyDoc
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| bool TPrimanota_application::easydoc_installed() 
 | |
| {
 | |
|   // check autorization
 | |
|   if (!has_module(AIAUT))
 | |
|     return FALSE;      
 | |
|     
 | |
|   // where is EasyDoc installed?                 
 | |
|   GetPrivateProfileString("Easydoc", "Path", "\\EASYDOC", 
 | |
|                           _EasyDocPath.get_buffer(), _EasyDocPath.size(), 
 | |
|                           "EasyDoc.ini");  
 | |
|   // EasyDoc there isn't
 | |
|   if (_EasyDocPath.empty())
 | |
|     return FALSE;
 | |
|   
 | |
|   // paste EasyDoc path
 | |
|   _EasyDocPath.add("EASYDOC.EXE");    
 | |
|   
 | |
|   // is EasyDoc present?
 | |
|   bool ok = fexist(_EasyDocPath);
 | |
|   if (!ok)
 | |
|     _EasyDocPath.cut(0);
 | |
|   
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| // Il documento attuale e' connesso a easydoc?
 | |
| bool TPrimanota_application::easydoc_connected()
 | |
| {
 | |
|   return _EasyDocPath.not_empty();
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::run_easydoc(const char* azione) const
 | |
| {                                        
 | |
|   const TMask& m = curr_mask();
 | |
|   
 | |
|   TString cmdline = _EasyDocPath;
 | |
|   TFilename ininame;
 | |
|   
 | |
|   if (azione && *azione)
 | |
|   {
 | |
|     // linea comando EasyDoc
 | |
|     ininame.tempdir();
 | |
|     ininame.add("easydoc.ini");
 | |
|     cmdline << ' ' << ininame;
 | |
|   
 | |
|     // path dei dati della ditta 
 | |
|     TFilename dati_dir = get_firm_dir(); 
 | |
|     // completa path relativo, 
 | |
|     // ma che male c'era a registrarlo sempre assoluto??
 | |
|     if (dati_dir.is_relative_path())
 | |
|     {      
 | |
|       TFilename modulename(argv(0));
 | |
|       modulename = modulename.path();
 | |
|       modulename.add(dati_dir);
 | |
|       dati_dir = modulename; 
 | |
|     } 
 | |
|       
 | |
|     // rimuove barre e controbarre per dargli un aspetto decente
 | |
|     dati_dir.replace('/','\\');  
 | |
|     for (int pos = dati_dir.find("\\\\"); pos >= 0; pos = dati_dir.find("\\\\"))
 | |
|       dati_dir[pos] = ' ';
 | |
|     dati_dir.strip_spaces();  
 | |
|     
 | |
|     // nome archivio
 | |
|     TFilename archivio(dati_dir);
 | |
|     archivio.add("easydoc.mdb"); 
 | |
|      
 | |
|     // drive di archiviazione             
 | |
|     TString drv_di_arch;
 | |
|     if (dati_dir[1] == ':') 
 | |
|       drv_di_arch = dati_dir.left(2);
 | |
|     
 | |
|     // directory di archiviazione
 | |
|     TString dir_di_arch(dati_dir);
 | |
|     if (dir_di_arch[1] == ':') 
 | |
|       dir_di_arch.ltrim(2);
 | |
|     dir_di_arch << SLASH;
 | |
|     
 | |
|     // prepara sempre sezione "EASYDOC" 
 | |
|     TConfig ini(ininame, "EASYDOC");
 | |
|     ini.set("Azione", azione);    
 | |
|     ini.set("Archivio", archivio);
 | |
|     ini.set("Cartella", "Movimenti primanota");
 | |
|     ini.set("Campo0", m.get(F_NUMREG));    
 | |
|     ini.set("Campo1", m.get(F_DATAREG));
 | |
|     ini.set("Descrizione", m.get(F_DESCR));
 | |
|     
 | |
|     // prepara la sezione "DefinizioneDoc1" (se non esiste l'archivio mdb)
 | |
|     if (!fexist(archivio))
 | |
|     {
 | |
|       ini.set_paragraph("DefinizioneDoc1");
 | |
|       ini.set("Archivio", archivio);             
 | |
|       ini.set("NomeDoc", "Movimenti primanota"); 
 | |
|       ini.set("DirDiArchiviazione", dir_di_arch); 
 | |
|       ini.set("DriveDiArchiviazione", drv_di_arch); 
 | |
|       ini.set("DirDocumento", "eddoc");  
 | |
|       ini.set("Campo0", "Numero registrazione"); 
 | |
|       ini.set("Tipo0", "Numero");                
 | |
|       ini.set("Campo1", "Data registrazione"); 
 | |
|       ini.set("Tipo1", "Data");          
 | |
|     }  
 | |
|   }  
 | |
|   
 | |
|   TExternal_app app(cmdline);                  
 | |
|   bool ok = app.run(FALSE, FALSE) == 0;  
 | |
|   
 | |
|   if (ininame.not_empty())
 | |
|     ::remove(ininame);
 | |
|   
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::easydoc_handler(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k == K_SPACE)
 | |
|   {
 | |
|     const TMask& m = f.mask();
 | |
|     if (m.insert_mode()) 
 | |
|       app().run_easydoc("Scan"); 
 | |
|     else
 | |
|     {
 | |
|       if (m.edit_mode()) 
 | |
|       {
 | |
|         if (app().easydoc_connected())
 | |
|           app().run_easydoc("Visualizza"); 
 | |
|         else  
 | |
|           app().run_easydoc("Scan"); 
 | |
|       }  
 | |
|       else
 | |
|         app().run_easydoc("");
 | |
|     }    
 | |
|   }  
 | |
|   return TRUE;
 | |
| }
 |