Files correlati : pe0.exe Ricompilazione Demo : [ ] Commento : Fatturazione 02 e velocizzazione calcolo consegnato mensile git-svn-id: svn://10.65.10.50/trunk@19915 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			229 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			229 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | |
| #include <automask.h>
 | |
| #include <progind.h>
 | |
| #include <relation.h>
 | |
| #include <utility.h>
 | |
| 
 | |
| #include "pe0600.h"
 | |
| #include "../ve/velib.h"
 | |
| #include "../ve/velib04.h"
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TGenerazione_ordine_produzione
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TGenerazione_ordine_produzione : public TCopia_documento
 | |
| { 
 | |
| protected:
 | |
|   virtual void post_process(TLista_documenti& doc_out, TLista_documenti& doc_in);
 | |
| 
 | |
| public:
 | |
| 	TGenerazione_ordine_produzione(const char* cod) : TCopia_documento(cod) {}
 | |
|   virtual ~TGenerazione_ordine_produzione() { }
 | |
| };
 | |
| 
 | |
| void TGenerazione_ordine_produzione::post_process(TLista_documenti& doc_out, TLista_documenti& doc_in)
 | |
| {
 | |
|   const int items = doc_out.items();
 | |
|   
 | |
| 	for (int d = 0; d < items; d++)
 | |
|   {
 | |
|     TDocumento& doc = doc_out[d];
 | |
| 		const int rows = doc.physical_rows();
 | |
| 		TBit_array to_delete;
 | |
| 
 | |
| 		for (int r = 1; r <= rows - 1; r++) 
 | |
| 		{
 | |
| 			TRiga_documento & row = (TRiga_documento &)doc[r];
 | |
| 			const int level = row.get_int(RDOC_LEVEL);
 | |
| 			const int next_level = doc[r + 1].get_int(RDOC_LEVEL);
 | |
| 
 | |
| 			to_delete.set(r, !row.is_merce() || level >= next_level);
 | |
| 		}
 | |
| 		to_delete.set(rows, true);
 | |
| 		for (int r = rows; r >= 1; r--) 
 | |
| 		{
 | |
| 			TRiga_documento & row = (TRiga_documento &)doc[r];
 | |
| 
 | |
| 			if (to_delete[r])
 | |
| 				doc.destroy_row(r, true);
 | |
| 		}
 | |
| 	}
 | |
| 	for (int d = items - 1; d >= 0; d--)
 | |
|   {
 | |
|     TDocumento& doc = doc_out[d];
 | |
| 		const int rows = doc.physical_rows();
 | |
| 
 | |
| 		if (rows == 0)
 | |
| 			doc_out.destroy(d, true);
 | |
| 	}
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TGenerazione_ordine_acquisto
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TGenerazione_ordine_acquisto : public TCopia_documento
 | |
| { 
 | |
| protected:
 | |
|   virtual void post_process(TLista_documenti& doc_out, TLista_documenti& doc_in);
 | |
| 
 | |
| public:
 | |
|   TGenerazione_ordine_acquisto(const char* cod) : TCopia_documento(cod) {}
 | |
|   virtual ~TGenerazione_ordine_acquisto() { }
 | |
| };
 | |
| 
 | |
| void TGenerazione_ordine_acquisto::post_process(TLista_documenti& doc_out, TLista_documenti& doc_in)
 | |
| {
 | |
|   const int items = doc_out.items();
 | |
|   
 | |
| 	for (int d = 0; d < items; d++)
 | |
|   {
 | |
|     TDocumento& doc = doc_out[d];
 | |
| 		const int rows = doc.physical_rows();
 | |
| 		TBit_array to_delete;
 | |
| 
 | |
| 		for (int r = 1; r <= rows - 1; r++) 
 | |
| 		{
 | |
| 			TRiga_documento & row = (TRiga_documento &)doc[r];
 | |
| 			const int level = row.get_int(RDOC_LEVEL);
 | |
| 			const int next_level = doc[r + 1].get_int(RDOC_LEVEL);
 | |
| 
 | |
| 			to_delete.set(r, !row.is_merce() || level < next_level);
 | |
| 		}
 | |
| 		for (int r = rows; r >= 1; r--) 
 | |
| 		{
 | |
| 			TRiga_documento & row = (TRiga_documento &)doc[r];
 | |
| 
 | |
| 			if (to_delete[r])
 | |
| 				doc.destroy_row(r, true);
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TGenOrdini_mask
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TGenOrdini_mask : public TAutomask
 | |
| {
 | |
| protected:
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| 
 | |
| public:
 | |
|   TGenOrdini_mask() : TAutomask("pe0600a") {}
 | |
| };
 | |
| 
 | |
| bool TGenOrdini_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | |
| {
 | |
|   switch (o.dlg())
 | |
|   {
 | |
|   case F_FROM_FRNDOC:
 | |
|   case F_FROM_TONDOC:  
 | |
|     if (e == fe_modify || e == fe_init)
 | |
|     {
 | |
|       const long docfr = get_long(F_FROM_FRNDOC);
 | |
|       const long docto = get_long(F_FROM_TONDOC);
 | |
| 			if (docto > 0L && docfr > docto)
 | |
| 				return error_box("Il documento finale non puo' essere maggiore di quello iniziale");
 | |
|     }
 | |
|     break;
 | |
|   default:
 | |
|     break;
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // Main program
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TGenOrdini_app : public TSkeleton_application
 | |
| { 
 | |
|   
 | |
| protected:
 | |
| 
 | |
| public:
 | |
|   virtual void main_loop();
 | |
| };
 | |
| 
 | |
| void TGenOrdini_app::main_loop()
 | |
| {
 | |
|   open_files(LF_TAB, LF_TABCOM, LF_DOC, LF_RIGHEDOC, LF_CONDV, LF_RCONDV, 
 | |
|              LF_ANAMAG, LF_SCONTI, LF_UMART, LF_CLIFO, LF_CFVEN, LF_INDSP, 
 | |
|              LF_OCCAS, LF_MOVMAG, LF_RMOVMAG, LF_SVRIEP, LF_AGENTI, LF_PERCPROV, 0);
 | |
| 
 | |
|   TGenOrdini_mask m; 
 | |
|   while (m.run() == K_ENTER)
 | |
|   {
 | |
| 		const TDate data(m.get_date(F_DATA));
 | |
|     TRectype rec_from(LF_DOC);
 | |
|     rec_from.put(DOC_ANNO, m.get(F_FROM_ANNO));
 | |
|     rec_from.put(DOC_CODNUM, m.get(F_FROM_NUM));
 | |
|     rec_from.put(DOC_PROVV, m.get(F_FROM_PROVV));
 | |
|     rec_from.put(DOC_NDOC, m.get(F_FROM_FRNDOC)); 
 | |
| 
 | |
| 
 | |
|     TRectype rec_to(rec_from);
 | |
|     rec_to.put(DOC_NDOC, m.get(F_FROM_TONDOC));
 | |
| 
 | |
|     // Costruisce il filtro sui tipi documento selezionati
 | |
|     // Il pipe significa OR per le espressioni
 | |
|     TRelation rel(LF_DOC);
 | |
|     TCursor cur(&rel, "", 1, &rec_from, &rec_to);
 | |
|         
 | |
|     const long tot = cur.items();
 | |
|     if (tot > 0L)
 | |
|     {
 | |
| 			TGenerazione_ordine_acquisto a(m.get(F_CODICE_ORA));
 | |
| 			TGenerazione_ordine_produzione * p = NULL;
 | |
| 
 | |
| 			a.preserve_original_rif();
 | |
| 			if (m.get(F_CODICE_ORP).full())
 | |
| 			{
 | |
| 				p = new TGenerazione_ordine_produzione(m.get(F_CODICE_ORP));
 | |
| 				p->preserve_original_rif();
 | |
| 			}
 | |
| 			cur.freeze();
 | |
|       TProgind pi(tot, "Generazione in corso...", FALSE, TRUE);
 | |
|       for (cur = 0; cur.pos() < tot; ++cur)
 | |
|       {
 | |
|         pi.addstatus(1);
 | |
| 
 | |
|         TDocumento srcdoc(cur.curr()), newdoc;
 | |
| 				TLista_documenti doc_in;
 | |
| 				TLista_documenti doc_out;
 | |
| 
 | |
| 				if (p != NULL && p->is_document_ok(srcdoc))
 | |
| 				{
 | |
| 
 | |
| 					doc_in.add(srcdoc);
 | |
| 					p->elabora(doc_in, doc_out, data);
 | |
| 					doc_in.rewrite();
 | |
| 					doc_out.write();
 | |
| 					doc_in.destroy(-1);
 | |
| 					doc_out.destroy(-1);
 | |
| 				}
 | |
| 				if (a.is_document_ok(srcdoc))
 | |
| 				{
 | |
| 					doc_in.add(srcdoc);
 | |
| 					a.elabora(doc_in, doc_out, data);
 | |
| 					doc_in.rewrite();
 | |
| 					doc_out.write();
 | |
| 				}
 | |
|       }
 | |
| 			if (p != NULL)
 | |
| 				delete p;
 | |
|     }
 | |
|     else
 | |
|       warning_box("Nessun documento soddisfa i vincoli indicati");
 | |
|   }
 | |
| }
 | |
| 
 | |
| int pe0600(int argc, char* argv[])
 | |
| {
 | |
|   TGenOrdini_app a;
 | |
|   a.run(argc, argv, "Generazione ordini di produzione e acquisto");
 | |
|   return 0;
 | |
| }
 |