#include #include #include "mglib.h" #include "mg3500.h" #include "mg3frm.h" #include "../cg/cglib01.h" // mg3500 Stampa class TForm_storgiac : public TForm_stampemg { TSorted_cursor * _sortcur; bool _use_alternate_cursor; TString16 _user1; public: void use_alternate_cursor(const bool b = TRUE) { _use_alternate_cursor = b; } void set_description_field(const char* u) { _user1 = u; } virtual TCursor* cursor() const ; virtual bool validate(TForm_item &cf, TToken_string &s); TForm_storgiac(const char *name,const char *code) ; virtual ~TForm_storgiac(); }; TCursor* TForm_storgiac::cursor() const { if (_use_alternate_cursor) // Se e' settata la stampa per ragg. fisc ritorna il cursore appropriato return (TCursor*)_sortcur; return TForm_stampemg::cursor(); } bool TForm_storgiac::validate(TForm_item &cf, TToken_string &s) { const TString80 cmd = s.get(0); if (cmd == "_FRACTION_MULT") { const TString16 id1 = s.get(); const TString16 id2 = s.get(); const fraction f1 = cf.find_field(id1).get(); const fraction f2 = cf.find_field(id2).get(); const real m = f1 * f2; cf.set(m.string()); return true; } if (cmd == "_USER") { const TFixed_string subcode = s.get(); if (subcode == "DESCR") { if (_user1.blank()) _user1 = ANAMAG_DESCR; const TString& desc = relation()->curr(LF_ANAMAG).get(_user1); cf.set(desc); return true; } } return TForm_stampemg::validate(cf, s); } TForm_storgiac::TForm_storgiac(const char *name,const char *code) : TForm_stampemg(name,code) { _use_alternate_cursor = FALSE; _sortcur = new TSorted_cursor(relation(),"RAGGFIS|CODART"); } TForm_storgiac::~TForm_storgiac() { delete _sortcur; } ///////////////////////////////////////////////////// // Applicazione ///////////////////////////////////////////////////// class TStampa_storgiac : public TSkeleton_application { TArray * _files; TStampemg_mask * _mask; TCursor * _cur; TForm_storgiac * _form; // to be moved into TPrint_application protected: virtual bool create(); virtual bool destroy(); virtual void main_loop(); virtual void set_def_valuta(TForm_storgiac & f) {} public: TStampa_storgiac() {} virtual ~TStampa_storgiac() {}; }; bool TStampa_storgiac::create() { _mask = new TStampemg_mask("mg3500"); TConfig prassid(CONFIG_DITTA, "ve"); // apre il file di configurazione della ditta corrente if (prassid.get_bool("CHK_USER", "ve", 1)) { const TString& user1 = prassid.get("PROMPT_USER", "ve", 1); _mask->field(F_DAUSR).set_prompt(user1); _mask->show(F_DAUSR); _mask->show(F_AUSR); } return TSkeleton_application::create(); } bool TStampa_storgiac::destroy() { delete _mask; return TSkeleton_application::destroy(); } // ORDINAMENTO void TStampa_storgiac::main_loop() { while (_mask->run() == K_ENTER) { if (_mask->magazz_ini().gestmag(TRUE)) { TRectype darec(LF_ANAMAG),arec(LF_ANAMAG); TString cfilter,joinexp, espr; cfilter.format("%d->NRIGA!=0", LF_STOMAG); //Considera l'articolo solo se ha almeno una riga di storico... TString16 es ; es.format("\"%04d\"", _mask->get_int(F_ANNOES)); joinexp << "ANNOESRIF==" << es << "|CODART==CODART"; _form = new TForm_storgiac("mg3500", ""); _cur = _form->cursor(); const char ordine = _mask->get(F_ORDINE)[0]; TString sortexp; switch (ordine) { case 'C': _cur->setkey(1); sortexp = ANAMAG_CODART; darec.put("CODART",_mask->get(F_DAART)); arec.put("CODART",_mask->get(F_AART)); _form->find_field('B',odd_page,"H_CATMER").hide(); _form->find_field('B',odd_page,"TOT_CATMER").hide(); _form->find_field('B',odd_page,"H_SCATMER").hide(); _form->find_field('B',odd_page,"TOT_SCATMER").hide(); _form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART[1,1]",_strexpr); break; case 'D': _cur->setkey(2); sortexp = ANAMAG_DESCR; darec.put("DESCR",_mask->get(F_DADES)); arec.put("DESCR",_mask->get(F_ADES)); _form->find_field('B',odd_page,"H_CATMER").hide(); _form->find_field('B',odd_page,"TOT_CATMER").hide(); _form->find_field('B',odd_page,"H_SCATMER").hide(); _form->find_field('B',odd_page,"TOT_SCATMER").hide(); _form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART[1,1]",_strexpr); break; case 'S': case 'M': { TString16 m1,m2; m1 = _mask->get(F_DAGRMERC); m2 = _mask->get(F_AGRMERC); if (ordine == 'S') { m1 << _mask->get(F_DASGRMERC); m2 << _mask->get(F_ASGRMERC); m1.trim(); m2.trim(); } if (m2.empty() && _mask->get(F_AART).not_empty()) m2.fill('\254',5); _cur->setkey(3); sortexp = ANAMAG_GRMERC; darec.put("GRMERC", m1); darec.put("CODART",_mask->get(F_DAART)); arec.put("GRMERC", m2); arec.put("CODART",_mask->get(F_AART)); _form->find_field('B',odd_page,"H_CATMER").show(); _form->find_field('B',odd_page,"TOT_CATMER").show(); if (ordine == 'S') { _form->find_field('B',odd_page,"H_SCATMER").show(); _form->find_field('B',odd_page,"TOT_SCATMER").show(); } else { _form->find_field('B',odd_page,"H_SCATMER").hide(); _form->find_field('B',odd_page,"TOT_SCATMER").hide(); _form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART[1,1]",_strexpr); } _form->set_ordering(mg_cat_merc); } break; case 'R': _form->set_ordering(mg_ragg_fisc);// Setta la subsection in modo da raggruppare per RAGGFIS _form->use_alternate_cursor(); _cur = _form->cursor(); _cur->setkey(1); sortexp = ANAMAG_CODART; _form->find_field('B',odd_page,"H_CATMER").show(); _form->find_field('B',odd_page,"TOT_CATMER").show(); _form->find_field('B',odd_page,"GRUPPI_CATMER").setcondition("RAGGFIS",_strexpr); _form->find_field('B',odd_page,"H_SCATMER").hide(); _form->find_field('B',odd_page,"TOT_SCATMER").hide(); _form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("RAGGFIS",_strexpr); cfilter.format("STR(%d->NRIGA!=0)", LF_STOMAG); //Considera l'articolo solo se ha almeno una riga di storico... if (_mask->get(F_DARAGGFIS).full()) cfilter << "&&(RAGGFIS>=\"" << _mask->get(F_DARAGGFIS) <<"\")"; if (_mask->get(F_ARAGGFIS).full()) cfilter << "&&(RAGGFIS<=\"" << _mask->get(F_ARAGGFIS) << "\")"; break; case 'P': _cur->setkey(1); sortexp = ANAMAG_USER1; _form->find_field('B',odd_page,"H_CATMER").hide(); _form->find_field('B',odd_page,"TOT_CATMER").hide(); _form->find_field('B',odd_page,"H_SCATMER").hide(); _form->find_field('B',odd_page,"TOT_SCATMER").hide(); _form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART[1,1]",_strexpr); cfilter.format("STR(%d->NRIGA!=0)", LF_STOMAG); //Considera l'articolo solo se ha almeno una riga di storico... if (_mask->get(F_DAUSR).full()) cfilter << "&&(USER1>=\"" << _mask->get(F_DAUSR) << "\")"; if (_mask->get(F_AUSR).full()) cfilter << "&&(USER1<=\"" << _mask->get(F_AUSR) << "~\")"; break; default: break; } TEsercizi_contabili esercizi; const int cod_es_prec = esercizi.pred(_mask->get_int(F_ANNOES)); TString16 es_prec ; es_prec.format("%04d", cod_es_prec); _form->find_field('H',odd_page,4).set(es_prec); _cur->relation()->replace(new TLocalisamfile(LF_STOMAG),1,joinexp); _cur->setfilter(cfilter, true); _cur->setregion(darec,arec); ((TSorted_cursor*)_cur)->change_order(sortexp); set_def_valuta(*_form); _form->print(); delete _form; } } // while true } int mg3500(int argc, char* argv[]) { TStampa_storgiac a; a.run(argc,argv,TR("Stampa storico rimanenze")); return 0; }