Revision 195883fd
Von Stephan Köhler vor etwa 19 Jahren hinzugefügt
SL/IC.pm | ||
---|---|---|
33 | 33 |
#====================================================================== |
34 | 34 |
|
35 | 35 |
package IC; |
36 |
|
|
36 |
use Data::Dumper; |
|
37 | 37 |
sub get_part { |
38 | 38 |
$main::lxdebug->enter_sub(); |
39 | 39 |
|
... | ... | |
101 | 101 |
$form->{amount}{IC_expense} = $form->{expense_accno}; |
102 | 102 |
$form->{amount}{IC_cogs} = $form->{expense_accno}; |
103 | 103 |
|
104 |
# get prices |
|
105 |
$query = |
|
106 |
qq|SELECT p.parts_id, p.pricegroup_id, p.price, (SELECT pg.pricegroup FROM pricegroup pg WHERE pg.id=p.pricegroup_id) AS pricegroup FROM prices p |
|
107 |
WHERE parts_id = $form->{id} |
|
108 |
ORDER by pricegroup|; |
|
109 |
|
|
110 |
$sth = $dbh->prepare($query); |
|
111 |
$sth->execute || $form->dberror($query); |
|
112 |
|
|
113 |
@pricegroups = (); |
|
114 |
@pricegroups_not_used = (); |
|
115 |
|
|
116 |
#for pricegroups |
|
117 |
my $i = 1; |
|
118 |
while ( |
|
119 |
($form->{"klass_$i"}, $form->{"pricegroup_id_$i"}, |
|
120 |
$form->{"price_$i"}, $form->{"pricegroup_$i"}) |
|
121 |
= $sth->fetchrow_array |
|
122 |
) { |
|
123 |
$form->{"price_$i"} = $form->round_amount($form->{"price_$i"}, 5); |
|
124 |
$form->{"price_$i"} = |
|
125 |
$form->format_amount($myconfig, $form->{"price_$i"}, 5); |
|
126 |
push @pricegroups, $form->{"pricegroup_id_$i"}; |
|
127 |
$i++; |
|
128 |
} |
|
129 |
|
|
130 |
$sth->finish; |
|
131 |
|
|
132 |
# get pricegroups |
|
133 |
$query = qq|SELECT p.id, p.pricegroup FROM pricegroup p|; |
|
134 |
|
|
135 |
$pkq = $dbh->prepare($query); |
|
136 |
$pkq->execute || $form->dberror($query); |
|
137 |
while ($pkr = $pkq->fetchrow_hashref(NAME_lc)) { |
|
138 |
push @{ $form->{PRICEGROUPS} }, $pkr; |
|
139 |
} |
|
140 |
$pkq->finish; |
|
141 |
|
|
142 |
#find not used pricegroups |
|
143 |
while ($tmp = pop @{ $form->{PRICEGROUPS} }) { |
|
144 |
my $insert = 0; |
|
145 |
foreach $item (@pricegroups) { |
|
146 |
if ($item eq $tmp->{id}) { |
|
147 |
|
|
148 |
#drop |
|
149 |
$insert = 1; |
|
150 |
} |
|
151 |
} |
|
152 |
if ($insert == 0) { |
|
153 |
push @pricegroups_not_used, $tmp; |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
# if not used pricegroups are avaible |
|
158 |
if (@pricegroups_not_used) { |
|
159 |
|
|
160 |
foreach $name (@pricegroups_not_used) { |
|
161 |
$form->{"klass_$i"} = "$name->{id}"; |
|
162 |
$form->{"price_$i"} = $form->round_amount($form->{sellprice}, 5); |
|
163 |
$form->{"price_$i"} = |
|
164 |
$form->format_amount($myconfig, $form->{"price_$i"}, 5); |
|
165 |
$form->{"pricegroup_id_$i"} = "$name->{id}"; |
|
166 |
$form->{"pricegroup_$i"} = "$name->{pricegroup}\n"; |
|
167 |
$i++; |
|
168 |
} |
|
169 |
} |
|
170 |
|
|
171 |
#correct rows |
|
172 |
$form->{price_rows} = $i - 1; |
|
173 |
|
|
104 | 174 |
unless ($form->{item} eq 'service') { |
105 | 175 |
|
106 | 176 |
# get makes |
... | ... | |
332 | 402 |
WHERE id = $form->{id}|; |
333 | 403 |
$dbh->do($query) || $form->dberror($query); |
334 | 404 |
|
405 |
# delete price records |
|
406 |
$query = qq|DELETE FROM prices |
|
407 |
WHERE parts_id = $form->{id}|; |
|
408 |
$dbh->do($query) || $form->dberror($query); |
|
409 |
|
|
410 |
# insert price records only if different to sellprice |
|
411 |
for my $i (1 .. $form->{price_rows}) { |
|
412 |
if (( $form->{"price_$i"} |
|
413 |
|| $form->{"klass_$i"} |
|
414 |
|| $form->{"pricegroup_id_$i"}) and $form->{"price_$i"} != $form->{sellprice}) { |
|
415 |
$klass = $form->parse_amount($myconfig, $form->{"klass_$i"}); |
|
416 |
$price = $form->parse_amount($myconfig, $form->{"price_$i"}); |
|
417 |
$pricegroup_id = |
|
418 |
$form->parse_amount($myconfig, $form->{"pricegroup_id_$i"}); |
|
419 |
$query = qq|INSERT INTO prices (parts_id, pricegroup_id, price) |
|
420 |
VALUES($form->{id},$pricegroup_id,$price)|; |
|
421 |
$dbh->do($query) || $form->dberror($query); |
|
422 |
} |
|
423 |
} |
|
424 |
|
|
335 | 425 |
# insert makemodel records |
336 | 426 |
unless ($form->{item} eq 'service') { |
337 | 427 |
for my $i (1 .. $form->{makemodel_rows}) { |
Auch abrufbar als: Unified diff
Preisgruppenerweiterung auf Basis von Andres Patch - Thanks
Preisgruppenverwaltung
...-Preiseingabe der Preisgruppen in Masken Waren,etc.
-Auswahl der Preisgruppen in den Verkaufsmasken
Erweiterung Datenbankschema