From e5f88c409aaf016d4ed4ea31c3a9cd57beb38961 Mon Sep 17 00:00:00 2001 From: luca83 <luca83@c028cbd2-c16b-5b4b-a496-9718f37d4682> Date: Tue, 25 Aug 2009 14:55:38 +0000 Subject: [PATCH] Patch level : 10.0 patch 414 Files correlati : lv2 Ricompilazione Demo : [ ] Commento : Aggiunta la gestione del ritiro automatico della dotazione temporanea git-svn-id: svn://10.65.10.50/trunk@19225 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- lv/lv2400.cpp | 334 +++++++++++++++++++++++++++++--------------------- 1 file changed, 197 insertions(+), 137 deletions(-) diff --git a/lv/lv2400.cpp b/lv/lv2400.cpp index 02087e786..0d92c87a6 100755 --- a/lv/lv2400.cpp +++ b/lv/lv2400.cpp @@ -4,6 +4,7 @@ #include <reprint.h> #include "lvlib.h" +#include "../mg/clifogiac.h" #include "../ve/velib.h" #include "../ve/rcondv.h" @@ -201,20 +202,22 @@ bool TGenera_documenti_app::crea_documento(const TISAM_recordset& plan, TLog_rep doc.put("DATAPRCO", dtcons); const long ndoc = doc.get_long(DOC_NDOC); - - //preparo la chiave per la tabella righe contratti - TToken_string keyrcont; - keycont.add(codcli); - keycont.add(codcont); FOR_EACH_ASSOC_OBJECT(_quantita,h,codart,obj) { - crea_riga(codart, modpas, tplis, false, prinbo, doc, rep); + //preparo la chiave per la tabella righe contratti + TToken_string keyrcont; + keyrcont.add(codcli); + keyrcont.add(codcont); + keyrcont.add(codart); + const TRectype& rcont = cache().get(LF_LVRCONDV, keyrcont); + const TDate dadata = (TDate)rcont.get(LVRCONDV_INDTTMP); + const TDate adata = (TDate)rcont.get(LVRCONDV_FIDTTMP); - /*const TDate dadata = rcont.get(LVRCONDV_INDTTMP).as_date(); - const TDate adata = rcont.get(LVRCONDV_FIDTTMP).as_date(); - if (dadata.ok() && dtcons >= dadata && dtcons <= adata) - crea_riga(rcont, modpas, true, doc);*/ + if (dadata.ok() && dtcons == adata) + crea_riga(codart, modpas, tplis, true, prinbo, doc, rep); + else + crea_riga(codart, modpas, tplis, false, prinbo, doc, rep); } if (doc.rows() > 0) @@ -238,8 +241,7 @@ bool TGenera_documenti_app::crea_documento(const TISAM_recordset& plan, TLog_rep //CREA_RIGA: questa funzione crea una riga merce per una bolla di consegna void TGenera_documenti_app::crea_riga(const TString& codart, const char modpas, const int tplis, const bool tmp, const bool prinbo, TDocumento& doc, TLog_report& rep) { - const int perarr = _configlv->get_int("Perarr"); - + const int perarr = ini_get_int(CONFIG_DITTA, "lv", "Perarr"); //creo la nuova riga TString4 tiporiga; switch (_buono) @@ -249,8 +251,6 @@ void TGenera_documenti_app::crea_riga(const TString& codart, const char modpas, default: break; } - TRiga_documento& rdoc = doc.new_row(tiporiga); - const long codcli = doc.get_long(DOC_CODCF); const long codcont = doc.get_long(DOC_CODCONT); @@ -272,7 +272,7 @@ void TGenera_documenti_app::crea_riga(const TString& codart, const char modpas, arrot = false; const real conguaglio = rcont.get_real(LVRCONDV_QTACONG); - const real& qta = *(real*)_quantita.objptr(codart); + real& qta = *(real*)_quantita.objptr(codart); const real& qta1 = *(real*)_quantita_ritirata.objptr(codart); //instanzio una cache sulla tabella del magazzino @@ -280,138 +280,198 @@ void TGenera_documenti_app::crea_riga(const TString& codart, const char modpas, //recupero i dati di interesse dall'anagrafica di magazzino const real ppconf = anamag.get_real(ANAMAG_PPCONF); - const real quantita_noarr = qta - conguaglio; - real quantita_arr = quantita_noarr > ZERO ? quantita_noarr : ZERO; - //se devo arrotondare - if (quantita_arr > ZERO && arrot) + //GESTIONE DOTAZIONE TEMPOARANEA + if (tmp && rcont.get_bool(LVRCONDV_RITAUDTTMP)) { - //calcolo di quanti pezzi sforo - long arr = quantita_arr.integer() % ppconf.integer(); - //se sforo (arr > 0) allora calcolo quanti pezzi in pi� gli devo dare e aggiorno la quantit� - if (arr > 0) - if (arr > ppconf.integer() * perarr / 100) //arr <= ppconf*perarr/100 -> formula calcolo congualgio di Tassan - { - arr = ppconf.integer() - arr; - quantita_arr += arr; - } - else - quantita_arr -= arr; - } + TRiga_documento& rdoc = doc.new_row(tiporiga); + rdoc.put(RDOC_CODART,codart); + rdoc.put(RDOC_CODARTMAG,codart); + rdoc.put(RDOC_CHECKED,'X'); + + if (prinbo) + rdoc.put(RDOC_PREZZO,rcont.get_real(LVRCONDV_PRZDTTMP)); //prezzo - //scrivo le quantit� - rdoc.put(RDOC_QTA, quantita_arr); //quantit� consegnata eventualmente arrotondata - rdoc.put(RDOC_QTAGG1, qta1); //quantit� ritirata - rdoc.put(RDOC_QTAGG2, conguaglio); //conguaglio - rdoc.put(RDOC_QTAGG3, quantita_arr); //copia della quantit� consegnata - rdoc.put(RDOC_QTAGG4, quantita_noarr); //quantit� che avrei consegnato se non arrotondavo (qta ritirata) - rdoc.put(RDOC_GENERATA, true); + //recupero i valori delle dotazione temporanea dal magazzino del cliente + TLocalisamfile magcli(LF_CLIFOGIAC); + magcli.put(CLIFOGIAC_ANNOES, doc.get_date(DOC_DATADOC).year()); + magcli.put(CLIFOGIAC_TIPOCF, 'C'); + magcli.put(CLIFOGIAC_CODCF, codcli); + magcli.put(CLIFOGIAC_INDSPED, 0); //in realt� � da leggere dal contratto + magcli.put(CLIFOGIAC_CODART, codart); + magcli.put(CLIFOGIAC_NRIGA, 1); + //leggo il record corrispondente + magcli.read(); + long dottmp = magcli.get_long(CLIFOGIAC_DOTTM); - const TString4 causale = ini_get_string(CONFIG_DITTA, "lv", "CAUSLAV"); - rdoc.put(RDOC_CODAGG1, causale); //causale presa dalla configurazione - - //aggiorno il conguaglio sulla riga del contratto - if (!rcont.empty()) - aggiorna_conguaglio((TRectype&)rcont, quantita_arr - quantita_noarr); - - //elaborazione sul prezzo da utilizzare - real prezzo; - - if (rcont.empty()) - { - //PROPONI PREZZO - TToken_string key; - key.add('C'); - key.add(codcli); - const TRectype& cfven = cache().get(LF_CFVEN, key); - - bool trvlst = false; - - if (!cfven.empty()) + //se ho ritirato un quantitativo di roba maggiore o uguale alla dotazione temporanea + //allora creo la nuova riga documento e azzero la dottmp; altrimenti preparo la riga + //per la quantit� che ho ritirato e tengo traccia della cosa + if (qta >= dottmp) { - //se � settata la categoria merceologica, leggo sia il listino che la cat merc, altrimenti solo il listino - TString8 codlis = cfven.get(CFV_CODLIST); - TString8 catven; - TConfig* configve = new TConfig(CONFIG_DITTA,"ve"); - const char gesliscv = configve->get_char("GESLISCV"); - if (gesliscv != 'X') - catven = ""; - else - catven = cfven.get(CFV_CATVEN); - - //cerco il prezzo sul listino - key.cut(0); - key.add('L'); //tipo - key.add(catven); //catven - key.add(""); //tipocf - key.add(""); //codcf - key.add(codlis); //codlis - key.add('A'); //tiporiga - key.add(codart); //codriga - key.add(""); //um - key.add(""); //nscagl - const TRectype& rcondv = cache().get(LF_RCONDV, key); - - if (!rcondv.empty()) - { - prezzo = rcondv.get_real(RCONDV_PREZZO); - trvlst = true; - } + qta -= dottmp; + rdoc.put(RDOC_QTAGG1, dottmp); //quantit� ritirata + rdoc.put(RDOC_GENERATA, true); + rdoc.put(RDOC_CODAGG1, ini_get_string(CONFIG_DITTA, "lv", "CAULVRITDT")); + dottmp = 0; } - - //se non ho trovato un listino, o se non c'� un listino impostato - //propongo come prezzo il valore convenzionale - if (!trvlst) - { - key.cut(0); - key.add(codart); - key.add(1); - const TRectype& umart = cache().get(LF_UMART, key); - prezzo = umart.get_real(UMART_PREZZO); - if (umart.get(UMART_PREZZO).full()) - trvlst = true; - } - } - else - { - //elaborazione per il prezzo: o lo prendo dalle righe contratto, o dall'anagrafica magazzino - if (tplis == 0) - prezzo = rcont.get_real(LVRCONDV_PREZZO); else - prezzo = anamag.get_real(ANAMAG_COSTSTD); + { + dottmp -= qta.integer(); + rdoc.put(RDOC_QTAGG1, qta); //quantit� ritirata + rdoc.put(RDOC_GENERATA, true); + rdoc.put(RDOC_CODAGG1, ini_get_string(CONFIG_DITTA, "lv", "CAULVRITDT")); + TString str; + str << "L'articolo " << codart << " inserito nel documento " << doc.get(DOC_CODNUM) << "-" << doc.get(DOC_TIPODOC) + << " numero " << doc.get(DOC_NDOC) << " in dotazione temporanea non � stato ritirato completamente." + << " Mancano " << dottmp << "unit�"; + rep.log(1, str); + qta = ZERO; + } + + //riscrivo la dotazione temporanea aggiornata + magcli.put(CLIFOGIAC_ANNOES, doc.get_date(DOC_DATADOC).year()); + magcli.put(CLIFOGIAC_TIPOCF, 'C'); + magcli.put(CLIFOGIAC_CODCF, codcli); + magcli.put(CLIFOGIAC_INDSPED, 0); //in realt� � da leggere dal contratto + magcli.put(CLIFOGIAC_CODART, codart); + magcli.put(CLIFOGIAC_NRIGA, 1); + magcli.put(CLIFOGIAC_DOTTM, dottmp); + magcli.rewrite(); } - rdoc.put(RDOC_CODART,codart); - rdoc.put(RDOC_CODARTMAG,codart); - rdoc.put(RDOC_CHECKED,'X'); - if (prinbo) + if (qta > ZERO) { - if (!tmp) - rdoc.put(RDOC_PREZZO, prezzo); - else //per adesso per questo ramo non ci passa mai, perch� non sappiamo come gestire le dotazioni temporanee - rdoc.put(RDOC_PREZZO,rcont.get_real(LVRCONDV_PRZDTTMP)); - rdoc.put(RDOC_SCONTO,rcont.get(LVRCONDV_SCONTPERC)); //sconto + TRiga_documento& rdoc = doc.new_row(tiporiga); + + const real quantita_noarr = qta - conguaglio; + real quantita_arr = quantita_noarr > ZERO ? quantita_noarr : ZERO; + //se devo arrotondare + if (quantita_arr > ZERO && arrot) + { + //calcolo di quanti pezzi sforo + long arr = quantita_arr.integer() % ppconf.integer(); + //se sforo (arr > 0) allora calcolo quanti pezzi in pi� gli devo dare e aggiorno la quantit� + if (arr > 0) + if (arr > ppconf.integer() * perarr / 100) //arr <= ppconf*perarr/100 -> formula calcolo congualgio di Tassan + { + arr = ppconf.integer() - arr; + quantita_arr += arr; + } + else + quantita_arr -= arr; + } + + //scrivo le quantit� + rdoc.put(RDOC_QTA, quantita_arr); //quantit� consegnata eventualmente arrotondata + rdoc.put(RDOC_QTAGG1, qta1); //quantit� ritirata + rdoc.put(RDOC_QTAGG2, conguaglio); //conguaglio + rdoc.put(RDOC_QTAGG3, quantita_arr); //copia della quantit� consegnata + rdoc.put(RDOC_QTAGG4, quantita_noarr); //quantit� che avrei consegnato se non arrotondavo (qta ritirata) + rdoc.put(RDOC_GENERATA, true); + + rdoc.put(RDOC_CODAGG1, ini_get_string(CONFIG_DITTA, "lv", "CAUSLAV")); //causale presa dalla configurazione + + //aggiorno il conguaglio sulla riga del contratto + if (!rcont.empty()) + aggiorna_conguaglio((TRectype&)rcont, quantita_arr - quantita_noarr); + + //elaborazione sul prezzo da utilizzare + real prezzo; + + if (rcont.empty()) + { + //PROPONI PREZZO + TToken_string key; + key.add('C'); + key.add(codcli); + const TRectype& cfven = cache().get(LF_CFVEN, key); + + bool trvlst = false; + + if (!cfven.empty()) + { + //se � settata la categoria merceologica, leggo sia il listino che la cat merc, altrimenti solo il listino + TString8 codlis = cfven.get(CFV_CODLIST); + TString8 catven; + TConfig* configve = new TConfig(CONFIG_DITTA,"ve"); + const char gesliscv = configve->get_char("GESLISCV"); + if (gesliscv != 'X') + catven = ""; + else + catven = cfven.get(CFV_CATVEN); + //cerco il prezzo sul listino + key.cut(0); + key.add('L'); //tipo + key.add(catven); //catven + key.add(""); //tipocf + key.add(""); //codcf + key.add(codlis); //codlis + key.add('A'); //tiporiga + key.add(codart); //codriga + key.add(""); //um + key.add(""); //nscagl + const TRectype& rcondv = cache().get(LF_RCONDV, key); + + if (!rcondv.empty()) + { + prezzo = rcondv.get_real(RCONDV_PREZZO); + trvlst = true; + } + } + //se non ho trovato un listino, o se non c'� un listino impostato + //propongo come prezzo il valore convenzionale + if (!trvlst) + { + key.cut(0); + key.add(codart); + key.add(1); + const TRectype& umart = cache().get(LF_UMART, key); + prezzo = umart.get_real(UMART_PREZZO); + if (umart.get(UMART_PREZZO).full()) + trvlst = true; + } + } + else + { + //elaborazione per il prezzo: o lo prendo dalle righe contratto, o dall'anagrafica magazzino + if (tplis == 0) + prezzo = rcont.get_real(LVRCONDV_PREZZO); + else + prezzo = anamag.get_real(ANAMAG_COSTSTD); + } + + rdoc.put(RDOC_CODART,codart); + rdoc.put(RDOC_CODARTMAG,codart); + rdoc.put(RDOC_CHECKED,'X'); + if (prinbo) + { + if (!tmp) + rdoc.put(RDOC_PREZZO, prezzo); + else //per adesso per questo ramo non ci passa mai, perch� non sappiamo come gestire le dotazioni temporanee + rdoc.put(RDOC_PREZZO,rcont.get_real(LVRCONDV_PRZDTTMP)); + rdoc.put(RDOC_SCONTO,rcont.get(LVRCONDV_SCONTPERC)); //sconto + } + + //scrivo il magazzino + TString8 magazzino; + TString8 magazzinoc; + + magazzino << ini_get_string(CONFIG_DITTA, "lv", "CODMAG") << ini_get_string(CONFIG_DITTA, "lv", "CODMAGN"); + magazzinoc << ini_get_string(CONFIG_DITTA, "lv", "CODMAG") << ini_get_string(CONFIG_DITTA, "lv", "CODMAGC"); + + rdoc.put(RDOC_CODMAG, magazzino); + rdoc.put(RDOC_CODMAGC, magazzinoc); + + //se il record di riga contratto � vuoto aggiorno il log + if (rcont.empty()) + { + TString str; + str << "L'articolo " << codart << " inserito nel documento " << doc.get(DOC_CODNUM) << "-" << doc.get(DOC_TIPODOC) + << " numero " << doc.get(DOC_NDOC) << " per la quantit� di " << quantita_arr << " unit�" + << " non � prsente sul contratto del cliente " << codcli; + rep.log(1, str); + } } - - //scrivo il magazzino - TString8 magazzino; - TString8 magazzinoc; - - magazzino << ini_get_string(CONFIG_DITTA, "lv", "CODMAG") << ini_get_string(CONFIG_DITTA, "lv", "CODMAGN"); - magazzinoc << ini_get_string(CONFIG_DITTA, "lv", "CODMAG") << ini_get_string(CONFIG_DITTA, "lv", "CODMAGC"); - - rdoc.put(RDOC_CODMAG, magazzino); - rdoc.put(RDOC_CODMAGC, magazzinoc); - - //se il record di riga contratto � vuoto aggiorno il log - if (rcont.empty()) - { - TString str; - str << "L'articolo " << codart << " inserito nel documento " << doc.get(DOC_CODNUM) << "-" << doc.get(DOC_TIPODOC) - << " numero " << doc.get(DOC_NDOC) << " per la quantit� di " << quantita_arr << " unit�" - << " non � prsente sul contratto del cliente " << codcli; - rep.log(1, str); - } - } //////////////////////////////////////////////////////////////