X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FOE.pm;h=48ff26e301403934ea35364a3245905d9aaa2dfb;hb=e765448cae9f91754d3e93b377705f8533e0b842;hp=888f422bea062ce8a3efa55c97906b2d6268c861;hpb=92daa1a66a9ff737c92df86da3c28d663c421032;p=kivitendo-erp.git diff --git a/SL/OE.pm b/SL/OE.pm index 888f422be..48ff26e30 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -35,6 +35,8 @@ package OE; use SL::AM; +use SL::Common; +use SL::DBUtils; sub transactions { $main::lxdebug->enter_sub(); @@ -64,7 +66,7 @@ sub transactions { my $query = qq|SELECT o.id, o.ordnumber, o.transdate, o.reqdate, o.amount, ct.name, o.netamount, o.$form->{vc}_id, ex.$rate AS exchangerate, - o.closed, o.quonumber, o.shippingpoint, o.shipvia, + o.closed, o.delivered, o.quonumber, o.shippingpoint, o.shipvia, e.name AS employee FROM oe o JOIN $form->{vc} ct ON (o.$form->{vc}_id = ct.id) @@ -125,6 +127,12 @@ sub transactions { $query .= ($form->{open}) ? " AND o.closed = '0'" : " AND o.closed = '1'"; } + if (($form->{"notdelivered"} || $form->{"delivered"}) && + ($form->{"notdelivered"} ne $form->{"delivered"})) { + $query .= $form->{"delivered"} ? + " AND o.delivered " : " AND NOT o.delivered"; + } + my $sortorder = join ', ', ("o.id", $form->sort_columns(transdate, $ordnumber, name)); $sortorder = $form->{sort} if $form->{sort}; @@ -173,8 +181,6 @@ sub save { $form->get_employee($dbh); } - $form->{contact_id} = $form->{cp_id}; - $form->{contact_id} *= 1; $form->{payment_id} *= 1; $form->{language_id} *= 1; $form->{shipto_id} *= 1; @@ -239,7 +245,7 @@ sub save { $form->parse_amount($myconfig, $form->{"${_}_$i"}) } qw(qty ship); - if ($form->{"qty_$i"}) { + if ($form->{"id_$i"}) { # get item baseunit $query = qq|SELECT p.unit @@ -459,6 +465,7 @@ Message: $form->{message}\r| if $form->{message}; intnotes = '$form->{intnotes}', curr = '$form->{currency}', closed = '$form->{closed}', + delivered = '| . ($form->{delivered} ? "t" : "f") . qq|', proforma = '$form->{proforma}', quotation = '$quotation', department_id = $form->{department_id}, @@ -469,16 +476,12 @@ Message: $form->{message}\r| if $form->{message}; delivery_vendor_id = $form->{delivery_vendor_id}, delivery_customer_id = $form->{delivery_customer_id}, employee_id = $form->{employee_id}, - cp_id = $form->{contact_id} + cp_id = | . conv_i($form->{cp_id}, 'NULL') . qq| WHERE id = $form->{id}|; $dbh->do($query) || $form->dberror($query); $form->{ordtotal} = $amount; - if ($form->{webdav}) { - &webdav_folder($myconfig, $form); - } - # add shipto $form->{name} = $form->{ $form->{vc} }; $form->{name} =~ s/--$form->{"$form->{vc}_id"}//; @@ -511,6 +514,8 @@ Message: $form->{message}\r| if $form->{message}; my $rc = $dbh->commit; $dbh->disconnect; + Common::webdav_folder($form) if ($main::webdav); + $main::lxdebug->leave_sub(); return $rc; @@ -524,27 +529,6 @@ sub close_orders { my ($self, $myconfig, $form) = @_; - for my $i (1 .. $form->{rowcount}) { - - map { - $form->{"${_}_$i"} = - $form->parse_amount($myconfig, $form->{"${_}_$i"}) - } qw(qty ship); - if ($delete_oe_id) { - $form->{"orderitems_id_$i"} = ""; - } - - if ($form->{"qty_$i"}) { - - # set values to 0 if nothing entered - $form->{"discount_$i"} = - $form->parse_amount($myconfig, $form->{"discount_$i"}); - - $form->{"sellprice_$i"} = - $form->parse_amount($myconfig, $form->{"sellprice_$i"}); - } - } - # get ids from $form map { push @ids, $form->{"ordnumber_$_"} if $form->{"ordnumber_$_"} } (1 .. $form->{rowcount}); @@ -560,6 +544,21 @@ sub close_orders { $main::lxdebug->leave_sub(); } +sub close_order { + $main::lxdebug->enter_sub(); + + my ($self, $myconfig, $form) = @_; + + $main::lxdebug->leave_sub() unless ($form->{"id"}); + + my $dbh = $form->dbconnect($myconfig); + do_query($form, $dbh, qq|UPDATE oe SET closed = TRUE where id = ?|, + $form->{"id"}); + $dbh->disconnect; + + $main::lxdebug->leave_sub(); +} + sub delete { $main::lxdebug->enter_sub(); @@ -708,7 +707,9 @@ sub retrieve { o.curr AS currency, e.name AS employee, o.employee_id, o.$form->{vc}_id, cv.name AS $form->{vc}, o.amount AS invtotal, o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber, - d.description AS department, o.payment_id, o.language_id, o.taxzone_id, o.delivery_customer_id, o.delivery_vendor_id, o.proforma, o.shipto_id + d.description AS department, o.payment_id, o.language_id, o.taxzone_id, + o.delivery_customer_id, o.delivery_vendor_id, o.proforma, o.shipto_id, + o.delivered FROM oe o JOIN $form->{vc} cv ON (o.$form->{vc}_id = cv.id) LEFT JOIN employee e ON (o.employee_id = e.id) @@ -787,10 +788,9 @@ sub retrieve { my %oid = ('Pg' => 'oid', 'Oracle' => 'rowid'); - my $transdate = "'$form->{transdate}'"; - if (!$transdate) { - $transdate = "current_date"; - } + my $transdate = + $form->{transdate} ? $dbh->quote($form->{transdate}) : "current_date"; + if(!$form->{taxzone_id}) { $form->{taxzone_id} = 0; } @@ -869,19 +869,13 @@ sub retrieve { # delete orderitems_id in collective orders, so that they get cloned no matter what delete $ref->{orderitems_id} if (@ids); - #set expense_accno=inventory_accno if they are different => bilanz - $vendor_accno = - ($ref->{expense_accno} != $ref->{inventory_accno}) - ? $ref->{inventory_accno} - : $ref->{expense_accno}; - # get tax rates and description $accno_id = - ($form->{vc} eq "customer") ? $ref->{income_accno} : $vendor_accno; + ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno}; $query = qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber - FROM tax t LEFT JOIN chart c ON (c.id=t.chart_id) - WHERE t.taxkey in (SELECT taxkey_id from chart where accno = '$accno_id') - ORDER BY accno|; + FROM tax t LEFT JOIN chart c on (c.id=t.chart_id) + WHERE t.id in (SELECT tk.tax_id from taxkeys tk where tk.chart_id = (SELECT id from chart WHERE accno='$accno_id') AND startdate<=$transdate ORDER BY startdate desc LIMIT 1) + ORDER BY c.accno|; $stw = $dbh->prepare($query); $stw->execute || $form->dberror($query); $ref->{taxaccounts} = ""; @@ -921,9 +915,7 @@ sub retrieve { $form->get_exchangerate($dbh, $form->{currency}, $form->{transdate}, ($form->{vc} eq 'customer') ? "buy" : "sell"); - if ($form->{webdav}) { - &webdav_folder($myconfig, $form); - } + Common::webdav_folder($form) if ($main::webdav); # get tax zones $query = qq|SELECT id, description @@ -1012,12 +1004,14 @@ sub order_details { $sameitem = $item->[1]; map { push(@{ $form->{$_} }, "") } - qw(runningnumber number qty ship unit bin partnotes serialnumber reqdate sellprice listprice netprice discount linetotal); + qw(runningnumber number qty ship unit bin partnotes + serialnumber reqdate sellprice listprice netprice + discount p_discount linetotal); } $form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"}); - if ($form->{"qty_$i"} != 0) { + if ($form->{"id_$i"} != 0) { # add number, description and qty to $form->{number}, .... @@ -1172,7 +1166,9 @@ sub order_details { while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { if ($form->{groupitems} && $ref->{partsgroup} ne $sameitem) { map { push(@{ $form->{$_} }, "") } - qw(runningnumber ship bin serialnumber number unit bin qty reqdate sellprice listprice netprice discount linetotal nodiscount_linetotal); + qw(runningnumber ship bin serialnumber number unit bin qty + reqdate sellprice listprice netprice discount p_discount + linetotal nodiscount_linetotal); $sameitem = ($ref->{partsgroup}) ? $ref->{partsgroup} : "--"; push(@{ $form->{description} }, $sameitem); } @@ -1183,7 +1179,9 @@ sub order_details { . qq|, $ref->{partnumber}, $ref->{description}|); map { push(@{ $form->{$_} }, "") } - qw(number unit qty runningnumber ship bin serialnumber reqdate sellprice listprice netprice discount linetotal nodiscount_linetotal); + qw(number unit qty runningnumber ship bin serialnumber reqdate + sellprice listprice netprice discount p_discount linetotal + nodiscount_linetotal); } $sth->finish; @@ -1640,39 +1638,5 @@ sub transfer { return $rc; } -sub webdav_folder { - $main::lxdebug->enter_sub(); - - my ($myconfig, $form) = @_; - -SWITCH: { - $path = "webdav/angebote/" . $form->{quonumber}, last SWITCH - if ($form->{type} eq "sales_quotation"); - $path = "webdav/bestellungen/" . $form->{ordnumber}, last SWITCH - if ($form->{type} eq "sales_order"); - $path = "webdav/anfragen/" . $form->{quonumber}, last SWITCH - if ($form->{type} eq "request_quotation"); - $path = "webdav/lieferantenbestellungen/" . $form->{ordnumber}, last SWITCH - if ($form->{type} eq "purchase_order"); - } - - if (!-d $path) { - mkdir($path, 0770) or die "can't make directory $!\n"; - } else { - if ($form->{id}) { - @files = <$path/*>; - foreach $file (@files) { - $file =~ /\/([^\/]*)$/; - $fname = $1; - $ENV{'SCRIPT_NAME'} =~ /\/([^\/]*)\//; - $lxerp = $1; - $link = "http://" . $ENV{'SERVER_NAME'} . "/" . $lxerp . "/" . $file; - $form->{WEBDAV}{$fname} = $link; - } - } - } - - $main::lxdebug->leave_sub(); -} 1;