Files correlati : cg5.exe Ricompilazione Demo : [ ] Commento : Sostituita funzione deprecated stricmp con xvt_str_compare_ignoring_case git-svn-id: svn://10.65.10.50/trunk@16878 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			240 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			240 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | |
| #include <mask.h>
 | |
| #include <progind.h>
 | |
| #include <relation.h>
 | |
| #include <tabutil.h>
 | |
| 
 | |
| #include <mov.h>
 | |
| 
 | |
| #include "cg5.h"
 | |
| #include "cg5400.h"
 | |
| 
 | |
| class TRipristina_stampa : public TSkeleton_application
 | |
| {
 | |
|   enum TOperation { restore_reg, restore_inl };
 | |
|   TOperation _op;
 | |
| 
 | |
| protected: // TApplication
 | |
|   virtual bool create() ;                         
 | |
|   virtual void main_loop();
 | |
|   
 | |
| public:
 | |
|   bool reg_restore(const TString& reg, int year, int month, int day, bool giornale);
 | |
|   bool inl_restore(const TString& lbu, int year, int month);
 | |
| 
 | |
|   TRipristina_stampa() : _op(restore_reg) {}
 | |
| };
 | |
| 
 | |
| // Azzera flag di stampato della liquidazione mensile dal mese dato in poi
 | |
| bool TRipristina_stampa::reg_restore(const TString& regist, 
 | |
|                                      int year, int month, int day,
 | |
|                                      bool giornale)
 | |
| {
 | |
|   CHECKD(month > 0 && month < 13, "Mese errato ", month);
 | |
| 
 | |
|   bool ok = TRUE;
 | |
|   const char * const fieldname = giornale ? MOV_STAMPATO : MOV_REGST;
 | |
|   TRelation rel(LF_MOV);
 | |
|   TLocalisamfile& mov = rel.lfile();
 | |
| 
 | |
|   TString8 s; s.format("%04d%s", year, (const char*)regist);
 | |
|   TTable reg("REG");
 | |
|   reg.put("CODTAB", s);
 | |
|   
 | |
|   const TDate inizio_anno(1, 1, year);
 | |
|   if (reg.read(_isequal, _lock) == NOERR)
 | |
|   {
 | |
|     const TDate dlast(reg.get_date("D3"));
 | |
| 
 | |
|     const int ld = TDate::last_day(month, year);
 | |
|     if (day > ld) day = ld;
 | |
|     TDate d(day, month, year);                   // Data di ripristino
 | |
|     
 | |
|     TRectype from(mov.curr()); from.zero();
 | |
|     TRectype to(from);
 | |
|     TString80 filter;
 | |
|     
 | |
|     from.put(MOV_DATAREG, d);
 | |
|     to.put(MOV_DATAREG, dlast);
 | |
|     if (!giornale)
 | |
|       filter.format("%s==\"%s\"", MOV_REG, (const char*)regist);
 | |
|     
 | |
|     TCursor cursor(&rel, filter, 2, &from, &to);
 | |
|     long last_num = 0L;
 | |
|     
 | |
|     cursor = 0L;
 | |
|     const long nitems = cursor.items();
 | |
|     
 | |
|     TString msg; msg.format(FR("Ripristino stampa del registro %s"), (const char*)regist);
 | |
|     TProgind p(nitems ? nitems : 1, msg , TRUE, TRUE);
 | |
|     
 | |
|     if (giornale)
 | |
|     {
 | |
|       last_num = mov.get_long(MOV_NUMGIO);
 | |
|       if (last_num > 0) last_num--;
 | |
|       CHECK(last_num >= 0, "Ultimo numero stampato impossibile"); 
 | |
|     }
 | |
|     for (; ok && cursor.pos() < cursor.items(); ++cursor)
 | |
|     {
 | |
|       p.addstatus(1);
 | |
|       mov.read(_isequal, _lock);
 | |
|       mov.zero(fieldname);                 // Azzera flag STAMPATO o REGST
 | |
|       
 | |
|       ok = (mov.rewrite() == NOERR);
 | |
|       if (!ok)
 | |
|         error_box(FR("Errore nell'aggiornamento del movimento %ld.\n Errore n. %d"),
 | |
|                   mov.get_long(MOV_NUMREG), mov.status());
 | |
|     }
 | |
|     
 | |
|     if (d > inizio_anno)                  // Aggiorna data ultima stampa
 | |
|     {            
 | |
|       --d;
 | |
|       reg.put("D3", d);                   // Data ultima stampa
 | |
|       if (!giornale)
 | |
|       {
 | |
|         const int mese = d.month();
 | |
|         if (reg.get_int("I4") > mese) 
 | |
|           reg.put("I4", (long)mese);      // Ultimo mese di stampa liquidazione
 | |
|         if (reg.get_int("I8") >= mese) 
 | |
|           reg.zero("I8");                 // Mese di ultima stampa credito precedente
 | |
|       }    
 | |
|     }  
 | |
|     else
 | |
|     {
 | |
|       reg.zero("D3");
 | |
|       if (!giornale)
 | |
|       {
 | |
|         reg.zero("I4");
 | |
|         reg.zero("I8");            
 | |
|       }  
 | |
|     }  
 | |
|     
 | |
|     ok = (reg.rewrite() == NOERR);
 | |
|     if (!ok)
 | |
|       error_box(FR("Errore nell'aggiornamento del registro %s.\n Errore n. %d"),
 | |
|                 (const char*)regist, mov.status());
 | |
|   }
 | |
|   else
 | |
|     ok = error_box(FR("Impossibile leggere il registro %s anno %04d"), 
 | |
|                    (const char*)regist, year);
 | |
| 
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| 
 | |
| bool TRipristina_stampa::inl_restore(const TString& lib, int year, int month)
 | |
| { 
 | |
| 	TString filter;
 | |
|   TRelation relinl(LF_INDLIB);
 | |
|   TRectype & inl = relinl.curr();
 | |
|   
 | |
|   inl.put("ANNO", year);
 | |
|   inl.put("CODLIB", lib);
 | |
| 	filter.format("STR(MESEREG>=%d)&&(STAMPATO==\"X\")", month);
 | |
| 
 | |
| 	TCursor cur(&relinl, filter, 1, &inl, &inl);
 | |
| 
 | |
| 	const TRecnotype items = cur.items();
 | |
| 
 | |
| 	cur.freeze();
 | |
|   bool ok = FALSE;
 | |
|   
 | |
|   // Azzera il flag di stampato sugli indici con mese >= month
 | |
|   for (cur = 0L; cur.pos() < items; ++cur)
 | |
| 	{
 | |
|     relinl.lfile().reread(_lock);
 | |
| 		inl.zero("STAMPATO");
 | |
|     ok = relinl.rewrite() == NOERR;
 | |
|     if (!ok)
 | |
|     {
 | |
|       error_box(FR("Errore di ripristino dell'indice %ld"), inl.get_long("NUMREG"));
 | |
|       break;
 | |
|     }
 | |
| 	}
 | |
|   
 | |
|   if (ok) // Se e' stato ripristinato almeno un indice e non ci sono stati errori
 | |
|   {
 | |
|     TTable lbu("%LBU"); 
 | |
|     TString8 cod; cod.format("%4d%s", year, (const char*)lib);
 | |
|     lbu.put("CODTAB", cod);
 | |
|     ok = lbu.read(_isequal, _lock) == NOERR;
 | |
|     if (ok)
 | |
|     {
 | |
|       TDate d(1, month, year); // Riporta la data di ultima stampa
 | |
|       lbu.put("D0", d);
 | |
|       ok = lbu.rewrite() == NOERR;
 | |
|     }
 | |
|     if (!ok) 
 | |
|       error_box(FR("Impossibile aggiornare il libro unico %s per l'anno %d"), (const char*)lib, year);
 | |
|   }
 | |
|   
 | |
|   return ok;  
 | |
| }
 | |
| 
 | |
| bool TRipristina_stampa::create()
 | |
| {
 | |
|   if (argc() > 2 && xvt_str_compare_ignoring_case(argv(2), "INL") == 0)
 | |
|     _op = restore_inl;
 | |
|   return TSkeleton_application::create();
 | |
| }
 | |
| 
 | |
| 
 | |
| void TRipristina_stampa::main_loop()
 | |
| {
 | |
|   TMask msk(_op == restore_inl ? "cg5400b" : "cg5400a") ;
 | |
|   
 | |
|   while (msk.run() == K_ENTER)
 | |
|   {
 | |
|     long firm = prefix().get_codditta();
 | |
|     const TString4 reg = msk.get(F_REG);
 | |
|     bool giornale = FALSE;                            
 | |
|     
 | |
|     if (_op == restore_reg)
 | |
|     {
 | |
|       firm = msk.get_long(F_FIRM);
 | |
|       giornale = msk.get_int(F_TIPO) == 5;
 | |
|     }
 | |
|     
 | |
|     const int year = msk.get_int(F_YEAR);
 | |
|     const int month = msk.get_int(F_MESE);
 | |
|     const int day = giornale ? msk.get_int(F_DAY) : 1;
 | |
|     
 | |
|     if (prefix().exist(firm))
 | |
|     {
 | |
|       TString256 mess(TR("Attenzione ripristino della stampa"));
 | |
|       if (_op == restore_reg) 
 | |
|         mess << (giornale ? TR(" del giornale") : TR(" del registro"));
 | |
|       else 
 | |
|         mess << TR(" degli indici del libro ");
 | |
|       mess << ' ' << reg << '\n' << TR("del ") << year;
 | |
|       if (_op == restore_reg) mess <<  TR(" della ditta ") << firm;
 | |
|       mess << " dal " << day << '-' << month << '-' << year;
 | |
| 
 | |
|       if (yesno_box(mess))
 | |
|       {
 | |
|         mess << TR("\nSi desidera veramente continuare?");
 | |
|         if (yesno_box(mess))
 | |
|         {                                         
 | |
|           switch (_op)
 | |
|           {               
 | |
|           case restore_inl:
 | |
|             inl_restore(reg, year, month); break;
 | |
|           default:
 | |
|             reg_restore(reg, year, month, day, giornale); break;
 | |
|           }  
 | |
|         }  
 | |
|       }
 | |
|     }
 | |
|     else 
 | |
|       error_box(TR("Ditta assente"));
 | |
|     msk.reset();
 | |
|   }
 | |
| }
 | |
| 
 | |
| int cg5400(int argc, char* argv[])
 | |
| {
 | |
|   TRipristina_stampa a ;
 | |
|   a.run(argc, argv, TR("Ripristino stampe"));
 | |
|   return 0;
 | |
| }
 |