2405e00496
Files correlati :lv2.exe Ricompilazione Demo : [ ] Commento : Gestione Val convenzionale in fatturazione git-svn-id: svn://10.65.10.50/trunk@18701 c028cbd2-c16b-5b4b-a496-9718f37d4682
545 lines
16 KiB
C++
Executable File
545 lines
16 KiB
C++
Executable File
#include <progind.h>
|
||
#include <config.h>
|
||
|
||
#include "lvlib.h"
|
||
#include "lv2500a.h"
|
||
|
||
#include "cfven.h"
|
||
#include "lvcondv.h"
|
||
#include "lvrcondv.h"
|
||
#include "rdoc.h"
|
||
|
||
|
||
#include "../ve/ve6200.h"
|
||
#include "../ve/ve6200a.h"
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TFatturazione_lavanderie
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TFatturazione_lavanderie:public TFatturazione_bolle
|
||
{
|
||
TDate _data_elab;
|
||
TToken_string _campi_raggruppamento;
|
||
|
||
|
||
protected:
|
||
virtual void add_rows(TRiga_documento & rout, TRiga_documento & rin);
|
||
virtual void create_row(TDocumento& doc_out, const TRiga_documento & rin);
|
||
virtual void pre_process_input(TLista_documenti& doc_in) {}
|
||
virtual void post_process_input(TLista_documenti& doc_out) {}
|
||
virtual void post_process_output(TLista_documenti& doc_out);
|
||
virtual bool da_raggruppare(const TRiga_documento & rin);
|
||
virtual bool doc_raggruppabili(const TDocumento& doc_in, const TDocumento& doc_out, TToken_string& campi) const ;
|
||
virtual bool doc_raggruppabile(const TDocumento & doc) const { return true; }
|
||
virtual void campi_raggruppamento_righe(TToken_string& campi_riga) const;
|
||
virtual bool gestione_riferimenti() const { return true; }
|
||
virtual bool riferimenti_in_testa() const { return true; }
|
||
virtual TRiga_documento& find_or_create_row(TDocumento& doc_out, const TRiga_documento & rin,const char lavtype);
|
||
|
||
public:
|
||
virtual bool elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
||
const TDate& data_elab, bool interattivo = false);
|
||
|
||
TFatturazione_lavanderie(const char* cod);
|
||
~TFatturazione_lavanderie() {}
|
||
};
|
||
|
||
TFatturazione_lavanderie::TFatturazione_lavanderie(const char* cod)
|
||
: TFatturazione_bolle(cod)
|
||
|
||
{
|
||
}
|
||
|
||
bool TFatturazione_lavanderie::doc_raggruppabili(const TDocumento& doc_in, const TDocumento& doc_out, TToken_string& campi) const
|
||
{
|
||
if (doc_in.ha_riga_esenzione() != doc_out.ha_riga_esenzione())
|
||
return false;
|
||
bool ok = true;
|
||
TString campo;
|
||
|
||
for (const char* c = campi.get(0); c && ok; c = campi.get())
|
||
{
|
||
if (strncmp(c, "CODABI", 6) == 0 || strncmp(c, "CODCAB", 6) == 0)
|
||
{
|
||
long cod = doc_in.get_long(c);
|
||
ok &= (cod == doc_out.get_long(c));
|
||
}
|
||
else
|
||
{
|
||
campo = doc_in.get(c);
|
||
ok &= campo == doc_out.get(c);
|
||
}
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TFatturazione_lavanderie::da_raggruppare(const TRiga_documento & rin)
|
||
{
|
||
/* const long clifo = rin.doc().get_long(DOC_CODCF);
|
||
const int indsped = rin.doc().get_int(DOC_CODINDSP);
|
||
TLaundry_contract contr(clifo, indsped, _data_elab);
|
||
const TString80 codart = rin.get(RDOC_CODART);
|
||
const TRectype & rcont = contr.row(codart);
|
||
const int tipoforf = rcont.get_int(LVRCONDV_TIPOFORF);
|
||
|
||
// return tipoforf > 1; // Test originale
|
||
if (tipoforf > 1)
|
||
return true;
|
||
|
||
// Da qui in poi e' sottinteso tipoforf == 1
|
||
if (ini_get_int(CONFIG_DITTA, "lv", "TipoPr") == 1)
|
||
return false;
|
||
|
||
// Test GUY
|
||
const TString8 causale = rin.get(RDOC_CODAGG1);
|
||
const TRectype& cau = cache().get("&CAU", causale);
|
||
if (cau.get_bool("B1"))
|
||
{
|
||
const TCausale_magazzino& con = cached_causale_magazzino(cau.get("S2"));
|
||
if (con.sgn(s_dottm)) // Causale di incremento sotazione temporanea
|
||
return true;
|
||
}
|
||
|
||
if (cau.get_bool("B4")) // Causale di rotto
|
||
return true; */
|
||
|
||
return false;
|
||
}
|
||
|
||
|
||
void TFatturazione_lavanderie::post_process_output(TLista_documenti& doc_out)
|
||
{
|
||
for (int id = 0; id < doc_out.items(); id++)
|
||
{
|
||
TDocumento& doc = doc_out[id];
|
||
const long clifo = doc.get_long(DOC_CODCF);
|
||
const int indsped = doc.get_int(DOC_CODINDSP);
|
||
TLaundry_contract contr(clifo,indsped,_data_elab);
|
||
|
||
for (int i = 1; i <= doc.physical_rows(); i++)
|
||
{
|
||
TRiga_documento& rout = doc[i];
|
||
const TString80 codart=rout.get(RDOC_CODART);
|
||
const TRectype & rcont=contr.row(codart);
|
||
const TString4 tipodot = rcont.get(LVRCONDV_NOLCIC);
|
||
const TString4 artcli = rcont.get(LVRCONDV_VCARTCLI);
|
||
real dot;
|
||
const int annoes = _data_elab.year();
|
||
TArticolo_lavanderie artlav(codart, 'C', clifo, indsped);
|
||
|
||
const int index = artlav.find_clifomag(annoes);
|
||
|
||
if (index >=0)
|
||
{
|
||
if (tipodot=="I")
|
||
dot=artlav.clifomag(annoes)[index].get_real("DOTIN");
|
||
else
|
||
dot=artlav.clifomag(annoes)[index].get_real("DOTOD");
|
||
}
|
||
|
||
const int tipoforf = rcont.get_int(LVRCONDV_TIPOFORF);
|
||
|
||
switch (tipoforf)
|
||
{
|
||
case 0:
|
||
break;
|
||
case 1:
|
||
{
|
||
// rout.put(RDOC_QTA, UNO);
|
||
rout.put(RDOC_PREZZO, rcont.get_real(LVRCONDV_IMPFISART));
|
||
// gestione in base codice per valore fisso ??? tolta la scelta dell'articolo o del cliente
|
||
}
|
||
break;
|
||
case 2:
|
||
{
|
||
TRiga_documento& nolorow=doc.insert_row(++i, "01");
|
||
doc.copy_data(nolorow,rout);
|
||
TString80 descr("Nolo");
|
||
const int contrper = contr.get_int(LVCONDV_PERFAT);
|
||
|
||
switch (contrper)
|
||
{
|
||
case 0:
|
||
descr << " per il giorno";
|
||
break;
|
||
case 1:
|
||
descr << " per la settimana";
|
||
break;
|
||
case 2:
|
||
descr << " per la quindicina";
|
||
break;
|
||
case 3:
|
||
descr << " per il mese";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
nolorow.put(RDOC_DESCR,descr);
|
||
|
||
nolorow.put(RDOC_QTA, dot);
|
||
nolorow.put(RDOC_PREZZO, rcont.get_real(LVRCONDV_PREZNOL));
|
||
}
|
||
break;
|
||
case 3:
|
||
{
|
||
const real qta=rout.get(RDOC_QTA);
|
||
const real consumo=qta * rout.get_real(RDOC_PREZZO);
|
||
const real ciclaggio=dot * rcont.get_real(LVRCONDV_PREZZO) * rcont.get_real(LVRCONDV_MINCIC);
|
||
if (consumo<ciclaggio)
|
||
{
|
||
const bool cicl2rig=contr.get_bool(LVCONDV_CICLAGGIO);
|
||
const real cicl=rcont.get_real(LVRCONDV_MINCIC)*dot;
|
||
if (cicl2rig)
|
||
{
|
||
TRiga_documento& congrow=doc.insert_row(++i, "01");
|
||
doc.copy_data(congrow,rout);
|
||
congrow.put(RDOC_DESCR,"Pareggio minimo ciclaggio");
|
||
congrow.put(RDOC_QTA, cicl-qta);
|
||
congrow.put(RDOC_PREZZO, rcont.get_real(LVRCONDV_PREZZO));
|
||
}
|
||
else
|
||
{
|
||
rout.put(RDOC_QTA, cicl);
|
||
rout.put(RDOC_PREZZO, rcont.get_real(LVRCONDV_PREZZO));
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 4:
|
||
{
|
||
const real qta=rout.get(RDOC_QTA);
|
||
const real consumo=qta * rout.get_real(RDOC_PREZZO);
|
||
const real impconv=dot * rcont.get_real(LVRCONDV_VALCONV) * rcont.get_real(LVRCONDV_FORFPERCL);
|
||
if (consumo<impconv)
|
||
{
|
||
const bool cicl2rig=contr.get_bool(LVCONDV_CICLAGGIO);
|
||
if (cicl2rig)
|
||
{
|
||
TRiga_documento& congrow=doc.insert_row(++i, "01");
|
||
doc.copy_data(congrow,rout);
|
||
congrow.put(RDOC_DESCR,"Conguaglio valore convenzionale");
|
||
congrow.put(RDOC_PREZZO, rcont.get_real(LVRCONDV_PREZZO));
|
||
}
|
||
else
|
||
{
|
||
rout.put(RDOC_QTA, UNO);
|
||
rout.put(RDOC_PREZZO, impconv);
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 5:
|
||
{
|
||
rout.put(RDOC_PREZZO, rcont.get_real(LVRCONDV_PREZZO));
|
||
|
||
rout.put(RDOC_QTA, dot);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
void TFatturazione_lavanderie::add_rows(TRiga_documento & rout, TRiga_documento & rin)
|
||
{
|
||
/*const TString8 causale = rin.get(RDOC_CODAGG1);
|
||
const TRectype& cau = cache().get("&CAU", causale);
|
||
const TCausale_magazzino& rit = cached_causale_magazzino(cau.get("S1"));
|
||
const TCausale_magazzino& con = cached_causale_magazzino(cau.get("S2")); //movimento o meno la dotazione temporanea/odierna a seconda di cosa prevede la causale
|
||
|
||
const long clifo = rin.doc().get_long(DOC_CODCF);
|
||
const int indsped = rin.doc().get_int(DOC_CODINDSP);
|
||
TLaundry_contract contr(clifo, indsped, _data_elab);
|
||
|
||
if (cau.get_bool("B4") && contr.get_int(LVCONDV_ADDCAPROT)) // Guardo se <20> una causale di rotto e se <20> abilitato nella testata del contratto la fatturazione dei rotti
|
||
{
|
||
const real qta = rit.sgn(s_consmese) * rin.get_real(RDOC_QTA);
|
||
rout.put(RDOC_PREZZO,contr.get_int(LVCONDV_PREZROT));
|
||
rout.add(RDOC_QTA, qta);
|
||
}
|
||
else
|
||
{
|
||
if (cau.get_bool("B0"))
|
||
{
|
||
const real qta = rit.sgn(s_consmese) * rin.get_real(RDOC_QTA);
|
||
rout.add(RDOC_QTA, qta);
|
||
|
||
}
|
||
if (cau.get_bool("B1"))
|
||
{
|
||
const real qta = con.sgn(s_consmese) * rin.get_real(RDOC_QTA);
|
||
rout.add(RDOC_QTA, qta);
|
||
}
|
||
} */
|
||
}
|
||
|
||
void TFatturazione_lavanderie::campi_raggruppamento_righe(TToken_string& campi_riga) const
|
||
{
|
||
TFatturazione_bolle::campi_raggruppamento_righe(campi_riga);
|
||
if (campi_riga.empty())
|
||
campi_riga = "CODART|UMQTA"; // Uguali sempre
|
||
}
|
||
|
||
TRiga_documento& TFatturazione_lavanderie::find_or_create_row(TDocumento& doc_out, const TRiga_documento & rin,const char lavtype)
|
||
{
|
||
const TString80 codart=rin.get(RDOC_CODARTMAG);
|
||
int r;
|
||
|
||
for (r=doc_out.physical_rows();r>0;r--)
|
||
if (doc_out[r].raggruppabile(rin, _campi_raggruppamento) && (doc_out[r].get_char("LVTYPE") == lavtype))
|
||
break;
|
||
if (r<=0)
|
||
{
|
||
TRiga_documento& row=doc_out.new_row("01");
|
||
doc_out.copy_data(row,rin);
|
||
row.put(RDOC_TIPORIGA, "01");
|
||
row.zero(RDOC_CODAGG1);
|
||
row.zero(RDOC_QTA);
|
||
row.zero(RDOC_QTAGG1);
|
||
row.zero(RDOC_CODMAGC);
|
||
row.put("LVTYPE",lavtype);
|
||
r=row.get_int(RDOC_NRIGA);
|
||
|
||
}
|
||
|
||
return doc_out[r];
|
||
|
||
}
|
||
|
||
void TFatturazione_lavanderie::create_row(TDocumento& doc_out, const TRiga_documento & rin)
|
||
{
|
||
const TString8 causale = rin.get(RDOC_CODAGG1);
|
||
const TRectype& cau = cache().get("&CAU", causale);
|
||
|
||
const long clifo = rin.doc().get_long(DOC_CODCF);
|
||
const int indsped = rin.doc().get_int(DOC_CODINDSP);
|
||
TLaundry_contract contr(clifo, indsped, _data_elab);
|
||
|
||
const TString80 codart=rin.get(RDOC_CODARTMAG);
|
||
const real qta=rin.get_real(RDOC_QTA);
|
||
const real qta1=rin.get_real(RDOC_QTAGG1);
|
||
const TRectype & rcont=contr.row(codart);
|
||
const int tipoprezzo=ini_get_int(CONFIG_DITTA, "lv", "TipoPr");
|
||
real prezzo=rin.get_real(RDOC_PREZZO);
|
||
|
||
if (tipoprezzo == 0)
|
||
{
|
||
if (rcont.empty())
|
||
{
|
||
TArticolo& art=cached_article(codart);
|
||
const TString& um=rin.get(RDOC_UMQTA);
|
||
const int index=art.find_um(um);
|
||
|
||
if (index>=0)
|
||
prezzo=art.um()[index].get_real(UMART_PREZZO);
|
||
|
||
}
|
||
else
|
||
prezzo=rcont.get_real(LVRCONDV_PREZZO);
|
||
}
|
||
|
||
// Guardo se <20> una causale di rotto e se <20> abilitato nella testata del contratto la fatturazione dei rotti
|
||
if (cau.get_bool("B3") && contr.get_int(LVCONDV_ADDCAPROT) && !qta1.is_zero())
|
||
{
|
||
TRiga_documento& rd=find_or_create_row(doc_out,rin,'D');
|
||
rd.add(RDOC_QTA, qta1);
|
||
rd.put(RDOC_PREZZO,contr.row(codart).get_real(LVRCONDV_PREZDAN));
|
||
}
|
||
|
||
if (cau.get_bool("B0") && !qta1.is_zero()) // movimenta ritirato
|
||
{
|
||
const TCausale_magazzino& rit = cached_causale_magazzino(cau.get("S1"));
|
||
const real sgnrit = rit.sgn(s_consmese);
|
||
if (!sgnrit.is_zero())
|
||
{
|
||
TRiga_documento& rr=find_or_create_row(doc_out,rin,'C');
|
||
rr.add(RDOC_QTA,sgnrit * qta1);
|
||
rr.put(RDOC_PREZZO,prezzo);
|
||
}
|
||
}
|
||
if (cau.get_bool("B1") && !qta.is_zero()) // movimenta consegnato
|
||
{
|
||
const TCausale_magazzino& con = cached_causale_magazzino(cau.get("S2"));
|
||
|
||
const real sgntmp=con.sgn(s_dottm);
|
||
if (!sgntmp.is_zero() && contr.get_bool(LVCONDV_DOTTMPPRZD))
|
||
{
|
||
TRiga_documento& rt=find_or_create_row(doc_out,rin,'T');
|
||
rt.add(RDOC_QTA,sgntmp * qta);
|
||
rt.put(RDOC_PREZZO,contr.row(codart).get_real(LVRCONDV_PRZDTTMP));
|
||
}
|
||
|
||
const real sgndotin=con.sgn(s_dotin);
|
||
if (!sgndotin.is_zero())
|
||
{
|
||
TRiga_documento& rc=find_or_create_row(doc_out,rin,'I');
|
||
rc.add(RDOC_QTA,sgndotin * qta);
|
||
rc.put(RDOC_PREZZO,prezzo);
|
||
}
|
||
|
||
const real sgncons=con.sgn(s_consmese);
|
||
if (!sgncons.is_zero())
|
||
{
|
||
TRiga_documento& rc=find_or_create_row(doc_out,rin,'C');
|
||
rc.add(RDOC_QTA,sgncons * qta);
|
||
rc.put(RDOC_PREZZO,prezzo);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
bool TFatturazione_lavanderie::elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
||
const TDate& data_elab, bool interattivo)
|
||
{
|
||
_data_elab = data_elab;
|
||
campi_raggruppamento_righe(_campi_raggruppamento);
|
||
return TFatturazione_bolle::elabora(doc_in, doc_out, data_elab, interattivo);
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TFatturazione_msk
|
||
///////////////////////////////////////////////////////////
|
||
|
||
|
||
class TFatturazione_msk: public TAutomask
|
||
{
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o,TField_event e,long jolly){return true;}
|
||
public:
|
||
TFatturazione_msk();
|
||
};
|
||
|
||
TFatturazione_msk::TFatturazione_msk():TAutomask("lv2500a")
|
||
{
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TFatturazione_lav_app
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TFatturazione_lav_app: public TSkeleton_application
|
||
{
|
||
protected:
|
||
virtual void main_loop();
|
||
};
|
||
|
||
void TFatturazione_lav_app::main_loop()
|
||
{
|
||
TFatturazione_msk msk;
|
||
const TString4 mskzona=msk.get(F_CODZONA);
|
||
const TString4 mskcat=(F_CODCATC);
|
||
|
||
TLocalisamfile doc(LF_DOC);
|
||
TLocalisamfile rdoc(LF_RIGHEDOC);
|
||
|
||
while (msk.run()!=K_QUIT)
|
||
{
|
||
TString query;
|
||
//&&(BETWEEN(DATADOC,#DADATA,#ADATA))&&(STATO==\"2\")&&(TIPODOC==\"B01\")
|
||
query << "USE DOC KEY 3 SELECT (TIPOCF==\"C\")\n"
|
||
<< "BY TIPOCF CODCF DATADOC\n"
|
||
<< "FROM " << "DATADOC=#DADATA PROVV=D ANNO=#ANNO\n"
|
||
<< "TO " << " DATADOC=#ADATA PROVV=D ANNO=#ANNO\n";
|
||
// query << "USE DOC KEY 2 SELECT BETWEEN(DATADOC,#DADATA,#ADATA)&&STATO==\"2\")&&(TIPODOC==\"B01\")\n"
|
||
// << "FROM " << "TIPOCF=C PROVV=D ANNO=#ANNO DATADOC=#DADATA \n"
|
||
// << "TO " << "TIPOCF=C PROVV=D ANNO=#ANNO DATADOC=#ADATA \n";
|
||
|
||
TISAM_recordset recset(query);
|
||
TDate al = msk.get_date(F_ADATA);
|
||
|
||
if (!al.ok())
|
||
al = msk.get_date(F_DATAFAT);
|
||
TDate dal = msk.get_date(F_DADATA);
|
||
const long year = al.year();
|
||
|
||
if (!dal.ok())
|
||
{
|
||
dal.set_day(1);
|
||
dal.set_month(1);
|
||
dal.set_year(year);
|
||
}
|
||
recset.set_var("#DADATA", dal);
|
||
recset.set_var("#ADATA", al);
|
||
recset.set_var("#ANNO", year);
|
||
|
||
TFatturazione_lavanderie elab(msk.get(F_COD_ELAB));
|
||
TLista_documenti docsin;
|
||
TLista_documenti docsout;
|
||
long lastcli=0;
|
||
const int period=msk.get_int(F_PERFAT);
|
||
const TDate datafat=msk.get_date(F_DATAFAT);
|
||
long indsped;
|
||
|
||
for (bool ok = recset.move_first(); ok; ok = recset.move_next())
|
||
{
|
||
const long clifo = recset.get(DOC_CODCF).as_int();
|
||
|
||
if (clifo != lastcli)
|
||
{
|
||
if (docsin.items()!=0)
|
||
{
|
||
elab.elabora(docsin, docsout, datafat);
|
||
docsout.write();
|
||
docsout.destroy(-1) ;
|
||
docsin.rewrite();
|
||
docsin.destroy(-1);
|
||
}
|
||
lastcli = clifo;
|
||
}
|
||
|
||
TToken_string key;
|
||
|
||
key.add('C');
|
||
key.add(clifo);
|
||
const TRectype& clienti=cache().get(LF_CFVEN,key);
|
||
bool cliok=elab.is_document_ok(recset.cursor()->curr());
|
||
|
||
if (cliok)
|
||
{
|
||
if (mskzona.full())
|
||
{
|
||
const TString& codzona=clienti.get(CFV_CODZONA);
|
||
cliok = (codzona==mskzona);
|
||
}
|
||
if (cliok && mskcat.full())
|
||
{
|
||
const TString& codcat=clienti.get(CFV_CODCATC);
|
||
cliok= (codcat==mskcat);
|
||
}
|
||
}
|
||
|
||
if (cliok)
|
||
{
|
||
indsped = recset.get(DOC_CODINDSP).as_int();
|
||
TLaundry_contract contr(clifo, indsped, datafat);
|
||
const int contrper = contr.get_int(LVCONDV_PERFAT);
|
||
|
||
if (!contr.get_bool(LVCONDV_FATTSOSP) && contrper <= period)
|
||
docsin.add(new TDocumento(recset.cursor()->curr()));
|
||
}
|
||
}
|
||
if (docsin.items()!=0)
|
||
{
|
||
elab.elabora(docsin, docsout, datafat);
|
||
docsout.write();
|
||
docsout.destroy(-1);
|
||
docsin.rewrite();
|
||
docsin.destroy(-1);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
int lv2500(int argc, char *argv[])
|
||
{
|
||
TFatturazione_lav_app a;
|
||
a.run (argc, argv, "Fatturazione lavanderie");
|
||
return TRUE;
|
||
}
|