Revision eebe8e90
Von Sven Schöling vor etwa 10 Jahren hinzugefügt
SL/IS.pm | ||
---|---|---|
2131 | 2131 |
$main::lxdebug->leave_sub(); |
2132 | 2132 |
} |
2133 | 2133 |
|
2134 |
########################## |
|
2135 |
# get pricegroups from database |
|
2136 |
# build up selected pricegroup |
|
2137 |
# if an exchange rate - change price |
|
2138 |
# for each part |
|
2139 |
# |
|
2140 |
sub get_pricegroups_for_parts { |
|
2141 |
|
|
2142 |
$main::lxdebug->enter_sub(); |
|
2143 |
|
|
2144 |
my ($self, $myconfig, $form) = @_; |
|
2145 |
|
|
2146 |
my $dbh = $form->get_standard_dbh; |
|
2147 |
|
|
2148 |
$form->{"PRICES"} = {}; |
|
2149 |
|
|
2150 |
my $i = 1; |
|
2151 |
my $id = 0; |
|
2152 |
my $all_units = AM->retrieve_units($myconfig, $form); |
|
2153 |
while (($form->{"id_$i"}) or ($form->{"new_id_$i"})) { |
|
2154 |
$form->{"PRICES"}{$i} = []; |
|
2155 |
|
|
2156 |
$id = $form->{"id_$i"}; |
|
2157 |
|
|
2158 |
if (!($form->{"id_$i"}) and $form->{"new_id_$i"}) { |
|
2159 |
$id = $form->{"new_id_$i"}; |
|
2160 |
} |
|
2161 |
|
|
2162 |
my ($price, $selectedpricegroup_id) = split(/--/, $form->{"sellprice_pg_$i"}); |
|
2163 |
|
|
2164 |
my $pricegroup_old = $form->{"pricegroup_old_$i"}; |
|
2165 |
|
|
2166 |
# sellprice has format 13,0000 or 0,00000, can't check for 0 numerically |
|
2167 |
my $sellprice = $form->{"sellprice_$i"}; |
|
2168 |
my $pricegroup_id = $form->{"pricegroup_id_$i"}; |
|
2169 |
$form->{"new_pricegroup_$i"} = $selectedpricegroup_id; |
|
2170 |
$form->{"old_pricegroup_$i"} = $pricegroup_old; |
|
2171 |
|
|
2172 |
my $price_new = $form->{"price_new_$i"}; |
|
2173 |
my $price_old = $form->{"price_old_$i"}; |
|
2174 |
|
|
2175 |
if (!$form->{"unit_old_$i"}) { |
|
2176 |
# Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die |
|
2177 |
# Einheit, wie sie in den Stammdaten hinterlegt wurde. |
|
2178 |
# Es sollte also angenommen werden, dass diese ausgewaehlt war. |
|
2179 |
$form->{"unit_old_$i"} = $form->{"unit_$i"}; |
|
2180 |
} |
|
2181 |
|
|
2182 |
# Die zuletzt ausgewaehlte mit der aktuell ausgewaehlten Einheit |
|
2183 |
# vergleichen und bei Unterschied den Preis entsprechend umrechnen. |
|
2184 |
$form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"}); |
|
2185 |
|
|
2186 |
if (!$all_units->{$form->{"selected_unit_$i"}} || |
|
2187 |
($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne |
|
2188 |
$all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) { |
|
2189 |
# Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig |
|
2190 |
# (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber |
|
2191 |
# um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen. |
|
2192 |
$form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"}; |
|
2193 |
} |
|
2194 |
|
|
2195 |
my $basefactor = 1; |
|
2196 |
|
|
2197 |
if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) { |
|
2198 |
if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) && |
|
2199 |
$all_units->{$form->{"unit_old_$i"}}->{"factor"}) { |
|
2200 |
$basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} / |
|
2201 |
$all_units->{$form->{"unit_old_$i"}}->{"factor"}; |
|
2202 |
} |
|
2203 |
} |
|
2204 |
|
|
2205 |
if (!$form->{"basefactor_$i"}) { |
|
2206 |
$form->{"basefactor_$i"} = 1; |
|
2207 |
} |
|
2208 |
|
|
2209 |
my $query = |
|
2210 |
qq|SELECT |
|
2211 |
0 as pricegroup_id, |
|
2212 |
sellprice AS default_sellprice, |
|
2213 |
'' AS pricegroup, |
|
2214 |
sellprice AS price, |
|
2215 |
'selected' AS selected |
|
2216 |
FROM parts |
|
2217 |
WHERE id = ? |
|
2218 |
UNION ALL |
|
2219 |
SELECT |
|
2220 |
pricegroup_id, |
|
2221 |
parts.sellprice AS default_sellprice, |
|
2222 |
pricegroup.pricegroup, |
|
2223 |
price, |
|
2224 |
'' AS selected |
|
2225 |
FROM prices |
|
2226 |
LEFT JOIN parts ON parts.id = parts_id |
|
2227 |
LEFT JOIN pricegroup ON pricegroup.id = pricegroup_id |
|
2228 |
WHERE parts_id = ? |
|
2229 |
ORDER BY pricegroup|; |
|
2230 |
my @values = (conv_i($id), conv_i($id)); |
|
2231 |
my $pkq = prepare_execute_query($form, $dbh, $query, @values); |
|
2232 |
|
|
2233 |
while (my $pkr = $pkq->fetchrow_hashref('NAME_lc')) { |
|
2234 |
$pkr->{id} = $id; |
|
2235 |
$pkr->{selected} = ''; |
|
2236 |
|
|
2237 |
# if there is an exchange rate change price |
|
2238 |
if (($form->{exchangerate} * 1) != 0) { |
|
2239 |
$pkr->{price} /= $form->{exchangerate}; |
|
2240 |
} |
|
2241 |
|
|
2242 |
$pkr->{price} *= $form->{"basefactor_$i"}; |
|
2243 |
$pkr->{price} *= $basefactor; |
|
2244 |
$pkr->{price_ufmt} = $pkr->{price}; |
|
2245 |
$pkr->{price} = $form->format_amount($myconfig, $pkr->{price}, 5); |
|
2246 |
|
|
2247 |
if (!defined $selectedpricegroup_id) { |
|
2248 |
# new entries in article list, either old invoice was loaded (edit) or a new article was added |
|
2249 |
# Case A: open old invoice, no pricegroup selected |
|
2250 |
# Case B: add new article to invoice, no pricegroup selected |
|
2251 |
|
|
2252 |
# to distinguish case A and B the variable pricegroup_id_$i is used |
|
2253 |
# for new articles this variable isn't defined, for loaded articles it is |
|
2254 |
# sellprice can't be used, as it already has 0,00 set |
|
2255 |
|
|
2256 |
if ($pkr->{pricegroup_id} eq $form->{"pricegroup_id_$i"} and defined $form->{"pricegroup_id_$i"}) { |
|
2257 |
# Case A |
|
2258 |
$pkr->{selected} = ' selected'; |
|
2259 |
} elsif ($pkr->{pricegroup_id} eq $form->{customer_klass} |
|
2260 |
and not defined $form->{"pricegroup_id_$i"} |
|
2261 |
and $pkr->{price_ufmt} != 0 # only use customer pricegroup price if it has a value, else use default_sellprice |
|
2262 |
# for the case where pricegroup prices haven't been set |
|
2263 |
) { |
|
2264 |
# Case B: use default pricegroup of customer |
|
2265 |
|
|
2266 |
$pkr->{selected} = ' selected'; # unless $form->{selected}; |
|
2267 |
# no customer pricesgroup set |
|
2268 |
if ($pkr->{price_ufmt} == $pkr->{default_sellprice}) { |
|
2269 |
|
|
2270 |
$pkr->{price} = $form->{"sellprice_$i"}; |
|
2271 |
|
|
2272 |
} else { |
|
2273 |
|
|
2274 |
# this sub should not set anything and only return. --sschoeling, 20090506 |
|
2275 |
# is this correct? put in again... -- grichardson 20110119 |
|
2276 |
$form->{"sellprice_$i"} = $pkr->{price}; |
|
2277 |
} |
|
2278 |
|
|
2279 |
} elsif ($pkr->{price_ufmt} == $pkr->{default_sellprice} and $pkr->{default_sellprice} != 0) { |
|
2280 |
$pkr->{price} = $form->{"sellprice_$i"}; |
|
2281 |
$pkr->{selected} = ' selected'; |
|
2282 |
} |
|
2283 |
} |
|
2284 |
|
|
2285 |
# existing article: pricegroup or price changed |
|
2286 |
if ($selectedpricegroup_id or $selectedpricegroup_id == 0) { |
|
2287 |
if ($selectedpricegroup_id ne $pricegroup_old) { |
|
2288 |
# pricegroup has changed |
|
2289 |
if ($pkr->{pricegroup_id} eq $selectedpricegroup_id) { |
|
2290 |
$pkr->{selected} = ' selected'; |
|
2291 |
} |
|
2292 |
} elsif ( ($form->parse_amount($myconfig, $price_new) |
|
2293 |
!= $form->parse_amount($myconfig, $form->{"sellprice_$i"})) |
|
2294 |
and ($price_new ne 0) and defined $price_new) { |
|
2295 |
# sellprice has changed |
|
2296 |
# when loading existing invoices $price_new is NULL |
|
2297 |
if ($pkr->{pricegroup_id} == 0) { |
|
2298 |
$pkr->{price} = $form->{"sellprice_$i"}; |
|
2299 |
$pkr->{selected} = ' selected'; |
|
2300 |
} |
|
2301 |
} elsif ($pkr->{pricegroup_id} eq $selectedpricegroup_id) { |
|
2302 |
# neither sellprice nor pricegroup changed |
|
2303 |
$pkr->{selected} = ' selected'; |
|
2304 |
if ( ($pkr->{pricegroup_id} == 0) and ($pkr->{price} == $form->{"sellprice_$i"})) { |
|
2305 |
# $pkr->{price} = $form->{"sellprice_$i"}; |
|
2306 |
} else { |
|
2307 |
$pkr->{price} = $form->{"sellprice_$i"}; |
|
2308 |
} |
|
2309 |
} |
|
2310 |
} |
|
2311 |
push @{ $form->{PRICES}{$i} }, $pkr; |
|
2312 |
|
|
2313 |
} |
|
2314 |
$form->{"basefactor_$i"} *= $basefactor; |
|
2315 |
|
|
2316 |
$i++; |
|
2317 |
|
|
2318 |
$pkq->finish; |
|
2319 |
} |
|
2320 |
|
|
2321 |
$main::lxdebug->leave_sub(); |
|
2322 |
} |
|
2323 |
|
|
2324 | 2134 |
sub has_storno { |
2325 | 2135 |
$main::lxdebug->enter_sub(); |
2326 | 2136 |
|
Auch abrufbar als: Unified diff
PriceSource: Erste Version
- Preisgruppen und Stammdaten sind implementiert
- Persistenz in allen Belegen funktioniert
- Rudimentäre Visualisierung funktioniert
- Klassen sind alle da
- Doku fehlt
- Verkauf/Einkaufweiche fehlt
- best_price ungetestet
- Preisgruppen hängen noch nicht von Verkäufer ab
- dependancy system fehlt
- verhalten bei fehlerhaften sources
- pricegroup -> active_source migration