Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.1 patch 766 git-svn-id: svn://10.65.10.50/trunk@14628 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			875 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			875 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "mglib.h"
 | 
						||
 | 
						||
#include "../cg/cglib01.h"
 | 
						||
#include "../db/dblib.h"
 | 
						||
#include "../ve/veconf.h"
 | 
						||
 | 
						||
#include <relapp.h>                                                                           
 | 
						||
#include <msksheet.h>
 | 
						||
 | 
						||
#include "mg1100.h"
 | 
						||
#include <cfven.h>
 | 
						||
 | 
						||
// maschera dell'applicazione "Gestione interattiva movimenti di magazzino"
 | 
						||
//
 | 
						||
class TMask_movmag : public TMask 
 | 
						||
{
 | 
						||
  static TArticolo_giacenza* _curr_art;
 | 
						||
  
 | 
						||
  TEsercizi_contabili _esercizi;  
 | 
						||
  TMov_mag * _mov_mag;
 | 
						||
  TCodice_articolo _price_codart;
 | 
						||
  real price_quant;
 | 
						||
  bool price_proposed;
 | 
						||
  real proposed_price(const char * codart, real quant,const char * causrig);
 | 
						||
 | 
						||
  // aggiorna la riga di magazzino aggiungendo righe automatiche o esplosioni
 | 
						||
  bool update_rigamov(int r, const char * old_codcaus, const char * old_codart, const real & old_quant);
 | 
						||
  bool add_autorows(int r, const char * old_codcaus, const char * old_codart, const real & old_quant);
 | 
						||
  bool add_explrows(int r);
 | 
						||
  TMagazzini _magazzini;   
 | 
						||
  
 | 
						||
  bool qta_inventory(real & qta);
 | 
						||
 | 
						||
  static bool notify_righe(TSheet_field & fld_righe, int item, KEY k); // notify delle righe di sheet
 | 
						||
  static bool handle_righe(TMask_field &f, KEY k); // handler delle righe
 | 
						||
  static bool handle_righeprezzo1(TMask_field &f, KEY k); // handler del prezzo delle righe
 | 
						||
  static bool handle_righeprezzo2(TMask_field &f, KEY k); // handler del prezzo delle righe
 | 
						||
  static bool handle_codcaus(TMask_field &fld, KEY k); // handler della causale
 | 
						||
  static bool handle_datacomp(TMask_field &, KEY k); // handler del numero di registrazione
 | 
						||
  static bool handle_checksosp(TMask_field &fld, KEY k); // handler 
 | 
						||
  static bool handle_codarticolo(TMask_field &fld, KEY k); // handler 
 | 
						||
  static bool handle_causrig(TMask_field &fld, KEY k); // handler 
 | 
						||
  static bool handle_giacattuale(TMask_field &fld, KEY k); // handler della giacenza attuale
 | 
						||
  static bool codgrp_handler(TMask_field &fld, KEY k); // handler del codice gruppo
 | 
						||
  static void sheetrighe_put(TSheet_field &fld_righe, int item);
 | 
						||
  static void sheetrighe_get(TSheet_field &fld_righe, int item);
 | 
						||
public:
 | 
						||
  TArticolo_giacenza& curr_art();
 | 
						||
	void update_tot();
 | 
						||
  const TMagazzini& magazzini() const { return _magazzini; } 
 | 
						||
  
 | 
						||
  TMask_movmag(TMov_mag* m_m);
 | 
						||
  virtual ~TMask_movmag();
 | 
						||
};
 | 
						||
 | 
						||
TArticolo_giacenza* TMask_movmag::_curr_art = NULL;
 | 
						||
 | 
						||
// HANDLER DEL CODICE LIVELLO anagrafica
 | 
						||
bool TMask_movmag::codgrp_handler(TMask_field& f, KEY k)
 | 
						||
{        
 | 
						||
  if ((k == K_TAB && f.focusdirty() ||k == K_ENTER ) && !f.empty())
 | 
						||
  {                  
 | 
						||
    if (!livelli_giacenza().enabled())
 | 
						||
    {
 | 
						||
      f.error_box(TR("Livelli del codice non abilitati"));
 | 
						||
      return FALSE;  
 | 
						||
    }
 | 
						||
    const int levnum=1+f.dlg()-F_LIV1;
 | 
						||
    return livelli_giacenza().autoinsert(levnum,f);
 | 
						||
  }
 | 
						||
  return TRUE;  
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
// costruttore della maschera anagrafica di magazzino
 | 
						||
//TMask_movmag::TMask_movmag() : 
 | 
						||
TMask_movmag::TMask_movmag(TMov_mag * m_m) 
 | 
						||
  : TMask("mg1100")
 | 
						||
{
 | 
						||
  _mov_mag = m_m;
 | 
						||
  // setta handler e notify
 | 
						||
  TSheet_field& ss = sfield(F_RIGHE);
 | 
						||
  TMask& sm = ss.sheet_mask();
 | 
						||
 | 
						||
  set_handler(F_DATACOMP, handle_datacomp);
 | 
						||
  set_handler(F_CODCAUS, handle_codcaus);
 | 
						||
  sm.field(F_QUANT).set_handler(handle_righeprezzo1);
 | 
						||
  sm.field(F_CAUSRIG).set_handler(handle_causrig);
 | 
						||
  sm.field(F_CODART).set_handler(handle_codarticolo);
 | 
						||
  sm.field(F_GIAC).set_handler(handle_giacattuale);
 | 
						||
  ss.set_notify(notify_righe);
 | 
						||
  ss.set_handler(handle_righe);
 | 
						||
  ss.set_userget(sheetrighe_get);
 | 
						||
  ss.set_userput(sheetrighe_put);
 | 
						||
  ss.set_lines_record(m_m->body());
 | 
						||
  // setta i campi della maschera
 | 
						||
  // per la pagina giacenze
 | 
						||
  
 | 
						||
 | 
						||
  // setta le colonne in base all'abilitazione dei livelli di giacenza
 | 
						||
  livelli_giacenza().set_sheet_columns(ss, F_LIV1);
 | 
						||
 | 
						||
  // abilita i controlli
 | 
						||
  for (int l=0; l<4; l++) if (livelli_giacenza().autoinsert(1+l))
 | 
						||
  {
 | 
						||
    sm.efield(F_LIV1+l).check_type(CHECK_SEARCH);
 | 
						||
    sm.field(F_LIV1+l).set_handler(codgrp_handler);
 | 
						||
  }
 | 
						||
  TConfig prassid(CONFIG_DITTA, "ve"); // apre il file di configurazione della ditta corrente
 | 
						||
  if (prassid.get_bool("GES", NULL, A_LISTINI))
 | 
						||
    field(F_CATVEN).show(prassid.get_bool("GESLISCV"));
 | 
						||
  else 
 | 
						||
    field(F_CATVEN).hide();  
 | 
						||
 | 
						||
  const bool gmm = magazzini().gestmultimag();
 | 
						||
  sm.field(F_DESMAG).enable(gmm);
 | 
						||
  ss.enable_column(ss.cid2index(F_CODMAG),gmm);
 | 
						||
 | 
						||
  const bool gd = magazzini().gestdep();
 | 
						||
  sm.field(F_DESDEP).enable(gd);
 | 
						||
  ss.enable_column(ss.cid2index(F_CODDEP),gd);
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
TMask_movmag::~TMask_movmag()
 | 
						||
{
 | 
						||
}
 | 
						||
 | 
						||
// item varies from 1 to items()
 | 
						||
void TMask_movmag::sheetrighe_get(TSheet_field &fld_righe, int item)
 | 
						||
{
 | 
						||
  // prende il record della riga corrente dal record array
 | 
						||
  TRectype &rec= fld_righe.record()->row(item, TRUE);
 | 
						||
  TToken_string &row= fld_righe.row(item-1);
 | 
						||
  // codici di livello
 | 
						||
  row.add( livelli_giacenza().unpack_grpcode(rec.get("LIVGIAC") ,1),fld_righe.cid2index(F_LIV1) );
 | 
						||
  row.add( livelli_giacenza().unpack_grpcode(rec.get("LIVGIAC") ,2),fld_righe.cid2index(F_LIV2) );
 | 
						||
  row.add( livelli_giacenza().unpack_grpcode(rec.get("LIVGIAC") ,3),fld_righe.cid2index(F_LIV3) );
 | 
						||
  row.add( livelli_giacenza().unpack_grpcode(rec.get("LIVGIAC") ,4),fld_righe.cid2index(F_LIV4) );
 | 
						||
}
 | 
						||
 | 
						||
// item varies from 1 to items()
 | 
						||
void TMask_movmag::sheetrighe_put(TSheet_field &fld_righe, int item)
 | 
						||
{
 | 
						||
  TToken_string &row= fld_righe.row(item-1);
 | 
						||
          
 | 
						||
    TRectype &recrighe= fld_righe.record()->row(item, TRUE);
 | 
						||
    // codici livello
 | 
						||
    if (livelli_giacenza().enabled()) 
 | 
						||
    {
 | 
						||
      TString16 packedcode;
 | 
						||
      livelli_giacenza().pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV1)),1);
 | 
						||
      livelli_giacenza().pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV2)),2);
 | 
						||
      livelli_giacenza().pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV3)),3);
 | 
						||
      livelli_giacenza().pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV4)),4);
 | 
						||
      recrighe.put("LIVGIAC", packedcode);
 | 
						||
    }     
 | 
						||
}  
 | 
						||
  
 | 
						||
bool TMask_movmag::handle_righe(TMask_field &f, KEY k)
 | 
						||
{
 | 
						||
  if (k == K_ENTER)  
 | 
						||
  {
 | 
						||
    TSheet_field& ss = (TSheet_field&)f;
 | 
						||
 | 
						||
    const int idx_codart = ss.cid2index(F_CODART);
 | 
						||
    for (int i = ss.items()-1; i >= 0; i--)
 | 
						||
    {
 | 
						||
      if (*ss.cell(i,idx_codart) <= ' ') // Riga senza codice articolo = vuota
 | 
						||
        ss.destroy(i);
 | 
						||
    }
 | 
						||
    
 | 
						||
    const int idx_codmag = ss.cid2index(F_CODMAG);
 | 
						||
    if (ss.column_enabled(idx_codmag))
 | 
						||
    {
 | 
						||
      for (int i = 0; i < ss.items(); i++)
 | 
						||
      {
 | 
						||
        if (*ss.cell(i,idx_codmag) <= ' ')
 | 
						||
          return f.error_box(FR("Nella riga %d manca l'indicazione del magazzino"),i+1);
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
void TMask_movmag::update_tot()
 | 
						||
{
 | 
						||
	TSheet_field& ss = sfield(F_RIGHE);
 | 
						||
  const int idx_val = ss.cid2index(F_VALORE); // Posizione del valore
 | 
						||
	real valore, tot;
 | 
						||
 | 
						||
	FOR_EACH_SHEET_ROW(ss, i, row)
 | 
						||
	{
 | 
						||
		row->get(idx_val, valore);
 | 
						||
		tot += valore;
 | 
						||
	}
 | 
						||
	set(F_VALORE_TOT, tot);
 | 
						||
}
 | 
						||
 | 
						||
bool TMask_movmag::notify_righe(TSheet_field& ss, int r, KEY key)
 | 
						||
{
 | 
						||
  static TString8 old_codcaus;
 | 
						||
  static TCodice_articolo old_codart;
 | 
						||
  static real old_quant = UNO;
 | 
						||
  static bool selecting = false;
 | 
						||
 | 
						||
  TMask_movmag& m= (TMask_movmag&)ss.mask();
 | 
						||
  if ( key == K_DEL ) // Cancellazione 
 | 
						||
  {
 | 
						||
    if (*ss.cell(r,ss.cid2index( F_AUTOMATICA))==riga_automatica)
 | 
						||
      return FALSE; // can't remove auto lines directly
 | 
						||
    while (r < ss.items()-1 && *ss.cell(r+1,ss.cid2index( F_AUTOMATICA))==riga_automatica)
 | 
						||
    {
 | 
						||
      // autoremove automatic lines along with the original one
 | 
						||
      ss.destroy(r+1);
 | 
						||
    }
 | 
						||
 | 
						||
  } else 
 | 
						||
  if ( key == K_CTRL + K_DEL ) // Cancellazione 
 | 
						||
	{
 | 
						||
		m.update_tot();
 | 
						||
	} else if (key == K_INS) { // Inserimento              
 | 
						||
    if (r < ss.items() && *ss.cell(r,ss.cid2index( F_AUTOMATICA))==riga_automatica)
 | 
						||
      return FALSE; // cannot insert between a row and its generated one
 | 
						||
 | 
						||
  } else 
 | 
						||
  if (key == K_CTRL + K_INS) { // Inserimento accordato
 | 
						||
    // Magazzino e Deposito di default: controlla prima quelli della causale,
 | 
						||
    // quindi se non sono settati, prende quelli di default
 | 
						||
    TToken_string key;                       
 | 
						||
    key.add(m.get(F_TIPOCF));
 | 
						||
    key.add(m.get(F_CODCF));
 | 
						||
 | 
						||
    TString4 stdmag = cache().get(LF_CFVEN, key, CFV_CODMAG);
 | 
						||
    TString4 stddep;
 | 
						||
 | 
						||
		if (stdmag.full())
 | 
						||
			stddep = cache().get(LF_CFVEN, key, CFV_CODDEP);
 | 
						||
		else
 | 
						||
		{
 | 
						||
			const TCausale_magazzino cau(m.get(F_CODCAUS));
 | 
						||
		
 | 
						||
			if (cau.default_magdep().full())
 | 
						||
			{
 | 
						||
				stdmag = cau.default_mag();
 | 
						||
				stddep = cau.default_dep();
 | 
						||
			}
 | 
						||
			else
 | 
						||
			{
 | 
						||
				stdmag  = m.magazzini().standardmag();
 | 
						||
				stddep  = m.magazzini().standarddep();
 | 
						||
			}
 | 
						||
		}
 | 
						||
 | 
						||
    if (stdmag.full())
 | 
						||
    {
 | 
						||
      TToken_string& row = ss.row(r);
 | 
						||
      row.add(stdmag, ss.cid2index(F_CODMAG));
 | 
						||
      row.add(stddep, ss.cid2index(F_CODDEP));
 | 
						||
    }
 | 
						||
    ss.select(r);
 | 
						||
 | 
						||
  } else 
 | 
						||
  if (key == K_SPACE) 
 | 
						||
  {
 | 
						||
    old_codcaus = ss.sheet_mask().get(F_CAUSRIG);
 | 
						||
    if (old_codcaus.blank())
 | 
						||
      old_codcaus = ss.mask().get(F_CODCAUS);
 | 
						||
    if (old_quant != ss.sheet_mask().get_real(F_QUANT))
 | 
						||
    {
 | 
						||
      old_quant = ss.sheet_mask().get_real(F_QUANT);
 | 
						||
      m.qta_inventory(old_quant);
 | 
						||
    }
 | 
						||
    old_codart = ss.sheet_mask().get(F_CODART);
 | 
						||
 | 
						||
  } else 
 | 
						||
  if (key == K_ENTER)  
 | 
						||
  {
 | 
						||
    if (m.get_bool(F_INVENTORYMODE))
 | 
						||
    {
 | 
						||
      real diff = ss.sheet_mask().get_real(F_QUANT) ;
 | 
						||
      m.qta_inventory(diff);
 | 
						||
      if (diff != old_quant)
 | 
						||
      {
 | 
						||
        ss.sheet_mask().set(F_QUANT, diff);
 | 
						||
        ss.row(r).add(diff.string(), ss.cid2index(F_QUANT));
 | 
						||
      }
 | 
						||
    }
 | 
						||
    if (m.update_rigamov(r,old_codcaus,old_codart,old_quant))
 | 
						||
       ss.select(r);
 | 
						||
 | 
						||
		m.update_tot();
 | 
						||
  } else 
 | 
						||
  if (key == K_TAB && !selecting)  
 | 
						||
  {
 | 
						||
    selecting = true;
 | 
						||
    ss.select(r, 1);
 | 
						||
    selecting = false;
 | 
						||
  }
 | 
						||
  return true;
 | 
						||
}
 | 
						||
 | 
						||
bool TMask_movmag::qta_inventory(real & qta)
 | 
						||
{
 | 
						||
  if (get_bool(F_INVENTORYMODE))
 | 
						||
  {
 | 
						||
    const TMask & sm = sfield(F_RIGHE).sheet_mask();
 | 
						||
    qta -= sm.get_real(F_GIAC);
 | 
						||
 | 
						||
    TString8 codcau(sm.get(F_CAUSRIG));
 | 
						||
    if (codcau.blank())
 | 
						||
      codcau = get(F_CODCAUS);
 | 
						||
    if (codcau.blank())
 | 
						||
      return error_box(TR("La causale non e' indicata"));
 | 
						||
 | 
						||
    const TCausale_magazzino cau(codcau);
 | 
						||
    switch (cau.sgn(s_giac))
 | 
						||
    {
 | 
						||
      case  1: break;
 | 
						||
      case -1: qta = - qta; break;
 | 
						||
      default: message_box(TR("La causale indicata non movimenta la giacenza"));
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
// proposta soft: solo se il prezzo <20> non nullo (gi<67> impostato)
 | 
						||
bool TMask_movmag::handle_righeprezzo1(TMask_field &f, KEY k)
 | 
						||
{      
 | 
						||
  if (f.mask().get(F_PREZZO).blank())
 | 
						||
    return handle_righeprezzo2(f, k);
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
// proposta hard: propone il prezzo in ogni caso
 | 
						||
bool TMask_movmag::handle_righeprezzo2(TMask_field &f, KEY k)
 | 
						||
{
 | 
						||
  if (k == K_TAB)
 | 
						||
  {                 
 | 
						||
    TMask& m = f.mask();
 | 
						||
    TMask_movmag& mmm = (TMask_movmag&)m.get_sheet()->mask();
 | 
						||
    const TString& codart = m.get(F_CODART);
 | 
						||
    if (f.focusdirty())
 | 
						||
    {
 | 
						||
      //  propone il prezzo in base alla causale
 | 
						||
      if (codart.full() && codart != mmm._price_codart)
 | 
						||
      {
 | 
						||
        const real prz = mmm.proposed_price(codart, m.get_real(F_QUANT), m.get(F_CAUSRIG));
 | 
						||
        m.set(F_PREZZO, prz);
 | 
						||
      }
 | 
						||
    }
 | 
						||
    mmm._price_codart = codart;
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
TArticolo_giacenza& TMask_movmag::curr_art()
 | 
						||
{
 | 
						||
  if (_curr_art == NULL)
 | 
						||
    _curr_art = new TArticolo_giacenza;
 | 
						||
  return *_curr_art;  
 | 
						||
}
 | 
						||
 | 
						||
bool TMask_movmag::handle_checksosp(TMask_field &f, KEY k)
 | 
						||
{
 | 
						||
  if (k==K_TAB && f.focusdirty())
 | 
						||
  {
 | 
						||
    TMask_movmag& mov_mask = (TMask_movmag &)f.mask().get_sheet()->mask();
 | 
						||
    TMask & row_mask = f.mask();
 | 
						||
 | 
						||
    mov_mask.curr_art().read(row_mask.get(F_CODART));
 | 
						||
        
 | 
						||
    TString8 caus(row_mask.get(F_CAUSRIG));
 | 
						||
    if (caus.empty())
 | 
						||
      caus = mov_mask.get(F_CODCAUS);
 | 
						||
    const TCausale_magazzino c(caus);   
 | 
						||
    if (!c.movimenta_sospesi() && mov_mask.curr_art().get_bool("SOSPESO")) 
 | 
						||
      return error_box(FR("Articolo %s sospeso, quindi non movimentabile"), (const char *)f.get());
 | 
						||
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TMask_movmag::handle_codarticolo(TMask_field &f, KEY k)
 | 
						||
{
 | 
						||
  bool ok = true;
 | 
						||
 | 
						||
  if (k==K_TAB && f.focusdirty())
 | 
						||
  {
 | 
						||
		TSheet_field * s = f.mask().get_sheet();
 | 
						||
    TMask_movmag& mov_mask = (TMask_movmag &)s->mask();
 | 
						||
    TMask & row_mask = f.mask();
 | 
						||
		TCodice_articolo codart(row_mask.get(F_CODART));   
 | 
						||
    TRectype anamag = cache().get(LF_ANAMAG, codart);  // anamag puo' cambiare
 | 
						||
    
 | 
						||
    if (anamag.empty())
 | 
						||
    {
 | 
						||
      TLocalisamfile codalt(LF_CODCORR);
 | 
						||
      
 | 
						||
      codalt.setkey(2);
 | 
						||
      codalt.put(CODCORR_CODARTALT, codart);
 | 
						||
      if (codalt.read() == NOERR)
 | 
						||
      {                                   
 | 
						||
        codart = codalt.get(CODCORR_CODART);
 | 
						||
        anamag = cache().get(LF_ANAMAG, codart);
 | 
						||
        if (!anamag.empty())
 | 
						||
					row_mask.set(F_CODART, codart, 0x2);
 | 
						||
				else
 | 
						||
					return error_box(TR("Articolo assente"));
 | 
						||
      }
 | 
						||
    }
 | 
						||
 | 
						||
		f.check_type(CHECK_REQUIRED);
 | 
						||
		ok = f.check(STARTING_CHECK);
 | 
						||
		f.check_type(CHECK_SEARCH);
 | 
						||
 | 
						||
    if (ok)
 | 
						||
		{
 | 
						||
			mov_mask.curr_art().read(codart);
 | 
						||
			ok = handle_checksosp(f, k);
 | 
						||
			if (ok)
 | 
						||
		    handle_righeprezzo2(f, k);
 | 
						||
		}
 | 
						||
		else 
 | 
						||
			error_box(TR("Articolo assente"));
 | 
						||
  }             
 | 
						||
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TMask_movmag::handle_causrig(TMask_field &f, KEY k)
 | 
						||
{
 | 
						||
  if (k==K_TAB && f.focusdirty())  
 | 
						||
  {
 | 
						||
    if (!handle_checksosp(f, k))
 | 
						||
      return FALSE;        
 | 
						||
    handle_righeprezzo1(f, k);
 | 
						||
  }
 | 
						||
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
// proposta hard: propone il prezzo in ogni caso
 | 
						||
bool TMask_movmag::handle_giacattuale(TMask_field &f, KEY k)
 | 
						||
{
 | 
						||
  TMask & maskrighe =f.mask();
 | 
						||
  TMask_movmag &maskmov=(TMask_movmag &)maskrighe.get_sheet()->mask();
 | 
						||
  if (k==K_TAB && (!maskmov.is_running() || f.focusdirty()))
 | 
						||
  {
 | 
						||
    TString codliv;
 | 
						||
    // codici livello
 | 
						||
    if (livelli_giacenza().enabled()) 
 | 
						||
    {
 | 
						||
      livelli_giacenza().pack_maskgrpcodes(codliv,maskrighe,F_LIV1,4);
 | 
						||
      codliv.rtrim();
 | 
						||
    }
 | 
						||
    TString8 codmag(maskrighe.get(F_CODMAG));
 | 
						||
    codmag.insert(maskrighe.get(F_CODDEP),3);
 | 
						||
 | 
						||
    const TString& um = maskrighe.get(F_UM);
 | 
						||
    if (um.not_empty())
 | 
						||
    {
 | 
						||
      TArticolo_giacenza & art = maskmov.curr_art();
 | 
						||
      real disp = art.disponibilita(maskmov.get(F_ANNOES),codmag,codliv,TRUE);
 | 
						||
      disp = art.convert_to_um(disp, um, NULL, false);
 | 
						||
      f.set(disp.string());
 | 
						||
    } 
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}     
 | 
						||
 | 
						||
 | 
						||
bool TMask_movmag::update_rigamov (int r, const char * old_codcaus, const char * old_codart, const real & old_quant)
 | 
						||
{
 | 
						||
  bool added_some=add_autorows(r, old_codcaus, old_codart, old_quant);
 | 
						||
  if (added_some)
 | 
						||
    add_explrows(r+1);
 | 
						||
  added_some |=add_explrows(r);
 | 
						||
  return added_some;
 | 
						||
}
 | 
						||
 | 
						||
bool TMask_movmag::add_autorows (int r, const char * old_codcaus, const char * old_codart, const real & old_quant)
 | 
						||
{
 | 
						||
  bool added_some=FALSE;
 | 
						||
  TSheet_field & ss=(TSheet_field & )field(F_RIGHE);
 | 
						||
  real new_factor(ss.cell(r,ss.cid2index(F_QUANT)));
 | 
						||
  new_factor = old_quant.is_zero() ? ZERO : new_factor / old_quant;
 | 
						||
  TString8 new_codcaus(ss.cell(r,ss.cid2index(F_CAUSRIG)));
 | 
						||
  if (new_codcaus.blank())
 | 
						||
    new_codcaus=get(F_CODCAUS);
 | 
						||
 | 
						||
  const TCausale_magazzino oldcau(old_codcaus);
 | 
						||
  const TCausale_magazzino cau(new_codcaus);
 | 
						||
  bool rimuovi_righe_coll=FALSE;
 | 
						||
  bool inserisci_righe_coll= *cau.caus_collegata()!='\0' && *ss.cell(r,ss.cid2index(F_ESPLOSA)) == ' ';
 | 
						||
  if (inserisci_righe_coll)
 | 
						||
  {
 | 
						||
    // *******************************
 | 
						||
    // deve esserci una riga collegata
 | 
						||
    const TCausale_magazzino cau_coll(cau.caus_collegata());
 | 
						||
 | 
						||
    if (old_codcaus !=  new_codcaus)
 | 
						||
    {
 | 
						||
      rimuovi_righe_coll = TRUE;
 | 
						||
    }
 | 
						||
    else
 | 
						||
      if ((r < ss.items()-1 && *ss.cell(r+1,ss.cid2index( F_AUTOMATICA)) == riga_automatica) 
 | 
						||
           && cau_coll.esplodente())
 | 
						||
      {
 | 
						||
        if (strcmp(old_codart,ss.cell(r,ss.cid2index( F_CODART)))!=0 )
 | 
						||
          // ho cambiato il codice articolo del finito: rimuovo le righe automatiche esplose
 | 
						||
          rimuovi_righe_coll = TRUE;
 | 
						||
        else 
 | 
						||
          inserisci_righe_coll=FALSE;
 | 
						||
      }
 | 
						||
  }
 | 
						||
  else
 | 
						||
    if (*oldcau.caus_collegata()!='\0') // ho cambiato causale, passando ad una che non ha collegamenti
 | 
						||
      rimuovi_righe_coll=TRUE;
 | 
						||
  // ******************
 | 
						||
  if (rimuovi_righe_coll)
 | 
						||
  {
 | 
						||
    while (r < ss.items()-1 
 | 
						||
      && *ss.cell(r+1,ss.cid2index( F_AUTOMATICA)) == riga_automatica)
 | 
						||
      ss.destroy(r + 1);
 | 
						||
  }
 | 
						||
 | 
						||
  // ******************
 | 
						||
  if (inserisci_righe_coll)
 | 
						||
  {
 | 
						||
    const TCausale_magazzino cau_coll(cau.caus_collegata());
 | 
						||
    TString8 mag, dep;
 | 
						||
    mag = cau_coll.default_mag();
 | 
						||
    dep = cau_coll.default_dep();
 | 
						||
    TString tmpstr;
 | 
						||
    int offset=1;
 | 
						||
#define COPIA_SU_AUTO(colnum) {tmpstr=(ss.row(r).get(ss.cid2index(colnum))); ss.row(r+offset).add(tmpstr,ss.cid2index(colnum));}
 | 
						||
    if ((r == ss.items()-1 || r < ss.items()-1 && *ss.cell(r+1,ss.cid2index( F_AUTOMATICA)) != riga_automatica))
 | 
						||
    {
 | 
						||
      // manca, la inserisco
 | 
						||
      ss.insert(r+offset);
 | 
						||
      TToken_string & newrow = ss.row(r+offset);
 | 
						||
      newrow = ss.row(r);
 | 
						||
      newrow.add(TString(1,riga_automatica),ss.cid2index(F_AUTOMATICA));
 | 
						||
      if (cau_coll.has_default_mag())
 | 
						||
        newrow.add(mag,ss.cid2index(F_CODMAG));
 | 
						||
      if (cau_coll.has_default_dep())
 | 
						||
        newrow.add(dep,ss.cid2index(F_CODDEP));
 | 
						||
      COPIA_SU_AUTO(F_PREZZO);
 | 
						||
      added_some= TRUE;
 | 
						||
    } 
 | 
						||
    while (r+offset < ss.items() && *ss.cell(r+offset,ss.cid2index( F_AUTOMATICA))==riga_automatica)
 | 
						||
    {
 | 
						||
      // riporta eventuali cambiamenti della riga "Master" sulle righe automatice
 | 
						||
      if (*ss.cell(r+offset,ss.cid2index( F_ESPLOSA)) <=' ')
 | 
						||
      {
 | 
						||
        COPIA_SU_AUTO(F_CODART);
 | 
						||
        COPIA_SU_AUTO(F_LIV1);
 | 
						||
        COPIA_SU_AUTO(F_LIV2);
 | 
						||
        COPIA_SU_AUTO(F_LIV3);
 | 
						||
        COPIA_SU_AUTO(F_LIV4);
 | 
						||
        COPIA_SU_AUTO(F_UM);
 | 
						||
        COPIA_SU_AUTO(F_QUANT);
 | 
						||
        ss.row(r+offset).add(cau.caus_collegata(),ss.cid2index(F_CAUSRIG));
 | 
						||
        ss.check_row(r+offset);
 | 
						||
        ss.force_update(r+offset);
 | 
						||
      } else {
 | 
						||
        if (new_factor != 1.0)
 | 
						||
        {
 | 
						||
          real q(ss.row(r+offset).get(ss.cid2index(F_QUANT)));
 | 
						||
          q*=new_factor;
 | 
						||
          tmpstr=q.string(); 
 | 
						||
          ss.row(r+offset).add(tmpstr,ss.cid2index(F_QUANT));
 | 
						||
          ss.force_update(r+offset);
 | 
						||
        }
 | 
						||
      }
 | 
						||
        
 | 
						||
      offset++;
 | 
						||
    }
 | 
						||
  } 
 | 
						||
  return added_some;
 | 
						||
}
 | 
						||
 | 
						||
bool TMask_movmag::add_explrows(int r)
 | 
						||
{
 | 
						||
  TSheet_field& sheet = sfield(F_RIGHE);
 | 
						||
  TString8 new_codcaus(sheet.cell(r,sheet.cid2index(F_CAUSRIG)));
 | 
						||
  if (new_codcaus.blank())
 | 
						||
    new_codcaus=get(F_CODCAUS);
 | 
						||
 | 
						||
  bool added_some=FALSE;
 | 
						||
 | 
						||
  const TCausale_magazzino cau(new_codcaus);
 | 
						||
  TArticolo articolo;
 | 
						||
  
 | 
						||
  if (cau.esplodente() && *sheet.cell(r,sheet.cid2index(F_ESPLOSA)) == ' ')
 | 
						||
  {
 | 
						||
    TDistinta_tree  distinta;
 | 
						||
    TArticolo       articolo;
 | 
						||
    TArray boom;
 | 
						||
    // *******************************
 | 
						||
    // c'e' una riga di movimento esplodente non ancora esplosa: 
 | 
						||
    // va sostituita con n righe esplose
 | 
						||
    real prezzo,quant;  
 | 
						||
    const char tipo_costo = cau.get("S11")[0];
 | 
						||
    const int livello = cau.get_int("I0");
 | 
						||
    const TString codart = sheet.cell(r,sheet.cid2index(F_CODART));
 | 
						||
    bool ok = distinta.set_root(codart);
 | 
						||
    const int rigaprec = r - 1;
 | 
						||
    const bool is_coll = rigaprec >= 0 && *sheet.cell(r, sheet.cid2index(F_AUTOMATICA)) == riga_automatica;
 | 
						||
    if (ok)
 | 
						||
    {
 | 
						||
      distinta.explode(boom, TRUE, RAGGR_EXP_NONE, livello, "A");
 | 
						||
      for (int newrow=0; newrow < boom.items() ; newrow++)
 | 
						||
      {
 | 
						||
        TRiga_esplosione & riga_esp=(TRiga_esplosione & )(boom[newrow]);
 | 
						||
        sheet.insert(r+newrow+1);
 | 
						||
        TToken_string & nuova_riga=sheet.row(r+newrow+1);
 | 
						||
        nuova_riga=sheet.row(r);
 | 
						||
        nuova_riga.add(riga_esp.articolo()  ,sheet.cid2index(F_CODART));
 | 
						||
        nuova_riga.add(riga_esp.um() , sheet.cid2index(F_UM));
 | 
						||
        quant=sheet.row(r).get(sheet.cid2index(F_QUANT));
 | 
						||
        quant*=riga_esp.val();
 | 
						||
        nuova_riga.add(quant.string() , sheet.cid2index(F_QUANT));
 | 
						||
 | 
						||
        articolo.read(riga_esp.articolo());
 | 
						||
        char coll_type = articolo.get_char(ANAMAG_COLLTYPE);
 | 
						||
        TString16 codmag;
 | 
						||
            
 | 
						||
        if (coll_type == 'M')
 | 
						||
        { 
 | 
						||
          if (is_coll)
 | 
						||
            codmag = *sheet.cell(rigaprec, sheet.cid2index(F_CODMAG));
 | 
						||
        }
 | 
						||
        else
 | 
						||
          if (coll_type == 'F')
 | 
						||
          {                         
 | 
						||
            TString key("F|");                   
 | 
						||
                
 | 
						||
            key << articolo.get(ANAMAG_CODFORN);
 | 
						||
            codmag = cache().get(LF_CFVEN, key, CFV_CODMAG);
 | 
						||
          }
 | 
						||
          else
 | 
						||
            if (coll_type == 'A')
 | 
						||
              codmag = articolo.get(ANAMAG_CODMAG);
 | 
						||
        if (codmag.not_empty()) 
 | 
						||
        {                           
 | 
						||
          const TString8 mag(codmag.left(3));
 | 
						||
          const TString8 dep(codmag.mid(3));
 | 
						||
          
 | 
						||
          nuova_riga.add(mag ,sheet.cid2index(F_CODMAG));
 | 
						||
          nuova_riga.add(dep ,sheet.cid2index(F_CODDEP));
 | 
						||
        }
 | 
						||
        articolo.read(riga_esp.articolo());
 | 
						||
        if (tipo_costo == 'U')
 | 
						||
          prezzo = articolo.get_real(ANAMAG_ULTCOS1);
 | 
						||
        else
 | 
						||
          if (tipo_costo == 'S')
 | 
						||
            prezzo = articolo.get_real(ANAMAG_COSTSTD);
 | 
						||
        if (!prezzo.is_zero())
 | 
						||
          nuova_riga.add(prezzo.string(),sheet.cid2index(F_PREZZO));
 | 
						||
        nuova_riga.add("X",sheet.cid2index(F_ESPLOSA));
 | 
						||
  
 | 
						||
        sheet.check_row(r+1+newrow);
 | 
						||
        sheet.force_update(r+1+newrow);
 | 
						||
        added_some=TRUE;
 | 
						||
      }
 | 
						||
      // elimino la riga "padre"
 | 
						||
      if (boom.items() > 0)
 | 
						||
      {
 | 
						||
        if (boom.items() == 1 && codart == ((TRiga_esplosione &)boom[0]).articolo())
 | 
						||
          error_box(TR("Distinta %s ciclica"), (const char *)codart);
 | 
						||
        sheet.destroy(r);
 | 
						||
      }
 | 
						||
      else
 | 
						||
        message_box(FR("Impossibile esplodere l'articolo %s"), (const char *)codart);
 | 
						||
 | 
						||
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return added_some;
 | 
						||
}
 | 
						||
 | 
						||
real TMask_movmag::proposed_price(const char *codart, 
 | 
						||
        real quant, const char *causrig)
 | 
						||
{ 
 | 
						||
  real rv;
 | 
						||
 | 
						||
  const TCausale_magazzino cau(causrig && *causrig ? causrig : (const char *)get(F_CODCAUS));
 | 
						||
  const char tipoprz = cau.tipoprz();
 | 
						||
 | 
						||
  if (tipoprz == 'P' || tipoprz == 'C')  // Se e' Libero non devo far nulla
 | 
						||
  {
 | 
						||
    TLocalisamfile anamag(LF_ANAMAG);
 | 
						||
    anamag.put("CODART",codart);
 | 
						||
    anamag.read();
 | 
						||
 | 
						||
    TConfig cfgditta(CONFIG_DITTA);
 | 
						||
    TLocalisamfile umart(LF_UMART);
 | 
						||
 | 
						||
    TCondizione_vendita cv(&cfgditta,&anamag,&umart);
 | 
						||
    cv.put_listino(get(F_CODLIST),get(F_CATVEN));
 | 
						||
    
 | 
						||
    switch (tipoprz) 
 | 
						||
    {
 | 
						||
    // prezzo 
 | 
						||
    case 'P': 
 | 
						||
      cv.ricerca(codart,quant,false);  // Considera UMART
 | 
						||
      rv=cv.get_prezzo();
 | 
						||
      break;
 | 
						||
      // costo
 | 
						||
    case 'C': 
 | 
						||
  		cv.ricerca(codart,quant,true);  // Ignora UMART
 | 
						||
			rv=cv.get_prezzo();
 | 
						||
			if (rv.is_zero())
 | 
						||
				rv=anamag.get_real("ULTCOS1");
 | 
						||
      break;
 | 
						||
    default:
 | 
						||
      break;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  
 | 
						||
  return rv;
 | 
						||
}
 | 
						||
 | 
						||
bool TMask_movmag::handle_codcaus(TMask_field &fld, KEY k)
 | 
						||
{
 | 
						||
  static TString8 old_codcaus;
 | 
						||
 | 
						||
  if (k == K_TAB && fld.focusdirty() && old_codcaus!="")  
 | 
						||
  {
 | 
						||
    // aggiorna le righe di sheet
 | 
						||
    TMask_movmag &m=(TMask_movmag &)fld.mask();
 | 
						||
    TSheet_field & ss=(TSheet_field & )m.field(F_RIGHE);
 | 
						||
    bool added_some = FALSE;
 | 
						||
    
 | 
						||
    // aggiorna le righe che dipendono dalla causale movimento
 | 
						||
    for (int i=0; i< ss.items(); i++)
 | 
						||
    {
 | 
						||
      if (*ss.cell(i,ss.cid2index(F_CAUSRIG)) ==' ')
 | 
						||
        added_some &=(m.update_rigamov(i,old_codcaus,ss.cell(i,ss.cid2index(F_CODART)), real(ss.cell(i,ss.cid2index(F_QUANT)))));
 | 
						||
    }
 | 
						||
    if (added_some)
 | 
						||
    {
 | 
						||
      ss.dirty();
 | 
						||
      ss.set_focus();
 | 
						||
    }
 | 
						||
  }
 | 
						||
  if (k == K_TAB) 
 | 
						||
    old_codcaus=fld.get();
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TMask_movmag::handle_datacomp(TMask_field &fld, KEY k)
 | 
						||
{
 | 
						||
  if (k == K_TAB) // && fld.focusdirty()) 
 | 
						||
  {
 | 
						||
    TMask_movmag& m = (TMask_movmag&) fld.mask();
 | 
						||
    const int codes = m._esercizi.date2esc(TDate(fld.get()));
 | 
						||
    if (codes > 0) 
 | 
						||
    {
 | 
						||
      m.set(F_ANNOES, codes);
 | 
						||
      m.set(H_ANNOES, codes);
 | 
						||
    } 
 | 
						||
    else 
 | 
						||
      return fld.error_box(TR("La data indicata non appartiene a nessuno degli esercizi contabili inseriti ")) ;
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
class TApp_movmag: public TRelation_application 
 | 
						||
{
 | 
						||
  TMask_movmag *_msk; // maschera principale
 | 
						||
  TRelation * _rel;   // relazione contenente il file movimenti
 | 
						||
 | 
						||
  virtual bool user_create();
 | 
						||
  virtual bool user_destroy();                        
 | 
						||
  virtual TMask *get_mask(int) { return _msk; }
 | 
						||
  virtual void init_query_mode(TMask&) ;
 | 
						||
  virtual void init_insert_mode(TMask&) ;
 | 
						||
  virtual void init_modify_mode(TMask&) ;
 | 
						||
  virtual bool changing_mask(int) { return FALSE; }
 | 
						||
  virtual TRelation *get_relation() const { return _rel; }
 | 
						||
  virtual const char *get_next_key();
 | 
						||
  virtual int read(TMask& m);
 | 
						||
  TString16 _nextcod;    
 | 
						||
 | 
						||
public:
 | 
						||
  TApp_movmag() {};
 | 
						||
  virtual ~TApp_movmag() {};
 | 
						||
};
 | 
						||
 | 
						||
 | 
						||
inline TApp_movmag& app() { return (TApp_movmag&) main_app(); }
 | 
						||
 | 
						||
int TApp_movmag::read(TMask& m)
 | 
						||
{
 | 
						||
  TArticolo_giacenza & art = _msk->curr_art();
 | 
						||
              
 | 
						||
  art.read("");        
 | 
						||
  const int err =  TRelation_application::read(m);
 | 
						||
	if (err == NOERR)
 | 
						||
		((TMask_movmag &)m).update_tot();
 | 
						||
	return err;
 | 
						||
}                                       
 | 
						||
 | 
						||
void TApp_movmag::init_query_mode(TMask& m)
 | 
						||
{
 | 
						||
  m.enable(F_INVENTORYMODE);     
 | 
						||
  TRelation_application::init_query_mode(m);
 | 
						||
}
 | 
						||
 | 
						||
void TApp_movmag::init_modify_mode(TMask& m)
 | 
						||
{
 | 
						||
  m.disable(F_INVENTORYMODE);
 | 
						||
  const bool inventory = m.get_bool(F_INVENTORYMODE);
 | 
						||
  TSheet_field & ss = m.sfield(F_RIGHE);
 | 
						||
  ss.sheet_mask().field(F_QUANT).check_type(inventory ? CHECK_NONE : CHECK_REQUIRED);
 | 
						||
  TRelation_application::init_modify_mode(m);
 | 
						||
}
 | 
						||
 | 
						||
void TApp_movmag::init_insert_mode(TMask& m)
 | 
						||
{
 | 
						||
  m.disable(F_INVENTORYMODE);
 | 
						||
  const bool inventory = m.get_bool(F_INVENTORYMODE);
 | 
						||
  TSheet_field& ss = m.sfield(F_RIGHE);
 | 
						||
  ss.sheet_mask().field(F_QUANT).check_type(inventory ? CHECK_NONE : CHECK_REQUIRED);
 | 
						||
 | 
						||
  for (int i = 0; i < 20; i++)
 | 
						||
    ss.insert(-1, false, true);
 | 
						||
 | 
						||
  TRelation_application::init_insert_mode(m);
 | 
						||
}
 | 
						||
 | 
						||
bool TApp_movmag::user_create()
 | 
						||
{
 | 
						||
  open_files(LF_ANAMAG, LF_UMART, LF_CODCORR, LF_DESLIN, LF_MOVMAG,LF_RMOVMAG, LF_MAG, LF_STOMAG, LF_TABCOM,0);
 | 
						||
  
 | 
						||
  TMov_mag * m_m= new TMov_mag(); // record del movimento di magazzino
 | 
						||
  m_m->enable_autoload(LF_RMOVMAG);
 | 
						||
  
 | 
						||
  // maschera specifica con gli handler dei movimenti
 | 
						||
  _msk= new TMask_movmag(m_m);                                                                             
 | 
						||
  // relazione con un solo file (LF_MOVMAG) ma col record Head_Body
 | 
						||
  _rel= new TRelation(LF_MOVMAG);
 | 
						||
  _rel->lfile().set_curr(m_m);
 | 
						||
      
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TApp_movmag::user_destroy()
 | 
						||
{
 | 
						||
  delete _rel;  
 | 
						||
  delete _msk;
 | 
						||
  
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
// autonumerazione
 | 
						||
const char *TApp_movmag::get_next_key()
 | 
						||
{
 | 
						||
  const char* nk = ((TMov_mag &)_rel->curr()).get_next_key();
 | 
						||
  return _nextcod.format("%d|%s",F_NUMREG, nk);
 | 
						||
}
 | 
						||
 | 
						||
int mg1100(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TApp_movmag a;
 | 
						||
  a.run(argc, argv, TR("Movimenti di magazzino"));
 | 
						||
  exit(0);
 | 
						||
  return 0;
 | 
						||
}
 | 
						||
 | 
						||
 |