File: FLStocks.cpp

package info (click to toggle)
facturalux 0.4-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,040 kB
  • ctags: 1,359
  • sloc: ansic: 15,260; cpp: 12,761; sh: 10,520; perl: 2,023; makefile: 692; xml: 194
file content (186 lines) | stat: -rw-r--r-- 9,686 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/***************************************************************************
                          FLStocks.cpp  -  description
                             -------------------
    begin                : Thu Jul 18 2002
    copyright            : (C) 2002 by Andres Oton Urbano
    email                : baxas@eresmas.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "FLStocks.h"

FLStocks::FLStocks ():FLReceiver ()
{
}

FLStocks::~FLStocks ()
{
  if (cursor_ )
	  disconnect (cursor_, SIGNAL (bufferChanged (QString)), this, SLOT (bufferChanged (QString)));
}

QVariant FLStocks::calculateField (const QString & )
{ 

    return  QVariant (cursor_->valueBuffer ("cantidad").toDouble () * cursor_->valueBuffer ("precio").toDouble ());

}

void                                                                                     
FLStocks::setSender(FLFormDB * sender)                                                   
{
  sender_ = sender;

  if (!cursor_)
	return;

  connect (cursor_, SIGNAL (bufferChanged (QString)), SLOT (bufferChanged (QString)));

  QWidget * main = sender_->mainWidget();

  if (!main)
    return;

 QObject *obj = main ->child ("precio");
  if (obj)
    {
      
            ((FLFieldDB *)obj)->setForeignField("preciocompra");
    }
}

void
FLStocks::bufferChanged (QString)
{
  if (!sender_)
    return;

  QWidget * main = sender_->mainWidget();

  if (!main)
    return;

  double res = 1 ; 

  QObject *obj = main->child ("cantidad");    

  if (obj)
    {
	    res *= ((QLineEdit *) ((FLFieldDB *) obj)->editor ())->text ().toDouble ();
    }

  obj = main->child ("precio");
  if (obj)
	res *= ((QLineEdit *) ((FLFieldDB *) obj)->editor ())->text ().toDouble ();

  obj = main->child ("total");
  if (obj)
	  ((QLabel *) obj)->setText (QString::number (res));   

}

void FLStocks::modifyStocks(QString idarticulo, QString idalmacenorig, QString idalmacendest, double cantidad)
{
          FLSqlCursor *cursorstocks = new FLSqlCursor("flstocks");
          FLSqlCursor *cursorkit = new FLSqlCursor("flkit");
          FLSqlCursor *cursorarticulos = new FLSqlCursor("flarticulos");
          FLSqlCursor *cursoraux = new FLSqlCursor("flarticulos");

          cursorarticulos->select("codarticulo="+FLManager::formatValue(cursorarticulos->metadata()->field("codarticulo"),idarticulo));
          cursorarticulos->refresh();

          if(cursorarticulos->valueBuffer("Kit").toBool()==true)
          {
                    cursorkit->select("idkit="+FLManager::formatValue(cursorkit->metadata()->field("idkit"),idarticulo));
                    cursorkit->refresh();


                    while(cursorkit->next())
                    {
                              cursorstocks->select("idarticulo="+FLManager::formatValue(cursorstocks->metadata()->field("idarticulo"),idarticulo));
                              cursorstocks->refresh();

                              cursoraux->select("idarticulo="+FLManager::formatValue(cursoraux->metadata()->field("idarticulo"),cursorkit->valueBuffer("idarticulo")));
                              cursoraux->refresh();
                              if(cursoraux->valueBuffer("Kit").toBool()==true)
                                        FLStocks::modifyStocks(QString::QString(cursorkit->valueBuffer("codarticulo").toString()), QString::QString(idalmacenorig), QString::QString(idalmacendest), cursorkit->valueBuffer("cantidad").toDouble()*cantidad);
                              else
                              {
                                        if(cursorarticulos->valueBuffer("tipostock").toInt()==FLStocks::Contable && cursorarticulos->valueBuffer("tipo").toInt()==FLStocks::Origen)
                                                  while(cursorstocks->next())
                                                  {
                                                            if(cursorstocks->valueBuffer("codalmacen")==FLManager::formatValue(cursorstocks->metadata()->field("codalmecen"),idalmacenorig))
                                                            {
                                                                      cursorstocks->setModeAccess(FLSqlCursor::EDIT);
                                                                      cursorstocks->transaction();
                                                                      cursorstocks->setValueBuffer("cantidad",FLManager::formatValue(cursorstocks->metadata()->field("cantidad"),cursorstocks->valueBuffer("cantidad").toInt()-cantidad));
                                                                      cursorstocks->commitBuffer();
                                                                      cursorstocks->commit();
                                                                      cursorstocks->last();
                                                            }
                                                  }
                                        cursorstocks->first();
                                        if(cursorarticulos->valueBuffer("tipo").toInt()==FLStocks::Contable && cursorarticulos->valueBuffer("tipo").toInt()==FLStocks::Destino)
                                                  while(cursorstocks->next())
                                                  {
                                                            if(cursorstocks->valueBuffer("codalmacen")==FLManager::formatValue(cursorstocks->metadata()->field("codalmecen"),idalmacendest))
                                                            {
                                                                      cursorstocks->setModeAccess(FLSqlCursor::EDIT);
                                                                      cursorstocks->transaction();
                                                                      cursorstocks->setValueBuffer("cantidad",FLManager::formatValue(cursorstocks->metadata()->field("cantidad"),cursorstocks->valueBuffer("cantidad").toInt()+cantidad));
                                                                      cursorstocks->commitBuffer();
                                                                      cursorstocks->commit();
                                                                      cursorstocks->last();
                                                            }
                                                  }

                              }
                    }
          }
          else
          {
                    cursorstocks->select("idarticulo="+FLManager::formatValue(cursorstocks->metadata()->field("idarticulo"),idarticulo));
                    cursorstocks->refresh();

                    if(cursorarticulos->valueBuffer("tipostock").toInt()==FLStocks::Contable && cursorarticulos->valueBuffer("tipo").toInt()==FLStocks::Origen)
                              while(cursorstocks->next())
                              {
                                        if(cursorstocks->valueBuffer("codalmacen")==FLManager::formatValue(cursorstocks->metadata()->field("codalmecen"),idalmacenorig))
                                        {
                                                  cursorstocks->setModeAccess(FLSqlCursor::EDIT);
                                                  cursorstocks->transaction();
                                                  cursorstocks->setValueBuffer("cantidad",FLManager::formatValue(cursorstocks->metadata()->field("cantidad"),cursorstocks->valueBuffer("cantidad").toInt()-cantidad));
                                                  cursorstocks->commitBuffer();
                                                  cursorstocks->commit();
                                                  cursorstocks->last();
                                        }
                              }
                    cursorstocks->first();
                    if(cursorarticulos->valueBuffer("tipo").toInt()==FLStocks::Contable && cursorarticulos->valueBuffer("tipo").toInt()==FLStocks::Destino)
                              while(cursorstocks->next())
                              {
                                        if(cursorstocks->valueBuffer("codalmacen")==FLManager::formatValue(cursorstocks->metadata()->field("codalmecen"),idalmacendest))
                                        {
                                                  cursorstocks->setModeAccess(FLSqlCursor::EDIT);
                                                  cursorstocks->transaction();
                                                  cursorstocks->setValueBuffer("cantidad",FLManager::formatValue(cursorstocks->metadata()->field("cantidad"),cursorstocks->valueBuffer("cantidad").toInt()+cantidad));
                                                  cursorstocks->commitBuffer();
                                                  cursorstocks->commit();
                                                  cursorstocks->last();
                                        }
                              }

          }
}