From 252e8cd5716c617a90796aac7c3edb8437f11508 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 25 Oct 1995 09:46:13 +0000 Subject: [PATCH] Aggiunti files per gestione saldaconto extra-contabile git-svn-id: svn://10.65.10.50/trunk@2006 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- sc/sc0.cpp | 22 ++ sc/sc0.h | 1 + sc/sc0.url | 17 ++ sc/sc0100.cpp | 55 ++++ sc/sc0100.h | 44 ++++ sc/sc0100a.h | 13 + sc/sc0100a.uml | 158 ++++++++++++ sc/sc0100b.uml | 21 ++ sc/sc0101.cpp | 417 ++++++++++++++++++++++++++++++ sc/sc1200.cpp | 679 +++++++++++++++++++++++++------------------------ 10 files changed, 1088 insertions(+), 339 deletions(-) create mode 100755 sc/sc0.cpp create mode 100755 sc/sc0.h create mode 100755 sc/sc0.url create mode 100755 sc/sc0100.cpp create mode 100755 sc/sc0100.h create mode 100755 sc/sc0100a.h create mode 100755 sc/sc0100a.uml create mode 100755 sc/sc0100b.uml create mode 100755 sc/sc0101.cpp diff --git a/sc/sc0.cpp b/sc/sc0.cpp new file mode 100755 index 000000000..9b997980a --- /dev/null +++ b/sc/sc0.cpp @@ -0,0 +1,22 @@ +#include +#include + +#include + +#include "sc0.h" + +#define usage "Errore - uso : sc0 -{0}" + +int main(int argc,char** argv) +{ + const int n = (argc > 1) ? (atoi(&argv[1][1])) : 0; + + switch(n) + { + case 0: + sc0100(argc,argv); break; + default: + error_box(usage); + } + return 0; +} diff --git a/sc/sc0.h b/sc/sc0.h new file mode 100755 index 000000000..686d0b72d --- /dev/null +++ b/sc/sc0.h @@ -0,0 +1 @@ +int sc0100(int argc, char* argv[]); \ No newline at end of file diff --git a/sc/sc0.url b/sc/sc0.url new file mode 100755 index 000000000..a9ce52300 --- /dev/null +++ b/sc/sc0.url @@ -0,0 +1,17 @@ +#include + +MENU TASK_MENUBAR + SUBMENU MENU_FILE "~File" + +MENUBAR MENU_BAR(1) + +MENU MENU_BAR(1) + SUBMENU MENU_FILE "~File" + +MENUBAR MENU_BAR(2) + +MENU MENU_BAR(2) + SUBMENU MENU_FILE "~File" + + + diff --git a/sc/sc0100.cpp b/sc/sc0100.cpp new file mode 100755 index 000000000..a00725871 --- /dev/null +++ b/sc/sc0100.cpp @@ -0,0 +1,55 @@ +#include + +#include +#include + +#include "sc0100.h" + +bool TSaldaconto_app::create() +{ + open_files(LF_PARTITE, LF_SCADENZE, LF_PAGSCA, 0); + _msk = new TMask("sc0100a"); + dispatch_e_menu(MENU_ITEM(1)); + return TRUE; +} + +bool TSaldaconto_app::destroy() +{ + delete _msk; + close_files(); + return TRUE; +} + +void TSaldaconto_app::open_files(int logicnum, ...) +{ + va_list marker; + va_start(marker, logicnum); + while (logicnum > 0) + { + CHECKD(_file.objptr(logicnum) == NULL, "File gia' aperto: ", logicnum); + _file.add(new TLocalisamfile(logicnum), logicnum); + logicnum = va_arg(marker, int); + } +} + + +bool TSaldaconto_app::menu(MENU_TAG) +{ + KEY k; + TMask& m = curr_mask(); + + do + { + k = m.run(); + if (k == K_ENTER) + edit_partite(m); + } while (k != K_QUIT); + return 0; +} + +int sc0100(int argc, char* argv[]) +{ + TSaldaconto_app app; + app.run(argc, argv, "Gestione Saldaconto"); + return 0; +} \ No newline at end of file diff --git a/sc/sc0100.h b/sc/sc0100.h new file mode 100755 index 000000000..10cbd2dbc --- /dev/null +++ b/sc/sc0100.h @@ -0,0 +1,44 @@ +#ifndef __SC100_H +#define __SC100_H + +#ifndef __APPLICAT_H +#include +#endif + +#ifndef __SALDACON_H +#include "../cg/saldacon.h" +#endif + +#ifndef __MASK_H +class TMask; +#endif + +class TSaldaconto_app : public TApplication +{ + TMask* _msk; + TArray _file; + + TPartite_array _partite; + +protected: // TApplication + virtual bool create(); + virtual bool destroy(); + virtual bool menu(MENU_TAG tag); + +protected: + void open_files(int logicnum, ...); + void close_files() { _file.destroy(); } + + void edit_partite(const TMask& m); + +public: + TMask& curr_mask() { return *_msk; } + TPartite_array& partite() { return _partite; } + + TSaldaconto_app() : _file(32) {} + virtual ~TSaldaconto_app() {} +}; + +inline TSaldaconto_app& app() { return (TSaldaconto_app&)main_app(); } + +#endif diff --git a/sc/sc0100a.h b/sc/sc0100a.h new file mode 100755 index 000000000..30d49cf8d --- /dev/null +++ b/sc/sc0100a.h @@ -0,0 +1,13 @@ +#define F_TIPO 101 +#define F_GRUPPO 102 +#define F_CONTO 103 +#define F_SOTTOCONTO 104 +#define F_CLIENTE 204 +#define F_FORNITORE 304 +#define F_DESCR 105 +#define F_DESCRCLI 205 +#define F_DESCRFOR 305 +#define F_FATPAG 106 +#define F_ANNO 107 +#define F_NUMERO 108 +#define F_RIGA 109 \ No newline at end of file diff --git a/sc/sc0100a.uml b/sc/sc0100a.uml new file mode 100755 index 000000000..65c01007c --- /dev/null +++ b/sc/sc0100a.uml @@ -0,0 +1,158 @@ +#include "sc0100a.h" + +TOOLBAR "" 0 20 0 2 + +BUTTON DLG_OK 10 2 +BEGIN + PROMPT -12 -1 "" +END + +BUTTON DLG_QUIT 10 2 +BEGIN + PROMPT -22 -1 "" +END + +ENDPAGE + +PAGE "Selezione partite" -1 -1 77 20 + +LIST F_TIPO 1 12 +BEGIN + PROMPT 1 1 "Tipo conto " + ITEM " |Conto" + MESSAGE SHOW,1@|RESET,1@|HIDE,2@|HIDE,3@ + ITEM "C|Cliente" + MESSAGE HIDE,1@|SHOW,2@|RESET,2@|HIDE,3@ + ITEM "F|Fornitore" + MESSAGE HIDE,1@|HIDE,2@|SHOW,3@|RESET,3@ +END + +NUMBER F_GRUPPO 3 +BEGIN + PROMPT 26 1 "Gruppo " + USE LF_PCON SELECT CONTO=="" + INPUT GRUPPO F_GRUPPO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Descrizione@50" DESCR + OUTPUT F_GRUPPO GRUPPO + CHECKTYPE REQUIRED + ADD RUN cg0 -0 +END + +NUMBER F_CONTO 3 +BEGIN + PROMPT 40 1 "Conto " + USE LF_PCON SELECT (CONTO!="")&&(SOTTOCONTO="") + INPUT GRUPPO F_GRUPPO + INPUT CONTO F_CONTO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Descrizione@50" DESCR + DISPLAY "Tipo" TMCF + OUTPUT F_TIPO TMCF + OUTPUT F_GRUPPO GRUPPO + OUTPUT F_CONTO CONTO + CHECKTYPE REQUIRED + ADD RUN cg0 -0 +END + +NUMBER F_SOTTOCONTO 6 +BEGIN + PROMPT 54 1 "Sottoconto " + USE LF_PCON SELECT SOTTOCONTO!="" + COPY INPUT F_CONTO + INPUT SOTTOCONTO F_SOTTOCONTO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + DISPLAY "Descrizione@50" DESCR + OUTPUT F_GRUPPO GRUPPO + OUTPUT F_CONTO CONTO + OUTPUT F_SOTTOCONTO SOTTOCONTO + OUTPUT F_DESCR DESCR + ADD RUN cg0 -0 + GROUP 1 + CHECKTYPE REQUIRED +END + +NUMBER F_CLIENTE 6 +BEGIN + PROMPT 54 1 "Cliente " + USE LF_CLIFO + INPUT TIPOCF "C" + INPUT CODCF F_CLIENTE + DISPLAY "Cliente" CODCF + DISPLAY "Descrizione@50" RAGSOC +// OUTPUT F_GRUPPO GRUPPO +// OUTPUT F_CONTO CONTO + OUTPUT F_CLIENTE CODCF + OUTPUT F_DESCRCLI RAGSOC + ADD RUN cg0 -1 C + GROUP 2 + CHECKTYPE REQUIRED + MESSAGE COPY,F_SOTTOCONTO +END + +NUMBER F_FORNITORE 6 +BEGIN + PROMPT 54 1 "Fornitore " + USE LF_CLIFO + INPUT TIPOCF "F" + INPUT CODCF F_FORNITORE + DISPLAY "Fornitore" CODCF + DISPLAY "Descrizione@50" RAGSOC +// OUTPUT F_GRUPPO GRUPPO +// OUTPUT F_CONTO CONTO + OUTPUT F_FORNITORE CODCF + OUTPUT F_DESCRFOR RAGSOC + ADD RUN cg0 -1 F + GROUP 3 + CHECKTYPE REQUIRED + MESSAGE COPY,F_SOTTOCONTO +END + +STRING F_DESCR 50 58 +BEGIN + PROMPT 1 2 "Descrizione " + USE LF_PCON KEY 2 + INPUT DESCR F_DESCR + DISPLAY "Descrizione@50" DESCR + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + COPY OUTPUT F_SOTTOCONTO + CHECKTYPE REQUIRED + GROUP 1 + ADD RUN cg0 -0 +END + +STRING F_DESCRCLI 50 58 +BEGIN + PROMPT 1 2 "Descrizione " + USE LF_CLIFO KEY 2 + INPUT TIPOCF "C" + INPUT RAGSOC F_DESCRCLI + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" CODCF + DISPLAY "Ragione sociale@50" RAGSOC + COPY OUTPUT F_CLIENTE + CHECKTYPE REQUIRED + GROUP 2 + ADD RUN cg0 -1 +END + +STRING F_DESCRFOR 50 58 +BEGIN + PROMPT 1 2 "Descrizione " + USE LF_PCON KEY 2 + INPUT TIPOCF "F" + INPUT RAGSOC F_DESCRFOR + COPY DISPLAY F_DESCRCLI + COPY OUTPUT F_FORNITORE + CHECKTYPE REQUIRED + GROUP 3 + ADD RUN cg0 -1 +END + +ENDMASK diff --git a/sc/sc0100b.uml b/sc/sc0100b.uml new file mode 100755 index 000000000..b15487191 --- /dev/null +++ b/sc/sc0100b.uml @@ -0,0 +1,21 @@ +#include "../cg/cg21sld.h" + +TOOLBAR "" 0 20 0 2 + +BUTTON DLG_OK 10 2 +BEGIN + PROMPT -12 -1 "" +END + +BUTTON DLG_CANCEL 10 2 +BEGIN + PROMPT -22 -1 "" +END + +ENDPAGE + +#include "../cg/cg21sld.uml" + +ENDMASK + +#include "../cg/cg21rata.uml" diff --git a/sc/sc0101.cpp b/sc/sc0101.cpp new file mode 100755 index 000000000..8b2ba4aa1 --- /dev/null +++ b/sc/sc0101.cpp @@ -0,0 +1,417 @@ +#include "../cg/conto.h" +#include "../cg/pagament.h" +#include "../cg/saldacon.h" +#include "../cg/cg21sld.h" + +#include "sc0100.h" +#include "sc0100a.h" + +#define __EXTRA__ +#include "../cg/cg2105.cpp" + +/////////////////////////////////////////////////////////// +// Maschera gestione rate +/////////////////////////////////////////////////////////// + +class TFattura_mask : public TMask +{ + TRiga_partite& _fattura; + TPagamento* _pag; + TString_array _pag_rows; + +protected: // TMask + virtual void start_run(); + virtual bool stop_run(KEY k); + +protected: + static bool pag_notify(TSheet_field& ps, int r, KEY k); + static bool pag_handler(TMask_field& f, KEY key); + static bool reset_handler(TMask_field& f, KEY key); + static bool recalc_handler(TMask_field& f, KEY key); + static bool nrate_handler(TMask_field& f, KEY key); + static bool codcab_handler(TMask_field& f, KEY key); + + TSheet_field& pag_sheet() const { return (TSheet_field&)field(FS_RATESHEET); } + + void read_scadenze(); + void write_scadenze() const; + +public: + TFattura_mask(TRiga_partite& fattura, const TString& codpag); + virtual ~TFattura_mask() {} +}; + +TFattura_mask::TFattura_mask(TRiga_partite& fattura, const TString& codpag) + : TMask("sc0100b"), _fattura(fattura), _pag(NULL) +{ + set_handler(FS_RESET, reset_handler); + set_handler(FS_RECALC, recalc_handler); + set_handler(FS_NRATE, nrate_handler); + set_handler(FS_NSCAB, codcab_handler); + set_handler(FS_VSCAB, codcab_handler); + + pag_sheet().set_notify(pag_notify); + pag_sheet().set_handler(pag_handler); + + const TRiga_partite& partita = _fattura; + const TString16 datadoc = partita.get(PART_DATADOC); + _pag = new TPagamento(codpag, datadoc); +} + +void TFattura_mask::start_run() +{ + read_scadenze(); +} + +bool TFattura_mask::stop_run(KEY k) +{ + const bool ok = TMask::stop_run(k); + if (ok && k == K_ENTER) + write_scadenze(); + return ok; +} + +bool TFattura_mask::pag_notify(TSheet_field& ps, int r, KEY k) +{ + if (k == K_INS || k == K_DEL) + return FALSE; + if (k != K_ENTER) + return TRUE; + + TFattura_mask& fm = (TFattura_mask&)ps.mask(); + TPagamento& pag = *fm._pag; + TString_array& rws = fm._pag_rows; + + const int rdiff = fm.get_int(FS_RDIFFER); + const bool in_valuta = pag.in_valuta(); + const int impos = in_valuta ? 2 : 1; + + bool doit = TRUE, m_imp = FALSE, m_perc = FALSE, m_pag = FALSE; + bool m_scad = FALSE, m_tipo = FALSE, mod = FALSE; + word ahiahi = P_OK; + + const bool recalc = fm.get_bool(FS_RECALC); + const bool mcomm = fm.get_bool(FS_MCOMM); + + TToken_string ns = ps.row(r); + TToken_string ts = rws.row(r); + + const TString news = ns.get(0); // Data scadenza + const TString newi = ns.get(impos); // Imponibile (lire o valuta) + const TString newp = ns.get(3); // Percentuale + const TString newt = ns.get(4); // Tipo pagamento + + // qui viene il bello, si fa per dire + if (news != ts.get(0)) // modificata data scadenza + mod = m_scad = TRUE; + if (newp != ts.get(3)) // modificata percentuale + mod = m_perc = TRUE; + if (newi != ts.get(impos)) // modificato importo + { + // se si modifica la percentuale l'importo non viene cagato + if ((recalc && !m_perc) || (!recalc)) + mod = m_imp = TRUE; + } + if (newt != ts.get(4)) // modificato tipo pagamento + mod = m_tipo = TRUE; + + + // settato da recalc_rate se occorre ridefinire lo sheet + // aggiungendo o togliendo righe + bool need_recalc = FALSE; + + if (mod && recalc) + { + // ricalcola sheet come sai fare tu + ahiahi = pag.recalc_rate(r, m_perc, + ((m_perc || m_imp) ? + (m_perc ? (const char*)newp : (const char*)newi) : + NULL), + (m_scad ? (const char*)news : NULL), + (m_tipo ? (const char*)newt : NULL), + rdiff, mcomm, need_recalc); + // see if rdiff changed + fm.set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2"); + fm.set(FS_NRATE, pag.n_rate()); + } + if (!recalc) + { + ahiahi = P_OK; + // put data as they are + TToken_string& trw = pag.rata(r); + TToken_string srw = trw; + if (m_tipo) trw.add(newt,2); + if (m_scad) trw.add(news,3); + if (m_imp) + { + trw.add(newi,4); + const real p = pag.recalc_percrata(r); + ps.row(r).add(p.string(), 3); + rws.row(r) = ps.row(r); + ps.force_update(r); + } + } + if (ahiahi) // any error? Rimetti le righe com'erano prima + { + if (recalc) + { + beep(); + ps.row(r) = rws.row(r); + ps.force_update(r); + } + } + else if (recalc && mod && need_recalc) + { + // ridefinisci lo sheet sulla base delle nuove rate + pag.set_sheet(ps); + rws = ps.rows_array(); + } + + return doit; +} + +bool TFattura_mask::pag_handler(TMask_field& f, KEY key) +{ + if (key == K_TAB || key == K_ENTER) + { + TFattura_mask& fm = (TFattura_mask&)f.mask(); + TPagamento& pag = *fm._pag; + const word err = pag.validate(); + if (err != P_OK) + { + TString256 s; + pag.strerr(err, s); + return error_box(s); + } + } + return TRUE; +} + +bool TFattura_mask::reset_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + TFattura_mask& fm = (TFattura_mask&)f.mask(); + if (fm._fattura.rate() == 0) + fm._pag->read(); + fm.read_scadenze(); + } + return TRUE; +} + +bool TFattura_mask::recalc_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + const bool on = f.get().not_empty(); + const TMask& m = f.mask(); + TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET); + ps.enable_column(3, on); + } + + return TRUE; +} + +bool TFattura_mask::nrate_handler(TMask_field& f, KEY key) +{ + if (key == K_TAB && f.focusdirty()) + { + TFattura_mask& fm = (TFattura_mask&)f.mask(); + TPagamento& pag = *fm._pag; + + pag.set_numero_rate(atoi(f.get())); + if (pag.dirty()) + { + TSheet_field& ps = (TSheet_field&)fm.field(FS_RATESHEET); + pag.set_sheet(ps); + } + } + return TRUE; +} + +bool TFattura_mask::codcab_handler(TMask_field& f, KEY key) +{ + if (key == K_TAB && f.focusdirty()) + { + const TMask& m = f.mask(); + const short id = f.dlg() == FS_NSCAB ? FS_NSABI : FS_VSABI; + const int pos = id == FS_NSABI ? 6 : 8; + const TString16 abi = m.get(id); + const TString16 cab = m.get(id+1); + TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET); + for (int i = ps.items()-1; i >= 0; i--) + { + TToken_string& row = ps.row(i); + row.add(abi, pos); + row.add(cab, pos+1); + } + ps.force_update(); + } + + return TRUE; +} + +void TFattura_mask::read_scadenze() +{ + TRiga_partite& partita = _fattura; + TPagamento& pag = *_pag; + TSheet_field& ps = pag_sheet(); + + real imponibile, imposte, spese, cambio; + + if (partita.in_valuta()) + { + imponibile = partita.get_real(PART_IMPORTOVAL); + cambio = partita.get_real(PART_CAMBIO); + + real imp = imponibile; + imp *= cambio; + imp.round(); + set(FS_IMPONIBILI, imp); + } + else + { + imponibile = partita.get_real(PART_IMPORTO); + set(FS_IMPONIBILI, imponibile); + } + + pag.set_total(imponibile, imposte, spese); + pag.set_cambio(cambio); + + if (partita.rate() > 0) + { + pag.zap_rate(); + for (int i = 1; i <= partita.rate(); i++) + { + const TRiga_scadenze& scadenza = partita.rata(i); + real importo = scadenza.get(SCAD_IMPORTO); + const TDate scad = scadenza.get(SCAD_DATASCAD); + const int tipop = scadenza.get_int(SCAD_TIPOPAG); + const bool paid = scadenza.get_bool(SCAD_PAGATA); + const TString16 ulc = scadenza.get(SCAD_ULTCLASS); + if (scadenza.in_valuta()) + { + const real impval(scadenza.get(SCAD_IMPORTOVAL)); + pag.set_rata(i-1, impval, importo, scad, tipop, ulc, paid); + } + else + pag.set_rata(i-1, importo, ZERO, scad, tipop, ulc, paid); + + TToken_string& str = ps.row(i-1); + str.add(scadenza.get(SCAD_CODABIPR), 6); + str.add(scadenza.get(SCAD_CODCABPR), 7); + str.add(scadenza.get(SCAD_CODABI), 8); + str.add(scadenza.get(SCAD_CODCAB), 9); + if (i == 1) + { + set(FS_NSABI, str.get(6)); + set(FS_NSCAB, str.get(7)); + set(FS_VSABI, str.get(8)); + set(FS_VSCAB, str.get(9)); + set(FS_AGENTE, scadenza.get(SCAD_CODAG)); + } + } + } + else + { + + pag.set_rate_auto(); + } + + set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2"); + set(FS_NAMEPAG, pag.name()); + set(FS_TIPOPR, pag.desc_tpr()); + set(FS_MCOMM, pag.mese_commerciale() ? "X" : ""); + set(FS_RECALC, "X", TRUE); + set(FS_NRATE, pag.n_rate()); + + pag.set_sheet(ps); + _pag_rows = ps.rows_array(); + + // se la prima rata e' fissa non si tocca + if (pag.tipo_prima_rata() > 3) + ps.disable_cell(0,-1); +} + +void TFattura_mask::write_scadenze() const +{ + CHECK(_pag, "Null pagament"); + const TPagamento& pag = *_pag; + TRiga_partite& partita = _fattura; + + TSheet_field& ps = pag_sheet(); + + const TString agente = get(FS_AGENTE); + + partita.elimina_rate(); + for (int i = 0; i < pag.n_rate(); i++) + { + TToken_string& row = ps.row(i); + + TRiga_scadenze& scadenza = partita.new_row(); + scadenza.put(SCAD_CODPAG, pag.code()); + scadenza.put(SCAD_TIPOPAG, pag.tipo_rata(i)); + scadenza.put(SCAD_ULTCLASS, pag.ulc_rata(i)); + if (partita.in_valuta()) + { + scadenza.put(SCAD_IMPORTO, pag.tlit_rata(i)); + scadenza.put(SCAD_IMPORTOVAL, pag.tpay_rata(i)); + } + else + { + scadenza.put(SCAD_IMPORTO, pag.tpay_rata(i)); + scadenza.zero(SCAD_IMPORTOVAL); + } + scadenza.put(SCAD_DATASCAD, pag.data_rata(i)); + scadenza.put(SCAD_CODABIPR, row.get(6)); + scadenza.put(SCAD_CODCABPR, row.get(7)); + scadenza.put(SCAD_CODABI, row.get(8)); + scadenza.put(SCAD_CODCAB, row.get(9)); + scadenza.put(SCAD_PAGATA, pag.ratapagata(i)); + scadenza.put(SCAD_CODAG, agente); + } +} + + +/////////////////////////////////////////////////////////// +// Addendum alla maschera gestione partite +/////////////////////////////////////////////////////////// + +bool TGame_mask::edit_fattura(TPartita& p, int nriga) +{ + TString16 codpag; + + const bool nuova = nriga <= 0; + if (nuova) + nriga = nuova_riga(p); + + TRiga_partite& f = p.riga(nriga); + if (f.rate() > 0) + _codpag = f.rata(1).get(SCAD_CODPAG); + + TFattura_mask fm(f, _codpag); + const bool ok = fm.run() == K_ENTER; + + if (nuova && !ok) + p.rimuovi_riga(nriga); + + return ok; +} + +/////////////////////////////////////////////////////////// +// Gestione partite extra-contabili +/////////////////////////////////////////////////////////// + +void TSaldaconto_app::edit_partite(const TMask& m) +{ + TBill b; // Legge il conto della riga selezionata + b.set(m.get_int(F_GRUPPO), m.get_int(F_CONTO), + m.get_long(F_SOTTOCONTO), m.get(F_TIPO)[0]); + + TGame_mask gm(b, 0, 0); + gm.run(); + if (gm.changed() && yesno_box("Si vogliono salvare le partite modificate?")) + partite().rewrite(); + partite().destroy(); +} + diff --git a/sc/sc1200.cpp b/sc/sc1200.cpp index f9946afe3..d75c19b37 100755 --- a/sc/sc1200.cpp +++ b/sc/sc1200.cpp @@ -1,339 +1,340 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../cg/conto.h" -#include "../cg/pagament.h" -#include "../cg/cglib.h" - -#include "sc1200.h" - -class TCreatepart_app : public TApplication -{ - TLocalisamfile* _conti; - TLocalisamfile* _partite; - TLocalisamfile* _scadenze; - TLocalisamfile* _pagsca; - - int _anno; - -protected: - - virtual bool create(); - virtual bool destroy(); - virtual bool menu(MENU_TAG m); - - bool zap_partite(); - -public: - - int is_clifo(int g, int c, char& cf, int& indbil); - TCreatepart_app() {} - virtual ~TCreatepart_app() {} -}; - - -bool TCreatepart_app::create() -{ - TApplication::create(); - - _conti = new TLocalisamfile(LF_PCON); - _partite = new TLocalisamfile(LF_PARTITE); - _scadenze = new TLocalisamfile(LF_SCADENZE); - _pagsca = new TLocalisamfile(LF_PAGSCA); - - dispatch_e_menu(BAR_ITEM(1)); - return TRUE; -} - -bool TCreatepart_app::destroy() -{ - delete _conti; - delete _partite; - delete _scadenze; - delete _pagsca; - - return TApplication::destroy(); -} - - -bool TCreatepart_app::zap_partite() -{ - bool first = TRUE; - for (_partite->first(); !_partite->eof(); _partite->next()) - { - // ignora saldaconto altri esercizi - if (_partite->get_long(PART_ANNO) != _anno) - continue; - - if (first) - { - bool ok = yesno_box("Il saldaconto per l'esercizio scelto non e' vuoto." - " La procedura lo azzera completamente." - " Si desidera proseguire?"); - if (ok) - ok = yesno_box("Confermare l'azzeramento del saldaconto esistente"); - if (!ok) return FALSE; - first = FALSE; - } - - bool gos = TRUE; - bool goi = TRUE; - - for (int i = 1; gos || goi ; i++) - { - // zappa scadenze - if (gos) - { - _scadenze->zero(); - _scadenze->put(SCAD_ANNO, _partite->get(PART_ANNO)); - _scadenze->put(SCAD_NUMPART, _partite->get(PART_NUMPART)); - _scadenze->put(SCAD_NRATA, i+1); - - if (gos = (_scadenze->read() == NOERR)) - _scadenze->remove(); - } - - // zappa solleciti - if (goi) - { - _pagsca->zero(); - _pagsca->put(PAGSCA_ANNO, _partite->get(PART_ANNO)); - _pagsca->put(PAGSCA_NUMPART, _partite->get(PART_NUMPART)); - _pagsca->put(PAGSCA_NRIGP, i+1); - - if (goi = (_pagsca->read() == NOERR)) - _pagsca->remove(); - } - } - _partite->remove(); - } - - return TRUE; -} - - -int TCreatepart_app::is_clifo(int g, int c, char& cf, int& indbil) -{ - // deve ritornare QUANTI sono i conti in cui appare lo stesso - // cliente; se piu' di uno deve creare n rate, una per cliente - - _conti->zero(); - _conti->put(PCN_GRUPPO, g); - _conti->put(PCN_CONTO, c); - if (_conti->read() != NOERR) - { - warning_box("Piano dei conti disallineato con archivio saldi: esecuzione interrotta"); - return 0; - } - - if (_conti->get(PCN_TMCF).empty()) - return 0; - - cf = _conti->get_char(PCN_TMCF); - indbil = _conti->get_int(PCN_INDBIL); - long cl = _conti->get_long(PCN_SOTTOCONTO); - - // cerca tutti i conti in cui compare lo stesso cliente o - // fornitore - int ncli = 0; - - for (_conti->first(); !_conti->eof(); _conti->next()) - { - if (_conti->get_char(PCN_TMCF) == cf && - _conti->get_long(PCN_SOTTOCONTO) == cl) - ncli++; - } - - return ncli; -} - - -bool TCreatepart_app::menu(MENU_TAG) -{ - TMask m("sc1200a"); - TRelation saldi(LF_SALDI); - saldi.zero(); - - TDate today(TODAY); - TString80 desccl = "Apertura clienti al "; desccl << today.string(); - TString80 descfo = "Apertura fornitori al "; descfo << today.string(); - - m.set(F_DESCCL, desccl); - m.set(F_DESCFO, descfo); - - while (m.run() == K_ENTER) - { - _anno = m.get_int(F_ANNO); - desccl = m.get(F_DESCCL); - descfo = m.get(F_DESCFO); - int n_part = 0; - m.set(F_NUMPART, format("%d",n_part)); - - // sputtana tutto il saldaculo - if (!zap_partite()) break; - - saldi.lfile().zero(); - saldi.lfile().put(SLD_ANNOES, _anno); - - TCursor cur(&saldi, "", 1, &saldi.curr(), &saldi.curr()); - const long items = cur.items(); - long npart = 0L; - // determina ultima partita; la prima volta, - // se ce n'e' chiedi se si vuole cancellare - long last_partita = 1l; - - if (items > 0) - { - begin_wait(); - - TProgind prind(items, "Creazione saldaconto", FALSE, TRUE,45); - - int hw = 0; - for (cur = 0, hw = 0 ; cur.pos() < items; ++cur, hw++) - { - char cf; int nclienti; - int gruppo = cur.curr().get_int(SLD_GRUPPO); - int conto = cur.curr().get_int(SLD_CONTO); - long sottoc = cur.curr().get_long(SLD_SOTTOCONTO); - - int indbil; - - if ((nclienti = is_clifo(gruppo, conto, cf, indbil)) > 0) - { - TSaldo sld; - - // ciuccia il saldo e vedi se e' movimentato nell'esercizio corrente - if (!sld.ultima_immissione_verifica(_anno, gruppo, conto, sottoc, indbil, 1)) - { - // non movimentato: se e' conto patrimoniale.... - if (!(indbil == 1 || indbil == 2 || indbil == 5)) - { - prind.addstatus(1); - continue; - } - // .. vedi saldo esercizio precedente, altrimenti inkul - sld.saldofin_esprec(_anno, gruppo, conto, sottoc); - } - - // genera importo con sezione appropriata - TImporto saldo(cur.curr().get_char(SLD_FLAGSALINI), sld.saldoini()); - TImporto pdare('D', sld.prgdare()); - TImporto pavere('A', sld.prgavere()); - - saldo += pdare; - saldo += pavere; - saldo.normalize(); - - // (whew) - - if (!saldo.is_zero()) - { - TString16 id; - real val(saldo.valore()); - - // TPagamento pag(codpag, today.string()); - // pag.set_total(val, ZERO, ZERO); - // pag.set_rate_auto(); - - // apri partita dimmerda - id << format("*%05ld", last_partita++); - - _partite->zero(); - _partite->put(PART_ANNO, _anno); - _partite->put(PART_NUMPART, id); - _partite->put(PART_NUMRIG, 1); - _partite->put(PART_NRIGA, 1); - _partite->put(PART_DATAREG, today); - _partite->put(PART_DATADOC, today); - _partite->put(PART_SEZ, saldo.sezione()); - _partite->put(PART_IMPORTO, saldo.valore()); - _partite->put(PART_CODVAL, "LIT"); - _partite->put(PART_TIPOCF, cf); - _partite->put(PART_GRUPPOCL, gruppo); - _partite->put(PART_CONTOCL, conto); - _partite->put(PART_SOTTOCONTO,sottoc); - _partite->put(PART_DESCR, cf == 'C' ? desccl : descfo); - -// _partite->put(PART_CODPAG, codpag); - - // cazzata dare/avere/fare/baciare/cagare - int tipo = (cf == 'C' ? (saldo.sezione() == 'D' ? 1 : 3) : - (saldo.sezione() == 'D' ? 3 : 1)); - - _partite->put(PART_TIPOMOV, tipo); - _partite->write(); - - if (tipo == 1) - { - // apri scadenze dimmerda: tante quanti clienti ci sono - for (int i = 0; i < nclienti; i++) - { - _scadenze->zero(); - _scadenze->put(SCAD_ANNO, _anno); - _scadenze->put(SCAD_NUMPART, id); - _scadenze->put(SCAD_NRATA, i+1); - _scadenze->put(SCAD_IMPORTO, val/real((double)nclienti)); - _scadenze->put(SCAD_TIPOCF, cf); - _scadenze->put(SCAD_SOTTOCONTO, sottoc); - - // oldies and goldies - // not removed, you know why - // ------------------------------------------------------------ - // _scadenze->put(SCAD_CODPAG, codpag); - // _scadenze->put(SCAD_ULTCLASS, pag.ulc_rata(i)); - // _scadenze->put(SCAD_TIPOPAG, pag.tipo_rata(i)); - // _scadenze->put(SCAD_DATASCAD, pag.data_rata(i)); - // _scadenze->put(SCAD_GRUPPO, gruppo); - // _scadenze->put(SCAD_CONTO, conto); - - _scadenze->write(); - } - } - else - { - // apri insoluto - for (int i = 0; i < nclienti; i++) - { - _pagsca->zero(); - _pagsca->put(PAGSCA_ANNO, _anno); - _pagsca->put(PAGSCA_NUMPART, id); - _pagsca->put(PAGSCA_NRIGP, i+1); - _pagsca->put(PAGSCA_IMPORTO, val/real((double)nclienti)); - _pagsca->put(PAGSCA_TIPOC, cf); - _pagsca->put(PAGSCA_SOTTOCONTO, sottoc); - _pagsca->write(); - } - } - - n_part++; - m.set(F_NUMPART, format("%d",n_part)); - } - } - prind.addstatus(1); - } - end_wait(); - } - else - message_box("Nessun saldo presente per l'esercizio %d", _anno); - } // while run - - return FALSE; -} - - -int sc1200(int argc, char** argv) -{ - TCreatepart_app a; - a.run(argc, argv, "Apertura scadenze da saldi contabili"); - return 0; -} +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../cg/conto.h" +#include "../cg/pagament.h" +#include "../cg/cglib.h" + +#include "sc1200.h" + +class TCreatepart_app : public TApplication +{ + TLocalisamfile* _conti; + TLocalisamfile* _partite; + TLocalisamfile* _scadenze; + TLocalisamfile* _pagsca; + + int _anno; + +protected: + + virtual bool create(); + virtual bool destroy(); + virtual bool menu(MENU_TAG m); + + bool zap_partite(); + +public: + + int is_clifo(int g, int c, char& cf, int& indbil); + TCreatepart_app() {} + virtual ~TCreatepart_app() {} +}; + + +bool TCreatepart_app::create() +{ + TApplication::create(); + + _conti = new TLocalisamfile(LF_PCON); + _partite = new TLocalisamfile(LF_PARTITE); + _scadenze = new TLocalisamfile(LF_SCADENZE); + _pagsca = new TLocalisamfile(LF_PAGSCA); + + dispatch_e_menu(BAR_ITEM(1)); + return TRUE; +} + +bool TCreatepart_app::destroy() +{ + delete _conti; + delete _partite; + delete _scadenze; + delete _pagsca; + + return TApplication::destroy(); +} + + +bool TCreatepart_app::zap_partite() +{ + bool first = TRUE; + for (_partite->first(); !_partite->eof(); _partite->next()) + { + // ignora saldaconto altri esercizi + if (_partite->get_long(PART_ANNO) != _anno) + continue; + + if (first) + { + bool ok = yesno_box("Il saldaconto per l'esercizio scelto non e' vuoto." + " La procedura lo azzera completamente." + " Si desidera proseguire?"); + if (ok) + ok = yesno_box("Confermare l'azzeramento del saldaconto esistente"); + if (!ok) return FALSE; + first = FALSE; + } + + bool gos = TRUE; + bool goi = TRUE; + + for (int i = 1; gos || goi ; i++) + { + // zappa scadenze + if (gos) + { + _scadenze->zero(); + _scadenze->put(SCAD_ANNO, _partite->get(PART_ANNO)); + _scadenze->put(SCAD_NUMPART, _partite->get(PART_NUMPART)); + _scadenze->put(SCAD_NRATA, i+1); + + if (gos = (_scadenze->read() == NOERR)) + _scadenze->remove(); + } + + // zappa pagamenti + if (goi) + { + _pagsca->zero(); + _pagsca->put(PAGSCA_ANNO, _partite->get(PART_ANNO)); + _pagsca->put(PAGSCA_NUMPART, _partite->get(PART_NUMPART)); + _pagsca->put(PAGSCA_NRIGP, i+1); + + if (goi = (_pagsca->read() == NOERR)) + _pagsca->remove(); + } + } + _partite->remove(); + } + + return TRUE; +} + + +int TCreatepart_app::is_clifo(int g, int c, char& cf, int& indbil) +{ + // deve ritornare QUANTI sono i conti in cui appare lo stesso + // cliente; se piu' di uno deve creare n rate, una per cliente + + _conti->zero(); + _conti->put(PCN_GRUPPO, g); + _conti->put(PCN_CONTO, c); + if (_conti->read() != NOERR) + { + warning_box("Piano dei conti disallineato con archivio saldi: esecuzione interrotta"); + return 0; + } + + if (_conti->get(PCN_TMCF).empty()) + return 0; + + cf = _conti->get_char(PCN_TMCF); + indbil = _conti->get_int(PCN_INDBIL); + long cl = _conti->get_long(PCN_SOTTOCONTO); + + // cerca tutti i conti in cui compare lo stesso cliente o + // fornitore + int ncli = 0; + + for (_conti->first(); !_conti->eof(); _conti->next()) + { + if (_conti->get_char(PCN_TMCF) == cf && + _conti->get_long(PCN_SOTTOCONTO) == cl) + ncli++; + } + + return ncli; +} + + +bool TCreatepart_app::menu(MENU_TAG) +{ + TMask m("sc1200a"); + TRelation saldi(LF_SALDI); + saldi.zero(); + + TDate today(TODAY); + TString80 desccl = "Apertura clienti al "; desccl << today.string(); + TString80 descfo = "Apertura fornitori al "; descfo << today.string(); + + m.set(F_DESCCL, desccl); + m.set(F_DESCFO, descfo); + + while (m.run() == K_ENTER) + { + _anno = m.get_int(F_ANNO); + desccl = m.get(F_DESCCL); + descfo = m.get(F_DESCFO); + int n_part = 0; + m.set(F_NUMPART, n_part); + + // sputtana tutto il saldaculo + if (!zap_partite()) break; + + saldi.lfile().zero(); + saldi.lfile().put(SLD_ANNOES, _anno); + + TCursor cur(&saldi, "", 1, &saldi.curr(), &saldi.curr()); + const long items = cur.items(); + long npart = 0L; + // determina ultima partita; la prima volta, + // se ce n'e' chiedi se si vuole cancellare + long last_partita = 1l; + + if (items > 0) + { + begin_wait(); + + TProgind prind(items, "Creazione saldaconto", FALSE, TRUE,45); + + int hw = 0; + for (cur = 0, hw = 0 ; cur.pos() < items; ++cur, hw++) + { + char cf; int nclienti; + int gruppo = cur.curr().get_int(SLD_GRUPPO); + int conto = cur.curr().get_int(SLD_CONTO); + long sottoc = cur.curr().get_long(SLD_SOTTOCONTO); + + int indbil; + + nclienti = is_clifo(gruppo, conto, cf, indbil); + if (nclienti > 0) + { + TSaldo sld; + + // ciuccia il saldo e vedi se e' movimentato nell'esercizio corrente + if (!sld.ultima_immissione_verifica(_anno, gruppo, conto, sottoc, indbil, 1)) + { + // non movimentato: se e' conto patrimoniale.... + if (!(indbil == 1 || indbil == 2 || indbil == 5)) + { + prind.addstatus(1); + continue; + } + // .. vedi saldo esercizio precedente, altrimenti inkul + sld.saldofin_esprec(_anno, gruppo, conto, sottoc); + } + + // genera importo con sezione appropriata + TImporto saldo(cur.curr().get_char(SLD_FLAGSALINI), sld.saldoini()); + TImporto pdare('D', sld.prgdare()); + TImporto pavere('A', sld.prgavere()); + + saldo += pdare; + saldo += pavere; + saldo.normalize(); + + // (whew) + + if (!saldo.is_zero()) + { + TString16 id; + real val(saldo.valore()); + + // TPagamento pag(codpag, today.string()); + // pag.set_total(val, ZERO, ZERO); + // pag.set_rate_auto(); + + // apri partita dimmerda + id << format("*%05ld", last_partita++); + + _partite->zero(); + _partite->put(PART_ANNO, _anno); + _partite->put(PART_NUMPART, id); + _partite->put(PART_NUMRIG, 1); + _partite->put(PART_NRIGA, 1); + _partite->put(PART_DATAREG, today); + _partite->put(PART_DATADOC, today); + _partite->put(PART_SEZ, saldo.sezione()); + _partite->put(PART_IMPORTO, saldo.valore()); + _partite->put(PART_CODVAL, "LIT"); + _partite->put(PART_TIPOCF, cf); + _partite->put(PART_GRUPPOCL, gruppo); + _partite->put(PART_CONTOCL, conto); + _partite->put(PART_SOTTOCONTO,sottoc); + _partite->put(PART_DESCR, cf == 'C' ? desccl : descfo); + +// _partite->put(PART_CODPAG, codpag); + + // cazzata dare/avere/fare/baciare/cagare + int tipo = (cf == 'C' ? (saldo.sezione() == 'D' ? 1 : 3) : + (saldo.sezione() == 'D' ? 3 : 1)); + + _partite->put(PART_TIPOMOV, tipo); + _partite->write(); + + if (tipo == 1) + { + // apri scadenze dimmerda: tante quanti clienti ci sono + for (int i = 0; i < nclienti; i++) + { + _scadenze->zero(); + _scadenze->put(SCAD_ANNO, _anno); + _scadenze->put(SCAD_NUMPART, id); + _scadenze->put(SCAD_NRATA, i+1); + _scadenze->put(SCAD_IMPORTO, val/real((double)nclienti)); + _scadenze->put(SCAD_TIPOCF, cf); + _scadenze->put(SCAD_SOTTOCONTO, sottoc); + + // oldies and goldies + // not removed, you know why + // ------------------------------------------------------------ + // _scadenze->put(SCAD_CODPAG, codpag); + // _scadenze->put(SCAD_ULTCLASS, pag.ulc_rata(i)); + // _scadenze->put(SCAD_TIPOPAG, pag.tipo_rata(i)); + // _scadenze->put(SCAD_DATASCAD, pag.data_rata(i)); + // _scadenze->put(SCAD_GRUPPO, gruppo); + // _scadenze->put(SCAD_CONTO, conto); + + _scadenze->write(); + } + } + else + { + // apri insoluto + for (int i = 0; i < nclienti; i++) + { + _pagsca->zero(); + _pagsca->put(PAGSCA_ANNO, _anno); + _pagsca->put(PAGSCA_NUMPART, id); + _pagsca->put(PAGSCA_NRIGP, i+1); + _pagsca->put(PAGSCA_IMPORTO, val/real((double)nclienti)); + _pagsca->put(PAGSCA_TIPOC, cf); + _pagsca->put(PAGSCA_SOTTOCONTO, sottoc); + _pagsca->write(); + } + } + + n_part++; + m.set(F_NUMPART, format("%d",n_part)); + } + } + prind.addstatus(1); + } + end_wait(); + } + else + message_box("Nessun saldo presente per l'esercizio %d", _anno); + } // while run + + return FALSE; +} + + +int sc1200(int argc, char** argv) +{ + TCreatepart_app a; + a.run(argc, argv, "Apertura scadenze da saldi contabili"); + return 0; +}