Files correlati : Ricompilazione Demo : [ ] Commento : riporto da 11 importazione documenti terminata (per quanto riguarda i campi noti); per gli ignoti si vedra'! git-svn-id: svn://10.65.10.50/branches/R_10_00@21083 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			430 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			430 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | ||
| #include <automask.h>
 | ||
| #include <config.h>
 | ||
| #include <progind.h>
 | ||
| #include <recarray.h>
 | ||
| #include <recset.h>
 | ||
| #include <relapp.h>
 | ||
| #include <reputils.h>
 | ||
| 
 | ||
| #include <clifo.h>
 | ||
| #include <doc.h>
 | ||
| #include <rdoc.h>
 | ||
| 
 | ||
| #include "../mg/umart.h"
 | ||
| #include "../ve/condv.h"
 | ||
| #include "../ve/rcondv.h"
 | ||
| 
 | ||
| #include "halib.h"
 | ||
| #include "ha0.h"
 | ||
| #include "ha0400a.h"
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // TAutomask
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| class THardy_tied_mask : public TAutomask
 | ||
| {
 | ||
|   int _pos_check, _pos_codcf, _pos_ragsoc, _pos_anno, _pos_codnum, _pos_ndoc, _pos_tipodoc, _pos_importo, _pos_condpag, _pos_codage;
 | ||
| protected:
 | ||
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | ||
| 
 | ||
|   bool one_checked() const;
 | ||
|   void check_all(const bool checked);
 | ||
| 
 | ||
|   long fill_recordset(const long codcf, TISAM_recordset& recset);
 | ||
|   void fill_sheet();
 | ||
| 
 | ||
|   int elabora_contratto(TToken_string* riga_sheet, TLog_report& log);
 | ||
|   real find_costo(const TString& codart, const TString& um) const;
 | ||
| 
 | ||
| public:
 | ||
|   THardy_tied_mask();
 | ||
|   ~THardy_tied_mask();
 | ||
| };
 | ||
| 
 | ||
| 
 | ||
| long THardy_tied_mask::fill_recordset(const long codcf, TISAM_recordset& recset)
 | ||
| {
 | ||
|   TString query;
 | ||
|   const char tipo_contratto = get(F_TIPO)[0];
 | ||
| 
 | ||
|   query << "USE RDOC";
 | ||
|   query << "\nSELECT (DOC.STATO=5)&&(TIPORIGA=#TIPORIGA)&&(STR(" << RCA_2_ANTICIPATO << "<=" << RCA_2_RESO_STORICO << "))";
 | ||
|   //in base al tipo contratto cambia la query
 | ||
|   if (tipo_contratto == 'T')
 | ||
|     query << "&&((DOC.TIPODOC=#A_TIPODOC)||(DOC.TIPODOC=#R_TIPODOC))";
 | ||
|   else
 | ||
|     query << "&&(DOC.TIPODOC=#TIPODOC)";
 | ||
| 
 | ||
|   if (codcf > 0)
 | ||
|     query << "&&(DOC.TIPOCF='C')&&(DOC.CODCF=#CODCF)";
 | ||
| 
 | ||
|   query << "\nJOIN DOC INTO PROVV=PROVV ANNO=ANNO CODNUM=CODNUM NDOC=NDOC";
 | ||
| 
 | ||
|   //setta la query al recordset, che inizialmente aveva una query vuota
 | ||
|   recset.set(query);
 | ||
| 
 | ||
|   //settaggio delle variabili
 | ||
|   //tipo riga
 | ||
|   const TString4 tiporiga = HARDY_TIPORIGA_SOMMA;
 | ||
|   recset.set_var("#TIPORIGA", tiporiga);
 | ||
|   //numerazione
 | ||
|   TConfig config(CONFIG_DITTA, "ha");
 | ||
|   const TString4 tipo_a = config.get("CoAntTip");
 | ||
|   const TString4 tipo_r = config.get("CoRifaTip");
 | ||
|   switch (tipo_contratto)
 | ||
|   {
 | ||
|   case 'A': recset.set_var("#TIPODOC", tipo_a); break;
 | ||
|   case 'R': recset.set_var("#TIPODOC", tipo_r); break;
 | ||
|   case 'T': recset.set_var("#A_TIPODOC", tipo_a);  recset.set_var("#R_TIPODOC", tipo_r); break;
 | ||
|   default:  break;
 | ||
|   }
 | ||
| 
 | ||
|   //clifo
 | ||
|   if (codcf > 0)
 | ||
|     recset.set_var("#CODCF", codcf);
 | ||
| 
 | ||
|   //e alla fine della fiera...
 | ||
|   const long items = recset.items();
 | ||
|   return items;
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| void THardy_tied_mask::fill_sheet()
 | ||
| {
 | ||
| 
 | ||
|   TSheet_field& sf_righe = sfield(F_RIGHE);
 | ||
|   sf_righe.destroy();
 | ||
| 
 | ||
|   //query per raccattare i contratti pareggiati; in base al filtro sul cliente cambia la query
 | ||
|   TString query;
 | ||
|   long recset_items;
 | ||
|   TISAM_recordset recset(query);
 | ||
|   const long codcf = get_long(F_CODCF);
 | ||
|   
 | ||
|   recset_items = fill_recordset(codcf, recset);
 | ||
| 
 | ||
|   //riempie le righe dello sheet
 | ||
|   TProgind progind(recset_items, "Ricerca contratti in corso...", false, true);
 | ||
|   //record corrente
 | ||
|   //const TRectype& rec = recset.cursor()->curr();    ****cazzone****
 | ||
|   //per ogni riga del recordset va ad aggiornare lo sheet sulla maschera (aggiunge la riga)
 | ||
|   for (bool ok = recset.move_first(); ok; ok = recset.move_next())
 | ||
|   {
 | ||
|     progind.addstatus(1);
 | ||
| 
 | ||
|     TToken_string& row = sf_righe.row(-1);          //riga sheet da riempire
 | ||
| 
 | ||
|     row.add("");
 | ||
|     const TString& codcf = recset.get("DOC.CODCF").as_string();
 | ||
|     row.add(codcf);
 | ||
|     TToken_string key;
 | ||
|     key.add("C");
 | ||
|     key.add(codcf);
 | ||
|     const TString& ragsoc = cache().get(LF_CLIFO, key, CLI_RAGSOC);
 | ||
|     row.add(ragsoc);
 | ||
|     const int anno = recset.get(RDOC_ANNO).as_int();
 | ||
|     row.add(anno);
 | ||
|     const TString& codnum = recset.get(RDOC_CODNUM).as_string();
 | ||
|     row.add(codnum);
 | ||
|     const long ndoc = recset.get(RDOC_NDOC).as_int();
 | ||
|     row.add(ndoc);
 | ||
|     const TString& tipo = recset.get("DOC.TIPODOC").as_string();
 | ||
|     row.add(tipo);
 | ||
|     real importo = recset.get(RCA_2_ANTICIPATO).as_real();
 | ||
|     const TString& str_importo = importo.string();
 | ||
|     row.add(str_importo);
 | ||
|     const TString& codpag = recset.get("DOC.CODPAG").as_string();
 | ||
|     row.add(codpag);
 | ||
|     const TString& codag = recset.get("DOC.CODAG").as_string();
 | ||
|     row.add(codag);
 | ||
| 
 | ||
|     sf_righe.check_row(sf_righe.items()-1, 3);
 | ||
|   }
 | ||
| 
 | ||
|   //mostra e aggiorna lo sheet
 | ||
|   sf_righe.show();
 | ||
|   sf_righe.force_update();
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| //controlla sulla colonna delle spunte se almeno una <20> checkata
 | ||
| bool THardy_tied_mask::one_checked() const
 | ||
| {
 | ||
|   TSheet_field& sf_righe = sfield(F_RIGHE);
 | ||
|   FOR_EACH_SHEET_ROW(sf_righe, i, riga)
 | ||
|   {
 | ||
|     if (riga->get_char(0) > ' ')
 | ||
|       return true;
 | ||
|   }
 | ||
|   return false;
 | ||
| }
 | ||
| 
 | ||
| //checka-dechecka la colonna di spunte dello sheet
 | ||
| void THardy_tied_mask::check_all(const bool checked)
 | ||
| {
 | ||
|   TSheet_field& sf_righe = sfield(F_RIGHE);
 | ||
| 
 | ||
|   FOR_EACH_SHEET_ROW(sf_righe, i, riga)
 | ||
|     riga->add(checked ? "X" : "", 0);
 | ||
| 
 | ||
|   sf_righe.force_update();
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| real THardy_tied_mask::find_costo(const TString& codart, const TString& um) const
 | ||
| {
 | ||
|   const TRectype& rec_anamag = cache().get(LF_ANAMAG, codart);
 | ||
|   real costo = rec_anamag.get_real(ANAMAG_ULTCOS1);
 | ||
|   if (costo <= ZERO)
 | ||
|     costo = rec_anamag.get_real(ANAMAG_COSTSTD);
 | ||
| 
 | ||
|   if (costo <= ZERO)
 | ||
|   {
 | ||
|     TLocalisamfile umart(LF_UMART);
 | ||
|     umart.setkey(2);
 | ||
|     umart.put(UMART_CODART, codart);
 | ||
|     umart.put(UMART_UM, um);
 | ||
|     const int err_umart = umart.read();
 | ||
|     if (err_umart == NOERR)
 | ||
|       costo = umart.get_real(UMART_PREZZO) * 0.5;
 | ||
|   }
 | ||
| 
 | ||
|   return costo;
 | ||
| }
 | ||
| 
 | ||
| //metodo base per l'elaborazione dei contratti pareggiati
 | ||
| int THardy_tied_mask::elabora_contratto(TToken_string* riga_sheet, TLog_report& log)
 | ||
| {
 | ||
|   //si crea il contratto_premi di origine, per caricare i dati che poi dovr<76> modificare
 | ||
|   const long codcf = riga_sheet->get_long(_pos_codcf);
 | ||
|   const int anno = riga_sheet->get_int(_pos_anno);
 | ||
|   const TString& codnum = riga_sheet->get(_pos_codnum);
 | ||
|   const long ndoc = riga_sheet->get_long(_pos_ndoc);
 | ||
|   
 | ||
|   //crea il contratto premi...
 | ||
|   TContratto_premi contratto_premi('D', anno, codnum, ndoc);
 | ||
|   //..e le sue righe
 | ||
|   TRecord_array& righe_contr_premi = contratto_premi.body();
 | ||
| 
 | ||
|   //indicatore di errore complessivo!
 | ||
|   int err = NOERR;
 | ||
| 
 | ||
|   //cerca il listino cliente corrispondente..
 | ||
|   const TString4 listino_cliente = contratto_premi.get(DOC_CODCONT);
 | ||
| 
 | ||
|   TToken_string key;
 | ||
|   key.add("C");             //0
 | ||
|   key.add("");              //1
 | ||
|   key.add("C");             //2
 | ||
|   key.add(codcf);           //3
 | ||
|   key.add(listino_cliente); //4
 | ||
|   TLocalisamfile condv(LF_CONDV);
 | ||
|   condv.put(CONDV_TIPO, key.get(0));
 | ||
|   condv.put(CONDV_CATVEN, key.get(1));
 | ||
|   condv.put(CONDV_TIPOCF, key.get(2));
 | ||
|   condv.put(CONDV_CODCF, key.get(3));
 | ||
|   condv.put(RCONDV_COD, key.get(4));
 | ||
|   err = condv.read();
 | ||
|   //se non lo trova (non dovrebbe MAI accadere, ma i listini cliente possono essere erroneamente accoppati via gestione contratti campo
 | ||
|   if (err != NOERR)
 | ||
|   {
 | ||
|     TString msg;
 | ||
|     msg.format("Il contratto premi %4d%s%7ld del cliente %6ld non ha un listino cliente associato !! Errore: %d", 
 | ||
|                anno, (const char*)codnum, ndoc, codcf, err);
 | ||
|     log.log(2, msg);
 | ||
|   }
 | ||
| 
 | ||
|   //se lo trova scatta l'analisi delle righe listino cliente
 | ||
|   TLocalisamfile rcondv(LF_RCONDV);
 | ||
| 
 | ||
|   //e adesso scatta la ricerca dell'articolo del contratto premi dentro le righe del listino cliente...
 | ||
|   for (int i = righe_contr_premi.last_row(); i > 0 && err == NOERR; i = righe_contr_premi.pred_row(i))
 | ||
|   {
 | ||
|     TRectype& riga = righe_contr_premi[i];
 | ||
|     //solo le righe merce del contratto premi devono essere scasinate!
 | ||
|     if (riga.get(RDOC_TIPORIGA) == HARDY_TIPORIGA_MERCE)
 | ||
|     {
 | ||
|       const TString80 codart = riga.get(RDOC_CODART);
 | ||
|       const TString4 um = riga.get(RDOC_UMQTA);
 | ||
|       //adesso gli tocca cercare lo stesso articolo (e UM) dentro le righe listino cliente per raccatare il prezzo
 | ||
|       rcondv.put(RCONDV_TIPO, key.get(0));
 | ||
|       rcondv.put(RCONDV_CATVEN, key.get(1));
 | ||
|       rcondv.put(RCONDV_TIPOCF, key.get(2));
 | ||
|       rcondv.put(RCONDV_CODCF, key.get(3));
 | ||
|       rcondv.put(RCONDV_COD, key.get(4));
 | ||
|       rcondv.put(RCONDV_TIPORIGA, 'A');
 | ||
|       rcondv.put(RCONDV_CODRIGA, codart);
 | ||
| 
 | ||
|       //la u.m. ci va solo se il listino cliente ha la gestione u.m. (tanto per complicarsi la vita!)
 | ||
|       const bool gestum_contr = cache().get(LF_CONDV, key, CONDV_GESTUM) == "X";
 | ||
|       if (gestum_contr)
 | ||
|         rcondv.put(RCONDV_UM, um);
 | ||
| 
 | ||
|       err = rcondv.read(_isequal, _lock);
 | ||
|       if (err == NOERR)
 | ||
|       {
 | ||
|         //premio e ns_carico li prende dalla riga del contratto premi
 | ||
|         const real premio = riga.get_real(RC_1_PREMIO);
 | ||
|         const real ns_carico = riga.get_real(RC_1_NSCARICO);
 | ||
|         //il prezzo lo prende dal listino cliente
 | ||
|         real prezzo = rcondv.get_real(RCONDV_PREZZO);
 | ||
|         //aggiorna il prezzo con una formula ladresca...
 | ||
|         prezzo = prezzo - premio + ns_carico;
 | ||
| 
 | ||
|         //controlla di non avere un prezzo del cazzo!
 | ||
|         const real costo = find_costo(codart, um);
 | ||
|         if (prezzo < costo)
 | ||
|         {
 | ||
|           TString msg;
 | ||
|           msg.format("Il prezzo dell'articolo %s e' inferiore alla meta' del costo !", (const char*)codart);
 | ||
|           log.log(2, msg);
 | ||
|         }
 | ||
| 
 | ||
|         rcondv.put(RCONDV_PREZZO, prezzo);
 | ||
|         
 | ||
|         err = rcondv.rewrite();
 | ||
|         if (err != NOERR)
 | ||
|         {
 | ||
|           TString msg;
 | ||
|           msg.format("Imossibile aggiornare il listino %s del cliente %6ld ! Errore %d", (const char*)listino_cliente, codcf, err);
 | ||
|           log.log(1, msg);
 | ||
|         }
 | ||
|       }
 | ||
|       else
 | ||
|       {
 | ||
|         TString msg;
 | ||
|         msg.format("Impossibile trovare l'articolo %s con u.m. %s nel listino %s del cliente %6ld !! Errore %d", 
 | ||
|                   (const char*)codart, (const char*)um, (const char*)listino_cliente, codcf, err);
 | ||
|         log.log(2, msg);
 | ||
|       }
 | ||
| 
 | ||
|     } //if (riga.get(RDOC_TIPORIGA)...
 | ||
|   } //for (int i = righe_contr_premi.last_row()...
 | ||
| 
 | ||
|   //alla fine della fiera il contratto premi va messo in stato scaduto, ovvero 9 direi...
 | ||
|   if (err == NOERR)
 | ||
|   {
 | ||
|     const TTipo_documento& tipodoc = contratto_premi.tipo();
 | ||
|     const char stato_scaduto = tipodoc.stato_chiuso();
 | ||
| 
 | ||
|     contratto_premi.put(DOC_STATO, stato_scaduto);
 | ||
|     err = contratto_premi.rewrite();
 | ||
| 
 | ||
|     if (err != NOERR)
 | ||
|     {
 | ||
|       TString msg;
 | ||
|       msg.format("Impossibile aggiornare il contratto premi %4d%s%7ld del cliente %6ld !! Errore %d",
 | ||
|                  anno, (const char*)codnum, ndoc, err);
 | ||
|       log.log(2, msg);
 | ||
|     }
 | ||
|   }
 | ||
| 
 | ||
|   //aggiornamento positivo del log!
 | ||
|   if (err == NOERR)
 | ||
|   {
 | ||
|     TString msg;
 | ||
|     msg.format("Chiuso contratto premi %7ld del cliente %6ld - Aggiornato listino %s", ndoc, codcf, (const char*)listino_cliente);
 | ||
|   }
 | ||
| 
 | ||
|   return err;
 | ||
| }
 | ||
| 
 | ||
| bool THardy_tied_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | ||
| {
 | ||
|   switch (o.dlg())
 | ||
| 	{
 | ||
|   case F_TIPO:
 | ||
|     if (e == fe_modify)
 | ||
|     {
 | ||
|       //riempie lo sheet con i contratti pareggiati
 | ||
|       const TString& tipo = get(F_TIPO);
 | ||
|       if (tipo.full())
 | ||
|         fill_sheet();
 | ||
|     }
 | ||
| 
 | ||
|     //toolbar
 | ||
|   case DLG_CHECKALL:
 | ||
|     if (e == fe_button)
 | ||
|     {
 | ||
|       check_all(!one_checked());
 | ||
|     }
 | ||
|     break;
 | ||
| 
 | ||
|   case DLG_OK:
 | ||
|     if (e == fe_button)
 | ||
|     {
 | ||
|       //gi<67> che ci siamo mettiamoci pure un log di elaborazione
 | ||
|       TLog_report log("Elaborazione contratti selezionati");
 | ||
|       log.kill_duplicates();
 | ||
|       log.log(0, "");
 | ||
|       TSheet_field& righe = sfield(F_RIGHE);
 | ||
|       FOR_EACH_SHEET_ROW(righe, r, riga)
 | ||
|       {
 | ||
|         //vengono elaborate solo le righe checkate
 | ||
|         const char checked = riga->get_char(0);
 | ||
|         if (checked == 'X')
 | ||
|           int err = elabora_contratto(riga, log);
 | ||
|       }
 | ||
|       log.print_or_preview();
 | ||
|     }
 | ||
|     break;
 | ||
|   default:
 | ||
|     break;
 | ||
|   }
 | ||
|   return true;
 | ||
| }
 | ||
| 
 | ||
| THardy_tied_mask::THardy_tied_mask() : TAutomask ("ha0400a")
 | ||
| {
 | ||
|   //assegna una volta per tutte le pos delle colonne di sheet
 | ||
|   TSheet_field& sf_righe = sfield(F_RIGHE);
 | ||
|   _pos_check = sf_righe.cid2index(S_CHECK);
 | ||
|   _pos_codcf = sf_righe.cid2index(S_CODCF);
 | ||
|   _pos_ragsoc = sf_righe.cid2index(S_RAGSOC);
 | ||
|   _pos_anno = sf_righe.cid2index(S_ANNO);
 | ||
|   _pos_codnum = sf_righe.cid2index(S_CODNUM);
 | ||
|   _pos_ndoc = sf_righe.cid2index(S_NDOC);
 | ||
|   _pos_tipodoc = sf_righe.cid2index(S_TIPO);
 | ||
|   _pos_importo = sf_righe.cid2index(S_IMPORTO);
 | ||
|   _pos_condpag = sf_righe.cid2index(S_CONDPAG);
 | ||
|   _pos_codage = sf_righe.cid2index(S_CODAG);
 | ||
| }
 | ||
| 
 | ||
| THardy_tied_mask::~THardy_tied_mask()
 | ||
| {
 | ||
| }
 | ||
| 
 | ||
| ///////////////////////////////////////
 | ||
| // TSkeleton_application
 | ||
| ///////////////////////////////////////
 | ||
| class THardy_tied : public TSkeleton_application
 | ||
| {
 | ||
| protected:
 | ||
| public:
 | ||
|   virtual void main_loop();
 | ||
|   virtual bool create();
 | ||
| };
 | ||
| 
 | ||
| void THardy_tied::main_loop()
 | ||
| {
 | ||
|   THardy_tied_mask mask;
 | ||
|   while (mask.run() == K_ENTER)
 | ||
|   {
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| bool THardy_tied::create()
 | ||
| {
 | ||
|   open_files(LF_DOC, LF_RIGHEDOC, LF_CONDV, LF_RCONDV, 0);
 | ||
| 
 | ||
| 	return TSkeleton_application::create();
 | ||
| }
 | ||
| 
 | ||
| int ha0400 (int argc, char* argv[])
 | ||
| {
 | ||
|   THardy_tied tiedapp;
 | ||
|   tiedapp.run(argc, argv, TR("Elaborazione contratti premio pareggiati"));
 | ||
|   return 0;
 | ||
| } |