42 |
42 |
sub get_tuple {
|
43 |
43 |
$main::lxdebug->enter_sub();
|
44 |
44 |
|
45 |
|
my ($self, $myconfig, $form) = @_;
|
|
45 |
my ( $self, $myconfig, $form ) = @_;
|
|
46 |
|
|
47 |
my $cv = $form->{db} eq "customer" ? "customer" : "vendor";
|
46 |
48 |
|
47 |
49 |
my $dbh = $form->dbconnect($myconfig);
|
48 |
|
my $query = qq|SELECT ct.*, b.id AS business, cp.*
|
49 |
|
FROM $form->{db} ct
|
50 |
|
LEFT JOIN business b on ct.business_id = b.id
|
51 |
|
LEFT JOIN contacts cp on ct.id = cp.cp_cv_id
|
52 |
|
WHERE ct.id = $form->{id} order by cp.cp_id limit 1|;
|
53 |
|
my $sth = $dbh->prepare($query);
|
54 |
|
$sth->execute || $form->dberror($query);
|
|
50 |
my $query =
|
|
51 |
qq|SELECT ct.*, b.id AS business, cp.* | .
|
|
52 |
qq|FROM $cv ct | .
|
|
53 |
qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
|
|
54 |
qq|LEFT JOIN contacts cp ON (ct.id = cp.cp_cv_id) | .
|
|
55 |
qq|WHERE (ct.id = ?) | .
|
|
56 |
qq|ORDER BY cp.cp_id LIMIT 1|;
|
|
57 |
my $sth = prepare_execute_query($form, $dbh, $query, $form->{id});
|
55 |
58 |
|
56 |
59 |
my $ref = $sth->fetchrow_hashref(NAME_lc);
|
57 |
60 |
|
58 |
61 |
map { $form->{$_} = $ref->{$_} } keys %$ref;
|
59 |
62 |
|
60 |
63 |
$sth->finish;
|
61 |
|
if ($form->{salesman_id}) {
|
62 |
|
my $query = qq|SELECT ct.name AS salesman
|
63 |
|
FROM $form->{db} ct
|
64 |
|
WHERE ct.id = $form->{salesman_id}|;
|
65 |
|
my $sth = $dbh->prepare($query);
|
66 |
|
$sth->execute || $form->dberror($query);
|
67 |
|
|
68 |
|
my ($ref) = $sth->fetchrow_array();
|
69 |
|
|
70 |
|
$form->{salesman} = $ref;
|
71 |
|
|
72 |
|
$sth->finish;
|
|
64 |
if ( $form->{salesman_id} ) {
|
|
65 |
my $query =
|
|
66 |
qq|SELECT ct.name AS salesman | .
|
|
67 |
qq|FROM $cv ct | .
|
|
68 |
qq|WHERE ct.id = ?|;
|
|
69 |
($form->{salesman}) =
|
|
70 |
selectrow_query($form, $dbh, $query, $form->{salesman_id});
|
73 |
71 |
}
|
74 |
72 |
|
75 |
73 |
# check if it is orphaned
|
76 |
|
my $arap = ($form->{db} eq 'customer') ? "ar" : "ap";
|
77 |
|
$query = qq|SELECT a.id
|
78 |
|
FROM $arap a
|
79 |
|
JOIN $form->{db} ct ON (a.$form->{db}_id = ct.id)
|
80 |
|
WHERE ct.id = $form->{id}
|
81 |
|
UNION
|
82 |
|
SELECT a.id
|
83 |
|
FROM oe a
|
84 |
|
JOIN $form->{db} ct ON (a.$form->{db}_id = ct.id)
|
85 |
|
WHERE ct.id = $form->{id}|;
|
86 |
|
$sth = $dbh->prepare($query);
|
87 |
|
$sth->execute || $form->dberror($query);
|
88 |
|
|
89 |
|
unless ($sth->fetchrow_array) {
|
90 |
|
$form->{status} = "orphaned";
|
91 |
|
}
|
92 |
|
$sth->finish;
|
93 |
|
|
94 |
|
# get tax labels
|
95 |
|
$query = qq|SELECT c.accno, c.description
|
96 |
|
FROM chart c
|
97 |
|
JOIN tax t ON (t.chart_id = c.id)
|
98 |
|
WHERE c.link LIKE '%CT_tax%'
|
99 |
|
ORDER BY c.accno|;
|
100 |
|
$sth = $dbh->prepare($query);
|
101 |
|
$sth->execute || $form->dberror($query);
|
102 |
|
|
103 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
104 |
|
$form->{taxaccounts} .= "$ref->{accno} ";
|
105 |
|
$form->{tax}{ $ref->{accno} }{description} = $ref->{description};
|
106 |
|
}
|
107 |
|
$sth->finish;
|
108 |
|
chop $form->{taxaccounts};
|
109 |
|
|
110 |
|
# get taxes for customer/vendor
|
111 |
|
$query = qq|SELECT c.accno
|
112 |
|
FROM chart c
|
113 |
|
JOIN $form->{db}tax t ON (t.chart_id = c.id)
|
114 |
|
WHERE t.$form->{db}_id = $form->{id}|;
|
115 |
|
$sth = $dbh->prepare($query);
|
116 |
|
$sth->execute || $form->dberror($query);
|
117 |
|
|
118 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
119 |
|
$form->{tax}{ $ref->{accno} }{taxable} = 1;
|
120 |
|
}
|
121 |
|
$sth->finish;
|
122 |
|
|
123 |
|
# get business types
|
124 |
|
$query = qq|SELECT id, description
|
125 |
|
FROM business
|
126 |
|
ORDER BY 1|;
|
127 |
|
$sth = $dbh->prepare($query);
|
128 |
|
$sth->execute || $form->dberror($query);
|
129 |
|
|
130 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
131 |
|
push @{ $form->{all_business} }, $ref;
|
132 |
|
}
|
133 |
|
$sth->finish;
|
|
74 |
my $arap = ( $form->{db} eq 'customer' ) ? "ar" : "ap";
|
|
75 |
$query =
|
|
76 |
qq|SELECT a.id | .
|
|
77 |
qq|FROM $arap a | .
|
|
78 |
qq|JOIN $cv ct ON (a.${cv}_id = ct.id) | .
|
|
79 |
qq|WHERE ct.id = ? | .
|
|
80 |
qq|UNION | .
|
|
81 |
qq|SELECT a.id | .
|
|
82 |
qq|FROM oe a | .
|
|
83 |
qq|JOIN $cv ct ON (a.${cv}_id = ct.id) | .
|
|
84 |
qq|WHERE ct.id = ?|;
|
|
85 |
my ($dummy) = selectrow_query($form, $dbh, $query, $form->{id}, $form->{id});
|
|
86 |
$form->{status} = "orphaned" unless ($dummy);
|
134 |
87 |
|
135 |
|
# get tax zones
|
136 |
|
$query = qq|SELECT id, description
|
137 |
|
FROM tax_zones|;
|
138 |
|
$sth = $dbh->prepare($query);
|
139 |
|
$sth->execute || $form->dberror($query);
|
|
88 |
$dbh->disconnect;
|
140 |
89 |
|
|
90 |
$main::lxdebug->leave_sub();
|
|
91 |
}
|
141 |
92 |
|
142 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
143 |
|
push @{ $form->{TAXZONE} }, $ref;
|
144 |
|
}
|
145 |
|
$sth->finish;
|
|
93 |
sub populate_drop_down_boxes {
|
|
94 |
$main::lxdebug->enter_sub();
|
146 |
95 |
|
|
96 |
my ($self, $myconfig, $form, $provided_dbh) = @_;
|
147 |
97 |
|
148 |
|
# get shipto address
|
149 |
|
$query = qq|SELECT shipto_id, shiptoname, shiptodepartment_1
|
150 |
|
FROM shipto WHERE trans_id=$form->{id}|;
|
151 |
|
$sth = $dbh->prepare($query);
|
152 |
|
$sth->execute || $form->dberror($query);
|
|
98 |
my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect($myconfig);
|
153 |
99 |
|
|
100 |
# get business types
|
|
101 |
$query = qq|SELECT id, description FROM business ORDER BY id|;
|
|
102 |
$form->{all_business} = selectall_hashref_query($form, $dbh, $query);
|
154 |
103 |
|
155 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
156 |
|
push @{ $form->{SHIPTO} }, $ref;
|
157 |
|
}
|
158 |
|
$sth->finish;
|
|
104 |
# get tax zones
|
|
105 |
$query = qq|SELECT id, description FROM tax_zones|;
|
|
106 |
$form->{TAXZONE} = selectall_hashref_query($form, $dbh, $query);
|
159 |
107 |
|
|
108 |
# get shipto address
|
|
109 |
$query =
|
|
110 |
qq|SELECT shipto_id, shiptoname, shiptodepartment_1 | .
|
|
111 |
qq|FROM shipto WHERE (trans_id = ?) AND (module = 'CT')|;
|
|
112 |
$form->{SHIPTO} = selectall_hashref_query($form, $dbh, $query, $form->{id});
|
160 |
113 |
|
161 |
114 |
# get contacts
|
162 |
|
$query = qq|SELECT cp_id, cp_name
|
163 |
|
FROM contacts WHERE cp_cv_id=$form->{id}|;
|
164 |
|
$sth = $dbh->prepare($query);
|
165 |
|
$sth->execute || $form->dberror($query);
|
166 |
|
|
167 |
|
|
168 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
169 |
|
push @{ $form->{CONTACTS} }, $ref;
|
170 |
|
}
|
171 |
|
$sth->finish;
|
|
115 |
$query = qq|SELECT cp_id, cp_name FROM contacts WHERE cp_cv_id = ?|;
|
|
116 |
$form->{CONTACTS} = selectall_hashref_query($form, $dbh, $query, $form->{id});
|
172 |
117 |
|
173 |
118 |
# get languages
|
174 |
|
$query = qq|SELECT id, description
|
175 |
|
FROM language
|
176 |
|
ORDER BY 1|;
|
177 |
|
$sth = $dbh->prepare($query);
|
178 |
|
$sth->execute || $form->dberror($query);
|
179 |
|
|
180 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
181 |
|
push @{ $form->{languages} }, $ref;
|
182 |
|
}
|
183 |
|
$sth->finish;
|
|
119 |
$query = qq|SELECT id, description FROM language ORDER BY id|;
|
|
120 |
$form->{languages} = selectall_hashref_query($form, $dbh, $query);
|
184 |
121 |
|
185 |
122 |
# get payment terms
|
186 |
|
$query = qq|SELECT id, description
|
187 |
|
FROM payment_terms
|
188 |
|
ORDER BY sortkey|;
|
189 |
|
$sth = $dbh->prepare($query);
|
190 |
|
$sth->execute || $form->dberror($query);
|
191 |
|
|
192 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
193 |
|
push @{ $form->{payment_terms} }, $ref;
|
194 |
|
}
|
195 |
|
$sth->finish;
|
|
123 |
$query = qq|SELECT id, description FROM payment_terms ORDER BY sortkey|;
|
|
124 |
$form->{payment_terms} = selectall_hashref_query($form, $dbh, $query);
|
196 |
125 |
|
197 |
|
$dbh->disconnect;
|
|
126 |
$dbh->disconnect() unless ($provided_dbh);
|
198 |
127 |
|
199 |
128 |
$main::lxdebug->leave_sub();
|
200 |
129 |
}
|
201 |
130 |
|
202 |
|
## LINET
|
203 |
131 |
sub query_titles_and_greetings {
|
204 |
132 |
$main::lxdebug->enter_sub();
|
205 |
133 |
|
206 |
|
my ($self, $myconfig, $form) = @_;
|
207 |
|
my (%tmp, $ref);
|
|
134 |
my ( $self, $myconfig, $form ) = @_;
|
|
135 |
my ( %tmp, $ref );
|
208 |
136 |
|
209 |
137 |
my $dbh = $form->dbconnect($myconfig);
|
210 |
138 |
|
211 |
139 |
$query =
|
212 |
|
"SELECT DISTINCT(c.cp_greeting) FROM contacts c WHERE c.cp_greeting LIKE '%'";
|
213 |
|
$sth = $dbh->prepare($query);
|
214 |
|
$sth->execute() || $form->dberror($query);
|
215 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
216 |
|
next unless ($ref->{cp_greeting} =~ /[a-zA-Z]/);
|
217 |
|
$tmp{ $ref->{cp_greeting} } = 1;
|
218 |
|
}
|
219 |
|
$sth->finish();
|
220 |
|
|
221 |
|
@{ $form->{GREETINGS} } = sort(keys(%tmp));
|
222 |
|
|
223 |
|
%tmp = ();
|
|
140 |
qq|SELECT DISTINCT(cp_greeting) | .
|
|
141 |
qq|FROM contacts | .
|
|
142 |
qq|WHERE cp_greeting ~ '[a-zA-Z]' | .
|
|
143 |
qq|ORDER BY cp_greeting|;
|
|
144 |
$form->{GREETINGS} = [ selectall_array_query($form, $dbh, $query) ];
|
224 |
145 |
|
225 |
146 |
$query =
|
226 |
|
"SELECT greeting FROM customer UNION select greeting FROM vendor";
|
227 |
|
$sth = $dbh->prepare($query);
|
228 |
|
$sth->execute() || $form->dberror($query);
|
229 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
230 |
|
next unless ($ref->{greeting} =~ /[a-zA-Z]/);
|
231 |
|
$tmp{ $ref->{greeting} } = 1;
|
232 |
|
}
|
233 |
|
$sth->finish();
|
234 |
|
|
235 |
|
@{ $form->{COMPANY_GREETINGS} } = sort(keys(%tmp));
|
236 |
|
|
237 |
|
%tmp = ();
|
|
147 |
qq|SELECT DISTINCT(greeting) | .
|
|
148 |
qq|FROM customer | .
|
|
149 |
qq|WHERE greeting ~ '[a-zA-Z]' | .
|
|
150 |
qq|UNION | .
|
|
151 |
qq|SELECT DISTINCT(greeting) | .
|
|
152 |
qq|FROM vendor | .
|
|
153 |
qq|WHERE greeting ~ '[a-zA-Z]' | .
|
|
154 |
qq|ORDER BY greeting|;
|
|
155 |
my %tmp;
|
|
156 |
map({ $tmp{$_} = 1; } selectall_array_query($form, $dbh, $query));
|
|
157 |
$form->{COMPANY_GREETINGS} = [ sort(keys(%tmp)) ];
|
238 |
158 |
|
239 |
159 |
$query =
|
240 |
|
"SELECT DISTINCT(c.cp_title) FROM contacts c WHERE c.cp_title LIKE '%'";
|
241 |
|
$sth = $dbh->prepare($query);
|
242 |
|
$sth->execute() || $form->dberror($query);
|
243 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
244 |
|
next unless ($ref->{cp_title} =~ /[a-zA-Z]/);
|
245 |
|
$tmp{ $ref->{cp_title} } = 1;
|
246 |
|
}
|
247 |
|
$sth->finish();
|
248 |
|
|
249 |
|
@{ $form->{TITLES} } = sort(keys(%tmp));
|
250 |
|
|
251 |
|
%tmp = ();
|
|
160 |
qq|SELECT DISTINCT(cp_title) | .
|
|
161 |
qq|FROM contacts | .
|
|
162 |
qq|WHERE cp_title ~ '[a-zA-Z]'|;
|
|
163 |
$form->{TITLES} = [ selectall_array_query($form, $dbh, $query) ];
|
252 |
164 |
|
253 |
165 |
$query =
|
254 |
|
"SELECT DISTINCT(c.cp_abteilung) FROM contacts c WHERE c.cp_abteilung LIKE '%'";
|
255 |
|
$sth = $dbh->prepare($query);
|
256 |
|
$sth->execute() || $form->dberror($query);
|
257 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
258 |
|
$tmp{ $ref->{cp_abteilung} } = 1;
|
259 |
|
}
|
260 |
|
$sth->finish();
|
261 |
|
|
262 |
|
@{ $form->{DEPARTMENT} } = sort(keys(%tmp));
|
|
166 |
qq|SELECT DISTINCT(cp_abteilung) | .
|
|
167 |
qq|FROM contacts | .
|
|
168 |
qq|WHERE cp_abteilung ~ '[a-zA-Z]'|;
|
|
169 |
$form->{DEPARTMENT} = [ selectall_array_query($form, $dbh, $query) ];
|
263 |
170 |
|
264 |
171 |
$dbh->disconnect();
|
265 |
172 |
$main::lxdebug->leave_sub();
|
266 |
173 |
}
|
267 |
|
## /LINET
|
268 |
|
|
269 |
|
sub taxaccounts {
|
270 |
|
$main::lxdebug->enter_sub();
|
271 |
|
|
272 |
|
my ($self, $myconfig, $form) = @_;
|
273 |
|
|
274 |
|
my $dbh = $form->dbconnect($myconfig);
|
275 |
|
|
276 |
|
# get tax labels
|
277 |
|
my $query = qq|SELECT accno, description
|
278 |
|
FROM chart c, tax t
|
279 |
|
WHERE c.link LIKE '%CT_tax%'
|
280 |
|
AND c.id = t.chart_id
|
281 |
|
ORDER BY accno|;
|
282 |
|
$sth = $dbh->prepare($query);
|
283 |
|
$sth->execute || $form->dberror($query);
|
284 |
|
|
285 |
|
my $ref = ();
|
286 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
287 |
|
$form->{taxaccounts} .= "$ref->{accno} ";
|
288 |
|
$form->{tax}{ $ref->{accno} }{description} = $ref->{description};
|
289 |
|
}
|
290 |
|
$sth->finish;
|
291 |
|
chop $form->{taxaccounts};
|
292 |
|
|
293 |
|
# this is just for the selection for type of business
|
294 |
|
$query = qq|SELECT id, description
|
295 |
|
FROM business|;
|
296 |
|
$sth = $dbh->prepare($query);
|
297 |
|
$sth->execute || $form->dberror($query);
|
298 |
|
|
299 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
300 |
|
push @{ $form->{all_business} }, $ref;
|
301 |
|
}
|
302 |
|
$sth->finish;
|
303 |
|
# get languages
|
304 |
|
$query = qq|SELECT id, description
|
305 |
|
FROM language
|
306 |
|
ORDER BY 1|;
|
307 |
|
$sth = $dbh->prepare($query);
|
308 |
|
$sth->execute || $form->dberror($query);
|
309 |
|
|
310 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
311 |
|
push @{ $form->{languages} }, $ref;
|
312 |
|
}
|
313 |
|
$sth->finish;
|
314 |
|
|
315 |
|
# get payment terms
|
316 |
|
$query = qq|SELECT id, description
|
317 |
|
FROM payment_terms
|
318 |
|
ORDER BY sortkey|;
|
319 |
|
$sth = $dbh->prepare($query);
|
320 |
|
$sth->execute || $form->dberror($query);
|
321 |
|
|
322 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
323 |
|
push @{ $form->{payment_terms} }, $ref;
|
324 |
|
}
|
325 |
|
$sth->finish;
|
326 |
|
|
327 |
|
# get taxkeys and description
|
328 |
|
$query = qq|SELECT id, description
|
329 |
|
FROM tax_zones|;
|
330 |
|
$sth = $dbh->prepare($query);
|
331 |
|
$sth->execute || $form->dberror($query);
|
332 |
|
|
333 |
|
|
334 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
335 |
|
push @{ $form->{TAXZONE} }, $ref;
|
336 |
|
}
|
337 |
|
$sth->finish;
|
338 |
|
|
339 |
|
|
340 |
|
$dbh->disconnect;
|
341 |
|
|
342 |
|
$main::lxdebug->leave_sub();
|
343 |
|
}
|
344 |
174 |
|
345 |
175 |
sub save_customer {
|
346 |
176 |
$main::lxdebug->enter_sub();
|
347 |
177 |
|
348 |
|
my ($self, $myconfig, $form) = @_;
|
|
178 |
my ( $self, $myconfig, $form ) = @_;
|
349 |
179 |
|
350 |
180 |
# set pricegroup to default
|
351 |
|
if ($form->{klass}) { }
|
352 |
|
else { $form->{klass} = 0; }
|
|
181 |
$form->{klass} = 0 unless ($form->{klass});
|
353 |
182 |
|
354 |
183 |
# connect to database
|
355 |
|
my $dbh = $form->dbconnect($myconfig);
|
356 |
|
##LINET
|
357 |
|
map({
|
358 |
|
$form->{"cp_${_}"} = $form->{"selected_cp_${_}"}
|
359 |
|
if ($form->{"selected_cp_${_}"});
|
360 |
|
} qw(title greeting abteilung));
|
|
184 |
my $dbh = $form->dbconnect_noauto($myconfig);
|
|
185 |
|
|
186 |
map( {
|
|
187 |
$form->{"cp_${_}"} = $form->{"selected_cp_${_}"}
|
|
188 |
if ( $form->{"selected_cp_${_}"} );
|
|
189 |
} qw(title greeting abteilung) );
|
361 |
190 |
$form->{"greeting"} = $form->{"selected_company_greeting"}
|
362 |
|
if ($form->{"selected_company_greeting"});
|
363 |
|
#
|
364 |
|
# escape '
|
365 |
|
map { $form->{$_} =~ s/\'/\'\'/g }
|
366 |
|
qw(customernumber name street zipcode city country homepage contact notes cp_title cp_greeting language pricegroup);
|
367 |
|
##/LINET
|
|
191 |
if ( $form->{"selected_company_greeting"} );
|
|
192 |
|
368 |
193 |
# assign value discount, terms, creditlimit
|
369 |
|
$form->{discount} = $form->parse_amount($myconfig, $form->{discount});
|
|
194 |
$form->{discount} = $form->parse_amount( $myconfig, $form->{discount} );
|
370 |
195 |
$form->{discount} /= 100;
|
371 |
|
$form->{terms} *= 1;
|
372 |
|
$form->{taxincluded} *= 1;
|
373 |
|
$form->{obsolete} *= 1;
|
374 |
|
$form->{business} *= 1;
|
375 |
|
$form->{salesman_id} *= 1;
|
376 |
|
$form->{payment_id} *= 1;
|
377 |
|
$form->{taxzone_id} *= 1;
|
378 |
|
$form->{creditlimit} = $form->parse_amount($myconfig, $form->{creditlimit});
|
379 |
|
|
380 |
|
my ($query, $sth, $f_id);
|
|
196 |
$form->{creditlimit} = $form->parse_amount( $myconfig, $form->{creditlimit} );
|
381 |
197 |
|
382 |
|
if ($form->{id}) {
|
|
198 |
my ( $query, $sth, $f_id );
|
383 |
199 |
|
384 |
|
$query = qq|SELECT id FROM customer
|
385 |
|
WHERE customernumber = '$form->{customernumber}'|;
|
386 |
|
$sth = $dbh->prepare($query);
|
387 |
|
$sth->execute || $form->dberror($query);
|
388 |
|
(${f_id}) = $sth->fetchrow_array;
|
389 |
|
$sth->finish;
|
390 |
|
if ((${f_id} ne $form->{id}) and (${f_id} ne "")) {
|
|
200 |
if ( $form->{id} ) {
|
|
201 |
$query = qq|SELECT id FROM customer WHERE customernumber = ?|;
|
|
202 |
($f_id) = selectrow_query($form, $dbh, $query, $form->{customernumber});
|
391 |
203 |
|
|
204 |
if (($f_id ne $form->{id}) && ($f_id ne "")) {
|
392 |
205 |
$main::lxdebug->leave_sub();
|
393 |
206 |
return 3;
|
394 |
207 |
}
|
395 |
|
$query = qq|DELETE FROM customertax
|
396 |
|
WHERE customer_id = $form->{id}|;
|
397 |
|
$dbh->do($query) || $form->dberror($query);
|
398 |
208 |
|
399 |
|
# $query = qq|DELETE FROM shipto
|
400 |
|
# WHERE trans_id = $form->{id} AND module = 'CT'|;
|
401 |
|
# $dbh->do($query) || $form->dberror($query);
|
402 |
209 |
} else {
|
403 |
|
|
404 |
|
my $uid = rand() . time;
|
405 |
|
|
406 |
|
$uid .= $form->{login};
|
407 |
|
|
408 |
|
$uid = substr($uid, 2, 75);
|
409 |
210 |
if (!$form->{customernumber} && $form->{business}) {
|
410 |
211 |
$form->{customernumber} =
|
411 |
|
$form->update_business($myconfig, $form->{business});
|
|
212 |
$form->update_business($myconfig, $form->{business}, $dbh);
|
412 |
213 |
}
|
413 |
214 |
if (!$form->{customernumber}) {
|
414 |
215 |
$form->{customernumber} =
|
415 |
|
$form->update_defaults($myconfig, "customernumber");
|
|
216 |
$form->update_defaults($myconfig, "customernumber", $dbh);
|
416 |
217 |
}
|
417 |
218 |
|
418 |
|
$query = qq|SELECT c.id FROM customer c
|
419 |
|
WHERE c.customernumber = '$form->{customernumber}'|;
|
420 |
|
$sth = $dbh->prepare($query);
|
421 |
|
$sth->execute || $form->dberror($query);
|
422 |
|
(${f_id}) = $sth->fetchrow_array;
|
423 |
|
$sth->finish;
|
424 |
|
if (${f_id} ne "") {
|
|
219 |
$query = qq|SELECT c.id FROM customer c WHERE c.customernumber = ?|;
|
|
220 |
($f_id) = selectrow_query($form, $dbh, $query, $form->{customernumber});
|
|
221 |
if ($f_id ne "") {
|
425 |
222 |
$main::lxdebug->leave_sub();
|
426 |
223 |
return 3;
|
427 |
224 |
}
|
428 |
225 |
|
429 |
|
$query = qq|INSERT INTO customer (name)
|
430 |
|
VALUES ('$uid')|;
|
431 |
|
$dbh->do($query) || $form->dberror($query);
|
432 |
|
|
433 |
|
$query = qq|SELECT c.id FROM customer c
|
434 |
|
WHERE c.name = '$uid'|;
|
435 |
|
$sth = $dbh->prepare($query);
|
436 |
|
$sth->execute || $form->dberror($query);
|
437 |
|
|
438 |
|
($form->{id}) = $sth->fetchrow_array;
|
439 |
|
$sth->finish;
|
440 |
|
}
|
441 |
|
$query = qq|UPDATE customer SET
|
442 |
|
customernumber = '$form->{customernumber}',
|
443 |
|
name = '$form->{name}',
|
444 |
|
greeting = '$form->{greeting}',
|
445 |
|
department_1 = '$form->{department_1}',
|
446 |
|
department_2 = '$form->{department_2}',
|
447 |
|
street = '$form->{street}',
|
448 |
|
zipcode = '$form->{zipcode}',
|
449 |
|
city = '$form->{city}',
|
450 |
|
country = '$form->{country}',
|
451 |
|
homepage = '$form->{homepage}',
|
452 |
|
contact = '$form->{contact}',
|
453 |
|
phone = '$form->{phone}',
|
454 |
|
fax = '$form->{fax}',
|
455 |
|
email = '$form->{email}',
|
456 |
|
cc = '$form->{cc}',
|
457 |
|
bcc = '$form->{bcc}',
|
458 |
|
notes = '$form->{notes}',
|
459 |
|
discount = $form->{discount},
|
460 |
|
creditlimit = $form->{creditlimit},
|
461 |
|
terms = $form->{terms},
|
462 |
|
taxincluded = '$form->{taxincluded}',
|
463 |
|
business_id = $form->{business},
|
464 |
|
taxnumber = '$form->{taxnumber}',
|
465 |
|
sic_code = '$form->{sic}',
|
466 |
|
language = '$form->{language}',
|
467 |
|
account_number = '$form->{account_number}',
|
468 |
|
bank_code = '$form->{bank_code}',
|
469 |
|
bank = '$form->{bank}',
|
470 |
|
obsolete = '$form->{obsolete}',
|
471 |
|
ustid = '$form->{ustid}',
|
472 |
|
username = '$form->{username}',
|
473 |
|
salesman_id = '$form->{salesman_id}',
|
474 |
|
language_id = | . conv_i($form->{language_id}, "NULL") . qq|,
|
475 |
|
payment_id = '$form->{payment_id}',
|
476 |
|
taxzone_id = '$form->{taxzone_id}',
|
477 |
|
user_password = | . $dbh->quote($form->{user_password}) . qq|,
|
478 |
|
c_vendor_id = '$form->{c_vendor_id}',
|
479 |
|
klass = '$form->{klass}'
|
480 |
|
WHERE id = $form->{id}|;
|
481 |
|
$dbh->do($query) || $form->dberror($query);
|
482 |
|
|
483 |
|
if ($form->{cp_id}) {
|
484 |
|
$query = qq|UPDATE contacts SET
|
485 |
|
cp_greeting = '$form->{cp_greeting}',
|
486 |
|
cp_title = '$form->{cp_title}',
|
487 |
|
cp_givenname = '$form->{cp_givenname}',
|
488 |
|
cp_name = '$form->{cp_name}',
|
489 |
|
cp_email = '$form->{cp_email}',
|
490 |
|
cp_phone1 = '$form->{cp_phone1}',
|
491 |
|
cp_phone2 = '$form->{cp_phone2}',
|
492 |
|
cp_abteilung = | . $dbh->quote($form->{cp_abteilung}) . qq|,
|
493 |
|
cp_fax = | . $dbh->quote($form->{cp_fax}) . qq|,
|
494 |
|
cp_mobile1 = | . $dbh->quote($form->{cp_mobile1}) . qq|,
|
495 |
|
cp_mobile2 = | . $dbh->quote($form->{cp_mobile2}) . qq|,
|
496 |
|
cp_satphone = | . $dbh->quote($form->{cp_satphone}) . qq|,
|
497 |
|
cp_satfax = | . $dbh->quote($form->{cp_satfax}) . qq|,
|
498 |
|
cp_project = | . $dbh->quote($form->{cp_project}) . qq|,
|
499 |
|
cp_privatphone = | . $dbh->quote($form->{cp_privatphone}) . qq|,
|
500 |
|
cp_privatemail = | . $dbh->quote($form->{cp_privatemail}) . qq|,
|
501 |
|
cp_birthday = | . $dbh->quote($form->{cp_birthday}) . qq|
|
502 |
|
WHERE cp_id = $form->{cp_id}|;
|
503 |
|
} elsif ($form->{cp_name} || $form->{cp_givenname}) {
|
|
226 |
$query = qq|SELECT nextval('id')|;
|
|
227 |
($form->{id}) = selectrow_query($form, $dbh, $query);
|
|
228 |
|
|
229 |
$query = qq|INSERT INTO customer (id, name) VALUES (?, '')|;
|
|
230 |
do_query($form, $dbh, $query, $form->{id});
|
|
231 |
}
|
|
232 |
|
|
233 |
$query = qq|UPDATE customer SET | .
|
|
234 |
qq|customernumber = ?, | .
|
|
235 |
qq|name = ?, | .
|
|
236 |
qq|greeting = ?, | .
|
|
237 |
qq|department_1 = ?, | .
|
|
238 |
qq|department_2 = ?, | .
|
|
239 |
qq|street = ?, | .
|
|
240 |
qq|zipcode = ?, | .
|
|
241 |
qq|city = ?, | .
|
|
242 |
qq|country = ?, | .
|
|
243 |
qq|homepage = ?, | .
|
|
244 |
qq|contact = ?, | .
|
|
245 |
qq|phone = ?, | .
|
|
246 |
qq|fax = ?, | .
|
|
247 |
qq|email = ?, | .
|
|
248 |
qq|cc = ?, | .
|
|
249 |
qq|bcc = ?, | .
|
|
250 |
qq|notes = ?, | .
|
|
251 |
qq|discount = ?, | .
|
|
252 |
qq|creditlimit = ?, | .
|
|
253 |
qq|terms = ?, | .
|
|
254 |
qq|business_id = ?, | .
|
|
255 |
qq|taxnumber = ?, | .
|
|
256 |
qq|sic_code = ?, | .
|
|
257 |
qq|language = ?, | .
|
|
258 |
qq|account_number = ?, | .
|
|
259 |
qq|bank_code = ?, | .
|
|
260 |
qq|bank = ?, | .
|
|
261 |
qq|obsolete = ?, | .
|
|
262 |
qq|ustid = ?, | .
|
|
263 |
qq|username = ?, | .
|
|
264 |
qq|salesman_id = ?, | .
|
|
265 |
qq|language_id = ?, | .
|
|
266 |
qq|payment_id = ?, | .
|
|
267 |
qq|taxzone_id = ?, | .
|
|
268 |
qq|user_password = ?, | .
|
|
269 |
qq|c_vendor_id = ?, | .
|
|
270 |
qq|klass = ? | .
|
|
271 |
qq|WHERE id = ?|;
|
|
272 |
my @values = (
|
|
273 |
$form->{customernumber},
|
|
274 |
$form->{name},
|
|
275 |
$form->{greeting},
|
|
276 |
$form->{department_1},
|
|
277 |
$form->{department_2},
|
|
278 |
$form->{street},
|
|
279 |
$form->{zipcode},
|
|
280 |
$form->{city},
|
|
281 |
$form->{country},
|
|
282 |
$form->{homepage},
|
|
283 |
$form->{contact},
|
|
284 |
$form->{phone},
|
|
285 |
$form->{fax},
|
|
286 |
$form->{email},
|
|
287 |
$form->{cc},
|
|
288 |
$form->{bcc},
|
|
289 |
$form->{notes},
|
|
290 |
$form->{discount},
|
|
291 |
$form->{creditlimit},
|
|
292 |
conv_i($form->{terms}),
|
|
293 |
conv_i($form->{business}),
|
|
294 |
$form->{taxnumber},
|
|
295 |
$form->{sic},
|
|
296 |
$form->{language},
|
|
297 |
$form->{account_number},
|
|
298 |
$form->{bank_code},
|
|
299 |
$form->{bank},
|
|
300 |
$form->{obsolete} ? 't' : 'f',
|
|
301 |
$form->{ustid},
|
|
302 |
$form->{username},
|
|
303 |
conv_i($form->{salesman_id}),
|
|
304 |
conv_i($form->{language_id}),
|
|
305 |
conv_i($form->{payment_id}),
|
|
306 |
conv_i($form->{taxzone_id}),
|
|
307 |
$form->{user_password},
|
|
308 |
$form->{c_vendor_id},
|
|
309 |
conv_i($form->{klass}),
|
|
310 |
$form->{id}
|
|
311 |
);
|
|
312 |
do_query( $form, $dbh, $query, @values );
|
|
313 |
|
|
314 |
$query = undef;
|
|
315 |
if ( $form->{cp_id} ) {
|
|
316 |
$query = qq|UPDATE contacts SET | .
|
|
317 |
qq|cp_greeting = ?, | .
|
|
318 |
qq|cp_title = ?, | .
|
|
319 |
qq|cp_givenname = ?, | .
|
|
320 |
qq|cp_name = ?, | .
|
|
321 |
qq|cp_email = ?, | .
|
|
322 |
qq|cp_phone1 = ?, | .
|
|
323 |
qq|cp_phone2 = ?, | .
|
|
324 |
qq|cp_abteilung = ?, | .
|
|
325 |
qq|cp_fax = ?, | .
|
|
326 |
qq|cp_mobile1 = ?, | .
|
|
327 |
qq|cp_mobile2 = ?, | .
|
|
328 |
qq|cp_satphone = ?, | .
|
|
329 |
qq|cp_satfax = ?, | .
|
|
330 |
qq|cp_project = ?, | .
|
|
331 |
qq|cp_privatphone = ?, | .
|
|
332 |
qq|cp_privatemail = ?, | .
|
|
333 |
qq|cp_birthday = ? | .
|
|
334 |
qq|WHERE cp_id = ?|;
|
|
335 |
@values = (
|
|
336 |
$form->{cp_greeting},
|
|
337 |
$form->{cp_title},
|
|
338 |
$form->{cp_givenname},
|
|
339 |
$form->{cp_name},
|
|
340 |
$form->{cp_email},
|
|
341 |
$form->{cp_phone1},
|
|
342 |
$form->{cp_phone2},
|
|
343 |
$form->{cp_abteilung},
|
|
344 |
$form->{cp_fax},
|
|
345 |
$form->{cp_mobile1},
|
|
346 |
$form->{cp_mobile2},
|
|
347 |
$form->{cp_satphone},
|
|
348 |
$form->{cp_satfax},
|
|
349 |
$form->{cp_project},
|
|
350 |
$form->{cp_privatphone},
|
|
351 |
$form->{cp_privatemail},
|
|
352 |
$form->{cp_birthday},
|
|
353 |
$form->{cp_id}
|
|
354 |
);
|
|
355 |
} elsif ( $form->{cp_name} || $form->{cp_givenname} ) {
|
504 |
356 |
$query =
|
505 |
|
qq|INSERT INTO contacts ( cp_cv_id, cp_greeting, cp_title, cp_givenname, cp_name, cp_email, cp_phone1, cp_phone2, cp_abteilung, cp_fax, cp_mobile1, cp_mobile2, cp_satphone, cp_satfax, cp_project, cp_privatphone, cp_privatemail, cp_birthday)
|
506 |
|
VALUES ($form->{id}, '$form->{cp_greeting}','$form->{cp_title}','$form->{cp_givenname}','$form->{cp_name}','$form->{cp_email}','$form->{cp_phone1}','$form->{cp_phone2}', '$form->{cp_abteilung}', | . $dbh->quote($form->{cp_fax}) . qq|,| . $dbh->quote($form->{cp_mobile1}) . qq|,| . $dbh->quote($form->{cp_mobile2}) . qq|,| . $dbh->quote($form->{cp_satphone}) . qq|,| . $dbh->quote($form->{cp_satfax}) . qq|,| . $dbh->quote($form->{cp_project}) . qq|,| . $dbh->quote($form->{cp_privatphone}) . qq|,| . $dbh->quote($form->{cp_privatemail}) . qq|,| . $dbh->quote($form->{cp_birthday}) . qq|)|;
|
507 |
|
}
|
508 |
|
$dbh->do($query) || $form->dberror($query);
|
509 |
|
|
510 |
|
# save taxes
|
511 |
|
foreach $item (split / /, $form->{taxaccounts}) {
|
512 |
|
if ($form->{"tax_$item"}) {
|
513 |
|
$query = qq|INSERT INTO customertax (customer_id, chart_id)
|
514 |
|
VALUES ($form->{id}, (SELECT c.id
|
515 |
|
FROM chart c
|
516 |
|
WHERE c.accno = '$item'))|;
|
517 |
|
$dbh->do($query) || $form->dberror($query);
|
518 |
|
}
|
519 |
|
}
|
|
357 |
qq|INSERT INTO contacts ( cp_cv_id, cp_greeting, cp_title, cp_givenname, | .
|
|
358 |
qq| cp_name, cp_email, cp_phone1, cp_phone2, cp_abteilung, cp_fax, cp_mobile1, | .
|
|
359 |
qq| cp_mobile2, cp_satphone, cp_satfax, cp_project, cp_privatphone, cp_privatemail, | .
|
|
360 |
qq| cp_birthday) | .
|
|
361 |
qq|VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
|
|
362 |
@values = (
|
|
363 |
$form->{id},
|
|
364 |
$form->{cp_greeting},
|
|
365 |
$form->{cp_title},
|
|
366 |
$form->{cp_givenname},
|
|
367 |
$form->{cp_name},
|
|
368 |
$form->{cp_email},
|
|
369 |
$form->{cp_phone1},
|
|
370 |
$form->{cp_phone2},
|
|
371 |
$form->{cp_abteilung},
|
|
372 |
$form->{cp_fax},
|
|
373 |
$form->{cp_mobile1},
|
|
374 |
$form->{cp_mobile2},
|
|
375 |
$form->{cp_satphone},
|
|
376 |
$form->{cp_satfax},
|
|
377 |
$form->{cp_project},
|
|
378 |
$form->{cp_privatphone},
|
|
379 |
$form->{cp_privatemail},
|
|
380 |
$form->{cp_birthday}
|
|
381 |
);
|
|
382 |
}
|
|
383 |
do_query( $form, $dbh, $query, @values ) if ($query);
|
|
384 |
|
520 |
385 |
# add shipto
|
521 |
|
$form->add_shipto($dbh, $form->{id}, "CT");
|
|
386 |
$form->add_shipto( $dbh, $form->{id}, "CT" );
|
522 |
387 |
|
523 |
|
$rc = $dbh->disconnect;
|
|
388 |
$rc = $dbh->commit();
|
|
389 |
$dbh->disconnect();
|
524 |
390 |
|
525 |
391 |
$main::lxdebug->leave_sub();
|
526 |
392 |
return $rc;
|
... | ... | |
529 |
395 |
sub save_vendor {
|
530 |
396 |
$main::lxdebug->enter_sub();
|
531 |
397 |
|
532 |
|
my ($self, $myconfig, $form) = @_;
|
|
398 |
my ( $self, $myconfig, $form ) = @_;
|
533 |
399 |
|
|
400 |
$form->{taxzone_id} *= 1;
|
534 |
401 |
# connect to database
|
535 |
|
my $dbh = $form->dbconnect($myconfig);
|
536 |
|
##LINET
|
537 |
|
map({
|
538 |
|
$form->{"cp_${_}"} = $form->{"selected_cp_${_}"}
|
539 |
|
if ($form->{"selected_cp_${_}"});
|
540 |
|
} qw(title greeting abteilung));
|
|
402 |
my $dbh = $form->dbconnect_noauto($myconfig);
|
|
403 |
|
|
404 |
map( {
|
|
405 |
$form->{"cp_${_}"} = $form->{"selected_cp_${_}"}
|
|
406 |
if ( $form->{"selected_cp_${_}"} );
|
|
407 |
} qw(title greeting abteilung) );
|
541 |
408 |
$form->{"greeting"} = $form->{"selected_company_greeting"}
|
542 |
|
if ($form->{"selected_company_greeting"});
|
543 |
|
# escape '
|
544 |
|
map { $form->{$_} =~ s/\'/\'\'/g }
|
545 |
|
qw(vendornumber name street zipcode city country homepage contact notes cp_title cp_greeting language);
|
546 |
|
##/LINET
|
547 |
|
$form->{discount} = $form->parse_amount($myconfig, $form->{discount});
|
|
409 |
if ( $form->{"selected_company_greeting"} );
|
|
410 |
|
|
411 |
$form->{discount} = $form->parse_amount( $myconfig, $form->{discount} );
|
548 |
412 |
$form->{discount} /= 100;
|
549 |
|
$form->{terms} *= 1;
|
550 |
|
$form->{taxincluded} *= 1;
|
551 |
|
$form->{obsolete} *= 1;
|
552 |
|
$form->{business} *= 1;
|
553 |
|
$form->{payment_id} *= 1;
|
554 |
|
$form->{taxzone_id} *= 1;
|
555 |
|
$form->{creditlimit} = $form->parse_amount($myconfig, $form->{creditlimit});
|
|
413 |
$form->{creditlimit} = $form->parse_amount( $myconfig, $form->{creditlimit} );
|
556 |
414 |
|
557 |
415 |
my $query;
|
558 |
416 |
|
559 |
|
if ($form->{id}) {
|
560 |
|
$query = qq|DELETE FROM vendortax
|
561 |
|
WHERE vendor_id = $form->{id}|;
|
562 |
|
$dbh->do($query) || $form->dberror($query);
|
|
417 |
if ( $form->{id} ) {
|
|
418 |
$query = qq|DELETE FROM shipto WHERE (trans_id = ?) AND (module = 'CT')|;
|
|
419 |
do_query($form, $dbh, $query, $form->{id});
|
563 |
420 |
|
564 |
|
$query = qq|DELETE FROM shipto
|
565 |
|
WHERE trans_id = $form->{id} AND module = 'CT'|;
|
566 |
|
$dbh->do($query) || $form->dberror($query);
|
567 |
421 |
} else {
|
568 |
|
my $uid = time;
|
569 |
|
$uid .= $form->{login};
|
570 |
|
my $uid = rand() . time;
|
571 |
|
$uid .= $form->{login};
|
572 |
|
$uid = substr($uid, 2, 75);
|
573 |
|
$query = qq|INSERT INTO vendor (name)
|
574 |
|
VALUES ('$uid')|;
|
575 |
|
$dbh->do($query) || $form->dberror($query);
|
576 |
|
|
577 |
|
$query = qq|SELECT v.id FROM vendor v
|
578 |
|
WHERE v.name = '$uid'|;
|
579 |
|
$sth = $dbh->prepare($query);
|
580 |
|
$sth->execute || $form->dberror($query);
|
581 |
|
|
582 |
|
($form->{id}) = $sth->fetchrow_array;
|
583 |
|
$sth->finish;
|
584 |
|
if (!$form->{vendornumber}) {
|
585 |
|
$form->{vendornumber} =
|
586 |
|
$form->update_defaults($myconfig, "vendornumber");
|
587 |
|
}
|
|
422 |
$query = qq|SELECT nextval('id')|;
|
|
423 |
($form->{id}) = selectrow_query($form, $dbh, $query);
|
588 |
424 |
|
589 |
|
}
|
|
425 |
$query = qq|INSERT INTO vendor (id, name) VALUES (?, '')|;
|
|
426 |
do_query($form, $dbh, $query, $form->{id});
|
590 |
427 |
|
591 |
|
##LINET
|
592 |
|
$query = qq|UPDATE vendor SET
|
593 |
|
vendornumber = '$form->{vendornumber}',
|
594 |
|
name = '$form->{name}',
|
595 |
|
greeting = '$form->{greeting}',
|
596 |
|
department_1 = '$form->{department_1}',
|
597 |
|
department_2 = '$form->{department_2}',
|
598 |
|
street = '$form->{street}',
|
599 |
|
zipcode = '$form->{zipcode}',
|
600 |
|
city = '$form->{city}',
|
601 |
|
country = '$form->{country}',
|
602 |
|
homepage = '$form->{homepage}',
|
603 |
|
contact = '$form->{contact}',
|
604 |
|
phone = '$form->{phone}',
|
605 |
|
fax = '$form->{fax}',
|
606 |
|
email = '$form->{email}',
|
607 |
|
cc = '$form->{cc}',
|
608 |
|
bcc = '$form->{bcc}',
|
609 |
|
notes = '$form->{notes}',
|
610 |
|
terms = $form->{terms},
|
611 |
|
discount = $form->{discount},
|
612 |
|
creditlimit = $form->{creditlimit},
|
613 |
|
taxincluded = '$form->{taxincluded}',
|
614 |
|
gifi_accno = '$form->{gifi_accno}',
|
615 |
|
business_id = $form->{business},
|
616 |
|
taxnumber = '$form->{taxnumber}',
|
617 |
|
sic_code = '$form->{sic}',
|
618 |
|
language = '$form->{language}',
|
619 |
|
account_number = '$form->{account_number}',
|
620 |
|
bank_code = '$form->{bank_code}',
|
621 |
|
bank = '$form->{bank}',
|
622 |
|
obsolete = '$form->{obsolete}',
|
623 |
|
ustid = '$form->{ustid}',
|
624 |
|
payment_id = '$form->{payment_id}',
|
625 |
|
taxzone_id = '$form->{taxzone_id}',
|
626 |
|
language_id = | . conv_i($form->{language_id}, "NULL") . qq|,
|
627 |
|
username = '$form->{username}',
|
628 |
|
user_password = '$form->{user_password}',
|
629 |
|
v_customer_id = '$form->{v_customer_id}'
|
630 |
|
WHERE id = $form->{id}|;
|
631 |
|
$dbh->do($query) || $form->dberror($query);
|
632 |
|
|
633 |
|
if ($form->{cp_id}) {
|
634 |
|
$query = qq|UPDATE contacts SET
|
635 |
|
cp_greeting = '$form->{cp_greeting}',
|
636 |
|
cp_title = '$form->{cp_title}',
|
637 |
|
cp_givenname = '$form->{cp_givenname}',
|
638 |
|
cp_name = '$form->{cp_name}',
|
639 |
|
cp_email = '$form->{cp_email}',
|
640 |
|
cp_phone1 = '$form->{cp_phone1}',
|
641 |
|
cp_phone2 = '$form->{cp_phone2}'
|
642 |
|
WHERE cp_id = $form->{cp_id}|;
|
643 |
|
} elsif ($form->{cp_name} || $form->{cp_givenname}) {
|
644 |
|
$query =
|
645 |
|
qq|INSERT INTO contacts ( cp_cv_id, cp_greeting, cp_title, cp_givenname, cp_name, cp_email, cp_phone1, cp_phone2)
|
646 |
|
VALUES ($form->{id}, '$form->{cp_greeting}','$form->{cp_title}','$form->{cp_givenname}','$form->{cp_name}','$form->{cp_email}','$form->{cp_phone1}','$form->{cp_phone2}')|;
|
647 |
|
}
|
648 |
|
$dbh->do($query) || $form->dberror($query);
|
649 |
|
|
650 |
|
# save taxes
|
651 |
|
foreach $item (split / /, $form->{taxaccounts}) {
|
652 |
|
if ($form->{"tax_$item"}) {
|
653 |
|
$query = qq|INSERT INTO vendortax (vendor_id, chart_id)
|
654 |
|
VALUES ($form->{id}, (SELECT c.id
|
655 |
|
FROM chart c
|
656 |
|
WHERE c.accno = '$item'))|;
|
657 |
|
$dbh->do($query) || $form->dberror($query);
|
|
428 |
if ( !$form->{vendornumber} ) {
|
|
429 |
$form->{vendornumber} = $form->update_defaults( $myconfig, "vendornumber", $dbh );
|
658 |
430 |
}
|
659 |
431 |
}
|
660 |
432 |
|
|
433 |
$query =
|
|
434 |
qq|UPDATE vendor SET | .
|
|
435 |
qq| vendornumber = ?, | .
|
|
436 |
qq| name = ?, | .
|
|
437 |
qq| greeting = ?, | .
|
|
438 |
qq| department_1 = ?, | .
|
|
439 |
qq| department_2 = ?, | .
|
|
440 |
qq| street = ?, | .
|
|
441 |
qq| zipcode = ?, | .
|
|
442 |
qq| city = ?, | .
|
|
443 |
qq| country = ?, | .
|
|
444 |
qq| homepage = ?, | .
|
|
445 |
qq| contact = ?, | .
|
|
446 |
qq| phone = ?, | .
|
|
447 |
qq| fax = ?, | .
|
|
448 |
qq| email = ?, | .
|
|
449 |
qq| cc = ?, | .
|
|
450 |
qq| bcc = ?, | .
|
|
451 |
qq| notes = ?, | .
|
|
452 |
qq| terms = ?, | .
|
|
453 |
qq| discount = ?, | .
|
|
454 |
qq| creditlimit = ?, | .
|
|
455 |
qq| business_id = ?, | .
|
|
456 |
qq| taxnumber = ?, | .
|
|
457 |
qq| sic_code = ?, | .
|
|
458 |
qq| language = ?, | .
|
|
459 |
qq| account_number = ?, | .
|
|
460 |
qq| bank_code = ?, | .
|
|
461 |
qq| bank = ?, | .
|
|
462 |
qq| obsolete = ?, | .
|
|
463 |
qq| ustid = ?, | .
|
|
464 |
qq| payment_id = ?, | .
|
|
465 |
qq| taxzone_id = ?, | .
|
|
466 |
qq| language_id = ?, | .
|
|
467 |
qq| username = ?, | .
|
|
468 |
qq| user_password = ?, | .
|
|
469 |
qq| v_customer_id = ? | .
|
|
470 |
qq|WHERE id = ?|;
|
|
471 |
@values = (
|
|
472 |
$form->{vendornumber},
|
|
473 |
$form->{name},
|
|
474 |
$form->{greeting},
|
|
475 |
$form->{department_1},
|
|
476 |
$form->{department_2},
|
|
477 |
$form->{street},
|
|
478 |
$form->{zipcode},
|
|
479 |
$form->{city},
|
|
480 |
$form->{country},
|
|
481 |
$form->{homepage},
|
|
482 |
$form->{contact},
|
|
483 |
$form->{phone},
|
|
484 |
$form->{fax},
|
|
485 |
$form->{email},
|
|
486 |
$form->{cc},
|
|
487 |
$form->{bcc},
|
|
488 |
$form->{notes},
|
|
489 |
conv_i($form->{terms}),
|
|
490 |
$form->{discount},
|
|
491 |
$form->{creditlimit},
|
|
492 |
conv_i($form->{business}),
|
|
493 |
$form->{taxnumber},
|
|
494 |
$form->{sic},
|
|
495 |
$form->{language},
|
|
496 |
$form->{account_number},
|
|
497 |
$form->{bank_code},
|
|
498 |
$form->{bank},
|
|
499 |
$form->{obsolete} ? 't' : 'f',
|
|
500 |
$form->{ustid},
|
|
501 |
conv_i($form->{payment_id}),
|
|
502 |
conv_i($form->{taxzone_id}),
|
|
503 |
conv_i( $form->{language_id}),
|
|
504 |
$form->{username},
|
|
505 |
$form->{user_password},
|
|
506 |
conv_i($form->{v_customer_id}),
|
|
507 |
$form->{id}
|
|
508 |
);
|
|
509 |
do_query($form, $dbh, $query, @values);
|
|
510 |
|
|
511 |
$query = undef;
|
|
512 |
if ( $form->{cp_id} ) {
|
|
513 |
$query =
|
|
514 |
qq|UPDATE contacts SET | .
|
|
515 |
qq| cp_greeting = ?, | .
|
|
516 |
qq| cp_title = ?, | .
|
|
517 |
qq| cp_givenname = ?, | .
|
|
518 |
qq| cp_name = ?, | .
|
|
519 |
qq| cp_email = ?, | .
|
|
520 |
qq| cp_phone1 = ?, | .
|
|
521 |
qq| cp_phone2 = ? | .
|
|
522 |
qq|WHERE cp_id = ?|;
|
|
523 |
@values = (
|
|
524 |
$form->{cp_greeting},
|
|
525 |
$form->{cp_title},
|
|
526 |
$form->{cp_givenname},
|
|
527 |
$form->{cp_name},
|
|
528 |
$form->{cp_email},
|
|
529 |
$form->{cp_phone1},
|
|
530 |
$form->{cp_phone2},
|
|
531 |
$form->{cp_id});
|
|
532 |
} elsif ( $form->{cp_name} || $form->{cp_givenname} ) {
|
|
533 |
$query =
|
|
534 |
qq|INSERT INTO contacts ( cp_cv_id, cp_greeting, cp_title, cp_givenname, cp_name, cp_email, cp_phone1, cp_phone2) | .
|
|
535 |
qq|VALUES (?, ?, ?, ?, ?, ?, ?, ?)|;
|
|
536 |
@values = (
|
|
537 |
conv_i($form->{id}),
|
|
538 |
$form->{cp_greeting},
|
|
539 |
$form->{cp_title},
|
|
540 |
$form->{cp_givenname},
|
|
541 |
$form->{cp_name},
|
|
542 |
$form->{cp_email},
|
|
543 |
$form->{cp_phone1},
|
|
544 |
$form->{cp_phone2});
|
|
545 |
}
|
|
546 |
do_query($form, $dbh, $query, @values) if ($query);
|
|
547 |
|
661 |
548 |
# add shipto
|
662 |
|
$form->add_shipto($dbh, $form->{id}, "CT");
|
|
549 |
$form->add_shipto( $dbh, $form->{id}, "CT" );
|
663 |
550 |
|
664 |
|
$rc = $dbh->disconnect;
|
|
551 |
$rc = $dbh->commit();
|
|
552 |
$dbh->disconnect();
|
665 |
553 |
|
666 |
554 |
$main::lxdebug->leave_sub();
|
667 |
555 |
return $rc;
|
... | ... | |
670 |
558 |
sub delete {
|
671 |
559 |
$main::lxdebug->enter_sub();
|
672 |
560 |
|
673 |
|
my ($self, $myconfig, $form) = @_;
|
674 |
|
|
|
561 |
my ( $self, $myconfig, $form ) = @_;
|
675 |
562 |
# connect to database
|
676 |
563 |
my $dbh = $form->dbconnect($myconfig);
|
677 |
564 |
|
678 |
565 |
# delete vendor
|
679 |
|
my $query = qq|DELETE FROM $form->{db}
|
680 |
|
WHERE id = $form->{id}|;
|
681 |
|
$dbh->do($query) || $form->dberror($query);
|
|
566 |
my $cv = $form->{db} eq "customer" ? "customer" : "vendor";
|
|
567 |
my $query = qq|DELETE FROM $cv WHERE id = ?|;
|
|
568 |
do_query($form, $dbh, $query, $form->{id});
|
682 |
569 |
|
683 |
570 |
$dbh->disconnect;
|
684 |
571 |
|
... | ... | |
688 |
575 |
sub search {
|
689 |
576 |
$main::lxdebug->enter_sub();
|
690 |
577 |
|
691 |
|
my ($self, $myconfig, $form) = @_;
|
|
578 |
my ( $self, $myconfig, $form ) = @_;
|
692 |
579 |
|
693 |
580 |
# connect to database
|
694 |
581 |
my $dbh = $form->dbconnect($myconfig);
|
695 |
582 |
|
|
583 |
my $cv = $form->{db} eq "customer" ? "customer" : "vendor";
|
|
584 |
|
696 |
585 |
my $where = "1 = 1";
|
697 |
|
$form->{sort} = "name" unless ($form->{sort});
|
698 |
|
if ($form->{sort} eq "address") {
|
699 |
|
$form->{sort} = "country,city,street";
|
700 |
|
}
|
|
586 |
my @values;
|
701 |
587 |
|
702 |
|
if ($form->{"$form->{db}number"}) {
|
703 |
|
my $companynumber = $form->like(lc $form->{"$form->{db}number"});
|
704 |
|
$where .= " AND lower(ct.$form->{db}number) LIKE '$companynumber'";
|
705 |
|
}
|
706 |
|
if ($form->{name}) {
|
707 |
|
my $name = $form->like(lc $form->{name});
|
708 |
|
$where .= " AND lower(ct.name) LIKE '$name'";
|
709 |
|
}
|
710 |
|
if ($form->{contact}) {
|
711 |
|
my $contact = $form->like(lc $form->{contact});
|
712 |
|
$where .= " AND lower(ct.contact) LIKE '$contact'";
|
|
588 |
my %allowed_sort_columns =
|
|
589 |
map({ $_, 1 } qw(id customernumber name address contact phone fax email
|
|
590 |
taxnumber sic_code business invnumber ordnumber quonumber));
|
|
591 |
$sortorder =
|
|
592 |
$form->{sort} && $allowed_sort_columns{$form->{sort}} ?
|
|
593 |
$form->{sort} : "name";
|
|
594 |
$sortorder = "country,city,street" if ($sortorder eq "address");
|
|
595 |
|
|
596 |
if ($form->{"${cv}number"}) {
|
|
597 |
$where .= " AND ct.${cv}number ILIKE ?";
|
|
598 |
push(@values, '%' . $form->{"${cv}number"} . '%');
|
713 |
599 |
}
|
714 |
|
if ($form->{email}) {
|
715 |
|
my $email = $form->like(lc $form->{email});
|
716 |
|
$where .= " AND lower(ct.email) LIKE '$email'";
|
|
600 |
|
|
601 |
foreach my $key (qw(name contact email)) {
|
|
602 |
if ($form->{$key}) {
|
|
603 |
$where .= " AND ct.$key ILIKE ?";
|
|
604 |
push(@values, '%' . $form->{$key} . '%');
|
|
605 |
}
|
717 |
606 |
}
|
718 |
607 |
|
719 |
|
if ($form->{status} eq 'orphaned') {
|
720 |
|
$where .= qq| AND ct.id NOT IN (SELECT o.$form->{db}_id
|
721 |
|
FROM oe o, $form->{db} cv
|
722 |
|
WHERE cv.id = o.$form->{db}_id)|;
|
723 |
|
if ($form->{db} eq 'customer') {
|
724 |
|
$where .= qq| AND ct.id NOT IN (SELECT a.customer_id
|
725 |
|
FROM ar a, customer cv
|
726 |
|
WHERE cv.id = a.customer_id)|;
|
|
608 |
if ( $form->{status} eq 'orphaned' ) {
|
|
609 |
$where .=
|
|
610 |
qq| AND ct.id NOT IN | .
|
|
611 |
qq| (SELECT o.${cv}_id FROM oe o, $cv cv WHERE cv.id = o.${cv}_id)|;
|
|
612 |
if ($cv eq 'customer') {
|
|
613 |
$where .=
|
|
614 |
qq| AND ct.id NOT IN | .
|
|
615 |
qq| (SELECT a.customer_id FROM ar a, customer cv | .
|
|
616 |
qq| WHERE cv.id = a.customer_id)|;
|
727 |
617 |
}
|
728 |
|
if ($form->{db} eq 'vendor') {
|
729 |
|
$where .= qq| AND ct.id NOT IN (SELECT a.vendor_id
|
730 |
|
FROM ap a, vendor cv
|
731 |
|
WHERE cv.id = a.vendor_id)|;
|
|
618 |
if ($cv eq 'vendor') {
|
|
619 |
$where .=
|
|
620 |
qq| AND ct.id NOT IN | .
|
|
621 |
qq| (SELECT a.vendor_id FROM ap a, vendor cv | .
|
|
622 |
qq| WHERE cv.id = a.vendor_id)|;
|
732 |
623 |
}
|
733 |
624 |
$form->{l_invnumber} = $form->{l_ordnumber} = $form->{l_quonumber} = "";
|
734 |
625 |
}
|
735 |
626 |
|
736 |
|
my $query = qq|SELECT ct.*, b.description AS business
|
737 |
|
FROM $form->{db} ct
|
738 |
|
LEFT JOIN business b ON (ct.business_id = b.id)
|
739 |
|
WHERE $where|;
|
|
627 |
my $query =
|
|
628 |
qq|SELECT ct.*, b.description AS business | .
|
|
629 |
qq|FROM $cv ct | .
|
|
630 |
qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
|
|
631 |
qq|WHERE $where|;
|
740 |
632 |
|
741 |
633 |
# redo for invoices, orders and quotations
|
742 |
634 |
if ($form->{l_invnumber} || $form->{l_ordnumber} || $form->{l_quonumber}) {
|
743 |
|
|
744 |
635 |
my ($ar, $union, $module);
|
745 |
636 |
$query = "";
|
746 |
637 |
|
747 |
638 |
if ($form->{l_invnumber}) {
|
748 |
|
$ar = ($form->{db} eq 'customer') ? 'ar' : 'ap';
|
749 |
|
$module = ($ar eq 'ar') ? 'is' : 'ir';
|
750 |
|
|
751 |
|
$query = qq|SELECT ct.*, b.description AS business,
|
752 |
|
a.invnumber, a.ordnumber, a.quonumber, a.id AS invid,
|
753 |
|
'$module' AS module, 'invoice' AS formtype,
|
754 |
|
(a.amount = a.paid) AS closed
|
755 |
|
FROM $form->{db} ct
|
756 |
|
JOIN $ar a ON (a.$form->{db}_id = ct.id)
|
757 |
|
LEFT JOIN business b ON (ct.business_id = b.id)
|
758 |
|
WHERE $where
|
759 |
|
AND a.invoice = '1'|;
|
760 |
|
|
761 |
|
$union = qq|
|
762 |
|
UNION|;
|
763 |
|
|
|
639 |
my $ar = $cv eq 'customer' ? 'ar' : 'ap';
|
|
640 |
my $module = $ar eq 'ar' ? 'is' : 'ir';
|
|
641 |
|
|
642 |
$query =
|
|
643 |
qq|SELECT ct.*, b.description AS business, | .
|
|
644 |
qq| a.invnumber, a.ordnumber, a.quonumber, a.id AS invid, | .
|
|
645 |
qq| '$module' AS module, 'invoice' AS formtype, | .
|
|
646 |
qq| (a.amount = a.paid) AS closed | .
|
|
647 |
qq|FROM $cv ct | .
|
|
648 |
qq|JOIN $ar a ON (a.${cv}_id = ct.id) | .
|
|
649 |
qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
|
|
650 |
qq|WHERE $where AND (a.invoice = '1')|;
|
|
651 |
|
|
652 |
$union = qq|UNION|;
|
764 |
653 |
}
|
765 |
654 |
|
766 |
|
if ($form->{l_ordnumber}) {
|
767 |
|
$query .= qq|$union
|
768 |
|
SELECT ct.*, b.description AS business,
|
769 |
|
' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid,
|
770 |
|
'oe' AS module, 'order' AS formtype,
|
771 |
|
o.closed
|
772 |
|
FROM $form->{db} ct
|
773 |
|
JOIN oe o ON (o.$form->{db}_id = ct.id)
|
774 |
|
LEFT JOIN business b ON (ct.business_id = b.id)
|
775 |
|
WHERE $where
|
776 |
|
AND o.quotation = '0'|;
|
777 |
|
|
778 |
|
$union = qq|
|
779 |
|
UNION|;
|
|
655 |
if ( $form->{l_ordnumber} ) {
|
|
656 |
$query .=
|
|
657 |
qq| $union | .
|
|
658 |
qq|SELECT ct.*, b.description AS business,| .
|
|
659 |
qq| ' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid, | .
|
|
660 |
qq| 'oe' AS module, 'order' AS formtype, o.closed | .
|
|
661 |
qq|FROM $cv ct | .
|
|
662 |
qq|JOIN oe o ON (o.${cv}_id = ct.id) | .
|
|
663 |
qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
|
|
664 |
qq|WHERE $where AND (o.quotation = '0')|;
|
|
665 |
|
|
666 |
$union = qq|UNION|;
|
780 |
667 |
}
|
781 |
668 |
|
782 |
|
if ($form->{l_quonumber}) {
|
783 |
|
$query .= qq|$union
|
784 |
|
SELECT ct.*, b.description AS business,
|
785 |
|
' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid,
|
786 |
|
'oe' AS module, 'quotation' AS formtype,
|
787 |
|
o.closed
|
788 |
|
FROM $form->{db} ct
|
789 |
|
JOIN oe o ON (o.$form->{db}_id = ct.id)
|
790 |
|
LEFT JOIN business b ON (ct.business_id = b.id)
|
791 |
|
WHERE $where
|
792 |
|
AND o.quotation = '1'|;
|
793 |
|
|
|
669 |
if ( $form->{l_quonumber} ) {
|
|
670 |
$query .=
|
|
671 |
qq| $union | .
|
|
672 |
qq|SELECT ct.*, b.description AS business, | .
|
|
673 |
qq| ' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid, | .
|
|
674 |
qq| 'oe' AS module, 'quotation' AS formtype, o.closed | .
|
|
675 |
qq|FROM $cv ct | .
|
|
676 |
qq|JOIN oe o ON (o.${cv}_id = ct.id) | .
|
|
677 |
qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
|
|
678 |
qq|WHERE $where AND (o.quotation = '1')|;
|
794 |
679 |
}
|
795 |
680 |
}
|
796 |
681 |
|
797 |
|
$query .= qq|
|
798 |
|
ORDER BY $form->{sort}|;
|
|
682 |
$query .= qq| ORDER BY $sortorder|;
|
799 |
683 |
|
800 |
|
my $sth = $dbh->prepare($query);
|
801 |
|
$sth->execute || $form->dberror($query);
|
802 |
|
##LINET
|
803 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
804 |
|
$ref->{address} = "";
|
805 |
|
map { $ref->{address} .= "$ref->{$_} "; } qw(street zipcode city country);
|
806 |
|
push @{ $form->{CT} }, $ref;
|
807 |
|
}
|
808 |
|
##/LINET
|
809 |
|
$sth->finish;
|
810 |
|
$dbh->disconnect;
|
|
684 |
$form->{CT} = selectall_hashref_query($form, $dbh, $query, @values);
|
|
685 |
map({ my $ref = $_; $ref->{address} = join(" ", map({ $ref->{$_} } qw(street zipcode city country))); }
|
|
686 |
@{ $form->{CT} });
|
811 |
687 |
|
812 |
688 |
$main::lxdebug->leave_sub();
|
813 |
689 |
}
|
... | ... | |
815 |
691 |
sub get_contact {
|
816 |
692 |
$main::lxdebug->enter_sub();
|
817 |
693 |
|
818 |
|
my ($self, $myconfig, $form) = @_;
|
|
694 |
my ( $self, $myconfig, $form ) = @_;
|
819 |
695 |
my $dbh = $form->dbconnect($myconfig);
|
820 |
|
my $query = qq|SELECT c.*
|
821 |
|
FROM contacts c
|
822 |
|
WHERE c.cp_id = $form->{cp_id} order by c.cp_id limit 1|;
|
823 |
|
my $sth = $dbh->prepare($query);
|
824 |
|
$sth->execute || $form->dberror($query);
|
825 |
|
|
|
696 |
my $query =
|
|
697 |
qq|SELECT * FROM contacts c | .
|
|
698 |
qq|WHERE cp_id = ? ORDER BY cp_id limit 1|;
|
|
699 |
my $sth = prepare_execute_query($form, $dbh, $query, $form->{cp_id});
|
826 |
700 |
my $ref = $sth->fetchrow_hashref(NAME_lc);
|
827 |
701 |
|
828 |
702 |
map { $form->{$_} = $ref->{$_} } keys %$ref;
|
... | ... | |
833 |
707 |
$main::lxdebug->leave_sub();
|
834 |
708 |
}
|
835 |
709 |
|
836 |
|
|
837 |
710 |
sub get_shipto {
|
838 |
711 |
$main::lxdebug->enter_sub();
|
839 |
712 |
|
840 |
|
my ($self, $myconfig, $form) = @_;
|
|
713 |
my ( $self, $myconfig, $form ) = @_;
|
841 |
714 |
my $dbh = $form->dbconnect($myconfig);
|
842 |
|
my $query = qq|SELECT s.*
|
843 |
|
FROM shipto s
|
844 |
|
WHERE s.shipto_id = $form->{shipto_id}|;
|
845 |
|
#WHERE s.shipto_id = $form->{shipto_id} order by s.shipto_id limit 1|;
|
846 |
|
my $sth = $dbh->prepare($query);
|
847 |
|
$sth->execute || $form->dberror($query);
|
|
715 |
my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|;
|
|
716 |
my $sth = prepare_execute_query($form, $dbh, $query, $form->{shipto_id});
|
848 |
717 |
|
849 |
718 |
my $ref = $sth->fetchrow_hashref(NAME_lc);
|
850 |
719 |
|
... | ... | |
859 |
728 |
sub get_delivery {
|
860 |
729 |
$main::lxdebug->enter_sub();
|
861 |
730 |
|
862 |
|
my ($self, $myconfig, $form) = @_;
|
863 |
|
my $dbh = $form->dbconnect($myconfig);
|
864 |
|
$tabelle = ($form->{db} eq "vendor") ? "ap" : "ar";
|
|
731 |
my ( $self, $myconfig, $form ) = @_;
|
|
732 |
my $dbh = $form->dbconnect($myconfig);
|
865 |
733 |
|
866 |
|
$where = " WHERE 1=1 ";
|
867 |
|
if ($form->{shipto_id} && $tabelle eq "ar") {
|
868 |
|
$where .= "AND $tabelle.shipto_id=$form->{shipto_id} ";
|
|
734 |
my $arap = $form->{db} eq "vendor" ? "ap" : "ar";
|
|
735 |
my $db = $form->{db} eq "customer" ? "customer" : "vendor";
|
|
736 |
|
|
737 |
my $where = " WHERE 1=1 ";
|
|
738 |
my @values;
|
|
739 |
|
|
740 |
if ($form->{shipto_id} && ($arap eq "ar")) {
|
|
741 |
$where .= "AND ${arap}.shipto_id = ?";
|
|
742 |
push(@values, $form->{shipto_id});
|
869 |
743 |
} else {
|
870 |
|
$where .="AND $tabelle.$form->{db}_id=$form->{id} ";
|
|
744 |
$where .= "AND ${arap}.${db}_id = ?";
|
|
745 |
push(@values, $form->{id});
|
871 |
746 |
}
|
|
747 |
|
872 |
748 |
if ($form->{from}) {
|
873 |
|
$where .= "AND $tabelle.transdate >= '$form->{from}' ";
|
|
749 |
$where .= "AND ${arap}.transdate >= ?";
|
|
750 |
push(@values, conv_date($form->{from}));
|
874 |
751 |
}
|
875 |
752 |
if ($form->{to}) {
|
876 |
|
$where .= "AND $tabelle.transdate <= '$form->{to}' ";
|
877 |
|
}
|
878 |
|
my $query = qq|select shiptoname, $tabelle.transdate, $tabelle.invnumber, $tabelle.ordnumber, invoice.description, qty, invoice.unit FROM $tabelle LEFT JOIN shipto ON |;
|
879 |
|
$query .= ($tabelle eq "ar") ? qq|($tabelle.shipto_id=shipto.shipto_id) |:qq|($tabelle.id=shipto.trans_id) |;
|
880 |
|
$query .=qq|LEFT join invoice on ($tabelle.id=invoice.trans_id) LEFT join parts ON (parts.id=invoice.parts_id) $where ORDER BY $tabelle.transdate DESC LIMIT 15|;
|
881 |
|
my $sth = $dbh->prepare($query);
|
882 |
|
$sth->execute || $form->dberror($query);
|
|
753 |
$where .= "AND ${arap}.transdate <= ?";
|
|
754 |
push(@values, conv_date($form->{to}));
|
|
755 |
}
|
|
756 |
my $query =
|
|
757 |
qq|SELECT s.shiptoname, i.qty, | .
|
|
758 |
qq| ${arap}.transdate, ${arap}.invnumber, ${arap}.ordnumber, | .
|
|
759 |
qq| invoice.description, invoice.unit | .
|
|
760 |
qq|FROM $arap | .
|
|
761 |
qq|LEFT JOIN shipto s ON | .
|
|
762 |
($arap eq "ar"
|
|
763 |
? qq|(ar.shipto_id = s.shipto_id) |
|
|
764 |
: qq|(ap.id = s.trans_id) |) .
|
|
765 |
qq|LEFT JOIN invoice i ON (${arap}.id = i.trans_id) | .
|
|
766 |
qq|LEFT join parts p ON (p.id = i.parts_id) | .
|
|
767 |
$where .
|
|
768 |
qq|ORDER BY ${arap}.transdate DESC LIMIT 15|;
|
|
769 |
|
|
770 |
$form->{DELIVERY} = selectall_hashref_query($form, $dbh, $query, @values);
|
883 |
771 |
|
884 |
|
|
885 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
886 |
|
push @{ $form->{DELIVERY} }, $ref;
|
887 |
|
}
|
888 |
|
$sth->finish;
|
889 |
772 |
$dbh->disconnect;
|
890 |
773 |
|
891 |
774 |
$main::lxdebug->leave_sub();
|
892 |
775 |
}
|
893 |
776 |
|
894 |
777 |
1;
|
895 |
|
|
CT.pm auf die Verwendung von parametrisierten Queries zur Vermeidung von SQL injection umgestellt. Dabei Restfunktionalität von customertax und vendortax entfernt. Mehr Datenbankhilfsfunktionen hinzugefügt.