From 55fc8fb76668280ee007a8c891d31a7d655faf99 Mon Sep 17 00:00:00 2001
From: villa <villa@c028cbd2-c16b-5b4b-a496-9718f37d4682>
Date: Thu, 17 Nov 1994 09:35:15 +0000
Subject: [PATCH] Aggiornata gestione corrispettivi come da fax misterioso in
 liquidazione Aggiunte frasi concilianti nel controllo esistenza registri di
 cg5300

git-svn-id: svn://10.65.10.50/trunk@646 c028cbd2-c16b-5b4b-a496-9718f37d4682
---
 cg/cg4301.cpp | 124 +++++++++++++++++++++++++++++---------------------
 cg/cg4303.cpp |   5 +-
 cg/cg5300.cpp |   2 +-
 3 files changed, 75 insertions(+), 56 deletions(-)

diff --git a/cg/cg4301.cpp b/cg/cg4301.cpp
index 2883b7d94..b929b62c8 100755
--- a/cg/cg4301.cpp
+++ b/cg/cg4301.cpp
@@ -15,7 +15,7 @@ bool TLiquidazione_app::recalc_all()
   long l;
   
   _prind = new TProgind(_selected.ones()*2,
-                        "       Calcolo liquidazioni...     \n"
+                        "       Calcolo liquidazione...     \n"
                         "       Preparazione archivi      ",
                         TRUE,TRUE,45);
 
@@ -440,7 +440,8 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt)
       if (_isplafond && tipomov == acquisto && 
           tipoiva == "NI" && tipopla != 0)
       { 
-        if (tipodoc == "BD") intra = TRUE;
+        if (tipodoc == "BD") 
+          intra = TRUE;
         add_plafond(month, codatt, tipopla, imponibile, intra);
       }
       // agenzie viaggio (CHECK imponibili etc.)
@@ -478,7 +479,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt)
         continue;                       // non entrano in liquidazione
       }
       
-      if (tipodet == 3)  // passaggi interni (solo ventilaz.)
+      if (tipodet == 3)  // passaggi interni (solo ventilaz)
       {  
         acq_pint     += imponibile;
         acq_pint_iva += imposta;
@@ -488,20 +489,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt)
       // ***************************************** 
       // Fine casi particolari
       // Non che i casi normali siano tanto meglio
-      // ***************************************** 
-
-      if (tipomov == vendita)
-      {
-        // totale vendite
-        vendite     += imponibile;
-        vendite_iva += imposta;
-      }
-      else
-      {
-        // totale acquisti
-        acquisti     += imponibile;
-        acquisti_iva += imposta;
-      }
+      // *****************************************
 
       /*
        * Calcolo e aggiornamento
@@ -513,31 +501,74 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt)
       real imp = _pim_r->get_real("R0"); // imponibile
       real ivp = _pim_r->get_real("R1"); // IVA su imp.
       real lor = _pim_r->get_real("R2"); // lordo
-      
-      /*
-       * se corrispettivi da ventilare considera il lordo
-       */
-      if (corrisp && tipoiva == "VE")
-      {
-        lor += imponibile;
-        _pim_r->put("I0",LORDO);
-        add_vendite(month, reg, imponibile);
-      }                    
-      /*
-       *  corrispettivi non da ventilare vanno comunque scorporati poi
-       */
-      else if (corrisp)
-      {
-        real perc = _iva->get_real("R0") / CENTO;
 
-        lor += imponibile;
-        lor += imposta;
-        _pim_r->put("I0",LORDO);
-        add_corrisp(month, reg, imponibile, perc, codiva);
+
+      if (tipomov == vendita && !corrisp)  // i corrispettivi sono gestiti a parte
+      {
+        // totale vendite
+        vendite     += imponibile;
+        vendite_iva += imposta;
       }
-      else
+      else if (tipomov == acquisto)
+      {
+        // totale acquisti
+        acquisti     += imponibile;
+        acquisti_iva += imposta;
+      }
+      
+      // corrispettivi               
+      if (corrisp)
+      {
+        // l'ultimo casino
+        if (tipodoc == "CR" || tipodoc == "RF" || tipodoc == "SC")
+        {
+          // questi sono corrispettivi davvero; comportamento normale 
+          if (tipoiva == "VE")   // da ventilare
+          {
+            lor += imponibile;
+            _pim_r->put("I0",LORDO);
+            add_vendite(month, reg, imponibile);
+          }                    
+          else // non da ventilare, con imposta gia' conteggiata
+          {
+            real perc = _iva->get_real("R0") / CENTO;
+            lor += imponibile + imposta;
+            _pim_r->put("I0",LORDO);
+            add_corrisp(month, reg, imponibile, perc, codiva);
+          }
+        }
+      else if (tipodoc == "FS")
+      {
+        // queste sono fatture che seguono scontrino, il lordo va detratto
+        // perche' si e' gia' registrato lo scontrino medesimo
+        if (tipoiva == "VE")
+        {
+          real rr  = imponibile + imposta; 
+          vendite += rr;
+          imp     += rr;
+          add_vendite(month, reg, rr); 
+        }
+        else
+        {
+          vendite     += imponibile;
+          vendite_iva += imposta;
+          imp         += imponibile;
+          ivp         += imposta;
+        }
+        lor           -= imponibile + imposta; 
+      }
+        else  // vendite normali a tutti gli effetti
+        {     
+          vendite     += imponibile;
+          vendite_iva += imposta;
+          imp         += imponibile;
+          ivp         += imposta;
+          _pim_r->put("I0",NETTO);
+        }
+      }  // if corrisp
+      else // non corrisp
       { 
-        // netti e imposta separata
+        // imponibile e imposta separata
         imp += imponibile;
         ivp += imposta;
         _pim_r->put("I0",NETTO);
@@ -627,8 +658,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt)
   _plm->put("R1", acquisti_iva);
   _plm->put("R3", ult_detr);
   _plm->put("R12", _prorata); // per comodita' in stampa
-  _plm->put("B0", "X");       // calcolato (deve essere invalidato dalla
-  // primanota)
+  _plm->put("B0", "X");       // calcolato (invalidato dalla primanota)
   _plm->put("S1",  for_rimb.string());
   _plm->put("S2",  acq_ies.string());
   _plm->put("S3",  acq_ies_iva.string());
@@ -914,17 +944,5 @@ _DescrItem* TLiquidazione_app::recalc_rimborso(int month, const char* codatts)
     d->_r7 = ala * CENTO; 
   }
 
-  //  if (rimborsami)
-  //  {
-  // il rimborso NON viene chiesto
-  //    look_lim(month);
-  //    real cred = _lim->get_real("R0");
-  //    if (cred.sign() < 0)
-  //    {
-  //      _lim->put("R1",abs(cred));
-  //      _lim->rewrite();
-  //    }
-  //  }
-  
   return d;
 }
diff --git a/cg/cg4303.cpp b/cg/cg4303.cpp
index a7210bf7d..7fcd7f86a 100755
--- a/cg/cg4303.cpp
+++ b/cg/cg4303.cpp
@@ -64,7 +64,8 @@ void TLiquidazione_app::zero_plafond (int month, const char* codatt)
     _ppa_r->put("R1","");
     _ppa->rewrite();
   } // for tipo esenzione plafond      
-}  
+}                                     
+
 // ricalcolo dei corrispettivi
 void TLiquidazione_app::recalc_corrispettivi(int month, const char* codatt)
 {
@@ -94,7 +95,7 @@ void TLiquidazione_app::recalc_corrispettivi(int month, const char* codatt)
     imposta    += _pim->get_real("R1");
     _pim->put("R0", imponibile);
     _pim->put("R1", imposta);
-    _pim->zero("R2"); // e' giusto ???? TBI
+
     // segnale per comodita'
     _pim->put("B1","X");
     _pim->rewrite();
diff --git a/cg/cg5300.cpp b/cg/cg5300.cpp
index 2904a6905..da1086d20 100755
--- a/cg/cg5300.cpp
+++ b/cg/cg5300.cpp
@@ -101,7 +101,7 @@ void CG5300_App::check_registers(int year)
 		 if (flags < R_ALL)
 		 {      
 		 	TString att = (TString&)_atts[i];
-		 	TString wrn("I seguenti registri non esistono per l'attivita' "); 
+		 	TString wrn("I seguenti registri probabilmente non esistono per l'attivita' "); 
             wrn << att << ":";
             if ((flags & R_VEN) == 0x00) wrn << "\n\tregistro vendite";
             if ((flags & R_ACQ) == 0x00) wrn << "\n\tregistro acquisti";