Files correlati : co0.exe co1.exe Ricompilazione Demo : [ ] Commento : Aggiunto fornitore / cliente sulla maschera di movimentazione per Dassi Documentazione lemco e lembi Zucchetti Corretta esplosione dettagliata Nel calcolo dettagliato dell'ordinato fornitori vengo no considerati tutti gli esercizi e non solo gli ultimi 2. Dalla versione 3.2 git-svn-id: svn://10.65.10.50/trunk@20585 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			476 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			476 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <browfile.h>
 | 
						|
#include <defmask.h>
 | 
						|
#include <execp.h>
 | 
						|
#include <mailbox.h>
 | 
						|
#include <printer.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <tabutil.h>
 | 
						|
#include <viswin.h>
 | 
						|
 | 
						|
#include "db2.h"
 | 
						|
#include "dblib.h"
 | 
						|
#include "../mg/mglib.h"
 | 
						|
 | 
						|
#include "db2400a.h"
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TValorizzazione_mask
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TValorizzazione_mask : public TAutomask
 | 
						|
{
 | 
						|
  TAssoc_array _valori;
 | 
						|
  TAssoc_array _risultati;
 | 
						|
 | 
						|
  TDistinta_tree _tree;
 | 
						|
  valtype _tipoval;
 | 
						|
  TString4 _annoes,_catven, _codlist ;
 | 
						|
  TString8 _codmag;
 | 
						|
	TDate _data;
 | 
						|
	bool _dettagliata;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& f, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
  real valore(const TCodice_articolo& dis, const char* liv = NULL);
 | 
						|
  void elabora();
 | 
						|
  void salva();
 | 
						|
 | 
						|
  TValorizzazione_mask();
 | 
						|
  virtual ~TValorizzazione_mask() { }
 | 
						|
};
 | 
						|
 | 
						|
real TValorizzazione_mask::valore(const TCodice_articolo& dis, const char* liv)
 | 
						|
{
 | 
						|
  real total;
 | 
						|
 | 
						|
  if (dis.not_empty())
 | 
						|
  {
 | 
						|
    TString80 cod = dis;
 | 
						|
		bool explode = true;
 | 
						|
 | 
						|
    if (liv && *liv)
 | 
						|
      cod << ',' << liv;
 | 
						|
 | 
						|
    real* val = (real*)_valori.objptr(cod);
 | 
						|
    if (val == NULL)
 | 
						|
    { 
 | 
						|
      _tree.set_global("_IMPIANTO", get(F_IMPIANTO));
 | 
						|
      _tree.set_global("_LINEA", get(F_LINEA));
 | 
						|
      TString8 codmagdep; 
 | 
						|
      add_magcode(codmagdep, get(F_CODMAG));
 | 
						|
      add_depcode(codmagdep, get(F_CODDEP));
 | 
						|
      _tree.set_global("_MAGDEP", codmagdep); 
 | 
						|
      const char tipo = _tree.get_type(dis);
 | 
						|
			valtype tipoval = _tipoval;
 | 
						|
 | 
						|
			if (_dettagliata && tipo == 'A')
 | 
						|
			{
 | 
						|
				const TRectype & rec = cache().get(LF_ANAMAG, dis);
 | 
						|
 | 
						|
				const valtype art_tipo = (valtype)rec.get_int(ANAMAG_VALDIST);
 | 
						|
 | 
						|
				if (art_tipo > no_val)
 | 
						|
				{
 | 
						|
					const TDate inizio_val = rec.get_date(ANAMAG_DATAVDIST);
 | 
						|
 | 
						|
					explode = _data < inizio_val;
 | 
						|
					if (!explode)
 | 
						|
						tipoval = art_tipo;
 | 
						|
				}
 | 
						|
			}
 | 
						|
	
 | 
						|
      if (explode &&_tree.set_root(dis))
 | 
						|
      {
 | 
						|
        TArray boom;
 | 
						|
        // Esplosione ai materiali di base 
 | 
						|
        // raggruppati alla unita' di misura di riferimento
 | 
						|
        _tree.explode(boom, false, RAGGR_EXP_BASE, 1);  
 | 
						|
        for (int r = boom.last(); r >= 0; r--)
 | 
						|
        {
 | 
						|
          const TRiga_esplosione& esp = (const TRiga_esplosione&)boom[r];
 | 
						|
 | 
						|
          const real value = esp.val() * valore(esp.articolo(), esp.giacenza());
 | 
						|
          total += value;
 | 
						|
        }
 | 
						|
        if (!total.is_zero())
 | 
						|
          _risultati.add(cod, total);
 | 
						|
      }
 | 
						|
      else
 | 
						|
      {
 | 
						|
        switch (tipo)
 | 
						|
        {
 | 
						|
        case 'A':
 | 
						|
          {
 | 
						|
            const TArticolo_giacenza art(dis);
 | 
						|
            switch (tipoval) 
 | 
						|
            {
 | 
						|
							case last_cost: total = art.ultimo_costo(_annoes); break;
 | 
						|
							case last2cost: total = art.media_costi(_annoes); break;
 | 
						|
							case std_cost:  total = art.costo_standard(_annoes); break;
 | 
						|
							case average_cost: total = art.costo_medio(_annoes, _codmag, liv); break;
 | 
						|
							case pond_cost: total = art.costo_mediopond(_annoes, _codmag, liv); break;
 | 
						|
							case LIFO_annuale: total = art.LIFO_annuale(_annoes, _codmag, liv); break;
 | 
						|
							case FIFO_annuale: total = art.FIFO_annuale(_annoes, _codmag, liv); break;
 | 
						|
							case LIFO_storico: total = art.LIFO(_annoes, _codmag, liv); break;
 | 
						|
							case FIFO_storico: total = art.FIFO(_annoes, _codmag, liv); break;
 | 
						|
							case prezzo_listino:  total = art.prezzo_listino(_annoes, _catven, _codlist); break;
 | 
						|
            default: NFCHECK("Tipo valorizzazione errato: %d", _tipoval);
 | 
						|
            }
 | 
						|
          }
 | 
						|
          break;
 | 
						|
        case 'L':
 | 
						|
          {                                 
 | 
						|
            const TLavorazione lav(dis);
 | 
						|
            total = lav.prezzo();
 | 
						|
          }
 | 
						|
          break;
 | 
						|
        default :
 | 
						|
          {
 | 
						|
            const real prezzo(cache().get(LF_DIST, dis, "PREZZO"));
 | 
						|
            total = prezzo;
 | 
						|
          }
 | 
						|
          break;
 | 
						|
        }
 | 
						|
        _valori.add(cod, total);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    else
 | 
						|
      total = *val;
 | 
						|
  }  
 | 
						|
 | 
						|
  return total;
 | 
						|
}
 | 
						|
 | 
						|
void TValorizzazione_mask::elabora()
 | 
						|
{
 | 
						|
  TRectype rec_from(LF_DIST), rec_to(LF_DIST);
 | 
						|
  rec_from.put("CODDIST", get(F_DIST_FROM));
 | 
						|
  rec_to.put  ("CODDIST", get(F_DIST_TO));
 | 
						|
  
 | 
						|
  _annoes = get(F_ANNOES);
 | 
						|
  _tipoval = (valtype) get_int(F_TIPO);
 | 
						|
  _catven = get(F_CATVEN_LIST);
 | 
						|
  _codlist = get(F_CODLIST);
 | 
						|
	_data = get_date(F_DATA);
 | 
						|
	_dettagliata = get_bool(F_DETTAGLIATA);
 | 
						|
 | 
						|
  
 | 
						|
  TRelation rel(LF_DIST);
 | 
						|
  TCursor cur(&rel);
 | 
						|
  cur.setregion(rec_from, rec_to, 0x2);
 | 
						|
 | 
						|
  const long items = cur.items();
 | 
						|
  TProgind pi(items, TR("Valorizzazione in corso..."), TRUE, TRUE);
 | 
						|
 | 
						|
  TBrowsefile_field& bf = (TBrowsefile_field&)field(F_PREVIEW);
 | 
						|
  TViswin& vw = bf.vis_win();
 | 
						|
  
 | 
						|
  vw.destroy_lines();
 | 
						|
  _valori.destroy();
 | 
						|
  _risultati.destroy();
 | 
						|
 | 
						|
  TString line, num;
 | 
						|
  const int sorc = get_int(F_TIPO);
 | 
						|
  const int dest = get_int(F_VALORIZZA);
 | 
						|
 
 | 
						|
//          123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 | 
						|
  line = FR("@b                           Valorizzazione al ");
 | 
						|
  switch (sorc)
 | 
						|
  {
 | 
						|
    case 1: line << TR("Media Costi"); break;
 | 
						|
    case 2: line << TR("Prezzo Listino"); break;
 | 
						|
    case 3: line << TR("Costo Standard"); break;
 | 
						|
    case 4: line << TR("Costo Medio"); break;
 | 
						|
    case 5: line << TR("Costo Medio Ponderato"); break;
 | 
						|
    case 6: line << TR("LIFO Annuale"); break;
 | 
						|
    case 7: line << TR("FIFO Annuale"); break;
 | 
						|
    case 8: line << TR("LIFO"); break;
 | 
						|
    case 9: line << TR("FIFO"); break;
 | 
						|
    default: line << TR("Ultimo Costo"); break;
 | 
						|
  }
 | 
						|
  line << TR(" - ricalcola ");
 | 
						|
  switch (dest) 
 | 
						|
  {
 | 
						|
    case 1: line << TR("l' Ultimo Costo"); break;
 | 
						|
    case 2: line << TR("il Prezzo di Listino"); break;
 | 
						|
    default: line << TR("il Costo Standard"); break;
 | 
						|
  }       
 | 
						|
  line << "     " << get(F_DATA);
 | 
						|
  bf.add_line(line);
 | 
						|
  line = FR("@bCodice distinta      Descrizione                                                Attuale      Precedente");
 | 
						|
  bf.add_line(line);
 | 
						|
  
 | 
						|
  TString80 descr;
 | 
						|
 | 
						|
  cur.freeze(TRUE);
 | 
						|
  for (cur = 0; cur.pos() < items; ++cur)
 | 
						|
  {
 | 
						|
    pi.addstatus(1);
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
 | 
						|
    const TCodice_articolo art = cur.curr().get("CODDIST");
 | 
						|
    const char tipo = _tree.get_type(art);
 | 
						|
    if (tipo != 'A')
 | 
						|
      continue;
 | 
						|
    
 | 
						|
    const TPrice value(valore(art));
 | 
						|
    line.cut(0) << "$[r,w]" << art << "$[n,w]";
 | 
						|
    
 | 
						|
    line.left_just(33);
 | 
						|
    
 | 
						|
    TArticolo_giacenza articolo(art);              
 | 
						|
    
 | 
						|
    descr = articolo.get(ANAMAG_DESCR);
 | 
						|
    descr.left_just(50);
 | 
						|
    line << descr;
 | 
						|
    
 | 
						|
    if (dest == 2 && sorc != 2)
 | 
						|
    {
 | 
						|
      const real perc = articolo.get_real(ANAMAG_PERCRIC);
 | 
						|
      const TPrice pric(value.get_num() * (100.0 + perc) / 100.0); 
 | 
						|
      num = pric.string(TRUE);
 | 
						|
    } 
 | 
						|
    else
 | 
						|
      num = value.string(TRUE);
 | 
						|
    num.right_just(16);
 | 
						|
    line << num;
 | 
						|
    
 | 
						|
    TPrice total;                
 | 
						|
    
 | 
						|
    switch (dest) 
 | 
						|
    {
 | 
						|
      case  1: total = articolo.ultimo_costo(_annoes); break;
 | 
						|
      case  2: total = articolo.prezzo_listino(_annoes, _catven, _codlist); break;
 | 
						|
      default: total = articolo.costo_standard(_annoes); break;
 | 
						|
    }
 | 
						|
    num = total.string(TRUE);
 | 
						|
    num.right_just(16);
 | 
						|
    line << num;
 | 
						|
 | 
						|
    bf.add_line(line);
 | 
						|
  }
 | 
						|
  enable(DLG_SAVEREC);
 | 
						|
  vw.goto_top();
 | 
						|
} 
 | 
						|
 | 
						|
void TValorizzazione_mask::salva()
 | 
						|
{
 | 
						|
  const TDate oggi = get_date(F_DATA);
 | 
						|
  const int sorc = get_int(F_TIPO);
 | 
						|
  const int dest = get_int(F_VALORIZZA);
 | 
						|
 | 
						|
  TProgind pi(_risultati.items(), TR("Registrazione in corso..."), TRUE, TRUE);
 | 
						|
 | 
						|
  TLocalisamfile dis(LF_DIST);
 | 
						|
  TTable lav("LAV");
 | 
						|
 | 
						|
  FOR_EACH_ASSOC_OBJECT(_risultati, obj, key, item)
 | 
						|
  {
 | 
						|
    pi.addstatus(1);
 | 
						|
    if (pi.iscancelled())
 | 
						|
      break;
 | 
						|
 | 
						|
    const real& val = (const real&)*item;
 | 
						|
    if (!val.is_zero())
 | 
						|
    {
 | 
						|
      const TPrice prezzo(val);
 | 
						|
      const real& price = prezzo.get_num(); // val arrotondato ai decimali dei prezzi
 | 
						|
      switch(_tree.get_type(key))
 | 
						|
      {
 | 
						|
      case 'A':
 | 
						|
        {
 | 
						|
          TArticolo_giacenza art(key);
 | 
						|
          switch (dest)
 | 
						|
          {
 | 
						|
          case 1: 
 | 
						|
            art.put_ultimo_costo(price, oggi); 
 | 
						|
            break;
 | 
						|
          case 2: 
 | 
						|
            if (sorc != 2)  // Tengo conto del ricarico
 | 
						|
            {
 | 
						|
              const real perc = art.get_real(ANAMAG_PERCRIC);
 | 
						|
              const TPrice pric(price * (100.0 + perc) / 100.0);
 | 
						|
              art.set_prezzo_vendita(pric.get_num()); 
 | 
						|
            }
 | 
						|
            else
 | 
						|
              art.set_prezzo_vendita(price); 
 | 
						|
            break;
 | 
						|
          default: 
 | 
						|
            art.put_costo_standard(price); 
 | 
						|
            break;
 | 
						|
          }
 | 
						|
          art.rewrite();
 | 
						|
        }
 | 
						|
        break;
 | 
						|
      case 'L':
 | 
						|
        lav.put("CODTAB", key);
 | 
						|
        if (lav.read(_isequal, _lock) == NOERR)
 | 
						|
        {                
 | 
						|
          lav.put("R10", price);  // Was R0
 | 
						|
          lav.rewrite();
 | 
						|
        }
 | 
						|
        break;
 | 
						|
      case 'G':
 | 
						|
      case 'V':
 | 
						|
        dis.put("CODDIST", key);
 | 
						|
        if (dis.read(_isequal, _lock) == NOERR)
 | 
						|
        {
 | 
						|
          dis.put("PREZZO", price);
 | 
						|
          dis.rewrite();
 | 
						|
        }
 | 
						|
        break;
 | 
						|
      default :break;
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  _valori.destroy();
 | 
						|
  _risultati.destroy();
 | 
						|
  disable(DLG_SAVEREC);
 | 
						|
}
 | 
						|
 | 
						|
bool TValorizzazione_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (f.dlg())
 | 
						|
  {
 | 
						|
  case DLG_ELABORA:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      elabora();
 | 
						|
      enable(-4);
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case DLG_SAVEREC:
 | 
						|
    if (e == fe_button)
 | 
						|
      salva();
 | 
						|
    break;
 | 
						|
  case DLG_PRINT:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      TBrowsefile_field& b = (TBrowsefile_field&)field(F_PREVIEW);
 | 
						|
      TViswin& w = b.vis_win();
 | 
						|
      TTextfile& f = w.text();
 | 
						|
      const long rows = f.lines();
 | 
						|
      if (rows > 2)
 | 
						|
      {                   
 | 
						|
        TPrinter& p = printer();
 | 
						|
        TPrintrow row; 
 | 
						|
        
 | 
						|
        TString line = f.line_formatted(0);      // Legge la prima riga dal line
 | 
						|
        row.put(line);   
 | 
						|
        p.setheaderline(0, row);  // La imposta come testata
 | 
						|
        line = f.line_formatted(1);      // Legge la prima riga dal line
 | 
						|
        row.reset();
 | 
						|
        row.put(line);   
 | 
						|
        p.setheaderline(1, row);  // La imposta come testata
 | 
						|
        
 | 
						|
        p.headerlen(3);           // Imposta altezza testata
 | 
						|
      
 | 
						|
        const TPrtype old_prtype = p.printtype();
 | 
						|
        p.set_printtype(winprinter);  // Forza la stampa su carta
 | 
						|
        p.open();
 | 
						|
        for (long l = 2; l < rows; l++) 
 | 
						|
        {
 | 
						|
          line = f.line_formatted(l);
 | 
						|
          row.reset();
 | 
						|
          row.put(line, 0);
 | 
						|
          p.print(row);
 | 
						|
        }
 | 
						|
        p.close();
 | 
						|
        p.set_printtype(old_prtype);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    break;    
 | 
						|
  case DLG_QUIT:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      if (_risultati.items() > 0)
 | 
						|
        return yesno_box(TR("I risultati dell'ultima elaborazione\n"
 | 
						|
                         "non sono stati registrati:\n"
 | 
						|
                         "Si desidera uscire ugualmente?"));
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
static const char* link_handler(TMask&, int id, const char* str, bool)
 | 
						|
{
 | 
						|
  const char* app = NULL; 
 | 
						|
  switch(id)
 | 
						|
  {
 | 
						|
  case  0: app = "ve2 -3"; break;
 | 
						|
  case  1: app = "ba3 -0 LAV"; break;
 | 
						|
  case  2: app = "db0 -4"; break;
 | 
						|
  default: break;
 | 
						|
  }
 | 
						|
 | 
						|
  if (app)
 | 
						|
  {
 | 
						|
    TString ss = "1|"; ss << str;
 | 
						|
    TMessage fs(app, MSG_LN, ss);
 | 
						|
    fs.send();
 | 
						|
 | 
						|
    TExternal_app prg(app);
 | 
						|
    prg.run();
 | 
						|
  }
 | 
						|
  return "";
 | 
						|
}
 | 
						|
 | 
						|
TValorizzazione_mask::TValorizzazione_mask() 
 | 
						|
                    : TAutomask("db2400a") 
 | 
						|
{ 
 | 
						|
  TBrowsefile_field& bf = (TBrowsefile_field&)field(F_PREVIEW);
 | 
						|
  bf.enable_link("Articolo ", 'r');
 | 
						|
  bf.enable_link("Lavorazione ", 'v');
 | 
						|
  bf.enable_link("Distinta ", 'b');
 | 
						|
  bf.set_link_handler(link_handler);
 | 
						|
 | 
						|
  disable(DLG_SAVEREC);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TValorizzazione
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TValorizzazione : public TSkeleton_application
 | 
						|
{
 | 
						|
protected:  
 | 
						|
  virtual bool create();
 | 
						|
public:
 | 
						|
  virtual void main_loop();
 | 
						|
};
 | 
						|
 | 
						|
bool TValorizzazione::create()
 | 
						|
{
 | 
						|
  open_files(LF_MAG,LF_STOMAG,0);
 | 
						|
  return TSkeleton_application::create();
 | 
						|
}
 | 
						|
 | 
						|
void TValorizzazione::main_loop()
 | 
						|
{
 | 
						|
  TValorizzazione_mask m;
 | 
						|
  TConfig conf(CONFIG_DITTA, "mg");
 | 
						|
  const bool listini = conf.get_bool("GES", "ve", 1);
 | 
						|
  m.enable(-G_LISTINO, listini);
 | 
						|
  m.enable(F_CATVEN_LIST, listini && conf.get_bool("GESLISCV", "ve"));
 | 
						|
  
 | 
						|
  m.run();
 | 
						|
}
 | 
						|
 | 
						|
int db2400(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TValorizzazione app;
 | 
						|
  app.run(argc, argv, TR("Valorizzazione"));
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 |