254 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			254 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | |
| #include <mask.h>
 | |
| #include <recarray.h>
 | |
| #include <relation.h>
 | |
| #include <sheet.h>
 | |
| #include <utility.h>
 | |
| #include <urldefid.h>
 | |
| 
 | |
| #include "ba4600.h"
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TSoci_sheet
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| const char* const PHYSICAL_HEAD = HR("Codice|Cognome@30|Nome@20");
 | |
| const char* const JURASSIC_HEAD = HR("Codice|Ragione sociale@50");
 | |
| 
 | |
| class TSoci_sheet : public TArray_sheet
 | |
| {
 | |
|   bool _physical;
 | |
| 
 | |
| protected:
 | |
|   const char* lastcode();
 | |
| 
 | |
| public:
 | |
|   TSoci_sheet(bool);
 | |
|   void add_socio(const TString& codice, const TString& ragione, int elem = -1);
 | |
| };
 | |
| 
 | |
| TSoci_sheet::TSoci_sheet(bool fis)
 | |
| : TArray_sheet(-1,-1, -4, -4, TR("Soci"), fis ? PHYSICAL_HEAD : JURASSIC_HEAD),
 | |
|   _physical(fis)
 | |
| {}
 | |
| 
 | |
| const char* TSoci_sheet::lastcode()
 | |
| {
 | |
|   if (items() < 1) return "";
 | |
|   return data(items()-1).get(0);
 | |
| }
 | |
| 
 | |
| void TSoci_sheet::add_socio(const TString& codice,
 | |
|                             const TString& ragione,
 | |
|                             int elem)
 | |
| {
 | |
|   if (elem == -1 && codice == lastcode()) return;
 | |
| 
 | |
|   TToken_string t(60);
 | |
| 
 | |
|   t.add(codice);
 | |
|   if (_physical)
 | |
|   {
 | |
|     t.add(ragione.left(30));
 | |
|     t.add(ragione.mid(30));
 | |
|   } else t.add(ragione);
 | |
| 
 | |
|   if (elem < 0) add(t);
 | |
|   else
 | |
|     row(elem) = (TString&) t;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TQuery_socio
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TQuery_socio
 | |
| {
 | |
|   TString16 _tipo;        // tipo = F | G
 | |
|   TString16 _attprec;     // {A}ttuale / {P}recedente
 | |
|   TString16 _carica;      // codice carica
 | |
|   TString16 _qualifica;   // richiesta qualifica
 | |
|   TString16 _q740;        // quadro 740
 | |
|   TString16 _q750;        // quadro 750
 | |
| 
 | |
| public:
 | |
|   TQuery_socio(const TMask* mask);
 | |
| 
 | |
|   const TString& tipo() const { return _tipo; }
 | |
|   int test(const TRectype& rec) const;
 | |
| };
 | |
| 
 | |
| TQuery_socio::TQuery_socio(const TMask* mask)
 | |
| {
 | |
|   _tipo      = mask->get(LST_SC1_TIPOASOC);
 | |
|   _attprec   = mask->get(FLD_SC1_ANNO);
 | |
|   _carica    = mask->get(FLD_SC1_CODCAR);
 | |
|   _qualifica = mask->get(LST_SC1_RICQUAL);
 | |
|   _q740      = mask->get(LST_SC2_Q740);
 | |
|   _q750      = mask->get(LST_SC2_QUATTPREV);
 | |
| }
 | |
| 
 | |
| int TQuery_socio::test(const TRectype& r) const
 | |
| {
 | |
|   if (_tipo != r.get("TIPOASOC")) return 1;
 | |
|   if (_attprec.not_empty()&& _attprec != r.get("ATTPREC")) return 2;
 | |
|   if (_carica.not_empty() && _carica != r.get("CODCAR")) return 3;
 | |
|   if (_qualifica.not_empty() && _qualifica != r.get("RICQUAL")) return 4;
 | |
|   if (_q740.not_empty() && _q740 != r.get("Q740")) return 5;
 | |
|   if (_q750.not_empty() && _q750 != r.get("QUATTPREV")) return 6;
 | |
|   return 0;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TQuery_application
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TQuery_application : public TSkeleton_application
 | |
| {
 | |
|   TMask* _mask;
 | |
| 
 | |
| protected:
 | |
|   virtual bool create();
 | |
|   virtual bool destroy();
 | |
|   virtual void main_loop();
 | |
| 
 | |
|   bool do_query();
 | |
| 
 | |
| public:
 | |
|   TQuery_application();
 | |
| };
 | |
| 
 | |
| 
 | |
| TQuery_application::TQuery_application() : _mask(NULL)
 | |
| {}
 | |
| 
 | |
| bool TQuery_application::create()
 | |
| {
 | |
|   open_files(LF_SOCI, LF_ANAG, LF_NDITTE,0);
 | |
|   _mask = new TMask("ba5000");
 | |
| 
 | |
|   return TSkeleton_application::create();
 | |
| }
 | |
| 
 | |
| bool TQuery_application::destroy()
 | |
| {
 | |
|   delete _mask;
 | |
| 
 | |
|   return TSkeleton_application::destroy();
 | |
| }
 | |
| 
 | |
| 
 | |
| void TQuery_application::main_loop()
 | |
| {
 | |
|   while (do_query());
 | |
| }
 | |
| 
 | |
| const char* head(const TRectype& r, const char* name,
 | |
|                  const char* title)
 | |
| {
 | |
|   if (title == NULL) 
 | |
|     title = name;
 | |
|   TString& tmp = get_tmp_string();
 | |
|   if (r.exist(name))
 | |
|   {
 | |
|     TString h(r.length(name));
 | |
|     h.spaces();
 | |
|     h.overwrite(title, 0);
 | |
|     tmp = h;
 | |
|   }
 | |
|   else 
 | |
|     tmp = title;
 | |
| 
 | |
|   return tmp;
 | |
| }
 | |
| 
 | |
| bool TQuery_application::do_query()
 | |
| {
 | |
|   if (_mask->run() != K_F9) return FALSE;
 | |
| 
 | |
|   TQuery_socio query(_mask);
 | |
|   TSoci_sheet s(query.tipo() == "F");                       // Create sheet
 | |
| 	TRelation fsoci(LF_SOCI);
 | |
| 
 | |
|   TRectype& soci = fsoci.curr();
 | |
| 
 | |
|   soci.zero();
 | |
|   _mask->autosave(fsoci);
 | |
|   for (fsoci.read(_isgteq); !fsoci.eof(); fsoci.next())  // Fill sheet
 | |
|   {
 | |
|     if (query.test(soci) == 0)
 | |
|     {
 | |
|       TString  ragsoc(80);
 | |
|       TString16 cur_codice = soci.get("CODANAGRSO");
 | |
| 			TString16 key; key << query.tipo() << "|" << cur_codice;
 | |
| 
 | |
| 			const TRectype & anag = cache().get(LF_ANAG, key);
 | |
|       if (anag.empty())
 | |
| 				ragsoc = TR("Anagrafica assente");
 | |
|       else
 | |
| 				ragsoc = anag.get("RAGSOC");
 | |
|       s.add_socio(cur_codice, ragsoc);
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   if (s.items() == 0)
 | |
|   {
 | |
|     warning_box(TR("Nessuna corrispondenza"));
 | |
|     return TRUE;
 | |
|   }
 | |
|   
 | |
|   while(s.run() == K_ENTER)
 | |
|   {
 | |
|     TToken_string& r = s.row();
 | |
|     r.restart();
 | |
|     TString codice(r.get());
 | |
|     TString nome(r.get());
 | |
|     TRectype ditte(LF_NDITTE);
 | |
| 
 | |
|     TToken_string h(128);
 | |
|     h.add("A/P ");
 | |
|     h.add(head(ditte, "CODDITTA", TR("Codice")));
 | |
|     h.add(head(ditte, "RAGSOC", TR("Ragione sociale")));
 | |
|     h.add(HR("Carica|Qualifica|740|750"));
 | |
|     h.add(head(soci, "PERCQUAZ", TR("% Quote")));
 | |
|     TArray_sheet d(-1,-1, -4, -4, nome, h);
 | |
| 
 | |
|     soci.zero();
 | |
|     soci.put("TIPOASOC", query.tipo());
 | |
|     soci.put("CODANAGRSO", codice);
 | |
| 
 | |
|     TToken_string row(128);
 | |
|     for (fsoci.read(_isgteq); !fsoci.eof(); fsoci.next())
 | |
|     {
 | |
|       if (codice != soci.get("CODANAGRSO")) break;
 | |
|       if (query.test(soci) != 0) continue;
 | |
| 
 | |
|       row = soci.get("ATTPREC");
 | |
|       row.add(soci.get("CODDITTA"));
 | |
|       ditte = cache().get(LF_NDITTE, row.get(1));
 | |
|       if (ditte.empty())
 | |
|         row.add(TR("Ditta assente"));
 | |
|       else
 | |
|         row.add(ditte.get("RAGSOC"));
 | |
|       row.add(soci.get("CODCAR"));
 | |
|       row.add(soci.get("RICQUAL"));
 | |
|       row.add(soci.get("Q740"));
 | |
|       row.add(soci.get("QUATTPREV"));
 | |
|       row.add(soci.get("PERCQUAZ"));
 | |
| 
 | |
|       d.add(row);
 | |
|     }
 | |
|     d.run();
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| 
 | |
| int ba5100(int argc,char* argv[])
 | |
| {
 | |
|   TQuery_application qa;
 | |
|   qa.run(argc, argv, TR("Ricerca Soci"));
 | |
|   return 0;
 | |
| }
 |