Revision dbbf8923
Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt
SL/AM.pm | ||
---|---|---|
880 | 880 |
# connect to database |
881 | 881 |
my $dbh = $form->dbconnect_noauto($myconfig); |
882 | 882 |
|
883 |
foreach my $table (qw(translation_payment_terms units_language)) {
|
|
883 |
foreach my $table (qw(generic_translations units_language)) {
|
|
884 | 884 |
$query = qq|DELETE FROM $table WHERE language_id = ?|; |
885 | 885 |
do_query($form, $dbh, $query, $form->{"id"}); |
886 | 886 |
} |
... | ... | |
1124 | 1124 |
$main::lxdebug->leave_sub(); |
1125 | 1125 |
} |
1126 | 1126 |
|
1127 |
sub payment { |
|
1128 |
$main::lxdebug->enter_sub(); |
|
1129 |
|
|
1130 |
my ($self, $myconfig, $form) = @_; |
|
1131 |
|
|
1132 |
# connect to database |
|
1133 |
my $dbh = $form->dbconnect($myconfig); |
|
1134 |
|
|
1135 |
my $query = qq|SELECT * FROM payment_terms ORDER BY sortkey|; |
|
1136 |
|
|
1137 |
my $sth = $dbh->prepare($query); |
|
1138 |
$sth->execute || $form->dberror($query); |
|
1139 |
|
|
1140 |
$form->{ALL} = []; |
|
1141 |
while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { |
|
1142 |
push @{ $form->{ALL} }, $ref; |
|
1143 |
} |
|
1144 |
|
|
1145 |
$sth->finish; |
|
1146 |
$dbh->disconnect; |
|
1147 |
|
|
1148 |
$main::lxdebug->leave_sub(); |
|
1149 |
} |
|
1150 |
|
|
1151 |
sub get_payment { |
|
1152 |
$main::lxdebug->enter_sub(); |
|
1153 |
|
|
1154 |
my ($self, $myconfig, $form) = @_; |
|
1155 |
|
|
1156 |
# connect to database |
|
1157 |
my $dbh = $form->dbconnect($myconfig); |
|
1158 |
|
|
1159 |
my $query = qq|SELECT * FROM payment_terms WHERE id = ?|; |
|
1160 |
my $sth = $dbh->prepare($query); |
|
1161 |
$sth->execute($form->{"id"}) || $form->dberror($query . " ($form->{id})"); |
|
1162 |
|
|
1163 |
my $ref = $sth->fetchrow_hashref("NAME_lc"); |
|
1164 |
map { $form->{$_} = $ref->{$_} } keys %$ref; |
|
1165 |
$sth->finish(); |
|
1166 |
|
|
1167 |
$query = |
|
1168 |
qq|SELECT t.language_id, t.description_long, l.description AS language | . |
|
1169 |
qq|FROM translation_payment_terms t | . |
|
1170 |
qq|LEFT JOIN language l ON t.language_id = l.id | . |
|
1171 |
qq|WHERE t.payment_terms_id = ? | . |
|
1172 |
qq|UNION | . |
|
1173 |
qq|SELECT l.id AS language_id, NULL AS description_long, | . |
|
1174 |
qq| l.description AS language | . |
|
1175 |
qq|FROM language l|; |
|
1176 |
$sth = $dbh->prepare($query); |
|
1177 |
$sth->execute($form->{"id"}) || $form->dberror($query . " ($form->{id})"); |
|
1178 |
|
|
1179 |
my %mapping; |
|
1180 |
while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { |
|
1181 |
$mapping{ $ref->{"language_id"} } = $ref |
|
1182 |
unless (defined($mapping{ $ref->{"language_id"} })); |
|
1183 |
} |
|
1184 |
$sth->finish; |
|
1185 |
|
|
1186 |
$form->{"TRANSLATION"} = [sort({ $a->{"language"} cmp $b->{"language"} } |
|
1187 |
values(%mapping))]; |
|
1188 |
|
|
1189 |
$dbh->disconnect; |
|
1190 |
|
|
1191 |
$main::lxdebug->leave_sub(); |
|
1192 |
} |
|
1193 |
|
|
1194 |
sub save_payment { |
|
1195 |
$main::lxdebug->enter_sub(); |
|
1196 |
|
|
1197 |
my ($self, $myconfig, $form) = @_; |
|
1198 |
|
|
1199 |
# connect to database |
|
1200 |
my $dbh = $form->dbconnect_noauto($myconfig); |
|
1201 |
|
|
1202 |
my $query; |
|
1203 |
|
|
1204 |
if (!$form->{id}) { |
|
1205 |
$query = qq|SELECT nextval('id'), COALESCE(MAX(sortkey) + 1, 1) | . |
|
1206 |
qq|FROM payment_terms|; |
|
1207 |
my $sortkey; |
|
1208 |
($form->{id}, $sortkey) = selectrow_query($form, $dbh, $query); |
|
1209 |
|
|
1210 |
$query = qq|INSERT INTO payment_terms (id, sortkey) VALUES (?, ?)|; |
|
1211 |
do_query($form, $dbh, $query, $form->{id}, $sortkey); |
|
1212 |
|
|
1213 |
} else { |
|
1214 |
$query = |
|
1215 |
qq|DELETE FROM translation_payment_terms | . |
|
1216 |
qq|WHERE payment_terms_id = ?|; |
|
1217 |
do_query($form, $dbh, $query, $form->{"id"}); |
|
1218 |
} |
|
1219 |
|
|
1220 |
$query = qq|UPDATE payment_terms SET |
|
1221 |
description = ?, description_long = ?, |
|
1222 |
terms_netto = ?, terms_skonto = ?, |
|
1223 |
percent_skonto = ? |
|
1224 |
WHERE id = ?|; |
|
1225 |
my @values = ($form->{description}, $form->{description_long}, |
|
1226 |
$form->{terms_netto} * 1, $form->{terms_skonto} * 1, |
|
1227 |
$form->{percent_skonto} * 1, |
|
1228 |
$form->{id}); |
|
1229 |
do_query($form, $dbh, $query, @values); |
|
1230 |
|
|
1231 |
$query = qq|SELECT id FROM language|; |
|
1232 |
my @language_ids; |
|
1233 |
my $sth = $dbh->prepare($query); |
|
1234 |
$sth->execute() || $form->dberror($query); |
|
1235 |
|
|
1236 |
while (my ($id) = $sth->fetchrow_array()) { |
|
1237 |
push(@language_ids, $id); |
|
1238 |
} |
|
1239 |
$sth->finish(); |
|
1240 |
|
|
1241 |
$query = |
|
1242 |
qq|INSERT INTO translation_payment_terms | . |
|
1243 |
qq|(language_id, payment_terms_id, description_long) | . |
|
1244 |
qq|VALUES (?, ?, ?)|; |
|
1245 |
$sth = $dbh->prepare($query); |
|
1246 |
|
|
1247 |
foreach my $language_id (@language_ids) { |
|
1248 |
do_statement($form, $sth, $query, $language_id, $form->{"id"}, |
|
1249 |
$form->{"description_long_${language_id}"}); |
|
1250 |
} |
|
1251 |
$sth->finish(); |
|
1252 |
|
|
1253 |
$dbh->commit(); |
|
1254 |
$dbh->disconnect; |
|
1255 |
|
|
1256 |
$main::lxdebug->leave_sub(); |
|
1257 |
} |
|
1258 |
|
|
1259 |
sub delete_payment { |
|
1260 |
$main::lxdebug->enter_sub(); |
|
1261 |
|
|
1262 |
my ($self, $myconfig, $form) = @_; |
|
1263 |
|
|
1264 |
# connect to database |
|
1265 |
my $dbh = $form->dbconnect_noauto($myconfig); |
|
1266 |
|
|
1267 |
my $query = |
|
1268 |
qq|DELETE FROM translation_payment_terms WHERE payment_terms_id = ?|; |
|
1269 |
do_query($form, $dbh, $query, $form->{"id"}); |
|
1270 |
|
|
1271 |
$query = qq|DELETE FROM payment_terms WHERE id = ?|; |
|
1272 |
do_query($form, $dbh, $query, $form->{"id"}); |
|
1273 |
|
|
1274 |
$dbh->commit(); |
|
1275 |
$dbh->disconnect; |
|
1276 |
|
|
1277 |
$main::lxdebug->leave_sub(); |
|
1278 |
} |
|
1279 |
|
|
1280 |
|
|
1281 | 1127 |
sub prepare_template_filename { |
1282 | 1128 |
$main::lxdebug->enter_sub(); |
1283 | 1129 |
|
Auch abrufbar als: Unified diff
Verwaltung von Zahlungsbedingungen auf Controller/Model umgestellt
Conflicts: