Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 43f9b1c5

Von G. Richardson vor etwa 13 Jahren hinzugefügt

  • ID 43f9b1c512be9bc2199369c2f5accea32b8bd423
  • Vorgänger 45de0008
  • Nachfolger 306fad80

Umstellung von eur zu 3 Variablen in defaults

accounting_method inventory_system profit_determination

Details siehe doc/umstellung_eur.txt

Unterschiede anzeigen:

SL/IR.pm
103 103
    $form->{"qty_$i"}  = $form->parse_amount($myconfig, $form->{"qty_$i"});
104 104
    $form->{"qty_$i"} *= -1 if $form->{storno};
105 105

  
106
    $form->{"inventory_accno_$i"} = $form->{"expense_accno_$i"} if $::lx_office_conf{system}->{eur};
106
    if ( $::instance_conf->get_inventory_system eq 'periodic') {
107
      # inventory account number is overwritten with expense account number, so
108
      # never book incoming to inventory account but always to expense account
109
      $form->{"inventory_accno_$i"} = $form->{"expense_accno_$i"} 
110
    };
107 111

  
108 112
    # get item baseunit
109 113
    if (!$item_units{$form->{"id_$i"}}) {
......
211 215
      # check if we sold the item already and
212 216
      # make an entry for the expense and inventory
213 217
      $query =
214
        qq|SELECT i.id, i.qty, i.allocated, i.trans_id,
218
        qq|SELECT i.id, i.qty, i.allocated, i.trans_id, i.base_qty,
215 219
             p.inventory_accno_id, p.expense_accno_id, a.transdate
216 220
           FROM invoice i, ar a, parts p
217 221
           WHERE (i.parts_id = p.id)
......
219 223
             AND ((i.base_qty + i.allocated) > 0)
220 224
             AND (i.trans_id = a.id)
221 225
           ORDER BY transdate|;
226
           # ORDER BY transdate guarantees FIFO
227

  
228
# sold two items without having bought them yet, example result of query:
229
# id | qty | allocated | trans_id | inventory_accno_id | expense_accno_id | transdate  
230
# ---+-----+-----------+----------+--------------------+------------------+------------
231
#  9 |   2 |         0 |        9 |                 15 |              151 | 2011-01-05
232

  
233
# base_qty + allocated > 0 if article has already been sold but not bought yet
234

  
235
# select qty,allocated,base_qty,sellprice from invoice where trans_id = 9;
236
#  qty | allocated | base_qty | sellprice  
237
# -----+-----------+----------+------------
238
#    2 |         0 |        2 | 1000.00000
239

  
222 240
      $sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{"id_$i"}));
223 241

  
224 242
      my $totalqty = $baseqty;
......
227 245
        my $qty    = min $totalqty, ($ref->{base_qty} + $ref->{allocated});
228 246
        $linetotal = $form->round_amount(($form->{"sellprice_$i"} * $qty) / $basefactor, 2);
229 247

  
230
        if ($ref->{allocated} < 0) {
231

  
232
          # we have an entry for it already, adjust amount
233
          $form->update_balance($dbh, "acc_trans", "amount",
234
                                qq|    (trans_id = $ref->{trans_id})
235
                                   AND (chart_id = $ref->{inventory_accno_id})
236
                                   AND (transdate = '$ref->{transdate}')|,
237
                                $linetotal);
238

  
239
          $form->update_balance($dbh, "acc_trans", "amount",
240
                                qq|    (trans_id = $ref->{trans_id})
241
                                   AND (chart_id = $ref->{expense_accno_id})
242
                                   AND (transdate = '$ref->{transdate}')|,
243
                                $linetotal * -1);
244

  
245
        } elsif ($linetotal != 0) {
246
          # add entry for inventory, this one is for the sold item
247
          $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?))|;
248
          @values = ($ref->{trans_id},  $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id});
249
          do_query($form, $dbh, $query, @values);
250

  
251
          # add expense
252
          $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?))|;
253
          @values = ($ref->{trans_id},  $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id});
254
          do_query($form, $dbh, $query, @values);
255
        }
248
        if  ( $::instance_conf->get_inventory_system eq 'perpetual' ) {
249
        # Warenbestandsbuchungen nur bei Bestandsmethode
250

  
251
          if ($ref->{allocated} < 0) {
252

  
253
# we have an entry for it already, adjust amount
254
            $form->update_balance($dbh, "acc_trans", "amount",
255
                qq|    (trans_id = $ref->{trans_id})
256
                AND (chart_id = $ref->{inventory_accno_id})
257
                AND (transdate = '$ref->{transdate}')|,
258
                $linetotal);
259

  
260
            $form->update_balance($dbh, "acc_trans", "amount",
261
                qq|    (trans_id = $ref->{trans_id})
262
                AND (chart_id = $ref->{expense_accno_id})
263
                AND (transdate = '$ref->{transdate}')|,
264
                $linetotal * -1);
265

  
266
          } elsif ($linetotal != 0) {
267

  
268
            # allocated >= 0
269
            # add entry for inventory, this one is for the sold item
270
            $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?))|;
271
            @values = ($ref->{trans_id},  $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id});
272
            do_query($form, $dbh, $query, @values);
273

  
274
# add expense
275
            $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?))|;
276
            @values = ($ref->{trans_id},  $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id});
277
            do_query($form, $dbh, $query, @values);
278
          }
279
        };
256 280

  
257 281
        # update allocated for sold item
258 282
        $form->update_balance($dbh, "invoice", "allocated", qq|id = $ref->{id}|, $qty * -1);
......
265 289
      $sth->finish();
266 290

  
267 291
    } else {                    # if ($form->{"inventory_accno_id_$i"})
292
      # part doesn't have an inventory_accno_id
293
      # lastcost of the part is updated at the end
268 294

  
269 295
      $linetotal = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} / $price_factor, 2);
270 296

  

Auch abrufbar als: Unified diff