#ifndef __RIGHEDOC_H
#include "righedoc.h"
#endif

#ifndef __VE0100_H
#include "ve0100.h"
#endif

#ifndef __VERIG_H
#include "verig.h"
#endif

#ifndef __VE0100C_H
#include "ve0100c.h"
#endif

#ifndef __SCONTI_H
#include "sconti.h"
#endif


void TRiga_documento_motore::load(TSheet_field & f,  TToken_string& row)
{
  put( "STATORIGA", row.get( f.cid2index(FR_STATORIGA) ) );
  put( "TIPORIGA", row.get( f.cid2index(FR_TIPORIGA )) );
  TString16 codmag(row.get(f.cid2index(FR_CODMAG)));
    
  codmag.left_just(3);
  codmag << row.get( f.cid2index(FR_CODDEP ));
  put( "CODMAG",  codmag);
  put( "CODART", row.get( f.cid2index(FR_CODART )) );
  TString s(row.get(f.cid2index(FR_DESCR))); 
  int split_pos = s.find('\n');
  if (split_pos > 0)
  {
    put( "DESCR", s.left(split_pos));
    put("DESCLUNGA", "X");  
    s.ltrim(split_pos);
    put("DESCEST", s);
  }
  else
  {
    put("DESCR", s);
    put("DESCLUNGA", "");
    zero("DESCEST");
  }
  
  put( "PREZZO", row.get( f.cid2index(FR_PREZZO )) );
  put( "UMQTA", row.get( f.cid2index(FR_UMQTA )) );
  put( "QTA", row.get( f.cid2index(FR_QTA )) );
  put( "QTAEVASA", row.get( f.cid2index(FR_QTAEVASA )) );
  put( "RIGAEVASA", row.get( f.cid2index(FR_RIGAEVASA )) );
  put( "TARA", row.get( f.cid2index(FR_TARA )) );
  put( "PNETTO", row.get( f.cid2index(FR_PNETTO )) );
  put( "NCOLLI", row.get( f.cid2index(FR_NCOLLI )) );
  put( "DAEVADERE", row.get( f.cid2index(FR_DAEVADERE )) );  
  put( "SCONTO", row.get( f.cid2index(FR_SCONTO )) );
  put( "PERCPROV", row.get( f.cid2index(FR_PERCPROV )) );
  put( "IMPFISSO", row.get( f.cid2index(FR_IMPFISSO )) );
  put( "CODIVA", row.get( f.cid2index(FR_CODIVA )) );
  put( "ADDIVA", row.get( f.cid2index(FR_ADDIVA )) );
  put( "ASPBENI", row.get( f.cid2index(FR_ASPBENI )) );  
}
    
void TRiga_documento_motore::save(TSheet_field & f, TToken_string& row )
{
  row.add( get( "STATORIGA" ), f.cid2index(FR_STATORIGA ));
  row.add( get( "TIPORIGA" ), f.cid2index(FR_TIPORIGA ));
  const TString codmag(get("CODMAG"));
  row.add( codmag.left(3), f.cid2index(FR_CODMAG ));
  row.add( codmag.mid(3), f.cid2index(FR_CODDEP ));
  row.add( get( "CODART" ), f.cid2index(FR_CODART ));
  TString s(get("DESCR"));
  if (get_bool("DESCLUNGA"))
    s << get("DESCEST");
  row.add(s, f.cid2index(FR_DESCR ));
  row.add( get( "UMQTA" ), f.cid2index(FR_UMQTA ));
  row.add( get( "PREZZO" ), f.cid2index(FR_PREZZO ));
  row.add( get( "QTA" ), f.cid2index(FR_QTA ));
  row.add( get( "QTAEVASA" ), f.cid2index(FR_QTAEVASA ));
  row.add( get( "RIGAEVASA" ), f.cid2index(FR_RIGAEVASA ));
  row.add( get( "TARA" ), f.cid2index(FR_TARA ));
  row.add( get( "PNETTO" ), f.cid2index(FR_PNETTO ));
  row.add( get( "NCOLLI" ), f.cid2index(FR_NCOLLI ));
  row.add( get( "DAEVADERE" ), f.cid2index(FR_DAEVADERE ));
  row.add( get( "SCONTO" ), f.cid2index(FR_SCONTO ));
  row.add( get( "PERCPROV" ), f.cid2index(FR_PERCPROV ));
  row.add( get( "IMPFISSO" ), f.cid2index(FR_IMPFISSO ));
  row.add( get( "CODIVA" ), f.cid2index(FR_CODIVA ));
  row.add( get( "ADDIVA" ), f.cid2index(FR_ADDIVA ));
  row.add( get( "ASPBENI" ), f.cid2index(FR_ASPBENI ));
}

