Files correlati : Ricompilazione Demo : [ ] Commento : Spostata in libreria funzione di calcoloformula sconti git-svn-id: svn://10.65.10.50/branches/R_10_00@22488 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			246 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			246 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "velib.h"
 | 
						|
 | 
						|
/////////////////////////////////////////////////////////////
 | 
						|
// TCodice_numerazione
 | 
						|
/////////////////////////////////////////////////////////////
 | 
						|
 | 
						|
TCodice_numerazione::TCodice_numerazione(const char* codnum)
 | 
						|
                   : TRectype(LF_TABCOM)
 | 
						|
{
 | 
						|
  settab("NUM");
 | 
						|
  if (codnum && *codnum)
 | 
						|
    read(codnum);
 | 
						|
  else
 | 
						|
    setempty(TRUE);  
 | 
						|
}
 | 
						|
 | 
						|
TCodice_numerazione::TCodice_numerazione(const TRectype& rec)
 | 
						|
               : TRectype(rec)
 | 
						|
{ }
 | 
						|
 | 
						|
TCodice_numerazione::~TCodice_numerazione()
 | 
						|
{ }
 | 
						|
 | 
						|
const TString& TCodice_numerazione::tipo_doc(int i) const
 | 
						|
{
 | 
						|
  CHECK(i < 36, "Impossibbile tipo documento"); 
 | 
						|
  const char * field = i < 17 ? "S2" : "S3";
 | 
						|
  
 | 
						|
  if (i >= 17)
 | 
						|
    i -= 17;
 | 
						|
	TString & tmp = get_tmp_string();
 | 
						|
	tmp = get(field).mid(i * 4, 4);
 | 
						|
	tmp.trim();
 | 
						|
  return tmp;
 | 
						|
}                                             
 | 
						|
 | 
						|
int TCodice_numerazione::ntipi_doc() const
 | 
						|
{
 | 
						|
  int l = get("S3").len(); 
 | 
						|
  if (l > 0)
 | 
						|
    return ((l - 1) / 4) + 18;
 | 
						|
  l = get("S2").len();
 | 
						|
  return l ? (((l - 1) / 4) + 1) : 0;
 | 
						|
}
 | 
						|
 | 
						|
void TCodice_numerazione::complete_num(long num, TString& codnum) const
 | 
						|
{
 | 
						|
  codnum = prefisso();
 | 
						|
  codnum << num;
 | 
						|
  codnum << postfisso();
 | 
						|
}
 | 
						|
 | 
						|
int TCodice_numerazione::read(const char* codnum)
 | 
						|
{                                   
 | 
						|
  *this = cache().get("%NUM", codnum);
 | 
						|
  int err = empty() ? _iskeynotfound : NOERR; 
 | 
						|
#ifdef DBG  
 | 
						|
  if (err != NOERR)
 | 
						|
    NFCHECK("Codice numerazione errato: %s", codnum);
 | 
						|
#endif    
 | 
						|
  return err;  
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
						|
//  trova le numerazioni documenti in base ai tipi richiesti (ca3800,ca3900,ps1001,ha3800)
 | 
						|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
						|
int numerazioni_documenti(TString_array& num_doc, const TString& tipo_doc)
 | 
						|
{
 | 
						|
  //e adesso cerca le numerazioni che contengono tipi ordine
 | 
						|
  TISAM_recordset num_recset("USE %NUM");
 | 
						|
  for (bool ok = num_recset.move_first(); ok; ok = num_recset.move_next())    //giro sui vari tipi numerazione
 | 
						|
  {
 | 
						|
    const TString4 codnum = num_recset.get("CODTAB").as_string();
 | 
						|
 | 
						|
    const TCodice_numerazione numerazione(codnum);
 | 
						|
    for (int t = numerazione.ntipi_doc() - 1; t >= 0; t--)
 | 
						|
    {
 | 
						|
      const TString& curr_tipo_doc = numerazione.tipo_doc(t);
 | 
						|
      if (curr_tipo_doc == tipo_doc)
 | 
						|
      {
 | 
						|
        num_doc.add(codnum);
 | 
						|
        break;
 | 
						|
      }
 | 
						|
    } //for (int t = codnum..
 | 
						|
  } //for (bool ok = num_recset...
 | 
						|
 | 
						|
  return num_doc.items();
 | 
						|
}
 | 
						|
 | 
						|
int numerazioni_documenti(TString_array& num_doc, TString_array& tip_doc, const int tipo)
 | 
						|
{
 | 
						|
  //cominciamo con i tipi
 | 
						|
  TISAM_recordset tipi_recset("USE %TIP\nSELECT STR(I1=#TIPO)");
 | 
						|
  tipi_recset.set_var("#TIPO", TVariant(long(tipo)));
 | 
						|
  for (bool ok = tipi_recset.move_first(); ok; ok = tipi_recset.move_next())    //giro sui vari tipi ordine
 | 
						|
  {
 | 
						|
    const TString4 tipo = tipi_recset.get("CODTAB").as_string();
 | 
						|
    tip_doc.add(tipo);
 | 
						|
  }
 | 
						|
 | 
						|
  //e adesso cerca le numerazioni che contengono tipi ordine
 | 
						|
  TISAM_recordset num_recset("USE %NUM");
 | 
						|
  for (bool ok = num_recset.move_first(); ok; ok = num_recset.move_next())    //giro sui vari tipi numerazione
 | 
						|
  {
 | 
						|
    const TString4 codtab = num_recset.get("CODTAB").as_string();
 | 
						|
 | 
						|
    const TCodice_numerazione numerazione(codtab);
 | 
						|
    for (int t = numerazione.ntipi_doc() - 1; t >= 0; t--)
 | 
						|
    {
 | 
						|
      const TString& tipo_doc = numerazione.tipo_doc(t);
 | 
						|
      if (tip_doc.find(tipo_doc) >= 0)
 | 
						|
      {
 | 
						|
        if (num_doc.find(codtab) < 0) // Evito aggiunta di doppioni
 | 
						|
          num_doc.add(codtab);
 | 
						|
        break;
 | 
						|
      }
 | 
						|
    } //for (int t = codnum..
 | 
						|
  } //for (bool ok = num_recset...
 | 
						|
 | 
						|
  return num_doc.items();
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
int numerazioni_ordini(TString_array& num_ordini, TString_array& tip_ordini)
 | 
						|
{
 | 
						|
  //i documenti che vanno presi in cosiderazione sono quelli che generano un IMPEGNATO secondo le auree regole del..
 | 
						|
  //..nostro invincibile Adolf!
 | 
						|
  num_ordini.destroy();
 | 
						|
  tip_ordini.destroy();
 | 
						|
  
 | 
						|
  numerazioni_documenti(num_ordini, tip_ordini, 3);
 | 
						|
 | 
						|
  return num_ordini.items();
 | 
						|
}
 | 
						|
 | 
						|
int numerazioni_fatture(TString_array& num_fatture, TString_array& tip_fatture)
 | 
						|
{
 | 
						|
  //i documenti che vanno presi in cosiderazione sono quelli non ancora contabilizzati di tipo 0=Altro 2=Fattura
 | 
						|
  num_fatture.destroy();
 | 
						|
  tip_fatture.destroy();
 | 
						|
  
 | 
						|
  numerazioni_documenti(num_fatture, tip_fatture, 0);
 | 
						|
  numerazioni_documenti(num_fatture, tip_fatture, 2);
 | 
						|
 | 
						|
  return num_fatture.items();
 | 
						|
}
 | 
						|
 | 
						|
/////////////////////////////////////////////////////////////
 | 
						|
// TSpesa_prest
 | 
						|
/////////////////////////////////////////////////////////////
 | 
						|
 | 
						|
TSpesa_prest::TSpesa_prest(const char* codice, char tipo)
 | 
						|
       : TRectype(LF_TAB)
 | 
						|
{ 
 | 
						|
	switch (tipo)
 | 
						|
	{
 | 
						|
		case RIGA_SPESEDOC :
 | 
						|
			settab("SPP");
 | 
						|
			break;
 | 
						|
		case RIGA_PRESTAZIONI :
 | 
						|
			settab("PRS");
 | 
						|
			break;
 | 
						|
		case RIGA_RISORSE :
 | 
						|
			settab("RSS");
 | 
						|
			break;
 | 
						|
		case RIGA_ATTREZZATURE :
 | 
						|
			settab("ATR");
 | 
						|
			break;
 | 
						|
		default :
 | 
						|
			settab("SPP");
 | 
						|
			break;
 | 
						|
	}
 | 
						|
  if (codice && *codice)
 | 
						|
  {
 | 
						|
    const int err = read(codice);
 | 
						|
#ifdef DBG
 | 
						|
    if (err != NOERR)
 | 
						|
			switch (tipo)
 | 
						|
			{
 | 
						|
				case RIGA_SPESEDOC :
 | 
						|
				  error_box("Spesa %s assente", codice);
 | 
						|
					break;
 | 
						|
				case RIGA_PRESTAZIONI :
 | 
						|
					error_box("Prestazione %s assente", codice);
 | 
						|
					break;
 | 
						|
				case RIGA_RISORSE :
 | 
						|
				  error_box("Risorsa %s assente", codice);
 | 
						|
					break;
 | 
						|
				case RIGA_ATTREZZATURE :
 | 
						|
				  error_box("Attrezzatura %s assente", codice);
 | 
						|
					break;
 | 
						|
				default :
 | 
						|
				  error_box("Spesa %s assente", codice);
 | 
						|
					break;
 | 
						|
			}
 | 
						|
#endif
 | 
						|
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
TSpesa_prest::TSpesa_prest(const TRectype& rec)
 | 
						|
      : TRectype(rec)
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
char TSpesa_prest::genere() const
 | 
						|
{ 
 | 
						|
	const TString & tipo = get("COD"); 
 | 
						|
	if (tipo == "SPP")
 | 
						|
		return RIGA_SPESEDOC;
 | 
						|
	else
 | 
						|
		if (tipo == "PRS")
 | 
						|
			return RIGA_PRESTAZIONI;
 | 
						|
	else
 | 
						|
		if (tipo == "RSS")
 | 
						|
			return RIGA_RISORSE;
 | 
						|
		else
 | 
						|
			if (tipo == "ATR")
 | 
						|
				return  RIGA_ATTREZZATURE;
 | 
						|
	return ' ';
 | 
						|
}
 | 
						|
int TSpesa_prest::read(const char* codice)
 | 
						|
{                      
 | 
						|
  const TString8 cod = get("COD");
 | 
						|
  *this = cache().get(cod, codice);
 | 
						|
  return empty() ? _iskeynotfound : NOERR;
 | 
						|
}
 | 
						|
 | 
						|
const TString& TSpesa_prest::cod_iva() const 
 | 
						|
{ 
 | 
						|
  // La parte seguente di s3 e' utilizzata dalle atrezzature per altri campi
 | 
						|
  TString& tmp = get_tmp_string();
 | 
						|
  tmp = get("S3").left(4);
 | 
						|
  tmp.trim();
 | 
						|
  return tmp;
 | 
						|
}
 | 
						|
 | 
						|
real TSpesa_prest::prezzo() const 
 | 
						|
{ 
 | 
						|
  real r = get("R10");   // Prezzo con tanti decimali
 | 
						|
  if (r.is_zero())
 | 
						|
    r = get_real("R0");  // Prezzo con pochi decimali
 | 
						|
  return r;
 | 
						|
}
 | 
						|
 |