Files correlati : pr1.exe pr1300a.msk Ricompilazione Demo : [ ] Commento : 0001607: 002422 - stampa schede Descrizione il bottone di esportazione excell non produce risultati; da impostazione stampante, scelgo di stampare su file, chiede il nome del file (che è già impostato) git-svn-id: svn://10.65.10.50/trunk@20432 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			294 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			294 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | |
| #include <automask.h>
 | |
| #include <defmask.h>
 | |
| #include <printer.h>
 | |
| #include <progind.h>
 | |
| 
 | |
| #include "provv.h"
 | |
| #include "pr1300a.h"
 | |
| #include "..\ve\velib.h"
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TStampa_schedeprovv_form
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TStampa_schedeprovv_form : public TForm
 | |
| {               
 | |
|   TString _basecalcolo;
 | |
|   TPagamento _pagamento;
 | |
| 
 | |
| protected:  
 | |
|   virtual bool validate(TForm_item &, TToken_string &); 
 | |
| 
 | |
| public:
 | |
|   void set_basecalcolo(const TString& s) { _basecalcolo = s; }
 | |
|   TStampa_schedeprovv_form(const char* name);
 | |
|   virtual ~TStampa_schedeprovv_form(){};
 | |
| };
 | |
| 
 | |
| TStampa_schedeprovv_form::TStampa_schedeprovv_form(const char* name) : TForm(name)
 | |
| { }
 | |
| 
 | |
| bool TStampa_schedeprovv_form::validate(TForm_item &cf, TToken_string &s)
 | |
| {
 | |
|   const TFixed_string code(s.get(0));      
 | |
|   if (code == "_BASECALCOLO")
 | |
|   {                             
 | |
|     real valore;
 | |
|     if (_basecalcolo.empty())
 | |
|     { 
 | |
|       const real cambio = TForm::find_field('B', odd_page, 666).get();
 | |
|       valore = TForm::cursor()->curr().get_real(PROV_IMPRATA)*cambio;
 | |
|     }
 | |
|     else
 | |
|     {                                  
 | |
|       const int nriga = TForm::cursor()->curr().get_int(PROV_NRIGA);
 | |
|       if (nriga == 1)
 | |
|       {
 | |
|         TDocumento doc(TForm::cursor()->curr(LF_DOC));
 | |
|         _pagamento = doc.pagamento();
 | |
|         real importo = doc.get(_basecalcolo);
 | |
|         if (doc.tipo().nota_credito())
 | |
|           importo = -importo;
 | |
|         const TCurrency zero;
 | |
|         _pagamento.set_total(importo,zero,zero);
 | |
|         _pagamento.set_rate_auto();
 | |
|       } 
 | |
|       const int nrata = TForm::cursor()->curr().get_int(PROV_NRATA);
 | |
|       if (nrata > 0 && nrata <= _pagamento.n_rate())
 | |
|         valore = _pagamento.importo_rata(nrata-1);
 | |
|       else
 | |
|         valore = ZERO;  
 | |
|     }  
 | |
|     cf.set(valore.string());
 | |
|   }  
 | |
|   return TForm::validate(cf, s);
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TStampa_schedeprovv_mask
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TStampa_schedeprovv_mask : public TAutomask
 | |
| {
 | |
| protected:
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| public:
 | |
|   TStampa_schedeprovv_mask() : TAutomask("pr1300a") {}
 | |
| };
 | |
| 
 | |
| bool TStampa_schedeprovv_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | |
| {
 | |
|   if (e == fe_button && o.dlg() == DLG_PREVIEW) // Anteprima
 | |
|   { stop_run('A'); }
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TStampa_schedeprovv
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TStampa_schedeprovv : public TSkeleton_application
 | |
| {
 | |
|   TMask * _m;
 | |
| 
 | |
| protected:
 | |
|   void riporta_pagamenti(TCursor &cur);
 | |
|   void print_or_preview(bool paper);
 | |
| 
 | |
|   virtual void print() { print_or_preview(true); }
 | |
|   virtual void preview() { print_or_preview(false); }
 | |
| 
 | |
| public:
 | |
|   virtual bool create(); 
 | |
|   virtual bool destroy(); 
 | |
|   virtual void main_loop();
 | |
| };
 | |
| 
 | |
| bool TStampa_schedeprovv::create()
 | |
| {
 | |
|   open_files(LF_CFVEN, LF_DOC, LF_RIGHEDOC, LF_CONDV, LF_RCONDV, LF_ANAMAG,
 | |
|              LF_SCONTI, LF_UMART, LF_TAB, LF_TABCOM, LF_CLIFO,  LF_INDSP,
 | |
|              LF_OCCAS, LF_PCON, LF_MOVMAG, LF_RMOVMAG, LF_MAG, LF_SVRIEP, 
 | |
|              LF_AGENTI, LF_PERCPROV, LF_ATTIV, LF_CAUSALI, 0);
 | |
| 
 | |
|   _m = new TStampa_schedeprovv_mask;    
 | |
|   
 | |
|   return TSkeleton_application::create();
 | |
| }
 | |
| 
 | |
| bool TStampa_schedeprovv::destroy()
 | |
| {
 | |
|   delete _m;
 | |
|   return TSkeleton_application::destroy();
 | |
| }
 | |
| 
 | |
| void TStampa_schedeprovv::riporta_pagamenti(TCursor &cur)
 | |
| {
 | |
|   if (cur.items()==0) return;
 | |
|   const TRelation * r = cur.relation();
 | |
|   TLocalisamfile& prov = r->lfile();
 | |
|   TProgind barra(cur.items(),TR("Registro le provvigioni pagate"));
 | |
|   for (int c=0; c<cur.items(); c++)
 | |
|   {
 | |
|     cur=c;
 | |
|     barra.setstatus(c);
 | |
|     // stampa definitiva: riporta le provvigioni maturate sulle provv. pagate
 | |
|     real provv_pag, pag_pag;
 | |
|     provv_pag = prov.get_real(PROV_PROVVMAT);
 | |
|     pag_pag   = prov.get_real(PROV_PAGMAT);
 | |
|     if (!provv_pag.is_zero() && 
 | |
|       !prov.get_bool(PROV_SALDATA)) // this should never happen!
 | |
|     {
 | |
|       prov.reread(_lock);
 | |
|       provv_pag += prov.get_real(PROV_PROVVPAG);
 | |
|       pag_pag   += prov.get_real(PROV_PAGATO);
 | |
|       prov.put(PROV_PROVVPAG,provv_pag);
 | |
|       prov.put(PROV_PROVVMAT,0);
 | |
|       prov.put(PROV_PAGATO,pag_pag);
 | |
|       prov.put(PROV_PAGMAT,0);
 | |
|       if (provv_pag>=prov.get_real(PROV_IMPPROVV))
 | |
|         prov.put(PROV_SALDATA,"X");
 | |
|       prov.rewrite();
 | |
|     }
 | |
|   }
 | |
| }
 | |
| 
 | |
| void TStampa_schedeprovv::print_or_preview(bool paper)
 | |
| {
 | |
|   const TPrtype pt = printer().printtype(); // save printer mode
 | |
|   if (paper == (pt == screenvis))
 | |
|   {
 | |
|     if (paper)
 | |
|       printer().set_printtype(winprinter);
 | |
|     else
 | |
|       printer().set_printtype(screenvis);
 | |
|   }
 | |
| 
 | |
|   TStampa_schedeprovv_form frm("pr1300a");
 | |
| 
 | |
|   const int hh = 7;
 | |
|   const int fh = 1;
 | |
|   const int fl = printer().formlen();
 | |
|     
 | |
|   int rows[4];         // Righe orizzontali
 | |
|   rows[0] = hh-3;
 | |
|   rows[1] = hh;
 | |
|   rows[2] = fl-1;
 | |
|   rows[3] = 0;
 | |
|   frm.genera_intestazioni(odd_page, hh-2);
 | |
|   frm.genera_fincatura(odd_page, hh-3, fl-1, rows);
 | |
|   
 | |
|   // filtro e regione
 | |
|   TString filter;
 | |
|     
 | |
|   if (_m->get(F_FILTRO).full())
 | |
|   {
 | |
|     filter = PROV_SALDATA;
 | |
|     if (_m->get(F_FILTRO)[0]=='P')
 | |
|       filter << "==\"X\"" ;
 | |
|     else
 | |
|       filter << "!=\"X\"" ;         
 | |
|   }  
 | |
|   if (_m->get_bool(F_NOZERO))
 | |
|   {
 | |
|     bool not_empty = filter.not_empty();
 | |
|     if (not_empty)       
 | |
|     {
 | |
|       filter.insert("(");
 | |
|       filter << ") && (";
 | |
|     }                                                                  
 | |
|     filter << "(" << PROV_IMPPRDOC << "!= 0)";
 | |
|     if (not_empty)
 | |
|       filter << ")";
 | |
|   }
 | |
|   if (_m->get(F_DADATA).not_empty() || _m->get(F_ADATA).not_empty())
 | |
|   {   
 | |
|     TDate datam;
 | |
|     bool not_empty = filter.not_empty();
 | |
|     if (not_empty)       
 | |
|     {
 | |
|       filter.insert("(");
 | |
|       filter << ") && (";
 | |
|     }                                                                  
 | |
|     if (_m->get(F_DADATA).not_empty())
 | |
|     {                                                         
 | |
|       datam = _m->get_date(F_DADATA);
 | |
|       filter << "(ANSI(" << PROV_DATADOC << ")>=\"" << datam.string(ANSI) << "\")";
 | |
|       if (_m->get(F_ADATA).not_empty())
 | |
|         filter << " && ";
 | |
|     } 
 | |
|     if (_m->get(F_ADATA).not_empty())
 | |
|     {
 | |
|       datam = _m->get_date(F_ADATA);
 | |
|       filter << "(ANSI(" << PROV_DATADOC << ")<=\"" << datam.string(ANSI) << "\")";
 | |
|     } 
 | |
|     if (not_empty)
 | |
|       filter << ")";
 | |
|   }      
 | |
|     
 | |
|   // aggiungo comunque il file alla relazione perche' mi serve avere il documento sempre
 | |
|   frm.cursor()->relation()->add(LF_DOC, "CODNUM==CODNUM|ANNO==ANNO|PROVV==\"D\"|NDOC==NDOC");
 | |
|     
 | |
|   const TString& tipodoc = _m->get(F_TIPODOC);
 | |
|   if (tipodoc.full())
 | |
|   {
 | |
|     //frm.cursor()->relation()->add(LF_DOC, "CODNUM==CODNUM|ANNO==ANNO|PROVV==\"D\"|NDOC==NDOC");
 | |
|     bool not_empty = filter.full();
 | |
|         
 | |
|     if (not_empty)       
 | |
|     {
 | |
|       filter.insert("(");
 | |
|       filter << ") && (";
 | |
|     }
 | |
|         
 | |
|     filter << LF_DOC << "->TIPODOC == \"" << tipodoc << "\"";
 | |
|         
 | |
|     if (not_empty)
 | |
|       filter << ")";
 | |
|                                      
 | |
|     frm.cursor()->setfilter(filter, TRUE);
 | |
|   }
 | |
|   else
 | |
|     frm.cursor()->setfilter(filter);
 | |
| 
 | |
|   TRectype start(LF_PROVV),end(LF_PROVV);
 | |
|   if (_m->get(F_DAAGE).not_empty())
 | |
|     start.put(PROV_CODAGE,_m->get(F_DAAGE));
 | |
|   if (_m->get(F_AAGE).not_empty())
 | |
|     end.put(PROV_CODAGE,_m->get(F_AAGE));
 | |
|   frm.cursor()->setregion(start,end);
 | |
|     
 | |
|   frm.set_basecalcolo(_m->get(F_FORMULA));
 | |
| 
 | |
|   // abilita le sezioni dei totali
 | |
|   frm.find_field('B',odd_page,"CLIENTI").show(!_m->get_bool(F_RAGGCLI));
 | |
|   frm.find_field('B',odd_page,"HCLIENTI").show(!_m->get_bool(F_RAGGDOC));
 | |
|   frm.find_field('B',odd_page,"DOCUMENTI").show(!_m->get_bool(F_RAGGDOC));
 | |
|   frm.find_field('B',odd_page,"HDOCUMENTI").show(!_m->get_bool(F_RAGGRATE));
 | |
|   frm.find_field('B',odd_page,"RATEDOC").show(!_m->get_bool(F_RAGGRATE));
 | |
|   frm.print();
 | |
|   if (_m->get(F_DEFINITIVA)[0]=='D')
 | |
|   {
 | |
|     riporta_pagamenti(*frm.cursor());
 | |
|   }
 | |
| 
 | |
|   printer().set_printtype(pt); // Restore printer mode
 | |
| }
 | |
| 
 | |
| void TStampa_schedeprovv::main_loop()
 | |
| {
 | |
|   KEY k;
 | |
|   while ((k = _m->run()) != K_QUIT)
 | |
|   {
 | |
|     print_or_preview(k == K_ENTER);
 | |
|   }
 | |
| }
 | |
| 
 | |
| int pr1300(int argc, char* argv[])
 | |
| {
 | |
|   TStampa_schedeprovv a;
 | |
|   a.run(argc,argv,TR("Stampa schede di provvigione"));
 | |
|   return 0;
 | |
| }
 |