git-svn-id: svn://10.65.10.50/branches/R_10_00@23073 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			300 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			300 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
 | 
						|
#include "../ve/velib.h"
 | 
						|
#include "ci1.h"
 | 
						|
#include "ci1600a.h"
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Utilities
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
static bool in_movint_filter(const TRectype& rdoc)
 | 
						|
{
 | 
						|
  static TAssoc_array movint_num;
 | 
						|
 | 
						|
  if (rdoc.get_real(RDOC_QTA).is_zero() || rdoc.get(RDOC_CODARTMAG).empty())
 | 
						|
    return false; // not an article
 | 
						|
 | 
						|
  const TString4 codnum = rdoc.get(RDOC_CODNUM);
 | 
						|
  if (!movint_num.is_key(codnum))
 | 
						|
  {
 | 
						|
    TLocalisamfile doc(LF_DOC);
 | 
						|
    doc.put(DOC_PROVV,  rdoc.get(RDOC_PROVV));
 | 
						|
    doc.put(DOC_ANNO,   rdoc.get(RDOC_ANNO));
 | 
						|
    doc.put(DOC_CODNUM, rdoc.get(RDOC_CODNUM));
 | 
						|
    doc.put(DOC_NDOC,   rdoc.get(RDOC_NDOC));
 | 
						|
    doc.read();
 | 
						|
    real sg = ZERO;
 | 
						|
    const TTipo_documento& tipo = cached_tipodoc(doc.get(DOC_TIPODOC));
 | 
						|
    if (tipo.is_bolla())
 | 
						|
    {
 | 
						|
      const TString& causmag = tipo.caus_mov();
 | 
						|
      if (causmag.full())
 | 
						|
      {
 | 
						|
        const TCausale_magazzino caus(causmag);
 | 
						|
        sg = caus.sgn(s_giac);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    movint_num.add(codnum, sg);
 | 
						|
  }
 | 
						|
  const real sg = *(real*)movint_num.objptr(codnum);
 | 
						|
  return !sg.is_zero();
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Maschera
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TInterrogazione_msk : public TAutomask
 | 
						|
{
 | 
						|
protected:
 | 
						|
  void fill_sheet();
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
  TInterrogazione_msk(const TDocumento& din);
 | 
						|
};
 | 
						|
 | 
						|
void TInterrogazione_msk::fill_sheet()
 | 
						|
{
 | 
						|
  const TString& cms = get(F_CODCMS);
 | 
						|
  const TString& art = get(F_CODART);
 | 
						|
  const bool null_giac = get_bool(F_NULLGIAC);
 | 
						|
 | 
						|
  TString query;
 | 
						|
  query << "USE "    << LF_RIGHEDOC << " KEY 6 SELECT CODARTMAG!=\"\""
 | 
						|
        << "\nFROM " << RDOC_CODCMS << '=' << cms
 | 
						|
        << "\nTO "   << RDOC_CODCMS << '=' << cms;
 | 
						|
    
 | 
						|
  TAssoc_array saldi;
 | 
						|
  TISAM_recordset rdoc_set(query);
 | 
						|
  const TRectype& rdoc = rdoc_set.cursor()->curr();
 | 
						|
  for (bool ok = rdoc_set.move_first(); ok; ok = rdoc_set.move_next())
 | 
						|
  {
 | 
						|
    if (!in_movint_filter(rdoc))
 | 
						|
      continue;
 | 
						|
 | 
						|
    const TString& codart = rdoc.get(RDOC_CODARTMAG);
 | 
						|
    if (art.full() && !codart.starts_with(art, true))
 | 
						|
      continue;
 | 
						|
 | 
						|
    const real qta = rdoc.get_real(RDOC_QTA);
 | 
						|
    real* s = (real*)saldi.objptr(codart);
 | 
						|
    if (s == NULL)
 | 
						|
      saldi.add(codart, qta);
 | 
						|
    else
 | 
						|
      *s += qta;
 | 
						|
  }
 | 
						|
 | 
						|
  const TDate oggi(TODAY);
 | 
						|
  TEsercizi_contabili esc;
 | 
						|
  const int annoes = esc.date2esc(oggi);
 | 
						|
 | 
						|
  TSheet_field& sheet = sfield(F_RIGHE);
 | 
						|
  sheet.hide();
 | 
						|
  sheet.destroy();
 | 
						|
  FOR_EACH_ASSOC_OBJECT(saldi, hash, key, itm)
 | 
						|
  {
 | 
						|
    const real& giac = *(real*)itm;
 | 
						|
    if (!null_giac && giac <= ZERO)
 | 
						|
      continue;
 | 
						|
    const TArticolo_giacenza& art = cached_article_balances(key);
 | 
						|
    TToken_string& row = sheet.row(-1);
 | 
						|
    row.add(art.um()[1].get(UMART_UM), 2);
 | 
						|
    row.add(giac.string(0, 2));
 | 
						|
    row.add(key);
 | 
						|
    row.add(art.descrizione());
 | 
						|
    row.add(art.get(ANAMAG_CODIVA));
 | 
						|
    row.add(art.costo_medio(annoes, "", "").string(0,2));
 | 
						|
    row.add(art.scorta_minima("", "", annoes).string(0,2));
 | 
						|
  }
 | 
						|
  sheet.force_update();
 | 
						|
  sheet.show();
 | 
						|
}
 | 
						|
 | 
						|
bool TInterrogazione_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case F_CODART:
 | 
						|
  case F_NULLGIAC:
 | 
						|
    if (e == fe_modify)
 | 
						|
      fill_sheet();
 | 
						|
    break;
 | 
						|
  case F_RIGHE:
 | 
						|
    if (e == se_query_del)
 | 
						|
      return false;
 | 
						|
    if (e == se_query_add)
 | 
						|
      fill_sheet();
 | 
						|
    break;
 | 
						|
  case S_CHECKED:
 | 
						|
    if (e == fe_modify)
 | 
						|
    {
 | 
						|
      TMask& m = o.mask();
 | 
						|
      if (o.get().full())
 | 
						|
      {
 | 
						|
        if (m.get_real(S_QTA).is_zero())
 | 
						|
          m.set(S_QTA, m.get(S_SALDO));
 | 
						|
      }
 | 
						|
      else
 | 
						|
        m.reset(S_QTA);
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case S_QTA:
 | 
						|
    if (e == fe_modify)
 | 
						|
    {
 | 
						|
      const real q = o.get();
 | 
						|
      o.mask().set(S_CHECKED, !q.is_zero());
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
TInterrogazione_msk::TInterrogazione_msk(const TDocumento& din) : TAutomask("ci1600a")
 | 
						|
{
 | 
						|
  set(F_CODCMS, din.get(DOC_COMMPREL), 0x3);
 | 
						|
  set(F_CODFAS, din.get(DOC_FASEPREL), 0x3);
 | 
						|
  fill_sheet();
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Applicazione
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TInterrogazione_app : public TSkeleton_application
 | 
						|
{
 | 
						|
  TFilename _trans;
 | 
						|
 | 
						|
protected:
 | 
						|
 | 
						|
public:
 | 
						|
  virtual bool create();
 | 
						|
  virtual void main_loop();
 | 
						|
};
 | 
						|
 | 
						|
bool TInterrogazione_app::create()
 | 
						|
{
 | 
						|
  const TFixed_string a2 = argc() >= 2 ? argv(2) : "";
 | 
						|
  if (a2.starts_with("-i", true) || a2.starts_with("/i", true))
 | 
						|
    _trans = a2.mid(2);
 | 
						|
 | 
						|
#ifdef DBG
 | 
						|
  if (_trans.blank())
 | 
						|
  {
 | 
						|
    const TDate oggi(TODAY);
 | 
						|
    _trans.tempdir();
 | 
						|
    _trans.add(name());
 | 
						|
    _trans.ext("ini");
 | 
						|
    TConfig ini(_trans, "Transaction");
 | 
						|
    ini.set("DataElab", oggi.string());
 | 
						|
 | 
						|
    ini.set_paragraph("33");
 | 
						|
    ini.set(DOC_PROVV, "D");
 | 
						|
    ini.set(DOC_ANNO, 2014);
 | 
						|
    ini.set(DOC_CODNUM, "TRAS");
 | 
						|
    ini.set(DOC_NDOC, 1);
 | 
						|
  }
 | 
						|
#endif
 | 
						|
 | 
						|
  if (!_trans.exist())
 | 
						|
    return cantread_box(_trans);
 | 
						|
 | 
						|
  open_files(LF_TABCOM, LF_DOC, LF_RIGHEDOC, LF_ANAMAG, LF_CODCORR, 0);
 | 
						|
  return TSkeleton_application::create();
 | 
						|
}
 | 
						|
 | 
						|
void TInterrogazione_app::main_loop()
 | 
						|
{
 | 
						|
  TConfig ini(_trans, "Transaction");
 | 
						|
  const TDate oggi = ini.get("DataElab");
 | 
						|
  ini.set_paragraph("33");
 | 
						|
  const char     provv  = ini.get_char(DOC_PROVV);
 | 
						|
  const int      anno   = ini.get_int(DOC_ANNO);
 | 
						|
  const TString& codnum = ini.get(DOC_CODNUM);
 | 
						|
  const long ndoc       = ini.get_long(DOC_NDOC);
 | 
						|
  TDocumento din(provv, anno, codnum, ndoc);
 | 
						|
  
 | 
						|
  TString4 riga_merce = "01"; // Stabilisce il tipo riga standard per la merce
 | 
						|
  FOR_EACH_PHYSICAL_RDOC(din, r, rdoc)
 | 
						|
  {
 | 
						|
    if (rdoc->is_merce())
 | 
						|
    {
 | 
						|
      riga_merce = rdoc->get(RDOC_TIPORIGA);
 | 
						|
      break;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  const int last_row = din.rows(); // Ultima riga del documento originale dopo cui fare aggiunte
 | 
						|
 | 
						|
  TInterrogazione_msk m(din);
 | 
						|
  while (m.run() == K_ENTER)
 | 
						|
  {
 | 
						|
    const TSheet_field& sheet = m.sfield(F_RIGHE);
 | 
						|
    const int iqta = sheet.cid2index(S_QTA);
 | 
						|
    const int iart = sheet.cid2index(S_CODART);
 | 
						|
    const int iiva = sheet.cid2index(S_CODIVA);
 | 
						|
    const int iums = sheet.cid2index(S_UM);
 | 
						|
    const int ides = sheet.cid2index(S_DESART);
 | 
						|
    int nr = 0, nu = 0;
 | 
						|
    FOR_EACH_ARRAY_ROW(sheet.rows_array(), r, riga)
 | 
						|
    {
 | 
						|
      const real qta = riga->get(iqta);
 | 
						|
      if (!qta.is_zero())
 | 
						|
      {
 | 
						|
        // Cerca una riga nuova (>last_row) col codice articolo corrispondente 
 | 
						|
        const TCodice_articolo codart = riga->get(iart);
 | 
						|
        int nriga = 0;
 | 
						|
        for (nriga = din.rows(); nriga > last_row; nriga--)
 | 
						|
          if (din[nriga].get(RDOC_CODARTMAG) == codart) break;
 | 
						|
        if (nriga <= last_row) // Se non la trova, ne crea una nuova
 | 
						|
        {
 | 
						|
          TRiga_documento& rdoc = din.new_row(riga_merce);
 | 
						|
          rdoc.put(RDOC_CODART,    codart);
 | 
						|
          rdoc.put(RDOC_CODARTMAG, codart);
 | 
						|
          rdoc.put(RDOC_CHECKED,   "X");
 | 
						|
          rdoc.put(RDOC_UMQTA,     riga->get(iums));
 | 
						|
          rdoc.put(RDOC_CODIVA,    riga->get(iiva));
 | 
						|
          rdoc.put(RDOC_DESCR,     riga->get(ides));
 | 
						|
          nriga = rdoc.get_int(RDOC_NRIGA);
 | 
						|
          nr++;
 | 
						|
        }
 | 
						|
        else
 | 
						|
          nu++;
 | 
						|
        din[nriga].put(RDOC_QTA, qta);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    message_box(FR("Sono state aggiunte %d righe ed aggiornate %d"), nr, nu);
 | 
						|
  }
 | 
						|
  if (din.rows() > last_row) // Sono state fatte aggiunte?
 | 
						|
  {
 | 
						|
    TString8 para;
 | 
						|
    for (int i = din.rows(); i > last_row; i--)
 | 
						|
    {
 | 
						|
      const TRiga_documento& rdoc = din[i];
 | 
						|
      para.format("%d,%d", LF_RIGHEDOC, i);
 | 
						|
      ini.set_paragraph(para);
 | 
						|
      for (int f = 0; f < rdoc.items(); f++) 
 | 
						|
      {
 | 
						|
        const char* fld = rdoc.fieldname(f);
 | 
						|
        const TString& val = rdoc.get(fld);
 | 
						|
        if (val.full() && val.len() <= 50) 
 | 
						|
          ini.set(fld, val);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
  ini.set_paragraph("Transaction");
 | 
						|
  ini.set("Result", "SUCCESS");
 | 
						|
  ini.set("Error", "0");
 | 
						|
}
 | 
						|
 | 
						|
int ci1600(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TInterrogazione_app mi;
 | 
						|
  mi.run(argc, argv, TR("Interrogazione magazzino"));
 | 
						|
  return 0;
 | 
						|
}
 |