580ae47f0d
git-svn-id: svn://10.65.10.50/branches/R_10_00@23059 c028cbd2-c16b-5b4b-a496-9718f37d4682
313 lines
8.5 KiB
C++
Executable File
313 lines
8.5 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <defmask.h>
|
|
#include <printer.h>
|
|
#include <progind.h>
|
|
|
|
#include "provv.h"
|
|
#include "pr1300a.h"
|
|
#include "..\ve\velib.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TStampa_schedeprovv_form
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TStampa_schedeprovv_form : public TForm
|
|
{
|
|
TString _basecalcolo;
|
|
TPagamento _pagamento;
|
|
|
|
protected:
|
|
void init_pagamento();
|
|
|
|
virtual bool validate(TForm_item &, TToken_string &);
|
|
|
|
public:
|
|
void set_basecalcolo(const TString& s) { _basecalcolo = s; }
|
|
TStampa_schedeprovv_form(const char* name);
|
|
virtual ~TStampa_schedeprovv_form(){};
|
|
};
|
|
|
|
TStampa_schedeprovv_form::TStampa_schedeprovv_form(const char* name) : TForm(name)
|
|
{ }
|
|
|
|
void TStampa_schedeprovv_form::init_pagamento()
|
|
{
|
|
TDocumento doc(TForm::cursor()->curr(LF_DOC));
|
|
_pagamento = doc.pagamento();
|
|
real importo = doc.get(_basecalcolo);
|
|
if (doc.is_nota_credito())
|
|
importo = -importo;
|
|
_pagamento.set_total(importo,ZERO,ZERO);
|
|
_pagamento.set_rate_auto();
|
|
}
|
|
|
|
bool TStampa_schedeprovv_form::validate(TForm_item &cf, TToken_string &s)
|
|
{
|
|
const TFixed_string code(s.get(0));
|
|
if (code == "_BASECALCOLO")
|
|
{
|
|
const TRectype& curr = TForm::cursor()->curr();
|
|
real valore;
|
|
if (_basecalcolo.empty())
|
|
{
|
|
const real cambio = TForm::find_field('B', odd_page, 666).get();
|
|
valore = curr.get_real(PROV_IMPRATA)*cambio;
|
|
}
|
|
else
|
|
{
|
|
const int nriga = curr.get_int(PROV_NRIGA);
|
|
if (nriga == 1)
|
|
init_pagamento();
|
|
const int nrata = curr.get_int(PROV_NRATA);
|
|
if (nrata > 0 && nrata <= _pagamento.n_rate())
|
|
valore = _pagamento.importo_rata(nrata-1);
|
|
}
|
|
cf.set(valore.string());
|
|
}
|
|
return TForm::validate(cf, s);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TStampa_schedeprovv_mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TStampa_schedeprovv_mask : public TAutomask
|
|
{
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
public:
|
|
TStampa_schedeprovv_mask() : TAutomask("pr1300a") {}
|
|
};
|
|
|
|
bool TStampa_schedeprovv_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
if (e == fe_button && o.dlg() == DLG_PREVIEW) // Anteprima
|
|
{ stop_run('A'); }
|
|
return true;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TStampa_schedeprovv
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TStampa_schedeprovv : public TSkeleton_application
|
|
{
|
|
TMask * _m;
|
|
|
|
protected:
|
|
void riporta_pagamenti(TCursor &cur);
|
|
void print_or_preview(bool paper);
|
|
|
|
virtual void print() { print_or_preview(true); }
|
|
virtual void preview() { print_or_preview(false); }
|
|
|
|
public:
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual void main_loop();
|
|
};
|
|
|
|
bool TStampa_schedeprovv::create()
|
|
{
|
|
open_files(LF_CFVEN, LF_DOC, LF_RIGHEDOC, LF_CONDV, LF_RCONDV, LF_ANAMAG,
|
|
LF_SCONTI, LF_UMART, LF_TAB, LF_TABCOM, LF_CLIFO, LF_INDSP,
|
|
LF_OCCAS, LF_PCON, LF_MOVMAG, LF_RMOVMAG, LF_MAG, LF_SVRIEP,
|
|
LF_AGENTI, LF_PERCPROV, LF_ATTIV, LF_CAUSALI, 0);
|
|
|
|
_m = new TStampa_schedeprovv_mask;
|
|
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
bool TStampa_schedeprovv::destroy()
|
|
{
|
|
delete _m;
|
|
return TSkeleton_application::destroy();
|
|
}
|
|
|
|
void TStampa_schedeprovv::riporta_pagamenti(TCursor &cur)
|
|
{
|
|
TLocalisamfile& fprov = cur.file();
|
|
TRectype& prov = fprov.curr();
|
|
const TRecnotype tot = cur.items();
|
|
TProgress_monitor barra(tot, TR("Registrazione delle provvigioni pagate"));
|
|
|
|
TDate oggi = _m->get(F_ADATA);
|
|
if (!oggi.ok())
|
|
oggi = TDate(TODAY);
|
|
|
|
for (cur = 0; cur.pos() < tot; ++cur)
|
|
{
|
|
if (!barra.add_status())
|
|
break;
|
|
// stampa definitiva: riporta le provvigioni maturate sulle provv. pagate
|
|
real provv_pag = prov.get_real(PROV_PROVVMAT);
|
|
real pag_pag = prov.get_real(PROV_PAGMAT);
|
|
if (!provv_pag.is_zero()
|
|
&& !prov.get_bool(PROV_SALDATA)) // this should never happen!
|
|
{
|
|
fprov.reread(_lock);
|
|
provv_pag += prov.get_real(PROV_PROVVPAG);
|
|
pag_pag += prov.get_real(PROV_PAGATO);
|
|
prov.put(PROV_PROVVPAG,provv_pag);
|
|
prov.put(PROV_PROVVMAT,0);
|
|
prov.put(PROV_PAGATO,pag_pag);
|
|
prov.put(PROV_PAGMAT,0);
|
|
if (provv_pag>=prov.get_real(PROV_IMPPROVV))
|
|
prov.put(PROV_SALDATA,"X");
|
|
if (prov.exist(PROV_DATASTAMPA))
|
|
prov.put(PROV_DATASTAMPA, oggi);
|
|
fprov.rewrite();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TStampa_schedeprovv::print_or_preview(bool paper)
|
|
{
|
|
const TPrtype pt = printer().printtype(); // save printer mode
|
|
if (paper == (pt == screenvis))
|
|
{
|
|
if (paper)
|
|
printer().set_printtype(winprinter);
|
|
else
|
|
printer().set_printtype(screenvis);
|
|
}
|
|
|
|
TStampa_schedeprovv_form frm("pr1300a");
|
|
|
|
const int hh = 7;
|
|
const int fh = 1;
|
|
const int fl = printer().formlen();
|
|
|
|
int rows[4]; // Righe orizzontali
|
|
rows[0] = hh-3;
|
|
rows[1] = hh;
|
|
rows[2] = fl-1;
|
|
rows[3] = 0;
|
|
frm.genera_intestazioni(odd_page, hh-2);
|
|
frm.genera_fincatura(odd_page, hh-3, fl-1, rows);
|
|
|
|
// filtro e regione
|
|
TString filter;
|
|
|
|
if (_m->get(F_FILTRO).full())
|
|
{
|
|
filter = PROV_SALDATA;
|
|
if (_m->get(F_FILTRO)[0]=='P')
|
|
filter << "==\"X\"" ;
|
|
else
|
|
filter << "!=\"X\"" ;
|
|
}
|
|
if (_m->get_bool(F_NOZERO))
|
|
{
|
|
const bool not_empty = filter.not_empty();
|
|
if (not_empty)
|
|
{
|
|
filter.insert("(");
|
|
filter << ") && (";
|
|
}
|
|
filter << "STR(" << PROV_IMPPROVV << ">0)"; // It was (PROV_IMPPRDOC!=0)
|
|
if (not_empty)
|
|
filter << ")";
|
|
}
|
|
if (_m->get(F_DADATA).not_empty() || _m->get(F_ADATA).not_empty())
|
|
{
|
|
const bool not_empty = filter.not_empty();
|
|
if (not_empty)
|
|
{
|
|
filter.insert("(");
|
|
filter << ") && (";
|
|
}
|
|
/*
|
|
TDate datam;
|
|
if (_m->get(F_DADATA).not_empty())
|
|
{
|
|
datam = _m->get_date(F_DADATA);
|
|
filter << "(ANSI(" << PROV_DATADOC << ")>=\"" << datam.string(ANSI) << "\")";
|
|
if (_m->get(F_ADATA).not_empty())
|
|
filter << " && ";
|
|
}
|
|
if (_m->get(F_ADATA).not_empty())
|
|
{
|
|
datam = _m->get_date(F_ADATA);
|
|
filter << "(ANSI(" << PROV_DATADOC << ")<=\"" << datam.string(ANSI) << "\")";
|
|
}
|
|
*/
|
|
if (!_m->field(F_DADATA).empty() || !_m->field(F_ADATA).empty())
|
|
{
|
|
filter << "BETWEEN(" << PROV_DATADOC
|
|
<< ',' << _m->get_date(F_DADATA).date2ansi()
|
|
<< ',' << _m->get_date(F_ADATA).date2ansi()
|
|
<< ")";
|
|
}
|
|
if (not_empty)
|
|
filter << ")";
|
|
}
|
|
|
|
// aggiungo comunque il file alla relazione perche' mi serve avere il documento sempre
|
|
frm.cursor()->relation()->add(LF_DOC, "CODNUM==CODNUM|ANNO==ANNO|PROVV==\"D\"|NDOC==NDOC");
|
|
|
|
const TString& tipodoc = _m->get(F_TIPODOC);
|
|
if (tipodoc.full())
|
|
{
|
|
bool not_empty = filter.full();
|
|
if (not_empty)
|
|
{
|
|
filter.insert("(");
|
|
filter << ") && (";
|
|
}
|
|
|
|
filter << LF_DOC << "->TIPODOC == \"" << tipodoc << "\"";
|
|
|
|
if (not_empty)
|
|
filter << ")";
|
|
|
|
frm.cursor()->setfilter(filter, TRUE);
|
|
}
|
|
else
|
|
frm.cursor()->setfilter(filter);
|
|
|
|
TRectype start(LF_PROVV),end(LF_PROVV);
|
|
start.put(PROV_CODAGE, _m->get(F_DAAGE));
|
|
end.put(PROV_CODAGE, _m->get(F_AAGE));
|
|
frm.cursor()->setregion(start, end);
|
|
frm.cursor()->freeze(true);
|
|
|
|
frm.set_basecalcolo(_m->get(F_FORMULA));
|
|
|
|
// abilita le sezioni dei totali
|
|
frm.find_field('B',odd_page,"CLIENTI").show(!_m->get_bool(F_RAGGCLI));
|
|
frm.find_field('B',odd_page,"HCLIENTI").show(!_m->get_bool(F_RAGGDOC));
|
|
frm.find_field('B',odd_page,"DOCUMENTI").show(!_m->get_bool(F_RAGGDOC));
|
|
frm.find_field('B',odd_page,"HDOCUMENTI").show(!_m->get_bool(F_RAGGRATE));
|
|
frm.find_field('B',odd_page,"RATEDOC").show(!_m->get_bool(F_RAGGRATE));
|
|
frm.print();
|
|
if (_m->get(F_DEFINITIVA)[0]=='D')
|
|
{
|
|
if (yesno_box(TR("Si desidera procedere con il riporto definitivo degli importi maturati nei pagamenti?")))
|
|
riporta_pagamenti(*frm.cursor());
|
|
}
|
|
|
|
frm.cursor()->freeze(false);
|
|
|
|
|
|
printer().set_printtype(pt); // Restore printer mode
|
|
}
|
|
|
|
void TStampa_schedeprovv::main_loop()
|
|
{
|
|
KEY k;
|
|
while ((k = _m->run()) != K_QUIT)
|
|
{
|
|
print_or_preview(k == K_ENTER);
|
|
}
|
|
}
|
|
|
|
int pr1300(int argc, char* argv[])
|
|
{
|
|
TStampa_schedeprovv a;
|
|
a.run(argc,argv,TR("Stampa schede di provvigione"));
|
|
return 0;
|
|
}
|