From 02998fe78ad15a6908229f6ae153787673d4d12b Mon Sep 17 00:00:00 2001 From: Mattia Tollari Date: Tue, 23 Jul 2019 16:07:13 +0200 Subject: [PATCH] Patch level : 12.0 no-patch Files correlati : mg Commento : Aggiunta classe TConai_articolo per gestire il conai di un articolo specifico Implemented #56 --- src/include/lffiles.h | 1 + src/mg/mglib.h | 19 +++++++++ src/mg/mglib02.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/src/include/lffiles.h b/src/include/lffiles.h index 4e11af404..27ef6c2bc 100755 --- a/src/include/lffiles.h +++ b/src/include/lffiles.h @@ -197,6 +197,7 @@ #define LF_FPCCAUS 177 #define LF_FPCART 178 #define LF_FPCADG 179 +#define LF_CONART 180 #define LF_EXTERNAL 1000 // Files with id >= are considered to be externals diff --git a/src/mg/mglib.h b/src/mg/mglib.h index bb07629d5..243cc04c5 100755 --- a/src/mg/mglib.h +++ b/src/mg/mglib.h @@ -48,6 +48,8 @@ #include "../mg/rmovmag.h" #endif +#include + // campi comuni alla maschere di magazzino typedef enum { @@ -330,6 +332,23 @@ void refresh_article(const char* codart); TArticolo& cached_article(const char* codart); TArticolo_giacenza& cached_article_balances(const char* codart); +class TArticolo_conai : TObject +{ +private: + const TString _codart; + // Categoria -> Sottocategoria + peso + std::map> _catsotpes; +public: + const std::map> get_map() { return _catsotpes; } + const std::map* get_scat(const TString& cat); + real get_peso(const TString& cat, const TString& scat); + real get_peso(const TString& fcat) { return get_peso(fcat.left(2), fcat.right(2)); } + + + + TArticolo_conai(const TString& codart); +}; + // ******************************* // LIBRERIA DI utility del magazzino // ******************************* diff --git a/src/mg/mglib02.cpp b/src/mg/mglib02.cpp index aba4fb41e..6bfe2fbc8 100755 --- a/src/mg/mglib02.cpp +++ b/src/mg/mglib02.cpp @@ -17,6 +17,7 @@ #include "clifogiac.h" #include "movmag.h" #include "rmovmag.h" +#include "conart.h" // libreria per i movimenti class TTimed_skipbox: public TTimed_breakbox @@ -1840,6 +1841,97 @@ TArticolo_giacenza& cached_article_balances(const char* codart) return __cache_articoli_giacenza.art(codart); } +const char* conai2anamagfld(const TString& conai_cat) +{ + if (conai_cat == "AL") + return "CONALL"; + else if (conai_cat == "AC") + return "CONACC"; + else if (conai_cat == "CA") + return "CONCAR"; + else if (conai_cat == "PL") + return "CONPLA"; + else if (conai_cat == "LE") + return "CONLEG"; + else if (conai_cat == "VE") + return "CONVET"; + else + return "ERROR"; +} + +// Conai nell'articolo +TArticolo_conai::TArticolo_conai(const TString& codart) + : _codart(codart) +{ + /* Devo caricarmi tutti i codici conai presenti nell'articolo + * Cerco inizialmente la presenza dell'articolo in tabmod, + * se non lo trovo sarà salvato nel vecchio metodo + */ + { + TLocalisamfile conart(LF_CONART); + conart.put(CONART_CODART, _codart); + if (conart.read(_isgteq) == NOERR) + { + while (_codart == conart.get(CONART_CODART)) + { + const TString& categoria = conart.get(CONART_CATEGORIA); + const TString& sottocat = conart.get(CONART_SOTTOCAT); + const real& peso = conart.get_real(CONART_PESO); + _catsotpes[categoria][sottocat] = peso; + ++conart; + } + } + } + /* + * Vado a cercare sempre nelle vecchie tabelle dell'articolo, Perchè giovane padawan? + * La risposta è semplice, tutti i programmi che non verranno aggiornati da queste modifiche (es. Importazione Pack/SKNT) + * scrivono li e quindi va tenuta la compatibilità + */ + { + TLocalisamfile anamag(LF_ANAMAG); + TRectype ranamag(LF_ANAMAG); + ranamag.put(ANAMAG_CODART, _codart); + if (ranamag.read(anamag) == NOERR) // Non dovrebbe mai fallire + { + const TString& conaisc = ranamag.get(ANAMAG_CONAISC); + int startcon = -1; + // Mi serve sapere dove iniziano i campi del conai + const RecFieldDes* fs = ranamag.rec_des().Fd; + for (int i = 0; i < ranamag.rec_des().NFields && startcon == -1; i++) + startcon = strcmp(fs[i].Name, ANAMAG_CONACC) == 0 ? i : -1; + + if (startcon > -1) + { + for (int i = 0; i < conaisc.len() / 4; i++) + { + const TString& con = conaisc.mid(i * 4, 4); + const TString& categoria = con.left(2); + const TString& sottocat = con.right(2); + if (con.blank()) continue; + + _catsotpes[categoria][sottocat] = ranamag.get_real(fs[startcon + i].Name); + } + } + } + } +} + +const std::map* TArticolo_conai::get_scat(const TString& cat) +{ + if (_catsotpes.find(cat) != _catsotpes.end()) + return &_catsotpes[cat]; + else + return nullptr; +} + +real TArticolo_conai::get_peso(const TString& cat, const TString& scat) +{ + real peso = -UNO; + if (_catsotpes.find(cat) != _catsotpes.end() && _catsotpes[cat].find(scat) != _catsotpes[cat].end()) + peso = _catsotpes[cat][scat]; + return peso; +} + // causali int TCausale_magazzino::sgn(TTipo_saldomag tiposaldo) const