git-svn-id: svn://10.65.10.50/branches/R_10_00@22724 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			147 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			147 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <applicat.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <textset.h>
 | 
						|
 | 
						|
#include "../cg/cgsaldac.h"
 | 
						|
 | 
						|
class TCheckDoublePagsca : public TSkeleton_application
 | 
						|
{
 | 
						|
protected:
 | 
						|
  void add_rec(const TISAM_recordset& inp, TCSV_recordset& outp);
 | 
						|
 | 
						|
public:
 | 
						|
  virtual void main_loop();
 | 
						|
};
 | 
						|
 | 
						|
void TCheckDoublePagsca::add_rec(const TISAM_recordset& p, TCSV_recordset& o)
 | 
						|
{
 | 
						|
  o.new_rec();
 | 
						|
  o.set(0, p.get(PART_TIPOCF));
 | 
						|
  o.set(1, p.get(PART_SOTTOCONTO));
 | 
						|
  o.set(2, p.get(PART_ANNO));
 | 
						|
  o.set(3, p.get(PART_NUMPART));
 | 
						|
  o.set(4, p.get(PART_NRIGA));
 | 
						|
  o.set(5, p.get(PART_IMPORTO));
 | 
						|
  o.set(6, p.get(PART_NREG));
 | 
						|
  o.set(7, p.get(PART_DESCR));
 | 
						|
}
 | 
						|
 | 
						|
void TCheckDoublePagsca::main_loop()
 | 
						|
{
 | 
						|
  TCSV_recordset o("");
 | 
						|
  o.create_column(PART_TIPOCF,     _alfafld);
 | 
						|
  o.create_column(PART_SOTTOCONTO, _longfld);
 | 
						|
  o.create_column(PART_ANNO,       _intfld);
 | 
						|
  o.create_column(PART_NUMPART,    _alfafld);
 | 
						|
  o.create_column(PART_NRIGA,      _intfld);
 | 
						|
  o.create_column(PART_IMPORTO,    _realfld);
 | 
						|
  o.create_column("NUM_REG",       _longfld);
 | 
						|
  o.create_column("Descrizione riga pagamento", _alfafld);
 | 
						|
 | 
						|
  TISAM_recordset p("USE PART SELECT TIPOMOV=3\nTO TIPOC=C");
 | 
						|
  const TRecnotype tot = p.items();
 | 
						|
 | 
						|
  if (tot > 1)
 | 
						|
  {
 | 
						|
    TProgind pi(tot, title());
 | 
						|
 | 
						|
    long sott1 = 0;
 | 
						|
    int anno1 = 0;
 | 
						|
    TString16 part1;
 | 
						|
    long nreg1 = 0;
 | 
						|
    int nrig1 = 0;
 | 
						|
    real impt1;
 | 
						|
    for (bool ok = p.move_first(); ok; ok = p.move_next())
 | 
						|
    {
 | 
						|
      if (!pi.addstatus(1))
 | 
						|
        break;
 | 
						|
      const long sott2 = p.get(PART_SOTTOCONTO).as_int();
 | 
						|
      const int anno2 = p.get(PART_ANNO).as_int();
 | 
						|
      const TString16 part2 = p.get(PART_NUMPART).as_string();
 | 
						|
      const long nreg2 = p.get(PART_NREG).as_int();
 | 
						|
      const int nrig2 = p.get(PART_NUMRIG).as_int();
 | 
						|
      const real impt2 = p.get(PART_IMPORTO).as_real();
 | 
						|
      if (sott1 == sott2 && anno1 == anno2 && part1 == part2 && nreg1 == nreg2 && nrig1 == nrig2 && impt1 == impt2)
 | 
						|
      {
 | 
						|
        p.move_prev();
 | 
						|
        add_rec(p, o);
 | 
						|
        p.move_next();
 | 
						|
        add_rec(p, o);
 | 
						|
      }
 | 
						|
      sott1 = sott2;
 | 
						|
      anno1 = anno2;
 | 
						|
      part1 = part2;
 | 
						|
      nreg1 = nreg2;
 | 
						|
      nrig1 = nrig2;
 | 
						|
      impt1 = impt2;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  const TRecnotype d = o.items();
 | 
						|
  if (d > 0)
 | 
						|
  {
 | 
						|
    TRecordset_sheet s(o);
 | 
						|
    if (s.run() == K_ENTER && noyes_box(FR("Confermare l'eliminazione di %ld righe doppie"), d/2))
 | 
						|
    {
 | 
						|
      TProgind pi(tot, TR("Eliminazione pagamenti doppi"));
 | 
						|
      TRecnotype e = 0;
 | 
						|
      for (bool ok = o.move_first(); ok; ok = o.move_next())
 | 
						|
      {
 | 
						|
        if (!pi.addstatus(1))
 | 
						|
          break;
 | 
						|
        const char tipocf = o.get(0L).as_string()[0];
 | 
						|
        const long codcf  = o.get(1).as_int();
 | 
						|
        const int anno    = o.get(2).as_int();
 | 
						|
        const TString8 num= o.get(3).as_string();
 | 
						|
        const int nriga1  = o.get(4).as_int();
 | 
						|
 | 
						|
        o.move_next();
 | 
						|
        const int nriga2  = o.get(4).as_int();
 | 
						|
        CHECKD(nriga1 < nriga2, "Numero riga partita incoerente ", nriga2);
 | 
						|
 | 
						|
        const TBill clifo(0, 0, codcf, tipocf);
 | 
						|
        TPartita p(clifo, anno, num);
 | 
						|
 | 
						|
        TRecord_array& u = p.unassigned();
 | 
						|
        const int flag = (u.exist(nriga1) ? 1 : 0) + (u.exist(nriga2) ? 2 : 0);
 | 
						|
        if (flag != 0)
 | 
						|
        {
 | 
						|
          const int nrigp = (flag == 1) ? nriga1 : nriga2;
 | 
						|
          p.elimina_pagamento(9999, 9999, nrigp);
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
          const int nrigp = nriga2;
 | 
						|
          for (int f = p.prima_fattura(); f > 0 && f < nriga2; f = p.succ(f))
 | 
						|
          {
 | 
						|
            const TRiga_partite& rf = p.riga(f);     // Fattura
 | 
						|
            for (int r = rf.rate(); r > 0; r--)
 | 
						|
            {
 | 
						|
              if (p.esiste(f, r, nrigp))
 | 
						|
                p.elimina_pagamento(f, r, nrigp);
 | 
						|
            }
 | 
						|
          }
 | 
						|
        }
 | 
						|
        if (p.rewrite())
 | 
						|
          e++;
 | 
						|
        else
 | 
						|
        {
 | 
						|
          error_box(TR("Errore durante l'aggiornamento delle partite"));
 | 
						|
          break;
 | 
						|
        }
 | 
						|
      }
 | 
						|
      message_box(FR("Sono state eliminate %ld righe"), e);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  else
 | 
						|
    message_box(TR("Non sono stati rilevati pagamenti doppi"));
 | 
						|
}
 | 
						|
 | 
						|
int sc1500(int argc, char** argv)
 | 
						|
{
 | 
						|
  TCheckDoublePagsca a;
 | 
						|
  a.run(argc, argv, TR("Controllo pagamenti doppi"));
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 |