\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "" . "" . "\n"; echo "" . "" . "\n"; echo "
Order Nr$nr
Supplier" . $row["os_name"] . "
Order Date " . $row["oo_order_date"] . "
Parts" . make_price_str( $row["oo_parts_price"] ) . " " . $row["oo_parts_currency"] . "@" . make_price_str( $row["oo_parts_cur_rate"] ) . "
Shipping  "; print_select( "ship_curr", $OP_CURRENCIES, $row["oo_ship_currency"] ); echo "@
Taxes  "; print_select( "taxes_curr", $OP_CURRENCIES, $row["oo_taxes_currency"] ); echo "@
\n"; echo "\n"; echo "\n"; } function cmd_orders_show_detail( $nr, $ounr ) { $sql = "select " . "os_name, " . "to_char( oo_deliver_date, 'DD.MM.YYYY' ) as oo_deliver_date, " . "oo_parts_price, " . "oo_parts_currency, " . "oo_parts_cur_rate, " . "oo_ship_price, " . "oo_ship_currency, " . "oo_ship_cur_rate, " . "oo_taxes_price, " . "oo_taxes_currency, " . "oo_taxes_cur_rate, " . "oo_total_rate " . "from " . "orderorder o, " . "ordersupplier s " . "where " . "o.os_nr = s.os_nr and " . "oo_nr = $nr"; $ress = db_query( $sql ); if( !$ress ) { print_error( "no result set" ); return; } $row = db_next( $ress ); if( !$row ) { print_error( "no rows" ); return; } $os_name = $row["os_name"]; $deliver_date = $row["oo_deliver_date"]; $parts_price = $row["oo_parts_price"]; $parts_curr = $row["oo_parts_currency"]; $parts_rate = $row["oo_parts_cur_rate"]; $ship_price = $row["oo_ship_price"]; $ship_curr = $row["oo_ship_currency"]; $ship_rate = $row["oo_ship_cur_rate"]; $taxes_price = $row["oo_taxes_price"]; $taxes_curr = $row["oo_taxes_currency"]; $taxes_rate = $row["oo_taxes_cur_rate"]; $total_rate = $row["oo_total_rate"]; $user = ""; if( $ounr > 0 ) { $sql = "select ou_name from orderuser where ou_nr = $ounr"; $ress = db_query( $sql ); if( !$ress ) { print_error( "no result set" ); return; } $row = db_next( $ress ); if( !$row ) { print_error( "no rows" ); return; } $user = $row["ou_name"]; $sql = "select " . "p.op_name, " . "p.op_descr, " . "p.op_part_nr, " . "pu.opu_count, " . "pu.opu_price, " . "pu.opu_price_chf " . "from " . "orderpart p " . "left join orderparttag pt on " . "p.op_nr = pt.op_nr and " . "pt.opt_primary = 1 " . "left join ordertag t on " . "pt.ot_nr = t.ot_nr, " . "orderpartuser pu " . "where " . "pu.ou_nr = $ounr and ". "pu.oo_nr = $nr and " . "p.op_nr = pu.op_nr " . "order by " . "t.ot_long_name, " . "p.op_name, " . "p.op_nr "; } else { $sql = "select " . "p.op_name, " . "p.op_descr, " . "p.op_part_nr, " . "pu.opu_count, " . "pu.opu_price, " . "pu.opu_price2, " . "pu.opu_price_chf, " . "pu.opu_price_chf2 " . "from " . "orderpart p " . "left join orderparttag pt on " . "p.op_nr = pt.op_nr and " . "pt.opt_primary = 1 " . "left join ordertag t on " . "pt.ot_nr = t.ot_nr, " . "( " . "select " . "op_nr, " . "sum(opu_count) as opu_count, " . "min(opu_price) as opu_price, " . "max(opu_price) as opu_price2, " . "min(opu_price_chf) as opu_price_chf, " . "max(opu_price_chf) as opu_price_chf2 " . "from " . "orderpartuser " . "where " . "oo_nr = $nr " . "group by " . "op_nr " . ") pu " . "where " . "p.op_nr = pu.op_nr " . "order by " . "t.ot_long_name, " . "p.op_name, " . "p.op_nr "; } $ress = db_query( $sql ); if( !$ress ) { print_error( "no result set" ); return; } $row = db_next( $ress ); if( !$row ) { print_error( "no rows" ); return; } echo "

Details $os_name Order $nr $user

\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if( $deliver_date != "" ) { echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if( $deliver_date != "" ) { echo "\n"; echo "\n"; } echo "\n"; $ptot = 0; $chftot = 0; while( $row ) { $partnr = htmlentities( $row["op_part_nr"] ); $name = htmlentities( $row["op_name"] ); $descr = htmlentities( $row["op_descr"] ); if( $descr != "" ) { $name .= " -- " . $descr; } $count = $row["opu_count"]; $pricei = $row["opu_price"]; $price = make_price_str( $pricei ); $totali = $pricei * $count; $total = make_price_str( $totali ); $ptot += $totali; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if( $deliver_date != "" ) { $price_chfi = $row["opu_price_chf"]; $price_chf = make_price_str( $price_chfi ); $total_chfi = $price_chfi * $count; $total_chf = make_price_str( $total_chfi ); $chftot += $total_chfi; echo "\n"; echo "\n"; } echo "\n"; $row = db_next( $ress ); } echo "\n"; echo "\n"; echo "\n"; echo "\n"; if( $ounr > 0 ) { $ship_price = ($ship_price * $ptot) / $parts_price; $taxes_price = ($taxes_price * $ptot) / $parts_price; } $ptotchf = currency_to_chf( $ptot, $parts_rate ) + currency_to_chf( $ship_price, $ship_rate ) + currency_to_chf( $taxes_price, $taxes_rate ); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if( $deliver_date != "" ) { echo ""; } echo "\n"; echo "
part nr name -- description count price total price total 
   $parts_curr $parts_curr CHF*CHF*
$partnr $name  $count $price $total $price_chf $total_chf
Subtotal" . make_price_str( $ptot ) . "
 
Shipping$ship_curr" . make_price_str( $ship_price ) . "
Taxes$taxes_curr" . make_price_str( $taxes_price ) . "
TotalCHF" . make_price_str( $ptotchf ) . "" . make_price_str( $chftot ) . "
\n"; if( $deliver_date != "" ) { echo "

 

\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Parts rate: " . make_price_str( $parts_rate ) . " $parts_curr
Shipping rate: " . make_price_str( $ship_rate ) . " $ship_curr
Taxes rate: " . make_price_str( $taxes_rate ) . " $taxes_curr
Total rate: " . make_price_str( $total_rate ) . " $parts_curr -> CHF *
\n"; echo "

* including shipping and taxes

\n"; } } function cmd_orders_show_summary( $nr ) { $sql = "select " . "to_char( o.oo_order_date, 'DD.MM.YYYY' ) as oo_order_date, " . "to_char( o.oo_deliver_date, 'DD.MM.YYYY' ) as oo_deliver_date, " . "o.oo_parts_price, " . "o.oo_parts_currency, " . "o.oo_parts_cur_rate, " . "o.oo_ship_price, " . "o.oo_ship_currency, " . "o.oo_ship_cur_rate, " . "o.oo_taxes_price, " . "o.oo_taxes_currency, " . "o.oo_taxes_cur_rate, " . "o.oo_total_rate, " . "ou.ou_nr, " . "ou.oou_parts_price, " . "ou.oou_stock_flag, " . "s.os_name, " . "u.ou_name " . "from " . "orderorder o, " . "orderorderuser ou, " . "ordersupplier s, " . "orderuser u " . "where " . "o.oo_nr = $nr and " . "o.oo_nr = ou.oo_nr and " . "o.os_nr = s.os_nr and " . "ou.ou_nr = u.ou_nr"; $ress = db_query( $sql ); if( !$ress ) { print_error( "no result set" ); return; } $row = db_next( $ress ); if( !$row ) { print_error( "no rows" ); return; } $deliverdate = $row["oo_deliver_date"]; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $partscurr = $row["oo_parts_currency"]; $partsrate = $row["oo_parts_cur_rate"]; $partsprice = $row["oo_parts_price"]; $partspricechf = currency_to_chf( $partsprice, $partsrate ); $shipcurr = $row["oo_ship_currency"]; $shiprate = $row["oo_ship_cur_rate"]; $shipprice = $row["oo_ship_price"]; $shippricechf = currency_to_chf( $shipprice, $shiprate ); $taxescurr = $row["oo_taxes_currency"]; $taxesrate = $row["oo_taxes_cur_rate"]; $taxesprice = $row["oo_taxes_price"]; $taxespricechf = currency_to_chf( $taxesprice, $taxesrate ); $totalchf = $partspricechf + $shippricechf + $taxespricechf; while( $row ) { $ounr = $row["ou_nr"]; $url = "?cmd=orders&subcmd=detail&nr=$nr&ounr=$ounr"; $name = $row["ou_name"]; $price = $row["oou_parts_price"]; $pricechf = currency_to_chf( $price, $partsrate ); echo "" . "" . "" . "" . "" . "\n"; $row = db_next( $ress ); } echo "" . "" . "" . "" . "" . "\n"; echo "" . "" . "" . "" . "" . "\n"; echo "" . "" . "" . "" . "" . "\n"; echo "" . "" . "\n"; echo "
Order Nr$nr
Supplier" . $row["os_name"] . "
Order Date" . $row["oo_order_date"] . "
Delivery Date $deliverdate
* $name " . make_price_str( $price ) . " $partscurr @" . make_price_str( $partsrate ) . " " . make_price_str( $pricechf ) . " CHF
Parts " . make_price_str( $partsprice ) . " $partscurr @" . make_price_str( $partsrate ) . " " . make_price_str( $partspricechf ) . " CHF
Shipping " . make_price_str( $shipprice ) . " $shipcurr @" . make_price_str( $shiprate ) . " " . make_price_str( $shippricechf ) . " CHF
Taxes" . make_price_str( $taxesprice ) . " $taxescurr @" . make_price_str( $taxesrate ) . " " . make_price_str( $taxespricechf ) . " CHF
Total " . make_price_str( $totalchf ) . " CHF
\n"; if( $deliverdate == "" ) { echo "

 
set taxes and delivery date

\n"; } } function cmd_orders_ordered() { global $OP_CURRENCIES; $supplier = get_FORM_var( "supplier" ); if( !ereg( "^[1-9][0-9]*\$", $supplier ) ) { print_error( "missing or invalid supplier ($supplier)" ); return; } $user = get_FORM_var( "user" ); $usersql = "ou_nr = $user and "; if( !ereg( "^[1-9][0-9]*\$", $user ) ) { $user = 0; $usersql = ""; } $pnrs = get_POST_var( "pnrs" ); if( !ereg( "^[1-9][0-9]*(,[1-9][0-9]*)*\$", $pnrs ) ) { print_error( "missing or invalid numbers ($pnrs)" ); return; } $prices = array(); foreach( explode( ",", $pnrs ) as $pnr ) { $price = get_POST_var( "p$pnr" ); if( $price == "" ) { $price = 0; } else if( ereg( "^[0-9][0-9]*\\.[0-9][0-9]\$", $price ) ) { $price = str_replace( ".", "", $price ); } else { print_error( "invalid price ($price)" ); return; } $prices[$pnr] = $price; } $parts_rate = get_POST_var( "parts_rate" ); if( !ereg( "^[0-9][0-9]*\\.[0-9][0-9]\$", $parts_rate ) ) { print_error( "invalid parts currency rate ($parts_rate)" ); return; } $parts_rate = str_replace( ".", "", $parts_rate ); $shipping = get_POST_var( "shipping" ); if( $shipping == "" ) { $shipping = 0; } else if( ereg( "^[0-9][0-9]*\\.[0-9][0-9]\$", $shipping ) ) { $shipping = str_replace( ".", "", $shipping ); } else { print_error( "invalid shipping ($shipping)" ); return; } $ship_curr = get_POST_var( "ship_curr" ); if( !isset( $OP_CURRENCIES[$ship_curr] ) ) { print_error( "invalid shipping currency ($ship_curr)" ); return; } $ship_rate = get_POST_var( "ship_rate" ); if( !ereg( "^[0-9][0-9]*\\.[0-9][0-9]\$", $ship_rate ) ) { print_error( "invalid shipping currency rate ($ship_rate)" ); return; } $ship_rate = str_replace( ".", "", $ship_rate ); $taxes = get_POST_var( "taxes" ); if( $taxes == "" ) { $taxes = 0; } else if( ereg( "^[0-9][0-9]*\\.[0-9][0-9]\$", $taxes ) ) { $taxes = str_replace( ".", "", $taxes ); } else { print_error( "invalid taxes ($taxes)" ); return; } $taxes_curr = get_POST_var( "taxes_curr" ); if( !isset( $OP_CURRENCIES[$taxes_curr] ) ) { print_error( "invalid taxes currency ($taxes_curr)" ); return; } $taxes_rate = get_POST_var( "taxes_rate" ); if( !ereg( "^[0-9][0-9]*\\.[0-9][0-9]\$", $taxes_rate ) ) { print_error( "invalid taxes currency rate ($taxes_rate)" ); return; } $taxes_rate = str_replace( ".", "", $taxes_rate ); $sql = null; if( $user > 0 ) { $sql = "select s.os_name, s.os_part_url, s.os_currency, u.ou_name from ordersupplier s, orderuser u where s.os_nr = $supplier and u.ou_nr = $user"; } else { $sql = "select os_name, os_part_url, os_currency, '' as ou_name from ordersupplier where os_nr = $supplier"; } $ress = db_query( $sql ); if( !$ress ) { print_error( "no result set" ); return; } $row = db_next( $ress ); if( !$row ) { print_error( "no rows" ); return; } echo "

ordered " . htmlentities($row["os_name"] . " " . $row["ou_name"]) . "

\n"; $currency = $row["os_currency"]; $nr = db_next_nr( "orderorder", "oo_nr" ); db_begin(); $sql = "insert into orderorder ( " . "oo_nr, os_nr, oo_order_date, " . "oo_parts_price, oo_parts_currency " . ") values ( " . "$nr, $supplier, CURRENT_TIMESTAMP, " . "0, '$currency' " . ")"; if( db_update( $sql ) <= 0 ) { db_rollback(); print_error( "insert order failed" ); return; } $sql = "update orderpartuser set oo_nr = $nr, opu_type = 4 where oo_nr = 0 and $usersql opu_type = 3 and op_nr in ($pnrs)"; if( db_update( $sql ) <= 0 ) { db_rollback(); print_error( "adding parts to order failed" ); return; } foreach( $prices as $pnr => $price ) { $sql = "update orderpartuser set opu_price = $price where oo_nr = $nr and op_nr = $pnr"; if( db_update( $sql ) <= 0 ) { db_rollback(); print_error( "storing price failed" ); return; } } $sql = "insert into orderorderuser ( oo_nr, ou_nr, oou_parts_price, oou_stock_flag ) select oo_nr, ou_nr, sum(opu_price*opu_count) as oou_parts_price, 0 as oou_stock_flag from orderpartuser where oo_nr = $nr group by oo_nr, ou_nr, oou_stock_flag"; if( db_update( $sql ) <= 0 ) { db_rollback(); print_error( "adding parts to order failed" ); return; } $sql = "select sum(oou_parts_price) as oo_parts_price from orderorderuser where oo_nr = $nr"; $ress = db_query( $sql ); if( !$ress ) { db_rollback(); print_error( "summing up failed" ); return; } $row = db_next( $ress ); if( !$row ) { db_rollback(); print_error( "summing up failed (2)" ); return; } $sum = $row["oo_parts_price"]; $sql = "update " . "orderorder " . "set " . "oo_parts_price = $sum, " . "oo_parts_cur_rate = $parts_rate, " . "oo_ship_price = $shipping, " . "oo_ship_currency = '$ship_curr', " . "oo_ship_cur_rate = $ship_rate, " . "oo_taxes_price = $taxes, " . "oo_taxes_currency = '$taxes_curr', " . "oo_taxes_cur_rate = $taxes_rate " . "where " . "oo_nr = $nr"; if( db_update( $sql ) <= 0 ) { db_rollback(); print_error( "storing sum failed" ); return; } db_commit(); cmd_orders_show_summary( $nr ); } function cmd_orders_order() { global $OP_CURRENCIES; $supplier = get_FORM_var( "supplier" ); if( !ereg( "^[1-9][0-9]*\$", $supplier ) ) { print_error( "missing or invalid supplier ($supplier)" ); return; } $user = get_FORM_var( "user" ); $usersql = "pu.ou_nr = $user and "; if( !ereg( "^[1-9][0-9]*\$", $user ) ) { $user = 0; $usersql = ""; } $sql = null; if( $user > 0 ) { $sql = "select s.os_name, s.os_part_url, s.os_currency, u.ou_name " . "from ordersupplier s, orderuser u " . "where s.os_nr = $supplier and u.ou_nr = $user"; } else { $sql = "select os_name, os_part_url, os_currency, '' as ou_name " . "from ordersupplier where os_nr = $supplier"; } $ress = db_query( $sql ); if( !$ress ) { print_error( "no result set" ); return; } $row = db_next( $ress ); if( !$row ) { print_error( "no rows" ); return; } $currency = $row["os_currency"]; echo "

order " . htmlentities($row["os_name"] . " " . $row["ou_name"]) . "

\n"; $sql = "select " . "t.ot_long_name, " . "p.op_nr, " . "p.op_part_nr, " . "p.op_web_part_nr, " . "p.op_name, " . "p.op_descr, " . "p.op_price, " . "p.op_price_drop, " . "s.os_part_url, " . "s.os_currency, " . "sum(pu.opu_count) as opu_count " . "from " . "orderpart p " . "left join orderparttag pt on " . "p.op_nr = pt.op_nr and " . "pt.opt_primary = 1 " . "left join ordertag t on " . "pt.ot_nr = t.ot_nr, " . "orderpartuser pu, " . "ordersupplier s " . "where " . "s.os_nr = $supplier and " . "p.os_nr = $supplier and " . "pu.op_nr = p.op_nr and $usersql" . "pu.oo_nr = 0 and " . "pu.opu_type = 3 " . "group by " . "t.ot_long_name, " . "p.op_nr, " . "p.op_part_nr, " . "p.op_web_part_nr, " . "p.op_name, " . "p.op_descr, " . "p.op_price, " . "p.op_price_drop, " . "s.os_part_url, " . "s.os_currency " . "order by " . "t.ot_long_name, " . "p.op_name, " . "p.op_nr "; $sum = 0; $ress = db_query( $sql ); if( !$ress ) { return; } $row = db_next( $ress ); if( !$row ) { return; } echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $pnrs = ""; $nrspfx = ""; while( $row ) { $nr = $row["op_nr"]; $partnr = $row["op_part_nr"]; $webpartnr = $row["op_web_part_nr"]; if( $webpartnr == "" ) { $webpartnr = $partnr; } $parturl = sprintf( $row["os_part_url"], $webpartnr ); $price = make_price_str( $row["op_price"] ); $htmlprice = $price; if( $htmlprice == "" ) { $htmlprice = " "; } $pnrs .= $nrspfx . $nr; $nrspfx = ","; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $row = db_next( $ress ); } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
PartNrNamePrice dflPriceCount
" . $partnr . "" . $row["op_name"] . " -- " . $row["op_descr"] . "$htmlprice" . $row["opu_count"] . "
 Currency Rate"; echo "$currency    "; $parts_rate = make_price_str( get_currency_rate( $currency ) ); echo ""; echo " 
 Shipping"; print_select( "ship_curr", $OP_CURRENCIES, $currency ); $ship_rate = $parts_rate; echo " "; echo " 
 Taxes"; print_select( "taxes_curr", $OP_CURRENCIES, "CHF" ); echo " "; echo " 
\n"; echo "\n"; echo "\n"; echo "
\n"; } function cmd_orders_pending_print( $row, $users, $parturl, &$userprice ) { global $OPU_TYPES; $webpartnr = $row["op_web_part_nr"]; if( $webpartnr == "" ) { $webpartnr = $row["op_part_nr"]; } $parturl = sprintf( $parturl, $webpartnr ); $editurl = "?cmd=parts&subcmd=edit&nr=" . $row["op_nr"]; $n = count($users); $i = 0; $totcount = 0; while( $i < $n ) { $user = $users[$i][0]; $name = $users[$i][1]; $type = $users[$i][2]; $count = $users[$i][3]; if( $type == 3 ) { $totcount += $count; if( isset($userprice[$name]) ) { $userprice[$name] += $count * $row["op_price"]; } else { $userprice[$name] = $count * $row["op_price"]; } } $i++; } $totprice = $row["op_price"] * $totcount; $h = $n + 1; echo "\n"; echo "" . htmlentities($row["op_part_nr"]) . "\n"; echo "" . htmlentities($row["op_name"]) . "
" . htmlentities($row["op_descr"]) . "
\n"; echo "" . make_price_str($row["op_price"],"0.00") . "\n"; $i = 0; while( $i < $n ) { $user = $users[$i][0]; $name = $users[$i][1]; $type = $users[$i][2]; $count = $users[$i][3]; $color = ""; if( $type == 2 ) { $color = " style=\"background-color: #FFDDDD\""; } echo "" . htmlentities($name) . "\n"; echo "" . $OPU_TYPES[$type] . "\n"; echo "" . $count . "\n"; if( $i == 0 ) { echo "" . make_price_str($totprice,"0.00") . "\n"; } echo "\n"; echo "\n"; $i++; } $droptxt = "> "; $pricedrop = $row["op_price_drop"]; if( $pricedrop > $totcount ) { $droptxt = " style=\"background-color:#FFFFDD\">(drop at $pricedrop)"; } echo "total\n\n" . $totcount . "\n"; echo "\n"; return $totprice; } function cmd_orders_pending_prt_usr( $row, $parturl ) { global $OPU_TYPES; $webpartnr = $row["op_web_part_nr"]; if( $webpartnr == "" ) { $webpartnr = $row["op_part_nr"]; } $parturl = sprintf( $parturl, $webpartnr ); $editurl = "?cmd=parts&subcmd=edit&nr=" . $row["op_nr"]; $totprice = 0; $price = $row["op_price"]; $type = $row["opu_type"]; $count = $row["opu_count"]; if( $type == 3 ) { $totprice = $price * $count; } echo "\n"; echo "" . htmlentities($row["op_part_nr"]) . "\n"; echo "" . htmlentities($row["op_name"]) . "\n"; echo "" . htmlentities($row["op_descr"]) . " \n"; echo "" . make_price_str($price,"0.00") . "\n"; $color = ""; if( $type == 2 ) { $color = " style=\"background-color: #FFCCCC\""; } echo "" . $OPU_TYPES[$type] . "\n"; echo "" . $count . "\n"; echo "" . make_price_str($totprice,"0.00") . "\n"; echo "\n"; return $totprice; } function cmd_orders_pending() { $supplier = get_FORM_var( "supplier" ); if( !ereg( "^[1-9][0-9]*\$", $supplier ) ) { print_error( "missing or invalid supplier ($supplier)" ); return; } $user = get_FORM_var( "user" ); if( !ereg( "^[1-9][0-9]*\$", $user ) ) { $user = 0; } $partcount = 0; $sql = null; if( $user > 0 ) { $sql = "select s.os_name, s.os_part_url, u.ou_name from ordersupplier s, orderuser u where s.os_nr = $supplier and u.ou_nr = $user"; } else { $sql = "select os_name, os_part_url, '' as ou_name from ordersupplier where os_nr = $supplier"; } $ress = db_query( $sql ); if( !$ress ) { print_error( "no result set" ); return; } $row = db_next( $ress ); if( !$row ) { print_error( "no rows" ); return; } echo "

" . htmlentities($row["os_name"] . " " . $row["ou_name"]) . "

\n"; $parturl = $row["os_part_url"]; $username = $row["ou_name"]; if( $user > 0 ) { $sql = "select " . "t.ot_long_name, " . "p.op_nr, " . "p.op_part_nr, " . "p.op_web_part_nr, " . "p.op_name, " . "p.op_descr, " . "p.op_price, " . "p.op_price_drop, " . "s.os_currency, " . "$user as ou_nr, " . db_escape_str($username) . " as ou_name, " . "pu.opu_type, " . "pu.opu_count " . "from " . "orderpart p " . "left join orderparttag pt on " . "p.op_nr = pt.op_nr and " . "pt.opt_primary = 1 " . "left join ordertag t on " . "pt.ot_nr = t.ot_nr, " . "orderpartuser pu, " . "ordersupplier s " . "where " . "s.os_nr = $supplier and " . "p.os_nr = $supplier and " . "pu.op_nr = p.op_nr and " . "pu.ou_nr = $user and " . "pu.oo_nr = 0 and " . "pu.opu_type in ( 2, 3 ) " . "order by " . "t.ot_long_name, " . "p.op_name, " . "p.op_nr"; } else { $sql = "select " . "t.ot_long_name, " . "p.op_nr, " . "p.op_part_nr, " . "p.op_web_part_nr, " . "p.op_name, " . "p.op_descr, " . "p.op_price, " . "p.op_price_drop, " . "s.os_currency, " . "u.ou_nr, " . "u.ou_name, " . "pu.opu_type, " . "pu.opu_count " . "from " . "orderpart p " . "left join orderparttag pt on " . "p.op_nr = pt.op_nr and " . "pt.opt_primary = 1 " . "left join ordertag t on " . "pt.ot_nr = t.ot_nr, " . "orderpartuser pu, " . "orderuser u, " . "ordersupplier s " . "where " . "s.os_nr = $supplier and " . "p.os_nr = $supplier and " . "pu.op_nr = p.op_nr and " . "pu.ou_nr = u.ou_nr and " . "pu.oo_nr = 0 and " . "pu.opu_type in ( 2, 3 ) " . "order by " . "t.ot_long_name, " . "p.op_name, " . "p.op_nr, " . "u.ou_name "; } $ress = db_query( $sql ); if( !$ress ) { return; } $row = db_next( $ress ); if( !$row ) { echo "

no data found

\n"; return; } echo "\n"; echo "\n"; echo "\n"; if( $user == 0 ) { echo "\n"; } else { echo "\n"; echo "\n"; } echo "\n"; if( $user == 0 ) { echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; $prevrow = array( "op_nr" => 0, "ot_long_name" => "----" ); $users = null; $userprice = array(); $i = 0; $totprice = 0; while( $row ) { if( $row["op_nr"] != $prevrow["op_nr"] ) { $partcount++; if( $prevrow["op_nr"] > 0 ) { if( $user == 0 ) { $totprice += cmd_orders_pending_print( $prevrow, $users, $parturl, $userprice ); } else { $totprice += cmd_orders_pending_prt_usr( $prevrow, $parturl ); } } if( $row["ot_long_name"] != $prevrow["ot_long_name"] ) { $longname = $row["ot_long_name"]; if( $longname == "" ) { $longname = "\"untagged\""; } echo "\n"; } $prevrow = $row; $users = array(); $i = 0; } $users[$i] = array( $row["ou_nr"], $row["ou_name"], $row["opu_type"], $row["opu_count"] ); $row = db_next( $ress ); $i++; } if( $user == 0 ) { $totprice += cmd_orders_pending_print( $prevrow, $users, $parturl, $userprice ); } else { $totprice += cmd_orders_pending_prt_usr( $prevrow, $parturl ); } echo "\n"; echo "\n"; ksort( $userprice ); foreach( $userprice as $username => $price ) { echo "\n"; } echo "
part nrname / descriptionnamedescriptionpriceusertypecnttotal
" . htmlentities($longname) . "
Total" . make_price_str($totprice," ") . "
$username" . make_price_str($price," ") . "
\n"; if( $partcount > 0 ) { echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; } } function cmd_orders_choose() { $sql = "select " . "s.os_nr, s.os_name, s.os_currency, " . "count(*) as cnt, sum(p.op_price*pu.opu_count) as price " . "from " . "ordersupplier s, " . "orderpart p, " . "orderpartuser pu " . "where " . "pu.opu_type in ( 2, 3 ) and " . "pu.op_nr = p.op_nr and " . "p.os_nr = s.os_nr " . "group by " . "s.os_nr, s.os_name, s.os_currency " . "order by " . "s.os_name"; $ress = db_query( $sql ); if( $ress ) { $row = db_next( $ress ); if( $row ) { echo "

pending

"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; while( $row ) { $nr = $row["os_nr"]; $sn = $row["os_name"]; $cu = $row["os_currency"]; $cn = $row["cnt"]; $pr = make_price_str( $row["price"] ); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $row = db_next( $ress ); } echo "
SupplierCountPrice
$sn$cn$pr $cu
\n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; $suppliers = db_read_suppliers(); print_select( "supplier", $suppliers ); $users = db_read_users(); echo " "; print_select( "user", $users, 0, array( 0 => "all" ) ); echo " \n"; echo "
\n"; echo "
\n"; } } $sql = "select " . "o.oo_nr, " . "to_char( o.oo_order_date, 'DD.MM.YYYY' ) as oo_order, " . "to_char( o.oo_deliver_date, 'DD.MM.YYYY' ) as oo_deliver, " . "o.oo_parts_price, " . "s.os_name, " . "s.os_currency " . "from " . "orderorder o, " . "ordersupplier s " . "where " . "o.os_nr = s.os_nr " . "order by " . "oo_order_date desc"; $ress = db_query( $sql ); if( $ress ) { $row = db_next( $ress ); if( $row ) { echo "

old orders

"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; while( $row ) { $nr = $row["oo_nr"]; $od = $row["oo_order"]; $dd = $row["oo_deliver"]; if( $dd == "" ) { $dd = " "; } $pr = make_price_str( $row["oo_parts_price"] ); $sn = $row["os_name"]; $cu = $row["os_currency"]; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $row = db_next( $ress ); } echo "
NrSupplierOrderedDeliveredPrice
$nr$sn$od$dd$pr $cu
\n"; echo "
\n"; } } } function cmd_orders( $subcmd ) { echo "

orders

\n"; switch( $subcmd ) { case "delivered": cmd_orders_delivered(); break; case "delivery": cmd_orders_delivery(); break; case "ordered": cmd_orders_ordered(); break; case "order": cmd_orders_order(); break; case "summary": $nr = get_FORM_var( "nr" ); if( ereg( "^[1-9][0-9]*\$", $nr ) ) { cmd_orders_show_summary( $nr ); } else { cmd_orders_pending(); } break; case "detail": $nr = get_FORM_var( "nr" ); $ounr = get_FORM_var( "ounr" ); if( !ereg( "^[1-9][0-9]*\$", $nr ) ) { cmd_orders_pending(); } else if( !ereg( "^[0-9][0-9]*\$", $ounr ) ) { cmd_orders_show_detail( $nr, 0 ); } else { cmd_orders_show_detail( $nr, $ounr ); } break; case "pending": cmd_orders_pending(); break; default: cmd_orders_choose(); break; } } ?>